rnd-19990216-1
[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_X                           2
134 #define GDI_Y                           3
135 #define GDI_WIDTH                       4
136 #define GDI_HEIGHT                      5
137 #define GDI_TYPE                        6
138 #define GDI_STATE                       7
139 #define GDI_CHECKED                     8
140 #define GDI_RADIO_NR                    9
141 #define GDI_NUMBER_VALUE                10
142 #define GDI_NUMBER_MIN                  11
143 #define GDI_NUMBER_MAX                  12
144 #define GDI_TEXT_VALUE                  13
145 #define GDI_TEXT_SIZE                   14
146 #define GDI_DESIGN_UNPRESSED            15
147 #define GDI_DESIGN_PRESSED              16
148 #define GDI_ALT_DESIGN_UNPRESSED        17
149 #define GDI_ALT_DESIGN_PRESSED          18
150 #define GDI_DESIGN_BORDER               19
151 #define GDI_DECORATION_DESIGN           20
152 #define GDI_DECORATION_POSITION         22
153 #define GDI_DECORATION_SIZE             21
154 #define GDI_DECORATION_SHIFTING         23
155 #define GDI_EVENT_MASK                  24
156 #define GDI_EVENT                       25
157 #define GDI_CALLBACK_INFO               26
158 #define GDI_CALLBACK_ACTION             27
159 #define GDI_AREA_SIZE                   28
160 #define GDI_ITEM_SIZE                   29
161 #define GDI_SCROLLBAR_ITEMS_MAX         30
162 #define GDI_SCROLLBAR_ITEMS_VISIBLE     31
163 #define GDI_SCROLLBAR_ITEM_POSITION     32
164 #define GDI_INFO_TEXT                   33
165
166 typedef void (*gadget_function)(void *);
167
168 struct GadgetDesign
169 {
170   Pixmap pixmap;                        /* Pixmap with gadget surface */
171   int x, y;                             /* position of rectangle in Pixmap */
172 };
173
174 struct GadgetDecoration
175 {
176   struct GadgetDesign design;           /* decoration design structure */
177   int x, y;                             /* position of deco on the gadget */
178   int width, height;                    /* width and height of decoration */
179   int xshift, yshift;                   /* deco shifting when gadget pressed */
180 };
181
182 struct GadgetEvent
183 {
184   unsigned long type;                   /* event type */
185   int button;                           /* button number for button events */
186   int x, y;                             /* gadget position at event time */
187   boolean off_borders;                  /* mouse pointer outside gadget? */
188   int item_x, item_y, item_position;    /* new item position */
189 };
190
191 struct GadgetDrawingArea
192 {
193   int area_xsize, area_ysize;           /* size of drawing area (in items) */
194   int item_xsize, item_ysize;           /* size of each item in drawing area */
195 };
196
197 struct GadgetTextInput
198 {
199   char value[MAX_GADGET_TEXTSIZE];      /* text string in input field */
200   int number_value;                     /* integer value, if numeric */
201   int number_min;                       /* minimal allowed numeric value */
202   int number_max;                       /* maximal allowed numeric value */
203   int size;                             /* maximal size of input text */
204   int cursor_position;                  /* actual cursor position */
205 };
206
207 struct GadgetScrollbar
208 {
209   int items_max;                        /* number of items to access */
210   int items_visible;                    /* number of visible items */
211   int item_position;                    /* actual item position */
212   int size_max;                         /* this is either width or height */
213   int size;                             /* scrollbar size on screen */
214   int position;                         /* scrollbar position on screen */
215   int position_max;                     /* bottom/right scrollbar position */
216   int drag_position;                    /* drag position on scrollbar */
217 };
218
219 struct GadgetInfo
220 {
221   int id;                               /* internal gadget identifier */
222   int custom_id;                        /* custom gadget identifier */
223   char info_text[MAX_INFO_TEXTSIZE];    /* short popup info text */
224   int x, y;                             /* gadget position */
225   int width, height;                    /* gadget size */
226   unsigned long type;                   /* type (button, text input, ...) */
227   unsigned long state;                  /* state (pressed, released, ...) */
228   boolean checked;                      /* check/radio button state */
229   int radio_nr;                         /* number of radio button series */
230   boolean mapped;                       /* gadget is active */
231   struct GadgetDesign design[2];        /* 0: normal; 1: pressed */
232   struct GadgetDesign alt_design[2];    /* alternative design */
233   struct GadgetDecoration deco;         /* decoration on top of gadget */
234   int design_border;                    /* border size of gadget decoration */
235   unsigned long event_mask;             /* possible events for this gadget */
236   struct GadgetEvent event;             /* actual gadget event */
237   gadget_function callback_info;        /* function for pop-up info text */
238   gadget_function callback_action;      /* function for gadget action */
239   struct GadgetDrawingArea drawing;     /* fields for drawing area gadget */
240   struct GadgetTextInput text;          /* fields for text input gadget */
241   struct GadgetScrollbar scrollbar;     /* fields for scrollbar gadget */
242   struct GadgetInfo *next;              /* next list entry */
243 };
244
245 struct GadgetInfo *CreateGadget(int, ...);
246 void FreeGadget(struct GadgetInfo *);
247
248 void ModifyGadget(struct GadgetInfo *, int, ...);
249 void RedrawGadget(struct GadgetInfo *);
250
251 void MapGadget(struct GadgetInfo *);
252 void UnmapGadget(struct GadgetInfo *);
253 void UnmapAllGadgets();
254 void RemapAllGadgets();
255
256 boolean anyTextGadgetActive();
257 void ClickOnGadget(struct GadgetInfo *, int);
258
259 void HandleGadgets(int, int, int);
260 void HandleGadgetsKeyInput(KeySym);
261
262 #endif