diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 0e44979..6581934 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -25,6 +25,11 @@ BoardCanvas::BoardCanvas(wxFrame *parent) Bind(wxEVT_KEY_UP, [p=this](wxKeyEvent &e){e.ResumePropagation(1);e.Skip();}); Bind(wxEVT_PAINT, &BoardCanvas::OnPaint, this); Bind(wxEVT_SIZE, &BoardCanvas::OnResize, this); + + // Mouse events: + Bind(wxEVT_MOTION, &BoardCanvas::MouseEvent, this); + Bind(wxEVT_LEFT_DOWN, &BoardCanvas::MouseEvent, this); + Bind(wxEVT_LEFT_UP, &BoardCanvas::MouseEvent, this); } void BoardCanvas::OnResize(wxSizeEvent &e){ @@ -367,6 +372,9 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) { ((char)('a' + file)) + std::to_string(rank + 1); event.SetString(move); ProcessEvent(event); + } else { + // If square not valid just redraw (place piece back to its square) + Refresh(); } } if (event.LeftDown()) { @@ -412,7 +420,3 @@ void BoardCanvas::SetClockTime(short hours, short min, short sec, white_time = std::make_tuple(hours, min, sec); } } - -wxBEGIN_EVENT_TABLE(BoardCanvas, wxPanel) - EVT_MOUSE_EVENTS(BoardCanvas::MouseEvent) - wxEND_EVENT_TABLE() diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index 76aa60f..9a00262 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -95,5 +95,4 @@ public: std::string white_player, std::string black_player); void Animate(const std::string &board, bool is_black_turn, std::map captures, std::string src, std::string dst,bool faster); void SetClockTime(short hours, short min, short sec, bool IsBlack); - DECLARE_EVENT_TABLE() };