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