diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index b3b5a95..5a0c430 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -26,7 +26,7 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr game) void GameTabLeftPanel::OnPreviousMove(wxCommandEvent &event) { game->Previous(); - Notify(); + Notify(true); NotifyEditor(); } @@ -48,7 +48,7 @@ void GameTabLeftPanel::OnSwap(wxCommandEvent &event) { void GameTabLeftPanel::OnNextMove(wxCommandEvent &event) { wxLogDebug("Game tab received NEXT_MOVE_EVENT"); game->Next(); - Notify(); + Notify(true); NotifyEditor(); } @@ -59,26 +59,30 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) { } Notify(); - std::string fen = game->GetFen(); std::map captures; HalfMove *m = game->GetCurrentMove(); if (m != NULL) { captures = m->GetLineCaptures(); - } - /*board_canvas->Animate(chessarbiter::FENParser::Parse(fen).board, - game->IsBlackToPlay(), captures,"a1","a2"); */ + } } -void GameTabLeftPanel::Notify() { +void GameTabLeftPanel::Notify(bool animate) { std::string fen = game->GetFen(); std::map captures; HalfMove *m = game->GetCurrentMove(); if (m != NULL) { captures = m->GetLineCaptures(); - } - board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board, - game->IsBlackToPlay(), captures); + } + + if(!animate){ + 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"); + } fen_text_field->SetValue(game->GetFen()); } diff --git a/src/game_tab/left_panel/GameTabLeftPanel.hpp b/src/game_tab/left_panel/GameTabLeftPanel.hpp index 7aeb725..5a160d2 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.hpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.hpp @@ -15,7 +15,7 @@ class GameTabLeftPanel : public TabGameLeftPanel { public: GameTabLeftPanel(wxFrame *parent, std::shared_ptr game); - void Notify(); + void Notify(bool animate=false); void OnPlay(wxCommandEvent &event); void OnGotoMove(wxCommandEvent &event); void OnPreviousMove(wxCommandEvent &event); diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 18c7288..ab1e969 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -15,15 +15,11 @@ BoardCanvas::BoardCanvas(wxFrame *parent) ApplyPreferences(); // The following should be called when using an EVT_PAINT handler SetBackgroundStyle(wxBG_STYLE_PAINT); - timer.Bind(wxEVT_TIMER, &BoardCanvas::OnTimerTick, this); + timer.Bind(wxEVT_TIMER, [p=this](wxTimerEvent &e){p->Refresh();}); duration=500; fps=30; } -void BoardCanvas::OnTimerTick(wxTimerEvent &event) { - Refresh(); -} - BoardCanvas::~BoardCanvas() { delete t; delete t_captures; @@ -64,7 +60,9 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) { else { // Otherwise reuse buffer and animate. TEST CODE FOR NOW: dc.DrawBitmap(*buffer, 0, 0, true); - dc.DrawRectangle(wxRect(0+frame,0+frame,50,50)); + // Draw piece + dc.DrawBitmap(*t->Get(piece_moved), 0+frame, 0+frame, false); + // end drawing frame++; if(frame*fps>=duration){ timer.Stop(); @@ -105,6 +103,7 @@ void BoardCanvas::SetupBoard(std::string board, bool is_black_turn, } void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map captures, std::string src, std::string dst){ + return; // Shortcut this method for now this->final_board=board; this->final_is_black_turn=is_black_turn; this->final_captures=captures; @@ -113,7 +112,7 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::mapboard[(7 - pfile) + 8 * (7-prank)]; // Piece to move + this->piece_moved = this->board[(7 - pfile) + 8 * (7-prank)]; // Piece to move // Animate piece here reuseBuffer=true; frame=0; diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index c87f20e..9e375d1 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -67,6 +67,7 @@ class BoardCanvas : public wxPanel { std::map final_captures; std::string src; std::string dst; + char piece_moved; public: BoardCanvas(wxFrame *parent); @@ -79,7 +80,6 @@ public: void MouseEvent(wxMouseEvent &event); void Zoom(std::int32_t zoom); void Swap(); - void OnTimerTick(wxTimerEvent &event); void SetupBoard(std::string board, bool is_black_turn, std::map captures); void Animate(std::string board, bool is_black_turn, std::map captures, std::string src, std::string dst);