aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/left_panel
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-01 12:15:08 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-01 12:15:08 +0100
commit5607057ac33ce3b6933697134b20d7ef0b1a43be (patch)
tree7a295be61805c2c7b8fe7c1c69aba08f20db919c /src/game_tab/left_panel
parent1eb91c592627041749d5f66ff9edbb95253bc5f4 (diff)
Debug and clean the game tab code
Diffstat (limited to 'src/game_tab/left_panel')
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.cpp101
-rw-r--r--src/game_tab/left_panel/GameTabLeftPanel.hpp7
-rw-r--r--src/game_tab/left_panel/board/BoardCanvas.cpp3
-rw-r--r--src/game_tab/left_panel/board/BoardCanvas.hpp4
4 files changed, 44 insertions, 71 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(); }
diff --git a/src/game_tab/left_panel/GameTabLeftPanel.hpp b/src/game_tab/left_panel/GameTabLeftPanel.hpp
index 3adbaee..b22d6fc 100644
--- a/src/game_tab/left_panel/GameTabLeftPanel.hpp
+++ b/src/game_tab/left_panel/GameTabLeftPanel.hpp
@@ -8,11 +8,9 @@
// Foreign events
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
-
class GameTabLeftPanel : public TabGameLeftPanel {
std::shared_ptr<Game> game;
BoardCanvas *board_canvas;
- void NotifyEditor();
std::string last_absolute_move;
bool repeat;
@@ -21,11 +19,6 @@ public:
void Notify(bool animate=false,bool backward=false);
void OnPlay(wxCommandEvent &event);
void OnGotoMove(wxCommandEvent &event);
- void PreviousMove(bool isKeyDown);
- void NextMove(bool isKeyDown);
- void OnZoomIn(wxCommandEvent &event);
- void OnZoomOut(wxCommandEvent &event);
- void OnSwap(wxCommandEvent &event);
void OnRefreshBoard(wxCommandEvent &event);
void ApplyPreferences();
void DisableSaveTool(){game_toolbar->EnableTool(0,false);};
diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp
index 386d593..7f2c38d 100644
--- a/src/game_tab/left_panel/board/BoardCanvas.cpp
+++ b/src/game_tab/left_panel/board/BoardCanvas.cpp
@@ -19,7 +19,7 @@ BoardCanvas::BoardCanvas(wxFrame *parent)
adata.duration=200;
adata.duration_fast=80;
adata.fps=30;
-
+ // Let GameTableLeftPanel process keyboard events:
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();});
}
@@ -385,6 +385,7 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) {
}
}
}
+ // Let GameTableLeftPanel process mouse wheel events:
if (event.GetWheelRotation() != 0) {
event.ResumePropagation(1);event.Skip();
}
diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp
index 0ed18a7..30f0d06 100644
--- a/src/game_tab/left_panel/board/BoardCanvas.hpp
+++ b/src/game_tab/left_panel/board/BoardCanvas.hpp
@@ -12,10 +12,6 @@
// Local events
wxDECLARE_EVENT(PLAY_MOVE_EVENT, wxCommandEvent);
-// Foreign events
-wxDECLARE_EVENT(PREVIOUS_MOVE_EVENT, wxCommandEvent);
-wxDECLARE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent);
-
#define REFRESH_MOUSE_LOCATION() \
{ \
const wxPoint pt = wxGetMousePosition(); \