From f1a54fd165251b1f2296f5845d31198f9b0198d9 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 9 Jan 2023 09:55:20 +0100 Subject: [PATCH] Improve arrow drawing --- src/game_tab/left_panel/board/BoardCanvas.cpp | 23 ++++++++++++++++--- src/game_tab/left_panel/board/BoardCanvas.hpp | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index aab3c45..a31b0c6 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -13,9 +13,11 @@ wxDEFINE_EVENT(PLAY_MOVE_EVENT, wxCommandEvent); BoardCanvas::BoardCanvas(wxFrame *parent) : wxPanel(parent), black_side(false), frozen(false), lock_square_size(false), t(new Theme()), t_captures(new Theme()) { + color_arrows=wxColour(145, 233, 255); is_dragging = false; valid_drag = false; valid_arrow = false; + arrows_offset = t->GetSquaresSizes()/2.5; // Init animation data adata.duration=100; adata.duration_fast=100; @@ -409,6 +411,7 @@ void BoardCanvas::DrawBoard(wxDC &dc) { std::uint32_t dx = boardX + (7 - dfile) * square_width + square_width/2; std::uint32_t dy = boardY + drank * square_width + square_width/2; + 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){ @@ -538,6 +541,14 @@ void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){ double angle=acos(vect.x/length); angle= (vect.y>0) ? angle=angle : -angle; + // Translate starting point (xsrc,ysrc) about arrows_offset px to not start on the center of the square (less confusing visually) + double k=arrows_offset/length; + xsrc=xsrc+(xdst-xsrc)*k; + ysrc=ysrc+(ydst-ysrc)*k; + vect.x=(xdst-xsrc); + vect.y=(ydst-ysrc); + length=ceil(sqrt(pow(vect.x,2)+pow(vect.y,2))); + // Compute metrics std::uint8_t thickness=50; std::uint8_t tip_height=sqrt(3)/2*thickness; @@ -557,7 +568,6 @@ void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){ // Draw dc.SetPen(wxNullPen); - dc.SetBrush(wxColour(255,0,0)); dc.DrawPolygon(3,tip); dc.DrawPolygon(4,tail); } @@ -572,6 +582,15 @@ void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, b return; } + // Translate starting point (xsrc,ysrc) about arrows_offset px to not start on the center of the square (less confusing visually) + if(!flip) + xsrc+= (xdst-xsrc) > 0 ? arrows_offset : -arrows_offset; + else + ysrc+= (ydst-ysrc) > 0 ? arrows_offset : -arrows_offset; + X=xdst-xsrc; + Y=ydst-ysrc; + + // Draw L shaped arrows if(flip){ // Compute metrics std::uint8_t thickness=50; @@ -589,7 +608,6 @@ void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, b // Draw dc.SetPen(wxNullPen); - dc.SetBrush(wxColour(255,0,0)); dc.DrawPolygon(4,tail1); dc.DrawPolygon(4,tail2); dc.DrawPolygon(3,tip); @@ -610,7 +628,6 @@ void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, b // Draw dc.SetPen(wxNullPen); - dc.SetBrush(wxColour(255,0,0)); dc.DrawPolygon(4,tail1); dc.DrawPolygon(4,tail2); dc.DrawPolygon(3,tip); diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index 24c469c..f387c22 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -76,6 +76,8 @@ class BoardCanvas : public wxPanel { // *t is theme for board+pieces and // *t_captures is theme for captured pieces (scale down version of t) Theme *t, *t_captures; + wxColour color_arrows; + int arrows_offset; // Board to draw (char version) std::string board; std::string white_player,black_player;