e27359015ba8a6212fe5c7fc07e05ef4b9fe7e96
[rocksndiamonds.git] / src / editor.c
1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * editor.c                                                 *
12 ***********************************************************/
13
14 #include <math.h>
15
16 #include "libgame/libgame.h"
17
18 #include "editor.h"
19 #include "screens.h"
20 #include "tools.h"
21 #include "files.h"
22 #include "game.h"
23 #include "init.h"
24 #include "tape.h"
25
26
27 #define INFOTEXT_UNKNOWN_ELEMENT        "unknown"
28
29
30 /*
31   -----------------------------------------------------------------------------
32   screen and artwork graphic pixel position definitions
33   -----------------------------------------------------------------------------
34 */
35
36 /* positions in the level editor */
37 #define ED_WIN_MB_LEFT_XPOS             6
38 #define ED_WIN_MB_LEFT_YPOS             258
39 #define ED_WIN_MB_MIDDLE_XPOS           42
40 #define ED_WIN_MB_MIDDLE_YPOS           ED_WIN_MB_LEFT_YPOS
41 #define ED_WIN_MB_RIGHT_XPOS            78
42 #define ED_WIN_MB_RIGHT_YPOS            ED_WIN_MB_LEFT_YPOS
43
44 /* values for the control window */
45 #define ED_CTRL_NO_BUTTONS_GFX_XPOS     6
46 #define ED_CTRL_NO_BUTTONS_GFX_YPOS     286
47 #define ED_CTRL1_BUTTONS_GFX_YPOS       236
48 #define ED_CTRL2_BUTTONS_GFX_YPOS       236
49 #define ED_CTRL3_BUTTONS_GFX_YPOS       324
50 #define ED_CTRL4_BUTTONS_GFX_XPOS       44
51 #define ED_CTRL4_BUTTONS_GFX_YPOS       214
52 #define ED_CTRL1_BUTTONS_ALT_GFX_YPOS   142
53 #define ED_CTRL3_BUTTONS_ALT_GFX_YPOS   302
54
55 #define ED_CTRL1_BUTTON_XSIZE           22
56 #define ED_CTRL1_BUTTON_YSIZE           22
57 #define ED_CTRL1_BUTTONS_XPOS           6
58 #define ED_CTRL1_BUTTONS_YPOS           6
59 #define ED_CTRL2_BUTTON_XSIZE           30
60 #define ED_CTRL2_BUTTON_YSIZE           20
61 #define ED_CTRL2_BUTTONS_XPOS           5
62 #define ED_CTRL2_BUTTONS_YPOS           99
63 #define ED_CTRL3_BUTTON_XSIZE           22
64 #define ED_CTRL3_BUTTON_YSIZE           22
65 #define ED_CTRL3_BUTTONS_XPOS           6
66 #define ED_CTRL3_BUTTONS_YPOS           6
67 #define ED_CTRL4_BUTTON_XSIZE           22
68 #define ED_CTRL4_BUTTON_YSIZE           22
69 #define ED_CTRL4_BUTTONS_XPOS           6
70 #define ED_CTRL4_BUTTONS_YPOS           6
71
72 #define ED_CTRL1_BUTTONS_HORIZ          4
73 #define ED_CTRL1_BUTTONS_VERT           4
74 #define ED_CTRL2_BUTTONS_HORIZ          3
75 #define ED_CTRL2_BUTTONS_VERT           2
76 #define ED_CTRL3_BUTTONS_HORIZ          3
77 #define ED_CTRL3_BUTTONS_VERT           1
78 #define ED_CTRL4_BUTTONS_HORIZ          2
79 #define ED_CTRL4_BUTTONS_VERT           1
80
81 #define ED_NUM_CTRL1_BUTTONS   (ED_CTRL1_BUTTONS_HORIZ * ED_CTRL1_BUTTONS_VERT)
82 #define ED_NUM_CTRL2_BUTTONS   (ED_CTRL2_BUTTONS_HORIZ * ED_CTRL2_BUTTONS_VERT)
83 #define ED_NUM_CTRL3_BUTTONS   (ED_CTRL3_BUTTONS_HORIZ * ED_CTRL3_BUTTONS_VERT)
84 #define ED_NUM_CTRL4_BUTTONS   (ED_CTRL4_BUTTONS_HORIZ * ED_CTRL4_BUTTONS_VERT)
85 #define ED_NUM_CTRL1_2_BUTTONS (ED_NUM_CTRL1_BUTTONS   + ED_NUM_CTRL2_BUTTONS)
86 #define ED_NUM_CTRL1_3_BUTTONS (ED_NUM_CTRL1_2_BUTTONS + ED_NUM_CTRL3_BUTTONS)
87 #define ED_NUM_CTRL_BUTTONS    (ED_NUM_CTRL1_BUTTONS +  \
88                                 ED_NUM_CTRL2_BUTTONS +  \
89                                 ED_NUM_CTRL3_BUTTONS +  \
90                                 ED_NUM_CTRL4_BUTTONS)
91
92 /* values for the element list */
93 #define ED_ELEMENTLIST_XPOS             5
94 #define ED_ELEMENTLIST_YPOS             30
95 #define ED_ELEMENTLIST_XSIZE            20
96 #define ED_ELEMENTLIST_YSIZE            20
97 #define ED_ELEMENTLIST_BUTTONS_HORIZ    4
98 #define ED_ELEMENTLIST_BUTTONS_VERT     11
99 #define ED_NUM_ELEMENTLIST_BUTTONS      (ED_ELEMENTLIST_BUTTONS_HORIZ * \
100                                          ED_ELEMENTLIST_BUTTONS_VERT)
101
102 /* standard distances */
103 #define ED_BORDER_SIZE                  3
104 #define ED_BORDER_TEXT_XSIZE            5
105 #define ED_BORDER_AREA_YSIZE            1
106
107 #define ED_GADGET_DISTANCE              2
108 #define ED_GADGET_TEXT_DISTANCE         (2 * ED_GADGET_DISTANCE)
109 #define ED_DRAWINGAREA_TEXT_DISTANCE    (ED_GADGET_TEXT_DISTANCE +      \
110                                          MINI_TILEX / 2)
111
112 /* values for the settings windows */
113 #define ED_LEVEL_SETTINGS_XSTART        (3 * MINI_TILEX / 2)
114 #define ED_LEVEL_SETTINGS_YSTART        (5 * MINI_TILEY)
115
116 #define ED_ELEMENT_SETTINGS_XSTART      (3 * MINI_TILEX / 2)
117 #define ED_ELEMENT_SETTINGS_YSTART      (10 * MINI_TILEY)
118
119 #define ED_XOFFSET_CHECKBOX             (ED_CHECKBUTTON_XSIZE +         \
120                                          2 * ED_GADGET_DISTANCE)
121
122 #define ED_SETTINGS_XOFFSET             ED_XOFFSET_CHECKBOX
123 #define ED_SETTINGS_YOFFSET             (3 * MINI_TILEY / 2)
124
125 #define ED_LEVEL_SETTINGS_XPOS(n)       (ED_LEVEL_SETTINGS_XSTART +     \
126                                          (n) * ED_SETTINGS_XOFFSET)
127 #define ED_LEVEL_SETTINGS_YPOS(n)       (ED_LEVEL_SETTINGS_YSTART +     \
128                                          (n) * ED_SETTINGS_YOFFSET)
129
130 #define ED_ELEMENT_SETTINGS_XPOS(n)     (ED_ELEMENT_SETTINGS_XSTART +   \
131                                          (n) * ED_SETTINGS_XOFFSET)
132 #define ED_ELEMENT_SETTINGS_YPOS(n)     (ED_ELEMENT_SETTINGS_YSTART +   \
133                                          (n) * ED_SETTINGS_YOFFSET)
134
135 #define ED_SETTINGS1_YPOS               MINI_TILEY
136 #define ED_SETTINGS2_XPOS               MINI_TILEX
137 #define ED_SETTINGS2_YPOS               (ED_SETTINGS1_YPOS + 12 * TILEY - 2)
138
139 /* values for counter gadgets */
140 #define ED_COUNTER_YSTART               (ED_SETTINGS1_YPOS + 2 * TILEY)
141 #define ED_COUNTER_YDISTANCE            (3 * MINI_TILEY)
142 #define ED_COUNTER_YPOS(n)              (ED_COUNTER_YSTART +            \
143                                          (n) * ED_COUNTER_YDISTANCE)
144 #define ED_COUNTER2_YPOS(n)             (ED_COUNTER_YSTART +            \
145                                          (n) * ED_COUNTER_YDISTANCE - 2)
146
147 /* values for element content drawing areas */
148 #define ED_AREA_1X1_SETTINGS_XPOS(n)    (ED_ELEMENT_SETTINGS_XPOS(n))
149 #define ED_AREA_1X1_SETTINGS_YPOS(n)    (ED_ELEMENT_SETTINGS_YPOS(n) +  \
150                                          ED_GADGET_DISTANCE)
151
152 #define ED_AREA_3X3_SETTINGS_XPOS(n)    (ED_ELEMENT_SETTINGS_XPOS(n))
153 #define ED_AREA_3X3_SETTINGS_YPOS(n)    (ED_ELEMENT_SETTINGS_YPOS(n) +  \
154                                          ED_GADGET_DISTANCE - MINI_TILEY)
155
156 /* yamyam content */
157 #define ED_AREA_YAMYAM_CONTENT_XPOS(n)  (2 * MINI_TILEX +               \
158                                          5 * ((n) % 4) * MINI_TILEX)
159 #define ED_AREA_YAMYAM_CONTENT_YPOS(n)  (11 * ED_SETTINGS_YOFFSET +     \
160                                          6 * ((n) / 4) * MINI_TILEY)
161
162 /* magic ball content */
163 #define ED_AREA_MAGIC_BALL_CONTENT_XPOS(n) (2 * MINI_TILEX +            \
164                                             5 * ((n) % 4) * MINI_TILEX)
165 #define ED_AREA_MAGIC_BALL_CONTENT_YPOS(n) (12 * ED_SETTINGS_YOFFSET +  \
166                                             6 * ((n) / 4) * MINI_TILEY)
167
168 /* values for scrolling gadgets for drawing area */
169 #define ED_SCROLLBUTTON_XPOS            24
170 #define ED_SCROLLBUTTON_YPOS            0
171 #define ED_SCROLLBAR_XPOS               24
172 #define ED_SCROLLBAR_YPOS               64
173
174 #define ED_SCROLLBUTTON_XSIZE           16
175 #define ED_SCROLLBUTTON_YSIZE           16
176
177 #define ED_SCROLL_UP_XPOS               (SXSIZE - ED_SCROLLBUTTON_XSIZE)
178 #define ED_SCROLL_UP_YPOS               (0)
179 #define ED_SCROLL_DOWN_XPOS             ED_SCROLL_UP_XPOS
180 #define ED_SCROLL_DOWN_YPOS             (SYSIZE - 3 * ED_SCROLLBUTTON_YSIZE)
181 #define ED_SCROLL_LEFT_XPOS             (0)
182 #define ED_SCROLL_LEFT_YPOS             (SYSIZE - 2 * ED_SCROLLBUTTON_YSIZE)
183 #define ED_SCROLL_RIGHT_XPOS            (SXSIZE - 2 * ED_SCROLLBUTTON_XSIZE)
184 #define ED_SCROLL_RIGHT_YPOS            ED_SCROLL_LEFT_YPOS
185 #define ED_SCROLL_HORIZONTAL_XPOS       (ED_SCROLL_LEFT_XPOS +          \
186                                          ED_SCROLLBUTTON_XSIZE)
187 #define ED_SCROLL_HORIZONTAL_YPOS       ED_SCROLL_LEFT_YPOS
188 #define ED_SCROLL_HORIZONTAL_XSIZE      (SXSIZE - 3 * ED_SCROLLBUTTON_XSIZE)
189 #define ED_SCROLL_HORIZONTAL_YSIZE      ED_SCROLLBUTTON_YSIZE
190 #define ED_SCROLL_VERTICAL_XPOS         ED_SCROLL_UP_XPOS
191 #define ED_SCROLL_VERTICAL_YPOS         (ED_SCROLL_UP_YPOS +            \
192                                          ED_SCROLLBUTTON_YSIZE)
193 #define ED_SCROLL_VERTICAL_XSIZE        ED_SCROLLBUTTON_XSIZE
194 #define ED_SCROLL_VERTICAL_YSIZE        (SYSIZE - 4 * ED_SCROLLBUTTON_YSIZE)
195
196 /* values for scrolling gadgets for element list */
197 #define ED_SCROLLBUTTON2_XPOS           50
198 #define ED_SCROLLBUTTON2_YPOS           0
199 #define ED_SCROLLBAR2_XPOS              50
200 #define ED_SCROLLBAR2_YPOS              20
201
202 #define ED_SCROLLBUTTON2_XSIZE          10
203 #define ED_SCROLLBUTTON2_YSIZE          10
204
205 #define ED_SCROLL2_UP_XPOS              85
206 #define ED_SCROLL2_UP_YPOS              30
207 #define ED_SCROLL2_DOWN_XPOS            ED_SCROLL2_UP_XPOS
208 #define ED_SCROLL2_DOWN_YPOS            (ED_SCROLL2_UP_YPOS +           \
209                                          ED_ELEMENTLIST_BUTTONS_VERT *  \
210                                          ED_ELEMENTLIST_YSIZE -         \
211                                          ED_SCROLLBUTTON2_YSIZE)
212 #define ED_SCROLL2_VERTICAL_XPOS        ED_SCROLL2_UP_XPOS
213 #define ED_SCROLL2_VERTICAL_YPOS        (ED_SCROLL2_UP_YPOS +           \
214                                          ED_SCROLLBUTTON2_YSIZE)
215 #define ED_SCROLL2_VERTICAL_XSIZE       ED_SCROLLBUTTON2_XSIZE
216 #define ED_SCROLL2_VERTICAL_YSIZE       (ED_ELEMENTLIST_BUTTONS_VERT *  \
217                                          ED_ELEMENTLIST_YSIZE -         \
218                                          2 * ED_SCROLLBUTTON2_YSIZE)
219
220 /* values for checkbutton gadgets */
221 #define ED_CHECKBUTTON_XSIZE            ED_BUTTON_COUNT_XSIZE
222 #define ED_CHECKBUTTON_YSIZE            ED_BUTTON_COUNT_YSIZE
223 #define ED_CHECKBUTTON_UNCHECKED_XPOS   ED_BUTTON_MINUS_XPOS
224 #define ED_CHECKBUTTON_CHECKED_XPOS     ED_BUTTON_PLUS_XPOS
225 #define ED_CHECKBUTTON_YPOS             (ED_BUTTON_MINUS_YPOS + 22)
226 #define ED_RADIOBUTTON_YPOS             (ED_BUTTON_MINUS_YPOS + 44)
227 #define ED_STICKYBUTTON_YPOS            (ED_BUTTON_MINUS_YPOS + 66)
228
229 /* values for some special graphic buttons */
230 #define ED_COPY_CHANGE_PAGE_XPOS        25
231 #define ED_COPY_CHANGE_PAGE_YPOS        50
232 #define ED_PASTE_CHANGE_PAGE_XPOS       25
233 #define ED_PASTE_CHANGE_PAGE_YPOS       70
234
235 /* some values for text input, selectbox and counter gadgets */
236 #define ED_BUTTON_COUNT_YPOS            60
237 #define ED_BUTTON_COUNT_XSIZE           20
238 #define ED_BUTTON_COUNT_YSIZE           20
239 #define ED_WIN_COUNT_XPOS               (2 + ED_BUTTON_COUNT_XSIZE + 2)
240 #define ED_WIN_COUNT_YPOS               ED_BUTTON_COUNT_YPOS
241 #define ED_WIN_COUNT_XSIZE              52
242 #define ED_WIN_COUNT_YSIZE              ED_BUTTON_COUNT_YSIZE
243 #define ED_WIN_COUNT2_XPOS              27
244 #define ED_WIN_COUNT2_YPOS              3
245 #define ED_WIN_COUNT2_XSIZE             46
246 #define ED_WIN_COUNT2_YSIZE             ED_BUTTON_COUNT_YSIZE
247
248 #define ED_BUTTON_MINUS_XPOS            2
249 #define ED_BUTTON_MINUS_YPOS            ED_BUTTON_COUNT_YPOS
250 #define ED_BUTTON_MINUS_XSIZE           ED_BUTTON_COUNT_XSIZE
251 #define ED_BUTTON_MINUS_YSIZE           ED_BUTTON_COUNT_YSIZE
252 #define ED_BUTTON_PLUS_XPOS             (ED_WIN_COUNT_XPOS +            \
253                                          ED_WIN_COUNT_XSIZE + 2)
254 #define ED_BUTTON_PLUS_YPOS             ED_BUTTON_COUNT_YPOS
255 #define ED_BUTTON_PLUS_XSIZE            ED_BUTTON_COUNT_XSIZE
256 #define ED_BUTTON_PLUS_YSIZE            ED_BUTTON_COUNT_YSIZE
257
258 #define ED_SELECTBOX_XPOS               ED_WIN_COUNT_XPOS
259 #define ED_SELECTBOX_YPOS               (ED_WIN_COUNT_YPOS +            \
260                                          2 + ED_WIN_COUNT_YSIZE)
261 #define ED_SELECTBOX_XSIZE              ED_WIN_COUNT_XSIZE
262 #define ED_SELECTBOX_YSIZE              ED_WIN_COUNT_YSIZE
263
264 #define ED_SELECTBOX_BUTTON_XSIZE       14
265
266 #define ED_TEXTBUTTON_XPOS              ED_WIN_COUNT_XPOS
267 #define ED_TEXTBUTTON_YPOS              (ED_WIN_COUNT_YPOS +            \
268                                          4 * (2 + ED_WIN_COUNT_YSIZE))
269 #define ED_TEXTBUTTON_INACTIVE_YPOS     ED_TEXTBUTTON_YPOS
270
271 #define ED_TEXTBUTTON_TAB_XPOS          ED_WIN_COUNT_XPOS
272 #define ED_TEXTBUTTON_TAB_YPOS          (ED_WIN_COUNT_YPOS +            \
273                                          2 * (2 + ED_WIN_COUNT_YSIZE))
274 #define ED_TEXTBUTTON_TAB_INACTIVE_YPOS (ED_WIN_COUNT_YPOS +            \
275                                          3 * (2 + ED_WIN_COUNT_YSIZE))
276
277 #define ED_TEXTBUTTON_XSIZE             ED_WIN_COUNT_XSIZE
278 #define ED_TEXTBUTTON_YSIZE             ED_WIN_COUNT_YSIZE
279
280 /* values for ClearEditorGadgetInfoText() and HandleEditorGadgetInfoText() */
281 #define INFOTEXT_XPOS                   SX
282 #define INFOTEXT_YPOS                   (SY + SYSIZE - MINI_TILEX + 2)
283 #define INFOTEXT_XSIZE                  SXSIZE
284 #define INFOTEXT_YSIZE                  MINI_TILEX
285
286
287 /*
288   -----------------------------------------------------------------------------
289   editor gadget definitions
290   -----------------------------------------------------------------------------
291 */
292
293 /* drawing toolbox buttons */
294 #define GADGET_ID_NONE                  -1
295 #define GADGET_ID_TOOLBOX_FIRST         0
296
297 #define GADGET_ID_SINGLE_ITEMS          (GADGET_ID_TOOLBOX_FIRST + 0)
298 #define GADGET_ID_CONNECTED_ITEMS       (GADGET_ID_TOOLBOX_FIRST + 1)
299 #define GADGET_ID_LINE                  (GADGET_ID_TOOLBOX_FIRST + 2)
300 #define GADGET_ID_ARC                   (GADGET_ID_TOOLBOX_FIRST + 3)
301 #define GADGET_ID_RECTANGLE             (GADGET_ID_TOOLBOX_FIRST + 4)
302 #define GADGET_ID_FILLED_BOX            (GADGET_ID_TOOLBOX_FIRST + 5)
303 #define GADGET_ID_WRAP_UP               (GADGET_ID_TOOLBOX_FIRST + 6)
304 #define GADGET_ID_TEXT                  (GADGET_ID_TOOLBOX_FIRST + 7)
305 #define GADGET_ID_FLOOD_FILL            (GADGET_ID_TOOLBOX_FIRST + 8)
306 #define GADGET_ID_WRAP_LEFT             (GADGET_ID_TOOLBOX_FIRST + 9)
307 #define GADGET_ID_PROPERTIES            (GADGET_ID_TOOLBOX_FIRST + 10)
308 #define GADGET_ID_WRAP_RIGHT            (GADGET_ID_TOOLBOX_FIRST + 11)
309 #define GADGET_ID_RANDOM_PLACEMENT      (GADGET_ID_TOOLBOX_FIRST + 12)
310 #define GADGET_ID_GRAB_BRUSH            (GADGET_ID_TOOLBOX_FIRST + 13)
311 #define GADGET_ID_WRAP_DOWN             (GADGET_ID_TOOLBOX_FIRST + 14)
312 #define GADGET_ID_PICK_ELEMENT          (GADGET_ID_TOOLBOX_FIRST + 15)
313
314 #define GADGET_ID_UNDO                  (GADGET_ID_TOOLBOX_FIRST + 16)
315 #define GADGET_ID_INFO                  (GADGET_ID_TOOLBOX_FIRST + 17)
316 #define GADGET_ID_SAVE                  (GADGET_ID_TOOLBOX_FIRST + 18)
317 #define GADGET_ID_CLEAR                 (GADGET_ID_TOOLBOX_FIRST + 19)
318 #define GADGET_ID_TEST                  (GADGET_ID_TOOLBOX_FIRST + 20)
319 #define GADGET_ID_EXIT                  (GADGET_ID_TOOLBOX_FIRST + 21)
320
321 #define GADGET_ID_CUSTOM_COPY_FROM      (GADGET_ID_TOOLBOX_FIRST + 22)
322 #define GADGET_ID_CUSTOM_COPY_TO        (GADGET_ID_TOOLBOX_FIRST + 23)
323 #define GADGET_ID_CUSTOM_EXCHANGE       (GADGET_ID_TOOLBOX_FIRST + 24)
324 #define GADGET_ID_CUSTOM_COPY           (GADGET_ID_TOOLBOX_FIRST + 25)
325 #define GADGET_ID_CUSTOM_PASTE          (GADGET_ID_TOOLBOX_FIRST + 26)
326
327 /* counter button identifiers */
328 #define GADGET_ID_COUNTER_FIRST         (GADGET_ID_TOOLBOX_FIRST + 27)
329
330 #define GADGET_ID_SELECT_LEVEL_DOWN     (GADGET_ID_COUNTER_FIRST + 0)
331 #define GADGET_ID_SELECT_LEVEL_TEXT     (GADGET_ID_COUNTER_FIRST + 1)
332 #define GADGET_ID_SELECT_LEVEL_UP       (GADGET_ID_COUNTER_FIRST + 2)
333 #define GADGET_ID_LEVEL_XSIZE_DOWN      (GADGET_ID_COUNTER_FIRST + 3)
334 #define GADGET_ID_LEVEL_XSIZE_TEXT      (GADGET_ID_COUNTER_FIRST + 4)
335 #define GADGET_ID_LEVEL_XSIZE_UP        (GADGET_ID_COUNTER_FIRST + 5)
336 #define GADGET_ID_LEVEL_YSIZE_DOWN      (GADGET_ID_COUNTER_FIRST + 6)
337 #define GADGET_ID_LEVEL_YSIZE_TEXT      (GADGET_ID_COUNTER_FIRST + 7)
338 #define GADGET_ID_LEVEL_YSIZE_UP        (GADGET_ID_COUNTER_FIRST + 8)
339 #define GADGET_ID_LEVEL_RANDOM_DOWN     (GADGET_ID_COUNTER_FIRST + 9)
340 #define GADGET_ID_LEVEL_RANDOM_TEXT     (GADGET_ID_COUNTER_FIRST + 10)
341 #define GADGET_ID_LEVEL_RANDOM_UP       (GADGET_ID_COUNTER_FIRST + 11)
342 #define GADGET_ID_LEVEL_GEMSLIMIT_DOWN  (GADGET_ID_COUNTER_FIRST + 12)
343 #define GADGET_ID_LEVEL_GEMSLIMIT_TEXT  (GADGET_ID_COUNTER_FIRST + 13)
344 #define GADGET_ID_LEVEL_GEMSLIMIT_UP    (GADGET_ID_COUNTER_FIRST + 14)
345 #define GADGET_ID_LEVEL_TIMELIMIT_DOWN  (GADGET_ID_COUNTER_FIRST + 15)
346 #define GADGET_ID_LEVEL_TIMELIMIT_TEXT  (GADGET_ID_COUNTER_FIRST + 16)
347 #define GADGET_ID_LEVEL_TIMELIMIT_UP    (GADGET_ID_COUNTER_FIRST + 17)
348 #define GADGET_ID_LEVEL_TIMESCORE_DOWN  (GADGET_ID_COUNTER_FIRST + 18)
349 #define GADGET_ID_LEVEL_TIMESCORE_TEXT  (GADGET_ID_COUNTER_FIRST + 19)
350 #define GADGET_ID_LEVEL_TIMESCORE_UP    (GADGET_ID_COUNTER_FIRST + 20)
351 #define GADGET_ID_ELEMENT_VALUE1_DOWN   (GADGET_ID_COUNTER_FIRST + 21)
352 #define GADGET_ID_ELEMENT_VALUE1_TEXT   (GADGET_ID_COUNTER_FIRST + 22)
353 #define GADGET_ID_ELEMENT_VALUE1_UP     (GADGET_ID_COUNTER_FIRST + 23)
354 #define GADGET_ID_ELEMENT_VALUE2_DOWN   (GADGET_ID_COUNTER_FIRST + 24)
355 #define GADGET_ID_ELEMENT_VALUE2_TEXT   (GADGET_ID_COUNTER_FIRST + 25)
356 #define GADGET_ID_ELEMENT_VALUE2_UP     (GADGET_ID_COUNTER_FIRST + 26)
357 #define GADGET_ID_ELEMENT_VALUE3_DOWN   (GADGET_ID_COUNTER_FIRST + 27)
358 #define GADGET_ID_ELEMENT_VALUE3_TEXT   (GADGET_ID_COUNTER_FIRST + 28)
359 #define GADGET_ID_ELEMENT_VALUE3_UP     (GADGET_ID_COUNTER_FIRST + 29)
360 #define GADGET_ID_ELEMENT_VALUE4_DOWN   (GADGET_ID_COUNTER_FIRST + 30)
361 #define GADGET_ID_ELEMENT_VALUE4_TEXT   (GADGET_ID_COUNTER_FIRST + 31)
362 #define GADGET_ID_ELEMENT_VALUE4_UP     (GADGET_ID_COUNTER_FIRST + 32)
363 #define GADGET_ID_YAMYAM_CONTENT_DOWN   (GADGET_ID_COUNTER_FIRST + 33)
364 #define GADGET_ID_YAMYAM_CONTENT_TEXT   (GADGET_ID_COUNTER_FIRST + 34)
365 #define GADGET_ID_YAMYAM_CONTENT_UP     (GADGET_ID_COUNTER_FIRST + 35)
366 #define GADGET_ID_BALL_CONTENT_DOWN     (GADGET_ID_COUNTER_FIRST + 36)
367 #define GADGET_ID_BALL_CONTENT_TEXT     (GADGET_ID_COUNTER_FIRST + 37)
368 #define GADGET_ID_BALL_CONTENT_UP       (GADGET_ID_COUNTER_FIRST + 38)
369 #define GADGET_ID_ENVELOPE_XSIZE_DOWN   (GADGET_ID_COUNTER_FIRST + 39)
370 #define GADGET_ID_ENVELOPE_XSIZE_TEXT   (GADGET_ID_COUNTER_FIRST + 40)
371 #define GADGET_ID_ENVELOPE_XSIZE_UP     (GADGET_ID_COUNTER_FIRST + 41)
372 #define GADGET_ID_ENVELOPE_YSIZE_DOWN   (GADGET_ID_COUNTER_FIRST + 42)
373 #define GADGET_ID_ENVELOPE_YSIZE_TEXT   (GADGET_ID_COUNTER_FIRST + 43)
374 #define GADGET_ID_ENVELOPE_YSIZE_UP     (GADGET_ID_COUNTER_FIRST + 44)
375 #define GADGET_ID_CUSTOM_SCORE_DOWN     (GADGET_ID_COUNTER_FIRST + 45)
376 #define GADGET_ID_CUSTOM_SCORE_TEXT     (GADGET_ID_COUNTER_FIRST + 46)
377 #define GADGET_ID_CUSTOM_SCORE_UP       (GADGET_ID_COUNTER_FIRST + 47)
378 #define GADGET_ID_CUSTOM_GEMCOUNT_DOWN  (GADGET_ID_COUNTER_FIRST + 48)
379 #define GADGET_ID_CUSTOM_GEMCOUNT_TEXT  (GADGET_ID_COUNTER_FIRST + 49)
380 #define GADGET_ID_CUSTOM_GEMCOUNT_UP    (GADGET_ID_COUNTER_FIRST + 50)
381 #define GADGET_ID_CUSTOM_VALUE_FIX_DOWN (GADGET_ID_COUNTER_FIRST + 51)
382 #define GADGET_ID_CUSTOM_VALUE_FIX_TEXT (GADGET_ID_COUNTER_FIRST + 52)
383 #define GADGET_ID_CUSTOM_VALUE_FIX_UP   (GADGET_ID_COUNTER_FIRST + 53)
384 #define GADGET_ID_CUSTOM_VALUE_RND_DOWN (GADGET_ID_COUNTER_FIRST + 54)
385 #define GADGET_ID_CUSTOM_VALUE_RND_TEXT (GADGET_ID_COUNTER_FIRST + 55)
386 #define GADGET_ID_CUSTOM_VALUE_RND_UP   (GADGET_ID_COUNTER_FIRST + 56)
387 #define GADGET_ID_PUSH_DELAY_FIX_DOWN   (GADGET_ID_COUNTER_FIRST + 57)
388 #define GADGET_ID_PUSH_DELAY_FIX_TEXT   (GADGET_ID_COUNTER_FIRST + 58)
389 #define GADGET_ID_PUSH_DELAY_FIX_UP     (GADGET_ID_COUNTER_FIRST + 59)
390 #define GADGET_ID_PUSH_DELAY_RND_DOWN   (GADGET_ID_COUNTER_FIRST + 60)
391 #define GADGET_ID_PUSH_DELAY_RND_TEXT   (GADGET_ID_COUNTER_FIRST + 61)
392 #define GADGET_ID_PUSH_DELAY_RND_UP     (GADGET_ID_COUNTER_FIRST + 62)
393 #define GADGET_ID_DROP_DELAY_FIX_DOWN   (GADGET_ID_COUNTER_FIRST + 63)
394 #define GADGET_ID_DROP_DELAY_FIX_TEXT   (GADGET_ID_COUNTER_FIRST + 64)
395 #define GADGET_ID_DROP_DELAY_FIX_UP     (GADGET_ID_COUNTER_FIRST + 65)
396 #define GADGET_ID_DROP_DELAY_RND_DOWN   (GADGET_ID_COUNTER_FIRST + 66)
397 #define GADGET_ID_DROP_DELAY_RND_TEXT   (GADGET_ID_COUNTER_FIRST + 67)
398 #define GADGET_ID_DROP_DELAY_RND_UP     (GADGET_ID_COUNTER_FIRST + 68)
399 #define GADGET_ID_MOVE_DELAY_FIX_DOWN   (GADGET_ID_COUNTER_FIRST + 69)
400 #define GADGET_ID_MOVE_DELAY_FIX_TEXT   (GADGET_ID_COUNTER_FIRST + 70)
401 #define GADGET_ID_MOVE_DELAY_FIX_UP     (GADGET_ID_COUNTER_FIRST + 71)
402 #define GADGET_ID_MOVE_DELAY_RND_DOWN   (GADGET_ID_COUNTER_FIRST + 72)
403 #define GADGET_ID_MOVE_DELAY_RND_TEXT   (GADGET_ID_COUNTER_FIRST + 73)
404 #define GADGET_ID_MOVE_DELAY_RND_UP     (GADGET_ID_COUNTER_FIRST + 74)
405 #define GADGET_ID_EXPLOSION_DELAY_DOWN  (GADGET_ID_COUNTER_FIRST + 75)
406 #define GADGET_ID_EXPLOSION_DELAY_TEXT  (GADGET_ID_COUNTER_FIRST + 76)
407 #define GADGET_ID_EXPLOSION_DELAY_UP    (GADGET_ID_COUNTER_FIRST + 77)
408 #define GADGET_ID_IGNITION_DELAY_DOWN   (GADGET_ID_COUNTER_FIRST + 78)
409 #define GADGET_ID_IGNITION_DELAY_TEXT   (GADGET_ID_COUNTER_FIRST + 79)
410 #define GADGET_ID_IGNITION_DELAY_UP     (GADGET_ID_COUNTER_FIRST + 80)
411 #define GADGET_ID_CHANGE_DELAY_FIX_DOWN (GADGET_ID_COUNTER_FIRST + 81)
412 #define GADGET_ID_CHANGE_DELAY_FIX_TEXT (GADGET_ID_COUNTER_FIRST + 82)
413 #define GADGET_ID_CHANGE_DELAY_FIX_UP   (GADGET_ID_COUNTER_FIRST + 83)
414 #define GADGET_ID_CHANGE_DELAY_RND_DOWN (GADGET_ID_COUNTER_FIRST + 84)
415 #define GADGET_ID_CHANGE_DELAY_RND_TEXT (GADGET_ID_COUNTER_FIRST + 85)
416 #define GADGET_ID_CHANGE_DELAY_RND_UP   (GADGET_ID_COUNTER_FIRST + 86)
417 #define GADGET_ID_CHANGE_CONT_RND_DOWN  (GADGET_ID_COUNTER_FIRST + 87)
418 #define GADGET_ID_CHANGE_CONT_RND_TEXT  (GADGET_ID_COUNTER_FIRST + 88)
419 #define GADGET_ID_CHANGE_CONT_RND_UP    (GADGET_ID_COUNTER_FIRST + 89)
420 #define GADGET_ID_GROUP_CONTENT_DOWN    (GADGET_ID_COUNTER_FIRST + 90)
421 #define GADGET_ID_GROUP_CONTENT_TEXT    (GADGET_ID_COUNTER_FIRST + 91)
422 #define GADGET_ID_GROUP_CONTENT_UP      (GADGET_ID_COUNTER_FIRST + 92)
423
424 /* drawing area identifiers */
425 #define GADGET_ID_DRAWING_AREA_FIRST    (GADGET_ID_COUNTER_FIRST + 93)
426
427 #define GADGET_ID_DRAWING_LEVEL         (GADGET_ID_DRAWING_AREA_FIRST + 0)
428 #define GADGET_ID_YAMYAM_CONTENT_0      (GADGET_ID_DRAWING_AREA_FIRST + 1)
429 #define GADGET_ID_YAMYAM_CONTENT_1      (GADGET_ID_DRAWING_AREA_FIRST + 2)
430 #define GADGET_ID_YAMYAM_CONTENT_2      (GADGET_ID_DRAWING_AREA_FIRST + 3)
431 #define GADGET_ID_YAMYAM_CONTENT_3      (GADGET_ID_DRAWING_AREA_FIRST + 4)
432 #define GADGET_ID_YAMYAM_CONTENT_4      (GADGET_ID_DRAWING_AREA_FIRST + 5)
433 #define GADGET_ID_YAMYAM_CONTENT_5      (GADGET_ID_DRAWING_AREA_FIRST + 6)
434 #define GADGET_ID_YAMYAM_CONTENT_6      (GADGET_ID_DRAWING_AREA_FIRST + 7)
435 #define GADGET_ID_YAMYAM_CONTENT_7      (GADGET_ID_DRAWING_AREA_FIRST + 8)
436 #define GADGET_ID_MAGIC_BALL_CONTENT_0  (GADGET_ID_DRAWING_AREA_FIRST + 9)
437 #define GADGET_ID_MAGIC_BALL_CONTENT_1  (GADGET_ID_DRAWING_AREA_FIRST + 10)
438 #define GADGET_ID_MAGIC_BALL_CONTENT_2  (GADGET_ID_DRAWING_AREA_FIRST + 11)
439 #define GADGET_ID_MAGIC_BALL_CONTENT_3  (GADGET_ID_DRAWING_AREA_FIRST + 12)
440 #define GADGET_ID_MAGIC_BALL_CONTENT_4  (GADGET_ID_DRAWING_AREA_FIRST + 13)
441 #define GADGET_ID_MAGIC_BALL_CONTENT_5  (GADGET_ID_DRAWING_AREA_FIRST + 14)
442 #define GADGET_ID_MAGIC_BALL_CONTENT_6  (GADGET_ID_DRAWING_AREA_FIRST + 15)
443 #define GADGET_ID_MAGIC_BALL_CONTENT_7  (GADGET_ID_DRAWING_AREA_FIRST + 16)
444 #define GADGET_ID_AMOEBA_CONTENT        (GADGET_ID_DRAWING_AREA_FIRST + 17)
445 #define GADGET_ID_START_ELEMENT         (GADGET_ID_DRAWING_AREA_FIRST + 18)
446 #define GADGET_ID_ARTWORK_ELEMENT       (GADGET_ID_DRAWING_AREA_FIRST + 19)
447 #define GADGET_ID_EXPLOSION_ELEMENT     (GADGET_ID_DRAWING_AREA_FIRST + 20)
448 #define GADGET_ID_CUSTOM_GRAPHIC        (GADGET_ID_DRAWING_AREA_FIRST + 21)
449 #define GADGET_ID_CUSTOM_CONTENT        (GADGET_ID_DRAWING_AREA_FIRST + 22)
450 #define GADGET_ID_CUSTOM_MOVE_ENTER     (GADGET_ID_DRAWING_AREA_FIRST + 23)
451 #define GADGET_ID_CUSTOM_MOVE_LEAVE     (GADGET_ID_DRAWING_AREA_FIRST + 24)
452 #define GADGET_ID_CUSTOM_CHANGE_TARGET  (GADGET_ID_DRAWING_AREA_FIRST + 25)
453 #define GADGET_ID_CUSTOM_CHANGE_CONTENT (GADGET_ID_DRAWING_AREA_FIRST + 26)
454 #define GADGET_ID_CUSTOM_CHANGE_TRIGGER (GADGET_ID_DRAWING_AREA_FIRST + 27)
455 #define GADGET_ID_GROUP_CONTENT         (GADGET_ID_DRAWING_AREA_FIRST + 28)
456 #define GADGET_ID_RANDOM_BACKGROUND     (GADGET_ID_DRAWING_AREA_FIRST + 29)
457
458 /* text input identifiers */
459 #define GADGET_ID_TEXT_INPUT_FIRST      (GADGET_ID_DRAWING_AREA_FIRST + 30)
460
461 #define GADGET_ID_LEVEL_NAME            (GADGET_ID_TEXT_INPUT_FIRST + 0)
462 #define GADGET_ID_LEVEL_AUTHOR          (GADGET_ID_TEXT_INPUT_FIRST + 1)
463 #define GADGET_ID_ELEMENT_NAME          (GADGET_ID_TEXT_INPUT_FIRST + 2)
464
465 /* text area identifiers */
466 #define GADGET_ID_TEXT_AREA_FIRST       (GADGET_ID_TEXT_INPUT_FIRST + 3)
467
468 #define GADGET_ID_ENVELOPE_INFO         (GADGET_ID_TEXT_AREA_FIRST + 0)
469
470 /* selectbox identifiers */
471 #define GADGET_ID_SELECTBOX_FIRST       (GADGET_ID_TEXT_AREA_FIRST + 1)
472
473 #define GADGET_ID_TIME_OR_STEPS         (GADGET_ID_SELECTBOX_FIRST + 0)
474 #define GADGET_ID_GAME_ENGINE_TYPE      (GADGET_ID_SELECTBOX_FIRST + 1)
475 #define GADGET_ID_WIND_DIRECTION        (GADGET_ID_SELECTBOX_FIRST + 2)
476 #define GADGET_ID_CUSTOM_WALK_TO_ACTION (GADGET_ID_SELECTBOX_FIRST + 3)
477 #define GADGET_ID_CUSTOM_EXPLOSION_TYPE (GADGET_ID_SELECTBOX_FIRST + 4)
478 #define GADGET_ID_CUSTOM_DEADLINESS     (GADGET_ID_SELECTBOX_FIRST + 5)
479 #define GADGET_ID_CUSTOM_MOVE_PATTERN   (GADGET_ID_SELECTBOX_FIRST + 6)
480 #define GADGET_ID_CUSTOM_MOVE_DIRECTION (GADGET_ID_SELECTBOX_FIRST + 7)
481 #define GADGET_ID_CUSTOM_MOVE_STEPSIZE  (GADGET_ID_SELECTBOX_FIRST + 8)
482 #define GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE (GADGET_ID_SELECTBOX_FIRST + 9)
483 #define GADGET_ID_CUSTOM_SMASH_TARGETS  (GADGET_ID_SELECTBOX_FIRST + 10)
484 #define GADGET_ID_CUSTOM_SLIPPERY_TYPE  (GADGET_ID_SELECTBOX_FIRST + 11)
485 #define GADGET_ID_CUSTOM_ACCESS_TYPE    (GADGET_ID_SELECTBOX_FIRST + 12)
486 #define GADGET_ID_CUSTOM_ACCESS_LAYER   (GADGET_ID_SELECTBOX_FIRST + 13)
487 #define GADGET_ID_CUSTOM_ACCESS_PROTECTED (GADGET_ID_SELECTBOX_FIRST + 14)
488 #define GADGET_ID_CUSTOM_ACCESS_DIRECTION (GADGET_ID_SELECTBOX_FIRST + 15)
489 #define GADGET_ID_CHANGE_TIME_UNITS     (GADGET_ID_SELECTBOX_FIRST + 16)
490 #define GADGET_ID_CHANGE_DIRECT_ACTION  (GADGET_ID_SELECTBOX_FIRST + 17)
491 #define GADGET_ID_CHANGE_OTHER_ACTION   (GADGET_ID_SELECTBOX_FIRST + 18)
492 #define GADGET_ID_CHANGE_SIDE           (GADGET_ID_SELECTBOX_FIRST + 19)
493 #define GADGET_ID_CHANGE_PLAYER         (GADGET_ID_SELECTBOX_FIRST + 20)
494 #define GADGET_ID_CHANGE_PAGE           (GADGET_ID_SELECTBOX_FIRST + 21)
495 #define GADGET_ID_CHANGE_REPLACE_WHEN   (GADGET_ID_SELECTBOX_FIRST + 22)
496 #define GADGET_ID_ACTION_TYPE           (GADGET_ID_SELECTBOX_FIRST + 23)
497 #define GADGET_ID_ACTION_MODE           (GADGET_ID_SELECTBOX_FIRST + 24)
498 #define GADGET_ID_ACTION_ARG            (GADGET_ID_SELECTBOX_FIRST + 25)
499 #define GADGET_ID_SELECT_CHANGE_PAGE    (GADGET_ID_SELECTBOX_FIRST + 26)
500 #define GADGET_ID_GROUP_CHOICE_MODE     (GADGET_ID_SELECTBOX_FIRST + 27)
501
502 /* textbutton identifiers */
503 #define GADGET_ID_TEXTBUTTON_FIRST      (GADGET_ID_SELECTBOX_FIRST + 28)
504
505 #define GADGET_ID_PROPERTIES_INFO       (GADGET_ID_TEXTBUTTON_FIRST + 0)
506 #define GADGET_ID_PROPERTIES_CONFIG     (GADGET_ID_TEXTBUTTON_FIRST + 1)
507 #define GADGET_ID_PROPERTIES_CONFIG_1   (GADGET_ID_TEXTBUTTON_FIRST + 2)
508 #define GADGET_ID_PROPERTIES_CONFIG_2   (GADGET_ID_TEXTBUTTON_FIRST + 3)
509 #define GADGET_ID_PROPERTIES_CHANGE     (GADGET_ID_TEXTBUTTON_FIRST + 4)
510 #define GADGET_ID_SAVE_AS_TEMPLATE      (GADGET_ID_TEXTBUTTON_FIRST + 5)
511 #define GADGET_ID_ADD_CHANGE_PAGE       (GADGET_ID_TEXTBUTTON_FIRST + 6)
512 #define GADGET_ID_DEL_CHANGE_PAGE       (GADGET_ID_TEXTBUTTON_FIRST + 7)
513
514 /* graphicbutton identifiers */
515 #define GADGET_ID_GRAPHICBUTTON_FIRST   (GADGET_ID_TEXTBUTTON_FIRST + 8)
516
517 #define GADGET_ID_PREV_CHANGE_PAGE      (GADGET_ID_GRAPHICBUTTON_FIRST + 0)
518 #define GADGET_ID_NEXT_CHANGE_PAGE      (GADGET_ID_GRAPHICBUTTON_FIRST + 1)
519 #define GADGET_ID_COPY_CHANGE_PAGE      (GADGET_ID_GRAPHICBUTTON_FIRST + 2)
520 #define GADGET_ID_PASTE_CHANGE_PAGE     (GADGET_ID_GRAPHICBUTTON_FIRST + 3)
521
522 /* gadgets for scrolling of drawing area */
523 #define GADGET_ID_SCROLLING_FIRST       (GADGET_ID_GRAPHICBUTTON_FIRST + 4)
524
525 #define GADGET_ID_SCROLL_UP             (GADGET_ID_SCROLLING_FIRST + 0)
526 #define GADGET_ID_SCROLL_DOWN           (GADGET_ID_SCROLLING_FIRST + 1)
527 #define GADGET_ID_SCROLL_LEFT           (GADGET_ID_SCROLLING_FIRST + 2)
528 #define GADGET_ID_SCROLL_RIGHT          (GADGET_ID_SCROLLING_FIRST + 3)
529 #define GADGET_ID_SCROLL_HORIZONTAL     (GADGET_ID_SCROLLING_FIRST + 4)
530 #define GADGET_ID_SCROLL_VERTICAL       (GADGET_ID_SCROLLING_FIRST + 5)
531
532 /* gadgets for scrolling element list */
533 #define GADGET_ID_SCROLLING_LIST_FIRST  (GADGET_ID_SCROLLING_FIRST + 6)
534
535 #define GADGET_ID_SCROLL_LIST_UP        (GADGET_ID_SCROLLING_LIST_FIRST + 0)
536 #define GADGET_ID_SCROLL_LIST_DOWN      (GADGET_ID_SCROLLING_LIST_FIRST + 1)
537 #define GADGET_ID_SCROLL_LIST_VERTICAL  (GADGET_ID_SCROLLING_LIST_FIRST + 2)
538
539 /* checkbuttons/radiobuttons for level/element properties */
540 #define GADGET_ID_CHECKBUTTON_FIRST     (GADGET_ID_SCROLLING_LIST_FIRST + 3)
541
542 #define GADGET_ID_RANDOM_PERCENTAGE     (GADGET_ID_CHECKBUTTON_FIRST + 0)
543 #define GADGET_ID_RANDOM_QUANTITY       (GADGET_ID_CHECKBUTTON_FIRST + 1)
544 #define GADGET_ID_RANDOM_RESTRICTED     (GADGET_ID_CHECKBUTTON_FIRST + 2)
545 #define GADGET_ID_INITIAL_GRAVITY       (GADGET_ID_CHECKBUTTON_FIRST + 3)
546 #define GADGET_ID_STICK_ELEMENT         (GADGET_ID_CHECKBUTTON_FIRST + 4)
547 #define GADGET_ID_EM_SLIPPERY_GEMS      (GADGET_ID_CHECKBUTTON_FIRST + 5)
548 #define GADGET_ID_USE_SPRING_BUG        (GADGET_ID_CHECKBUTTON_FIRST + 6)
549 #define GADGET_ID_USE_TIME_ORB_BUG      (GADGET_ID_CHECKBUTTON_FIRST + 7)
550 #define GADGET_ID_RANDOM_BALL_CONTENT   (GADGET_ID_CHECKBUTTON_FIRST + 8)
551 #define GADGET_ID_INITIAL_BALL_STATE    (GADGET_ID_CHECKBUTTON_FIRST + 9)
552 #define GADGET_ID_GROW_INTO_DIGGABLE    (GADGET_ID_CHECKBUTTON_FIRST + 10)
553 #define GADGET_ID_DOUBLE_SPEED          (GADGET_ID_CHECKBUTTON_FIRST + 11)
554 #define GADGET_ID_BLOCK_SNAP_FIELD      (GADGET_ID_CHECKBUTTON_FIRST + 12)
555 #define GADGET_ID_BLOCK_LAST_FIELD      (GADGET_ID_CHECKBUTTON_FIRST + 13)
556 #define GADGET_ID_SP_BLOCK_LAST_FIELD   (GADGET_ID_CHECKBUTTON_FIRST + 14)
557 #define GADGET_ID_INSTANT_RELOCATION    (GADGET_ID_CHECKBUTTON_FIRST + 15)
558 #define GADGET_ID_USE_START_ELEMENT     (GADGET_ID_CHECKBUTTON_FIRST + 16)
559 #define GADGET_ID_USE_ARTWORK_ELEMENT   (GADGET_ID_CHECKBUTTON_FIRST + 17)
560 #define GADGET_ID_USE_EXPLOSION_ELEMENT (GADGET_ID_CHECKBUTTON_FIRST + 18)
561 #define GADGET_ID_CAN_PASS_TO_WALKABLE  (GADGET_ID_CHECKBUTTON_FIRST + 19)
562 #define GADGET_ID_CAN_FALL_INTO_ACID    (GADGET_ID_CHECKBUTTON_FIRST + 20)
563 #define GADGET_ID_CAN_MOVE_INTO_ACID    (GADGET_ID_CHECKBUTTON_FIRST + 21)
564 #define GADGET_ID_DONT_COLLIDE_WITH     (GADGET_ID_CHECKBUTTON_FIRST + 22)
565 #define GADGET_ID_CUSTOM_INDESTRUCTIBLE (GADGET_ID_CHECKBUTTON_FIRST + 23)
566 #define GADGET_ID_CUSTOM_CAN_EXPLODE    (GADGET_ID_CHECKBUTTON_FIRST + 24)
567 #define GADGET_ID_CUSTOM_EXPLODE_FIRE   (GADGET_ID_CHECKBUTTON_FIRST + 25)
568 #define GADGET_ID_CUSTOM_EXPLODE_SMASH  (GADGET_ID_CHECKBUTTON_FIRST + 26)
569 #define GADGET_ID_CUSTOM_EXPLODE_IMPACT (GADGET_ID_CHECKBUTTON_FIRST + 27)
570 #define GADGET_ID_CUSTOM_WALK_TO_OBJECT (GADGET_ID_CHECKBUTTON_FIRST + 28)
571 #define GADGET_ID_CUSTOM_DEADLY         (GADGET_ID_CHECKBUTTON_FIRST + 29)
572 #define GADGET_ID_CUSTOM_CAN_MOVE       (GADGET_ID_CHECKBUTTON_FIRST + 30)
573 #define GADGET_ID_CUSTOM_CAN_FALL       (GADGET_ID_CHECKBUTTON_FIRST + 31)
574 #define GADGET_ID_CUSTOM_CAN_SMASH      (GADGET_ID_CHECKBUTTON_FIRST + 32)
575 #define GADGET_ID_CUSTOM_SLIPPERY       (GADGET_ID_CHECKBUTTON_FIRST + 33)
576 #define GADGET_ID_CUSTOM_ACCESSIBLE     (GADGET_ID_CHECKBUTTON_FIRST + 34)
577 #define GADGET_ID_CUSTOM_GRAV_REACHABLE (GADGET_ID_CHECKBUTTON_FIRST + 35)
578 #define GADGET_ID_CUSTOM_USE_LAST_VALUE (GADGET_ID_CHECKBUTTON_FIRST + 36)
579 #define GADGET_ID_CUSTOM_USE_GRAPHIC    (GADGET_ID_CHECKBUTTON_FIRST + 37)
580 #define GADGET_ID_CUSTOM_USE_TEMPLATE   (GADGET_ID_CHECKBUTTON_FIRST + 38)
581 #define GADGET_ID_CUSTOM_CAN_CHANGE     (GADGET_ID_CHECKBUTTON_FIRST + 39)
582 #define GADGET_ID_CHANGE_USE_CONTENT    (GADGET_ID_CHECKBUTTON_FIRST + 40)
583 #define GADGET_ID_CHANGE_USE_EXPLOSION  (GADGET_ID_CHECKBUTTON_FIRST + 41)
584 #define GADGET_ID_CHANGE_ONLY_COMPLETE  (GADGET_ID_CHECKBUTTON_FIRST + 42)
585 #define GADGET_ID_CHANGE_USE_RANDOM     (GADGET_ID_CHECKBUTTON_FIRST + 43)
586 #define GADGET_ID_CHANGE_HAS_ACTION     (GADGET_ID_CHECKBUTTON_FIRST + 44)
587 #define GADGET_ID_CHANGE_DELAY          (GADGET_ID_CHECKBUTTON_FIRST + 45)
588 #define GADGET_ID_CHANGE_BY_DIRECT_ACT  (GADGET_ID_CHECKBUTTON_FIRST + 46)
589 #define GADGET_ID_CHANGE_BY_OTHER_ACT   (GADGET_ID_CHECKBUTTON_FIRST + 47)
590
591 /* gadgets for buttons in element list */
592 #define GADGET_ID_ELEMENTLIST_FIRST     (GADGET_ID_CHECKBUTTON_FIRST + 48)
593 #define GADGET_ID_ELEMENTLIST_LAST      (GADGET_ID_ELEMENTLIST_FIRST +  \
594                                         ED_NUM_ELEMENTLIST_BUTTONS - 1)
595
596 #define NUM_EDITOR_GADGETS              (GADGET_ID_ELEMENTLIST_LAST + 1)
597
598 /* radio button numbers */
599 #define RADIO_NR_NONE                   0
600 #define RADIO_NR_DRAWING_TOOLBOX        1
601 #define RADIO_NR_RANDOM_ELEMENTS        2
602
603 /* values for counter gadgets */
604 #define ED_COUNTER_ID_SELECT_LEVEL      0
605 #define ED_COUNTER_ID_LEVEL_XSIZE       1
606 #define ED_COUNTER_ID_LEVEL_YSIZE       2
607 #define ED_COUNTER_ID_LEVEL_GEMSLIMIT   3
608 #define ED_COUNTER_ID_LEVEL_TIMELIMIT   4
609 #define ED_COUNTER_ID_LEVEL_TIMESCORE   5
610 #define ED_COUNTER_ID_LEVEL_RANDOM      6
611 #define ED_COUNTER_ID_ELEMENT_VALUE1    7
612 #define ED_COUNTER_ID_ELEMENT_VALUE2    8
613 #define ED_COUNTER_ID_ELEMENT_VALUE3    9
614 #define ED_COUNTER_ID_ELEMENT_VALUE4    10
615 #define ED_COUNTER_ID_YAMYAM_CONTENT    11
616 #define ED_COUNTER_ID_BALL_CONTENT      12
617 #define ED_COUNTER_ID_ENVELOPE_XSIZE    13
618 #define ED_COUNTER_ID_ENVELOPE_YSIZE    14
619 #define ED_COUNTER_ID_CUSTOM_SCORE      15
620 #define ED_COUNTER_ID_CUSTOM_GEMCOUNT   16
621 #define ED_COUNTER_ID_CUSTOM_VALUE_FIX  17
622 #define ED_COUNTER_ID_CUSTOM_VALUE_RND  18
623 #define ED_COUNTER_ID_PUSH_DELAY_FIX    19
624 #define ED_COUNTER_ID_PUSH_DELAY_RND    20
625 #define ED_COUNTER_ID_DROP_DELAY_FIX    21
626 #define ED_COUNTER_ID_DROP_DELAY_RND    22
627 #define ED_COUNTER_ID_MOVE_DELAY_FIX    23
628 #define ED_COUNTER_ID_MOVE_DELAY_RND    24
629 #define ED_COUNTER_ID_EXPLOSION_DELAY   25
630 #define ED_COUNTER_ID_IGNITION_DELAY    26
631 #define ED_COUNTER_ID_GROUP_CONTENT     27
632 #define ED_COUNTER_ID_CHANGE_DELAY_FIX  28
633 #define ED_COUNTER_ID_CHANGE_DELAY_RND  29
634 #define ED_COUNTER_ID_CHANGE_CONT_RND   30
635
636 #define ED_NUM_COUNTERBUTTONS           31
637
638 #define ED_COUNTER_ID_LEVEL_FIRST       ED_COUNTER_ID_LEVEL_XSIZE
639 #define ED_COUNTER_ID_LEVEL_LAST        ED_COUNTER_ID_LEVEL_RANDOM
640
641 #define ED_COUNTER_ID_CUSTOM1_FIRST     ED_COUNTER_ID_CUSTOM_SCORE
642 #define ED_COUNTER_ID_CUSTOM1_LAST      ED_COUNTER_ID_DROP_DELAY_RND
643 #define ED_COUNTER_ID_CUSTOM2_FIRST     ED_COUNTER_ID_MOVE_DELAY_FIX
644 #define ED_COUNTER_ID_CUSTOM2_LAST      ED_COUNTER_ID_IGNITION_DELAY
645 #define ED_COUNTER_ID_CUSTOM_FIRST      ED_COUNTER_ID_CUSTOM1_FIRST
646 #define ED_COUNTER_ID_CUSTOM_LAST       ED_COUNTER_ID_CUSTOM2_LAST
647
648 #define ED_COUNTER_ID_CHANGE_FIRST      ED_COUNTER_ID_CHANGE_DELAY_FIX
649 #define ED_COUNTER_ID_CHANGE_LAST       ED_COUNTER_ID_CHANGE_CONT_RND
650
651 /* values for scrollbutton gadgets */
652 #define ED_SCROLLBUTTON_ID_AREA_UP      0
653 #define ED_SCROLLBUTTON_ID_AREA_DOWN    1
654 #define ED_SCROLLBUTTON_ID_AREA_LEFT    2
655 #define ED_SCROLLBUTTON_ID_AREA_RIGHT   3
656 #define ED_SCROLLBUTTON_ID_LIST_UP      4
657 #define ED_SCROLLBUTTON_ID_LIST_DOWN    5
658
659 #define ED_NUM_SCROLLBUTTONS            6
660
661 #define ED_SCROLLBUTTON_ID_AREA_FIRST   ED_SCROLLBUTTON_ID_AREA_UP
662 #define ED_SCROLLBUTTON_ID_AREA_LAST    ED_SCROLLBUTTON_ID_AREA_RIGHT
663
664 /* values for scrollbar gadgets */
665 #define ED_SCROLLBAR_ID_AREA_HORIZONTAL 0
666 #define ED_SCROLLBAR_ID_AREA_VERTICAL   1
667 #define ED_SCROLLBAR_ID_LIST_VERTICAL   2
668
669 #define ED_NUM_SCROLLBARS               3
670
671 #define ED_SCROLLBAR_ID_AREA_FIRST      ED_SCROLLBAR_ID_AREA_HORIZONTAL
672 #define ED_SCROLLBAR_ID_AREA_LAST       ED_SCROLLBAR_ID_AREA_VERTICAL
673
674 /* values for text input gadgets */
675 #define ED_TEXTINPUT_ID_LEVEL_NAME      0
676 #define ED_TEXTINPUT_ID_LEVEL_AUTHOR    1
677 #define ED_TEXTINPUT_ID_ELEMENT_NAME    2
678
679 #define ED_NUM_TEXTINPUT                3
680
681 #define ED_TEXTINPUT_ID_LEVEL_FIRST     ED_TEXTINPUT_ID_LEVEL_NAME
682 #define ED_TEXTINPUT_ID_LEVEL_LAST      ED_TEXTINPUT_ID_LEVEL_AUTHOR
683
684 /* values for text area gadgets */
685 #define ED_TEXTAREA_ID_ENVELOPE_INFO    0
686
687 #define ED_NUM_TEXTAREAS                        1
688
689 #define ED_TEXTAREA_ID_LEVEL_FIRST      ED_TEXTAREA_ID_ENVELOPE
690 #define ED_TEXTAREA_ID_LEVEL_LAST       ED_TEXTAREA_ID_ENVELOPE
691
692 /* values for selectbox gadgets */
693 #define ED_SELECTBOX_ID_TIME_OR_STEPS           0
694 #define ED_SELECTBOX_ID_GAME_ENGINE_TYPE        1
695 #define ED_SELECTBOX_ID_WIND_DIRECTION          2
696 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE      3
697 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_LAYER     4
698 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_PROTECTED 5
699 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_DIRECTION 6
700 #define ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION   7
701 #define ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN     8
702 #define ED_SELECTBOX_ID_CUSTOM_MOVE_DIRECTION   9
703 #define ED_SELECTBOX_ID_CUSTOM_MOVE_STEPSIZE    10
704 #define ED_SELECTBOX_ID_CUSTOM_MOVE_LEAVE_TYPE  11
705 #define ED_SELECTBOX_ID_CUSTOM_SMASH_TARGETS    12
706 #define ED_SELECTBOX_ID_CUSTOM_SLIPPERY_TYPE    13
707 #define ED_SELECTBOX_ID_CUSTOM_DEADLINESS       14
708 #define ED_SELECTBOX_ID_CUSTOM_EXPLOSION_TYPE   15
709 #define ED_SELECTBOX_ID_CHANGE_TIME_UNITS       16
710 #define ED_SELECTBOX_ID_CHANGE_DIRECT_ACTION    17
711 #define ED_SELECTBOX_ID_CHANGE_OTHER_ACTION     18
712 #define ED_SELECTBOX_ID_CHANGE_SIDE             19
713 #define ED_SELECTBOX_ID_CHANGE_PLAYER           20
714 #define ED_SELECTBOX_ID_CHANGE_PAGE             21
715 #define ED_SELECTBOX_ID_CHANGE_REPLACE_WHEN     22
716 #define ED_SELECTBOX_ID_ACTION_TYPE             23
717 #define ED_SELECTBOX_ID_ACTION_MODE             24
718 #define ED_SELECTBOX_ID_ACTION_ARG              25
719 #define ED_SELECTBOX_ID_SELECT_CHANGE_PAGE      26
720 #define ED_SELECTBOX_ID_GROUP_CHOICE_MODE       27
721
722 #define ED_NUM_SELECTBOX                        28
723
724 #define ED_SELECTBOX_ID_LEVEL_FIRST     ED_SELECTBOX_ID_TIME_OR_STEPS
725 #define ED_SELECTBOX_ID_LEVEL_LAST      ED_SELECTBOX_ID_WIND_DIRECTION
726
727 #define ED_SELECTBOX_ID_CUSTOM1_FIRST   ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE
728 #define ED_SELECTBOX_ID_CUSTOM1_LAST    ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION
729 #define ED_SELECTBOX_ID_CUSTOM2_FIRST   ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN
730 #define ED_SELECTBOX_ID_CUSTOM2_LAST    ED_SELECTBOX_ID_CUSTOM_EXPLOSION_TYPE
731 #define ED_SELECTBOX_ID_CUSTOM_FIRST    ED_SELECTBOX_ID_CUSTOM1_FIRST
732 #define ED_SELECTBOX_ID_CUSTOM_LAST     ED_SELECTBOX_ID_CUSTOM2_LAST
733
734 #define ED_SELECTBOX_ID_CHANGE_FIRST    ED_SELECTBOX_ID_CHANGE_TIME_UNITS
735 #define ED_SELECTBOX_ID_CHANGE_LAST     ED_SELECTBOX_ID_SELECT_CHANGE_PAGE
736
737 /* values for textbutton gadgets */
738 #define ED_TEXTBUTTON_ID_PROPERTIES_INFO        0
739 #define ED_TEXTBUTTON_ID_PROPERTIES_CONFIG      1
740 #define ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_1    2
741 #define ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2    3
742 #define ED_TEXTBUTTON_ID_PROPERTIES_CHANGE      4
743 #define ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE       5
744 #define ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE        6
745 #define ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE        7
746
747 #define ED_NUM_TEXTBUTTONS                      8
748
749 #define ED_TEXTBUTTON_ID_PROPERTIES_FIRST ED_TEXTBUTTON_ID_PROPERTIES_INFO
750 #define ED_TEXTBUTTON_ID_PROPERTIES_LAST  ED_TEXTBUTTON_ID_PROPERTIES_CHANGE
751
752 #define ED_TEXTBUTTON_ID_CHANGE_FIRST   ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE
753 #define ED_TEXTBUTTON_ID_CHANGE_LAST    ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE
754
755 /* values for graphicbutton gadgets */
756 #define ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE    0
757 #define ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE    1
758 #define ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE    2
759 #define ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE   3
760
761 #define ED_NUM_GRAPHICBUTTONS                   4
762
763 #define ED_GRAPHICBUTTON_ID_CHANGE_FIRST  ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE
764 #define ED_GRAPHICBUTTON_ID_CHANGE_LAST   ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE
765
766 /* values for checkbutton gadgets */
767 #define ED_CHECKBUTTON_ID_INITIAL_GRAVITY       0
768 #define ED_CHECKBUTTON_ID_RANDOM_RESTRICTED     1
769 #define ED_CHECKBUTTON_ID_STICK_ELEMENT         2
770 #define ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS      3
771 #define ED_CHECKBUTTON_ID_USE_SPRING_BUG        4
772 #define ED_CHECKBUTTON_ID_USE_TIME_ORB_BUG      5
773 #define ED_CHECKBUTTON_ID_RANDOM_BALL_CONTENT   6
774 #define ED_CHECKBUTTON_ID_INITIAL_BALL_STATE    7
775 #define ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE    8
776 #define ED_CHECKBUTTON_ID_DOUBLE_SPEED          9
777 #define ED_CHECKBUTTON_ID_BLOCK_SNAP_FIELD      10
778 #define ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD      11
779 #define ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD   12
780 #define ED_CHECKBUTTON_ID_INSTANT_RELOCATION    13
781 #define ED_CHECKBUTTON_ID_USE_START_ELEMENT     14
782 #define ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT   15
783 #define ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT 16
784 #define ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE  17
785 #define ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID    18
786 #define ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID    19
787 #define ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH     20
788 #define ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC    21
789 #define ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE   22
790 #define ED_CHECKBUTTON_ID_CUSTOM_ACCESSIBLE     23
791 #define ED_CHECKBUTTON_ID_CUSTOM_GRAV_REACHABLE 24
792 #define ED_CHECKBUTTON_ID_CUSTOM_USE_LAST_VALUE 25
793 #define ED_CHECKBUTTON_ID_CUSTOM_WALK_TO_OBJECT 26
794 #define ED_CHECKBUTTON_ID_CUSTOM_INDESTRUCTIBLE 27
795 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_MOVE       28
796 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_FALL       29
797 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_SMASH      30
798 #define ED_CHECKBUTTON_ID_CUSTOM_SLIPPERY       31
799 #define ED_CHECKBUTTON_ID_CUSTOM_DEADLY         32
800 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_EXPLODE    33
801 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_FIRE   34
802 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_SMASH  35
803 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT 36
804 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_CHANGE     37
805 #define ED_CHECKBUTTON_ID_CHANGE_DELAY          38
806 #define ED_CHECKBUTTON_ID_CHANGE_BY_DIRECT_ACT  39
807 #define ED_CHECKBUTTON_ID_CHANGE_BY_OTHER_ACT   40
808 #define ED_CHECKBUTTON_ID_CHANGE_USE_EXPLOSION  41
809 #define ED_CHECKBUTTON_ID_CHANGE_USE_CONTENT    42
810 #define ED_CHECKBUTTON_ID_CHANGE_ONLY_COMPLETE  43
811 #define ED_CHECKBUTTON_ID_CHANGE_USE_RANDOM     44
812 #define ED_CHECKBUTTON_ID_CHANGE_HAS_ACTION     45
813
814 #define ED_NUM_CHECKBUTTONS                     46
815
816 #define ED_CHECKBUTTON_ID_LEVEL_FIRST   ED_CHECKBUTTON_ID_INITIAL_GRAVITY
817 #define ED_CHECKBUTTON_ID_LEVEL_LAST    ED_CHECKBUTTON_ID_RANDOM_RESTRICTED
818
819 #define ED_CHECKBUTTON_ID_CUSTOM1_FIRST ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC
820 #define ED_CHECKBUTTON_ID_CUSTOM1_LAST  ED_CHECKBUTTON_ID_CUSTOM_INDESTRUCTIBLE
821 #define ED_CHECKBUTTON_ID_CUSTOM2_FIRST ED_CHECKBUTTON_ID_CUSTOM_CAN_MOVE
822 #define ED_CHECKBUTTON_ID_CUSTOM2_LAST  ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT
823 #define ED_CHECKBUTTON_ID_CUSTOM_FIRST  ED_CHECKBUTTON_ID_CUSTOM1_FIRST
824 #define ED_CHECKBUTTON_ID_CUSTOM_LAST   ED_CHECKBUTTON_ID_CUSTOM2_LAST
825
826 #define ED_CHECKBUTTON_ID_CHANGE_FIRST  ED_CHECKBUTTON_ID_CUSTOM_CAN_CHANGE
827 #define ED_CHECKBUTTON_ID_CHANGE_LAST   ED_CHECKBUTTON_ID_CHANGE_HAS_ACTION
828
829 /* values for radiobutton gadgets */
830 #define ED_RADIOBUTTON_ID_PERCENTAGE    0
831 #define ED_RADIOBUTTON_ID_QUANTITY      1
832
833 #define ED_NUM_RADIOBUTTONS             2
834
835 #define ED_RADIOBUTTON_ID_LEVEL_FIRST   ED_RADIOBUTTON_ID_PERCENTAGE
836 #define ED_RADIOBUTTON_ID_LEVEL_LAST    ED_RADIOBUTTON_ID_QUANTITY
837
838 /* values for drawing area gadgets */
839 #define ED_DRAWING_ID_DRAWING_LEVEL             0
840 #define ED_DRAWING_ID_YAMYAM_CONTENT_0          1
841 #define ED_DRAWING_ID_YAMYAM_CONTENT_1          2
842 #define ED_DRAWING_ID_YAMYAM_CONTENT_2          3
843 #define ED_DRAWING_ID_YAMYAM_CONTENT_3          4
844 #define ED_DRAWING_ID_YAMYAM_CONTENT_4          5
845 #define ED_DRAWING_ID_YAMYAM_CONTENT_5          6
846 #define ED_DRAWING_ID_YAMYAM_CONTENT_6          7
847 #define ED_DRAWING_ID_YAMYAM_CONTENT_7          8
848 #define ED_DRAWING_ID_MAGIC_BALL_CONTENT_0      9
849 #define ED_DRAWING_ID_MAGIC_BALL_CONTENT_1      10
850 #define ED_DRAWING_ID_MAGIC_BALL_CONTENT_2      11
851 #define ED_DRAWING_ID_MAGIC_BALL_CONTENT_3      12
852 #define ED_DRAWING_ID_MAGIC_BALL_CONTENT_4      13
853 #define ED_DRAWING_ID_MAGIC_BALL_CONTENT_5      14
854 #define ED_DRAWING_ID_MAGIC_BALL_CONTENT_6      15
855 #define ED_DRAWING_ID_MAGIC_BALL_CONTENT_7      16
856 #define ED_DRAWING_ID_AMOEBA_CONTENT            17
857 #define ED_DRAWING_ID_START_ELEMENT             18
858 #define ED_DRAWING_ID_ARTWORK_ELEMENT           19
859 #define ED_DRAWING_ID_EXPLOSION_ELEMENT         20
860 #define ED_DRAWING_ID_CUSTOM_GRAPHIC            21
861 #define ED_DRAWING_ID_CUSTOM_CONTENT            22
862 #define ED_DRAWING_ID_CUSTOM_MOVE_ENTER         23
863 #define ED_DRAWING_ID_CUSTOM_MOVE_LEAVE         24
864 #define ED_DRAWING_ID_CUSTOM_CHANGE_TARGET      25
865 #define ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT     26
866 #define ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER     27
867 #define ED_DRAWING_ID_GROUP_CONTENT             28
868 #define ED_DRAWING_ID_RANDOM_BACKGROUND         29
869
870 #define ED_NUM_DRAWING_AREAS                    30
871
872
873 /*
874   -----------------------------------------------------------------------------
875   some internally used definitions
876   -----------------------------------------------------------------------------
877 */
878
879 /* values for CopyLevelToUndoBuffer() */
880 #define UNDO_IMMEDIATE                  0
881 #define UNDO_ACCUMULATE                 1
882
883 /* values for scrollbars */
884 #define ED_SCROLL_NO                    0
885 #define ED_SCROLL_LEFT                  1
886 #define ED_SCROLL_RIGHT                 2
887 #define ED_SCROLL_UP                    4
888 #define ED_SCROLL_DOWN                  8
889
890 /* screens in the level editor */
891 #define ED_MODE_DRAWING                 0
892 #define ED_MODE_INFO                    1
893 #define ED_MODE_PROPERTIES              2
894
895 /* sub-screens in the element properties section */
896 #define ED_MODE_PROPERTIES_INFO         ED_TEXTBUTTON_ID_PROPERTIES_INFO
897 #define ED_MODE_PROPERTIES_CONFIG       ED_TEXTBUTTON_ID_PROPERTIES_CONFIG
898 #define ED_MODE_PROPERTIES_CONFIG_1     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_1
899 #define ED_MODE_PROPERTIES_CONFIG_2     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2
900 #define ED_MODE_PROPERTIES_CHANGE       ED_TEXTBUTTON_ID_PROPERTIES_CHANGE
901
902 /* how many steps can be cancelled */
903 #define NUM_UNDO_STEPS                  (10 + 1)
904
905 /* values for elements with score for certain actions */
906 #define MIN_SCORE                       0
907 #define MAX_SCORE                       255
908
909 /* values for elements with count for collecting */
910 #define MIN_COLLECT_COUNT               0
911 #define MAX_COLLECT_COUNT               255
912
913 /* values for random placement */
914 #define RANDOM_USE_PERCENTAGE           0
915 #define RANDOM_USE_QUANTITY             1
916
917 /* maximal size of level editor drawing area */
918 #define MAX_ED_FIELDX           (2 * SCR_FIELDX)
919 #define MAX_ED_FIELDY           (2 * SCR_FIELDY - 1)
920
921
922 /*
923   -----------------------------------------------------------------------------
924   some internally used data structure definitions
925   -----------------------------------------------------------------------------
926 */
927
928 static struct
929 {
930   char shortcut;
931   char *text;
932 } control_info[ED_NUM_CTRL_BUTTONS] =
933 {
934   /* note: some additional characters are already reserved for "cheat mode"
935      shortcuts (":XYZ" style) -- for details, see "events.c" */
936
937   { 's',        "draw single items"                     },
938   { 'd',        "draw connected items"                  },
939   { 'l',        "draw lines"                            },
940   { 'a',        "draw arcs"                             },
941   { 'r',        "draw outline rectangles"               },
942   { 'R',        "draw filled rectangles"                },
943   { '\0',       "wrap (rotate) level up"                },
944   { 't',        "enter text elements"                   },
945   { 'f',        "flood fill"                            },
946   { '\0',       "wrap (rotate) level left"              },
947   { '?',        "properties of drawing element"         },
948   { '\0',       "wrap (rotate) level right"             },
949   { '\0',       "random element placement"              },
950   { 'b',        "grab brush"                            },
951   { '\0',       "wrap (rotate) level down"              },
952   { ',',        "pick drawing element"                  },
953
954   { 'U',        "undo last operation"                   },
955   { 'I',        "level properties"                      },
956   { 'S',        "save level"                            },
957   { 'C',        "clear level"                           },
958   { 'T',        "test level"                            },
959   { 'E',        "exit level editor"                     },
960
961   { '\0',       "copy settings from other element"      },
962   { '\0',       "copy settings to other element"        },
963   { '\0',       "exchange element with other element"   },
964
965   { '\0',       "copy settings from this element"       },
966   { '\0',       "paste settings to this element"        },
967 };
968
969 static int random_placement_value = 10;
970 static int random_placement_method = RANDOM_USE_QUANTITY;
971 static int random_placement_background_element = EL_SAND;
972 static boolean random_placement_background_restricted = FALSE;
973 static boolean stick_element_properties_window = FALSE;
974 static boolean custom_element_properties[NUM_ELEMENT_PROPERTIES];
975 static boolean custom_element_change_events[NUM_CHANGE_EVENTS];
976 static struct ElementChangeInfo custom_element_change;
977 static struct ElementGroupInfo group_element_info;
978 static struct ElementInfo custom_element;
979
980 static struct
981 {
982   int x, y;
983   int min_value, max_value;
984   int gadget_id_down, gadget_id_up;
985   int gadget_id_text;
986   int gadget_id_align;
987   int *value;
988   char *text_above, *text_left, *text_right;
989 } counterbutton_info[ED_NUM_COUNTERBUTTONS] =
990 {
991   /* ---------- current level number --------------------------------------- */
992
993   {
994     DX + 5 - SX,                        DY + 3 - SY,
995     1,                                  100,
996     GADGET_ID_SELECT_LEVEL_DOWN,        GADGET_ID_SELECT_LEVEL_UP,
997     GADGET_ID_SELECT_LEVEL_TEXT,        GADGET_ID_NONE,
998     &level_nr,
999     NULL,                               NULL, NULL
1000   },
1001
1002   /* ---------- level and editor settings ---------------------------------- */
1003
1004   {
1005     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(4),
1006     MIN_LEV_FIELDX,                     MAX_LEV_FIELDX,
1007     GADGET_ID_LEVEL_XSIZE_DOWN,         GADGET_ID_LEVEL_XSIZE_UP,
1008     GADGET_ID_LEVEL_XSIZE_TEXT,         GADGET_ID_NONE,
1009     &level.fieldx,
1010     "playfield size:",                  NULL, "width",
1011   },
1012   {
1013     -1,                                 ED_LEVEL_SETTINGS_YPOS(4),
1014     MIN_LEV_FIELDY,                     MAX_LEV_FIELDY,
1015     GADGET_ID_LEVEL_YSIZE_DOWN,         GADGET_ID_LEVEL_YSIZE_UP,
1016     GADGET_ID_LEVEL_YSIZE_TEXT,         GADGET_ID_LEVEL_XSIZE_UP,
1017     &level.fieldy,
1018     NULL,                               " ", "height",
1019   },
1020   {
1021     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(6),
1022     0,                                  999,
1023     GADGET_ID_LEVEL_GEMSLIMIT_DOWN,     GADGET_ID_LEVEL_GEMSLIMIT_UP,
1024     GADGET_ID_LEVEL_GEMSLIMIT_TEXT,     GADGET_ID_NONE,
1025     &level.gems_needed,
1026     NULL, "number of gems to collect:", NULL
1027   },
1028   {
1029     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(8),
1030     0,                                  9999,
1031     GADGET_ID_LEVEL_TIMELIMIT_DOWN,     GADGET_ID_LEVEL_TIMELIMIT_UP,
1032     GADGET_ID_LEVEL_TIMELIMIT_TEXT,     GADGET_ID_NONE,
1033     &level.time,
1034     "time or step limit to solve level:", NULL, NULL
1035   },
1036   {
1037     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(10),
1038     0,                                  255,
1039     GADGET_ID_LEVEL_TIMESCORE_DOWN,     GADGET_ID_LEVEL_TIMESCORE_UP,
1040     GADGET_ID_LEVEL_TIMESCORE_TEXT,     GADGET_ID_NONE,
1041     &level.score[SC_TIME_BONUS],
1042     "score for each second/step left:", NULL, NULL
1043   },
1044   {
1045     ED_LEVEL_SETTINGS_XPOS(0),          ED_COUNTER2_YPOS(8),
1046     1,                                  100,
1047     GADGET_ID_LEVEL_RANDOM_DOWN,        GADGET_ID_LEVEL_RANDOM_UP,
1048     GADGET_ID_LEVEL_RANDOM_TEXT,        GADGET_ID_NONE,
1049     &random_placement_value,
1050     "random element placement:",        NULL, "in"
1051   },
1052
1053   /* ---------- element settings: configure (various elements) ------------- */
1054
1055   {
1056     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(0),
1057     MIN_SCORE,                          MAX_SCORE,
1058     GADGET_ID_ELEMENT_VALUE1_DOWN,      GADGET_ID_ELEMENT_VALUE1_UP,
1059     GADGET_ID_ELEMENT_VALUE1_TEXT,      GADGET_ID_NONE,
1060     NULL,                               /* will be set when used */
1061     NULL,                               NULL, NULL
1062   },
1063   {
1064     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
1065     MIN_SCORE,                          MAX_SCORE,
1066     GADGET_ID_ELEMENT_VALUE2_DOWN,      GADGET_ID_ELEMENT_VALUE2_UP,
1067     GADGET_ID_ELEMENT_VALUE2_TEXT,      GADGET_ID_NONE,
1068     NULL,                               /* will be set when used */
1069     NULL,                               NULL, NULL
1070   },
1071   {
1072     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(2),
1073     MIN_SCORE,                          MAX_SCORE,
1074     GADGET_ID_ELEMENT_VALUE3_DOWN,      GADGET_ID_ELEMENT_VALUE3_UP,
1075     GADGET_ID_ELEMENT_VALUE3_TEXT,      GADGET_ID_NONE,
1076     NULL,                               /* will be set when used */
1077     NULL,                               NULL, NULL
1078   },
1079   {
1080     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(3),
1081     MIN_SCORE,                          MAX_SCORE,
1082     GADGET_ID_ELEMENT_VALUE4_DOWN,      GADGET_ID_ELEMENT_VALUE4_UP,
1083     GADGET_ID_ELEMENT_VALUE4_TEXT,      GADGET_ID_NONE,
1084     NULL,                               /* will be set when used */
1085     NULL,                               NULL, NULL
1086   },
1087   {
1088     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(3),
1089     MIN_ELEMENT_CONTENTS,               MAX_ELEMENT_CONTENTS,
1090     GADGET_ID_YAMYAM_CONTENT_DOWN,      GADGET_ID_YAMYAM_CONTENT_UP,
1091     GADGET_ID_YAMYAM_CONTENT_TEXT,      GADGET_ID_NONE,
1092     &level.num_yamyam_contents,
1093     NULL,                               NULL, "number of content areas"
1094   },
1095   {
1096     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(4),
1097     MIN_ELEMENT_CONTENTS,               MAX_ELEMENT_CONTENTS,
1098     GADGET_ID_BALL_CONTENT_DOWN,        GADGET_ID_BALL_CONTENT_UP,
1099     GADGET_ID_BALL_CONTENT_TEXT,        GADGET_ID_NONE,
1100     &level.num_ball_contents,
1101     NULL,                               NULL, "number of content areas"
1102   },
1103   {
1104     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(0),
1105     MIN_ENVELOPE_XSIZE,                 MAX_ENVELOPE_XSIZE,
1106     GADGET_ID_ENVELOPE_XSIZE_DOWN,      GADGET_ID_ENVELOPE_XSIZE_UP,
1107     GADGET_ID_ENVELOPE_XSIZE_TEXT,      GADGET_ID_NONE,
1108     NULL,
1109     NULL,                               NULL, "width",
1110   },
1111   {
1112     -1,                                 ED_ELEMENT_SETTINGS_YPOS(0),
1113     MIN_ENVELOPE_YSIZE,                 MAX_ENVELOPE_YSIZE,
1114     GADGET_ID_ENVELOPE_YSIZE_DOWN,      GADGET_ID_ENVELOPE_YSIZE_UP,
1115     GADGET_ID_ENVELOPE_YSIZE_TEXT,      GADGET_ID_ENVELOPE_XSIZE_UP,
1116     NULL,
1117     NULL,                               " ", "height",
1118   },
1119
1120   /* ---------- element settings: configure 1 (custom elements) ------------ */
1121
1122   {
1123     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(6),
1124     MIN_SCORE,                          MAX_SCORE,
1125     GADGET_ID_CUSTOM_SCORE_DOWN,        GADGET_ID_CUSTOM_SCORE_UP,
1126     GADGET_ID_CUSTOM_SCORE_TEXT,        GADGET_ID_NONE,
1127     &custom_element.collect_score_initial,
1128     NULL,                               "CE score", " "
1129   },
1130   {
1131     -1,                                 ED_ELEMENT_SETTINGS_YPOS(6),
1132     MIN_COLLECT_COUNT,                  MAX_COLLECT_COUNT,
1133     GADGET_ID_CUSTOM_GEMCOUNT_DOWN,     GADGET_ID_CUSTOM_GEMCOUNT_UP,
1134     GADGET_ID_CUSTOM_GEMCOUNT_TEXT,     GADGET_ID_CUSTOM_SCORE_UP,
1135     &custom_element.collect_count_initial,
1136     NULL,                               "CE count", NULL
1137   },
1138   {
1139     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(12),
1140     0,                                  9999,
1141     GADGET_ID_CUSTOM_VALUE_FIX_DOWN,    GADGET_ID_CUSTOM_VALUE_FIX_UP,
1142     GADGET_ID_CUSTOM_VALUE_FIX_TEXT,    GADGET_ID_NONE,
1143     &custom_element.ce_value_fixed_initial,
1144     NULL,                               "CE value", NULL
1145   },
1146   {
1147     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(12),
1148     0,                                  9999,
1149     GADGET_ID_CUSTOM_VALUE_RND_DOWN,    GADGET_ID_CUSTOM_VALUE_RND_UP,
1150     GADGET_ID_CUSTOM_VALUE_RND_TEXT,    GADGET_ID_CUSTOM_VALUE_FIX_UP,
1151     &custom_element.ce_value_random_initial,
1152     NULL,                               "+random", NULL
1153   },
1154   {
1155     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(7),
1156     0,                                  255,
1157     GADGET_ID_PUSH_DELAY_FIX_DOWN,      GADGET_ID_PUSH_DELAY_FIX_UP,
1158     GADGET_ID_PUSH_DELAY_FIX_TEXT,      GADGET_ID_NONE,
1159     &custom_element.push_delay_fixed,
1160     NULL,                               "push delay", NULL
1161   },
1162   {
1163     -1,                                 ED_ELEMENT_SETTINGS_YPOS(7),
1164     0,                                  255,
1165     GADGET_ID_PUSH_DELAY_RND_DOWN,      GADGET_ID_PUSH_DELAY_RND_UP,
1166     GADGET_ID_PUSH_DELAY_RND_TEXT,      GADGET_ID_PUSH_DELAY_FIX_UP,
1167     &custom_element.push_delay_random,
1168     NULL,                               "+random", NULL
1169   },
1170   {
1171     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(8),
1172     0,                                  255,
1173     GADGET_ID_DROP_DELAY_FIX_DOWN,      GADGET_ID_DROP_DELAY_FIX_UP,
1174     GADGET_ID_DROP_DELAY_FIX_TEXT,      GADGET_ID_NONE,
1175     &custom_element.drop_delay_fixed,
1176     NULL,                               "drop delay", NULL
1177   },
1178   {
1179     -1,                                 ED_ELEMENT_SETTINGS_YPOS(8),
1180     0,                                  255,
1181     GADGET_ID_DROP_DELAY_RND_DOWN,      GADGET_ID_DROP_DELAY_RND_UP,
1182     GADGET_ID_DROP_DELAY_RND_TEXT,      GADGET_ID_DROP_DELAY_FIX_UP,
1183     &custom_element.drop_delay_random,
1184     NULL,                               "+random", NULL
1185   },
1186
1187   /* ---------- element settings: configure 2 (custom elements) ------------ */
1188
1189   {
1190     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(5),
1191     0,                                  999,
1192     GADGET_ID_MOVE_DELAY_FIX_DOWN,      GADGET_ID_MOVE_DELAY_FIX_UP,
1193     GADGET_ID_MOVE_DELAY_FIX_TEXT,      GADGET_ID_NONE,
1194     &custom_element.move_delay_fixed,
1195     NULL,                               "move delay", NULL
1196   },
1197   {
1198     -1,                                 ED_ELEMENT_SETTINGS_YPOS(5),
1199     0,                                  999,
1200     GADGET_ID_MOVE_DELAY_RND_DOWN,      GADGET_ID_MOVE_DELAY_RND_UP,
1201     GADGET_ID_MOVE_DELAY_RND_TEXT,      GADGET_ID_MOVE_DELAY_FIX_UP,
1202     &custom_element.move_delay_random,
1203     NULL,                               "+random", NULL
1204   },
1205   {
1206     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(12),
1207     0,                                  255,
1208     GADGET_ID_EXPLOSION_DELAY_DOWN,     GADGET_ID_EXPLOSION_DELAY_UP,
1209     GADGET_ID_EXPLOSION_DELAY_TEXT,     GADGET_ID_NONE,
1210     &custom_element.explosion_delay,
1211     NULL,                               "explosion delay", NULL
1212   },
1213   {
1214     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(13),
1215     0,                                  255,
1216     GADGET_ID_IGNITION_DELAY_DOWN,      GADGET_ID_IGNITION_DELAY_UP,
1217     GADGET_ID_IGNITION_DELAY_TEXT,      GADGET_ID_NONE,
1218     &custom_element.ignition_delay,
1219     NULL,                               "ignition delay", "(by fire)"
1220   },
1221
1222   /* ---------- element settings: configure (group elements) --------------- */
1223
1224   {
1225     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(5),
1226     MIN_ELEMENTS_IN_GROUP,              MAX_ELEMENTS_IN_GROUP,
1227     GADGET_ID_GROUP_CONTENT_DOWN,       GADGET_ID_GROUP_CONTENT_UP,
1228     GADGET_ID_GROUP_CONTENT_TEXT,       GADGET_ID_NONE,
1229     &group_element_info.num_elements,
1230     NULL,                               NULL, "number of elements in group"
1231   },
1232
1233   /* ---------- element settings: advanced (custom elements) --------------- */
1234
1235   {
1236     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(2),
1237     0,                                  999,
1238     GADGET_ID_CHANGE_DELAY_FIX_DOWN,    GADGET_ID_CHANGE_DELAY_FIX_UP,
1239     GADGET_ID_CHANGE_DELAY_FIX_TEXT,    GADGET_ID_NONE,
1240     &custom_element_change.delay_fixed,
1241     NULL,                               "CE delay", NULL,
1242   },
1243   {
1244     -1,                                 ED_ELEMENT_SETTINGS_YPOS(2),
1245     0,                                  999,
1246     GADGET_ID_CHANGE_DELAY_RND_DOWN,    GADGET_ID_CHANGE_DELAY_RND_UP,
1247     GADGET_ID_CHANGE_DELAY_RND_TEXT,    GADGET_ID_CHANGE_DELAY_FIX_UP,
1248     &custom_element_change.delay_random,
1249     NULL,                               "+random", NULL
1250   },
1251   {
1252     ED_ELEMENT_SETTINGS_XPOS(3),        ED_ELEMENT_SETTINGS_YPOS(12),
1253     0,                                  100,
1254     GADGET_ID_CHANGE_CONT_RND_DOWN,     GADGET_ID_CHANGE_CONT_RND_UP,
1255     GADGET_ID_CHANGE_CONT_RND_TEXT,     GADGET_ID_NONE,
1256     &custom_element_change.random_percentage,
1257     NULL,                               "use random replace:", "%"
1258   },
1259 };
1260
1261 static struct
1262 {
1263   int x, y;
1264   int gadget_id;
1265   int size;
1266   char *value;
1267   char *text_above, *infotext;
1268 } textinput_info[ED_NUM_TEXTINPUT] =
1269 {
1270   {
1271     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(0),
1272     GADGET_ID_LEVEL_NAME,
1273     MAX_LEVEL_NAME_LEN,
1274     level.name,
1275     "Title:", "Title"
1276   },
1277   {
1278     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(2),
1279     GADGET_ID_LEVEL_AUTHOR,
1280     MAX_LEVEL_AUTHOR_LEN,
1281     level.author,
1282     "Author:", "Author"
1283   },
1284   {
1285     5 * MINI_TILEX - 2,                 5 * MINI_TILEY - ED_BORDER_SIZE + 1,
1286     GADGET_ID_ELEMENT_NAME,
1287     MAX_ELEMENT_NAME_LEN - 2,           /* currently 2 chars less editable */
1288     custom_element.description,
1289     NULL, "Element name"
1290   }
1291 };
1292
1293 static struct
1294 {
1295   int x, y;
1296   int gadget_id;
1297   int xsize, ysize;
1298   char *value;
1299   char *text_above, *infotext;
1300 } textarea_info[ED_NUM_TEXTAREAS] =
1301 {
1302   {
1303     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(2),
1304     GADGET_ID_ENVELOPE_INFO,
1305     MAX_ENVELOPE_XSIZE, MAX_ENVELOPE_YSIZE,
1306     NULL,
1307     "Envelope Info:", "Envelope Info"
1308   }
1309 };
1310
1311 static struct ValueTextInfo options_time_or_steps[] =
1312 {
1313   { 0,                          "seconds"                       },
1314   { 1,                          "steps"                         },
1315
1316   { -1,                         NULL                            }
1317 };
1318
1319 static struct ValueTextInfo options_game_engine_type[] =
1320 {
1321   { GAME_ENGINE_TYPE_RND,       "Rocks'n'Diamonds"              },
1322   { GAME_ENGINE_TYPE_EM,        "Emerald Mine"                  },
1323
1324   { -1,                         NULL                            }
1325 };
1326
1327 static struct ValueTextInfo options_wind_direction[] =
1328 {
1329   { MV_START_NONE,              "none"                          },
1330   { MV_START_LEFT,              "left"                          },
1331   { MV_START_RIGHT,             "right"                         },
1332   { MV_START_UP,                "up"                            },
1333   { MV_START_DOWN,              "down"                          },
1334
1335   { -1,                         NULL                            }
1336 };
1337
1338 static struct ValueTextInfo options_access_type[] =
1339 {
1340   { EP_WALKABLE,                "walkable"                      },
1341   { EP_PASSABLE,                "passable"                      },
1342
1343   { -1,                         NULL                            }
1344 };
1345
1346 static struct ValueTextInfo options_access_layer[] =
1347 {
1348   { EP_ACCESSIBLE_OVER,         "over"                          },
1349   { EP_ACCESSIBLE_INSIDE,       "inside"                        },
1350   { EP_ACCESSIBLE_UNDER,        "under"                         },
1351
1352   { -1,                         NULL                            }
1353 };
1354
1355 static struct ValueTextInfo options_access_protected[] =
1356 {
1357   { 0,                          "unprotected"                   },
1358   { 1,                          "protected"                     },
1359
1360   { -1,                         NULL                            }
1361 };
1362
1363 static struct ValueTextInfo options_access_direction[] =
1364 {
1365   { MV_NO_DIRECTION,            "no direction"                  },
1366   { MV_LEFT,                    "left"                          },
1367   { MV_RIGHT,                   "right"                         },
1368   { MV_UP,                      "up"                            },
1369   { MV_DOWN,                    "down"                          },
1370   { MV_LEFT  | MV_UP,           "left + up"                     },
1371   { MV_LEFT  | MV_DOWN,         "left + down"                   },
1372   { MV_RIGHT | MV_UP,           "right + up"                    },
1373   { MV_RIGHT | MV_DOWN,         "right + down"                  },
1374   { MV_HORIZONTAL,              "horizontal"                    },
1375   { MV_VERTICAL,                "vertical"                      },
1376   { MV_HORIZONTAL | MV_UP,      "horizontal + up"               },
1377   { MV_HORIZONTAL | MV_DOWN,    "horizontal + down"             },
1378   { MV_VERTICAL   | MV_LEFT,    "vertical + left"               },
1379   { MV_VERTICAL   | MV_RIGHT,   "vertical + right"              },
1380   { MV_ALL_DIRECTIONS,          "all directions"                },
1381
1382   { -1,                         NULL                            }
1383 };
1384
1385 static struct ValueTextInfo options_walk_to_action[] =
1386 {
1387   { EP_DIGGABLE,                "diggable"                      },
1388   { EP_COLLECTIBLE_ONLY,        "collectible"                   },
1389   { EP_DROPPABLE,               "collectible & droppable"       },
1390   { EP_THROWABLE,               "collectible & throwable"       },
1391   { EP_PUSHABLE,                "pushable"                      },
1392
1393   { -1,                         NULL                            }
1394 };
1395
1396 static struct ValueTextInfo options_move_pattern[] =
1397 {
1398   { MV_LEFT,                    "left"                          },
1399   { MV_RIGHT,                   "right"                         },
1400   { MV_UP,                      "up"                            },
1401   { MV_DOWN,                    "down"                          },
1402   { MV_HORIZONTAL,              "horizontal"                    },
1403   { MV_VERTICAL,                "vertical"                      },
1404   { MV_ALL_DIRECTIONS,          "all directions"                },
1405   { MV_WIND_DIRECTION,          "wind direction"                },
1406   { MV_TOWARDS_PLAYER,          "towards player"                },
1407   { MV_AWAY_FROM_PLAYER,        "away from player"              },
1408   { MV_ALONG_LEFT_SIDE,         "along left side"               },
1409   { MV_ALONG_RIGHT_SIDE,        "along right side"              },
1410   { MV_TURNING_LEFT,            "turning left"                  },
1411   { MV_TURNING_RIGHT,           "turning right"                 },
1412   { MV_TURNING_LEFT_RIGHT,      "turning left, right"           },
1413   { MV_TURNING_RIGHT_LEFT,      "turning right, left"           },
1414   { MV_TURNING_RANDOM,          "turning random"                },
1415   { MV_MAZE_RUNNER,             "maze runner style"             },
1416   { MV_MAZE_HUNTER,             "maze hunter style"             },
1417   { MV_WHEN_PUSHED,             "when pushed"                   },
1418   { MV_WHEN_DROPPED,            "when dropped/thrown"           },
1419
1420   { -1,                         NULL                            }
1421 };
1422
1423 static struct ValueTextInfo options_move_direction[] =
1424 {
1425   { MV_START_AUTOMATIC,         "automatic"                     },
1426   { MV_START_LEFT,              "left"                          },
1427   { MV_START_RIGHT,             "right"                         },
1428   { MV_START_UP,                "up"                            },
1429   { MV_START_DOWN,              "down"                          },
1430   { MV_START_RANDOM,            "random"                        },
1431   { MV_START_PREVIOUS,          "previous"                      },
1432
1433   { -1,                         NULL                            }
1434 };
1435
1436 static struct ValueTextInfo options_move_stepsize[] =
1437 {
1438   { 0,                          "not moving"                    },
1439   { 1,                          "very slow"                     },
1440   { 2,                          "slow"                          },
1441   { 4,                          "normal"                        },
1442   { 8,                          "fast"                          },
1443   { 16,                         "very fast"                     },
1444   { 32,                         "even faster"                   },
1445
1446   { -1,                         NULL                            }
1447 };
1448
1449 static struct ValueTextInfo options_move_leave_type[] =
1450 {
1451   { LEAVE_TYPE_UNLIMITED,       "leave behind"                  },
1452   { LEAVE_TYPE_LIMITED,         "change it to"                  },
1453
1454   { -1,                         NULL                            }
1455 };
1456
1457 static struct ValueTextInfo options_smash_targets[] =
1458 {
1459   { EP_CAN_SMASH_PLAYER,        "player"                        },
1460 #if 0
1461   { EP_CAN_SMASH_ENEMIES,       "enemies"                       },
1462 #endif
1463   { EP_CAN_SMASH_EVERYTHING,    "everything"                    },
1464
1465   { -1,                         NULL                            }
1466 };
1467
1468 static struct ValueTextInfo options_slippery_type[] =
1469 {
1470   { SLIPPERY_ANY_RANDOM,        "random"                        },
1471   { SLIPPERY_ANY_LEFT_RIGHT,    "left, right"                   },
1472   { SLIPPERY_ANY_RIGHT_LEFT,    "right, left"                   },
1473   { SLIPPERY_ONLY_LEFT,         "only left"                     },
1474   { SLIPPERY_ONLY_RIGHT,        "only right"                    },
1475
1476   { -1,                         NULL                            }
1477 };
1478
1479 static struct ValueTextInfo options_deadliness[] =
1480 {
1481   { EP_DONT_RUN_INTO,           "running into"                  },
1482   { EP_DONT_COLLIDE_WITH,       "colliding with"                },
1483   { EP_DONT_TOUCH,              "touching"                      },
1484
1485   { -1,                         NULL                            }
1486 };
1487
1488 static struct ValueTextInfo options_explosion_type[] =
1489 {
1490   { EXPLODES_3X3,               "3x3"                           },
1491   { EXPLODES_CROSS,             "3+3"                           },
1492   { EXPLODES_1X1,               "1x1"                           },
1493
1494   { -1,                         NULL                            }
1495 };
1496
1497 static struct ValueTextInfo options_time_units[] =
1498 {
1499   { 1,                          "frames"                        },
1500   { FRAMES_PER_SECOND,          "seconds"                       },
1501
1502   { -1,                         NULL                            }
1503 };
1504
1505 static struct ValueTextInfo options_change_direct_action[] =
1506 {
1507   { CE_TOUCHED_BY_PLAYER,       "touched by player"             },
1508   { CE_PRESSED_BY_PLAYER,       "pressed by player"             },
1509   { CE_SWITCHED_BY_PLAYER,      "switched by player"            },
1510   { CE_SNAPPED_BY_PLAYER,       "snapped by player"             },
1511   { CE_PUSHED_BY_PLAYER,        "pushed by player"              },
1512   { CE_ENTERED_BY_PLAYER,       "entered by player"             },
1513   { CE_LEFT_BY_PLAYER,          "left by player"                },
1514   { CE_DROPPED_BY_PLAYER,       "dropped/thrown by player"      },
1515   { CE_SWITCHED,                "switched"                      },
1516   { CE_HITTING_SOMETHING,       "hitting something"             },
1517   { CE_HIT_BY_SOMETHING,        "hit by something"              },
1518 #if 0
1519   { CE_BLOCKED,                 "blocked"                       },
1520 #endif
1521   { CE_IMPACT,                  "impact (on something)"         },
1522   { CE_SMASHED,                 "smashed (from above)"          },
1523   { CE_VALUE_GETS_ZERO,         "CE value gets 0"               },
1524
1525   { -1,                         NULL                            }
1526 };
1527
1528 static struct ValueTextInfo options_change_other_action[] =
1529 {
1530   { CE_PLAYER_TOUCHES_X,        "player touches"                },
1531   { CE_PLAYER_PRESSES_X,        "player presses"                },
1532   { CE_PLAYER_SWITCHES_X,       "player switches"               },
1533   { CE_PLAYER_SNAPS_X,          "player snaps"                  },
1534   { CE_PLAYER_PUSHES_X,         "player pushes"                 },
1535   { CE_PLAYER_ENTERS_X,         "player enters"                 },
1536   { CE_PLAYER_LEAVES_X,         "player leaves"                 },
1537   { CE_PLAYER_DIGS_X,           "player digs"                   },
1538   { CE_PLAYER_COLLECTS_X,       "player collects"               },
1539   { CE_PLAYER_DROPS_X,          "player drops/throws"           },
1540   { CE_TOUCHING_X,              "touching"                      },
1541   { CE_HITTING_X,               "hitting"                       },
1542   { CE_HIT_BY_X,                "hit by"                        },
1543   { CE_SWITCH_OF_X,             "switch of"                     },
1544   { CE_CHANGE_OF_X,             "change by page of"             },
1545   { CE_EXPLOSION_OF_X,          "explosion of"                  },
1546   { CE_MOVE_OF_X,               "move of"                       },
1547   { CE_VALUE_GETS_ZERO_OF_X,    "CE value gets 0 of"            },
1548
1549   { -1,                         NULL                            }
1550 };
1551
1552 static struct ValueTextInfo options_change_trigger_side[] =
1553 {
1554   { CH_SIDE_LEFT,               "left"                          },
1555   { CH_SIDE_RIGHT,              "right"                         },
1556   { CH_SIDE_TOP,                "top"                           },
1557   { CH_SIDE_BOTTOM,             "bottom"                        },
1558   { CH_SIDE_LEFT_RIGHT,         "left/right"                    },
1559   { CH_SIDE_TOP_BOTTOM,         "top/bottom"                    },
1560   { CH_SIDE_ANY,                "any"                           },
1561
1562   { -1,                         NULL                            }
1563 };
1564
1565 static struct ValueTextInfo options_change_trigger_player[] =
1566 {
1567   { CH_PLAYER_1,                "1"                             },
1568   { CH_PLAYER_2,                "2"                             },
1569   { CH_PLAYER_3,                "3"                             },
1570   { CH_PLAYER_4,                "4"                             },
1571   { CH_PLAYER_ANY,              "any"                           },
1572
1573   { -1,                         NULL                            }
1574 };
1575
1576 static struct ValueTextInfo options_change_trigger_page[] =
1577 {
1578   { (1 << 0),                   "1"                             },
1579   { (1 << 1),                   "2"                             },
1580   { (1 << 2),                   "3"                             },
1581   { (1 << 3),                   "4"                             },
1582   { (1 << 4),                   "5"                             },
1583   { (1 << 5),                   "6"                             },
1584   { (1 << 6),                   "7"                             },
1585   { (1 << 7),                   "8"                             },
1586   { (1 << 8),                   "9"                             },
1587   { (1 << 9),                   "10"                            },
1588   { (1 << 10),                  "11"                            },
1589   { (1 << 11),                  "12"                            },
1590   { (1 << 12),                  "13"                            },
1591   { (1 << 13),                  "14"                            },
1592   { (1 << 14),                  "15"                            },
1593   { (1 << 15),                  "16"                            },
1594   { (1 << 16),                  "17"                            },
1595   { (1 << 17),                  "18"                            },
1596   { (1 << 18),                  "19"                            },
1597   { (1 << 19),                  "20"                            },
1598   { (1 << 20),                  "21"                            },
1599   { (1 << 21),                  "22"                            },
1600   { (1 << 22),                  "23"                            },
1601   { (1 << 23),                  "24"                            },
1602   { (1 << 24),                  "25"                            },
1603   { (1 << 25),                  "26"                            },
1604   { (1 << 26),                  "27"                            },
1605   { (1 << 27),                  "28"                            },
1606   { (1 << 28),                  "29"                            },
1607   { (1 << 29),                  "30"                            },
1608   { (1 << 30),                  "31"                            },
1609   { (1 << 31),                  "32"                            },
1610   { CH_PAGE_ANY,                "any"                           },
1611
1612   { -1,                         NULL                            }
1613 };
1614
1615 static struct ValueTextInfo options_change_replace_when[] =
1616 {
1617   { CP_WHEN_EMPTY,              "empty"                         },
1618   { CP_WHEN_WALKABLE,           "walkable"                      },
1619   { CP_WHEN_DIGGABLE,           "diggable"                      },
1620   { CP_WHEN_COLLECTIBLE,        "collectible"                   },
1621   { CP_WHEN_REMOVABLE,          "removable"                     },
1622   { CP_WHEN_DESTRUCTIBLE,       "destructible"                  },
1623
1624   { -1,                         NULL                            }
1625 };
1626
1627 static struct ValueTextInfo options_action_type[] =
1628 {
1629   { CA_NO_ACTION,               "no action"                     },
1630   { CA_UNDEFINED,               " "                             },
1631   { CA_HEADLINE_LEVEL_ACTIONS,  "[level actions]"               },
1632   { CA_RESTART_LEVEL,           "restart level"                 },
1633   { CA_SHOW_ENVELOPE,           "show envelope"                 },
1634   { CA_SET_LEVEL_TIME,          "set time"                      },
1635   { CA_SET_LEVEL_SCORE,         "set score"                     },
1636   { CA_SET_LEVEL_GEMS,          "set needed gems"               },
1637   { CA_SET_LEVEL_GRAVITY,       "set gravity"                   },
1638   { CA_SET_LEVEL_WIND,          "set wind dir."                 },
1639   { CA_UNDEFINED,               " "                             },
1640   { CA_HEADLINE_PLAYER_ACTIONS, "[player actions]"              },
1641   { CA_MOVE_PLAYER,             "move player"                   },
1642   { CA_EXIT_PLAYER,             "exit player"                   },
1643   { CA_KILL_PLAYER,             "kill player"                   },
1644   { CA_SET_PLAYER_KEYS,         "set keys"                      },
1645   { CA_SET_PLAYER_SPEED,        "set speed"                     },
1646   { CA_SET_PLAYER_SHIELD,       "set shield"                    },
1647   { CA_SET_PLAYER_ARTWORK,      "set artwork"                   },
1648   { CA_UNDEFINED,               " "                             },
1649   { CA_HEADLINE_CE_ACTIONS,     "[CE actions]"                  },
1650   { CA_SET_CE_SCORE,            "set CE score"                  },
1651   { CA_SET_CE_VALUE,            "set CE value"                  },
1652
1653   { -1,                         NULL                            }
1654 };
1655
1656 static struct ValueTextInfo options_action_mode_none[] =
1657 {
1658   { CA_ARG_UNDEFINED,           " "                             },
1659
1660   { -1,                         NULL                            }
1661 };
1662
1663 static struct ValueTextInfo options_action_mode_assign[] =
1664 {
1665   { CA_MODE_SET,                "="                             },
1666
1667   { -1,                         NULL                            }
1668 };
1669
1670 static struct ValueTextInfo options_action_mode_add_remove[] =
1671 {
1672   { CA_MODE_ADD,                "+"                             },
1673   { CA_MODE_SUBTRACT,           "-"                             },
1674
1675   { -1,                         NULL                            }
1676 };
1677
1678 static struct ValueTextInfo options_action_mode_calculate[] =
1679 {
1680   { CA_MODE_SET,                "="                             },
1681   { CA_MODE_ADD,                "+"                             },
1682   { CA_MODE_SUBTRACT,           "-"                             },
1683   { CA_MODE_MULTIPLY,           "*"                             },
1684   { CA_MODE_DIVIDE,             "/"                             },
1685   { CA_MODE_MODULO,             "%"                             },
1686
1687   { -1,                         NULL                            }
1688 };
1689
1690 static struct ValueTextInfo options_action_arg_none[] =
1691 {
1692   { CA_ARG_UNDEFINED,           "         "                     },
1693
1694   { -1,                         NULL                            }
1695 };
1696
1697 static struct ValueTextInfo options_action_arg_player[] =
1698 {
1699   { CA_ARG_PLAYER_HEADLINE,     "[player]"                      },
1700   { CA_ARG_PLAYER_1,            "1"                             },
1701   { CA_ARG_PLAYER_2,            "2"                             },
1702   { CA_ARG_PLAYER_3,            "3"                             },
1703   { CA_ARG_PLAYER_4,            "4"                             },
1704   { CA_ARG_PLAYER_ANY,          "any"                           },
1705   { CA_ARG_PLAYER_TRIGGER,      "trigger"                       },
1706
1707   { -1,                         NULL                            }
1708 };
1709
1710 static struct ValueTextInfo options_action_arg_number[] =
1711 {
1712   { CA_ARG_NUMBER_HEADLINE,     "[number]"                      },
1713   { CA_ARG_0,                   "0"                             },
1714   { CA_ARG_1,                   "1"                             },
1715   { CA_ARG_2,                   "2"                             },
1716   { CA_ARG_3,                   "3"                             },
1717   { CA_ARG_4,                   "4"                             },
1718   { CA_ARG_5,                   "5"                             },
1719   { CA_ARG_10,                  "10"                            },
1720   { CA_ARG_100,                 "100"                           },
1721   { CA_ARG_1000,                "1000"                          },
1722   { CA_ARG_UNDEFINED,           " "                             },
1723   { CA_ARG_NUMBER_MIN,          "min"                           },
1724   { CA_ARG_NUMBER_MAX,          "max"                           },
1725   { CA_ARG_UNDEFINED,           " "                             },
1726   { CA_ARG_NUMBER_RESET,        "reset"                         },
1727   { CA_ARG_UNDEFINED,           " "                             },
1728   { CA_ARG_NUMBER_CE_DELAY,     "CE delay"                      },
1729   { CA_ARG_NUMBER_CE_SCORE,     "CE score"                      },
1730   { CA_ARG_NUMBER_CE_VALUE,     "CE value"                      },
1731   { CA_ARG_UNDEFINED,           " "                             },
1732   { CA_ARG_NUMBER_LEVEL_TIME,   "time"                          },
1733   { CA_ARG_NUMBER_LEVEL_GEMS,   "gems"                          },
1734   { CA_ARG_NUMBER_LEVEL_SCORE,  "score"                         },
1735   { CA_ARG_UNDEFINED,           " "                             },
1736   { CA_ARG_ELEMENT_HEADLINE,    "[CE value"                     },
1737   { CA_ARG_ELEMENT_HEADLINE,    " of"                           },
1738   { CA_ARG_ELEMENT_HEADLINE,    " element]"                     },
1739   { CA_ARG_ELEMENT_TARGET,      "target"                        },
1740   { CA_ARG_ELEMENT_TRIGGER,     "trigger"                       },
1741
1742   { -1,                         NULL                            }
1743 };
1744
1745 static struct ValueTextInfo options_action_arg_envelope[] =
1746 {
1747   { CA_ARG_NUMBER_HEADLINE,     "[number]"                      },
1748   { CA_ARG_1,                   "1"                             },
1749   { CA_ARG_2,                   "2"                             },
1750   { CA_ARG_3,                   "3"                             },
1751   { CA_ARG_4,                   "4"                             },
1752   { CA_ARG_UNDEFINED,           " "                             },
1753   { CA_ARG_ELEMENT_HEADLINE,    "[element]"                     },
1754   { CA_ARG_ELEMENT_TARGET,      "target"                        },
1755   { CA_ARG_ELEMENT_TRIGGER,     "trigger"                       },
1756
1757   { -1,                         NULL                            }
1758 };
1759
1760 static struct ValueTextInfo options_action_arg_key[] =
1761 {
1762   { CA_ARG_NUMBER_HEADLINE,     "[number]"                      },
1763   { CA_ARG_1,                   "1"                             },
1764   { CA_ARG_2,                   "2"                             },
1765   { CA_ARG_3,                   "3"                             },
1766   { CA_ARG_4,                   "4"                             },
1767   { CA_ARG_5,                   "5"                             },
1768   { CA_ARG_6,                   "6"                             },
1769   { CA_ARG_7,                   "7"                             },
1770   { CA_ARG_8,                   "8"                             },
1771   { CA_ARG_UNDEFINED,           " "                             },
1772   { CA_ARG_ELEMENT_HEADLINE,    "[element]"                     },
1773   { CA_ARG_ELEMENT_TARGET,      "target"                        },
1774   { CA_ARG_ELEMENT_TRIGGER,     "trigger"                       },
1775
1776   { -1,                         NULL                            }
1777 };
1778
1779 static struct ValueTextInfo options_action_arg_speed[] =
1780 {
1781   { CA_ARG_SPEED_HEADLINE,      "[speed]"                       },
1782   { CA_ARG_SPEED_NOT_MOVING,    "frozen"                        },
1783   { CA_ARG_SPEED_VERY_SLOW,     "very slow"                     },
1784   { CA_ARG_SPEED_SLOW,          "slow"                          },
1785   { CA_ARG_SPEED_NORMAL,        "normal"                        },
1786   { CA_ARG_SPEED_FAST,          "fast"                          },
1787   { CA_ARG_SPEED_VERY_FAST,     "very fast"                     },
1788   { CA_ARG_SPEED_EVEN_FASTER,   "ultrafast"                     },
1789   { CA_ARG_UNDEFINED,           " "                             },
1790   { CA_ARG_SPEED_SLOWER,        "slower"                        },
1791   { CA_ARG_SPEED_FASTER,        "faster"                        },
1792   { CA_ARG_UNDEFINED,           " "                             },
1793   { CA_ARG_SPEED_RESET,         "reset"                         },
1794
1795   { -1,                         NULL                            }
1796 };
1797
1798 static struct ValueTextInfo options_action_arg_shield[] =
1799 {
1800   { CA_ARG_SHIELD_HEADLINE,     "[shield]"                      },
1801   { CA_ARG_SHIELD_OFF,          "off"                           },
1802   { CA_ARG_SHIELD_NORMAL,       "normal"                        },
1803   { CA_ARG_SHIELD_DEADLY,       "deadly"                        },
1804
1805   { -1,                         NULL                            }
1806 };
1807
1808 static struct ValueTextInfo options_action_arg_artwork[] =
1809 {
1810   { CA_ARG_ELEMENT_HEADLINE,    "[element]"                     },
1811   { CA_ARG_ELEMENT_TARGET,      "target"                        },
1812   { CA_ARG_ELEMENT_TRIGGER,     "trigger"                       },
1813   { CA_ARG_UNDEFINED,           " "                             },
1814   { CA_ARG_ELEMENT_RESET,       "reset"                         },
1815
1816   { -1,                         NULL                            }
1817 };
1818
1819 static struct ValueTextInfo options_action_arg_gravity[] =
1820 {
1821   { CA_ARG_GRAVITY_HEADLINE,    "[gravity]"                     },
1822   { CA_ARG_GRAVITY_ON,          "on"                            },
1823   { CA_ARG_GRAVITY_OFF,         "off"                           },
1824   { CA_ARG_GRAVITY_TOGGLE,      "toggle"                        },
1825
1826   { -1,                         NULL                            }
1827 };
1828
1829 static struct ValueTextInfo options_action_arg_direction[] =
1830 {
1831   { CA_ARG_DIRECTION_HEADLINE,  "[dir.]"                        },
1832   { CA_ARG_DIRECTION_NONE,      "none"                          },
1833   { CA_ARG_DIRECTION_LEFT,      "left"                          },
1834   { CA_ARG_DIRECTION_RIGHT,     "right"                         },
1835   { CA_ARG_DIRECTION_UP,        "up"                            },
1836   { CA_ARG_DIRECTION_DOWN,      "down"                          },
1837   { CA_ARG_DIRECTION_TRIGGER,   "trigger"                       },
1838   { CA_ARG_DIRECTION_TRIGGER_BACK, "-trigger"                   },
1839
1840   { -1,                         NULL                            }
1841 };
1842
1843 static char options_change_page_strings[MAX_CHANGE_PAGES][10];
1844 static struct ValueTextInfo options_change_page[MAX_CHANGE_PAGES + 1] =
1845 {
1846   { -1,                         NULL                            }
1847 };
1848
1849 static struct ValueTextInfo options_group_choice_mode[] =
1850 {
1851   { ANIM_RANDOM,                "random"                        },
1852   { ANIM_LOOP,                  "loop"                          },
1853   { ANIM_LINEAR,                "linear"                        },
1854   { ANIM_PINGPONG,              "pingpong"                      },
1855   { ANIM_PINGPONG2,             "pingpong 2"                    },
1856
1857   { -1,                         NULL                            }
1858 };
1859
1860 static struct ValueTextInfo *action_arg_modes[] =
1861 {
1862   options_action_mode_none,
1863   options_action_mode_assign,
1864   options_action_mode_add_remove,
1865   options_action_mode_calculate,
1866 };
1867
1868 static struct
1869 {
1870   int value;
1871   int mode;
1872   struct ValueTextInfo *options;
1873 }
1874 action_arg_options[] =
1875 {
1876   { CA_NO_ACTION,               0,      options_action_arg_none,        },
1877   { CA_EXIT_PLAYER,             0,      options_action_arg_player,      },
1878   { CA_KILL_PLAYER,             0,      options_action_arg_player,      },
1879   { CA_MOVE_PLAYER,             0,      options_action_arg_direction,   },
1880   { CA_RESTART_LEVEL,           0,      options_action_arg_none,        },
1881   { CA_SHOW_ENVELOPE,           0,      options_action_arg_envelope,    },
1882   { CA_SET_LEVEL_TIME,          3,      options_action_arg_number,      },
1883   { CA_SET_LEVEL_GEMS,          3,      options_action_arg_number,      },
1884   { CA_SET_LEVEL_SCORE,         3,      options_action_arg_number,      },
1885   { CA_SET_LEVEL_GRAVITY,       1,      options_action_arg_gravity,     },
1886   { CA_SET_LEVEL_WIND,          1,      options_action_arg_direction,   },
1887   { CA_SET_PLAYER_KEYS,         2,      options_action_arg_key,         },
1888   { CA_SET_PLAYER_SPEED,        1,      options_action_arg_speed,       },
1889   { CA_SET_PLAYER_SHIELD,       1,      options_action_arg_shield,      },
1890   { CA_SET_PLAYER_ARTWORK,      1,      options_action_arg_artwork,     },
1891   { CA_SET_CE_SCORE,            3,      options_action_arg_number,      },
1892   { CA_SET_CE_VALUE,            3,      options_action_arg_number,      },
1893
1894   { -1,                         FALSE,  NULL                            }
1895 };
1896
1897 static struct
1898 {
1899   int x, y;
1900   int gadget_id;
1901   int gadget_id_align;
1902   int size;     /* char size of selectbox or '-1' (dynamically determined) */
1903   struct ValueTextInfo *options;
1904   int *value;
1905   char *text_left, *text_right, *infotext;
1906 } selectbox_info[ED_NUM_SELECTBOX] =
1907 {
1908   /* ---------- level and editor settings ---------------------------------- */
1909
1910   {
1911     -1,                                 ED_LEVEL_SETTINGS_YPOS(8),
1912     GADGET_ID_TIME_OR_STEPS,            GADGET_ID_LEVEL_TIMELIMIT_UP,
1913     -1,
1914     options_time_or_steps,
1915     &level.use_step_counter,
1916     NULL, "(0 => no limit)",            "time or step limit"
1917   },
1918   {
1919     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(5),
1920     GADGET_ID_GAME_ENGINE_TYPE,         GADGET_ID_NONE,
1921     -1,
1922     options_game_engine_type,
1923     &level.game_engine_type,
1924     "game engine:", NULL,               "game engine"
1925   },
1926   {
1927     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(12),
1928     GADGET_ID_WIND_DIRECTION,           GADGET_ID_NONE,
1929     -1,
1930     options_wind_direction,
1931     &level.wind_direction_initial,
1932     "initial wind direction:", NULL,    "initial wind direction"
1933   },
1934
1935   /* ---------- element settings: configure (several elements) ------------- */
1936
1937   /* ---------- element settings: configure 1 (custom elements) ------------ */
1938
1939   {
1940     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(3),
1941     GADGET_ID_CUSTOM_ACCESS_TYPE,       GADGET_ID_NONE,
1942     -1,
1943     options_access_type,
1944     &custom_element.access_type,
1945     NULL, NULL,                         "type of access to this field"
1946   },
1947   {
1948     -1,                                 ED_ELEMENT_SETTINGS_YPOS(3),
1949     GADGET_ID_CUSTOM_ACCESS_LAYER,      GADGET_ID_CUSTOM_ACCESS_TYPE,
1950     -1,
1951     options_access_layer,
1952     &custom_element.access_layer,
1953     NULL, NULL,                         "layer of access for this field"
1954   },
1955   {
1956     -1,                                 ED_ELEMENT_SETTINGS_YPOS(3),
1957     GADGET_ID_CUSTOM_ACCESS_PROTECTED,  GADGET_ID_CUSTOM_ACCESS_LAYER,
1958     -1,
1959     options_access_protected,
1960     &custom_element.access_protected,
1961     NULL, NULL,                         "protected access for this field"
1962   },
1963   {
1964     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(4),
1965     GADGET_ID_CUSTOM_ACCESS_DIRECTION,  GADGET_ID_NONE,
1966     -1,
1967     options_access_direction,
1968     &custom_element.access_direction,
1969     "from", NULL,                       "access direction for this field"
1970   },
1971   {
1972     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(5),
1973     GADGET_ID_CUSTOM_WALK_TO_ACTION,    GADGET_ID_NONE,
1974     -1,
1975     options_walk_to_action,
1976     &custom_element.walk_to_action,
1977     NULL, NULL,                         "diggable/collectible/pushable"
1978   },
1979
1980   /* ---------- element settings: configure 2 (custom elements) ------------ */
1981
1982   {
1983     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(1),
1984     GADGET_ID_CUSTOM_MOVE_PATTERN,      GADGET_ID_NONE,
1985     -1,
1986     options_move_pattern,
1987     &custom_element.move_pattern,
1988     "can move", NULL,                   "element move pattern"
1989   },
1990   {
1991     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(2),
1992     GADGET_ID_CUSTOM_MOVE_DIRECTION,    GADGET_ID_NONE,
1993     -1,
1994     options_move_direction,
1995     &custom_element.move_direction_initial,
1996     "starts moving", NULL,              "initial element move direction"
1997   },
1998   {
1999     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(4),
2000     GADGET_ID_CUSTOM_MOVE_STEPSIZE,     GADGET_ID_NONE,
2001     -1,
2002     options_move_stepsize,
2003     &custom_element.move_stepsize,
2004     "move/fall speed", NULL,            "speed of element movement"
2005   },
2006   {
2007     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(3),
2008     GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE,   GADGET_ID_NONE,
2009     -1,
2010     options_move_leave_type,
2011     &custom_element.move_leave_type,
2012     "can dig:    can", ":",             "leave behind or change element"
2013   },
2014   {
2015     -1,                                 ED_ELEMENT_SETTINGS_YPOS(7),
2016     GADGET_ID_CUSTOM_SMASH_TARGETS,     GADGET_ID_CUSTOM_CAN_SMASH,
2017     -1,
2018     options_smash_targets,
2019     &custom_element.smash_targets,
2020     "can smash", NULL,                  "elements that can be smashed"
2021   },
2022   {
2023     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(8),
2024     GADGET_ID_CUSTOM_SLIPPERY_TYPE,     GADGET_ID_NONE,
2025     -1,
2026     options_slippery_type,
2027     &custom_element.slippery_type,
2028     "slippery", NULL,                   "where other elements fall down"
2029   },
2030   {
2031     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(9),
2032     GADGET_ID_CUSTOM_DEADLINESS,        GADGET_ID_NONE,
2033     -1,
2034     options_deadliness,
2035     &custom_element.deadliness,
2036     "deadly when", NULL,                "deadliness of element"
2037   },
2038   {
2039     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(10),
2040     GADGET_ID_CUSTOM_EXPLOSION_TYPE,    GADGET_ID_NONE,
2041     -1,
2042     options_explosion_type,
2043     &custom_element.explosion_type,
2044     "can explode", NULL,                "explosion type"
2045   },
2046
2047   /* ---------- element settings: advanced (custom elements) --------------- */
2048
2049   {
2050     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(3),
2051     GADGET_ID_CHANGE_TIME_UNITS,        GADGET_ID_NONE,
2052     -1,
2053     options_time_units,
2054     &custom_element_change.delay_frames,
2055     "delay time given in", NULL,        "delay time units for change"
2056   },
2057   {
2058     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(4),
2059     GADGET_ID_CHANGE_DIRECT_ACTION,     GADGET_ID_NONE,
2060     -1,
2061     options_change_direct_action,
2062     &custom_element_change.direct_action,
2063     NULL, NULL,                         "type of direct action"
2064   },
2065   {
2066     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(5),
2067     GADGET_ID_CHANGE_OTHER_ACTION,      GADGET_ID_NONE,
2068     -1,
2069     options_change_other_action,
2070     &custom_element_change.other_action,
2071     NULL, "element:",                   "type of other element action"
2072   },
2073   {
2074     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(6),
2075     GADGET_ID_CHANGE_SIDE,              GADGET_ID_NONE,
2076     -1,
2077     options_change_trigger_side,
2078     &custom_element_change.trigger_side,
2079     "at", "side",                       "element side triggering change"
2080   },
2081   {
2082     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(7),
2083     GADGET_ID_CHANGE_PLAYER,            GADGET_ID_NONE,
2084     -1,
2085     options_change_trigger_player,
2086     &custom_element_change.trigger_player,
2087     "player:", " ",                     "player that causes change"
2088   },
2089   {
2090     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(7),
2091     GADGET_ID_CHANGE_PAGE,              GADGET_ID_CHANGE_PLAYER,
2092     -1,
2093     options_change_trigger_page,
2094     &custom_element_change.trigger_page,
2095     "page:", NULL,                      "change page that causes change"
2096   },
2097   {
2098     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(10),
2099     GADGET_ID_CHANGE_REPLACE_WHEN,      GADGET_ID_NONE,
2100     -1,
2101     options_change_replace_when,
2102     &custom_element_change.replace_when,
2103     "replace when", NULL,               "which elements can be replaced"
2104   },
2105   {
2106     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(13),
2107     GADGET_ID_ACTION_TYPE,              GADGET_ID_NONE,
2108     -1,
2109     options_action_type,
2110     &custom_element_change.action_type,
2111     NULL, NULL,                         "action on specified condition"
2112   },
2113   {
2114     -1,                                 ED_ELEMENT_SETTINGS_YPOS(13),
2115     GADGET_ID_ACTION_MODE,              GADGET_ID_ACTION_TYPE,
2116     -1,
2117     options_action_mode_none,
2118     &custom_element_change.action_mode,
2119     NULL, NULL,                         "action operator"
2120   },
2121   {
2122     -1,                                 ED_ELEMENT_SETTINGS_YPOS(13),
2123     GADGET_ID_ACTION_ARG,               GADGET_ID_ACTION_MODE,
2124     -1,
2125     options_action_arg_none,
2126     &custom_element_change.action_arg,
2127     NULL, NULL,                         "action parameter"
2128   },
2129   {
2130     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(14),
2131     GADGET_ID_SELECT_CHANGE_PAGE,       GADGET_ID_NONE,
2132     3,
2133     options_change_page,
2134     &custom_element.current_change_page,
2135     NULL, NULL,                         "element change page"
2136   },
2137
2138   /* ---------- element settings: configure (group elements) --------------- */
2139
2140   {
2141     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(6),
2142     GADGET_ID_GROUP_CHOICE_MODE,        GADGET_ID_NONE,
2143     -1,
2144     options_group_choice_mode,
2145     &group_element_info.choice_mode,
2146     "choice type:", NULL,               "type of group element choice"
2147   },
2148 };
2149
2150 static struct
2151 {
2152   int x, y;
2153   int gadget_id;
2154   int gadget_id_align;
2155   int size;
2156   char *text;
2157   char *text_left, *text_right, *infotext;
2158 } textbutton_info[ED_NUM_TEXTBUTTONS] =
2159 {
2160   {
2161     ED_ELEMENT_SETTINGS_XPOS(0),        ED_COUNTER_YPOS(1),
2162     GADGET_ID_PROPERTIES_INFO,          GADGET_ID_NONE,
2163     8,                                  "Info",                 
2164     NULL, NULL,                         "Show information about element"
2165   },
2166   {
2167     ED_ELEMENT_SETTINGS_XPOS(0) + 124,  ED_COUNTER_YPOS(1),
2168     GADGET_ID_PROPERTIES_CONFIG,        GADGET_ID_NONE,
2169     8,                                  "Config",
2170     NULL, NULL,                         "Configure element properties"
2171   },
2172   {
2173     ED_ELEMENT_SETTINGS_XPOS(0) + 124,  ED_COUNTER_YPOS(1),
2174     GADGET_ID_PROPERTIES_CONFIG_1,      GADGET_ID_NONE,
2175     8,                                  "Config 1",
2176     NULL, NULL,                         "Configure custom element properties"
2177   },
2178   {
2179     ED_ELEMENT_SETTINGS_XPOS(0) + 248,  ED_COUNTER_YPOS(1),
2180     GADGET_ID_PROPERTIES_CONFIG_2,      GADGET_ID_NONE,
2181     8,                                  "Config 2",
2182     NULL, NULL,                         "Configure custom element properties"
2183   },
2184   {
2185     ED_ELEMENT_SETTINGS_XPOS(0) + 372,  ED_COUNTER_YPOS(1),
2186     GADGET_ID_PROPERTIES_CHANGE,        GADGET_ID_NONE,
2187     8,                                  "Change",
2188     NULL, NULL,                         "Custom element change configuration"
2189   },
2190   {
2191     -1,                                 ED_ELEMENT_SETTINGS_YPOS(2),
2192     GADGET_ID_SAVE_AS_TEMPLATE,         GADGET_ID_CUSTOM_USE_TEMPLATE,
2193     -1,                                 "Save",
2194     " ", "As Template",                 "Save current settings as new template"
2195   },
2196   {
2197     -1,                                 ED_ELEMENT_SETTINGS_YPOS(14),
2198     GADGET_ID_ADD_CHANGE_PAGE,          GADGET_ID_PASTE_CHANGE_PAGE,
2199     -1,                                 "New",
2200     NULL, NULL,                         "Add new change page"
2201   },
2202   {
2203     -1,                                 ED_ELEMENT_SETTINGS_YPOS(14),
2204     GADGET_ID_DEL_CHANGE_PAGE,          GADGET_ID_ADD_CHANGE_PAGE,
2205     -1,                                 "Delete",
2206     NULL, NULL,                         "Delete current change page"
2207   },
2208 };
2209
2210 static struct
2211 {
2212   int gd_x, gd_y;
2213   int x, y;
2214   int width, height;
2215   int gadget_id;
2216   int gadget_id_align;
2217   char *text_left, *text_right, *infotext;
2218 } graphicbutton_info[ED_NUM_GRAPHICBUTTONS] =
2219 {
2220   {
2221     ED_BUTTON_MINUS_XPOS,               ED_BUTTON_COUNT_YPOS,
2222     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(14),
2223     ED_BUTTON_COUNT_XSIZE,              ED_BUTTON_COUNT_YSIZE,
2224     GADGET_ID_PREV_CHANGE_PAGE,         GADGET_ID_NONE,
2225     NULL, NULL,                         "select previous change page"
2226   },
2227   {
2228     ED_BUTTON_PLUS_XPOS,                ED_BUTTON_COUNT_YPOS,
2229     -1,                                 ED_ELEMENT_SETTINGS_YPOS(14),
2230     ED_BUTTON_COUNT_XSIZE,              ED_BUTTON_COUNT_YSIZE,
2231     GADGET_ID_NEXT_CHANGE_PAGE,         GADGET_ID_SELECT_CHANGE_PAGE,
2232     NULL, "change page",                "select next change page"
2233   },
2234   {
2235     ED_COPY_CHANGE_PAGE_XPOS,           ED_COPY_CHANGE_PAGE_YPOS,
2236     -1,                                 ED_ELEMENT_SETTINGS_YPOS(14),
2237     ED_BUTTON_COUNT_XSIZE,              ED_BUTTON_COUNT_YSIZE,
2238     GADGET_ID_COPY_CHANGE_PAGE,         GADGET_ID_NEXT_CHANGE_PAGE,
2239     " ", NULL,                          "copy settings from this change page"
2240   },
2241   {
2242     ED_PASTE_CHANGE_PAGE_XPOS,          ED_PASTE_CHANGE_PAGE_YPOS,
2243     -1,                                 ED_ELEMENT_SETTINGS_YPOS(14),
2244     ED_BUTTON_COUNT_XSIZE,              ED_BUTTON_COUNT_YSIZE,
2245     GADGET_ID_PASTE_CHANGE_PAGE,        GADGET_ID_COPY_CHANGE_PAGE,
2246     NULL, NULL,                         "paste settings to this change page"
2247   },
2248 };
2249
2250 static struct
2251 {
2252   int gd_x, gd_y;
2253   int x, y;
2254   int gadget_id;
2255   char *infotext;
2256 } scrollbutton_info[ED_NUM_SCROLLBUTTONS] =
2257 {
2258   {
2259     ED_SCROLLBUTTON_XPOS,   ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE,
2260     ED_SCROLL_UP_XPOS,      ED_SCROLL_UP_YPOS,
2261     GADGET_ID_SCROLL_UP,
2262     "scroll level editing area up"
2263   },
2264   {
2265     ED_SCROLLBUTTON_XPOS,   ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE,
2266     ED_SCROLL_DOWN_XPOS,    ED_SCROLL_DOWN_YPOS,
2267     GADGET_ID_SCROLL_DOWN,
2268     "scroll level editing area down"
2269   },
2270   {
2271     ED_SCROLLBUTTON_XPOS,   ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE,
2272     ED_SCROLL_LEFT_XPOS,    ED_SCROLL_LEFT_YPOS,
2273     GADGET_ID_SCROLL_LEFT,
2274     "scroll level editing area left"
2275   },
2276   {
2277     ED_SCROLLBUTTON_XPOS,   ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE,
2278     ED_SCROLL_RIGHT_XPOS,   ED_SCROLL_RIGHT_YPOS,
2279     GADGET_ID_SCROLL_RIGHT,
2280     "scroll level editing area right"
2281   },
2282   {
2283     ED_SCROLLBUTTON2_XPOS,  ED_SCROLLBUTTON2_YPOS + 0 * ED_SCROLLBUTTON2_YSIZE,
2284     ED_SCROLL2_UP_XPOS,     ED_SCROLL2_UP_YPOS,
2285     GADGET_ID_SCROLL_LIST_UP,
2286     "scroll element list up ('Page Up')"
2287   },
2288   {
2289     ED_SCROLLBUTTON2_XPOS,  ED_SCROLLBUTTON2_YPOS + 1 * ED_SCROLLBUTTON2_YSIZE,
2290     ED_SCROLL2_DOWN_XPOS,   ED_SCROLL2_DOWN_YPOS,
2291     GADGET_ID_SCROLL_LIST_DOWN,
2292     "scroll element list down ('Page Down')"
2293   },
2294 };
2295
2296 static struct
2297 {
2298   int gd_x, gd_y;
2299   int x, y;
2300   int width, height;
2301   int type;
2302   int gadget_id;
2303   char *infotext;
2304 } scrollbar_info[ED_NUM_SCROLLBARS] =
2305 {
2306   {
2307     ED_SCROLLBAR_XPOS,                  ED_SCROLLBAR_YPOS,
2308     SX + ED_SCROLL_HORIZONTAL_XPOS,     SY + ED_SCROLL_HORIZONTAL_YPOS,
2309     ED_SCROLL_HORIZONTAL_XSIZE,         ED_SCROLL_HORIZONTAL_YSIZE,
2310     GD_TYPE_SCROLLBAR_HORIZONTAL,
2311     GADGET_ID_SCROLL_HORIZONTAL,
2312     "scroll level editing area horizontally"
2313   },
2314   {
2315     ED_SCROLLBAR_XPOS,                  ED_SCROLLBAR_YPOS,
2316     SX + ED_SCROLL_VERTICAL_XPOS,       SY + ED_SCROLL_VERTICAL_YPOS,
2317     ED_SCROLL_VERTICAL_XSIZE,           ED_SCROLL_VERTICAL_YSIZE,
2318     GD_TYPE_SCROLLBAR_VERTICAL,
2319     GADGET_ID_SCROLL_VERTICAL,
2320     "scroll level editing area vertically"
2321   },
2322   {
2323     ED_SCROLLBAR2_XPOS,                 ED_SCROLLBAR2_YPOS,
2324     DX + ED_SCROLL2_VERTICAL_XPOS,      DY + ED_SCROLL2_VERTICAL_YPOS,
2325     ED_SCROLL2_VERTICAL_XSIZE,          ED_SCROLL2_VERTICAL_YSIZE,
2326     GD_TYPE_SCROLLBAR_VERTICAL,
2327     GADGET_ID_SCROLL_LIST_VERTICAL,
2328     "scroll element list vertically"
2329   }
2330 };
2331
2332 static struct
2333 {
2334   int x, y;
2335   int gadget_id;
2336   int gadget_id_align;
2337   int radio_button_nr;
2338   int *value;
2339   int checked_value;
2340   char *text_left, *text_right, *infotext;
2341 } radiobutton_info[ED_NUM_RADIOBUTTONS] =
2342 {
2343   {
2344     -1,                                 ED_COUNTER2_YPOS(8),
2345     GADGET_ID_RANDOM_PERCENTAGE,        GADGET_ID_LEVEL_RANDOM_UP,
2346     RADIO_NR_RANDOM_ELEMENTS,
2347     &random_placement_method,           RANDOM_USE_PERCENTAGE,
2348     " ", "percentage",                  "use percentage for random elements"
2349   },
2350   {
2351     -1,                                 ED_COUNTER2_YPOS(8),
2352     GADGET_ID_RANDOM_QUANTITY,          GADGET_ID_RANDOM_PERCENTAGE,
2353     RADIO_NR_RANDOM_ELEMENTS,
2354     &random_placement_method,           RANDOM_USE_QUANTITY,
2355     " ", "quantity",                    "use quantity for random elements"
2356   }
2357 };
2358
2359 static struct
2360 {
2361   int x, y;
2362   int gadget_id;
2363   int gadget_id_align;
2364   boolean *value;
2365   char *text_left, *text_right, *infotext;
2366 } checkbutton_info[ED_NUM_CHECKBUTTONS] =
2367 {
2368   /* ---------- level and editor settings ---------------------------------- */
2369
2370   {
2371     ED_LEVEL_SETTINGS_XPOS(0),          ED_LEVEL_SETTINGS_YPOS(11),
2372     GADGET_ID_INITIAL_GRAVITY,          GADGET_ID_NONE,
2373     &level.initial_gravity,
2374     NULL,
2375     "initial gravity",                  "set initial level gravity"
2376   },
2377   {
2378     ED_LEVEL_SETTINGS_XPOS(0),          ED_COUNTER2_YPOS(9) - MINI_TILEY,
2379     GADGET_ID_RANDOM_RESTRICTED,        GADGET_ID_NONE,
2380     &random_placement_background_restricted,
2381     NULL,
2382     "restrict random placement to:",    "set random placement restriction"
2383   },
2384
2385   /* ---------- element settings: configure (various elements) ------------- */
2386
2387   {
2388     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(0),
2389     GADGET_ID_STICK_ELEMENT,            GADGET_ID_NONE,
2390     &stick_element_properties_window,
2391     NULL,
2392     "stick this screen to edit content","stick this screen to edit content"
2393   },
2394   {
2395     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2396     GADGET_ID_EM_SLIPPERY_GEMS,         GADGET_ID_NONE,
2397     &level.em_slippery_gems,
2398     NULL,
2399     "slip down from certain flat walls","use EM style slipping behaviour"
2400   },
2401   {
2402     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2403     GADGET_ID_USE_SPRING_BUG,           GADGET_ID_NONE,
2404     &level.use_spring_bug,
2405     NULL,
2406     "use spring pushing bug",           "use odd spring pushing behaviour"
2407   },
2408   {
2409     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2410     GADGET_ID_USE_TIME_ORB_BUG,         GADGET_ID_NONE,
2411     &level.use_time_orb_bug,
2412     NULL,
2413     "use time orb bug",                 "use odd time orb behaviour"
2414   },
2415   {
2416     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(2),
2417     GADGET_ID_RANDOM_BALL_CONTENT,      GADGET_ID_NONE,
2418     &level.ball_random,
2419     NULL,
2420     "create single random element",     "only create one element from content"
2421   },
2422   {
2423     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2424     GADGET_ID_INITIAL_BALL_STATE,       GADGET_ID_NONE,
2425     &level.ball_state_initial,
2426     NULL,
2427     "magic ball initially activated",   "activate magic ball after level start"
2428   },
2429   {
2430     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(0),
2431     GADGET_ID_GROW_INTO_DIGGABLE,       GADGET_ID_NONE,
2432     &level.grow_into_diggable,
2433     NULL,
2434     "can grow into anything diggable",  "grow into more than just sand"
2435   },
2436   {
2437     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(5),
2438     GADGET_ID_DOUBLE_SPEED,             GADGET_ID_NONE,
2439     &level.double_speed,
2440     NULL,
2441     "double speed movement",            "set initial movement speed of player"
2442   },
2443   {
2444     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(6),
2445     GADGET_ID_BLOCK_SNAP_FIELD,         GADGET_ID_NONE,
2446     &level.block_snap_field,
2447     NULL,
2448     "block snapped field when snapping", "use snapping delay to show animation"
2449   },
2450   {
2451     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(2),
2452     GADGET_ID_BLOCK_LAST_FIELD,         GADGET_ID_NONE,
2453     &level.block_last_field,
2454     NULL,
2455     "block last field when moving",     "player blocks last field when moving"
2456   },
2457   {
2458     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(2),
2459     GADGET_ID_SP_BLOCK_LAST_FIELD,      GADGET_ID_NONE,
2460     &level.sp_block_last_field,
2461     NULL,
2462     "block last field when moving",     "player blocks last field when moving"
2463   },
2464   {
2465     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(3),
2466     GADGET_ID_INSTANT_RELOCATION,       GADGET_ID_NONE,
2467     &level.instant_relocation,
2468     NULL,
2469     "no scrolling when relocating",     "player gets relocated without delay"
2470   },
2471   {
2472     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(7),
2473     GADGET_ID_USE_START_ELEMENT,        GADGET_ID_NONE,
2474     &level.use_start_element[0],
2475     NULL,
2476     "use level start element:",        "start level at this element's position"
2477   },
2478   {
2479     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(8),
2480     GADGET_ID_USE_ARTWORK_ELEMENT,      GADGET_ID_NONE,
2481     &level.use_artwork_element[0],
2482     NULL,
2483     "use artwork from element:",        "use player artwork from other element"
2484   },
2485   {
2486     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(9),
2487     GADGET_ID_USE_EXPLOSION_ELEMENT,    GADGET_ID_NONE,
2488     &level.use_explosion_element[0],
2489     NULL,
2490     "use explosion from element:",      "use explosion properties from element"
2491   },
2492   {
2493     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(4),
2494     GADGET_ID_CAN_PASS_TO_WALKABLE,     GADGET_ID_NONE,
2495     &level.can_pass_to_walkable,
2496     NULL,
2497     "can pass to walkable element",     "player can pass to empty or walkable"
2498   },
2499   {
2500     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2501     GADGET_ID_CAN_FALL_INTO_ACID,       GADGET_ID_NONE,
2502     &custom_element_properties[EP_CAN_MOVE_INTO_ACID],
2503     NULL,
2504     "can fall into acid (with gravity)","player can fall into acid pool"
2505   },
2506   {
2507     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(0),
2508     GADGET_ID_CAN_MOVE_INTO_ACID,       GADGET_ID_NONE,
2509     &custom_element_properties[EP_CAN_MOVE_INTO_ACID],
2510     NULL,
2511     "can move into acid",               "element can move into acid pool"
2512   },
2513   {
2514     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2515     GADGET_ID_DONT_COLLIDE_WITH,        GADGET_ID_NONE,
2516     &custom_element_properties[EP_DONT_COLLIDE_WITH],
2517     NULL,
2518     "deadly when colliding with",       "element is deadly when hitting player"
2519   },
2520
2521   /* ---------- element settings: configure 1 (custom elements) ----------- */
2522
2523   {
2524     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2525     GADGET_ID_CUSTOM_USE_GRAPHIC,       GADGET_ID_NONE,
2526     &custom_element.use_gfx_element,
2527
2528     /* !!! add separate "use existing element sound" !!! */
2529 #if 0
2530     NULL, "use graphic/sound of element:", "use existing graphic and sound"
2531 #else
2532     NULL, "use graphic of element:",    "use existing element graphic"
2533 #endif
2534   },
2535   {
2536     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(2),
2537     GADGET_ID_CUSTOM_USE_TEMPLATE,      GADGET_ID_NONE,
2538     &level.use_custom_template,
2539     NULL, "use template",               "use template for custom properties"
2540   },
2541   {
2542     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(3),
2543     GADGET_ID_CUSTOM_ACCESSIBLE,        GADGET_ID_NONE,
2544     &custom_element_properties[EP_ACCESSIBLE],
2545     NULL, NULL,                         "player can walk to or pass this field"
2546   },
2547   {
2548     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(10),
2549     GADGET_ID_CUSTOM_GRAV_REACHABLE,    GADGET_ID_NONE,
2550     &custom_element_properties[EP_GRAVITY_REACHABLE],
2551     NULL, "reachable despite gravity",  "player can walk/dig despite gravity"
2552   },
2553   {
2554     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(13),
2555     GADGET_ID_CUSTOM_USE_LAST_VALUE,    GADGET_ID_NONE,
2556     &custom_element.use_last_ce_value,
2557     NULL, "use last CE value after change", "use last CE value after change"
2558   },
2559   {
2560     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(5),
2561     GADGET_ID_CUSTOM_WALK_TO_OBJECT,    GADGET_ID_NONE,
2562     &custom_element_properties[EP_WALK_TO_OBJECT],
2563     NULL, NULL,                         "player can dig/collect/push element"
2564   },
2565   {
2566     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(9),
2567     GADGET_ID_CUSTOM_INDESTRUCTIBLE,    GADGET_ID_NONE,
2568     &custom_element_properties[EP_INDESTRUCTIBLE],
2569     NULL, "indestructible",             "element is indestructible"
2570   },
2571
2572   /* ---------- element settings: configure 2 (custom elements) ----------- */
2573
2574   {
2575     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2576     GADGET_ID_CUSTOM_CAN_MOVE,          GADGET_ID_NONE,
2577     &custom_element_properties[EP_CAN_MOVE],
2578     NULL, NULL,                         "element can move with some pattern"
2579   },
2580   {
2581     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(7),
2582     GADGET_ID_CUSTOM_CAN_FALL,          GADGET_ID_NONE,
2583     &custom_element_properties[EP_CAN_FALL],
2584     NULL, "can fall",                   "element can fall down"
2585   },
2586   {
2587     -1,                                 ED_ELEMENT_SETTINGS_YPOS(7),
2588     GADGET_ID_CUSTOM_CAN_SMASH,         GADGET_ID_CUSTOM_CAN_FALL,
2589     &custom_element_properties[EP_CAN_SMASH],
2590     " ", NULL,                          "element can smash other elements"
2591   },
2592   {
2593     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(8),
2594     GADGET_ID_CUSTOM_SLIPPERY,          GADGET_ID_NONE,
2595     &custom_element_properties[EP_SLIPPERY],
2596     NULL, NULL,                         "other elements can fall down from it"
2597   },
2598   {
2599     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(9),
2600     GADGET_ID_CUSTOM_DEADLY,            GADGET_ID_NONE,
2601     &custom_element_properties[EP_DEADLY],
2602     NULL, NULL,                         "element can kill the player"
2603   },
2604   {
2605     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(10),
2606     GADGET_ID_CUSTOM_CAN_EXPLODE,       GADGET_ID_NONE,
2607     &custom_element_properties[EP_CAN_EXPLODE],
2608     NULL, NULL,                         "element can explode"
2609   },
2610   {
2611     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(11),
2612     GADGET_ID_CUSTOM_EXPLODE_FIRE,      GADGET_ID_NONE,
2613     &custom_element_properties[EP_EXPLODES_BY_FIRE],
2614     NULL, "by fire",                    "element can explode by fire/explosion"
2615   },
2616   {
2617     -1,                                 ED_ELEMENT_SETTINGS_YPOS(11),
2618     GADGET_ID_CUSTOM_EXPLODE_SMASH,     GADGET_ID_CUSTOM_EXPLODE_FIRE,
2619     &custom_element_properties[EP_EXPLODES_SMASHED],
2620     " ", "smashed",                     "element can explode when smashed"
2621   },
2622   {
2623     -1,                                 ED_ELEMENT_SETTINGS_YPOS(11),
2624     GADGET_ID_CUSTOM_EXPLODE_IMPACT,    GADGET_ID_CUSTOM_EXPLODE_SMASH,
2625     &custom_element_properties[EP_EXPLODES_IMPACT],
2626     " ", "impact",                      "element can explode on impact"
2627   },
2628
2629   /* ---------- element settings: advanced (custom elements) --------------- */
2630
2631   {
2632     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(1),
2633     GADGET_ID_CUSTOM_CAN_CHANGE,        GADGET_ID_NONE,
2634     &custom_element_change.can_change,
2635     NULL, "element changes to:",        "change element on specified condition"
2636   },
2637   {
2638     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(2),
2639     GADGET_ID_CHANGE_DELAY,             GADGET_ID_NONE,
2640     &custom_element_change_events[CE_DELAY],
2641     NULL, NULL,                         "element changes after delay"
2642   },
2643   {
2644     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(4),
2645     GADGET_ID_CHANGE_BY_DIRECT_ACT,     GADGET_ID_NONE,
2646     &custom_element_change_events[CE_BY_DIRECT_ACTION],
2647     NULL, NULL,                         "element changes by direct action"
2648   },
2649   {
2650     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(5),
2651     GADGET_ID_CHANGE_BY_OTHER_ACT,      GADGET_ID_NONE,
2652     &custom_element_change_events[CE_BY_OTHER_ACTION],
2653     NULL, NULL,                         "element changes by other element"
2654   },
2655   {
2656     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(8),
2657     GADGET_ID_CHANGE_USE_EXPLOSION,     GADGET_ID_NONE,
2658     &custom_element_change.explode,
2659     NULL, "explode instead of change",  "element explodes instead of change"
2660   },
2661   {
2662     ED_ELEMENT_SETTINGS_XPOS(1),        ED_ELEMENT_SETTINGS_YPOS(9),
2663     GADGET_ID_CHANGE_USE_CONTENT,       GADGET_ID_NONE,
2664     &custom_element_change.use_target_content,
2665     NULL, "use extended change target:","element changes to more elements"
2666   },
2667   {
2668     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(11),
2669     GADGET_ID_CHANGE_ONLY_COMPLETE,     GADGET_ID_NONE,
2670     &custom_element_change.only_if_complete,
2671     NULL, "replace all or nothing",     "only replace when all can be changed"
2672   },
2673   {
2674     ED_ELEMENT_SETTINGS_XPOS(2),        ED_ELEMENT_SETTINGS_YPOS(12),
2675     GADGET_ID_CHANGE_USE_RANDOM,        GADGET_ID_NONE,
2676     &custom_element_change.use_random_replace,
2677     NULL, NULL,                         "use percentage for random replace"
2678   },
2679   {
2680     ED_ELEMENT_SETTINGS_XPOS(0),        ED_ELEMENT_SETTINGS_YPOS(13),
2681     GADGET_ID_CHANGE_HAS_ACTION,        GADGET_ID_NONE,
2682     &custom_element_change.has_action,
2683     NULL, NULL,                         "execute action on specified condition"
2684   },
2685 };
2686
2687 static struct
2688 {
2689   int x, y;
2690   int gadget_id;
2691   int gadget_id_align;
2692   int *value;
2693   int area_xsize, area_ysize;
2694   char *text_left, *text_right, *text_below, *infotext;
2695 } drawingarea_info[ED_NUM_DRAWING_AREAS] =
2696 {
2697   /* ---------- level playfield content ------------------------------------ */
2698
2699   {
2700     0,                                  0,
2701     GADGET_ID_DRAWING_LEVEL,            GADGET_ID_NONE,
2702     NULL,                               MAX_ED_FIELDX, MAX_ED_FIELDY,
2703     NULL, NULL, NULL,                   NULL
2704   },
2705
2706   /* ---------- yam yam content -------------------------------------------- */
2707
2708   {
2709     ED_AREA_YAMYAM_CONTENT_XPOS(0),     ED_AREA_YAMYAM_CONTENT_YPOS(0),
2710     GADGET_ID_YAMYAM_CONTENT_0,         GADGET_ID_NONE,
2711     &level.yamyam_content[0].e[0][0],   3, 3,
2712     NULL, NULL, "1",                    NULL
2713   },
2714   {
2715     ED_AREA_YAMYAM_CONTENT_XPOS(1),     ED_AREA_YAMYAM_CONTENT_YPOS(1),
2716     GADGET_ID_YAMYAM_CONTENT_1,         GADGET_ID_NONE,
2717     &level.yamyam_content[1].e[0][0],   3, 3,
2718     NULL, NULL, "2",                    NULL
2719   },
2720   {
2721     ED_AREA_YAMYAM_CONTENT_XPOS(2),     ED_AREA_YAMYAM_CONTENT_YPOS(2),
2722     GADGET_ID_YAMYAM_CONTENT_2,         GADGET_ID_NONE,
2723     &level.yamyam_content[2].e[0][0],   3, 3,
2724     NULL, NULL, "3",                    NULL
2725   },
2726   {
2727     ED_AREA_YAMYAM_CONTENT_XPOS(3),     ED_AREA_YAMYAM_CONTENT_YPOS(3),
2728     GADGET_ID_YAMYAM_CONTENT_3,         GADGET_ID_NONE,
2729     &level.yamyam_content[3].e[0][0],   3, 3,
2730     NULL, NULL, "4",                    NULL
2731   },
2732   {
2733     ED_AREA_YAMYAM_CONTENT_XPOS(4),     ED_AREA_YAMYAM_CONTENT_YPOS(4),
2734     GADGET_ID_YAMYAM_CONTENT_4,         GADGET_ID_NONE,
2735     &level.yamyam_content[4].e[0][0],   3, 3,
2736     NULL, NULL, "5",                    NULL
2737   },
2738   {
2739     ED_AREA_YAMYAM_CONTENT_XPOS(5),     ED_AREA_YAMYAM_CONTENT_YPOS(5),
2740     GADGET_ID_YAMYAM_CONTENT_5,         GADGET_ID_NONE,
2741     &level.yamyam_content[5].e[0][0],   3, 3,
2742     NULL, NULL, "6",                    NULL
2743   },
2744   {
2745     ED_AREA_YAMYAM_CONTENT_XPOS(6),     ED_AREA_YAMYAM_CONTENT_YPOS(6),
2746     GADGET_ID_YAMYAM_CONTENT_6,         GADGET_ID_NONE,
2747     &level.yamyam_content[6].e[0][0],   3, 3,
2748     NULL, NULL, "7",                    NULL
2749   },
2750   {
2751     ED_AREA_YAMYAM_CONTENT_XPOS(7),     ED_AREA_YAMYAM_CONTENT_YPOS(7),
2752     GADGET_ID_YAMYAM_CONTENT_7,         GADGET_ID_NONE,
2753     &level.yamyam_content[7].e[0][0],   3, 3,
2754     NULL, NULL, "8",                    NULL
2755   },
2756
2757   /* ---------- magic ball content ----------------------------------------- */
2758
2759   {
2760     ED_AREA_MAGIC_BALL_CONTENT_XPOS(0), ED_AREA_MAGIC_BALL_CONTENT_YPOS(0),
2761     GADGET_ID_MAGIC_BALL_CONTENT_0,     GADGET_ID_NONE,
2762     &level.ball_content[0].e[0][0],     3, 3,
2763     NULL, NULL, "1",                    NULL
2764   },
2765   {
2766     ED_AREA_MAGIC_BALL_CONTENT_XPOS(1), ED_AREA_MAGIC_BALL_CONTENT_YPOS(1),
2767     GADGET_ID_MAGIC_BALL_CONTENT_1,     GADGET_ID_NONE,
2768     &level.ball_content[1].e[0][0],     3, 3,
2769     NULL, NULL, "2",                    NULL
2770   },
2771   {
2772     ED_AREA_MAGIC_BALL_CONTENT_XPOS(2), ED_AREA_MAGIC_BALL_CONTENT_YPOS(2),
2773     GADGET_ID_MAGIC_BALL_CONTENT_2,     GADGET_ID_NONE,
2774     &level.ball_content[2].e[0][0],     3, 3,
2775     NULL, NULL, "3",                    NULL
2776   },
2777   {
2778     ED_AREA_MAGIC_BALL_CONTENT_XPOS(3), ED_AREA_MAGIC_BALL_CONTENT_YPOS(3),
2779     GADGET_ID_MAGIC_BALL_CONTENT_3,     GADGET_ID_NONE,
2780     &level.ball_content[3].e[0][0],     3, 3,
2781     NULL, NULL, "4",                    NULL
2782   },
2783   {
2784     ED_AREA_MAGIC_BALL_CONTENT_XPOS(4), ED_AREA_MAGIC_BALL_CONTENT_YPOS(4),
2785     GADGET_ID_MAGIC_BALL_CONTENT_4,     GADGET_ID_NONE,
2786     &level.ball_content[4].e[0][0],     3, 3,
2787     NULL, NULL, "5",                    NULL
2788   },
2789   {
2790     ED_AREA_MAGIC_BALL_CONTENT_XPOS(5), ED_AREA_MAGIC_BALL_CONTENT_YPOS(5),
2791     GADGET_ID_MAGIC_BALL_CONTENT_5,     GADGET_ID_NONE,
2792     &level.ball_content[5].e[0][0],     3, 3,
2793     NULL, NULL, "6",                    NULL
2794   },
2795   {
2796     ED_AREA_MAGIC_BALL_CONTENT_XPOS(6), ED_AREA_MAGIC_BALL_CONTENT_YPOS(6),
2797     GADGET_ID_MAGIC_BALL_CONTENT_6,     GADGET_ID_NONE,
2798     &level.ball_content[6].e[0][0],     3, 3,
2799     NULL, NULL, "7",                    NULL
2800   },
2801   {
2802     ED_AREA_MAGIC_BALL_CONTENT_XPOS(7), ED_AREA_MAGIC_BALL_CONTENT_YPOS(7),
2803     GADGET_ID_MAGIC_BALL_CONTENT_7,     GADGET_ID_NONE,
2804     &level.ball_content[7].e[0][0],     3, 3,
2805     NULL, NULL, "8",                    NULL
2806   },
2807
2808   /* ---------- amoeba content --------------------------------------------- */
2809
2810   {
2811     ED_AREA_1X1_SETTINGS_XPOS(0),       ED_AREA_1X1_SETTINGS_YPOS(3),
2812     GADGET_ID_AMOEBA_CONTENT,           GADGET_ID_NONE,
2813     &level.amoeba_content,              1, 1,
2814     "content:", NULL, NULL,             "amoeba content"
2815   },
2816
2817   /* ---------- level start element ---------------------------------------- */
2818
2819   {
2820     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(7),
2821     GADGET_ID_START_ELEMENT,            GADGET_ID_USE_START_ELEMENT,
2822     &level.start_element[0],            1, 1,
2823     NULL, NULL, NULL,                   "level start element"
2824   },
2825
2826   /* ---------- player artwork element ------------------------------------- */
2827
2828   {
2829     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(8),
2830     GADGET_ID_ARTWORK_ELEMENT,          GADGET_ID_USE_ARTWORK_ELEMENT,
2831     &level.artwork_element[0],          1, 1,
2832     NULL, NULL, NULL,                   "element for player artwork"
2833   },
2834
2835   /* ---------- player explosion element ----------------------------------- */
2836
2837   {
2838     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(9),
2839     GADGET_ID_EXPLOSION_ELEMENT,        GADGET_ID_USE_EXPLOSION_ELEMENT,
2840     &level.explosion_element[0],        1, 1,
2841     NULL, NULL, NULL,                   "element for player explosion"
2842   },
2843
2844   /* ---------- element settings: configure 1 (custom elements) ----------- */
2845
2846   /* ---------- custom graphic --------------------------------------------- */
2847
2848   {
2849     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(1),
2850     GADGET_ID_CUSTOM_GRAPHIC,           GADGET_ID_CUSTOM_USE_GRAPHIC,
2851     &custom_element.gfx_element,        1, 1,
2852     NULL, NULL, NULL,                   "custom graphic element"
2853   },
2854
2855   /* ---------- element settings: configure 2 (custom elements) ----------- */
2856
2857   /* ---------- custom content (when exploding) ---------------------------- */
2858
2859   {
2860     -1,                                 ED_AREA_3X3_SETTINGS_YPOS(10),
2861     GADGET_ID_CUSTOM_CONTENT,           GADGET_ID_NONE, /* align three rows */
2862     &custom_element.content.e[0][0],    3, 3,
2863     "content:", NULL, NULL,             NULL
2864   },
2865
2866   /* ---------- custom enter and leave element (when moving) --------------- */
2867
2868   {
2869     ED_AREA_1X1_SETTINGS_XPOS(1),       ED_AREA_1X1_SETTINGS_YPOS(3),
2870     GADGET_ID_CUSTOM_MOVE_ENTER,        GADGET_ID_NONE,
2871     &custom_element.move_enter_element, 1, 1,
2872     "can dig:", " ", NULL,              "element that can be digged/collected"
2873   },
2874   {
2875     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(3),
2876     GADGET_ID_CUSTOM_MOVE_LEAVE,        GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE,
2877     &custom_element.move_leave_element, 1, 1,
2878     NULL, NULL, NULL,                   "element that will be left behind"
2879   },
2880
2881   /* ---------- element settings: advanced (custom elements) --------------- */
2882
2883   /* ---------- custom change target --------------------------------------- */
2884
2885   {
2886     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(1),
2887     GADGET_ID_CUSTOM_CHANGE_TARGET,     GADGET_ID_CUSTOM_CAN_CHANGE,
2888     &custom_element_change.target_element, 1, 1,
2889     NULL, "after/when:", NULL,          "new target element after change"
2890   },
2891
2892   /* ---------- custom change content (extended change target) ------------- */
2893
2894   {
2895     -1,                                 ED_AREA_3X3_SETTINGS_YPOS(10),
2896     GADGET_ID_CUSTOM_CHANGE_CONTENT,    GADGET_ID_NONE, /* align three rows */
2897     &custom_element_change.target_content.e[0][0], 3, 3,
2898     NULL, NULL, NULL,                   "new extended elements after change"
2899   },
2900
2901   /* ---------- custom change trigger (element causing change) ------------- */
2902
2903   {
2904     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(5),
2905     GADGET_ID_CUSTOM_CHANGE_TRIGGER,    GADGET_ID_CHANGE_OTHER_ACTION,
2906     &custom_element_change.trigger_element, 1, 1,
2907     NULL, NULL, NULL,                   "other element triggering change"
2908   },
2909
2910   /* ---------- group element content -------------------------------------- */
2911
2912   {
2913     ED_AREA_1X1_SETTINGS_XPOS(0),       ED_AREA_1X1_SETTINGS_YPOS(4),
2914     GADGET_ID_GROUP_CONTENT,            GADGET_ID_NONE,
2915     &group_element_info.element[0],     MAX_ELEMENTS_IN_GROUP, 1,
2916     "content:", NULL, NULL,             NULL
2917   },
2918
2919   /* ---------- random background (for random painting) -------------------- */
2920
2921   {
2922     -1,                                 ED_ELEMENT_SETTINGS_YPOS(14),
2923     GADGET_ID_RANDOM_BACKGROUND,        GADGET_ID_RANDOM_RESTRICTED,
2924     &random_placement_background_element, 1, 1,
2925     NULL, NULL, NULL,                   "random placement background"
2926   },
2927 };
2928
2929
2930 /*
2931   -----------------------------------------------------------------------------
2932   some internally used variables
2933   -----------------------------------------------------------------------------
2934 */
2935
2936 /* actual size of level editor drawing area */
2937 static int ed_fieldx = MAX_ED_FIELDX - 1, ed_fieldy = MAX_ED_FIELDY - 1;
2938
2939 /* actual position of level editor drawing area in level playfield */
2940 static int level_xpos = -1, level_ypos = -1;
2941
2942 #define IN_ED_FIELD(x,y)  ((x)>=0 && (x)<ed_fieldx && (y)>=0 &&(y)<ed_fieldy)
2943
2944 /* drawing elements on the three mouse buttons */
2945 static int new_element1 = EL_WALL;
2946 static int new_element2 = EL_EMPTY;
2947 static int new_element3 = EL_SAND;
2948
2949 #define IS_VALID_BUTTON(button) (button >= 1 && button <= 3)
2950 #define BUTTON_ELEMENT(button) ((button) == 1 ? new_element1 : \
2951                                 (button) == 2 ? new_element2 : \
2952                                 (button) == 3 ? new_element3 : EL_EMPTY)
2953 #define BUTTON_STEPSIZE(button) ((button) == 1 ? 1 : (button) == 2 ? 5 : 10)
2954
2955 /* forward declaration for internal use */
2956 static void ModifyEditorCounterValue(int, int);
2957 static void ModifyEditorCounterLimits(int, int, int);
2958 static void ModifyEditorSelectboxValue(int, int);
2959 static void ModifyEditorSelectboxOptions(int, struct ValueTextInfo *);
2960 static void ModifyEditorDrawingArea(int, int, int);
2961 static void ModifyEditorElementList();
2962 static void AdjustElementListScrollbar();
2963 static void RedrawDrawingElements();
2964 static void DrawDrawingWindow();
2965 static void DrawLevelInfoWindow();
2966 static void DrawPropertiesWindow();
2967 static void UpdateCustomElementGraphicGadgets();
2968 static boolean checkPropertiesConfig(int);
2969 static void CopyLevelToUndoBuffer(int);
2970 static void HandleDrawingAreas(struct GadgetInfo *);
2971 static void HandleCounterButtons(struct GadgetInfo *);
2972 static void HandleTextInputGadgets(struct GadgetInfo *);
2973 static void HandleTextAreaGadgets(struct GadgetInfo *);
2974 static void HandleSelectboxGadgets(struct GadgetInfo *);
2975 static void HandleTextbuttonGadgets(struct GadgetInfo *);
2976 static void HandleGraphicbuttonGadgets(struct GadgetInfo *);
2977 static void HandleRadiobuttons(struct GadgetInfo *);
2978 static void HandleCheckbuttons(struct GadgetInfo *);
2979 static void HandleControlButtons(struct GadgetInfo *);
2980 static void HandleDrawingAreaInfo(struct GadgetInfo *);
2981 static void PrintEditorGadgetInfoText(struct GadgetInfo *);
2982
2983 static struct GadgetInfo *level_editor_gadget[NUM_EDITOR_GADGETS];
2984 static int right_gadget_border[NUM_EDITOR_GADGETS];
2985
2986 static int drawing_function = GADGET_ID_SINGLE_ITEMS;
2987 static int last_drawing_function = GADGET_ID_SINGLE_ITEMS;
2988 static boolean draw_with_brush = FALSE;
2989 static int properties_element = 0;
2990
2991 static short FieldBackup[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
2992 static short UndoBuffer[NUM_UNDO_STEPS][MAX_LEV_FIELDX][MAX_LEV_FIELDY];
2993 static int undo_buffer_position = 0;
2994 static int undo_buffer_steps = 0;
2995
2996 static int edit_mode;
2997 static int edit_mode_properties;
2998
2999 static int element_shift = 0;
3000
3001 static int editor_hl_boulderdash[] =
3002 {
3003   EL_INTERNAL_CASCADE_BD_ACTIVE,
3004   EL_CHAR('B'),
3005   EL_CHAR('D'),
3006   EL_EMPTY,
3007
3008 #if 0
3009   EL_CHAR('B'),
3010   EL_CHAR('O'),
3011   EL_CHAR('U'),
3012   EL_CHAR('L'),
3013
3014   EL_CHAR('-'),
3015   EL_CHAR('D'),
3016   EL_CHAR('E'),
3017   EL_CHAR('R'),
3018
3019   EL_CHAR('D'),
3020   EL_CHAR('A'),
3021   EL_CHAR('S'),
3022   EL_CHAR('H'),
3023 #endif
3024 };
3025
3026 static int editor_el_boulderdash[] =
3027 {
3028   EL_PLAYER_1,
3029   EL_EMPTY,
3030   EL_SAND,
3031   EL_STEELWALL,
3032
3033   EL_BD_WALL,
3034   EL_BD_MAGIC_WALL,
3035   EL_EXIT_CLOSED,
3036   EL_EXIT_OPEN,
3037
3038   EL_BD_DIAMOND,
3039   EL_BD_BUTTERFLY_UP,
3040   EL_BD_FIREFLY_UP,
3041   EL_BD_ROCK,
3042
3043   EL_BD_BUTTERFLY_LEFT,
3044   EL_BD_FIREFLY_LEFT,
3045   EL_BD_BUTTERFLY_RIGHT,
3046   EL_BD_FIREFLY_RIGHT,
3047
3048   EL_BD_AMOEBA,
3049   EL_BD_BUTTERFLY_DOWN,
3050   EL_BD_FIREFLY_DOWN,
3051   EL_EMPTY,
3052 };
3053 static int *editor_hl_boulderdash_ptr = editor_hl_boulderdash;
3054 static int *editor_el_boulderdash_ptr = editor_el_boulderdash;
3055 static int num_editor_hl_boulderdash = SIZEOF_ARRAY_INT(editor_hl_boulderdash);
3056 static int num_editor_el_boulderdash = SIZEOF_ARRAY_INT(editor_el_boulderdash);
3057
3058 static int editor_hl_emerald_mine[] =
3059 {
3060   EL_INTERNAL_CASCADE_EM_ACTIVE,
3061   EL_CHAR('E'),
3062   EL_CHAR('M'),
3063   EL_EMPTY,
3064
3065 #if 0
3066   EL_CHAR('E'),
3067   EL_CHAR('M'),
3068   EL_CHAR('E'),
3069   EL_CHAR('-'),
3070
3071   EL_CHAR('R'),
3072   EL_CHAR('A'),
3073   EL_CHAR('L'),
3074   EL_CHAR('D'),
3075
3076   EL_CHAR('M'),
3077   EL_CHAR('I'),
3078   EL_CHAR('N'),
3079   EL_CHAR('E'),
3080 #endif
3081 };
3082
3083 static int editor_el_emerald_mine[] =
3084 {
3085   EL_PLAYER_1,
3086   EL_PLAYER_2,
3087   EL_PLAYER_3,
3088   EL_PLAYER_4,
3089
3090   EL_PLAYER_1,
3091   EL_EMPTY,
3092   EL_SAND,
3093   EL_ROCK,
3094
3095   EL_STEELWALL,
3096   EL_WALL,
3097   EL_WALL_SLIPPERY,
3098   EL_MAGIC_WALL,
3099
3100   EL_EMERALD,
3101   EL_DIAMOND,
3102   EL_NUT,
3103   EL_BOMB,
3104
3105   EL_WALL_EMERALD,
3106   EL_WALL_DIAMOND,
3107   EL_QUICKSAND_EMPTY,
3108   EL_QUICKSAND_FULL,
3109
3110   EL_DYNAMITE,
3111   EL_DYNAMITE_ACTIVE,
3112   EL_EXIT_CLOSED,
3113   EL_EXIT_OPEN,
3114
3115   EL_YAMYAM,
3116   EL_BUG_UP,
3117   EL_SPACESHIP_UP,
3118   EL_ROBOT,
3119
3120   EL_BUG_LEFT,
3121   EL_SPACESHIP_LEFT,
3122   EL_BUG_RIGHT,
3123   EL_SPACESHIP_RIGHT,
3124
3125   EL_ROBOT_WHEEL,
3126   EL_BUG_DOWN,
3127   EL_SPACESHIP_DOWN,
3128   EL_INVISIBLE_WALL,
3129
3130   EL_ACID_POOL_TOPLEFT,
3131   EL_ACID,
3132   EL_ACID_POOL_TOPRIGHT,
3133   EL_EMPTY,
3134
3135   EL_ACID_POOL_BOTTOMLEFT,
3136   EL_ACID_POOL_BOTTOM,
3137   EL_ACID_POOL_BOTTOMRIGHT,
3138   EL_EMPTY,
3139
3140   EL_AMOEBA_DROP,
3141   EL_AMOEBA_DEAD,
3142   EL_AMOEBA_WET,
3143   EL_AMOEBA_DRY,
3144
3145   EL_EM_KEY_1,
3146   EL_EM_KEY_2,
3147   EL_EM_KEY_3,
3148   EL_EM_KEY_4,
3149
3150   EL_EM_GATE_1,
3151   EL_EM_GATE_2,
3152   EL_EM_GATE_3,
3153   EL_EM_GATE_4,
3154
3155   EL_EM_GATE_1_GRAY,
3156   EL_EM_GATE_2_GRAY,
3157   EL_EM_GATE_3_GRAY,
3158   EL_EM_GATE_4_GRAY,
3159 };
3160 static int *editor_hl_emerald_mine_ptr = editor_hl_emerald_mine;
3161 static int *editor_el_emerald_mine_ptr = editor_el_emerald_mine;
3162 static int num_editor_hl_emerald_mine=SIZEOF_ARRAY_INT(editor_hl_emerald_mine);
3163 static int num_editor_el_emerald_mine=SIZEOF_ARRAY_INT(editor_el_emerald_mine);
3164
3165 static int editor_hl_emerald_mine_club[] =
3166 {
3167   EL_INTERNAL_CASCADE_EMC_ACTIVE,
3168   EL_CHAR('E'),
3169   EL_CHAR('M'),
3170   EL_CHAR('C'),
3171
3172 #if 0
3173   EL_CHAR('E'),
3174   EL_CHAR('M'),
3175   EL_CHAR('E'),
3176   EL_CHAR('-'),
3177
3178   EL_CHAR('R'),
3179   EL_CHAR('A'),
3180   EL_CHAR('L'),
3181   EL_CHAR('D'),
3182
3183   EL_CHAR('M'),
3184   EL_CHAR('I'),
3185   EL_CHAR('N'),
3186   EL_CHAR('E'),
3187
3188   EL_CHAR('C'),
3189   EL_CHAR('L'),
3190   EL_CHAR('U'),
3191   EL_CHAR('B'),
3192 #endif
3193 };
3194
3195 static int editor_el_emerald_mine_club[] =
3196 {
3197   EL_EMC_KEY_5,
3198   EL_EMC_KEY_6,
3199   EL_EMC_KEY_7,
3200   EL_EMC_KEY_8,
3201
3202   EL_EMC_GATE_5,
3203   EL_EMC_GATE_6,
3204   EL_EMC_GATE_7,
3205   EL_EMC_GATE_8,
3206
3207   EL_EMC_GATE_5_GRAY,
3208   EL_EMC_GATE_6_GRAY,
3209   EL_EMC_GATE_7_GRAY,
3210   EL_EMC_GATE_8_GRAY,
3211
3212   EL_EMC_STEELWALL_1,
3213   EL_EMC_STEELWALL_2,
3214   EL_EMC_STEELWALL_3,
3215   EL_EMC_STEELWALL_4,
3216
3217   EL_EMC_WALL_13,
3218   EL_EMC_WALL_14,
3219   EL_EMC_WALL_15,
3220   EL_EMC_WALL_16,
3221
3222   EL_EMC_WALL_SLIPPERY_1,
3223   EL_EMC_WALL_SLIPPERY_2,
3224   EL_EMC_WALL_SLIPPERY_3,
3225   EL_EMC_WALL_SLIPPERY_4,
3226
3227   EL_EMC_WALL_1,
3228   EL_EMC_WALL_2,
3229   EL_EMC_WALL_3,
3230   EL_EMC_WALL_4,
3231
3232   EL_EMC_WALL_5,
3233   EL_EMC_WALL_6,
3234   EL_EMC_WALL_7,
3235   EL_EMC_WALL_8,
3236
3237   EL_EMC_WALL_9,
3238   EL_EMC_WALL_10,
3239   EL_EMC_WALL_11,
3240   EL_EMC_WALL_12,
3241
3242 #if RELEASE_3_1_2
3243   EL_EMPTY,
3244 #else
3245   EL_EMC_ANDROID,
3246 #endif
3247   EL_BALLOON,
3248   EL_BALLOON_SWITCH_ANY,
3249 #if RELEASE_3_1_2
3250   EL_EMPTY,
3251 #else
3252   EL_BALLOON_SWITCH_NONE,
3253 #endif
3254
3255   EL_BALLOON_SWITCH_LEFT,
3256   EL_BALLOON_SWITCH_RIGHT,
3257   EL_BALLOON_SWITCH_UP,
3258   EL_BALLOON_SWITCH_DOWN,
3259
3260   EL_EMC_GRASS,
3261   EL_EMC_PLANT,
3262 #if RELEASE_3_1_2
3263   EL_EMPTY,
3264   EL_EMPTY,
3265 #else
3266   EL_EMC_LENSES,
3267   EL_EMC_MAGNIFIER,
3268 #endif
3269
3270 #if RELEASE_3_1_2
3271   EL_EMPTY,
3272   EL_EMPTY,
3273 #else
3274   EL_EMC_MAGIC_BALL,
3275   EL_EMC_MAGIC_BALL_SWITCH,
3276 #endif
3277   EL_SPRING,
3278 #if RELEASE_3_1_2
3279   EL_EMPTY,
3280 #else
3281   EL_EMC_SPRING_BUMPER,
3282 #endif
3283
3284 #if RELEASE_3_1_2
3285   EL_EMPTY,
3286 #else
3287
3288 #if 0
3289   EL_EMC_DRIPPER,
3290 #else
3291   EL_EMPTY,
3292 #endif
3293
3294 #endif
3295   EL_EMC_FAKE_GRASS,
3296   EL_EMPTY,
3297   EL_EMPTY,
3298 };
3299 static int *editor_hl_emerald_mine_club_ptr = editor_hl_emerald_mine_club;
3300 static int *editor_el_emerald_mine_club_ptr = editor_el_emerald_mine_club;
3301 static int num_editor_hl_emerald_mine_club=SIZEOF_ARRAY_INT(editor_hl_emerald_mine_club);
3302 static int num_editor_el_emerald_mine_club=SIZEOF_ARRAY_INT(editor_el_emerald_mine_club);
3303
3304 static int editor_hl_more[] =
3305 {
3306   EL_INTERNAL_CASCADE_RND_ACTIVE,
3307   EL_CHAR('R'),
3308   EL_CHAR('N'),
3309   EL_CHAR('D'),
3310
3311 #if 0
3312   EL_CHAR('M'),
3313   EL_CHAR('O'),
3314   EL_CHAR('R'),
3315   EL_CHAR('E'),
3316 #endif
3317 };
3318
3319 static int editor_el_more[] =
3320 {
3321   EL_KEY_1,
3322   EL_KEY_2,
3323   EL_KEY_3,
3324   EL_KEY_4,
3325
3326   EL_GATE_1,
3327   EL_GATE_2,
3328   EL_GATE_3,
3329   EL_GATE_4,
3330
3331   EL_GATE_1_GRAY,
3332   EL_GATE_2_GRAY,
3333   EL_GATE_3_GRAY,
3334   EL_GATE_4_GRAY,
3335
3336   EL_ARROW_LEFT,
3337   EL_ARROW_RIGHT,
3338   EL_ARROW_UP,
3339   EL_ARROW_DOWN,
3340
3341   EL_AMOEBA_FULL,
3342   EL_EMERALD_YELLOW,
3343   EL_EMERALD_RED,
3344   EL_EMERALD_PURPLE,
3345
3346   EL_WALL_BD_DIAMOND,
3347   EL_WALL_EMERALD_YELLOW,
3348   EL_WALL_EMERALD_RED,
3349   EL_WALL_EMERALD_PURPLE,
3350
3351   EL_GAME_OF_LIFE,
3352   EL_PACMAN_UP,
3353   EL_TIME_ORB_FULL,
3354   EL_TIME_ORB_EMPTY,
3355
3356   EL_PACMAN_LEFT,
3357   EL_DARK_YAMYAM,
3358   EL_PACMAN_RIGHT,
3359   EL_EXPANDABLE_WALL,
3360
3361   EL_BIOMAZE,
3362   EL_PACMAN_DOWN,
3363   EL_LAMP,
3364   EL_LAMP_ACTIVE,
3365
3366   EL_DYNABOMB_INCREASE_NUMBER,
3367   EL_DYNABOMB_INCREASE_SIZE,
3368   EL_DYNABOMB_INCREASE_POWER,
3369   EL_STONEBLOCK,
3370
3371   EL_MOLE,
3372   EL_PENGUIN,
3373   EL_PIG,
3374   EL_DRAGON,
3375
3376   EL_BUG,
3377   EL_MOLE_UP,
3378   EL_BD_BUTTERFLY,
3379   EL_BD_FIREFLY,
3380
3381   EL_MOLE_LEFT,
3382   EL_EMPTY,
3383   EL_MOLE_RIGHT,
3384   EL_PACMAN,
3385
3386   EL_SPACESHIP,
3387   EL_MOLE_DOWN,
3388   EL_EMPTY,
3389   EL_EMPTY,
3390
3391   EL_SATELLITE,
3392   EL_EXPANDABLE_WALL_HORIZONTAL,
3393   EL_EXPANDABLE_WALL_VERTICAL,
3394   EL_EXPANDABLE_WALL_ANY,
3395
3396   EL_INVISIBLE_STEELWALL,
3397   EL_INVISIBLE_WALL,
3398   EL_SPEED_PILL,
3399   EL_BLACK_ORB,
3400 };
3401 static int *editor_hl_more_ptr = editor_hl_more;
3402 static int *editor_el_more_ptr = editor_el_more;
3403 static int num_editor_hl_more = SIZEOF_ARRAY_INT(editor_hl_more);
3404 static int num_editor_el_more = SIZEOF_ARRAY_INT(editor_el_more);
3405
3406 static int editor_hl_sokoban[] =
3407 {
3408   EL_INTERNAL_CASCADE_SB_ACTIVE,
3409   EL_CHAR('S'),
3410   EL_CHAR('B'),
3411   EL_EMPTY,
3412
3413 #if 0
3414   EL_CHAR('S'),
3415   EL_CHAR('O'),
3416   EL_CHAR('K'),
3417   EL_CHAR('O'),
3418
3419   EL_CHAR('-'),
3420   EL_CHAR('B'),
3421   EL_CHAR('A'),
3422   EL_CHAR('N'),
3423 #endif
3424 };
3425
3426 static int editor_el_sokoban[] =
3427 {
3428   EL_SOKOBAN_OBJECT,
3429   EL_SOKOBAN_FIELD_EMPTY,
3430   EL_SOKOBAN_FIELD_FULL,
3431   EL_SOKOBAN_FIELD_PLAYER,
3432 };
3433 static int *editor_hl_sokoban_ptr = editor_hl_sokoban;
3434 static int *editor_el_sokoban_ptr = editor_el_sokoban;
3435 static int num_editor_hl_sokoban = SIZEOF_ARRAY_INT(editor_hl_sokoban);
3436 static int num_editor_el_sokoban = SIZEOF_ARRAY_INT(editor_el_sokoban);
3437
3438 static int editor_hl_supaplex[] =
3439 {
3440   EL_INTERNAL_CASCADE_SP_ACTIVE,
3441   EL_CHAR('S'),
3442   EL_CHAR('P'),
3443   EL_EMPTY,
3444
3445 #if 0
3446   EL_CHAR('S'),
3447   EL_CHAR('U'),
3448   EL_CHAR('P'),
3449   EL_CHAR('A'),
3450
3451   EL_CHAR('P'),
3452   EL_CHAR('L'),
3453   EL_CHAR('E'),
3454   EL_CHAR('X'),
3455 #endif
3456 };
3457
3458 static int editor_el_supaplex[] =
3459 {
3460 #if 1
3461   EL_EMPTY,
3462 #else
3463   EL_SP_EMPTY,
3464 #endif
3465   EL_SP_ZONK,
3466   EL_SP_BASE,
3467   EL_SP_MURPHY,
3468
3469   EL_SP_INFOTRON,
3470   EL_SP_CHIP_SINGLE,
3471   EL_SP_HARDWARE_GRAY,
3472   EL_SP_EXIT_CLOSED,
3473
3474   EL_SP_DISK_ORANGE,
3475   EL_SP_PORT_RIGHT,
3476   EL_SP_PORT_DOWN,
3477   EL_SP_PORT_LEFT,
3478
3479   EL_SP_PORT_UP,
3480   EL_SP_GRAVITY_PORT_RIGHT,
3481   EL_SP_GRAVITY_PORT_DOWN,
3482   EL_SP_GRAVITY_PORT_LEFT,
3483
3484   EL_SP_GRAVITY_PORT_UP,
3485   EL_SP_SNIKSNAK,
3486   EL_SP_DISK_YELLOW,
3487   EL_SP_TERMINAL,
3488
3489   EL_SP_DISK_RED,
3490   EL_SP_PORT_VERTICAL,
3491   EL_SP_PORT_HORIZONTAL,
3492   EL_SP_PORT_ANY,
3493
3494   EL_SP_ELECTRON,
3495   EL_SP_BUGGY_BASE,
3496   EL_SP_CHIP_LEFT,
3497   EL_SP_CHIP_RIGHT,
3498
3499   EL_SP_HARDWARE_BASE_1,
3500   EL_SP_HARDWARE_GREEN,
3501   EL_SP_HARDWARE_BLUE,
3502   EL_SP_HARDWARE_RED,
3503
3504   EL_SP_HARDWARE_YELLOW,
3505   EL_SP_HARDWARE_BASE_2,
3506   EL_SP_HARDWARE_BASE_3,
3507   EL_SP_HARDWARE_BASE_4,
3508
3509   EL_SP_HARDWARE_BASE_5,
3510   EL_SP_HARDWARE_BASE_6,
3511   EL_SP_CHIP_TOP,
3512   EL_SP_CHIP_BOTTOM,
3513 };
3514 static int *editor_hl_supaplex_ptr = editor_hl_supaplex;
3515 static int *editor_el_supaplex_ptr = editor_el_supaplex;
3516 static int num_editor_hl_supaplex = SIZEOF_ARRAY_INT(editor_hl_supaplex);
3517 static int num_editor_el_supaplex = SIZEOF_ARRAY_INT(editor_el_supaplex);
3518
3519 static int editor_hl_diamond_caves[] =
3520 {
3521   EL_INTERNAL_CASCADE_DC_ACTIVE,
3522   EL_CHAR('D'),
3523   EL_CHAR('C'),
3524   EL_CHAR('2'),
3525
3526 #if 0
3527   EL_CHAR('D'),
3528   EL_CHAR('I'),
3529   EL_CHAR('A'),
3530   EL_CHAR('-'),
3531
3532   EL_CHAR('M'),
3533   EL_CHAR('O'),
3534   EL_CHAR('N'),
3535   EL_CHAR('D'),
3536
3537   EL_CHAR('C'),
3538   EL_CHAR('A'),
3539   EL_CHAR('V'),
3540   EL_CHAR('E'),
3541
3542   EL_CHAR('S'),
3543   EL_CHAR(' '),
3544   EL_CHAR('I'),
3545   EL_CHAR('I'),
3546 #endif
3547 };
3548
3549 static int editor_el_diamond_caves[] =
3550 {
3551   EL_PEARL,
3552   EL_CRYSTAL,
3553   EL_WALL_PEARL,
3554   EL_WALL_CRYSTAL,
3555
3556   EL_CONVEYOR_BELT_1_LEFT,
3557   EL_CONVEYOR_BELT_1_MIDDLE,
3558   EL_CONVEYOR_BELT_1_RIGHT,
3559   EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
3560
3561   EL_CONVEYOR_BELT_2_LEFT,
3562   EL_CONVEYOR_BELT_2_MIDDLE,
3563   EL_CONVEYOR_BELT_2_RIGHT,
3564   EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
3565
3566   EL_CONVEYOR_BELT_3_LEFT,
3567   EL_CONVEYOR_BELT_3_MIDDLE,
3568   EL_CONVEYOR_BELT_3_RIGHT,
3569   EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
3570
3571   EL_CONVEYOR_BELT_4_LEFT,
3572   EL_CONVEYOR_BELT_4_MIDDLE,
3573   EL_CONVEYOR_BELT_4_RIGHT,
3574   EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
3575
3576   EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3577   EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3578   EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3579   EL_CONVEYOR_BELT_4_SWITCH_LEFT,
3580
3581   EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
3582   EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
3583   EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
3584   EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
3585
3586   EL_SWITCHGATE_OPEN,
3587   EL_SWITCHGATE_CLOSED,
3588   EL_SWITCHGATE_SWITCH_UP,
3589   EL_EMPTY,
3590
3591   EL_ENVELOPE_1,
3592   EL_ENVELOPE_2,
3593   EL_ENVELOPE_3,
3594   EL_ENVELOPE_4,
3595
3596   EL_TIMEGATE_CLOSED,
3597   EL_TIMEGATE_OPEN,
3598   EL_TIMEGATE_SWITCH,
3599   EL_EMPTY,
3600
3601   EL_LANDMINE,
3602   EL_INVISIBLE_SAND,
3603   EL_STEELWALL_SLIPPERY,
3604   EL_EMPTY,
3605
3606   EL_SIGN_EXCLAMATION,
3607   EL_SIGN_STOP,
3608   EL_LIGHT_SWITCH,
3609   EL_LIGHT_SWITCH_ACTIVE,
3610
3611   EL_SHIELD_NORMAL,
3612   EL_SHIELD_DEADLY,
3613   EL_EXTRA_TIME,
3614   EL_EMPTY,
3615 };
3616 static int *editor_hl_diamond_caves_ptr = editor_hl_diamond_caves;
3617 static int *editor_el_diamond_caves_ptr = editor_el_diamond_caves;
3618 static int num_editor_hl_diamond_caves = SIZEOF_ARRAY_INT(editor_hl_diamond_caves);
3619 static int num_editor_el_diamond_caves = SIZEOF_ARRAY_INT(editor_el_diamond_caves);
3620
3621 static int editor_hl_dx_boulderdash[] =
3622 {
3623   EL_INTERNAL_CASCADE_DX_ACTIVE,
3624   EL_CHAR('D'),
3625   EL_CHAR('X'),
3626   EL_EMPTY,
3627
3628 #if 0
3629   EL_CHAR('D'),
3630   EL_CHAR('X'),
3631   EL_CHAR('-'),
3632   EL_CHAR(' '),
3633
3634   EL_CHAR('B'),
3635   EL_CHAR('O'),
3636   EL_CHAR('U'),
3637   EL_CHAR('L'),
3638
3639   EL_CHAR('-'),
3640   EL_CHAR('D'),
3641   EL_CHAR('E'),
3642   EL_CHAR('R'),
3643
3644   EL_CHAR('D'),
3645   EL_CHAR('A'),
3646   EL_CHAR('S'),
3647   EL_CHAR('H'),
3648 #endif
3649 };
3650
3651 static int editor_el_dx_boulderdash[] =
3652 {
3653   EL_EMPTY,
3654   EL_TUBE_RIGHT_DOWN,
3655   EL_TUBE_HORIZONTAL_DOWN,
3656   EL_TUBE_LEFT_DOWN,
3657
3658   EL_TUBE_HORIZONTAL,
3659   EL_TUBE_VERTICAL_RIGHT,
3660   EL_TUBE_ANY,
3661   EL_TUBE_VERTICAL_LEFT,
3662
3663   EL_TUBE_VERTICAL,
3664   EL_TUBE_RIGHT_UP,
3665   EL_TUBE_HORIZONTAL_UP,
3666   EL_TUBE_LEFT_UP,
3667
3668   EL_TRAP,
3669   EL_DX_SUPABOMB,
3670   EL_EMPTY,
3671   EL_EMPTY
3672 };
3673 static int *editor_hl_dx_boulderdash_ptr = editor_hl_dx_boulderdash;
3674 static int *editor_el_dx_boulderdash_ptr = editor_el_dx_boulderdash;
3675 static int num_editor_hl_dx_boulderdash = SIZEOF_ARRAY_INT(editor_hl_dx_boulderdash);
3676 static int num_editor_el_dx_boulderdash = SIZEOF_ARRAY_INT(editor_el_dx_boulderdash);
3677
3678 static int editor_hl_chars[] =
3679 {
3680   EL_INTERNAL_CASCADE_CHARS_ACTIVE,
3681   EL_CHAR('T'),
3682   EL_CHAR('X'),
3683   EL_CHAR('T'),
3684
3685 #if 0
3686   EL_CHAR('T'),
3687   EL_CHAR('E'),
3688   EL_CHAR('X'),
3689   EL_CHAR('T'),
3690 #endif
3691 };
3692
3693 static int editor_el_chars[] =
3694 {
3695   EL_CHAR(' '),
3696   EL_CHAR('!'),
3697   EL_CHAR('"'),
3698   EL_CHAR('#'),
3699
3700   EL_CHAR('$'),
3701   EL_CHAR('%'),
3702   EL_CHAR('&'),
3703   EL_CHAR('\''),
3704
3705   EL_CHAR('('),
3706   EL_CHAR(')'),
3707   EL_CHAR('*'),
3708   EL_CHAR('+'),
3709
3710   EL_CHAR(','),
3711   EL_CHAR('-'),
3712   EL_CHAR('.'),
3713   EL_CHAR('/'),
3714
3715   EL_CHAR('0'),
3716   EL_CHAR('1'),
3717   EL_CHAR('2'),
3718   EL_CHAR('3'),
3719
3720   EL_CHAR('4'),
3721   EL_CHAR('5'),
3722   EL_CHAR('6'),
3723   EL_CHAR('7'),
3724
3725   EL_CHAR('8'),
3726   EL_CHAR('9'),
3727   EL_CHAR(':'),
3728   EL_CHAR(';'),
3729
3730   EL_CHAR('<'),
3731   EL_CHAR('='),
3732   EL_CHAR('>'),
3733   EL_CHAR('?'),
3734
3735   EL_CHAR('@'),
3736   EL_CHAR('A'),
3737   EL_CHAR('B'),
3738   EL_CHAR('C'),
3739
3740   EL_CHAR('D'),
3741   EL_CHAR('E'),
3742   EL_CHAR('F'),
3743   EL_CHAR('G'),
3744
3745   EL_CHAR('H'),
3746   EL_CHAR('I'),
3747   EL_CHAR('J'),
3748   EL_CHAR('K'),
3749
3750   EL_CHAR('L'),
3751   EL_CHAR('M'),
3752   EL_CHAR('N'),
3753   EL_CHAR('O'),
3754
3755   EL_CHAR('P'),
3756   EL_CHAR('Q'),
3757   EL_CHAR('R'),
3758   EL_CHAR('S'),
3759
3760   EL_CHAR('T'),
3761   EL_CHAR('U'),
3762   EL_CHAR('V'),
3763   EL_CHAR('W'),
3764
3765   EL_CHAR('X'),
3766   EL_CHAR('Y'),
3767   EL_CHAR('Z'),
3768   EL_CHAR('['),
3769
3770   EL_CHAR('\\'),
3771   EL_CHAR(']'),
3772   EL_CHAR('^'),
3773   EL_CHAR('_'),
3774
3775   EL_CHAR('©'),
3776   EL_CHAR('Ä'),
3777   EL_CHAR('Ö'),
3778   EL_CHAR('Ãœ'),
3779
3780   EL_CHAR('°'),
3781   EL_CHAR('®'),
3782   EL_CHAR(FONT_ASCII_CURSOR),
3783   EL_CHAR(' ')
3784 };
3785 static int *editor_hl_chars_ptr = editor_hl_chars;
3786 static int *editor_el_chars_ptr = editor_el_chars;
3787 static int num_editor_hl_chars = SIZEOF_ARRAY_INT(editor_hl_chars);
3788 static int num_editor_el_chars = SIZEOF_ARRAY_INT(editor_el_chars);
3789
3790 static int editor_hl_custom[] =
3791 {
3792   EL_INTERNAL_CASCADE_CE_ACTIVE,
3793   EL_CHAR('C'),
3794   EL_CHAR('E'),
3795   EL_EMPTY,
3796
3797 #if 0
3798   EL_CHAR('C'),
3799   EL_CHAR('U'),
3800   EL_CHAR('S'),
3801   EL_CHAR('-'),
3802
3803   EL_CHAR('T'),
3804   EL_CHAR('O'),
3805   EL_CHAR('M'),
3806   EL_CHAR(' '),
3807
3808   EL_CHAR('E'),
3809   EL_CHAR('L'),
3810   EL_CHAR('E'),
3811   EL_CHAR('M'),
3812
3813   EL_CHAR('E'),
3814   EL_CHAR('N'),
3815   EL_CHAR('T'),
3816   EL_CHAR('S'),
3817 #endif
3818 };
3819
3820 static int editor_el_custom[] =
3821 {
3822   EL_CUSTOM_START + 0,
3823   EL_CUSTOM_START + 1,
3824   EL_CUSTOM_START + 2,
3825   EL_CUSTOM_START + 3,
3826
3827   EL_CUSTOM_START + 4,
3828   EL_CUSTOM_START + 5,
3829   EL_CUSTOM_START + 6,
3830   EL_CUSTOM_START + 7,
3831
3832   EL_CUSTOM_START + 8,
3833   EL_CUSTOM_START + 9,
3834   EL_CUSTOM_START + 10,
3835   EL_CUSTOM_START + 11,
3836
3837   EL_CUSTOM_START + 12,
3838   EL_CUSTOM_START + 13,
3839   EL_CUSTOM_START + 14,
3840   EL_CUSTOM_START + 15,
3841
3842   EL_CUSTOM_START + 16,
3843   EL_CUSTOM_START + 17,
3844   EL_CUSTOM_START + 18,
3845   EL_CUSTOM_START + 19,
3846
3847   EL_CUSTOM_START + 20,
3848   EL_CUSTOM_START + 21,
3849   EL_CUSTOM_START + 22,
3850   EL_CUSTOM_START + 23,
3851
3852   EL_CUSTOM_START + 24,
3853   EL_CUSTOM_START + 25,
3854   EL_CUSTOM_START + 26,
3855   EL_CUSTOM_START + 27,
3856
3857   EL_CUSTOM_START + 28,
3858   EL_CUSTOM_START + 29,
3859   EL_CUSTOM_START + 30,
3860   EL_CUSTOM_START + 31,
3861
3862   EL_CUSTOM_START + 32,
3863   EL_CUSTOM_START + 33,
3864   EL_CUSTOM_START + 34,
3865   EL_CUSTOM_START + 35,
3866
3867   EL_CUSTOM_START + 36,
3868   EL_CUSTOM_START + 37,
3869   EL_CUSTOM_START + 38,
3870   EL_CUSTOM_START + 39,
3871
3872   EL_CUSTOM_START + 40,
3873   EL_CUSTOM_START + 41,
3874   EL_CUSTOM_START + 42,
3875   EL_CUSTOM_START + 43,
3876
3877   EL_CUSTOM_START + 44,
3878   EL_CUSTOM_START + 45,
3879   EL_CUSTOM_START + 46,
3880   EL_CUSTOM_START + 47,
3881
3882   EL_CUSTOM_START + 48,
3883   EL_CUSTOM_START + 49,
3884   EL_CUSTOM_START + 50,
3885   EL_CUSTOM_START + 51,
3886
3887   EL_CUSTOM_START + 52,
3888   EL_CUSTOM_START + 53,
3889   EL_CUSTOM_START + 54,
3890   EL_CUSTOM_START + 55,
3891
3892   EL_CUSTOM_START + 56,
3893   EL_CUSTOM_START + 57,
3894   EL_CUSTOM_START + 58,
3895   EL_CUSTOM_START + 59,
3896
3897   EL_CUSTOM_START + 60,
3898   EL_CUSTOM_START + 61,
3899   EL_CUSTOM_START + 62,
3900   EL_CUSTOM_START + 63,
3901
3902   EL_CUSTOM_START + 64,
3903   EL_CUSTOM_START + 65,
3904   EL_CUSTOM_START + 66,
3905   EL_CUSTOM_START + 67,
3906
3907   EL_CUSTOM_START + 68,
3908   EL_CUSTOM_START + 69,
3909   EL_CUSTOM_START + 70,
3910   EL_CUSTOM_START + 71,
3911
3912   EL_CUSTOM_START + 72,
3913   EL_CUSTOM_START + 73,
3914   EL_CUSTOM_START + 74,
3915   EL_CUSTOM_START + 75,
3916
3917   EL_CUSTOM_START + 76,
3918   EL_CUSTOM_START + 77,
3919   EL_CUSTOM_START + 78,
3920   EL_CUSTOM_START + 79,
3921
3922   EL_CUSTOM_START + 80,
3923   EL_CUSTOM_START + 81,
3924   EL_CUSTOM_START + 82,
3925   EL_CUSTOM_START + 83,
3926
3927   EL_CUSTOM_START + 84,
3928   EL_CUSTOM_START + 85,
3929   EL_CUSTOM_START + 86,
3930   EL_CUSTOM_START + 87,
3931
3932   EL_CUSTOM_START + 88,
3933   EL_CUSTOM_START + 89,
3934   EL_CUSTOM_START + 90,
3935   EL_CUSTOM_START + 91,
3936
3937   EL_CUSTOM_START + 92,
3938   EL_CUSTOM_START + 93,
3939   EL_CUSTOM_START + 94,
3940   EL_CUSTOM_START + 95,
3941
3942   EL_CUSTOM_START + 96,
3943   EL_CUSTOM_START + 97,
3944   EL_CUSTOM_START + 98,
3945   EL_CUSTOM_START + 99,
3946
3947   EL_CUSTOM_START + 100,
3948   EL_CUSTOM_START + 101,
3949   EL_CUSTOM_START + 102,
3950   EL_CUSTOM_START + 103,
3951
3952   EL_CUSTOM_START + 104,
3953   EL_CUSTOM_START + 105,
3954   EL_CUSTOM_START + 106,
3955   EL_CUSTOM_START + 107,
3956
3957   EL_CUSTOM_START + 108,
3958   EL_CUSTOM_START + 109,
3959   EL_CUSTOM_START + 110,
3960   EL_CUSTOM_START + 111,
3961
3962   EL_CUSTOM_START + 112,
3963   EL_CUSTOM_START + 113,
3964   EL_CUSTOM_START + 114,
3965   EL_CUSTOM_START + 115,
3966
3967   EL_CUSTOM_START + 116,
3968   EL_CUSTOM_START + 117,
3969   EL_CUSTOM_START + 118,
3970   EL_CUSTOM_START + 119,
3971
3972   EL_CUSTOM_START + 120,
3973   EL_CUSTOM_START + 121,
3974   EL_CUSTOM_START + 122,
3975   EL_CUSTOM_START + 123,
3976
3977   EL_CUSTOM_START + 124,
3978   EL_CUSTOM_START + 125,
3979   EL_CUSTOM_START + 126,
3980   EL_CUSTOM_START + 127,
3981
3982   EL_CUSTOM_START + 128,
3983   EL_CUSTOM_START + 129,
3984   EL_CUSTOM_START + 130,
3985   EL_CUSTOM_START + 131,
3986
3987   EL_CUSTOM_START + 132,
3988   EL_CUSTOM_START + 133,
3989   EL_CUSTOM_START + 134,
3990   EL_CUSTOM_START + 135,
3991
3992   EL_CUSTOM_START + 136,
3993   EL_CUSTOM_START + 137,
3994   EL_CUSTOM_START + 138,
3995   EL_CUSTOM_START + 139,
3996
3997   EL_CUSTOM_START + 140,
3998   EL_CUSTOM_START + 141,
3999   EL_CUSTOM_START + 142,
4000   EL_CUSTOM_START + 143,
4001
4002   EL_CUSTOM_START + 144,
4003   EL_CUSTOM_START + 145,
4004   EL_CUSTOM_START + 146,
4005   EL_CUSTOM_START + 147,
4006
4007   EL_CUSTOM_START + 148,
4008   EL_CUSTOM_START + 149,
4009   EL_CUSTOM_START + 150,
4010   EL_CUSTOM_START + 151,
4011
4012   EL_CUSTOM_START + 152,
4013   EL_CUSTOM_START + 153,
4014   EL_CUSTOM_START + 154,
4015   EL_CUSTOM_START + 155,
4016
4017   EL_CUSTOM_START + 156,
4018   EL_CUSTOM_START + 157,
4019   EL_CUSTOM_START + 158,
4020   EL_CUSTOM_START + 159,
4021
4022   EL_CUSTOM_START + 160,
4023   EL_CUSTOM_START + 161,
4024   EL_CUSTOM_START + 162,
4025   EL_CUSTOM_START + 163,
4026
4027   EL_CUSTOM_START + 164,
4028   EL_CUSTOM_START + 165,
4029   EL_CUSTOM_START + 166,
4030   EL_CUSTOM_START + 167,
4031
4032   EL_CUSTOM_START + 168,
4033   EL_CUSTOM_START + 169,
4034   EL_CUSTOM_START + 170,
4035   EL_CUSTOM_START + 171,
4036
4037   EL_CUSTOM_START + 172,
4038   EL_CUSTOM_START + 173,
4039   EL_CUSTOM_START + 174,
4040   EL_CUSTOM_START + 175,
4041
4042   EL_CUSTOM_START + 176,
4043   EL_CUSTOM_START + 177,
4044   EL_CUSTOM_START + 178,
4045   EL_CUSTOM_START + 179,
4046
4047   EL_CUSTOM_START + 180,
4048   EL_CUSTOM_START + 181,
4049   EL_CUSTOM_START + 182,
4050   EL_CUSTOM_START + 183,
4051
4052   EL_CUSTOM_START + 184,
4053   EL_CUSTOM_START + 185,
4054   EL_CUSTOM_START + 186,
4055   EL_CUSTOM_START + 187,
4056
4057   EL_CUSTOM_START + 188,
4058   EL_CUSTOM_START + 189,
4059   EL_CUSTOM_START + 190,
4060   EL_CUSTOM_START + 191,
4061
4062   EL_CUSTOM_START + 192,
4063   EL_CUSTOM_START + 193,
4064   EL_CUSTOM_START + 194,
4065   EL_CUSTOM_START + 195,
4066
4067   EL_CUSTOM_START + 196,
4068   EL_CUSTOM_START + 197,
4069   EL_CUSTOM_START + 198,
4070   EL_CUSTOM_START + 199,
4071
4072   EL_CUSTOM_START + 200,
4073   EL_CUSTOM_START + 201,
4074   EL_CUSTOM_START + 202,
4075   EL_CUSTOM_START + 203,
4076
4077   EL_CUSTOM_START + 204,
4078   EL_CUSTOM_START + 205,
4079   EL_CUSTOM_START + 206,
4080   EL_CUSTOM_START + 207,
4081
4082   EL_CUSTOM_START + 208,
4083   EL_CUSTOM_START + 209,
4084   EL_CUSTOM_START + 210,
4085   EL_CUSTOM_START + 211,
4086
4087   EL_CUSTOM_START + 212,
4088   EL_CUSTOM_START + 213,
4089   EL_CUSTOM_START + 214,
4090   EL_CUSTOM_START + 215,
4091
4092   EL_CUSTOM_START + 216,
4093   EL_CUSTOM_START + 217,
4094   EL_CUSTOM_START + 218,
4095   EL_CUSTOM_START + 219,
4096
4097   EL_CUSTOM_START + 220,
4098   EL_CUSTOM_START + 221,
4099   EL_CUSTOM_START + 222,
4100   EL_CUSTOM_START + 223,
4101
4102   EL_CUSTOM_START + 224,
4103   EL_CUSTOM_START + 225,
4104   EL_CUSTOM_START + 226,
4105   EL_CUSTOM_START + 227,
4106
4107   EL_CUSTOM_START + 228,
4108   EL_CUSTOM_START + 229,
4109   EL_CUSTOM_START + 230,
4110   EL_CUSTOM_START + 231,
4111
4112   EL_CUSTOM_START + 232,
4113   EL_CUSTOM_START + 233,
4114   EL_CUSTOM_START + 234,
4115   EL_CUSTOM_START + 235,
4116
4117   EL_CUSTOM_START + 236,
4118   EL_CUSTOM_START + 237,
4119   EL_CUSTOM_START + 238,
4120   EL_CUSTOM_START + 239,
4121
4122   EL_CUSTOM_START + 240,
4123   EL_CUSTOM_START + 241,
4124   EL_CUSTOM_START + 242,
4125   EL_CUSTOM_START + 243,
4126
4127   EL_CUSTOM_START + 244,
4128   EL_CUSTOM_START + 245,
4129   EL_CUSTOM_START + 246,
4130   EL_CUSTOM_START + 247,
4131
4132   EL_CUSTOM_START + 248,
4133   EL_CUSTOM_START + 249,
4134   EL_CUSTOM_START + 250,
4135   EL_CUSTOM_START + 251,
4136
4137   EL_CUSTOM_START + 252,
4138   EL_CUSTOM_START + 253,
4139   EL_CUSTOM_START + 254,
4140   EL_CUSTOM_START + 255,
4141
4142   EL_TRIGGER_ELEMENT,
4143   EL_TRIGGER_PLAYER,
4144   EL_EMPTY,
4145   EL_EMPTY
4146 };
4147 static int *editor_hl_custom_ptr = editor_hl_custom;
4148 static int *editor_el_custom_ptr = editor_el_custom;
4149 static int num_editor_hl_custom = SIZEOF_ARRAY_INT(editor_hl_custom);
4150 static int num_editor_el_custom = SIZEOF_ARRAY_INT(editor_el_custom);
4151
4152 static int editor_hl_group[] =
4153 {
4154   EL_INTERNAL_CASCADE_GE_ACTIVE,
4155   EL_CHAR('G'),
4156   EL_CHAR('E'),
4157   EL_EMPTY,
4158
4159 #if 0
4160   EL_CHAR('G'),
4161   EL_CHAR('R'),
4162   EL_CHAR('O'),
4163   EL_CHAR('U'),
4164
4165   EL_CHAR('P'),
4166   EL_CHAR(' '),
4167   EL_CHAR(' '),
4168   EL_CHAR(' '),
4169
4170   EL_CHAR('E'),
4171   EL_CHAR('L'),
4172   EL_CHAR('E'),
4173   EL_CHAR('M'),
4174
4175   EL_CHAR('E'),
4176   EL_CHAR('N'),
4177   EL_CHAR('T'),
4178   EL_CHAR('S'),
4179 #endif
4180 };
4181
4182 static int editor_el_group[] =
4183 {
4184   EL_GROUP_START + 0,
4185   EL_GROUP_START + 1,
4186   EL_GROUP_START + 2,
4187   EL_GROUP_START + 3,
4188
4189   EL_GROUP_START + 4,
4190   EL_GROUP_START + 5,
4191   EL_GROUP_START + 6,
4192   EL_GROUP_START + 7,
4193
4194   EL_GROUP_START + 8,
4195   EL_GROUP_START + 9,
4196   EL_GROUP_START + 10,
4197   EL_GROUP_START + 11,
4198
4199   EL_GROUP_START + 12,
4200   EL_GROUP_START + 13,
4201   EL_GROUP_START + 14,
4202   EL_GROUP_START + 15,
4203
4204   EL_GROUP_START + 16,
4205   EL_GROUP_START + 17,
4206   EL_GROUP_START + 18,
4207   EL_GROUP_START + 19,
4208
4209   EL_GROUP_START + 20,
4210   EL_GROUP_START + 21,
4211   EL_GROUP_START + 22,
4212   EL_GROUP_START + 23,
4213
4214   EL_GROUP_START + 24,
4215   EL_GROUP_START + 25,
4216   EL_GROUP_START + 26,
4217   EL_GROUP_START + 27,
4218
4219   EL_GROUP_START + 28,
4220   EL_GROUP_START + 29,
4221   EL_GROUP_START + 30,
4222   EL_GROUP_START + 31
4223 };
4224 static int *editor_hl_group_ptr = editor_hl_group;
4225 static int *editor_el_group_ptr = editor_el_group;
4226 static int num_editor_hl_group = SIZEOF_ARRAY_INT(editor_hl_group);
4227 static int num_editor_el_group = SIZEOF_ARRAY_INT(editor_el_group);
4228
4229 static int editor_hl_user_defined[] =
4230 {
4231   EL_INTERNAL_CASCADE_USER_ACTIVE,
4232   EL_CHAR('M'),
4233   EL_CHAR('Y'),
4234   EL_EMPTY,
4235
4236 #if 0
4237   EL_CHAR('U'),
4238   EL_CHAR('S'),
4239   EL_CHAR('E'),
4240   EL_CHAR('R'),
4241
4242   EL_CHAR('D'),
4243   EL_CHAR('E'),
4244   EL_CHAR('F'),
4245   EL_CHAR('I'),
4246
4247   EL_CHAR('-'),
4248   EL_CHAR('N'),
4249   EL_CHAR('E'),
4250   EL_CHAR('D'),
4251 #endif
4252 };
4253
4254 static int *editor_hl_user_defined_ptr = editor_hl_user_defined;
4255 static int *editor_el_user_defined_ptr = NULL;
4256 static int num_editor_hl_user_defined=SIZEOF_ARRAY_INT(editor_hl_user_defined);
4257 static int num_editor_el_user_defined = 0;
4258
4259 static int editor_hl_dynamic[] =
4260 {
4261   EL_INTERNAL_CASCADE_DYNAMIC_ACTIVE,
4262   EL_CHAR('U'),
4263   EL_CHAR('S'),
4264   EL_CHAR('E'),
4265 };
4266
4267 static int *editor_hl_dynamic_ptr = editor_hl_dynamic;
4268 static int *editor_el_dynamic_ptr = NULL;
4269 static int num_editor_hl_dynamic = SIZEOF_ARRAY_INT(editor_hl_dynamic);
4270 static int num_editor_el_dynamic = 0;
4271
4272 static int editor_hl_empty[] = { };
4273 static int editor_el_empty[ED_NUM_ELEMENTLIST_BUTTONS];
4274
4275 static int *editor_hl_empty_ptr = editor_hl_empty;
4276 static int *editor_el_empty_ptr = editor_el_empty;
4277 static int num_editor_hl_empty = 0;
4278 static int num_editor_el_empty = 0;     /* dynamically determined, if needed */
4279
4280 static boolean use_el_empty = FALSE;
4281
4282 static int *editor_elements = NULL;     /* dynamically allocated */
4283 static int num_editor_elements = 0;     /* dynamically determined */
4284
4285 static struct
4286 {
4287   boolean *setup_value;
4288   boolean *setup_cascade_value;
4289
4290   int **headline_list;
4291   int *headline_list_size;
4292
4293   int **element_list;
4294   int *element_list_size;
4295
4296   boolean last_setup_value;
4297 }
4298 editor_elements_info[] =
4299 {
4300   {
4301     &setup.editor.el_boulderdash,
4302     &setup.editor_cascade.el_bd,
4303     &editor_hl_boulderdash_ptr,         &num_editor_hl_boulderdash,
4304     &editor_el_boulderdash_ptr,         &num_editor_el_boulderdash
4305   },
4306   {
4307     &setup.editor.el_emerald_mine,
4308     &setup.editor_cascade.el_em,
4309     &editor_hl_emerald_mine_ptr,        &num_editor_hl_emerald_mine,
4310     &editor_el_emerald_mine_ptr,        &num_editor_el_emerald_mine
4311   },
4312   {
4313     &setup.editor.el_emerald_mine_club,
4314     &setup.editor_cascade.el_emc,
4315     &editor_hl_emerald_mine_club_ptr,   &num_editor_hl_emerald_mine_club,
4316     &editor_el_emerald_mine_club_ptr,   &num_editor_el_emerald_mine_club
4317   },
4318   {
4319     &setup.editor.el_more,
4320     &setup.editor_cascade.el_rnd,
4321     &editor_hl_more_ptr,                &num_editor_hl_more,
4322     &editor_el_more_ptr,                &num_editor_el_more
4323   },
4324   {
4325     &setup.editor.el_sokoban,
4326     &setup.editor_cascade.el_sb,
4327     &editor_hl_sokoban_ptr,             &num_editor_hl_sokoban,
4328     &editor_el_sokoban_ptr,             &num_editor_el_sokoban
4329   },
4330   {
4331     &setup.editor.el_supaplex,
4332     &setup.editor_cascade.el_sp,
4333     &editor_hl_supaplex_ptr,            &num_editor_hl_supaplex,
4334     &editor_el_supaplex_ptr,            &num_editor_el_supaplex
4335   },
4336   {
4337     &setup.editor.el_diamond_caves,
4338     &setup.editor_cascade.el_dc,
4339     &editor_hl_diamond_caves_ptr,       &num_editor_hl_diamond_caves,
4340     &editor_el_diamond_caves_ptr,       &num_editor_el_diamond_caves
4341   },
4342   {
4343     &setup.editor.el_dx_boulderdash,
4344     &setup.editor_cascade.el_dx,
4345     &editor_hl_dx_boulderdash_ptr,      &num_editor_hl_dx_boulderdash,
4346     &editor_el_dx_boulderdash_ptr,      &num_editor_el_dx_boulderdash
4347   },
4348   {
4349     &setup.editor.el_chars,
4350     &setup.editor_cascade.el_chars,
4351     &editor_hl_chars_ptr,               &num_editor_hl_chars,
4352     &editor_el_chars_ptr,               &num_editor_el_chars
4353   },
4354   {
4355     &setup.editor.el_custom,
4356     &setup.editor_cascade.el_ce,
4357     &editor_hl_custom_ptr,              &num_editor_hl_custom,
4358     &editor_el_custom_ptr,              &num_editor_el_custom
4359   },
4360   {
4361     &setup.editor.el_custom,
4362     &setup.editor_cascade.el_ge,
4363     &editor_hl_group_ptr,               &num_editor_hl_group,
4364     &editor_el_group_ptr,               &num_editor_el_group
4365   },
4366   {
4367     &setup.editor.el_user_defined,
4368     &setup.editor_cascade.el_user,
4369     &editor_hl_user_defined_ptr,        &num_editor_hl_user_defined,
4370     &editor_el_user_defined_ptr,        &num_editor_el_user_defined
4371   },
4372   {
4373     &setup.editor.el_dynamic,
4374     &setup.editor_cascade.el_dynamic,
4375     &editor_hl_dynamic_ptr,             &num_editor_hl_dynamic,
4376     &editor_el_dynamic_ptr,             &num_editor_el_dynamic,
4377   },
4378   {
4379     &use_el_empty,
4380     &use_el_empty,
4381     &editor_hl_empty_ptr,               &num_editor_hl_empty,
4382     &editor_el_empty_ptr,               &num_editor_el_empty,
4383   },
4384   {
4385     NULL,
4386     NULL,
4387     NULL,                               NULL,
4388     NULL,                               NULL
4389   }
4390 };
4391
4392
4393 /*
4394   -----------------------------------------------------------------------------
4395   functions
4396   -----------------------------------------------------------------------------
4397 */
4398
4399 static int getMaxInfoTextLength()
4400 {
4401   return (SXSIZE / getFontWidth(FONT_TEXT_2));
4402 }
4403
4404 static int getTextWidthForGadget(char *text)
4405 {
4406   if (text == NULL)
4407     return 0;
4408
4409   return (getTextWidth(text, FONT_TEXT_1) + ED_GADGET_TEXT_DISTANCE);
4410 }
4411
4412 static int getTextWidthForDrawingArea(char *text)
4413 {
4414   if (text == NULL)
4415     return 0;
4416
4417   return (getTextWidth(text, FONT_TEXT_1) + ED_DRAWINGAREA_TEXT_DISTANCE);
4418 }
4419
4420 static int getRightGadgetBorder(struct GadgetInfo *gi, char *text)
4421 {
4422   return (gi->x + gi->width + getTextWidthForGadget(text));
4423 }
4424
4425 static char *getElementInfoText(int element)
4426 {
4427   char *info_text = NULL;
4428
4429 #if 1
4430   if (element < MAX_NUM_ELEMENTS)
4431 #else
4432   if (element < NUM_FILE_ELEMENTS)
4433 #endif
4434   {
4435     if (strlen(element_info[element].description) > 0)
4436       info_text = element_info[element].description;
4437     else if (element_info[element].custom_description != NULL)
4438       info_text = element_info[element].custom_description;
4439     else if (element_info[element].editor_description != NULL)
4440       info_text = element_info[element].editor_description;
4441   }
4442
4443   if (info_text == NULL)
4444     info_text = INFOTEXT_UNKNOWN_ELEMENT;
4445
4446   return info_text;
4447 }
4448
4449 static void InitDynamicEditorElementList(int **elements, int *num_elements)
4450 {
4451   boolean element_found[NUM_FILE_ELEMENTS];
4452   int i, x, y;
4453
4454   /* initialize list of used elements to "not used" */
4455   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
4456     element_found[i] = FALSE;
4457
4458   /* find all elements used in current level */
4459   for (y = 0; y < lev_fieldy; y++)
4460     for (x = 0; x < lev_fieldx; x++)
4461       if (Feld[x][y] < NUM_FILE_ELEMENTS)       /* should always be true */
4462         element_found[Feld[x][y]] = TRUE;
4463
4464   *num_elements = 0;
4465
4466   /* count number of elements used in current level */
4467   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
4468     if (element_found[i])
4469       (*num_elements)++;
4470
4471   /* add space for up to 3 more elements for padding that may be needed */
4472   *num_elements += 3;
4473
4474   /* free memory for old list of elements, if needed */
4475   checked_free(*elements);
4476
4477   /* allocate memory for new list of elements */
4478   *elements = checked_malloc(*num_elements * sizeof(int));
4479
4480   *num_elements = 0;
4481
4482   /* add all elements used in current level (non-custom/group elements) */
4483   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
4484     if (element_found[i] && !(IS_CUSTOM_ELEMENT(i) || IS_GROUP_ELEMENT(i)))
4485       (*elements)[(*num_elements)++] = i;
4486
4487   /* add all elements used in current level (custom/group elements) */
4488   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
4489     if (element_found[i] && (IS_CUSTOM_ELEMENT(i) || IS_GROUP_ELEMENT(i)))
4490       (*elements)[(*num_elements)++] = i;
4491
4492   while (*num_elements % 4)     /* pad with empty elements, if needed */
4493     (*elements)[(*num_elements)++] = EL_EMPTY;
4494 }
4495
4496 static void ReinitializeElementList()
4497 {
4498   static boolean initialization_needed = TRUE;
4499   int pos = 0;
4500   int i, j;
4501
4502   if (initialization_needed)
4503   {
4504     LoadSetup_EditorCascade();          /* load last editor cascade state */
4505
4506     /* initialize editor cascade element from saved cascade state */
4507     for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
4508     {
4509       int *cascade_element = &(*editor_elements_info[i].headline_list)[0];
4510       boolean cascade_value = *editor_elements_info[i].setup_cascade_value;
4511
4512       if (IS_EDITOR_CASCADE(*cascade_element))
4513         *cascade_element =
4514           (cascade_value ? EL_CASCADE_ACTIVE(*cascade_element) :
4515            EL_CASCADE_INACTIVE(*cascade_element));
4516     }
4517
4518     initialization_needed = FALSE;
4519   }
4520
4521   checked_free(editor_elements);
4522
4523   /* reload optional user defined element list for each invocation of editor */
4524   LoadUserDefinedEditorElementList(&editor_el_user_defined_ptr,
4525                                    &num_editor_el_user_defined);
4526
4527   /* initialize dynamic level element list for each invocation of editor */
4528   InitDynamicEditorElementList(&editor_el_dynamic_ptr,
4529                                &num_editor_el_dynamic);
4530
4531   /* initialize list of empty elements (used for padding, if needed) */
4532   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
4533     editor_el_empty[i] = EL_EMPTY;
4534
4535   /* do some sanity checks for each element from element list */
4536   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
4537   {
4538     for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
4539     {
4540       int element = (*editor_elements_info[i].element_list)[j];
4541
4542       if (element >= NUM_FILE_ELEMENTS)
4543         Error(ERR_WARN, "editor element %d is runtime element", element);
4544
4545       if (strcmp(getElementInfoText(element), INFOTEXT_UNKNOWN_ELEMENT) == 0)
4546         Error(ERR_WARN, "no element description for element %d", element);
4547     }
4548   }
4549
4550   num_editor_elements = 0;
4551   use_el_empty = FALSE;
4552
4553   /* determine size of element list */
4554   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
4555   {
4556     boolean found_inactive_cascade = FALSE;
4557
4558     if (*editor_elements_info[i].setup_value)
4559     {
4560       if (setup.editor.el_headlines)
4561       {
4562         num_editor_elements += *editor_elements_info[i].headline_list_size;
4563
4564         for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
4565         {
4566           int element = (*editor_elements_info[i].headline_list)[j];
4567
4568           if (IS_EDITOR_CASCADE_INACTIVE(element))
4569             found_inactive_cascade = TRUE;
4570         }
4571       }
4572
4573       if (found_inactive_cascade)
4574         continue;
4575
4576       num_editor_elements += *editor_elements_info[i].element_list_size;
4577     }
4578   }
4579
4580   if (num_editor_elements < ED_NUM_ELEMENTLIST_BUTTONS)
4581   {
4582     /* offer at least as many elements as element buttons exist */
4583     use_el_empty = TRUE;
4584     num_editor_el_empty = ED_NUM_ELEMENTLIST_BUTTONS - num_editor_elements;
4585
4586     num_editor_elements += num_editor_el_empty;
4587   }
4588
4589   editor_elements = checked_malloc(num_editor_elements * sizeof(int));
4590
4591   /* fill element list */
4592   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
4593   {
4594     boolean found_inactive_cascade = FALSE;
4595
4596     if (*editor_elements_info[i].setup_value)
4597     {
4598       if (setup.editor.el_headlines)
4599       {
4600         for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
4601         {
4602           int element = (*editor_elements_info[i].headline_list)[j];
4603
4604           editor_elements[pos++] = element;
4605
4606           if (IS_EDITOR_CASCADE_INACTIVE(element))
4607             found_inactive_cascade = TRUE;
4608         }
4609       }
4610
4611       if (found_inactive_cascade)
4612         continue;
4613
4614       for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
4615         editor_elements[pos++] = (*editor_elements_info[i].element_list)[j];
4616     }
4617   }
4618
4619   /* this function is also called before editor gadgets are initialized */
4620   if (level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL] != NULL)
4621     AdjustElementListScrollbar();
4622 }
4623
4624 void PrintEditorElementList()
4625 {
4626   boolean *stop = &setup.editor.el_user_defined;
4627   int i, j;
4628
4629   for (i = 0; editor_elements_info[i].setup_value != stop; i++)
4630   {
4631     int cascade_element = (*editor_elements_info[i].headline_list)[0];
4632
4633     if (IS_EDITOR_CASCADE(cascade_element))
4634     {
4635       int cascade_element_show = EL_CASCADE_INACTIVE(cascade_element);
4636       char *headline = element_info[cascade_element_show].editor_description;
4637
4638       printf_line_with_prefix("# ", "-", 77);
4639       printf("# %s\n", headline);
4640       printf_line_with_prefix("# ", "-", 77);
4641     }
4642
4643     for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
4644     {
4645       int element = (*editor_elements_info[i].headline_list)[j];
4646
4647       if (IS_EDITOR_CASCADE(element))
4648         element = EL_CHAR_MINUS;
4649
4650       printf("# %s\n", element_info[element].token_name);
4651     }
4652
4653     if (j > 0)
4654       printf("#\n");
4655
4656     for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
4657     {
4658       int element = (*editor_elements_info[i].element_list)[j];
4659
4660       printf("# %s\n", element_info[element].token_name);
4661     }
4662
4663     if (j > 0)
4664       printf("#\n");
4665   }
4666 }
4667
4668 static void ReinitializeElementListButtons()
4669 {
4670   static boolean last_setup_value_headlines = FALSE;
4671   static boolean initialization_needed = TRUE;
4672   int i;
4673
4674   if (!initialization_needed)   /* check if editor element setup has changed */
4675   {
4676     if (last_setup_value_headlines != setup.editor.el_headlines)
4677       initialization_needed = TRUE;
4678
4679     for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
4680       if (editor_elements_info[i].last_setup_value !=
4681           *editor_elements_info[i].setup_value)
4682         initialization_needed = TRUE;
4683   }
4684
4685   if (!initialization_needed)
4686     return;
4687
4688   FreeLevelEditorGadgets();
4689   CreateLevelEditorGadgets();
4690
4691   /* store current setup values for next invocation of this function */
4692   last_setup_value_headlines = setup.editor.el_headlines;
4693   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
4694     editor_elements_info[i].last_setup_value =
4695       *editor_elements_info[i].setup_value;
4696
4697   initialization_needed = FALSE;
4698 }
4699
4700 static void DrawElementBorder(int dest_x, int dest_y, int width, int height,
4701                               boolean input)
4702 {
4703   int border_graphic =
4704     (input ? IMG_EDITOR_ELEMENT_BORDER_INPUT : IMG_EDITOR_ELEMENT_BORDER);
4705   Bitmap *src_bitmap;
4706   int src_x, src_y;
4707   int num_mini_tilex = width  / MINI_TILEX + 1;
4708   int num_mini_tiley = height / MINI_TILEY + 1;
4709   int from_x = dest_x - MINI_TILEX / 2;
4710   int from_y = dest_y - MINI_TILEY / 2;
4711   int to_x = from_x + num_mini_tilex * MINI_TILEX - 1;
4712   int to_y = from_y + num_mini_tiley * MINI_TILEY - 1;
4713   int x, y;
4714
4715   getMiniGraphicSource(border_graphic, &src_bitmap, &src_x, &src_y);
4716
4717   for (y = 0; y < num_mini_tiley; y++)
4718     for (x = 0; x < num_mini_tilex; x++)
4719       BlitBitmap(src_bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
4720                  from_x + x * MINI_TILEX, from_y + y * MINI_TILEY);
4721
4722   ClearRectangle(drawto, dest_x - 1, dest_y - 1, width + 2, height + 2);
4723
4724   DrawSimpleBlackLine(drawto, from_x, from_y, to_x, from_y);
4725   DrawSimpleBlackLine(drawto, to_x, from_y, to_x, to_y);
4726   DrawSimpleBlackLine(drawto, to_x, to_y, from_x, to_y);
4727   DrawSimpleBlackLine(drawto, from_x, to_y, from_x, from_y);
4728 }
4729
4730 static void DrawDrawingArea(int id)
4731 {
4732   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
4733   int x, y;
4734
4735   int *value = drawingarea_info[id].value;
4736   int area_xsize = drawingarea_info[id].area_xsize;
4737   int area_ysize = drawingarea_info[id].area_ysize;
4738
4739   for (x = 0; x < area_xsize; x++)
4740     for (y = 0; y < area_ysize; y++)
4741       DrawMiniGraphicExt(drawto,
4742                          gi->x + x * MINI_TILEX,
4743                          gi->y + y * MINI_TILEY,
4744                          el2edimg(value[x * area_ysize + y]));
4745 }
4746
4747 static void ScrollMiniLevel(int from_x, int from_y, int scroll)
4748 {
4749   int x,y;
4750   int dx = (scroll == ED_SCROLL_LEFT ? -1 : scroll == ED_SCROLL_RIGHT ? 1 : 0);
4751   int dy = (scroll == ED_SCROLL_UP   ? -1 : scroll == ED_SCROLL_DOWN  ? 1 : 0);
4752
4753   BlitBitmap(drawto, drawto,
4754              SX + (dx == -1 ? MINI_TILEX : 0),
4755              SY + (dy == -1 ? MINI_TILEY : 0),
4756              (ed_fieldx * MINI_TILEX) - (dx != 0 ? MINI_TILEX : 0),
4757              (ed_fieldy * MINI_TILEY) - (dy != 0 ? MINI_TILEY : 0),
4758              SX + (dx == +1 ? MINI_TILEX : 0),
4759              SY + (dy == +1 ? MINI_TILEY : 0));
4760   if (dx)
4761   {
4762     x = (dx == 1 ? 0 : ed_fieldx - 1);
4763     for (y = 0; y < ed_fieldy; y++)
4764       DrawMiniElementOrWall(x, y, from_x, from_y);
4765   }
4766   else if (dy)
4767   {
4768     y = (dy == 1 ? 0 : ed_fieldy - 1);
4769     for (x = 0; x < ed_fieldx; x++)
4770       DrawMiniElementOrWall(x, y, from_x, from_y);
4771   }
4772
4773   redraw_mask |= REDRAW_FIELD;
4774   BackToFront();
4775 }
4776
4777 static void CreateControlButtons()
4778 {
4779   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4780   struct GadgetInfo *gi;
4781   unsigned long event_mask;
4782   int i;
4783
4784   /* create toolbox buttons */
4785   for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
4786   {
4787     int id = i;
4788     int width, height;
4789     int gd_xoffset, gd_yoffset;
4790     int gd_x1, gd_x2, gd_y1, gd_y2;
4791     int button_type;
4792     int radio_button_nr;
4793     boolean checked;
4794
4795     if (id == GADGET_ID_SINGLE_ITEMS ||
4796         id == GADGET_ID_CONNECTED_ITEMS ||
4797         id == GADGET_ID_LINE ||
4798         id == GADGET_ID_ARC ||
4799         id == GADGET_ID_TEXT ||
4800         id == GADGET_ID_RECTANGLE ||
4801         id == GADGET_ID_FILLED_BOX ||
4802         id == GADGET_ID_FLOOD_FILL ||
4803         id == GADGET_ID_GRAB_BRUSH ||
4804         id == GADGET_ID_PICK_ELEMENT ||
4805         id == GADGET_ID_CUSTOM_COPY_FROM ||
4806         id == GADGET_ID_CUSTOM_COPY_TO ||
4807         id == GADGET_ID_CUSTOM_EXCHANGE)
4808     {
4809       button_type = GD_TYPE_RADIO_BUTTON;
4810       radio_button_nr = RADIO_NR_DRAWING_TOOLBOX;
4811       checked = (id == drawing_function ? TRUE : FALSE);
4812       event_mask = GD_EVENT_PRESSED;
4813     }
4814     else
4815     {
4816       button_type = GD_TYPE_NORMAL_BUTTON;
4817       radio_button_nr = RADIO_NR_NONE;
4818       checked = FALSE;
4819
4820       if (id == GADGET_ID_WRAP_LEFT ||
4821           id == GADGET_ID_WRAP_RIGHT ||
4822           id == GADGET_ID_WRAP_UP ||
4823           id == GADGET_ID_WRAP_DOWN)
4824         event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4825       else
4826         event_mask = GD_EVENT_RELEASED;
4827     }
4828
4829     if (id < ED_NUM_CTRL1_BUTTONS)
4830     {
4831       int x = i % ED_CTRL1_BUTTONS_HORIZ;
4832       int y = i / ED_CTRL1_BUTTONS_HORIZ;
4833
4834       gd_xoffset = ED_CTRL1_BUTTONS_XPOS + x * ED_CTRL1_BUTTON_XSIZE;
4835       gd_yoffset = ED_CTRL1_BUTTONS_YPOS + y * ED_CTRL1_BUTTON_YSIZE;
4836       width  = ED_CTRL1_BUTTON_XSIZE;
4837       height = ED_CTRL1_BUTTON_YSIZE;
4838
4839       gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
4840       gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
4841       gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL1_BUTTONS_GFX_YPOS     + gd_yoffset;
4842       gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL1_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
4843     }
4844     else if (id < ED_NUM_CTRL1_2_BUTTONS)
4845     {
4846       int x = (i - ED_NUM_CTRL1_BUTTONS) % ED_CTRL2_BUTTONS_HORIZ;
4847       int y = (i - ED_NUM_CTRL1_BUTTONS) / ED_CTRL2_BUTTONS_HORIZ;
4848
4849       gd_xoffset = ED_CTRL2_BUTTONS_XPOS + x * ED_CTRL2_BUTTON_XSIZE;
4850       gd_yoffset = ED_CTRL2_BUTTONS_YPOS + y * ED_CTRL2_BUTTON_YSIZE;
4851       width  = ED_CTRL2_BUTTON_XSIZE;
4852       height = ED_CTRL2_BUTTON_YSIZE;
4853
4854       gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
4855       gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
4856       gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL2_BUTTONS_GFX_YPOS + gd_yoffset;
4857       gd_y2 = 0;        /* no alternative graphic for these buttons */
4858     }
4859     else if (id < ED_NUM_CTRL1_3_BUTTONS)
4860     {
4861       int x = (i - ED_NUM_CTRL1_2_BUTTONS) % ED_CTRL3_BUTTONS_HORIZ + 1;
4862       int y = (i - ED_NUM_CTRL1_2_BUTTONS) / ED_CTRL3_BUTTONS_HORIZ;
4863
4864       gd_xoffset = ED_CTRL3_BUTTONS_XPOS + x * ED_CTRL3_BUTTON_XSIZE;
4865       gd_yoffset = ED_CTRL3_BUTTONS_YPOS + y * ED_CTRL3_BUTTON_YSIZE;
4866       width  = ED_CTRL3_BUTTON_XSIZE;
4867       height = ED_CTRL3_BUTTON_YSIZE;
4868
4869       gd_x1 = DOOR_GFX_PAGEX6 + gd_xoffset;
4870       gd_x2 = DOOR_GFX_PAGEX5 + gd_xoffset;
4871       gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL3_BUTTONS_GFX_YPOS     + gd_yoffset;
4872       gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL3_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
4873     }
4874     else
4875     {
4876       int x = (i - ED_NUM_CTRL1_3_BUTTONS) % ED_CTRL4_BUTTONS_HORIZ;
4877       int y = (i - ED_NUM_CTRL1_3_BUTTONS) / ED_CTRL4_BUTTONS_HORIZ + 3;
4878
4879       gd_xoffset = ED_CTRL4_BUTTONS_XPOS + x * ED_CTRL4_BUTTON_XSIZE;
4880       gd_yoffset = ED_CTRL4_BUTTONS_YPOS + y * ED_CTRL4_BUTTON_YSIZE;
4881       width  = ED_CTRL4_BUTTON_XSIZE;
4882       height = ED_CTRL4_BUTTON_YSIZE;
4883
4884       gd_x1 = DOOR_GFX_PAGEX6 + ED_CTRL4_BUTTONS_GFX_XPOS + gd_xoffset;
4885       gd_x2 = DOOR_GFX_PAGEX5 + ED_CTRL4_BUTTONS_GFX_XPOS + gd_xoffset;
4886       gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL4_BUTTONS_GFX_YPOS + gd_yoffset;
4887       gd_y2 = 0;        /* no alternative graphic for these buttons */
4888     }
4889
4890     gi = CreateGadget(GDI_CUSTOM_ID, id,
4891                       GDI_CUSTOM_TYPE_ID, i,
4892                       GDI_INFO_TEXT, control_info[i].text,
4893                       GDI_X, EX + gd_xoffset,
4894                       GDI_Y, EY + gd_yoffset,
4895                       GDI_WIDTH, width,
4896                       GDI_HEIGHT, height,
4897                       GDI_TYPE, button_type,
4898                       GDI_STATE, GD_BUTTON_UNPRESSED,
4899                       GDI_RADIO_NR, radio_button_nr,
4900                       GDI_CHECKED, checked,
4901                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
4902                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
4903                       GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
4904                       GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
4905                       GDI_EVENT_MASK, event_mask,
4906                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4907                       GDI_CALLBACK_ACTION, HandleControlButtons,
4908                       GDI_END);
4909
4910     if (gi == NULL)
4911       Error(ERR_EXIT, "cannot create gadget");
4912
4913     level_editor_gadget[id] = gi;
4914   }
4915
4916   /* create buttons for scrolling of drawing area and element list */
4917   for (i = 0; i < ED_NUM_SCROLLBUTTONS; i++)
4918   {
4919     int id = scrollbutton_info[i].gadget_id;
4920     int x, y, width, height;
4921     int gd_x1, gd_x2, gd_y1, gd_y2;
4922
4923     x = scrollbutton_info[i].x;
4924     y = scrollbutton_info[i].y;
4925
4926     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4927
4928     if (id == GADGET_ID_SCROLL_LIST_UP ||
4929         id == GADGET_ID_SCROLL_LIST_DOWN)
4930     {
4931       x += DX;
4932       y += DY;
4933       width = ED_SCROLLBUTTON2_XSIZE;
4934       height = ED_SCROLLBUTTON2_YSIZE;
4935       gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x;
4936       gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y;
4937       gd_x2 = gd_x1 - ED_SCROLLBUTTON2_XSIZE;
4938       gd_y2 = gd_y1;
4939     }
4940     else
4941     {
4942       x += SX;
4943       y += SY;
4944       width = ED_SCROLLBUTTON_XSIZE;
4945       height = ED_SCROLLBUTTON_YSIZE;
4946       gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x;
4947       gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y;
4948       gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
4949       gd_y2 = gd_y1;
4950     }
4951
4952     gi = CreateGadget(GDI_CUSTOM_ID, id,
4953                       GDI_CUSTOM_TYPE_ID, i,
4954                       GDI_INFO_TEXT, scrollbutton_info[i].infotext,
4955                       GDI_X, x,
4956                       GDI_Y, y,
4957                       GDI_WIDTH, width,
4958                       GDI_HEIGHT, height,
4959                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4960                       GDI_STATE, GD_BUTTON_UNPRESSED,
4961                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
4962                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
4963                       GDI_EVENT_MASK, event_mask,
4964                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4965                       GDI_CALLBACK_ACTION, HandleControlButtons,
4966                       GDI_END);
4967
4968     if (gi == NULL)
4969       Error(ERR_EXIT, "cannot create gadget");
4970
4971     level_editor_gadget[id] = gi;
4972   }
4973
4974   /* create buttons for element list */
4975   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
4976   {
4977     Bitmap *deco_bitmap;
4978     int deco_x, deco_y, deco_xpos, deco_ypos;
4979     int gd_xoffset, gd_yoffset;
4980     int gd_x1, gd_x2, gd_y;
4981     int x = i % ED_ELEMENTLIST_BUTTONS_HORIZ;
4982     int y = i / ED_ELEMENTLIST_BUTTONS_HORIZ;
4983     int id = GADGET_ID_ELEMENTLIST_FIRST + i;
4984     int element = editor_elements[i];
4985
4986     event_mask = GD_EVENT_RELEASED;
4987
4988     gd_xoffset = ED_ELEMENTLIST_XPOS + x * ED_ELEMENTLIST_XSIZE;
4989     gd_yoffset = ED_ELEMENTLIST_YPOS + y * ED_ELEMENTLIST_YSIZE;
4990
4991     gd_x1 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS + ED_ELEMENTLIST_XSIZE;
4992     gd_x2 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS;
4993     gd_y  = DOOR_GFX_PAGEY1 + ED_ELEMENTLIST_YPOS;
4994
4995     getMiniGraphicSource(el2edimg(element), &deco_bitmap, &deco_x, &deco_y);
4996     deco_xpos = (ED_ELEMENTLIST_XSIZE - MINI_TILEX) / 2;
4997     deco_ypos = (ED_ELEMENTLIST_YSIZE - MINI_TILEY) / 2;
4998
4999     gi = CreateGadget(GDI_CUSTOM_ID, id,
5000                       GDI_CUSTOM_TYPE_ID, i,
5001                       GDI_INFO_TEXT, getElementInfoText(element),
5002                       GDI_X, DX + gd_xoffset,
5003                       GDI_Y, DY + gd_yoffset,
5004                       GDI_WIDTH, ED_ELEMENTLIST_XSIZE,
5005                       GDI_HEIGHT, ED_ELEMENTLIST_YSIZE,
5006                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5007                       GDI_STATE, GD_BUTTON_UNPRESSED,
5008                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
5009                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
5010                       GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
5011                       GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
5012                       GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY,
5013                       GDI_DECORATION_SHIFTING, 1, 1,
5014                       GDI_EVENT_MASK, event_mask,
5015                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5016                       GDI_CALLBACK_ACTION, HandleControlButtons,
5017                       GDI_END);
5018
5019     if (gi == NULL)
5020       Error(ERR_EXIT, "cannot create gadget");
5021
5022     level_editor_gadget[id] = gi;
5023   }
5024 }
5025
5026 static void CreateCounterButtons()
5027 {
5028   int max_infotext_len = getMaxInfoTextLength();
5029   int i;
5030
5031   for (i = 0; i < ED_NUM_COUNTERBUTTONS; i++)
5032   {
5033     int j;
5034     int x = SX + counterbutton_info[i].x;       /* down count button */
5035     int y = SY + counterbutton_info[i].y;
5036
5037     /* determine horizontal position to the right of specified gadget */
5038     if (counterbutton_info[i].gadget_id_align != GADGET_ID_NONE)
5039       x = (right_gadget_border[counterbutton_info[i].gadget_id_align] +
5040            ED_GADGET_TEXT_DISTANCE);
5041
5042     /* determine horizontal offset for leading text */
5043     if (counterbutton_info[i].text_left != NULL)
5044       x += getTextWidthForGadget(counterbutton_info[i].text_left);
5045
5046     for (j = 0; j < 2; j++)
5047     {
5048       Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5049       struct GadgetInfo *gi;
5050       int id = (j == 0 ?
5051                 counterbutton_info[i].gadget_id_down :
5052                 counterbutton_info[i].gadget_id_up);
5053       int gd_xoffset;
5054       int gd_x, gd_x1, gd_x2, gd_y;
5055       int x_size, y_size;
5056       unsigned long event_mask;
5057       char infotext[max_infotext_len + 1];
5058
5059       event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5060
5061       if (i == ED_COUNTER_ID_SELECT_LEVEL)
5062       {
5063         int sid = (j == 0 ?
5064                    ED_SCROLLBUTTON_ID_AREA_LEFT :
5065                    ED_SCROLLBUTTON_ID_AREA_RIGHT);
5066
5067         event_mask |= GD_EVENT_RELEASED;
5068
5069         if (j == 1)
5070           x += 2 * ED_GADGET_DISTANCE;
5071         y += ED_GADGET_DISTANCE;
5072
5073         gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[sid].gd_x;
5074         gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
5075         gd_y  = DOOR_GFX_PAGEY1 + scrollbutton_info[sid].gd_y;
5076         x_size = ED_SCROLLBUTTON_XSIZE;
5077         y_size = ED_SCROLLBUTTON_YSIZE;
5078       }
5079       else
5080       {
5081         gd_xoffset = (j == 0 ? ED_BUTTON_MINUS_XPOS : ED_BUTTON_PLUS_XPOS);
5082         gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
5083         gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
5084         gd_y  = DOOR_GFX_PAGEY1 + ED_BUTTON_COUNT_YPOS;
5085         x_size = ED_BUTTON_COUNT_XSIZE;
5086         y_size = ED_BUTTON_COUNT_YSIZE;
5087       }
5088
5089       sprintf(infotext, "%s counter value by 1, 5 or 10",
5090               (j == 0 ? "decrease" : "increase"));
5091
5092       gi = CreateGadget(GDI_CUSTOM_ID, id,
5093                         GDI_CUSTOM_TYPE_ID, i,
5094                         GDI_INFO_TEXT, infotext,
5095                         GDI_X, x,
5096                         GDI_Y, y,
5097                         GDI_WIDTH, x_size,
5098                         GDI_HEIGHT, y_size,
5099                         GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5100                         GDI_STATE, GD_BUTTON_UNPRESSED,
5101                         GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
5102                         GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
5103                         GDI_EVENT_MASK, event_mask,
5104                         GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5105                         GDI_CALLBACK_ACTION, HandleCounterButtons,
5106                         GDI_END);
5107
5108       if (gi == NULL)
5109         Error(ERR_EXIT, "cannot create gadget");
5110
5111       level_editor_gadget[id] = gi;
5112       right_gadget_border[id] =
5113         getRightGadgetBorder(gi, counterbutton_info[i].text_right);
5114
5115       x += gi->width + ED_GADGET_DISTANCE;      /* text count button */
5116
5117       if (j == 0)
5118       {
5119         int font_type = FONT_INPUT_1;
5120         int font_type_active = FONT_INPUT_1_ACTIVE;
5121         int gd_width = ED_WIN_COUNT_XSIZE;
5122
5123         id = counterbutton_info[i].gadget_id_text;
5124         event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
5125
5126         if (i == ED_COUNTER_ID_SELECT_LEVEL)
5127         {
5128           font_type = FONT_LEVEL_NUMBER;
5129           font_type_active = FONT_LEVEL_NUMBER;
5130
5131           x += 2 * ED_GADGET_DISTANCE;
5132           y -= ED_GADGET_DISTANCE;
5133
5134           gd_x = DOOR_GFX_PAGEX6 + ED_WIN_COUNT2_XPOS;
5135           gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT2_YPOS;
5136           gd_width = ED_WIN_COUNT2_XSIZE;
5137         }
5138         else
5139         {
5140           gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
5141           gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
5142         }
5143
5144         gi = CreateGadget(GDI_CUSTOM_ID, id,
5145                           GDI_CUSTOM_TYPE_ID, i,
5146                           GDI_INFO_TEXT, "enter counter value",
5147                           GDI_X, x,
5148                           GDI_Y, y,
5149                           GDI_TYPE, GD_TYPE_TEXT_INPUT_NUMERIC,
5150                           GDI_NUMBER_VALUE, 0,
5151                           GDI_NUMBER_MIN, counterbutton_info[i].min_value,
5152                           GDI_NUMBER_MAX, counterbutton_info[i].max_value,
5153                           GDI_TEXT_SIZE, 3,     /* minimal counter text size */
5154                           GDI_TEXT_FONT, font_type,
5155                           GDI_TEXT_FONT_ACTIVE, font_type_active,
5156                           GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
5157                           GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
5158                           GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
5159                           GDI_DESIGN_WIDTH, gd_width,
5160                           GDI_EVENT_MASK, event_mask,
5161                           GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5162                           GDI_CALLBACK_ACTION, HandleCounterButtons,
5163                           GDI_END);
5164
5165         if (gi == NULL)
5166           Error(ERR_EXIT, "cannot create gadget");
5167
5168         level_editor_gadget[id] = gi;
5169         right_gadget_border[id] =
5170           getRightGadgetBorder(gi, counterbutton_info[i].text_right);
5171
5172         x += gi->width + ED_GADGET_DISTANCE;    /* up count button */
5173       }
5174     }
5175   }
5176 }
5177
5178 static void CreateDrawingAreas()
5179 {
5180   int i;
5181
5182   for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
5183   {
5184     struct GadgetInfo *gi;
5185     unsigned long event_mask;
5186     int id = drawingarea_info[i].gadget_id;
5187     int x = SX + drawingarea_info[i].x;
5188     int y = SY + drawingarea_info[i].y;
5189     int area_xsize = drawingarea_info[i].area_xsize;
5190     int area_ysize = drawingarea_info[i].area_ysize;
5191
5192     event_mask =
5193       GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING |
5194       GD_EVENT_OFF_BORDERS;
5195
5196     /* determine horizontal position to the right of specified gadget */
5197     if (drawingarea_info[i].gadget_id_align != GADGET_ID_NONE)
5198       x = (right_gadget_border[drawingarea_info[i].gadget_id_align] +
5199            ED_DRAWINGAREA_TEXT_DISTANCE);
5200
5201     /* determine horizontal offset for leading text */
5202     if (drawingarea_info[i].text_left != NULL)
5203       x += getTextWidthForDrawingArea(drawingarea_info[i].text_left);
5204
5205     gi = CreateGadget(GDI_CUSTOM_ID, id,
5206                       GDI_CUSTOM_TYPE_ID, i,
5207                       GDI_X, x,
5208                       GDI_Y, y,
5209                       GDI_TYPE, GD_TYPE_DRAWING_AREA,
5210                       GDI_AREA_SIZE, area_xsize, area_ysize,
5211                       GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
5212                       GDI_EVENT_MASK, event_mask,
5213                       GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
5214                       GDI_CALLBACK_ACTION, HandleDrawingAreas,
5215                       GDI_END);
5216
5217     if (gi == NULL)
5218       Error(ERR_EXIT, "cannot create gadget");
5219
5220     level_editor_gadget[id] = gi;
5221     right_gadget_border[id] =
5222       getRightGadgetBorder(gi, drawingarea_info[i].text_right);
5223   }
5224 }
5225
5226 static void CreateTextInputGadgets()
5227 {
5228   int max_infotext_len = getMaxInfoTextLength();
5229   int i;
5230
5231   for (i = 0; i < ED_NUM_TEXTINPUT; i++)
5232   {
5233     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5234     int gd_x, gd_y;
5235     struct GadgetInfo *gi;
5236     unsigned long event_mask;
5237     char infotext[MAX_OUTPUT_LINESIZE + 1];
5238     int id = textinput_info[i].gadget_id;
5239
5240     event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
5241
5242     gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
5243     gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
5244
5245     sprintf(infotext, "Enter %s", textinput_info[i].infotext);
5246     infotext[max_infotext_len] = '\0';
5247
5248     gi = CreateGadget(GDI_CUSTOM_ID, id,
5249                       GDI_CUSTOM_TYPE_ID, i,
5250                       GDI_INFO_TEXT, infotext,
5251                       GDI_X, SX + textinput_info[i].x,
5252                       GDI_Y, SY + textinput_info[i].y,
5253                       GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
5254                       GDI_TEXT_VALUE, textinput_info[i].value,
5255                       GDI_TEXT_SIZE, textinput_info[i].size,
5256                       GDI_TEXT_FONT, FONT_INPUT_1,
5257                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
5258                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
5259                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
5260                       GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
5261                       GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
5262                       GDI_EVENT_MASK, event_mask,
5263                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5264                       GDI_CALLBACK_ACTION, HandleTextInputGadgets,
5265                       GDI_END);
5266
5267     if (gi == NULL)
5268       Error(ERR_EXIT, "cannot create gadget");
5269
5270     level_editor_gadget[id] = gi;
5271   }
5272 }
5273
5274 static void CreateTextAreaGadgets()
5275 {
5276   int max_infotext_len = getMaxInfoTextLength();
5277   int i;
5278
5279   for (i = 0; i < ED_NUM_TEXTAREAS; i++)
5280   {
5281     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5282     int gd_x, gd_y;
5283     struct GadgetInfo *gi;
5284     unsigned long event_mask;
5285     char infotext[MAX_OUTPUT_LINESIZE + 1];
5286     int id = textarea_info[i].gadget_id;
5287     int area_xsize = textarea_info[i].xsize;
5288     int area_ysize = textarea_info[i].ysize;
5289
5290     event_mask = GD_EVENT_TEXT_LEAVING;
5291
5292     gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
5293     gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
5294
5295     sprintf(infotext, "Enter %s", textarea_info[i].infotext);
5296     infotext[max_infotext_len] = '\0';
5297
5298     gi = CreateGadget(GDI_CUSTOM_ID, id,
5299                       GDI_CUSTOM_TYPE_ID, i,
5300                       GDI_INFO_TEXT, infotext,
5301                       GDI_X, SX + textarea_info[i].x,
5302                       GDI_Y, SY + textarea_info[i].y,
5303                       GDI_TYPE, GD_TYPE_TEXT_AREA,
5304                       GDI_AREA_SIZE, area_xsize, area_ysize,
5305                       GDI_TEXT_FONT, FONT_INPUT_1,
5306                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
5307                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
5308                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
5309                       GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
5310                       GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
5311                       GDI_EVENT_MASK, event_mask,
5312                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5313                       GDI_CALLBACK_ACTION, HandleTextAreaGadgets,
5314                       GDI_END);
5315
5316     if (gi == NULL)
5317       Error(ERR_EXIT, "cannot create gadget");
5318
5319     level_editor_gadget[id] = gi;
5320   }
5321 }
5322
5323 static void CreateSelectboxGadgets()
5324 {
5325   int max_infotext_len = getMaxInfoTextLength();
5326   int i, j;
5327
5328   for (i = 0; i < ED_NUM_SELECTBOX; i++)
5329   {
5330     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5331     int gd_x, gd_y;
5332     struct GadgetInfo *gi;
5333     unsigned long event_mask;
5334     char infotext[MAX_OUTPUT_LINESIZE + 1];
5335     int id = selectbox_info[i].gadget_id;
5336     int x = SX + selectbox_info[i].x;
5337     int y = SY + selectbox_info[i].y;
5338
5339     if (selectbox_info[i].size == -1)   /* dynamically determine size */
5340     {
5341       /* (we cannot use -1 for uninitialized values if we directly compare
5342          with results from strlen(), because the '<' and '>' operation will
5343          implicitely cast -1 to an unsigned integer value!) */
5344       selectbox_info[i].size = 0;
5345
5346       for (j = 0; selectbox_info[i].options[j].text != NULL; j++)
5347         if (strlen(selectbox_info[i].options[j].text) > selectbox_info[i].size)
5348           selectbox_info[i].size = strlen(selectbox_info[i].options[j].text);
5349
5350       selectbox_info[i].size++;         /* add one character empty space */
5351     }
5352
5353     event_mask = GD_EVENT_RELEASED |
5354       GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
5355
5356     gd_x = DOOR_GFX_PAGEX4 + ED_SELECTBOX_XPOS;
5357     gd_y = DOOR_GFX_PAGEY1 + ED_SELECTBOX_YPOS;
5358
5359     /* determine horizontal position to the right of specified gadget */
5360     if (selectbox_info[i].gadget_id_align != GADGET_ID_NONE)
5361       x = (right_gadget_border[selectbox_info[i].gadget_id_align] +
5362            ED_GADGET_TEXT_DISTANCE);
5363
5364     /* determine horizontal offset for leading text */
5365     if (selectbox_info[i].text_left != NULL)
5366       x += getTextWidthForGadget(selectbox_info[i].text_left);
5367
5368     sprintf(infotext, "Select %s", selectbox_info[i].infotext);
5369     infotext[max_infotext_len] = '\0';
5370
5371     gi = CreateGadget(GDI_CUSTOM_ID, id,
5372                       GDI_CUSTOM_TYPE_ID, i,
5373                       GDI_INFO_TEXT, infotext,
5374                       GDI_X, x,
5375                       GDI_Y, y,
5376                       GDI_TYPE, GD_TYPE_SELECTBOX,
5377                       GDI_SELECTBOX_OPTIONS, selectbox_info[i].options,
5378                       GDI_TEXT_SIZE, selectbox_info[i].size,
5379                       GDI_TEXT_FONT, FONT_INPUT_1,
5380                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
5381                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
5382                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
5383                       GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
5384                       GDI_BORDER_SIZE_SELECTBUTTON, ED_SELECTBOX_BUTTON_XSIZE,
5385                       GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
5386                       GDI_EVENT_MASK, event_mask,
5387                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5388                       GDI_CALLBACK_ACTION, HandleSelectboxGadgets,
5389                       GDI_END);
5390
5391     if (gi == NULL)
5392       Error(ERR_EXIT, "cannot create gadget");
5393
5394     level_editor_gadget[id] = gi;
5395     right_gadget_border[id] =
5396       getRightGadgetBorder(gi, selectbox_info[i].text_right);
5397   }
5398 }
5399
5400 static void CreateTextbuttonGadgets()
5401 {
5402   int max_infotext_len = getMaxInfoTextLength();
5403   int i;
5404
5405   for (i = 0; i < ED_NUM_TEXTBUTTONS; i++)
5406   {
5407     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5408     int gd_x1, gd_x2, gd_y1, gd_y2;
5409     struct GadgetInfo *gi;
5410     unsigned long event_mask;
5411     char infotext[MAX_OUTPUT_LINESIZE + 1];
5412     int id = textbutton_info[i].gadget_id;
5413     int x = SX + textbutton_info[i].x;
5414     int y = SY + textbutton_info[i].y;
5415
5416     if (textbutton_info[i].size == -1)  /* dynamically determine size */
5417       textbutton_info[i].size = strlen(textbutton_info[i].text);
5418
5419     event_mask = GD_EVENT_RELEASED;
5420
5421     if (id >= GADGET_ID_PROPERTIES_INFO && id <= GADGET_ID_PROPERTIES_CHANGE)
5422     {
5423       gd_x1 = DOOR_GFX_PAGEX4 + ED_TEXTBUTTON_TAB_XPOS;
5424       gd_x2 = DOOR_GFX_PAGEX3 + ED_TEXTBUTTON_TAB_XPOS;
5425       gd_y1 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_TAB_YPOS;
5426       gd_y2 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_TAB_INACTIVE_YPOS;
5427     }
5428     else
5429     {
5430       gd_x1 = DOOR_GFX_PAGEX4 + ED_TEXTBUTTON_XPOS;
5431       gd_x2 = DOOR_GFX_PAGEX3 + ED_TEXTBUTTON_XPOS;
5432       gd_y1 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_YPOS;
5433       gd_y2 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_INACTIVE_YPOS;
5434     }
5435
5436     sprintf(infotext, "%s", textbutton_info[i].infotext);
5437     infotext[max_infotext_len] = '\0';
5438
5439     /* determine horizontal position to the right of specified gadget */
5440     if (textbutton_info[i].gadget_id_align != GADGET_ID_NONE)
5441       x = (right_gadget_border[textbutton_info[i].gadget_id_align] +
5442            ED_GADGET_TEXT_DISTANCE);
5443
5444     /* determine horizontal offset for leading text */
5445     if (textbutton_info[i].text_left != NULL)
5446       x += getTextWidthForGadget(textbutton_info[i].text_left);
5447
5448     gi = CreateGadget(GDI_CUSTOM_ID, id,
5449                       GDI_CUSTOM_TYPE_ID, i,
5450                       GDI_INFO_TEXT, infotext,
5451                       GDI_X, x,
5452                       GDI_Y, y,
5453                       GDI_TYPE, GD_TYPE_TEXT_BUTTON,
5454                       GDI_TEXT_VALUE, textbutton_info[i].text,
5455                       GDI_TEXT_SIZE, textbutton_info[i].size,
5456                       GDI_TEXT_FONT, FONT_INPUT_2_ACTIVE,
5457                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_2,
5458                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
5459                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
5460                       GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
5461                       GDI_BORDER_SIZE, ED_BORDER_TEXT_XSIZE, ED_BORDER_SIZE,
5462                       GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
5463                       GDI_DECORATION_SHIFTING, 1, 1,
5464                       GDI_EVENT_MASK, event_mask,
5465                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5466                       GDI_CALLBACK_ACTION, HandleTextbuttonGadgets,
5467                       GDI_END);
5468
5469     if (gi == NULL)
5470       Error(ERR_EXIT, "cannot create gadget");
5471
5472     level_editor_gadget[id] = gi;
5473     right_gadget_border[id] =
5474       getRightGadgetBorder(gi, textbutton_info[i].text_right);
5475   }
5476 }
5477
5478 static void CreateGraphicbuttonGadgets()
5479 {
5480   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5481   struct GadgetInfo *gi;
5482   unsigned long event_mask;
5483   int i;
5484
5485   /* create buttons for scrolling of drawing area and element list */
5486   for (i = 0; i < ED_NUM_GRAPHICBUTTONS; i++)
5487   {
5488     int id = graphicbutton_info[i].gadget_id;
5489     int gd_x1, gd_x2, gd_y1, gd_y2;
5490     int x = SX + graphicbutton_info[i].x;
5491     int y = SY + graphicbutton_info[i].y;
5492
5493     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
5494
5495     if (i <= ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE)
5496     {
5497       gd_x1 = DOOR_GFX_PAGEX4 + graphicbutton_info[i].gd_x;
5498       gd_y1 = DOOR_GFX_PAGEY1 + graphicbutton_info[i].gd_y;
5499       gd_x2 = DOOR_GFX_PAGEX3 + graphicbutton_info[i].gd_x;
5500       gd_y2 = gd_y1;
5501     }
5502     else        /* (i <= ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE) */
5503     {
5504       gd_x1 = DOOR_GFX_PAGEX6 + graphicbutton_info[i].gd_x;
5505       gd_y1 = DOOR_GFX_PAGEY1 + graphicbutton_info[i].gd_y;
5506       gd_x2 = gd_x1 - ED_BUTTON_COUNT_XSIZE;
5507       gd_y2 = gd_y1;
5508     }
5509
5510     /* determine horizontal position to the right of specified gadget */
5511     if (graphicbutton_info[i].gadget_id_align != GADGET_ID_NONE)
5512       x = (right_gadget_border[graphicbutton_info[i].gadget_id_align] +
5513            ED_GADGET_TEXT_DISTANCE);
5514
5515     /* determine horizontal offset for leading text */
5516     if (graphicbutton_info[i].text_left != NULL)
5517       x += getTextWidthForGadget(graphicbutton_info[i].text_left);
5518
5519     gi = CreateGadget(GDI_CUSTOM_ID, id,
5520                       GDI_CUSTOM_TYPE_ID, i,
5521                       GDI_INFO_TEXT, graphicbutton_info[i].infotext,
5522                       GDI_X, x,
5523                       GDI_Y, y,
5524                       GDI_WIDTH, graphicbutton_info[i].width,
5525                       GDI_HEIGHT, graphicbutton_info[i].height,
5526                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
5527                       GDI_STATE, GD_BUTTON_UNPRESSED,
5528                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
5529                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
5530                       GDI_EVENT_MASK, event_mask,
5531                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5532                       GDI_CALLBACK_ACTION, HandleGraphicbuttonGadgets,
5533                       GDI_END);
5534
5535     if (gi == NULL)
5536       Error(ERR_EXIT, "cannot create gadget");
5537
5538     level_editor_gadget[id] = gi;
5539     right_gadget_border[id] =
5540       getRightGadgetBorder(gi, graphicbutton_info[i].text_right);
5541   }
5542 }
5543
5544 static void CreateScrollbarGadgets()
5545 {
5546   int i;
5547
5548   for (i = 0; i < ED_NUM_SCROLLBARS; i++)
5549   {
5550     int id = scrollbar_info[i].gadget_id;
5551     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5552     int gd_x1, gd_x2, gd_y1, gd_y2;
5553     struct GadgetInfo *gi;
5554     int items_max, items_visible, item_position;
5555     unsigned long event_mask;
5556
5557     if (i == ED_SCROLLBAR_ID_LIST_VERTICAL)
5558     {
5559       items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
5560       items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
5561       item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
5562     }
5563     else        /* drawing area scrollbars */
5564     {
5565       if (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL)
5566       {
5567         items_max = MAX(lev_fieldx + 2, ed_fieldx);
5568         items_visible = ed_fieldx;
5569         item_position = 0;
5570       }
5571       else
5572       {
5573         items_max = MAX(lev_fieldy + 2, ed_fieldy);
5574         items_visible = ed_fieldy;
5575         item_position = 0;
5576       }
5577     }
5578
5579     event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
5580
5581     gd_x1 = DOOR_GFX_PAGEX8 + scrollbar_info[i].gd_x;
5582     gd_x2 = (gd_x1 - (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL ?
5583                       scrollbar_info[i].height : scrollbar_info[i].width));
5584     gd_y1 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y;
5585     gd_y2 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y;
5586
5587     gi = CreateGadget(GDI_CUSTOM_ID, id,
5588                       GDI_CUSTOM_TYPE_ID, i,
5589                       GDI_INFO_TEXT, scrollbar_info[i].infotext,
5590                       GDI_X, scrollbar_info[i].x,
5591                       GDI_Y, scrollbar_info[i].y,
5592                       GDI_WIDTH, scrollbar_info[i].width,
5593                       GDI_HEIGHT, scrollbar_info[i].height,
5594                       GDI_TYPE, scrollbar_info[i].type,
5595                       GDI_SCROLLBAR_ITEMS_MAX, items_max,
5596                       GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
5597                       GDI_SCROLLBAR_ITEM_POSITION, item_position,
5598                       GDI_STATE, GD_BUTTON_UNPRESSED,
5599                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
5600                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
5601                       GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
5602                       GDI_EVENT_MASK, event_mask,
5603                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5604                       GDI_CALLBACK_ACTION, HandleControlButtons,
5605                       GDI_END);
5606
5607     if (gi == NULL)
5608       Error(ERR_EXIT, "cannot create gadget");
5609
5610     level_editor_gadget[id] = gi;
5611   }
5612 }
5613
5614 static void CreateCheckbuttonGadgets()
5615 {
5616   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5617   struct GadgetInfo *gi;
5618   unsigned long event_mask;
5619   int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
5620   int i;
5621
5622   event_mask = GD_EVENT_PRESSED;
5623
5624   gd_x1 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_UNCHECKED_XPOS;
5625   gd_x2 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_UNCHECKED_XPOS;
5626   gd_x3 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_CHECKED_XPOS;
5627   gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
5628   gd_y  = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
5629
5630   for (i = 0; i < ED_NUM_CHECKBUTTONS; i++)
5631   {
5632     int id = checkbutton_info[i].gadget_id;
5633     int x = SX + checkbutton_info[i].x;
5634     int y = SY + checkbutton_info[i].y;
5635
5636     if (id == GADGET_ID_STICK_ELEMENT)
5637       gd_y  = DOOR_GFX_PAGEY1 + ED_STICKYBUTTON_YPOS;
5638     else
5639       gd_y  = DOOR_GFX_PAGEY1 + ED_CHECKBUTTON_YPOS;
5640
5641     /* determine horizontal position to the right of specified gadget */
5642     if (checkbutton_info[i].gadget_id_align != GADGET_ID_NONE)
5643       x = (right_gadget_border[checkbutton_info[i].gadget_id_align] +
5644            ED_GADGET_TEXT_DISTANCE);
5645
5646     /* determine horizontal offset for leading text */
5647     if (checkbutton_info[i].text_left != NULL)
5648       x += getTextWidthForGadget(checkbutton_info[i].text_left);
5649
5650     gi = CreateGadget(GDI_CUSTOM_ID, id,
5651                       GDI_CUSTOM_TYPE_ID, i,
5652                       GDI_INFO_TEXT, checkbutton_info[i].infotext,
5653                       GDI_X, x,
5654                       GDI_Y, y,
5655                       GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
5656                       GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
5657                       GDI_TYPE, GD_TYPE_CHECK_BUTTON,
5658                       GDI_CHECKED, *checkbutton_info[i].value,
5659                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
5660                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
5661                       GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x3, gd_y,
5662                       GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x4, gd_y,
5663                       GDI_EVENT_MASK, event_mask,
5664                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5665                       GDI_CALLBACK_ACTION, HandleCheckbuttons,
5666                       GDI_END);
5667
5668     if (gi == NULL)
5669       Error(ERR_EXIT, "cannot create gadget");
5670
5671     level_editor_gadget[id] = gi;
5672     right_gadget_border[id] =
5673       getRightGadgetBorder(gi, checkbutton_info[i].text_right);
5674   }
5675 }
5676
5677 static void CreateRadiobuttonGadgets()
5678 {
5679   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5680   struct GadgetInfo *gi;
5681   unsigned long event_mask;
5682   int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
5683   int i;
5684
5685   event_mask = GD_EVENT_PRESSED;
5686
5687   gd_x1 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_UNCHECKED_XPOS;
5688   gd_x2 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_UNCHECKED_XPOS;
5689   gd_x3 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_CHECKED_XPOS;
5690   gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
5691   gd_y  = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
5692
5693   for (i = 0; i < ED_NUM_RADIOBUTTONS; i++)
5694   {
5695     int id = radiobutton_info[i].gadget_id;
5696     int x = SX + radiobutton_info[i].x;
5697     int y = SY + radiobutton_info[i].y;
5698
5699     int checked =
5700       (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
5701
5702     /* determine horizontal position to the right of specified gadget */
5703     if (radiobutton_info[i].gadget_id_align != GADGET_ID_NONE)
5704       x = (right_gadget_border[radiobutton_info[i].gadget_id_align] +
5705            ED_GADGET_TEXT_DISTANCE);
5706
5707     /* determine horizontal offset for leading text */
5708     if (radiobutton_info[i].text_left != NULL)
5709       x += getTextWidthForGadget(radiobutton_info[i].text_left);
5710
5711     gi = CreateGadget(GDI_CUSTOM_ID, id,
5712                       GDI_CUSTOM_TYPE_ID, i,
5713                       GDI_INFO_TEXT, radiobutton_info[i].infotext,
5714                       GDI_X, x,
5715                       GDI_Y, y,
5716                       GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
5717                       GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
5718                       GDI_TYPE, GD_TYPE_RADIO_BUTTON,
5719                       GDI_RADIO_NR, radiobutton_info[i].radio_button_nr,
5720                       GDI_CHECKED, checked,
5721                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
5722                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
5723                       GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x3, gd_y,
5724                       GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x4, gd_y,
5725                       GDI_EVENT_MASK, event_mask,
5726                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5727                       GDI_CALLBACK_ACTION, HandleRadiobuttons,
5728                       GDI_END);
5729
5730     if (gi == NULL)
5731       Error(ERR_EXIT, "cannot create gadget");
5732
5733     level_editor_gadget[id] = gi;
5734     right_gadget_border[id] =
5735       getRightGadgetBorder(gi, radiobutton_info[i].text_right);
5736   }
5737 }
5738
5739 void CreateLevelEditorGadgets()
5740 {
5741   int old_game_status = game_status;
5742
5743   /* setting 'game_status' is needed to get the right fonts for the editor */
5744   game_status = GAME_MODE_EDITOR;
5745
5746   ReinitializeElementList();
5747
5748   CreateControlButtons();
5749   CreateScrollbarGadgets();
5750
5751   /* order of function calls is important because of cross-references */
5752   CreateCheckbuttonGadgets();
5753   CreateCounterButtons();
5754   CreateRadiobuttonGadgets();
5755   CreateTextInputGadgets();
5756   CreateTextAreaGadgets();
5757   CreateSelectboxGadgets();
5758   CreateGraphicbuttonGadgets();
5759   CreateTextbuttonGadgets();
5760   CreateDrawingAreas();
5761
5762   game_status = old_game_status;
5763 }
5764
5765 void FreeLevelEditorGadgets()
5766 {
5767   int i;
5768
5769   for (i = 0; i < NUM_EDITOR_GADGETS; i++)
5770     FreeGadget(level_editor_gadget[i]);
5771 }
5772
5773 static void MapCounterButtons(int id)
5774 {
5775   int gadget_id_down = counterbutton_info[id].gadget_id_down;
5776   int gadget_id_text = counterbutton_info[id].gadget_id_text;
5777   int gadget_id_up   = counterbutton_info[id].gadget_id_up;
5778   struct GadgetInfo *gi_down = level_editor_gadget[gadget_id_down];
5779   struct GadgetInfo *gi_text = level_editor_gadget[gadget_id_text];
5780   struct GadgetInfo *gi_up   = level_editor_gadget[gadget_id_up];
5781   int xoffset_left = getTextWidthForGadget(counterbutton_info[id].text_left);
5782   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5783   int yoffset_above = MINI_TILEX + ED_GADGET_DISTANCE;
5784   int yoffset = ED_BORDER_SIZE;
5785   int x_left = gi_down->x - xoffset_left;
5786 #if 1
5787   int x_right;  /* set after gadget position was modified */
5788 #else
5789   int x_right = gi_up->x + gi_up->width + xoffset_right;
5790 #endif
5791   int y_above = gi_down->y - yoffset_above;
5792   int x = gi_down->x;
5793   int y;        /* set after gadget position was modified */
5794
5795   /* counter limits must be changed first to prevent value truncation */
5796   ModifyEditorCounterLimits(id, counterbutton_info[id].min_value,
5797                             counterbutton_info[id].max_value);
5798
5799   /* right text position might have changed after setting position above */
5800   x_right = gi_up->x + gi_up->width + xoffset_right;
5801
5802   ModifyEditorCounterValue(id, *counterbutton_info[id].value);
5803
5804   /* set position for "value[1,2,3,4]" counter gadgets (score in most cases) */
5805   if (id >= ED_COUNTER_ID_ELEMENT_VALUE1 &&
5806       id <= ED_COUNTER_ID_ELEMENT_VALUE4)
5807   {
5808     ModifyGadget(gi_down, GDI_Y, SY + counterbutton_info[id].y, GDI_END);
5809     ModifyGadget(gi_text, GDI_Y, SY + counterbutton_info[id].y, GDI_END);
5810     ModifyGadget(gi_up,   GDI_Y, SY + counterbutton_info[id].y, GDI_END);
5811   }
5812
5813   /* vertical position might have changed after setting position above */
5814   y = gi_up->y + yoffset;
5815
5816   if (counterbutton_info[id].text_above)
5817     DrawText(x, y_above, counterbutton_info[id].text_above, FONT_TEXT_1);
5818
5819   if (counterbutton_info[id].text_left)
5820     DrawText(x_left, y, counterbutton_info[id].text_left, FONT_TEXT_1);
5821
5822   if (counterbutton_info[id].text_right)
5823     DrawText(x_right, y, counterbutton_info[id].text_right, FONT_TEXT_1);
5824
5825   MapGadget(gi_down);
5826   MapGadget(gi_text);
5827   MapGadget(gi_up);
5828 }
5829
5830 static void MapControlButtons()
5831 {
5832   int counter_id;
5833   int i;
5834
5835   /* map toolbox buttons (excluding special CE toolbox buttons) */
5836   for (i = 0; i < ED_NUM_CTRL1_2_BUTTONS; i++)
5837     MapGadget(level_editor_gadget[i]);
5838
5839   /* map buttons to select elements */
5840   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
5841     MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
5842   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
5843   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
5844   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
5845
5846   /* map buttons to select level */
5847   counter_id = ED_COUNTER_ID_SELECT_LEVEL;
5848   counterbutton_info[counter_id].min_value = leveldir_current->first_level;
5849   counterbutton_info[counter_id].max_value = leveldir_current->last_level;
5850   MapCounterButtons(counter_id);
5851 }
5852
5853 static void MapDrawingArea(int id)
5854 {
5855   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
5856   int area_xsize = gi->drawing.area_xsize;
5857   int area_ysize = gi->drawing.area_ysize;
5858   int xoffset_left= getTextWidthForDrawingArea(drawingarea_info[id].text_left);
5859   int xoffset_below= getTextWidth(drawingarea_info[id].text_below,FONT_TEXT_1);
5860   int x_left  = gi->x - xoffset_left;
5861   int x_right = gi->x + gi->width + ED_DRAWINGAREA_TEXT_DISTANCE;
5862   int x_below = gi->x + (gi->width - xoffset_below) / 2;
5863   int y_side  = gi->y + (gi->height - getFontHeight(FONT_TEXT_1)) / 2;
5864   int y_below = gi->y + gi->height + ED_DRAWINGAREA_TEXT_DISTANCE;
5865
5866   if (drawingarea_info[id].text_left)
5867     DrawText(x_left, y_side, drawingarea_info[id].text_left, FONT_TEXT_1);
5868
5869   if (drawingarea_info[id].text_right)
5870     DrawText(x_right, y_side, drawingarea_info[id].text_right, FONT_TEXT_1);
5871
5872   if (drawingarea_info[id].text_below)
5873     DrawText(x_below, y_below, drawingarea_info[id].text_below, FONT_TEXT_1);
5874
5875   if (id != ED_DRAWING_ID_DRAWING_LEVEL)
5876   {
5877     DrawElementBorder(gi->x, gi->y,
5878                       area_xsize * MINI_TILEX, area_ysize * MINI_TILEY, TRUE);
5879
5880     DrawDrawingArea(id);
5881   }
5882
5883   MapGadget(gi);
5884 }
5885
5886 static void MapTextInputGadget(int id)
5887 {
5888   struct GadgetInfo *gi = level_editor_gadget[textinput_info[id].gadget_id];
5889   int xoffset_above = 0;
5890   int yoffset_above = -(MINI_TILEX + ED_GADGET_DISTANCE);
5891   int x_above = textinput_info[id].x + xoffset_above;
5892   int y_above = textinput_info[id].y + yoffset_above;
5893
5894   if (textinput_info[id].text_above)
5895     DrawTextS(x_above, y_above, FONT_TEXT_1, textinput_info[id].text_above);
5896
5897   ModifyGadget(gi, GDI_TEXT_VALUE, textinput_info[id].value, GDI_END);
5898
5899   MapGadget(gi);
5900 }
5901
5902 static void MapTextAreaGadget(int id)
5903 {
5904   struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
5905   int xoffset_above = 0;
5906   int yoffset_above = -(MINI_TILEX + ED_GADGET_DISTANCE);
5907   int x_above = textarea_info[id].x + xoffset_above;
5908   int y_above = textarea_info[id].y + yoffset_above;
5909
5910   if (textarea_info[id].text_above)
5911     DrawTextS(x_above, y_above, FONT_TEXT_1, textarea_info[id].text_above);
5912
5913   ModifyGadget(gi, GDI_TEXT_VALUE, textarea_info[id].value, GDI_END);
5914
5915   MapGadget(gi);
5916 }
5917
5918 static void MapSelectboxGadget(int id)
5919 {
5920   struct GadgetInfo *gi = level_editor_gadget[selectbox_info[id].gadget_id];
5921   int xoffset_left = getTextWidthForGadget(selectbox_info[id].text_left);
5922   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5923   int yoffset = ED_BORDER_SIZE;
5924   int x_left = gi->x - xoffset_left;
5925   int x_right = gi->x + gi->width + xoffset_right;
5926   int y = gi->y + yoffset;
5927
5928   if (selectbox_info[id].text_left)
5929     DrawText(x_left, y, selectbox_info[id].text_left, FONT_TEXT_1);
5930
5931   if (selectbox_info[id].text_right)
5932     DrawText(x_right, y, selectbox_info[id].text_right, FONT_TEXT_1);
5933
5934   ModifyEditorSelectboxValue(id, *selectbox_info[id].value);
5935
5936   MapGadget(gi);
5937 }
5938
5939 static void MapTextbuttonGadget(int id)
5940 {
5941   struct GadgetInfo *gi = level_editor_gadget[textbutton_info[id].gadget_id];
5942   int xoffset_left = getTextWidthForGadget(textbutton_info[id].text_left);
5943   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5944   int yoffset = ED_BORDER_SIZE;
5945   int x_left = gi->x - xoffset_left;
5946   int x_right = gi->x + gi->width + xoffset_right;
5947   int y = gi->y + yoffset;
5948
5949   /* only show button to delete change pages when more than minimum pages */
5950   if (id == ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE &&
5951       custom_element.num_change_pages == MIN_CHANGE_PAGES)
5952     return;
5953
5954   if (textbutton_info[id].text_left)
5955     DrawText(x_left, y, textbutton_info[id].text_left, FONT_TEXT_1);
5956
5957   if (textbutton_info[id].text_right)
5958     DrawText(x_right, y, textbutton_info[id].text_right, FONT_TEXT_1);
5959
5960   MapGadget(gi);
5961 }
5962
5963 static void MapGraphicbuttonGadget(int id)
5964 {
5965   struct GadgetInfo *gi= level_editor_gadget[graphicbutton_info[id].gadget_id];
5966   int xoffset_left = getTextWidthForGadget(graphicbutton_info[id].text_left);
5967   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5968   int yoffset = ED_BORDER_SIZE;
5969   int x_left = gi->x - xoffset_left;
5970   int x_right = gi->x + gi->width + xoffset_right;
5971   int y = gi->y + yoffset;
5972
5973   if (graphicbutton_info[id].text_left)
5974     DrawText(x_left, y, graphicbutton_info[id].text_left, FONT_TEXT_1);
5975
5976   if (graphicbutton_info[id].text_right)
5977     DrawText(x_right, y, graphicbutton_info[id].text_right, FONT_TEXT_1);
5978
5979   MapGadget(gi);
5980 }
5981
5982 static void MapRadiobuttonGadget(int id)
5983 {
5984   struct GadgetInfo *gi = level_editor_gadget[radiobutton_info[id].gadget_id];
5985   int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
5986   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5987   int yoffset = ED_BORDER_SIZE;
5988   int x_left = gi->x - xoffset_left;
5989   int x_right = gi->x + gi->width + xoffset_right;
5990   int y = gi->y + yoffset;
5991   boolean checked =
5992     (*radiobutton_info[id].value == radiobutton_info[id].checked_value);
5993
5994   if (radiobutton_info[id].text_left)
5995     DrawText(x_left, y, radiobutton_info[id].text_left, FONT_TEXT_1);
5996
5997   if (radiobutton_info[id].text_right)
5998     DrawText(x_right, y, radiobutton_info[id].text_right, FONT_TEXT_1);
5999
6000   ModifyGadget(gi, GDI_CHECKED, checked, GDI_END);
6001
6002   MapGadget(gi);
6003 }
6004
6005 static void MapCheckbuttonGadget(int id)
6006 {
6007   struct GadgetInfo *gi = level_editor_gadget[checkbutton_info[id].gadget_id];
6008   int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
6009   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
6010   int yoffset = ED_BORDER_SIZE;
6011   int x_left, x_right, y;       /* set after gadget position was modified */
6012
6013   /* set position for gadgets with dynamically determined position */
6014   if (checkbutton_info[id].x != -1)     /* do not change dynamic positions */
6015     ModifyGadget(gi, GDI_X, SX + checkbutton_info[id].x, GDI_END);
6016   ModifyGadget(gi, GDI_Y, SY + checkbutton_info[id].y, GDI_END);
6017
6018   x_left = gi->x - xoffset_left;
6019   x_right = gi->x + gi->width + xoffset_right;
6020   y = gi->y + yoffset;
6021
6022   if (checkbutton_info[id].text_left)
6023     DrawText(x_left, y, checkbutton_info[id].text_left, FONT_TEXT_1);
6024
6025   if (checkbutton_info[id].text_right)
6026     DrawText(x_right, y, checkbutton_info[id].text_right, FONT_TEXT_1);
6027
6028   ModifyGadget(gi, GDI_CHECKED, *checkbutton_info[id].value, GDI_END);
6029
6030   MapGadget(gi);
6031 }
6032
6033 static void MapMainDrawingArea()
6034 {
6035   boolean no_horizontal_scrollbar = (lev_fieldx + 2 <= ed_fieldx);
6036   boolean no_vertical_scrollbar = (lev_fieldy + 2 <= ed_fieldy);
6037   int i;
6038
6039   for (i=ED_SCROLLBUTTON_ID_AREA_FIRST; i <= ED_SCROLLBUTTON_ID_AREA_LAST; i++)
6040   {
6041     if (((i == ED_SCROLLBUTTON_ID_AREA_LEFT ||
6042           i == ED_SCROLLBUTTON_ID_AREA_RIGHT) &&
6043          no_horizontal_scrollbar) ||
6044         ((i == ED_SCROLLBUTTON_ID_AREA_UP ||
6045           i == ED_SCROLLBUTTON_ID_AREA_DOWN) &&
6046          no_vertical_scrollbar))
6047       continue;
6048
6049     MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
6050   }
6051
6052   for (i = ED_SCROLLBAR_ID_AREA_FIRST; i <= ED_SCROLLBAR_ID_AREA_LAST; i++)
6053   {
6054     if ((i == ED_SCROLLBAR_ID_AREA_HORIZONTAL && no_horizontal_scrollbar) ||
6055         (i == ED_SCROLLBAR_ID_AREA_VERTICAL && no_vertical_scrollbar))
6056       continue;
6057
6058     MapGadget(level_editor_gadget[scrollbar_info[i].gadget_id]);
6059   }
6060
6061   MapDrawingArea(ED_DRAWING_ID_DRAWING_LEVEL);
6062 }
6063
6064 static void MapOrUnmapLevelEditorToolboxCustomGadgets(boolean map)
6065 {
6066   int i;
6067
6068   for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
6069   {
6070     if (i == GADGET_ID_CUSTOM_COPY_FROM ||
6071         i == GADGET_ID_CUSTOM_COPY_TO ||
6072         i == GADGET_ID_CUSTOM_EXCHANGE ||
6073         i == GADGET_ID_CUSTOM_COPY ||
6074         i == GADGET_ID_CUSTOM_PASTE)
6075     {
6076       if (map)
6077         MapGadget(level_editor_gadget[i]);
6078       else
6079         UnmapGadget(level_editor_gadget[i]);
6080     }
6081   }
6082 }
6083
6084 static void MapLevelEditorToolboxCustomGadgets()
6085 {
6086   MapOrUnmapLevelEditorToolboxCustomGadgets(TRUE);
6087 }
6088
6089 static void UnmapLevelEditorToolboxCustomGadgets()
6090 {
6091   MapOrUnmapLevelEditorToolboxCustomGadgets(FALSE);
6092 }
6093
6094 static void MapOrUnmapLevelEditorToolboxDrawingGadgets(boolean map)
6095 {
6096   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
6097   int i;
6098
6099   for (i = 0; i < ED_NUM_CTRL1_BUTTONS; i++)
6100   {
6101     if (i != GADGET_ID_SINGLE_ITEMS &&
6102         i != GADGET_ID_PROPERTIES &&
6103         i != GADGET_ID_PICK_ELEMENT)
6104     {
6105       struct GadgetInfo *gi = level_editor_gadget[i];
6106
6107       if (map)
6108         MapGadget(gi);
6109       else
6110       {
6111         UnmapGadget(gi);
6112
6113         BlitBitmap(gd_bitmap, drawto,
6114                    DOOR_GFX_PAGEX6 + ED_CTRL_NO_BUTTONS_GFX_XPOS,
6115                    DOOR_GFX_PAGEY1 + ED_CTRL_NO_BUTTONS_GFX_YPOS,
6116                    gi->width, gi->height, gi->x, gi->y);
6117
6118         redraw_mask |= REDRAW_DOOR_3;
6119       }
6120     }
6121   }
6122 }
6123
6124 static void MapLevelEditorToolboxDrawingGadgets()
6125 {
6126   MapOrUnmapLevelEditorToolboxDrawingGadgets(TRUE);
6127 }
6128
6129 static void UnmapLevelEditorToolboxDrawingGadgets()
6130 {
6131   MapOrUnmapLevelEditorToolboxDrawingGadgets(FALSE);
6132 }
6133
6134 static void UnmapDrawingArea(int id)
6135 {
6136   UnmapGadget(level_editor_gadget[drawingarea_info[id].gadget_id]);
6137 }
6138
6139 static void UnmapLevelEditorWindowGadgets()
6140 {
6141   int i;
6142
6143   for (i = 0; i < NUM_EDITOR_GADGETS; i++)
6144     if (level_editor_gadget[i]->x < SX + SXSIZE)
6145       UnmapGadget(level_editor_gadget[i]);
6146 }
6147
6148 void UnmapLevelEditorGadgets()
6149 {
6150   int i;
6151
6152   for (i = 0; i < NUM_EDITOR_GADGETS; i++)
6153     UnmapGadget(level_editor_gadget[i]);
6154 }
6155
6156 static void ResetUndoBuffer()
6157 {
6158   undo_buffer_position = -1;
6159   undo_buffer_steps = -1;
6160   CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
6161
6162   level.changed = FALSE;
6163 }
6164
6165 static void DrawEditModeWindow()
6166 {
6167   ModifyEditorElementList();
6168   RedrawDrawingElements();
6169
6170   if (edit_mode == ED_MODE_INFO)
6171     DrawLevelInfoWindow();
6172   else if (edit_mode == ED_MODE_PROPERTIES)
6173     DrawPropertiesWindow();
6174   else  /* edit_mode == ED_MODE_DRAWING */
6175     DrawDrawingWindow();
6176 }
6177
6178 static boolean LevelChanged()
6179 {
6180   boolean field_changed = FALSE;
6181   int x, y;
6182
6183   if (leveldir_current->readonly)
6184     return FALSE;
6185
6186   for (y = 0; y < lev_fieldy; y++) 
6187     for (x = 0; x < lev_fieldx; x++)
6188       if (Feld[x][y] != level.field[x][y])
6189         field_changed = TRUE;
6190
6191   return (level.changed || field_changed);
6192 }
6193
6194 static boolean LevelContainsPlayer()
6195 {
6196   boolean player_found = FALSE;
6197   int x, y;
6198
6199   return TRUE;          /* !!! CURRENTLY DEACTIVATED !!! */
6200
6201   for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6202   {
6203     if (Feld[x][y] == EL_PLAYER_1 ||
6204         Feld[x][y] == EL_SP_MURPHY) 
6205       player_found = TRUE;
6206   }
6207
6208   return player_found;
6209 }
6210
6211 static void CopyPlayfield(short src[MAX_LEV_FIELDX][MAX_LEV_FIELDY],
6212                           short dst[MAX_LEV_FIELDX][MAX_LEV_FIELDY])
6213 {
6214   int x, y;
6215
6216   for (x = 0; x < lev_fieldx; x++)
6217     for (y = 0; y < lev_fieldy; y++) 
6218       dst[x][y] = src[x][y];
6219 }
6220
6221 static int setSelectboxValue(int selectbox_id, int new_value)
6222 {
6223   int new_index_value = 0;
6224   int i;
6225
6226   for (i = 0; selectbox_info[selectbox_id].options[i].text != NULL; i++)
6227     if (selectbox_info[selectbox_id].options[i].value == new_value)
6228       new_index_value = i;
6229
6230   *selectbox_info[selectbox_id].value =
6231     selectbox_info[selectbox_id].options[new_index_value].value;
6232
6233   return new_index_value;
6234 }
6235
6236 static void setSelectboxSpecialActionOptions()
6237 {
6238   int i;
6239
6240   /* change action mode and arg selectbox according to action type selectbox */
6241   for (i = 0; action_arg_options[i].value != -1; i++)
6242   {
6243     if (action_arg_options[i].value == custom_element_change.action_type)
6244     {
6245       int mode = action_arg_options[i].mode;
6246
6247       ModifyEditorSelectboxOptions(ED_SELECTBOX_ID_ACTION_MODE,
6248                                    action_arg_modes[mode]);
6249       ModifyEditorSelectboxValue(ED_SELECTBOX_ID_ACTION_MODE,
6250                                  custom_element_change.action_mode);
6251
6252       ModifyEditorSelectboxOptions(ED_SELECTBOX_ID_ACTION_ARG,
6253                                    action_arg_options[i].options);
6254       ModifyEditorSelectboxValue(ED_SELECTBOX_ID_ACTION_ARG,
6255                                  custom_element_change.action_arg);
6256     }
6257   }
6258 }
6259
6260 static void copy_custom_element_settings(int element_from, int element_to)
6261 {
6262   struct ElementInfo *ei_from = &element_info[element_from];
6263   struct ElementInfo *ei_to = &element_info[element_to];
6264   int i, x, y;
6265
6266   /* ---------- copy element description ---------- */
6267   for (i = 0; i < MAX_ELEMENT_NAME_LEN + 1; i++)
6268     ei_to->description[i] = ei_from->description[i];
6269
6270   /* ---------- copy element base properties ---------- */
6271   Properties[element_to][EP_BITFIELD_BASE] =
6272     Properties[element_from][EP_BITFIELD_BASE];
6273
6274   /* ---------- copy custom property values ---------- */
6275
6276   ei_to->use_gfx_element = ei_from->use_gfx_element;
6277   ei_to->gfx_element = ei_from->gfx_element;
6278
6279   ei_to->access_direction = ei_from->access_direction;
6280
6281   ei_to->collect_score_initial = ei_from->collect_score_initial;
6282   ei_to->collect_count_initial = ei_from->collect_count_initial;
6283
6284   ei_to->ce_value_fixed_initial = ei_from->ce_value_fixed_initial;
6285   ei_to->ce_value_random_initial = ei_from->ce_value_random_initial;
6286   ei_to->use_last_ce_value = ei_from->use_last_ce_value;
6287
6288   ei_to->push_delay_fixed = ei_from->push_delay_fixed;
6289   ei_to->push_delay_random = ei_from->push_delay_random;
6290   ei_to->drop_delay_fixed = ei_from->drop_delay_fixed;
6291   ei_to->drop_delay_random = ei_from->drop_delay_random;
6292   ei_to->move_delay_fixed = ei_from->move_delay_fixed;
6293   ei_to->move_delay_random = ei_from->move_delay_random;
6294
6295   ei_to->move_pattern = ei_from->move_pattern;
6296   ei_to->move_direction_initial = ei_from->move_direction_initial;
6297   ei_to->move_stepsize = ei_from->move_stepsize;
6298
6299   ei_to->move_enter_element = ei_from->move_enter_element;
6300   ei_to->move_leave_element = ei_from->move_leave_element;
6301   ei_to->move_leave_type = ei_from->move_leave_type;
6302
6303   ei_to->slippery_type = ei_from->slippery_type;
6304
6305   for (y = 0; y < 3; y++)
6306     for (x = 0; x < 3; x++)
6307       ei_to->content.e[x][y] = ei_from->content.e[x][y];
6308
6309   ei_to->explosion_type = ei_from->explosion_type;
6310   ei_to->explosion_delay = ei_from->explosion_delay;
6311   ei_to->ignition_delay = ei_from->ignition_delay;
6312
6313   /* ---------- reinitialize and copy change pages ---------- */
6314
6315   ei_to->num_change_pages = ei_from->num_change_pages;
6316   ei_to->current_change_page = ei_from->current_change_page;
6317
6318   setElementChangePages(ei_to, ei_to->num_change_pages);
6319
6320   for (i=0; i < ei_to->num_change_pages; i++)
6321     ei_to->change_page[i] = ei_from->change_page[i];
6322
6323   /* ---------- copy group element info ---------- */
6324   if (ei_from->group != NULL && ei_to->group != NULL)   /* group or internal */
6325     *ei_to->group = *ei_from->group;
6326
6327   /* mark this custom element as modified */
6328   ei_to->modified_settings = TRUE;
6329 }
6330
6331 static void replace_custom_element_in_settings(int element_from,
6332                                                int element_to)
6333 {
6334   int i, j, x, y;
6335
6336   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
6337   {
6338     struct ElementInfo *ei = &element_info[i];
6339
6340     for (y = 0; y < 3; y++)
6341       for (x = 0; x < 3; x++)
6342         if (ei->content.e[x][y] == element_from)
6343           ei->content.e[x][y] = element_to;
6344
6345     for (j = 0; j < ei->num_change_pages; j++)
6346     {
6347       struct ElementChangeInfo *change = &ei->change_page[j];
6348
6349       if (change->target_element == element_from)
6350         change->target_element = element_to;
6351
6352       if (change->trigger_element == element_from)
6353         change->trigger_element = element_to;
6354
6355       for (y = 0; y < 3; y++)
6356         for (x = 0; x < 3; x++)
6357           if (change->target_content.e[x][y] == element_from)
6358             change->target_content.e[x][y] = element_to;
6359     }
6360
6361     if (ei->group != NULL)                              /* group or internal */
6362       for (j = 0; j < MAX_ELEMENTS_IN_GROUP; j++)
6363         if (ei->group->element[j] == element_from)
6364           ei->group->element[j] = element_to;
6365   }
6366 }
6367
6368 static void replace_custom_element_in_playfield(int element_from,
6369                                                 int element_to)
6370 {
6371   int x, y;
6372
6373   for (x = 0; x < lev_fieldx; x++)
6374     for (y = 0; y < lev_fieldy; y++)
6375       if (Feld[x][y] == element_from)
6376         Feld[x][y] = element_to;
6377 }
6378
6379 static boolean CopyCustomElement(int element_old, int element_new,
6380                                  int copy_mode)
6381 {
6382   if (copy_mode == GADGET_ID_CUSTOM_COPY)
6383   {
6384     element_new = (IS_CUSTOM_ELEMENT(element_old) ?
6385                    EL_INTERNAL_CLIPBOARD_CUSTOM : EL_INTERNAL_CLIPBOARD_GROUP);
6386     copy_mode = GADGET_ID_CUSTOM_COPY_TO;
6387   }
6388   else if (copy_mode == GADGET_ID_CUSTOM_PASTE)
6389   {
6390     element_old = (IS_CUSTOM_ELEMENT(element_new) ?
6391                    EL_INTERNAL_CLIPBOARD_CUSTOM : EL_INTERNAL_CLIPBOARD_GROUP);
6392     copy_mode = GADGET_ID_CUSTOM_COPY_TO;
6393
6394     level.changed = TRUE;
6395   }
6396   else if (IS_CUSTOM_ELEMENT(element_old) && !IS_CUSTOM_ELEMENT(element_new))
6397   {
6398     Request("Please choose custom element !", REQ_CONFIRM);
6399
6400     return FALSE;
6401   }
6402   else if (IS_GROUP_ELEMENT(element_old) && !IS_GROUP_ELEMENT(element_new))
6403   {
6404     Request("Please choose group element !", REQ_CONFIRM);
6405
6406     return FALSE;
6407   }
6408   else
6409   {
6410     level.changed = TRUE;
6411   }
6412
6413   if (copy_mode == GADGET_ID_CUSTOM_COPY_FROM)
6414   {
6415     copy_custom_element_settings(element_new, element_old);
6416   }
6417   else if (copy_mode == GADGET_ID_CUSTOM_COPY_TO)
6418   {
6419     copy_custom_element_settings(element_old, element_new);
6420   }
6421   else if (copy_mode == GADGET_ID_CUSTOM_EXCHANGE)
6422   {
6423     copy_custom_element_settings(element_old, EL_INTERNAL_DUMMY);
6424     copy_custom_element_settings(element_new, element_old);
6425     copy_custom_element_settings(EL_INTERNAL_DUMMY, element_new);
6426
6427     replace_custom_element_in_settings(element_old, EL_INTERNAL_DUMMY);
6428     replace_custom_element_in_settings(element_new, element_old);
6429     replace_custom_element_in_settings(EL_INTERNAL_DUMMY, element_new);
6430
6431     replace_custom_element_in_playfield(element_old, EL_INTERNAL_DUMMY);
6432     replace_custom_element_in_playfield(element_new, element_old);
6433     replace_custom_element_in_playfield(EL_INTERNAL_DUMMY, element_new);
6434   }
6435
6436   UpdateCustomElementGraphicGadgets();
6437   DrawPropertiesWindow();
6438
6439   return TRUE;
6440 }
6441
6442 static void CopyCustomElementPropertiesToEditor(int element)
6443 {
6444   int i;
6445   int current_change_page = element_info[element].current_change_page;
6446
6447   /* dynamically (re)build selectbox for selecting change page */
6448   for (i = 0; i < element_info[element].num_change_pages; i++)
6449   {
6450     sprintf(options_change_page_strings[i], "%d", i + 1);
6451
6452     options_change_page[i].value = i;
6453     options_change_page[i].text = options_change_page_strings[i];
6454   }
6455
6456   options_change_page[i].value = -1;
6457   options_change_page[i].text = NULL;
6458
6459   /* needed here to initialize combined element properties */
6460   InitElementPropertiesEngine(level.game_version);
6461
6462   element_info[element].change =
6463     &element_info[element].change_page[current_change_page];
6464
6465   custom_element = element_info[element];
6466   custom_element_change = *element_info[element].change;
6467
6468   /* needed to initially set selectbox options for special action options */
6469   setSelectboxSpecialActionOptions();
6470
6471   /* needed to initially set selectbox value variables to reliable defaults */
6472   for (i = 0; i < ED_NUM_SELECTBOX; i++)
6473     setSelectboxValue(i, *selectbox_info[i].value);
6474
6475   for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
6476     custom_element_properties[i] = HAS_PROPERTY(element, i);
6477
6478   for (i = 0; i < NUM_CHANGE_EVENTS; i++)
6479     custom_element_change_events[i] = HAS_CHANGE_EVENT(element, i);
6480
6481   /* ---------- element settings: configure (custom elements) ------------- */
6482
6483   /* set accessible layer selectbox help value */
6484   custom_element.access_type =
6485     (IS_WALKABLE(element) ? EP_WALKABLE :
6486      IS_PASSABLE(element) ? EP_PASSABLE :
6487      custom_element.access_type);
6488   custom_element.access_layer =
6489     (IS_ACCESSIBLE_OVER(element) ? EP_ACCESSIBLE_OVER :
6490      IS_ACCESSIBLE_INSIDE(element) ? EP_ACCESSIBLE_INSIDE :
6491      IS_ACCESSIBLE_UNDER(element) ? EP_ACCESSIBLE_UNDER :
6492      custom_element.access_layer);
6493   custom_element.access_protected =
6494     (IS_PROTECTED(element) ? 1 : 0);
6495   custom_element_properties[EP_ACCESSIBLE] =
6496     (IS_ACCESSIBLE_OVER(element) ||
6497      IS_ACCESSIBLE_INSIDE(element) ||
6498      IS_ACCESSIBLE_UNDER(element));
6499
6500   /* set walk-to-object action selectbox help value */
6501   custom_element.walk_to_action =
6502     (IS_DIGGABLE(element) ? EP_DIGGABLE :
6503      IS_COLLECTIBLE_ONLY(element) ? EP_COLLECTIBLE_ONLY :
6504      IS_DROPPABLE(element) ? EP_DROPPABLE :
6505      IS_THROWABLE(element) ? EP_THROWABLE :
6506      IS_PUSHABLE(element) ? EP_PUSHABLE :
6507      custom_element.walk_to_action);
6508   custom_element_properties[EP_WALK_TO_OBJECT] =
6509     (IS_DIGGABLE(element) ||
6510      IS_COLLECTIBLE_ONLY(element) ||
6511      IS_DROPPABLE(element) ||
6512      IS_THROWABLE(element) ||
6513      IS_PUSHABLE(element));
6514
6515   /* set smash targets selectbox help value */
6516   custom_element.smash_targets =
6517     (CAN_SMASH_EVERYTHING(element) ? EP_CAN_SMASH_EVERYTHING :
6518      CAN_SMASH_ENEMIES(element) ? EP_CAN_SMASH_ENEMIES :
6519      CAN_SMASH_PLAYER(element) ? EP_CAN_SMASH_PLAYER :
6520      custom_element.smash_targets);
6521   custom_element_properties[EP_CAN_SMASH] =
6522     (CAN_SMASH_EVERYTHING(element) ||
6523      CAN_SMASH_ENEMIES(element) ||
6524      CAN_SMASH_PLAYER(element));
6525
6526   /* set deadliness selectbox help value */
6527   custom_element.deadliness =
6528     (DONT_TOUCH(element) ? EP_DONT_TOUCH :
6529      DONT_COLLIDE_WITH(element) ? EP_DONT_COLLIDE_WITH :
6530      DONT_RUN_INTO(element) ? EP_DONT_RUN_INTO :
6531      custom_element.deadliness);
6532   custom_element_properties[EP_DEADLY] =
6533     (DONT_TOUCH(element) ||
6534      DONT_COLLIDE_WITH(element) ||
6535      DONT_RUN_INTO(element));
6536
6537   /* ---------- element settings: advanced (custom elements) --------------- */
6538
6539   /* set "change by direct action" selectbox help value */
6540   custom_element_change.direct_action =
6541     (HAS_CHANGE_EVENT(element, CE_TOUCHED_BY_PLAYER) ? CE_TOUCHED_BY_PLAYER :
6542      HAS_CHANGE_EVENT(element, CE_PRESSED_BY_PLAYER) ? CE_PRESSED_BY_PLAYER :
6543      HAS_CHANGE_EVENT(element, CE_SWITCHED_BY_PLAYER) ? CE_SWITCHED_BY_PLAYER :
6544      HAS_CHANGE_EVENT(element, CE_SNAPPED_BY_PLAYER) ? CE_SNAPPED_BY_PLAYER :
6545      HAS_CHANGE_EVENT(element, CE_PUSHED_BY_PLAYER) ? CE_PUSHED_BY_PLAYER :
6546      HAS_CHANGE_EVENT(element, CE_ENTERED_BY_PLAYER) ? CE_ENTERED_BY_PLAYER :
6547      HAS_CHANGE_EVENT(element, CE_LEFT_BY_PLAYER) ? CE_LEFT_BY_PLAYER :
6548      HAS_CHANGE_EVENT(element, CE_DROPPED_BY_PLAYER) ? CE_DROPPED_BY_PLAYER :
6549      HAS_CHANGE_EVENT(element, CE_SWITCHED) ? CE_SWITCHED :
6550      HAS_CHANGE_EVENT(element, CE_HITTING_SOMETHING) ? CE_HITTING_SOMETHING :
6551      HAS_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING) ? CE_HIT_BY_SOMETHING :
6552      HAS_CHANGE_EVENT(element, CE_BLOCKED) ? CE_BLOCKED :
6553      HAS_CHANGE_EVENT(element, CE_IMPACT) ? CE_IMPACT :
6554      HAS_CHANGE_EVENT(element, CE_SMASHED) ? CE_SMASHED :
6555      HAS_CHANGE_EVENT(element, CE_VALUE_GETS_ZERO) ? CE_VALUE_GETS_ZERO :
6556      custom_element_change.direct_action);
6557
6558   /* set "change by other element action" selectbox help value */
6559   custom_element_change.other_action =
6560     (HAS_CHANGE_EVENT(element, CE_PLAYER_TOUCHES_X) ? CE_PLAYER_TOUCHES_X :
6561      HAS_CHANGE_EVENT(element, CE_PLAYER_PRESSES_X) ? CE_PLAYER_PRESSES_X :
6562      HAS_CHANGE_EVENT(element, CE_PLAYER_SWITCHES_X) ? CE_PLAYER_SWITCHES_X :
6563      HAS_CHANGE_EVENT(element, CE_PLAYER_SNAPS_X) ? CE_PLAYER_SNAPS_X :
6564      HAS_CHANGE_EVENT(element, CE_PLAYER_PUSHES_X) ? CE_PLAYER_PUSHES_X :
6565      HAS_CHANGE_EVENT(element, CE_PLAYER_ENTERS_X) ? CE_PLAYER_ENTERS_X :
6566      HAS_CHANGE_EVENT(element, CE_PLAYER_LEAVES_X) ? CE_PLAYER_LEAVES_X :
6567      HAS_CHANGE_EVENT(element, CE_PLAYER_DIGS_X) ? CE_PLAYER_DIGS_X :
6568      HAS_CHANGE_EVENT(element, CE_PLAYER_COLLECTS_X) ? CE_PLAYER_COLLECTS_X :
6569      HAS_CHANGE_EVENT(element, CE_PLAYER_DROPS_X) ? CE_PLAYER_DROPS_X :
6570      HAS_CHANGE_EVENT(element, CE_TOUCHING_X) ? CE_TOUCHING_X :
6571      HAS_CHANGE_EVENT(element, CE_HITTING_X) ? CE_HITTING_X :
6572      HAS_CHANGE_EVENT(element, CE_HIT_BY_X) ? CE_HIT_BY_X :
6573      HAS_CHANGE_EVENT(element, CE_SWITCH_OF_X) ? CE_SWITCH_OF_X :
6574      HAS_CHANGE_EVENT(element, CE_CHANGE_OF_X) ? CE_CHANGE_OF_X :
6575      HAS_CHANGE_EVENT(element, CE_EXPLOSION_OF_X) ? CE_EXPLOSION_OF_X :
6576      HAS_CHANGE_EVENT(element, CE_MOVE_OF_X) ? CE_MOVE_OF_X :
6577      HAS_CHANGE_EVENT(element, CE_VALUE_GETS_ZERO_OF_X) ? CE_VALUE_GETS_ZERO_OF_X :
6578      custom_element_change.other_action);
6579 }
6580
6581 static void CopyGroupElementPropertiesToEditor(int element)
6582 {
6583   group_element_info = *element_info[element].group;
6584   custom_element = element_info[element];       /* needed for description */
6585 }
6586
6587 static void CopyClassicElementPropertiesToEditor(int element)
6588 {
6589   if (ELEM_IS_PLAYER(element) || COULD_MOVE_INTO_ACID(element))
6590     custom_element_properties[EP_CAN_MOVE_INTO_ACID] =
6591       getMoveIntoAcidProperty(&level, element);
6592
6593   if (MAYBE_DONT_COLLIDE_WITH(element))
6594     custom_element_properties[EP_DONT_COLLIDE_WITH] =
6595       getDontCollideWithProperty(&level, element);
6596 }
6597
6598 static void CopyElementPropertiesToEditor(int element)
6599 {
6600   if (IS_CUSTOM_ELEMENT(element))
6601     CopyCustomElementPropertiesToEditor(element);
6602   else if (IS_GROUP_ELEMENT(element))
6603     CopyGroupElementPropertiesToEditor(element);
6604   else
6605     CopyClassicElementPropertiesToEditor(element);
6606 }
6607
6608 static void CopyCustomElementPropertiesToGame(int element)
6609 {
6610   int i;
6611   int access_type_and_layer;
6612
6613   /* mark that this custom element has been modified */
6614   custom_element.modified_settings = TRUE;
6615   level.changed = TRUE;
6616
6617   if (level.use_custom_template)
6618   {
6619     if (Request("Copy and modify level template ?", REQ_ASK))
6620     {
6621       level.use_custom_template = FALSE;
6622       ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE],
6623                    GDI_CHECKED, FALSE, GDI_END);
6624     }
6625     else
6626     {
6627       LoadLevelTemplate(-1);    /* this resets all element modifications ... */
6628
6629       DrawEditModeWindow();     /* ... and copies them to 'custom_element' */
6630     }
6631   }
6632
6633   element_info[element] = custom_element;
6634   *element_info[element].change = custom_element_change;
6635
6636   /* ---------- element settings: configure (custom elements) ------------- */
6637
6638   /* set accessible property from checkbox and selectbox */
6639   custom_element_properties[EP_WALKABLE_OVER] = FALSE;
6640   custom_element_properties[EP_WALKABLE_INSIDE] = FALSE;
6641   custom_element_properties[EP_WALKABLE_UNDER] = FALSE;
6642   custom_element_properties[EP_PASSABLE_OVER] = FALSE;
6643   custom_element_properties[EP_PASSABLE_INSIDE] = FALSE;
6644   custom_element_properties[EP_PASSABLE_UNDER] = FALSE;
6645   access_type_and_layer = ((custom_element.access_type == EP_WALKABLE ?
6646                             EP_WALKABLE_OVER : EP_PASSABLE_OVER) +
6647                            (custom_element.access_layer - EP_ACCESSIBLE_OVER));
6648   custom_element_properties[access_type_and_layer] =
6649     custom_element_properties[EP_ACCESSIBLE];
6650   custom_element_properties[EP_PROTECTED] =
6651     (custom_element.access_protected != 0 &&
6652      custom_element_properties[EP_ACCESSIBLE]);
6653
6654   /* set walk-to-object property from checkbox and selectbox */
6655   custom_element_properties[EP_DIGGABLE] = FALSE;
6656   custom_element_properties[EP_COLLECTIBLE_ONLY] = FALSE;
6657   custom_element_properties[EP_DROPPABLE] = FALSE;
6658   custom_element_properties[EP_THROWABLE] = FALSE;
6659   custom_element_properties[EP_PUSHABLE] = FALSE;
6660   custom_element_properties[custom_element.walk_to_action] =
6661     custom_element_properties[EP_WALK_TO_OBJECT];
6662
6663   /* set smash property from checkbox and selectbox */
6664   custom_element_properties[EP_CAN_SMASH_PLAYER] = FALSE;
6665   custom_element_properties[EP_CAN_SMASH_ENEMIES] = FALSE;
6666   custom_element_properties[EP_CAN_SMASH_EVERYTHING] = FALSE;
6667   custom_element_properties[custom_element.smash_targets] =
6668     custom_element_properties[EP_CAN_SMASH];
6669
6670   /* set deadliness property from checkbox and selectbox */
6671   custom_element_properties[EP_DONT_RUN_INTO] = FALSE;
6672   custom_element_properties[EP_DONT_COLLIDE_WITH] = FALSE;
6673   custom_element_properties[EP_DONT_TOUCH] = FALSE;
6674   custom_element_properties[custom_element.deadliness] =
6675     custom_element_properties[EP_DEADLY];
6676
6677   /* ---------- element settings: advanced (custom elements) --------------- */
6678
6679   /* set player change event from checkbox and selectbox */
6680   custom_element_change_events[CE_TOUCHED_BY_PLAYER] = FALSE;
6681   custom_element_change_events[CE_PRESSED_BY_PLAYER] = FALSE;
6682   custom_element_change_events[CE_SWITCHED_BY_PLAYER] = FALSE;
6683   custom_element_change_events[CE_SNAPPED_BY_PLAYER] = FALSE;
6684   custom_element_change_events[CE_PUSHED_BY_PLAYER] = FALSE;
6685   custom_element_change_events[CE_ENTERED_BY_PLAYER] = FALSE;
6686   custom_element_change_events[CE_LEFT_BY_PLAYER] = FALSE;
6687   custom_element_change_events[CE_DROPPED_BY_PLAYER] = FALSE;
6688   custom_element_change_events[CE_SWITCHED] = FALSE;
6689   custom_element_change_events[CE_HITTING_SOMETHING] = FALSE;
6690   custom_element_change_events[CE_HIT_BY_SOMETHING] = FALSE;
6691   custom_element_change_events[CE_BLOCKED] = FALSE;
6692   custom_element_change_events[CE_IMPACT] = FALSE;
6693   custom_element_change_events[CE_SMASHED] = FALSE;
6694   custom_element_change_events[CE_VALUE_GETS_ZERO] = FALSE;
6695   custom_element_change_events[custom_element_change.direct_action] =
6696     custom_element_change_events[CE_BY_DIRECT_ACTION];
6697
6698   /* set other element action change event from checkbox and selectbox */
6699   custom_element_change_events[CE_PLAYER_TOUCHES_X] = FALSE;
6700   custom_element_change_events[CE_PLAYER_PRESSES_X] = FALSE;
6701   custom_element_change_events[CE_PLAYER_SWITCHES_X] = FALSE;
6702   custom_element_change_events[CE_PLAYER_SNAPS_X] = FALSE;
6703   custom_element_change_events[CE_PLAYER_PUSHES_X] = FALSE;
6704   custom_element_change_events[CE_PLAYER_ENTERS_X] = FALSE;
6705   custom_element_change_events[CE_PLAYER_LEAVES_X] = FALSE;
6706   custom_element_change_events[CE_PLAYER_DIGS_X] = FALSE;
6707   custom_element_change_events[CE_PLAYER_COLLECTS_X] = FALSE;
6708   custom_element_change_events[CE_PLAYER_DROPS_X] = FALSE;
6709   custom_element_change_events[CE_TOUCHING_X] = FALSE;
6710   custom_element_change_events[CE_HITTING_X] = FALSE;
6711   custom_element_change_events[CE_HIT_BY_X] = FALSE;
6712   custom_element_change_events[CE_SWITCH_OF_X] = FALSE;
6713   custom_element_change_events[CE_CHANGE_OF_X] = FALSE;
6714   custom_element_change_events[CE_EXPLOSION_OF_X] = FALSE;
6715   custom_element_change_events[CE_MOVE_OF_X] = FALSE;
6716   custom_element_change_events[CE_VALUE_GETS_ZERO_OF_X] = FALSE;
6717   custom_element_change_events[custom_element_change.other_action] =
6718     custom_element_change_events[CE_BY_OTHER_ACTION];
6719
6720   for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
6721     SET_PROPERTY(element, i, custom_element_properties[i]);
6722
6723   for (i = 0; i < NUM_CHANGE_EVENTS; i++)
6724     SET_CHANGE_EVENT(element, i, custom_element_change_events[i]);
6725
6726   /* copy change events also to special level editor variable */
6727   custom_element = element_info[element];
6728   custom_element_change = *element_info[element].change;
6729 }
6730
6731 static void CopyGroupElementPropertiesToGame(int element)
6732 {
6733   element_info[element] = custom_element;
6734   *element_info[element].group = group_element_info;
6735
6736   /* mark that this group element has been modified */
6737   element_info[element].modified_settings = TRUE;
6738   level.changed = TRUE;
6739 }
6740
6741 static void CopyClassicElementPropertiesToGame(int element)
6742 {
6743   if (ELEM_IS_PLAYER(element) || COULD_MOVE_INTO_ACID(element))
6744     setMoveIntoAcidProperty(&level, element,
6745                             custom_element_properties[EP_CAN_MOVE_INTO_ACID]);
6746
6747   if (MAYBE_DONT_COLLIDE_WITH(element))
6748     setDontCollideWithProperty(&level, element,
6749                               custom_element_properties[EP_DONT_COLLIDE_WITH]);
6750 }
6751
6752 static void CopyElementPropertiesToGame(int element)
6753 {
6754   if (IS_CUSTOM_ELEMENT(element))
6755     CopyCustomElementPropertiesToGame(element);
6756   else if (IS_GROUP_ELEMENT(element))
6757     CopyGroupElementPropertiesToGame(element);
6758   else
6759     CopyClassicElementPropertiesToGame(element);
6760 }
6761
6762 void DrawLevelEd()
6763 {
6764   CloseDoor(DOOR_CLOSE_ALL);
6765   OpenDoor(DOOR_OPEN_2 | DOOR_NO_DELAY);
6766
6767   if (level_editor_test_game)
6768   {
6769     CopyPlayfield(level.field, Feld);
6770     CopyPlayfield(FieldBackup, level.field);
6771
6772     level_editor_test_game = FALSE;
6773   }
6774   else
6775   {
6776     edit_mode = ED_MODE_DRAWING;
6777     edit_mode_properties = ED_MODE_PROPERTIES_INFO;
6778
6779     ResetUndoBuffer();
6780
6781     level_xpos = -1;
6782     level_ypos = -1;
6783   }
6784
6785   /* copy default editor door content to main double buffer */
6786   BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
6787              DOOR_GFX_PAGEX6, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
6788
6789   /* draw bigger door */
6790   DrawSpecialEditorDoor();
6791
6792   /* draw new control window */
6793   BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
6794              DOOR_GFX_PAGEX8, 236, EXSIZE, EYSIZE, EX, EY);
6795
6796   redraw_mask |= REDRAW_ALL;
6797
6798   ReinitializeElementList();            /* update dynamic level element list */
6799   ReinitializeElementListButtons();     /* custom element may look different */
6800
6801   UnmapTapeButtons();
6802   MapControlButtons();
6803
6804   DrawEditModeWindow();
6805
6806   /* copy actual editor door content to door double buffer for OpenDoor() */
6807   BlitBitmap(drawto, bitmap_db_door,
6808              DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
6809
6810   OpenDoor(DOOR_OPEN_1);
6811 }
6812
6813 static void AdjustDrawingAreaGadgets()
6814 {
6815   int ed_xsize = lev_fieldx + 2;
6816   int ed_ysize = lev_fieldy + 2;
6817   int max_ed_fieldx = MAX_ED_FIELDX;
6818   int max_ed_fieldy = MAX_ED_FIELDY;
6819   boolean horizontal_scrollbar_needed;
6820   boolean vertical_scrollbar_needed;
6821   int x, y, width, height;
6822   int xoffset, yoffset;
6823
6824   /* check if we need any scrollbars */
6825   horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
6826   vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
6827
6828   /* check if we have a smaller editor field because of scrollbars */
6829   if (horizontal_scrollbar_needed)
6830     max_ed_fieldy = MAX_ED_FIELDY - 1;
6831   if (vertical_scrollbar_needed)
6832     max_ed_fieldx = MAX_ED_FIELDX - 1;
6833
6834   /* check again if we now need more scrollbars because of less space */
6835   horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
6836   vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
6837
6838   /* check if editor field gets even smaller after adding new scrollbars */
6839   if (horizontal_scrollbar_needed)
6840     max_ed_fieldy = MAX_ED_FIELDY - 1;
6841   if (vertical_scrollbar_needed)
6842     max_ed_fieldx = MAX_ED_FIELDX - 1;
6843
6844   ed_fieldx = (ed_xsize < MAX_ED_FIELDX ? ed_xsize : max_ed_fieldx);
6845   ed_fieldy = (ed_ysize < MAX_ED_FIELDY ? ed_ysize : max_ed_fieldy);
6846
6847   ModifyGadget(level_editor_gadget[GADGET_ID_DRAWING_LEVEL],
6848                GDI_WIDTH, ed_fieldx * MINI_TILEX,
6849                GDI_HEIGHT, ed_fieldy * MINI_TILEY,
6850                GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
6851                GDI_END);
6852
6853   xoffset = (ed_fieldx == MAX_ED_FIELDX ? ED_SCROLLBUTTON_XSIZE : 0);
6854   yoffset = (ed_fieldy == MAX_ED_FIELDY ? ED_SCROLLBUTTON_YSIZE : 0);
6855
6856   x = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset;
6857   y = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset;
6858
6859   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT], GDI_X, x, GDI_END);
6860   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN], GDI_Y, y, GDI_END);
6861
6862   width = scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset;
6863   height = scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset;
6864
6865   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
6866                GDI_WIDTH, width,
6867                GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldx,
6868                GDI_END);
6869   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
6870                GDI_HEIGHT, height,
6871                GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldy,
6872                GDI_END);
6873 }
6874
6875 static void AdjustLevelScrollPosition()
6876 {
6877   if (level_xpos < -1)
6878     level_xpos = -1;
6879   if (level_xpos > lev_fieldx - ed_fieldx + 1)
6880     level_xpos = lev_fieldx - ed_fieldx + 1;
6881   if (lev_fieldx < ed_fieldx - 2)
6882     level_xpos = -1;
6883
6884   if (level_ypos < -1)
6885     level_ypos = -1;
6886   if (level_ypos > lev_fieldy - ed_fieldy + 1)
6887     level_ypos = lev_fieldy - ed_fieldy + 1;
6888   if (lev_fieldy < ed_fieldy - 2)
6889     level_ypos = -1;
6890 }
6891
6892 static void AdjustEditorScrollbar(int id)
6893 {
6894   struct GadgetInfo *gi = level_editor_gadget[id];
6895   int items_max, items_visible, item_position;
6896
6897   if (id == GADGET_ID_SCROLL_HORIZONTAL)
6898   {
6899     items_max = MAX(lev_fieldx + 2, ed_fieldx);
6900     items_visible = ed_fieldx;
6901     item_position = level_xpos + 1;
6902   }
6903   else
6904   {
6905     items_max = MAX(lev_fieldy + 2, ed_fieldy);
6906     items_visible = ed_fieldy;
6907     item_position = level_ypos + 1;
6908   }
6909
6910   if (item_position > items_max - items_visible)
6911     item_position = items_max - items_visible;
6912
6913   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
6914                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
6915 }
6916
6917 static void AdjustElementListScrollbar()
6918 {
6919   struct GadgetInfo *gi = level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL];
6920   int items_max, items_visible, item_position;
6921
6922   /* correct position of element list scrollbar */
6923   if (element_shift < 0)
6924     element_shift = 0;
6925   if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
6926     element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
6927
6928   items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
6929   items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
6930   item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
6931
6932   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
6933                GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
6934                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
6935 }
6936
6937 static void ModifyEditorCounterValue(int counter_id, int new_value)
6938 {
6939   int *counter_value = counterbutton_info[counter_id].value;
6940   int gadget_id = counterbutton_info[counter_id].gadget_id_text;
6941   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6942
6943   ModifyGadget(gi, GDI_NUMBER_VALUE, new_value, GDI_END);
6944
6945   if (counter_value != NULL)
6946     *counter_value = gi->textinput.number_value;
6947 }
6948
6949 static void ModifyEditorCounterLimits(int counter_id, int min, int max)
6950 {
6951   int gadget_id = counterbutton_info[counter_id].gadget_id_text;
6952   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6953
6954   ModifyGadget(gi, GDI_NUMBER_MIN, min, GDI_NUMBER_MAX, max, GDI_END);
6955
6956   if (counter_id >= ED_COUNTER_ID_ELEMENT_VALUE1 &&
6957       counter_id <= ED_COUNTER_ID_ELEMENT_VALUE4)
6958   {
6959     int gadget_id_up = counterbutton_info[counter_id].gadget_id_up;
6960     struct GadgetInfo *gi_up = level_editor_gadget[gadget_id_up];
6961
6962     ModifyGadget(gi, GDI_TEXT_SIZE, (max < 10 ? 1 : 3), GDI_END);
6963     ModifyGadget(gi_up, GDI_X, gi->x + gi->width + ED_GADGET_DISTANCE,GDI_END);
6964   }
6965 }
6966
6967 static void ModifyEditorSelectboxValue(int selectbox_id, int new_value)
6968 {
6969   int gadget_id = selectbox_info[selectbox_id].gadget_id;
6970   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6971   int new_index_value = setSelectboxValue(selectbox_id, new_value);
6972
6973   ModifyGadget(gi, GDI_SELECTBOX_INDEX, new_index_value, GDI_END);
6974 }
6975
6976 static void ModifyEditorSelectboxOptions(int selectbox_id,
6977                                          struct ValueTextInfo *options)
6978 {
6979   int gadget_id = selectbox_info[selectbox_id].gadget_id;
6980   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6981
6982   selectbox_info[selectbox_id].options = options;
6983
6984   /* set index to zero -- list may be shorter now (correct later, if needed) */
6985   ModifyGadget(gi, GDI_SELECTBOX_INDEX, 0,
6986                GDI_SELECTBOX_OPTIONS, options, GDI_END);
6987 }
6988
6989 static void ModifyEditorDrawingArea(int drawingarea_id, int xsize, int ysize)
6990 {
6991   int gadget_id = drawingarea_info[drawingarea_id].gadget_id;
6992   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6993
6994   drawingarea_info[drawingarea_id].area_xsize = xsize;
6995   drawingarea_info[drawingarea_id].area_ysize = ysize;
6996
6997   ModifyGadget(gi, GDI_AREA_SIZE, xsize, ysize, GDI_END);
6998 }
6999
7000 static void ModifyEditorElementList()
7001 {
7002   int i;
7003
7004   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
7005   {
7006     int gadget_id = GADGET_ID_ELEMENTLIST_FIRST + i;
7007     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
7008     struct GadgetDesign *gd = &gi->deco.design;
7009     int element = editor_elements[element_shift + i];
7010
7011     UnmapGadget(gi);
7012
7013     getMiniGraphicSource(el2edimg(element), &gd->bitmap, &gd->x, &gd->y);
7014     ModifyGadget(gi, GDI_INFO_TEXT, getElementInfoText(element), GDI_END);
7015
7016     MapGadget(gi);
7017   }
7018 }
7019
7020 static void PickDrawingElement(int button, int element)
7021 {
7022   if (button < 1 || button > 3)
7023     return;
7024
7025   if (button == 1)
7026   {
7027     new_element1 = element;
7028     DrawMiniGraphicExt(drawto,
7029                        DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS,
7030                        el2edimg(new_element1));
7031   }
7032   else if (button == 2)
7033   {
7034     new_element2 = element;
7035     DrawMiniGraphicExt(drawto,
7036                        DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS,
7037                        el2edimg(new_element2));
7038   }
7039   else
7040   {
7041     new_element3 = element;
7042     DrawMiniGraphicExt(drawto,
7043                        DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS,
7044                        el2edimg(new_element3));
7045   }
7046
7047   redraw_mask |= REDRAW_DOOR_1;
7048 }
7049
7050 static void RedrawDrawingElements()
7051 {
7052   PickDrawingElement(1, new_element1);
7053   PickDrawingElement(2, new_element2);
7054   PickDrawingElement(3, new_element3);
7055 }
7056
7057 static void DrawDrawingWindow()
7058 {
7059   stick_element_properties_window = FALSE;
7060
7061   SetMainBackgroundImage(IMG_UNDEFINED);
7062   ClearWindow();
7063
7064   UnmapLevelEditorWindowGadgets();
7065   UnmapLevelEditorToolboxCustomGadgets();
7066
7067   AdjustDrawingAreaGadgets();
7068   AdjustLevelScrollPosition();
7069   AdjustEditorScrollbar(GADGET_ID_SCROLL_HORIZONTAL);
7070   AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
7071
7072   DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
7073
7074   MapMainDrawingArea();
7075   MapLevelEditorToolboxDrawingGadgets();
7076 }
7077
7078 static void DrawLevelInfoWindow()
7079 {
7080   int i;
7081
7082   stick_element_properties_window = FALSE;
7083
7084   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
7085   ClearWindow();
7086   UnmapLevelEditorWindowGadgets();
7087
7088 #if 0
7089   DrawTextSCentered(ED_SETTINGS1_YPOS, FONT_TITLE_1, "Level Settings");
7090   DrawTextSCentered(ED_SETTINGS2_YPOS, FONT_TITLE_1, "Editor Settings");
7091 #else
7092   DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS1_YPOS,
7093            "Level Settings", FONT_TITLE_1);
7094   DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS2_YPOS,
7095            "Editor Settings", FONT_TITLE_1);
7096 #endif
7097
7098   /* draw counter gadgets */
7099   for (i = ED_COUNTER_ID_LEVEL_FIRST; i <= ED_COUNTER_ID_LEVEL_LAST; i++)
7100     MapCounterButtons(i);
7101
7102   /* draw selectbox gadgets */
7103   for (i = ED_SELECTBOX_ID_LEVEL_FIRST; i <= ED_SELECTBOX_ID_LEVEL_LAST; i++)
7104     MapSelectboxGadget(i);
7105
7106   /* draw checkbutton gadgets */
7107   for (i=ED_CHECKBUTTON_ID_LEVEL_FIRST; i <= ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
7108     MapCheckbuttonGadget(i);
7109
7110   /* draw radiobutton gadgets */
7111   for (i=ED_RADIOBUTTON_ID_LEVEL_FIRST; i <= ED_RADIOBUTTON_ID_LEVEL_LAST; i++)
7112     MapRadiobuttonGadget(i);
7113
7114   /* draw text input gadgets */
7115   for (i = ED_TEXTINPUT_ID_LEVEL_FIRST; i <= ED_TEXTINPUT_ID_LEVEL_LAST; i++)
7116     MapTextInputGadget(i);
7117
7118   /* draw drawing area */
7119   MapDrawingArea(ED_DRAWING_ID_RANDOM_BACKGROUND);
7120 }
7121
7122 static void DrawCustomContentArea()
7123 {
7124   int id = ED_DRAWING_ID_CUSTOM_CONTENT;
7125   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
7126   int x1 = right_gadget_border[GADGET_ID_CUSTOM_DEADLINESS];
7127   int x2 = right_gadget_border[GADGET_ID_CUSTOM_EXPLOSION_TYPE];
7128   int x3 = right_gadget_border[GADGET_ID_CUSTOM_EXPLODE_IMPACT];
7129   int xoffset = ED_DRAWINGAREA_TEXT_DISTANCE;
7130
7131   /* add distance for potential left text (without drawing area border) */
7132   x2 += getTextWidthForGadget(drawingarea_info[id].text_left);
7133
7134   ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
7135
7136   MapDrawingArea(ED_DRAWING_ID_CUSTOM_CONTENT);
7137 }
7138
7139 static void DrawCustomChangeContentArea()
7140 {
7141   int id = ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT;
7142   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
7143   int x1 = right_gadget_border[GADGET_ID_CHANGE_USE_CONTENT];
7144   int x2 = right_gadget_border[GADGET_ID_CHANGE_REPLACE_WHEN];
7145   int x3 = right_gadget_border[GADGET_ID_CHANGE_ONLY_COMPLETE];
7146   int xoffset = ED_DRAWINGAREA_TEXT_DISTANCE;
7147
7148   ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
7149
7150   MapDrawingArea(id);
7151 }
7152
7153 static void DrawYamYamContentAreas()
7154 {
7155   int x = SX + ED_AREA_YAMYAM_CONTENT_XPOS(3) + 4 * MINI_TILEX;
7156   int y = SY + ED_AREA_YAMYAM_CONTENT_YPOS(0) + ED_BORDER_AREA_YSIZE;
7157   int i;
7158
7159   /* display counter to choose number of element content areas */
7160   MapCounterButtons(ED_COUNTER_ID_YAMYAM_CONTENT);
7161
7162   for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
7163   {
7164     int id = ED_DRAWING_ID_YAMYAM_CONTENT_0 + i;
7165
7166     if (i < level.num_yamyam_contents)
7167     {
7168       MapDrawingArea(id);
7169     }
7170     else
7171     {
7172       int font_height = getFontHeight(FONT_TEXT_1);
7173
7174       UnmapDrawingArea(id);
7175
7176       /* delete content areas in case of reducing number of them */
7177       DrawBackground(SX + drawingarea_info[id].x - MINI_TILEX / 2,
7178                      SY + drawingarea_info[id].y - MINI_TILEY / 2,
7179                      4 * MINI_TILEX,
7180                      4 * MINI_TILEY + ED_GADGET_TEXT_DISTANCE + font_height);
7181     }
7182   }
7183
7184   DrawText(x, y + 0 * MINI_TILEY, "content", FONT_TEXT_1);
7185   DrawText(x, y + 1 * MINI_TILEY, "when",    FONT_TEXT_1);
7186   DrawText(x, y + 2 * MINI_TILEY, "smashed", FONT_TEXT_1);
7187 }
7188
7189 static void DrawMagicBallContentAreas()
7190 {
7191   int x = SX + ED_AREA_MAGIC_BALL_CONTENT_XPOS(3) + 4 * MINI_TILEX;
7192   int y = SY + ED_AREA_MAGIC_BALL_CONTENT_YPOS(0) + ED_BORDER_AREA_YSIZE;
7193   int i;
7194
7195   /* display counter to choose number of element content areas */
7196   MapCounterButtons(ED_COUNTER_ID_BALL_CONTENT);
7197
7198   for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
7199   {
7200     int id = ED_DRAWING_ID_MAGIC_BALL_CONTENT_0 + i;
7201
7202     if (i < level.num_ball_contents)
7203     {
7204       MapDrawingArea(id);
7205     }
7206     else
7207     {
7208       int font_height = getFontHeight(FONT_TEXT_1);
7209
7210       UnmapDrawingArea(id);
7211
7212       /* delete content areas in case of reducing number of them */
7213       DrawBackground(SX + drawingarea_info[id].x - MINI_TILEX / 2,
7214                      SY + drawingarea_info[id].y - MINI_TILEY / 2,
7215                      4 * MINI_TILEX,
7216                      4 * MINI_TILEY + ED_GADGET_TEXT_DISTANCE + font_height);
7217     }
7218   }
7219
7220   DrawText(x, y + 0 * MINI_TILEY, "generated", FONT_TEXT_1);
7221   DrawText(x, y + 1 * MINI_TILEY, "when",      FONT_TEXT_1);
7222   DrawText(x, y + 2 * MINI_TILEY, "active",    FONT_TEXT_1);
7223 }
7224
7225 static void DrawGroupElementArea(int element)
7226 {
7227   int num_elements = group_element_info.num_elements;
7228   int id = ED_DRAWING_ID_GROUP_CONTENT;
7229   int sx = SX + drawingarea_info[id].x - MINI_TILEX / 2;
7230   int sy = SY + drawingarea_info[id].y - MINI_TILEY / 2;
7231   int xsize = MAX_ELEMENTS_IN_GROUP;
7232   int ysize = 1;
7233
7234   if (drawingarea_info[id].text_left != NULL)
7235     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
7236
7237   UnmapDrawingArea(id);
7238
7239   ModifyEditorDrawingArea(id, num_elements, 1);
7240
7241   /* delete content areas in case of reducing number of them */
7242   DrawBackground(sx, sy, (xsize + 1) * MINI_TILEX, (ysize + 1) * MINI_TILEY);
7243
7244   MapDrawingArea(id);
7245 }
7246
7247 static void DrawEnvelopeTextArea(int envelope_nr)
7248 {
7249   int id = ED_TEXTAREA_ID_ENVELOPE_INFO;
7250   struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
7251
7252   UnmapGadget(gi);
7253   DrawBackground(gi->x, gi->y, gi->width, gi->height);
7254
7255   if (envelope_nr != -1)
7256     textarea_info[id].value = level.envelope_text[envelope_nr];
7257
7258   ModifyGadget(gi, GDI_AREA_SIZE,
7259                *counterbutton_info[ED_COUNTER_ID_ENVELOPE_XSIZE].value,
7260                *counterbutton_info[ED_COUNTER_ID_ENVELOPE_YSIZE].value,
7261                GDI_END);
7262
7263   MapTextAreaGadget(ED_TEXTAREA_ID_ENVELOPE_INFO);
7264 }
7265
7266 char *getElementDescriptionFilename(int element)
7267 {
7268   char *docs_dir = options.docs_directory;
7269   char *elements_subdir = "elements";
7270   static char *filename = NULL;
7271   char basename[MAX_FILENAME_LEN];
7272
7273   checked_free(filename);
7274
7275   /* 1st try: look for element description file for exactly this element */
7276   sprintf(basename, "%s.txt", element_info[element].token_name);
7277   filename = getPath3(docs_dir, elements_subdir, basename);
7278   if (fileExists(filename))
7279     return filename;
7280
7281   free(filename);
7282
7283   /* 2nd try: look for element description file for this element's class */
7284   sprintf(basename, "%s.txt", element_info[element].class_name);
7285   filename = getPath3(docs_dir, elements_subdir, basename);
7286   if (fileExists(filename))
7287     return filename;
7288
7289   return NULL;
7290 }
7291
7292 static boolean PrintInfoText(char *text, int font_nr, int start_line)
7293 {
7294   int font_height = getFontHeight(font_nr);
7295   int pad_x = ED_ELEMENT_SETTINGS_XPOS(0);
7296   int pad_y = ED_ELEMENT_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
7297   int sx = SX + pad_x;
7298   int sy = SY + pad_y;
7299   int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
7300
7301   if (start_line >= max_lines_per_screen)
7302     return FALSE;
7303
7304   DrawText(sx, sy + start_line * font_height, text, font_nr);
7305
7306   return TRUE;
7307 }
7308
7309 static int PrintElementDescriptionFromFile(char *filename, int start_line)
7310 {
7311   int font_nr = FONT_TEXT_2;
7312   int font_width = getFontWidth(font_nr);
7313   int font_height = getFontHeight(font_nr);
7314   int pad_x = ED_ELEMENT_SETTINGS_XPOS(0);
7315   int pad_y = ED_ELEMENT_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
7316   int sx = SX + pad_x;
7317   int sy = SY + pad_y + start_line * font_height;
7318   int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
7319   int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
7320
7321   return DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
7322                           max_lines_per_screen);
7323 }
7324
7325 static void DrawPropertiesTabulatorGadgets()
7326 {
7327   struct GadgetInfo *gd_gi = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
7328   struct GadgetDesign *gd = &gd_gi->alt_design[GD_BUTTON_UNPRESSED];
7329   int gd_x = gd->x + gd_gi->border.width / 2;
7330   int gd_y = gd->y + gd_gi->height - 1;
7331   Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
7332   int id_first = ED_TEXTBUTTON_ID_PROPERTIES_INFO;
7333   int id_last  = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG;
7334   int max_tabs = 4;
7335   int i;
7336
7337   /* draw additional "advanced" tabulator for custom elements */
7338   if (IS_CUSTOM_ELEMENT(properties_element))
7339     id_last = ED_TEXTBUTTON_ID_PROPERTIES_CHANGE;
7340
7341   for (i = id_first; i <= id_last; i++)
7342   {
7343     int gadget_id = textbutton_info[i].gadget_id;
7344     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
7345     boolean active = (i != edit_mode_properties);
7346
7347     /* use "config 1" and "config 2" instead of "config" */
7348     if (i == ED_TEXTBUTTON_ID_PROPERTIES_CONFIG &&
7349         IS_CUSTOM_ELEMENT(properties_element))
7350       continue;
7351
7352     /* draw background line below tabulator button */
7353     ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width,1);
7354
7355     /* draw solid line below inactive tabulator buttons */
7356     if (!active && tab_color != BLACK_PIXEL)    /* black => transparent */
7357       FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,1, tab_color);
7358
7359     ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
7360     MapTextbuttonGadget(i);
7361   }
7362
7363   /* draw little border line below tabulator buttons */
7364   if (tab_color != BLACK_PIXEL)                 /* black => transparent */
7365     FillRectangle(drawto, gd_gi->x, gd_gi->y + gd_gi->height + 1,
7366                   max_tabs * gd_gi->width + (max_tabs -1) * ED_GADGET_DISTANCE,
7367                   ED_GADGET_DISTANCE, tab_color);
7368 }
7369
7370 static void DrawPropertiesInfo()
7371 {
7372   static struct
7373   {
7374     int value;
7375     char *text;
7376   }
7377   properties[] =
7378   {
7379     /* configurable properties */
7380
7381     { EP_WALKABLE_OVER,         "- player can walk over it"             },
7382     { EP_WALKABLE_INSIDE,       "- player can walk inside it"           },
7383     { EP_WALKABLE_UNDER,        "- player can walk under it"            },
7384     { EP_PASSABLE_OVER,         "- player can pass over it"             },
7385     { EP_PASSABLE_INSIDE,       "- player can pass through it"          },
7386     { EP_PASSABLE_UNDER,        "- player can pass under it"            },
7387     { EP_PROTECTED,             "- player is protected by it"           },
7388
7389     { EP_DIGGABLE,              "- can be digged away"                  },
7390     { EP_COLLECTIBLE,           "- can be collected"                    },
7391     { EP_DROPPABLE,             "- can be dropped after collecting"     },
7392     { EP_THROWABLE,             "- can be thrown after collecting"      },
7393     { EP_PUSHABLE,              "- can be pushed"                       },
7394
7395     { EP_CAN_FALL,              "- can fall"                            },
7396     { EP_CAN_MOVE,              "- can move"                            },
7397
7398     { EP_CAN_SMASH_PLAYER,      "- can smash player"                    },
7399 #if 0
7400     { EP_CAN_SMASH_ENEMIES,     "- can smash good and bad guys"         },
7401 #endif
7402     { EP_CAN_SMASH_EVERYTHING,  "- can smash everything smashable"      },
7403
7404     { EP_SLIPPERY,              "- slippery for falling elements"       },
7405     { EP_EM_SLIPPERY_WALL,      "- slippery for some gems (EM style)"   },
7406
7407     { EP_DONT_RUN_INTO,         "- deadly when running into"            },
7408     { EP_DONT_COLLIDE_WITH,     "- deadly when colliding with"          },
7409     { EP_DONT_TOUCH,            "- deadly when touching"                },
7410
7411     { EP_INDESTRUCTIBLE,        "- indestructible"                      },
7412
7413     { EP_CAN_EXPLODE_BY_FIRE,   "- can explode by fire or explosions"   },
7414     { EP_CAN_EXPLODE_SMASHED,   "- can explode when smashed"            },
7415     { EP_CAN_EXPLODE_IMPACT,    "- can explode on impact"               },
7416
7417     { EP_CAN_CHANGE,            "- can change to other element"         },
7418
7419     /* pre-defined properties */
7420     { EP_CAN_PASS_MAGIC_WALL,   "- can pass magic walls"                },
7421     { EP_SWITCHABLE,            "- can be switched"                     },
7422     { EP_HAS_CONTENT,           "- can contain other elements"          },
7423
7424     { -1,                       NULL                                    }
7425   };
7426   char *filename = getElementDescriptionFilename(properties_element);
7427   char *percentage_text = "In this level:";
7428   char *properties_text = "Standard properties:";
7429   float percentage;
7430   int num_elements_in_level;
7431   int num_standard_properties = 0;
7432   int font1_nr = FONT_TEXT_1;
7433   int font2_nr = FONT_TEXT_2;
7434   int font1_width = getFontWidth(font1_nr);
7435   int font2_height = getFontHeight(font2_nr);
7436   int pad_x = ED_ELEMENT_SETTINGS_XPOS(0);
7437   int pad_y = ED_ELEMENT_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
7438   int screen_line = 0;
7439   int i, x, y;
7440
7441 #if DEBUG
7442   if (IS_CUSTOM_ELEMENT(properties_element))
7443   {
7444     DrawTextF(pad_x, pad_y + screen_line++ * font2_height, FONT_TEXT_3,
7445               "[Custom Element %d]", properties_element - EL_CUSTOM_START + 1);
7446     screen_line++;
7447   }
7448   else if (IS_GROUP_ELEMENT(properties_element))
7449   {
7450     DrawTextF(pad_x, pad_y + screen_line++ * font2_height, FONT_TEXT_3,
7451               "[Group Element %d]", properties_element - EL_GROUP_START + 1);
7452     screen_line++;
7453   }
7454 #endif
7455
7456   /* ----- print number of elements / percentage of this element in level */
7457
7458   num_elements_in_level = 0;
7459   for (y = 0; y < lev_fieldy; y++) 
7460     for (x = 0; x < lev_fieldx; x++)
7461       if (Feld[x][y] == properties_element)
7462         num_elements_in_level++;
7463   percentage = num_elements_in_level * 100.0 / (lev_fieldx * lev_fieldy);
7464
7465   DrawTextS(pad_x, pad_y + screen_line * font2_height, font1_nr,
7466             percentage_text);
7467   DrawTextF(pad_x + strlen(percentage_text) * font1_width,
7468             pad_y + screen_line++ * font2_height, font2_nr,
7469             "%d (%.2f%%)", num_elements_in_level, percentage);
7470
7471   screen_line++;
7472
7473   /* ----- print standard properties of this element */
7474
7475   DrawTextS(pad_x, pad_y + screen_line++ * font2_height, font1_nr,
7476             properties_text);
7477
7478   for (i = 0; properties[i].value != -1; i++)
7479   {
7480     if (!HAS_PROPERTY(properties_element, properties[i].value))
7481       continue;
7482
7483     DrawTextS(pad_x, pad_y + screen_line++ * font2_height, font2_nr,
7484               properties[i].text);
7485     num_standard_properties++;
7486   }
7487
7488   if (num_standard_properties == 0)
7489     DrawTextS(pad_x + strlen(properties_text) * font1_width,
7490               pad_y + (screen_line - 1) * font2_height, font2_nr, "none");
7491
7492   screen_line++;
7493
7494   /* ----- print special description of this element */
7495
7496   PrintInfoText("Description:", FONT_TEXT_1, screen_line);
7497   if (PrintElementDescriptionFromFile(filename, screen_line + 1) == 0)
7498     PrintInfoText("No description available.", FONT_TEXT_1, screen_line);
7499 }
7500
7501 #define TEXT_COLLECTING         "Score for collecting"
7502 #define TEXT_SMASHING           "Score for smashing"
7503 #define TEXT_SLURPING           "Score for slurping"
7504 #define TEXT_CRACKING           "Score for cracking"
7505 #define TEXT_AMOEBA_SPEED       "Speed of amoeba growth"
7506 #define TEXT_DURATION           "Duration when activated"
7507 #define TEXT_BALL_DELAY         "Element generation delay"
7508 #define TEXT_MOVE_SPEED         "Speed of android moving"
7509 #define TEXT_CLONE_SPEED        "Speed of android cloning"
7510 #define TEXT_GAME_OF_LIFE_1     "Min neighbours to survive"
7511 #define TEXT_GAME_OF_LIFE_2     "Max neighbours to survive"
7512 #define TEXT_GAME_OF_LIFE_3     "Min neighbours to create"
7513 #define TEXT_GAME_OF_LIFE_4     "Max neighbours to create"
7514 #define TEXT_TIME_BONUS         "Extra time to solve level"
7515
7516 static struct
7517 {
7518   int element;
7519   int *value;
7520   char *text;
7521 } elements_with_counter[] =
7522 {
7523   { EL_EMERALD,         &level.score[SC_EMERALD],       TEXT_COLLECTING },
7524   { EL_BD_DIAMOND,      &level.score[SC_EMERALD],       TEXT_COLLECTING },
7525   { EL_EMERALD_YELLOW,  &level.score[SC_EMERALD],       TEXT_COLLECTING },
7526   { EL_EMERALD_RED,     &level.score[SC_EMERALD],       TEXT_COLLECTING },
7527   { EL_EMERALD_PURPLE,  &level.score[SC_EMERALD],       TEXT_COLLECTING },
7528   { EL_SP_INFOTRON,     &level.score[SC_EMERALD],       TEXT_COLLECTING },
7529   { EL_DIAMOND,         &level.score[SC_DIAMOND],       TEXT_COLLECTING },
7530   { EL_CRYSTAL,         &level.score[SC_CRYSTAL],       TEXT_COLLECTING },
7531   { EL_PEARL,           &level.score[SC_PEARL],         TEXT_COLLECTING },
7532   { EL_BUG,             &level.score[SC_BUG],           TEXT_SMASHING   },
7533   { EL_BUG_RIGHT,       &level.score[SC_BUG],           TEXT_SMASHING   },
7534   { EL_BUG_UP,          &level.score[SC_BUG],           TEXT_SMASHING   },
7535   { EL_BUG_LEFT,        &level.score[SC_BUG],           TEXT_SMASHING   },
7536   { EL_BUG_DOWN,        &level.score[SC_BUG],           TEXT_SMASHING   },
7537   { EL_BD_BUTTERFLY,    &level.score[SC_BUG],           TEXT_SMASHING   },
7538   { EL_BD_BUTTERFLY_RIGHT,&level.score[SC_BUG],         TEXT_SMASHING   },
7539   { EL_BD_BUTTERFLY_UP,   &level.score[SC_BUG],         TEXT_SMASHING   },
7540   { EL_BD_BUTTERFLY_LEFT, &level.score[SC_BUG],         TEXT_SMASHING   },
7541   { EL_BD_BUTTERFLY_DOWN, &level.score[SC_BUG],         TEXT_SMASHING   },
7542   { EL_SP_ELECTRON,     &level.score[SC_BUG],           TEXT_SMASHING   },
7543   { EL_SPACESHIP,       &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7544   { EL_SPACESHIP_RIGHT, &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7545   { EL_SPACESHIP_UP,    &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7546   { EL_SPACESHIP_LEFT,  &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7547   { EL_SPACESHIP_DOWN,  &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7548   { EL_BD_FIREFLY,      &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7549   { EL_BD_FIREFLY_RIGHT,&level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7550   { EL_BD_FIREFLY_UP,   &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7551   { EL_BD_FIREFLY_LEFT, &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7552   { EL_BD_FIREFLY_DOWN, &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7553   { EL_SP_SNIKSNAK,     &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
7554   { EL_YAMYAM,          &level.score[SC_YAMYAM],        TEXT_SMASHING   },
7555   { EL_DARK_YAMYAM,     &level.score[SC_YAMYAM],        TEXT_SMASHING   },
7556   { EL_ROBOT,           &level.score[SC_ROBOT],         TEXT_SMASHING   },
7557   { EL_PACMAN,          &level.score[SC_PACMAN],        TEXT_SMASHING   },
7558   { EL_PACMAN_RIGHT,    &level.score[SC_PACMAN],        TEXT_SMASHING   },
7559   { EL_PACMAN_UP,       &level.score[SC_PACMAN],        TEXT_SMASHING   },
7560   { EL_PACMAN_LEFT,     &level.score[SC_PACMAN],        TEXT_SMASHING   },
7561   { EL_PACMAN_DOWN,     &level.score[SC_PACMAN],        TEXT_SMASHING   },
7562   { EL_NUT,             &level.score[SC_NUT],           TEXT_CRACKING   },
7563   { EL_DYNAMITE,        &level.score[SC_DYNAMITE],      TEXT_COLLECTING },
7564   { EL_DYNABOMB_INCREASE_NUMBER,&level.score[SC_DYNAMITE],TEXT_COLLECTING },
7565   { EL_DYNABOMB_INCREASE_SIZE,  &level.score[SC_DYNAMITE],TEXT_COLLECTING },
7566   { EL_DYNABOMB_INCREASE_POWER, &level.score[SC_DYNAMITE],TEXT_COLLECTING },
7567   { EL_SHIELD_NORMAL,   &level.score[SC_SHIELD],        TEXT_COLLECTING },
7568   { EL_SHIELD_DEADLY,   &level.score[SC_SHIELD],        TEXT_COLLECTING },
7569   { EL_EXTRA_TIME,      &level.extra_time_score,        TEXT_COLLECTING },
7570   { EL_KEY_1,           &level.score[SC_KEY],           TEXT_COLLECTING },
7571   { EL_KEY_2,           &level.score[SC_KEY],           TEXT_COLLECTING },
7572   { EL_KEY_3,           &level.score[SC_KEY],           TEXT_COLLECTING },
7573   { EL_KEY_4,           &level.score[SC_KEY],           TEXT_COLLECTING },
7574   { EL_EM_KEY_1,        &level.score[SC_KEY],           TEXT_COLLECTING },
7575   { EL_EM_KEY_2,        &level.score[SC_KEY],           TEXT_COLLECTING },
7576   { EL_EM_KEY_3,        &level.score[SC_KEY],           TEXT_COLLECTING },
7577   { EL_EM_KEY_4,        &level.score[SC_KEY],           TEXT_COLLECTING },
7578   { EL_EMC_KEY_5,       &level.score[SC_KEY],           TEXT_COLLECTING },
7579   { EL_EMC_KEY_6,       &level.score[SC_KEY],           TEXT_COLLECTING },
7580   { EL_EMC_KEY_7,       &level.score[SC_KEY],           TEXT_COLLECTING },
7581   { EL_EMC_KEY_8,       &level.score[SC_KEY],           TEXT_COLLECTING },
7582   { EL_AMOEBA_WET,      &level.amoeba_speed,            TEXT_AMOEBA_SPEED },
7583   { EL_AMOEBA_DRY,      &level.amoeba_speed,            TEXT_AMOEBA_SPEED },
7584   { EL_AMOEBA_FULL,     &level.amoeba_speed,            TEXT_AMOEBA_SPEED },
7585   { EL_BD_AMOEBA,       &level.amoeba_speed,            TEXT_AMOEBA_SPEED },
7586   { EL_MAGIC_WALL,      &level.time_magic_wall,         TEXT_DURATION   },
7587   { EL_BD_MAGIC_WALL,   &level.time_magic_wall,         TEXT_DURATION   },
7588   { EL_ROBOT_WHEEL,     &level.time_wheel,              TEXT_DURATION   },
7589
7590 #if 1
7591   { EL_TIMEGATE_SWITCH, &level.time_timegate,           TEXT_DURATION   },
7592   { EL_LIGHT_SWITCH_ACTIVE, &level.time_light,          TEXT_DURATION   },
7593   { EL_SHIELD_NORMAL,   &level.shield_normal_time,      TEXT_DURATION   },
7594   { EL_SHIELD_DEADLY,   &level.shield_deadly_time,      TEXT_DURATION   },
7595   { EL_EXTRA_TIME,      &level.extra_time,              TEXT_TIME_BONUS },
7596   { EL_TIME_ORB_FULL,   &level.time_orb_time,           TEXT_TIME_BONUS },
7597   { EL_GAME_OF_LIFE,    &level.game_of_life[0],         TEXT_GAME_OF_LIFE_1 },
7598   { EL_GAME_OF_LIFE,    &level.game_of_life[1],         TEXT_GAME_OF_LIFE_2 },
7599   { EL_GAME_OF_LIFE,    &level.game_of_life[2],         TEXT_GAME_OF_LIFE_3 },
7600   { EL_GAME_OF_LIFE,    &level.game_of_life[3],         TEXT_GAME_OF_LIFE_4 },
7601   { EL_BIOMAZE,         &level.biomaze[0],              TEXT_GAME_OF_LIFE_1 },
7602   { EL_BIOMAZE,         &level.biomaze[1],              TEXT_GAME_OF_LIFE_2 },
7603   { EL_BIOMAZE,         &level.biomaze[2],              TEXT_GAME_OF_LIFE_3 },
7604   { EL_BIOMAZE,         &level.biomaze[3],              TEXT_GAME_OF_LIFE_4 },
7605 #endif
7606
7607 #if 1
7608   { EL_EMC_ANDROID,     &level.android_move_time,       TEXT_MOVE_SPEED },
7609   { EL_EMC_ANDROID,     &level.android_clone_time,      TEXT_CLONE_SPEED },
7610   { EL_EMC_MAGIC_BALL,  &level.ball_time,               TEXT_BALL_DELAY },
7611   { EL_EMC_LENSES,      &level.lenses_score,            TEXT_COLLECTING },
7612   { EL_EMC_MAGNIFIER,   &level.magnify_score,           TEXT_COLLECTING },
7613   { EL_ROBOT,           &level.slurp_score,             TEXT_SLURPING   },
7614   { EL_EMC_LENSES,      &level.lenses_time,             TEXT_DURATION   },
7615   { EL_EMC_MAGNIFIER,   &level.magnify_time,            TEXT_DURATION   },
7616 #endif
7617
7618   { -1,                 NULL,                           NULL            }
7619 };
7620
7621 static boolean checkPropertiesConfig(int element)
7622 {
7623   int i;
7624
7625   if (IS_GEM(element) ||
7626       IS_CUSTOM_ELEMENT(element) ||
7627       IS_GROUP_ELEMENT(element) ||
7628       IS_ENVELOPE(element) ||
7629       ELEM_IS_PLAYER(element) ||
7630       HAS_CONTENT(element) ||
7631       CAN_GROW(element) ||
7632       COULD_MOVE_INTO_ACID(element) ||
7633       MAYBE_DONT_COLLIDE_WITH(element))
7634     return TRUE;
7635   else
7636     for (i = 0; elements_with_counter[i].element != -1; i++)
7637       if (elements_with_counter[i].element == element)
7638         return TRUE;
7639
7640   return FALSE;
7641 }
7642
7643 static void DrawPropertiesConfig()
7644 {
7645   int max_num_element_counters = 4;
7646   int num_element_counters = 0;
7647   int i;
7648
7649   if (!checkPropertiesConfig(properties_element))
7650   {
7651     PrintInfoText("No configuration options available.", FONT_TEXT_1, 0);
7652
7653     return;
7654   }
7655
7656   /* check if there are elements where a value can be chosen for */
7657   for (i = 0; elements_with_counter[i].element != -1; i++)
7658   {
7659     if (elements_with_counter[i].element == properties_element)
7660     {
7661       int counter_id = ED_COUNTER_ID_ELEMENT_VALUE1 + num_element_counters;
7662
7663       counterbutton_info[counter_id].y =
7664         ED_ELEMENT_SETTINGS_YPOS((HAS_CONTENT(properties_element) ? 1 : 0) +
7665                          (CAN_GROW(properties_element) ? 1 : 0) +
7666                          (COULD_MOVE_INTO_ACID(properties_element) ? 1 : 0) +
7667                          (MAYBE_DONT_COLLIDE_WITH(properties_element) ? 1 : 0)+
7668                          (properties_element == EL_EMC_MAGIC_BALL ? 2 : 0) +
7669                          num_element_counters);
7670
7671       counterbutton_info[counter_id].value = elements_with_counter[i].value;
7672       counterbutton_info[counter_id].text_right= elements_with_counter[i].text;
7673
7674       if (properties_element == EL_GAME_OF_LIFE ||
7675           properties_element == EL_BIOMAZE)
7676       {
7677         counterbutton_info[counter_id].min_value = 0;   /* min neighbours */
7678         counterbutton_info[counter_id].max_value = 8;   /* max neighbours */
7679       }
7680       else
7681       {
7682         /* !!! CHANGE THIS FOR CERTAIN ELEMENTS !!! */
7683         counterbutton_info[counter_id].min_value = MIN_SCORE;
7684         counterbutton_info[counter_id].max_value = MAX_SCORE;
7685       }
7686
7687       MapCounterButtons(counter_id);
7688
7689       num_element_counters++;
7690       if (num_element_counters >= max_num_element_counters)
7691         break;
7692     }
7693   }
7694
7695   if (HAS_CONTENT(properties_element))
7696   {
7697     /* draw stickybutton gadget */
7698     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
7699
7700     if (IS_AMOEBOID(properties_element))
7701       MapDrawingArea(ED_DRAWING_ID_AMOEBA_CONTENT);
7702     else if (properties_element == EL_YAMYAM)
7703       DrawYamYamContentAreas();
7704     else if (properties_element == EL_EMC_MAGIC_BALL)
7705     {
7706       DrawMagicBallContentAreas();
7707
7708       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_RANDOM_BALL_CONTENT);
7709       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INITIAL_BALL_STATE);
7710     }
7711   }
7712
7713   if (ELEM_IS_PLAYER(properties_element))
7714   {
7715     int player_nr = GET_PLAYER_NR(properties_element);
7716
7717     /* these properties can be set for every player individually */
7718     drawingarea_info[ED_DRAWING_ID_START_ELEMENT].value =
7719       &level.start_element[player_nr];
7720     drawingarea_info[ED_DRAWING_ID_ARTWORK_ELEMENT].value =
7721       &level.artwork_element[player_nr];
7722     drawingarea_info[ED_DRAWING_ID_EXPLOSION_ELEMENT].value =
7723       &level.explosion_element[player_nr];
7724
7725     /* these properties can be set for every player individually */
7726     checkbutton_info[ED_CHECKBUTTON_ID_USE_START_ELEMENT].value =
7727       &level.use_start_element[player_nr];
7728     checkbutton_info[ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT].value =
7729       &level.use_artwork_element[player_nr];
7730     checkbutton_info[ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT].value =
7731       &level.use_explosion_element[player_nr];
7732
7733     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID);
7734     MapCheckbuttonGadget(properties_element == EL_SP_MURPHY ?
7735                          ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD :
7736                          ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD);
7737     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BLOCK_SNAP_FIELD);
7738     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INSTANT_RELOCATION);
7739     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_START_ELEMENT);
7740     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT);
7741     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT);
7742     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE);
7743     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DOUBLE_SPEED);
7744
7745     MapDrawingArea(ED_DRAWING_ID_START_ELEMENT);
7746     MapDrawingArea(ED_DRAWING_ID_ARTWORK_ELEMENT);
7747     MapDrawingArea(ED_DRAWING_ID_EXPLOSION_ELEMENT);
7748   }
7749
7750   if (IS_GEM(properties_element))
7751     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS);
7752
7753   if (COULD_MOVE_INTO_ACID(properties_element) &&
7754       !ELEM_IS_PLAYER(properties_element) &&
7755       (!IS_CUSTOM_ELEMENT(properties_element) ||
7756        edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2))
7757   {
7758     /* set position for checkbutton for "can move into acid" */
7759     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].x =
7760       ED_ELEMENT_SETTINGS_XPOS(IS_CUSTOM_ELEMENT(properties_element) ? 1 : 0);
7761     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].y =
7762       ED_ELEMENT_SETTINGS_YPOS(IS_CUSTOM_ELEMENT(properties_element) ? 6 :
7763                        HAS_CONTENT(properties_element) ? 1 : 0);
7764
7765     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID);
7766   }
7767
7768   if (MAYBE_DONT_COLLIDE_WITH(properties_element))
7769     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH);
7770
7771   if (properties_element == EL_SPRING)
7772     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_SPRING_BUG);
7773
7774   if (properties_element == EL_TIME_ORB_FULL)
7775     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_TIME_ORB_BUG);
7776
7777 #if 0
7778   if (properties_element == EL_BALLOON)
7779     MapSelectboxGadget(ED_SELECTBOX_ID_WIND_DIRECTION);
7780 #endif
7781
7782   if (CAN_GROW(properties_element))
7783   {
7784     checkbutton_info[ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE].y =
7785       ED_ELEMENT_SETTINGS_YPOS(HAS_CONTENT(properties_element) ? 1 : 0);
7786
7787     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE);
7788   }
7789
7790   if (IS_ENVELOPE(properties_element))
7791   {
7792     int counter1_id = ED_COUNTER_ID_ENVELOPE_XSIZE;
7793     int counter2_id = ED_COUNTER_ID_ENVELOPE_YSIZE;
7794     int envelope_nr = properties_element - EL_ENVELOPE_1;
7795
7796     counterbutton_info[counter1_id].value = &level.envelope_xsize[envelope_nr];
7797     counterbutton_info[counter2_id].value = &level.envelope_ysize[envelope_nr];
7798
7799     /* display counter to choose size of envelope text area */
7800     MapCounterButtons(ED_COUNTER_ID_ENVELOPE_XSIZE);
7801     MapCounterButtons(ED_COUNTER_ID_ENVELOPE_YSIZE);
7802
7803     DrawEnvelopeTextArea(envelope_nr);
7804   }
7805
7806   if (IS_CUSTOM_ELEMENT(properties_element))
7807   {
7808     /* draw stickybutton gadget */
7809     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
7810
7811     if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_1)
7812     {
7813       /* draw checkbutton gadgets */
7814       for (i =  ED_CHECKBUTTON_ID_CUSTOM1_FIRST;
7815            i <= ED_CHECKBUTTON_ID_CUSTOM1_LAST; i++)
7816         MapCheckbuttonGadget(i);
7817
7818       /* draw counter gadgets */
7819       for (i =  ED_COUNTER_ID_CUSTOM1_FIRST;
7820            i <= ED_COUNTER_ID_CUSTOM1_LAST; i++)
7821         MapCounterButtons(i);
7822
7823       /* draw selectbox gadgets */
7824       for (i =  ED_SELECTBOX_ID_CUSTOM1_FIRST;
7825            i <= ED_SELECTBOX_ID_CUSTOM1_LAST; i++)
7826         MapSelectboxGadget(i);
7827
7828       /* draw textbutton gadgets */
7829       MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE);
7830
7831       /* draw text input gadgets */
7832       MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
7833
7834       /* draw drawing area gadgets */
7835       MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
7836     }
7837     else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2)
7838     {
7839       /* draw checkbutton gadgets */
7840       for (i =  ED_CHECKBUTTON_ID_CUSTOM2_FIRST;
7841            i <= ED_CHECKBUTTON_ID_CUSTOM2_LAST; i++)
7842         MapCheckbuttonGadget(i);
7843
7844       /* draw counter gadgets */
7845       for (i =  ED_COUNTER_ID_CUSTOM2_FIRST;
7846            i <= ED_COUNTER_ID_CUSTOM2_LAST; i++)
7847         MapCounterButtons(i);
7848
7849       /* draw selectbox gadgets */
7850       for (i =  ED_SELECTBOX_ID_CUSTOM2_FIRST;
7851            i <= ED_SELECTBOX_ID_CUSTOM2_LAST; i++)
7852         MapSelectboxGadget(i);
7853
7854       /* draw drawing area gadgets */
7855       MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_ENTER);
7856       MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_LEAVE);
7857       DrawCustomContentArea();
7858     }
7859   }
7860   else if (IS_GROUP_ELEMENT(properties_element))
7861   {
7862     /* draw stickybutton gadget */
7863     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
7864
7865     /* draw checkbutton gadgets */
7866     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
7867     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE);
7868
7869     /* draw counter gadgets */
7870     MapCounterButtons(ED_COUNTER_ID_GROUP_CONTENT);
7871
7872     /* draw selectbox gadgets */
7873     MapSelectboxGadget(ED_SELECTBOX_ID_GROUP_CHOICE_MODE);
7874
7875     /* draw textbutton gadgets */
7876     MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE);
7877
7878     /* draw drawing area gadgets */
7879     DrawGroupElementArea(properties_element);
7880
7881     /* draw text input gadgets */
7882     MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
7883
7884     /* draw drawing area gadgets */
7885     MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
7886   }
7887 }
7888
7889 static void DrawPropertiesChangeDrawingAreas()
7890 {
7891   if (IS_CUSTOM_ELEMENT(properties_element))
7892   {
7893     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TARGET);
7894     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER);
7895
7896     DrawCustomChangeContentArea();
7897   }
7898
7899   redraw_mask |= REDRAW_FIELD;
7900 }
7901
7902 static void DrawPropertiesChange()
7903 {
7904   int i;
7905
7906   /* needed to initially set selectbox options for special action options */
7907   setSelectboxSpecialActionOptions();
7908
7909   /* draw stickybutton gadget */
7910   MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
7911
7912   /* draw checkbutton gadgets */
7913   for (i =  ED_CHECKBUTTON_ID_CHANGE_FIRST;
7914        i <= ED_CHECKBUTTON_ID_CHANGE_LAST; i++)
7915     MapCheckbuttonGadget(i);
7916
7917   /* draw counter gadgets */
7918   for (i =  ED_COUNTER_ID_CHANGE_FIRST;
7919        i <= ED_COUNTER_ID_CHANGE_LAST; i++)
7920     MapCounterButtons(i);
7921
7922   /* draw selectbox gadgets */
7923   for (i =  ED_SELECTBOX_ID_CHANGE_FIRST;
7924        i <= ED_SELECTBOX_ID_CHANGE_LAST; i++)
7925     MapSelectboxGadget(i);
7926
7927   /* draw textbutton gadgets */
7928   for (i =  ED_TEXTBUTTON_ID_CHANGE_FIRST;
7929        i <= ED_TEXTBUTTON_ID_CHANGE_LAST; i++)
7930     MapTextbuttonGadget(i);
7931
7932   /* draw graphicbutton gadgets */
7933   for (i =  ED_GRAPHICBUTTON_ID_CHANGE_FIRST;
7934        i <= ED_GRAPHICBUTTON_ID_CHANGE_LAST; i++)
7935     MapGraphicbuttonGadget(i);
7936
7937   /* draw drawing area gadgets */
7938   DrawPropertiesChangeDrawingAreas();
7939 }
7940
7941 static void DrawElementName(int x, int y, int element)
7942 {
7943   char *element_name = getElementInfoText(element);
7944   int font_nr = FONT_TEXT_1;
7945   int font_width = getFontWidth(font_nr);
7946   int font_height = getFontHeight(font_nr);
7947   int max_text_width = SXSIZE - x - ED_ELEMENT_SETTINGS_XPOS(0);
7948   int max_chars_per_line = max_text_width / font_width;
7949   char buffer[max_chars_per_line + 1];
7950
7951   if (strlen(element_name) <= max_chars_per_line)
7952     DrawTextS(x, y, font_nr, element_name);
7953   else
7954   {
7955     int next_pos = max_chars_per_line;
7956
7957     strncpy(buffer, element_name, max_chars_per_line);
7958     buffer[max_chars_per_line] = '\0';
7959
7960     if (element_name[max_chars_per_line] == ' ')
7961       next_pos++;
7962     else
7963     {
7964       int i;
7965
7966       for (i = max_chars_per_line - 1; i >= 0; i--)
7967         if (buffer[i] == ' ')
7968           break;
7969
7970       if (strlen(&element_name[i + 1]) <= max_chars_per_line)
7971       {
7972         buffer[i] = '\0';
7973         next_pos = i + 1;
7974       }
7975     }
7976
7977     DrawTextS(x, y - font_height / 2, font_nr, buffer);
7978
7979     strncpy(buffer, &element_name[next_pos], max_chars_per_line);
7980     buffer[max_chars_per_line] = '\0';
7981
7982     DrawTextS(x, y + font_height / 2, font_nr, buffer);
7983   }
7984 }
7985
7986 static void DrawPropertiesWindow()
7987 {
7988   int xstart = 2;
7989   int ystart = 4;
7990
7991   stick_element_properties_window = FALSE;
7992
7993   /* make sure that previous properties edit mode exists for this element */
7994   if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG &&
7995       !IS_CUSTOM_ELEMENT(properties_element))
7996     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
7997
7998   if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG &&
7999       IS_CUSTOM_ELEMENT(properties_element))
8000     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_1;
8001
8002   CopyElementPropertiesToEditor(properties_element);
8003
8004   UnmapLevelEditorWindowGadgets();
8005   UnmapLevelEditorToolboxDrawingGadgets();
8006   UnmapLevelEditorToolboxCustomGadgets();
8007
8008   if (IS_CUSTOM_ELEMENT(properties_element) ||
8009       IS_GROUP_ELEMENT(properties_element))
8010     MapLevelEditorToolboxCustomGadgets();
8011
8012   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
8013   ClearWindow();
8014
8015 #if 0
8016   DrawTextSCentered(ED_SETTINGS1_YPOS, FONT_TITLE_1, "Element Settings");
8017 #else
8018   DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS1_YPOS,
8019            "Element Settings", FONT_TITLE_1);
8020 #endif
8021
8022   DrawElementBorder(SX + xstart * MINI_TILEX,
8023                     SY + ystart * MINI_TILEY + MINI_TILEY / 2,
8024                     TILEX, TILEY, FALSE);
8025   DrawGraphicAnimationExt(drawto,
8026                           SX + xstart * MINI_TILEX,
8027                           SY + ystart * MINI_TILEY + MINI_TILEY / 2,
8028                           el2img(properties_element), -1, NO_MASKING);
8029
8030   FrameCounter = 0;     /* restart animation frame counter */
8031
8032   DrawElementName((xstart + 3) * MINI_TILEX + 1, (ystart + 1) * MINI_TILEY + 1,
8033                   properties_element);
8034
8035   DrawPropertiesTabulatorGadgets();
8036
8037   if (edit_mode_properties == ED_MODE_PROPERTIES_INFO)
8038     DrawPropertiesInfo();
8039   else if (edit_mode_properties == ED_MODE_PROPERTIES_CHANGE)
8040     DrawPropertiesChange();
8041   else  /* (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG[_1|_2]) */
8042     DrawPropertiesConfig();
8043 }
8044
8045 static void UpdateCustomElementGraphicGadgets()
8046 {
8047   int i;
8048
8049   ModifyEditorElementList();
8050   RedrawDrawingElements();
8051
8052   /* force redraw of all mapped drawing area gadgets */
8053   for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
8054   {
8055     struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[i].gadget_id];
8056
8057     if (gi->mapped)
8058       MapDrawingArea(i);
8059   }
8060 }
8061
8062 static void DrawLineElement(int sx, int sy, int element, boolean change_level)
8063 {
8064   int lx = sx + level_xpos;
8065   int ly = sy + level_ypos;
8066
8067   DrawMiniElement(sx, sy, (element < 0 ? Feld[lx][ly] : element));
8068
8069   if (change_level)
8070     Feld[lx][ly] = element;
8071 }
8072
8073 static void DrawLine(int from_x, int from_y, int to_x, int to_y,
8074                      int element, boolean change_level)
8075 {
8076   if (from_y == to_y)                   /* horizontal line */
8077   {
8078     int x;
8079     int y = from_y;
8080
8081     if (from_x > to_x)
8082       swap_numbers(&from_x, &to_x);
8083
8084     for (x = from_x; x <= to_x; x++)
8085       DrawLineElement(x, y, element, change_level);
8086   }
8087   else if (from_x == to_x)              /* vertical line */
8088   {
8089     int x = from_x;
8090     int y;
8091
8092     if (from_y > to_y)
8093       swap_numbers(&from_y, &to_y);
8094
8095     for (y = from_y; y <= to_y; y++)
8096       DrawLineElement(x, y, element, change_level);
8097   }
8098   else                                  /* diagonal line */
8099   {
8100     int len_x = ABS(to_x - from_x);
8101     int len_y = ABS(to_y - from_y);
8102     int x, y;
8103
8104     if (len_y < len_x)                  /* a < 1 */
8105     {
8106       float a = (float)len_y / (float)len_x;
8107
8108       if (from_x > to_x)
8109         swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
8110
8111       for (x = 0; x <= len_x; x++)
8112       {
8113         y = (int)(a * x + 0.5) * (to_y < from_y ? -1 : +1);
8114         DrawLineElement(from_x + x, from_y + y, element, change_level);
8115       }
8116     }
8117     else                                /* a >= 1 */
8118     {
8119       float a = (float)len_x / (float)len_y;
8120
8121       if (from_y > to_y)
8122         swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
8123
8124       for (y = 0; y <= len_y; y++)
8125       {
8126         x = (int)(a * y + 0.5) * (to_x < from_x ? -1 : +1);
8127         DrawLineElement(from_x + x, from_y + y, element, change_level);
8128       }
8129     }
8130   }
8131 }
8132
8133 static void DrawBox(int from_x, int from_y, int to_x, int to_y,
8134                     int element, boolean change_level)
8135 {
8136   DrawLine(from_x, from_y, from_x, to_y, element, change_level);
8137   DrawLine(from_x, to_y, to_x, to_y, element, change_level);
8138   DrawLine(to_x, to_y, to_x, from_y, element, change_level);
8139   DrawLine(to_x, from_y, from_x, from_y, element, change_level);
8140 }
8141
8142 static void DrawFilledBox(int from_x, int from_y, int to_x, int to_y,
8143                           int element, boolean change_level)
8144 {
8145   int y;
8146
8147   if (from_y > to_y)
8148     swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
8149
8150   for (y = from_y; y <= to_y; y++)
8151     DrawLine(from_x, y, to_x, y, element, change_level);
8152 }
8153
8154 static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
8155                        int element, boolean change_level)
8156 {
8157   int to_x = to_x2 - (to_x2 > from_x ? +1 : -1);
8158   int to_y = to_y2 - (to_y2 > from_y ? +1 : -1);
8159   int len_x = ABS(to_x - from_x);
8160   int len_y = ABS(to_y - from_y);
8161   int radius, x, y;
8162
8163   radius = (int)(sqrt((float)(len_x * len_x + len_y * len_y)) + 0.5);
8164
8165   /* not optimal (some points get drawn twice) but simple,
8166      and fast enough for the few points we are drawing */
8167
8168   for (x = 0; x <= radius; x++)
8169   {
8170     int sx, sy, lx, ly;
8171
8172     y = (int)(sqrt((float)(radius * radius - x * x)) + 0.5);
8173
8174     sx = from_x + x * (from_x < to_x2 ? +1 : -1);
8175     sy = from_y + y * (from_y < to_y2 ? +1 : -1);
8176     lx = sx + level_xpos;
8177     ly = sy + level_ypos;
8178
8179     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
8180       DrawLineElement(sx, sy, element, change_level);
8181   }
8182
8183   for (y = 0; y <= radius; y++)
8184   {
8185     int sx, sy, lx, ly;
8186
8187     x = (int)(sqrt((float)(radius * radius - y * y)) + 0.5);
8188
8189     sx = from_x + x * (from_x < to_x2 ? +1 : -1);
8190     sy = from_y + y * (from_y < to_y2 ? +1 : -1);
8191     lx = sx + level_xpos;
8192     ly = sy + level_ypos;
8193
8194     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
8195       DrawLineElement(sx, sy, element, change_level);
8196   }
8197 }
8198
8199 static void DrawArc(int from_x, int from_y, int to_x, int to_y,
8200                     int element, boolean change_level)
8201 {
8202   int to_x2 = to_x + (to_x < from_x ? -1 : +1);
8203   int to_y2 = to_y + (to_y > from_y ? +1 : -1);
8204
8205   DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
8206 }
8207
8208 #define DRAW_CIRCLES_BUTTON_AVAILABLE   0
8209
8210 #if DRAW_CIRCLES_BUTTON_AVAILABLE
8211 static void DrawCircle(int from_x, int from_y, int to_x, int to_y,
8212                        int element, boolean change_level)
8213 {
8214   int to_x2 = to_x + (to_x < from_x ? -1 : +1);
8215   int to_y2 = to_y + (to_y > from_y ? +1 : -1);
8216   int mirror_to_x2 = from_x - (to_x2 - from_x);
8217   int mirror_to_y2 = from_y - (to_y2 - from_y);
8218
8219   DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
8220   DrawArcExt(from_x, from_y, mirror_to_x2, to_y2, element, change_level);
8221   DrawArcExt(from_x, from_y, to_x2, mirror_to_y2, element, change_level);
8222   DrawArcExt(from_x, from_y, mirror_to_x2, mirror_to_y2, element,change_level);
8223 }
8224 #endif
8225
8226 static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y)
8227 {
8228   int from_sx, from_sy;
8229   int to_sx, to_sy;
8230
8231   if (from_x > to_x)
8232     swap_numbers(&from_x, &to_x);
8233
8234   if (from_y > to_y)
8235     swap_numbers(&from_y, &to_y);
8236
8237   from_sx = SX + from_x * MINI_TILEX;
8238   from_sy = SY + from_y * MINI_TILEY;
8239   to_sx = SX + to_x * MINI_TILEX + MINI_TILEX - 1;
8240   to_sy = SY + to_y * MINI_TILEY + MINI_TILEY - 1;
8241
8242   DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx, from_sy);
8243   DrawSimpleWhiteLine(drawto, to_sx, from_sy, to_sx, to_sy);
8244   DrawSimpleWhiteLine(drawto, to_sx, to_sy, from_sx, to_sy);
8245   DrawSimpleWhiteLine(drawto, from_sx, to_sy, from_sx, from_sy);
8246
8247   if (from_x == to_x && from_y == to_y)
8248     MarkTileDirty(from_x/2, from_y/2);
8249   else
8250     redraw_mask |= REDRAW_FIELD;
8251 }
8252
8253 static void SelectArea(int from_x, int from_y, int to_x, int to_y,
8254                        int element, boolean change_level)
8255 {
8256   if (element == -1 || change_level)
8257     DrawBox(from_x, from_y, to_x, to_y, -1, FALSE);
8258   else
8259     DrawAreaBorder(from_x, from_y, to_x, to_y);
8260 }
8261
8262 /* values for CopyBrushExt() */
8263 #define CB_AREA_TO_BRUSH        0
8264 #define CB_BRUSH_TO_CURSOR      1
8265 #define CB_BRUSH_TO_LEVEL       2
8266 #define CB_DELETE_OLD_CURSOR    3
8267 #define CB_DUMP_BRUSH           4
8268 #define CB_DUMP_BRUSH_SMALL     5
8269
8270 static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
8271                          int button, int mode)
8272 {
8273   static short brush_buffer[MAX_ED_FIELDX][MAX_ED_FIELDY];
8274   static int brush_width, brush_height;
8275   static int last_cursor_x = -1, last_cursor_y = -1;
8276   static boolean delete_old_brush;
8277   int new_element = BUTTON_ELEMENT(button);
8278   int x, y;
8279
8280   if (mode == CB_DUMP_BRUSH ||
8281       mode == CB_DUMP_BRUSH_SMALL)
8282   {
8283     if (!draw_with_brush)
8284     {
8285       Error(ERR_WARN, "no brush selected");
8286
8287       return;
8288     }
8289
8290     for (y = 0; y < brush_height; y++)
8291     {
8292       for (x = 0; x < brush_width; x++)
8293       {
8294         int element = brush_buffer[x][y];
8295         int element_mapped = element;
8296
8297         if (IS_CUSTOM_ELEMENT(element))
8298           element_mapped = EL_CUSTOM_START;
8299         else if (IS_GROUP_ELEMENT(element))
8300           element_mapped = EL_GROUP_START;
8301         else if (element >= NUM_FILE_ELEMENTS)
8302           element_mapped = EL_UNKNOWN;
8303
8304         printf("%c%03d", (mode == CB_DUMP_BRUSH ? '`' : '¸'), element_mapped);
8305       }
8306
8307       printf("\n");
8308     }
8309
8310     return;
8311   }
8312
8313   if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush)
8314     return;
8315
8316   if (mode == CB_AREA_TO_BRUSH)
8317   {
8318     int from_lx, from_ly;
8319
8320     if (from_x > to_x)
8321       swap_numbers(&from_x, &to_x);
8322
8323     if (from_y > to_y)
8324       swap_numbers(&from_y, &to_y);
8325
8326     brush_width = to_x - from_x + 1;
8327     brush_height = to_y - from_y + 1;
8328
8329     from_lx = from_x + level_xpos;
8330     from_ly = from_y + level_ypos;
8331
8332     for (y = 0; y < brush_height; y++)
8333     {
8334       for (x=0; x < brush_width; x++)
8335       {
8336         brush_buffer[x][y] = Feld[from_lx + x][from_ly + y];
8337
8338         if (button != 1)
8339           DrawLineElement(from_x + x, from_y + y, new_element, TRUE);
8340       }
8341     }
8342
8343     if (button != 1)
8344       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8345
8346     delete_old_brush = FALSE;
8347   }
8348   else if (mode == CB_BRUSH_TO_CURSOR || mode == CB_DELETE_OLD_CURSOR ||
8349            mode == CB_BRUSH_TO_LEVEL)
8350   {
8351     int cursor_x = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_x : from_x);
8352     int cursor_y = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_y : from_y);
8353     int cursor_from_x = cursor_x - brush_width / 2;
8354     int cursor_from_y = cursor_y - brush_height / 2;
8355     int border_from_x = cursor_x, border_from_y = cursor_y;
8356     int border_to_x = cursor_x, border_to_y = cursor_y;
8357
8358     if (mode != CB_DELETE_OLD_CURSOR && delete_old_brush)
8359       CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
8360
8361     if (!IN_ED_FIELD(cursor_x, cursor_y) ||
8362         !IN_LEV_FIELD(cursor_x + level_xpos, cursor_y + level_ypos))
8363     {
8364       delete_old_brush = FALSE;
8365       return;
8366     }
8367
8368     for (y = 0; y < brush_height; y++)
8369     {
8370       for (x = 0; x < brush_width; x++)
8371       {
8372         int sx = cursor_from_x + x;
8373         int sy = cursor_from_y + y;
8374         int lx = sx + level_xpos;
8375         int ly = sy + level_ypos;
8376         boolean change_level = (mode == CB_BRUSH_TO_LEVEL);
8377         int element = (mode == CB_DELETE_OLD_CURSOR ? -1 :
8378                        mode == CB_BRUSH_TO_CURSOR || button == 1 ?
8379                        brush_buffer[x][y] : new_element);
8380
8381         if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
8382         {
8383           if (sx < border_from_x)
8384             border_from_x = sx;
8385           else if (sx > border_to_x)
8386             border_to_x = sx;
8387           if (sy < border_from_y)
8388             border_from_y = sy;
8389           else if (sy > border_to_y)
8390             border_to_y = sy;
8391
8392           DrawLineElement(sx, sy, element, change_level);
8393         }
8394       }
8395     }
8396
8397     if (mode != CB_DELETE_OLD_CURSOR)
8398       DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y);
8399
8400     last_cursor_x = cursor_x;
8401     last_cursor_y = cursor_y;
8402     delete_old_brush = TRUE;
8403   }
8404 }
8405
8406 static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y,
8407                             int button)
8408 {
8409   CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH);
8410 }
8411
8412 static void CopyBrushToLevel(int x, int y, int button)
8413 {
8414   CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL);
8415 }
8416
8417 static void CopyBrushToCursor(int x, int y)
8418 {
8419   CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
8420 }
8421
8422 static void DeleteBrushFromCursor()
8423 {
8424   CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
8425 }
8426
8427 void DumpBrush()
8428 {
8429   CopyBrushExt(0, 0, 0, 0, 0, CB_DUMP_BRUSH);
8430 }
8431
8432 void DumpBrush_Small()
8433 {
8434   CopyBrushExt(0, 0, 0, 0, 0, CB_DUMP_BRUSH_SMALL);
8435 }
8436
8437 static void FloodFill(int from_x, int from_y, int fill_element)
8438 {
8439   int i,x,y;
8440   int old_element;
8441   static int check[4][2] = { {-1,0}, {0,-1}, {1,0}, {0,1} };
8442   static int safety = 0;
8443
8444   /* check if starting field still has the desired content */
8445   if (Feld[from_x][from_y] == fill_element)
8446     return;
8447
8448   safety++;
8449
8450   if (safety > lev_fieldx*lev_fieldy)
8451     Error(ERR_EXIT, "Something went wrong in 'FloodFill()'. Please debug.");
8452
8453   old_element = Feld[from_x][from_y];
8454   Feld[from_x][from_y] = fill_element;
8455
8456   for (i = 0; i < 4; i++)
8457   {
8458     x = from_x + check[i][0];
8459     y = from_y + check[i][1];
8460
8461     if (IN_LEV_FIELD(x,y) && Feld[x][y] == old_element)
8462       FloodFill(x, y, fill_element);
8463   }
8464
8465   safety--;
8466 }
8467
8468 /* values for DrawLevelText() modes */
8469 #define TEXT_INIT               0
8470 #define TEXT_SETCURSOR          1
8471 #define TEXT_WRITECHAR          2
8472 #define TEXT_BACKSPACE          3
8473 #define TEXT_NEWLINE            4
8474 #define TEXT_END                5
8475 #define TEXT_QUERY_TYPING       6
8476
8477 static int DrawLevelText(int sx, int sy, char letter, int mode)
8478 {
8479   static short delete_buffer[MAX_LEV_FIELDX];
8480   static int start_sx, start_sy;
8481   static int last_sx, last_sy;
8482   static boolean typing = FALSE;
8483   int letter_element = EL_CHAR_ASCII0 + letter;
8484   int lx = 0, ly = 0;
8485
8486   /* map lower case letters to upper case and convert special characters */
8487   if (letter >= 'a' && letter <= 'z')
8488     letter_element = EL_CHAR_ASCII0 + letter + (int)('A' - 'a');
8489   else if (letter == 'ä' || letter == 'Ä')
8490     letter_element = EL_CHAR_AUMLAUT;
8491   else if (letter == 'ö' || letter == 'Ö')
8492     letter_element = EL_CHAR_OUMLAUT;
8493   else if (letter == 'ü' || letter == 'Ãœ')
8494     letter_element = EL_CHAR_UUMLAUT;
8495   else if (letter == '^')
8496     letter_element = EL_CHAR_COPYRIGHT;
8497   else
8498     letter_element = EL_CHAR_ASCII0 + letter;
8499
8500   if (mode != TEXT_INIT)
8501   {
8502     if (!typing)
8503       return FALSE;
8504
8505     if (mode != TEXT_SETCURSOR)
8506     {
8507       sx = last_sx;
8508       sy = last_sy;
8509     }
8510
8511     lx = last_sx + level_xpos;
8512     ly = last_sy + level_ypos;
8513   }
8514
8515   switch (mode)
8516   {
8517     case TEXT_INIT:
8518       if (typing)
8519         DrawLevelText(0, 0, 0, TEXT_END);
8520
8521       typing = TRUE;
8522       start_sx = last_sx = sx;
8523       start_sy = last_sy = sy;
8524       DrawLevelText(sx, sy, 0, TEXT_SETCURSOR);
8525       break;
8526
8527     case TEXT_SETCURSOR:
8528       DrawMiniElement(last_sx, last_sy, Feld[lx][ly]);
8529       DrawAreaBorder(sx, sy, sx, sy);
8530       last_sx = sx;
8531       last_sy = sy;
8532       break;
8533
8534     case TEXT_WRITECHAR:
8535       if (letter_element >= EL_CHAR_START && letter_element <= EL_CHAR_END)
8536       {
8537         delete_buffer[sx - start_sx] = Feld[lx][ly];
8538         Feld[lx][ly] = letter_element;
8539
8540         if (sx + 1 < ed_fieldx && lx + 1 < lev_fieldx)
8541           DrawLevelText(sx + 1, sy, 0, TEXT_SETCURSOR);
8542         else if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
8543           DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
8544         else
8545           DrawLevelText(0, 0, 0, TEXT_END);
8546
8547         level.changed = TRUE;
8548       }
8549       break;
8550
8551     case TEXT_BACKSPACE:
8552       if (sx > start_sx)
8553       {
8554         Feld[lx - 1][ly] = delete_buffer[sx - start_sx - 1];
8555         DrawMiniElement(sx - 1, sy, Feld[lx - 1][ly]);
8556         DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR);
8557       }
8558       break;
8559
8560     case TEXT_NEWLINE:
8561       if (sy + 1 < ed_fieldy - 1 && ly + 1 < lev_fieldy - 1)
8562         DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
8563       else
8564         DrawLevelText(0, 0, 0, TEXT_END);
8565       break;
8566
8567     case TEXT_END:
8568       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8569       DrawMiniElement(sx, sy, Feld[lx][ly]);
8570       typing = FALSE;
8571       break;
8572
8573     case TEXT_QUERY_TYPING:
8574       break;
8575
8576     default:
8577       break;
8578   }
8579
8580   return typing;
8581 }
8582
8583 static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy,
8584                           int element, boolean change_level)
8585 {
8586   int lx = sx + level_xpos;
8587   int ly = sy + level_ypos;
8588
8589   if (element == -1)
8590     DrawMiniElement(sx, sy, Feld[lx][ly]);
8591   else
8592     DrawAreaBorder(sx, sy, sx, sy);
8593 }
8594
8595 static void CopyLevelToUndoBuffer(int mode)
8596 {
8597   static boolean accumulated_undo = FALSE;
8598   boolean new_undo_buffer_position = TRUE;
8599   int last_border_element;
8600   int x, y;
8601
8602   switch (mode)
8603   {
8604     case UNDO_IMMEDIATE:
8605       accumulated_undo = FALSE;
8606       break;
8607
8608     case UNDO_ACCUMULATE:
8609       if (accumulated_undo)
8610         new_undo_buffer_position = FALSE;
8611       accumulated_undo = TRUE;
8612       break;
8613
8614     default:
8615       break;
8616   }
8617
8618   if (new_undo_buffer_position)
8619   {
8620     /* new position in undo buffer ring */
8621     undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS;
8622
8623     if (undo_buffer_steps < NUM_UNDO_STEPS - 1)
8624       undo_buffer_steps++;
8625   }
8626
8627   for (x = 0; x < lev_fieldx; x++)
8628     for (y = 0; y < lev_fieldy; y++)
8629       UndoBuffer[undo_buffer_position][x][y] = Feld[x][y];
8630
8631   /* check if drawing operation forces change of border style */
8632   last_border_element = BorderElement;
8633   SetBorderElement();
8634   if (BorderElement != last_border_element)
8635     DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8636
8637   level.changed = TRUE;
8638 }
8639
8640 static void RandomPlacement(int new_element)
8641 {
8642   static boolean free_position[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
8643   int num_free_positions = 0;
8644   int num_percentage, num_elements;
8645   int x, y;
8646
8647   /* determine number of free positions for randomly placing the new element */
8648   for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
8649   {
8650     free_position[x][y] =
8651       (random_placement_background_restricted ?
8652        Feld[x][y] == random_placement_background_element :
8653        Feld[x][y] != new_element);
8654
8655     if (free_position[x][y])
8656       num_free_positions++;
8657   }
8658
8659   /* determine number of new elements to place there */
8660   num_percentage = num_free_positions * random_placement_value / 100;
8661   num_elements = (random_placement_method == RANDOM_USE_PERCENTAGE ?
8662                   num_percentage : random_placement_value);
8663
8664   /* if less free positions than elements to place, fill all these positions */
8665   if (num_free_positions < num_elements)
8666   {
8667     for (x = 0; x < lev_fieldx; x++)
8668       for (y = 0; y < lev_fieldy; y++)
8669         if (free_position[x][y])
8670           Feld[x][y] = new_element;
8671   }
8672   else
8673   {
8674     while (num_elements > 0)
8675     {
8676       x = RND(lev_fieldx);
8677       y = RND(lev_fieldy);
8678
8679       /* don't place element at the same position twice */
8680       if (free_position[x][y])
8681       {
8682         free_position[x][y] = FALSE;
8683         Feld[x][y] = new_element;
8684         num_elements--;
8685       }
8686     }
8687   }
8688
8689   DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8690   CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8691 }
8692
8693 void WrapLevel(int dx, int dy)
8694 {
8695   int wrap_dx = lev_fieldx - dx;
8696   int wrap_dy = lev_fieldy - dy;
8697   int x, y;
8698
8699   for (x = 0; x < lev_fieldx; x++)
8700     for (y = 0; y < lev_fieldy; y++)
8701       FieldBackup[x][y] = Feld[x][y];
8702
8703   for (x = 0; x < lev_fieldx; x++)
8704     for (y = 0; y < lev_fieldy; y++)
8705       Feld[x][y] =
8706         FieldBackup[(x + wrap_dx) % lev_fieldx][(y + wrap_dy) % lev_fieldy];
8707
8708   DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8709   CopyLevelToUndoBuffer(UNDO_ACCUMULATE);
8710 }
8711
8712 static void HandleDrawingAreas(struct GadgetInfo *gi)
8713 {
8714   static boolean started_inside_drawing_area = FALSE;
8715   int id = gi->custom_id;
8716   boolean button_press_event;
8717   boolean button_release_event;
8718   boolean inside_drawing_area = !gi->event.off_borders;
8719   boolean draw_level = (id == GADGET_ID_DRAWING_LEVEL);
8720   int actual_drawing_function;
8721   int button = gi->event.button;
8722   int new_element = BUTTON_ELEMENT(button);
8723   int sx = gi->event.x, sy = gi->event.y;
8724   int min_sx = 0, min_sy = 0;
8725   int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1;
8726   int item_xsize = gi->drawing.item_xsize, item_ysize = gi->drawing.item_ysize;
8727   int lx = 0, ly = 0;
8728   int min_lx = 0, min_ly = 0;
8729   int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
8730   int x, y;
8731
8732   /* handle info callback for each invocation of action callback */
8733   gi->callback_info(gi);
8734
8735   button_press_event = (gi->event.type == GD_EVENT_PRESSED);
8736   button_release_event = (gi->event.type == GD_EVENT_RELEASED);
8737
8738   /* make sure to stay inside drawing area boundaries */
8739   sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
8740   sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
8741
8742   if (draw_level)
8743   {
8744     /* get positions inside level field */
8745     lx = sx + level_xpos;
8746     ly = sy + level_ypos;
8747
8748     if (!IN_LEV_FIELD(lx, ly))
8749       inside_drawing_area = FALSE;
8750
8751     /* make sure to stay inside level field boundaries */
8752     lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
8753     ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
8754
8755     /* correct drawing area positions accordingly */
8756     sx = lx - level_xpos;
8757     sy = ly - level_ypos;
8758   }
8759
8760   if (button_press_event)
8761     started_inside_drawing_area = inside_drawing_area;
8762
8763   if (!started_inside_drawing_area)
8764     return;
8765
8766 #if 1
8767   if (!IS_VALID_BUTTON(button))
8768     return;
8769 #endif
8770
8771   if (!button && !button_release_event)
8772     return;
8773
8774   /* automatically switch to 'single item' drawing mode, if needed */
8775   actual_drawing_function =
8776     (draw_level || drawing_function == GADGET_ID_PICK_ELEMENT ?
8777      drawing_function : GADGET_ID_SINGLE_ITEMS);
8778
8779   /* clicking into drawing area with pressed Control key picks element */
8780   if (GetKeyModState() & KMOD_Control)
8781   {
8782     last_drawing_function = drawing_function;
8783     actual_drawing_function = GADGET_ID_PICK_ELEMENT;
8784   }
8785
8786   switch (actual_drawing_function)
8787   {
8788     case GADGET_ID_SINGLE_ITEMS:
8789       if (draw_level)
8790       {
8791         if (button_release_event)
8792         {
8793           CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8794
8795           if (edit_mode == ED_MODE_DRAWING && draw_with_brush &&
8796               !inside_drawing_area)
8797             DeleteBrushFromCursor();
8798         }
8799
8800         if (!button)
8801           break;
8802
8803         if (draw_with_brush)
8804         {
8805           if (!button_release_event)
8806             CopyBrushToLevel(sx, sy, button);
8807         }
8808         else if (new_element != Feld[lx][ly])
8809         {
8810           if (new_element == EL_PLAYER_1)
8811           {
8812             /* remove player at old position */
8813             for (y = 0; y < lev_fieldy; y++)
8814             {
8815               for (x = 0; x < lev_fieldx; x++)
8816               {
8817                 if (Feld[x][y] == EL_PLAYER_1)
8818                 {
8819                   Feld[x][y] = EL_EMPTY;
8820                   if (x - level_xpos >= 0 && x - level_xpos < ed_fieldx &&
8821                       y - level_ypos >= 0 && y - level_ypos < ed_fieldy)
8822                     DrawMiniElement(x - level_xpos, y - level_ypos,
8823                                     EL_EMPTY);
8824                 }
8825               }
8826             }
8827           }
8828
8829           Feld[lx][ly] = new_element;
8830           DrawMiniElement(sx, sy, new_element);
8831         }
8832       }
8833       else
8834       {
8835         int type_id = gi->custom_type_id;
8836         int pos = sx * drawingarea_info[type_id].area_ysize + sy;
8837
8838         if (item_xsize == MINI_TILEX && item_ysize == MINI_TILEY)
8839           DrawMiniGraphicExt(drawto,
8840                              gi->x + sx * MINI_TILEX,
8841                              gi->y + sy * MINI_TILEY,
8842                              el2edimg(new_element));
8843         else
8844           DrawGraphicExt(drawto,
8845                          gi->x + sx * TILEX,
8846                          gi->y + sy * TILEY,
8847                          el2img(new_element), 0);
8848
8849         if (id == GADGET_ID_CUSTOM_GRAPHIC)
8850           new_element = GFX_ELEMENT(new_element);
8851
8852         drawingarea_info[type_id].value[pos] = new_element;
8853
8854         CopyElementPropertiesToGame(properties_element);
8855
8856         if (id == GADGET_ID_CUSTOM_GRAPHIC)
8857         {
8858           UpdateCustomElementGraphicGadgets();
8859
8860           FrameCounter = 0;     /* restart animation frame counter */
8861         }
8862       }
8863       break;
8864
8865     case GADGET_ID_CONNECTED_ITEMS:
8866       {
8867         static int last_sx = -1;
8868         static int last_sy = -1;
8869
8870         if (button_release_event)
8871           CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8872
8873         if (button)
8874         {
8875           if (!button_press_event)
8876             DrawLine(last_sx, last_sy, sx, sy, new_element, TRUE);
8877
8878           last_sx = sx;
8879           last_sy = sy;
8880         }
8881       }
8882       break;
8883
8884     case GADGET_ID_LINE:
8885     case GADGET_ID_ARC:
8886     case GADGET_ID_RECTANGLE:
8887     case GADGET_ID_FILLED_BOX:
8888     case GADGET_ID_GRAB_BRUSH:
8889     case GADGET_ID_TEXT:
8890       {
8891         static int last_sx = -1;
8892         static int last_sy = -1;
8893         static int start_sx = -1;
8894         static int start_sy = -1;
8895         void (*draw_func)(int, int, int, int, int, boolean);
8896
8897         if (drawing_function == GADGET_ID_LINE)
8898           draw_func = DrawLine;
8899         else if (drawing_function == GADGET_ID_ARC)
8900           draw_func = DrawArc;
8901         else if (drawing_function == GADGET_ID_RECTANGLE)
8902           draw_func = DrawBox;
8903         else if (drawing_function == GADGET_ID_FILLED_BOX)
8904           draw_func = DrawFilledBox;
8905         else if (drawing_function == GADGET_ID_GRAB_BRUSH)
8906           draw_func = SelectArea;
8907         else /* (drawing_function == GADGET_ID_TEXT) */
8908           draw_func = SetTextCursor;
8909
8910         if (button_press_event)
8911         {
8912           draw_func(sx, sy, sx, sy, new_element, FALSE);
8913           start_sx = last_sx = sx;
8914           start_sy = last_sy = sy;
8915
8916           if (drawing_function == GADGET_ID_TEXT)
8917             DrawLevelText(0, 0, 0, TEXT_END);
8918         }
8919         else if (button_release_event)
8920         {
8921           draw_func(start_sx, start_sy, sx, sy, new_element, TRUE);
8922           if (drawing_function == GADGET_ID_GRAB_BRUSH)
8923           {
8924             CopyAreaToBrush(start_sx, start_sy, sx, sy, button);
8925             CopyBrushToCursor(sx, sy);
8926             ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
8927                           MB_LEFTBUTTON);
8928             draw_with_brush = TRUE;
8929           }
8930           else if (drawing_function == GADGET_ID_TEXT)
8931             DrawLevelText(sx, sy, 0, TEXT_INIT);
8932           else
8933             CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8934         }
8935         else if (last_sx != sx || last_sy != sy)
8936         {
8937           draw_func(start_sx, start_sy, last_sx, last_sy, -1, FALSE);
8938           draw_func(start_sx, start_sy, sx, sy, new_element, FALSE);
8939           last_sx = sx;
8940           last_sy = sy;
8941         }
8942       }
8943       break;
8944
8945     case GADGET_ID_FLOOD_FILL:
8946       if (button_press_event && Feld[lx][ly] != new_element)
8947       {
8948         FloodFill(lx, ly, new_element);
8949         DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8950         CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8951       }
8952       break;
8953
8954     case GADGET_ID_PICK_ELEMENT:
8955       if (button_release_event)
8956         ClickOnGadget(level_editor_gadget[last_drawing_function],
8957                       MB_LEFTBUTTON);
8958       else if (draw_level)
8959         PickDrawingElement(button, Feld[lx][ly]);
8960       else
8961       {
8962         int type_id = gi->custom_type_id;
8963         int pos = sx * drawingarea_info[type_id].area_ysize + sy;
8964
8965         PickDrawingElement(button, drawingarea_info[type_id].value[pos]);
8966       }
8967
8968       break;
8969
8970     default:
8971       break;
8972   }
8973 }
8974
8975 static void HandleCounterButtons(struct GadgetInfo *gi)
8976 {
8977   int gadget_id = gi->custom_id;
8978   int counter_id = gi->custom_type_id;
8979   int button = gi->event.button;
8980   int *counter_value = counterbutton_info[counter_id].value;
8981   int step = BUTTON_STEPSIZE(button) *
8982     (gadget_id == counterbutton_info[counter_id].gadget_id_down ? -1 : +1);
8983
8984   if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
8985   {
8986     boolean pressed = (gi->event.type == GD_EVENT_PRESSED);
8987     boolean released = (gi->event.type == GD_EVENT_RELEASED);
8988     boolean level_changed = LevelChanged();
8989
8990     if ((level_changed && pressed) || (!level_changed && released))
8991       return;
8992
8993     if (level_changed && !Request("Level has changed ! Discard changes ?",
8994                                   REQ_ASK))
8995     {
8996       if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
8997         ModifyEditorCounterValue(counter_id, *counter_value);
8998
8999       return;
9000     }
9001   }
9002
9003   if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
9004     *counter_value = gi->textinput.number_value;
9005   else
9006     ModifyEditorCounterValue(counter_id, *counter_value + step);
9007
9008   if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
9009   {
9010       LoadLevel(level_nr);
9011       TapeErase();
9012       ResetUndoBuffer();
9013       DrawEditModeWindow();
9014
9015       return;
9016   }
9017
9018   switch (counter_id)
9019   {
9020     case ED_COUNTER_ID_YAMYAM_CONTENT:
9021       DrawYamYamContentAreas();
9022       break;
9023
9024     case ED_COUNTER_ID_BALL_CONTENT:
9025       DrawMagicBallContentAreas();
9026       break;
9027
9028     case ED_COUNTER_ID_GROUP_CONTENT:
9029       DrawGroupElementArea(properties_element);
9030       CopyGroupElementPropertiesToGame(properties_element);
9031       break;
9032
9033     case ED_COUNTER_ID_ENVELOPE_XSIZE:
9034     case ED_COUNTER_ID_ENVELOPE_YSIZE:
9035       DrawEnvelopeTextArea(-1);
9036       break;
9037
9038     case ED_COUNTER_ID_LEVEL_XSIZE:
9039     case ED_COUNTER_ID_LEVEL_YSIZE:
9040       lev_fieldx = level.fieldx;
9041       lev_fieldy = level.fieldy;
9042       break;
9043
9044     default:
9045       break;
9046   }
9047
9048   if ((counter_id >= ED_COUNTER_ID_CUSTOM_FIRST &&
9049        counter_id <= ED_COUNTER_ID_CUSTOM_LAST) ||
9050       (counter_id >= ED_COUNTER_ID_CHANGE_FIRST &&
9051        counter_id <= ED_COUNTER_ID_CHANGE_LAST))
9052     CopyElementPropertiesToGame(properties_element);
9053
9054   level.changed = TRUE;
9055 }
9056
9057 static void HandleTextInputGadgets(struct GadgetInfo *gi)
9058 {
9059   int type_id = gi->custom_type_id;
9060
9061   strcpy(textinput_info[type_id].value, gi->textinput.value);
9062
9063   if (type_id == ED_TEXTINPUT_ID_ELEMENT_NAME)
9064   {
9065     CopyElementPropertiesToGame(properties_element);
9066
9067     ModifyEditorElementList();  /* update changed button info text */
9068   }
9069
9070   level.changed = TRUE;
9071 }
9072
9073 static void HandleTextAreaGadgets(struct GadgetInfo *gi)
9074 {
9075   int type_id = gi->custom_type_id;
9076
9077   strcpy(textarea_info[type_id].value, gi->textarea.value);
9078
9079   level.changed = TRUE;
9080 }
9081
9082 static void HandleSelectboxGadgets(struct GadgetInfo *gi)
9083 {
9084   int type_id = gi->custom_type_id;
9085   int value_old = *selectbox_info[type_id].value;
9086   int value_new = selectbox_info[type_id].options[gi->selectbox.index].value;
9087
9088   *selectbox_info[type_id].value = value_new;
9089
9090   if (type_id == ED_SELECTBOX_ID_SELECT_CHANGE_PAGE)
9091   {
9092     element_info[properties_element].current_change_page = gi->selectbox.index;
9093
9094     DrawPropertiesWindow();
9095   }
9096   else if ((type_id >= ED_SELECTBOX_ID_CUSTOM_FIRST &&
9097             type_id <= ED_SELECTBOX_ID_CUSTOM_LAST) ||
9098            (type_id >= ED_SELECTBOX_ID_CHANGE_FIRST &&
9099             type_id <= ED_SELECTBOX_ID_CHANGE_LAST) ||
9100            (type_id == ED_SELECTBOX_ID_GROUP_CHOICE_MODE))
9101   {
9102     if (type_id == ED_SELECTBOX_ID_ACTION_TYPE)
9103     {
9104       /* when changing action type, reset action mode and action arg */
9105       if (value_old != value_new)
9106       {
9107         custom_element_change.action_mode = -1;
9108         custom_element_change.action_arg = -1;
9109       }
9110
9111       DrawPropertiesChange();
9112     }
9113
9114     CopyElementPropertiesToGame(properties_element);
9115
9116     level.changed = TRUE;
9117   }
9118 }
9119
9120 static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
9121 {
9122   int type_id = gi->custom_type_id;
9123   int i;
9124
9125   if (type_id >= ED_TEXTBUTTON_ID_PROPERTIES_FIRST &&
9126       type_id <= ED_TEXTBUTTON_ID_PROPERTIES_LAST)
9127   {
9128     edit_mode_properties = gi->custom_type_id;
9129
9130     DrawPropertiesWindow();
9131   }
9132   else if (type_id == ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE)
9133   {
9134     char *template_filename = getDefaultLevelFilename(-1);
9135     boolean new_template = !fileExists(template_filename);
9136
9137     if (new_template ||
9138         Request("Save this template and kill the old ?", REQ_ASK))
9139       SaveLevelTemplate();
9140
9141     if (new_template)
9142       Request("Template saved !", REQ_CONFIRM);
9143   }
9144   else if (type_id == ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE &&
9145            custom_element.num_change_pages < MAX_CHANGE_PAGES)
9146   {
9147     struct ElementInfo *ei = &element_info[properties_element];
9148
9149     setElementChangePages(ei, ei->num_change_pages + 1);
9150
9151     /* set new change page to be new current change page */
9152     ei->current_change_page = ei->num_change_pages - 1;
9153     ei->change = &ei->change_page[ei->current_change_page];
9154
9155     setElementChangeInfoToDefaults(ei->change);
9156
9157     DrawPropertiesWindow();
9158
9159     level.changed = TRUE;
9160   }
9161   else if (type_id == ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE &&
9162            custom_element.num_change_pages > MIN_CHANGE_PAGES)
9163   {
9164     struct ElementInfo *ei = &element_info[properties_element];
9165
9166     /* copy all change pages after change page to be deleted */
9167     for (i = ei->current_change_page; i < ei->num_change_pages - 1; i++)
9168       ei->change_page[i] = ei->change_page[i + 1];
9169
9170     setElementChangePages(ei, ei->num_change_pages - 1);
9171
9172     DrawPropertiesWindow();
9173
9174     level.changed = TRUE;
9175   }
9176 }
9177
9178 static void HandleGraphicbuttonGadgets(struct GadgetInfo *gi)
9179 {
9180   int type_id = gi->custom_type_id;
9181
9182   if (type_id == ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE ||
9183       type_id == ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE)
9184   {
9185     struct ElementInfo *ei = &element_info[properties_element];
9186     int step = BUTTON_STEPSIZE(gi->event.button);
9187
9188     step *= (type_id == ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE ? -1 : +1);
9189     ei->current_change_page += step;
9190
9191     if (ei->current_change_page < 0)
9192       ei->current_change_page = 0;
9193     else if (ei->current_change_page >= ei->num_change_pages)
9194       ei->current_change_page = ei->num_change_pages - 1;
9195
9196     DrawPropertiesWindow();
9197   }
9198   else if (type_id == ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE ||
9199            type_id == ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE)
9200   {
9201     struct ElementInfo *ei = &element_info[properties_element];
9202     int current_change_page = ei->current_change_page;
9203
9204     if (type_id == ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE)
9205       element_info[EL_INTERNAL_CLIPBOARD_CHANGE].change_page[0] =
9206         ei->change_page[current_change_page];
9207     else if (type_id == ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE)
9208     {
9209       ei->change_page[current_change_page] =
9210         element_info[EL_INTERNAL_CLIPBOARD_CHANGE].change_page[0];
9211
9212       level.changed = TRUE;
9213     }
9214
9215     DrawPropertiesWindow();
9216   }
9217 }
9218
9219 static void HandleRadiobuttons(struct GadgetInfo *gi)
9220 {
9221   *radiobutton_info[gi->custom_type_id].value =
9222     radiobutton_info[gi->custom_type_id].checked_value;
9223
9224   level.changed = TRUE;
9225 }
9226
9227 static void HandleCheckbuttons(struct GadgetInfo *gi)
9228 {
9229   int type_id = gi->custom_type_id;
9230
9231   *checkbutton_info[type_id].value ^= TRUE;
9232
9233   if (type_id == ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID ||
9234       type_id == ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID ||
9235       type_id == ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH ||
9236       (((type_id >= ED_CHECKBUTTON_ID_CUSTOM_FIRST &&
9237          type_id <= ED_CHECKBUTTON_ID_CUSTOM_LAST) ||
9238         (type_id >= ED_CHECKBUTTON_ID_CHANGE_FIRST &&
9239          type_id <= ED_CHECKBUTTON_ID_CHANGE_LAST)) &&
9240        type_id != ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE))
9241   {
9242     CopyElementPropertiesToGame(properties_element);
9243   }
9244
9245   if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC)
9246   {
9247     UpdateCustomElementGraphicGadgets();
9248   }
9249   else if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE)
9250   {
9251     char *template_filename = getDefaultLevelFilename(-1);
9252
9253     if (level.use_custom_template && !fileExists(template_filename))
9254     {
9255       Request("No level template found !", REQ_CONFIRM);
9256
9257       level.use_custom_template = FALSE;
9258       ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
9259
9260       return;
9261     }
9262
9263     LoadLevelTemplate(level.use_custom_template ? -1 : level_nr);
9264
9265     DrawEditModeWindow();
9266   }
9267
9268   level.changed = TRUE;
9269 }
9270
9271 static void HandleControlButtons(struct GadgetInfo *gi)
9272 {
9273   static int last_level_drawing_function = GADGET_ID_SINGLE_ITEMS;
9274   static int last_edit_mode = ED_MODE_DRAWING;
9275   static int last_custom_copy_mode = -1;
9276   int id = gi->custom_id;
9277   int button = gi->event.button;
9278   int step = BUTTON_STEPSIZE(button);
9279   int new_element = BUTTON_ELEMENT(button);
9280   int x, y;
9281
9282 #if 0
9283   /* MAKES PROBLEMS WITH ELEMENT LIST SCROLLBAR AND IS PROBABLY NOT NEEDED */
9284   /* !!! CHECK WHAT HAPPENS WHEN MOUSE WHEEL IS USED OVER ELEMENT LIST !!! */
9285
9286   if (!IS_VALID_BUTTON(button))
9287     return;
9288 #endif
9289
9290   if (edit_mode == ED_MODE_DRAWING && drawing_function == GADGET_ID_TEXT)
9291     DrawLevelText(0, 0, 0, TEXT_END);
9292
9293   if (id < ED_NUM_CTRL1_BUTTONS &&
9294       id != GADGET_ID_SINGLE_ITEMS &&
9295       id != GADGET_ID_PROPERTIES &&
9296       id != GADGET_ID_PICK_ELEMENT &&
9297       edit_mode != ED_MODE_DRAWING &&
9298       drawing_function != GADGET_ID_PICK_ELEMENT &&
9299       !(GetKeyModState() & KMOD_Control))
9300   {
9301     DrawDrawingWindow();
9302     edit_mode = ED_MODE_DRAWING;
9303   }
9304
9305   /* element copy mode active, but no element button pressed => deactivate */
9306   if (last_custom_copy_mode != -1 && id < ED_NUM_CTRL_BUTTONS)
9307     last_custom_copy_mode = -1;
9308
9309   switch (id)
9310   {
9311     case GADGET_ID_SCROLL_LEFT:
9312       if (level_xpos >= 0)
9313       {
9314         if (lev_fieldx < ed_fieldx - 2)
9315           break;
9316
9317         level_xpos -= step;
9318         if (level_xpos < -1)
9319           level_xpos = -1;
9320         if (button == 1)
9321           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT);
9322         else
9323           DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
9324
9325         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
9326                      GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
9327       }
9328       break;
9329
9330     case GADGET_ID_SCROLL_RIGHT:
9331       if (level_xpos <= lev_fieldx - ed_fieldx)
9332       {
9333         if (lev_fieldx < ed_fieldx - 2)
9334           break;
9335
9336         level_xpos += step;
9337         if (level_xpos > lev_fieldx - ed_fieldx + 1)
9338           level_xpos = lev_fieldx - ed_fieldx + 1;
9339         if (button == 1)
9340           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT);
9341         else
9342           DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
9343
9344         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
9345                      GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
9346       }
9347       break;
9348
9349     case GADGET_ID_SCROLL_UP:
9350       if (level_ypos >= 0)
9351       {
9352         if (lev_fieldy < ed_fieldy - 2)
9353           break;
9354
9355         level_ypos -= step;
9356         if (level_ypos < -1)
9357           level_ypos = -1;
9358         if (button == 1)
9359           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN);
9360         else
9361           DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
9362
9363         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
9364                      GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
9365       }
9366       break;
9367
9368     case GADGET_ID_SCROLL_DOWN:
9369       if (level_ypos <= lev_fieldy - ed_fieldy)
9370       {
9371         if (lev_fieldy < ed_fieldy - 2)
9372           break;
9373
9374         level_ypos += step;
9375         if (level_ypos > lev_fieldy - ed_fieldy + 1)
9376           level_ypos = lev_fieldy - ed_fieldy + 1;
9377         if (button == 1)
9378           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP);
9379         else
9380           DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
9381
9382         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
9383                      GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
9384       }
9385       break;
9386
9387     case GADGET_ID_SCROLL_HORIZONTAL:
9388       level_xpos = gi->event.item_position - 1;
9389       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
9390       break;
9391
9392     case GADGET_ID_SCROLL_VERTICAL:
9393       level_ypos = gi->event.item_position - 1;
9394       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
9395       break;
9396
9397     case GADGET_ID_SCROLL_LIST_UP:
9398     case GADGET_ID_SCROLL_LIST_DOWN:
9399     case GADGET_ID_SCROLL_LIST_VERTICAL:
9400       if (id == GADGET_ID_SCROLL_LIST_VERTICAL)
9401         element_shift = gi->event.item_position * ED_ELEMENTLIST_BUTTONS_HORIZ;
9402       else
9403       {
9404         step *= (id == GADGET_ID_SCROLL_LIST_UP ? -1 : +1);
9405         element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ;
9406
9407         if (element_shift < 0)
9408           element_shift = 0;
9409         if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
9410           element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
9411
9412         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
9413                      GDI_SCROLLBAR_ITEM_POSITION,
9414                      element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
9415       }
9416
9417       ModifyEditorElementList();
9418
9419       break;
9420
9421     case GADGET_ID_WRAP_LEFT:
9422       WrapLevel(-step, 0);
9423       break;
9424
9425     case GADGET_ID_WRAP_RIGHT:
9426       WrapLevel(step, 0);
9427       break;
9428
9429     case GADGET_ID_WRAP_UP:
9430       WrapLevel(0, -step);
9431       break;
9432
9433     case GADGET_ID_WRAP_DOWN:
9434       WrapLevel(0, step);
9435       break;
9436
9437     case GADGET_ID_SINGLE_ITEMS:
9438     case GADGET_ID_CONNECTED_ITEMS:
9439     case GADGET_ID_LINE:
9440     case GADGET_ID_ARC:
9441     case GADGET_ID_TEXT:
9442     case GADGET_ID_RECTANGLE:
9443     case GADGET_ID_FILLED_BOX:
9444     case GADGET_ID_FLOOD_FILL:
9445     case GADGET_ID_GRAB_BRUSH:
9446     case GADGET_ID_PICK_ELEMENT:
9447       if (drawing_function != GADGET_ID_PICK_ELEMENT)
9448         last_drawing_function = drawing_function;
9449       drawing_function = id;
9450       draw_with_brush = FALSE;
9451       break;
9452
9453     case GADGET_ID_RANDOM_PLACEMENT:
9454       RandomPlacement(new_element);
9455       break;
9456
9457     case GADGET_ID_PROPERTIES:
9458       if (edit_mode != ED_MODE_PROPERTIES)
9459       {
9460         properties_element = new_element;
9461         DrawPropertiesWindow();
9462         edit_mode = ED_MODE_PROPERTIES;
9463
9464         last_level_drawing_function = drawing_function;
9465         ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
9466                       MB_LEFTBUTTON);
9467       }
9468       else
9469       {
9470         DrawDrawingWindow();
9471         edit_mode = ED_MODE_DRAWING;
9472
9473         ClickOnGadget(level_editor_gadget[last_level_drawing_function],
9474                       MB_LEFTBUTTON);
9475       }
9476       break;
9477
9478     case GADGET_ID_CUSTOM_COPY_FROM:
9479     case GADGET_ID_CUSTOM_COPY_TO:
9480     case GADGET_ID_CUSTOM_EXCHANGE:
9481       last_custom_copy_mode = id;
9482       last_drawing_function = drawing_function;
9483       break;
9484
9485     case GADGET_ID_CUSTOM_COPY:
9486       CopyCustomElement(properties_element, -1, id);
9487       break;
9488
9489     case GADGET_ID_CUSTOM_PASTE:
9490       CopyCustomElement(-1, properties_element, id);
9491       break;
9492
9493     case GADGET_ID_UNDO:
9494       if (undo_buffer_steps == 0)
9495       {
9496         Request("Undo buffer empty !", REQ_CONFIRM);
9497         break;
9498       }
9499
9500       if (edit_mode != ED_MODE_DRAWING)
9501       {
9502         DrawDrawingWindow();
9503         edit_mode = ED_MODE_DRAWING;
9504       }
9505
9506       undo_buffer_position =
9507         (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS;
9508       undo_buffer_steps--;
9509
9510       for (x = 0; x < lev_fieldx; x++)
9511         for (y = 0; y < lev_fieldy; y++)
9512           Feld[x][y] = UndoBuffer[undo_buffer_position][x][y];
9513       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos,level_ypos);
9514       break;
9515
9516     case GADGET_ID_INFO:
9517       if (edit_mode != ED_MODE_INFO)
9518       {
9519         last_edit_mode = edit_mode;
9520         edit_mode = ED_MODE_INFO;
9521
9522         DrawLevelInfoWindow();
9523       }
9524       else
9525       {
9526         edit_mode = last_edit_mode;
9527
9528         DrawEditModeWindow();
9529       }
9530       break;
9531
9532     case GADGET_ID_CLEAR:
9533       if (edit_mode != ED_MODE_DRAWING)
9534       {
9535         DrawDrawingWindow();
9536         edit_mode = ED_MODE_DRAWING;
9537       }
9538
9539       for (x = 0; x < MAX_LEV_FIELDX; x++) 
9540         for (y = 0; y < MAX_LEV_FIELDY; y++) 
9541           Feld[x][y] = (button == 1 ? EL_EMPTY : new_element);
9542
9543       CopyLevelToUndoBuffer(GADGET_ID_CLEAR);
9544
9545       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
9546       break;
9547
9548     case GADGET_ID_SAVE:
9549       if (leveldir_current->readonly)
9550       {
9551         Request("This level is read only !", REQ_CONFIRM);
9552         break;
9553       }
9554
9555       if (!LevelContainsPlayer())
9556         Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM);
9557       else
9558       {
9559         char *level_filename = getDefaultLevelFilename(level_nr);
9560         boolean new_level = !fileExists(level_filename);
9561
9562         if (new_level ||
9563             Request("Save this level and kill the old ?", REQ_ASK))
9564         {
9565           CopyPlayfield(Feld, level.field);
9566
9567           SaveLevel(level_nr);
9568         }
9569
9570         if (new_level)
9571           Request("Level saved !", REQ_CONFIRM);
9572
9573         level.changed = FALSE;
9574       }
9575       break;
9576
9577     case GADGET_ID_TEST:
9578       if (!LevelContainsPlayer())
9579         Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM);
9580       else
9581       {
9582         if (LevelChanged())
9583           level.game_version = GAME_VERSION_ACTUAL;
9584
9585         CopyPlayfield(level.field, FieldBackup);
9586         CopyPlayfield(Feld, level.field);
9587
9588         CopyNativeLevel_RND_to_Native(&level);
9589
9590         UnmapLevelEditorGadgets();
9591         UndrawSpecialEditorDoor();
9592
9593         CloseDoor(DOOR_CLOSE_ALL);
9594
9595         DrawCompleteVideoDisplay();
9596
9597         level_editor_test_game = TRUE;
9598
9599         StartGameActions(FALSE, setup.autorecord, NEW_RANDOMIZE);
9600       }
9601       break;
9602
9603     case GADGET_ID_EXIT:
9604       RequestExitLevelEditor(TRUE);     /* if level has changed, ask user */
9605       break;
9606
9607     default:
9608       if (id >= GADGET_ID_ELEMENTLIST_FIRST &&
9609           id <= GADGET_ID_ELEMENTLIST_LAST)
9610       {
9611         int element_position = id - GADGET_ID_ELEMENTLIST_FIRST;
9612         int new_element = editor_elements[element_position + element_shift];
9613
9614         if (IS_EDITOR_CASCADE(new_element))
9615         {
9616           int i;
9617
9618           for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
9619           {
9620             int *cascade_element= &(*editor_elements_info[i].headline_list)[0];
9621             boolean *cascade_value=editor_elements_info[i].setup_cascade_value;
9622
9623             if (*cascade_element == new_element)
9624             {
9625               *cascade_element = EL_CASCADE_TOGGLE(*cascade_element);
9626               *cascade_value = IS_EDITOR_CASCADE_ACTIVE(*cascade_element);
9627
9628               /* update element selection list */
9629               ReinitializeElementList();
9630               ModifyEditorElementList();
9631
9632               /* update cascading gadget info text */
9633               PrintEditorGadgetInfoText(level_editor_gadget[id]);
9634
9635               /* save current editor cascading state */
9636               SaveSetup_EditorCascade();
9637
9638               break;
9639             }
9640           }
9641
9642           break;
9643         }
9644
9645         if (last_custom_copy_mode != -1)
9646         {
9647           if (CopyCustomElement(properties_element, new_element,
9648                                 last_custom_copy_mode))
9649           {
9650             ClickOnGadget(level_editor_gadget[last_drawing_function],
9651                           MB_LEFTBUTTON);
9652
9653             last_custom_copy_mode = -1;
9654           }
9655
9656           break;
9657         }
9658
9659         PickDrawingElement(button, new_element);
9660
9661         if (!stick_element_properties_window &&
9662             drawing_function != GADGET_ID_PICK_ELEMENT &&
9663             !(GetKeyModState() & KMOD_Control))
9664         {
9665           properties_element = new_element;
9666           if (edit_mode == ED_MODE_PROPERTIES)
9667             DrawPropertiesWindow();
9668         }
9669
9670         if (drawing_function == GADGET_ID_PICK_ELEMENT)
9671           ClickOnGadget(level_editor_gadget[last_drawing_function],
9672                         MB_LEFTBUTTON);
9673       }
9674 #ifdef DEBUG
9675       else if (gi->event.type == GD_EVENT_PRESSED)
9676         printf("default: HandleControlButtons: GD_EVENT_PRESSED(%d)\n", id);
9677       else if (gi->event.type == GD_EVENT_RELEASED)
9678         printf("default: HandleControlButtons: GD_EVENT_RELEASED(%d)\n", id);
9679       else if (gi->event.type == GD_EVENT_MOVING)
9680         printf("default: HandleControlButtons: GD_EVENT_MOVING(%d)\n", id);
9681       else
9682         printf("default: HandleControlButtons: ? (id == %d)\n", id);
9683 #endif
9684       break;
9685   }
9686 }
9687
9688 void HandleLevelEditorKeyInput(Key key)
9689 {
9690   char letter = getCharFromKey(key);
9691   int button = MB_LEFTBUTTON;
9692
9693   if (drawing_function == GADGET_ID_TEXT &&
9694       DrawLevelText(0, 0, 0, TEXT_QUERY_TYPING) == TRUE)
9695   {
9696     if (letter)
9697       DrawLevelText(0, 0, letter, TEXT_WRITECHAR);
9698     else if (key == KSYM_Delete || key == KSYM_BackSpace)
9699       DrawLevelText(0, 0, 0, TEXT_BACKSPACE);
9700     else if (key == KSYM_Return)
9701       DrawLevelText(0, 0, 0, TEXT_NEWLINE);
9702     else if (key == KSYM_Escape)
9703       DrawLevelText(0, 0, 0, TEXT_END);
9704   }
9705   else if (button_status == MB_RELEASED)
9706   {
9707     int i, id = GADGET_ID_NONE;
9708
9709     switch (key)
9710     {
9711       case KSYM_Left:
9712         id = GADGET_ID_SCROLL_LEFT;
9713         break;
9714       case KSYM_Right:
9715         id = GADGET_ID_SCROLL_RIGHT;
9716         break;
9717       case KSYM_Up:
9718         id = GADGET_ID_SCROLL_UP;
9719         break;
9720       case KSYM_Down:
9721         id = GADGET_ID_SCROLL_DOWN;
9722         break;
9723       case KSYM_Page_Up:
9724         id = GADGET_ID_SCROLL_LIST_UP;
9725         button = MB_RIGHTBUTTON;
9726         break;
9727       case KSYM_Page_Down:
9728         id = GADGET_ID_SCROLL_LIST_DOWN;
9729         button = MB_RIGHTBUTTON;
9730         break;
9731
9732       case KSYM_Escape:
9733         if (edit_mode == ED_MODE_DRAWING)
9734         {
9735           RequestExitLevelEditor(setup.ask_on_escape);
9736         }
9737         else if (edit_mode == ED_MODE_INFO)
9738         {
9739           HandleControlButtons(level_editor_gadget[GADGET_ID_INFO]);
9740         }
9741         else if (edit_mode == ED_MODE_PROPERTIES)
9742         {
9743           HandleControlButtons(level_editor_gadget[GADGET_ID_PROPERTIES]);
9744         }
9745         else            /* should never happen */
9746         {
9747           DrawDrawingWindow();
9748           edit_mode = ED_MODE_DRAWING;
9749         }
9750         break;
9751
9752       default:
9753         break;
9754     }
9755
9756     if (id != GADGET_ID_NONE)
9757       ClickOnGadget(level_editor_gadget[id], button);
9758     else if (letter == '.')
9759       ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS], button);
9760     else if (key == KSYM_Return || key == setup.shortcut.toggle_pause)
9761       ClickOnGadget(level_editor_gadget[GADGET_ID_TEST], button);
9762     else
9763       for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
9764         if (letter && letter == control_info[i].shortcut)
9765           if (!anyTextGadgetActive())
9766             ClickOnGadget(level_editor_gadget[i], button);
9767   }
9768 }
9769
9770 void HandleLevelEditorIdle()
9771 {
9772   static unsigned long action_delay = 0;
9773   unsigned long action_delay_value = GameFrameDelay;
9774   int xpos = 1, ypos = 2;
9775
9776   if (edit_mode != ED_MODE_PROPERTIES)
9777     return;
9778
9779   if (!DelayReached(&action_delay, action_delay_value))
9780     return;
9781
9782   DrawGraphicAnimationExt(drawto,
9783                           SX + xpos * TILEX,
9784                           SY + ypos * TILEY + MINI_TILEY / 2,
9785                           el2img(properties_element), -1, NO_MASKING);
9786
9787   MarkTileDirty(xpos, ypos);
9788   MarkTileDirty(xpos, ypos + 1);
9789
9790   FrameCounter++;       /* increase animation frame counter */
9791 }
9792
9793 void ClearEditorGadgetInfoText()
9794 {
9795   DrawBackground(INFOTEXT_XPOS, INFOTEXT_YPOS, INFOTEXT_XSIZE, INFOTEXT_YSIZE);
9796 }
9797
9798 void PrintEditorGadgetInfoText(struct GadgetInfo *gi)
9799 {
9800   char infotext[MAX_OUTPUT_LINESIZE + 1];
9801   char shortcut[MAX_OUTPUT_LINESIZE + 1];
9802   int max_infotext_len = getMaxInfoTextLength();
9803
9804   if (gi == NULL || gi->info_text == NULL)
9805     return;
9806
9807   strncpy(infotext, gi->info_text, max_infotext_len);
9808   infotext[max_infotext_len] = '\0';
9809
9810   if (gi->custom_id < ED_NUM_CTRL_BUTTONS)
9811   {
9812     int key = control_info[gi->custom_id].shortcut;
9813
9814     if (key)
9815     {
9816       if (gi->custom_id == GADGET_ID_SINGLE_ITEMS)      /* special case 1 */
9817         sprintf(shortcut, " ('.' or '%c')", key);
9818       else if (gi->custom_id == GADGET_ID_PICK_ELEMENT) /* special case 2 */
9819         sprintf(shortcut, " ('%c' or 'Ctrl')", key);
9820       else if (gi->custom_id == GADGET_ID_TEST)         /* special case 3 */
9821         sprintf(shortcut, " ('Enter' or 'Shift-%c')", key);
9822       else                                              /* normal case */
9823         sprintf(shortcut, " ('%s%c')",
9824                 (key >= 'A' && key <= 'Z' ? "Shift-" : ""), key);
9825
9826       if (strlen(infotext) + strlen(shortcut) <= max_infotext_len)
9827         strcat(infotext, shortcut);
9828     }
9829   }
9830
9831   DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, FONT_TEXT_2);
9832 }
9833
9834 void HandleEditorGadgetInfoText(void *ptr)
9835 {
9836   struct GadgetInfo *gi = (struct GadgetInfo *)ptr;
9837 #if 0
9838   char infotext[MAX_OUTPUT_LINESIZE + 1];
9839   char shortcut[MAX_OUTPUT_LINESIZE + 1];
9840   int max_infotext_len = getMaxInfoTextLength();
9841 #endif
9842
9843   if (game_status != GAME_MODE_EDITOR)
9844     return;
9845
9846   ClearEditorGadgetInfoText();
9847
9848   if (gi == NULL || gi->event.type == GD_EVENT_INFO_LEAVING)
9849     return;
9850
9851   /* misuse this function to delete brush cursor, if needed */
9852   if (edit_mode == ED_MODE_DRAWING && draw_with_brush)
9853     DeleteBrushFromCursor();
9854
9855 #if 1
9856   PrintEditorGadgetInfoText(gi);
9857 #else
9858   if (gi == NULL || gi->info_text == NULL)
9859     return;
9860
9861   strncpy(infotext, gi->info_text, max_infotext_len);
9862   infotext[max_infotext_len] = '\0';
9863
9864   if (gi->custom_id < ED_NUM_CTRL_BUTTONS)
9865   {
9866     int key = control_info[gi->custom_id].shortcut;
9867
9868     if (key)
9869     {
9870       if (gi->custom_id == GADGET_ID_SINGLE_ITEMS)      /* special case 1 */
9871         sprintf(shortcut, " ('.' or '%c')", key);
9872       else if (gi->custom_id == GADGET_ID_PICK_ELEMENT) /* special case 2 */
9873         sprintf(shortcut, " ('%c' or 'Ctrl')", key);
9874       else if (gi->custom_id == GADGET_ID_TEST)         /* special case 3 */
9875         sprintf(shortcut, " ('Enter' or 'Shift-%c')", key);
9876       else                                              /* normal case */
9877         sprintf(shortcut, " ('%s%c')",
9878                 (key >= 'A' && key <= 'Z' ? "Shift-" : ""), key);
9879
9880       if (strlen(infotext) + strlen(shortcut) <= max_infotext_len)
9881         strcat(infotext, shortcut);
9882     }
9883   }
9884
9885   DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, FONT_TEXT_2);
9886 #endif
9887 }
9888
9889 static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
9890 {
9891   static int start_lx, start_ly;
9892   int id = gi->custom_id;
9893   int type_id = gi->custom_type_id;
9894   int sx = gi->event.x;
9895   int sy = gi->event.y;
9896   int lx = sx + level_xpos;
9897   int ly = sy + level_ypos;
9898   int min_sx = 0, min_sy = 0;
9899   int max_sx = gi->drawing.area_xsize - 1;
9900   int max_sy = gi->drawing.area_ysize - 1;
9901   int actual_drawing_function = drawing_function;
9902   int max_infotext_len = getMaxInfoTextLength();
9903   char infotext[MAX_OUTPUT_LINESIZE + 1];
9904   char *text;
9905
9906   infotext[0] = '\0';           /* start with empty info text */
9907
9908   /* pressed Control key: simulate picking element */
9909   if (GetKeyModState() & KMOD_Control)
9910     actual_drawing_function = GADGET_ID_PICK_ELEMENT;
9911
9912   ClearEditorGadgetInfoText();
9913
9914   if (gi->event.type == GD_EVENT_INFO_LEAVING)
9915     return;
9916
9917   /* make sure to stay inside drawing area boundaries */
9918   sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
9919   sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
9920
9921   if (id == GADGET_ID_DRAWING_LEVEL)
9922   {
9923     if (button_status)
9924     {
9925       int min_lx = 0, min_ly = 0;
9926       int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
9927
9928       /* get positions inside level field */
9929       lx = sx + level_xpos;
9930       ly = sy + level_ypos;
9931
9932       /* make sure to stay inside level field boundaries */
9933       lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
9934       ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
9935
9936       /* correct drawing area positions accordingly */
9937       sx = lx - level_xpos;
9938       sy = ly - level_ypos;
9939     }
9940
9941     if (IN_ED_FIELD(sx,sy) && IN_LEV_FIELD(lx, ly))
9942     {
9943       if (button_status)        /* if (gi->state == GD_BUTTON_PRESSED) */
9944       {
9945         if (gi->event.type == GD_EVENT_PRESSED)
9946         {
9947           start_lx = lx;
9948           start_ly = ly;
9949         }
9950
9951         switch (actual_drawing_function)
9952         {
9953           case GADGET_ID_SINGLE_ITEMS:
9954             text = "Drawing single items";
9955             break;
9956           case GADGET_ID_CONNECTED_ITEMS:
9957             text = "Drawing connected items";
9958             break;
9959           case GADGET_ID_LINE:
9960             text = "Drawing line";
9961             break;
9962           case GADGET_ID_ARC:
9963             text = "Drawing arc";
9964             break;
9965           case GADGET_ID_TEXT:
9966             text = "Setting text cursor";
9967             break;
9968           case GADGET_ID_RECTANGLE:
9969             text = "Drawing rectangle";
9970             break;
9971           case GADGET_ID_FILLED_BOX:
9972             text = "Drawing filled box";
9973             break;
9974           case GADGET_ID_FLOOD_FILL:
9975             text = "Flood fill";
9976             break;
9977           case GADGET_ID_GRAB_BRUSH:
9978             text = "Grabbing brush";
9979             break;
9980           case GADGET_ID_PICK_ELEMENT:
9981             text = "Picking element";
9982             break;
9983
9984           default:
9985             text = "Drawing position";
9986             break;
9987         }
9988
9989         if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
9990           sprintf(infotext, "%s: %d, %d", text, lx, ly);
9991         else
9992           sprintf(infotext, "%s: %d, %d", text,
9993                   ABS(lx - start_lx) + 1, ABS(ly - start_ly) + 1);
9994       }
9995       else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
9996         strncpy(infotext, getElementInfoText(Feld[lx][ly]), max_infotext_len);
9997       else
9998         sprintf(infotext, "Level position: %d, %d", lx, ly);
9999     }
10000
10001     /* misuse this function to draw brush cursor, if needed */
10002     if (edit_mode == ED_MODE_DRAWING && draw_with_brush && !button_status)
10003     {
10004       if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
10005         CopyBrushToCursor(sx, sy);
10006       else
10007         DeleteBrushFromCursor();
10008     }
10009   }
10010   else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
10011   {
10012     int pos = sx * drawingarea_info[type_id].area_ysize + sy;
10013     int element = drawingarea_info[type_id].value[pos];
10014
10015     strncpy(infotext, getElementInfoText(element), max_infotext_len);
10016   }
10017   else
10018   {
10019     if (id == GADGET_ID_CUSTOM_CONTENT)
10020       sprintf(infotext, "custom element content position: %d, %d", sx, sy);
10021     else if (id == GADGET_ID_GROUP_CONTENT)
10022       sprintf(infotext, "group element position: %d", sx + 1);
10023     else if (id >= GADGET_ID_YAMYAM_CONTENT_0 &&
10024              id <= GADGET_ID_YAMYAM_CONTENT_7)
10025       sprintf(infotext, "content area %d position: %d, %d",
10026               id - GADGET_ID_YAMYAM_CONTENT_0 + 1, sx, sy);
10027     else if (id >= GADGET_ID_MAGIC_BALL_CONTENT_0 &&
10028              id <= GADGET_ID_MAGIC_BALL_CONTENT_7)
10029       sprintf(infotext, "content area %d position: %d, %d",
10030               id - GADGET_ID_MAGIC_BALL_CONTENT_0 + 1, sx, sy);
10031     else if (drawingarea_info[type_id].infotext != NULL)
10032       strcpy(infotext, drawingarea_info[type_id].infotext);
10033   }
10034
10035   infotext[max_infotext_len] = '\0';
10036
10037   if (strlen(infotext) > 0)
10038     DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, infotext);
10039 }
10040
10041 void RequestExitLevelEditor(boolean ask_if_level_has_changed)
10042 {
10043   if (!ask_if_level_has_changed ||
10044       !LevelChanged() ||
10045       Request("Level has changed ! Exit without saving ?",
10046               REQ_ASK | REQ_STAY_OPEN))
10047   {
10048 #if 1
10049     CloseDoor(DOOR_CLOSE_1);
10050     SetDoorState(DOOR_CLOSE_2);
10051 #else
10052     CloseDoor(DOOR_CLOSE_ALL);
10053 #endif
10054     game_status = GAME_MODE_MAIN;
10055     DrawMainMenu();
10056   }
10057   else
10058   {
10059     CloseDoor(DOOR_CLOSE_1);
10060     OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
10061   }
10062 }