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