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