1#include "game_tab/left_panel/board/BoardCanvas.hpp"
3#include <wx/combobox.h>
5#include <wx/filename.h>
6#include <wx/preferences.h>
7#include <wx/spinctrl.h>
8#include <wx/stdpaths.h>
10#include <wx/bmpbndl.h>
18 wxFileName pieces_path;
19 wxFileName squares_path;
23 wxBoxSizer *sizer =
new wxBoxSizer(wxHORIZONTAL);
24 real_board_canvas =
new BoardCanvas((wxFrame *)board_canvas, 40,
true);
25 sizer->Add(real_board_canvas, 1, wxEXPAND, 5);
26 board_canvas->SetSizerAndFit(sizer);
28 wxStandardPaths p = wxStandardPaths::Get();
29 pieces_path = wxFileName(p.GetExecutablePath());
30 pieces_path = pieces_path.GetPath() +
"/assets/pieces";
31 squares_path = wxFileName(pieces_path);
32 squares_path = squares_path.GetPath() +
"/boards";
33 wxLogDebug(squares_path.GetFullPath());
35 Bind(wxEVT_LISTBOX, &BoardPrefsPanel::OnConfChange,
this, wxID_ANY);
36 Bind(wxEVT_SPINCTRL, &BoardPrefsPanel::OnConfChange,
this, wxID_ANY);
38 void OnConfChange(wxCommandEvent &event) {
41 real_board_canvas->ApplyPreferences();
44 virtual bool TransferDataToWindow() {
47 wxDir pieces_dir(pieces_path.GetFullPath());
49 bool cont = pieces_dir.GetFirst(&filename, wxEmptyString, wxDIR_DEFAULT);
50 piece_theme->Append(
"default");
52 wxFileName fn(filename);
54 piece_theme->Append(fn.GetName());
55 cont = pieces_dir.GetNext(&filename);
58 wxDir squares_dir(squares_path.GetFullPath());
59 cont = squares_dir.GetFirst(&filename, wxEmptyString, wxDIR_DEFAULT);
60 square_theme->Append(
"default");
62 wxFileName fn(filename);
64 square_theme->Append(fn.GetName());
65 cont = squares_dir.GetNext(&filename);
69 piece_theme->SetStringSelection(
70 config->Read(
"board/theme/pieces/name",
"default"));
71 square_theme->SetStringSelection(
72 config->Read(
"board/theme/squares/name",
"default"));
73 show_side_badge->SetValue(config->Read(
"board/show_side_badge",
true));
74 show_captures->SetValue(config->Read(
"board/show_captures",
true));
75 black_by_default->SetValue(config->Read(
"board/black_by_default",
false));
76 corner_radius->SetValue(config->Read(
"board/corner_radius", 8));
77 square_size->SetValue(config->Read(
"board/square_size", 80));
83 void ApplyPreferences() {
85 wxString cur_theme = piece_theme->GetString(piece_theme->GetSelection());
86 config->Write(
"board/theme/pieces/name", cur_theme);
87 config->Write(
"board/theme/pieces/path",
88 pieces_path.GetFullPath() +
"/" + cur_theme +
".png");
89 cur_theme = square_theme->GetString(square_theme->GetSelection());
90 config->Write(
"board/theme/squares/name", cur_theme);
91 config->Write(
"board/theme/squares/path",
92 squares_path.GetFullPath() +
"/" + cur_theme +
".png");
94 config->Write(
"board/show_side_badge", show_side_badge->GetValue());
95 config->Write(
"board/show_captures", show_captures->GetValue());
96 config->Write(
"board/black_by_default", black_by_default->GetValue());
97 config->Write(
"board/corner_radius", corner_radius->GetValue());
98 config->Write(
"board/square_size", square_size->GetValue());
100 CONFIG_CLOSE(config);
103 virtual bool TransferDataFromWindow() {
105 MAINWIN->ApplyPreferences();
116 virtual wxString GetName()
const {
return "Board"; }
117 virtual wxBitmap GetLargeIcon() {
118 return wxArtProvider::GetBitmap(wxART_HELP, wxART_TOOLBAR);
121 virtual wxBitmapBundle GetIcon() {
122 return wxBitmapBundle::FromBitmap(
LoadPNG(
"ui_rook"));
125 virtual wxWindow *CreateWindow(wxWindow *parent) {
This class draws the chess board (squares, pieces, arrows and every other board related components).
Definition: BoardCanvas.hpp:113
Configuration page for the BoardCanvas.
Definition: BoardPrefs.hpp:16
Interface for wxWidgets to load BoardPrefsPanel into the preference window.
Definition: BoardPrefs.hpp:114
Class PrefsBoard.
Definition: gui.h:229
wxBitmap LoadPNG(std::string icon, wxSize size)
Load an icon from embedded binary resources and rescale it to a specified size.
Definition: binres.cpp:7