Improve documentation

This commit is contained in:
Loic Guegan 2023-05-13 10:43:21 +02:00
parent 055410c0e0
commit 617f2b01b2
23 changed files with 173 additions and 11 deletions

View file

@ -15,9 +15,16 @@ wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
wxDECLARE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent); wxDECLARE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent);
wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent); wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent);
/**
* @brief Main GUI window of OChess
*
*/
class MainWindow : public MainFrame { class MainWindow : public MainFrame {
/// @brief Preference popup window
wxPreferencesEditor *prefsEditor; wxPreferencesEditor *prefsEditor;
/// @brief Menu to manage existing chess engines
wxMenu *manageMenu; wxMenu *manageMenu;
/// @brief Store the number of available chess engines (to create entries in the menus)
int engine_count; int engine_count;
void OnClose(wxCloseEvent &e); void OnClose(wxCloseEvent &e);

View file

@ -5,6 +5,10 @@
#include "gamebase/PGNGameBase.hpp" #include "gamebase/PGNGameBase.hpp"
#include "GameListManager.hpp" #include "GameListManager.hpp"
/**
* @brief A BaseTab sub-tab to list and search games
*
*/
class BaseGameTab : public TabBase_TabGames { class BaseGameTab : public TabBase_TabGames {
std::shared_ptr<GameBase> base; std::shared_ptr<GameBase> base;

View file

@ -6,6 +6,10 @@
#include <vector> #include <vector>
#include <utility> #include <utility>
/**
* @brief A BaseTab sub-tab to import games
*
*/
class BaseImportTab : public TabBase_TabImport { class BaseImportTab : public TabBase_TabImport {
TabInfos *main_tab; TabInfos *main_tab;
std::shared_ptr<GameListManager> glm; std::shared_ptr<GameListManager> glm;

View file

@ -6,6 +6,10 @@
#include "BaseImportTab.hpp" #include "BaseImportTab.hpp"
#include "BaseGameTab.hpp" #include "BaseGameTab.hpp"
/**
* @brief A BaseTab sub-tab to manage games
*
*/
class BaseManageTab : public TabBase_TabManage { class BaseManageTab : public TabBase_TabManage {
/// Never free the following pointers in that class /// Never free the following pointers in that class

View file

@ -13,6 +13,10 @@ wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent);
// Local events // Local events
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent); wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
/**
* @brief Class that represents an opened chess games database in the MainWindow
*
*/
class BaseTab : public TabBase, public TabInfos { class BaseTab : public TabBase, public TabInfos {
/// @brief The opened database /// @brief The opened database
std::shared_ptr<GameBase> base; std::shared_ptr<GameBase> base;

View file

@ -25,7 +25,7 @@ typedef struct Item {
} RType; } RType;
/** /**
* @brief A manager for wxListCtrl that display games * @brief A helper class to manage a wxListCtrl that display games
* *
*/ */
class GameListManager { class GameListManager {

View file

@ -3,6 +3,10 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
/**
* @brief Represent the interface that each database type (such as PGNGameBase) must follow
* to be accessible in OChess.
*/
class GameBase { class GameBase {
public: public:

View file

@ -3,6 +3,10 @@
#include "GameBase.hpp" #include "GameBase.hpp"
#include "pgnp.hpp" #include "pgnp.hpp"
/**
* @brief Used to open PGN files
*
*/
class PGNGameBase : public GameBase { class PGNGameBase : public GameBase {
pgnp::PGN *pgn; pgnp::PGN *pgn;
bool hasNextGame; bool hasNextGame;

View file

@ -1,7 +1,32 @@
/**
* @file binres.hpp
* @author Manzerbredes
* @brief Binary resources functions
* @version 0.1
* @date 2023-05-12
*
* @copyright Copyright (c) 2023
*
*/
#pragma once #pragma once
#include "ochess.hpp" #include "ochess.hpp"
/**
* @brief Load an icon from embedded binary resources and rescale it
* to a specified @a size
*
* @param icon The icon name
* @param size Scale the icon to the specified size
* @return wxBitmap
*/
wxBitmap LoadPNG(std::string icon, wxSize size); wxBitmap LoadPNG(std::string icon, wxSize size);
/**
* @brief Load an icon from embedded binary resources
*
* @param icon
* @return wxBitmap
*/
wxBitmap LoadPNG(std::string icon); wxBitmap LoadPNG(std::string icon);

View file

@ -1,3 +1,13 @@
/**
* @file config.h.in
* @author Manzerbredes
* @brief CMake configuration entries
* @version 0.1
* @date 2023-05-12
*
* @copyright Copyright (c) 2023
*
*/
#define OCHESS_VERSION "@PROJECT_VERSION@" #define OCHESS_VERSION "@PROJECT_VERSION@"
#define OCHESS_MAJOR "@PROJECT_VERSION_MAJOR@" #define OCHESS_MAJOR "@PROJECT_VERSION_MAJOR@"
#define OCHESS_MINOR "@PROJECT_VERSION_MINOR@" #define OCHESS_MINOR "@PROJECT_VERSION_MINOR@"

View file

@ -6,6 +6,10 @@ wxDECLARE_EVENT(CLOSE_TAB_EVENT, wxCommandEvent);
wxDECLARE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent); wxDECLARE_EVENT(REFRESH_ENGINE_LIST, wxCommandEvent);
wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent); wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
/**
* @brief Tab used to configure UCI chess engines
*
*/
class EngineTab : public TabEngine, public TabInfos { class EngineTab : public TabEngine, public TabInfos {
std::string confGroup, enginePath; std::string confGroup, enginePath;
uciadapter::UCI *engine; uciadapter::UCI *engine;

View file

@ -15,6 +15,10 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent); wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent); wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
/**
* @brief Main tab for opened games. Contains GameTabLeftPanel and GameTabRightPanel.
*
*/
class GameTab : public wxPanel, public TabInfos { class GameTab : public wxPanel, public TabInfos {
GameTabRightPanel *editor_panel; GameTabRightPanel *editor_panel;
GameTabLeftPanel *board_panel; GameTabLeftPanel *board_panel;

View file

@ -18,6 +18,7 @@ class HalfMove : public CMI::HalfMove {
std::string src,dst; std::string src,dst;
/// @brief Opening reach by that move while taking into account all the parents /// @brief Opening reach by that move while taking into account all the parents
std::string opening, eco; std::string opening, eco;
/// @brief Arbiter used to ensure that chess rules are followed
chessarbiter::ChessArbiter arbiter; chessarbiter::ChessArbiter arbiter;
public: public:

View file

@ -9,6 +9,10 @@
// Foreign events // Foreign events
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent); wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
/**
* @brief Panel that contains the BoardCanvas and the bottom control buttons
*
*/
class GameTabLeftPanel : public TabGameLeftPanel { class GameTabLeftPanel : public TabGameLeftPanel {
std::shared_ptr<Game> game; std::shared_ptr<Game> game;
BoardCanvas *board_canvas; BoardCanvas *board_canvas;

View file

@ -40,7 +40,9 @@ wxDECLARE_EVENT(PLAY_MOVE_EVENT, wxCommandEvent);
typedef std::tuple<short, short, short> ClockTime; typedef std::tuple<short, short, short> ClockTime;
// Drawing buffer (ANIMATIONS) /**
* @brief Drawing buffer and state for animations
*/
typedef struct AnimState { typedef struct AnimState {
/// @brief Temporary buffer to reduce latency /// @brief Temporary buffer to reduce latency
wxBitmap *buffer; wxBitmap *buffer;
@ -62,21 +64,39 @@ typedef struct AnimState {
wxPoint transVect; wxPoint transVect;
} AnimState; } AnimState;
/**
* @brief Current game state displayed by BoardCanvas
*/
typedef struct GameState { typedef struct GameState {
/// @brief State of an arrow
typedef struct Arrow { typedef struct Arrow {
std::string src,dst; std::string src,dst;
wxColour color=wxNullColour; wxColour color=wxNullColour;
float scale=1; float scale=1;
} Arrow; } Arrow;
/// @brief State of an highlighted square
typedef struct Square { typedef struct Square {
std::string square; std::string square;
wxColour color=wxNullColour; wxColour color=wxNullColour;
} Square; } Square;
std::string white, black; std::string white, black;
/**
* @brief Contains all the board squares with their pieces in the same order as the FEN specification.
*
* For example, the following board
@verbatim
"rnb RNB"
@endverbatim
* contains a black rook on a8, a black knight on b8, a black bishop on c8, a white rook
* on a1, a white knight on b1 and a white bishop on c1
*/
std::string board; std::string board;
/// @brief When there is a pending promotion, this variable contains the coordinate of the square on which the promotion takes place.
std::string promotion; std::string promotion;
std::map<char, std::uint8_t> captures; std::map<char, std::uint8_t> captures;
/// @brief Square to highlight (combined to BoardCanvas::squares_hl)
std::vector<Square> squares_hl; std::vector<Square> squares_hl;
/// @brief Arrow to draw (combined to BoardCanvas::arrows)
std::vector<Arrow> arrows; std::vector<Arrow> arrows;
bool is_black_turn; bool is_black_turn;
bool mat_black; bool mat_black;
@ -86,29 +106,44 @@ typedef struct GameState {
ClockTime black_time={-1,-1,-1}, white_time={-1,-1,-1}; ClockTime black_time={-1,-1,-1}, white_time={-1,-1,-1};
} GameState; } GameState;
/**
* @brief This class draws the chess board (squares, pieces, arrows and every other board related components).
*
*/
class BoardCanvas : public wxPanel { class BoardCanvas : public wxPanel {
// *t is theme for board+pieces and /// @brief Contains the theme for squares and pieces (see Theme)
// *t_captures is theme for captured pieces (scale down version of t) Theme *t;
Theme *t, *t_captures; /// @brief Scale down version of BoardCanvas::t for the captured pieces by black and white
Theme *t_captures;
/// @brief Stores the color of the arrows
wxColour color_arrows; wxColour color_arrows;
/// @brief Offset used for the start point of the arrows (this way, arrows do not completely overlap on the pieces)
int arrows_offset; int arrows_offset;
/// @brief Thickness of the arrows
std::uint8_t arrow_thickness; std::uint8_t arrow_thickness;
/// @brief Player names
std::string white_player,black_player; std::string white_player,black_player;
// Current highlighted squares and arrows: /// @brief Current highlighted squares that were highlighted with the mouse
std::vector<GameState::Square> squares_hl; std::vector<GameState::Square> squares_hl;
/// @brief Current drawn arrows that were drawn with the mouse
std::vector<GameState::Arrow> arrows; std::vector<GameState::Arrow> arrows;
// Various canvas state variables // Various canvas state variables
bool black_side, is_dragging, valid_drag, arrow_drag, is_black_turn; bool black_side, is_dragging, valid_drag, arrow_drag, is_black_turn;
std::int32_t boardX, boardY, square_width, piece_width, mouseX, mouseY, lastClickX, std::int32_t boardX, boardY, square_width, piece_width, mouseX, mouseY, lastClickX,
lastClickY; lastClickY;
/// @brief Contains an up to date dimension of the canvas size and its use in various places
wxSize canvas_size; wxSize canvas_size;
/// @brief Used for drag and drop
wxPoint active_square; wxPoint active_square;
std::map<char, std::uint8_t> captures; std::map<char, std::uint8_t> captures;
bool frozen,lock_square_size; /// @brief Board can be frozen (to preview the board themes in the preference menu for example)
bool frozen;
bool lock_square_size;
// Current animation state /// @brief Current animation state
AnimState adata; AnimState adata;
/// @brief Current board state (contains all the game state)
GameState gs; GameState gs;
/// @brief Draw an arrow from a source point to a destination point on DC /// @brief Draw an arrow from a source point to a destination point on DC
@ -121,9 +156,11 @@ public:
BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen); BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen);
~BoardCanvas(); ~BoardCanvas();
void ApplyPreferences(); void ApplyPreferences();
/// @brief Draw current state of the board (GameState) on the given wxDC /// @brief Draw current board state BoardCanvas::gs on the given @a wxDC
void DrawBoard(wxDC &dc); void DrawBoard(wxDC &dc);
/// @brief Callback called by wxWidgets to refresh the canvas
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
/// @brief Callback called by wxWidgets to handle mouse events
void MouseEvent(wxMouseEvent &event); void MouseEvent(wxMouseEvent &event);
/// @brief Zomm in/out on the canvas /// @brief Zomm in/out on the canvas
void Zoom(std::int32_t zoom); void Zoom(std::int32_t zoom);

View file

@ -12,6 +12,10 @@
#define DEFAULT_PIECE_THEME "assets/pieces/cburnett.png" #define DEFAULT_PIECE_THEME "assets/pieces/cburnett.png"
#define DEFAULT_SQUARE_THEME "assets/boards/chesscom_8bits.png" #define DEFAULT_SQUARE_THEME "assets/boards/chesscom_8bits.png"
/**
* @brief The in memory board theme (used by BoardCanvas)
*
*/
class Theme { class Theme {
private: private:
std::unordered_map<char, wxImage> skin; std::unordered_map<char, wxImage> skin;
@ -21,18 +25,30 @@ private:
public: public:
Theme(); Theme();
/// @brief Create piece using two png file path
Theme(std::string piece, std::string square); Theme(std::string piece, std::string square);
~Theme(); ~Theme();
/// @brief Load piece skin image (break image tile into individual pieces)
void LoadPiecesSkin(wxImage skin); void LoadPiecesSkin(wxImage skin);
/// @brief Load square skin image (break the 2 square tiles into individual squares)
void LoadSquaresSkin(wxImage iskin); void LoadSquaresSkin(wxImage iskin);
/// @brief Set pieces width
void ResizePieces(std::uint32_t width); void ResizePieces(std::uint32_t width);
/// @brief Set squares width
void ResizeSquares(std::uint32_t width); void ResizeSquares(std::uint32_t width);
/// @brief Set square width and adjust piece size accordingly
void ResizeSquaresAndPieces(std::uint32_t width); void ResizeSquaresAndPieces(std::uint32_t width);
/// @brief Having rounded corners on squares
void SetSquareRadius(std::uint8_t radius); void SetSquareRadius(std::uint8_t radius);
std::uint8_t GetSquareRadius(); std::uint8_t GetSquareRadius();
bool Zoom(int amount); bool Zoom(int amount);
double GetPiecesSizes(); double GetPiecesSizes();
double GetSquaresSizes(); double GetSquaresSizes();
/**
* @brief Get bitmap of an element
*
* @param c For black pieces rnbkqp for white pieces RNBKQP and # for mate symbol and s for black square and S for white square
* @return wxBitmap*
*/
wxBitmap *Get(char c); wxBitmap *Get(char c);
}; };

View file

@ -12,6 +12,10 @@ wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent); wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
wxDECLARE_EVENT(LIVE_ANALYSIS_STATUS, wxCommandEvent); wxDECLARE_EVENT(LIVE_ANALYSIS_STATUS, wxCommandEvent);
/**
* @brief Right panel of the GameTab and contains the EditorCanvas and the live engine tab
*
*/
class GameTabRightPanel : public TabGameRightPanel { class GameTabRightPanel : public TabGameRightPanel {
std::shared_ptr<Game> game; std::shared_ptr<Game> game;
EditorCanvas *editor_canvas; EditorCanvas *editor_canvas;

View file

@ -7,11 +7,16 @@
wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent); wxDECLARE_EVENT(SHOW_ENGINE_EVALUATION, wxCommandEvent);
/// @brief Contains the current engine evaluation (sorted vector of best lines + position score in cp)
typedef struct EngineEvaluation { typedef struct EngineEvaluation {
std::vector<std::string> best_lines; std::vector<std::string> best_lines;
float eval=0; float eval=0;
} EngineEvaluation; } EngineEvaluation;
/**
* @brief Dialog to control the current running engine on the game tab
*
*/
class LiveEngineDialog : public DialogLiveEngine { class LiveEngineDialog : public DialogLiveEngine {
uciadapter::UCI *engine; uciadapter::UCI *engine;
std::string engine_name; std::string engine_name;

View file

@ -9,6 +9,10 @@
// Foreign events // Foreign events
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent); wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
/**
* @brief Contains the moves editor for the currently opened game
*
*/
class EditorCanvas : public wxPanel, public cgeditor::CGEditor { class EditorCanvas : public wxPanel, public cgeditor::CGEditor {
wxPaintDC *dc; wxPaintDC *dc;
wxPoint Middle(cgeditor::Element e); wxPoint Middle(cgeditor::Element e);

View file

@ -41,7 +41,7 @@
class Game; class Game;
class GameBase; class GameBase;
/** /**
* @brief Used by each tab of the GUI to attach informations additional informations and features * @brief Used by each tab of the GUI to attach additional informations and features
* *
*/ */
class TabInfos { class TabInfos {

View file

@ -7,6 +7,10 @@
#include <wx/spinctrl.h> #include <wx/spinctrl.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
/**
* @brief Configuration page for the BoardCanvas
*
*/
class BoardPrefsPanel : public PrefsBoard { class BoardPrefsPanel : public PrefsBoard {
BoardCanvas *real_board_canvas; BoardCanvas *real_board_canvas;
wxFileName pieces_path; wxFileName pieces_path;
@ -101,6 +105,10 @@ public:
} }
}; };
/**
* @brief Interface for wxWidgets to load BoardPrefsPanel into the preference window
*
*/
class BoardPrefs : public wxPreferencesPage { class BoardPrefs : public wxPreferencesPage {
public: public:
virtual wxString GetName() const { return "Board"; } virtual wxString GetName() const { return "Board"; }

View file

@ -6,6 +6,10 @@
#include <wx/spinctrl.h> #include <wx/spinctrl.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
/**
* @brief Configuration page for the EditorCanvas
*
*/
class EditorPrefsPanel : public PrefsEditor { class EditorPrefsPanel : public PrefsEditor {
public: public:
@ -49,6 +53,10 @@ public:
} }
}; };
/**
* @brief Interface for wxWidgets to load EditorPrefsPanel into the preference window
*
*/
class EditorPrefs : public wxPreferencesPage { class EditorPrefs : public wxPreferencesPage {
public: public:
virtual wxString GetName() const { return "Editor"; } virtual wxString GetName() const { return "Editor"; }

View file

@ -964,6 +964,7 @@ FILE_PATTERNS = *.c \
*.c++ \ *.c++ \
*.java \ *.java \
*.ii \ *.ii \
*.in \
*.ixx \ *.ixx \
*.ipp \ *.ipp \
*.i++ \ *.i++ \