diff options
Diffstat (limited to 'src/game_tab/left_panel/GameTabLeftPanel.cpp')
| -rw-r--r-- | src/game_tab/left_panel/GameTabLeftPanel.cpp | 67 |
1 files changed, 52 insertions, 15 deletions
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index 5a0c430..cd3bfe4 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -17,17 +17,33 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game) fen_text_field->SetFont(wxFont(*wxNORMAL_FONT).Bold().Larger()); Bind(PLAY_MOVE_EVENT, &GameTabLeftPanel::OnPlay, this, wxID_ANY); - Bind(PREVIOUS_MOVE_EVENT, &GameTabLeftPanel::OnPreviousMove, this, wxID_ANY); - Bind(NEXT_MOVE_EVENT, &GameTabLeftPanel::OnNextMove, 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();}); + repeat=false; } -void GameTabLeftPanel::OnPreviousMove(wxCommandEvent &event) { - game->Previous(); - Notify(true); - NotifyEditor(); +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) { @@ -45,12 +61,7 @@ void GameTabLeftPanel::OnSwap(wxCommandEvent &event) { board_canvas->Swap(); } -void GameTabLeftPanel::OnNextMove(wxCommandEvent &event) { - wxLogDebug("Game tab received NEXT_MOVE_EVENT"); - game->Next(); - Notify(true); - NotifyEditor(); -} + void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { wxLogDebug("Game tab received PLAY_MOVE_EVENT"); @@ -67,7 +78,8 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { } } -void GameTabLeftPanel::Notify(bool animate) { +void GameTabLeftPanel::Notify(bool animate, bool backward) { + wxLogDebug("Notify"); std::string fen = game->GetFen(); std::map<char, std::uint8_t> captures; HalfMove *m = game->GetCurrentMove(); @@ -76,12 +88,37 @@ void GameTabLeftPanel::Notify(bool animate) { } if(!animate){ + if(m){ + last_absolute_move=m->GetAbsoluteMove(); + } board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board, game->IsBlackToPlay(), captures); } else{ - board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board, - game->IsBlackToPlay(), captures,"a1","a2"); + if(backward && last_absolute_move.size()>0){ + std::string dst=last_absolute_move.substr(0,2); + std::string src=last_absolute_move.substr(2,2); + board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board, + game->IsBlackToPlay(), captures,src,dst,repeat); + if(m){ + last_absolute_move=m->GetAbsoluteMove(); + } + } + else if(!backward && m){ + std::string new_absolute_move=m->GetAbsoluteMove(); + if(last_absolute_move!=new_absolute_move){ + last_absolute_move=new_absolute_move; + std::string src=last_absolute_move.substr(0,2); + std::string dst=last_absolute_move.substr(2,2); + board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board, + game->IsBlackToPlay(), captures,src,dst,repeat); + } + } + + // If m undefined + if(!m){ + last_absolute_move=""; + } } fen_text_field->SetValue(game->GetFen()); |
