10#include <wx/artprov.h>
11#include <wx/dcbuffer.h>
14wxDECLARE_EVENT(PLAY_MOVE_EVENT, wxCommandEvent);
16#define REFRESH_MOUSE_LOCATION() \
18 const wxPoint pt = wxGetMousePosition(); \
19 mouseX = pt.x - this->GetScreenPosition().x; \
20 mouseY = pt.y - this->GetScreenPosition().y; \
23#define INIT_CURRENT_SQUARE() \
24 std::uint32_t file = 7 - (mouseX - boardX) / square_width; \
25 std::uint32_t rank = (mouseY - boardY) / square_width; \
30 bool IsCurrentSquareValid = file <= 7 && rank <= 7;
32#define MOUSE_ON(x, y, width, height) \
33 (mouseX >= (x) && mouseX <= ((x) + (width)) && mouseY >= (y) && \
34 mouseY <= ((y) + (height)))
36#define CAPTURE_FACTOR 0.35
37#define SQUARE_NUM_PADDING 5
38#define DEFAULT_ARROW(SRC,DST) {(SRC),(DST),wxNullColour,1}
39#define DEFAULT_SQUARE(SQUARE) {(SQUARE),wxNullColour}
41typedef std::tuple<short, short, short> ClockTime;
74 wxColour color=wxNullColour;
80 wxColour color=wxNullColour;
82 std::string white, black;
96 std::map<char, std::uint8_t> captures;
104 bool show_evalbar=
false;
106 ClockTime black_time={-1,-1,-1}, white_time={-1,-1,-1};
132 bool black_side, is_dragging, valid_drag, arrow_drag, is_black_turn;
133 std::int32_t boardX, boardY, square_width, piece_width, mouseX, mouseY, lastClickX,
139 std::map<char, std::uint8_t> captures;
142 bool lock_square_size;
150 void DrawArrow(wxDC &dc,
int xsrc,
int ysrc,
int xdst,
int ydst, std::uint8_t thickness=50);
152 void DrawLArrow(wxDC &dc,
int xsrc,
int ysrc,
int xdst,
int ydst,
bool flip=
false, std::uint8_t thickness=50);
158 void ApplyPreferences();
162 void OnPaint(wxPaintEvent &event);
166 void Zoom(std::int32_t zoom);
172 void Animate(
const GameState &new_gs,
const std::string &src,
const std::string &dst,
bool faster);
174 void SetClockTime(
short hours,
short min,
short sec,
bool IsBlack);
This class draws the chess board (squares, pieces, arrows and every other board related components).
Definition: BoardCanvas.hpp:113
bool frozen
Board can be frozen (to preview the board themes in the preference menu for example)
Definition: BoardCanvas.hpp:141
void SetClockTime(short hours, short min, short sec, bool IsBlack)
Setup clock on displayed on the canvas.
Definition: BoardCanvas.cpp:599
void DrawBoard(wxDC &dc)
Draw current board state BoardCanvas::gs on the given wxDC.
Definition: BoardCanvas.cpp:192
int arrows_offset
Offset used for the start point of the arrows (this way, arrows do not completely overlap on the piec...
Definition: BoardCanvas.hpp:121
void Swap()
Change between black side and white side.
Definition: BoardCanvas.cpp:594
AnimState adata
Current animation state.
Definition: BoardCanvas.hpp:145
void OnPaint(wxPaintEvent &event)
Callback called by wxWidgets to refresh the canvas.
Definition: BoardCanvas.cpp:71
wxSize canvas_size
Contains an up to date dimension of the canvas size and its use in various places.
Definition: BoardCanvas.hpp:136
GameState gs
Current board state (contains all the game state)
Definition: BoardCanvas.hpp:147
wxPoint active_square
Used for drag and drop.
Definition: BoardCanvas.hpp:138
Theme * t_captures
Scale down version of BoardCanvas::t for the captured pieces by black and white.
Definition: BoardCanvas.hpp:117
std::string white_player
Player names.
Definition: BoardCanvas.hpp:125
Theme * t
Contains the theme for squares and pieces (see Theme)
Definition: BoardCanvas.hpp:115
void DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip=false, std::uint8_t thickness=50)
Draw an arrow with a L shape (such as knight moves)
Definition: BoardCanvas.cpp:645
wxColour color_arrows
Stores the color of the arrows.
Definition: BoardCanvas.hpp:119
void DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, std::uint8_t thickness=50)
Draw an arrow from a source point to a destination point on DC.
Definition: BoardCanvas.cpp:608
std::vector< GameState::Arrow > arrows
Current drawn arrows that were drawn with the mouse.
Definition: BoardCanvas.hpp:129
void Animate(const GameState &new_gs, const std::string &src, const std::string &dst, bool faster)
Animate a piece front src to dst from current position.
Definition: BoardCanvas.cpp:130
std::vector< GameState::Square > squares_hl
Current highlighted squares that were highlighted with the mouse.
Definition: BoardCanvas.hpp:127
void SetupBoard(const GameState &new_gs)
Display a position on the canvas.
Definition: BoardCanvas.cpp:125
void Zoom(std::int32_t zoom)
Zomm in/out on the canvas.
Definition: BoardCanvas.cpp:586
void MouseEvent(wxMouseEvent &event)
Callback called by wxWidgets to handle mouse events.
Definition: BoardCanvas.cpp:455
std::uint8_t arrow_thickness
Thickness of the arrows.
Definition: BoardCanvas.hpp:123
The in memory board theme (used by BoardCanvas)
Definition: Theme.hpp:19
Drawing buffer and state for animations.
Definition: BoardCanvas.hpp:46
int duration
Animation durations (in ms)
Definition: BoardCanvas.hpp:56
bool animate
Should animation be played on refresh?
Definition: BoardCanvas.hpp:50
wxBitmap * buffer
Temporary buffer to reduce latency.
Definition: BoardCanvas.hpp:48
char piece_moved
Current animated piece.
Definition: BoardCanvas.hpp:60
std::uint8_t fps
Animation FPS.
Definition: BoardCanvas.hpp:58
int frames
Total number of frames for the animation.
Definition: BoardCanvas.hpp:54
int frame
Current animated frame.
Definition: BoardCanvas.hpp:52
wxPoint src
Starting point of the animated piece.
Definition: BoardCanvas.hpp:62
wxPoint transVect
Translation vector of the animated piece.
Definition: BoardCanvas.hpp:64
State of an arrow.
Definition: BoardCanvas.hpp:72
State of an highlighted square.
Definition: BoardCanvas.hpp:78
Current game state displayed by BoardCanvas.
Definition: BoardCanvas.hpp:70
std::vector< Square > squares_hl
Square to highlight (combined to BoardCanvas::squares_hl)
Definition: BoardCanvas.hpp:98
struct GameState::Arrow Arrow
State of an arrow.
std::string promotion
When there is a pending promotion, this variable contains the coordinate of the square on which the p...
Definition: BoardCanvas.hpp:95
std::string board
Contains all the board squares with their pieces in the same order as the FEN specification.
Definition: BoardCanvas.hpp:93
struct GameState::Square Square
State of an highlighted square.
std::vector< Arrow > arrows
Arrow to draw (combined to BoardCanvas::arrows)
Definition: BoardCanvas.hpp:100