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