diff --git a/cpp/src/view/gui.cpp b/cpp/src/view/gui.cpp index 595a617..8a188a0 100644 --- a/cpp/src/view/gui.cpp +++ b/cpp/src/view/gui.cpp @@ -6,6 +6,8 @@ GUI::GUI() { window.create(sf::VideoMode(WINDOW_SIZE, WINDOW_SIZE), "Chess Board"); load_textures(); + + font.loadFromFile("res/arial.ttf"); } void GUI::update_board( @@ -41,16 +43,12 @@ void GUI::load_textures() { } void GUI::handle_click(int x, int y) { - // int file = x / TILE_SIZE; - // int rank = 7 - (y / TILE_SIZE); - // controller.on_tile_selected(file, rank); + int file = x / TILE_SIZE; + int rank = 7 - (y / TILE_SIZE); + controller->on_tile_selected(file, rank); } void GUI::draw_board(int selected_square, std::vector legal_moves) { - sf::Color colours[2] = { - sf::Color(0xEDD6B0FF), - sf::Color(0xB88762FF) - }; // Light and dark squares // sf::Color alt_colours[2] = { // sf::Color(0xF6EB72), // sf::Color(0xDCC34B) @@ -68,6 +66,35 @@ 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); + } } } } diff --git a/cpp/src/view/gui.hpp b/cpp/src/view/gui.hpp index ad96e4d..570ed2f 100644 --- a/cpp/src/view/gui.hpp +++ b/cpp/src/view/gui.hpp @@ -23,6 +23,7 @@ class GUI : public View { sf::RenderWindow window; sf::Texture textures[6][2]; sf::Sprite pieces[64]; + sf::Font font; sf::Color colours[2] = { sf::Color(0xB88762FF), sf::Color(0xEDD6B0FF) }; // Light and dark squares