From 679c735596168228ad0df4e42a3768c61c809a40 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 14:12:57 +0100 Subject: Improve game tab --- src/game_tab/right_panel/editor/EditorCanvas.cpp | 40 ++++++------------------ 1 file changed, 9 insertions(+), 31 deletions(-) (limited to 'src/game_tab/right_panel/editor/EditorCanvas.cpp') diff --git a/src/game_tab/right_panel/editor/EditorCanvas.cpp b/src/game_tab/right_panel/editor/EditorCanvas.cpp index ae0c096..8a1c745 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.cpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.cpp @@ -1,7 +1,7 @@ #include "EditorCanvas.hpp" -EditorCanvas::EditorCanvas(wxFrame *parent) - : wxPanel(parent), NeedRedraw(false) { +EditorCanvas::EditorCanvas(wxFrame *parent, std::shared_ptr game) + : wxPanel(parent), game(game), NeedRedraw(false) { hide_icon = LoadPNG("hide", wxSize(CGEditor::status.MoveIconWidth, CGEditor::status.MoveIconWidth)); t.ResizePieces(CGEditor::status.MoveIconWidth); @@ -173,28 +173,18 @@ void EditorCanvas::DrawElement(const cgeditor::Element &e) { } } void EditorCanvas::HandleEvent(const cgeditor::Event &e) { - wxLogDebug("Editor event!"); if (e.type == cgeditor::Event::Goto) { - wxCommandEvent event(GOTO_MOVE_EVENT, GetId()); - event.SetEventObject(this); - event.SetClientData(e.move); - ProcessEvent(event); + game->SetCurrent((HalfMove *)e.move); } else if (e.type == cgeditor::Event::Delete) { - wxCommandEvent event(DELETE_MOVE_EVENT, GetId()); - event.SetEventObject(this); - event.SetClientData(e.move); - ProcessEvent(event); + game->DeleteMove((HalfMove *)e.move); } else if (e.type == cgeditor::Event::Promote) { - wxCommandEvent event(PROMOTE_MOVE_EVENT, GetId()); - event.SetEventObject(this); - event.SetClientData(e.move); - ProcessEvent(event); + game->PromoteMove((HalfMove *)e.move); } else if (e.type == cgeditor::Event::SetAsMainline) { - wxCommandEvent event(SET_AS_MAINLINE_EVENT, GetId()); - event.SetEventObject(this); - event.SetClientData(e.move); - ProcessEvent(event); + game->SetMoveAsMainline((HalfMove *)e.move); } + wxCommandEvent event(GAME_CHANGE, GetId()); + event.SetEventObject(this); + ProcessEvent(event); } void EditorCanvas::MouseEvent(wxMouseEvent &event) { @@ -234,17 +224,5 @@ void EditorCanvas::SetMoves(HalfMove *moves, HalfMove *current) { Refresh(); } -void EditorCanvas::OnKeyEvent(wxKeyEvent &event) { - /*if (event.GetKeyCode() == WXK_LEFT) { - wxCommandEvent previousEvent(PREVIOUS_MOVE_EVENT, GetId()); - previousEvent.SetEventObject(this); - ProcessEvent(previousEvent); - } else if (event.GetKeyCode() == WXK_RIGHT) { - wxCommandEvent nextEvent(NEXT_MOVE_EVENT, GetId()); - nextEvent.SetEventObject(this); - ProcessEvent(nextEvent); - }*/ -} - wxBEGIN_EVENT_TABLE(EditorCanvas, wxPanel) EVT_PAINT(EditorCanvas::OnPaint) EVT_MOUSE_EVENTS(EditorCanvas::MouseEvent) wxEND_EVENT_TABLE() -- cgit v1.2.3 From 88430eec2951290633875b0f036a33bbc6ee60a2 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 17:30:55 +0100 Subject: Improve editor drawing loop --- libs/cgeditor | 2 +- src/game_tab/right_panel/editor/EditorCanvas.cpp | 15 +++++++++++---- src/game_tab/right_panel/editor/EditorCanvas.hpp | 1 - 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/game_tab/right_panel/editor/EditorCanvas.cpp') diff --git a/libs/cgeditor b/libs/cgeditor index 3271972..31c332d 160000 --- a/libs/cgeditor +++ b/libs/cgeditor @@ -1 +1 @@ -Subproject commit 3271972f9eef3069bf80de8be4c057102fff1138 +Subproject commit 31c332da9ab426daa73b68772d0ef9c1b0744a50 diff --git a/src/game_tab/right_panel/editor/EditorCanvas.cpp b/src/game_tab/right_panel/editor/EditorCanvas.cpp index 8a1c745..3856102 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.cpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.cpp @@ -1,7 +1,7 @@ #include "EditorCanvas.hpp" EditorCanvas::EditorCanvas(wxFrame *parent, std::shared_ptr game) - : wxPanel(parent), game(game), NeedRedraw(false) { + : wxPanel(parent), game(game) { hide_icon = LoadPNG("hide", wxSize(CGEditor::status.MoveIconWidth, CGEditor::status.MoveIconWidth)); t.ResizePieces(CGEditor::status.MoveIconWidth); @@ -210,10 +210,17 @@ void EditorCanvas::MouseEvent(wxMouseEvent &event) { Refresh(); } - // Should another draw of CGEditor be made? - if (NeedRedraw) { + // Handle editor events + Update(); + bool need_redraw=false; + for(auto event: status.Events){ + HandleEvent(event); + need_redraw=true; + } + if(need_redraw){ + status.Events.clear(); Refresh(); - NeedRedraw = false; + Update(); } } diff --git a/src/game_tab/right_panel/editor/EditorCanvas.hpp b/src/game_tab/right_panel/editor/EditorCanvas.hpp index 7ee56d3..740a6a1 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.hpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.hpp @@ -11,7 +11,6 @@ wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent); class EditorCanvas : public wxPanel, public cgeditor::CGEditor { wxPaintDC *dc; - bool NeedRedraw; wxPoint Middle(cgeditor::Element e); wxBitmap hide_icon; Theme t; -- cgit v1.2.3 From dd24427d81d04765cbe3426b511b1ad05952d087 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 1 Jan 2023 20:28:39 +0100 Subject: Debug drawing canvas --- src/game_tab/left_panel/board/BoardCanvas.cpp | 2 +- src/game_tab/left_panel/board/Theme.cpp | 2 ++ src/game_tab/right_panel/editor/EditorCanvas.cpp | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/game_tab/right_panel/editor/EditorCanvas.cpp') diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 5297250..0e44979 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -16,7 +16,7 @@ BoardCanvas::BoardCanvas(wxFrame *parent) ApplyPreferences(); // The following should be called when using an EVT_PAINT handler SetBackgroundStyle(wxBG_STYLE_PAINT); - adata.duration=5000; + adata.duration=200; adata.duration_fast=80; adata.fps=30; adata.buffer=new wxBitmap(500,500,32); diff --git a/src/game_tab/left_panel/board/Theme.cpp b/src/game_tab/left_panel/board/Theme.cpp index 0c05fa1..6c662dc 100644 --- a/src/game_tab/left_panel/board/Theme.cpp +++ b/src/game_tab/left_panel/board/Theme.cpp @@ -134,6 +134,8 @@ bool Theme::Zoom(int amount) { double width = skin_scaled['s']->GetWidth() + amount; if(width<=20) return false; + if(width>=180) + return false; ResizeSquares(std::max(width, 1.0)); ResizePieces(std::max(width * PIECE_SIZE_FACTOR, 1.0)); return true; diff --git a/src/game_tab/right_panel/editor/EditorCanvas.cpp b/src/game_tab/right_panel/editor/EditorCanvas.cpp index 3856102..5a0afd0 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.cpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.cpp @@ -14,13 +14,17 @@ EditorCanvas::EditorCanvas(wxFrame *parent, std::shared_ptr game) color_comments_bg=wxColour(255, 255, 204); color_current_move_bg=wxColour(216, 216, 216); color_menu_item_bg=wxColour(216, 216, 216); - + // The following should be called when using an EVT_PAINT handler + SetBackgroundStyle(wxBG_STYLE_PAINT); + Bind(wxEVT_KEY_DOWN, [p=this](wxKeyEvent &e){e.ResumePropagation(1);e.Skip();}); Bind(wxEVT_KEY_UP, [p=this](wxKeyEvent &e){e.ResumePropagation(1);e.Skip();}); } void EditorCanvas::OnPaint(wxPaintEvent &event) { wxPaintDC current_dc(this); + current_dc.SetBackground(*wxWHITE_BRUSH); + current_dc.Clear(); dc = ¤t_dc; // Refresh canvas size -- cgit v1.2.3 From 4f2c68de6013bab307b299cfd6158225475a3fc6 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 2 Jan 2023 08:15:51 +0100 Subject: Update CGEditor+debug --- libs/cgeditor | 2 +- src/game_tab/left_panel/GameTabLeftPanel.cpp | 2 +- src/game_tab/right_panel/editor/EditorCanvas.cpp | 8 +------- 3 files changed, 3 insertions(+), 9 deletions(-) (limited to 'src/game_tab/right_panel/editor/EditorCanvas.cpp') diff --git a/libs/cgeditor b/libs/cgeditor index 31c332d..5e18d43 160000 --- a/libs/cgeditor +++ b/libs/cgeditor @@ -1 +1 @@ -Subproject commit 31c332da9ab426daa73b68772d0ef9c1b0744a50 +Subproject commit 5e18d43a6ba4fd378178418de6b2ca7a67d64c21 diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index fd89791..fa97f6f 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -63,12 +63,12 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr game) void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { wxLogDebug("Game tab received PLAY_MOVE_EVENT"); if (game->Play(event.GetString().ToStdString())) { - Notify(true); // Notify other classes wxCommandEvent event(GAME_CHANGE, GetId()); event.SetEventObject(this); ProcessEvent(event); } + Notify(true); // Redraw event is move failed! Otherwise piece not resets to it initial position after dragging } void GameTabLeftPanel::Notify(bool skip_animation) { diff --git a/src/game_tab/right_panel/editor/EditorCanvas.cpp b/src/game_tab/right_panel/editor/EditorCanvas.cpp index 5a0afd0..19d81ec 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.cpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.cpp @@ -216,13 +216,7 @@ void EditorCanvas::MouseEvent(wxMouseEvent &event) { // Handle editor events Update(); - bool need_redraw=false; - for(auto event: status.Events){ - HandleEvent(event); - need_redraw=true; - } - if(need_redraw){ - status.Events.clear(); + if(ProcessEvents()){ Refresh(); Update(); } -- cgit v1.2.3