From 058616fa8979d870438128445666dc7214a66f54 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Thu, 6 Feb 2025 18:45:11 +0100 Subject: [PATCH] extracted the drawing of the annotation in it's own function --- cpp/src/view/gui.cpp | 57 ++++++++++++++++++++++---------------------- cpp/src/view/gui.hpp | 1 + 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cpp/src/view/gui.cpp b/cpp/src/view/gui.cpp index 8a188a0..0c6c321 100644 --- a/cpp/src/view/gui.cpp +++ b/cpp/src/view/gui.cpp @@ -48,6 +48,33 @@ void GUI::handle_click(int x, int y) { controller->on_tile_selected(file, rank); } +void GUI::draw_annotation(int file, int rank) { + if (file == 0) { + sf::Text annotation(std::to_string(rank + 1), font); + annotation.setStyle(sf::Text::Bold); + annotation.setCharacterSize(16); + annotation.setFillColor(rank % 2 == 0 ? colours[1] : colours[0]); + annotation.setPosition( + (file + .05) * TILE_SIZE, + (7 - rank + .05) * TILE_SIZE + ); + window.draw(annotation); + } + + if (rank == 0) { + sf::Text annotation("abcdefgh"[file], font); + annotation.setCharacterSize(16); + annotation.setOrigin(16, 16); + annotation.setStyle(sf::Text::Bold); + annotation.setFillColor(file % 2 == 0 ? colours[1] : colours[0]); + annotation.setPosition( + (file + 1) * TILE_SIZE, + (7 - rank + .95) * TILE_SIZE + ); + window.draw(annotation); + } +} + void GUI::draw_board(int selected_square, std::vector legal_moves) { // sf::Color alt_colours[2] = { // sf::Color(0xF6EB72), @@ -66,35 +93,7 @@ void GUI::draw_board(int selected_square, std::vector legal_moves) { (file + rank) % 2 == 0 ? colours[0] : colours[1] ); window.draw(square); - - if (file == 0) { - sf::Text annotation(std::to_string(rank + 1), font); - annotation.setStyle(sf::Text::Bold); - annotation.setCharacterSize(16); - annotation.setFillColor( - rank % 2 == 0 ? colours[1] : colours[0] - ); - annotation.setPosition( - (file + .05) * TILE_SIZE, - (7 - rank + .05) * TILE_SIZE - ); - window.draw(annotation); - } - - if (rank == 0) { - sf::Text annotation("abcdefgh"[file], font); - annotation.setCharacterSize(16); - annotation.setOrigin(16, 16); - annotation.setStyle(sf::Text::Bold); - annotation.setFillColor( - file % 2 == 0 ? colours[1] : colours[0] - ); - annotation.setPosition( - (file + 1) * TILE_SIZE, - (7 - rank + .95) * TILE_SIZE - ); - window.draw(annotation); - } + draw_annotation(file, rank); } } } diff --git a/cpp/src/view/gui.hpp b/cpp/src/view/gui.hpp index 570ed2f..ce0fdaa 100644 --- a/cpp/src/view/gui.hpp +++ b/cpp/src/view/gui.hpp @@ -33,4 +33,5 @@ class GUI : public View { void handle_click(int, int); void draw_board(int, std::vector); void draw_pieces(const Board&); + void draw_annotation(int, int); };