mirror of
https://gitlab.com/manzerbredes/cgeditor.git
synced 2025-05-06 19:43:57 +00:00
Introduce move based focusing
This commit is contained in:
parent
298714449a
commit
2a4a20beef
7 changed files with 100 additions and 12 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue