2022-02-28 13:44:27 +01:00
|
|
|
#include "GameTabLeftPanel.hpp"
|
2022-02-23 18:11:55 +01:00
|
|
|
#include <wx/clipbrd.h>
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, Game *game)
|
2022-02-23 18:11:55 +01:00
|
|
|
: wxPanel(parent), game(game) {
|
|
|
|
|
|
|
|
wxBoxSizer *board_panel_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
board_canvas = new BoardCanvas((wxFrame *)this);
|
|
|
|
board_panel_sizer->Add(board_canvas, 1, wxEXPAND);
|
|
|
|
|
|
|
|
// Left Panel buttons
|
|
|
|
wxBoxSizer *board_panel_button_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
board_panel_button_sizer->Add(
|
|
|
|
new wxBitmapButton(this, SWAP_BTN, LoadPNG("swap")), 0);
|
|
|
|
board_panel_button_sizer->Add(
|
|
|
|
new wxBitmapButton(this, ZOOM_IN_BTN, LoadPNG("zoomin")), 0);
|
|
|
|
board_panel_button_sizer->Add(
|
|
|
|
new wxBitmapButton(this, ZOOM_OUT_BTN, LoadPNG("zoomout")), 0);
|
|
|
|
board_panel_button_sizer->Add(new wxButton(this, COPY_FEN_BTN, L"Copy FEN"),
|
|
|
|
0, wxEXPAND);
|
|
|
|
board_panel_sizer->Add(board_panel_button_sizer, 0);
|
|
|
|
this->SetSizer(board_panel_sizer);
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
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_BUTTON, &GameTabLeftPanel::OnCopyFEN, this, COPY_FEN_BTN);
|
2022-02-23 18:11:55 +01:00
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::OnPreviousMove(wxCommandEvent &event) {
|
2022-02-23 18:11:55 +01:00
|
|
|
game->Previous();
|
|
|
|
Notify();
|
|
|
|
NotifyEditor();
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::OnZoomIn(wxCommandEvent &event) {
|
2022-02-23 18:11:55 +01:00
|
|
|
wxLogDebug("Clicked on zoom in");
|
|
|
|
board_canvas->Zoom(10);
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::OnZoomOut(wxCommandEvent &event) {
|
2022-02-23 18:11:55 +01:00
|
|
|
wxLogDebug("Clicked on zoom out");
|
|
|
|
board_canvas->Zoom(-10);
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::OnSwap(wxCommandEvent &event) {
|
2022-02-23 18:11:55 +01:00
|
|
|
wxLogDebug("Clicked on swap");
|
|
|
|
board_canvas->Swap();
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::OnNextMove(wxCommandEvent &event) {
|
2022-02-23 18:11:55 +01:00
|
|
|
wxLogDebug("Game tab received NEXT_MOVE_EVENT");
|
|
|
|
game->Next();
|
|
|
|
Notify();
|
|
|
|
NotifyEditor();
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
|
2022-02-23 18:11:55 +01:00
|
|
|
wxLogDebug("Game tab received PLAY_MOVE_EVENT");
|
|
|
|
if (game->Play(event.GetString().ToStdString())) {
|
|
|
|
NotifyEditor();
|
|
|
|
}
|
|
|
|
Notify();
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::OnCopyFEN(wxCommandEvent &event) {
|
2022-02-23 18:11:55 +01:00
|
|
|
wxLogDebug("Clicked on copy fen");
|
|
|
|
if (wxTheClipboard->Open()) {
|
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(game->GetFen()));
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::Notify() {
|
2022-02-23 18:11:55 +01:00
|
|
|
std::string fen = game->GetFen();
|
|
|
|
std::map<char, std::uint8_t> captures;
|
|
|
|
HalfMove *m = game->GetCurrentMove();
|
|
|
|
if (m != NULL) {
|
|
|
|
captures = m->GetLineCaptures();
|
|
|
|
}
|
|
|
|
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
|
|
|
game->IsBlackToPlay(), captures);
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::NotifyEditor() {
|
2022-02-23 18:11:55 +01:00
|
|
|
wxCommandEvent previousEvent(GAME_CHANGE, GetId());
|
|
|
|
previousEvent.SetEventObject(this);
|
|
|
|
ProcessEvent(previousEvent);
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:44:27 +01:00
|
|
|
void GameTabLeftPanel::ApplyPreferences() {
|
2022-02-23 18:11:55 +01:00
|
|
|
board_canvas->ApplyPreferences();
|
|
|
|
}
|