mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Debug BoardCanvas and enable square highlight
This commit is contained in:
parent
3cc84d5ec8
commit
334906fce4
1 changed files with 21 additions and 9 deletions
|
@ -48,6 +48,7 @@ BoardCanvas::BoardCanvas(wxFrame *parent)
|
||||||
Bind(wxEVT_LEFT_UP, &BoardCanvas::MouseEvent, this);
|
Bind(wxEVT_LEFT_UP, &BoardCanvas::MouseEvent, this);
|
||||||
Bind(wxEVT_RIGHT_DOWN, &BoardCanvas::MouseEvent, this);
|
Bind(wxEVT_RIGHT_DOWN, &BoardCanvas::MouseEvent, this);
|
||||||
Bind(wxEVT_RIGHT_UP, &BoardCanvas::MouseEvent, this);
|
Bind(wxEVT_RIGHT_UP, &BoardCanvas::MouseEvent, this);
|
||||||
|
Bind(wxEVT_RIGHT_DCLICK, &BoardCanvas::MouseEvent, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoardCanvas::OnResize(wxSizeEvent &e){
|
void BoardCanvas::OnResize(wxSizeEvent &e){
|
||||||
|
@ -235,8 +236,8 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
|
||||||
|
|
||||||
// Draw highlighted squares
|
// Draw highlighted squares
|
||||||
for(const std::string &s:gs.squares_hl){
|
for(const std::string &s:gs.squares_hl){
|
||||||
std::uint8_t srank = s[0]-'a';
|
std::uint8_t sfile = s[0]-'a';
|
||||||
std::uint8_t sfile = s[1]-'1';
|
std::uint8_t srank = s[1]-'1';
|
||||||
if (!black_side) {
|
if (!black_side) {
|
||||||
srank = 7 - srank;
|
srank = 7 - srank;
|
||||||
sfile = 7 - sfile;
|
sfile = 7 - sfile;
|
||||||
|
@ -246,7 +247,7 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
|
||||||
if(s.size()>2)
|
if(s.size()>2)
|
||||||
type=s[2];
|
type=s[2];
|
||||||
// Default highlight (type='a' or something else not supported)
|
// Default highlight (type='a' or something else not supported)
|
||||||
dc.SetPen(wxPen(*wxWHITE, 1));
|
dc.SetPen(wxNullPen);
|
||||||
dc.SetBrush(wxColour(255,0,0,110));
|
dc.SetBrush(wxColour(255,0,0,110));
|
||||||
if(type=='b')
|
if(type=='b')
|
||||||
dc.SetBrush(wxColour(0,255,0,110));
|
dc.SetBrush(wxColour(0,255,0,110));
|
||||||
|
@ -437,17 +438,27 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) {
|
||||||
is_dragging = true;
|
is_dragging = true;
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
} else if (valid_arrow && event.RightUp()) {
|
} else if ((valid_arrow && event.RightUp()) || event.RightDClick()) {
|
||||||
valid_arrow=false;
|
valid_arrow=false;
|
||||||
// Handle drop
|
// Handle drop
|
||||||
REFRESH_MOUSE_LOCATION();
|
REFRESH_MOUSE_LOCATION();
|
||||||
INIT_CURRENT_SQUARE();
|
INIT_CURRENT_SQUARE();
|
||||||
if (IsCurrentSquareValid) {
|
if (IsCurrentSquareValid) {
|
||||||
std::string arrow = ((char)('a' + active_square.x)) +
|
std::string src=((char)('a' + active_square.x)) +
|
||||||
std::to_string(+active_square.y + 1) +
|
std::to_string(+active_square.y + 1);
|
||||||
((char)('a' + file)) + std::to_string(rank + 1);
|
std::string dst=((char)('a' + file)) + std::to_string(rank + 1);
|
||||||
gs.arrows.push_back(arrow);
|
if(src!=dst){
|
||||||
wxLogDebug("Draw arrow %s",arrow);
|
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();
|
Refresh();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -496,6 +507,7 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) {
|
||||||
}
|
}
|
||||||
else if(event.LeftUp()){
|
else if(event.LeftUp()){
|
||||||
gs.arrows.clear();
|
gs.arrows.clear();
|
||||||
|
gs.squares_hl.clear();
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue