aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/left_panel/board/BoardCanvas.cpp
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-10 11:14:25 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-10 11:14:25 +0100
commite069a29f99dfb6e1139f47f3bb291902752d1283 (patch)
tree746ffcbfc5d17f076a34eed6a86fb086df979526 /src/game_tab/left_panel/board/BoardCanvas.cpp
parent179a173b3b063a6e9e9807912919b77abbbe5115 (diff)
Debug animations, LiveEngine and improve arrow/squares highlights
Diffstat (limited to 'src/game_tab/left_panel/board/BoardCanvas.cpp')
-rw-r--r--src/game_tab/left_panel/board/BoardCanvas.cpp88
1 files changed, 35 insertions, 53 deletions
diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp
index 9c80196..9294006 100644
--- a/src/game_tab/left_panel/board/BoardCanvas.cpp
+++ b/src/game_tab/left_panel/board/BoardCanvas.cpp
@@ -18,9 +18,10 @@ BoardCanvas::BoardCanvas(wxFrame *parent)
valid_drag = false;
arrow_drag = false;
arrows_offset = t->GetSquaresSizes()/2.5;
+ arrow_thickness = t->GetSquaresSizes()/1.8;
// Init animation data
adata.duration=100;
- adata.duration_fast=100;
+ adata.duration_fast=50;
adata.fps=60;
adata.buffer=new wxBitmap(500,500,32);
adata.animate=false;
@@ -230,30 +231,19 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
// Draw highlighted squares
for(int i=0;i<(gs.squares_hl.size()+squares_hl.size());i++){
- const std::string &s=i<gs.squares_hl.size() ? gs.squares_hl[i] : squares_hl[i-gs.squares_hl.size()];
- std::uint8_t sfile = s[0]-'a';
- std::uint8_t srank = s[1]-'1';
+ const GameState::Square &s=i<gs.squares_hl.size() ? gs.squares_hl[i] : squares_hl[i-gs.squares_hl.size()];
+ std::uint8_t sfile = s.square[0]-'a';
+ std::uint8_t srank = s.square[1]-'1';
if (!black_side) {
srank = 7 - srank;
sfile = 7 - sfile;
}
if(srank == rank && sfile==file){
- char type='a';
- if(s.size()>2)
- type=s[2];
- // Default highlight (type='a' or something else not supported)
dc.SetPen(wxNullPen);
- dc.SetBrush(wxColour(255, 102, 122));
- if(type=='b')
- dc.SetBrush(wxColour(120, 255, 102));
- else if(type=='c')
- dc.SetBrush(wxColour(102, 196, 255));
- else if(type=='d')
- dc.SetBrush(wxColour(255, 204, 213));
- else if(type=='e')
- dc.SetBrush(wxColour(220, 255, 204));
- else if(type=='f')
- dc.SetBrush(wxColour(204, 231, 255));
+ if(s.color!=wxNullColour)
+ dc.SetBrush(s.color);
+ else
+ dc.SetBrush(wxColour(255, 102, 122));
dc.DrawRectangle(wxRect(x,y,square_width,square_width));
}
}
@@ -396,12 +386,12 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
boardY + square_width * 8 + numbers_size.y*2));
}
// Draw arrows
- for(int i=0;i<(gs.arrows.size()+arrows.size());i++){
- const std::string &arrow= i<gs.arrows.size() ? gs.arrows[i] : arrows[i-gs.arrows.size()];
- std::uint8_t sfile = arrow[0]-'a';
- std::uint8_t srank = arrow[1]-'1';
- std::uint8_t dfile = arrow[2]-'a';
- std::uint8_t drank = arrow[3]-'1';
+ for(int i=0;i<(gs.arrows.size()+arrows.size());i++){
+ const GameState::Arrow &arrow= i<gs.arrows.size() ? gs.arrows[i] : arrows[i-gs.arrows.size()];
+ std::uint8_t sfile = arrow.src[0]-'a';
+ std::uint8_t srank = arrow.src[1]-'1';
+ std::uint8_t dfile = arrow.dst[0]-'a';
+ std::uint8_t drank = arrow.dst[1]-'1';
if (!black_side) {
srank = 7 - srank;
sfile = 7 - sfile;
@@ -414,37 +404,20 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
std::uint32_t dy = boardY + drank * square_width + square_width/2;
// Parse arrow for metadata (maybe having a datatype is better)
- std::uint8_t thickness=50;
- if(arrow.size()>4){
- std::string color="#";
- std::string new_thickness="";
- char key='?';
- for(const char &c:arrow){
- if(c=='#'||c=='%'){
- key=c;
- continue;
- }else if(key=='#'){
- color+=c;
- } else if(key=='%'){
- new_thickness+=c;
- }
- }
- if(color.size()>1)
- dc.SetBrush(wxColour(color));
- if(new_thickness.size()>0)
- thickness=(std::uint8_t)std::stoi(new_thickness);
- } else
+ if(arrow.color!=wxNullColour)
+ dc.SetBrush(arrow.color);
+ else
dc.SetBrush(color_arrows);
if(((abs(drank-srank) == 2) && (abs(dfile-sfile) == 1))||
((abs(drank-srank) == 1) && (abs(dfile-sfile) == 2))){
if(abs(drank-srank) == 1){
- DrawLArrow(dc,sx,sy,dx,dy,false,thickness);
+ DrawLArrow(dc,sx,sy,dx,dy,false,arrow_thickness*arrow.scale);
}
else {
- DrawLArrow(dc,sx,sy,dx,dy,true,thickness);
+ DrawLArrow(dc,sx,sy,dx,dy,true,arrow_thickness*arrow.scale);
}
} else {
- DrawArrow(dc,sx,sy,dx,dy,thickness);
+ DrawArrow(dc,sx,sy,dx,dy,arrow_thickness*arrow.scale);
}
}
}
@@ -519,14 +492,22 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) {
std::to_string(+active_square.y + 1);
std::string dst=((char)('a' + file)) + std::to_string(rank + 1);
if(src!=dst){
- arrows.push_back(src+dst);
+ arrows.push_back(DEFAULT_ARROW(src,dst));
wxLogDebug("Draw arrow %s",src+dst);
}
else {
- if(std::count(squares_hl.begin(), squares_hl.end(), src)){
- squares_hl.erase(std::remove(squares_hl.begin(), squares_hl.end(), src), squares_hl.end());
- }else{
- squares_hl.push_back(src+"f");
+ int id=0;
+ bool removed=false;
+ for(GameState::Square &s:squares_hl){
+ if(s.square==src){
+ squares_hl.erase(squares_hl.begin()+id);
+ removed=true;
+ break;
+ }
+ id++;
+ }
+ if(!removed){
+ squares_hl.push_back(DEFAULT_SQUARE(src));
wxLogDebug("Highlight square %s",src);
}
}
@@ -548,6 +529,7 @@ void BoardCanvas::Zoom(std::int32_t zoom) {
if(!t->Zoom(zoom))
return;
t_captures->ResizePieces(t->GetPiecesSizes() * CAPTURE_FACTOR);
+ arrow_thickness = t->GetSquaresSizes()/1.8;
Refresh();
}