diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 8687639..1043d86 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -48,6 +48,7 @@ BoardCanvas::BoardCanvas(wxFrame *parent) Bind(wxEVT_LEFT_UP, &BoardCanvas::MouseEvent, this); Bind(wxEVT_RIGHT_DOWN, &BoardCanvas::MouseEvent, this); Bind(wxEVT_RIGHT_UP, &BoardCanvas::MouseEvent, this); + Bind(wxEVT_RIGHT_DCLICK, &BoardCanvas::MouseEvent, this); } void BoardCanvas::OnResize(wxSizeEvent &e){ @@ -235,8 +236,8 @@ void BoardCanvas::DrawBoard(wxDC &dc) { // Draw highlighted squares for(const std::string &s:gs.squares_hl){ - std::uint8_t srank = s[0]-'a'; - std::uint8_t sfile = s[1]-'1'; + std::uint8_t sfile = s[0]-'a'; + std::uint8_t srank = s[1]-'1'; if (!black_side) { srank = 7 - srank; sfile = 7 - sfile; @@ -246,7 +247,7 @@ void BoardCanvas::DrawBoard(wxDC &dc) { if(s.size()>2) type=s[2]; // Default highlight (type='a' or something else not supported) - dc.SetPen(wxPen(*wxWHITE, 1)); + dc.SetPen(wxNullPen); dc.SetBrush(wxColour(255,0,0,110)); if(type=='b') dc.SetBrush(wxColour(0,255,0,110)); @@ -437,17 +438,27 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) { is_dragging = true; Refresh(); } - } else if (valid_arrow && event.RightUp()) { + } else if ((valid_arrow && event.RightUp()) || event.RightDClick()) { valid_arrow=false; // Handle drop REFRESH_MOUSE_LOCATION(); INIT_CURRENT_SQUARE(); if (IsCurrentSquareValid) { - std::string arrow = ((char)('a' + active_square.x)) + - std::to_string(+active_square.y + 1) + - ((char)('a' + file)) + std::to_string(rank + 1); - gs.arrows.push_back(arrow); - wxLogDebug("Draw arrow %s",arrow); + std::string src=((char)('a' + active_square.x)) + + std::to_string(+active_square.y + 1); + std::string dst=((char)('a' + file)) + std::to_string(rank + 1); + if(src!=dst){ + gs.arrows.push_back(src+dst); + wxLogDebug("Draw arrow %s",src+dst); + } + else { + if(std::count(gs.squares_hl.begin(), gs.squares_hl.end(), src)){ + gs.squares_hl.erase(std::remove(gs.squares_hl.begin(), gs.squares_hl.end(), src), gs.squares_hl.end()); + }else{ + gs.squares_hl.push_back(src); + wxLogDebug("Highlight square %s",src); + } + } Refresh(); } } else { @@ -496,6 +507,7 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) { } else if(event.LeftUp()){ gs.arrows.clear(); + gs.squares_hl.clear(); Refresh(); } }