now we draw the annotations for the squares
This commit is contained in:
parent
56b74318c1
commit
77f77ac04e
@ -6,6 +6,8 @@
|
|||||||
GUI::GUI() {
|
GUI::GUI() {
|
||||||
window.create(sf::VideoMode(WINDOW_SIZE, WINDOW_SIZE), "Chess Board");
|
window.create(sf::VideoMode(WINDOW_SIZE, WINDOW_SIZE), "Chess Board");
|
||||||
load_textures();
|
load_textures();
|
||||||
|
|
||||||
|
font.loadFromFile("res/arial.ttf");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::update_board(
|
void GUI::update_board(
|
||||||
@ -41,16 +43,12 @@ void GUI::load_textures() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GUI::handle_click(int x, int y) {
|
void GUI::handle_click(int x, int y) {
|
||||||
// int file = x / TILE_SIZE;
|
int file = x / TILE_SIZE;
|
||||||
// int rank = 7 - (y / TILE_SIZE);
|
int rank = 7 - (y / TILE_SIZE);
|
||||||
// controller.on_tile_selected(file, rank);
|
controller->on_tile_selected(file, rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::draw_board(int selected_square, std::vector<Move> legal_moves) {
|
void GUI::draw_board(int selected_square, std::vector<Move> legal_moves) {
|
||||||
sf::Color colours[2] = {
|
|
||||||
sf::Color(0xEDD6B0FF),
|
|
||||||
sf::Color(0xB88762FF)
|
|
||||||
}; // Light and dark squares
|
|
||||||
// sf::Color alt_colours[2] = {
|
// sf::Color alt_colours[2] = {
|
||||||
// sf::Color(0xF6EB72),
|
// sf::Color(0xF6EB72),
|
||||||
// sf::Color(0xDCC34B)
|
// sf::Color(0xDCC34B)
|
||||||
@ -68,6 +66,35 @@ void GUI::draw_board(int selected_square, std::vector<Move> legal_moves) {
|
|||||||
(file + rank) % 2 == 0 ? colours[0] : colours[1]
|
(file + rank) % 2 == 0 ? colours[0] : colours[1]
|
||||||
);
|
);
|
||||||
window.draw(square);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ class GUI : public View {
|
|||||||
sf::RenderWindow window;
|
sf::RenderWindow window;
|
||||||
sf::Texture textures[6][2];
|
sf::Texture textures[6][2];
|
||||||
sf::Sprite pieces[64];
|
sf::Sprite pieces[64];
|
||||||
|
sf::Font font;
|
||||||
sf::Color colours[2] = {
|
sf::Color colours[2] = {
|
||||||
sf::Color(0xB88762FF), sf::Color(0xEDD6B0FF)
|
sf::Color(0xB88762FF), sf::Color(0xEDD6B0FF)
|
||||||
}; // Light and dark squares
|
}; // Light and dark squares
|
||||||
|
Loading…
x
Reference in New Issue
Block a user