mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Add code to draw arrows on the board
This commit is contained in:
parent
a9eb4e0569
commit
b64489be9e
2 changed files with 40 additions and 0 deletions
|
@ -1,5 +1,11 @@
|
||||||
#include "BoardCanvas.hpp"
|
#include "BoardCanvas.hpp"
|
||||||
|
|
||||||
|
#define TRANS(PT) { \
|
||||||
|
wxPoint2DDouble tmp((PT).x,(PT).y); \
|
||||||
|
tmp=rot_m.TransformPoint(tmp); \
|
||||||
|
tmp=trans_m.TransformPoint(tmp); \
|
||||||
|
(PT).x=tmp.m_x;(PT).y=tmp.m_y;}
|
||||||
|
|
||||||
wxDEFINE_EVENT(PLAY_MOVE_EVENT, wxCommandEvent);
|
wxDEFINE_EVENT(PLAY_MOVE_EVENT, wxCommandEvent);
|
||||||
|
|
||||||
BoardCanvas::BoardCanvas(wxFrame *parent)
|
BoardCanvas::BoardCanvas(wxFrame *parent)
|
||||||
|
@ -462,3 +468,34 @@ void BoardCanvas::SetClockTime(short hours, short min, short sec,
|
||||||
gs.white_time = std::make_tuple(hours, min, sec);
|
gs.white_time = std::make_tuple(hours, min, sec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
|
||||||
|
// Compute arrow length and angle
|
||||||
|
wxPoint vect(xdst-xsrc,ydst-ysrc);
|
||||||
|
double length=sqrt(pow(vect.x,2)+pow(vect.y,2));
|
||||||
|
double angle=acos(vect.x/length);
|
||||||
|
|
||||||
|
// Compute metrics
|
||||||
|
std::uint8_t thickness=50;
|
||||||
|
std::uint8_t tip_height=sqrt(3)/2*thickness;
|
||||||
|
std::uint32_t tail_length=length-tip_height;
|
||||||
|
|
||||||
|
// Setup transform matrix
|
||||||
|
wxAffineMatrix2D rot_m,trans_m;
|
||||||
|
rot_m.Rotate(angle);
|
||||||
|
trans_m.Translate(xsrc,ysrc);
|
||||||
|
|
||||||
|
// Init polygons
|
||||||
|
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)};
|
||||||
|
|
||||||
|
// Transform points
|
||||||
|
TRANS(tip[0]);TRANS(tip[1]);TRANS(tip[2]);
|
||||||
|
TRANS(tail[0]);TRANS(tail[1]);TRANS(tail[2]);TRANS(tail[3]);
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
dc.SetPen(wxNullPen);
|
||||||
|
dc.SetBrush(wxColour(255,0,0));
|
||||||
|
dc.DrawPolygon(3,tip);
|
||||||
|
dc.DrawPolygon(4,tail);
|
||||||
|
}
|
||||||
|
|
|
@ -91,6 +91,9 @@ class BoardCanvas : public wxPanel {
|
||||||
AnimState adata;
|
AnimState adata;
|
||||||
GameState gs;
|
GameState gs;
|
||||||
|
|
||||||
|
/// @brief Draw an arrow from a source point to a destination point on DC
|
||||||
|
void DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BoardCanvas(wxFrame *parent);
|
BoardCanvas(wxFrame *parent);
|
||||||
BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen);
|
BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen);
|
||||||
|
|
Loading…
Add table
Reference in a new issue