1 /*
2  * $Source: /cvsroot/cgoban1/cgoban1/src/cgbuts.h,v $
3  * $Revision: 1.2 $
4  * $Author: wmshub $
5  * $Date: 2002/05/31 23:40:54 $
6  *
7  * src/cgbuts.h, part of Complete Goban (game program)
8  * Copyright (C) 1995 William Shubert.
9  * See "configure.h.in" for more copyright information.
10  */
11 
12 
13 #ifndef  _CGBUTS_H_
14 #define  _CGBUTS_H_  1
15 
16 #ifndef  _GOBOARD_H_
17 #include "goBoard.h"
18 #endif
19 #ifndef  _BUT_BUT_H_
20 #include <but/but.h>
21 #endif
22 
23 
24 /**********************************************************************
25  * Constants
26  **********************************************************************/
27 #define  CGBUTS_COLORBG1       (BUT_DCOLORS+0)
28 #define  CGBUTS_COLORBG2       (BUT_DCOLORS+1)
29 #define  CGBUTS_COLORBGLIT1    (BUT_DCOLORS+2)
30 #define  CGBUTS_COLORBGLIT2    (BUT_DCOLORS+3)
31 #define  CGBUTS_COLORBGSHAD1   (BUT_DCOLORS+4)
32 #define  CGBUTS_COLORBGSHAD2   (BUT_DCOLORS+5)
33 #define  CGBUTS_COLORREDLED    (BUT_DCOLORS+6)
34 #define  CGBUTS_GREY(n)        (BUT_DCOLORS+7+(n))
35 #define  CGBUTS_COLORBOARD(n)  (BUT_DCOLORS+7+256+(n))
36 #define  CGBUTS_NUMCOLORS  (COLOR_BOARD(256))
37 
38 
39 #define  CGBUTS_REWCHAR   "\1\1"
40 #define  CGBUTS_BACKCHAR  "\1\2"
41 #define  CGBUTS_FWDCHAR   "\1\3"
42 #define  CGBUTS_FFCHAR    "\1\4"
43 
44 #define  CGBUTS_WSTONECHAR    "\1\5"
45 #define  CGBUTS_BSTONECHAR    "\1\6"
46 
47 #define  CGBUTS_NUMWHITE  5
48 #define  CGBUTS_YINYANG(x)    (CGBUTS_NUMWHITE+(x))
49 #define  CGBUTS_WORLDWEST(x)  (CGBUTS_YINYANG(CGBUTS_NUMWHITE)+(x))
50 #define  CGBUTS_WORLDEAST(x)  (CGBUTS_WORLDWEST(CGBUTS_NUMWHITE)+(x))
51 
52 #define  CGBUTS_HOLDTIME  500  /* ms */
53 
54 
55 /**********************************************************************
56  * Data types
57  **********************************************************************/
58 typedef struct CgbutsPics_struct  {
59   Pixmap  stonePixmaps;
60   Pixmap  maskBitmaps;
61 } CgbutsPic;
62 
63 
64 typedef struct Cgbuts_struct  {
65   ButEnv  *env;
66   int  dpyDepth;
67   Window  dpyRootWindow;
68   int  numPics;
69   CgbutsPic  *pics;
70   Rnd  *rnd;
71   int  color;  /* TrueColor, PseudoColor, or GrayScale. */
72   bool  hiContrast;
73   bool  holdEnabled;
74   Time  holdStart;
75   int timeWarn;
76 
77   MAGIC_STRUCT
78 } Cgbuts;
79 
80 
81 typedef enum  {
82   goMark_none,   goMark_lastMove, goMark_ko,
83   goMark_triangle, goMark_x, goMark_square, goMark_circle,
84   goMark_letter, goMark_number, goMark_smWhite, goMark_smBlack
85 } GoMarkType;
86 #define  goMark_max  (goMark_ko + 1)
87 
88 
89 typedef enum  {
90   gridLines_ul,   gridLines_top,    gridLines_ur,
91   gridLines_left, gridLines_center, gridLines_right,
92   gridLines_ll,   gridLines_bottom, gridLines_lr,
93   gridLines_none
94 } GridLines;
95 
96 
97 typedef struct Grid_struct  {
98   Cgbuts  *b;
99   ButOut (*callback)(But *but);
100   GridLines  lineGroup;
101   bool  starPoint;
102   int  pos;
103   GoStone  ptype;  /* The piece at this point on the board. */
104   GoStone  pressColor;  /* The color to add when this button is pressed. */
105   int  stoneVersion;
106   bool  grey, holdRequired;
107   GoMarkType  markType;
108   int  markAux;
109 
110   MAGIC_STRUCT
111 } Grid;
112 
113 
114 /**********************************************************************
115  * Global Variables
116  **********************************************************************/
117 extern const char  *cgbuts_stoneChar[2];
118 
119 /**********************************************************************
120  * Functions
121  **********************************************************************/
122 extern void  cgbuts_init(Cgbuts *cgbuts, ButEnv *env, Rnd *rnd, int color,
123 			 bool hold, bool hiContrast, int timeWarn);
124 extern But  *grid_create(Cgbuts *b, ButOut (*func)(But *but), void *packet,
125 			 ButWin *win, int layer, int flags, int pos);
126 extern void  grid_setStone(But *but, GoStone piece, bool grey);
127 extern void  grid_setMark(But *but, GoMarkType markType, int markAux);
128 extern void  grid_setPress(But *but, GoStone pressColor);
129 #define  grid_setHold(b, h)  (((Grid *)((b)->iPacket))->holdRequired = (h))
130 #define  grid_pressColor(b)  (((Grid *)((b)->iPacket))->pressColor)
131 #define  grid_setLineGroup(b, g)  (((Grid *)((b)->iPacket))->lineGroup = (g))
132 #define  grid_setStarPoint(b, s)  (((Grid *)((b)->iPacket))->starPoint = (s))
133 #define  grid_pos(b)  (((Grid *)((b)->iPacket))->pos)
134 #define  grid_stone(b)  (((Grid *)((b)->iPacket))->ptype)
135 #define  grid_grey(b)  (((Grid *)((b)->iPacket))->grey)
136 #define  grid_markType(b)  (((Grid *)((b)->iPacket))->markType)
137 #define  grid_markAux(b)  (((Grid *)((b)->iPacket))->markAux)
138 #define  grid_setVersion(b, v)  (((Grid *)((b)->iPacket))->stoneVersion = v)
139 #define  goMarkType_stone2sm(s)  \
140   ((GoMarkType)((s - goStone_white) + goMark_smWhite))
141 
142 extern But  *gobanPic_create(Cgbuts *b, ButWin *win, int layer, int flags);
143 extern But  *stoneGroup_create(Cgbuts *b, ButWin *win, int layer, int flags);
144 extern But  *computerPic_create(Cgbuts *b, ButWin *win, int layer, int flags);
145 extern But  *toolPic_create(Cgbuts *b, ButWin *win, int layer, int flags);
146 extern void  cgbuts_redraw(Cgbuts *b);
147 
148 /* Functions only for "friend" routines. */
149 extern void  cgbuts_drawp(Cgbuts *b, ButWin *win, GoStone piece, bool grey,
150 			  int x, int y, int size, int stoneVersion,
151 			  int dx, int dy, int dw, int dh);
152 extern void  cgbuts_markPiece(Cgbuts *b, ButWin *win, GoStone piece,
153 			      GoMarkType markType, int markAux,
154 			      int x, int y, int w, int stoneVersion,
155 			      int dx,int dy, int dw,int dh);
156 
157 #endif  /* _CGBUTS_H_ */
158