aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/GameTab.cpp
blob: 5a3e6b834e81a8d3a95ec8f7055066fbbdbb39cd (plain)
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
#include "GameTab.hpp"
#include <wx/clipbrd.h>

wxDEFINE_EVENT(GAME_CHANGE, wxCommandEvent);

GameTab::GameTab(wxFrame *parent, Game *game)
    : wxPanel(parent), game(game), TabInfos(TabInfos::GAME) {
  // Splitter
  wxSplitterWindow *splitter = new wxSplitterWindow(this, wxID_ANY);
  splitter->SetMinimumPaneSize(100);

  // Panels
  game->BuildAndVerify();
  board_panel = new BoardPanel((wxFrame *)splitter, game);
  editor_panel = new EditorPanel((wxFrame *)splitter, game);
  splitter->SplitVertically(board_panel, editor_panel);

  // Setup splitter
  wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);
  topSizer->Add(splitter, 1, wxEXPAND);
  SetSizerAndFit(topSizer);

  // Refresh panels
  wxCommandEvent event(REFRESH_TAB_TITLE, GetId());
  event.SetEventObject(this);
  OnRefreshTabTitle(event);
  board_panel->Notify();
  editor_panel->Notify();

  Bind(REFRESH_TAB_TITLE, &GameTab::OnRefreshTabTitle, this, wxID_ANY);
  Bind(GAME_CHANGE, &GameTab::OnGameChange, this, wxID_ANY);
}

void GameTab::OnGameChange(wxCommandEvent &event) {
  board_panel->Notify();
  editor_panel->Notify();
}

void GameTab::OnRefreshTabTitle(wxCommandEvent &event) {
  std::string white = game->GetTag("White");
  std::string black = game->GetTag("Black");
  if (white.size() == 0 && black.size() == 0) {
    SetLabel("New Game");
  } else {
    SetLabel(white + "-" + black);
  }
  event.SetEventObject(this);
  event.Skip();
}

void GameTab::ApplyPreferences() {
  board_panel->ApplyPreferences();
}