OChess v0.0.2
Programmer's Manual
ochess.hpp
1#pragma once
2
3#include <wx/wxprec.h>
4#ifndef WX_PRECOMP
5#include <wx/wx.h>
6#endif
7
8#include "binres/binres.hpp"
9#include "Openings.hpp"
10#include "gui.h"
11#include <memory>
12#include <wx/app.h>
13#include <wx/config.h>
14#include <wx/filefn.h> // Check file exists etc
15#include <wx/log.h>
16#include <wx/busyinfo.h>
17#include <vector>
18
19#define MAINWIN ((MainWindow *)wxGetApp().GetTopWindow())
20
21#define SHOW_DIALOG_ERROR(message) \
22 { \
23 wxMessageDialog *dial = new wxMessageDialog( \
24 NULL, wxT(message), wxT("Error"), wxOK | wxICON_ERROR); \
25 dial->ShowModal(); \
26 }
27#define SHOW_DIALOG_INFO(message) {wxMessageBox( wxT(message) );}
28#define SHOW_DIALOG_BUSY(message) {wxBusyInfo wait(message);}
29#define REQUIRE_FILE(file) \
30 { \
31 if (!wxFileExists(file)) { \
32 Abort(std::string("File ") + file + std::string(" not found")); \
33 } \
34 }
35
36#define CONFIG_OPEN(name) wxConfig *name = new wxConfig("ochess")
37#define CONFIG_CLOSE(name) delete name
38#define CONFIG_VERSION "1.0"
39#define UNUSED(symbol) (void)(symbol);
40
41class Game;
42class GameBase;
47class TabInfos {
49 static long tab_count;
50public:
52 typedef enum Type { GAME, BASE, ENGINE, NONE } Type;
53 Type type;
55 long id;
62 TabInfos(Type type_) : type(type_), id(tab_count), is_linked(false), is_dirty(false) { tab_count++; }
63 void Link(TabInfos *tab);
64 virtual void Refresh(){};
66 virtual void OnLink(){};
68 virtual void ApplyPreferences() {};
69 virtual std::shared_ptr<Game> GetGame() = 0;
70 virtual std::shared_ptr<GameBase> GetBase() = 0;
71 virtual std::uint32_t GetEngineId() { return 0; };
72};
73
74
79class MyApp : public wxApp {
80public:
81 Openings Book;
83 virtual bool OnInit();
85 std::vector<TabInfos *> ListTabInfos();
87 void FocusOnTab(TabInfos *);
89 void NewGame(TabInfos *tabsrc,std::shared_ptr<Game> g);
91 void NewGame(std::shared_ptr<Game> g);
94};
95
96wxDECLARE_APP(MyApp);
97
99void Abort(std::string msg);
Binary resources functions.
Represent the interface that each database type (such as PGNGameBase) must follow to be accessible in...
Definition: GameBase.hpp:10
Hold an entire chess game. Used in many places in the projects.
Definition: Game.hpp:12
Main application.
Definition: ochess.hpp:79
Openings & GetBook()
Singleton to get the opening book (see Openings)
Definition: ochess.cpp:62
void NewGame(TabInfos *tabsrc, std::shared_ptr< Game > g)
Open a new game tab linked to tabsrc that uses game g.
Definition: ochess.cpp:64
virtual bool OnInit()
Entry point of the application.
Definition: ochess.cpp:5
std::vector< TabInfos * > ListTabInfos()
Get a list of all the tabs opened in OChess.
Definition: ochess.cpp:45
void FocusOnTab(TabInfos *)
Trigger a wxWidget focus event on a specific tab.
Definition: ochess.cpp:54
Guess the opening using the Lichess Opening Database See: https://github.com/lichess-org/chess-openin...
Definition: Openings.hpp:10
Used by each tab of the GUI to attach additional informations and features.
Definition: ochess.hpp:47
long id
Each tab has an associated unique id.
Definition: ochess.hpp:55
bool is_linked
Set to true if this tab is attach to another one (c.f linked_id)
Definition: ochess.hpp:59
static long tab_count
Keep track of the number of opened tabs.
Definition: ochess.hpp:49
bool is_dirty
True if current tab is dirty.
Definition: ochess.hpp:61
long linked_id
Specify to which tab id this tab is linked (e.g: database to linked to on of its opened game tab)
Definition: ochess.hpp:57
virtual void ApplyPreferences()
Can be called to load preferences that have been modify in the application settings.
Definition: ochess.hpp:68
virtual void OnLink()
Callback that is called when the current tab is linked to another one.
Definition: ochess.hpp:66
Type
Which type of tab is it?
Definition: ochess.hpp:52