aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-09 18:38:19 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-09 18:38:19 +0100
commitd6ed30d276d0e2688051ed8d6fe542a331e5ac90 (patch)
tree67bb2e67103451d5bb012956196b9bd8cade04ea
parentf4108bc06cd9fa1977267836e9176118e8863b57 (diff)
Improve engine arrows
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.cpp8
-rw-r--r--src/game_tab/left_panel/board/BoardCanvas.cpp36
-rw-r--r--src/game_tab/left_panel/board/BoardCanvas.hpp4
-rw-r--r--src/game_tab/right_panel/LiveEngineDialog.cpp6
4 files changed, 41 insertions, 13 deletions
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp
index c7be112..3304904 100644
--- a/src/game_tab/left_panel/GameTabLeftPanel.cpp
+++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp
@@ -73,6 +73,14 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
void GameTabLeftPanel::SetEngineArrows(std::vector<std::string> arrows){
engine_arrows=arrows;
+ int min_size=5, max_size=80;
+ int steps=(max_size-min_size)/arrows.size();
+ int current_size=max_size;
+ for(std::string &arrow:engine_arrows){
+ wxLogDebug("%s",arrow);
+ arrow+="#000000%"+std::to_string(current_size);
+ current_size-=steps;
+ }
Notify(true);
}
diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp
index 0593cde..9c80196 100644
--- a/src/game_tab/left_panel/board/BoardCanvas.cpp
+++ b/src/game_tab/left_panel/board/BoardCanvas.cpp
@@ -413,17 +413,38 @@ 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);
+ // 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
+ 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);
+ DrawLArrow(dc,sx,sy,dx,dy,false,thickness);
}
else {
- DrawLArrow(dc,sx,sy,dx,dy,true);
+ DrawLArrow(dc,sx,sy,dx,dy,true,thickness);
}
} else {
- DrawArrow(dc,sx,sy,dx,dy);
+ DrawArrow(dc,sx,sy,dx,dy,thickness);
}
}
}
@@ -544,7 +565,7 @@ void BoardCanvas::SetClockTime(short hours, short min, short sec,
}
}
-void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
+void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, std::uint8_t thickness){
// Compute arrow length and angle
wxPoint vect(xdst-xsrc,ydst-ysrc);
double length=ceil(sqrt(pow(vect.x,2)+pow(vect.y,2)));
@@ -560,7 +581,6 @@ void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
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;
std::uint32_t tail_length=length-tip_height;
@@ -582,7 +602,7 @@ void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
dc.DrawPolygon(4,tail);
}
-void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip){
+void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip, std::uint8_t thickness){
double X=xdst-xsrc;
double Y=ydst-ysrc;
@@ -603,7 +623,6 @@ void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, b
// Draw L shaped arrows
if(flip){
// Compute metrics
- std::uint8_t thickness=50;
double tip_height=sqrt(3)/2*thickness;
double yoffset=Y<0 ? -thickness/4 : thickness/4; // Y tail should be longer to form a right angle (corner of tail joins)
if(X<0){tip_height=-tip_height;}
@@ -623,7 +642,6 @@ void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, b
dc.DrawPolygon(3,tip);
} else {
// Compute metrics
- std::uint8_t thickness=50;
double tip_height=sqrt(3)/2*thickness;
double xoffset=X<0 ? -thickness/4 : thickness/4; // Y tail should be longer to form a right angle (corner of tail joins)
if(Y<0){tip_height=-tip_height;}
diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp
index a764fee..553994c 100644
--- a/src/game_tab/left_panel/board/BoardCanvas.hpp
+++ b/src/game_tab/left_panel/board/BoardCanvas.hpp
@@ -97,9 +97,9 @@ class BoardCanvas : public wxPanel {
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);
+ void DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, std::uint8_t thickness=50);
/// @brief Draw an arrow with a L shape (such as knight moves)
- void DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip=false);
+ void DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip=false, std::uint8_t thickness=50);
public:
BoardCanvas(wxFrame *parent);
diff --git a/src/game_tab/right_panel/LiveEngineDialog.cpp b/src/game_tab/right_panel/LiveEngineDialog.cpp
index 347c32e..0c2ecfc 100644
--- a/src/game_tab/right_panel/LiveEngineDialog.cpp
+++ b/src/game_tab/right_panel/LiveEngineDialog.cpp
@@ -105,14 +105,16 @@ void LiveEngineDialog::OnTimerTick(wxTimerEvent &event) {
lines_list->DeleteAllItems();
engine->SyncAfter(0);
EngineEvaluation *eval=new EngineEvaluation();
- for (auto const &line : engine->GetLines()) {
+ auto const &lines=engine->GetLines();
+ eval->best_lines.resize(lines.size());
+ for (auto const &line : lines) {
long index = lines_list->InsertItem(0, std::to_string(line.first));
std::string line_moves;
for (std::string move : line.second.pv) {
line_moves += move + " ";
}
if(line.second.pv.size()>0){
- eval->best_lines.push_back(line.second.pv[0]);
+ eval->best_lines.insert(eval->best_lines.begin()+line.first,line.second.pv[0]);
}
std::string cp_str = std::to_string(line.second.score_cp);
if (line.second.score_cp > 0) {