cd8db0efe7601bf2997624f54a3b9a0d0bf201e1
[rocksndiamonds.git] / src / buttons.h
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  (c) 1995-98 Artsoft Entertainment                       *
5 *              Holger Schemel                              *
6 *              Oststrasse 11a                              *
7 *              33604 Bielefeld                             *
8 *              phone: ++49 +521 290471                     *
9 *              email: aeglos@valinor.owl.de                *
10 *----------------------------------------------------------*
11 *  buttons.h                                               *
12 ***********************************************************/
13
14 #ifndef BUTTONS_H
15 #define BUTTONS_H
16
17 #include "main.h"
18
19 /* the following definitions are also used by tools.c */
20
21 /* some positions in the video tape control window */
22 #define VIDEO_DISPLAY1_XPOS     5
23 #define VIDEO_DISPLAY1_YPOS     5
24 #define VIDEO_DISPLAY2_XPOS     5
25 #define VIDEO_DISPLAY2_YPOS     41
26 #define VIDEO_DISPLAY_XSIZE     90
27 #define VIDEO_DISPLAY_YSIZE     31
28 #define VIDEO_BUTTON_XSIZE      18
29 #define VIDEO_BUTTON_YSIZE      18
30 #define VIDEO_CONTROL_XPOS      5
31 #define VIDEO_CONTROL_YPOS      77
32 #define VIDEO_CONTROL_XSIZE     VIDEO_DISPLAY_XSIZE
33 #define VIDEO_CONTROL_YSIZE     VIDEO_BUTTON_YSIZE
34
35 /* values for video tape control */
36 #define VIDEO_STATE_PLAY_OFF    (1L << 0)
37 #define VIDEO_STATE_PLAY_ON     (1L << 1)
38 #define VIDEO_STATE_PLAY        (VIDEO_STATE_PLAY_OFF   | VIDEO_STATE_PLAY_ON)
39 #define VIDEO_STATE_REC_OFF     (1L << 2)
40 #define VIDEO_STATE_REC_ON      (1L << 3)
41 #define VIDEO_STATE_REC         (VIDEO_STATE_REC_OFF    | VIDEO_STATE_REC_ON)
42 #define VIDEO_STATE_PAUSE_OFF   (1L << 4)
43 #define VIDEO_STATE_PAUSE_ON    (1L << 5)
44 #define VIDEO_STATE_PAUSE       (VIDEO_STATE_PAUSE_OFF  | VIDEO_STATE_PAUSE_ON)
45 #define VIDEO_STATE_DATE_OFF    (1L << 6)
46 #define VIDEO_STATE_DATE_ON     (1L << 7)
47 #define VIDEO_STATE_DATE        (VIDEO_STATE_DATE_OFF   | VIDEO_STATE_DATE_ON)
48 #define VIDEO_STATE_TIME_OFF    (1L << 8)
49 #define VIDEO_STATE_TIME_ON     (1L << 9)
50 #define VIDEO_STATE_TIME        (VIDEO_STATE_TIME_OFF   | VIDEO_STATE_TIME_ON)
51 #define VIDEO_PRESS_PLAY_ON     (1L << 10)
52 #define VIDEO_PRESS_PLAY_OFF    (1L << 11)
53 #define VIDEO_PRESS_PLAY        (VIDEO_PRESS_PLAY_OFF   | VIDEO_PRESS_PLAY_ON)
54 #define VIDEO_PRESS_REC_ON      (1L << 12)
55 #define VIDEO_PRESS_REC_OFF     (1L << 13)
56 #define VIDEO_PRESS_REC         (VIDEO_PRESS_REC_OFF    | VIDEO_PRESS_REC_ON)
57 #define VIDEO_PRESS_PAUSE_ON    (1L << 14)
58 #define VIDEO_PRESS_PAUSE_OFF   (1L << 15)
59 #define VIDEO_PRESS_PAUSE       (VIDEO_PRESS_PAUSE_OFF  | VIDEO_PRESS_PAUSE_ON)
60 #define VIDEO_PRESS_STOP_ON     (1L << 16)
61 #define VIDEO_PRESS_STOP_OFF    (1L << 17)
62 #define VIDEO_PRESS_STOP        (VIDEO_PRESS_STOP_OFF   | VIDEO_PRESS_STOP_ON)
63 #define VIDEO_PRESS_EJECT_ON    (1L << 18)
64 #define VIDEO_PRESS_EJECT_OFF   (1L << 19)
65 #define VIDEO_PRESS_EJECT       (VIDEO_PRESS_EJECT_OFF  | VIDEO_PRESS_EJECT_ON)
66
67 /* special */
68 #define VIDEO_STATE_FFWD_OFF    ((1L << 20) | VIDEO_STATE_PAUSE_OFF)
69 #define VIDEO_STATE_FFWD_ON     (1L << 21)
70 #define VIDEO_STATE_FFWD        (VIDEO_STATE_FFWD_OFF   | VIDEO_STATE_FFWD_ON)
71 #define VIDEO_STATE_PBEND_OFF   (1L << 22)
72 #define VIDEO_STATE_PBEND_ON    (1L << 23)
73 #define VIDEO_STATE_PBEND       (VIDEO_STATE_PBEND_OFF  | VIDEO_STATE_PBEND_ON)
74
75 /* tags to draw video display labels or symbols only */
76 #define VIDEO_DISPLAY_DEFAULT           0
77 #define VIDEO_DISPLAY_LABEL_ONLY        1
78 #define VIDEO_DISPLAY_SYMBOL_ONLY       2
79
80 void DrawVideoDisplay(unsigned long, unsigned long);
81 void DrawCompleteVideoDisplay(void);
82
83
84 /* NEW GADGET STUFF -------------------------------------------------------- */
85
86 /* some values for gadget graphics (also used by editor.c) */
87 #define ED_BUTTON_COUNT_YPOS    60
88 #define ED_BUTTON_COUNT_XSIZE   20
89 #define ED_BUTTON_COUNT_YSIZE   20
90 #define ED_WIN_COUNT_XPOS       (2 + ED_BUTTON_COUNT_XSIZE + 2)
91 #define ED_WIN_COUNT_YPOS       ED_BUTTON_COUNT_YPOS
92 #define ED_WIN_COUNT_XSIZE      52
93 #define ED_WIN_COUNT_YSIZE      ED_BUTTON_COUNT_YSIZE
94
95 /* gadget types */
96 #define GD_TYPE_NORMAL_BUTTON           (1 << 0)
97 #define GD_TYPE_CHECK_BUTTON            (1 << 1)
98 #define GD_TYPE_RADIO_BUTTON            (1 << 2)
99 #define GD_TYPE_DRAWING_AREA            (1 << 3)
100 #define GD_TYPE_TEXTINPUT_ALPHANUMERIC  (1 << 4)
101 #define GD_TYPE_TEXTINPUT_NUMERIC       (1 << 5)
102 #define GD_TYPE_SCROLLBAR_VERTICAL      (1 << 6)
103 #define GD_TYPE_SCROLLBAR_HORIZONTAL    (1 << 7)
104
105 #define GD_TYPE_BUTTON                  (GD_TYPE_NORMAL_BUTTON | \
106                                          GD_TYPE_CHECK_BUTTON | \
107                                          GD_TYPE_RADIO_BUTTON)
108 #define GD_TYPE_SCROLLBAR               (GD_TYPE_SCROLLBAR_VERTICAL | \
109                                          GD_TYPE_SCROLLBAR_HORIZONTAL)
110 #define GD_TYPE_TEXTINPUT               (GD_TYPE_TEXTINPUT_ALPHANUMERIC | \
111                                          GD_TYPE_TEXTINPUT_NUMERIC)
112
113 /* gadget events */
114 #define GD_EVENT_PRESSED                (1 << 0)
115 #define GD_EVENT_RELEASED               (1 << 1)
116 #define GD_EVENT_MOVING                 (1 << 2)
117 #define GD_EVENT_REPEATED               (1 << 3)
118 #define GD_EVENT_OFF_BORDERS            (1 << 4)
119 #define GD_EVENT_TEXT_RETURN            (1 << 5)
120 #define GD_EVENT_TEXT_LEAVING           (1 << 6)
121
122 /* gadget button states */
123 #define GD_BUTTON_UNPRESSED             0
124 #define GD_BUTTON_PRESSED               1
125
126 /* gadget structure constants */
127 #define MAX_GADGET_TEXTSIZE             1024
128 #define MAX_INFO_TEXTSIZE               1024
129
130 /* gadget creation tags */
131 #define GDI_END                         0
132 #define GDI_CUSTOM_ID                   1
133 #define GDI_CUSTOM_TYPE_ID              2
134 #define GDI_X                           3
135 #define GDI_Y                           4
136 #define GDI_WIDTH                       5
137 #define GDI_HEIGHT                      6
138 #define GDI_TYPE                        7
139 #define GDI_STATE                       8
140 #define GDI_CHECKED                     9
141 #define GDI_RADIO_NR                    10
142 #define GDI_NUMBER_VALUE                11
143 #define GDI_NUMBER_MIN                  12
144 #define GDI_NUMBER_MAX                  13
145 #define GDI_TEXT_VALUE                  14
146 #define GDI_TEXT_SIZE                   15
147 #define GDI_DESIGN_UNPRESSED            16
148 #define GDI_DESIGN_PRESSED              17
149 #define GDI_ALT_DESIGN_UNPRESSED        18
150 #define GDI_ALT_DESIGN_PRESSED          19
151 #define GDI_DESIGN_BORDER               20
152 #define GDI_DECORATION_DESIGN           21
153 #define GDI_DECORATION_POSITION         22
154 #define GDI_DECORATION_SIZE             23
155 #define GDI_DECORATION_SHIFTING         24
156 #define GDI_EVENT_MASK                  25
157 #define GDI_EVENT                       26
158 #define GDI_CALLBACK_INFO               27
159 #define GDI_CALLBACK_ACTION             28
160 #define GDI_AREA_SIZE                   29
161 #define GDI_ITEM_SIZE                   30
162 #define GDI_SCROLLBAR_ITEMS_MAX         31
163 #define GDI_SCROLLBAR_ITEMS_VISIBLE     32
164 #define GDI_SCROLLBAR_ITEM_POSITION     33
165 #define GDI_INFO_TEXT                   34
166
167 typedef void (*gadget_function)(void *);
168
169 struct GadgetDesign
170 {
171   Pixmap pixmap;                        /* Pixmap with gadget surface */
172   int x, y;                             /* position of rectangle in Pixmap */
173 };
174
175 struct GadgetDecoration
176 {
177   struct GadgetDesign design;           /* decoration design structure */
178   int x, y;                             /* position of deco on the gadget */
179   int width, height;                    /* width and height of decoration */
180   int xshift, yshift;                   /* deco shifting when gadget pressed */
181 };
182
183 struct GadgetEvent
184 {
185   unsigned long type;                   /* event type */
186   int button;                           /* button number for button events */
187   int x, y;                             /* gadget position at event time */
188   boolean off_borders;                  /* mouse pointer outside gadget? */
189   int item_x, item_y, item_position;    /* new item position */
190 };
191
192 struct GadgetDrawingArea
193 {
194   int area_xsize, area_ysize;           /* size of drawing area (in items) */
195   int item_xsize, item_ysize;           /* size of each item in drawing area */
196 };
197
198 struct GadgetTextInput
199 {
200   char value[MAX_GADGET_TEXTSIZE];      /* text string in input field */
201   int number_value;                     /* integer value, if numeric */
202   int number_min;                       /* minimal allowed numeric value */
203   int number_max;                       /* maximal allowed numeric value */
204   int size;                             /* maximal size of input text */
205   int cursor_position;                  /* actual cursor position */
206 };
207
208 struct GadgetScrollbar
209 {
210   int items_max;                        /* number of items to access */
211   int items_visible;                    /* number of visible items */
212   int item_position;                    /* actual item position */
213   int size_max;                         /* this is either width or height */
214   int size;                             /* scrollbar size on screen */
215   int position;                         /* scrollbar position on screen */
216   int position_max;                     /* bottom/right scrollbar position */
217   int drag_position;                    /* drag position on scrollbar */
218 };
219
220 struct GadgetInfo
221 {
222   int id;                               /* internal gadget identifier */
223   int custom_id;                        /* custom gadget identifier */
224   int custom_type_id;                   /* custom gadget type identifier */
225   char info_text[MAX_INFO_TEXTSIZE];    /* short popup info text */
226   int x, y;                             /* gadget position */
227   int width, height;                    /* gadget size */
228   unsigned long type;                   /* type (button, text input, ...) */
229   unsigned long state;                  /* state (pressed, released, ...) */
230   boolean checked;                      /* check/radio button state */
231   int radio_nr;                         /* number of radio button series */
232   boolean mapped;                       /* gadget is active */
233   struct GadgetDesign design[2];        /* 0: normal; 1: pressed */
234   struct GadgetDesign alt_design[2];    /* alternative design */
235   struct GadgetDecoration deco;         /* decoration on top of gadget */
236   int design_border;                    /* border size of gadget decoration */
237   unsigned long event_mask;             /* possible events for this gadget */
238   struct GadgetEvent event;             /* actual gadget event */
239   gadget_function callback_info;        /* function for pop-up info text */
240   gadget_function callback_action;      /* function for gadget action */
241   struct GadgetDrawingArea drawing;     /* fields for drawing area gadget */
242   struct GadgetTextInput text;          /* fields for text input gadget */
243   struct GadgetScrollbar scrollbar;     /* fields for scrollbar gadget */
244   struct GadgetInfo *next;              /* next list entry */
245 };
246
247 struct GadgetInfo *CreateGadget(int, ...);
248 void FreeGadget(struct GadgetInfo *);
249
250 void ModifyGadget(struct GadgetInfo *, int, ...);
251 void RedrawGadget(struct GadgetInfo *);
252
253 void MapGadget(struct GadgetInfo *);
254 void UnmapGadget(struct GadgetInfo *);
255 void UnmapAllGadgets();
256 void RemapAllGadgets();
257
258 boolean anyTextGadgetActive();
259 void ClickOnGadget(struct GadgetInfo *, int);
260
261 void HandleGadgets(int, int, int);
262 void HandleGadgetsKeyInput(KeySym);
263
264 #endif