From e069a29f99dfb6e1139f47f3bb291902752d1283 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 10 Jan 2023 11:14:25 +0100 Subject: Debug animations, LiveEngine and improve arrow/squares highlights --- src/game_tab/left_panel/board/BoardCanvas.cpp | 88 +++++++++++---------------- src/game_tab/left_panel/board/BoardCanvas.hpp | 20 ++++-- 2 files changed, 51 insertions(+), 57 deletions(-) (limited to 'src/game_tab/left_panel/board') 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=i2) - 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= i4){ - 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(); } diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index 553994c..bc850b7 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -35,6 +35,8 @@ wxDECLARE_EVENT(PLAY_MOVE_EVENT, wxCommandEvent); #define CAPTURE_FACTOR 0.35 #define SQUARE_NUM_PADDING 5 +#define DEFAULT_ARROW(SRC,DST) {(SRC),(DST),wxNullColour,1} +#define DEFAULT_SQUARE(SQUARE) {(SQUARE),wxNullColour} typedef std::tuple ClockTime; @@ -61,11 +63,20 @@ typedef struct AnimState { } AnimState; typedef struct GameState { + typedef struct Arrow { + std::string src,dst; + wxColour color=wxNullColour; + float scale=1; + } Arrow; + typedef struct Square { + std::string square; + wxColour color=wxNullColour; + } Square; std::string white, black; std::string board; std::map captures; - std::vector squares_hl; - std::vector arrows; + std::vector squares_hl; + std::vector arrows; bool is_black_turn; bool mat_black; bool mat_white; @@ -78,10 +89,11 @@ class BoardCanvas : public wxPanel { Theme *t, *t_captures; wxColour color_arrows; int arrows_offset; + std::uint8_t arrow_thickness; std::string white_player,black_player; // Current highlighted squares and arrows: - std::vector squares_hl; - std::vector arrows; + std::vector squares_hl; + std::vector arrows; // Various canvas state variables bool black_side, is_dragging, valid_drag, arrow_drag, is_black_turn; -- cgit v1.2.3