aboutsummaryrefslogtreecommitdiff
path: root/src/ochess.hpp
blob: d5b7c168cc9f2965bb4f488e2201ec1a46d5ce04 (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
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
#pragma once

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include "binres/binres.hpp"
#include "Openings.hpp"
#include "gui.h"
#include <memory>
#include <wx/app.h>
#include <wx/config.h>
#include <wx/filefn.h> // Check file exists etc
#include <wx/log.h>
#include <wx/busyinfo.h>
#include <vector>

#define MAINWIN ((MainWindow *)wxGetApp().GetTopWindow())

#define SHOW_DIALOG_ERROR(message)                                             \
  {                                                                            \
    wxMessageDialog *dial = new wxMessageDialog(                               \
        NULL, wxT(message), wxT("Error"), wxOK | wxICON_ERROR);                \
    dial->ShowModal();                                                         \
  }
#define SHOW_DIALOG_INFO(message) {wxMessageBox( wxT(message) );}
#define SHOW_DIALOG_BUSY(message) {wxBusyInfo wait(message);}
#define REQUIRE_FILE(file)                                                     \
  {                                                                            \
    if (!wxFileExists(file)) {                                                 \
      Abort(std::string("File ") + file + std::string(" not found"));          \
    }                                                                          \
  }

#define CONFIG_OPEN(name) wxConfig *name = new wxConfig("ochess")
#define CONFIG_CLOSE(name) delete name
#define CONFIG_VERSION "1.0"

class Game;
class GameBase;
/**
 * @brief Attach informations to the application tabs
 *
 */
class TabInfos {
  static long tab_count;
public:
  typedef enum Type { GAME, BASE, ENGINE, NONE } Type;
  Type type;
  /// @brief Each tab has an associated unique id
  long id;
  /// @brief Specify to which tab id this tab is linked (e.g: database to linked to game tab)
  long linked_id;
  /// @brief Set to true if this tab is attach to another one (c.f linked_id)
  bool is_linked;
  /// @brief True if current tab is dirty
  bool is_dirty;
  TabInfos(Type type_) : type(type_), id(tab_count), is_linked(false), is_dirty(false) { tab_count++; }
  void Link(TabInfos *tab);
  virtual void Refresh(){};
  /// @brief Call when tab is linked to another one
  virtual void OnLink(){};
  virtual void ApplyPreferences() {};
  virtual std::shared_ptr<Game> GetGame() = 0;
  virtual std::shared_ptr<GameBase> GetBase() = 0;
};


/**
 * @brief Main application
 *
 */
class MyApp : public wxApp {
public:
  Openings Book;
  virtual bool OnInit();
  std::vector<TabInfos *> ListTabInfos();
  void NewGame(TabInfos *tabsrc,std::shared_ptr<Game> g);
  void NewGame(std::shared_ptr<Game> g);
  Openings& GetBook();
};

wxDECLARE_APP(MyApp);

///@brief Abort ochess with a message
void Abort(std::string msg);