diff options
Diffstat (limited to 'examples/wxWidgets/main.cpp')
| -rw-r--r-- | examples/wxWidgets/main.cpp | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/examples/wxWidgets/main.cpp b/examples/wxWidgets/main.cpp index 9f35981..78fa38c 100644 --- a/examples/wxWidgets/main.cpp +++ b/examples/wxWidgets/main.cpp @@ -10,19 +10,22 @@ * @brief CGEditor Window * */ -class MyFrame : public wxFrame, public cgeditor::CGEditor { +class EditorPanel : public wxPanel, public cgeditor::CGEditor { wxPaintDC *dc; - + /// @brief Used to test focus: + CMI::HalfMove *toFocus; public: - MyFrame() - : wxFrame(NULL, wxID_ANY, "Hello World CGEditor"), CGEditor(), dc(NULL) { - CreateStatusBar(); - SetStatusText("CGEditor"); + EditorPanel(wxWindow *parent) + : wxPanel(parent), CGEditor(), dc(NULL) { // Create a game CGEditor::status.Moves = BuildExampleGame(); + // Set move to focus to the last move (downest move in the window!): + toFocus= CGEditor::status.Moves; + while(toFocus->GetMainline()!=nullptr){ + toFocus=toFocus->GetMainline(); + } } -private: void OnExit(wxCommandEvent &event) { (void)event; // Disable unused variable warning Close(true); } @@ -81,6 +84,19 @@ private: } } + void KeyboardEvent(wxKeyEvent& event){ + switch ( event.GetKeyCode() ) + { + case WXK_DOWN: + CGEditor::FocusOnMove(toFocus); + Refresh(); + if(toFocus->GetParent()!=nullptr){ + toFocus=toFocus->GetParent(); // Get previous move (not that it can be on the same line!) + } + break; + } + } + /** * @brief Convenient fonction to center text * @@ -191,15 +207,30 @@ private: DECLARE_EVENT_TABLE() }; -wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) -EVT_PAINT(MyFrame::OnPaint) -EVT_MOUSE_EVENTS(MyFrame::MouseEvent) +wxBEGIN_EVENT_TABLE(EditorPanel, wxPanel) +EVT_PAINT(EditorPanel::OnPaint) +EVT_MOUSE_EVENTS(EditorPanel::MouseEvent) +EVT_KEY_DOWN(EditorPanel::KeyboardEvent) wxEND_EVENT_TABLE() + +class MainWindow: public wxFrame +{ + wxPanel* editorPane; +public: + + MainWindow(const wxString& title):wxFrame(NULL, wxID_ANY, title){ + CreateStatusBar(); + SetStatusText("CGEditor"); + editorPane = new EditorPanel(this); + } + +}; + class MyApp : public wxApp { public: virtual bool OnInit() { - MyFrame *frame = new MyFrame(); + MainWindow *frame = new MainWindow("Hello World CGEditor"); frame->Show(true); return true; } |
