diff options
Diffstat (limited to 'src/game_tab/left_panel/GameTabLeftPanel.cpp')
| -rw-r--r-- | src/game_tab/left_panel/GameTabLeftPanel.cpp | 101 |
1 files changed, 42 insertions, 59 deletions
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index 70a09cd..50919c0 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -4,7 +4,7 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game) : TabGameLeftPanel(parent), game(game), repeat(false) { - // Configure toolbal + // Configure toolbar (note that toolbar events are processed into the GameTab class) game_toolbar->AddTool(0, wxT("Save As"), wxArtProvider::GetBitmap(wxART_FILE_SAVE, wxART_TOOLBAR)); game_toolbar->AddTool(1, wxT("Duplicate Game"), @@ -22,70 +22,57 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game) // Configure FEN field fen_text_field->SetFont(wxFont(*wxNORMAL_FONT).Bold().Larger()); + // Bind events: Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY); - Bind(wxEVT_BUTTON, &GameTabLeftPanel::OnSwap, this, SWAP_BTN); - Bind(wxEVT_BUTTON, &GameTabLeftPanel::OnZoomIn, this, ZOOM_IN_BTN); - Bind(wxEVT_BUTTON, &GameTabLeftPanel::OnZoomOut, this, ZOOM_OUT_BTN); - 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 GameTabLeftPanel::PreviousMove(bool isKeyDown) { - if(isKeyDown){ - game->Previous(); - Notify(true,true); - repeat=true; - } else { - repeat=false; - } -} - -void GameTabLeftPanel::NextMove(bool isKeyDown) { - if(isKeyDown){ - game->Next(); - Notify(true,false); - repeat=true; - } - else{ - repeat=false; - } -} - -void GameTabLeftPanel::OnZoomIn(wxCommandEvent &event) { - wxLogDebug("Clicked on zoom in"); - board_canvas->Zoom(10); -} - -void GameTabLeftPanel::OnZoomOut(wxCommandEvent &event) { - wxLogDebug("Clicked on zoom out"); - board_canvas->Zoom(-10); -} - -void GameTabLeftPanel::OnSwap(wxCommandEvent &event) { - wxLogDebug("Clicked on swap"); - board_canvas->Swap(); + Bind(wxEVT_BUTTON, [bc=board_canvas](wxCommandEvent &event){bc->Zoom(10);}, ZOOM_IN_BTN); + Bind(wxEVT_BUTTON, [bc=board_canvas](wxCommandEvent &event){bc->Zoom(-10);}, ZOOM_OUT_BTN); + Bind(wxEVT_BUTTON, [bc=board_canvas](wxCommandEvent &event){bc->Swap();}, SWAP_BTN); + Bind(wxEVT_KEY_UP, [p=this](wxKeyEvent &e){p->repeat=false;}); + Bind(wxEVT_KEY_DOWN, [p=this](wxKeyEvent &e){ + if(e.GetKeyCode() == WXK_RIGHT){ + p->game->Next(); + p->Notify(true,false); + p->repeat=true; + } else if(e.GetKeyCode() == WXK_LEFT){ + p->game->Previous(); + p->Notify(true,true); + p->repeat=true; + } + // Notify other classes + wxCommandEvent event(GAME_CHANGE, p->GetId()); + event.SetEventObject(p); + p->ProcessEvent(event); + }); + Bind(wxEVT_MOUSEWHEEL, [p=this](wxMouseEvent& e){ + if(e.GetWheelRotation()<0){ + p->game->Next(); + p->Notify(true,false); + }else { + p->game->Previous(); + p->Notify(true,true); + } + // Notify other classes + wxCommandEvent event(GAME_CHANGE, p->GetId()); + event.SetEventObject(p); + p->ProcessEvent(event); + }); } - void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { wxLogDebug("Game tab received PLAY_MOVE_EVENT"); if (game->Play(event.GetString().ToStdString())) { - NotifyEditor(); + // Notify other classes + wxCommandEvent event(GAME_CHANGE, GetId()); + event.SetEventObject(this); + ProcessEvent(event); } + // Refresh board canvas: Notify(); - - std::string fen = game->GetFen(); - std::map<char, std::uint8_t> captures; - HalfMove *m = game->GetCurrentMove(); - if (m != nullptr) { - captures = m->GetLineCaptures(); - } } void GameTabLeftPanel::Notify(bool animate, bool backward) { + // Update fen and captures std::string fen = game->GetFen(); std::map<char, std::uint8_t> captures; HalfMove *m = game->GetCurrentMove(); @@ -93,6 +80,7 @@ void GameTabLeftPanel::Notify(bool animate, bool backward) { captures = m->GetLineCaptures(); } + // Update board canvas: if(!animate){ if(m){ last_absolute_move=m->GetAbsoluteMove(); @@ -127,13 +115,8 @@ void GameTabLeftPanel::Notify(bool animate, bool backward) { } } + // Update fen field: fen_text_field->SetValue(game->GetFen()); } -void GameTabLeftPanel::NotifyEditor() { - wxCommandEvent previousEvent(GAME_CHANGE, GetId()); - previousEvent.SetEventObject(this); - ProcessEvent(previousEvent); -} - void GameTabLeftPanel::ApplyPreferences() { board_canvas->ApplyPreferences(); } |
