Create repository

This commit is contained in:
Loic Guegan 2022-02-23 18:11:55 +01:00
commit ce941c146a
127 changed files with 16162 additions and 0 deletions

View file

@ -0,0 +1,113 @@
#include "BoardPrefsPanelBF.h"
#include "game_tab/board/BoardCanvas.hpp"
#include "ochess.hpp"
#include <wx/combobox.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/preferences.h>
#include <wx/spinctrl.h>
#include <wx/stdpaths.h>
class BoardPrefsPanel : public BoardPrefsPanelBF {
BoardCanvas *real_board_canvas;
wxFileName pieces_path;
wxFileName squares_path;
public:
BoardPrefsPanel(wxWindow *parent) : BoardPrefsPanelBF(parent) {
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
real_board_canvas = new BoardCanvas((wxFrame *)board_canvas, 40, true);
sizer->Add(real_board_canvas, 1, wxEXPAND, 5);
board_canvas->SetSizerAndFit(sizer);
wxStandardPaths p = wxStandardPaths::Get();
pieces_path = wxFileName(p.GetExecutablePath());
pieces_path = pieces_path.GetPath() + "/assets/pieces";
squares_path = wxFileName(pieces_path);
squares_path = squares_path.GetPath() + "/boards";
wxLogDebug(squares_path.GetFullPath());
Bind(wxEVT_LISTBOX, &BoardPrefsPanel::OnConfChange, this, wxID_ANY);
Bind(wxEVT_SPINCTRL, &BoardPrefsPanel::OnConfChange, this, wxID_ANY);
}
void OnConfChange(wxCommandEvent &event) {
ApplyPreferences();
real_board_canvas->ApplyPreferences();
}
virtual bool TransferDataToWindow() {
wxLogDebug("Load!");
wxDir pieces_dir(pieces_path.GetFullPath());
wxString filename;
bool cont = pieces_dir.GetFirst(&filename, wxEmptyString, wxDIR_DEFAULT);
piece_theme->Append("default");
while (cont) {
wxFileName fn(filename);
fn.ClearExt();
piece_theme->Append(fn.GetName());
cont = pieces_dir.GetNext(&filename);
}
wxDir squares_dir(squares_path.GetFullPath());
cont = squares_dir.GetFirst(&filename, wxEmptyString, wxDIR_DEFAULT);
square_theme->Append("default");
while (cont) {
wxFileName fn(filename);
fn.ClearExt();
square_theme->Append(fn.GetName());
cont = squares_dir.GetNext(&filename);
}
CONFIG_OPEN(config);
piece_theme->SetStringSelection(
config->Read("board/theme/pieces/name", "default"));
square_theme->SetStringSelection(
config->Read("board/theme/squares/name", "default"));
show_side_badge->SetValue(config->Read("board/show_side_badge", true));
show_captures->SetValue(config->Read("board/show_captures", true));
black_by_default->SetValue(config->Read("board/black_by_default", false));
corner_radius->SetValue(config->Read("board/corner_radius", 8));
square_size->SetValue(config->Read("board/square_size", 80));
CONFIG_CLOSE(config);
return true;
}
void ApplyPreferences() {
CONFIG_OPEN(config);
wxString cur_theme = piece_theme->GetString(piece_theme->GetSelection());
config->Write("board/theme/pieces/name", cur_theme);
config->Write("board/theme/pieces/path",
pieces_path.GetFullPath() + "/" + cur_theme + ".png");
cur_theme = square_theme->GetString(square_theme->GetSelection());
config->Write("board/theme/squares/name", cur_theme);
config->Write("board/theme/squares/path",
squares_path.GetFullPath() + "/" + cur_theme + ".png");
config->Write("board/show_side_badge", show_side_badge->GetValue());
config->Write("board/show_captures", show_captures->GetValue());
config->Write("board/black_by_default", black_by_default->GetValue());
config->Write("board/corner_radius", corner_radius->GetValue());
config->Write("board/square_size", square_size->GetValue());
CONFIG_CLOSE(config);
}
virtual bool TransferDataFromWindow() {
ApplyPreferences();
MAINWIN->ApplyPreferences();
return (true);
}
};
class BoardPrefs : public wxPreferencesPage {
public:
virtual wxString GetName() const { return "Board"; }
virtual wxBitmap GetLargeIcon() {
return wxArtProvider::GetBitmap(wxART_HELP, wxART_TOOLBAR);
}
virtual wxWindow *CreateWindow(wxWindow *parent) {
return new BoardPrefsPanel(parent);
}
};

View file

@ -0,0 +1,106 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-40-g8042f487)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "BoardPrefsPanelBF.h"
///////////////////////////////////////////////////////////////////////////
BoardPrefsPanelBF::BoardPrefsPanelBF( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{
wxBoxSizer* main_sizer;
main_sizer = new wxBoxSizer( wxVERTICAL );
splitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D|wxSP_LIVE_UPDATE );
splitter->Connect( wxEVT_IDLE, wxIdleEventHandler( BoardPrefsPanelBF::splitterOnIdle ), NULL, this );
board_canvas = new wxPanel( splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
options_panel = new wxPanel( splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* options_sizer;
options_sizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* themes_sizer;
themes_sizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* piece_theme_sizer;
piece_theme_sizer = new wxBoxSizer( wxVERTICAL );
piece_theme_label = new wxStaticText( options_panel, wxID_ANY, wxT("Piece theme"), wxDefaultPosition, wxDefaultSize, 0 );
piece_theme_label->Wrap( -1 );
piece_theme_sizer->Add( piece_theme_label, 0, wxALL, 5 );
piece_theme = new wxListBox( options_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
piece_theme_sizer->Add( piece_theme, 1, wxALL|wxEXPAND, 5 );
themes_sizer->Add( piece_theme_sizer, 1, wxEXPAND, 5 );
wxBoxSizer* square_theme_sizer;
square_theme_sizer = new wxBoxSizer( wxVERTICAL );
square_theme_label = new wxStaticText( options_panel, wxID_ANY, wxT("Square theme"), wxDefaultPosition, wxDefaultSize, 0 );
square_theme_label->Wrap( -1 );
square_theme_sizer->Add( square_theme_label, 0, wxALL, 5 );
square_theme = new wxListBox( options_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
square_theme_sizer->Add( square_theme, 1, wxALL|wxEXPAND, 5 );
themes_sizer->Add( square_theme_sizer, 1, wxEXPAND, 5 );
options_sizer->Add( themes_sizer, 1, wxEXPAND, 5 );
show_side_badge = new wxCheckBox( options_panel, wxID_ANY, wxT("Side to play badge"), wxDefaultPosition, wxDefaultSize, 0 );
options_sizer->Add( show_side_badge, 0, wxALL, 5 );
show_captures = new wxCheckBox( options_panel, wxID_ANY, wxT("Show captured pieces"), wxDefaultPosition, wxDefaultSize, 0 );
options_sizer->Add( show_captures, 0, wxALL, 5 );
black_by_default = new wxCheckBox( options_panel, wxID_ANY, wxT("Black side by default"), wxDefaultPosition, wxDefaultSize, 0 );
options_sizer->Add( black_by_default, 0, wxALL, 5 );
wxBoxSizer* border_radius_sizer;
border_radius_sizer = new wxBoxSizer( wxHORIZONTAL );
border_radius_label = new wxStaticText( options_panel, wxID_ANY, wxT("Corner radius:"), wxDefaultPosition, wxDefaultSize, 0 );
border_radius_label->Wrap( -1 );
border_radius_sizer->Add( border_radius_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
corner_radius = new wxSpinCtrl( options_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 20, 0 );
border_radius_sizer->Add( corner_radius, 0, wxALL, 5 );
options_sizer->Add( border_radius_sizer, 0, wxEXPAND, 5 );
wxBoxSizer* board_size_sizer;
board_size_sizer = new wxBoxSizer( wxHORIZONTAL );
board_size_label = new wxStaticText( options_panel, wxID_ANY, wxT("Board squares size:"), wxDefaultPosition, wxDefaultSize, 0 );
board_size_label->Wrap( -1 );
board_size_sizer->Add( board_size_label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
square_size = new wxSpinCtrl( options_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 20, 150, 0 );
board_size_sizer->Add( square_size, 0, wxALL|wxEXPAND, 5 );
options_sizer->Add( board_size_sizer, 0, wxEXPAND, 5 );
options_panel->SetSizer( options_sizer );
options_panel->Layout();
options_sizer->Fit( options_panel );
splitter->SplitHorizontally( board_canvas, options_panel, 350 );
main_sizer->Add( splitter, 1, wxEXPAND, 5 );
this->SetSizer( main_sizer );
this->Layout();
}
BoardPrefsPanelBF::~BoardPrefsPanelBF()
{
}

View file

@ -0,0 +1,64 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-40-g8042f487)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/panel.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/listbox.h>
#include <wx/sizer.h>
#include <wx/checkbox.h>
#include <wx/spinctrl.h>
#include <wx/splitter.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class BoardPrefsPanelBF
///////////////////////////////////////////////////////////////////////////////
class BoardPrefsPanelBF : public wxPanel
{
private:
protected:
wxSplitterWindow* splitter;
wxPanel* board_canvas;
wxPanel* options_panel;
wxStaticText* piece_theme_label;
wxListBox* piece_theme;
wxStaticText* square_theme_label;
wxListBox* square_theme;
wxCheckBox* show_side_badge;
wxCheckBox* show_captures;
wxCheckBox* black_by_default;
wxStaticText* border_radius_label;
wxSpinCtrl* corner_radius;
wxStaticText* board_size_label;
wxSpinCtrl* square_size;
public:
BoardPrefsPanelBF( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 756,751 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
~BoardPrefsPanelBF();
void splitterOnIdle( wxIdleEvent& )
{
splitter->SetSashPosition( 350 );
splitter->Disconnect( wxEVT_IDLE, wxIdleEventHandler( BoardPrefsPanelBF::splitterOnIdle ), NULL, this );
}
};

View file

@ -0,0 +1,2 @@
#pragma once
#include "BoardPrefs.hpp"