aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/right_panel/editor
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-01 14:12:57 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-01 14:12:57 +0100
commit679c735596168228ad0df4e42a3768c61c809a40 (patch)
treeacec93ad61c3ba26a997a3835079c48fcf911d72 /src/game_tab/right_panel/editor
parent8bf9e7e7b5b963b8be3916c4926e9cade3064eb8 (diff)
Improve game tab
Diffstat (limited to 'src/game_tab/right_panel/editor')
-rw-r--r--src/game_tab/right_panel/editor/EditorCanvas.cpp40
-rw-r--r--src/game_tab/right_panel/editor/EditorCanvas.hpp12
2 files changed, 13 insertions, 39 deletions
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> 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()
diff --git a/src/game_tab/right_panel/editor/EditorCanvas.hpp b/src/game_tab/right_panel/editor/EditorCanvas.hpp
index 05d6258..7ee56d3 100644
--- a/src/game_tab/right_panel/editor/EditorCanvas.hpp
+++ b/src/game_tab/right_panel/editor/EditorCanvas.hpp
@@ -4,14 +4,10 @@
#include "CGEditor.hpp"
#include "ochess.hpp"
#include "../../left_panel/board/Theme.hpp"
+#include "game_tab/Game.hpp"
// Foreign events
-wxDECLARE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent);
-wxDECLARE_EVENT(PREVIOUS_MOVE_EVENT, wxCommandEvent);
-wxDECLARE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent);
-wxDECLARE_EVENT(DELETE_MOVE_EVENT, wxCommandEvent);
-wxDECLARE_EVENT(PROMOTE_MOVE_EVENT, wxCommandEvent);
-wxDECLARE_EVENT(SET_AS_MAINLINE_EVENT, wxCommandEvent);
+wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
class EditorCanvas : public wxPanel, public cgeditor::CGEditor {
wxPaintDC *dc;
@@ -20,6 +16,7 @@ class EditorCanvas : public wxPanel, public cgeditor::CGEditor {
wxBitmap hide_icon;
Theme t;
wxFont default_font;
+ std::shared_ptr<Game> game;
wxColour color_scrollbar_bg;
wxColour color_scrollbar;
@@ -29,13 +26,12 @@ class EditorCanvas : public wxPanel, public cgeditor::CGEditor {
wxColour color_menu_item_bg;
public:
- EditorCanvas(wxFrame *parent);
+ EditorCanvas(wxFrame *parent, std::shared_ptr<Game> game);
void OnPaint(wxPaintEvent &event);
void MouseEvent(wxMouseEvent &event);
void DrawElement(const cgeditor::Element &e);
void HandleEvent(const cgeditor::Event &e);
void SetMoves(HalfMove *moves, HalfMove *current);
- void OnKeyEvent(wxKeyEvent &event);
DECLARE_EVENT_TABLE()
};