1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#include "GameTabLeftPanel.hpp"
#include <wx/clipbrd.h>
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
: TabGameLeftPanel(parent), game(game), repeat(false) {
// Configure toolbal
game_toolbar->AddTool(0, wxT("Exit application"),
wxArtProvider::GetBitmap(wxART_FILE_SAVE, wxART_TOOLBAR));
// Add board
board_canvas = new BoardCanvas((wxFrame *)this);
main_sizer->Insert(1, 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(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();});
game_toolbar->Bind(wxEVT_TOOL,&GameTabLeftPanel::OnToolClick,this);
}
void GameTabLeftPanel::OnToolClick(wxCommandEvent &event){
short id=event.GetId();
if(id==0){
if(related_file.size()>0){
// Todo implement save file
}
}
}
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();
}
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();
}
}
void GameTabLeftPanel::Notify(bool animate, bool backward) {
std::string fen = game->GetFen();
std::map<char, std::uint8_t> captures;
HalfMove *m = game->GetCurrentMove();
if (m != NULL) {
captures = m->GetLineCaptures();
}
if(!animate){
if(m){
last_absolute_move=m->GetAbsoluteMove();
}
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
game->IsBlackToPlay(), captures,
game->GetTag("White"),game->GetTag("Black"));
}
else{
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());
}
void GameTabLeftPanel::NotifyEditor() {
wxCommandEvent previousEvent(GAME_CHANGE, GetId());
previousEvent.SetEventObject(this);
ProcessEvent(previousEvent);
}
void GameTabLeftPanel::ApplyPreferences() { board_canvas->ApplyPreferences(); }
|