1 /*
2  * gtkboard.h
3  *
4  * by Gary Wong <gtw@gnu.org>, 1997-2001.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of version 3 or later of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * $Id: gtkboard.h,v 1.107 2018/05/05 20:52:19 plm Exp $
20  */
21 
22 #ifndef GTKBOARD_H
23 #define GTKBOARD_H
24 
25 #include "backgammon.h"
26 #include <gtk/gtk.h>
27 #include "eval.h"
28 #include "gtkpanels.h"
29 #include "common.h"
30 #include "render.h"
31 #include "gtklocdefs.h"
32 
33 #if defined(USE_BOARD3D)
34 #include "types3d.h"
35 #endif
36 
37 #define TYPE_BOARD			(board_get_type ())
38 #define BOARD(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BOARD, Board))
39 #define BOARD_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BOARD, BoardClass))
40 #define IS_BOARD(obj)			(G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BOARD))
41 #define IS_BOARD_CLASS(klass)		(G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_BOARD))
42 #define BOARD_GET_CLASS(obj)  		(G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_BOARD, BoardClass))
43 
44 typedef struct _BoardData BoardData;    /* Forward declaration for use in Board */
45 typedef struct _Board Board;
46 typedef struct _BoardClass BoardClass;
47 
48 struct _BoardClass {
49     GtkVBoxClass parent_class;
50 };
51 
52 struct _Board {
53     GtkVBox vbox;
54     /* private data */
55     BoardData *board_data;
56 };
57 
58 typedef enum _DiceShown {
59     DICE_NOT_SHOWN = 0, DICE_BELOW_BOARD, DICE_ON_BOARD, DICE_ROLLING
60 } DiceShown;
61 
62 /* private data */
63 struct _BoardData {
64     GtkWidget *drawing_area, *dice_area, *table, *wmove,
65         *reset, *edit, *name0, *name1, *score0, *score1,
66         *crawford, *jacoby, *widget, *key0, *key1, *stop, *stopparent,
67         *doub, *lname0, *lname1, *lscore0, *lscore1, *mname0, *mname1, *mscore0, *mscore1, *play;
68     GtkWidget *mmatch, *lmatch, *match;
69     GtkAdjustment *amatch, *ascore0, *ascore1;
70     GtkWidget *roll;
71     GtkWidget *take, *drop, *redouble;
72     GtkWidget *pipcount0, *pipcount1;
73     GtkWidget *pipcountlabel0, *pipcountlabel1;
74     GtkWidget *pwvboxcnt;
75 
76     gtk_locdef_surface *appmKey[2];
77 
78     gboolean playing, computer_turn;
79     gint drag_point, drag_colour, x_drag, y_drag, x_dice[2], y_dice[2], drag_button, click_time, cube_use;      /* roll showing on the off-board dice */
80     DiceShown diceShown;
81     TanBoard old_board;
82 
83     gint cube_owner;            /* -1 = bottom, 0 = centred, 1 = top */
84     gint qedit_point;           /* used to remember last point in quick edit mode */
85     gint resigned;
86     gint nchequers;
87     move *all_moves, *valid_move;
88     movelist move_list;
89 
90     renderimages ri;
91 
92     /* remainder is from FIBS board: data */
93     char name[MAX_NAME_LEN], name_opponent[MAX_NAME_LEN];
94     gint match_to, score, score_opponent;
95     gint points[28];            /* 0 and 25 are the bars */
96     gint turn;                  /* -1 is X, 1 is O, 0 if game over */
97     unsigned int diceRoll[2];   /* 0, 0 if not rolled */
98     guint cube;
99     gint can_double, opponent_can_double;       /* allowed to double */
100     gint doubled;               /* -1 if X is doubling, 1 if O is doubling */
101     gint colour;                /* -1 for player X, 1 for player O */
102     gint direction;             /* -1 playing from 24 to 1, 1 playing from 1 to 24 */
103     gint home, bar;             /* 0 or 25 depending on fDirection */
104     gint off, off_opponent;     /* number of men borne off */
105     gint on_bar, on_bar_opponent;       /* number of men on bar */
106     gint to_move;               /* 0 to 4 -- number of pieces to move */
107     gint forced, crawford_game; /* unused, Crawford game flag */
108     gint jacoby_flag;           /* jacoby enabled flag */
109     gint redoubles;             /* number of instant redoubles allowed */
110     int DragTargetHelp;         /* Currently showing draw targets? */
111     int iTargetHelpPoints[4];   /* Drag target position */
112     int grayBoard;              /* Show board grayed when editing */
113 
114 #if defined(USE_BOARD3D)
115     BoardData3d *bd3d;          /* extra members for 3d board */
116 #endif
117     renderdata *rd;             /* The board colour settings */
118 };
119 
120 
121 typedef enum _animation {
122     ANIMATE_NONE, ANIMATE_BLINK, ANIMATE_SLIDE
123 } animation;
124 
125 typedef enum _GuiShowPips {
126     GUI_SHOW_PIPS_NONE, GUI_SHOW_PIPS_PIPS, GUI_SHOW_PIPS_EPC, GUI_SHOW_PIPS_WASTAGE, N_GUI_SHOW_PIPS
127 } GuiShowPips;
128 
129 extern animation animGUI;
130 extern int fGUIBeep;
131 extern int fGUIHighDieFirst;
132 extern int fGUIIllegal;
133 extern int fShowIDs;
134 extern GuiShowPips gui_show_pips;
135 extern int fGUISetWindowPos;
136 extern int fGUIDragTargetHelp;
137 extern int fGUIUseStatsPanel;
138 extern int fGUIGrayEdit;
139 extern unsigned int nGUIAnimSpeed;
140 
141 extern GType board_get_type(void);
142 extern GtkWidget *board_new(renderdata * prd);
143 extern GtkWidget *board_cube_widget(Board * board);
144 extern void DestroySetCube(GObject * po, GtkWidget * pw);
145 extern void Copy3dDiceColour(renderdata * prd);
146 typedef enum { MT_STANDARD, MT_FIRSTMOVE, MT_EDIT } manualDiceType;
147 extern GtkWidget *board_dice_widget(Board * board, manualDiceType mdt);
148 extern gint game_set(Board * board, TanBoard points, int roll,
149                      const gchar * name, const gchar * opp_name, gint match,
150                      gint score, gint opp_score, gint die0, gint die1, gint computer_turn, gint nchequers);
151 extern void board_set_playing(Board * board, gboolean f);
152 extern void board_animate(Board * board, int move[8], int player);
153 extern unsigned int convert_point(int i, int player);
154 
155 
156 extern void board_create_pixmaps(GtkWidget * board, BoardData * bd);
157 extern void board_free_pixmaps(BoardData * bd);
158 extern void board_edit(BoardData * bd);
159 
160 extern void InitBoardPreview(BoardData * bd);
161 
162 extern int animate_player, *animate_move_list, animation_finished;
163 
164 enum TheoryTypes { TT_PIPCOUNT = 1, TT_EPC = 2, TT_RETURNHITS = 4, TT_KLEINCOUNT = 8 };
165 void UpdateTheoryData(BoardData * bd, int UpdateTypes, const TanBoard points);
166 
167 extern void read_board(BoardData * bd, TanBoard points);
168 extern void update_pipcount(BoardData * bd, const TanBoard points);
169 extern void InitBoardData(BoardData * bd);
170 extern gboolean board_button_press(GtkWidget * board, GdkEventButton * event, BoardData * bd);
171 extern gboolean board_motion_notify(GtkWidget * widget, GdkEventMotion * event, BoardData * bd);
172 extern gboolean board_button_release(GtkWidget * board, GdkEventButton * event, BoardData * bd);
173 extern void RollDice2d(BoardData * bd);
174 extern void DestroyPanel(gnubgwindow window);
175 extern void
176 DrawDie(cairo_t * pd,
177         unsigned char *achDice[2], unsigned char *achPip[2],
178         const int s, int x, int y, int fColour, int n, int alpha);
179 
180 extern int UpdateMove(BoardData * bd, TanBoard anBoard);
181 extern void stop_board_expose(BoardData * bd);
182 
183 #endif
184