mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Now arrows can be drawn using right clicks and drag
This commit is contained in:
parent
1e03d1c245
commit
3cc84d5ec8
3 changed files with 35 additions and 8 deletions
2
TODO.md
2
TODO.md
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
## Additional Features
|
## Additional Features
|
||||||
- [ ] Add a live evaluation bar to the BoardCanvas
|
- [ ] Add a live evaluation bar to the BoardCanvas
|
||||||
- [ ] Be able to draw arrows on the Board
|
- [x] Be able to draw arrows on the Board
|
||||||
- [ ] Highlight the last played move
|
- [ ] Highlight the last played move
|
||||||
- [ ] Be able to play against an engine
|
- [ ] Be able to play against an engine
|
||||||
- [ ] Implement full chess engine game analyzer/annotator
|
- [ ] Implement full chess engine game analyzer/annotator
|
||||||
|
|
|
@ -15,6 +15,7 @@ BoardCanvas::BoardCanvas(wxFrame *parent)
|
||||||
lock_square_size(false), t(new Theme()), t_captures(new Theme()) {
|
lock_square_size(false), t(new Theme()), t_captures(new Theme()) {
|
||||||
is_dragging = false;
|
is_dragging = false;
|
||||||
valid_drag = false;
|
valid_drag = false;
|
||||||
|
valid_arrow = false;
|
||||||
// Init animation data
|
// Init animation data
|
||||||
adata.duration=200;
|
adata.duration=200;
|
||||||
adata.duration_fast=80;
|
adata.duration_fast=80;
|
||||||
|
@ -45,6 +46,8 @@ BoardCanvas::BoardCanvas(wxFrame *parent)
|
||||||
Bind(wxEVT_MOTION, &BoardCanvas::MouseEvent, this);
|
Bind(wxEVT_MOTION, &BoardCanvas::MouseEvent, this);
|
||||||
Bind(wxEVT_LEFT_DOWN, &BoardCanvas::MouseEvent, this);
|
Bind(wxEVT_LEFT_DOWN, &BoardCanvas::MouseEvent, this);
|
||||||
Bind(wxEVT_LEFT_UP, &BoardCanvas::MouseEvent, this);
|
Bind(wxEVT_LEFT_UP, &BoardCanvas::MouseEvent, this);
|
||||||
|
Bind(wxEVT_RIGHT_DOWN, &BoardCanvas::MouseEvent, this);
|
||||||
|
Bind(wxEVT_RIGHT_UP, &BoardCanvas::MouseEvent, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoardCanvas::OnResize(wxSizeEvent &e){
|
void BoardCanvas::OnResize(wxSizeEvent &e){
|
||||||
|
@ -434,6 +437,19 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) {
|
||||||
is_dragging = true;
|
is_dragging = true;
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
} else if (valid_arrow && event.RightUp()) {
|
||||||
|
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);
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_dragging) {
|
if (is_dragging) {
|
||||||
is_dragging = false;
|
is_dragging = false;
|
||||||
|
@ -457,7 +473,7 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) {
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.LeftDown()) {
|
if (event.LeftDown() || event.RightDown()) {
|
||||||
SetFocus();
|
SetFocus();
|
||||||
REFRESH_MOUSE_LOCATION();
|
REFRESH_MOUSE_LOCATION();
|
||||||
lastClickX = mouseX;
|
lastClickX = mouseX;
|
||||||
|
@ -466,12 +482,22 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) {
|
||||||
if (IsCurrentSquareValid) {
|
if (IsCurrentSquareValid) {
|
||||||
active_square.x = file;
|
active_square.x = file;
|
||||||
active_square.y = rank;
|
active_square.y = rank;
|
||||||
if (gs.board[(7 - rank) * 8 + file] != ' ') {
|
if(event.LeftDown()){
|
||||||
wxLogDebug("Drag start on square (%d,%d)", file, rank);
|
if (gs.board[(7 - rank) * 8 + file] != ' ') {
|
||||||
valid_drag = true;
|
wxLogDebug("Drag start on square (%d,%d)", file, rank);
|
||||||
|
valid_drag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wxLogDebug("Arrow start on square (%d,%d)", file, rank);
|
||||||
|
valid_arrow = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(event.LeftUp()){
|
||||||
|
gs.arrows.clear();
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Let GameTableLeftPanel process mouse wheel events:
|
// Let GameTableLeftPanel process mouse wheel events:
|
||||||
|
@ -506,6 +532,7 @@ void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
|
||||||
wxPoint vect(xdst-xsrc,ydst-ysrc);
|
wxPoint vect(xdst-xsrc,ydst-ysrc);
|
||||||
double length=ceil(sqrt(pow(vect.x,2)+pow(vect.y,2)));
|
double length=ceil(sqrt(pow(vect.x,2)+pow(vect.y,2)));
|
||||||
double angle=acos(vect.x/length);
|
double angle=acos(vect.x/length);
|
||||||
|
angle= (vect.y>0) ? angle=angle : -angle;
|
||||||
|
|
||||||
// Compute metrics
|
// Compute metrics
|
||||||
std::uint8_t thickness=50;
|
std::uint8_t thickness=50;
|
||||||
|
@ -514,8 +541,8 @@ void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
|
||||||
|
|
||||||
// Setup transform matrix
|
// Setup transform matrix
|
||||||
wxAffineMatrix2D rot_m;
|
wxAffineMatrix2D rot_m;
|
||||||
rot_m.Rotate(-angle);
|
rot_m.Rotate(angle);
|
||||||
|
wxLogDebug("Angle is %d,%d",(int)vect.x,(int)vect.y);
|
||||||
// Init polygons
|
// Init polygons
|
||||||
wxPoint tip[]={wxPoint(tail_length,-thickness/2),wxPoint(tail_length,thickness/2),wxPoint(tail_length+tip_height,0)};
|
wxPoint tip[]={wxPoint(tail_length,-thickness/2),wxPoint(tail_length,thickness/2),wxPoint(tail_length+tip_height,0)};
|
||||||
wxPoint tail[]={wxPoint(0,-thickness/4),wxPoint(tail_length,-thickness/4),wxPoint(tail_length,thickness/4),wxPoint(0,thickness/4)};
|
wxPoint tail[]={wxPoint(0,-thickness/4),wxPoint(tail_length,-thickness/4),wxPoint(tail_length,thickness/4),wxPoint(0,thickness/4)};
|
||||||
|
|
|
@ -80,7 +80,7 @@ class BoardCanvas : public wxPanel {
|
||||||
std::string white_player,black_player;
|
std::string white_player,black_player;
|
||||||
|
|
||||||
// Various canvas state variables
|
// Various canvas state variables
|
||||||
bool black_side, is_dragging, valid_drag, is_black_turn;
|
bool black_side, is_dragging, valid_drag, valid_arrow, is_black_turn;
|
||||||
std::uint32_t boardX, boardY, square_width, piece_width, mouseX, mouseY, lastClickX,
|
std::uint32_t boardX, boardY, square_width, piece_width, mouseX, mouseY, lastClickX,
|
||||||
lastClickY;
|
lastClickY;
|
||||||
wxSize canvas_size;
|
wxSize canvas_size;
|
||||||
|
|
Loading…
Add table
Reference in a new issue