mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
92 lines
2.7 KiB
C++
92 lines
2.7 KiB
C++
#include "GameTabLeftPanel.hpp"
|
|
#include <wx/clipbrd.h>
|
|
|
|
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
|
: TabGameLeftPanel(parent), game(game) {
|
|
|
|
// Add board
|
|
board_canvas = new BoardCanvas((wxFrame *)this);
|
|
main_sizer->Insert(0, board_canvas, 1, wxEXPAND);
|
|
|
|
// Configure buttons
|
|
swap_button->SetBitmapLabel(LoadPNG("swap"));
|
|
zoomin_button->SetBitmapLabel(LoadPNG("zoomin"));
|
|
zoomout_button->SetBitmapLabel(LoadPNG("zoomout"));
|
|
|
|
// Configure FEN field
|
|
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);
|
|
}
|
|
|
|
void GameTabLeftPanel::OnPreviousMove(wxCommandEvent &event) {
|
|
game->Previous();
|
|
Notify();
|
|
NotifyEditor();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
void GameTabLeftPanel::OnNextMove(wxCommandEvent &event) {
|
|
wxLogDebug("Game tab received NEXT_MOVE_EVENT");
|
|
game->Next();
|
|
Notify();
|
|
NotifyEditor();
|
|
}
|
|
|
|
void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
|
|
wxLogDebug("Game tab received PLAY_MOVE_EVENT");
|
|
if (game->Play(event.GetString().ToStdString())) {
|
|
NotifyEditor();
|
|
}
|
|
Notify();
|
|
|
|
|
|
std::string fen = game->GetFen();
|
|
std::map<char, std::uint8_t> 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() {
|
|
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);
|
|
|
|
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(); }
|