aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/right_panel/editor/EditorCanvas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_tab/right_panel/editor/EditorCanvas.cpp')
-rw-r--r--src/game_tab/right_panel/editor/EditorCanvas.cpp53
1 files changed, 18 insertions, 35 deletions
diff --git a/src/game_tab/right_panel/editor/EditorCanvas.cpp b/src/game_tab/right_panel/editor/EditorCanvas.cpp
index ae0c096..19d81ec 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) {
hide_icon = LoadPNG("hide", wxSize(CGEditor::status.MoveIconWidth,
CGEditor::status.MoveIconWidth));
t.ResizePieces(CGEditor::status.MoveIconWidth);
@@ -14,13 +14,17 @@ EditorCanvas::EditorCanvas(wxFrame *parent)
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 = &current_dc;
// Refresh canvas size
@@ -173,28 +177,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) {
@@ -220,10 +214,11 @@ void EditorCanvas::MouseEvent(wxMouseEvent &event) {
Refresh();
}
- // Should another draw of CGEditor be made?
- if (NeedRedraw) {
+ // Handle editor events
+ Update();
+ if(ProcessEvents()){
Refresh();
- NeedRedraw = false;
+ Update();
}
}
@@ -234,17 +229,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()