changed showing standard element properties for some engines in editor
[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 //                  https://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 // screen and artwork graphic pixel position definitions
30 // ----------------------------------------------------------------------------
31
32 // values for the control window
33 #define ED_CTRL1_BUTTONS_HORIZ          4       // toolbox
34 #define ED_CTRL1_BUTTONS_VERT           4
35 #define ED_CTRL2_BUTTONS_HORIZ          3       // level
36 #define ED_CTRL2_BUTTONS_VERT           2
37 #define ED_CTRL3_BUTTONS_HORIZ          3       // CE and GE
38 #define ED_CTRL3_BUTTONS_VERT           1
39 #define ED_CTRL4_BUTTONS_HORIZ          2       // CE and GE
40 #define ED_CTRL4_BUTTONS_VERT           1
41 #define ED_CTRL5_BUTTONS_HORIZ          1       // properties
42 #define ED_CTRL5_BUTTONS_VERT           1
43 #define ED_CTRL6_BUTTONS_HORIZ          3       // properties
44 #define ED_CTRL6_BUTTONS_VERT           1
45 #define ED_CTRL7_BUTTONS_HORIZ          1       // palette
46 #define ED_CTRL7_BUTTONS_VERT           1
47
48 #define ED_NUM_CTRL1_BUTTONS   (ED_CTRL1_BUTTONS_HORIZ * ED_CTRL1_BUTTONS_VERT)
49 #define ED_NUM_CTRL2_BUTTONS   (ED_CTRL2_BUTTONS_HORIZ * ED_CTRL2_BUTTONS_VERT)
50 #define ED_NUM_CTRL3_BUTTONS   (ED_CTRL3_BUTTONS_HORIZ * ED_CTRL3_BUTTONS_VERT)
51 #define ED_NUM_CTRL4_BUTTONS   (ED_CTRL4_BUTTONS_HORIZ * ED_CTRL4_BUTTONS_VERT)
52 #define ED_NUM_CTRL5_BUTTONS   (ED_CTRL5_BUTTONS_HORIZ * ED_CTRL5_BUTTONS_VERT)
53 #define ED_NUM_CTRL6_BUTTONS   (ED_CTRL6_BUTTONS_HORIZ * ED_CTRL6_BUTTONS_VERT)
54 #define ED_NUM_CTRL7_BUTTONS   (ED_CTRL7_BUTTONS_HORIZ * ED_CTRL7_BUTTONS_VERT)
55 #define ED_NUM_CTRL1_2_BUTTONS (ED_NUM_CTRL1_BUTTONS   + ED_NUM_CTRL2_BUTTONS)
56 #define ED_NUM_CTRL1_3_BUTTONS (ED_NUM_CTRL1_2_BUTTONS + ED_NUM_CTRL3_BUTTONS)
57 #define ED_NUM_CTRL1_4_BUTTONS (ED_NUM_CTRL1_3_BUTTONS + ED_NUM_CTRL4_BUTTONS)
58 #define ED_NUM_CTRL1_5_BUTTONS (ED_NUM_CTRL1_4_BUTTONS + ED_NUM_CTRL5_BUTTONS)
59 #define ED_NUM_CTRL1_6_BUTTONS (ED_NUM_CTRL1_5_BUTTONS + ED_NUM_CTRL6_BUTTONS)
60 #define ED_NUM_CTRL1_7_BUTTONS (ED_NUM_CTRL1_6_BUTTONS + ED_NUM_CTRL7_BUTTONS)
61 #define ED_NUM_CTRL_BUTTONS    ED_NUM_CTRL1_7_BUTTONS
62
63 // values for the element list
64 #define ED_ELEMENTLIST_XPOS             (editor.palette.x)
65 #define ED_ELEMENTLIST_YPOS             (editor.palette.y)
66 #define ED_ELEMENTLIST_XSIZE            (graphic_info[IMG_EDITOR_PALETTE_BUTTON].width)
67 #define ED_ELEMENTLIST_YSIZE            (graphic_info[IMG_EDITOR_PALETTE_BUTTON].height)
68 #define ED_ELEMENTLIST_COLS             MAX(1, editor.palette.cols)
69 #define ED_ELEMENTLIST_ROWS             MAX(1, editor.palette.rows)
70 #define ED_ELEMENTLIST_BUTTONS_HORIZ    (ED_ELEMENTLIST_COLS)
71 #define ED_ELEMENTLIST_BUTTONS_VERT     (ED_ELEMENTLIST_ROWS)
72 #define ED_NUM_ELEMENTLIST_BUTTONS      (ED_ELEMENTLIST_BUTTONS_HORIZ * \
73                                          ED_ELEMENTLIST_BUTTONS_VERT)
74
75 // standard distances
76 #define ED_GADGET_NORMAL_DISTANCE       (editor.gadget.normal_spacing)
77 #define ED_GADGET_SMALL_DISTANCE        (editor.gadget.small_spacing)
78 #define ED_GADGET_TINY_DISTANCE         (editor.gadget.tiny_spacing)
79 #define ED_GADGET_LINE_DISTANCE         (editor.gadget.line_spacing)
80 #define ED_GADGET_TEXT_DISTANCE         (editor.gadget.text_spacing)
81 #define ED_TAB_BAR_HEIGHT               (editor.gadget.separator_line.height)
82 #define ED_DRAWINGAREA_TEXT_DISTANCE    (ED_GADGET_TEXT_DISTANCE +      \
83                                          ED_DRAWINGAREA_BORDER_SIZE)
84 #define ED_GADGET_SPACE_DISTANCE        (getFontWidth(FONT_TEXT_1))
85
86 // values for drawingarea gadgets
87 #define IMG_BORDER_1                    IMG_EDITOR_ELEMENT_BORDER
88 #define IMG_BORDER_2                    IMG_EDITOR_ELEMENT_BORDER_INPUT
89 #define ED_ELEMENT_BORDER               (graphic_info[IMG_BORDER_1].border_size)
90 #define ED_DRAWINGAREA_BORDER_SIZE      (graphic_info[IMG_BORDER_2].border_size)
91 #define ED_DRAWINGAREA_TILE_SIZE        (editor.drawingarea.tile_size)
92
93 // values for checkbutton gadgets
94 #define ED_CHECKBUTTON_XSIZE         (graphic_info[IMG_EDITOR_CHECKBOX].width)
95 #define ED_CHECKBUTTON_YSIZE         (graphic_info[IMG_EDITOR_CHECKBOX].height)
96
97 #define ED_TABBUTTON_XSIZE           (graphic_info[IMG_EDITOR_TABBUTTON].width)
98 #define ED_TABBUTTON_YSIZE           (graphic_info[IMG_EDITOR_TABBUTTON].height)
99
100 #define ED_SETTINGS_LEVEL_TABS_X        (editor.settings.tabs.x)
101 #define ED_SETTINGS_LEVEL_TABS_Y        (editor.settings.tabs.y)
102 #define ED_SETTINGS_ENGINE_TABS_X       (editor.settings.tabs.x)
103 #define ED_SETTINGS_ENGINE_TABS_Y       (editor.settings.tabs.y +       \
104                                          ED_TABBUTTON_YSIZE +           \
105                                          ED_GADGET_TINY_DISTANCE +      \
106                                          ED_TAB_BAR_HEIGHT +            \
107                                          ED_GADGET_TEXT_DISTANCE)
108 #define ED_SETTINGS_ELEMENT_TABS_X      (editor.settings.tabs.x)
109 #define ED_SETTINGS_ELEMENT_TABS_Y      (editor.settings.tabs.y +       \
110                                          editor.settings.tabs.yoffset2)
111
112 #define ED_SETTINGS_TABS_XOFFSET        (editor.settings.tabs.draw_xoffset)
113 #define ED_SETTINGS_TABS_YOFFSET        (editor.settings.tabs.draw_yoffset)
114
115 #define ED_LEVEL_TABS_XSTART            (ED_SETTINGS_LEVEL_TABS_X)
116 #define ED_LEVEL_TABS_YSTART            (ED_SETTINGS_LEVEL_TABS_Y)
117 #define ED_LEVEL_SETTINGS_XSTART        (ED_SETTINGS_LEVEL_TABS_X +     \
118                                          ED_SETTINGS_TABS_XOFFSET)
119 #define ED_LEVEL_SETTINGS_YSTART        (ED_SETTINGS_LEVEL_TABS_Y +     \
120                                          ED_TABBUTTON_YSIZE +           \
121                                          ED_GADGET_TINY_DISTANCE +      \
122                                          ED_TAB_BAR_HEIGHT +            \
123                                          ED_SETTINGS_TABS_YOFFSET +     \
124                                          getFontHeight(FONT_TEXT_1) +   \
125                                          ED_GADGET_TEXT_DISTANCE)
126 #define ED_ENGINE_TABS_XSTART           (ED_SETTINGS_ENGINE_TABS_X)
127 #define ED_ENGINE_TABS_YSTART           (ED_SETTINGS_ENGINE_TABS_Y)
128 #define ED_ENGINE_SETTINGS_XSTART       (ED_SETTINGS_ENGINE_TABS_X +    \
129                                          ED_SETTINGS_TABS_XOFFSET)
130 #define ED_ENGINE_SETTINGS_YSTART       (ED_SETTINGS_ENGINE_TABS_Y +    \
131                                          ED_TABBUTTON_YSIZE +           \
132                                          ED_GADGET_TINY_DISTANCE +      \
133                                          ED_TAB_BAR_HEIGHT +            \
134                                          ED_SETTINGS_TABS_YOFFSET +     \
135                                          getFontHeight(FONT_TEXT_1) +   \
136                                          ED_GADGET_TEXT_DISTANCE)
137 #define ED_ELEMENT_TABS_XSTART          (ED_SETTINGS_ELEMENT_TABS_X)
138 #define ED_ELEMENT_TABS_YSTART          (ED_SETTINGS_ELEMENT_TABS_Y)
139 #define ED_ELEMENT_SETTINGS_XSTART      (ED_SETTINGS_ELEMENT_TABS_X +   \
140                                          ED_SETTINGS_TABS_XOFFSET)
141 #define ED_ELEMENT_SETTINGS_YSTART      (ED_SETTINGS_ELEMENT_TABS_Y +   \
142                                          ED_TABBUTTON_YSIZE +           \
143                                          ED_GADGET_TINY_DISTANCE +      \
144                                          ED_TAB_BAR_HEIGHT +            \
145                                          ED_SETTINGS_TABS_YOFFSET)
146
147 #define ED_SETTINGS_XOFFSET             (ED_CHECKBUTTON_XSIZE +         \
148                                          ED_GADGET_TEXT_DISTANCE)
149 #define ED_SETTINGS_YOFFSET             (ED_CHECKBUTTON_YSIZE +         \
150                                          ED_GADGET_LINE_DISTANCE)
151
152 #define ED_POS_RANGE                    (10000)
153 #define ED_POS_LEVEL_TABS_FIRST         (1 * ED_POS_RANGE)
154 #define ED_POS_LEVEL_TABS_LAST          (2 * ED_POS_RANGE - 1)
155 #define ED_POS_LEVEL_SETTINGS_FIRST     (2 * ED_POS_RANGE)
156 #define ED_POS_LEVEL_SETTINGS_LAST      (3 * ED_POS_RANGE - 1)
157 #define ED_POS_ENGINE_TABS_FIRST        (3 * ED_POS_RANGE)
158 #define ED_POS_ENGINE_TABS_LAST         (4 * ED_POS_RANGE - 1)
159 #define ED_POS_ENGINE_SETTINGS_FIRST    (4 * ED_POS_RANGE)
160 #define ED_POS_ENGINE_SETTINGS_LAST     (5 * ED_POS_RANGE - 1)
161 #define ED_POS_ELEMENT_TABS_FIRST       (5 * ED_POS_RANGE)
162 #define ED_POS_ELEMENT_TABS_LAST        (6 * ED_POS_RANGE - 1)
163 #define ED_POS_ELEMENT_SETTINGS_FIRST   (6 * ED_POS_RANGE)
164 #define ED_POS_ELEMENT_SETTINGS_LAST    (7 * ED_POS_RANGE - 1)
165
166 #define ED_LEVEL_TABS_XPOS(n)           (ED_POS_LEVEL_TABS_FIRST + (n))
167 #define ED_LEVEL_TABS_YPOS(n)           (ED_POS_LEVEL_TABS_FIRST + (n))
168
169 #define ED_LEVEL_SETTINGS_XPOS(n)       (ED_POS_LEVEL_SETTINGS_FIRST + (n))
170 #define ED_LEVEL_SETTINGS_YPOS(n)       (ED_POS_LEVEL_SETTINGS_FIRST + (n))
171
172 #define ED_ENGINE_TABS_XPOS(n)          (ED_POS_ENGINE_TABS_FIRST + (n))
173 #define ED_ENGINE_TABS_YPOS(n)          (ED_POS_ENGINE_TABS_FIRST + (n))
174
175 #define ED_ENGINE_SETTINGS_XPOS(n)      (ED_POS_ENGINE_SETTINGS_FIRST + (n))
176 #define ED_ENGINE_SETTINGS_YPOS(n)      (ED_POS_ENGINE_SETTINGS_FIRST + (n))
177
178 #define ED_ELEMENT_TABS_XPOS(n)         (ED_POS_ELEMENT_TABS_FIRST + (n))
179 #define ED_ELEMENT_TABS_YPOS(n)         (ED_POS_ELEMENT_TABS_FIRST + (n))
180
181 #define ED_ELEMENT_SETTINGS_XPOS(n)     (ED_POS_ELEMENT_SETTINGS_FIRST + (n))
182 #define ED_ELEMENT_SETTINGS_YPOS(n)     (ED_POS_ELEMENT_SETTINGS_FIRST + (n))
183
184 #define IS_POS_LEVEL_TABS(n)          ((n) >= ED_POS_LEVEL_TABS_FIRST && \
185                                        (n) <= ED_POS_LEVEL_TABS_LAST)
186 #define IS_POS_LEVEL_SETTINGS(n)      ((n) >= ED_POS_LEVEL_SETTINGS_FIRST && \
187                                        (n) <= ED_POS_LEVEL_SETTINGS_LAST)
188 #define IS_POS_ENGINE_TABS(n)         ((n) >= ED_POS_ENGINE_TABS_FIRST && \
189                                        (n) <= ED_POS_ENGINE_TABS_LAST)
190 #define IS_POS_ENGINE_SETTINGS(n)     ((n) >= ED_POS_ENGINE_SETTINGS_FIRST && \
191                                        (n) <= ED_POS_ENGINE_SETTINGS_LAST)
192 #define IS_POS_ELEMENT_TABS(n)        ((n) >= ED_POS_ELEMENT_TABS_FIRST && \
193                                        (n) <= ED_POS_ELEMENT_TABS_LAST)
194 #define IS_POS_ELEMENT_SETTINGS(n)    ((n) >= ED_POS_ELEMENT_SETTINGS_FIRST && \
195                                        (n) <= ED_POS_ELEMENT_SETTINGS_LAST)
196
197 #define ED_LEVEL_TABS_LINE(n)           ((n) - ED_POS_LEVEL_TABS_FIRST)
198 #define ED_LEVEL_SETTINGS_LINE(n)       ((n) - ED_POS_LEVEL_SETTINGS_FIRST)
199 #define ED_ENGINE_TABS_LINE(n)          ((n) - ED_POS_ENGINE_TABS_FIRST)
200 #define ED_ENGINE_SETTINGS_LINE(n)      ((n) - ED_POS_ENGINE_SETTINGS_FIRST)
201 #define ED_ELEMENT_TABS_LINE(n)         ((n) - ED_POS_ELEMENT_TABS_FIRST)
202 #define ED_ELEMENT_SETTINGS_LINE(n)     ((n) - ED_POS_ELEMENT_SETTINGS_FIRST)
203
204 #define ED_LEVEL_TABS_X(n)              (ED_LEVEL_TABS_XSTART + \
205                                          (n) * ED_SETTINGS_TABS_XOFFSET)
206 #define ED_LEVEL_TABS_Y(n)              (ED_LEVEL_TABS_YSTART + \
207                                          (n) * ED_SETTINGS_TABS_YOFFSET)
208
209 #define ED_LEVEL_SETTINGS_X(n)          (ED_LEVEL_SETTINGS_XSTART +     \
210                                          (n) * ED_SETTINGS_XOFFSET)
211 #define ED_LEVEL_SETTINGS_Y(n)          (ED_LEVEL_SETTINGS_YSTART +     \
212                                          (n) * ED_SETTINGS_YOFFSET)
213
214 #define ED_ENGINE_TABS_X(n)             (ED_ENGINE_TABS_XSTART +        \
215                                          (n) * ED_SETTINGS_TABS_XOFFSET)
216 #define ED_ENGINE_TABS_Y(n)             (ED_ENGINE_TABS_YSTART +        \
217                                          (n) * ED_SETTINGS_TABS_YOFFSET)
218
219 #define ED_ENGINE_SETTINGS_X(n)         (ED_ENGINE_SETTINGS_XSTART +    \
220                                          (n) * ED_SETTINGS_XOFFSET)
221 #define ED_ENGINE_SETTINGS_Y(n)         (ED_ENGINE_SETTINGS_YSTART +    \
222                                          (n) * ED_SETTINGS_YOFFSET)
223
224 #define ED_ELEMENT_TABS_X(n)            (ED_ELEMENT_TABS_XSTART +       \
225                                          (n) * ED_SETTINGS_TABS_XOFFSET)
226 #define ED_ELEMENT_TABS_Y(n)            (ED_ELEMENT_TABS_YSTART +       \
227                                          (n) * ED_SETTINGS_TABS_YOFFSET)
228
229 #define ED_ELEMENT_SETTINGS_X(n)        (ED_ELEMENT_SETTINGS_XSTART +   \
230                                          (n) * ED_SETTINGS_XOFFSET)
231 #define ED_ELEMENT_SETTINGS_Y(n)        (ED_ELEMENT_SETTINGS_YSTART +   \
232                                          (n) * ED_SETTINGS_YOFFSET)
233
234 #define ED_POS_TO_LEVEL_TABS_X(n)       \
235   (ED_LEVEL_TABS_X(ED_LEVEL_TABS_LINE(n)))
236 #define ED_POS_TO_LEVEL_TABS_Y(n)       \
237   (ED_LEVEL_TABS_Y(ED_LEVEL_TABS_LINE(n)))
238
239 #define ED_POS_TO_LEVEL_SETTINGS_X(n)   \
240   (ED_LEVEL_SETTINGS_X(ED_LEVEL_SETTINGS_LINE(n)))
241 #define ED_POS_TO_LEVEL_SETTINGS_Y(n)   \
242   (ED_LEVEL_SETTINGS_Y(ED_LEVEL_SETTINGS_LINE(n)))
243
244 #define ED_POS_TO_ENGINE_TABS_X(n)      \
245   (ED_ENGINE_TABS_X(ED_ENGINE_TABS_LINE(n)))
246 #define ED_POS_TO_ENGINE_TABS_Y(n)      \
247   (ED_ENGINE_TABS_Y(ED_ENGINE_TABS_LINE(n)))
248
249 #define ED_POS_TO_ENGINE_SETTINGS_X(n)  \
250   (ED_ENGINE_SETTINGS_X(ED_ENGINE_SETTINGS_LINE(n)))
251 #define ED_POS_TO_ENGINE_SETTINGS_Y(n)  \
252   (ED_ENGINE_SETTINGS_Y(ED_ENGINE_SETTINGS_LINE(n)))
253
254 #define ED_POS_TO_ELEMENT_TABS_X(n)     \
255   (ED_ELEMENT_TABS_X(ED_ELEMENT_TABS_LINE(n)))
256 #define ED_POS_TO_ELEMENT_TABS_Y(n)     \
257   (ED_ELEMENT_TABS_Y(ED_ELEMENT_TABS_LINE(n)))
258
259 #define ED_POS_TO_ELEMENT_SETTINGS_X(n) \
260   (ED_ELEMENT_SETTINGS_X(ED_ELEMENT_SETTINGS_LINE(n)))
261 #define ED_POS_TO_ELEMENT_SETTINGS_Y(n) \
262   (ED_ELEMENT_SETTINGS_Y(ED_ELEMENT_SETTINGS_LINE(n)))
263
264 #define ED_SETTINGS_X(n)                (IS_POS_LEVEL_TABS(n) ? \
265                                          ED_POS_TO_LEVEL_TABS_X(n) : \
266                                          IS_POS_LEVEL_SETTINGS(n) ?     \
267                                          ED_POS_TO_LEVEL_SETTINGS_X(n) : \
268                                          IS_POS_ENGINE_TABS(n) ?        \
269                                          ED_POS_TO_ENGINE_TABS_X(n) : \
270                                          IS_POS_ENGINE_SETTINGS(n) ?    \
271                                          ED_POS_TO_ENGINE_SETTINGS_X(n) : \
272                                          IS_POS_ELEMENT_TABS(n) ?       \
273                                          ED_POS_TO_ELEMENT_TABS_X(n) : \
274                                          IS_POS_ELEMENT_SETTINGS(n) ?   \
275                                          ED_POS_TO_ELEMENT_SETTINGS_X(n) : (n))
276 #define ED_SETTINGS_Y(n)                (IS_POS_LEVEL_TABS(n) ? \
277                                          ED_POS_TO_LEVEL_TABS_Y(n) : \
278                                          IS_POS_LEVEL_SETTINGS(n) ?     \
279                                          ED_POS_TO_LEVEL_SETTINGS_Y(n) : \
280                                          IS_POS_ENGINE_TABS(n) ?        \
281                                          ED_POS_TO_ENGINE_TABS_Y(n) : \
282                                          IS_POS_ENGINE_SETTINGS(n) ?    \
283                                          ED_POS_TO_ENGINE_SETTINGS_Y(n) : \
284                                          IS_POS_ELEMENT_TABS(n) ?       \
285                                          ED_POS_TO_ELEMENT_TABS_Y(n) : \
286                                          IS_POS_ELEMENT_SETTINGS(n) ?   \
287                                          ED_POS_TO_ELEMENT_SETTINGS_Y(n) : (n))
288
289 #define ED_SETTINGS_XOFF(n)             (5 * ((n) % 4) *                \
290                                          ED_DRAWINGAREA_TILE_SIZE)
291 #define ED_SETTINGS_YOFF(n)             (5 * ((n) / 4) *                \
292                                          ED_DRAWINGAREA_TILE_SIZE)
293
294 #define ED_AREA_XOFFSET_1(n)            ((n) != 0 ?                     \
295                                          ED_DRAWINGAREA_BORDER_SIZE : 0)
296 #define ED_AREA_YOFFSET_1(n)            ((n) != 0 ?                     \
297                                          (ED_CHECKBUTTON_YSIZE -        \
298                                           ED_DRAWINGAREA_TILE_SIZE) / 2 : 0)
299
300 #define ED_AREA_XOFFSET_2(n)      (0)
301 #define ED_AREA_YOFFSET_2(n)      ((n) == 3 ?                   \
302                                    ((n) - 1) * ED_DRAWINGAREA_TILE_SIZE / 2 : 0)
303
304 #define ED_AREA_SETTINGS_X(i)      (ED_SETTINGS_X((i).x) +              \
305                                     ED_SETTINGS_XOFF((i).xoffset) +     \
306                                     ED_AREA_XOFFSET_1((i).x) -          \
307                                     ED_AREA_XOFFSET_2((i).area_xsize))
308 #define ED_AREA_SETTINGS_Y(i)      (ED_SETTINGS_Y((i).y) +              \
309                                     ED_SETTINGS_YOFF((i).yoffset) +     \
310                                     ED_AREA_YOFFSET_1((i).y) -          \
311                                     ED_AREA_YOFFSET_2((i).area_ysize))
312
313 // values for element content drawing areas
314 #define ED_AREA_1X1_LSETTINGS_XPOS(n)   ED_LEVEL_SETTINGS_XPOS(n)
315 #define ED_AREA_1X1_LSETTINGS_YPOS(n)   ED_LEVEL_SETTINGS_YPOS(n)
316 #define ED_AREA_1X1_LSETTINGS_XOFF      (0)
317 #define ED_AREA_1X1_LSETTINGS_YOFF      (0)
318
319 #define ED_AREA_1X1_SETTINGS_XPOS(n)    ED_ELEMENT_SETTINGS_XPOS(n)
320 #define ED_AREA_1X1_SETTINGS_YPOS(n)    ED_ELEMENT_SETTINGS_YPOS(n)
321 #define ED_AREA_1X1_SETTINGS_XOFF       (0)
322 #define ED_AREA_1X1_SETTINGS_YOFF       (0)
323
324 #define ED_AREA_3X3_SETTINGS_XPOS(n)    ED_ELEMENT_SETTINGS_XPOS(n)
325 #define ED_AREA_3X3_SETTINGS_YPOS(n)    ED_ELEMENT_SETTINGS_YPOS(n)
326 #define ED_AREA_3X3_SETTINGS_XOFF       (0)
327 #define ED_AREA_3X3_SETTINGS_YOFF       (0)
328
329 // element content
330 #define ED_AREA_ELEMENT_CONTENT_XOFF(n) (n)
331 #define ED_AREA_ELEMENT_CONTENT_YOFF(n) (n)
332
333 // yamyam content
334 #define ED_XPOS_YAM                     0
335 #define ED_YPOS_YAM                     5
336 #define ED_AREA_YAMYAM_CONTENT_XPOS     ED_ELEMENT_SETTINGS_XPOS(ED_XPOS_YAM)
337 #define ED_AREA_YAMYAM_CONTENT_YPOS     ED_ELEMENT_SETTINGS_YPOS(ED_YPOS_YAM)
338 #define ED_AREA_YAMYAM_CONTENT_XOFF(n)  ED_AREA_ELEMENT_CONTENT_XOFF(n)
339 #define ED_AREA_YAMYAM_CONTENT_YOFF(n)  ED_AREA_ELEMENT_CONTENT_YOFF(n)
340 #define ED_AREA_YAMYAM_CONTENT_X(n)     (ED_ELEMENT_SETTINGS_X(ED_XPOS_YAM) + \
341                                          ED_SETTINGS_XOFF(n))
342 #define ED_AREA_YAMYAM_CONTENT_Y(n)     (ED_ELEMENT_SETTINGS_Y(ED_YPOS_YAM) + \
343                                          ED_SETTINGS_YOFF(n) +          \
344                                          ED_AREA_YOFFSET_1(ED_YPOS_YAM) - \
345                                          ED_AREA_YOFFSET_2(3))
346
347 // magic ball content
348 #define ED_XPOS_BALL                    0
349 #define ED_YPOS_BALL                    6
350 #define ED_AREA_MAGIC_BALL_CONTENT_XPOS ED_ELEMENT_SETTINGS_XPOS(ED_XPOS_BALL)
351 #define ED_AREA_MAGIC_BALL_CONTENT_YPOS ED_ELEMENT_SETTINGS_YPOS(ED_YPOS_BALL)
352 #define ED_AREA_MAGIC_BALL_CONTENT_XOFF(n) ED_AREA_ELEMENT_CONTENT_XOFF(n)
353 #define ED_AREA_MAGIC_BALL_CONTENT_YOFF(n) ED_AREA_ELEMENT_CONTENT_YOFF(n)
354 #define ED_AREA_MAGIC_BALL_CONTENT_X(n) (ED_ELEMENT_SETTINGS_X(ED_XPOS_BALL) + \
355                                          ED_SETTINGS_XOFF(n))
356 #define ED_AREA_MAGIC_BALL_CONTENT_Y(n) (ED_ELEMENT_SETTINGS_Y(ED_YPOS_BALL) + \
357                                          ED_SETTINGS_YOFF(n) +          \
358                                          ED_AREA_YOFFSET_1(ED_YPOS_BALL) - \
359                                          ED_AREA_YOFFSET_2(3))
360
361 // values for scrolling gadgets for drawing area
362 #define ED_SCROLLBUTTON_XSIZE           (graphic_info[IMG_EDITOR_PLAYFIELD_SCROLLBAR].width)
363 #define ED_SCROLLBUTTON_YSIZE           (graphic_info[IMG_EDITOR_PLAYFIELD_SCROLLBAR].height)
364
365 #define ED_SCROLL_UP_XPOS               (SXSIZE - ED_SCROLLBUTTON_XSIZE)
366 #define ED_SCROLL_UP_YPOS               (0)
367 #define ED_SCROLL_DOWN_XPOS             ED_SCROLL_UP_XPOS
368 #define ED_SCROLL_DOWN_YPOS             (SYSIZE - 3 * ED_SCROLLBUTTON_YSIZE)
369 #define ED_SCROLL_LEFT_XPOS             (0)
370 #define ED_SCROLL_LEFT_YPOS             (SYSIZE - 2 * ED_SCROLLBUTTON_YSIZE)
371 #define ED_SCROLL_RIGHT_XPOS            (SXSIZE - 2 * ED_SCROLLBUTTON_XSIZE)
372 #define ED_SCROLL_RIGHT_YPOS            ED_SCROLL_LEFT_YPOS
373 #define ED_SCROLL_HORIZONTAL_XPOS       (ED_SCROLL_LEFT_XPOS +          \
374                                          ED_SCROLLBUTTON_XSIZE)
375 #define ED_SCROLL_HORIZONTAL_YPOS       ED_SCROLL_LEFT_YPOS
376 #define ED_SCROLL_HORIZONTAL_XSIZE      (SXSIZE - 3 * ED_SCROLLBUTTON_XSIZE)
377 #define ED_SCROLL_HORIZONTAL_YSIZE      ED_SCROLLBUTTON_YSIZE
378 #define ED_SCROLL_VERTICAL_XPOS         ED_SCROLL_UP_XPOS
379 #define ED_SCROLL_VERTICAL_YPOS         (ED_SCROLL_UP_YPOS +            \
380                                          ED_SCROLLBUTTON_YSIZE)
381 #define ED_SCROLL_VERTICAL_XSIZE        ED_SCROLLBUTTON_XSIZE
382 #define ED_SCROLL_VERTICAL_YSIZE        (SYSIZE - 4 * ED_SCROLLBUTTON_YSIZE)
383
384 // values for scrolling gadgets for element list
385 #define ED_SCROLLBUTTON2_XSIZE          (graphic_info[IMG_EDITOR_PALETTE_SCROLL_UP].width)
386 #define ED_SCROLLBUTTON2_YSIZE          (graphic_info[IMG_EDITOR_PALETTE_SCROLL_UP].height)
387
388 #define ED_SCROLL2_UP_XPOS              (ED_ELEMENTLIST_XPOS +          \
389                                          ED_ELEMENTLIST_BUTTONS_HORIZ * \
390                                          ED_ELEMENTLIST_XSIZE)
391 #define ED_SCROLL2_UP_YPOS              ED_ELEMENTLIST_YPOS
392 #define ED_SCROLL2_DOWN_XPOS            ED_SCROLL2_UP_XPOS
393 #define ED_SCROLL2_DOWN_YPOS            (ED_SCROLL2_UP_YPOS +           \
394                                          ED_ELEMENTLIST_BUTTONS_VERT *  \
395                                          ED_ELEMENTLIST_YSIZE -         \
396                                          ED_SCROLLBUTTON2_YSIZE)
397 #define ED_SCROLL2_VERTICAL_XPOS        ED_SCROLL2_UP_XPOS
398 #define ED_SCROLL2_VERTICAL_YPOS        (ED_SCROLL2_UP_YPOS +           \
399                                          ED_SCROLLBUTTON2_YSIZE)
400 #define ED_SCROLL2_VERTICAL_XSIZE       ED_SCROLLBUTTON2_XSIZE
401 #define ED_SCROLL2_VERTICAL_YSIZE       (ED_ELEMENTLIST_BUTTONS_VERT *  \
402                                          ED_ELEMENTLIST_YSIZE -         \
403                                          2 * ED_SCROLLBUTTON2_YSIZE)
404
405 // values for ClearEditorGadgetInfoText() and HandleEditorGadgetInfoText()
406 #define INFOTEXT_FONT           FONT_TEXT_2
407 #define INFOTEXT_XSIZE          SXSIZE
408 #define INFOTEXT_YSIZE          getFontHeight(INFOTEXT_FONT)
409 #define INFOTEXT_YSIZE_FULL     (INFOTEXT_YSIZE + ED_GADGET_SMALL_DISTANCE)
410 #define INFOTEXT_X              (editor.settings.tooltip.x)
411 #define INFOTEXT_Y              (editor.settings.tooltip.y)
412 #define INFOTEXT_XY_REDEFINED   (INFOTEXT_X != -1 || INFOTEXT_Y != -1)
413 #define INFOTEXT_XPOS           SX + (INFOTEXT_XY_REDEFINED ? INFOTEXT_X : 0)
414 #define INFOTEXT_YPOS           SY + (INFOTEXT_XY_REDEFINED ? INFOTEXT_Y : \
415                                       SYSIZE - INFOTEXT_YSIZE)
416
417
418 // ----------------------------------------------------------------------------
419 // editor gadget definitions
420 // ----------------------------------------------------------------------------
421
422 enum
423 {
424   GADGET_ID_NONE = -1,
425
426   // drawing toolbox buttons
427
428   GADGET_ID_SINGLE_ITEMS,
429   GADGET_ID_CONNECTED_ITEMS,
430   GADGET_ID_LINE,
431   GADGET_ID_ARC,
432   GADGET_ID_RECTANGLE,
433   GADGET_ID_FILLED_BOX,
434   GADGET_ID_WRAP_UP,
435   GADGET_ID_TEXT,
436   GADGET_ID_FLOOD_FILL,
437   GADGET_ID_WRAP_LEFT,
438   GADGET_ID_ZOOM,
439   GADGET_ID_WRAP_RIGHT,
440   GADGET_ID_RANDOM_PLACEMENT,
441   GADGET_ID_GRAB_BRUSH,
442   GADGET_ID_WRAP_DOWN,
443   GADGET_ID_PICK_ELEMENT,
444
445   GADGET_ID_UNDO,
446   GADGET_ID_CONF,
447   GADGET_ID_SAVE,
448   GADGET_ID_CLEAR,
449   GADGET_ID_TEST,
450   GADGET_ID_EXIT,
451
452   GADGET_ID_CUSTOM_COPY_FROM,
453   GADGET_ID_CUSTOM_COPY_TO,
454   GADGET_ID_CUSTOM_EXCHANGE,
455   GADGET_ID_CUSTOM_COPY,
456   GADGET_ID_CUSTOM_PASTE,
457
458   GADGET_ID_PROPERTIES,
459   GADGET_ID_ELEMENT_LEFT,
460   GADGET_ID_ELEMENT_MIDDLE,
461   GADGET_ID_ELEMENT_RIGHT,
462   GADGET_ID_PALETTE,
463
464   // counter gadget identifiers
465
466   GADGET_ID_SELECT_LEVEL_DOWN,
467   GADGET_ID_SELECT_LEVEL_TEXT,
468   GADGET_ID_SELECT_LEVEL_UP,
469   GADGET_ID_LEVEL_XSIZE_DOWN,
470   GADGET_ID_LEVEL_XSIZE_TEXT,
471   GADGET_ID_LEVEL_XSIZE_UP,
472   GADGET_ID_LEVEL_YSIZE_DOWN,
473   GADGET_ID_LEVEL_YSIZE_TEXT,
474   GADGET_ID_LEVEL_YSIZE_UP,
475   GADGET_ID_LEVEL_RANDOM_DOWN,
476   GADGET_ID_LEVEL_RANDOM_TEXT,
477   GADGET_ID_LEVEL_RANDOM_UP,
478   GADGET_ID_LEVEL_GEMSLIMIT_DOWN,
479   GADGET_ID_LEVEL_GEMSLIMIT_TEXT,
480   GADGET_ID_LEVEL_GEMSLIMIT_UP,
481   GADGET_ID_LEVEL_TIMELIMIT_DOWN,
482   GADGET_ID_LEVEL_TIMELIMIT_TEXT,
483   GADGET_ID_LEVEL_TIMELIMIT_UP,
484   GADGET_ID_LEVEL_TIMESCORE_DOWN,
485   GADGET_ID_LEVEL_TIMESCORE_TEXT,
486   GADGET_ID_LEVEL_TIMESCORE_UP,
487   GADGET_ID_LEVEL_RANDOM_SEED_DOWN,
488   GADGET_ID_LEVEL_RANDOM_SEED_TEXT,
489   GADGET_ID_LEVEL_RANDOM_SEED_UP,
490   GADGET_ID_LEVELSET_NUM_LEVELS_DOWN,
491   GADGET_ID_LEVELSET_NUM_LEVELS_TEXT,
492   GADGET_ID_LEVELSET_NUM_LEVELS_UP,
493   GADGET_ID_BD_CYCLE_DELAY_MS_DOWN,
494   GADGET_ID_BD_CYCLE_DELAY_MS_TEXT,
495   GADGET_ID_BD_CYCLE_DELAY_MS_UP,
496   GADGET_ID_BD_CYCLE_DELAY_C64_DOWN,
497   GADGET_ID_BD_CYCLE_DELAY_C64_TEXT,
498   GADGET_ID_BD_CYCLE_DELAY_C64_UP,
499   GADGET_ID_BD_HATCHING_DELAY_CYCLES_DOWN,
500   GADGET_ID_BD_HATCHING_DELAY_CYCLES_TEXT,
501   GADGET_ID_BD_HATCHING_DELAY_CYCLES_UP,
502   GADGET_ID_BD_HATCHING_DELAY_SECONDS_DOWN,
503   GADGET_ID_BD_HATCHING_DELAY_SECONDS_TEXT,
504   GADGET_ID_BD_HATCHING_DELAY_SECONDS_UP,
505   GADGET_ID_BD_PUSHING_PROB_DOWN,
506   GADGET_ID_BD_PUSHING_PROB_TEXT,
507   GADGET_ID_BD_PUSHING_PROB_UP,
508   GADGET_ID_BD_PUSHING_PROB_WITH_SWEET_DOWN,
509   GADGET_ID_BD_PUSHING_PROB_WITH_SWEET_TEXT,
510   GADGET_ID_BD_PUSHING_PROB_WITH_SWEET_UP,
511   GADGET_ID_ELEMENT_VALUE1_DOWN,
512   GADGET_ID_ELEMENT_VALUE1_TEXT,
513   GADGET_ID_ELEMENT_VALUE1_UP,
514   GADGET_ID_ELEMENT_VALUE2_DOWN,
515   GADGET_ID_ELEMENT_VALUE2_TEXT,
516   GADGET_ID_ELEMENT_VALUE2_UP,
517   GADGET_ID_ELEMENT_VALUE3_DOWN,
518   GADGET_ID_ELEMENT_VALUE3_TEXT,
519   GADGET_ID_ELEMENT_VALUE3_UP,
520   GADGET_ID_ELEMENT_VALUE4_DOWN,
521   GADGET_ID_ELEMENT_VALUE4_TEXT,
522   GADGET_ID_ELEMENT_VALUE4_UP,
523   GADGET_ID_YAMYAM_CONTENT_DOWN,
524   GADGET_ID_YAMYAM_CONTENT_TEXT,
525   GADGET_ID_YAMYAM_CONTENT_UP,
526   GADGET_ID_BALL_CONTENT_DOWN,
527   GADGET_ID_BALL_CONTENT_TEXT,
528   GADGET_ID_BALL_CONTENT_UP,
529   GADGET_ID_ANDROID_CONTENT_DOWN,
530   GADGET_ID_ANDROID_CONTENT_TEXT,
531   GADGET_ID_ANDROID_CONTENT_UP,
532   GADGET_ID_ENVELOPE_XSIZE_DOWN,
533   GADGET_ID_ENVELOPE_XSIZE_TEXT,
534   GADGET_ID_ENVELOPE_XSIZE_UP,
535   GADGET_ID_ENVELOPE_YSIZE_DOWN,
536   GADGET_ID_ENVELOPE_YSIZE_TEXT,
537   GADGET_ID_ENVELOPE_YSIZE_UP,
538   GADGET_ID_INVENTORY_SIZE_DOWN,
539   GADGET_ID_INVENTORY_SIZE_TEXT,
540   GADGET_ID_INVENTORY_SIZE_UP,
541   GADGET_ID_MM_BALL_CONTENT_DOWN,
542   GADGET_ID_MM_BALL_CONTENT_TEXT,
543   GADGET_ID_MM_BALL_CONTENT_UP,
544   GADGET_ID_CUSTOM_SCORE_DOWN,
545   GADGET_ID_CUSTOM_SCORE_TEXT,
546   GADGET_ID_CUSTOM_SCORE_UP,
547   GADGET_ID_CUSTOM_GEMCOUNT_DOWN,
548   GADGET_ID_CUSTOM_GEMCOUNT_TEXT,
549   GADGET_ID_CUSTOM_GEMCOUNT_UP,
550   GADGET_ID_CUSTOM_VALUE_FIX_DOWN,
551   GADGET_ID_CUSTOM_VALUE_FIX_TEXT,
552   GADGET_ID_CUSTOM_VALUE_FIX_UP,
553   GADGET_ID_CUSTOM_VALUE_RND_DOWN,
554   GADGET_ID_CUSTOM_VALUE_RND_TEXT,
555   GADGET_ID_CUSTOM_VALUE_RND_UP,
556   GADGET_ID_PUSH_DELAY_FIX_DOWN,
557   GADGET_ID_PUSH_DELAY_FIX_TEXT,
558   GADGET_ID_PUSH_DELAY_FIX_UP,
559   GADGET_ID_PUSH_DELAY_RND_DOWN,
560   GADGET_ID_PUSH_DELAY_RND_TEXT,
561   GADGET_ID_PUSH_DELAY_RND_UP,
562   GADGET_ID_DROP_DELAY_FIX_DOWN,
563   GADGET_ID_DROP_DELAY_FIX_TEXT,
564   GADGET_ID_DROP_DELAY_FIX_UP,
565   GADGET_ID_DROP_DELAY_RND_DOWN,
566   GADGET_ID_DROP_DELAY_RND_TEXT,
567   GADGET_ID_DROP_DELAY_RND_UP,
568   GADGET_ID_MOVE_DELAY_FIX_DOWN,
569   GADGET_ID_MOVE_DELAY_FIX_TEXT,
570   GADGET_ID_MOVE_DELAY_FIX_UP,
571   GADGET_ID_MOVE_DELAY_RND_DOWN,
572   GADGET_ID_MOVE_DELAY_RND_TEXT,
573   GADGET_ID_MOVE_DELAY_RND_UP,
574   GADGET_ID_STEP_DELAY_FIX_DOWN,
575   GADGET_ID_STEP_DELAY_FIX_TEXT,
576   GADGET_ID_STEP_DELAY_FIX_UP,
577   GADGET_ID_STEP_DELAY_RND_DOWN,
578   GADGET_ID_STEP_DELAY_RND_TEXT,
579   GADGET_ID_STEP_DELAY_RND_UP,
580   GADGET_ID_EXPLOSION_DELAY_DOWN,
581   GADGET_ID_EXPLOSION_DELAY_TEXT,
582   GADGET_ID_EXPLOSION_DELAY_UP,
583   GADGET_ID_IGNITION_DELAY_DOWN,
584   GADGET_ID_IGNITION_DELAY_TEXT,
585   GADGET_ID_IGNITION_DELAY_UP,
586   GADGET_ID_CHANGE_DELAY_FIX_DOWN,
587   GADGET_ID_CHANGE_DELAY_FIX_TEXT,
588   GADGET_ID_CHANGE_DELAY_FIX_UP,
589   GADGET_ID_CHANGE_DELAY_RND_DOWN,
590   GADGET_ID_CHANGE_DELAY_RND_TEXT,
591   GADGET_ID_CHANGE_DELAY_RND_UP,
592   GADGET_ID_CHANGE_CONT_RND_DOWN,
593   GADGET_ID_CHANGE_CONT_RND_TEXT,
594   GADGET_ID_CHANGE_CONT_RND_UP,
595   GADGET_ID_GROUP_CONTENT_DOWN,
596   GADGET_ID_GROUP_CONTENT_TEXT,
597   GADGET_ID_GROUP_CONTENT_UP,
598
599   // drawing area identifiers
600
601   GADGET_ID_DRAWING_LEVEL,
602   GADGET_ID_YAMYAM_CONTENT_0,
603   GADGET_ID_YAMYAM_CONTENT_1,
604   GADGET_ID_YAMYAM_CONTENT_2,
605   GADGET_ID_YAMYAM_CONTENT_3,
606   GADGET_ID_YAMYAM_CONTENT_4,
607   GADGET_ID_YAMYAM_CONTENT_5,
608   GADGET_ID_YAMYAM_CONTENT_6,
609   GADGET_ID_YAMYAM_CONTENT_7,
610   GADGET_ID_MAGIC_BALL_CONTENT_0,
611   GADGET_ID_MAGIC_BALL_CONTENT_1,
612   GADGET_ID_MAGIC_BALL_CONTENT_2,
613   GADGET_ID_MAGIC_BALL_CONTENT_3,
614   GADGET_ID_MAGIC_BALL_CONTENT_4,
615   GADGET_ID_MAGIC_BALL_CONTENT_5,
616   GADGET_ID_MAGIC_BALL_CONTENT_6,
617   GADGET_ID_MAGIC_BALL_CONTENT_7,
618   GADGET_ID_ANDROID_CONTENT,
619   GADGET_ID_AMOEBA_CONTENT,
620   GADGET_ID_BD_SNAP_ELEMENT,
621   GADGET_ID_BD_MAGIC_WALL_DIAMOND_TO,
622   GADGET_ID_BD_MAGIC_WALL_ROCK_TO,
623   GADGET_ID_BD_MAGIC_WALL_MEGA_ROCK_TO,
624   GADGET_ID_BD_MAGIC_WALL_NUT_TO,
625   GADGET_ID_BD_MAGIC_WALL_NITRO_PACK_TO,
626   GADGET_ID_BD_MAGIC_WALL_FLYING_DIAMOND_TO,
627   GADGET_ID_BD_MAGIC_WALL_FLYING_ROCK_TO,
628   GADGET_ID_BD_AMOEBA_CONTENT_TOO_BIG,
629   GADGET_ID_BD_AMOEBA_CONTENT_ENCLOSED,
630   GADGET_ID_BD_AMOEBA_2_CONTENT_TOO_BIG,
631   GADGET_ID_BD_AMOEBA_2_CONTENT_ENCLOSED,
632   GADGET_ID_BD_AMOEBA_2_CONTENT_EXPLODING,
633   GADGET_ID_BD_AMOEBA_2_CONTENT_LOOKS_LIKE,
634   GADGET_ID_BD_SLIME_EATS_ELEMENT_1,
635   GADGET_ID_BD_SLIME_CONVERTS_TO_ELEMENT_1,
636   GADGET_ID_BD_SLIME_EATS_ELEMENT_2,
637   GADGET_ID_BD_SLIME_CONVERTS_TO_ELEMENT_2,
638   GADGET_ID_BD_SLIME_EATS_ELEMENT_3,
639   GADGET_ID_BD_SLIME_CONVERTS_TO_ELEMENT_3,
640   GADGET_ID_BD_ACID_EATS_ELEMENT,
641   GADGET_ID_BD_ACID_TURNS_TO_ELEMENT,
642   GADGET_ID_BD_BITER_EATS_ELEMENT,
643   GADGET_ID_BD_BLADDER_CONVERTS_BY_ELEMENT,
644   GADGET_ID_BD_NUT_CONTENT,
645   GADGET_ID_BD_EXPANDING_WALL_LOOKS_LIKE,
646   GADGET_ID_BD_SAND_LOOKS_LIKE,
647   GADGET_ID_BD_ROCK_TURNS_TO_ON_FALLING,
648   GADGET_ID_BD_ROCK_TURNS_TO_ON_IMPACT,
649   GADGET_ID_BD_DIAMOND_TURNS_TO_ON_FALLING,
650   GADGET_ID_BD_DIAMOND_TURNS_TO_ON_IMPACT,
651   GADGET_ID_BD_FIREFLY_EXPLODES_TO,
652   GADGET_ID_BD_FIREFLY_2_EXPLODES_TO,
653   GADGET_ID_BD_BUTTERFLY_EXPLODES_TO,
654   GADGET_ID_BD_BUTTERFLY_2_EXPLODES_TO,
655   GADGET_ID_BD_STONEFLY_EXPLODES_TO,
656   GADGET_ID_BD_DRAGONFLY_EXPLODES_TO,
657   GADGET_ID_BD_DIAMOND_BIRTH_TURNS_TO,
658   GADGET_ID_BD_BOMB_EXPLOSION_TURNS_TO,
659   GADGET_ID_BD_NITRO_EXPLOSION_TURNS_TO,
660   GADGET_ID_BD_EXPLOSION_TURNS_TO,
661   GADGET_ID_START_ELEMENT,
662   GADGET_ID_ARTWORK_ELEMENT,
663   GADGET_ID_EXPLOSION_ELEMENT,
664   GADGET_ID_INVENTORY_CONTENT,
665   GADGET_ID_MM_BALL_CONTENT,
666   GADGET_ID_CUSTOM_GRAPHIC,
667   GADGET_ID_CUSTOM_CONTENT,
668   GADGET_ID_CUSTOM_MOVE_ENTER,
669   GADGET_ID_CUSTOM_MOVE_LEAVE,
670   GADGET_ID_CUSTOM_CHANGE_TARGET,
671   GADGET_ID_CUSTOM_CHANGE_CONTENT,
672   GADGET_ID_CUSTOM_CHANGE_TRIGGER,
673   GADGET_ID_CUSTOM_CHANGE_ACTION,
674   GADGET_ID_GROUP_CONTENT,
675   GADGET_ID_RANDOM_BACKGROUND,
676
677   // text input identifiers
678
679   GADGET_ID_LEVEL_NAME,
680   GADGET_ID_LEVEL_AUTHOR,
681   GADGET_ID_LEVELSET_NAME,
682   GADGET_ID_LEVELSET_AUTHOR,
683   GADGET_ID_BD_COLOR_TEXT_B,
684   GADGET_ID_BD_COLOR_TEXT_0,
685   GADGET_ID_BD_COLOR_TEXT_1,
686   GADGET_ID_BD_COLOR_TEXT_2,
687   GADGET_ID_BD_COLOR_TEXT_3,
688   GADGET_ID_BD_COLOR_TEXT_4,
689   GADGET_ID_BD_COLOR_TEXT_5,
690   GADGET_ID_ELEMENT_NAME,
691
692   // text area identifiers
693
694   GADGET_ID_ENVELOPE_INFO,
695
696   // selectbox identifiers
697
698   GADGET_ID_TIME_OR_STEPS,
699   GADGET_ID_TIME_SCORE_BASE,
700   GADGET_ID_GAME_ENGINE_TYPE,
701   GADGET_ID_LEVELSET_SAVE_MODE,
702   GADGET_ID_BD_SCHEDULING_TYPE,
703   GADGET_ID_BD_COLOR_TYPE,
704   GADGET_ID_BD_COLOR_C64_B,
705   GADGET_ID_BD_COLOR_C64_0,
706   GADGET_ID_BD_COLOR_C64_1,
707   GADGET_ID_BD_COLOR_C64_2,
708   GADGET_ID_BD_COLOR_C64_3,
709   GADGET_ID_BD_COLOR_C64_4,
710   GADGET_ID_BD_COLOR_C64_5,
711   GADGET_ID_WIND_DIRECTION,
712   GADGET_ID_PLAYER_SPEED,
713   GADGET_ID_BD_GRAVITY_DIRECTION,
714   GADGET_ID_MM_BALL_CHOICE_MODE,
715   GADGET_ID_CUSTOM_WALK_TO_ACTION,
716   GADGET_ID_CUSTOM_EXPLOSION_TYPE,
717   GADGET_ID_CUSTOM_DEADLINESS,
718   GADGET_ID_CUSTOM_MOVE_PATTERN,
719   GADGET_ID_CUSTOM_MOVE_DIRECTION,
720   GADGET_ID_CUSTOM_MOVE_STEPSIZE,
721   GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE,
722   GADGET_ID_CUSTOM_SMASH_TARGETS,
723   GADGET_ID_CUSTOM_SLIPPERY_TYPE,
724   GADGET_ID_CUSTOM_ACCESS_TYPE,
725   GADGET_ID_CUSTOM_ACCESS_LAYER,
726   GADGET_ID_CUSTOM_ACCESS_PROTECTED,
727   GADGET_ID_CUSTOM_ACCESS_DIRECTION,
728   GADGET_ID_CHANGE_TIME_UNITS,
729   GADGET_ID_CHANGE_DIRECT_ACTION,
730   GADGET_ID_CHANGE_OTHER_ACTION,
731   GADGET_ID_CHANGE_SIDE,
732   GADGET_ID_CHANGE_PLAYER,
733   GADGET_ID_CHANGE_PAGE,
734   GADGET_ID_CHANGE_REPLACE_WHEN,
735   GADGET_ID_ACTION_TYPE,
736   GADGET_ID_ACTION_MODE,
737   GADGET_ID_ACTION_ARG,
738   GADGET_ID_SELECT_CHANGE_PAGE,
739   GADGET_ID_GROUP_CHOICE_MODE,
740
741   // textbutton identifiers
742
743   GADGET_ID_LEVELCONFIG_LEVEL,
744   GADGET_ID_LEVELCONFIG_LEVELSET,
745   GADGET_ID_LEVELCONFIG_EDITOR,
746   GADGET_ID_LEVELCONFIG_ENGINE,
747   GADGET_ID_ENGINECONFIG_CONFIG,
748   GADGET_ID_ENGINECONFIG_COLORS,
749   GADGET_ID_PROPERTIES_INFO,
750   GADGET_ID_PROPERTIES_CONFIG,
751   GADGET_ID_PROPERTIES_CONFIG_1,
752   GADGET_ID_PROPERTIES_CONFIG_2,
753   GADGET_ID_PROPERTIES_CHANGE,
754   GADGET_ID_SAVE_AS_TEMPLATE_1,
755   GADGET_ID_SAVE_AS_TEMPLATE_2,
756   GADGET_ID_SAVE_LEVELSET,
757   GADGET_ID_ADD_CHANGE_PAGE,
758   GADGET_ID_DEL_CHANGE_PAGE,
759   GADGET_ID_BD_SET_RANDOM_COLORS,
760
761   // graphicbutton identifiers
762
763   GADGET_ID_PREV_CHANGE_PAGE,
764   GADGET_ID_NEXT_CHANGE_PAGE,
765   GADGET_ID_COPY_CHANGE_PAGE,
766   GADGET_ID_PASTE_CHANGE_PAGE,
767
768   // gadgets for scrolling of drawing area
769
770   GADGET_ID_SCROLL_UP,
771   GADGET_ID_SCROLL_DOWN,
772   GADGET_ID_SCROLL_LEFT,
773   GADGET_ID_SCROLL_RIGHT,
774   GADGET_ID_SCROLL_HORIZONTAL,
775   GADGET_ID_SCROLL_VERTICAL,
776
777   // gadgets for scrolling element list
778
779   GADGET_ID_SCROLL_LIST_UP,
780   GADGET_ID_SCROLL_LIST_DOWN,
781   GADGET_ID_SCROLL_LIST_VERTICAL,
782
783   // checkbuttons/radiobuttons for level/element properties
784
785   GADGET_ID_AUTO_COUNT_GEMS,
786   GADGET_ID_RATE_TIME_OVER_SCORE,
787   GADGET_ID_USE_LEVELSET_ARTWORK,
788   GADGET_ID_COPY_LEVEL_TEMPLATE,
789   GADGET_ID_RANDOM_PERCENTAGE,
790   GADGET_ID_RANDOM_QUANTITY,
791   GADGET_ID_RANDOM_RESTRICTED,
792   GADGET_ID_BD_INTERMISSION,
793   GADGET_ID_BD_PAL_TIMING,
794   GADGET_ID_BD_LINE_SHIFTING_BORDERS,
795   GADGET_ID_BD_SCAN_FIRST_AND_LAST_ROW,
796   GADGET_ID_BD_SHORT_EXPLOSIONS,
797   GADGET_ID_STICK_ELEMENT,
798   GADGET_ID_EM_SLIPPERY_GEMS,
799   GADGET_ID_EM_EXPLODES_BY_FIRE,
800   GADGET_ID_USE_SPRING_BUG,
801   GADGET_ID_USE_TIME_ORB_BUG,
802   GADGET_ID_USE_LIFE_BUGS,
803   GADGET_ID_RANDOM_BALL_CONTENT,
804   GADGET_ID_INITIAL_BALL_ACTIVE,
805   GADGET_ID_GROW_INTO_DIGGABLE,
806   GADGET_ID_SB_FIELDS_NEEDED,
807   GADGET_ID_SB_OBJECTS_NEEDED,
808   GADGET_ID_AUTO_EXIT_SOKOBAN,
809   GADGET_ID_SOLVED_BY_ONE_PLAYER,
810   GADGET_ID_FINISH_DIG_COLLECT,
811   GADGET_ID_KEEP_WALKABLE_CE,
812   GADGET_ID_CONTINUOUS_SNAPPING,
813   GADGET_ID_BLOCK_SNAP_FIELD,
814   GADGET_ID_BLOCK_LAST_FIELD,
815   GADGET_ID_SP_BLOCK_LAST_FIELD,
816   GADGET_ID_INSTANT_RELOCATION,
817   GADGET_ID_SHIFTED_RELOCATION,
818   GADGET_ID_LAZY_RELOCATION,
819   GADGET_ID_USE_START_ELEMENT,
820   GADGET_ID_USE_ARTWORK_ELEMENT,
821   GADGET_ID_USE_EXPLOSION_ELEMENT,
822   GADGET_ID_INITIAL_GRAVITY,
823   GADGET_ID_USE_INITIAL_INVENTORY,
824   GADGET_ID_CAN_PASS_TO_WALKABLE,
825   GADGET_ID_CAN_FALL_INTO_ACID,
826   GADGET_ID_CAN_MOVE_INTO_ACID,
827   GADGET_ID_DONT_COLLIDE_WITH,
828   GADGET_ID_BD_DIAGONAL_MOVEMENTS,
829   GADGET_ID_BD_TOPMOST_PLAYER_ACTIVE,
830   GADGET_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET,
831   GADGET_ID_BD_MAGIC_WALL_ZERO_INFINITE,
832   GADGET_ID_BD_MAGIC_WALL_WAIT_HATCHING,
833   GADGET_ID_BD_MAGIC_WALL_STOPS_AMOEBA,
834   GADGET_ID_BD_MAGIC_WALL_BREAK_SCAN,
835   GADGET_ID_BD_AMOEBA_WAIT_FOR_HATCHING,
836   GADGET_ID_BD_AMOEBA_START_IMMEDIATELY,
837   GADGET_ID_BD_AMOEBA_2_EXPLODE_BY_AMOEBA,
838   GADGET_ID_BD_VOODOO_COLLECTS_DIAMONDS,
839   GADGET_ID_BD_VOODOO_HURT_KILLS_PLAYER,
840   GADGET_ID_BD_VOODOO_DIES_BY_ROCK,
841   GADGET_ID_BD_VOODOO_VANISH_BY_EXPLOSION,
842   GADGET_ID_BD_SLIME_IS_PREDICTABLE,
843   GADGET_ID_BD_CHANGE_EXPANDING_WALL,
844   GADGET_ID_BD_REPLICATORS_ACTIVE,
845   GADGET_ID_BD_CONVEYOR_BELTS_ACTIVE,
846   GADGET_ID_BD_CONVEYOR_BELTS_CHANGED,
847   GADGET_ID_BD_WATER_CANNOT_FLOW_DOWN,
848   GADGET_ID_BD_HAMMER_WALLS_REAPPEAR,
849   GADGET_ID_BD_INFINITE_ROCKETS,
850   GADGET_ID_BD_CREATURES_START_BACKWARDS,
851   GADGET_ID_BD_CREATURES_TURN_ON_HATCHING,
852   GADGET_ID_BD_GRAVITY_SWITCH_ACTIVE,
853   GADGET_ID_BD_GRAVITY_AFFECTS_ALL,
854   GADGET_ID_ENVELOPE_AUTOWRAP,
855   GADGET_ID_ENVELOPE_CENTERED,
856   GADGET_ID_MM_LASER_RED,
857   GADGET_ID_MM_LASER_GREEN,
858   GADGET_ID_MM_LASER_BLUE,
859   GADGET_ID_DF_LASER_RED,
860   GADGET_ID_DF_LASER_GREEN,
861   GADGET_ID_DF_LASER_BLUE,
862   GADGET_ID_ROTATE_MM_BALL_CONTENT,
863   GADGET_ID_EXPLODE_MM_BALL,
864   GADGET_ID_CUSTOM_INDESTRUCTIBLE,
865   GADGET_ID_CUSTOM_CAN_EXPLODE,
866   GADGET_ID_CUSTOM_EXPLODE_FIRE,
867   GADGET_ID_CUSTOM_EXPLODE_SMASH,
868   GADGET_ID_CUSTOM_EXPLODE_IMPACT,
869   GADGET_ID_CUSTOM_WALK_TO_OBJECT,
870   GADGET_ID_CUSTOM_DEADLY,
871   GADGET_ID_CUSTOM_CAN_MOVE,
872   GADGET_ID_CUSTOM_CAN_FALL,
873   GADGET_ID_CUSTOM_CAN_SMASH,
874   GADGET_ID_CUSTOM_SLIPPERY,
875   GADGET_ID_CUSTOM_ACCESSIBLE,
876   GADGET_ID_CUSTOM_GRAV_REACHABLE,
877   GADGET_ID_CUSTOM_USE_LAST_VALUE,
878   GADGET_ID_CUSTOM_USE_GRAPHIC,
879   GADGET_ID_CUSTOM_USE_TEMPLATE_1,
880   GADGET_ID_CUSTOM_USE_TEMPLATE_2,
881   GADGET_ID_CUSTOM_USE_TEMPLATE_3,
882   GADGET_ID_CUSTOM_CAN_CHANGE,
883   GADGET_ID_CHANGE_USE_CONTENT,
884   GADGET_ID_CHANGE_USE_EXPLOSION,
885   GADGET_ID_CHANGE_ONLY_COMPLETE,
886   GADGET_ID_CHANGE_USE_RANDOM,
887   GADGET_ID_CHANGE_HAS_ACTION,
888   GADGET_ID_CHANGE_DELAY,
889   GADGET_ID_CHANGE_BY_DIRECT_ACT,
890   GADGET_ID_CHANGE_BY_OTHER_ACT,
891
892   NUM_STATIC_GADGET_IDS
893 };
894
895 // gadgets for buttons in element list (dynamic)
896 #define GADGET_ID_ELEMENTLIST_FIRST     (NUM_STATIC_GADGET_IDS)
897 #define GADGET_ID_ELEMENTLIST_LAST      (GADGET_ID_ELEMENTLIST_FIRST +  \
898                                         ED_NUM_ELEMENTLIST_BUTTONS - 1)
899
900 #define NUM_EDITOR_GADGETS              (GADGET_ID_ELEMENTLIST_LAST + 1)
901
902 // radio button numbers
903 enum
904 {
905   RADIO_NR_NONE,
906   RADIO_NR_DRAWING_TOOLBOX,
907   RADIO_NR_RANDOM_ELEMENTS
908 };
909
910 // values for counter gadgets
911 enum
912 {
913   ED_COUNTER_ID_SELECT_LEVEL,
914   ED_COUNTER_ID_LEVEL_XSIZE,
915   ED_COUNTER_ID_LEVEL_YSIZE,
916   ED_COUNTER_ID_LEVEL_GEMSLIMIT,
917   ED_COUNTER_ID_LEVEL_TIMELIMIT,
918   ED_COUNTER_ID_LEVEL_TIMESCORE,
919   ED_COUNTER_ID_LEVEL_RANDOM_SEED,
920   ED_COUNTER_ID_LEVELSET_NUM_LEVELS,
921   ED_COUNTER_ID_LEVEL_RANDOM,
922   ED_COUNTER_ID_BD_CYCLE_DELAY_MS,
923   ED_COUNTER_ID_BD_CYCLE_DELAY_C64,
924   ED_COUNTER_ID_BD_HATCHING_DELAY_CYCLES,
925   ED_COUNTER_ID_BD_HATCHING_DELAY_SECONDS,
926   ED_COUNTER_ID_BD_PUSHING_PROB,
927   ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET,
928   ED_COUNTER_ID_ELEMENT_VALUE1,
929   ED_COUNTER_ID_ELEMENT_VALUE2,
930   ED_COUNTER_ID_ELEMENT_VALUE3,
931   ED_COUNTER_ID_ELEMENT_VALUE4,
932   ED_COUNTER_ID_YAMYAM_CONTENT,
933   ED_COUNTER_ID_BALL_CONTENT,
934   ED_COUNTER_ID_ANDROID_CONTENT,
935   ED_COUNTER_ID_ENVELOPE_XSIZE,
936   ED_COUNTER_ID_ENVELOPE_YSIZE,
937   ED_COUNTER_ID_INVENTORY_SIZE,
938   ED_COUNTER_ID_MM_BALL_CONTENT,
939   ED_COUNTER_ID_CUSTOM_SCORE,
940   ED_COUNTER_ID_CUSTOM_GEMCOUNT,
941   ED_COUNTER_ID_CUSTOM_VALUE_FIX,
942   ED_COUNTER_ID_CUSTOM_VALUE_RND,
943   ED_COUNTER_ID_PUSH_DELAY_FIX,
944   ED_COUNTER_ID_PUSH_DELAY_RND,
945   ED_COUNTER_ID_DROP_DELAY_FIX,
946   ED_COUNTER_ID_DROP_DELAY_RND,
947   ED_COUNTER_ID_MOVE_DELAY_FIX,
948   ED_COUNTER_ID_MOVE_DELAY_RND,
949   ED_COUNTER_ID_STEP_DELAY_FIX,
950   ED_COUNTER_ID_STEP_DELAY_RND,
951   ED_COUNTER_ID_EXPLOSION_DELAY,
952   ED_COUNTER_ID_IGNITION_DELAY,
953   ED_COUNTER_ID_GROUP_CONTENT,
954   ED_COUNTER_ID_CHANGE_DELAY_FIX,
955   ED_COUNTER_ID_CHANGE_DELAY_RND,
956   ED_COUNTER_ID_CHANGE_CONT_RND,
957
958   ED_NUM_COUNTERBUTTONS
959 };
960
961 #define ED_COUNTER_ID_LEVEL_FIRST       ED_COUNTER_ID_LEVEL_XSIZE
962 #define ED_COUNTER_ID_LEVEL_LAST        ED_COUNTER_ID_LEVEL_RANDOM_SEED
963 #define ED_COUNTER_ID_LEVELSET_FIRST    ED_COUNTER_ID_LEVELSET_NUM_LEVELS
964 #define ED_COUNTER_ID_LEVELSET_LAST     ED_COUNTER_ID_LEVELSET_NUM_LEVELS
965 #define ED_COUNTER_ID_EDITOR_FIRST      ED_COUNTER_ID_LEVEL_RANDOM
966 #define ED_COUNTER_ID_EDITOR_LAST       ED_COUNTER_ID_LEVEL_RANDOM
967
968 #define ED_COUNTER_ID_CUSTOM1_FIRST     ED_COUNTER_ID_CUSTOM_SCORE
969 #define ED_COUNTER_ID_CUSTOM1_LAST      ED_COUNTER_ID_DROP_DELAY_RND
970 #define ED_COUNTER_ID_CUSTOM2_FIRST     ED_COUNTER_ID_MOVE_DELAY_FIX
971 #define ED_COUNTER_ID_CUSTOM2_LAST      ED_COUNTER_ID_IGNITION_DELAY
972 #define ED_COUNTER_ID_CUSTOM_FIRST      ED_COUNTER_ID_CUSTOM1_FIRST
973 #define ED_COUNTER_ID_CUSTOM_LAST       ED_COUNTER_ID_CUSTOM2_LAST
974
975 #define ED_COUNTER_ID_CHANGE_FIRST      ED_COUNTER_ID_CHANGE_DELAY_FIX
976 #define ED_COUNTER_ID_CHANGE_LAST       ED_COUNTER_ID_CHANGE_CONT_RND
977
978 // values for scrollbutton gadgets
979 enum
980 {
981   ED_SCROLLBUTTON_ID_AREA_UP,
982   ED_SCROLLBUTTON_ID_AREA_DOWN,
983   ED_SCROLLBUTTON_ID_AREA_LEFT,
984   ED_SCROLLBUTTON_ID_AREA_RIGHT,
985   ED_SCROLLBUTTON_ID_LIST_UP,
986   ED_SCROLLBUTTON_ID_LIST_DOWN,
987
988   ED_NUM_SCROLLBUTTONS
989 };
990
991 #define ED_SCROLLBUTTON_ID_AREA_FIRST   ED_SCROLLBUTTON_ID_AREA_UP
992 #define ED_SCROLLBUTTON_ID_AREA_LAST    ED_SCROLLBUTTON_ID_AREA_RIGHT
993
994 // values for scrollbar gadgets
995 enum
996 {
997   ED_SCROLLBAR_ID_AREA_HORIZONTAL,
998   ED_SCROLLBAR_ID_AREA_VERTICAL,
999   ED_SCROLLBAR_ID_LIST_VERTICAL,
1000
1001   ED_NUM_SCROLLBARS
1002 };
1003
1004 #define ED_SCROLLBAR_ID_AREA_FIRST      ED_SCROLLBAR_ID_AREA_HORIZONTAL
1005 #define ED_SCROLLBAR_ID_AREA_LAST       ED_SCROLLBAR_ID_AREA_VERTICAL
1006
1007 // values for text input gadgets
1008 enum
1009 {
1010   ED_TEXTINPUT_ID_LEVEL_NAME,
1011   ED_TEXTINPUT_ID_LEVEL_AUTHOR,
1012   ED_TEXTINPUT_ID_LEVELSET_NAME,
1013   ED_TEXTINPUT_ID_LEVELSET_AUTHOR,
1014   ED_TEXTINPUT_ID_BD_COLOR_TEXT_B,
1015   ED_TEXTINPUT_ID_BD_COLOR_TEXT_0,
1016   ED_TEXTINPUT_ID_BD_COLOR_TEXT_1,
1017   ED_TEXTINPUT_ID_BD_COLOR_TEXT_2,
1018   ED_TEXTINPUT_ID_BD_COLOR_TEXT_3,
1019   ED_TEXTINPUT_ID_BD_COLOR_TEXT_4,
1020   ED_TEXTINPUT_ID_BD_COLOR_TEXT_5,
1021   ED_TEXTINPUT_ID_ELEMENT_NAME,
1022
1023   ED_NUM_TEXTINPUT
1024 };
1025
1026 #define ED_TEXTINPUT_ID_LEVEL_FIRST     ED_TEXTINPUT_ID_LEVEL_NAME
1027 #define ED_TEXTINPUT_ID_LEVEL_LAST      ED_TEXTINPUT_ID_LEVEL_AUTHOR
1028
1029 #define ED_TEXTINPUT_ID_LEVELSET_FIRST  ED_TEXTINPUT_ID_LEVELSET_NAME
1030 #define ED_TEXTINPUT_ID_LEVELSET_LAST   ED_TEXTINPUT_ID_LEVELSET_AUTHOR
1031
1032 #define ED_TEXTINPUT_ID_COLORS_FIRST    ED_TEXTINPUT_ID_BD_COLOR_TEXT_B
1033 #define ED_TEXTINPUT_ID_COLORS_LAST     ED_TEXTINPUT_ID_BD_COLOR_TEXT_5
1034
1035 // values for text area gadgets
1036 enum
1037 {
1038   ED_TEXTAREA_ID_ENVELOPE_INFO,
1039
1040   ED_NUM_TEXTAREAS
1041 };
1042
1043 #define ED_TEXTAREA_ID_LEVEL_FIRST      ED_TEXTAREA_ID_ENVELOPE
1044 #define ED_TEXTAREA_ID_LEVEL_LAST       ED_TEXTAREA_ID_ENVELOPE
1045
1046 // values for selectbox gadgets
1047 enum
1048 {
1049   ED_SELECTBOX_ID_TIME_OR_STEPS,
1050   ED_SELECTBOX_ID_TIME_SCORE_BASE,
1051   ED_SELECTBOX_ID_GAME_ENGINE_TYPE,
1052   ED_SELECTBOX_ID_LEVELSET_SAVE_MODE,
1053   ED_SELECTBOX_ID_BD_SCHEDULING_TYPE,
1054   ED_SELECTBOX_ID_BD_COLOR_TYPE,
1055   ED_SELECTBOX_ID_BD_COLOR_C64_B,
1056   ED_SELECTBOX_ID_BD_COLOR_C64_0,
1057   ED_SELECTBOX_ID_BD_COLOR_C64_1,
1058   ED_SELECTBOX_ID_BD_COLOR_C64_2,
1059   ED_SELECTBOX_ID_BD_COLOR_C64_3,
1060   ED_SELECTBOX_ID_BD_COLOR_C64_4,
1061   ED_SELECTBOX_ID_BD_COLOR_C64_5,
1062   ED_SELECTBOX_ID_WIND_DIRECTION,
1063   ED_SELECTBOX_ID_PLAYER_SPEED,
1064   ED_SELECTBOX_ID_BD_GRAVITY_DIRECTION,
1065   ED_SELECTBOX_ID_MM_BALL_CHOICE_MODE,
1066   ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE,
1067   ED_SELECTBOX_ID_CUSTOM_ACCESS_LAYER,
1068   ED_SELECTBOX_ID_CUSTOM_ACCESS_PROTECTED,
1069   ED_SELECTBOX_ID_CUSTOM_ACCESS_DIRECTION,
1070   ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION,
1071   ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN,
1072   ED_SELECTBOX_ID_CUSTOM_MOVE_DIRECTION,
1073   ED_SELECTBOX_ID_CUSTOM_MOVE_STEPSIZE,
1074   ED_SELECTBOX_ID_CUSTOM_MOVE_LEAVE_TYPE,
1075   ED_SELECTBOX_ID_CUSTOM_SMASH_TARGETS,
1076   ED_SELECTBOX_ID_CUSTOM_SLIPPERY_TYPE,
1077   ED_SELECTBOX_ID_CUSTOM_DEADLINESS,
1078   ED_SELECTBOX_ID_CUSTOM_EXPLOSION_TYPE,
1079   ED_SELECTBOX_ID_CHANGE_TIME_UNITS,
1080   ED_SELECTBOX_ID_CHANGE_DIRECT_ACTION,
1081   ED_SELECTBOX_ID_CHANGE_OTHER_ACTION,
1082   ED_SELECTBOX_ID_CHANGE_SIDE,
1083   ED_SELECTBOX_ID_CHANGE_PLAYER,
1084   ED_SELECTBOX_ID_CHANGE_PAGE,
1085   ED_SELECTBOX_ID_CHANGE_REPLACE_WHEN,
1086   ED_SELECTBOX_ID_ACTION_TYPE,
1087   ED_SELECTBOX_ID_ACTION_MODE,
1088   ED_SELECTBOX_ID_ACTION_ARG,
1089   ED_SELECTBOX_ID_SELECT_CHANGE_PAGE,
1090   ED_SELECTBOX_ID_GROUP_CHOICE_MODE,
1091
1092   ED_NUM_SELECTBOX
1093 };
1094
1095 #define ED_SELECTBOX_ID_LEVEL_FIRST     ED_SELECTBOX_ID_TIME_OR_STEPS
1096 #define ED_SELECTBOX_ID_LEVEL_LAST      ED_SELECTBOX_ID_GAME_ENGINE_TYPE
1097
1098 #define ED_SELECTBOX_ID_LEVELSET_FIRST  ED_SELECTBOX_ID_LEVELSET_SAVE_MODE
1099 #define ED_SELECTBOX_ID_LEVELSET_LAST   ED_SELECTBOX_ID_LEVELSET_SAVE_MODE
1100
1101 #define ED_SELECTBOX_ID_ENGINE_FIRST    ED_SELECTBOX_ID_BD_SCHEDULING_TYPE
1102 #define ED_SELECTBOX_ID_ENGINE_LAST     ED_SELECTBOX_ID_BD_SCHEDULING_TYPE
1103
1104 #define ED_SELECTBOX_ID_COLORS_FIRST    ED_SELECTBOX_ID_BD_COLOR_C64_B
1105 #define ED_SELECTBOX_ID_COLORS_LAST     ED_SELECTBOX_ID_BD_COLOR_C64_5
1106
1107 #define ED_SELECTBOX_ID_CUSTOM1_FIRST   ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE
1108 #define ED_SELECTBOX_ID_CUSTOM1_LAST    ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION
1109 #define ED_SELECTBOX_ID_CUSTOM2_FIRST   ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN
1110 #define ED_SELECTBOX_ID_CUSTOM2_LAST    ED_SELECTBOX_ID_CUSTOM_EXPLOSION_TYPE
1111 #define ED_SELECTBOX_ID_CUSTOM_FIRST    ED_SELECTBOX_ID_CUSTOM1_FIRST
1112 #define ED_SELECTBOX_ID_CUSTOM_LAST     ED_SELECTBOX_ID_CUSTOM2_LAST
1113
1114 #define ED_SELECTBOX_ID_CHANGE_FIRST    ED_SELECTBOX_ID_CHANGE_TIME_UNITS
1115 #define ED_SELECTBOX_ID_CHANGE_LAST     ED_SELECTBOX_ID_SELECT_CHANGE_PAGE
1116
1117 // values for textbutton gadgets
1118 enum
1119 {
1120   ED_TEXTBUTTON_ID_LEVELCONFIG_LEVEL,
1121   ED_TEXTBUTTON_ID_LEVELCONFIG_LEVELSET,
1122   ED_TEXTBUTTON_ID_LEVELCONFIG_EDITOR,
1123   ED_TEXTBUTTON_ID_LEVELCONFIG_ENGINE,
1124   ED_TEXTBUTTON_ID_ENGINECONFIG_CONFIG,
1125   ED_TEXTBUTTON_ID_ENGINECONFIG_COLORS,
1126   ED_TEXTBUTTON_ID_PROPERTIES_INFO,
1127   ED_TEXTBUTTON_ID_PROPERTIES_CONFIG,
1128   ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_1,
1129   ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2,
1130   ED_TEXTBUTTON_ID_PROPERTIES_CHANGE,
1131   ED_TEXTBUTTON_ID_SAVE_LEVELSET,
1132   ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_2,
1133   ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1,
1134   ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE,
1135   ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE,
1136   ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS,
1137
1138   ED_NUM_TEXTBUTTONS
1139 };
1140
1141 #define ED_TAB_BUTTON_ID_LEVELCONFIG_FIRST ED_TEXTBUTTON_ID_LEVELCONFIG_LEVEL
1142 #define ED_TAB_BUTTON_ID_LEVELCONFIG_LAST  ED_TEXTBUTTON_ID_LEVELCONFIG_ENGINE
1143
1144 #define ED_TAB_BUTTON_ID_ENGINECONFIG_FIRST ED_TEXTBUTTON_ID_ENGINECONFIG_CONFIG
1145 #define ED_TAB_BUTTON_ID_ENGINECONFIG_LAST  ED_TEXTBUTTON_ID_ENGINECONFIG_COLORS
1146
1147 #define ED_TAB_BUTTON_ID_PROPERTIES_FIRST ED_TEXTBUTTON_ID_PROPERTIES_INFO
1148 #define ED_TAB_BUTTON_ID_PROPERTIES_LAST  ED_TEXTBUTTON_ID_PROPERTIES_CHANGE
1149
1150 #define ED_TEXTBUTTON_ID_CHANGE_FIRST   ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE
1151 #define ED_TEXTBUTTON_ID_CHANGE_LAST    ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE
1152
1153 // values for graphicbutton gadgets
1154 enum
1155 {
1156   ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE,
1157   ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE,
1158   ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE,
1159   ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE,
1160
1161   ED_NUM_GRAPHICBUTTONS
1162 };
1163
1164 #define ED_GRAPHICBUTTON_ID_CHANGE_FIRST  ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE
1165 #define ED_GRAPHICBUTTON_ID_CHANGE_LAST   ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE
1166
1167 // values for checkbutton gadgets
1168 enum
1169 {
1170   ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS,
1171   ED_CHECKBUTTON_ID_RATE_TIME_OVER_SCORE,
1172   ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK,
1173   ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE,
1174   ED_CHECKBUTTON_ID_RANDOM_RESTRICTED,
1175   ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_3,
1176   ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_2,
1177   ED_CHECKBUTTON_ID_BD_INTERMISSION,
1178   ED_CHECKBUTTON_ID_BD_PAL_TIMING,
1179   ED_CHECKBUTTON_ID_BD_LINE_SHIFTING_BORDERS,
1180   ED_CHECKBUTTON_ID_BD_SCAN_FIRST_AND_LAST_ROW,
1181   ED_CHECKBUTTON_ID_BD_SHORT_EXPLOSIONS,
1182   ED_CHECKBUTTON_ID_STICK_ELEMENT,
1183   ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS,
1184   ED_CHECKBUTTON_ID_EM_EXPLODES_BY_FIRE,
1185   ED_CHECKBUTTON_ID_USE_SPRING_BUG,
1186   ED_CHECKBUTTON_ID_USE_TIME_ORB_BUG,
1187   ED_CHECKBUTTON_ID_USE_LIFE_BUGS,
1188   ED_CHECKBUTTON_ID_RANDOM_BALL_CONTENT,
1189   ED_CHECKBUTTON_ID_INITIAL_BALL_ACTIVE,
1190   ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE,
1191   ED_CHECKBUTTON_ID_SB_FIELDS_NEEDED,
1192   ED_CHECKBUTTON_ID_SB_OBJECTS_NEEDED,
1193   ED_CHECKBUTTON_ID_AUTO_EXIT_SOKOBAN,
1194   ED_CHECKBUTTON_ID_SOLVED_BY_ONE_PLAYER,
1195   ED_CHECKBUTTON_ID_FINISH_DIG_COLLECT,
1196   ED_CHECKBUTTON_ID_KEEP_WALKABLE_CE,
1197   ED_CHECKBUTTON_ID_CONTINUOUS_SNAPPING,
1198   ED_CHECKBUTTON_ID_BLOCK_SNAP_FIELD,
1199   ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD,
1200   ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD,
1201   ED_CHECKBUTTON_ID_INSTANT_RELOCATION,
1202   ED_CHECKBUTTON_ID_SHIFTED_RELOCATION,
1203   ED_CHECKBUTTON_ID_LAZY_RELOCATION,
1204   ED_CHECKBUTTON_ID_USE_START_ELEMENT,
1205   ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT,
1206   ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT,
1207   ED_CHECKBUTTON_ID_INITIAL_GRAVITY,
1208   ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY,
1209   ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE,
1210   ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID,
1211   ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID,
1212   ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH,
1213   ED_CHECKBUTTON_ID_BD_DIAGONAL_MOVEMENTS,
1214   ED_CHECKBUTTON_ID_BD_TOPMOST_PLAYER_ACTIVE,
1215   ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET,
1216   ED_CHECKBUTTON_ID_BD_MAGIC_WALL_ZERO_INFINITE,
1217   ED_CHECKBUTTON_ID_BD_MAGIC_WALL_WAIT_HATCHING,
1218   ED_CHECKBUTTON_ID_BD_MAGIC_WALL_STOPS_AMOEBA,
1219   ED_CHECKBUTTON_ID_BD_MAGIC_WALL_BREAK_SCAN,
1220   ED_CHECKBUTTON_ID_BD_AMOEBA_WAIT_FOR_HATCHING,
1221   ED_CHECKBUTTON_ID_BD_AMOEBA_START_IMMEDIATELY,
1222   ED_CHECKBUTTON_ID_BD_AMOEBA_2_EXPLODE_BY_AMOEBA,
1223   ED_CHECKBUTTON_ID_BD_VOODOO_COLLECTS_DIAMONDS,
1224   ED_CHECKBUTTON_ID_BD_VOODOO_HURT_KILLS_PLAYER,
1225   ED_CHECKBUTTON_ID_BD_VOODOO_DIES_BY_ROCK,
1226   ED_CHECKBUTTON_ID_BD_VOODOO_VANISH_BY_EXPLOSION,
1227   ED_CHECKBUTTON_ID_BD_SLIME_IS_PREDICTABLE,
1228   ED_CHECKBUTTON_ID_BD_CHANGE_EXPANDING_WALL,
1229   ED_CHECKBUTTON_ID_BD_REPLICATORS_ACTIVE,
1230   ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_ACTIVE,
1231   ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_CHANGED,
1232   ED_CHECKBUTTON_ID_BD_WATER_CANNOT_FLOW_DOWN,
1233   ED_CHECKBUTTON_ID_BD_HAMMER_WALLS_REAPPEAR,
1234   ED_CHECKBUTTON_ID_BD_INFINITE_ROCKETS,
1235   ED_CHECKBUTTON_ID_BD_CREATURES_START_BACKWARDS,
1236   ED_CHECKBUTTON_ID_BD_CREATURES_TURN_ON_HATCHING,
1237   ED_CHECKBUTTON_ID_BD_GRAVITY_SWITCH_ACTIVE,
1238   ED_CHECKBUTTON_ID_BD_GRAVITY_AFFECTS_ALL,
1239   ED_CHECKBUTTON_ID_ENVELOPE_AUTOWRAP,
1240   ED_CHECKBUTTON_ID_ENVELOPE_CENTERED,
1241   ED_CHECKBUTTON_ID_MM_LASER_RED,
1242   ED_CHECKBUTTON_ID_MM_LASER_GREEN,
1243   ED_CHECKBUTTON_ID_MM_LASER_BLUE,
1244   ED_CHECKBUTTON_ID_DF_LASER_RED,
1245   ED_CHECKBUTTON_ID_DF_LASER_GREEN,
1246   ED_CHECKBUTTON_ID_DF_LASER_BLUE,
1247   ED_CHECKBUTTON_ID_ROTATE_MM_BALL_CONTENT,
1248   ED_CHECKBUTTON_ID_EXPLODE_MM_BALL,
1249   ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC,
1250   ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1,
1251   ED_CHECKBUTTON_ID_CUSTOM_ACCESSIBLE,
1252   ED_CHECKBUTTON_ID_CUSTOM_GRAV_REACHABLE,
1253   ED_CHECKBUTTON_ID_CUSTOM_USE_LAST_VALUE,
1254   ED_CHECKBUTTON_ID_CUSTOM_WALK_TO_OBJECT,
1255   ED_CHECKBUTTON_ID_CUSTOM_INDESTRUCTIBLE,
1256   ED_CHECKBUTTON_ID_CUSTOM_CAN_MOVE,
1257   ED_CHECKBUTTON_ID_CUSTOM_CAN_FALL,
1258   ED_CHECKBUTTON_ID_CUSTOM_CAN_SMASH,
1259   ED_CHECKBUTTON_ID_CUSTOM_SLIPPERY,
1260   ED_CHECKBUTTON_ID_CUSTOM_DEADLY,
1261   ED_CHECKBUTTON_ID_CUSTOM_CAN_EXPLODE,
1262   ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_FIRE,
1263   ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_SMASH,
1264   ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT,
1265   ED_CHECKBUTTON_ID_CUSTOM_CAN_CHANGE,
1266   ED_CHECKBUTTON_ID_CHANGE_DELAY,
1267   ED_CHECKBUTTON_ID_CHANGE_BY_DIRECT_ACT,
1268   ED_CHECKBUTTON_ID_CHANGE_BY_OTHER_ACT,
1269   ED_CHECKBUTTON_ID_CHANGE_USE_EXPLOSION,
1270   ED_CHECKBUTTON_ID_CHANGE_USE_CONTENT,
1271   ED_CHECKBUTTON_ID_CHANGE_ONLY_COMPLETE,
1272   ED_CHECKBUTTON_ID_CHANGE_USE_RANDOM,
1273   ED_CHECKBUTTON_ID_CHANGE_HAS_ACTION,
1274
1275   ED_NUM_CHECKBUTTONS
1276 };
1277
1278 #define ED_CHECKBUTTON_ID_LEVEL_FIRST   ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS
1279 #define ED_CHECKBUTTON_ID_LEVEL_LAST    ED_CHECKBUTTON_ID_RATE_TIME_OVER_SCORE
1280
1281 #define ED_CHECKBUTTON_ID_LEVELSET_FIRST ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK
1282 #define ED_CHECKBUTTON_ID_LEVELSET_LAST  ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE
1283
1284 #define ED_CHECKBUTTON_ID_EDITOR_FIRST  ED_CHECKBUTTON_ID_RANDOM_RESTRICTED
1285 #define ED_CHECKBUTTON_ID_EDITOR_LAST   ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_2
1286
1287 #define ED_CHECKBUTTON_ID_ENGINE_FIRST  ED_CHECKBUTTON_ID_BD_INTERMISSION
1288 #define ED_CHECKBUTTON_ID_ENGINE_LAST   ED_CHECKBUTTON_ID_BD_SHORT_EXPLOSIONS
1289
1290 #define ED_CHECKBUTTON_ID_CUSTOM1_FIRST ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC
1291 #define ED_CHECKBUTTON_ID_CUSTOM1_LAST  ED_CHECKBUTTON_ID_CUSTOM_INDESTRUCTIBLE
1292 #define ED_CHECKBUTTON_ID_CUSTOM2_FIRST ED_CHECKBUTTON_ID_CUSTOM_CAN_MOVE
1293 #define ED_CHECKBUTTON_ID_CUSTOM2_LAST  ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT
1294 #define ED_CHECKBUTTON_ID_CUSTOM_FIRST  ED_CHECKBUTTON_ID_CUSTOM1_FIRST
1295 #define ED_CHECKBUTTON_ID_CUSTOM_LAST   ED_CHECKBUTTON_ID_CUSTOM2_LAST
1296
1297 #define ED_CHECKBUTTON_ID_CHANGE_FIRST  ED_CHECKBUTTON_ID_CUSTOM_CAN_CHANGE
1298 #define ED_CHECKBUTTON_ID_CHANGE_LAST   ED_CHECKBUTTON_ID_CHANGE_HAS_ACTION
1299
1300 // values for radiobutton gadgets
1301 enum
1302 {
1303   ED_RADIOBUTTON_ID_PERCENTAGE,
1304   ED_RADIOBUTTON_ID_QUANTITY,
1305
1306   ED_NUM_RADIOBUTTONS
1307 };
1308
1309 #define ED_RADIOBUTTON_ID_EDITOR_FIRST  ED_RADIOBUTTON_ID_PERCENTAGE
1310 #define ED_RADIOBUTTON_ID_EDITOR_LAST   ED_RADIOBUTTON_ID_QUANTITY
1311
1312 // values for drawing area gadgets
1313 enum
1314 {
1315   ED_DRAWING_ID_DRAWING_LEVEL,
1316   ED_DRAWING_ID_YAMYAM_CONTENT_0,
1317   ED_DRAWING_ID_YAMYAM_CONTENT_1,
1318   ED_DRAWING_ID_YAMYAM_CONTENT_2,
1319   ED_DRAWING_ID_YAMYAM_CONTENT_3,
1320   ED_DRAWING_ID_YAMYAM_CONTENT_4,
1321   ED_DRAWING_ID_YAMYAM_CONTENT_5,
1322   ED_DRAWING_ID_YAMYAM_CONTENT_6,
1323   ED_DRAWING_ID_YAMYAM_CONTENT_7,
1324   ED_DRAWING_ID_MAGIC_BALL_CONTENT_0,
1325   ED_DRAWING_ID_MAGIC_BALL_CONTENT_1,
1326   ED_DRAWING_ID_MAGIC_BALL_CONTENT_2,
1327   ED_DRAWING_ID_MAGIC_BALL_CONTENT_3,
1328   ED_DRAWING_ID_MAGIC_BALL_CONTENT_4,
1329   ED_DRAWING_ID_MAGIC_BALL_CONTENT_5,
1330   ED_DRAWING_ID_MAGIC_BALL_CONTENT_6,
1331   ED_DRAWING_ID_MAGIC_BALL_CONTENT_7,
1332   ED_DRAWING_ID_ANDROID_CONTENT,
1333   ED_DRAWING_ID_AMOEBA_CONTENT,
1334   ED_DRAWING_ID_BD_SNAP_ELEMENT,
1335   ED_DRAWING_ID_BD_MAGIC_WALL_DIAMOND_TO,
1336   ED_DRAWING_ID_BD_MAGIC_WALL_ROCK_TO,
1337   ED_DRAWING_ID_BD_MAGIC_WALL_MEGA_ROCK_TO,
1338   ED_DRAWING_ID_BD_MAGIC_WALL_NUT_TO,
1339   ED_DRAWING_ID_BD_MAGIC_WALL_NITRO_PACK_TO,
1340   ED_DRAWING_ID_BD_MAGIC_WALL_FLYING_DIAMOND_TO,
1341   ED_DRAWING_ID_BD_MAGIC_WALL_FLYING_ROCK_TO,
1342   ED_DRAWING_ID_BD_AMOEBA_CONTENT_TOO_BIG,
1343   ED_DRAWING_ID_BD_AMOEBA_CONTENT_ENCLOSED,
1344   ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_TOO_BIG,
1345   ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_ENCLOSED,
1346   ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_EXPLODING,
1347   ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_LOOKS_LIKE,
1348   ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_1,
1349   ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_1,
1350   ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_2,
1351   ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_2,
1352   ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_3,
1353   ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_3,
1354   ED_DRAWING_ID_BD_ACID_EATS_ELEMENT,
1355   ED_DRAWING_ID_BD_ACID_TURNS_TO_ELEMENT,
1356   ED_DRAWING_ID_BD_BITER_EATS_ELEMENT,
1357   ED_DRAWING_ID_BD_BLADDER_CONVERTS_BY_ELEMENT,
1358   ED_DRAWING_ID_BD_NUT_CONTENT,
1359   ED_DRAWING_ID_BD_EXPANDING_WALL_LOOKS_LIKE,
1360   ED_DRAWING_ID_BD_SAND_LOOKS_LIKE,
1361   ED_DRAWING_ID_BD_ROCK_TURNS_TO_ON_FALLING,
1362   ED_DRAWING_ID_BD_ROCK_TURNS_TO_ON_IMPACT,
1363   ED_DRAWING_ID_BD_DIAMOND_TURNS_TO_ON_FALLING,
1364   ED_DRAWING_ID_BD_DIAMOND_TURNS_TO_ON_IMPACT,
1365   ED_DRAWING_ID_BD_FIREFLY_EXPLODES_TO,
1366   ED_DRAWING_ID_BD_FIREFLY_2_EXPLODES_TO,
1367   ED_DRAWING_ID_BD_BUTTERFLY_EXPLODES_TO,
1368   ED_DRAWING_ID_BD_BUTTERFLY_2_EXPLODES_TO,
1369   ED_DRAWING_ID_BD_STONEFLY_EXPLODES_TO,
1370   ED_DRAWING_ID_BD_DRAGONFLY_EXPLODES_TO,
1371   ED_DRAWING_ID_BD_DIAMOND_BIRTH_TURNS_TO,
1372   ED_DRAWING_ID_BD_BOMB_EXPLOSION_TURNS_TO,
1373   ED_DRAWING_ID_BD_NITRO_EXPLOSION_TURNS_TO,
1374   ED_DRAWING_ID_BD_EXPLOSION_TURNS_TO,
1375   ED_DRAWING_ID_START_ELEMENT,
1376   ED_DRAWING_ID_ARTWORK_ELEMENT,
1377   ED_DRAWING_ID_EXPLOSION_ELEMENT,
1378   ED_DRAWING_ID_INVENTORY_CONTENT,
1379   ED_DRAWING_ID_MM_BALL_CONTENT,
1380   ED_DRAWING_ID_CUSTOM_GRAPHIC,
1381   ED_DRAWING_ID_CUSTOM_CONTENT,
1382   ED_DRAWING_ID_CUSTOM_MOVE_ENTER,
1383   ED_DRAWING_ID_CUSTOM_MOVE_LEAVE,
1384   ED_DRAWING_ID_CUSTOM_CHANGE_TARGET,
1385   ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT,
1386   ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER,
1387   ED_DRAWING_ID_CUSTOM_CHANGE_ACTION,
1388   ED_DRAWING_ID_GROUP_CONTENT,
1389   ED_DRAWING_ID_RANDOM_BACKGROUND,
1390
1391   ED_NUM_DRAWING_AREAS
1392 };
1393
1394 #define ED_DRAWING_ID_EDITOR_FIRST      ED_DRAWING_ID_RANDOM_BACKGROUND
1395 #define ED_DRAWING_ID_EDITOR_LAST       ED_DRAWING_ID_RANDOM_BACKGROUND
1396
1397
1398 // ----------------------------------------------------------------------------
1399 // some internally used definitions
1400 // ----------------------------------------------------------------------------
1401
1402 // values for CopyLevelToUndoBuffer()
1403 #define UNDO_IMMEDIATE                  0
1404 #define UNDO_ACCUMULATE                 1
1405
1406 // values for scrollbars
1407 #define ED_SCROLL_NO                    0
1408 #define ED_SCROLL_LEFT                  1
1409 #define ED_SCROLL_RIGHT                 2
1410 #define ED_SCROLL_UP                    4
1411 #define ED_SCROLL_DOWN                  8
1412
1413 // screens in the level editor
1414 #define ED_MODE_DRAWING                 0
1415 #define ED_MODE_LEVELCONFIG             1
1416 #define ED_MODE_PROPERTIES              2
1417 #define ED_MODE_PALETTE                 3
1418
1419 // sub-screens in the global settings section
1420 #define ED_MODE_LEVELCONFIG_LEVEL       ED_TEXTBUTTON_ID_LEVELCONFIG_LEVEL
1421 #define ED_MODE_LEVELCONFIG_LEVELSET    ED_TEXTBUTTON_ID_LEVELCONFIG_LEVELSET
1422 #define ED_MODE_LEVELCONFIG_EDITOR      ED_TEXTBUTTON_ID_LEVELCONFIG_EDITOR
1423 #define ED_MODE_LEVELCONFIG_ENGINE      ED_TEXTBUTTON_ID_LEVELCONFIG_ENGINE
1424
1425 // sub-screens in the engine settings section
1426 #define ED_MODE_ENGINECONFIG_CONFIG     ED_TEXTBUTTON_ID_ENGINECONFIG_CONFIG
1427 #define ED_MODE_ENGINECONFIG_COLORS     ED_TEXTBUTTON_ID_ENGINECONFIG_COLORS
1428
1429 // sub-screens in the element properties section
1430 #define ED_MODE_PROPERTIES_INFO         ED_TEXTBUTTON_ID_PROPERTIES_INFO
1431 #define ED_MODE_PROPERTIES_CONFIG       ED_TEXTBUTTON_ID_PROPERTIES_CONFIG
1432 #define ED_MODE_PROPERTIES_CONFIG_1     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_1
1433 #define ED_MODE_PROPERTIES_CONFIG_2     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2
1434 #define ED_MODE_PROPERTIES_CHANGE       ED_TEXTBUTTON_ID_PROPERTIES_CHANGE
1435
1436 // how many steps can be cancelled
1437 #define NUM_UNDO_STEPS                  (64 + 1)
1438
1439 // values for elements with score for certain actions
1440 #define MIN_SCORE                       0
1441 #define MAX_SCORE                       999
1442
1443 // values for elements with count for collecting
1444 #define MIN_COLLECT_COUNT               0
1445 #define MAX_COLLECT_COUNT               999
1446
1447 // values for random placement
1448 #define RANDOM_USE_PERCENTAGE           0
1449 #define RANDOM_USE_QUANTITY             1
1450
1451 // values for level set save mode
1452 #define LEVELSET_SAVE_MODE_UPDATE       0
1453 #define LEVELSET_SAVE_MODE_CREATE       1
1454
1455 // default value for element tile size in drawing area
1456 #define DEFAULT_EDITOR_TILESIZE         MINI_TILESIZE
1457 #define DEFAULT_EDITOR_TILESIZE_MM      TILESIZE
1458
1459
1460 // ----------------------------------------------------------------------------
1461 // some internally used data structure definitions
1462 // ----------------------------------------------------------------------------
1463
1464 static struct
1465 {
1466   int graphic;
1467   int gadget_id;
1468   struct XYTileSize *pos;
1469   int gadget_type;
1470   char *infotext;
1471   char shortcut;
1472 } controlbutton_info[ED_NUM_CTRL_BUTTONS] =
1473 {
1474   // note: some additional characters are already reserved for "cheat mode"
1475   // shortcuts (":XYZ" style) -- for details, see "events.c"
1476
1477   // ---------- toolbox control buttons ---------------------------------------
1478
1479   {
1480     IMG_GFX_EDITOR_BUTTON_DRAW_SINGLE,          GADGET_ID_SINGLE_ITEMS,
1481     &editor.button.draw_single,                 GD_TYPE_RADIO_BUTTON,
1482     "Draw single items",                        's'
1483   },
1484   {
1485     IMG_GFX_EDITOR_BUTTON_DRAW_CONNECTED,       GADGET_ID_CONNECTED_ITEMS,
1486     &editor.button.draw_connected,              GD_TYPE_RADIO_BUTTON,
1487     "Draw connected items",                     'd'
1488   },
1489   {
1490     IMG_GFX_EDITOR_BUTTON_DRAW_LINE,            GADGET_ID_LINE,
1491     &editor.button.draw_line,                   GD_TYPE_RADIO_BUTTON,
1492     "Draw lines",                               'l'
1493   },
1494   {
1495     IMG_GFX_EDITOR_BUTTON_DRAW_ARC,             GADGET_ID_ARC,
1496     &editor.button.draw_arc,                    GD_TYPE_RADIO_BUTTON,
1497     "Draw arcs",                                'a'
1498   },
1499   {
1500     IMG_GFX_EDITOR_BUTTON_DRAW_RECTANGLE,       GADGET_ID_RECTANGLE,
1501     &editor.button.draw_rectangle,              GD_TYPE_RADIO_BUTTON,
1502     "Draw outline rectangles",                  'r'
1503   },
1504   {
1505     IMG_GFX_EDITOR_BUTTON_DRAW_FILLED_BOX,      GADGET_ID_FILLED_BOX,
1506     &editor.button.draw_filled_box,             GD_TYPE_RADIO_BUTTON,
1507     "Draw filled rectangles",                   'R'
1508   },
1509   {
1510     IMG_GFX_EDITOR_BUTTON_ROTATE_UP,            GADGET_ID_WRAP_UP,
1511     &editor.button.rotate_up,                   GD_TYPE_NORMAL_BUTTON,
1512     "Wrap (rotate) level up",                   0
1513   },
1514   {
1515     IMG_GFX_EDITOR_BUTTON_DRAW_TEXT,            GADGET_ID_TEXT,
1516     &editor.button.draw_text,                   GD_TYPE_RADIO_BUTTON,
1517     "Enter text elements",                      't'
1518   },
1519   {
1520     IMG_GFX_EDITOR_BUTTON_FLOOD_FILL,           GADGET_ID_FLOOD_FILL,
1521     &editor.button.flood_fill,                  GD_TYPE_RADIO_BUTTON,
1522     "Flood fill",                               'f'
1523   },
1524   {
1525     IMG_GFX_EDITOR_BUTTON_ROTATE_LEFT,          GADGET_ID_WRAP_LEFT,
1526     &editor.button.rotate_left,                 GD_TYPE_NORMAL_BUTTON,
1527     "Wrap (rotate) level left",                 0
1528   },
1529   {
1530     IMG_GFX_EDITOR_BUTTON_ZOOM_LEVEL,           GADGET_ID_ZOOM,
1531     &editor.button.zoom_level,                  GD_TYPE_NORMAL_BUTTON,
1532     "Zoom level tile size",                     '+'
1533   },
1534   {
1535     IMG_GFX_EDITOR_BUTTON_ROTATE_RIGHT,         GADGET_ID_WRAP_RIGHT,
1536     &editor.button.rotate_right,                GD_TYPE_NORMAL_BUTTON,
1537     "Wrap (rotate) level right",                0
1538   },
1539   {
1540     IMG_GFX_EDITOR_BUTTON_DRAW_RANDOM,          GADGET_ID_RANDOM_PLACEMENT,
1541     &editor.button.draw_random,                 GD_TYPE_NORMAL_BUTTON,
1542     "Random element placement",                 0
1543   },
1544   {
1545     IMG_GFX_EDITOR_BUTTON_GRAB_BRUSH,           GADGET_ID_GRAB_BRUSH,
1546     &editor.button.grab_brush,                  GD_TYPE_RADIO_BUTTON,
1547     "Grab brush",                               'b'
1548   },
1549   {
1550     IMG_GFX_EDITOR_BUTTON_ROTATE_DOWN,          GADGET_ID_WRAP_DOWN,
1551     &editor.button.rotate_down,                 GD_TYPE_NORMAL_BUTTON,
1552     "Wrap (rotate) level down",                 0
1553   },
1554   {
1555     IMG_GFX_EDITOR_BUTTON_PICK_ELEMENT,         GADGET_ID_PICK_ELEMENT,
1556     &editor.button.pick_element,                GD_TYPE_RADIO_BUTTON,
1557     "Pick drawing element",                     ','
1558   },
1559
1560   // ---------- level control buttons -----------------------------------------
1561
1562   {
1563     IMG_GFX_EDITOR_BUTTON_UNDO,                 GADGET_ID_UNDO,
1564     &editor.button.undo,                        GD_TYPE_NORMAL_BUTTON,
1565     "Undo/redo last operation",                 'u'
1566   },
1567   {
1568     IMG_GFX_EDITOR_BUTTON_CONF,                 GADGET_ID_CONF,
1569     &editor.button.conf,                        GD_TYPE_NORMAL_BUTTON,
1570     "Level and editor settings",                'I'
1571   },
1572   {
1573     IMG_GFX_EDITOR_BUTTON_SAVE,                 GADGET_ID_SAVE,
1574     &editor.button.save,                        GD_TYPE_NORMAL_BUTTON,
1575     "Save level",                               'S'
1576   },
1577   {
1578     IMG_GFX_EDITOR_BUTTON_CLEAR,                GADGET_ID_CLEAR,
1579     &editor.button.clear,                       GD_TYPE_NORMAL_BUTTON,
1580     "Clear level",                              'C'
1581   },
1582   {
1583     IMG_GFX_EDITOR_BUTTON_TEST,                 GADGET_ID_TEST,
1584     &editor.button.test,                        GD_TYPE_NORMAL_BUTTON,
1585     "Test level",                               'T'
1586   },
1587   {
1588     IMG_GFX_EDITOR_BUTTON_EXIT,                 GADGET_ID_EXIT,
1589     &editor.button.exit,                        GD_TYPE_NORMAL_BUTTON,
1590     "Exit level editor",                        'E'
1591   },
1592
1593   // ---------- CE and GE control buttons -------------------------------------
1594
1595   {
1596     IMG_GFX_EDITOR_BUTTON_CE_COPY_FROM,         GADGET_ID_CUSTOM_COPY_FROM,
1597     &editor.button.ce_copy_from,                GD_TYPE_RADIO_BUTTON,
1598     "Copy settings from other element",         0
1599   },
1600   {
1601     IMG_GFX_EDITOR_BUTTON_CE_COPY_TO,           GADGET_ID_CUSTOM_COPY_TO,
1602     &editor.button.ce_copy_to,                  GD_TYPE_RADIO_BUTTON,
1603     "Copy settings to other element",           0
1604   },
1605   {
1606     IMG_GFX_EDITOR_BUTTON_CE_SWAP,              GADGET_ID_CUSTOM_EXCHANGE,
1607     &editor.button.ce_swap,                     GD_TYPE_RADIO_BUTTON,
1608     "Exchange element with other element",      0
1609   },
1610   {
1611     IMG_GFX_EDITOR_BUTTON_CE_COPY,              GADGET_ID_CUSTOM_COPY,
1612     &editor.button.ce_copy,                     GD_TYPE_NORMAL_BUTTON,
1613     "Copy settings from this element",          0
1614   },
1615   {
1616     IMG_GFX_EDITOR_BUTTON_CE_PASTE,             GADGET_ID_CUSTOM_PASTE,
1617     &editor.button.ce_paste,                    GD_TYPE_NORMAL_BUTTON,
1618     "Paste settings to this element",           0
1619   },
1620
1621   // ---------- palette control buttons ---------------------------------------
1622
1623   {
1624     IMG_GFX_EDITOR_BUTTON_PROPERTIES,           GADGET_ID_PROPERTIES,
1625     &editor.button.properties,                  GD_TYPE_NORMAL_BUTTON,
1626     "Properties of drawing element",            'p'
1627   },
1628   {
1629     IMG_GFX_EDITOR_BUTTON_ELEMENT_LEFT,         GADGET_ID_ELEMENT_LEFT,
1630     &editor.button.element_left,                GD_TYPE_NORMAL_BUTTON,
1631     "Properties of drawing element 1",          '1'
1632   },
1633   {
1634     IMG_GFX_EDITOR_BUTTON_ELEMENT_MIDDLE,       GADGET_ID_ELEMENT_MIDDLE,
1635     &editor.button.element_middle,              GD_TYPE_NORMAL_BUTTON,
1636     "Properties of drawing element 2",          '2'
1637   },
1638   {
1639     IMG_GFX_EDITOR_BUTTON_ELEMENT_RIGHT,        GADGET_ID_ELEMENT_RIGHT,
1640     &editor.button.element_right,               GD_TYPE_NORMAL_BUTTON,
1641     "Properties of drawing element 3",          '3'
1642   },
1643   {
1644     IMG_GFX_EDITOR_BUTTON_PALETTE,              GADGET_ID_PALETTE,
1645     &editor.button.palette,                     GD_TYPE_NORMAL_BUTTON,
1646     "Show list of elements",                    'e'
1647   }
1648 };
1649
1650 static int random_placement_value = 10;
1651 static int random_placement_method = RANDOM_USE_QUANTITY;
1652 static int random_placement_background_element = EL_SAND;
1653 static boolean random_placement_background_restricted = FALSE;
1654 static boolean stick_element_properties_window = FALSE;
1655 static boolean custom_element_properties[NUM_ELEMENT_PROPERTIES];
1656 static boolean custom_element_change_events[NUM_CHANGE_EVENTS];
1657 static struct ElementChangeInfo custom_element_change;
1658 static struct ElementGroupInfo group_element_info;
1659 static struct ElementInfo custom_element;
1660
1661 static char levelset_name[MAX_LEVEL_NAME_LEN + 1];
1662 static char levelset_author[MAX_LEVEL_AUTHOR_LEN + 1];
1663 static int levelset_num_levels = 100;
1664 static boolean levelset_use_levelset_artwork = FALSE;
1665 static boolean levelset_copy_level_template = FALSE;
1666 static int levelset_save_mode = LEVELSET_SAVE_MODE_UPDATE;
1667
1668 #define MAX_BD_COLORS                   7
1669 #define MAX_BD_COLOR_TEXT_LEN           10
1670
1671 static boolean bd_color_type_changed = FALSE;
1672 static int bd_color_type_default = GD_COLOR_TYPE_RGB;
1673 static int bd_color_c64[MAX_BD_COLORS];
1674 static char bd_color_text[MAX_BD_COLORS][MAX_BD_COLOR_TEXT_LEN + 1];
1675 static int bd_color_default[MAX_BD_COLORS];
1676 static int *bd_color[MAX_BD_COLORS] =
1677 {
1678   &level.bd_color_b,
1679   &level.bd_color_0,
1680   &level.bd_color_1,
1681   &level.bd_color_2,
1682   &level.bd_color_3,
1683   &level.bd_color_4,
1684   &level.bd_color_5,
1685 };
1686
1687 static struct
1688 {
1689   int gadget_type_id;
1690   int x, y;
1691   int min_value, max_value;
1692   int gadget_id_down, gadget_id_up;
1693   int gadget_id_text;
1694   int gadget_id_align;
1695   int *value;
1696   char *text_above, *text_left, *text_right;
1697 } counterbutton_info[ED_NUM_COUNTERBUTTONS] =
1698 {
1699   // ---------- current level number ------------------------------------------
1700
1701   {
1702     ED_COUNTER_ID_SELECT_LEVEL,
1703     -1, -1,     // these values are not constant, but can change at runtime
1704     1,                                          100,
1705     GADGET_ID_SELECT_LEVEL_DOWN,                GADGET_ID_SELECT_LEVEL_UP,
1706     GADGET_ID_SELECT_LEVEL_TEXT,                GADGET_ID_NONE,
1707     &level_nr,
1708     NULL,                                       NULL, NULL
1709   },
1710
1711   // ---------- level and editor settings -------------------------------------
1712
1713   {
1714     ED_COUNTER_ID_LEVEL_XSIZE,
1715     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(4),
1716     MIN_LEV_FIELDX,                             MAX_LEV_FIELDX,
1717     GADGET_ID_LEVEL_XSIZE_DOWN,                 GADGET_ID_LEVEL_XSIZE_UP,
1718     GADGET_ID_LEVEL_XSIZE_TEXT,                 GADGET_ID_NONE,
1719     &level.fieldx,
1720     "Playfield size:",                          NULL, "Width",
1721   },
1722   {
1723     ED_COUNTER_ID_LEVEL_YSIZE,
1724     -1,                                         ED_LEVEL_SETTINGS_YPOS(4),
1725     MIN_LEV_FIELDY,                             MAX_LEV_FIELDY,
1726     GADGET_ID_LEVEL_YSIZE_DOWN,                 GADGET_ID_LEVEL_YSIZE_UP,
1727     GADGET_ID_LEVEL_YSIZE_TEXT,                 GADGET_ID_LEVEL_XSIZE_UP,
1728     &level.fieldy,
1729     NULL,                                       " ", "Height",
1730   },
1731   {
1732     ED_COUNTER_ID_LEVEL_GEMSLIMIT,
1733     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(5),
1734     0,                                          999,
1735     GADGET_ID_LEVEL_GEMSLIMIT_DOWN,             GADGET_ID_LEVEL_GEMSLIMIT_UP,
1736     GADGET_ID_LEVEL_GEMSLIMIT_TEXT,             GADGET_ID_NONE,
1737     &level.gems_needed,
1738     NULL,                                       "Number of gems to collect:", NULL
1739   },
1740   {
1741     ED_COUNTER_ID_LEVEL_TIMELIMIT,
1742     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(8),
1743     0,                                          9999,
1744     GADGET_ID_LEVEL_TIMELIMIT_DOWN,             GADGET_ID_LEVEL_TIMELIMIT_UP,
1745     GADGET_ID_LEVEL_TIMELIMIT_TEXT,             GADGET_ID_NONE,
1746     &level.time,
1747     "Time or step limit to solve level:",       NULL, NULL
1748   },
1749   {
1750     ED_COUNTER_ID_LEVEL_TIMESCORE,
1751     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(10),
1752     0,                                          999,
1753     GADGET_ID_LEVEL_TIMESCORE_DOWN,             GADGET_ID_LEVEL_TIMESCORE_UP,
1754     GADGET_ID_LEVEL_TIMESCORE_TEXT,             GADGET_ID_NONE,
1755     &level.score[SC_TIME_BONUS],
1756     "Score for time or steps left:",            NULL, NULL
1757   },
1758   {
1759     ED_COUNTER_ID_LEVEL_RANDOM_SEED,
1760     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(13),
1761     0,                                          9999,
1762     GADGET_ID_LEVEL_RANDOM_SEED_DOWN,           GADGET_ID_LEVEL_RANDOM_SEED_UP,
1763     GADGET_ID_LEVEL_RANDOM_SEED_TEXT,           GADGET_ID_NONE,
1764     &level.random_seed,
1765     NULL,                                       "Random seed:", "(0 => random)"
1766   },
1767   {
1768     ED_COUNTER_ID_LEVELSET_NUM_LEVELS,
1769     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(4),
1770     1,                                          MAX_LEVELS,
1771     GADGET_ID_LEVELSET_NUM_LEVELS_DOWN,         GADGET_ID_LEVELSET_NUM_LEVELS_UP,
1772     GADGET_ID_LEVELSET_NUM_LEVELS_TEXT,         GADGET_ID_NONE,
1773     &levelset_num_levels,
1774     "Number of levels:",                        NULL, NULL,
1775   },
1776   {
1777     ED_COUNTER_ID_LEVEL_RANDOM,
1778     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(0),
1779     1,                                          100,
1780     GADGET_ID_LEVEL_RANDOM_DOWN,                GADGET_ID_LEVEL_RANDOM_UP,
1781     GADGET_ID_LEVEL_RANDOM_TEXT,                GADGET_ID_NONE,
1782     &random_placement_value,
1783     "Random element placement:",                NULL, "in"
1784   },
1785   {
1786     ED_COUNTER_ID_BD_CYCLE_DELAY_MS,
1787     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(3),
1788     50,                                         500,
1789     GADGET_ID_BD_CYCLE_DELAY_MS_DOWN,           GADGET_ID_BD_CYCLE_DELAY_MS_UP,
1790     GADGET_ID_BD_CYCLE_DELAY_MS_TEXT,           GADGET_ID_NONE,
1791     &level.bd_cycle_delay_ms,
1792     NULL,                                       NULL, "Game cycle delay (ms)"
1793   },
1794   {
1795     ED_COUNTER_ID_BD_CYCLE_DELAY_C64,
1796     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(3),
1797     0,                                          32,
1798     GADGET_ID_BD_CYCLE_DELAY_C64_DOWN,          GADGET_ID_BD_CYCLE_DELAY_C64_UP,
1799     GADGET_ID_BD_CYCLE_DELAY_C64_TEXT,          GADGET_ID_NONE,
1800     &level.bd_cycle_delay_c64,
1801     NULL,                                       NULL, "Game cycle delay (C64-style)"
1802   },
1803   {
1804     ED_COUNTER_ID_BD_HATCHING_DELAY_CYCLES,
1805     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(4),
1806     1,                                          40,
1807     GADGET_ID_BD_HATCHING_DELAY_CYCLES_DOWN,    GADGET_ID_BD_HATCHING_DELAY_CYCLES_UP,
1808     GADGET_ID_BD_HATCHING_DELAY_CYCLES_TEXT,    GADGET_ID_NONE,
1809     &level.bd_hatching_delay_cycles,
1810     NULL,                                       NULL, "Hatching delay (cycles)"
1811   },
1812   {
1813     ED_COUNTER_ID_BD_HATCHING_DELAY_SECONDS,
1814     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(4),
1815     1,                                          40,
1816     GADGET_ID_BD_HATCHING_DELAY_SECONDS_DOWN,   GADGET_ID_BD_HATCHING_DELAY_SECONDS_UP,
1817     GADGET_ID_BD_HATCHING_DELAY_SECONDS_TEXT,   GADGET_ID_NONE,
1818     &level.bd_hatching_delay_seconds,
1819     NULL,                                       NULL, "Hatching delay (seconds)"
1820   },
1821
1822   // ---------- element settings: configure (various elements) ----------------
1823
1824   {
1825     ED_COUNTER_ID_BD_PUSHING_PROB,
1826     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
1827     0,                                          100,
1828     GADGET_ID_BD_PUSHING_PROB_DOWN,             GADGET_ID_BD_PUSHING_PROB_UP,
1829     GADGET_ID_BD_PUSHING_PROB_TEXT,             GADGET_ID_NONE,
1830     &level.bd_pushing_prob,
1831     NULL,                                       NULL, "Push probability"
1832   },
1833   {
1834     ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET,
1835     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
1836     0,                                          100,
1837     GADGET_ID_BD_PUSHING_PROB_WITH_SWEET_DOWN,  GADGET_ID_BD_PUSHING_PROB_WITH_SWEET_UP,
1838     GADGET_ID_BD_PUSHING_PROB_WITH_SWEET_TEXT,  GADGET_ID_NONE,
1839     &level.bd_pushing_prob_with_sweet,
1840     NULL,                                       NULL, "Push probability with sweet"
1841   },
1842   {
1843     ED_COUNTER_ID_ELEMENT_VALUE1,
1844     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
1845     MIN_SCORE,                                  MAX_SCORE,
1846     GADGET_ID_ELEMENT_VALUE1_DOWN,              GADGET_ID_ELEMENT_VALUE1_UP,
1847     GADGET_ID_ELEMENT_VALUE1_TEXT,              GADGET_ID_NONE,
1848     NULL,                                       // will be set when used
1849     NULL,                                       NULL, NULL
1850   },
1851   {
1852     ED_COUNTER_ID_ELEMENT_VALUE2,
1853     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
1854     MIN_SCORE,                                  MAX_SCORE,
1855     GADGET_ID_ELEMENT_VALUE2_DOWN,              GADGET_ID_ELEMENT_VALUE2_UP,
1856     GADGET_ID_ELEMENT_VALUE2_TEXT,              GADGET_ID_NONE,
1857     NULL,                                       // will be set when used
1858     NULL,                                       NULL, NULL
1859   },
1860   {
1861     ED_COUNTER_ID_ELEMENT_VALUE3,
1862     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
1863     MIN_SCORE,                                  MAX_SCORE,
1864     GADGET_ID_ELEMENT_VALUE3_DOWN,              GADGET_ID_ELEMENT_VALUE3_UP,
1865     GADGET_ID_ELEMENT_VALUE3_TEXT,              GADGET_ID_NONE,
1866     NULL,                                       // will be set when used
1867     NULL,                                       NULL, NULL
1868   },
1869   {
1870     ED_COUNTER_ID_ELEMENT_VALUE4,
1871     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
1872     MIN_SCORE,                                  MAX_SCORE,
1873     GADGET_ID_ELEMENT_VALUE4_DOWN,              GADGET_ID_ELEMENT_VALUE4_UP,
1874     GADGET_ID_ELEMENT_VALUE4_TEXT,              GADGET_ID_NONE,
1875     NULL,                                       // will be set when used
1876     NULL,                                       NULL, NULL
1877   },
1878   {
1879     ED_COUNTER_ID_YAMYAM_CONTENT,
1880     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
1881     MIN_ELEMENT_CONTENTS,                       MAX_ELEMENT_CONTENTS,
1882     GADGET_ID_YAMYAM_CONTENT_DOWN,              GADGET_ID_YAMYAM_CONTENT_UP,
1883     GADGET_ID_YAMYAM_CONTENT_TEXT,              GADGET_ID_NONE,
1884     &level.num_yamyam_contents,
1885     NULL,                                       NULL, "Number of content areas"
1886   },
1887   {
1888     ED_COUNTER_ID_BALL_CONTENT,
1889     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
1890     MIN_ELEMENT_CONTENTS,                       MAX_ELEMENT_CONTENTS,
1891     GADGET_ID_BALL_CONTENT_DOWN,                GADGET_ID_BALL_CONTENT_UP,
1892     GADGET_ID_BALL_CONTENT_TEXT,                GADGET_ID_NONE,
1893     &level.num_ball_contents,
1894     NULL,                                       NULL, "Number of content areas"
1895   },
1896   {
1897     ED_COUNTER_ID_ANDROID_CONTENT,
1898     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
1899     MIN_ANDROID_ELEMENTS,                       MAX_ANDROID_ELEMENTS,
1900     GADGET_ID_ANDROID_CONTENT_DOWN,             GADGET_ID_ANDROID_CONTENT_UP,
1901     GADGET_ID_ANDROID_CONTENT_TEXT,             GADGET_ID_NONE,
1902     &level.num_android_clone_elements,
1903     NULL,                                       NULL, "Number of clonable elements"
1904   },
1905   {
1906     ED_COUNTER_ID_ENVELOPE_XSIZE,
1907     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
1908     MIN_ENVELOPE_XSIZE,                         MAX_ENVELOPE_XSIZE,
1909     GADGET_ID_ENVELOPE_XSIZE_DOWN,              GADGET_ID_ENVELOPE_XSIZE_UP,
1910     GADGET_ID_ENVELOPE_XSIZE_TEXT,              GADGET_ID_NONE,
1911     NULL,                                       // will be set when used
1912     NULL,                                       NULL, "Width",
1913   },
1914   {
1915     ED_COUNTER_ID_ENVELOPE_YSIZE,
1916     -1,                                         ED_ELEMENT_SETTINGS_YPOS(0),
1917     MIN_ENVELOPE_YSIZE,                         MAX_ENVELOPE_YSIZE,
1918     GADGET_ID_ENVELOPE_YSIZE_DOWN,              GADGET_ID_ENVELOPE_YSIZE_UP,
1919     GADGET_ID_ENVELOPE_YSIZE_TEXT,              GADGET_ID_ENVELOPE_XSIZE_UP,
1920     NULL,                                       // will be set when used
1921     NULL,                                       " ", "Height",
1922   },
1923   {
1924     ED_COUNTER_ID_INVENTORY_SIZE,
1925     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
1926     MIN_INITIAL_INVENTORY_SIZE,                 MAX_INITIAL_INVENTORY_SIZE,
1927     GADGET_ID_INVENTORY_SIZE_DOWN,              GADGET_ID_INVENTORY_SIZE_UP,
1928     GADGET_ID_INVENTORY_SIZE_TEXT,              GADGET_ID_NONE,
1929     &level.initial_inventory_size[0],
1930     NULL,                                       NULL, "Number of inventory elements"
1931   },
1932   {
1933     ED_COUNTER_ID_MM_BALL_CONTENT,
1934     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
1935     MIN_ELEMENTS_IN_GROUP,                      MAX_MM_BALL_CONTENTS,
1936     GADGET_ID_MM_BALL_CONTENT_DOWN,             GADGET_ID_MM_BALL_CONTENT_UP,
1937     GADGET_ID_MM_BALL_CONTENT_TEXT,             GADGET_ID_NONE,
1938     &level.num_mm_ball_contents,
1939     NULL,                                       NULL, "Number of content elements"
1940   },
1941
1942   // ---------- element settings: configure 1 (custom elements) ---------------
1943
1944   {
1945     ED_COUNTER_ID_CUSTOM_SCORE,
1946     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(5),
1947     MIN_SCORE,                                  MAX_SCORE,
1948     GADGET_ID_CUSTOM_SCORE_DOWN,                GADGET_ID_CUSTOM_SCORE_UP,
1949     GADGET_ID_CUSTOM_SCORE_TEXT,                GADGET_ID_NONE,
1950     &custom_element.collect_score_initial,
1951     NULL,                                       "CE score", " "
1952   },
1953   {
1954     ED_COUNTER_ID_CUSTOM_GEMCOUNT,
1955     -1,                                         ED_ELEMENT_SETTINGS_YPOS(5),
1956     MIN_COLLECT_COUNT,                          MAX_COLLECT_COUNT,
1957     GADGET_ID_CUSTOM_GEMCOUNT_DOWN,             GADGET_ID_CUSTOM_GEMCOUNT_UP,
1958     GADGET_ID_CUSTOM_GEMCOUNT_TEXT,             GADGET_ID_CUSTOM_SCORE_UP,
1959     &custom_element.collect_count_initial,
1960     NULL,                                       "CE count", NULL
1961   },
1962   {
1963     ED_COUNTER_ID_CUSTOM_VALUE_FIX,
1964     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(10),
1965     0,                                          9999,
1966     GADGET_ID_CUSTOM_VALUE_FIX_DOWN,            GADGET_ID_CUSTOM_VALUE_FIX_UP,
1967     GADGET_ID_CUSTOM_VALUE_FIX_TEXT,            GADGET_ID_NONE,
1968     &custom_element.ce_value_fixed_initial,
1969     NULL,                                       "CE value", NULL
1970   },
1971   {
1972     ED_COUNTER_ID_CUSTOM_VALUE_RND,
1973     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(10),
1974     0,                                          9999,
1975     GADGET_ID_CUSTOM_VALUE_RND_DOWN,            GADGET_ID_CUSTOM_VALUE_RND_UP,
1976     GADGET_ID_CUSTOM_VALUE_RND_TEXT,            GADGET_ID_CUSTOM_VALUE_FIX_UP,
1977     &custom_element.ce_value_random_initial,
1978     NULL,                                       "+random", NULL
1979   },
1980   {
1981     ED_COUNTER_ID_PUSH_DELAY_FIX,
1982     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(6),
1983     0,                                          999,
1984     GADGET_ID_PUSH_DELAY_FIX_DOWN,              GADGET_ID_PUSH_DELAY_FIX_UP,
1985     GADGET_ID_PUSH_DELAY_FIX_TEXT,              GADGET_ID_NONE,
1986     &custom_element.push_delay_fixed,
1987     NULL,                                       "Push delay", NULL
1988   },
1989   {
1990     ED_COUNTER_ID_PUSH_DELAY_RND,
1991     -1,                                         ED_ELEMENT_SETTINGS_YPOS(6),
1992     0,                                          999,
1993     GADGET_ID_PUSH_DELAY_RND_DOWN,              GADGET_ID_PUSH_DELAY_RND_UP,
1994     GADGET_ID_PUSH_DELAY_RND_TEXT,              GADGET_ID_PUSH_DELAY_FIX_UP,
1995     &custom_element.push_delay_random,
1996     NULL,                                       "+random", NULL
1997   },
1998   {
1999     ED_COUNTER_ID_DROP_DELAY_FIX,
2000     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(7),
2001     0,                                          999,
2002     GADGET_ID_DROP_DELAY_FIX_DOWN,              GADGET_ID_DROP_DELAY_FIX_UP,
2003     GADGET_ID_DROP_DELAY_FIX_TEXT,              GADGET_ID_NONE,
2004     &custom_element.drop_delay_fixed,
2005     NULL,                                       "Drop delay", NULL
2006   },
2007   {
2008     ED_COUNTER_ID_DROP_DELAY_RND,
2009     -1,                                         ED_ELEMENT_SETTINGS_YPOS(7),
2010     0,                                          999,
2011     GADGET_ID_DROP_DELAY_RND_DOWN,              GADGET_ID_DROP_DELAY_RND_UP,
2012     GADGET_ID_DROP_DELAY_RND_TEXT,              GADGET_ID_DROP_DELAY_FIX_UP,
2013     &custom_element.drop_delay_random,
2014     NULL,                                       "+random", NULL
2015   },
2016
2017   // ---------- element settings: configure 2 (custom elements) ---------------
2018
2019   {
2020     ED_COUNTER_ID_MOVE_DELAY_FIX,
2021     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(5),
2022     0,                                          999,
2023     GADGET_ID_MOVE_DELAY_FIX_DOWN,              GADGET_ID_MOVE_DELAY_FIX_UP,
2024     GADGET_ID_MOVE_DELAY_FIX_TEXT,              GADGET_ID_NONE,
2025     &custom_element.move_delay_fixed,
2026     NULL,                                       "Move delay", NULL
2027   },
2028   {
2029     ED_COUNTER_ID_MOVE_DELAY_RND,
2030     -1,                                         ED_ELEMENT_SETTINGS_YPOS(5),
2031     0,                                          999,
2032     GADGET_ID_MOVE_DELAY_RND_DOWN,              GADGET_ID_MOVE_DELAY_RND_UP,
2033     GADGET_ID_MOVE_DELAY_RND_TEXT,              GADGET_ID_MOVE_DELAY_FIX_UP,
2034     &custom_element.move_delay_random,
2035     NULL,                                       "+random", NULL
2036   },
2037   {
2038     ED_COUNTER_ID_STEP_DELAY_FIX,
2039     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(6),
2040     0,                                          999,
2041     GADGET_ID_STEP_DELAY_FIX_DOWN,              GADGET_ID_STEP_DELAY_FIX_UP,
2042     GADGET_ID_STEP_DELAY_FIX_TEXT,              GADGET_ID_NONE,
2043     &custom_element.step_delay_fixed,
2044     NULL,                                       "Step delay", NULL
2045   },
2046   {
2047     ED_COUNTER_ID_STEP_DELAY_RND,
2048     -1,                                         ED_ELEMENT_SETTINGS_YPOS(6),
2049     0,                                          999,
2050     GADGET_ID_STEP_DELAY_RND_DOWN,              GADGET_ID_STEP_DELAY_RND_UP,
2051     GADGET_ID_STEP_DELAY_RND_TEXT,              GADGET_ID_STEP_DELAY_FIX_UP,
2052     &custom_element.step_delay_random,
2053     NULL,                                       "+random", NULL
2054   },
2055   {
2056     ED_COUNTER_ID_EXPLOSION_DELAY,
2057     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(13),
2058     0,                                          999,
2059     GADGET_ID_EXPLOSION_DELAY_DOWN,             GADGET_ID_EXPLOSION_DELAY_UP,
2060     GADGET_ID_EXPLOSION_DELAY_TEXT,             GADGET_ID_NONE,
2061     &custom_element.explosion_delay,
2062     NULL,                                       "Explosion delay", NULL
2063   },
2064   {
2065     ED_COUNTER_ID_IGNITION_DELAY,
2066     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(14),
2067     0,                                          999,
2068     GADGET_ID_IGNITION_DELAY_DOWN,              GADGET_ID_IGNITION_DELAY_UP,
2069     GADGET_ID_IGNITION_DELAY_TEXT,              GADGET_ID_NONE,
2070     &custom_element.ignition_delay,
2071     NULL,                                       "Ignition delay", "(by fire)"
2072   },
2073
2074   // ---------- element settings: configure (group elements) ------------------
2075
2076   {
2077     ED_COUNTER_ID_GROUP_CONTENT,
2078     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
2079     MIN_ELEMENTS_IN_GROUP,                      MAX_ELEMENTS_IN_GROUP,
2080     GADGET_ID_GROUP_CONTENT_DOWN,               GADGET_ID_GROUP_CONTENT_UP,
2081     GADGET_ID_GROUP_CONTENT_TEXT,               GADGET_ID_NONE,
2082     &group_element_info.num_elements,
2083     NULL,                                       NULL, "Number of elements in group"
2084   },
2085
2086   // ---------- element settings: advanced (custom elements) ------------------
2087
2088   {
2089     ED_COUNTER_ID_CHANGE_DELAY_FIX,
2090     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(2),
2091     0,                                          999,
2092     GADGET_ID_CHANGE_DELAY_FIX_DOWN,            GADGET_ID_CHANGE_DELAY_FIX_UP,
2093     GADGET_ID_CHANGE_DELAY_FIX_TEXT,            GADGET_ID_NONE,
2094     &custom_element_change.delay_fixed,
2095     NULL,                                       "CE delay", NULL,
2096   },
2097   {
2098     ED_COUNTER_ID_CHANGE_DELAY_RND,
2099     -1,                                         ED_ELEMENT_SETTINGS_YPOS(2),
2100     0,                                          999,
2101     GADGET_ID_CHANGE_DELAY_RND_DOWN,            GADGET_ID_CHANGE_DELAY_RND_UP,
2102     GADGET_ID_CHANGE_DELAY_RND_TEXT,            GADGET_ID_CHANGE_DELAY_FIX_UP,
2103     &custom_element_change.delay_random,
2104     NULL,                                       "+random", NULL
2105   },
2106   {
2107     ED_COUNTER_ID_CHANGE_CONT_RND,
2108     ED_ELEMENT_SETTINGS_XPOS(3),                ED_ELEMENT_SETTINGS_YPOS(12),
2109     0,                                          100,
2110     GADGET_ID_CHANGE_CONT_RND_DOWN,             GADGET_ID_CHANGE_CONT_RND_UP,
2111     GADGET_ID_CHANGE_CONT_RND_TEXT,             GADGET_ID_NONE,
2112     &custom_element_change.random_percentage,
2113     NULL,                                       "Use random replace:", "%"
2114   },
2115 };
2116
2117 static struct
2118 {
2119   int gadget_type_id;
2120   int x, y;
2121   int gadget_id;
2122   int size;
2123   char *value;
2124   char *text_above, *text_left, *text_right, *infotext;
2125 } textinput_info[ED_NUM_TEXTINPUT] =
2126 {
2127   // ---------- level and editor settings -------------------------------------
2128
2129   {
2130     ED_TEXTINPUT_ID_LEVEL_NAME,
2131     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(0),
2132     GADGET_ID_LEVEL_NAME,
2133     MAX_LEVEL_NAME_LEN,
2134     level.name,
2135     "Title:", NULL, NULL,                       "Enter title for this level"
2136   },
2137   {
2138     ED_TEXTINPUT_ID_LEVEL_AUTHOR,
2139     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(2),
2140     GADGET_ID_LEVEL_AUTHOR,
2141     MAX_LEVEL_AUTHOR_LEN,
2142     level.author,
2143     "Author:", NULL, NULL,                      "Enter author for this level"
2144   },
2145   {
2146     ED_TEXTINPUT_ID_LEVELSET_NAME,
2147     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(0),
2148     GADGET_ID_LEVELSET_NAME,
2149     MAX_LEVEL_NAME_LEN,
2150     levelset_name,
2151     "Title:", NULL, NULL,                       "Enter title for this or new level set"
2152   },
2153   {
2154     ED_TEXTINPUT_ID_LEVELSET_AUTHOR,
2155     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(2),
2156     GADGET_ID_LEVELSET_AUTHOR,
2157     MAX_LEVEL_AUTHOR_LEN,
2158     levelset_author,
2159     "Author:", NULL, NULL,                      "Enter author for this or new level set"
2160   },
2161
2162   // ---------- engine settings: colors ---------------------------------------
2163
2164   {
2165     ED_TEXTINPUT_ID_BD_COLOR_TEXT_B,
2166     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(1),
2167     GADGET_ID_BD_COLOR_TEXT_B,
2168     MAX_BD_COLOR_TEXT_LEN,
2169     bd_color_text[0],
2170     NULL, "Border color:      ", NULL,          "Enter border color (not used)"
2171   },
2172   {
2173     ED_TEXTINPUT_ID_BD_COLOR_TEXT_0,
2174     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(2),
2175     GADGET_ID_BD_COLOR_TEXT_0,
2176     MAX_BD_COLOR_TEXT_LEN,
2177     bd_color_text[1],
2178     NULL, "Background color:  ", NULL,          "Enter background color (C64 graphics)"
2179   },
2180   {
2181     ED_TEXTINPUT_ID_BD_COLOR_TEXT_1,
2182     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(3),
2183     GADGET_ID_BD_COLOR_TEXT_1,
2184     MAX_BD_COLOR_TEXT_LEN,
2185     bd_color_text[2],
2186     NULL, "Sand color:        ", NULL,          "Enter sand color (C64 graphics)"
2187   },
2188   {
2189     ED_TEXTINPUT_ID_BD_COLOR_TEXT_2,
2190     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(4),
2191     GADGET_ID_BD_COLOR_TEXT_2,
2192     MAX_BD_COLOR_TEXT_LEN,
2193     bd_color_text[3],
2194     NULL, "Steel wall color:  ", NULL,          "Enter steel wall color (C64 graphics)"
2195   },
2196   {
2197     ED_TEXTINPUT_ID_BD_COLOR_TEXT_3,
2198     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(5),
2199     GADGET_ID_BD_COLOR_TEXT_3,
2200     MAX_BD_COLOR_TEXT_LEN,
2201     bd_color_text[4],
2202     NULL, "Wall color:        ", NULL,          "Enter wall color (C64 graphics)"
2203   },
2204   {
2205     ED_TEXTINPUT_ID_BD_COLOR_TEXT_4,
2206     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(6),
2207     GADGET_ID_BD_COLOR_TEXT_4,
2208     MAX_BD_COLOR_TEXT_LEN,
2209     bd_color_text[5],
2210     NULL, "Amoeba color:      ", NULL,          "Enter amoeba color (C64 graphics)"
2211   },
2212   {
2213     ED_TEXTINPUT_ID_BD_COLOR_TEXT_5,
2214     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(7),
2215     GADGET_ID_BD_COLOR_TEXT_5,
2216     MAX_BD_COLOR_TEXT_LEN,
2217     bd_color_text[6],
2218     NULL, "Slime color:       ", NULL,          "Enter slime color (C64 graphics)"
2219   },
2220
2221   // ---------- element settings: configure (several elements) ----------------
2222
2223   {
2224     ED_TEXTINPUT_ID_ELEMENT_NAME,
2225     -1, -1,     // these values are not constant, but can change at runtime
2226     GADGET_ID_ELEMENT_NAME,
2227     MAX_ELEMENT_NAME_LEN - 2,                   // currently 2 chars less editable
2228     custom_element.description,
2229     NULL, NULL, NULL,                           "Enter element name"
2230   }
2231 };
2232
2233 static struct
2234 {
2235   int gadget_type_id;
2236   int x, y;
2237   int gadget_id;
2238   int xsize, ysize;
2239   char *value;
2240   char *text_above, *text_above_cropped, *infotext;
2241 } textarea_info[ED_NUM_TEXTAREAS] =
2242 {
2243   {
2244     ED_TEXTAREA_ID_ENVELOPE_INFO,
2245     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
2246     GADGET_ID_ENVELOPE_INFO,
2247     MAX_ENVELOPE_XSIZE, MAX_ENVELOPE_YSIZE,
2248     NULL,
2249     "Envelope Content:", "Envelope Content (cropped):", "Envelope Content"
2250   }
2251 };
2252
2253 static struct ValueTextInfo options_time_or_steps[] =
2254 {
2255   { 0,                                  "seconds"                       },
2256   { 1,                                  "steps"                         },
2257
2258   { -1,                                 NULL                            }
2259 };
2260
2261 static struct ValueTextInfo options_time_score_base[] =
2262 {
2263   { 1,                                  "per second/step"               },
2264   { 10,                                 "per 10 seconds/steps"          },
2265
2266   { -1,                                 NULL                            }
2267 };
2268
2269 static struct ValueTextInfo options_game_engine_type[] =
2270 {
2271   { GAME_ENGINE_TYPE_RND,               "Rocks'n'Diamonds"              },
2272   { GAME_ENGINE_TYPE_BD,                "Boulder Dash"                  },
2273   { GAME_ENGINE_TYPE_EM,                "Emerald Mine"                  },
2274   { GAME_ENGINE_TYPE_SP,                "Supaplex"                      },
2275   { GAME_ENGINE_TYPE_MM,                "Mirror Magic"                  },
2276
2277   { -1,                                 NULL                            }
2278 };
2279
2280 static struct ValueTextInfo options_levelset_save_mode[] =
2281 {
2282   { LEVELSET_SAVE_MODE_UPDATE,          "Update this level set"         },
2283   { LEVELSET_SAVE_MODE_CREATE,          "Create new level set"          },
2284
2285   { -1,                                 NULL                            }
2286 };
2287
2288 static struct ValueTextInfo options_bd_gravity_direction[] =
2289 {
2290   { GD_MV_DOWN,                         "down"                          },
2291   { GD_MV_UP,                           "up"                            },
2292   { GD_MV_LEFT,                         "left"                          },
2293   { GD_MV_RIGHT,                        "right"                         },
2294
2295   { -1,                                 NULL                            }
2296 };
2297
2298 static struct ValueTextInfo options_wind_direction[] =
2299 {
2300   { MV_START_NONE,                      "none"                          },
2301   { MV_START_LEFT,                      "left"                          },
2302   { MV_START_RIGHT,                     "right"                         },
2303   { MV_START_UP,                        "up"                            },
2304   { MV_START_DOWN,                      "down"                          },
2305
2306   { -1,                                 NULL                            }
2307 };
2308
2309 static struct ValueTextInfo options_player_speed[] =
2310 {
2311   { 0,                                  "frozen"                        },
2312   { 1,                                  "very slow"                     },
2313   { 2,                                  "slow"                          },
2314   { 4,                                  "normal"                        },
2315   { 8,                                  "fast"                          },
2316   { 16,                                 "very fast"                     },
2317   { 32,                                 "ultrafast"                     },
2318
2319   { -1,                                 NULL                            }
2320 };
2321
2322 static struct ValueTextInfo options_access_type[] =
2323 {
2324   { EP_WALKABLE,                        "walkable"                      },
2325   { EP_PASSABLE,                        "passable"                      },
2326
2327   { -1,                                 NULL                            }
2328 };
2329
2330 static struct ValueTextInfo options_access_layer[] =
2331 {
2332   { EP_ACCESSIBLE_OVER,                 "over"                          },
2333   { EP_ACCESSIBLE_INSIDE,               "inside"                        },
2334   { EP_ACCESSIBLE_UNDER,                "under"                         },
2335
2336   { -1,                                 NULL                            }
2337 };
2338
2339 static struct ValueTextInfo options_access_protected[] =
2340 {
2341   { 0,                                  "unprotected"                   },
2342   { 1,                                  "protected"                     },
2343
2344   { -1,                                 NULL                            }
2345 };
2346
2347 static struct ValueTextInfo options_access_direction[] =
2348 {
2349   { MV_NO_DIRECTION,                    "no direction"                  },
2350   { MV_LEFT,                            "left"                          },
2351   { MV_RIGHT,                           "right"                         },
2352   { MV_UP,                              "up"                            },
2353   { MV_DOWN,                            "down"                          },
2354   { MV_LEFT  | MV_UP,                   "left + up"                     },
2355   { MV_LEFT  | MV_DOWN,                 "left + down"                   },
2356   { MV_RIGHT | MV_UP,                   "right + up"                    },
2357   { MV_RIGHT | MV_DOWN,                 "right + down"                  },
2358   { MV_HORIZONTAL,                      "horizontal"                    },
2359   { MV_VERTICAL,                        "vertical"                      },
2360   { MV_HORIZONTAL | MV_UP,              "horizontal + up"               },
2361   { MV_HORIZONTAL | MV_DOWN,            "horizontal + down"             },
2362   { MV_VERTICAL   | MV_LEFT,            "vertical + left"               },
2363   { MV_VERTICAL   | MV_RIGHT,           "vertical + right"              },
2364   { MV_ALL_DIRECTIONS,                  "all directions"                },
2365
2366   { -1,                                 NULL                            }
2367 };
2368
2369 static struct ValueTextInfo options_walk_to_action[] =
2370 {
2371   { EP_DIGGABLE,                        "diggable"                      },
2372   { EP_COLLECTIBLE_ONLY,                "collectible"                   },
2373   { EP_DROPPABLE,                       "collectible & droppable"       },
2374   { EP_THROWABLE,                       "collectible & throwable"       },
2375   { EP_PUSHABLE,                        "pushable"                      },
2376
2377   { -1,                                 NULL                            }
2378 };
2379
2380 static struct ValueTextInfo options_move_pattern[] =
2381 {
2382   { MV_LEFT,                            "left"                          },
2383   { MV_RIGHT,                           "right"                         },
2384   { MV_UP,                              "up"                            },
2385   { MV_DOWN,                            "down"                          },
2386   { MV_HORIZONTAL,                      "horizontal"                    },
2387   { MV_VERTICAL,                        "vertical"                      },
2388   { MV_ALL_DIRECTIONS,                  "all directions"                },
2389   { MV_WIND_DIRECTION,                  "wind direction"                },
2390   { MV_TOWARDS_PLAYER,                  "towards player"                },
2391   { MV_AWAY_FROM_PLAYER,                "away from player"              },
2392   { MV_ALONG_LEFT_SIDE,                 "along left side"               },
2393   { MV_ALONG_RIGHT_SIDE,                "along right side"              },
2394   { MV_TURNING_LEFT,                    "turning left"                  },
2395   { MV_TURNING_RIGHT,                   "turning right"                 },
2396   { MV_TURNING_LEFT_RIGHT,              "turning left, right"           },
2397   { MV_TURNING_RIGHT_LEFT,              "turning right, left"           },
2398   { MV_TURNING_RANDOM,                  "turning random"                },
2399   { MV_MAZE_RUNNER,                     "maze runner style"             },
2400   { MV_MAZE_HUNTER,                     "maze hunter style"             },
2401   { MV_WHEN_PUSHED,                     "when pushed"                   },
2402   { MV_WHEN_DROPPED,                    "when dropped/thrown"           },
2403
2404   { -1,                                 NULL                            }
2405 };
2406
2407 static struct ValueTextInfo options_move_direction[] =
2408 {
2409   { MV_START_AUTOMATIC,                 "automatic"                     },
2410   { MV_START_LEFT,                      "left"                          },
2411   { MV_START_RIGHT,                     "right"                         },
2412   { MV_START_UP,                        "up"                            },
2413   { MV_START_DOWN,                      "down"                          },
2414   { MV_START_RANDOM,                    "random"                        },
2415   { MV_START_PREVIOUS,                  "previous"                      },
2416
2417   { -1,                                 NULL                            }
2418 };
2419
2420 static struct ValueTextInfo options_move_stepsize[] =
2421 {
2422   { 0,                                  "not moving"                    },
2423   { 1,                                  "very slow"                     },
2424   { 2,                                  "slow"                          },
2425   { 4,                                  "normal"                        },
2426   { 8,                                  "fast"                          },
2427   { 16,                                 "very fast"                     },
2428   { 32,                                 "even faster"                   },
2429
2430   { -1,                                 NULL                            }
2431 };
2432
2433 static struct ValueTextInfo options_move_leave_type[] =
2434 {
2435   { LEAVE_TYPE_UNLIMITED,               "leave behind"                  },
2436   { LEAVE_TYPE_LIMITED,                 "change it to"                  },
2437
2438   { -1,                                 NULL                            }
2439 };
2440
2441 static struct ValueTextInfo options_smash_targets[] =
2442 {
2443   { EP_CAN_SMASH_PLAYER,                "player"                        },
2444 #if 0
2445   { EP_CAN_SMASH_ENEMIES,               "enemies"                       },
2446 #endif
2447   { EP_CAN_SMASH_EVERYTHING,            "everything"                    },
2448
2449   { -1,                                 NULL                            }
2450 };
2451
2452 static struct ValueTextInfo options_slippery_type[] =
2453 {
2454   { SLIPPERY_ANY_RANDOM,                "random"                        },
2455   { SLIPPERY_ANY_LEFT_RIGHT,            "left, right"                   },
2456   { SLIPPERY_ANY_RIGHT_LEFT,            "right, left"                   },
2457   { SLIPPERY_ONLY_LEFT,                 "only left"                     },
2458   { SLIPPERY_ONLY_RIGHT,                "only right"                    },
2459
2460   { -1,                                 NULL                            }
2461 };
2462
2463 static struct ValueTextInfo options_deadliness[] =
2464 {
2465   { EP_DONT_RUN_INTO,                   "running into"                  },
2466   { EP_DONT_COLLIDE_WITH,               "colliding with"                },
2467   { EP_DONT_GET_HIT_BY,                 "getting hit by"                },
2468   { EP_DONT_TOUCH,                      "touching"                      },
2469
2470   { -1,                                 NULL                            }
2471 };
2472
2473 static struct ValueTextInfo options_explosion_type[] =
2474 {
2475   { EXPLODES_3X3,                       "3x3"                           },
2476   { EXPLODES_CROSS,                     "3+3"                           },
2477   { EXPLODES_1X1,                       "1x1"                           },
2478
2479   { -1,                                 NULL                            }
2480 };
2481
2482 static struct ValueTextInfo options_time_units[] =
2483 {
2484   { 1,                                  "frames"                        },
2485   { FRAMES_PER_SECOND,                  "seconds"                       },
2486
2487   { -1,                                 NULL                            }
2488 };
2489
2490 static struct ValueTextInfo options_change_direct_action[] =
2491 {
2492   { CE_TOUCHED_BY_PLAYER,               "touched by player"             },
2493   { CE_PRESSED_BY_PLAYER,               "pressed by player"             },
2494   { CE_SWITCHED_BY_PLAYER,              "switched by player"            },
2495   { CE_SNAPPED_BY_PLAYER,               "snapped by player"             },
2496   { CE_PUSHED_BY_PLAYER,                "pushed by player"              },
2497   { CE_ENTERED_BY_PLAYER,               "entered by player"             },
2498   { CE_LEFT_BY_PLAYER,                  "left by player"                },
2499   { CE_DROPPED_BY_PLAYER,               "dropped/thrown by player"      },
2500   { CE_SWITCHED,                        "switched"                      },
2501   { CE_HITTING_SOMETHING,               "hitting something"             },
2502   { CE_HIT_BY_SOMETHING,                "hit by something"              },
2503 #if 0
2504   { CE_BLOCKED,                         "blocked"                       },
2505 #endif
2506   { CE_IMPACT,                          "impact (on something)"         },
2507   { CE_SMASHED,                         "smashed (from above)"          },
2508 #if 0
2509   { CE_VALUE_CHANGES,                   "CE value changes"              },
2510   { CE_SCORE_CHANGES,                   "CE score changes"              },
2511 #endif
2512   { CE_VALUE_GETS_ZERO,                 "CE value gets 0"               },
2513   { CE_SCORE_GETS_ZERO,                 "CE score gets 0"               },
2514   { CE_UNDEFINED,                       " "                             },
2515   { CE_HEADLINE_SPECIAL_EVENTS,         "[mouse events]"                },
2516   { CE_CLICKED_BY_MOUSE,                "clicked by mouse"              },
2517   { CE_PRESSED_BY_MOUSE,                "pressed by mouse"              },
2518   { CE_UNDEFINED,                       " "                             },
2519   { CE_HEADLINE_SPECIAL_EVENTS,         "[static states]"               },
2520   { CE_NEXT_TO_PLAYER,                  "next to player"                },
2521
2522   { -1,                                 NULL                            }
2523 };
2524
2525 static struct ValueTextInfo options_change_other_action[] =
2526 {
2527   { CE_PLAYER_TOUCHES_X,                "player touches"                },
2528   { CE_PLAYER_PRESSES_X,                "player presses"                },
2529   { CE_PLAYER_SWITCHES_X,               "player switches"               },
2530   { CE_PLAYER_SNAPS_X,                  "player snaps"                  },
2531   { CE_PLAYER_PUSHES_X,                 "player pushes"                 },
2532   { CE_PLAYER_ENTERS_X,                 "player enters"                 },
2533   { CE_PLAYER_LEAVES_X,                 "player leaves"                 },
2534   { CE_PLAYER_DIGS_X,                   "player digs"                   },
2535   { CE_PLAYER_COLLECTS_X,               "player collects"               },
2536   { CE_PLAYER_DROPS_X,                  "player drops/throws"           },
2537   { CE_TOUCHING_X,                      "touching"                      },
2538   { CE_HITTING_X,                       "hitting"                       },
2539   { CE_DIGGING_X,                       "digging"                       },
2540   { CE_HIT_BY_X,                        "hit by"                        },
2541   { CE_SWITCH_OF_X,                     "switch of"                     },
2542   { CE_CHANGE_OF_X,                     "change by page of"             },
2543   { CE_EXPLOSION_OF_X,                  "explosion of"                  },
2544   { CE_MOVE_OF_X,                       "move of"                       },
2545   { CE_CREATION_OF_X,                   "creation of"                   },
2546   { CE_VALUE_CHANGES_OF_X,              "CE value changes of"           },
2547   { CE_SCORE_CHANGES_OF_X,              "CE score changes of"           },
2548   { CE_VALUE_GETS_ZERO_OF_X,            "CE value gets 0 of"            },
2549   { CE_SCORE_GETS_ZERO_OF_X,            "CE score gets 0 of"            },
2550   { CE_UNDEFINED,                       " "                             },
2551   { CE_HEADLINE_SPECIAL_EVENTS,         "[mouse events]"                },
2552   { CE_MOUSE_CLICKED_ON_X,              "mouse clicked on"              },
2553   { CE_MOUSE_PRESSED_ON_X,              "mouse pressed on"              },
2554   { CE_UNDEFINED,                       " "                             },
2555   { CE_HEADLINE_SPECIAL_EVENTS,         "[static states]"               },
2556   { CE_PLAYER_NEXT_TO_X,                "player next to"                },
2557   { CE_NEXT_TO_X,                       "next to"                       },
2558
2559   { -1,                                 NULL                            }
2560 };
2561
2562 static struct ValueTextInfo options_change_trigger_side[] =
2563 {
2564   { CH_SIDE_LEFT,                       "left"                          },
2565   { CH_SIDE_RIGHT,                      "right"                         },
2566   { CH_SIDE_TOP,                        "top"                           },
2567   { CH_SIDE_BOTTOM,                     "bottom"                        },
2568   { CH_SIDE_LEFT_RIGHT,                 "left/right"                    },
2569   { CH_SIDE_TOP_BOTTOM,                 "top/bottom"                    },
2570   { CH_SIDE_ANY,                        "any"                           },
2571
2572   { -1,                                 NULL                            }
2573 };
2574
2575 static struct ValueTextInfo options_change_trigger_player[] =
2576 {
2577   { CH_PLAYER_1,                        "1"                             },
2578   { CH_PLAYER_2,                        "2"                             },
2579   { CH_PLAYER_3,                        "3"                             },
2580   { CH_PLAYER_4,                        "4"                             },
2581   { CH_PLAYER_ANY,                      "any"                           },
2582
2583   { -1,                                 NULL                            }
2584 };
2585
2586 static struct ValueTextInfo options_change_trigger_page[] =
2587 {
2588   { (1u << 0),                          "1"                             },
2589   { (1u << 1),                          "2"                             },
2590   { (1u << 2),                          "3"                             },
2591   { (1u << 3),                          "4"                             },
2592   { (1u << 4),                          "5"                             },
2593   { (1u << 5),                          "6"                             },
2594   { (1u << 6),                          "7"                             },
2595   { (1u << 7),                          "8"                             },
2596   { (1u << 8),                          "9"                             },
2597   { (1u << 9),                          "10"                            },
2598   { (1u << 10),                         "11"                            },
2599   { (1u << 11),                         "12"                            },
2600   { (1u << 12),                         "13"                            },
2601   { (1u << 13),                         "14"                            },
2602   { (1u << 14),                         "15"                            },
2603   { (1u << 15),                         "16"                            },
2604   { (1u << 16),                         "17"                            },
2605   { (1u << 17),                         "18"                            },
2606   { (1u << 18),                         "19"                            },
2607   { (1u << 19),                         "20"                            },
2608   { (1u << 20),                         "21"                            },
2609   { (1u << 21),                         "22"                            },
2610   { (1u << 22),                         "23"                            },
2611   { (1u << 23),                         "24"                            },
2612   { (1u << 24),                         "25"                            },
2613   { (1u << 25),                         "26"                            },
2614   { (1u << 26),                         "27"                            },
2615   { (1u << 27),                         "28"                            },
2616   { (1u << 28),                         "29"                            },
2617   { (1u << 29),                         "30"                            },
2618   { (1u << 30),                         "31"                            },
2619   { (1u << 31),                         "32"                            },
2620   { CH_PAGE_ANY,                        "any"                           },
2621
2622   { -1,                                 NULL                            }
2623 };
2624
2625 static struct ValueTextInfo options_change_replace_when[] =
2626 {
2627   { CP_WHEN_EMPTY,                      "empty"                         },
2628   { CP_WHEN_WALKABLE,                   "walkable"                      },
2629   { CP_WHEN_DIGGABLE,                   "diggable"                      },
2630   { CP_WHEN_COLLECTIBLE,                "collectible"                   },
2631   { CP_WHEN_REMOVABLE,                  "removable"                     },
2632   { CP_WHEN_DESTRUCTIBLE,               "destructible"                  },
2633
2634   { -1,                                 NULL                            }
2635 };
2636
2637 static struct ValueTextInfo options_action_type[] =
2638 {
2639   { CA_NO_ACTION,                       "no action"                     },
2640   { CA_UNDEFINED,                       " "                             },
2641   { CA_HEADLINE_LEVEL_ACTIONS,          "[level]"                       },
2642   { CA_RESTART_LEVEL,                   "restart level"                 },
2643   { CA_SHOW_ENVELOPE,                   "show envelope"                 },
2644   { CA_SET_LEVEL_TIME,                  "set time"                      },
2645   { CA_SET_LEVEL_SCORE,                 "set score"                     },
2646   { CA_SET_LEVEL_GEMS,                  "set gems"                      },
2647   { CA_SET_LEVEL_WIND,                  "set wind dir."                 },
2648   { CA_SET_LEVEL_RANDOM_SEED,           "set random seed"               },
2649   { CA_UNDEFINED,                       " "                             },
2650   { CA_HEADLINE_PLAYER_ACTIONS,         "[player]"                      },
2651   { CA_MOVE_PLAYER,                     "move player"                   },
2652   { CA_MOVE_PLAYER_NEW,                 "move player new"               },
2653   { CA_EXIT_PLAYER,                     "exit player"                   },
2654   { CA_KILL_PLAYER,                     "kill player"                   },
2655   { CA_SET_PLAYER_KEYS,                 "set keys"                      },
2656   { CA_SET_PLAYER_SPEED,                "set speed"                     },
2657   { CA_SET_PLAYER_SHIELD,               "set shield"                    },
2658   { CA_SET_PLAYER_GRAVITY,              "set gravity"                   },
2659   { CA_SET_PLAYER_ARTWORK,              "set artwork"                   },
2660   { CA_SET_PLAYER_INVENTORY,            "set inventory"                 },
2661   { CA_UNDEFINED,                       " "                             },
2662   { CA_HEADLINE_CE_ACTIONS,             "[CE]"                          },
2663   { CA_SET_CE_VALUE,                    "set CE value"                  },
2664   { CA_SET_CE_SCORE,                    "set CE score"                  },
2665   { CA_SET_CE_ARTWORK,                  "set CE artwork"                },
2666   { CA_UNDEFINED,                       " "                             },
2667   { CA_HEADLINE_ENGINE_ACTIONS,         "[engine]"                      },
2668   { CA_SET_ENGINE_SCAN_MODE,            "set scan mode"                 },
2669
2670   { -1,                                 NULL                            }
2671 };
2672
2673 static struct ValueTextInfo options_action_mode_none[] =
2674 {
2675   { CA_MODE_UNDEFINED,                  " "                             },
2676
2677   { -1,                                 NULL                            }
2678 };
2679
2680 static struct ValueTextInfo options_action_mode_assign[] =
2681 {
2682   { CA_MODE_SET,                        "="                             },
2683
2684   { -1,                                 NULL                            }
2685 };
2686
2687 static struct ValueTextInfo options_action_mode_add_remove[] =
2688 {
2689   { CA_MODE_ADD,                        "+"                             },
2690   { CA_MODE_SUBTRACT,                   "-"                             },
2691
2692   { -1,                                 NULL                            }
2693 };
2694
2695 static struct ValueTextInfo options_action_mode_calculate[] =
2696 {
2697   { CA_MODE_SET,                        "="                             },
2698   { CA_MODE_ADD,                        "+"                             },
2699   { CA_MODE_SUBTRACT,                   "-"                             },
2700   { CA_MODE_MULTIPLY,                   "*"                             },
2701   { CA_MODE_DIVIDE,                     "/"                             },
2702   { CA_MODE_MODULO,                     "%"                             },
2703
2704   { -1,                                 NULL                            }
2705 };
2706
2707 static struct ValueTextInfo options_action_arg_none[] =
2708 {
2709   { CA_ARG_UNDEFINED,                   "         "                     },
2710
2711   { -1,                                 NULL                            }
2712 };
2713
2714 static struct ValueTextInfo options_action_arg_player[] =
2715 {
2716   { CA_ARG_PLAYER_HEADLINE,             "[player]"                      },
2717   { CA_ARG_PLAYER_1,                    "1"                             },
2718   { CA_ARG_PLAYER_2,                    "2"                             },
2719   { CA_ARG_PLAYER_3,                    "3"                             },
2720   { CA_ARG_PLAYER_4,                    "4"                             },
2721   { CA_ARG_PLAYER_ANY,                  "any"                           },
2722   { CA_ARG_PLAYER_TRIGGER,              "trigger"                       },
2723   { CA_ARG_PLAYER_ACTION,               "action ->"                     },
2724
2725   { -1,                                 NULL                            }
2726 };
2727
2728 static struct ValueTextInfo options_action_arg_number[] =
2729 {
2730   { CA_ARG_NUMBER_HEADLINE,             "[number]"                      },
2731   { CA_ARG_0,                           "0"                             },
2732   { CA_ARG_1,                           "1"                             },
2733   { CA_ARG_2,                           "2"                             },
2734   { CA_ARG_3,                           "3"                             },
2735   { CA_ARG_4,                           "4"                             },
2736   { CA_ARG_5,                           "5"                             },
2737   { CA_ARG_10,                          "10"                            },
2738   { CA_ARG_100,                         "100"                           },
2739   { CA_ARG_1000,                        "1000"                          },
2740   { CA_ARG_UNDEFINED,                   " "                             },
2741   { CA_ARG_NUMBER_MIN,                  "min"                           },
2742   { CA_ARG_NUMBER_MAX,                  "max"                           },
2743   { CA_ARG_UNDEFINED,                   " "                             },
2744   { CA_ARG_NUMBER_RESET,                "reset"                         },
2745   { CA_ARG_UNDEFINED,                   " "                             },
2746   { CA_ARG_NUMBER_CE_VALUE,             "CE value"                      },
2747   { CA_ARG_NUMBER_CE_SCORE,             "CE score"                      },
2748   { CA_ARG_NUMBER_CE_DELAY,             "CE delay"                      },
2749   { CA_ARG_UNDEFINED,                   " "                             },
2750   { CA_ARG_NUMBER_LEVEL_TIME,           "time"                          },
2751   { CA_ARG_NUMBER_LEVEL_GEMS,           "gems"                          },
2752   { CA_ARG_NUMBER_LEVEL_SCORE,          "score"                         },
2753   { CA_ARG_UNDEFINED,                   " "                             },
2754   { CA_ARG_ELEMENT_CV_HEADLINE,         "[CE value]"                    },
2755   { CA_ARG_ELEMENT_CV_TARGET,           "target"                        },
2756   { CA_ARG_ELEMENT_CV_TRIGGER,          "trigger"                       },
2757   { CA_ARG_ELEMENT_CV_ACTION,           "action ->"                     },
2758   { CA_ARG_UNDEFINED,                   " "                             },
2759   { CA_ARG_ELEMENT_CS_HEADLINE,         "[CE score]"                    },
2760   { CA_ARG_ELEMENT_CS_TARGET,           "target"                        },
2761   { CA_ARG_ELEMENT_CS_TRIGGER,          "trigger"                       },
2762   { CA_ARG_ELEMENT_CS_ACTION,           "action ->"                     },
2763
2764   { -1,                                 NULL                            }
2765 };
2766
2767 static struct ValueTextInfo options_action_arg_value[] =
2768 {
2769   { CA_ARG_NUMBER_HEADLINE,             "[number]"                      },
2770   { CA_ARG_0,                           "0"                             },
2771   { CA_ARG_1,                           "1"                             },
2772   { CA_ARG_2,                           "2"                             },
2773   { CA_ARG_3,                           "3"                             },
2774   { CA_ARG_4,                           "4"                             },
2775   { CA_ARG_5,                           "5"                             },
2776   { CA_ARG_10,                          "10"                            },
2777   { CA_ARG_100,                         "100"                           },
2778   { CA_ARG_1000,                        "1000"                          },
2779   { CA_ARG_UNDEFINED,                   " "                             },
2780   { CA_ARG_NUMBER_MIN,                  "min"                           },
2781   { CA_ARG_NUMBER_MAX,                  "max"                           },
2782   { CA_ARG_UNDEFINED,                   " "                             },
2783   { CA_ARG_NUMBER_RESET,                "reset"                         },
2784   { CA_ARG_UNDEFINED,                   " "                             },
2785   { CA_ARG_NUMBER_CE_VALUE,             "CE value"                      },
2786   { CA_ARG_NUMBER_CE_SCORE,             "CE score"                      },
2787   { CA_ARG_NUMBER_CE_DELAY,             "CE delay"                      },
2788   { CA_ARG_UNDEFINED,                   " "                             },
2789   { CA_ARG_NUMBER_LEVEL_TIME,           "time"                          },
2790   { CA_ARG_NUMBER_LEVEL_GEMS,           "gems"                          },
2791   { CA_ARG_NUMBER_LEVEL_SCORE,          "score"                         },
2792   { CA_ARG_UNDEFINED,                   " "                             },
2793   { CA_ARG_ELEMENT_CV_HEADLINE,         "[CE value]"                    },
2794   { CA_ARG_ELEMENT_CV_TARGET,           "target"                        },
2795   { CA_ARG_ELEMENT_CV_TRIGGER,          "trigger"                       },
2796   { CA_ARG_ELEMENT_CV_ACTION,           "action ->"                     },
2797   { CA_ARG_UNDEFINED,                   " "                             },
2798   { CA_ARG_ELEMENT_CS_HEADLINE,         "[CE score]"                    },
2799   { CA_ARG_ELEMENT_CS_TARGET,           "target"                        },
2800   { CA_ARG_ELEMENT_CS_TRIGGER,          "trigger"                       },
2801   { CA_ARG_ELEMENT_CS_ACTION,           "action ->"                     },
2802   { CA_ARG_UNDEFINED,                   " "                             },
2803   { CA_ARG_ELEMENT_NR_HEADLINE,         "[element]"                     },
2804   { CA_ARG_ELEMENT_NR_TARGET,           "target"                        },
2805   { CA_ARG_ELEMENT_NR_TRIGGER,          "trigger"                       },
2806   { CA_ARG_ELEMENT_NR_ACTION,           "action ->"                     },
2807
2808   { -1,                                 NULL                            }
2809 };
2810
2811 static struct ValueTextInfo options_action_arg_envelope[] =
2812 {
2813   { CA_ARG_NUMBER_HEADLINE,             "[number]"                      },
2814   { CA_ARG_1,                           "1"                             },
2815   { CA_ARG_2,                           "2"                             },
2816   { CA_ARG_3,                           "3"                             },
2817   { CA_ARG_4,                           "4"                             },
2818   { CA_ARG_UNDEFINED,                   " "                             },
2819   { CA_ARG_ELEMENT_HEADLINE,            "[element]"                     },
2820   { CA_ARG_ELEMENT_TARGET,              "target"                        },
2821   { CA_ARG_ELEMENT_TRIGGER,             "trigger"                       },
2822   { CA_ARG_ELEMENT_ACTION,              "action ->"                     },
2823
2824   { -1,                                 NULL                            }
2825 };
2826
2827 static struct ValueTextInfo options_action_arg_key[] =
2828 {
2829   { CA_ARG_NUMBER_HEADLINE,             "[number]"                      },
2830   { CA_ARG_1,                           "1"                             },
2831   { CA_ARG_2,                           "2"                             },
2832   { CA_ARG_3,                           "3"                             },
2833   { CA_ARG_4,                           "4"                             },
2834   { CA_ARG_5,                           "5"                             },
2835   { CA_ARG_6,                           "6"                             },
2836   { CA_ARG_7,                           "7"                             },
2837   { CA_ARG_8,                           "8"                             },
2838   { CA_ARG_UNDEFINED,                   " "                             },
2839   { CA_ARG_ELEMENT_HEADLINE,            "[element]"                     },
2840   { CA_ARG_ELEMENT_TARGET,              "target"                        },
2841   { CA_ARG_ELEMENT_TRIGGER,             "trigger"                       },
2842   { CA_ARG_ELEMENT_ACTION,              "action ->"                     },
2843
2844   { -1,                                 NULL                            }
2845 };
2846
2847 static struct ValueTextInfo options_action_arg_speed[] =
2848 {
2849   { CA_ARG_SPEED_HEADLINE,              "[speed]"                       },
2850   { CA_ARG_SPEED_NOT_MOVING,            "frozen"                        },
2851   { CA_ARG_SPEED_VERY_SLOW,             "very slow"                     },
2852   { CA_ARG_SPEED_SLOW,                  "slow"                          },
2853   { CA_ARG_SPEED_NORMAL,                "normal"                        },
2854   { CA_ARG_SPEED_FAST,                  "fast"                          },
2855   { CA_ARG_SPEED_VERY_FAST,             "very fast"                     },
2856   { CA_ARG_SPEED_EVEN_FASTER,           "ultrafast"                     },
2857   { CA_ARG_UNDEFINED,                   " "                             },
2858   { CA_ARG_SPEED_SLOWER,                "slower"                        },
2859   { CA_ARG_SPEED_FASTER,                "faster"                        },
2860   { CA_ARG_UNDEFINED,                   " "                             },
2861   { CA_ARG_SPEED_RESET,                 "reset"                         },
2862
2863   { -1,                                 NULL                            }
2864 };
2865
2866 static struct ValueTextInfo options_action_arg_shield[] =
2867 {
2868   { CA_ARG_SHIELD_HEADLINE,             "[shield]"                      },
2869   { CA_ARG_SHIELD_OFF,                  "off"                           },
2870   { CA_ARG_SHIELD_NORMAL,               "normal"                        },
2871   { CA_ARG_SHIELD_DEADLY,               "deadly"                        },
2872
2873   { -1,                                 NULL                            }
2874 };
2875
2876 static struct ValueTextInfo options_action_arg_artwork[] =
2877 {
2878   { CA_ARG_ELEMENT_HEADLINE,            "[element]"                     },
2879   { CA_ARG_ELEMENT_TARGET,              "target"                        },
2880   { CA_ARG_ELEMENT_TRIGGER,             "trigger"                       },
2881   { CA_ARG_ELEMENT_ACTION,              "action ->"                     },
2882   { CA_ARG_UNDEFINED,                   " "                             },
2883   { CA_ARG_ELEMENT_RESET,               "reset"                         },
2884
2885   { -1,                                 NULL                            }
2886 };
2887
2888 static struct ValueTextInfo options_action_arg_gravity[] =
2889 {
2890   { CA_ARG_GRAVITY_HEADLINE,            "[gravity]"                     },
2891   { CA_ARG_GRAVITY_ON,                  "on"                            },
2892   { CA_ARG_GRAVITY_OFF,                 "off"                           },
2893   { CA_ARG_GRAVITY_TOGGLE,              "toggle"                        },
2894
2895   { -1,                                 NULL                            }
2896 };
2897
2898 static struct ValueTextInfo options_action_arg_direction[] =
2899 {
2900   { CA_ARG_DIRECTION_HEADLINE,          "[dir.]"                        },
2901   { CA_ARG_DIRECTION_NONE,              "none"                          },
2902   { CA_ARG_DIRECTION_LEFT,              "left"                          },
2903   { CA_ARG_DIRECTION_RIGHT,             "right"                         },
2904   { CA_ARG_DIRECTION_UP,                "up"                            },
2905   { CA_ARG_DIRECTION_DOWN,              "down"                          },
2906   { CA_ARG_DIRECTION_TRIGGER,           "trigger"                       },
2907   { CA_ARG_DIRECTION_TRIGGER_BACK,      "-trigger"                      },
2908
2909   { -1,                                 NULL                            }
2910 };
2911
2912 static struct ValueTextInfo options_action_arg_scan_mode[] =
2913 {
2914   { CA_ARG_SCAN_MODE_HEADLINE,          "[mode]"                        },
2915   { CA_ARG_SCAN_MODE_NORMAL,            "normal"                        },
2916   { CA_ARG_SCAN_MODE_REVERSE,           "reverse"                       },
2917
2918   { -1,                                 NULL                            }
2919 };
2920
2921 static struct ValueTextInfo options_action_arg_inventory[] =
2922 {
2923   { CA_ARG_INVENTORY_HEADLINE,          "[add]"                         },
2924   { CA_ARG_ELEMENT_TARGET,              "+ target"                      },
2925   { CA_ARG_ELEMENT_TRIGGER,             "+ trigger"                     },
2926   { CA_ARG_ELEMENT_ACTION,              "+ action"                      },
2927   { CA_ARG_UNDEFINED,                   " "                             },
2928   { CA_ARG_INVENTORY_RM_HEADLINE,       "[remove]"                      },
2929   { CA_ARG_INVENTORY_RM_TARGET,         "- target"                      },
2930   { CA_ARG_INVENTORY_RM_TRIGGER,        "- trigger"                     },
2931   { CA_ARG_INVENTORY_RM_ACTION,         "- action"                      },
2932   { CA_ARG_INVENTORY_RM_FIRST,          "- first"                       },
2933   { CA_ARG_INVENTORY_RM_LAST,           "- last"                        },
2934   { CA_ARG_INVENTORY_RM_ALL,            "- all"                         },
2935   { CA_ARG_UNDEFINED,                   " "                             },
2936   { CA_ARG_INVENTORY_RESET,             "reset"                         },
2937
2938   { -1,                                 NULL                            }
2939 };
2940
2941 static char options_change_page_strings[MAX_CHANGE_PAGES][10];
2942 static struct ValueTextInfo options_change_page[MAX_CHANGE_PAGES + 1] =
2943 {
2944   { -1,                                 NULL                            }
2945 };
2946
2947 static struct ValueTextInfo options_group_choice_mode[] =
2948 {
2949   { ANIM_RANDOM,                        "random"                        },
2950   { ANIM_LOOP,                          "loop"                          },
2951   { ANIM_LINEAR,                        "linear"                        },
2952   { ANIM_PINGPONG,                      "pingpong"                      },
2953   { ANIM_PINGPONG2,                     "pingpong 2"                    },
2954   { ANIM_LEVEL_NR,                      "level number"                  },
2955
2956   { -1,                                 NULL                            }
2957 };
2958
2959 static struct ValueTextInfo options_bd_scheduling_type[] =
2960 {
2961   { GD_SCHEDULING_MILLISECONDS,         "Milliseconds"                  },
2962   { GD_SCHEDULING_BD1,                  "BD1"                           },
2963   { GD_SCHEDULING_BD2,                  "BD2"                           },
2964   { GD_SCHEDULING_PLCK,                 "Construction Kit"              },
2965   { GD_SCHEDULING_CRDR,                 "Crazy Dream 7"                 },
2966   { GD_SCHEDULING_BD1_ATARI,            "Atari BD1"                     },
2967   { GD_SCHEDULING_BD2_PLCK_ATARI,       "Atari BD2 / PLCK"              },
2968
2969   { -1,                                   NULL                          }
2970 };
2971
2972 static struct ValueTextInfo options_bd_color_type[] =
2973 {
2974   { GD_COLOR_TYPE_RGB,                  "RGB colors"                    },
2975   { GD_COLOR_TYPE_C64,                  "C64 colors"                    },
2976   { GD_COLOR_TYPE_C64DTV,               "C64DTV colors"                 },
2977   { GD_COLOR_TYPE_ATARI,                "Atari colors"                  },
2978
2979   { -1,                                   NULL                          }
2980 };
2981
2982 static struct ValueTextInfo options_bd_color_c64_name[] =
2983 {
2984   { GD_COLOR_INDEX_BLACK,               "Black"                         },
2985   { GD_COLOR_INDEX_WHITE,               "White"                         },
2986   { GD_COLOR_INDEX_RED,                 "Red"                           },
2987   { GD_COLOR_INDEX_CYAN,                "Cyan"                          },
2988   { GD_COLOR_INDEX_PURPLE,              "Purple"                        },
2989   { GD_COLOR_INDEX_GREEN,               "Green"                         },
2990   { GD_COLOR_INDEX_BLUE,                "Blue"                          },
2991   { GD_COLOR_INDEX_YELLOW,              "Yellow"                        },
2992   { GD_COLOR_INDEX_ORANGE,              "Orange"                        },
2993   { GD_COLOR_INDEX_BROWN,               "Brown"                         },
2994   { GD_COLOR_INDEX_LIGHTRED,            "Light red"                     },
2995   { GD_COLOR_INDEX_GRAY1,               "Dark gray"                     },
2996   { GD_COLOR_INDEX_GRAY2,               "Gray"                          },
2997   { GD_COLOR_INDEX_LIGHTGREEN,          "Light green"                   },
2998   { GD_COLOR_INDEX_LIGHTBLUE,           "Light blue"                    },
2999   { GD_COLOR_INDEX_GRAY3,               "Light gray"                    },
3000
3001   { -1,                                   NULL                          }
3002 };
3003
3004 static struct ValueTextInfo *action_arg_modes[] =
3005 {
3006   options_action_mode_none,
3007   options_action_mode_assign,
3008   options_action_mode_add_remove,
3009   options_action_mode_calculate,
3010 };
3011
3012 static struct
3013 {
3014   int value;
3015   int mode;
3016   struct ValueTextInfo *options;
3017 }
3018 action_arg_options[] =
3019 {
3020   { CA_NO_ACTION,               0,      options_action_arg_none,        },
3021   { CA_EXIT_PLAYER,             0,      options_action_arg_player,      },
3022   { CA_KILL_PLAYER,             0,      options_action_arg_player,      },
3023   { CA_MOVE_PLAYER,             0,      options_action_arg_direction,   },
3024   { CA_MOVE_PLAYER_NEW,         0,      options_action_arg_direction,   },
3025   { CA_RESTART_LEVEL,           0,      options_action_arg_none,        },
3026   { CA_SHOW_ENVELOPE,           0,      options_action_arg_envelope,    },
3027   { CA_SET_LEVEL_TIME,          3,      options_action_arg_number,      },
3028   { CA_SET_LEVEL_GEMS,          3,      options_action_arg_number,      },
3029   { CA_SET_LEVEL_SCORE,         3,      options_action_arg_number,      },
3030   { CA_SET_LEVEL_WIND,          1,      options_action_arg_direction,   },
3031   { CA_SET_LEVEL_RANDOM_SEED,   1,      options_action_arg_number,      },
3032   { CA_SET_PLAYER_KEYS,         2,      options_action_arg_key,         },
3033   { CA_SET_PLAYER_SPEED,        1,      options_action_arg_speed,       },
3034   { CA_SET_PLAYER_SHIELD,       1,      options_action_arg_shield,      },
3035   { CA_SET_PLAYER_GRAVITY,      1,      options_action_arg_gravity,     },
3036   { CA_SET_PLAYER_ARTWORK,      1,      options_action_arg_artwork,     },
3037   { CA_SET_PLAYER_INVENTORY,    0,      options_action_arg_inventory,   },
3038   { CA_SET_CE_VALUE,            3,      options_action_arg_value,       },
3039   { CA_SET_CE_SCORE,            3,      options_action_arg_value,       },
3040   { CA_SET_CE_ARTWORK,          1,      options_action_arg_artwork,     },
3041   { CA_SET_ENGINE_SCAN_MODE,    1,      options_action_arg_scan_mode,   },
3042
3043   { -1,                         FALSE,  NULL                            }
3044 };
3045
3046 static struct
3047 {
3048   int gadget_type_id;
3049   int x, y;
3050   int gadget_id;
3051   int gadget_id_align;
3052   int size;     // char size of selectbox or '-1' (dynamically determined)
3053   struct ValueTextInfo *options;
3054   int *value;
3055   char *text_above, *text_left, *text_right, *infotext;
3056 } selectbox_info[ED_NUM_SELECTBOX] =
3057 {
3058   // ---------- level and editor settings -------------------------------------
3059
3060   {
3061     ED_SELECTBOX_ID_TIME_OR_STEPS,
3062     -1,                                         ED_LEVEL_SETTINGS_YPOS(8),
3063     GADGET_ID_TIME_OR_STEPS,                    GADGET_ID_LEVEL_TIMELIMIT_UP,
3064     -1,
3065     options_time_or_steps,
3066     &level.use_step_counter,
3067     NULL, NULL, "(0 => no limit)",              "Select time or step limit"
3068   },
3069   {
3070     ED_SELECTBOX_ID_TIME_SCORE_BASE,
3071     -1,                                         ED_LEVEL_SETTINGS_YPOS(10),
3072     GADGET_ID_TIME_SCORE_BASE,                  GADGET_ID_LEVEL_TIMESCORE_UP,
3073     -1,
3074     options_time_score_base,
3075     &level.time_score_base,
3076     NULL, NULL, NULL,                           "Select time score for 1 or 10 seconds/steps"
3077   },
3078   {
3079     ED_SELECTBOX_ID_GAME_ENGINE_TYPE,
3080     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(12),
3081     GADGET_ID_GAME_ENGINE_TYPE,                 GADGET_ID_NONE,
3082     -1,
3083     options_game_engine_type,
3084     &level.game_engine_type,
3085     NULL, "Game engine:", NULL,                 "Select game engine"
3086   },
3087   {
3088     ED_SELECTBOX_ID_LEVELSET_SAVE_MODE,
3089     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(10),
3090     GADGET_ID_LEVELSET_SAVE_MODE,               GADGET_ID_NONE,
3091     -1,
3092     options_levelset_save_mode,
3093     &levelset_save_mode,
3094     "Action:", NULL, NULL,                      "Select action when saving level set"
3095   },
3096
3097   // ---------- engine settings: config ---------------------------------------
3098
3099   {
3100     ED_SELECTBOX_ID_BD_SCHEDULING_TYPE,
3101     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(1),
3102     GADGET_ID_BD_SCHEDULING_TYPE,               GADGET_ID_NONE,
3103     -1,
3104     options_bd_scheduling_type,
3105     &level.bd_scheduling_type,
3106     NULL, "Scheduling type:", NULL,             "Select level timing"
3107   },
3108
3109   // ---------- engine settings: colors ---------------------------------------
3110
3111   {
3112     ED_SELECTBOX_ID_BD_COLOR_TYPE,
3113     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(0),
3114     GADGET_ID_BD_COLOR_TYPE,                    GADGET_ID_NONE,
3115     -1,
3116     options_bd_color_type,
3117     &level.bd_color_type,
3118     "Boulder Dash level colors:",
3119     "Color palette type:", NULL,                "Select color palette type"
3120   },
3121   {
3122     ED_SELECTBOX_ID_BD_COLOR_C64_B,
3123     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(1),
3124     GADGET_ID_BD_COLOR_C64_B,                   GADGET_ID_NONE,
3125     -1,
3126     options_bd_color_c64_name,
3127     &bd_color_c64[0],
3128     NULL, "Border color:      ", NULL,          "Select border color (not used)"
3129   },
3130   {
3131     ED_SELECTBOX_ID_BD_COLOR_C64_0,
3132     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(2),
3133     GADGET_ID_BD_COLOR_C64_0,                   GADGET_ID_NONE,
3134     -1,
3135     options_bd_color_c64_name,
3136     &bd_color_c64[1],
3137     NULL, "Background color:  ", NULL,          "Select background color (C64 graphics)"
3138   },
3139   {
3140     ED_SELECTBOX_ID_BD_COLOR_C64_1,
3141     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(3),
3142     GADGET_ID_BD_COLOR_C64_1,                   GADGET_ID_NONE,
3143     -1,
3144     options_bd_color_c64_name,
3145     &bd_color_c64[2],
3146     NULL, "Sand color:        ", NULL,          "Select sand color (C64 graphics)"
3147   },
3148   {
3149     ED_SELECTBOX_ID_BD_COLOR_C64_2,
3150     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(4),
3151     GADGET_ID_BD_COLOR_C64_2,                   GADGET_ID_NONE,
3152     -1,
3153     options_bd_color_c64_name,
3154     &bd_color_c64[3],
3155     NULL, "Steel wall color:  ", NULL,          "Select steel wall color (C64 graphics)"
3156   },
3157   {
3158     ED_SELECTBOX_ID_BD_COLOR_C64_3,
3159     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(5),
3160     GADGET_ID_BD_COLOR_C64_3,                   GADGET_ID_NONE,
3161     -1,
3162     options_bd_color_c64_name,
3163     &bd_color_c64[4],
3164     NULL, "Wall color:        ", NULL,          "Select wall color (C64 graphics)"
3165   },
3166   {
3167     ED_SELECTBOX_ID_BD_COLOR_C64_4,
3168     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(6),
3169     GADGET_ID_BD_COLOR_C64_4,                   GADGET_ID_NONE,
3170     -1,
3171     options_bd_color_c64_name,
3172     &bd_color_c64[5],
3173     NULL, "Amoeba color:      ", NULL,          "Select amoeba color (C64 graphics)"
3174   },
3175   {
3176     ED_SELECTBOX_ID_BD_COLOR_C64_5,
3177     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(7),
3178     GADGET_ID_BD_COLOR_C64_5,                   GADGET_ID_NONE,
3179     -1,
3180     options_bd_color_c64_name,
3181     &bd_color_c64[6],
3182     NULL, "Slime color:       ", NULL,          "Select slime color (C64 graphics)"
3183   },
3184
3185   // ---------- element settings: configure (several elements) ----------------
3186
3187   {
3188     ED_SELECTBOX_ID_WIND_DIRECTION,
3189     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
3190     GADGET_ID_WIND_DIRECTION,                   GADGET_ID_NONE,
3191     -1,
3192     options_wind_direction,
3193     &level.wind_direction_initial,
3194     NULL, "Initial wind direction:", NULL,      "Select initial wind direction"
3195   },
3196   {
3197     ED_SELECTBOX_ID_PLAYER_SPEED,
3198     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(7),
3199     GADGET_ID_PLAYER_SPEED,                     GADGET_ID_NONE,
3200     -1,
3201     options_player_speed,
3202     &level.initial_player_stepsize[0],
3203     NULL, "Initial player speed:", NULL,        "Select initial player speed"
3204   },
3205   {
3206     ED_SELECTBOX_ID_BD_GRAVITY_DIRECTION,
3207     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
3208     GADGET_ID_BD_GRAVITY_DIRECTION,             GADGET_ID_NONE,
3209     -1,
3210     options_bd_gravity_direction,
3211     &level.bd_gravity_direction,
3212     NULL, "Gravity direction:", NULL,           "Select initial gravity direction"
3213   },
3214   {
3215     ED_SELECTBOX_ID_MM_BALL_CHOICE_MODE,
3216     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
3217     GADGET_ID_MM_BALL_CHOICE_MODE,              GADGET_ID_NONE,
3218     -1,
3219     options_group_choice_mode,
3220     &level.mm_ball_choice_mode,
3221     NULL, "Choice type:", NULL,                 "Select type of content choice"
3222   },
3223
3224   // ---------- element settings: configure 1 (custom elements) ---------------
3225
3226   {
3227     ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE,
3228     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(2),
3229     GADGET_ID_CUSTOM_ACCESS_TYPE,               GADGET_ID_NONE,
3230     -1,
3231     options_access_type,
3232     &custom_element.access_type,
3233     NULL, NULL, NULL,                           "Select type of access to this field"
3234   },
3235   {
3236     ED_SELECTBOX_ID_CUSTOM_ACCESS_LAYER,
3237     -1,                                         ED_ELEMENT_SETTINGS_YPOS(2),
3238     GADGET_ID_CUSTOM_ACCESS_LAYER,              GADGET_ID_CUSTOM_ACCESS_TYPE,
3239     -1,
3240     options_access_layer,
3241     &custom_element.access_layer,
3242     NULL, NULL, NULL,                           "Select layer of access for this field"
3243   },
3244   {
3245     ED_SELECTBOX_ID_CUSTOM_ACCESS_PROTECTED,
3246     -1,                                         ED_ELEMENT_SETTINGS_YPOS(2),
3247     GADGET_ID_CUSTOM_ACCESS_PROTECTED,          GADGET_ID_CUSTOM_ACCESS_LAYER,
3248     -1,
3249     options_access_protected,
3250     &custom_element.access_protected,
3251     NULL, NULL, NULL,                           "Select protected access for this field"
3252   },
3253   {
3254     ED_SELECTBOX_ID_CUSTOM_ACCESS_DIRECTION,
3255     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(3),
3256     GADGET_ID_CUSTOM_ACCESS_DIRECTION,          GADGET_ID_NONE,
3257     -1,
3258     options_access_direction,
3259     &custom_element.access_direction,
3260     NULL, "from", NULL,                         "Select access direction for this field"
3261   },
3262   {
3263     ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION,
3264     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(4),
3265     GADGET_ID_CUSTOM_WALK_TO_ACTION,            GADGET_ID_NONE,
3266     -1,
3267     options_walk_to_action,
3268     &custom_element.walk_to_action,
3269     NULL, NULL, NULL,                           "Select diggable/collectible/pushable"
3270   },
3271
3272   // ---------- element settings: configure 2 (custom elements) ---------------
3273
3274   {
3275     ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN,
3276     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(1),
3277     GADGET_ID_CUSTOM_MOVE_PATTERN,              GADGET_ID_NONE,
3278     -1,
3279     options_move_pattern,
3280     &custom_element.move_pattern,
3281     NULL, "Can move", NULL,                     "Select element move pattern"
3282   },
3283   {
3284     ED_SELECTBOX_ID_CUSTOM_MOVE_DIRECTION,
3285     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(2),
3286     GADGET_ID_CUSTOM_MOVE_DIRECTION,            GADGET_ID_NONE,
3287     -1,
3288     options_move_direction,
3289     &custom_element.move_direction_initial,
3290     NULL, "Starts moving", NULL,                "Select initial element move direction"
3291   },
3292   {
3293     ED_SELECTBOX_ID_CUSTOM_MOVE_STEPSIZE,
3294     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(4),
3295     GADGET_ID_CUSTOM_MOVE_STEPSIZE,             GADGET_ID_NONE,
3296     -1,
3297     options_move_stepsize,
3298     &custom_element.move_stepsize,
3299     NULL, "Move/fall speed", NULL,              "Select speed of element movement"
3300   },
3301   {
3302     ED_SELECTBOX_ID_CUSTOM_MOVE_LEAVE_TYPE,
3303     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(3),
3304     GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE,           GADGET_ID_NONE,
3305     -1,
3306     options_move_leave_type,
3307     &custom_element.move_leave_type,
3308     // left text with leading spaces to place gadget next to "can dig" gadget
3309     // (needed because drawing area gadgets created after selectbox gadgets)
3310     // NULL, "can dig:    can", ":",            "leave behind or change element"
3311     NULL, "            Can", ":",               "Select leave behind or change element"
3312   },
3313   {
3314     ED_SELECTBOX_ID_CUSTOM_SMASH_TARGETS,
3315     -1,                                         ED_ELEMENT_SETTINGS_YPOS(8),
3316     GADGET_ID_CUSTOM_SMASH_TARGETS,             GADGET_ID_CUSTOM_CAN_SMASH,
3317     -1,
3318     options_smash_targets,
3319     &custom_element.smash_targets,
3320     NULL, "Can smash", NULL,                    "Select elements that can be smashed"
3321   },
3322   {
3323     ED_SELECTBOX_ID_CUSTOM_SLIPPERY_TYPE,
3324     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(9),
3325     GADGET_ID_CUSTOM_SLIPPERY_TYPE,             GADGET_ID_NONE,
3326     -1,
3327     options_slippery_type,
3328     &custom_element.slippery_type,
3329     NULL, "Slippery", NULL,                     "Select where other elements fall down"
3330   },
3331   {
3332     ED_SELECTBOX_ID_CUSTOM_DEADLINESS,
3333     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(10),
3334     GADGET_ID_CUSTOM_DEADLINESS,                GADGET_ID_NONE,
3335     -1,
3336     options_deadliness,
3337     &custom_element.deadliness,
3338     NULL, "Deadly when", NULL,                  "Select deadliness of element"
3339   },
3340   {
3341     ED_SELECTBOX_ID_CUSTOM_EXPLOSION_TYPE,
3342     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(11),
3343     GADGET_ID_CUSTOM_EXPLOSION_TYPE,            GADGET_ID_NONE,
3344     -1,
3345     options_explosion_type,
3346     &custom_element.explosion_type,
3347     NULL, "Can explode", NULL,                  "Select explosion type"
3348   },
3349
3350   // ---------- element settings: advanced (custom elements) ------------------
3351
3352   {
3353     ED_SELECTBOX_ID_CHANGE_TIME_UNITS,
3354     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(3),
3355     GADGET_ID_CHANGE_TIME_UNITS,                GADGET_ID_NONE,
3356     -1,
3357     options_time_units,
3358     &custom_element_change.delay_frames,
3359     NULL, "Delay time given in", NULL,          "Select delay time units for change"
3360   },
3361   {
3362     ED_SELECTBOX_ID_CHANGE_DIRECT_ACTION,
3363     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(4),
3364     GADGET_ID_CHANGE_DIRECT_ACTION,             GADGET_ID_NONE,
3365     -1,
3366     options_change_direct_action,
3367     &custom_element_change.direct_action,
3368     NULL, NULL, NULL,                           "Select type of direct action"
3369   },
3370   {
3371     ED_SELECTBOX_ID_CHANGE_OTHER_ACTION,
3372     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(5),
3373     GADGET_ID_CHANGE_OTHER_ACTION,              GADGET_ID_NONE,
3374     -1,
3375     options_change_other_action,
3376     &custom_element_change.other_action,
3377     NULL, NULL, "element:",                     "Select type of other element action"
3378   },
3379   {
3380     ED_SELECTBOX_ID_CHANGE_SIDE,
3381     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(6),
3382     GADGET_ID_CHANGE_SIDE,                      GADGET_ID_NONE,
3383     -1,
3384     options_change_trigger_side,
3385     &custom_element_change.trigger_side,
3386     NULL, "at", "side",                         "Select element side triggering change"
3387   },
3388   {
3389     ED_SELECTBOX_ID_CHANGE_PLAYER,
3390     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(7),
3391     GADGET_ID_CHANGE_PLAYER,                    GADGET_ID_NONE,
3392     -1,
3393     options_change_trigger_player,
3394     &custom_element_change.trigger_player,
3395     NULL, "Player:", " ",                       "Select player that causes change"
3396   },
3397   {
3398     ED_SELECTBOX_ID_CHANGE_PAGE,
3399     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(7),
3400     GADGET_ID_CHANGE_PAGE,                      GADGET_ID_CHANGE_PLAYER,
3401     -1,
3402     options_change_trigger_page,
3403     &custom_element_change.trigger_page,
3404     NULL, "Page:", NULL,                        "Select change page that causes change"
3405   },
3406   {
3407     ED_SELECTBOX_ID_CHANGE_REPLACE_WHEN,
3408     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(10),
3409     GADGET_ID_CHANGE_REPLACE_WHEN,              GADGET_ID_NONE,
3410     -1,
3411     options_change_replace_when,
3412     &custom_element_change.replace_when,
3413     NULL, "Replace when", NULL,                 "Select which elements can be replaced"
3414   },
3415   {
3416     ED_SELECTBOX_ID_ACTION_TYPE,
3417     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(13),
3418     GADGET_ID_ACTION_TYPE,                      GADGET_ID_NONE,
3419     15,
3420     options_action_type,
3421     &custom_element_change.action_type,
3422     NULL, NULL, NULL,                           "Select action on specified condition"
3423   },
3424   {
3425     ED_SELECTBOX_ID_ACTION_MODE,
3426     -1,                                         ED_ELEMENT_SETTINGS_YPOS(13),
3427     GADGET_ID_ACTION_MODE,                      GADGET_ID_ACTION_TYPE,
3428     -1,
3429     options_action_mode_none,
3430     &custom_element_change.action_mode,
3431     NULL, NULL, NULL,                           "Select action operator"
3432   },
3433   {
3434     ED_SELECTBOX_ID_ACTION_ARG,
3435     -1,                                         ED_ELEMENT_SETTINGS_YPOS(13),
3436     GADGET_ID_ACTION_ARG,                       GADGET_ID_ACTION_MODE,
3437     -1,
3438     options_action_arg_none,
3439     &custom_element_change.action_arg,
3440     NULL, NULL, NULL,                           "Select action parameter"
3441   },
3442   {
3443     ED_SELECTBOX_ID_SELECT_CHANGE_PAGE,
3444     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(14),
3445     GADGET_ID_SELECT_CHANGE_PAGE,               GADGET_ID_NONE,
3446     3,
3447     options_change_page,
3448     &custom_element.current_change_page,
3449     NULL, NULL, NULL,                           "Select element change page"
3450   },
3451
3452   // ---------- element settings: configure (group elements) ------------------
3453
3454   {
3455     ED_SELECTBOX_ID_GROUP_CHOICE_MODE,
3456     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
3457     GADGET_ID_GROUP_CHOICE_MODE,                GADGET_ID_NONE,
3458     -1,
3459     options_group_choice_mode,
3460     &group_element_info.choice_mode,
3461     NULL, "Choice type:", NULL,                 "Select type of group element choice"
3462   },
3463 };
3464
3465 static struct
3466 {
3467   int gadget_type_id;
3468   int x, y;
3469   int gadget_id;
3470   int gadget_id_align;
3471   int size;
3472   char *text;
3473   char *text_above, *text_left, *text_right, *infotext;
3474 } textbutton_info[ED_NUM_TEXTBUTTONS] =
3475 {
3476   // ---------- level and editor settings (tabs) ------------------------------
3477
3478   {
3479     ED_TEXTBUTTON_ID_LEVELCONFIG_LEVEL,
3480     ED_LEVEL_TABS_XPOS(0),                      ED_LEVEL_TABS_YPOS(0),
3481     GADGET_ID_LEVELCONFIG_LEVEL,                GADGET_ID_NONE,
3482     8,                                          "Level",
3483     NULL, NULL, NULL,                           "Configure level settings"
3484   },
3485   {
3486     ED_TEXTBUTTON_ID_LEVELCONFIG_LEVELSET,
3487     -1,                                         -1,
3488     GADGET_ID_LEVELCONFIG_LEVELSET,             GADGET_ID_LEVELCONFIG_LEVEL,
3489     8,                                          "Levelset",
3490     NULL, NULL, NULL,                           "Update this or create new level set"
3491   },
3492   {
3493     ED_TEXTBUTTON_ID_LEVELCONFIG_EDITOR,
3494     -1,                                         -1,
3495     GADGET_ID_LEVELCONFIG_EDITOR,               GADGET_ID_LEVELCONFIG_LEVELSET,
3496     8,                                          "Editor",
3497     NULL, NULL, NULL,                           "Configure editor settings"
3498   },
3499   {
3500     ED_TEXTBUTTON_ID_LEVELCONFIG_ENGINE,
3501     -1,                                         -1,
3502     GADGET_ID_LEVELCONFIG_ENGINE,               GADGET_ID_LEVELCONFIG_EDITOR,
3503     8,                                          "Engine",
3504     NULL, NULL, NULL,                           "Configure game engine settings"
3505   },
3506
3507   // ---------- engine settings (tabs) ----------------------------------------
3508
3509   {
3510     ED_TEXTBUTTON_ID_ENGINECONFIG_CONFIG,
3511     ED_ENGINE_TABS_XPOS(0),                     ED_ENGINE_TABS_YPOS(0),
3512     GADGET_ID_ENGINECONFIG_CONFIG,              GADGET_ID_NONE,
3513     8,                                          "Config",
3514     NULL, NULL, NULL,                           "Configure game engine settings"
3515   },
3516   {
3517     ED_TEXTBUTTON_ID_ENGINECONFIG_COLORS,
3518     -1,                                         -1,
3519     GADGET_ID_ENGINECONFIG_COLORS,              GADGET_ID_ENGINECONFIG_CONFIG,
3520     8,                                          "Colors",
3521     NULL, NULL, NULL,                           "Configure level colors"
3522   },
3523
3524   // ---------- element settings (tabs) ---------------------------------------
3525
3526   {
3527     ED_TEXTBUTTON_ID_PROPERTIES_INFO,
3528     ED_ELEMENT_TABS_XPOS(0),                    ED_ELEMENT_TABS_YPOS(0),
3529     GADGET_ID_PROPERTIES_INFO,                  GADGET_ID_NONE,
3530     8,                                          "Info",
3531     NULL, NULL, NULL,                           "Show information about element"
3532   },
3533   {
3534     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG,
3535     -1,                                         -1,
3536     GADGET_ID_PROPERTIES_CONFIG,                GADGET_ID_PROPERTIES_INFO,
3537     8,                                          "Config",
3538     NULL, NULL, NULL,                           "Configure element properties"
3539   },
3540   {
3541     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_1,
3542     -1,                                         -1,
3543     GADGET_ID_PROPERTIES_CONFIG_1,              GADGET_ID_PROPERTIES_INFO,
3544     8,                                          "Config 1",
3545     NULL, NULL, NULL,                           "Configure element properties, part 1"
3546   },
3547   {
3548     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2,
3549     -1,                                         -1,
3550     GADGET_ID_PROPERTIES_CONFIG_2,              GADGET_ID_PROPERTIES_CONFIG_1,
3551     8,                                          "Config 2",
3552     NULL, NULL, NULL,                           "Configure element properties, part 2"
3553   },
3554   {
3555     ED_TEXTBUTTON_ID_PROPERTIES_CHANGE,
3556     -1,                                         -1,
3557     GADGET_ID_PROPERTIES_CHANGE,                GADGET_ID_PROPERTIES_CONFIG_2,
3558     8,                                          "Change",
3559     NULL, NULL, NULL,                           "Configure custom element change pages"
3560   },
3561
3562   // ---------- level and editor settings (buttons) ---------------------------
3563
3564   {
3565     ED_TEXTBUTTON_ID_SAVE_LEVELSET,
3566     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(10),
3567     GADGET_ID_SAVE_LEVELSET,                    GADGET_ID_LEVELSET_SAVE_MODE,
3568     -1,                                         "Save",
3569     NULL, NULL, NULL,                           "Update or create level set"
3570   },
3571   {
3572     ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_2,
3573     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(6),
3574     GADGET_ID_SAVE_AS_TEMPLATE_2,               GADGET_ID_NONE,
3575     -1,                                         "Save",
3576     NULL, NULL,                                 "this level as level template",
3577     "Save current settings as new template"
3578   },
3579
3580   // ---------- element settings (buttons) ------------------------------------
3581
3582   {
3583     ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1,
3584     -1,                                         -1,
3585     GADGET_ID_SAVE_AS_TEMPLATE_1,               GADGET_ID_CUSTOM_USE_TEMPLATE_1,
3586     -1,                                         "Save",
3587     NULL, " ",                                  "As Template",
3588     "Save current settings as new template"
3589   },
3590   {
3591     ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE,
3592     -1,                                         -1,
3593     GADGET_ID_ADD_CHANGE_PAGE,                  GADGET_ID_PASTE_CHANGE_PAGE,
3594     -1,                                         "New",
3595     NULL, NULL, NULL,                           "Add new change page"
3596   },
3597   {
3598     ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE,
3599     -1,                                         -1,
3600     GADGET_ID_DEL_CHANGE_PAGE,                  GADGET_ID_ADD_CHANGE_PAGE,
3601     -1,                                         "Delete",
3602     NULL, NULL, NULL,                           "Delete current change page"
3603   },
3604
3605   // ---------- engine settings (buttons) -------------------------------------
3606
3607   {
3608     ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS,
3609     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(8),
3610     GADGET_ID_BD_SET_RANDOM_COLORS,             GADGET_ID_NONE,
3611     -1,                                         "Set random colors",
3612     NULL, NULL, NULL,                           "Create and set random level colors"
3613   },
3614 };
3615
3616 static struct
3617 {
3618   int gadget_type_id;
3619   int graphic;
3620   int x, y;
3621   int gadget_id;
3622   int gadget_id_align;
3623   char *text_left, *text_right, *infotext;
3624 } graphicbutton_info[ED_NUM_GRAPHICBUTTONS] =
3625 {
3626   {
3627     ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE,
3628     IMG_EDITOR_COUNTER_DOWN,
3629     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(14),
3630     GADGET_ID_PREV_CHANGE_PAGE,                 GADGET_ID_NONE,
3631     NULL, NULL,                                 "Select previous change page"
3632   },
3633   {
3634     ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE,
3635     IMG_EDITOR_COUNTER_UP,
3636     -1,                                         ED_ELEMENT_SETTINGS_YPOS(14),
3637     GADGET_ID_NEXT_CHANGE_PAGE,                 GADGET_ID_SELECT_CHANGE_PAGE,
3638     NULL, "Change page",                        "Select next change page"
3639   },
3640   {
3641     ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE,
3642     IMG_GFX_EDITOR_BUTTON_CP_COPY,
3643     -1,                                         ED_ELEMENT_SETTINGS_YPOS(14),
3644     GADGET_ID_COPY_CHANGE_PAGE,                 GADGET_ID_NEXT_CHANGE_PAGE,
3645     " ", NULL,                                  "Copy settings from this change page"
3646   },
3647   {
3648     ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE,
3649     IMG_GFX_EDITOR_BUTTON_CP_PASTE,
3650     -1,                                         ED_ELEMENT_SETTINGS_YPOS(14),
3651     GADGET_ID_PASTE_CHANGE_PAGE,                GADGET_ID_COPY_CHANGE_PAGE,
3652     NULL, NULL,                                 "Paste settings to this change page"
3653   },
3654 };
3655
3656 static struct
3657 {
3658   int x, y;
3659 } scrollbutton_pos[ED_NUM_SCROLLBUTTONS];
3660
3661 static struct
3662 {
3663   int gadget_type_id;
3664   int graphic;
3665   int gadget_id;
3666   char *infotext;
3667 } scrollbutton_info[ED_NUM_SCROLLBUTTONS] =
3668 {
3669   {
3670     ED_SCROLLBUTTON_ID_AREA_UP,
3671     IMG_EDITOR_PLAYFIELD_SCROLL_UP,
3672     GADGET_ID_SCROLL_UP,
3673     "Scroll level editing area up"
3674   },
3675   {
3676     ED_SCROLLBUTTON_ID_AREA_DOWN,
3677     IMG_EDITOR_PLAYFIELD_SCROLL_DOWN,
3678     GADGET_ID_SCROLL_DOWN,
3679     "Scroll level editing area down"
3680   },
3681   {
3682     ED_SCROLLBUTTON_ID_AREA_LEFT,
3683     IMG_EDITOR_PLAYFIELD_SCROLL_LEFT,
3684     GADGET_ID_SCROLL_LEFT,
3685     "Scroll level editing area left"
3686   },
3687   {
3688     ED_SCROLLBUTTON_ID_AREA_RIGHT,
3689     IMG_EDITOR_PLAYFIELD_SCROLL_RIGHT,
3690     GADGET_ID_SCROLL_RIGHT,
3691     "Scroll level editing area right"
3692   },
3693   {
3694     ED_SCROLLBUTTON_ID_LIST_UP,
3695     IMG_EDITOR_PALETTE_SCROLL_UP,
3696     GADGET_ID_SCROLL_LIST_UP,
3697     "Scroll element list up ('Page Up')"
3698   },
3699   {
3700     ED_SCROLLBUTTON_ID_LIST_DOWN,
3701     IMG_EDITOR_PALETTE_SCROLL_DOWN,
3702     GADGET_ID_SCROLL_LIST_DOWN,
3703     "Scroll element list down ('Page Down')"
3704   },
3705 };
3706
3707 static struct
3708 {
3709   int x, y;
3710   int width, height;
3711   int wheel_x, wheel_y;
3712   int wheel_width, wheel_height;
3713 } scrollbar_pos[ED_NUM_SCROLLBARS];
3714
3715 static struct
3716 {
3717   int gadget_type_id;
3718   int graphic;
3719   int type;
3720   int gadget_id;
3721   char *infotext;
3722 } scrollbar_info[ED_NUM_SCROLLBARS] =
3723 {
3724   {
3725     ED_SCROLLBAR_ID_AREA_HORIZONTAL,
3726     IMG_EDITOR_PLAYFIELD_SCROLLBAR,
3727     GD_TYPE_SCROLLBAR_HORIZONTAL,
3728     GADGET_ID_SCROLL_HORIZONTAL,
3729     "Scroll level editing area horizontally"
3730   },
3731   {
3732     ED_SCROLLBAR_ID_AREA_VERTICAL,
3733     IMG_EDITOR_PLAYFIELD_SCROLLBAR,
3734     GD_TYPE_SCROLLBAR_VERTICAL,
3735     GADGET_ID_SCROLL_VERTICAL,
3736     "Scroll level editing area vertically"
3737   },
3738   {
3739     ED_SCROLLBAR_ID_LIST_VERTICAL,
3740     IMG_EDITOR_PALETTE_SCROLLBAR,
3741     GD_TYPE_SCROLLBAR_VERTICAL,
3742     GADGET_ID_SCROLL_LIST_VERTICAL,
3743     "Scroll element list vertically"
3744   }
3745 };
3746
3747
3748 static struct
3749 {
3750   int gadget_type_id;
3751   int x, y;
3752   int gadget_id;
3753   int gadget_id_align;
3754   int radio_button_nr;
3755   int *value;
3756   int checked_value;
3757   char *text_left, *text_right, *infotext;
3758 } radiobutton_info[ED_NUM_RADIOBUTTONS] =
3759 {
3760   {
3761     ED_RADIOBUTTON_ID_PERCENTAGE,
3762     -1,                                         ED_LEVEL_SETTINGS_YPOS(0),
3763     GADGET_ID_RANDOM_PERCENTAGE,                GADGET_ID_LEVEL_RANDOM_UP,
3764     RADIO_NR_RANDOM_ELEMENTS,
3765     &random_placement_method,                   RANDOM_USE_PERCENTAGE,
3766     " ", "percentage",                          "Use percentage for random elements"
3767   },
3768   {
3769     ED_RADIOBUTTON_ID_QUANTITY,
3770     -1,                                         ED_LEVEL_SETTINGS_YPOS(0),
3771     GADGET_ID_RANDOM_QUANTITY,                  GADGET_ID_RANDOM_PERCENTAGE,
3772     RADIO_NR_RANDOM_ELEMENTS,
3773     &random_placement_method,                   RANDOM_USE_QUANTITY,
3774     " ", "quantity",                            "Use quantity for random elements"
3775   }
3776 };
3777
3778 static struct
3779 {
3780   int gadget_type_id;
3781   int x, y;
3782   int gadget_id;
3783   int gadget_id_align;
3784   boolean *value;
3785   char *text_above, *text_left, *text_right, *infotext;
3786 } checkbutton_info[ED_NUM_CHECKBUTTONS] =
3787 {
3788   // ---------- level and editor settings -------------------------------------
3789
3790   {
3791     ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS,
3792     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(6),
3793     GADGET_ID_AUTO_COUNT_GEMS,                  GADGET_ID_NONE,
3794     &level.auto_count_gems,
3795     NULL, NULL,
3796     "Automatically count gems needed",          "Set counter to number of gems"
3797   },
3798   {
3799     ED_CHECKBUTTON_ID_RATE_TIME_OVER_SCORE,
3800     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(11),
3801     GADGET_ID_RATE_TIME_OVER_SCORE,             GADGET_ID_NONE,
3802     &level.rate_time_over_score,
3803     NULL, NULL,
3804     "Rate time/steps used over score",          "Sort high scores by playing time/steps"
3805   },
3806   {
3807     ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK,
3808     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(7),
3809     GADGET_ID_USE_LEVELSET_ARTWORK,             GADGET_ID_NONE,
3810     &levelset_use_levelset_artwork,
3811     NULL, NULL,
3812     "Use current custom artwork",               "Use custom artwork of this level set"
3813   },
3814   {
3815     ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE,
3816     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(8),
3817     GADGET_ID_COPY_LEVEL_TEMPLATE,              GADGET_ID_NONE,
3818     &levelset_copy_level_template,
3819     NULL, NULL,
3820     "Copy current level template",              "Copy level template of this level set"
3821   },
3822   {
3823     ED_CHECKBUTTON_ID_RANDOM_RESTRICTED,
3824     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(1),
3825     GADGET_ID_RANDOM_RESTRICTED,                GADGET_ID_NONE,
3826     &random_placement_background_restricted,
3827     NULL, NULL,
3828     "Restrict random placement to:",            "Set random placement restriction"
3829   },
3830   {
3831     ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_3,
3832     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(4),
3833     GADGET_ID_CUSTOM_USE_TEMPLATE_3,            GADGET_ID_NONE,
3834     &setup.editor.use_template_for_new_levels,
3835     "Template for new levels and CE/GE:", NULL,
3836     "Use template for new levels",              "Use template for level properties"
3837   },
3838   {
3839     ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_2,
3840     ED_LEVEL_SETTINGS_XPOS(0),                  ED_LEVEL_SETTINGS_YPOS(5),
3841     GADGET_ID_CUSTOM_USE_TEMPLATE_2,            GADGET_ID_NONE,
3842     &level.use_custom_template,
3843     NULL, NULL,
3844     "Use template for custom elements",         "Use template for custom properties"
3845   },
3846   {
3847     ED_CHECKBUTTON_ID_BD_INTERMISSION,
3848     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(0),
3849     GADGET_ID_BD_INTERMISSION,                  GADGET_ID_NONE,
3850     &level.bd_intermission,
3851     "Boulder Dash game engine settings:", NULL,
3852     "Intermission",                             "Level is an intermission level"
3853   },
3854   {
3855     ED_CHECKBUTTON_ID_BD_PAL_TIMING,
3856     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(2),
3857     GADGET_ID_BD_PAL_TIMING,                    GADGET_ID_NONE,
3858     &level.bd_pal_timing,
3859     NULL, NULL,
3860     "PAL timing",                               "Use slower timer (like PAL C64)"
3861   },
3862   {
3863     ED_CHECKBUTTON_ID_BD_LINE_SHIFTING_BORDERS,
3864     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(6),
3865     GADGET_ID_BD_LINE_SHIFTING_BORDERS,         GADGET_ID_NONE,
3866     &level.bd_line_shifting_borders,
3867     "Compatibility settings:", NULL,
3868     "Line-shifting borders",                    "Use line-shifting wrap-around"
3869   },
3870   {
3871     ED_CHECKBUTTON_ID_BD_SCAN_FIRST_AND_LAST_ROW,
3872     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(7),
3873     GADGET_ID_BD_SCAN_FIRST_AND_LAST_ROW,       GADGET_ID_NONE,
3874     &level.bd_scan_first_and_last_row,
3875     NULL, NULL,
3876     "Scan first and last row",                  "Also process top/bottom border rows"
3877   },
3878   {
3879     ED_CHECKBUTTON_ID_BD_SHORT_EXPLOSIONS,
3880     ED_ENGINE_SETTINGS_XPOS(0),                 ED_ENGINE_SETTINGS_YPOS(8),
3881     GADGET_ID_BD_SHORT_EXPLOSIONS,              GADGET_ID_NONE,
3882     &level.bd_short_explosions,
3883     NULL, NULL,
3884     "Short explosions",                         "Use four game cycles for explosions"
3885   },
3886
3887   // ---------- element settings: configure (various elements) ----------------
3888
3889   {
3890     ED_CHECKBUTTON_ID_STICK_ELEMENT,
3891     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
3892     GADGET_ID_STICK_ELEMENT,                    GADGET_ID_NONE,
3893     &stick_element_properties_window,
3894     NULL, NULL,
3895     "Stick this screen to edit content",        "Stick this screen to edit content"
3896   },
3897   {
3898     ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS,
3899     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
3900     GADGET_ID_EM_SLIPPERY_GEMS,                 GADGET_ID_NONE,
3901     &level.em_slippery_gems,
3902     NULL, NULL,
3903     "Slip down from certain flat walls",        "Use EM/DC style slipping behaviour"
3904   },
3905   {
3906     ED_CHECKBUTTON_ID_EM_EXPLODES_BY_FIRE,
3907     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
3908     GADGET_ID_EM_EXPLODES_BY_FIRE,              GADGET_ID_NONE,
3909     &level.em_explodes_by_fire,
3910     NULL, NULL,
3911     "Explodes with chain reaction",             "Use R'n'D style explosion behaviour"
3912   },
3913   {
3914     ED_CHECKBUTTON_ID_USE_SPRING_BUG,
3915     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
3916     GADGET_ID_USE_SPRING_BUG,                   GADGET_ID_NONE,
3917     &level.use_spring_bug,
3918     NULL, NULL,
3919     "Use spring pushing bug",                   "Use odd spring pushing behaviour"
3920   },
3921   {
3922     ED_CHECKBUTTON_ID_USE_TIME_ORB_BUG,
3923     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
3924     GADGET_ID_USE_TIME_ORB_BUG,                 GADGET_ID_NONE,
3925     &level.use_time_orb_bug,
3926     NULL, NULL,
3927     "Use time orb bug",                         "Use odd time orb behaviour"
3928   },
3929   {
3930     ED_CHECKBUTTON_ID_USE_LIFE_BUGS,
3931     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(5),
3932     GADGET_ID_USE_LIFE_BUGS,                    GADGET_ID_NONE,
3933     &level.use_life_bugs,
3934     NULL, NULL,
3935     "Use buggy element behaviour",              "Use odd (historic) element behaviour"
3936   },
3937   {
3938     ED_CHECKBUTTON_ID_RANDOM_BALL_CONTENT,
3939     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
3940     GADGET_ID_RANDOM_BALL_CONTENT,              GADGET_ID_NONE,
3941     &level.ball_random,
3942     NULL, NULL,
3943     "Create single random element",             "Only create one element from content"
3944   },
3945   {
3946     ED_CHECKBUTTON_ID_INITIAL_BALL_ACTIVE,
3947     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
3948     GADGET_ID_INITIAL_BALL_ACTIVE,              GADGET_ID_NONE,
3949     &level.ball_active_initial,
3950     NULL, NULL,
3951     "Magic ball initially activated",           "Activate magic ball after level start"
3952   },
3953   {
3954     ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE,
3955     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
3956     GADGET_ID_GROW_INTO_DIGGABLE,               GADGET_ID_NONE,
3957     &level.grow_into_diggable,
3958     NULL, NULL,
3959     "Can grow into anything diggable",          "Grow into more than just sand"
3960   },
3961   {
3962     ED_CHECKBUTTON_ID_SB_FIELDS_NEEDED,
3963     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
3964     GADGET_ID_SB_FIELDS_NEEDED,                 GADGET_ID_NONE,
3965     &level.sb_fields_needed,
3966     NULL, NULL,
3967     "All fields need to be filled",             "Require all SB fields to be solved"
3968   },
3969   {
3970     ED_CHECKBUTTON_ID_SB_OBJECTS_NEEDED,
3971     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
3972     GADGET_ID_SB_OBJECTS_NEEDED,                GADGET_ID_NONE,
3973     &level.sb_objects_needed,
3974     NULL, NULL,
3975     "All objects need to be placed",            "Require all SB objects to be solved"
3976   },
3977   {
3978     ED_CHECKBUTTON_ID_AUTO_EXIT_SOKOBAN,
3979     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
3980     GADGET_ID_AUTO_EXIT_SOKOBAN,                GADGET_ID_NONE,
3981     &level.auto_exit_sokoban,
3982     NULL, NULL,
3983     "Exit level if all tasks solved",           "Automatically finish Sokoban levels"
3984   },
3985   {
3986     ED_CHECKBUTTON_ID_SOLVED_BY_ONE_PLAYER,
3987     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(14),
3988     GADGET_ID_SOLVED_BY_ONE_PLAYER,             GADGET_ID_NONE,
3989     &level.solved_by_one_player,
3990     NULL, NULL,
3991     "Only one player must enter exit",          "Level solved by first player in exit"
3992   },
3993   {
3994     ED_CHECKBUTTON_ID_FINISH_DIG_COLLECT,
3995     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
3996     GADGET_ID_FINISH_DIG_COLLECT,               GADGET_ID_NONE,
3997     &level.finish_dig_collect,
3998     NULL, NULL,
3999     "CE action on finished dig/collect",        "Only finished dig/collect triggers CE"
4000   },
4001   {
4002     ED_CHECKBUTTON_ID_KEEP_WALKABLE_CE,
4003     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
4004     GADGET_ID_KEEP_WALKABLE_CE,                 GADGET_ID_NONE,
4005     &level.keep_walkable_ce,
4006     NULL, NULL,
4007     "Keep walkable CE changed to player",       "Keep CE changing to player if walkable"
4008   },
4009   {
4010     ED_CHECKBUTTON_ID_CONTINUOUS_SNAPPING,
4011     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(9),
4012     GADGET_ID_CONTINUOUS_SNAPPING,              GADGET_ID_NONE,
4013     &level.continuous_snapping,
4014     NULL, NULL,
4015     "Continuous snapping",                      "Use snapping without releasing key"
4016   },
4017   {
4018     ED_CHECKBUTTON_ID_BLOCK_SNAP_FIELD,
4019     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(8),
4020     GADGET_ID_BLOCK_SNAP_FIELD,                 GADGET_ID_NONE,
4021     &level.block_snap_field,
4022     NULL, NULL,
4023     "Block snapped field when snapping",        "Use snapping delay to show animation"
4024   },
4025   {
4026     ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD,
4027     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4028     GADGET_ID_BLOCK_LAST_FIELD,                 GADGET_ID_NONE,
4029     &level.block_last_field,
4030     NULL, NULL,
4031     "Block last field when moving",             "Player blocks last field when moving"
4032   },
4033   {
4034     ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD,
4035     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4036     GADGET_ID_SP_BLOCK_LAST_FIELD,              GADGET_ID_NONE,
4037     &level.sp_block_last_field,
4038     NULL, NULL,
4039     "Block last field when moving",             "Player blocks last field when moving"
4040   },
4041   {
4042     ED_CHECKBUTTON_ID_INSTANT_RELOCATION,
4043     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
4044     GADGET_ID_INSTANT_RELOCATION,               GADGET_ID_NONE,
4045     &level.instant_relocation,
4046     NULL, NULL,
4047     "No scrolling when relocating",             "Player gets relocated without delay"
4048   },
4049   {
4050     ED_CHECKBUTTON_ID_SHIFTED_RELOCATION,
4051     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
4052     GADGET_ID_SHIFTED_RELOCATION,               GADGET_ID_NONE,
4053     &level.shifted_relocation,
4054     NULL, NULL,
4055     "No centering when relocating",             "Level not centered after relocation"
4056   },
4057   {
4058     ED_CHECKBUTTON_ID_LAZY_RELOCATION,
4059     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(5),
4060     GADGET_ID_LAZY_RELOCATION,                  GADGET_ID_NONE,
4061     &level.lazy_relocation,
4062     NULL, NULL,
4063     "Only redraw off-screen relocation",        "No redraw if relocation target visible"
4064   },
4065   {
4066     ED_CHECKBUTTON_ID_USE_START_ELEMENT,
4067     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(10),
4068     GADGET_ID_USE_START_ELEMENT,                GADGET_ID_NONE,
4069     &level.use_start_element[0],
4070     NULL, NULL,
4071     "Use level start element:",                "Start level at this element's position"
4072   },
4073   {
4074     ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT,
4075     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(11),
4076     GADGET_ID_USE_ARTWORK_ELEMENT,              GADGET_ID_NONE,
4077     &level.use_artwork_element[0],
4078     NULL, NULL,
4079     "Use artwork from element:",                "Use player artwork from other element"
4080   },
4081   {
4082     ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT,
4083     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(12),
4084     GADGET_ID_USE_EXPLOSION_ELEMENT,            GADGET_ID_NONE,
4085     &level.use_explosion_element[0],
4086     NULL, NULL,
4087     "Use explosion from element:",              "Use explosion properties from element"
4088   },
4089   {
4090     ED_CHECKBUTTON_ID_INITIAL_GRAVITY,
4091     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(13),
4092     GADGET_ID_INITIAL_GRAVITY,                  GADGET_ID_NONE,
4093     &level.initial_player_gravity[0],
4094     NULL, NULL,
4095     "Use initial gravity",                      "Set initial player gravity"
4096   },
4097   {
4098     ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY,
4099     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4100     GADGET_ID_USE_INITIAL_INVENTORY,            GADGET_ID_NONE,
4101     &level.use_initial_inventory[0],
4102     NULL, NULL,
4103     "Use initial inventory:",                   "Use collected elements on level start"
4104   },
4105   {
4106     ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE,
4107     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(6),
4108     GADGET_ID_CAN_PASS_TO_WALKABLE,             GADGET_ID_NONE,
4109     &level.can_pass_to_walkable,
4110     NULL, NULL,
4111     "Can pass to walkable element",             "Player can pass to empty or walkable"
4112   },
4113   {
4114     ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID,
4115     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4116     GADGET_ID_CAN_FALL_INTO_ACID,               GADGET_ID_NONE,
4117     &custom_element_properties[EP_CAN_MOVE_INTO_ACID],
4118     NULL, NULL,
4119     "Can fall into acid (with gravity)",        "Player can fall into acid pool"
4120   },
4121   {
4122     ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID,
4123     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4124     GADGET_ID_CAN_MOVE_INTO_ACID,               GADGET_ID_NONE,
4125     &custom_element_properties[EP_CAN_MOVE_INTO_ACID],
4126     NULL, NULL,
4127     "Can move into acid",                       "Element can move into acid pool"
4128   },
4129   {
4130     ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH,
4131     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4132     GADGET_ID_DONT_COLLIDE_WITH,                GADGET_ID_NONE,
4133     &custom_element_properties[EP_DONT_COLLIDE_WITH],
4134     NULL, NULL,
4135     "Deadly when colliding with",               "Element is deadly when hitting player"
4136   },
4137   {
4138     ED_CHECKBUTTON_ID_BD_DIAGONAL_MOVEMENTS,
4139     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4140     GADGET_ID_BD_DIAGONAL_MOVEMENTS,            GADGET_ID_NONE,
4141     &level.bd_diagonal_movements,
4142     NULL, NULL,
4143     "Can move diagonally",                      "Player can move diagonally"
4144   },
4145   {
4146     ED_CHECKBUTTON_ID_BD_TOPMOST_PLAYER_ACTIVE,
4147     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4148     GADGET_ID_BD_TOPMOST_PLAYER_ACTIVE,         GADGET_ID_NONE,
4149     &level.bd_topmost_player_active,
4150     NULL, NULL,
4151     "Topmost player is active",                 "Use first player found on playfield"
4152   },
4153   {
4154     ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET,
4155     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
4156     GADGET_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET,     GADGET_ID_NONE,
4157     &level.bd_push_mega_rock_with_sweet,
4158     NULL, NULL,
4159     "Mega rocks pushable with sweet",           "Push mega rocks after eating sweet"
4160   },
4161   {
4162     ED_CHECKBUTTON_ID_BD_MAGIC_WALL_ZERO_INFINITE,
4163     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4164     GADGET_ID_BD_MAGIC_WALL_ZERO_INFINITE,      GADGET_ID_NONE,
4165     &level.bd_magic_wall_zero_infinite,
4166     NULL, NULL,
4167     "Run forever if duration is zero",          "Run infinitely if timer is zero"
4168   },
4169   {
4170     ED_CHECKBUTTON_ID_BD_MAGIC_WALL_WAIT_HATCHING,
4171     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
4172     GADGET_ID_BD_MAGIC_WALL_WAIT_HATCHING,      GADGET_ID_NONE,
4173     &level.bd_magic_wall_wait_hatching,
4174     NULL, NULL,
4175     "Wait for player's birth",                  "Timer start waits for player's birth"
4176   },
4177   {
4178     ED_CHECKBUTTON_ID_BD_MAGIC_WALL_STOPS_AMOEBA,
4179     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
4180     GADGET_ID_BD_MAGIC_WALL_STOPS_AMOEBA,       GADGET_ID_NONE,
4181     &level.bd_magic_wall_stops_amoeba,
4182     NULL, NULL,
4183     "Stop amoeba and turn to diamonds",         "Activation changes amoeba to diamonds"
4184   },
4185   {
4186     ED_CHECKBUTTON_ID_BD_MAGIC_WALL_BREAK_SCAN,
4187     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(5),
4188     GADGET_ID_BD_MAGIC_WALL_BREAK_SCAN,         GADGET_ID_NONE,
4189     &level.bd_magic_wall_break_scan,
4190     NULL, NULL,
4191     "Emulate amoeba bug in BD1",                "Use buggy BD1 behavior"
4192   },
4193   {
4194     ED_CHECKBUTTON_ID_BD_AMOEBA_WAIT_FOR_HATCHING,
4195     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4196     GADGET_ID_BD_AMOEBA_WAIT_FOR_HATCHING,      GADGET_ID_NONE,
4197     &level.bd_amoeba_wait_for_hatching,
4198     NULL, NULL,
4199     "Wait for player's birth",                  "Timer start waits for player's birth"
4200   },
4201   {
4202     ED_CHECKBUTTON_ID_BD_AMOEBA_START_IMMEDIATELY,
4203     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4204     GADGET_ID_BD_AMOEBA_START_IMMEDIATELY,      GADGET_ID_NONE,
4205     &level.bd_amoeba_start_immediately,
4206     NULL, NULL,
4207     "Start growing immediately",                "Start slow growth time immediately"
4208   },
4209   {
4210     ED_CHECKBUTTON_ID_BD_AMOEBA_2_EXPLODE_BY_AMOEBA,
4211     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(9),
4212     GADGET_ID_BD_AMOEBA_2_EXPLODE_BY_AMOEBA,    GADGET_ID_NONE,
4213     &level.bd_amoeba_2_explode_by_amoeba,
4214     NULL, NULL,
4215     "Explodes if touched by amoeba",            "Amoeba 2 explodes if touched by amoeba"
4216   },
4217   {
4218     ED_CHECKBUTTON_ID_BD_VOODOO_COLLECTS_DIAMONDS,
4219     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4220     GADGET_ID_BD_VOODOO_COLLECTS_DIAMONDS,      GADGET_ID_NONE,
4221     &level.bd_voodoo_collects_diamonds,
4222     NULL, NULL,
4223     "Can collect diamonds",                     "Can collect diamonds for the player"
4224   },
4225   {
4226     ED_CHECKBUTTON_ID_BD_VOODOO_HURT_KILLS_PLAYER,
4227     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4228     GADGET_ID_BD_VOODOO_HURT_KILLS_PLAYER,      GADGET_ID_NONE,
4229     &level.bd_voodoo_hurt_kills_player,
4230     NULL, NULL,
4231     "Player is killed if hurt",                 "If hurt in any way, player is killed"
4232   },
4233   {
4234     ED_CHECKBUTTON_ID_BD_VOODOO_DIES_BY_ROCK,
4235     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4236     GADGET_ID_BD_VOODOO_DIES_BY_ROCK,           GADGET_ID_NONE,
4237     &level.bd_voodoo_dies_by_rock,
4238     NULL, NULL,
4239     "Killed by falling rock",                   "Can be killed by a falling rock"
4240   },
4241   {
4242     ED_CHECKBUTTON_ID_BD_VOODOO_VANISH_BY_EXPLOSION,
4243     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
4244     GADGET_ID_BD_VOODOO_VANISH_BY_EXPLOSION,    GADGET_ID_NONE,
4245     &level.bd_voodoo_vanish_by_explosion,
4246     NULL, NULL,
4247     "Disappears in explosions",                 "Can be destroyed by explosions"
4248   },
4249   {
4250     ED_CHECKBUTTON_ID_BD_SLIME_IS_PREDICTABLE,
4251     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4252     GADGET_ID_BD_SLIME_IS_PREDICTABLE,          GADGET_ID_NONE,
4253     &level.bd_slime_is_predictable,
4254     NULL, NULL,
4255     "Slime is predictable",                     "Use predictable random numbers"
4256   },
4257   {
4258     ED_CHECKBUTTON_ID_BD_CHANGE_EXPANDING_WALL,
4259     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4260     GADGET_ID_BD_CHANGE_EXPANDING_WALL,         GADGET_ID_NONE,
4261     &level.bd_change_expanding_wall,
4262     NULL, NULL,
4263     "Change direction",                         "Switch horizontal/vertical direction"
4264   },
4265   {
4266     ED_CHECKBUTTON_ID_BD_REPLICATORS_ACTIVE,
4267     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4268     GADGET_ID_BD_REPLICATORS_ACTIVE,            GADGET_ID_NONE,
4269     &level.bd_replicators_active,
4270     NULL, NULL,
4271     "Active at start",                          "Replicators start in active state"
4272   },
4273   {
4274     ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_ACTIVE,
4275     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4276     GADGET_ID_BD_CONVEYOR_BELTS_ACTIVE,         GADGET_ID_NONE,
4277     &level.bd_conveyor_belts_active,
4278     NULL, NULL,
4279     "Active at start",                          "Conveyor belts start in active state"
4280   },
4281   {
4282     ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_CHANGED,
4283     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4284     GADGET_ID_BD_CONVEYOR_BELTS_CHANGED,        GADGET_ID_NONE,
4285     &level.bd_conveyor_belts_changed,
4286     NULL, NULL,
4287     "Change direction",                         "Switch conveyor belt direction"
4288   },
4289   {
4290     ED_CHECKBUTTON_ID_BD_WATER_CANNOT_FLOW_DOWN,
4291     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4292     GADGET_ID_BD_WATER_CANNOT_FLOW_DOWN,        GADGET_ID_NONE,
4293     &level.bd_water_cannot_flow_down,
4294     NULL, NULL,
4295     "Does not flow downwards",                  "Water can only flow up, left and right"
4296   },
4297   {
4298     ED_CHECKBUTTON_ID_BD_HAMMER_WALLS_REAPPEAR,
4299     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4300     GADGET_ID_BD_HAMMER_WALLS_REAPPEAR,         GADGET_ID_NONE,
4301     &level.bd_hammer_walls_reappear,
4302     NULL, NULL,
4303     "Hammered walls reappear",                  "Hammered walls reappear after delay"
4304   },
4305   {
4306     ED_CHECKBUTTON_ID_BD_INFINITE_ROCKETS,
4307     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4308     GADGET_ID_BD_INFINITE_ROCKETS,              GADGET_ID_NONE,
4309     &level.bd_infinite_rockets,
4310     NULL, NULL,
4311     "Infinite rockets",                         "Rocket launcher has infinite rockets"
4312   },
4313   {
4314     ED_CHECKBUTTON_ID_BD_CREATURES_START_BACKWARDS,
4315     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(0),
4316     GADGET_ID_BD_CREATURES_START_BACKWARDS,     GADGET_ID_NONE,
4317     &level.bd_creatures_start_backwards,
4318     NULL, NULL,
4319     "Creatures start moving backwards",         "Creatures start in opposite direction"
4320   },
4321   {
4322     ED_CHECKBUTTON_ID_BD_CREATURES_TURN_ON_HATCHING,
4323     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4324     GADGET_ID_BD_CREATURES_TURN_ON_HATCHING,    GADGET_ID_NONE,
4325     &level.bd_creatures_turn_on_hatching,
4326     NULL, NULL,
4327     "Creatures auto turn on hatching",          "Creatures change direction on hatching"
4328   },
4329   {
4330     ED_CHECKBUTTON_ID_BD_GRAVITY_SWITCH_ACTIVE,
4331     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4332     GADGET_ID_BD_GRAVITY_SWITCH_ACTIVE,         GADGET_ID_NONE,
4333     &level.bd_gravity_switch_active,
4334     NULL, NULL,
4335     "Gravity switch active at start",           "Gravity switch starts in active state"
4336   },
4337   {
4338     ED_CHECKBUTTON_ID_BD_GRAVITY_AFFECTS_ALL,
4339     ED_LEVEL_SETTINGS_XPOS(0),                  ED_ELEMENT_SETTINGS_YPOS(3),
4340     GADGET_ID_BD_GRAVITY_AFFECTS_ALL,           GADGET_ID_NONE,
4341     &level.bd_gravity_affects_all,
4342     NULL, NULL,
4343     "Gravity change affects everything",        "Gravity affects all falling objects"
4344   },
4345   {
4346     ED_CHECKBUTTON_ID_ENVELOPE_AUTOWRAP,
4347     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4348     GADGET_ID_ENVELOPE_AUTOWRAP,                GADGET_ID_NONE,
4349     &level.envelope[0].autowrap,
4350     NULL, NULL,
4351     "Auto-wrap",                                "Automatically wrap envelope text"
4352   },
4353   {
4354     ED_CHECKBUTTON_ID_ENVELOPE_CENTERED,
4355     -1,                                         ED_ELEMENT_SETTINGS_YPOS(1),
4356     GADGET_ID_ENVELOPE_CENTERED,                GADGET_ID_ENVELOPE_AUTOWRAP,
4357     &level.envelope[0].centered,
4358     NULL, " ",
4359     "Centered",                                 "Automatically center envelope text"
4360   },
4361   {
4362     ED_CHECKBUTTON_ID_MM_LASER_RED,
4363     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4364     GADGET_ID_MM_LASER_RED,                     GADGET_ID_NONE,
4365     &level.mm_laser_red,
4366     "Choose color components for laser:", NULL,
4367     "Red",                                      "Use red color components in laser"
4368   },
4369   {
4370     ED_CHECKBUTTON_ID_MM_LASER_GREEN,
4371     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4372     GADGET_ID_MM_LASER_GREEN,                   GADGET_ID_NONE,
4373     &level.mm_laser_green,
4374     NULL, NULL,
4375     "Green",                                    "Use green color components in laser"
4376   },
4377   {
4378     ED_CHECKBUTTON_ID_MM_LASER_BLUE,
4379     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
4380     GADGET_ID_MM_LASER_BLUE,                    GADGET_ID_NONE,
4381     &level.mm_laser_blue,
4382     NULL, NULL,
4383     "Blue",                                     "Use blue color components in laser"
4384   },
4385   {
4386     ED_CHECKBUTTON_ID_DF_LASER_RED,
4387     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4388     GADGET_ID_DF_LASER_RED,                     GADGET_ID_NONE,
4389     &level.df_laser_red,
4390     "Choose color components for laser:", NULL,
4391     "Red",                                      "Use red color components in laser"
4392   },
4393   {
4394     ED_CHECKBUTTON_ID_DF_LASER_GREEN,
4395     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4396     GADGET_ID_DF_LASER_GREEN,                   GADGET_ID_NONE,
4397     &level.df_laser_green,
4398     NULL, NULL,
4399     "Green",                                    "Use green color components in laser"
4400   },
4401   {
4402     ED_CHECKBUTTON_ID_DF_LASER_BLUE,
4403     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(3),
4404     GADGET_ID_DF_LASER_BLUE,                    GADGET_ID_NONE,
4405     &level.df_laser_blue,
4406     NULL, NULL,
4407     "Blue",                                     "Use blue color components in laser"
4408   },
4409   {
4410     ED_CHECKBUTTON_ID_ROTATE_MM_BALL_CONTENT,
4411     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(5),
4412     GADGET_ID_ROTATE_MM_BALL_CONTENT,           GADGET_ID_NONE,
4413     &level.rotate_mm_ball_content,
4414     NULL, NULL,
4415     "Randomly rotate created content",          "Randomly rotate newly created content"
4416   },
4417   {
4418     ED_CHECKBUTTON_ID_EXPLODE_MM_BALL,
4419     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(6),
4420     GADGET_ID_EXPLODE_MM_BALL,                  GADGET_ID_NONE,
4421     &level.explode_mm_ball,
4422     NULL, NULL,
4423     "Explode ball instead of melting",          "Use explosion to release ball content"
4424   },
4425
4426   // ---------- element settings: configure 1 (custom elements) ---------------
4427
4428   {
4429     ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC,
4430     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4431     GADGET_ID_CUSTOM_USE_GRAPHIC,               GADGET_ID_NONE,
4432     &custom_element.use_gfx_element,
4433     NULL, NULL,
4434     "Use graphic of element:",                  "Use existing element graphic"
4435   },
4436   {
4437     ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1,
4438     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(14),
4439     GADGET_ID_CUSTOM_USE_TEMPLATE_1,            GADGET_ID_NONE,
4440     &level.use_custom_template,
4441     NULL, NULL,
4442     "Use template",                             "Use template for custom properties"
4443   },
4444   {
4445     ED_CHECKBUTTON_ID_CUSTOM_ACCESSIBLE,
4446     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(2),
4447     GADGET_ID_CUSTOM_ACCESSIBLE,                GADGET_ID_NONE,
4448     &custom_element_properties[EP_ACCESSIBLE],
4449     NULL, NULL,
4450     NULL,                                       "Player can walk to or pass this field"
4451   },
4452   {
4453     ED_CHECKBUTTON_ID_CUSTOM_GRAV_REACHABLE,
4454     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(9),
4455     GADGET_ID_CUSTOM_GRAV_REACHABLE,            GADGET_ID_NONE,
4456     &custom_element_properties[EP_GRAVITY_REACHABLE],
4457     NULL, NULL,
4458     "Reachable despite gravity",                "Player can walk/dig despite gravity"
4459   },
4460   {
4461     ED_CHECKBUTTON_ID_CUSTOM_USE_LAST_VALUE,
4462     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(11),
4463     GADGET_ID_CUSTOM_USE_LAST_VALUE,            GADGET_ID_NONE,
4464     &custom_element.use_last_ce_value,
4465     NULL, NULL,
4466     "Use last CE value after change",           "Use last CE value after change"
4467   },
4468   {
4469     ED_CHECKBUTTON_ID_CUSTOM_WALK_TO_OBJECT,
4470     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(4),
4471     GADGET_ID_CUSTOM_WALK_TO_OBJECT,            GADGET_ID_NONE,
4472     &custom_element_properties[EP_WALK_TO_OBJECT],
4473     NULL, NULL,
4474     NULL,                                       "Player can dig/collect/push element"
4475   },
4476   {
4477     ED_CHECKBUTTON_ID_CUSTOM_INDESTRUCTIBLE,
4478     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(8),
4479     GADGET_ID_CUSTOM_INDESTRUCTIBLE,            GADGET_ID_NONE,
4480     &custom_element_properties[EP_INDESTRUCTIBLE],
4481     NULL, NULL,
4482     "Indestructible",                           "Element is indestructible"
4483   },
4484
4485   // ---------- element settings: configure 2 (custom elements) ---------------
4486
4487   {
4488     ED_CHECKBUTTON_ID_CUSTOM_CAN_MOVE,
4489     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4490     GADGET_ID_CUSTOM_CAN_MOVE,                  GADGET_ID_NONE,
4491     &custom_element_properties[EP_CAN_MOVE],
4492     NULL, NULL,
4493     NULL,                                       "Element can move with some pattern"
4494   },
4495   {
4496     ED_CHECKBUTTON_ID_CUSTOM_CAN_FALL,
4497     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(8),
4498     GADGET_ID_CUSTOM_CAN_FALL,                  GADGET_ID_NONE,
4499     &custom_element_properties[EP_CAN_FALL],
4500     NULL, NULL,
4501     "Can fall",                                 "Element can fall down"
4502   },
4503   {
4504     ED_CHECKBUTTON_ID_CUSTOM_CAN_SMASH,
4505     -1,                                         ED_ELEMENT_SETTINGS_YPOS(8),
4506     GADGET_ID_CUSTOM_CAN_SMASH,                 GADGET_ID_CUSTOM_CAN_FALL,
4507     &custom_element_properties[EP_CAN_SMASH],
4508     NULL, " ",
4509     NULL,                                       "Element can smash other elements"
4510   },
4511   {
4512     ED_CHECKBUTTON_ID_CUSTOM_SLIPPERY,
4513     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(9),
4514     GADGET_ID_CUSTOM_SLIPPERY,                  GADGET_ID_NONE,
4515     &custom_element_properties[EP_SLIPPERY],
4516     NULL, NULL,
4517     NULL,                                       "Other elements can fall down from it"
4518   },
4519   {
4520     ED_CHECKBUTTON_ID_CUSTOM_DEADLY,
4521     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(10),
4522     GADGET_ID_CUSTOM_DEADLY,                    GADGET_ID_NONE,
4523     &custom_element_properties[EP_DEADLY],
4524     NULL, NULL,
4525     NULL,                                       "Element can kill the player"
4526   },
4527   {
4528     ED_CHECKBUTTON_ID_CUSTOM_CAN_EXPLODE,
4529     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(11),
4530     GADGET_ID_CUSTOM_CAN_EXPLODE,               GADGET_ID_NONE,
4531     &custom_element_properties[EP_CAN_EXPLODE],
4532     NULL, NULL,
4533     NULL,                                       "Element can explode"
4534   },
4535   {
4536     ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_FIRE,
4537     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(12),
4538     GADGET_ID_CUSTOM_EXPLODE_FIRE,              GADGET_ID_NONE,
4539     &custom_element_properties[EP_EXPLODES_BY_FIRE],
4540     NULL, NULL,
4541     "By fire",                                  "Element can explode by fire/explosion"
4542   },
4543   {
4544     ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_SMASH,
4545     -1,                                         ED_ELEMENT_SETTINGS_YPOS(12),
4546     GADGET_ID_CUSTOM_EXPLODE_SMASH,             GADGET_ID_CUSTOM_EXPLODE_FIRE,
4547     &custom_element_properties[EP_EXPLODES_SMASHED],
4548     NULL, " ",
4549     "Smashed",                                  "Element can explode when smashed"
4550   },
4551   {
4552     ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT,
4553     -1,                                         ED_ELEMENT_SETTINGS_YPOS(12),
4554     GADGET_ID_CUSTOM_EXPLODE_IMPACT,            GADGET_ID_CUSTOM_EXPLODE_SMASH,
4555     &custom_element_properties[EP_EXPLODES_IMPACT],
4556     NULL, " ",
4557     "Impact",                                   "Element can explode on impact"
4558   },
4559
4560   // ---------- element settings: advanced (custom elements) ------------------
4561
4562   {
4563     ED_CHECKBUTTON_ID_CUSTOM_CAN_CHANGE,
4564     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(1),
4565     GADGET_ID_CUSTOM_CAN_CHANGE,                GADGET_ID_NONE,
4566     &custom_element_change.can_change,
4567     NULL, NULL,
4568     "Element changes to:",                      "Change element on specified condition"
4569   },
4570   {
4571     ED_CHECKBUTTON_ID_CHANGE_DELAY,
4572     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(2),
4573     GADGET_ID_CHANGE_DELAY,                     GADGET_ID_NONE,
4574     &custom_element_change_events[CE_DELAY],
4575     NULL, NULL,
4576     NULL,                                       "Element changes after delay"
4577   },
4578   {
4579     ED_CHECKBUTTON_ID_CHANGE_BY_DIRECT_ACT,
4580     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(4),
4581     GADGET_ID_CHANGE_BY_DIRECT_ACT,             GADGET_ID_NONE,
4582     &custom_element_change_events[CE_BY_DIRECT_ACTION],
4583     NULL, NULL,
4584     NULL,                                       "Element changes by direct action"
4585   },
4586   {
4587     ED_CHECKBUTTON_ID_CHANGE_BY_OTHER_ACT,
4588     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(5),
4589     GADGET_ID_CHANGE_BY_OTHER_ACT,              GADGET_ID_NONE,
4590     &custom_element_change_events[CE_BY_OTHER_ACTION],
4591     NULL, NULL,
4592     NULL,                                       "Element changes by other element"
4593   },
4594   {
4595     ED_CHECKBUTTON_ID_CHANGE_USE_EXPLOSION,
4596     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(8),
4597     GADGET_ID_CHANGE_USE_EXPLOSION,             GADGET_ID_NONE,
4598     &custom_element_change.explode,
4599     NULL, NULL,
4600     "Explode instead of change",                "Element explodes instead of change"
4601   },
4602   {
4603     ED_CHECKBUTTON_ID_CHANGE_USE_CONTENT,
4604     ED_ELEMENT_SETTINGS_XPOS(1),                ED_ELEMENT_SETTINGS_YPOS(9),
4605     GADGET_ID_CHANGE_USE_CONTENT,               GADGET_ID_NONE,
4606     &custom_element_change.use_target_content,
4607     NULL, NULL,
4608     "Use extended change target:",              "Element changes to more elements"
4609   },
4610   {
4611     ED_CHECKBUTTON_ID_CHANGE_ONLY_COMPLETE,
4612     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(11),
4613     GADGET_ID_CHANGE_ONLY_COMPLETE,             GADGET_ID_NONE,
4614     &custom_element_change.only_if_complete,
4615     NULL, NULL,
4616     "Replace all or nothing",                   "Only replace when all can be changed"
4617   },
4618   {
4619     ED_CHECKBUTTON_ID_CHANGE_USE_RANDOM,
4620     ED_ELEMENT_SETTINGS_XPOS(2),                ED_ELEMENT_SETTINGS_YPOS(12),
4621     GADGET_ID_CHANGE_USE_RANDOM,                GADGET_ID_NONE,
4622     &custom_element_change.use_random_replace,
4623     NULL, NULL,
4624     NULL,                                       "Use percentage for random replace"
4625   },
4626   {
4627     ED_CHECKBUTTON_ID_CHANGE_HAS_ACTION,
4628     ED_ELEMENT_SETTINGS_XPOS(0),                ED_ELEMENT_SETTINGS_YPOS(13),
4629     GADGET_ID_CHANGE_HAS_ACTION,                GADGET_ID_NONE,
4630     &custom_element_change.has_action,
4631     NULL, NULL,
4632     NULL,                                       "Execute action on specified condition"
4633   },
4634 };
4635
4636 static struct
4637 {
4638   int gadget_type_id;
4639   int x, y;
4640   int xoffset, yoffset;
4641   int gadget_id;
4642   int gadget_id_align;
4643   int *value;
4644   int area_xsize, area_ysize;
4645   char *text_left, *text_right, *text_above, *text_below, *infotext;
4646 } drawingarea_info[ED_NUM_DRAWING_AREAS] =
4647 {
4648   // ---------- level playfield content ---------------------------------------
4649
4650   {
4651     ED_DRAWING_ID_DRAWING_LEVEL,
4652     0,                                          0,
4653     0,                                          0,
4654     GADGET_ID_DRAWING_LEVEL,                    GADGET_ID_NONE,
4655     NULL,
4656     -1, -1,     // these values are not constant, but can change at runtime
4657     NULL, NULL, NULL, NULL,                     NULL
4658   },
4659
4660   // ---------- yam yam content -----------------------------------------------
4661
4662   {
4663     ED_DRAWING_ID_YAMYAM_CONTENT_0,
4664     ED_AREA_YAMYAM_CONTENT_XPOS,                ED_AREA_YAMYAM_CONTENT_YPOS,
4665     ED_AREA_YAMYAM_CONTENT_XOFF(0),             ED_AREA_YAMYAM_CONTENT_YOFF(0),
4666     GADGET_ID_YAMYAM_CONTENT_0,                 GADGET_ID_NONE,
4667     &level.yamyam_content[0].e[0][0],           3, 3,
4668     NULL, NULL, NULL, "1",                      NULL
4669   },
4670   {
4671     ED_DRAWING_ID_YAMYAM_CONTENT_1,
4672     ED_AREA_YAMYAM_CONTENT_XPOS,                ED_AREA_YAMYAM_CONTENT_YPOS,
4673     ED_AREA_YAMYAM_CONTENT_XOFF(1),             ED_AREA_YAMYAM_CONTENT_YOFF(1),
4674     GADGET_ID_YAMYAM_CONTENT_1,                 GADGET_ID_NONE,
4675     &level.yamyam_content[1].e[0][0],           3, 3,
4676     NULL, NULL, NULL, "2",                      NULL
4677   },
4678   {
4679     ED_DRAWING_ID_YAMYAM_CONTENT_2,
4680     ED_AREA_YAMYAM_CONTENT_XPOS,                ED_AREA_YAMYAM_CONTENT_YPOS,
4681     ED_AREA_YAMYAM_CONTENT_XOFF(2),             ED_AREA_YAMYAM_CONTENT_YOFF(2),
4682     GADGET_ID_YAMYAM_CONTENT_2,                 GADGET_ID_NONE,
4683     &level.yamyam_content[2].e[0][0],           3, 3,
4684     NULL, NULL, NULL, "3",                      NULL
4685   },
4686   {
4687     ED_DRAWING_ID_YAMYAM_CONTENT_3,
4688     ED_AREA_YAMYAM_CONTENT_XPOS,                ED_AREA_YAMYAM_CONTENT_YPOS,
4689     ED_AREA_YAMYAM_CONTENT_XOFF(3),             ED_AREA_YAMYAM_CONTENT_YOFF(3),
4690     GADGET_ID_YAMYAM_CONTENT_3,                 GADGET_ID_NONE,
4691     &level.yamyam_content[3].e[0][0],           3, 3,
4692     NULL, NULL, NULL, "4",                      NULL
4693   },
4694   {
4695     ED_DRAWING_ID_YAMYAM_CONTENT_4,
4696     ED_AREA_YAMYAM_CONTENT_XPOS,                ED_AREA_YAMYAM_CONTENT_YPOS,
4697     ED_AREA_YAMYAM_CONTENT_XOFF(4),             ED_AREA_YAMYAM_CONTENT_YOFF(4),
4698     GADGET_ID_YAMYAM_CONTENT_4,                 GADGET_ID_NONE,
4699     &level.yamyam_content[4].e[0][0],           3, 3,
4700     NULL, NULL, NULL, "5",                      NULL
4701   },
4702   {
4703     ED_DRAWING_ID_YAMYAM_CONTENT_5,
4704     ED_AREA_YAMYAM_CONTENT_XPOS,                ED_AREA_YAMYAM_CONTENT_YPOS,
4705     ED_AREA_YAMYAM_CONTENT_XOFF(5),             ED_AREA_YAMYAM_CONTENT_YOFF(5),
4706     GADGET_ID_YAMYAM_CONTENT_5,                 GADGET_ID_NONE,
4707     &level.yamyam_content[5].e[0][0],           3, 3,
4708     NULL, NULL, NULL, "6",                      NULL
4709   },
4710   {
4711     ED_DRAWING_ID_YAMYAM_CONTENT_6,
4712     ED_AREA_YAMYAM_CONTENT_XPOS,                ED_AREA_YAMYAM_CONTENT_YPOS,
4713     ED_AREA_YAMYAM_CONTENT_XOFF(6),             ED_AREA_YAMYAM_CONTENT_YOFF(6),
4714     GADGET_ID_YAMYAM_CONTENT_6,                 GADGET_ID_NONE,
4715     &level.yamyam_content[6].e[0][0],           3, 3,
4716     NULL, NULL, NULL, "7",                      NULL
4717   },
4718   {
4719     ED_DRAWING_ID_YAMYAM_CONTENT_7,
4720     ED_AREA_YAMYAM_CONTENT_XPOS,                ED_AREA_YAMYAM_CONTENT_YPOS,
4721     ED_AREA_YAMYAM_CONTENT_XOFF(7),             ED_AREA_YAMYAM_CONTENT_YOFF(7),
4722     GADGET_ID_YAMYAM_CONTENT_7,                 GADGET_ID_NONE,
4723     &level.yamyam_content[7].e[0][0],           3, 3,
4724     NULL, NULL, NULL, "8",                      NULL
4725   },
4726
4727   // ---------- magic ball content --------------------------------------------
4728
4729   {
4730     ED_DRAWING_ID_MAGIC_BALL_CONTENT_0,
4731     ED_AREA_MAGIC_BALL_CONTENT_XPOS,            ED_AREA_MAGIC_BALL_CONTENT_YPOS,
4732     ED_AREA_MAGIC_BALL_CONTENT_XOFF(0),         ED_AREA_MAGIC_BALL_CONTENT_YOFF(0),
4733     GADGET_ID_MAGIC_BALL_CONTENT_0,             GADGET_ID_NONE,
4734     &level.ball_content[0].e[0][0],             3, 3,
4735     NULL, NULL, NULL, "1",                      NULL
4736   },
4737   {
4738     ED_DRAWING_ID_MAGIC_BALL_CONTENT_1,
4739     ED_AREA_MAGIC_BALL_CONTENT_XPOS,            ED_AREA_MAGIC_BALL_CONTENT_YPOS,
4740     ED_AREA_MAGIC_BALL_CONTENT_XOFF(1),         ED_AREA_MAGIC_BALL_CONTENT_YOFF(1),
4741     GADGET_ID_MAGIC_BALL_CONTENT_1,             GADGET_ID_NONE,
4742     &level.ball_content[1].e[0][0],             3, 3,
4743     NULL, NULL, NULL, "2",                      NULL
4744   },
4745   {
4746     ED_DRAWING_ID_MAGIC_BALL_CONTENT_2,
4747     ED_AREA_MAGIC_BALL_CONTENT_XPOS,            ED_AREA_MAGIC_BALL_CONTENT_YPOS,
4748     ED_AREA_MAGIC_BALL_CONTENT_XOFF(2),         ED_AREA_MAGIC_BALL_CONTENT_YOFF(2),
4749     GADGET_ID_MAGIC_BALL_CONTENT_2,             GADGET_ID_NONE,
4750     &level.ball_content[2].e[0][0],             3, 3,
4751     NULL, NULL, NULL, "3",                      NULL
4752   },
4753   {
4754     ED_DRAWING_ID_MAGIC_BALL_CONTENT_3,
4755     ED_AREA_MAGIC_BALL_CONTENT_XPOS,            ED_AREA_MAGIC_BALL_CONTENT_YPOS,
4756     ED_AREA_MAGIC_BALL_CONTENT_XOFF(3),         ED_AREA_MAGIC_BALL_CONTENT_YOFF(3),
4757     GADGET_ID_MAGIC_BALL_CONTENT_3,             GADGET_ID_NONE,
4758     &level.ball_content[3].e[0][0],             3, 3,
4759     NULL, NULL, NULL, "4",                      NULL
4760   },
4761   {
4762     ED_DRAWING_ID_MAGIC_BALL_CONTENT_4,
4763     ED_AREA_MAGIC_BALL_CONTENT_XPOS,            ED_AREA_MAGIC_BALL_CONTENT_YPOS,
4764     ED_AREA_MAGIC_BALL_CONTENT_XOFF(4),         ED_AREA_MAGIC_BALL_CONTENT_YOFF(4),
4765     GADGET_ID_MAGIC_BALL_CONTENT_4,             GADGET_ID_NONE,
4766     &level.ball_content[4].e[0][0],             3, 3,
4767     NULL, NULL, NULL, "5",                      NULL
4768   },
4769   {
4770     ED_DRAWING_ID_MAGIC_BALL_CONTENT_5,
4771     ED_AREA_MAGIC_BALL_CONTENT_XPOS,            ED_AREA_MAGIC_BALL_CONTENT_YPOS,
4772     ED_AREA_MAGIC_BALL_CONTENT_XOFF(5),         ED_AREA_MAGIC_BALL_CONTENT_YOFF(5),
4773     GADGET_ID_MAGIC_BALL_CONTENT_5,             GADGET_ID_NONE,
4774     &level.ball_content[5].e[0][0],             3, 3,
4775     NULL, NULL, NULL, "6",                      NULL
4776   },
4777   {
4778     ED_DRAWING_ID_MAGIC_BALL_CONTENT_6,
4779     ED_AREA_MAGIC_BALL_CONTENT_XPOS,            ED_AREA_MAGIC_BALL_CONTENT_YPOS,
4780     ED_AREA_MAGIC_BALL_CONTENT_XOFF(6),         ED_AREA_MAGIC_BALL_CONTENT_YOFF(6),
4781     GADGET_ID_MAGIC_BALL_CONTENT_6,             GADGET_ID_NONE,
4782     &level.ball_content[6].e[0][0],             3, 3,
4783     NULL, NULL, NULL, "7",                      NULL
4784   },
4785   {
4786     ED_DRAWING_ID_MAGIC_BALL_CONTENT_7,
4787     ED_AREA_MAGIC_BALL_CONTENT_XPOS,            ED_AREA_MAGIC_BALL_CONTENT_YPOS,
4788     ED_AREA_MAGIC_BALL_CONTENT_XOFF(7),         ED_AREA_MAGIC_BALL_CONTENT_YOFF(7),
4789     GADGET_ID_MAGIC_BALL_CONTENT_7,             GADGET_ID_NONE,
4790     &level.ball_content[7].e[0][0],             3, 3,
4791     NULL, NULL, NULL, "8",                      NULL
4792   },
4793
4794   // ---------- android content -----------------------------------------------
4795
4796   {
4797     ED_DRAWING_ID_ANDROID_CONTENT,
4798     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(6),
4799     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4800     GADGET_ID_ANDROID_CONTENT,                  GADGET_ID_NONE,
4801     &level.android_clone_element[0],            MAX_ANDROID_ELEMENTS, 1,
4802     NULL, NULL, "Elements:", NULL,              "Elements android can clone"
4803   },
4804
4805   // ---------- amoeba content ------------------------------------------------
4806
4807   {
4808     ED_DRAWING_ID_AMOEBA_CONTENT,
4809     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(3),
4810     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4811     GADGET_ID_AMOEBA_CONTENT,                   GADGET_ID_NONE,
4812     &level.amoeba_content,                      1, 1,
4813     "Content:", NULL, NULL, NULL,               "Amoeba content"
4814   },
4815
4816   // ---------- BD snap element -----------------------------------------------
4817
4818   {
4819     ED_DRAWING_ID_BD_SNAP_ELEMENT,
4820     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(5),
4821     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4822     GADGET_ID_BD_SNAP_ELEMENT,                  GADGET_ID_NONE,
4823     &level.bd_snap_element,                     1, 1,
4824     "Snap element:", NULL, NULL, NULL,          "Element created when snapping"
4825   },
4826
4827   // ---------- BD magic wall elements ----------------------------------------
4828
4829   {
4830     ED_DRAWING_ID_BD_MAGIC_WALL_DIAMOND_TO,
4831     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(6),
4832     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4833     GADGET_ID_BD_MAGIC_WALL_DIAMOND_TO,         GADGET_ID_NONE,
4834     &level.bd_magic_wall_diamond_to,            1, 1,
4835     "Changes diamonds to:", NULL, NULL, NULL,   "Element to turn diamonds to"
4836   },
4837   {
4838     ED_DRAWING_ID_BD_MAGIC_WALL_ROCK_TO,
4839     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(7),
4840     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4841     GADGET_ID_BD_MAGIC_WALL_ROCK_TO,            GADGET_ID_NONE,
4842     &level.bd_magic_wall_rock_to,               1, 1,
4843     "Changes rocks to:", NULL, NULL, NULL,      "Element to turn rocks to"
4844   },
4845   {
4846     ED_DRAWING_ID_BD_MAGIC_WALL_MEGA_ROCK_TO,
4847     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(8),
4848     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4849     GADGET_ID_BD_MAGIC_WALL_MEGA_ROCK_TO,       GADGET_ID_NONE,
4850     &level.bd_magic_wall_mega_rock_to,          1, 1,
4851     "Changes mega rocks to:", NULL, NULL, NULL, "Element to turn mega rocks to"
4852   },
4853   {
4854     ED_DRAWING_ID_BD_MAGIC_WALL_NUT_TO,
4855     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(9),
4856     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4857     GADGET_ID_BD_MAGIC_WALL_NUT_TO,             GADGET_ID_NONE,
4858     &level.bd_magic_wall_nut_to,                1, 1,
4859     "Changes nuts to:", NULL, NULL, NULL,       "Element to turn nuts to"
4860   },
4861   {
4862     ED_DRAWING_ID_BD_MAGIC_WALL_NITRO_PACK_TO,
4863     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(10),
4864     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4865     GADGET_ID_BD_MAGIC_WALL_NITRO_PACK_TO,      GADGET_ID_NONE,
4866     &level.bd_magic_wall_nitro_pack_to,         1, 1,
4867     "Changes nitro packs to:", NULL, NULL, NULL, "Element to turn nitro packs to"
4868   },
4869   {
4870     ED_DRAWING_ID_BD_MAGIC_WALL_FLYING_DIAMOND_TO,
4871     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(11),
4872     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4873     GADGET_ID_BD_MAGIC_WALL_FLYING_DIAMOND_TO,  GADGET_ID_NONE,
4874     &level.bd_magic_wall_flying_diamond_to,     1, 1,
4875     "Changes flying diamonds to:", NULL, NULL, NULL, "Element to turn flying diamonds to"
4876   },
4877   {
4878     ED_DRAWING_ID_BD_MAGIC_WALL_FLYING_ROCK_TO,
4879     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(12),
4880     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4881     GADGET_ID_BD_MAGIC_WALL_FLYING_ROCK_TO,     GADGET_ID_NONE,
4882     &level.bd_magic_wall_flying_rock_to,        1, 1,
4883     "Changes flying rocks to:", NULL, NULL, NULL, "Element to turn flying rocks to"
4884   },
4885
4886   // ---------- BD amoeba content ---------------------------------------------
4887
4888   {
4889     ED_DRAWING_ID_BD_AMOEBA_CONTENT_TOO_BIG,
4890     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(7),
4891     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4892     GADGET_ID_BD_AMOEBA_CONTENT_TOO_BIG,        GADGET_ID_NONE,
4893     &level.bd_amoeba_content_too_big,           1, 1,
4894     "If too big, changes to:", NULL, NULL, NULL, "BD amoeba content if too big"
4895   },
4896   {
4897     ED_DRAWING_ID_BD_AMOEBA_CONTENT_ENCLOSED,
4898     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(8),
4899     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4900     GADGET_ID_BD_AMOEBA_CONTENT_ENCLOSED,       GADGET_ID_NONE,
4901     &level.bd_amoeba_content_enclosed,          1, 1,
4902     "If enclosed, changes to:", NULL, NULL, NULL, "BD amoeba content if enclosed"
4903   },
4904
4905   // ---------- BD amoeba 2 content -------------------------------------------
4906
4907   {
4908     ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_TOO_BIG,
4909     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(7),
4910     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4911     GADGET_ID_BD_AMOEBA_2_CONTENT_TOO_BIG,      GADGET_ID_NONE,
4912     &level.bd_amoeba_2_content_too_big,         1, 1,
4913     "If too big, changes to:", NULL, NULL, NULL, "BD amoeba 2 content if too big"
4914   },
4915   {
4916     ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_ENCLOSED,
4917     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(8),
4918     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4919     GADGET_ID_BD_AMOEBA_2_CONTENT_ENCLOSED,     GADGET_ID_NONE,
4920     &level.bd_amoeba_2_content_enclosed,        1, 1,
4921     "If enclosed, changes to:", NULL, NULL, NULL, "BD amoeba 2 content if enclosed"
4922   },
4923   {
4924     ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_EXPLODING,
4925     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(10),
4926     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4927     GADGET_ID_BD_AMOEBA_2_CONTENT_EXPLODING,    GADGET_ID_NONE,
4928     &level.bd_amoeba_2_content_exploding,       1, 1,
4929     "If exploding, changes to:", NULL, NULL, NULL, "BD amoeba 2 content if exploding"
4930   },
4931   {
4932     ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_LOOKS_LIKE,
4933     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(11),
4934     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4935     GADGET_ID_BD_AMOEBA_2_CONTENT_LOOKS_LIKE,   GADGET_ID_NONE,
4936     &level.bd_amoeba_2_content_looks_like,      1, 1,
4937     "Use graphic of element:", NULL, NULL, NULL, "BD amoeba 2 looks like this element"
4938   },
4939   {
4940     ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_1,
4941     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(5),
4942     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4943     GADGET_ID_BD_SLIME_EATS_ELEMENT_1,          GADGET_ID_NONE,
4944     &level.bd_slime_eats_element_1,             1, 1,
4945     "Can eat:", NULL, NULL, NULL,               "Element that can be eaten"
4946   },
4947   {
4948     ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_1,
4949     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(5),
4950     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4951     GADGET_ID_BD_SLIME_CONVERTS_TO_ELEMENT_1,   GADGET_ID_BD_SLIME_EATS_ELEMENT_1,
4952     &level.bd_slime_converts_to_element_1,      1, 1,
4953     " and convert to:", NULL, NULL, NULL,       "Eaten element is converted to"
4954   },
4955   {
4956     ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_2,
4957     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(6),
4958     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4959     GADGET_ID_BD_SLIME_EATS_ELEMENT_2,          GADGET_ID_NONE,
4960     &level.bd_slime_eats_element_2,             1, 1,
4961     "Can eat:", NULL, NULL, NULL,               "Element that can be eaten"
4962   },
4963   {
4964     ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_2,
4965     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(6),
4966     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4967     GADGET_ID_BD_SLIME_CONVERTS_TO_ELEMENT_2,   GADGET_ID_BD_SLIME_EATS_ELEMENT_2,
4968     &level.bd_slime_converts_to_element_2,      1, 1,
4969     " and convert to:", NULL, NULL, NULL,       "Eaten element is converted to"
4970   },
4971   {
4972     ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_3,
4973     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(7),
4974     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4975     GADGET_ID_BD_SLIME_EATS_ELEMENT_3,          GADGET_ID_NONE,
4976     &level.bd_slime_eats_element_3,             1, 1,
4977     "Can eat:", NULL, NULL, NULL,               "Element that can be eaten"
4978   },
4979   {
4980     ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_3,
4981     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(7),
4982     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4983     GADGET_ID_BD_SLIME_CONVERTS_TO_ELEMENT_3,   GADGET_ID_BD_SLIME_EATS_ELEMENT_3,
4984     &level.bd_slime_converts_to_element_3,      1, 1,
4985     " and convert to:", NULL, NULL, NULL,       "Eaten element is converted to"
4986   },
4987   {
4988     ED_DRAWING_ID_BD_ACID_EATS_ELEMENT,
4989     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(1),
4990     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4991     GADGET_ID_BD_ACID_EATS_ELEMENT,             GADGET_ID_NONE,
4992     &level.bd_acid_eats_element,                1, 1,
4993     "Can eat:", NULL, NULL, NULL,               "Eats this element when spreading"
4994   },
4995   {
4996     ED_DRAWING_ID_BD_ACID_TURNS_TO_ELEMENT,
4997     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(3),
4998     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
4999     GADGET_ID_BD_ACID_TURNS_TO_ELEMENT,         GADGET_ID_NONE,
5000     &level.bd_acid_turns_to_element,            1, 1,
5001     "Can leave behind:", NULL, NULL, NULL,      "Turns to this element after spreading"
5002   },
5003   {
5004     ED_DRAWING_ID_BD_BITER_EATS_ELEMENT,
5005     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(2),
5006     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5007     GADGET_ID_BD_BITER_EATS_ELEMENT,            GADGET_ID_NONE,
5008     &level.bd_biter_eats_element,               1, 1,
5009     "Can eat:", NULL, NULL, NULL,               "Eats this element when moving"
5010   },
5011   {
5012     ED_DRAWING_ID_BD_BLADDER_CONVERTS_BY_ELEMENT,
5013     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(1),
5014     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5015     GADGET_ID_BD_BLADDER_CONVERTS_BY_ELEMENT,   GADGET_ID_NONE,
5016     &level.bd_bladder_converts_by_element,      1, 1,
5017     "Turns to clock by touching:", NULL, NULL, NULL, "Turns to clock by touching element"
5018   },
5019   {
5020     ED_DRAWING_ID_BD_NUT_CONTENT,
5021     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(1),
5022     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5023     GADGET_ID_BD_NUT_CONTENT,                   GADGET_ID_NONE,
5024     &level.bd_nut_content,                      1, 1,
5025     "When breaking, changes to:", NULL, NULL, NULL, "Element created when breaking nut"
5026   },
5027   {
5028     ED_DRAWING_ID_BD_EXPANDING_WALL_LOOKS_LIKE,
5029     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(1),
5030     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5031     GADGET_ID_BD_EXPANDING_WALL_LOOKS_LIKE,     GADGET_ID_NONE,
5032     &level.bd_expanding_wall_looks_like,        1, 1,
5033     "Use graphic of element:", NULL, NULL, NULL, "Expanding wall looks like this element"
5034   },
5035   {
5036     ED_DRAWING_ID_BD_SAND_LOOKS_LIKE,
5037     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5038     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5039     GADGET_ID_BD_SAND_LOOKS_LIKE,               GADGET_ID_NONE,
5040     &level.bd_sand_looks_like,                  1, 1,
5041     "Use graphic of element:", NULL, NULL, NULL, "Sand looks like this element"
5042   },
5043   {
5044     ED_DRAWING_ID_BD_ROCK_TURNS_TO_ON_FALLING,
5045     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(2),
5046     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5047     GADGET_ID_BD_ROCK_TURNS_TO_ON_FALLING,      GADGET_ID_NONE,
5048     &level.bd_rock_turns_to_on_falling,         1, 1,
5049     "Turns to when falling:", NULL, NULL, NULL, "Changes to this when falling starts"
5050   },
5051   {
5052     ED_DRAWING_ID_BD_ROCK_TURNS_TO_ON_IMPACT,
5053     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(3),
5054     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5055     GADGET_ID_BD_ROCK_TURNS_TO_ON_IMPACT,       GADGET_ID_NONE,
5056     &level.bd_rock_turns_to_on_impact,          1, 1,
5057     "Turns to on impact:", NULL, NULL, NULL,    "Changes to this when falling stops"
5058   },
5059   {
5060     ED_DRAWING_ID_BD_DIAMOND_TURNS_TO_ON_FALLING,
5061     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(2),
5062     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5063     GADGET_ID_BD_DIAMOND_TURNS_TO_ON_FALLING,   GADGET_ID_NONE,
5064     &level.bd_diamond_turns_to_on_falling,      1, 1,
5065     "Turns to when falling:", NULL, NULL, NULL, "Changes to this when falling starts"
5066   },
5067   {
5068     ED_DRAWING_ID_BD_DIAMOND_TURNS_TO_ON_IMPACT,
5069     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(3),
5070     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5071     GADGET_ID_BD_DIAMOND_TURNS_TO_ON_IMPACT,    GADGET_ID_NONE,
5072     &level.bd_diamond_turns_to_on_impact,       1, 1,
5073     "Turns to on impact:", NULL, NULL, NULL,    "Changes to this when falling stops"
5074   },
5075   {
5076     ED_DRAWING_ID_BD_FIREFLY_EXPLODES_TO,
5077     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5078     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5079     GADGET_ID_BD_FIREFLY_EXPLODES_TO,           GADGET_ID_NONE,
5080     &level.bd_firefly_explodes_to,              1, 1,
5081     "Explodes to:", NULL, NULL, NULL,           "Changes to this when exploding"
5082   },
5083   {
5084     ED_DRAWING_ID_BD_FIREFLY_2_EXPLODES_TO,
5085     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5086     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5087     GADGET_ID_BD_FIREFLY_2_EXPLODES_TO,         GADGET_ID_NONE,
5088     &level.bd_firefly_2_explodes_to,            1, 1,
5089     "Explodes to:", NULL, NULL, NULL,           "Changes to this when exploding"
5090   },
5091   {
5092     ED_DRAWING_ID_BD_BUTTERFLY_EXPLODES_TO,
5093     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5094     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5095     GADGET_ID_BD_BUTTERFLY_EXPLODES_TO,         GADGET_ID_NONE,
5096     &level.bd_butterfly_explodes_to,            1, 1,
5097     "Explodes to:", NULL, NULL, NULL,           "Changes to this when exploding"
5098   },
5099   {
5100     ED_DRAWING_ID_BD_BUTTERFLY_2_EXPLODES_TO,
5101     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5102     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5103     GADGET_ID_BD_BUTTERFLY_2_EXPLODES_TO,       GADGET_ID_NONE,
5104     &level.bd_butterfly_2_explodes_to,          1, 1,
5105     "Explodes to:", NULL, NULL, NULL,           "Changes to this when exploding"
5106   },
5107   {
5108     ED_DRAWING_ID_BD_STONEFLY_EXPLODES_TO,
5109     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5110     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5111     GADGET_ID_BD_STONEFLY_EXPLODES_TO,          GADGET_ID_NONE,
5112     &level.bd_stonefly_explodes_to,             1, 1,
5113     "Explodes to:", NULL, NULL, NULL,           "Changes to this when exploding"
5114   },
5115   {
5116     ED_DRAWING_ID_BD_DRAGONFLY_EXPLODES_TO,
5117     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5118     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5119     GADGET_ID_BD_DRAGONFLY_EXPLODES_TO,         GADGET_ID_NONE,
5120     &level.bd_dragonfly_explodes_to,            1, 1,
5121     "Explodes to:", NULL, NULL, NULL,           "Changes to this when exploding"
5122   },
5123   {
5124     ED_DRAWING_ID_BD_DIAMOND_BIRTH_TURNS_TO,
5125     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(1),
5126     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5127     GADGET_ID_BD_DIAMOND_BIRTH_TURNS_TO,        GADGET_ID_NONE,
5128     &level.bd_diamond_birth_turns_to,           1, 1,
5129     "Explosion ends in:", NULL, NULL, NULL,     "Changes to this after explosion"
5130   },
5131   {
5132     ED_DRAWING_ID_BD_BOMB_EXPLOSION_TURNS_TO,
5133     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5134     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5135     GADGET_ID_BD_BOMB_EXPLOSION_TURNS_TO,       GADGET_ID_NONE,
5136     &level.bd_bomb_explosion_turns_to,          1, 1,
5137     "Explosion ends in:", NULL, NULL, NULL,     "Changes to this after explosion"
5138   },
5139   {
5140     ED_DRAWING_ID_BD_NITRO_EXPLOSION_TURNS_TO,
5141     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(0),
5142     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5143     GADGET_ID_BD_NITRO_EXPLOSION_TURNS_TO,      GADGET_ID_NONE,
5144     &level.bd_nitro_explosion_turns_to,         1, 1,
5145     "Explosion ends in:", NULL, NULL, NULL,     "Changes to this after explosion"
5146   },
5147   {
5148     ED_DRAWING_ID_BD_EXPLOSION_TURNS_TO,
5149     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(1),
5150     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5151     GADGET_ID_BD_EXPLOSION_TURNS_TO,            GADGET_ID_NONE,
5152     &level.bd_explosion_turns_to,               1, 1,
5153     "Explosion ends in:", NULL, NULL, NULL,     "Changes to this after explosion"
5154   },
5155
5156   // ---------- level start element -------------------------------------------
5157
5158   {
5159     ED_DRAWING_ID_START_ELEMENT,
5160     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(10),
5161     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5162     GADGET_ID_START_ELEMENT,                    GADGET_ID_USE_START_ELEMENT,
5163     &level.start_element[0],                    1, 1,
5164     NULL, NULL, NULL, NULL,                     "Level start element"
5165   },
5166
5167   // ---------- player artwork element ----------------------------------------
5168
5169   {
5170     ED_DRAWING_ID_ARTWORK_ELEMENT,
5171     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(11),
5172     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5173     GADGET_ID_ARTWORK_ELEMENT,                  GADGET_ID_USE_ARTWORK_ELEMENT,
5174     &level.artwork_element[0],                  1, 1,
5175     NULL, NULL, NULL, NULL,                     "Element for player artwork"
5176   },
5177
5178   // ---------- player explosion element --------------------------------------
5179
5180   {
5181     ED_DRAWING_ID_EXPLOSION_ELEMENT,
5182     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(12),
5183     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5184     GADGET_ID_EXPLOSION_ELEMENT,                GADGET_ID_USE_EXPLOSION_ELEMENT,
5185     &level.explosion_element[0],                1, 1,
5186     NULL, NULL, NULL, NULL,                     "Element for player explosion"
5187   },
5188
5189   // ---------- player initial inventory --------------------------------------
5190
5191   {
5192     ED_DRAWING_ID_INVENTORY_CONTENT,
5193     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(1),
5194     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5195     GADGET_ID_INVENTORY_CONTENT,                GADGET_ID_USE_INITIAL_INVENTORY,
5196     &level.initial_inventory_content[0][0],     MAX_INITIAL_INVENTORY_SIZE, 1,
5197     NULL, NULL, NULL, NULL,                     "Content for initial inventory"
5198   },
5199
5200   // ---------- gray ball content -----------------------------------------
5201
5202   {
5203     ED_DRAWING_ID_MM_BALL_CONTENT,
5204     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(2),
5205     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5206     GADGET_ID_MM_BALL_CONTENT,                  GADGET_ID_NONE,
5207     &level.mm_ball_content[0],                  MAX_MM_BALL_CONTENTS, 1,
5208     "Content:", NULL, NULL, NULL,               "Content for gray ball"
5209   },
5210
5211   // ---------- element settings: configure 1 (custom elements) ---------------
5212
5213   // ---------- custom graphic ------------------------------------------------
5214
5215   {
5216     ED_DRAWING_ID_CUSTOM_GRAPHIC,
5217     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(1),
5218     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5219     GADGET_ID_CUSTOM_GRAPHIC,                   GADGET_ID_CUSTOM_USE_GRAPHIC,
5220     &custom_element.gfx_element_initial,        1, 1,
5221     NULL, NULL, NULL, NULL,                     "Custom graphic element"
5222   },
5223
5224   // ---------- element settings: configure 2 (custom elements) ---------------
5225
5226   // ---------- custom content (when exploding) -------------------------------
5227
5228   {
5229     ED_DRAWING_ID_CUSTOM_CONTENT,
5230     -1,                                         ED_AREA_3X3_SETTINGS_YPOS(11),
5231     0,                                          ED_AREA_3X3_SETTINGS_YOFF,
5232     GADGET_ID_CUSTOM_CONTENT,                   GADGET_ID_NONE,         // align three rows
5233     &custom_element.content.e[0][0],            3, 3,
5234     "Content:", NULL, NULL, NULL,               NULL
5235   },
5236
5237   // ---------- custom enter and leave element (when moving) ------------------
5238
5239   {
5240     ED_DRAWING_ID_CUSTOM_MOVE_ENTER,
5241     ED_AREA_1X1_SETTINGS_XPOS(1),               ED_AREA_1X1_SETTINGS_YPOS(3),
5242     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5243     GADGET_ID_CUSTOM_MOVE_ENTER,                GADGET_ID_NONE,
5244     &custom_element.move_enter_element,         1, 1,
5245     "Can dig:", " ", NULL, NULL,                "Element that can be digged/collected"
5246   },
5247   {
5248     ED_DRAWING_ID_CUSTOM_MOVE_LEAVE,
5249     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(3),
5250     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5251     GADGET_ID_CUSTOM_MOVE_LEAVE,                GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE,
5252     &custom_element.move_leave_element,         1, 1,
5253     NULL, NULL, NULL, NULL,                     "Element that will be left behind"
5254   },
5255
5256   // ---------- element settings: advanced (custom elements) ------------------
5257
5258   // ---------- custom change target ------------------------------------------
5259
5260   {
5261     ED_DRAWING_ID_CUSTOM_CHANGE_TARGET,
5262     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(1),
5263     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5264     GADGET_ID_CUSTOM_CHANGE_TARGET,             GADGET_ID_CUSTOM_CAN_CHANGE,
5265     &custom_element_change.target_element,      1, 1,
5266     NULL, "after/when:", NULL, NULL,            "New target element after change"
5267   },
5268
5269   // ---------- custom change content (extended change target) ----------------
5270
5271   {
5272     ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT,
5273     -1,                                         ED_AREA_3X3_SETTINGS_YPOS(9),
5274     0,                                          ED_AREA_3X3_SETTINGS_YOFF,
5275     GADGET_ID_CUSTOM_CHANGE_CONTENT,            GADGET_ID_NONE,         // align three rows
5276     &custom_element_change.target_content.e[0][0], 3, 3,
5277     NULL, NULL, NULL, NULL,                     "New extended elements after change"
5278   },
5279
5280   // ---------- custom change trigger (element causing change) ----------------
5281
5282   {
5283     ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER,
5284     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(5),
5285     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5286     GADGET_ID_CUSTOM_CHANGE_TRIGGER,            GADGET_ID_CHANGE_OTHER_ACTION,
5287     &custom_element_change.initial_trigger_element, 1, 1,
5288     NULL, NULL, NULL, NULL,                     "Other element triggering change"
5289   },
5290
5291   // ---------- custom change action (element used for action) ----------------
5292
5293   {
5294     ED_DRAWING_ID_CUSTOM_CHANGE_ACTION,
5295     -1,                                         ED_AREA_1X1_SETTINGS_YPOS(13),
5296     0,                                          ED_AREA_1X1_SETTINGS_YOFF,
5297     GADGET_ID_CUSTOM_CHANGE_ACTION,             GADGET_ID_ACTION_ARG,
5298     &custom_element_change.action_element,      1, 1,
5299     NULL, NULL, NULL, NULL,                     "Element used as action parameter"
5300   },
5301
5302   // ---------- group element content -----------------------------------------
5303
5304   {
5305     ED_DRAWING_ID_GROUP_CONTENT,
5306     ED_AREA_1X1_SETTINGS_XPOS(0),               ED_AREA_1X1_SETTINGS_YPOS(2),
5307     ED_AREA_1X1_SETTINGS_XOFF,                  ED_AREA_1X1_SETTINGS_YOFF,
5308     GADGET_ID_GROUP_CONTENT,                    GADGET_ID_NONE,
5309     &group_element_info.element[0],             MAX_ELEMENTS_IN_GROUP, 1,
5310     "Content:", NULL, NULL, NULL,               NULL
5311   },
5312
5313   // ---------- random background (for random painting) -----------------------
5314
5315   {
5316     ED_DRAWING_ID_RANDOM_BACKGROUND,
5317     -1,                                         ED_AREA_1X1_LSETTINGS_YPOS(1),
5318     0,                                          ED_AREA_1X1_LSETTINGS_YOFF,
5319     GADGET_ID_RANDOM_BACKGROUND,                GADGET_ID_RANDOM_RESTRICTED,
5320     &random_placement_background_element,       1, 1,
5321     NULL, NULL, NULL, NULL,                     "Random placement background"
5322   },
5323 };
5324
5325
5326 // ----------------------------------------------------------------------------
5327 // some internally used variables
5328 // ----------------------------------------------------------------------------
5329
5330 // maximal size of level editor drawing area
5331 static int MAX_ED_FIELDX, MAX_ED_FIELDY;
5332
5333 // actual size of level editor drawing area
5334 static int ed_fieldx, ed_fieldy;
5335
5336 // actual position of level editor drawing area in level playfield
5337 static int level_xpos = -1, level_ypos = -1;
5338
5339 // actual tile size used to display playfield drawing area
5340 static int ed_tilesize = DEFAULT_EDITOR_TILESIZE;
5341 static int ed_tilesize_default = DEFAULT_EDITOR_TILESIZE;
5342
5343 #define IN_ED_FIELD(x, y)       IN_FIELD(x, y, ed_fieldx, ed_fieldy)
5344
5345 // drawing elements on the three mouse buttons
5346 static int new_element1 = EL_WALL;
5347 static int new_element2 = EL_EMPTY;
5348 static int new_element3 = EL_SAND;
5349
5350 #define IS_VALID_BUTTON(button) (button >= 1 && button <= 3)
5351 #define BUTTON_ELEMENT(button) ((button) == 1 ? new_element1 : \
5352                                 (button) == 2 ? new_element2 : \
5353                                 (button) == 3 ? new_element3 : EL_EMPTY)
5354
5355 #define BUTTON_TILE_SIZE(x)     ((x) >= TILESIZE ? TILESIZE : MINI_TILESIZE)
5356
5357 static int use_permanent_palette = TRUE;
5358
5359 #define PX              (use_permanent_palette ? DX : SX)
5360 #define PY              (use_permanent_palette ? DY : SY)
5361 #define PXSIZE          (use_permanent_palette ? DXSIZE : SXSIZE)
5362 #define PYSIZE          (use_permanent_palette ? DYSIZE : SYSIZE)
5363
5364 // forward declaration for internal use
5365 static void CopyBrushToCursor(int, int);
5366 static void DeleteBrushFromCursor(void);
5367 static void ModifyEditorCounterValue(int, int);
5368 static void ModifyEditorCounterLimits(int, int, int);
5369 static void ModifyEditorSelectboxValue(int, int);
5370 static void ModifyEditorSelectboxOptions(int, struct ValueTextInfo *);
5371 static void ModifyEditorDrawingArea(int, int, int);
5372 static void ModifyEditorElementList(void);
5373 static void AdjustElementListScrollbar(void);
5374 static void RedrawDrawingElements(void);
5375 static void DrawDrawingWindowExt(boolean);
5376 static void DrawDrawingWindow(void);
5377 static void DrawLevelConfigWindow(void);
5378 static void DrawPropertiesWindow(void);
5379 static void DrawPaletteWindow(void);
5380 static void UpdateCustomElementGraphicGadgets(void);
5381 static boolean checkPropertiesConfig(int);
5382 static void SetAutomaticNumberOfGemsNeeded(void);
5383 static void ClearEditorGadgetInfoText(void);
5384 static void CopyLevelToUndoBuffer(int);
5385 static void HandleDrawingAreas(struct GadgetInfo *);
5386 static void HandleCounterButtons(struct GadgetInfo *);
5387 static void HandleTextInputGadgets(struct GadgetInfo *);
5388 static void HandleTextAreaGadgets(struct GadgetInfo *);
5389 static void HandleSelectboxGadgets(struct GadgetInfo *);
5390 static void HandleTextbuttonGadgets(struct GadgetInfo *);
5391 static void HandleGraphicbuttonGadgets(struct GadgetInfo *);
5392 static void HandleRadiobuttons(struct GadgetInfo *);
5393 static void HandleCheckbuttons(struct GadgetInfo *);
5394 static void HandleControlButtons(struct GadgetInfo *);
5395 static void HandleDrawingAreaInfo(struct GadgetInfo *);
5396 static void PrintEditorGadgetInfoText(struct GadgetInfo *);
5397 static boolean AskToCopyAndModifyLevelTemplate(void);
5398 static boolean getDrawModeHiRes(void);
5399 static int getTabulatorBarWidth(void);
5400 static int getTabulatorBarHeight(void);
5401 static Pixel getTabulatorBarColor(void);
5402 static void getEditorGraphicAndFrame(int, int *, int *, boolean);
5403 static int numHiresTiles(int);
5404
5405 static int num_editor_gadgets = 0;      // dynamically determined
5406
5407 static struct GadgetInfo **level_editor_gadget = NULL;
5408 static int *right_gadget_border = NULL;
5409
5410 static int drawing_function = GADGET_ID_SINGLE_ITEMS;
5411 static int last_drawing_function = GADGET_ID_SINGLE_ITEMS;
5412 static boolean draw_with_brush = FALSE;
5413 static int properties_element = 0;
5414
5415 static short TileBackup[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
5416 static short UndoBuffer[NUM_UNDO_STEPS][MAX_LEV_FIELDX][MAX_LEV_FIELDY];
5417 static short IntelliDrawBuffer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
5418 static int undo_buffer_position = 0;
5419 static int undo_buffer_steps = 0;
5420 static int redo_buffer_steps = 0;
5421
5422 static int edit_mode;
5423 static int edit_mode_levelconfig;
5424 static int edit_mode_engineconfig;
5425 static int edit_mode_properties;
5426
5427 static int element_shift = 0;
5428
5429 static int editor_el_players[] =
5430 {
5431   EL_PLAYER_1,
5432   EL_PLAYER_2,
5433   EL_PLAYER_3,
5434   EL_PLAYER_4
5435 };
5436 static int *editor_el_players_ptr = editor_el_players;
5437 static int num_editor_el_players = ARRAY_SIZE(editor_el_players);
5438
5439 static int editor_hl_boulderdash[] =
5440 {
5441   EL_INTERNAL_CASCADE_BD_ACTIVE,
5442   EL_CHAR('B'),
5443   EL_CHAR('D'),
5444   EL_EMPTY,
5445 };
5446
5447 static int editor_el_boulderdash[] =
5448 {
5449   EL_EMPTY,
5450   EL_SAND,
5451   EL_BD_ROCK,
5452   EL_BD_DIAMOND,
5453
5454   EL_STEELWALL,
5455   EL_BD_WALL,
5456   EL_BD_EXPANDABLE_WALL,
5457   EL_BD_MAGIC_WALL,
5458
5459   EL_BD_AMOEBA,
5460   EL_BD_BUTTERFLY_UP,
5461   EL_BD_FIREFLY_UP,
5462   EL_EXIT_CLOSED,
5463
5464   EL_BD_BUTTERFLY_LEFT,
5465   EL_BD_FIREFLY_LEFT,
5466   EL_BD_BUTTERFLY_RIGHT,
5467   EL_BD_FIREFLY_RIGHT,
5468
5469   EL_EMPTY,
5470   EL_BD_BUTTERFLY_DOWN,
5471   EL_BD_FIREFLY_DOWN,
5472   EL_EXIT_OPEN,
5473 };
5474 static int *editor_hl_boulderdash_ptr = editor_hl_boulderdash;
5475 static int *editor_el_boulderdash_ptr = editor_el_boulderdash;
5476 static int num_editor_hl_boulderdash = ARRAY_SIZE(editor_hl_boulderdash);
5477 static int num_editor_el_boulderdash = ARRAY_SIZE(editor_el_boulderdash);
5478
5479 static int editor_hl_boulderdash_native[] =
5480 {
5481   EL_INTERNAL_CASCADE_BD_NATIVE_ACTIVE,
5482   EL_CHAR('B'),
5483   EL_CHAR('D'),
5484   EL_EMPTY,
5485 };
5486
5487 static int editor_el_boulderdash_native[] =
5488 {
5489   EL_EMPTY,
5490   EL_BD_SAND,
5491   EL_BD_ROCK,
5492   EL_BD_DIAMOND,
5493
5494   EL_BD_INBOX,
5495   EL_BD_STEELWALL,
5496   EL_BD_WALL,
5497   EL_BD_MAGIC_WALL,
5498
5499   EL_BD_AMOEBA,
5500   EL_BD_BUTTERFLY_UP,
5501   EL_BD_FIREFLY_UP,
5502   EL_BD_EXIT_CLOSED,
5503
5504   EL_BD_BUTTERFLY_LEFT,
5505   EL_BD_FIREFLY_LEFT,
5506   EL_BD_BUTTERFLY_RIGHT,
5507   EL_BD_FIREFLY_RIGHT,
5508
5509   EL_BD_SAND_2,
5510   EL_BD_BUTTERFLY_DOWN,
5511   EL_BD_FIREFLY_DOWN,
5512   EL_BD_EXIT_OPEN,
5513
5514   EL_BD_AMOEBA_2,
5515   EL_BD_BUTTERFLY_2_UP,
5516   EL_BD_FIREFLY_2_UP,
5517   EL_BD_SLIME,
5518
5519   EL_BD_BUTTERFLY_2_LEFT,
5520   EL_BD_FIREFLY_2_LEFT,
5521   EL_BD_BUTTERFLY_2_RIGHT,
5522   EL_BD_FIREFLY_2_RIGHT,
5523
5524   EL_BD_BOMB,
5525   EL_BD_BUTTERFLY_2_DOWN,
5526   EL_BD_FIREFLY_2_DOWN,
5527   EL_BD_FLYING_DIAMOND,
5528
5529   EL_BD_NITRO_PACK,
5530   EL_BD_DRAGONFLY_UP,
5531   EL_BD_STONEFLY_UP,
5532   EL_BD_DIAMOND_GLUED,
5533
5534   EL_BD_DRAGONFLY_LEFT,
5535   EL_BD_STONEFLY_LEFT,
5536   EL_BD_DRAGONFLY_RIGHT,
5537   EL_BD_STONEFLY_RIGHT,
5538
5539   EL_BD_NUT,
5540   EL_BD_DRAGONFLY_DOWN,
5541   EL_BD_STONEFLY_DOWN,
5542   EL_EMPTY,
5543
5544   EL_BD_BITER_SWITCH_1,
5545   EL_BD_BITER_UP,
5546   EL_BD_COW_UP,
5547   EL_EMPTY,
5548
5549   EL_BD_BITER_LEFT,
5550   EL_BD_COW_LEFT,
5551   EL_BD_BITER_RIGHT,
5552   EL_BD_COW_RIGHT,
5553
5554   EL_BD_VOODOO_DOLL,
5555   EL_BD_BITER_DOWN,
5556   EL_BD_COW_DOWN,
5557   EL_BD_GHOST,
5558
5559   EL_BD_SAND_GLUED,
5560   EL_BD_SAND_BALL,
5561   EL_BD_SAND_LOOSE,
5562   EL_BD_WALL_NON_SLOPED,
5563
5564   EL_BD_SAND_SLOPED_UP_LEFT,
5565   EL_BD_SAND_SLOPED_UP_RIGHT,
5566   EL_BD_WALL_SLOPED_UP_LEFT,
5567   EL_BD_WALL_SLOPED_UP_RIGHT,
5568
5569   EL_BD_SAND_SLOPED_DOWN_LEFT,
5570   EL_BD_SAND_SLOPED_DOWN_RIGHT,
5571   EL_BD_WALL_SLOPED_DOWN_LEFT,
5572   EL_BD_WALL_SLOPED_DOWN_RIGHT,
5573
5574   EL_BD_FLYING_ROCK,
5575   EL_BD_ROCK_GLUED,
5576   EL_BD_STEELWALL_SLOPED_UP_LEFT,
5577   EL_BD_STEELWALL_SLOPED_UP_RIGHT,
5578
5579   EL_BD_WAITING_ROCK,
5580   EL_BD_CHASING_ROCK,
5581   EL_BD_STEELWALL_SLOPED_DOWN_LEFT,
5582   EL_BD_STEELWALL_SLOPED_DOWN_RIGHT,
5583
5584   EL_BD_MEGA_ROCK,
5585   EL_BD_SWEET,
5586   EL_BD_INVISIBLE_EXIT_CLOSED,
5587   EL_BD_INVISIBLE_EXIT_OPEN,
5588
5589   EL_BD_STEELWALL_EXPLODABLE,
5590   EL_BD_STEELWALL_DIGGABLE,
5591   EL_BD_WALL_DIGGABLE,
5592   EL_BD_FALLING_WALL,
5593
5594   EL_BD_EXPANDABLE_WALL_HORIZONTAL,
5595   EL_BD_EXPANDABLE_WALL_VERTICAL,
5596   EL_BD_EXPANDABLE_WALL_ANY,
5597   EL_BD_EXPANDABLE_WALL_SWITCH,
5598
5599   EL_BD_EXPANDABLE_STEELWALL_HORIZONTAL,
5600   EL_BD_EXPANDABLE_STEELWALL_VERTICAL,
5601   EL_BD_EXPANDABLE_STEELWALL_ANY,
5602   EL_BD_CREATURE_SWITCH,
5603
5604   EL_BD_BLADDER,
5605   EL_BD_BLADDER_SPENDER,
5606   EL_BD_REPLICATOR,
5607   EL_BD_REPLICATOR_SWITCH,
5608
5609   EL_BD_CONVEYOR_LEFT,
5610   EL_BD_CONVEYOR_RIGHT,
5611   EL_BD_CONVEYOR_SWITCH,
5612   EL_BD_CONVEYOR_DIR_SWITCH,
5613
5614   EL_BD_CLOCK,
5615   EL_BD_TIME_PENALTY,
5616   EL_BD_GRAVESTONE,
5617   EL_BD_SKELETON,
5618
5619   EL_BD_WATER,
5620   EL_BD_ACID,
5621   EL_BD_LAVA,
5622   EL_BD_BOX,
5623
5624   EL_BD_GATE_1,
5625   EL_BD_GATE_2,
5626   EL_BD_GATE_3,
5627   EL_BD_TRAPPED_DIAMOND,
5628
5629   EL_BD_KEY_1,
5630   EL_BD_KEY_2,
5631   EL_BD_KEY_3,
5632   EL_BD_DIAMOND_KEY,
5633
5634   EL_BD_WALL_KEY_1,
5635   EL_BD_WALL_KEY_2,
5636   EL_BD_WALL_KEY_3,
5637   EL_BD_WALL_DIAMOND,
5638
5639   EL_BD_POT,
5640   EL_BD_GRAVITY_SWITCH,
5641   EL_BD_PNEUMATIC_HAMMER,
5642   EL_BD_TELEPORTER,
5643
5644   EL_BD_PLAYER,
5645   EL_BD_PLAYER_WITH_BOMB,
5646   EL_BD_PLAYER_WITH_ROCKET_LAUNCHER,
5647   EL_BD_ROCKET_LAUNCHER,
5648
5649   EL_BD_PLAYER_GLUED,
5650   EL_BD_PLAYER_STIRRING,
5651   EL_EMPTY,
5652   EL_EMPTY,
5653 };
5654 static int *editor_hl_boulderdash_native_ptr = editor_hl_boulderdash_native;
5655 static int *editor_el_boulderdash_native_ptr = editor_el_boulderdash_native;
5656 static int num_editor_hl_boulderdash_native = ARRAY_SIZE(editor_hl_boulderdash_native);
5657 static int num_editor_el_boulderdash_native = ARRAY_SIZE(editor_el_boulderdash_native);
5658
5659 static int editor_hl_boulderdash_effects[] =
5660 {
5661   EL_INTERNAL_CASCADE_BD_EFFECTS_ACTIVE,
5662   EL_CHAR('B'),
5663   EL_CHAR('D'),
5664   EL_CHAR('E'),
5665 };
5666
5667 static int editor_el_boulderdash_effects[] =
5668 {
5669   EL_BD_DIAMOND_FALLING,
5670   EL_BD_ROCK_FALLING,
5671   EL_BD_MEGA_ROCK_FALLING,
5672   EL_BD_FLYING_DIAMOND_FLYING,
5673
5674   EL_BD_FALLING_WALL_FALLING,
5675   EL_BD_NITRO_PACK_FALLING,
5676   EL_BD_NUT_FALLING,
5677   EL_BD_FLYING_ROCK_FLYING,
5678
5679   EL_BD_PLAYER_GROWING_1,
5680   EL_BD_PLAYER_GROWING_2,
5681   EL_BD_PLAYER_GROWING_3,
5682   EL_BD_PLAYER,
5683
5684   EL_BD_PLAYER_WITH_BOMB,
5685   EL_BD_PLAYER_STIRRING,
5686   EL_BD_EXIT_OPEN,
5687   EL_BD_INVISIBLE_EXIT_OPEN,
5688
5689   EL_BD_BLADDER_1,
5690   EL_BD_BLADDER_2,
5691   EL_BD_BLADDER_3,
5692   EL_BD_BLADDER_4,
5693
5694   EL_BD_BLADDER_5,
5695   EL_BD_BLADDER_6,
5696   EL_BD_BLADDER_7,
5697   EL_BD_BLADDER_8,
5698
5699   EL_BD_SAND_2,
5700   EL_BD_COW_ENCLOSED_1,
5701   EL_BD_COW_ENCLOSED_2,
5702   EL_BD_COW_ENCLOSED_3,
5703
5704   EL_BD_COW_ENCLOSED_4,
5705   EL_BD_COW_ENCLOSED_5,
5706   EL_BD_COW_ENCLOSED_6,
5707   EL_BD_COW_ENCLOSED_7,
5708
5709   EL_BD_WATER_1,
5710   EL_BD_WATER_2,
5711   EL_BD_WATER_3,
5712   EL_BD_WATER_4,
5713
5714   EL_BD_WATER_5,
5715   EL_BD_WATER_6,
5716   EL_BD_WATER_7,
5717   EL_BD_WATER_8,
5718
5719   EL_BD_WATER_9,
5720   EL_BD_WATER_10,
5721   EL_BD_WATER_11,
5722   EL_BD_WATER_12,
5723
5724   EL_BD_WATER_13,
5725   EL_BD_WATER_14,
5726   EL_BD_WATER_15,
5727   EL_BD_WATER_16,
5728
5729   EL_BD_BOMB_TICKING_1,
5730   EL_BD_BOMB_TICKING_2,
5731   EL_BD_BOMB_TICKING_3,
5732   EL_BD_BOMB_TICKING_4,
5733
5734   EL_BD_BOMB_TICKING_5,
5735   EL_BD_BOMB_TICKING_6,
5736   EL_BD_BOMB_TICKING_7,
5737   EL_EMPTY,
5738
5739   EL_BD_BOMB_EXPLODING_1,
5740   EL_BD_BOMB_EXPLODING_2,
5741   EL_BD_BOMB_EXPLODING_3,
5742   EL_BD_BOMB_EXPLODING_4,
5743
5744   EL_BD_NUT_BREAKING_1,
5745   EL_BD_NUT_BREAKING_2,
5746   EL_BD_NUT_BREAKING_3,
5747   EL_BD_NUT_BREAKING_4,
5748
5749   EL_BD_EXPLODING_1,
5750   EL_BD_EXPLODING_2,
5751   EL_BD_EXPLODING_3,
5752   EL_BD_EXPLODING_4,
5753
5754   EL_BD_EXPLODING_5,
5755   EL_BD_TIME_PENALTY,
5756   EL_BD_DIAMOND_GROWING_1,
5757   EL_BD_DIAMOND_GROWING_2,
5758
5759   EL_BD_DIAMOND_GROWING_3,
5760   EL_BD_DIAMOND_GROWING_4,
5761   EL_BD_DIAMOND_GROWING_5,
5762   EL_BD_NITRO_PACK_EXPLODING,
5763
5764   EL_BD_NITRO_PACK_EXPLODING_1,
5765   EL_BD_NITRO_PACK_EXPLODING_2,
5766   EL_BD_NITRO_PACK_EXPLODING_3,
5767   EL_BD_NITRO_PACK_EXPLODING_4,
5768
5769   EL_BD_ROCK_GROWING_1,
5770   EL_BD_ROCK_GROWING_2,
5771   EL_BD_ROCK_GROWING_3,
5772   EL_BD_ROCK_GROWING_4,
5773
5774   EL_BD_STEELWALL_GROWING_1,
5775   EL_BD_STEELWALL_GROWING_2,
5776   EL_BD_STEELWALL_GROWING_3,
5777   EL_BD_STEELWALL_GROWING_4,
5778
5779   EL_BD_CLOCK_GROWING_1,
5780   EL_BD_CLOCK_GROWING_2,
5781   EL_BD_CLOCK_GROWING_3,
5782   EL_BD_CLOCK_GROWING_4,
5783
5784   EL_BD_GHOST_EXPLODING_1,
5785   EL_BD_GHOST_EXPLODING_2,
5786   EL_BD_GHOST_EXPLODING_3,
5787   EL_BD_GHOST_EXPLODING_4,
5788 };
5789 static int *editor_hl_boulderdash_effects_ptr = editor_hl_boulderdash_effects;
5790 static int *editor_el_boulderdash_effects_ptr = editor_el_boulderdash_effects;
5791 static int num_editor_hl_boulderdash_effects = ARRAY_SIZE(editor_hl_boulderdash_effects);
5792 static int num_editor_el_boulderdash_effects = ARRAY_SIZE(editor_el_boulderdash_effects);
5793
5794 static int editor_hl_emerald_mine[] =
5795 {
5796   EL_INTERNAL_CASCADE_EM_ACTIVE,
5797   EL_CHAR('E'),
5798   EL_CHAR('M'),
5799   EL_EMPTY,
5800 };
5801
5802 static int editor_el_emerald_mine[] =
5803 {
5804   EL_SAND,
5805   EL_ROCK,
5806   EL_QUICKSAND_EMPTY,
5807   EL_QUICKSAND_FULL,
5808
5809   EL_STEELWALL,
5810   EL_WALL,
5811   EL_WALL_SLIPPERY,
5812   EL_MAGIC_WALL,
5813
5814   EL_EMERALD,
5815   EL_DIAMOND,
5816   EL_NUT,
5817   EL_BOMB,
5818
5819   EL_EM_DYNAMITE,
5820   EL_EM_DYNAMITE_ACTIVE,
5821   EL_EM_EXIT_CLOSED,
5822   EL_EM_EXIT_OPEN,
5823
5824   EL_YAMYAM_UP,
5825   EL_BUG_UP,
5826   EL_SPACESHIP_UP,
5827   EL_ROBOT,
5828
5829   EL_BUG_LEFT,
5830   EL_SPACESHIP_LEFT,
5831   EL_BUG_RIGHT,
5832   EL_SPACESHIP_RIGHT,
5833
5834   EL_ROBOT_WHEEL,
5835   EL_BUG_DOWN,
5836   EL_SPACESHIP_DOWN,
5837   EL_INVISIBLE_WALL,
5838
5839   EL_ACID_POOL_TOPLEFT,
5840   EL_ACID,
5841   EL_ACID_POOL_TOPRIGHT,
5842   EL_AMOEBA_DROP,
5843
5844   EL_ACID_POOL_BOTTOMLEFT,
5845   EL_ACID_POOL_BOTTOM,
5846   EL_ACID_POOL_BOTTOMRIGHT,
5847   EL_AMOEBA_WET,
5848
5849   EL_EM_KEY_1,
5850   EL_EM_KEY_2,
5851   EL_EM_KEY_3,
5852   EL_EM_KEY_4,
5853
5854   EL_EM_GATE_1,
5855   EL_EM_GATE_2,
5856   EL_EM_GATE_3,
5857   EL_EM_GATE_4,
5858
5859   EL_EM_GATE_1_GRAY,
5860   EL_EM_GATE_2_GRAY,
5861   EL_EM_GATE_3_GRAY,
5862   EL_EM_GATE_4_GRAY,
5863 };
5864 static int *editor_hl_emerald_mine_ptr = editor_hl_emerald_mine;
5865 static int *editor_el_emerald_mine_ptr = editor_el_emerald_mine;
5866 static int num_editor_hl_emerald_mine = ARRAY_SIZE(editor_hl_emerald_mine);
5867 static int num_editor_el_emerald_mine = ARRAY_SIZE(editor_el_emerald_mine);
5868
5869 static int editor_hl_emerald_mine_club[] =
5870 {
5871   EL_INTERNAL_CASCADE_EMC_ACTIVE,
5872   EL_CHAR('E'),
5873   EL_CHAR('M'),
5874   EL_CHAR('C'),
5875 };
5876
5877 static int editor_el_emerald_mine_club[] =
5878 {
5879   EL_EMC_KEY_5,
5880   EL_EMC_KEY_6,
5881   EL_EMC_KEY_7,
5882   EL_EMC_KEY_8,
5883
5884   EL_EMC_GATE_5,
5885   EL_EMC_GATE_6,
5886   EL_EMC_GATE_7,
5887   EL_EMC_GATE_8,
5888
5889   EL_EMC_GATE_5_GRAY,
5890   EL_EMC_GATE_6_GRAY,
5891   EL_EMC_GATE_7_GRAY,
5892   EL_EMC_GATE_8_GRAY,
5893
5894   EL_EMC_STEELWALL_1,
5895   EL_EMC_STEELWALL_2,
5896   EL_EMC_STEELWALL_3,
5897   EL_EMC_STEELWALL_4,
5898
5899   EL_EMC_WALL_13,
5900   EL_EMC_WALL_14,
5901   EL_EMC_WALL_15,
5902   EL_EMC_WALL_16,
5903
5904   EL_EMC_WALL_SLIPPERY_1,
5905   EL_EMC_WALL_SLIPPERY_2,
5906   EL_EMC_WALL_SLIPPERY_3,
5907   EL_EMC_WALL_SLIPPERY_4,
5908
5909   EL_EMC_WALL_1,
5910   EL_EMC_WALL_2,
5911   EL_EMC_WALL_3,
5912   EL_EMC_WALL_4,
5913
5914   EL_EMC_WALL_5,
5915   EL_EMC_WALL_6,
5916   EL_EMC_WALL_7,
5917   EL_EMC_WALL_8,
5918
5919   EL_EMC_WALL_9,
5920   EL_EMC_WALL_10,
5921   EL_EMC_WALL_11,
5922   EL_EMC_WALL_12,
5923
5924   EL_EMC_GRASS,
5925   EL_EMC_FAKE_GRASS,
5926   EL_EMC_PLANT,
5927   EL_EMC_DRIPPER,
5928
5929   EL_EMC_MAGIC_BALL,
5930   EL_EMC_MAGIC_BALL_SWITCH,
5931   EL_EMC_LENSES,
5932   EL_EMC_MAGNIFIER,
5933
5934   EL_SPRING_LEFT,
5935   EL_SPRING,
5936   EL_SPRING_RIGHT,
5937   EL_EMC_SPRING_BUMPER,
5938
5939   EL_BALLOON,
5940   EL_YAMYAM_UP,
5941   EL_BALLOON_SWITCH_UP,
5942   EL_BALLOON_SWITCH_ANY,
5943
5944   EL_YAMYAM_LEFT,
5945   EL_BALLOON_SWITCH_LEFT,
5946   EL_YAMYAM_RIGHT,
5947   EL_BALLOON_SWITCH_RIGHT,
5948
5949   EL_EMC_ANDROID,
5950   EL_YAMYAM_DOWN,
5951   EL_BALLOON_SWITCH_DOWN,
5952   EL_BALLOON_SWITCH_NONE,
5953 };
5954 static int *editor_hl_emerald_mine_club_ptr = editor_hl_emerald_mine_club;
5955 static int *editor_el_emerald_mine_club_ptr = editor_el_emerald_mine_club;
5956 static int num_editor_hl_emerald_mine_club = ARRAY_SIZE(editor_hl_emerald_mine_club);
5957 static int num_editor_el_emerald_mine_club = ARRAY_SIZE(editor_el_emerald_mine_club);
5958
5959 static int editor_hl_rnd[] =
5960 {
5961   EL_INTERNAL_CASCADE_RND_ACTIVE,
5962   EL_CHAR('R'),
5963   EL_CHAR('N'),
5964   EL_CHAR('D'),
5965 };
5966
5967 static int editor_el_rnd[] =
5968 {
5969   EL_DYNAMITE,                  // RND
5970   EL_DYNAMITE_ACTIVE,           // RND
5971   EL_EMPTY,
5972   EL_EMPTY,
5973
5974   EL_KEY_1,
5975   EL_KEY_2,
5976   EL_KEY_3,
5977   EL_KEY_4,
5978
5979   EL_GATE_1,
5980   EL_GATE_2,
5981   EL_GATE_3,
5982   EL_GATE_4,
5983
5984   EL_GATE_1_GRAY,
5985   EL_GATE_2_GRAY,
5986   EL_GATE_3_GRAY,
5987   EL_GATE_4_GRAY,
5988
5989   EL_ARROW_LEFT,
5990   EL_ARROW_RIGHT,
5991   EL_ARROW_UP,
5992   EL_ARROW_DOWN,
5993
5994   EL_AMOEBA_DEAD,
5995   EL_AMOEBA_DRY,
5996   EL_AMOEBA_FULL,
5997   EL_GAME_OF_LIFE,
5998
5999   EL_EMERALD_YELLOW,
6000   EL_EMERALD_RED,
6001   EL_EMERALD_PURPLE,
6002   EL_BIOMAZE,
6003
6004   EL_WALL_EMERALD_YELLOW,
6005   EL_WALL_EMERALD_RED,
6006   EL_WALL_EMERALD_PURPLE,
6007   EL_WALL_BD_DIAMOND,
6008
6009   EL_SPEED_PILL,
6010   EL_PACMAN_UP,
6011   EL_TIME_ORB_FULL,
6012   EL_TIME_ORB_EMPTY,
6013
6014   EL_PACMAN_LEFT,
6015   EL_DARK_YAMYAM,
6016   EL_PACMAN_RIGHT,
6017   EL_YAMYAM,                    // RND
6018
6019   EL_BLACK_ORB,
6020   EL_PACMAN_DOWN,
6021   EL_LAMP,
6022   EL_LAMP_ACTIVE,
6023
6024   EL_DYNABOMB_INCREASE_NUMBER,
6025   EL_DYNABOMB_INCREASE_SIZE,
6026   EL_DYNABOMB_INCREASE_POWER,
6027   EL_STONEBLOCK,
6028
6029   EL_MOLE,
6030   EL_PENGUIN,
6031   EL_PIG,
6032   EL_DRAGON,
6033
6034   EL_BUG,
6035   EL_MOLE_UP,
6036   EL_BD_BUTTERFLY,
6037   EL_BD_FIREFLY,
6038
6039   EL_MOLE_LEFT,
6040   EL_SATELLITE,
6041   EL_MOLE_RIGHT,
6042   EL_PACMAN,
6043
6044   EL_SPACESHIP,
6045   EL_MOLE_DOWN,
6046   EL_INVISIBLE_STEELWALL,
6047   EL_INVISIBLE_WALL,
6048
6049   EL_EXPANDABLE_WALL,
6050   EL_EXPANDABLE_WALL_HORIZONTAL,
6051   EL_EXPANDABLE_WALL_VERTICAL,
6052   EL_EXPANDABLE_WALL_ANY,
6053 };
6054 static int *editor_hl_rnd_ptr = editor_hl_rnd;
6055 static int *editor_el_rnd_ptr = editor_el_rnd;
6056 static int num_editor_hl_rnd = ARRAY_SIZE(editor_hl_rnd);
6057 static int num_editor_el_rnd = ARRAY_SIZE(editor_el_rnd);
6058
6059 static int editor_hl_sokoban[] =
6060 {
6061   EL_INTERNAL_CASCADE_SB_ACTIVE,
6062   EL_CHAR('S'),
6063   EL_CHAR('B'),
6064   EL_EMPTY,
6065 };
6066
6067 static int editor_el_sokoban[] =
6068 {
6069   EL_SOKOBAN_OBJECT,
6070   EL_SOKOBAN_FIELD_EMPTY,
6071   EL_SOKOBAN_FIELD_FULL,
6072   EL_SOKOBAN_FIELD_PLAYER,
6073 };
6074 static int *editor_hl_sokoban_ptr = editor_hl_sokoban;
6075 static int *editor_el_sokoban_ptr = editor_el_sokoban;
6076 static int num_editor_hl_sokoban = ARRAY_SIZE(editor_hl_sokoban);
6077 static int num_editor_el_sokoban = ARRAY_SIZE(editor_el_sokoban);
6078
6079 static int editor_hl_supaplex[] =
6080 {
6081   EL_INTERNAL_CASCADE_SP_ACTIVE,
6082   EL_CHAR('S'),
6083   EL_CHAR('P'),
6084   EL_EMPTY,
6085 };
6086
6087 static int editor_el_supaplex[] =
6088 {
6089   EL_SP_MURPHY,
6090   EL_EMPTY,
6091   EL_SP_BASE,
6092   EL_SP_BUGGY_BASE,
6093
6094   EL_SP_INFOTRON,
6095   EL_SP_ZONK,
6096   EL_SP_SNIKSNAK,
6097   EL_SP_ELECTRON,
6098
6099   EL_SP_DISK_RED,
6100   EL_SP_DISK_ORANGE,
6101   EL_SP_DISK_YELLOW,
6102   EL_SP_TERMINAL,
6103
6104   EL_SP_EXIT_CLOSED,
6105   EL_SP_PORT_HORIZONTAL,
6106   EL_SP_PORT_VERTICAL,
6107   EL_SP_PORT_ANY,
6108
6109   EL_SP_PORT_LEFT,
6110   EL_SP_PORT_RIGHT,
6111   EL_SP_PORT_UP,
6112   EL_SP_PORT_DOWN,
6113
6114   EL_SP_GRAVITY_PORT_LEFT,
6115   EL_SP_GRAVITY_PORT_RIGHT,
6116   EL_SP_GRAVITY_PORT_UP,
6117   EL_SP_GRAVITY_PORT_DOWN,
6118
6119   EL_SP_GRAVITY_ON_PORT_LEFT,
6120   EL_SP_GRAVITY_ON_PORT_RIGHT,
6121   EL_SP_GRAVITY_ON_PORT_UP,
6122   EL_SP_GRAVITY_ON_PORT_DOWN,
6123
6124   EL_SP_GRAVITY_OFF_PORT_LEFT,
6125   EL_SP_GRAVITY_OFF_PORT_RIGHT,
6126   EL_SP_GRAVITY_OFF_PORT_UP,
6127   EL_SP_GRAVITY_OFF_PORT_DOWN,
6128
6129   EL_SP_HARDWARE_GRAY,
6130   EL_SP_HARDWARE_GREEN,
6131   EL_SP_HARDWARE_BLUE,
6132   EL_SP_HARDWARE_RED,
6133
6134   EL_SP_HARDWARE_BASE_1,
6135   EL_SP_HARDWARE_BASE_2,
6136   EL_SP_HARDWARE_BASE_3,
6137   EL_SP_HARDWARE_BASE_4,
6138
6139   EL_SP_HARDWARE_BASE_5,
6140   EL_SP_HARDWARE_BASE_6,
6141   EL_SP_HARDWARE_YELLOW,
6142   EL_SP_CHIP_TOP,
6143
6144   EL_SP_CHIP_SINGLE,
6145   EL_SP_CHIP_LEFT,
6146   EL_SP_CHIP_RIGHT,
6147   EL_SP_CHIP_BOTTOM,
6148 };
6149 static int *editor_hl_supaplex_ptr = editor_hl_supaplex;
6150 static int *editor_el_supaplex_ptr = editor_el_supaplex;
6151 static int num_editor_hl_supaplex = ARRAY_SIZE(editor_hl_supaplex);
6152 static int num_editor_el_supaplex = ARRAY_SIZE(editor_el_supaplex);
6153
6154 static int editor_hl_diamond_caves[] =
6155 {
6156   EL_INTERNAL_CASCADE_DC_ACTIVE,
6157   EL_CHAR('D'),
6158   EL_CHAR('C'),
6159   EL_CHAR('2'),
6160 };
6161
6162 static int editor_el_diamond_caves[] =
6163 {
6164   EL_EM_STEEL_EXIT_CLOSED,      // DC2
6165   EL_EM_STEEL_EXIT_OPEN,        // DC2
6166   EL_WALL_EMERALD,              // DC2
6167   EL_WALL_DIAMOND,              // DC2
6168
6169   EL_PEARL,
6170   EL_CRYSTAL,
6171   EL_WALL_PEARL,
6172   EL_WALL_CRYSTAL,
6173
6174   EL_CONVEYOR_BELT_1_LEFT,
6175   EL_CONVEYOR_BELT_1_MIDDLE,
6176   EL_CONVEYOR_BELT_1_RIGHT,
6177   EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
6178
6179   EL_CONVEYOR_BELT_2_LEFT,
6180   EL_CONVEYOR_BELT_2_MIDDLE,
6181   EL_CONVEYOR_BELT_2_RIGHT,
6182   EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
6183
6184   EL_CONVEYOR_BELT_3_LEFT,
6185   EL_CONVEYOR_BELT_3_MIDDLE,
6186   EL_CONVEYOR_BELT_3_RIGHT,
6187   EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
6188
6189   EL_CONVEYOR_BELT_4_LEFT,
6190   EL_CONVEYOR_BELT_4_MIDDLE,
6191   EL_CONVEYOR_BELT_4_RIGHT,
6192   EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
6193
6194   EL_CONVEYOR_BELT_1_SWITCH_LEFT,
6195   EL_CONVEYOR_BELT_2_SWITCH_LEFT,
6196   EL_CONVEYOR_BELT_3_SWITCH_LEFT,
6197   EL_CONVEYOR_BELT_4_SWITCH_LEFT,
6198
6199   EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
6200   EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
6201   EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
6202   EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
6203
6204   EL_TIMEGATE_CLOSED,
6205   EL_TIMEGATE_OPEN,
6206   EL_TIMEGATE_SWITCH,
6207   EL_DC_TIMEGATE_SWITCH,
6208
6209   EL_SWITCHGATE_CLOSED,
6210   EL_SWITCHGATE_OPEN,
6211   EL_SWITCHGATE_SWITCH_UP,
6212   EL_SWITCHGATE_SWITCH_DOWN,
6213
6214   EL_LIGHT_SWITCH,
6215   EL_LIGHT_SWITCH_ACTIVE,
6216   EL_DC_SWITCHGATE_SWITCH_UP,
6217   EL_DC_SWITCHGATE_SWITCH_DOWN,
6218
6219   EL_STEEL_EXIT_CLOSED,
6220   EL_STEEL_EXIT_OPEN,
6221   EL_STEELWALL_SLIPPERY,
6222   EL_INVISIBLE_SAND,
6223
6224   EL_QUICKSAND_FAST_EMPTY,
6225   EL_QUICKSAND_FAST_FULL,
6226   EL_LANDMINE,
6227   EL_DC_LANDMINE,
6228
6229   EL_SHIELD_NORMAL,
6230   EL_SHIELD_DEADLY,
6231   EL_EXTRA_TIME,
6232   EL_DC_MAGIC_WALL,
6233
6234   EL_ENVELOPE_1,
6235   EL_ENVELOPE_2,
6236   EL_ENVELOPE_3,
6237   EL_ENVELOPE_4,
6238
6239   EL_SIGN_RADIOACTIVITY,
6240   EL_SIGN_WHEELCHAIR,
6241   EL_SIGN_PARKING,
6242   EL_SIGN_NO_ENTRY,
6243
6244   EL_SIGN_GIVE_WAY,
6245   EL_SIGN_ENTRY_FORBIDDEN,
6246   EL_SIGN_EMERGENCY_EXIT,
6247   EL_SIGN_YIN_YANG,
6248
6249 #if 0
6250   EL_SIGN_SPERMS,
6251   EL_SIGN_BULLET,
6252   EL_SIGN_HEART,
6253   EL_SIGN_CROSS,
6254
6255   EL_SIGN_FRANKIE,
6256   EL_EMPTY,
6257   EL_EMPTY,
6258   EL_EMPTY,
6259
6260   EL_SPERMS,
6261   EL_BULLET,
6262   EL_HEART,
6263   EL_CROSS,
6264
6265   EL_FRANKIE,
6266   EL_EMPTY,
6267   EL_EMPTY,
6268   EL_EMPTY,
6269 #endif
6270
6271   EL_DC_STEELWALL_2_SINGLE,
6272   EL_DC_STEELWALL_2_TOP,
6273   EL_SIGN_EXCLAMATION,
6274   EL_SIGN_STOP,
6275
6276   EL_DC_STEELWALL_2_LEFT,
6277   EL_DC_STEELWALL_2_MIDDLE,
6278   EL_DC_STEELWALL_2_HORIZONTAL,
6279   EL_DC_STEELWALL_2_RIGHT,
6280
6281   EL_DC_STEELWALL_1_TOPLEFT,
6282   EL_DC_STEELWALL_2_VERTICAL,
6283   EL_DC_STEELWALL_1_TOPRIGHT,
6284   EL_DC_GATE_WHITE,
6285
6286   EL_DC_STEELWALL_1_VERTICAL,
6287   EL_DC_STEELWALL_2_BOTTOM,
6288   EL_DC_KEY_WHITE,
6289   EL_DC_GATE_WHITE_GRAY,
6290
6291   EL_DC_STEELWALL_1_BOTTOMLEFT,
6292   EL_DC_STEELWALL_1_HORIZONTAL,
6293   EL_DC_STEELWALL_1_BOTTOMRIGHT,
6294   EL_DC_GATE_FAKE_GRAY,
6295
6296   EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
6297   EL_DC_STEELWALL_1_BOTTOM,
6298   EL_DC_STEELWALL_1_BOTTOMLEFT_2,
6299   EL_EXPANDABLE_STEELWALL_HORIZONTAL,
6300
6301   EL_DC_STEELWALL_1_RIGHT,
6302   EL_EMPTY,
6303   EL_DC_STEELWALL_1_LEFT,
6304   EL_EXPANDABLE_STEELWALL_VERTICAL,
6305
6306   EL_DC_STEELWALL_1_TOPRIGHT_2,
6307   EL_DC_STEELWALL_1_TOP,
6308   EL_DC_STEELWALL_1_TOPLEFT_2,
6309   EL_EXPANDABLE_STEELWALL_ANY,
6310 };
6311 static int *editor_hl_diamond_caves_ptr = editor_hl_diamond_caves;
6312 static int *editor_el_diamond_caves_ptr = editor_el_diamond_caves;
6313 static int num_editor_hl_diamond_caves = ARRAY_SIZE(editor_hl_diamond_caves);
6314 static int num_editor_el_diamond_caves = ARRAY_SIZE(editor_el_diamond_caves);
6315
6316 static int editor_hl_dx_boulderdash[] =
6317 {
6318   EL_INTERNAL_CASCADE_DX_ACTIVE,
6319   EL_CHAR('D'),
6320   EL_CHAR('X'),
6321   EL_EMPTY,
6322 };
6323
6324 static int editor_el_dx_boulderdash[] =
6325 {
6326   EL_EMPTY,
6327   EL_TUBE_RIGHT_DOWN,
6328   EL_TUBE_HORIZONTAL_DOWN,
6329   EL_TUBE_LEFT_DOWN,
6330
6331   EL_TUBE_HORIZONTAL,
6332   EL_TUBE_VERTICAL_RIGHT,
6333   EL_TUBE_ANY,
6334   EL_TUBE_VERTICAL_LEFT,
6335
6336   EL_TUBE_VERTICAL,
6337   EL_TUBE_RIGHT_UP,
6338   EL_TUBE_HORIZONTAL_UP,
6339   EL_TUBE_LEFT_UP,
6340
6341   EL_TRAP,
6342   EL_DX_SUPABOMB,
6343   EL_EMPTY,
6344   EL_EMPTY
6345 };
6346 static int *editor_hl_dx_boulderdash_ptr = editor_hl_dx_boulderdash;
6347 static int *editor_el_dx_boulderdash_ptr = editor_el_dx_boulderdash;
6348 static int num_editor_hl_dx_boulderdash = ARRAY_SIZE(editor_hl_dx_boulderdash);
6349 static int num_editor_el_dx_boulderdash = ARRAY_SIZE(editor_el_dx_boulderdash);
6350
6351 static int editor_hl_mirror_magic[] =
6352 {
6353   EL_INTERNAL_CASCADE_MM_ACTIVE,
6354   EL_CHAR('M'),
6355   EL_CHAR('M'),
6356   EL_EMPTY,
6357 };
6358
6359 static int editor_el_mirror_magic[] =
6360 {
6361   EL_MM_MCDUFFIN_RIGHT,
6362   EL_MM_MCDUFFIN_UP,
6363   EL_MM_MCDUFFIN_LEFT,
6364   EL_MM_MCDUFFIN_DOWN,
6365
6366   EL_MM_MIRROR_START,
6367   EL_MM_MIRROR_FIXED_START,
6368   EL_MM_POLARIZER_START,
6369   EL_MM_POLARIZER_CROSS_START,
6370
6371   EL_MM_TELEPORTER_RED_START,
6372   EL_MM_TELEPORTER_YELLOW_START,
6373   EL_MM_TELEPORTER_GREEN_START,
6374   EL_MM_TELEPORTER_BLUE_START,
6375
6376   EL_MM_PRISM,
6377   EL_MM_FUSE_ACTIVE,
6378   EL_MM_PACMAN_RIGHT,
6379   EL_MM_EXIT_CLOSED,
6380
6381   EL_MM_KETTLE,
6382   EL_MM_BOMB,
6383   EL_MM_KEY,
6384   EL_MM_FUEL_FULL,
6385
6386   EL_MM_LIGHTBULB,
6387   EL_MM_LIGHTBULB_ACTIVE,
6388   EL_MM_GRAY_BALL,
6389   EL_MM_LIGHTBALL,
6390
6391   EL_MM_STEEL_WALL,
6392   EL_MM_WOODEN_WALL,
6393   EL_MM_ICE_WALL,
6394   EL_MM_AMOEBA_WALL,
6395
6396   EL_MM_STEEL_LOCK,
6397   EL_MM_WOODEN_LOCK,
6398   EL_MM_STEEL_BLOCK,
6399   EL_MM_WOODEN_BLOCK,
6400
6401   EL_MM_STEEL_GRID_FIXED_1,
6402   EL_MM_STEEL_GRID_FIXED_2,
6403   EL_MM_STEEL_GRID_FIXED_3,
6404   EL_MM_STEEL_GRID_FIXED_4,
6405
6406   EL_MM_WOODEN_GRID_FIXED_1,
6407   EL_MM_WOODEN_GRID_FIXED_2,
6408   EL_MM_WOODEN_GRID_FIXED_3,
6409   EL_MM_WOODEN_GRID_FIXED_4,
6410
6411   EL_MM_ENVELOPE_1,
6412   EL_MM_ENVELOPE_2,
6413   EL_MM_ENVELOPE_3,
6414   EL_MM_ENVELOPE_4
6415 };
6416 static int *editor_hl_mirror_magic_ptr = editor_hl_mirror_magic;
6417 static int *editor_el_mirror_magic_ptr = editor_el_mirror_magic;
6418 static int num_editor_hl_mirror_magic = ARRAY_SIZE(editor_hl_mirror_magic);
6419 static int num_editor_el_mirror_magic = ARRAY_SIZE(editor_el_mirror_magic);
6420
6421 static int editor_hl_deflektor[] =
6422 {
6423   EL_INTERNAL_CASCADE_DF_ACTIVE,
6424   EL_CHAR('D'),
6425   EL_CHAR('F'),
6426   EL_EMPTY,
6427 };
6428
6429 static int editor_el_deflektor[] =
6430 {
6431   EL_DF_LASER_RIGHT,
6432   EL_DF_LASER_UP,
6433   EL_DF_LASER_LEFT,
6434   EL_DF_LASER_DOWN,
6435
6436   EL_DF_RECEIVER_RIGHT,
6437   EL_DF_RECEIVER_UP,
6438   EL_DF_RECEIVER_LEFT,
6439   EL_DF_RECEIVER_DOWN,
6440
6441   EL_DF_MIRROR_START,
6442   EL_DF_MIRROR_ROTATING_START,
6443   EL_DF_MIRROR_FIXED_START,
6444   EL_DF_CELL,
6445
6446   EL_DF_FIBRE_OPTIC_RED_1,
6447   EL_DF_FIBRE_OPTIC_YELLOW_1,
6448   EL_DF_FIBRE_OPTIC_GREEN_1,
6449   EL_DF_FIBRE_OPTIC_BLUE_1,
6450
6451   EL_DF_STEEL_GRID_FIXED_START,
6452   EL_DF_STEEL_GRID_ROTATING_START,
6453   EL_DF_WOODEN_GRID_FIXED_START,
6454   EL_DF_WOODEN_GRID_ROTATING_START,
6455
6456   EL_DF_STEEL_WALL,
6457   EL_DF_WOODEN_WALL,
6458   EL_DF_REFRACTOR,
6459   EL_DF_MINE,
6460
6461   EL_DF_SLOPE_1,
6462   EL_DF_SLOPE_2,
6463   EL_DF_SLOPE_3,
6464   EL_DF_SLOPE_4
6465 };
6466 static int *editor_hl_deflektor_ptr = editor_hl_deflektor;
6467 static int *editor_el_deflektor_ptr = editor_el_deflektor;
6468 static int num_editor_hl_deflektor = ARRAY_SIZE(editor_hl_deflektor);
6469 static int num_editor_el_deflektor = ARRAY_SIZE(editor_el_deflektor);
6470
6471 static int editor_hl_chars[] =
6472 {
6473   EL_INTERNAL_CASCADE_CHARS_ACTIVE,
6474   EL_CHAR('T'),
6475   EL_CHAR('X'),
6476   EL_CHAR('T'),
6477 };
6478
6479 static int editor_el_chars[] =
6480 {
6481   EL_CHAR(' '),
6482   EL_CHAR('!'),
6483   EL_CHAR('"'),
6484   EL_CHAR('#'),
6485
6486   EL_CHAR('$'),
6487   EL_CHAR('%'),
6488   EL_CHAR('&'),
6489   EL_CHAR('\''),
6490
6491   EL_CHAR('('),
6492   EL_CHAR(')'),
6493   EL_CHAR('*'),
6494   EL_CHAR('+'),
6495
6496   EL_CHAR(','),
6497   EL_CHAR('-'),
6498   EL_CHAR('.'),
6499   EL_CHAR('/'),
6500
6501   EL_CHAR('0'),
6502   EL_CHAR('1'),
6503   EL_CHAR('2'),
6504   EL_CHAR('3'),
6505
6506   EL_CHAR('4'),
6507   EL_CHAR('5'),
6508   EL_CHAR('6'),
6509   EL_CHAR('7'),
6510
6511   EL_CHAR('8'),
6512   EL_CHAR('9'),
6513   EL_CHAR(':'),
6514   EL_CHAR(';'),
6515
6516   EL_CHAR('<'),
6517   EL_CHAR('='),
6518   EL_CHAR('>'),
6519   EL_CHAR('?'),
6520
6521   EL_CHAR('@'),
6522   EL_CHAR('A'),
6523   EL_CHAR('B'),
6524   EL_CHAR('C'),
6525
6526   EL_CHAR('D'),
6527   EL_CHAR('E'),
6528   EL_CHAR('F'),
6529   EL_CHAR('G'),
6530
6531   EL_CHAR('H'),
6532   EL_CHAR('I'),
6533   EL_CHAR('J'),
6534   EL_CHAR('K'),
6535
6536   EL_CHAR('L'),
6537   EL_CHAR('M'),
6538   EL_CHAR('N'),
6539   EL_CHAR('O'),
6540
6541   EL_CHAR('P'),
6542   EL_CHAR('Q'),
6543   EL_CHAR('R'),
6544   EL_CHAR('S'),
6545
6546   EL_CHAR('T'),
6547   EL_CHAR('U'),
6548   EL_CHAR('V'),
6549   EL_CHAR('W'),
6550
6551   EL_CHAR('X'),
6552   EL_CHAR('Y'),
6553   EL_CHAR('Z'),
6554   EL_CHAR('['),
6555
6556   EL_CHAR('\\'),
6557   EL_CHAR(']'),
6558   EL_CHAR('^'),
6559   EL_CHAR('_'),
6560
6561   EL_CHAR(CHAR_BYTE_COPYRIGHT),
6562   EL_CHAR(CHAR_BYTE_UMLAUT_A),
6563   EL_CHAR(CHAR_BYTE_UMLAUT_O),
6564   EL_CHAR(CHAR_BYTE_UMLAUT_U),
6565
6566   EL_CHAR(CHAR_BYTE_DEGREE),
6567   EL_CHAR(CHAR_BYTE_REGISTERED),
6568   EL_CHAR(FONT_ASCII_CURSOR),
6569   EL_CHAR(FONT_ASCII_BUTTON),
6570
6571   EL_CHAR(FONT_ASCII_UP),
6572   EL_CHAR(FONT_ASCII_DOWN),
6573   EL_CHAR(' '),
6574   EL_CHAR(' ')
6575 };
6576 static int *editor_hl_chars_ptr = editor_hl_chars;
6577 static int *editor_el_chars_ptr = editor_el_chars;
6578 static int num_editor_hl_chars = ARRAY_SIZE(editor_hl_chars);
6579 static int num_editor_el_chars = ARRAY_SIZE(editor_el_chars);
6580
6581 static int editor_hl_steel_chars[] =
6582 {
6583   EL_INTERNAL_CASCADE_STEEL_CHARS_ACTIVE,
6584   EL_STEEL_CHAR('T'),
6585   EL_STEEL_CHAR('X'),
6586   EL_STEEL_CHAR('T'),
6587 };
6588
6589 static int editor_el_steel_chars[] =
6590 {
6591   EL_STEEL_CHAR(' '),
6592   EL_STEEL_CHAR('!'),
6593   EL_STEEL_CHAR('"'),
6594   EL_STEEL_CHAR('#'),
6595
6596   EL_STEEL_CHAR('$'),
6597   EL_STEEL_CHAR('%'),
6598   EL_STEEL_CHAR('&'),
6599   EL_STEEL_CHAR('\''),
6600
6601   EL_STEEL_CHAR('('),
6602   EL_STEEL_CHAR(')'),
6603   EL_STEEL_CHAR('*'),
6604   EL_STEEL_CHAR('+'),
6605
6606   EL_STEEL_CHAR(','),
6607   EL_STEEL_CHAR('-'),
6608   EL_STEEL_CHAR('.'),
6609   EL_STEEL_CHAR('/'),
6610
6611   EL_STEEL_CHAR('0'),
6612   EL_STEEL_CHAR('1'),
6613   EL_STEEL_CHAR('2'),
6614   EL_STEEL_CHAR('3'),
6615
6616   EL_STEEL_CHAR('4'),
6617   EL_STEEL_CHAR('5'),
6618   EL_STEEL_CHAR('6'),
6619   EL_STEEL_CHAR('7'),
6620
6621   EL_STEEL_CHAR('8'),
6622   EL_STEEL_CHAR('9'),
6623   EL_STEEL_CHAR(':'),
6624   EL_STEEL_CHAR(';'),
6625
6626   EL_STEEL_CHAR('<'),
6627   EL_STEEL_CHAR('='),
6628   EL_STEEL_CHAR('>'),
6629   EL_STEEL_CHAR('?'),
6630
6631   EL_STEEL_CHAR('@'),
6632   EL_STEEL_CHAR('A'),
6633   EL_STEEL_CHAR('B'),
6634   EL_STEEL_CHAR('C'),
6635
6636   EL_STEEL_CHAR('D'),
6637   EL_STEEL_CHAR('E'),
6638   EL_STEEL_CHAR('F'),
6639   EL_STEEL_CHAR('G'),
6640
6641   EL_STEEL_CHAR('H'),
6642   EL_STEEL_CHAR('I'),
6643   EL_STEEL_CHAR('J'),
6644   EL_STEEL_CHAR('K'),
6645
6646   EL_STEEL_CHAR('L'),
6647   EL_STEEL_CHAR('M'),
6648   EL_STEEL_CHAR('N'),
6649   EL_STEEL_CHAR('O'),
6650
6651   EL_STEEL_CHAR('P'),
6652   EL_STEEL_CHAR('Q'),
6653   EL_STEEL_CHAR('R'),
6654   EL_STEEL_CHAR('S'),
6655
6656   EL_STEEL_CHAR('T'),
6657   EL_STEEL_CHAR('U'),
6658   EL_STEEL_CHAR('V'),
6659   EL_STEEL_CHAR('W'),
6660
6661   EL_STEEL_CHAR('X'),
6662   EL_STEEL_CHAR('Y'),
6663   EL_STEEL_CHAR('Z'),
6664   EL_STEEL_CHAR('['),
6665
6666   EL_STEEL_CHAR('\\'),
6667   EL_STEEL_CHAR(']'),
6668   EL_STEEL_CHAR('^'),
6669   EL_STEEL_CHAR('_'),
6670
6671   EL_STEEL_CHAR(CHAR_BYTE_COPYRIGHT),
6672   EL_STEEL_CHAR(CHAR_BYTE_UMLAUT_A),
6673   EL_STEEL_CHAR(CHAR_BYTE_UMLAUT_O),
6674   EL_STEEL_CHAR(CHAR_BYTE_UMLAUT_U),
6675
6676   EL_STEEL_CHAR(CHAR_BYTE_DEGREE),
6677   EL_STEEL_CHAR(CHAR_BYTE_REGISTERED),
6678   EL_STEEL_CHAR(FONT_ASCII_CURSOR),
6679   EL_STEEL_CHAR(FONT_ASCII_BUTTON),
6680
6681   EL_STEEL_CHAR(FONT_ASCII_UP),
6682   EL_STEEL_CHAR(FONT_ASCII_DOWN),
6683   EL_STEEL_CHAR(' '),
6684   EL_STEEL_CHAR(' ')
6685 };
6686 static int *editor_hl_steel_chars_ptr = editor_hl_steel_chars;
6687 static int *editor_el_steel_chars_ptr = editor_el_steel_chars;
6688 static int num_editor_hl_steel_chars = ARRAY_SIZE(editor_hl_steel_chars);
6689 static int num_editor_el_steel_chars = ARRAY_SIZE(editor_el_steel_chars);
6690
6691 static int editor_hl_custom[] =
6692 {
6693   EL_INTERNAL_CASCADE_CE_ACTIVE,
6694   EL_CHAR('C'),
6695   EL_CHAR('E'),
6696   EL_EMPTY,
6697 };
6698
6699 static int editor_el_custom[] =
6700 {
6701   EL_CUSTOM_START + 0,
6702   EL_CUSTOM_START + 1,
6703   EL_CUSTOM_START + 2,
6704   EL_CUSTOM_START + 3,
6705
6706   EL_CUSTOM_START + 4,
6707   EL_CUSTOM_START + 5,
6708   EL_CUSTOM_START + 6,
6709   EL_CUSTOM_START + 7,
6710
6711   EL_CUSTOM_START + 8,
6712   EL_CUSTOM_START + 9,
6713   EL_CUSTOM_START + 10,
6714   EL_CUSTOM_START + 11,
6715
6716   EL_CUSTOM_START + 12,
6717   EL_CUSTOM_START + 13,
6718   EL_CUSTOM_START + 14,
6719   EL_CUSTOM_START + 15,
6720
6721   EL_CUSTOM_START + 16,
6722   EL_CUSTOM_START + 17,
6723   EL_CUSTOM_START + 18,
6724   EL_CUSTOM_START + 19,
6725
6726   EL_CUSTOM_START + 20,
6727   EL_CUSTOM_START + 21,
6728   EL_CUSTOM_START + 22,
6729   EL_CUSTOM_START + 23,
6730
6731   EL_CUSTOM_START + 24,
6732   EL_CUSTOM_START + 25,
6733   EL_CUSTOM_START + 26,
6734   EL_CUSTOM_START + 27,
6735
6736   EL_CUSTOM_START + 28,
6737   EL_CUSTOM_START + 29,
6738   EL_CUSTOM_START + 30,
6739   EL_CUSTOM_START + 31,
6740
6741   EL_CUSTOM_START + 32,
6742   EL_CUSTOM_START + 33,
6743   EL_CUSTOM_START + 34,
6744   EL_CUSTOM_START + 35,
6745
6746   EL_CUSTOM_START + 36,
6747   EL_CUSTOM_START + 37,
6748   EL_CUSTOM_START + 38,
6749   EL_CUSTOM_START + 39,
6750
6751   EL_CUSTOM_START + 40,
6752   EL_CUSTOM_START + 41,
6753   EL_CUSTOM_START + 42,
6754   EL_CUSTOM_START + 43,
6755
6756   EL_CUSTOM_START + 44,
6757   EL_CUSTOM_START + 45,
6758   EL_CUSTOM_START + 46,
6759   EL_CUSTOM_START + 47,
6760
6761   EL_CUSTOM_START + 48,
6762   EL_CUSTOM_START + 49,
6763   EL_CUSTOM_START + 50,
6764   EL_CUSTOM_START + 51,
6765
6766   EL_CUSTOM_START + 52,
6767   EL_CUSTOM_START + 53,
6768   EL_CUSTOM_START + 54,
6769   EL_CUSTOM_START + 55,
6770
6771   EL_CUSTOM_START + 56,
6772   EL_CUSTOM_START + 57,
6773   EL_CUSTOM_START + 58,
6774   EL_CUSTOM_START + 59,
6775
6776   EL_CUSTOM_START + 60,
6777   EL_CUSTOM_START + 61,
6778   EL_CUSTOM_START + 62,
6779   EL_CUSTOM_START + 63,
6780
6781   EL_CUSTOM_START + 64,
6782   EL_CUSTOM_START + 65,
6783   EL_CUSTOM_START + 66,
6784   EL_CUSTOM_START + 67,
6785
6786   EL_CUSTOM_START + 68,
6787   EL_CUSTOM_START + 69,
6788   EL_CUSTOM_START + 70,
6789   EL_CUSTOM_START + 71,
6790
6791   EL_CUSTOM_START + 72,
6792   EL_CUSTOM_START + 73,
6793   EL_CUSTOM_START + 74,
6794   EL_CUSTOM_START + 75,
6795
6796   EL_CUSTOM_START + 76,
6797   EL_CUSTOM_START + 77,
6798   EL_CUSTOM_START + 78,
6799   EL_CUSTOM_START + 79,
6800
6801   EL_CUSTOM_START + 80,
6802   EL_CUSTOM_START + 81,
6803   EL_CUSTOM_START + 82,
6804   EL_CUSTOM_START + 83,
6805
6806   EL_CUSTOM_START + 84,
6807   EL_CUSTOM_START + 85,
6808   EL_CUSTOM_START + 86,
6809   EL_CUSTOM_START + 87,
6810
6811   EL_CUSTOM_START + 88,
6812   EL_CUSTOM_START + 89,
6813   EL_CUSTOM_START + 90,
6814   EL_CUSTOM_START + 91,
6815
6816   EL_CUSTOM_START + 92,
6817   EL_CUSTOM_START + 93,
6818   EL_CUSTOM_START + 94,
6819   EL_CUSTOM_START + 95,
6820
6821   EL_CUSTOM_START + 96,
6822   EL_CUSTOM_START + 97,
6823   EL_CUSTOM_START + 98,
6824   EL_CUSTOM_START + 99,
6825
6826   EL_CUSTOM_START + 100,
6827   EL_CUSTOM_START + 101,
6828   EL_CUSTOM_START + 102,
6829   EL_CUSTOM_START + 103,
6830
6831   EL_CUSTOM_START + 104,
6832   EL_CUSTOM_START + 105,
6833   EL_CUSTOM_START + 106,
6834   EL_CUSTOM_START + 107,
6835
6836   EL_CUSTOM_START + 108,
6837   EL_CUSTOM_START + 109,
6838   EL_CUSTOM_START + 110,
6839   EL_CUSTOM_START + 111,
6840
6841   EL_CUSTOM_START + 112,
6842   EL_CUSTOM_START + 113,
6843   EL_CUSTOM_START + 114,
6844   EL_CUSTOM_START + 115,
6845
6846   EL_CUSTOM_START + 116,
6847   EL_CUSTOM_START + 117,
6848   EL_CUSTOM_START + 118,
6849   EL_CUSTOM_START + 119,
6850
6851   EL_CUSTOM_START + 120,
6852   EL_CUSTOM_START + 121,
6853   EL_CUSTOM_START + 122,
6854   EL_CUSTOM_START + 123,
6855
6856   EL_CUSTOM_START + 124,
6857   EL_CUSTOM_START + 125,
6858   EL_CUSTOM_START + 126,
6859   EL_CUSTOM_START + 127,
6860
6861   EL_CUSTOM_START + 128,
6862   EL_CUSTOM_START + 129,
6863   EL_CUSTOM_START + 130,
6864   EL_CUSTOM_START + 131,
6865
6866   EL_CUSTOM_START + 132,
6867   EL_CUSTOM_START + 133,
6868   EL_CUSTOM_START + 134,
6869   EL_CUSTOM_START + 135,
6870
6871   EL_CUSTOM_START + 136,
6872   EL_CUSTOM_START + 137,
6873   EL_CUSTOM_START + 138,
6874   EL_CUSTOM_START + 139,
6875
6876   EL_CUSTOM_START + 140,
6877   EL_CUSTOM_START + 141,
6878   EL_CUSTOM_START + 142,
6879   EL_CUSTOM_START + 143,
6880
6881   EL_CUSTOM_START + 144,
6882   EL_CUSTOM_START + 145,
6883   EL_CUSTOM_START + 146,
6884   EL_CUSTOM_START + 147,
6885
6886   EL_CUSTOM_START + 148,
6887   EL_CUSTOM_START + 149,
6888   EL_CUSTOM_START + 150,
6889   EL_CUSTOM_START + 151,
6890
6891   EL_CUSTOM_START + 152,
6892   EL_CUSTOM_START + 153,
6893   EL_CUSTOM_START + 154,
6894   EL_CUSTOM_START + 155,
6895
6896   EL_CUSTOM_START + 156,
6897   EL_CUSTOM_START + 157,
6898   EL_CUSTOM_START + 158,
6899   EL_CUSTOM_START + 159,
6900
6901   EL_CUSTOM_START + 160,
6902   EL_CUSTOM_START + 161,
6903   EL_CUSTOM_START + 162,
6904   EL_CUSTOM_START + 163,
6905
6906   EL_CUSTOM_START + 164,
6907   EL_CUSTOM_START + 165,
6908   EL_CUSTOM_START + 166,
6909   EL_CUSTOM_START + 167,
6910
6911   EL_CUSTOM_START + 168,
6912   EL_CUSTOM_START + 169,
6913   EL_CUSTOM_START + 170,
6914   EL_CUSTOM_START + 171,
6915
6916   EL_CUSTOM_START + 172,
6917   EL_CUSTOM_START + 173,
6918   EL_CUSTOM_START + 174,
6919   EL_CUSTOM_START + 175,
6920
6921   EL_CUSTOM_START + 176,
6922   EL_CUSTOM_START + 177,
6923   EL_CUSTOM_START + 178,
6924   EL_CUSTOM_START + 179,
6925
6926   EL_CUSTOM_START + 180,
6927   EL_CUSTOM_START + 181,
6928   EL_CUSTOM_START + 182,
6929   EL_CUSTOM_START + 183,
6930
6931   EL_CUSTOM_START + 184,
6932   EL_CUSTOM_START + 185,
6933   EL_CUSTOM_START + 186,
6934   EL_CUSTOM_START + 187,
6935
6936   EL_CUSTOM_START + 188,
6937   EL_CUSTOM_START + 189,
6938   EL_CUSTOM_START + 190,
6939   EL_CUSTOM_START + 191,
6940
6941   EL_CUSTOM_START + 192,
6942   EL_CUSTOM_START + 193,
6943   EL_CUSTOM_START + 194,
6944   EL_CUSTOM_START + 195,
6945
6946   EL_CUSTOM_START + 196,
6947   EL_CUSTOM_START + 197,
6948   EL_CUSTOM_START + 198,
6949   EL_CUSTOM_START + 199,
6950
6951   EL_CUSTOM_START + 200,
6952   EL_CUSTOM_START + 201,
6953   EL_CUSTOM_START + 202,
6954   EL_CUSTOM_START + 203,
6955
6956   EL_CUSTOM_START + 204,
6957   EL_CUSTOM_START + 205,
6958   EL_CUSTOM_START + 206,
6959   EL_CUSTOM_START + 207,
6960
6961   EL_CUSTOM_START + 208,
6962   EL_CUSTOM_START + 209,
6963   EL_CUSTOM_START + 210,
6964   EL_CUSTOM_START + 211,
6965
6966   EL_CUSTOM_START + 212,
6967   EL_CUSTOM_START + 213,
6968   EL_CUSTOM_START + 214,
6969   EL_CUSTOM_START + 215,
6970
6971   EL_CUSTOM_START + 216,
6972   EL_CUSTOM_START + 217,
6973   EL_CUSTOM_START + 218,
6974   EL_CUSTOM_START + 219,
6975
6976   EL_CUSTOM_START + 220,
6977   EL_CUSTOM_START + 221,
6978   EL_CUSTOM_START + 222,
6979   EL_CUSTOM_START + 223,
6980
6981   EL_CUSTOM_START + 224,
6982   EL_CUSTOM_START + 225,
6983   EL_CUSTOM_START + 226,
6984   EL_CUSTOM_START + 227,
6985
6986   EL_CUSTOM_START + 228,
6987   EL_CUSTOM_START + 229,
6988   EL_CUSTOM_START + 230,
6989   EL_CUSTOM_START + 231,
6990
6991   EL_CUSTOM_START + 232,
6992   EL_CUSTOM_START + 233,
6993   EL_CUSTOM_START + 234,
6994   EL_CUSTOM_START + 235,
6995
6996   EL_CUSTOM_START + 236,
6997   EL_CUSTOM_START + 237,
6998   EL_CUSTOM_START + 238,
6999   EL_CUSTOM_START + 239,
7000
7001   EL_CUSTOM_START + 240,
7002   EL_CUSTOM_START + 241,
7003   EL_CUSTOM_START + 242,
7004   EL_CUSTOM_START + 243,
7005
7006   EL_CUSTOM_START + 244,
7007   EL_CUSTOM_START + 245,
7008   EL_CUSTOM_START + 246,
7009   EL_CUSTOM_START + 247,
7010
7011   EL_CUSTOM_START + 248,
7012   EL_CUSTOM_START + 249,
7013   EL_CUSTOM_START + 250,
7014   EL_CUSTOM_START + 251,
7015
7016   EL_CUSTOM_START + 252,
7017   EL_CUSTOM_START + 253,
7018   EL_CUSTOM_START + 254,
7019   EL_CUSTOM_START + 255
7020 };
7021 static int *editor_hl_custom_ptr = editor_hl_custom;
7022 static int *editor_el_custom_ptr = editor_el_custom;
7023 static int num_editor_hl_custom = ARRAY_SIZE(editor_hl_custom);
7024 static int num_editor_el_custom = ARRAY_SIZE(editor_el_custom);
7025
7026 static int editor_hl_group[] =
7027 {
7028   EL_INTERNAL_CASCADE_GE_ACTIVE,
7029   EL_CHAR('G'),
7030   EL_CHAR('E'),
7031   EL_EMPTY,
7032 };
7033
7034 static int editor_el_group[] =
7035 {
7036   EL_GROUP_START + 0,
7037   EL_GROUP_START + 1,
7038   EL_GROUP_START + 2,
7039   EL_GROUP_START + 3,
7040
7041   EL_GROUP_START + 4,
7042   EL_GROUP_START + 5,
7043   EL_GROUP_START + 6,
7044   EL_GROUP_START + 7,
7045
7046   EL_GROUP_START + 8,
7047   EL_GROUP_START + 9,
7048   EL_GROUP_START + 10,
7049   EL_GROUP_START + 11,
7050
7051   EL_GROUP_START + 12,
7052   EL_GROUP_START + 13,
7053   EL_GROUP_START + 14,
7054   EL_GROUP_START + 15,
7055
7056   EL_GROUP_START + 16,
7057   EL_GROUP_START + 17,
7058   EL_GROUP_START + 18,
7059   EL_GROUP_START + 19,
7060
7061   EL_GROUP_START + 20,
7062   EL_GROUP_START + 21,
7063   EL_GROUP_START + 22,
7064   EL_GROUP_START + 23,
7065
7066   EL_GROUP_START + 24,
7067   EL_GROUP_START + 25,
7068   EL_GROUP_START + 26,
7069   EL_GROUP_START + 27,
7070
7071   EL_GROUP_START + 28,
7072   EL_GROUP_START + 29,
7073   EL_GROUP_START + 30,
7074   EL_GROUP_START + 31
7075 };
7076 static int *editor_hl_group_ptr = editor_hl_group;
7077 static int *editor_el_group_ptr = editor_el_group;
7078 static int num_editor_hl_group = ARRAY_SIZE(editor_hl_group);
7079 static int num_editor_el_group = ARRAY_SIZE(editor_el_group);
7080
7081 static int editor_hl_empty_space[] =
7082 {
7083   EL_INTERNAL_CASCADE_ES_ACTIVE,
7084   EL_CHAR('E'),
7085   EL_CHAR('S'),
7086   EL_EMPTY,
7087 };
7088
7089 static int editor_el_empty_space[] =
7090 {
7091   EL_EMPTY_SPACE_1,
7092   EL_EMPTY_SPACE_2,
7093   EL_EMPTY_SPACE_3,
7094   EL_EMPTY_SPACE_4,
7095
7096   EL_EMPTY_SPACE_5,
7097   EL_EMPTY_SPACE_6,
7098   EL_EMPTY_SPACE_7,
7099   EL_EMPTY_SPACE_8,
7100
7101   EL_EMPTY_SPACE_9,
7102   EL_EMPTY_SPACE_10,
7103   EL_EMPTY_SPACE_11,
7104   EL_EMPTY_SPACE_12,
7105
7106   EL_EMPTY_SPACE_13,
7107   EL_EMPTY_SPACE_14,
7108   EL_EMPTY_SPACE_15,
7109   EL_EMPTY_SPACE_16
7110 };
7111 static int *editor_hl_empty_space_ptr = editor_hl_empty_space;
7112 static int *editor_el_empty_space_ptr = editor_el_empty_space;
7113 static int num_editor_hl_empty_space = ARRAY_SIZE(editor_hl_empty_space);
7114 static int num_editor_el_empty_space = ARRAY_SIZE(editor_el_empty_space);
7115
7116 static int editor_hl_reference[] =
7117 {
7118   EL_INTERNAL_CASCADE_REF_ACTIVE,
7119   EL_CHAR('R'),
7120   EL_CHAR('E'),
7121   EL_CHAR('F')
7122 };
7123
7124 static int editor_el_reference[] =
7125 {
7126   EL_TRIGGER_PLAYER,
7127   EL_TRIGGER_ELEMENT,
7128   EL_TRIGGER_CE_VALUE,
7129   EL_TRIGGER_CE_SCORE,
7130
7131   EL_SELF,
7132   EL_ANY_ELEMENT,
7133   EL_CURRENT_CE_VALUE,
7134   EL_CURRENT_CE_SCORE,
7135
7136   EL_PREV_CE_8,
7137   EL_PREV_CE_7,
7138   EL_PREV_CE_6,
7139   EL_PREV_CE_5,
7140
7141   EL_PREV_CE_4,
7142   EL_PREV_CE_3,
7143   EL_PREV_CE_2,
7144   EL_PREV_CE_1,
7145
7146   EL_NEXT_CE_1,
7147   EL_NEXT_CE_2,
7148   EL_NEXT_CE_3,
7149   EL_NEXT_CE_4,
7150
7151   EL_NEXT_CE_5,
7152   EL_NEXT_CE_6,
7153   EL_NEXT_CE_7,
7154   EL_NEXT_CE_8,
7155 };
7156 static int *editor_hl_reference_ptr = editor_hl_reference;
7157 static int *editor_el_reference_ptr = editor_el_reference;
7158 static int num_editor_hl_reference = ARRAY_SIZE(editor_hl_reference);
7159 static int num_editor_el_reference = ARRAY_SIZE(editor_el_reference);
7160
7161 static int editor_hl_user_defined[] =
7162 {
7163   EL_INTERNAL_CASCADE_USER_ACTIVE,
7164   EL_CHAR('M'),
7165   EL_CHAR('Y'),
7166   EL_EMPTY,
7167 };
7168
7169 static int *editor_hl_user_defined_ptr = editor_hl_user_defined;
7170 static int *editor_el_user_defined_ptr = NULL;
7171 static int num_editor_hl_user_defined = ARRAY_SIZE(editor_hl_user_defined);
7172 static int num_editor_el_user_defined = 0;
7173
7174 static int editor_hl_dynamic[] =
7175 {
7176   EL_INTERNAL_CASCADE_DYNAMIC_ACTIVE,
7177   EL_CHAR('U'),
7178   EL_CHAR('S'),
7179   EL_CHAR('E'),
7180 };
7181
7182 static int *editor_hl_dynamic_ptr = editor_hl_dynamic;
7183 static int *editor_el_dynamic_ptr = NULL;
7184 static int num_editor_hl_dynamic = ARRAY_SIZE(editor_hl_dynamic);
7185 static int num_editor_el_dynamic = 0;
7186
7187 static int editor_hl_empty[] = { EL_EMPTY };
7188 static int *editor_el_empty = NULL;     // dynamically allocated
7189
7190 static int *editor_hl_empty_ptr = editor_hl_empty;
7191 static int *editor_el_empty_ptr = NULL;
7192 static int num_editor_hl_empty = 0;
7193 static int num_editor_el_empty = 0;     // dynamically determined, if needed
7194
7195 static boolean use_el_empty = FALSE;
7196
7197 static int *editor_elements = NULL;     // dynamically allocated
7198 static int num_editor_elements = 0;     // dynamically determined
7199
7200 static boolean setup_editor_cascade_never = FALSE;
7201
7202 static boolean setup_editor_el_players                  = TRUE;
7203 static boolean setup_editor_el_boulderdash              = TRUE;
7204 static boolean setup_editor_el_boulderdash_native       = TRUE;
7205 static boolean setup_editor_el_boulderdash_effects      = TRUE;
7206 static boolean setup_editor_el_emerald_mine             = TRUE;
7207 static boolean setup_editor_el_emerald_mine_club        = TRUE;
7208 static boolean setup_editor_el_more                     = TRUE;
7209 static boolean setup_editor_el_sokoban                  = TRUE;
7210 static boolean setup_editor_el_supaplex                 = TRUE;
7211 static boolean setup_editor_el_diamond_caves            = TRUE;
7212 static boolean setup_editor_el_dx_boulderdash           = TRUE;
7213 static boolean setup_editor_el_mirror_magic             = TRUE;
7214 static boolean setup_editor_el_deflektor                = TRUE;
7215 static boolean setup_editor_el_chars                    = TRUE;
7216 static boolean setup_editor_el_steel_chars              = TRUE;
7217 static boolean setup_editor_el_custom                   = TRUE;
7218 static boolean setup_editor_el_user_defined             = TRUE;
7219 static boolean setup_editor_el_dynamic                  = TRUE;
7220
7221 static int editor_hl_unused[] = { EL_EMPTY };
7222 static int *editor_hl_unused_ptr = editor_hl_unused;
7223 static int num_editor_hl_unused = 0;
7224
7225 static struct
7226 {
7227   boolean *setup_value;
7228   boolean *setup_cascade_value;
7229
7230   int **headline_list;
7231   int *headline_list_size;
7232
7233   int **element_list;
7234   int *element_list_size;
7235
7236   boolean last_setup_value;
7237 }
7238 editor_elements_info[] =
7239 {
7240   {
7241     &setup_editor_el_players,
7242     &setup_editor_cascade_never,
7243     &editor_hl_unused_ptr,              &num_editor_hl_unused,
7244     &editor_el_players_ptr,             &num_editor_el_players
7245   },
7246   {
7247     &setup_editor_el_boulderdash,
7248     &setup.editor_cascade.el_bd,
7249     &editor_hl_boulderdash_ptr,         &num_editor_hl_boulderdash,
7250     &editor_el_boulderdash_ptr,         &num_editor_el_boulderdash
7251   },
7252   {
7253     &setup_editor_el_boulderdash_native,
7254     &setup.editor_cascade.el_bd_native,
7255     &editor_hl_boulderdash_native_ptr,  &num_editor_hl_boulderdash_native,
7256     &editor_el_boulderdash_native_ptr,  &num_editor_el_boulderdash_native
7257   },
7258   {
7259     &setup_editor_el_boulderdash_effects,
7260     &setup.editor_cascade.el_bd_effects,
7261     &editor_hl_boulderdash_effects_ptr, &num_editor_hl_boulderdash_effects,
7262     &editor_el_boulderdash_effects_ptr, &num_editor_el_boulderdash_effects
7263   },
7264   {
7265     &setup_editor_el_emerald_mine,
7266     &setup.editor_cascade.el_em,
7267     &editor_hl_emerald_mine_ptr,        &num_editor_hl_emerald_mine,
7268     &editor_el_emerald_mine_ptr,        &num_editor_el_emerald_mine
7269   },
7270   {
7271     &setup_editor_el_emerald_mine_club,
7272     &setup.editor_cascade.el_emc,
7273     &editor_hl_emerald_mine_club_ptr,   &num_editor_hl_emerald_mine_club,
7274     &editor_el_emerald_mine_club_ptr,   &num_editor_el_emerald_mine_club
7275   },
7276   {
7277     &setup_editor_el_more,
7278     &setup.editor_cascade.el_rnd,
7279     &editor_hl_rnd_ptr,                 &num_editor_hl_rnd,
7280     &editor_el_rnd_ptr,                 &num_editor_el_rnd
7281   },
7282   {
7283     &setup_editor_el_sokoban,
7284     &setup.editor_cascade.el_sb,
7285     &editor_hl_sokoban_ptr,             &num_editor_hl_sokoban,
7286     &editor_el_sokoban_ptr,             &num_editor_el_sokoban
7287   },
7288   {
7289     &setup_editor_el_supaplex,
7290     &setup.editor_cascade.el_sp,
7291     &editor_hl_supaplex_ptr,            &num_editor_hl_supaplex,
7292     &editor_el_supaplex_ptr,            &num_editor_el_supaplex
7293   },
7294   {
7295     &setup_editor_el_diamond_caves,
7296     &setup.editor_cascade.el_dc,
7297     &editor_hl_diamond_caves_ptr,       &num_editor_hl_diamond_caves,
7298     &editor_el_diamond_caves_ptr,       &num_editor_el_diamond_caves
7299   },
7300   {
7301     &setup_editor_el_dx_boulderdash,
7302     &setup.editor_cascade.el_dx,
7303     &editor_hl_dx_boulderdash_ptr,      &num_editor_hl_dx_boulderdash,
7304     &editor_el_dx_boulderdash_ptr,      &num_editor_el_dx_boulderdash
7305   },
7306   {
7307     &setup_editor_el_mirror_magic,
7308     &setup.editor_cascade.el_mm,
7309     &editor_hl_mirror_magic_ptr,        &num_editor_hl_mirror_magic,
7310     &editor_el_mirror_magic_ptr,        &num_editor_el_mirror_magic
7311   },
7312   {
7313     &setup_editor_el_deflektor,
7314     &setup.editor_cascade.el_df,
7315     &editor_hl_deflektor_ptr,           &num_editor_hl_deflektor,
7316     &editor_el_deflektor_ptr,           &num_editor_el_deflektor
7317   },
7318   {
7319     &setup_editor_el_chars,
7320     &setup.editor_cascade.el_chars,
7321     &editor_hl_chars_ptr,               &num_editor_hl_chars,
7322     &editor_el_chars_ptr,               &num_editor_el_chars
7323   },
7324   {
7325     &setup_editor_el_steel_chars,
7326     &setup.editor_cascade.el_steel_chars,
7327     &editor_hl_steel_chars_ptr,         &num_editor_hl_steel_chars,
7328     &editor_el_steel_chars_ptr,         &num_editor_el_steel_chars
7329   },
7330   {
7331     &setup_editor_el_custom,
7332     &setup.editor_cascade.el_ce,
7333     &editor_hl_custom_ptr,              &num_editor_hl_custom,
7334     &editor_el_custom_ptr,              &num_editor_el_custom
7335   },
7336   {
7337     &setup_editor_el_custom,
7338     &setup.editor_cascade.el_ge,
7339     &editor_hl_group_ptr,               &num_editor_hl_group,
7340     &editor_el_group_ptr,               &num_editor_el_group
7341   },
7342   {
7343     &setup_editor_el_custom,
7344     &setup.editor_cascade.el_es,
7345     &editor_hl_empty_space_ptr,         &num_editor_hl_empty_space,
7346     &editor_el_empty_space_ptr,         &num_editor_el_empty_space
7347   },
7348   {
7349     &setup_editor_el_custom,
7350     &setup.editor_cascade.el_ref,
7351     &editor_hl_reference_ptr,           &num_editor_hl_reference,
7352     &editor_el_reference_ptr,           &num_editor_el_reference
7353   },
7354   {
7355     &setup_editor_el_user_defined,
7356     &setup.editor_cascade.el_user,
7357     &editor_hl_user_defined_ptr,        &num_editor_hl_user_defined,
7358     &editor_el_user_defined_ptr,        &num_editor_el_user_defined
7359   },
7360   {
7361     &setup_editor_el_dynamic,
7362     &setup.editor_cascade.el_dynamic,
7363     &editor_hl_dynamic_ptr,             &num_editor_hl_dynamic,
7364     &editor_el_dynamic_ptr,             &num_editor_el_dynamic,
7365   },
7366   {
7367     &use_el_empty,
7368     &use_el_empty,
7369     &editor_hl_empty_ptr,               &num_editor_hl_empty,
7370     &editor_el_empty_ptr,               &num_editor_el_empty,
7371   },
7372   {
7373     NULL,
7374     NULL,
7375     NULL,                               NULL,
7376     NULL,                               NULL
7377   }
7378 };
7379
7380 static struct XY xy_directions[] =
7381 {
7382   { -1,  0 },
7383   { +1,  0 },
7384   {  0, -1 },
7385   {  0, +1 }
7386 };
7387
7388
7389 // ----------------------------------------------------------------------------
7390 // functions
7391 // ----------------------------------------------------------------------------
7392
7393 static int getMaxInfoTextLength(void)
7394 {
7395   return (SXSIZE / getFontWidth(INFOTEXT_FONT));
7396 }
7397
7398 static int getTextWidthForGadget(char *text)
7399 {
7400   if (text == NULL)
7401     return 0;
7402
7403   return (getTextWidth(text, FONT_TEXT_1) + ED_GADGET_TEXT_DISTANCE);
7404 }
7405
7406 static int getTextWidthForDrawingArea(char *text)
7407 {
7408   if (text == NULL)
7409     return 0;
7410
7411   return (getTextWidth(text, FONT_TEXT_1) + ED_DRAWINGAREA_BORDER_SIZE);
7412 }
7413
7414 static int getRightGadgetBorder(struct GadgetInfo *gi, char *text)
7415 {
7416   return (gi->x + gi->width + getTextWidthForGadget(text));
7417 }
7418
7419 static char *getElementInfoText(int element)
7420 {
7421   char *info_text = NULL;
7422
7423   if (element < MAX_NUM_ELEMENTS)
7424   {
7425     if (strlen(element_info[element].description) > 0)
7426       info_text = element_info[element].description;
7427     else if (element_info[element].custom_description != NULL)
7428       info_text = element_info[element].custom_description;
7429     else if (element_info[element].editor_description != NULL)
7430       info_text = element_info[element].editor_description;
7431   }
7432
7433   if (info_text == NULL)
7434     info_text = INFOTEXT_UNKNOWN_ELEMENT;
7435
7436   return info_text;
7437 }
7438
7439 static char *getElementDescriptionFilenameExt(char *basename)
7440 {
7441   char *elements_subdir = ELEMENTS_DIRECTORY;
7442   static char *elements_subdir2 = NULL;
7443   static char *filename = NULL;
7444
7445   if (elements_subdir2 == NULL)
7446     elements_subdir2 = getPath2(DOCS_DIRECTORY, elements_subdir);
7447
7448   checked_free(filename);
7449
7450   // 1st try: look for element description in current level set directory
7451   filename = getPath3(getCurrentLevelDir(), elements_subdir2, basename);
7452   if (fileExists(filename))
7453     return filename;
7454
7455   free(filename);
7456
7457   // 2nd try: look for element description in the game's base directory
7458   filename = getPath3(options.docs_directory, elements_subdir, basename);
7459   if (fileExists(filename))
7460     return filename;
7461
7462   return NULL;
7463 }
7464
7465 static char *getElementDescriptionFilename(int element)
7466 {
7467   char basename[MAX_FILENAME_LEN];
7468   char *filename;
7469
7470   // 1st try: look for element description file for exactly this element
7471   sprintf(basename, "%s.txt", element_info[element].token_name);
7472   filename = getElementDescriptionFilenameExt(basename);
7473   if (filename != NULL)
7474     return filename;
7475
7476   // 2nd try: look for element description file for this element's class
7477   sprintf(basename, "%s.txt", element_info[element].class_name);
7478   filename = getElementDescriptionFilenameExt(basename);
7479   if (filename != NULL)
7480     return filename;
7481
7482   // 3rd try: look for generic fallback text file for any element
7483   filename = getElementDescriptionFilenameExt(FALLBACK_TEXT_FILENAME);
7484   if (filename != NULL)
7485     return filename;
7486
7487   return NULL;
7488 }
7489
7490 static boolean suppressBorderElement(void)
7491 {
7492   return (level.game_engine_type == GAME_ENGINE_TYPE_MM &&
7493           lev_fieldx <= MAX_ED_FIELDX &&
7494           lev_fieldy <= MAX_ED_FIELDY);
7495 }
7496
7497 static void InitDynamicEditorElementList(int **elements, int *num_elements)
7498 {
7499   boolean element_found[NUM_FILE_ELEMENTS];
7500   int i, x, y;
7501
7502   // initialize list of used elements to "not used"
7503   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
7504     element_found[i] = FALSE;
7505
7506   // find all elements used in current level
7507   for (y = 0; y < lev_fieldy; y++)
7508   {
7509     for (x = 0; x < lev_fieldx; x++)
7510     {
7511       if (Tile[x][y] >= NUM_FILE_ELEMENTS)      // should never happen
7512         continue;
7513
7514       if (IS_MM_WALL(Tile[x][y]))
7515         element_found[map_mm_wall_element(Tile[x][y])] = TRUE;
7516       else
7517         element_found[Tile[x][y]] = TRUE;
7518     }
7519   }
7520
7521   *num_elements = 0;
7522
7523   // count number of elements used in current level
7524   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
7525     if (element_found[i])
7526       (*num_elements)++;
7527
7528   // add space for up to 3 more elements for padding that may be needed
7529   *num_elements += 3;
7530
7531   // free memory for old list of elements, if needed
7532   checked_free(*elements);
7533
7534   // allocate memory for new list of elements
7535   *elements = checked_malloc(*num_elements * sizeof(int));
7536
7537   *num_elements = 0;
7538
7539   // add all elements used in current level (non-custom/group/empty elements)
7540   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
7541     if (element_found[i] && !(IS_CUSTOM_ELEMENT(i) ||
7542                               IS_GROUP_ELEMENT(i) ||
7543                               IS_EMPTY_ELEMENT(i)))
7544       (*elements)[(*num_elements)++] = i;
7545
7546   // add all elements used in current level (custom/group/empty elements)
7547   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
7548     if (element_found[i] && (IS_CUSTOM_ELEMENT(i) ||
7549                              IS_GROUP_ELEMENT(i) ||
7550                              IS_EMPTY_ELEMENT(i)))
7551       (*elements)[(*num_elements)++] = i;
7552
7553   while (*num_elements % 4)     // pad with empty elements, if needed
7554     (*elements)[(*num_elements)++] = EL_EMPTY;
7555 }
7556
7557 static void ReinitializeElementList_EnableSections(void)
7558 {
7559   // default: enable all element sections
7560
7561   setup_editor_el_players               = TRUE;
7562   setup_editor_el_boulderdash           = TRUE;
7563   setup_editor_el_boulderdash_native    = TRUE;
7564   setup_editor_el_boulderdash_effects   = TRUE;
7565   setup_editor_el_emerald_mine          = TRUE;
7566   setup_editor_el_emerald_mine_club     = TRUE;
7567   setup_editor_el_more                  = TRUE;
7568   setup_editor_el_sokoban               = TRUE;
7569   setup_editor_el_supaplex              = TRUE;
7570   setup_editor_el_diamond_caves         = TRUE;
7571   setup_editor_el_dx_boulderdash        = TRUE;
7572   setup_editor_el_mirror_magic          = TRUE;
7573   setup_editor_el_deflektor             = TRUE;
7574   setup_editor_el_chars                 = TRUE;
7575   setup_editor_el_steel_chars           = TRUE;
7576
7577   setup_editor_el_custom                = TRUE;
7578   setup_editor_el_user_defined          = TRUE;
7579   setup_editor_el_dynamic               = TRUE;
7580
7581   // now disable all element sections not to be displayed
7582
7583   if (!setup.editor.el_classic)
7584   {
7585     setup_editor_el_players             = FALSE;
7586     setup_editor_el_boulderdash         = FALSE;
7587     setup_editor_el_boulderdash_native  = FALSE;
7588     setup_editor_el_boulderdash_effects = FALSE;
7589     setup_editor_el_emerald_mine        = FALSE;
7590     setup_editor_el_emerald_mine_club   = FALSE;
7591     setup_editor_el_more                = FALSE;
7592     setup_editor_el_sokoban             = FALSE;
7593     setup_editor_el_supaplex            = FALSE;
7594     setup_editor_el_diamond_caves       = FALSE;
7595     setup_editor_el_dx_boulderdash      = FALSE;
7596     setup_editor_el_mirror_magic        = FALSE;
7597     setup_editor_el_deflektor           = FALSE;
7598     setup_editor_el_chars               = FALSE;
7599     setup_editor_el_steel_chars         = FALSE;
7600   }
7601
7602   if (!setup.editor.el_custom)
7603   {
7604     setup_editor_el_custom              = FALSE;
7605   }
7606
7607   if (!setup.editor.el_user_defined)
7608   {
7609     setup_editor_el_user_defined        = FALSE;
7610   }
7611
7612   if (!setup.editor.el_dynamic)
7613   {
7614     setup_editor_el_dynamic             = FALSE;
7615   }
7616
7617   if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
7618   {
7619     setup_editor_el_boulderdash_native  = FALSE;
7620     setup_editor_el_boulderdash_effects = FALSE;
7621     setup_editor_el_mirror_magic        = FALSE;
7622     setup_editor_el_deflektor           = FALSE;
7623   }
7624   else if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
7625   {
7626     setup_editor_el_players             = FALSE;
7627     setup_editor_el_boulderdash         = FALSE;
7628     setup_editor_el_emerald_mine        = FALSE;
7629     setup_editor_el_emerald_mine_club   = FALSE;
7630     setup_editor_el_more                = FALSE;
7631     setup_editor_el_sokoban             = FALSE;
7632     setup_editor_el_supaplex            = FALSE;
7633     setup_editor_el_diamond_caves       = FALSE;
7634     setup_editor_el_dx_boulderdash      = FALSE;
7635     setup_editor_el_mirror_magic        = FALSE;
7636     setup_editor_el_deflektor           = FALSE;
7637     setup_editor_el_chars               = FALSE;
7638     setup_editor_el_steel_chars         = FALSE;
7639
7640     setup_editor_el_custom              = FALSE;
7641   }
7642   else if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
7643   {
7644     setup_editor_el_boulderdash         = FALSE;
7645     setup_editor_el_boulderdash_native  = FALSE;
7646     setup_editor_el_boulderdash_effects = FALSE;
7647     setup_editor_el_more                = FALSE;
7648     setup_editor_el_sokoban             = FALSE;
7649     setup_editor_el_supaplex            = FALSE;
7650     setup_editor_el_diamond_caves       = FALSE;
7651     setup_editor_el_dx_boulderdash      = FALSE;
7652     setup_editor_el_mirror_magic        = FALSE;
7653     setup_editor_el_deflektor           = FALSE;
7654     setup_editor_el_steel_chars         = FALSE;
7655
7656     setup_editor_el_custom              = FALSE;
7657   }
7658   else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
7659   {
7660     setup_editor_el_players             = FALSE;
7661     setup_editor_el_boulderdash         = FALSE;
7662     setup_editor_el_boulderdash_native  = FALSE;
7663     setup_editor_el_boulderdash_effects = FALSE;
7664     setup_editor_el_emerald_mine        = FALSE;
7665     setup_editor_el_emerald_mine_club   = FALSE;
7666     setup_editor_el_more                = FALSE;
7667     setup_editor_el_sokoban             = FALSE;
7668     setup_editor_el_diamond_caves       = FALSE;
7669     setup_editor_el_dx_boulderdash      = FALSE;
7670     setup_editor_el_mirror_magic        = FALSE;
7671     setup_editor_el_deflektor           = FALSE;
7672     setup_editor_el_chars               = FALSE;
7673     setup_editor_el_steel_chars         = FALSE;
7674
7675     setup_editor_el_custom              = FALSE;
7676   }
7677   else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
7678   {
7679     setup_editor_el_players             = FALSE;
7680     setup_editor_el_boulderdash         = FALSE;
7681     setup_editor_el_boulderdash_native  = FALSE;
7682     setup_editor_el_boulderdash_effects = FALSE;
7683     setup_editor_el_emerald_mine        = FALSE;
7684     setup_editor_el_emerald_mine_club   = FALSE;
7685     setup_editor_el_more                = FALSE;
7686     setup_editor_el_sokoban             = FALSE;
7687     setup_editor_el_supaplex            = FALSE;
7688     setup_editor_el_diamond_caves       = FALSE;
7689     setup_editor_el_dx_boulderdash      = FALSE;
7690     setup_editor_el_steel_chars         = FALSE;
7691
7692     setup_editor_el_custom              = FALSE;
7693   }
7694 }
7695
7696 static void ReinitializeElementList(void)
7697 {
7698   static boolean initialization_needed = TRUE;
7699   int pos = 0;
7700   int i, j;
7701
7702   ReinitializeElementList_EnableSections();
7703
7704   if (initialization_needed)
7705   {
7706     LoadSetup_EditorCascade();          // load last editor cascade state
7707
7708     // initialize editor cascade element from saved cascade state
7709     for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
7710     {
7711       int *cascade_element = &(*editor_elements_info[i].headline_list)[0];
7712       boolean cascade_value = *editor_elements_info[i].setup_cascade_value;
7713
7714       if (IS_EDITOR_CASCADE(*cascade_element))
7715         *cascade_element =
7716           (cascade_value ? EL_CASCADE_ACTIVE(*cascade_element) :
7717            EL_CASCADE_INACTIVE(*cascade_element));
7718     }
7719
7720     initialization_needed = FALSE;
7721   }
7722
7723   checked_free(editor_elements);
7724
7725   // reload optional user defined element list for each invocation of editor
7726   LoadUserDefinedEditorElementList(&editor_el_user_defined_ptr,
7727                                    &num_editor_el_user_defined);
7728
7729   // initialize dynamic level element list for each invocation of editor
7730   InitDynamicEditorElementList(&editor_el_dynamic_ptr,
7731                                &num_editor_el_dynamic);
7732
7733   // initialize list of empty elements (used for padding, if needed)
7734   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
7735     editor_el_empty[i] = EL_EMPTY;
7736
7737   // do some sanity checks for each element from element list
7738   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
7739   {
7740     for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
7741     {
7742       int element = (*editor_elements_info[i].element_list)[j];
7743
7744       if (element >= NUM_FILE_ELEMENTS)
7745         Warn("editor element %d is runtime element", element);
7746
7747       if (strEqual(getElementInfoText(element), INFOTEXT_UNKNOWN_ELEMENT))
7748         Warn("no element description text for element %d", element);
7749     }
7750   }
7751
7752   num_editor_elements = 0;
7753   use_el_empty = FALSE;
7754
7755   // determine size of element list
7756   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
7757   {
7758     if (*editor_elements_info[i].setup_value)
7759     {
7760       boolean found_inactive_cascade = FALSE;
7761
7762       if (setup.editor.el_headlines)
7763       {
7764         // required for correct padding of palette headline buttons
7765         if (*editor_elements_info[i].headline_list_size > 0)
7766           num_editor_elements += ED_ELEMENTLIST_COLS;
7767
7768         for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
7769         {
7770           int element = (*editor_elements_info[i].headline_list)[j];
7771
7772           if (IS_EDITOR_CASCADE_INACTIVE(element))
7773             found_inactive_cascade = TRUE;
7774         }
7775       }
7776
7777       if (found_inactive_cascade)
7778         continue;
7779
7780       // required for correct padding of palette element buttons
7781       int element_list_size = *editor_elements_info[i].element_list_size;
7782       int element_rows =
7783         (element_list_size + ED_ELEMENTLIST_COLS - 1) / ED_ELEMENTLIST_COLS;
7784       int element_buttons = ED_ELEMENTLIST_COLS * element_rows;
7785
7786       num_editor_elements += element_buttons;
7787     }
7788   }
7789
7790   if (num_editor_elements < ED_NUM_ELEMENTLIST_BUTTONS)
7791   {
7792     // offer at least as many elements as element buttons exist
7793     use_el_empty = TRUE;
7794     num_editor_el_empty = ED_NUM_ELEMENTLIST_BUTTONS - num_editor_elements;
7795
7796     num_editor_elements += num_editor_el_empty;
7797   }
7798   else
7799   {
7800     num_editor_el_empty = 0;
7801   }
7802
7803   editor_elements = checked_malloc(num_editor_elements * sizeof(int));
7804
7805   // fill element list
7806   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
7807   {
7808     boolean found_inactive_cascade = FALSE;
7809
7810     if (*editor_elements_info[i].setup_value)
7811     {
7812       if (setup.editor.el_headlines)
7813       {
7814         // required for correct padding of palette headline buttons
7815         int headline_size = (*editor_elements_info[i].headline_list_size > 0 ?
7816                              ED_ELEMENTLIST_COLS : 0);
7817
7818         for (j = 0; j < headline_size; j++)
7819         {
7820           // use empty elements for padding of palette headline buttons
7821           int element = (j < *editor_elements_info[i].headline_list_size ?
7822                          (*editor_elements_info[i].headline_list)[j] :
7823                          editor_el_empty[0]);
7824
7825           editor_elements[pos++] = element;
7826
7827           if (IS_EDITOR_CASCADE_INACTIVE(element))
7828             found_inactive_cascade = TRUE;
7829         }
7830       }
7831
7832       if (found_inactive_cascade)
7833         continue;
7834
7835       // required for correct padding of palette element buttons
7836       int element_list_size = *editor_elements_info[i].element_list_size;
7837       int element_rows =
7838         (element_list_size + ED_ELEMENTLIST_COLS - 1) / ED_ELEMENTLIST_COLS;
7839       int element_buttons = ED_ELEMENTLIST_COLS * element_rows;
7840
7841       // copy all elements from element list
7842       for (j = 0; j < element_list_size; j++)
7843         editor_elements[pos++] = (*editor_elements_info[i].element_list)[j];
7844
7845       // use empty elements for padding of palette element buttons
7846       for (j = 0; j < element_buttons - element_list_size; j++)
7847         editor_elements[pos++] = editor_el_empty[0];
7848     }
7849   }
7850
7851   // (this function is also called before editor gadgets are initialized!)
7852   AdjustElementListScrollbar();
7853 }
7854
7855 void PrintEditorElementList(void)
7856 {
7857   boolean *stop = &setup_editor_el_user_defined;
7858   int i, j;
7859
7860   for (i = 0; editor_elements_info[i].setup_value != stop; i++)
7861   {
7862     int cascade_element = (*editor_elements_info[i].headline_list)[0];
7863
7864     if (IS_EDITOR_CASCADE(cascade_element))
7865     {
7866       int cascade_element_show = EL_CASCADE_INACTIVE(cascade_element);
7867       char *headline = element_info[cascade_element_show].editor_description;
7868
7869       PrintLineWithPrefix("# ", "-", 77);
7870       Print("# %s\n", headline);
7871       PrintLineWithPrefix("# ", "-", 77);
7872     }
7873
7874     for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
7875     {
7876       int element = (*editor_elements_info[i].headline_list)[j];
7877
7878       if (IS_EDITOR_CASCADE(element))
7879         element = EL_CHAR_MINUS;
7880
7881       Print("# %s\n", element_info[element].token_name);
7882     }
7883
7884     if (j > 0)
7885       Print("#\n");
7886
7887     for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
7888     {
7889       int element = (*editor_elements_info[i].element_list)[j];
7890
7891       Print("# %s\n", element_info[element].token_name);
7892     }
7893
7894     if (j > 0)
7895       Print("#\n");
7896   }
7897 }
7898
7899 static void ReinitializeElementListButtons(void)
7900 {
7901   static boolean last_setup_value_headlines = FALSE;
7902   static boolean initialization_needed = TRUE;
7903   int i;
7904
7905   if (!initialization_needed)   // check if editor element setup has changed
7906   {
7907     if (last_setup_value_headlines != setup.editor.el_headlines)
7908       initialization_needed = TRUE;
7909
7910     for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
7911       if (editor_elements_info[i].last_setup_value !=
7912           *editor_elements_info[i].setup_value)
7913         initialization_needed = TRUE;
7914   }
7915
7916   if (!initialization_needed)
7917     return;
7918
7919   FreeLevelEditorGadgets();
7920   CreateLevelEditorGadgets();
7921
7922   // store current setup values for next invocation of this function
7923   last_setup_value_headlines = setup.editor.el_headlines;
7924   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
7925     editor_elements_info[i].last_setup_value =
7926       *editor_elements_info[i].setup_value;
7927
7928   initialization_needed = FALSE;
7929 }
7930
7931 static void DrawElementBorder(int dest_x, int dest_y, int width, int height,
7932                               boolean input)
7933 {
7934   int border_graphic =
7935     (input ? IMG_EDITOR_ELEMENT_BORDER_INPUT : IMG_EDITOR_ELEMENT_BORDER);
7936   struct GraphicInfo *g = &graphic_info[border_graphic];
7937   Bitmap *src_bitmap = g->bitmap;
7938   int src_x = g->src_x;
7939   int src_y = g->src_y;
7940   int border_size = g->border_size;
7941   int border_xpos = g->width  - border_size;
7942   int border_ypos = g->height - border_size;
7943   int tilesize = ED_DRAWINGAREA_TILE_SIZE;
7944   int i;
7945
7946   BlitBitmap(src_bitmap, drawto, src_x, src_y,
7947              border_size, border_size,
7948              dest_x - border_size, dest_y - border_size);
7949   BlitBitmap(src_bitmap, drawto, src_x + border_xpos, src_y,
7950              border_size, border_size,
7951              dest_x + width, dest_y - border_size);
7952   BlitBitmap(src_bitmap, drawto, src_x, src_y + border_ypos,
7953              border_size, border_size,
7954              dest_x - border_size, dest_y + height);
7955   BlitBitmap(src_bitmap, drawto, src_x + border_xpos, src_y + border_ypos,
7956              border_size, border_size,
7957              dest_x + width, dest_y + height);
7958
7959   for (i = 0; i < width / tilesize; i++)
7960   {
7961     BlitBitmap(src_bitmap, drawto, src_x + border_size, src_y,
7962                tilesize, border_size,
7963                dest_x + i * tilesize, dest_y - border_size);
7964     BlitBitmap(src_bitmap, drawto, src_x + border_size, src_y + border_ypos,
7965                tilesize, border_size,
7966                dest_x + i * tilesize, dest_y + height);
7967   }
7968
7969   for (i = 0; i < height / tilesize; i++)
7970   {
7971     BlitBitmap(src_bitmap, drawto, src_x, src_y + border_size,
7972                border_size, tilesize,
7973                dest_x - border_size, dest_y + i * tilesize);
7974     BlitBitmap(src_bitmap, drawto, src_x + border_xpos, src_y + border_size,
7975                border_size, tilesize,
7976                dest_x + width, dest_y + i * tilesize);
7977   }
7978
7979   ClearRectangle(drawto, dest_x - 1, dest_y - 1, width + 2, height + 2);
7980 }
7981
7982 static void DrawEditorLevelBorderLine(int x, int y, int xsize, int ysize)
7983 {
7984   int xsize_tile = MAX(ed_tilesize, xsize);
7985   int ysize_tile = MAX(ed_tilesize, ysize);
7986   int xsize_full = xsize + 1;
7987   int ysize_full = ysize + 1;
7988   int xsize_thin = (xsize < ed_tilesize ? 1 : xsize);
7989   int ysize_thin = (ysize < ed_tilesize ? 1 : ysize);
7990   Pixel line_color = getTabulatorBarColor();
7991
7992   if (line_color == BLACK_PIXEL)                // black => transparent
7993     return;
7994
7995   FillRectangle(drawto, SX + x, SY + y, xsize_tile, ysize_tile, BLACK_PIXEL);
7996   FillRectangle(drawto, SX + x, SY + y, xsize_full, ysize_full, line_color);
7997   FillRectangle(drawto, SX + x, SY + y, xsize_thin, ysize_thin, BLACK_PIXEL);
7998 }
7999
8000 static void DrawEditorLevelBorderLinesIfNeeded(void)
8001 {
8002   int xsize = lev_fieldx * ed_tilesize;
8003   int ysize = lev_fieldy * ed_tilesize;
8004   int line_size = getTabulatorBarHeight();
8005
8006   if (!suppressBorderElement())
8007     return;
8008
8009   // draw little border line around editable level playfield
8010
8011   if (xsize < SXSIZE)
8012     DrawEditorLevelBorderLine(xsize, 0, line_size, ysize);
8013
8014   if (ysize < SYSIZE)
8015     DrawEditorLevelBorderLine(0, ysize, xsize, line_size);
8016
8017   if (xsize < SXSIZE && ysize < SYSIZE)
8018     DrawEditorLevelBorderLine(xsize, ysize, line_size, line_size);
8019 }
8020
8021 static void DrawEditorElement(int x, int y, int element)
8022 {
8023   DrawSizedElement(x, y, element, ed_tilesize);
8024 }
8025
8026 static void DrawEditorElementThruMask(int x, int y, int element)
8027 {
8028   DrawSizedElementThruMask(x, y, element, ed_tilesize);
8029 }
8030
8031 static void DrawEditorElementOrWall(int x, int y, int scroll_x, int scroll_y)
8032 {
8033   DrawSizedElementOrWall(x, y, scroll_x, scroll_y, ed_tilesize);
8034 }
8035
8036 static void DrawEditorLevel(int size_x, int size_y, int scroll_x, int scroll_y)
8037 {
8038   DrawSizedLevel(size_x, size_y, scroll_x, scroll_y, ed_tilesize);
8039   DrawEditorLevelBorderLinesIfNeeded();
8040 }
8041
8042 static void DrawDrawingArea(int id)
8043 {
8044   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
8045   int x, y;
8046
8047   int *value = drawingarea_info[id].value;
8048   int area_xsize = drawingarea_info[id].area_xsize;
8049   int area_ysize = drawingarea_info[id].area_ysize;
8050   int tilesize = ED_DRAWINGAREA_TILE_SIZE;
8051
8052   for (x = 0; x < area_xsize; x++)
8053   {
8054     for (y = 0; y < area_ysize; y++)
8055     {
8056       int element = value[x * area_ysize + y];
8057       int graphic;
8058       int frame;
8059
8060       getEditorGraphicAndFrame(element, &graphic, &frame, TRUE);
8061
8062       DrawSizedGraphicExt(drawto,
8063                           gi->x + x * tilesize,
8064                           gi->y + y * tilesize,
8065                           graphic, frame, tilesize);
8066     }
8067   }
8068 }
8069
8070 static void ScrollEditorLevel(int from_x, int from_y, int scroll)
8071 {
8072   int x, y;
8073   int dx = (scroll == ED_SCROLL_LEFT ? -1 : scroll == ED_SCROLL_RIGHT ? 1 : 0);
8074   int dy = (scroll == ED_SCROLL_UP   ? -1 : scroll == ED_SCROLL_DOWN  ? 1 : 0);
8075
8076   BlitBitmap(drawto, drawto,
8077              SX + (dx == -1 ? ed_tilesize : 0),
8078              SY + (dy == -1 ? ed_tilesize : 0),
8079              (ed_fieldx * ed_tilesize) - (dx != 0 ? ed_tilesize : 0),
8080              (ed_fieldy * ed_tilesize) - (dy != 0 ? ed_tilesize : 0),
8081              SX + (dx == +1 ? ed_tilesize : 0),
8082              SY + (dy == +1 ? ed_tilesize : 0));
8083
8084   if (dx)
8085   {
8086     x = (dx == 1 ? 0 : ed_fieldx - 1);
8087     for (y = 0; y < ed_fieldy; y++)
8088       DrawEditorElementOrWall(x, y, from_x, from_y);
8089   }
8090   else if (dy)
8091   {
8092     y = (dy == 1 ? 0 : ed_fieldy - 1);
8093     for (x = 0; x < ed_fieldx; x++)
8094       DrawEditorElementOrWall(x, y, from_x, from_y);
8095   }
8096
8097   redraw_mask |= REDRAW_FIELD;
8098   BackToFront();
8099 }
8100
8101 static void getEditorGraphicAndFrame(int element, int *graphic, int *frame, boolean use_editor_gfx)
8102 {
8103   if (use_editor_gfx)
8104   {
8105     *graphic = el2edimg(element);
8106     *frame = 0;
8107   }
8108   else
8109   {
8110     *graphic = el2img(element);
8111     *frame = (ANIM_MODE(*graphic) == ANIM_CE_VALUE ?
8112               custom_element.ce_value_fixed_initial :
8113               ANIM_MODE(*graphic) == ANIM_CE_SCORE ?
8114               custom_element.collect_score_initial : FrameCounter);
8115   }
8116
8117   if (*graphic == IMG_UNKNOWN)
8118   {
8119     // no graphic defined -- if BD style, try to get runtime ("effect") element graphics
8120     // (normal BD style elements have graphics, but runtime ("effects") elements do not)
8121     int element_bd = map_element_RND_to_BD_cave(element);
8122
8123     if (element_bd != O_UNKNOWN)
8124     {
8125       struct GraphicInfo_BD *g_bd = &graphic_info_bd_object[element_bd][0];
8126
8127       *graphic = g_bd->graphic;
8128       *frame   = g_bd->frame;
8129     }
8130   }
8131 }
8132
8133 static void getEditorGraphicSource(int element, int tile_size, Bitmap **bitmap,
8134                                    int *x, int *y)
8135 {
8136   int graphic;
8137   int frame;
8138
8139   getEditorGraphicAndFrame(element, &graphic, &frame, TRUE);
8140
8141   getSizedGraphicSource(graphic, frame, tile_size, bitmap, x, y);
8142 }
8143
8144 static void CreateControlButtons(void)
8145 {
8146   struct GadgetInfo *gi;
8147   int i;
8148
8149   // create toolbox buttons
8150   for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
8151   {
8152     int type_id = controlbutton_info[i].gadget_id;      // same as gadget ID here
8153     int id = controlbutton_info[i].gadget_id;
8154     int type = controlbutton_info[i].gadget_type;
8155     int graphic = controlbutton_info[i].graphic;
8156     struct XYTileSize *pos = controlbutton_info[i].pos;
8157     struct GraphicInfo *gd = &graphic_info[graphic];
8158     Bitmap *deco_bitmap = NULL;
8159     int deco_x = 0, deco_y = 0, deco_xpos = 0, deco_ypos = 0;
8160     int tile_size = 0, deco_shift = 0;
8161     boolean deco_masked = FALSE;
8162     int gd_x1 = gd->src_x;
8163     int gd_y1 = gd->src_y;
8164     int gd_x2 = gd->src_x + gd->pressed_xoffset;
8165     int gd_y2 = gd->src_y + gd->pressed_yoffset;
8166     int gd_x1a = gd->src_x + gd->active_xoffset;
8167     int gd_y1a = gd->src_y + gd->active_yoffset;
8168     int gd_x2a = gd->src_x + gd->active_xoffset + gd->pressed_xoffset;
8169     int gd_y2a = gd->src_y + gd->active_yoffset + gd->pressed_yoffset;
8170     int x = pos->x;
8171     int y = pos->y;
8172     unsigned int event_mask;
8173     int radio_button_nr = RADIO_NR_NONE;
8174     boolean checked = FALSE;
8175
8176     if (type_id != i)
8177       Fail("'controlbutton_info' structure corrupted at index %d -- please fix", i);
8178
8179     if (type == GD_TYPE_RADIO_BUTTON)
8180     {
8181       event_mask = GD_EVENT_PRESSED;
8182       radio_button_nr = RADIO_NR_DRAWING_TOOLBOX;
8183
8184       if (id == drawing_function)
8185         checked = TRUE;
8186     }
8187     else
8188     {
8189       if (id == GADGET_ID_WRAP_LEFT ||
8190           id == GADGET_ID_WRAP_RIGHT ||
8191           id == GADGET_ID_WRAP_UP ||
8192           id == GADGET_ID_WRAP_DOWN)
8193         event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8194       else
8195         event_mask = GD_EVENT_RELEASED;
8196     }
8197
8198     if (id == GADGET_ID_PROPERTIES ||
8199         id == GADGET_ID_PALETTE)
8200     {
8201       x += DX;
8202       y += DY;
8203     }
8204     else if (id == GADGET_ID_ELEMENT_LEFT ||
8205              id == GADGET_ID_ELEMENT_MIDDLE ||
8206              id == GADGET_ID_ELEMENT_RIGHT)
8207     {
8208       x += DX;
8209       y += DY;
8210
8211       int element = (id == GADGET_ID_ELEMENT_LEFT   ? new_element1 :
8212                      id == GADGET_ID_ELEMENT_MIDDLE ? new_element2 :
8213                      id == GADGET_ID_ELEMENT_RIGHT  ? new_element3 : EL_EMPTY);
8214
8215       tile_size = BUTTON_TILE_SIZE(id == GADGET_ID_ELEMENT_LEFT ?
8216                                    editor.button.element_left.tile_size :
8217                                    id == GADGET_ID_ELEMENT_MIDDLE ?
8218                                    editor.button.element_middle.tile_size :
8219                                    id == GADGET_ID_ELEMENT_RIGHT ?
8220                                    editor.button.element_right.tile_size : 0);
8221
8222       // make sure that decoration does not overlap gadget border
8223       tile_size = MIN(tile_size, MIN(gd->width, gd->height));
8224
8225       getEditorGraphicSource(element, tile_size, &deco_bitmap, &deco_x,&deco_y);
8226
8227       deco_xpos = (gd->width  - tile_size) / 2;
8228       deco_ypos = (gd->height - tile_size) / 2;
8229       deco_shift = 1;
8230       deco_masked = gd->draw_masked;
8231     }
8232     else
8233     {
8234       x += EX;
8235       y += EY;
8236     }
8237
8238     gi = CreateGadget(GDI_CUSTOM_ID, id,
8239                       GDI_CUSTOM_TYPE_ID, type_id,
8240                       GDI_IMAGE_ID, graphic,
8241                       GDI_INFO_TEXT, controlbutton_info[i].infotext,
8242                       GDI_X, x,
8243                       GDI_Y, y,
8244                       GDI_WIDTH, gd->width,
8245                       GDI_HEIGHT, gd->height,
8246                       GDI_TYPE, type,
8247                       GDI_STATE, GD_BUTTON_UNPRESSED,
8248                       GDI_RADIO_NR, radio_button_nr,
8249                       GDI_CHECKED, checked,
8250                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8251                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8252                       GDI_ALT_DESIGN_UNPRESSED, gd->bitmap, gd_x1a, gd_y1a,
8253                       GDI_ALT_DESIGN_PRESSED, gd->bitmap, gd_x2a, gd_y2a,
8254                       GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
8255                       GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
8256                       GDI_DECORATION_SIZE, tile_size, tile_size,
8257                       GDI_DECORATION_SHIFTING, deco_shift, deco_shift,
8258                       GDI_DECORATION_MASKED, deco_masked,
8259                       GDI_EVENT_MASK, event_mask,
8260                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8261                       GDI_CALLBACK_ACTION, HandleControlButtons,
8262                       GDI_END);
8263
8264     if (gi == NULL)
8265       Fail("cannot create gadget");
8266
8267     level_editor_gadget[id] = gi;
8268   }
8269
8270   // these values are not constant, but can change at runtime
8271   scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_UP].x    = ED_SCROLL_UP_XPOS;
8272   scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_UP].y    = ED_SCROLL_UP_YPOS;
8273   scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_DOWN].x  = ED_SCROLL_DOWN_XPOS;
8274   scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_DOWN].y  = ED_SCROLL_DOWN_YPOS;
8275   scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_LEFT].x  = ED_SCROLL_LEFT_XPOS;
8276   scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_LEFT].y  = ED_SCROLL_LEFT_YPOS;
8277   scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_RIGHT].x = ED_SCROLL_RIGHT_XPOS;
8278   scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_RIGHT].y = ED_SCROLL_RIGHT_YPOS;
8279   scrollbutton_pos[ED_SCROLLBUTTON_ID_LIST_UP].x    = ED_SCROLL2_UP_XPOS;
8280   scrollbutton_pos[ED_SCROLLBUTTON_ID_LIST_UP].y    = ED_SCROLL2_UP_YPOS;
8281   scrollbutton_pos[ED_SCROLLBUTTON_ID_LIST_DOWN].x  = ED_SCROLL2_DOWN_XPOS;
8282   scrollbutton_pos[ED_SCROLLBUTTON_ID_LIST_DOWN].y  = ED_SCROLL2_DOWN_YPOS;
8283
8284   // create buttons for scrolling of drawing area and element list
8285   for (i = 0; i < ED_NUM_SCROLLBUTTONS; i++)
8286   {
8287     int id = scrollbutton_info[i].gadget_id;
8288     int type_id = scrollbutton_info[i].gadget_type_id;
8289     int graphic = scrollbutton_info[i].graphic;
8290     struct GraphicInfo *gd = &graphic_info[graphic];
8291     Bitmap *gd_bitmap = gd->bitmap;
8292     int gd_x1 = gd->src_x;
8293     int gd_y1 = gd->src_y;
8294     int gd_x2 = gd->src_x + gd->pressed_xoffset;
8295     int gd_y2 = gd->src_y + gd->pressed_yoffset;
8296     int width  = gd->width;
8297     int height = gd->height;
8298     int x = scrollbutton_pos[i].x;
8299     int y = scrollbutton_pos[i].y;
8300     unsigned int event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8301
8302     if (type_id != i)
8303       Fail("'scrollbutton_info' structure corrupted at index %d -- please fix", i);
8304
8305     if (id == GADGET_ID_SCROLL_LIST_UP ||
8306         id == GADGET_ID_SCROLL_LIST_DOWN)
8307     {
8308       x += PX;
8309       y += PY;
8310     }
8311     else
8312     {
8313       x += SX;
8314       y += SY;
8315     }
8316
8317     gi = CreateGadget(GDI_CUSTOM_ID, id,
8318                       GDI_CUSTOM_TYPE_ID, type_id,
8319                       GDI_IMAGE_ID, graphic,
8320                       GDI_INFO_TEXT, scrollbutton_info[i].infotext,
8321                       GDI_X, x,
8322                       GDI_Y, y,
8323                       GDI_WIDTH, width,
8324                       GDI_HEIGHT, height,
8325                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8326                       GDI_STATE, GD_BUTTON_UNPRESSED,
8327                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
8328                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
8329                       GDI_EVENT_MASK, event_mask,
8330                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8331                       GDI_CALLBACK_ACTION, HandleControlButtons,
8332                       GDI_END);
8333
8334     if (gi == NULL)
8335       Fail("cannot create gadget");
8336
8337     level_editor_gadget[id] = gi;
8338   }
8339
8340   // create buttons for element list
8341   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
8342   {
8343     int type_id = i;
8344     int id = GADGET_ID_ELEMENTLIST_FIRST + i;
8345     int graphic = IMG_EDITOR_PALETTE_BUTTON;
8346     struct GraphicInfo *gd = &graphic_info[graphic];
8347     Bitmap *gd_bitmap = gd->bitmap;
8348     Bitmap *deco_bitmap;
8349     int deco_x, deco_y, deco_xpos, deco_ypos;
8350     int gd_x1 = gd->src_x;
8351     int gd_y1 = gd->src_y;
8352     int gd_x2 = gd->src_x + gd->pressed_xoffset;
8353     int gd_y2 = gd->src_y + gd->pressed_yoffset;
8354     int xx = i % ED_ELEMENTLIST_BUTTONS_HORIZ;
8355     int yy = i / ED_ELEMENTLIST_BUTTONS_HORIZ;
8356     int x = PX + ED_ELEMENTLIST_XPOS + xx * gd->width;
8357     int y = PY + ED_ELEMENTLIST_YPOS + yy * gd->height;
8358     int element = editor_elements[i];
8359     int tile_size = BUTTON_TILE_SIZE(editor.palette.tile_size);
8360     unsigned int event_mask = GD_EVENT_RELEASED;
8361
8362     getEditorGraphicSource(element, tile_size, &deco_bitmap, &deco_x, &deco_y);
8363
8364     deco_xpos = (gd->width  - tile_size) / 2;
8365     deco_ypos = (gd->height - tile_size) / 2;
8366
8367     gi = CreateGadget(GDI_CUSTOM_ID, id,
8368                       GDI_CUSTOM_TYPE_ID, type_id,
8369                       GDI_IMAGE_ID, graphic,
8370                       GDI_INFO_TEXT, getElementInfoText(element),
8371                       GDI_X, x,
8372                       GDI_Y, y,
8373                       GDI_WIDTH, gd->width,
8374                       GDI_HEIGHT, gd->height,
8375                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8376                       GDI_STATE, GD_BUTTON_UNPRESSED,
8377                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
8378                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
8379                       GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
8380                       GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
8381                       GDI_DECORATION_SIZE, tile_size, tile_size,
8382                       GDI_DECORATION_SHIFTING, 1, 1,
8383                       GDI_EVENT_MASK, event_mask,
8384                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8385                       GDI_CALLBACK_ACTION, HandleControlButtons,
8386                       GDI_END);
8387
8388     if (gi == NULL)
8389       Fail("cannot create gadget");
8390
8391     level_editor_gadget[id] = gi;
8392   }
8393 }
8394
8395 static void CreateCounterButtons(void)
8396 {
8397   int max_infotext_len = getMaxInfoTextLength();
8398   int i;
8399
8400   for (i = 0; i < ED_NUM_COUNTERBUTTONS; i++)
8401   {
8402     int type_id = counterbutton_info[i].gadget_type_id;
8403     int x = SX + ED_SETTINGS_X(counterbutton_info[i].x); // down count button
8404     int y = SY + ED_SETTINGS_Y(counterbutton_info[i].y);
8405     int j;
8406
8407     if (type_id != i)
8408       Fail("'counterbutton_info' structure corrupted at index %d -- please fix", i);
8409
8410     // determine horizontal position to the right of specified gadget
8411     if (counterbutton_info[i].gadget_id_align != GADGET_ID_NONE)
8412       x = (right_gadget_border[counterbutton_info[i].gadget_id_align] +
8413            ED_GADGET_TEXT_DISTANCE);
8414
8415     // determine horizontal offset for leading text
8416     if (counterbutton_info[i].text_left != NULL)
8417       x += getTextWidthForGadget(counterbutton_info[i].text_left);
8418
8419     for (j = 0; j < 2; j++)
8420     {
8421       struct GadgetInfo *gi;
8422       int id = (j == 0 ?
8423                 counterbutton_info[i].gadget_id_down :
8424                 counterbutton_info[i].gadget_id_up);
8425       int graphic;
8426       struct GraphicInfo *gd;
8427       int gd_x1, gd_x2, gd_y1, gd_y2;
8428       unsigned int event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
8429       char infotext[max_infotext_len + 1];
8430
8431       if (i == ED_COUNTER_ID_SELECT_LEVEL)
8432       {
8433         graphic = (j == 0 ?
8434                    IMG_GFX_EDITOR_BUTTON_PREV_LEVEL :
8435                    IMG_GFX_EDITOR_BUTTON_NEXT_LEVEL);
8436
8437         event_mask |= GD_EVENT_RELEASED;
8438
8439         if (j == 0)
8440         {
8441           x = DX + editor.button.prev_level.x;
8442           y = DY + editor.button.prev_level.y;
8443         }
8444         else
8445         {
8446           x = DX + editor.button.next_level.x;
8447           y = DY + editor.button.next_level.y;
8448         }
8449       }
8450       else
8451       {
8452         graphic = (j == 0 ?
8453                    IMG_EDITOR_COUNTER_DOWN :
8454                    IMG_EDITOR_COUNTER_UP);
8455       }
8456
8457       gd = &graphic_info[graphic];
8458
8459       gd_x1 = gd->src_x;
8460       gd_y1 = gd->src_y;
8461       gd_x2 = gd->src_x + gd->pressed_xoffset;
8462       gd_y2 = gd->src_y + gd->pressed_yoffset;
8463
8464       sprintf(infotext, "%s counter value by 1, 5 or 10",
8465               (j == 0 ? "Decrease" : "Increase"));
8466
8467       gi = CreateGadget(GDI_CUSTOM_ID, id,
8468                         GDI_CUSTOM_TYPE_ID, type_id,
8469                         GDI_IMAGE_ID, graphic,
8470                         GDI_INFO_TEXT, infotext,
8471                         GDI_X, x,
8472                         GDI_Y, y,
8473                         GDI_WIDTH, gd->width,
8474                         GDI_HEIGHT, gd->height,
8475                         GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8476                         GDI_STATE, GD_BUTTON_UNPRESSED,
8477                         GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8478                         GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8479                         GDI_EVENT_MASK, event_mask,
8480                         GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8481                         GDI_CALLBACK_ACTION, HandleCounterButtons,
8482                         GDI_END);
8483
8484       if (gi == NULL)
8485         Fail("cannot create gadget");
8486
8487       level_editor_gadget[id] = gi;
8488       right_gadget_border[id] =
8489         getRightGadgetBorder(gi, counterbutton_info[i].text_right);
8490
8491       x += gi->width + ED_GADGET_SMALL_DISTANCE;        // text count button
8492
8493       if (j == 0)
8494       {
8495         int font_type = FONT_INPUT_1;
8496         int font_type_active = FONT_INPUT_1_ACTIVE;
8497
8498         id = counterbutton_info[i].gadget_id_text;
8499
8500         event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8501
8502         if (i == ED_COUNTER_ID_SELECT_LEVEL)
8503         {
8504           graphic = IMG_GFX_EDITOR_INPUT_LEVEL_NUMBER;
8505
8506           font_type = FONT_LEVEL_NUMBER;
8507           font_type_active = FONT_LEVEL_NUMBER_ACTIVE;
8508
8509           x = DX + editor.input.level_number.x;
8510           y = DY + editor.input.level_number.y;
8511         }
8512         else
8513         {
8514           graphic = IMG_EDITOR_COUNTER_INPUT;
8515         }
8516
8517         gd = &graphic_info[graphic];
8518
8519         gd_x1 = gd->src_x;
8520         gd_y1 = gd->src_y;
8521         gd_x2 = gd->src_x + gd->active_xoffset;
8522         gd_y2 = gd->src_y + gd->active_yoffset;
8523
8524         gi = CreateGadget(GDI_CUSTOM_ID, id,
8525                           GDI_CUSTOM_TYPE_ID, type_id,
8526                           GDI_IMAGE_ID, graphic,
8527                           GDI_INFO_TEXT, "Enter counter value",
8528                           GDI_X, x,
8529                           GDI_Y, y,
8530                           GDI_TYPE, GD_TYPE_TEXT_INPUT_NUMERIC,
8531                           GDI_NUMBER_VALUE, 0,
8532                           GDI_NUMBER_MIN, counterbutton_info[i].min_value,
8533                           GDI_NUMBER_MAX, counterbutton_info[i].max_value,
8534                           GDI_TEXT_SIZE, 3,     // minimal counter text size
8535                           GDI_TEXT_FONT, font_type,
8536                           GDI_TEXT_FONT_ACTIVE, font_type_active,
8537                           GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8538                           GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8539                           GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8540                           GDI_DESIGN_WIDTH, gd->width,
8541                           GDI_EVENT_MASK, event_mask,
8542                           GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8543                           GDI_CALLBACK_ACTION, HandleCounterButtons,
8544                           GDI_END);
8545
8546         if (gi == NULL)
8547           Fail("cannot create gadget");
8548
8549         level_editor_gadget[id] = gi;
8550         right_gadget_border[id] =
8551           getRightGadgetBorder(gi, counterbutton_info[i].text_right);
8552
8553         x += gi->width + ED_GADGET_SMALL_DISTANCE;      // up count button
8554       }
8555     }
8556   }
8557 }
8558
8559 static void CreateDrawingAreas(void)
8560 {
8561   int i;
8562
8563   // these values are not constant, but can change at runtime
8564   drawingarea_info[ED_DRAWING_ID_DRAWING_LEVEL].area_xsize = MAX_ED_FIELDX;
8565   drawingarea_info[ED_DRAWING_ID_DRAWING_LEVEL].area_ysize = MAX_ED_FIELDY;
8566
8567   for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
8568   {
8569     struct GadgetInfo *gi;
8570     int id = drawingarea_info[i].gadget_id;
8571     int type_id = drawingarea_info[i].gadget_type_id;
8572     int x = SX + ED_AREA_SETTINGS_X(drawingarea_info[i]);
8573     int y = SY + ED_AREA_SETTINGS_Y(drawingarea_info[i]);
8574     int area_xsize = drawingarea_info[i].area_xsize;
8575     int area_ysize = drawingarea_info[i].area_ysize;
8576     int item_size = (id == GADGET_ID_DRAWING_LEVEL ?
8577                      ed_tilesize : ED_DRAWINGAREA_TILE_SIZE);
8578     unsigned int event_mask =
8579       GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING |
8580       GD_EVENT_OFF_BORDERS | GD_EVENT_PIXEL_PRECISE;
8581
8582     if (type_id != i)
8583       Fail("'drawingarea_info' structure corrupted at index %d -- please fix", i);
8584
8585     // determine horizontal position to the right of specified gadget
8586     if (drawingarea_info[i].gadget_id_align != GADGET_ID_NONE)
8587       x = (right_gadget_border[drawingarea_info[i].gadget_id_align] +
8588            ED_DRAWINGAREA_TEXT_DISTANCE);
8589
8590     // determine horizontal offset for leading text
8591     if (drawingarea_info[i].text_left != NULL)
8592       x += getTextWidthForDrawingArea(drawingarea_info[i].text_left);
8593
8594     gi = CreateGadget(GDI_CUSTOM_ID, id,
8595                       GDI_CUSTOM_TYPE_ID, type_id,
8596                       GDI_X, x,
8597                       GDI_Y, y,
8598                       GDI_TYPE, GD_TYPE_DRAWING_AREA,
8599                       GDI_AREA_SIZE, area_xsize, area_ysize,
8600                       GDI_ITEM_SIZE, item_size, item_size,
8601                       GDI_EVENT_MASK, event_mask,
8602                       GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
8603                       GDI_CALLBACK_ACTION, HandleDrawingAreas,
8604                       GDI_END);
8605
8606     if (gi == NULL)
8607       Fail("cannot create gadget");
8608
8609     level_editor_gadget[id] = gi;
8610     right_gadget_border[id] =
8611       getRightGadgetBorder(gi, drawingarea_info[i].text_right);
8612   }
8613 }
8614
8615 static void CreateTextInputGadgets(void)
8616 {
8617   struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_TEXT];
8618   int max_infotext_len = getMaxInfoTextLength();
8619   int i;
8620
8621   for (i = 0; i < ED_NUM_TEXTINPUT; i++)
8622   {
8623     int gd_x1 = gd->src_x;
8624     int gd_y1 = gd->src_y;
8625     int gd_x2 = gd->src_x + gd->active_xoffset;
8626     int gd_y2 = gd->src_y + gd->active_yoffset;
8627     struct GadgetInfo *gi;
8628     unsigned int event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8629     char infotext[MAX_OUTPUT_LINESIZE + 1];
8630     int id = textinput_info[i].gadget_id;
8631     int type_id = textinput_info[i].gadget_type_id;
8632     int x, y;
8633
8634     if (type_id != i)
8635       Fail("'textinput_info' structure corrupted at index %d -- please fix", i);
8636
8637     if (i == ED_TEXTINPUT_ID_ELEMENT_NAME)
8638     {
8639       int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
8640       int border_size = gd->border_size;
8641       int font_nr = FONT_INPUT_1;
8642       int font_height = getFontHeight(font_nr);
8643       int xoffset = element_border + TILEX + element_border + 3 * border_size;
8644       int yoffset = element_border + (TILEY - font_height) / 2;
8645
8646       x = (editor.settings.element_name.x != -1 ?
8647            editor.settings.element_name.x :
8648            editor.settings.element_graphic.x + xoffset) - border_size;
8649       y = (editor.settings.element_name.y != -1 ?
8650            editor.settings.element_name.y :
8651            editor.settings.element_graphic.y + yoffset) - border_size;
8652     }
8653     else
8654     {
8655       x = ED_SETTINGS_X(textinput_info[i].x);
8656       y = ED_SETTINGS_Y(textinput_info[i].y);
8657     }
8658
8659     // determine horizontal offset for leading text
8660     if (textinput_info[i].text_left != NULL)
8661       x += getTextWidthForGadget(textinput_info[i].text_left);
8662
8663     sprintf(infotext, "%s", textinput_info[i].infotext);
8664     infotext[max_infotext_len] = '\0';
8665
8666     gi = CreateGadget(GDI_CUSTOM_ID, id,
8667                       GDI_CUSTOM_TYPE_ID, type_id,
8668                       GDI_INFO_TEXT, infotext,
8669                       GDI_X, SX + x,
8670                       GDI_Y, SY + y,
8671                       GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
8672                       GDI_TEXT_VALUE, textinput_info[i].value,
8673                       GDI_TEXT_SIZE, textinput_info[i].size,
8674                       GDI_TEXT_FONT, FONT_INPUT_1,
8675                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
8676                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8677                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8678                       GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8679                       GDI_DESIGN_WIDTH, gd->width,
8680                       GDI_EVENT_MASK, event_mask,
8681                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8682                       GDI_CALLBACK_ACTION, HandleTextInputGadgets,
8683                       GDI_END);
8684
8685     if (gi == NULL)
8686       Fail("cannot create gadget");
8687
8688     level_editor_gadget[id] = gi;
8689   }
8690 }
8691
8692 static void CreateTextAreaGadgets(void)
8693 {
8694   int max_infotext_len = getMaxInfoTextLength();
8695   int i;
8696
8697   for (i = 0; i < ED_NUM_TEXTAREAS; i++)
8698   {
8699     struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_TEXTAREA];
8700     int gd_x1 = gd->src_x;
8701     int gd_y1 = gd->src_y;
8702     int gd_x2 = gd->src_x + gd->active_xoffset;
8703     int gd_y2 = gd->src_y + gd->active_yoffset;
8704     struct GadgetInfo *gi;
8705     unsigned int event_mask = GD_EVENT_TEXT_LEAVING;
8706     char infotext[MAX_OUTPUT_LINESIZE + 1];
8707     int id = textarea_info[i].gadget_id;
8708     int type_id = textarea_info[i].gadget_type_id;
8709     int area_xsize = textarea_info[i].xsize;
8710     int area_ysize = textarea_info[i].ysize;
8711
8712     if (type_id != i)
8713       Fail("'textarea_info' structure corrupted at index %d -- please fix", i);
8714
8715     sprintf(infotext, "Enter %s", textarea_info[i].infotext);
8716     infotext[max_infotext_len] = '\0';
8717
8718     gi = CreateGadget(GDI_CUSTOM_ID, id,
8719                       GDI_CUSTOM_TYPE_ID, type_id,
8720                       GDI_INFO_TEXT, infotext,
8721                       GDI_X, SX + ED_SETTINGS_X(textarea_info[i].x),
8722                       GDI_Y, SY + ED_SETTINGS_Y(textarea_info[i].y),
8723                       GDI_TYPE, GD_TYPE_TEXT_AREA,
8724                       GDI_AREA_SIZE, area_xsize, area_ysize,
8725                       GDI_TEXT_FONT, FONT_INPUT_1,
8726                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
8727                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8728                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8729                       GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8730                       GDI_DESIGN_WIDTH, gd->width,
8731                       GDI_EVENT_MASK, event_mask,
8732                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8733                       GDI_CALLBACK_ACTION, HandleTextAreaGadgets,
8734                       GDI_END);
8735
8736     if (gi == NULL)
8737       Fail("cannot create gadget");
8738
8739     level_editor_gadget[id] = gi;
8740   }
8741 }
8742
8743 static void CreateSelectboxGadgets(void)
8744 {
8745   int max_infotext_len = getMaxInfoTextLength();
8746
8747   int i, j;
8748
8749   for (i = 0; i < ED_NUM_SELECTBOX; i++)
8750   {
8751     struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_SELECTBOX_INPUT];
8752     struct GraphicInfo *gd2 = &graphic_info[IMG_EDITOR_SELECTBOX_BUTTON];
8753     int gd_x1 = gd->src_x;
8754     int gd_y1 = gd->src_y;
8755     int gd_x2 = gd->src_x + gd->active_xoffset;
8756     int gd_y2 = gd->src_y + gd->active_yoffset;
8757     int selectbox_button_xsize = gd2->width;
8758     struct GadgetInfo *gi;
8759     char infotext[MAX_OUTPUT_LINESIZE + 1];
8760     int id = selectbox_info[i].gadget_id;
8761     int type_id = selectbox_info[i].gadget_type_id;
8762     int x = SX + ED_SETTINGS_X(selectbox_info[i].x);
8763     int y = SY + ED_SETTINGS_Y(selectbox_info[i].y);
8764     unsigned int event_mask =
8765       GD_EVENT_RELEASED | GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
8766
8767     if (type_id != i)
8768       Fail("'selectbox_info' structure corrupted at index %d -- please fix", i);
8769
8770     if (selectbox_info[i].size == -1)   // dynamically determine size
8771     {
8772       // (we cannot use -1 for uninitialized values if we directly compare
8773       // with results from strlen(), because the '<' and '>' operation will
8774       // implicitely cast -1 to an unsigned integer value!)
8775       selectbox_info[i].size = 0;
8776
8777       for (j = 0; selectbox_info[i].options[j].text != NULL; j++)
8778         if (strlen(selectbox_info[i].options[j].text) > selectbox_info[i].size)
8779           selectbox_info[i].size = strlen(selectbox_info[i].options[j].text);
8780
8781       selectbox_info[i].size++;         // add one character empty space
8782     }
8783
8784     // determine horizontal position to the right of specified gadget
8785     if (selectbox_info[i].gadget_id_align != GADGET_ID_NONE)
8786       x = (right_gadget_border[selectbox_info[i].gadget_id_align] +
8787            ED_GADGET_TEXT_DISTANCE);
8788
8789     // determine horizontal offset for leading text
8790     if (selectbox_info[i].text_left != NULL)
8791       x += getTextWidthForGadget(selectbox_info[i].text_left);
8792
8793     sprintf(infotext, "%s", selectbox_info[i].infotext);
8794     infotext[max_infotext_len] = '\0';
8795
8796     gi = CreateGadget(GDI_CUSTOM_ID, id,
8797                       GDI_CUSTOM_TYPE_ID, type_id,
8798                       GDI_INFO_TEXT, infotext,
8799                       GDI_X, x,
8800                       GDI_Y, y,
8801                       GDI_TYPE, GD_TYPE_SELECTBOX,
8802                       GDI_SELECTBOX_OPTIONS, selectbox_info[i].options,
8803                       GDI_SELECTBOX_CHAR_UNSELECTABLE, '[',
8804                       GDI_TEXT_SIZE, selectbox_info[i].size,
8805                       GDI_TEXT_FONT, FONT_INPUT_1,
8806                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
8807                       GDI_TEXT_FONT_UNSELECTABLE, FONT_TEXT_1,
8808                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8809                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8810                       GDI_BORDER_SIZE, gd->border_size, gd->border_size,
8811                       GDI_BORDER_SIZE_SELECTBUTTON, selectbox_button_xsize,
8812                       GDI_DESIGN_WIDTH, gd->width,
8813                       GDI_EVENT_MASK, event_mask,
8814                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8815                       GDI_CALLBACK_ACTION, HandleSelectboxGadgets,
8816                       GDI_END);
8817
8818     if (gi == NULL)
8819       Fail("cannot create gadget");
8820
8821     level_editor_gadget[id] = gi;
8822     right_gadget_border[id] =
8823       getRightGadgetBorder(gi, selectbox_info[i].text_right);
8824   }
8825 }
8826
8827 static void CreateTextbuttonGadgets(void)
8828 {
8829   int max_infotext_len = getMaxInfoTextLength();
8830   int i;
8831
8832   for (i = 0; i < ED_NUM_TEXTBUTTONS; i++)
8833   {
8834     int id = textbutton_info[i].gadget_id;
8835     int type_id = textbutton_info[i].gadget_type_id;
8836     int is_tab_button =
8837       ((id >= GADGET_ID_LEVELCONFIG_LEVEL && id <= GADGET_ID_LEVELCONFIG_ENGINE) ||
8838        (id >= GADGET_ID_ENGINECONFIG_CONFIG && id <= GADGET_ID_ENGINECONFIG_COLORS) ||
8839        (id >= GADGET_ID_PROPERTIES_INFO && id <= GADGET_ID_PROPERTIES_CHANGE));
8840     int graphic =
8841       (is_tab_button ? IMG_EDITOR_TABBUTTON : IMG_EDITOR_TEXTBUTTON);
8842     int gadget_distance =
8843       (is_tab_button ? ED_GADGET_SMALL_DISTANCE : ED_GADGET_TEXT_DISTANCE);
8844     struct GraphicInfo *gd = &graphic_info[graphic];
8845     int gd_x1 = gd->src_x;
8846     int gd_y1 = gd->src_y;
8847     int gd_x2 = gd->src_x + gd->pressed_xoffset;
8848     int gd_y2 = gd->src_y + gd->pressed_yoffset;
8849     int gd_x1a = gd->src_x + gd->active_xoffset;
8850     int gd_y1a = gd->src_y + gd->active_yoffset;
8851     int border_xsize = gd->border_size + gd->draw_xoffset;
8852     int border_ysize = gd->border_size;
8853     struct GadgetInfo *gi;
8854     unsigned int event_mask = GD_EVENT_RELEASED;
8855     char infotext[MAX_OUTPUT_LINESIZE + 1];
8856     int x = SX + ED_SETTINGS_X(textbutton_info[i].x);
8857     int y = SY + ED_SETTINGS_Y(textbutton_info[i].y);
8858
8859     if (type_id != i)
8860       Fail("'textbutton_info' structure corrupted at index %d -- please fix", i);
8861
8862     if (textbutton_info[i].size == -1)  // dynamically determine size
8863       textbutton_info[i].size = strlen(textbutton_info[i].text);
8864
8865     sprintf(infotext, "%s", textbutton_info[i].infotext);
8866     infotext[max_infotext_len] = '\0';
8867
8868     // determine horizontal position to the right of specified gadget
8869     if (textbutton_info[i].gadget_id_align != GADGET_ID_NONE)
8870     {
8871       int gadget_id_align = textbutton_info[i].gadget_id_align;
8872
8873       x = right_gadget_border[gadget_id_align] + gadget_distance;
8874
8875       if (textbutton_info[i].y == -1)
8876         y = level_editor_gadget[gadget_id_align]->y;
8877     }
8878
8879     // determine horizontal offset for leading text
8880     if (textbutton_info[i].text_left != NULL)
8881       x += getTextWidthForGadget(textbutton_info[i].text_left);
8882
8883     gi = CreateGadget(GDI_CUSTOM_ID, id,
8884                       GDI_CUSTOM_TYPE_ID, type_id,
8885                       GDI_IMAGE_ID, graphic,
8886                       GDI_INFO_TEXT, infotext,
8887                       GDI_X, x,
8888                       GDI_Y, y,
8889                       GDI_TYPE, GD_TYPE_TEXT_BUTTON,
8890                       GDI_TEXT_VALUE, textbutton_info[i].text,
8891                       GDI_TEXT_SIZE, textbutton_info[i].size,
8892                       GDI_TEXT_FONT, FONT_INPUT_2,
8893                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_2_ACTIVE,
8894                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8895                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8896                       GDI_ALT_DESIGN_UNPRESSED, gd->bitmap, gd_x1a, gd_y1a,
8897                       GDI_BORDER_SIZE, border_xsize, border_ysize,
8898                       GDI_DESIGN_WIDTH, gd->width,
8899                       GDI_DECORATION_SHIFTING, 1, 1,
8900                       GDI_EVENT_MASK, event_mask,
8901                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8902                       GDI_CALLBACK_ACTION, HandleTextbuttonGadgets,
8903                       GDI_END);
8904
8905     if (gi == NULL)
8906       Fail("cannot create gadget");
8907
8908     level_editor_gadget[id] = gi;
8909     right_gadget_border[id] =
8910       getRightGadgetBorder(gi, textbutton_info[i].text_right);
8911   }
8912 }
8913
8914 static void CreateGraphicbuttonGadgets(void)
8915 {
8916   struct GadgetInfo *gi;
8917   int i;
8918
8919   // create buttons for scrolling of drawing area and element list
8920   for (i = 0; i < ED_NUM_GRAPHICBUTTONS; i++)
8921   {
8922     int id = graphicbutton_info[i].gadget_id;
8923     int type_id = graphicbutton_info[i].gadget_type_id;
8924     int x = SX + ED_SETTINGS_X(graphicbutton_info[i].x);
8925     int y = SY + ED_SETTINGS_Y(graphicbutton_info[i].y);
8926     int graphic = graphicbutton_info[i].graphic;
8927     struct GraphicInfo *gd = &graphic_info[graphic];
8928     int gd_x1 = gd->src_x;
8929     int gd_y1 = gd->src_y;
8930     int gd_x2 = gd->src_x + gd->pressed_xoffset;
8931     int gd_y2 = gd->src_y + gd->pressed_yoffset;
8932     unsigned int event_mask = GD_EVENT_RELEASED;
8933
8934     if (type_id != i)
8935       Fail("'graphicbutton_info' structure corrupted at index %d -- please fix", i);
8936
8937     // determine horizontal position to the right of specified gadget
8938     if (graphicbutton_info[i].gadget_id_align != GADGET_ID_NONE)
8939       x = (right_gadget_border[graphicbutton_info[i].gadget_id_align] +
8940            ED_GADGET_TEXT_DISTANCE);
8941
8942     // determine horizontal offset for leading text
8943     if (graphicbutton_info[i].text_left != NULL)
8944       x += getTextWidthForGadget(graphicbutton_info[i].text_left);
8945
8946     gi = CreateGadget(GDI_CUSTOM_ID, id,
8947                       GDI_CUSTOM_TYPE_ID, type_id,
8948                       GDI_IMAGE_ID, graphic,
8949                       GDI_INFO_TEXT, graphicbutton_info[i].infotext,
8950                       GDI_X, x,
8951                       GDI_Y, y,
8952                       GDI_WIDTH, gd->width,
8953                       GDI_HEIGHT, gd->height,
8954                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
8955                       GDI_STATE, GD_BUTTON_UNPRESSED,
8956                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
8957                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
8958                       GDI_EVENT_MASK, event_mask,
8959                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
8960                       GDI_CALLBACK_ACTION, HandleGraphicbuttonGadgets,
8961                       GDI_END);
8962
8963     if (gi == NULL)
8964       Fail("cannot create gadget");
8965
8966     level_editor_gadget[id] = gi;
8967     right_gadget_border[id] =
8968       getRightGadgetBorder(gi, graphicbutton_info[i].text_right);
8969   }
8970 }
8971
8972 static void CreateScrollbarGadgets(void)
8973 {
8974   int i;
8975
8976   // these values are not constant, but can change at runtime
8977   scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].x =
8978     SX + ED_SCROLL_HORIZONTAL_XPOS;
8979   scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].y =
8980     SY + ED_SCROLL_HORIZONTAL_YPOS;
8981   scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width =
8982     ED_SCROLL_HORIZONTAL_XSIZE;
8983   scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].height =
8984     ED_SCROLL_HORIZONTAL_YSIZE;
8985   scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_x      = SX;
8986   scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_y      = SY;
8987   scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_width  = SXSIZE;
8988   scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_height = SYSIZE;
8989
8990   scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].x =
8991     SX + ED_SCROLL_VERTICAL_XPOS;
8992   scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].y =
8993     SY + ED_SCROLL_VERTICAL_YPOS;
8994   scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].width =
8995     ED_SCROLL_VERTICAL_XSIZE;
8996   scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].height =
8997     ED_SCROLL_VERTICAL_YSIZE;
8998   scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_x      = SX;
8999   scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_y      = SY;
9000   scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_width  = SXSIZE;
9001   scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_height = SYSIZE;
9002
9003   scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].x =
9004     PX + ED_SCROLL2_VERTICAL_XPOS;
9005   scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].y =
9006     PY + ED_SCROLL2_VERTICAL_YPOS;
9007   scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].width =
9008     ED_SCROLL2_VERTICAL_XSIZE;
9009   scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].height =
9010     ED_SCROLL2_VERTICAL_YSIZE;
9011   scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_x = PX;
9012   scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_y = PY;
9013   scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_width  = PXSIZE;
9014   scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_height = PYSIZE;
9015
9016   for (i = 0; i < ED_NUM_SCROLLBARS; i++)
9017   {
9018     int id = scrollbar_info[i].gadget_id;
9019     int type_id = scrollbar_info[i].gadget_type_id;
9020     int graphic = scrollbar_info[i].graphic;
9021     struct GraphicInfo *gd = &graphic_info[graphic];
9022     int gd_x1 = gd->src_x;
9023     int gd_y1 = gd->src_y;
9024     int gd_x2 = gd->src_x + gd->pressed_xoffset;
9025     int gd_y2 = gd->src_y + gd->pressed_yoffset;
9026     struct GadgetInfo *gi;
9027     int items_max, items_visible, item_position;
9028     unsigned int event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
9029
9030     if (type_id != i)
9031       Fail("'scrollbar_info' structure corrupted at index %d -- please fix", i);
9032
9033     if (i == ED_SCROLLBAR_ID_LIST_VERTICAL)
9034     {
9035       items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
9036       items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
9037       item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
9038     }
9039     else        // drawing area scrollbars
9040     {
9041       if (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL)
9042       {
9043         items_max = MAX(lev_fieldx + 2, ed_fieldx);
9044         items_visible = ed_fieldx;
9045         item_position = 0;
9046       }
9047       else
9048       {
9049         items_max = MAX(lev_fieldy + 2, ed_fieldy);
9050         items_visible = ed_fieldy;
9051         item_position = 0;
9052       }
9053     }
9054
9055     gi = CreateGadget(GDI_CUSTOM_ID, id,
9056                       GDI_CUSTOM_TYPE_ID, type_id,
9057                       GDI_IMAGE_ID, graphic,
9058                       GDI_INFO_TEXT, scrollbar_info[i].infotext,
9059                       GDI_X, scrollbar_pos[i].x,
9060                       GDI_Y, scrollbar_pos[i].y,
9061                       GDI_WIDTH, scrollbar_pos[i].width,
9062                       GDI_HEIGHT, scrollbar_pos[i].height,
9063                       GDI_TYPE, scrollbar_info[i].type,
9064                       GDI_SCROLLBAR_ITEMS_MAX, items_max,
9065                       GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
9066                       GDI_SCROLLBAR_ITEM_POSITION, item_position,
9067                       GDI_WHEEL_AREA_X, scrollbar_pos[i].wheel_x,
9068                       GDI_WHEEL_AREA_Y, scrollbar_pos[i].wheel_y,
9069                       GDI_WHEEL_AREA_WIDTH, scrollbar_pos[i].wheel_width,
9070                       GDI_WHEEL_AREA_HEIGHT, scrollbar_pos[i].wheel_height,
9071                       GDI_STATE, GD_BUTTON_UNPRESSED,
9072                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9073                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9074                       GDI_BORDER_SIZE, gd->border_size, gd->border_size,
9075                       GDI_EVENT_MASK, event_mask,
9076                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
9077                       GDI_CALLBACK_ACTION, HandleControlButtons,
9078                       GDI_END);
9079
9080     if (gi == NULL)
9081       Fail("cannot create gadget");
9082
9083     level_editor_gadget[id] = gi;
9084   }
9085 }
9086
9087 static void CreateCheckbuttonGadgets(void)
9088 {
9089   struct GadgetInfo *gi;
9090   int i;
9091
9092   for (i = 0; i < ED_NUM_CHECKBUTTONS; i++)
9093   {
9094     int id = checkbutton_info[i].gadget_id;
9095     int type_id = checkbutton_info[i].gadget_type_id;
9096     int graphic = (id == GADGET_ID_STICK_ELEMENT ? IMG_EDITOR_STICKYBUTTON :
9097                    IMG_EDITOR_CHECKBOX);
9098     struct GraphicInfo *gd = &graphic_info[graphic];
9099     int gd_x1 = gd->src_x;
9100     int gd_y1 = gd->src_y;
9101     int gd_x2 = gd->src_x + gd->pressed_xoffset;
9102     int gd_y2 = gd->src_y + gd->pressed_yoffset;
9103     int gd_x1a = gd->src_x + gd->active_xoffset;
9104     int gd_y1a = gd->src_y + gd->active_yoffset;
9105     int gd_x2a = gd->src_x + gd->active_xoffset + gd->pressed_xoffset;
9106     int gd_y2a = gd->src_y + gd->active_yoffset + gd->pressed_yoffset;
9107     int x = SX + ED_SETTINGS_X(checkbutton_info[i].x);
9108     int y = SY + ED_SETTINGS_Y(checkbutton_info[i].y);
9109     unsigned int event_mask = GD_EVENT_PRESSED;
9110
9111     if (type_id != i)
9112       Fail("'checkbutton_info' structure corrupted at index %d -- please fix", i);
9113
9114     // determine horizontal position to the right of specified gadget
9115     if (checkbutton_info[i].gadget_id_align != GADGET_ID_NONE)
9116       x = (right_gadget_border[checkbutton_info[i].gadget_id_align] +
9117            ED_GADGET_TEXT_DISTANCE);
9118
9119     // determine horizontal offset for leading text
9120     if (checkbutton_info[i].text_left != NULL)
9121       x += getTextWidthForGadget(checkbutton_info[i].text_left);
9122
9123     gi = CreateGadget(GDI_CUSTOM_ID, id,
9124                       GDI_CUSTOM_TYPE_ID, type_id,
9125                       GDI_IMAGE_ID, graphic,
9126                       GDI_INFO_TEXT, checkbutton_info[i].infotext,
9127                       GDI_X, x,
9128                       GDI_Y, y,
9129                       GDI_WIDTH, gd->width,
9130                       GDI_HEIGHT, gd->height,
9131                       GDI_TYPE, GD_TYPE_CHECK_BUTTON,
9132                       GDI_CHECKED, *checkbutton_info[i].value,
9133                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9134                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9135                       GDI_ALT_DESIGN_UNPRESSED, gd->bitmap, gd_x1a, gd_y1a,
9136                       GDI_ALT_DESIGN_PRESSED, gd->bitmap, gd_x2a, gd_y2a,
9137                       GDI_EVENT_MASK, event_mask,
9138                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
9139                       GDI_CALLBACK_ACTION, HandleCheckbuttons,
9140                       GDI_END);
9141
9142     if (gi == NULL)
9143       Fail("cannot create gadget");
9144
9145     level_editor_gadget[id] = gi;
9146     right_gadget_border[id] =
9147       getRightGadgetBorder(gi, checkbutton_info[i].text_right);
9148   }
9149 }
9150
9151 static void CreateRadiobuttonGadgets(void)
9152 {
9153   int graphic = IMG_EDITOR_RADIOBUTTON;
9154   struct GraphicInfo *gd = &graphic_info[graphic];
9155   int gd_x1 = gd->src_x;
9156   int gd_y1 = gd->src_y;
9157   int gd_x2 = gd->src_x + gd->pressed_xoffset;
9158   int gd_y2 = gd->src_y + gd->pressed_yoffset;
9159   int gd_x1a = gd->src_x + gd->active_xoffset;
9160   int gd_y1a = gd->src_y + gd->active_yoffset;
9161   int gd_x2a = gd->src_x + gd->active_xoffset + gd->pressed_xoffset;
9162   int gd_y2a = gd->src_y + gd->active_yoffset + gd->pressed_yoffset;
9163   struct GadgetInfo *gi;
9164   int i;
9165
9166   for (i = 0; i < ED_NUM_RADIOBUTTONS; i++)
9167   {
9168     int id = radiobutton_info[i].gadget_id;
9169     int type_id = radiobutton_info[i].gadget_type_id;
9170     int x = SX + ED_SETTINGS_X(radiobutton_info[i].x);
9171     int y = SY + ED_SETTINGS_Y(radiobutton_info[i].y);
9172     unsigned int event_mask = GD_EVENT_PRESSED;
9173
9174     if (type_id != i)
9175       Fail("'radiobutton_info' structure corrupted at index %d -- please fix", i);
9176
9177     int checked =
9178       (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
9179
9180     // determine horizontal position to the right of specified gadget
9181     if (radiobutton_info[i].gadget_id_align != GADGET_ID_NONE)
9182       x = (right_gadget_border[radiobutton_info[i].gadget_id_align] +
9183            ED_GADGET_TEXT_DISTANCE);
9184
9185     // determine horizontal offset for leading text
9186     if (radiobutton_info[i].text_left != NULL)
9187       x += getTextWidthForGadget(radiobutton_info[i].text_left);
9188
9189     gi = CreateGadget(GDI_CUSTOM_ID, id,
9190                       GDI_CUSTOM_TYPE_ID, type_id,
9191                       GDI_IMAGE_ID, graphic,
9192                       GDI_INFO_TEXT, radiobutton_info[i].infotext,
9193                       GDI_X, x,
9194                       GDI_Y, y,
9195                       GDI_WIDTH, gd->width,
9196                       GDI_HEIGHT, gd->height,
9197                       GDI_TYPE, GD_TYPE_RADIO_BUTTON,
9198                       GDI_RADIO_NR, radiobutton_info[i].radio_button_nr,
9199                       GDI_CHECKED, checked,
9200                       GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
9201                       GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
9202                       GDI_ALT_DESIGN_UNPRESSED, gd->bitmap, gd_x1a, gd_y1a,
9203                       GDI_ALT_DESIGN_PRESSED, gd->bitmap, gd_x2a, gd_y2a,
9204                       GDI_EVENT_MASK, event_mask,
9205                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
9206                       GDI_CALLBACK_ACTION, HandleRadiobuttons,
9207                       GDI_END);
9208
9209     if (gi == NULL)
9210       Fail("cannot create gadget");
9211
9212     level_editor_gadget[id] = gi;
9213     right_gadget_border[id] =
9214       getRightGadgetBorder(gi, radiobutton_info[i].text_right);
9215   }
9216 }
9217
9218 void CreateLevelEditorGadgets(void)
9219 {
9220   // force EDITOR font inside level editor
9221   SetFontStatus(GAME_MODE_EDITOR);
9222
9223   // these values are not constant, but can change at runtime
9224   ed_fieldx = MAX_ED_FIELDX - 1;
9225   ed_fieldy = MAX_ED_FIELDY - 1;
9226
9227   num_editor_gadgets = NUM_EDITOR_GADGETS;
9228
9229   // Debug("editor", "allocating %d gadgets ...\n", num_editor_gadgets);
9230
9231   level_editor_gadget =
9232     checked_calloc(num_editor_gadgets * sizeof(struct GadgetInfo *));
9233   right_gadget_border =
9234     checked_calloc(num_editor_gadgets * sizeof(int));
9235
9236   // set number of empty (padding) element buttons to maximum number of buttons
9237   num_editor_el_empty = ED_NUM_ELEMENTLIST_BUTTONS;
9238
9239   editor_el_empty = checked_calloc(num_editor_el_empty * sizeof(int));
9240   editor_el_empty_ptr = editor_el_empty;
9241
9242   use_permanent_palette = !editor.palette.show_as_separate_screen;
9243
9244   InitGadgetScreenBorders(-1, INFOTEXT_YPOS);
9245
9246   ReinitializeElementList();
9247
9248   CreateControlButtons();
9249   CreateScrollbarGadgets();
9250
9251   // order of function calls is important because of cross-references
9252   CreateCheckbuttonGadgets();
9253   CreateCounterButtons();
9254   CreateRadiobuttonGadgets();
9255   CreateTextInputGadgets();
9256   CreateTextAreaGadgets();
9257   CreateSelectboxGadgets();
9258   CreateGraphicbuttonGadgets();
9259   CreateTextbuttonGadgets();
9260   CreateDrawingAreas();
9261
9262   ResetFontStatus();
9263 }
9264
9265 void FreeLevelEditorGadgets(void)
9266 {
9267   int i;
9268
9269   // Debug("editor", "freeing %d gadgets ...\n", num_editor_gadgets);
9270
9271   for (i = 0; i < num_editor_gadgets; i++)
9272   {
9273     FreeGadget(level_editor_gadget[i]);
9274
9275     level_editor_gadget[i] = NULL;
9276   }
9277
9278   checked_free(level_editor_gadget);
9279   checked_free(right_gadget_border);
9280
9281   checked_free(editor_el_empty);
9282 }
9283
9284 static void MapCounterButtons(int id)
9285 {
9286   int font_nr = FONT_TEXT_1;
9287   int font_height = getFontHeight(font_nr);
9288   int gadget_id_down = counterbutton_info[id].gadget_id_down;
9289   int gadget_id_text = counterbutton_info[id].gadget_id_text;
9290   int gadget_id_up   = counterbutton_info[id].gadget_id_up;
9291   struct GadgetInfo *gi_down = level_editor_gadget[gadget_id_down];
9292   struct GadgetInfo *gi_text = level_editor_gadget[gadget_id_text];
9293   struct GadgetInfo *gi_up   = level_editor_gadget[gadget_id_up];
9294   int xoffset_left = getTextWidthForGadget(counterbutton_info[id].text_left);
9295   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
9296   int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
9297   int yoffset = (gi_down->height - font_height) / 2;
9298   int x_left = gi_down->x - xoffset_left;
9299   int x_right;  // set after gadget position was modified
9300   int y_above = gi_down->y - yoffset_above;
9301   int x = gi_down->x;
9302   int y;        // set after gadget position was modified
9303
9304   // counter limits must be changed first to prevent value truncation
9305   ModifyEditorCounterLimits(id, counterbutton_info[id].min_value,
9306                             counterbutton_info[id].max_value);
9307
9308   // right text position might have changed after setting position above
9309   x_right = gi_up->x + gi_up->width + xoffset_right;
9310
9311   ModifyEditorCounterValue(id, *counterbutton_info[id].value);
9312
9313   // set position for counter gadgets with dynamically determined position
9314   if (id != ED_COUNTER_ID_SELECT_LEVEL)
9315   {
9316     ModifyGadget(gi_down, GDI_Y, SY + ED_SETTINGS_Y(counterbutton_info[id].y), GDI_END);
9317     ModifyGadget(gi_text, GDI_Y, SY + ED_SETTINGS_Y(counterbutton_info[id].y), GDI_END);
9318     ModifyGadget(gi_up,   GDI_Y, SY + ED_SETTINGS_Y(counterbutton_info[id].y), GDI_END);
9319   }
9320
9321   // vertical position might have changed after setting position above
9322   y = gi_up->y + yoffset;
9323
9324   if (counterbutton_info[id].text_above)
9325     DrawText(x, y_above, counterbutton_info[id].text_above, font_nr);
9326
9327   if (counterbutton_info[id].text_left)
9328     DrawText(x_left, y, counterbutton_info[id].text_left, font_nr);
9329
9330   if (counterbutton_info[id].text_right)
9331     DrawText(x_right, y, counterbutton_info[id].text_right, font_nr);
9332
9333   MapGadget(gi_down);
9334   MapGadget(gi_text);
9335   MapGadget(gi_up);
9336 }
9337
9338 static void MapControlButtons(void)
9339 {
9340   int counter_id;
9341   int i;
9342
9343   // map toolbox buttons (excluding special CE toolbox buttons)
9344   for (i = 0; i < ED_NUM_CTRL1_2_BUTTONS; i++)
9345     MapGadget(level_editor_gadget[i]);
9346
9347   // map toolbox buttons (element properties buttons)
9348   for (i = ED_NUM_CTRL1_4_BUTTONS; i < ED_NUM_CTRL1_7_BUTTONS; i++)
9349     MapGadget(level_editor_gadget[i]);
9350
9351   if (use_permanent_palette)
9352   {
9353     // map buttons to select elements
9354     for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
9355       MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
9356     MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
9357     MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
9358     MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
9359   }
9360
9361   // map buttons to select level
9362   counter_id = ED_COUNTER_ID_SELECT_LEVEL;
9363   counterbutton_info[counter_id].min_value = leveldir_current->first_level;
9364   counterbutton_info[counter_id].max_value = leveldir_current->last_level;
9365   MapCounterButtons(counter_id);
9366 }
9367
9368 static void MapDrawingArea(int id)
9369 {
9370   int font_nr = FONT_TEXT_1;
9371   int font_height = getFontHeight(font_nr);
9372   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
9373   int area_xsize = gi->drawing.area_xsize;
9374   int area_ysize = gi->drawing.area_ysize;
9375   int xoffset_left = getTextWidthForDrawingArea(drawingarea_info[id].text_left);
9376   int xoffset_below = getTextWidth(drawingarea_info[id].text_below, font_nr);
9377   int x_left  = gi->x - xoffset_left - ED_DRAWINGAREA_BORDER_SIZE;
9378   int x_right = gi->x + gi->width + ED_DRAWINGAREA_TEXT_DISTANCE;
9379   int x_above = gi->x - ED_DRAWINGAREA_BORDER_SIZE;
9380   int x_below = gi->x + (gi->width - xoffset_below) / 2;
9381   int y_side  = gi->y + (gi->height - font_height) / 2;
9382   int y_above = gi->y - font_height - ED_DRAWINGAREA_TEXT_DISTANCE;
9383   int y_below = gi->y + gi->height + ED_DRAWINGAREA_TEXT_DISTANCE;
9384
9385   if (drawingarea_info[id].text_left)
9386     DrawText(x_left, y_side, drawingarea_info[id].text_left, font_nr);
9387
9388   if (drawingarea_info[id].text_right)
9389     DrawText(x_right, y_side, drawingarea_info[id].text_right, font_nr);
9390
9391   if (drawingarea_info[id].text_above)
9392     DrawText(x_above, y_above, drawingarea_info[id].text_above, font_nr);
9393
9394   if (drawingarea_info[id].text_below)
9395     DrawText(x_below, y_below, drawingarea_info[id].text_below, font_nr);
9396
9397   if (id != ED_DRAWING_ID_DRAWING_LEVEL)
9398   {
9399     DrawElementBorder(gi->x, gi->y,
9400                       area_xsize * ED_DRAWINGAREA_TILE_SIZE,
9401                       area_ysize * ED_DRAWINGAREA_TILE_SIZE, TRUE);
9402
9403     DrawDrawingArea(id);
9404   }
9405
9406   MapGadget(gi);
9407 }
9408
9409 static void MapTextInputGadget(int id)
9410 {
9411   int font_nr = FONT_TEXT_1;
9412   int font_height = getFontHeight(font_nr);
9413   struct GadgetInfo *gi = level_editor_gadget[textinput_info[id].gadget_id];
9414   int xoffset_left = getTextWidthForGadget(textinput_info[id].text_left);
9415   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
9416   int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
9417   int yoffset = (gi->height - font_height) / 2;
9418   int x_left = gi->x - xoffset_left;
9419   int x_right = gi->x + gi->width + xoffset_right;
9420   int y_above = gi->y - yoffset_above;
9421   int y = gi->y + yoffset;
9422
9423   if (textinput_info[id].text_above)
9424     DrawText(x_left, y_above, textinput_info[id].text_above, font_nr);
9425
9426   if (textinput_info[id].text_left)
9427     DrawText(x_left, y, textinput_info[id].text_left, font_nr);
9428
9429   if (textinput_info[id].text_right)
9430     DrawText(x_right, y, textinput_info[id].text_right, font_nr);
9431
9432   ModifyGadget(gi, GDI_TEXT_VALUE, textinput_info[id].value, GDI_END);
9433
9434   MapGadget(gi);
9435 }
9436
9437 static void MapTextAreaGadget(int id)
9438 {
9439   int font_nr = FONT_TEXT_1;
9440   int font_height = getFontHeight(font_nr);
9441   struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
9442   int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
9443   int x_above = ED_SETTINGS_X(textarea_info[id].x);
9444   int y_above = ED_SETTINGS_Y(textarea_info[id].y) - yoffset_above;
9445   char *text_above = textarea_info[id].text_above;
9446
9447   if (gi->textarea.cropped && textarea_info[id].text_above_cropped)
9448     text_above = textarea_info[id].text_above_cropped;
9449
9450   if (text_above)
9451     DrawTextS(x_above, y_above, font_nr, text_above);
9452
9453   ModifyGadget(gi, GDI_TEXT_VALUE, textarea_info[id].value, GDI_END);
9454
9455   MapGadget(gi);
9456 }
9457
9458 static void MapSelectboxGadget(int id)
9459 {
9460   int font_nr = FONT_TEXT_1;
9461   int font_height = getFontHeight(font_nr);
9462   struct GadgetInfo *gi = level_editor_gadget[selectbox_info[id].gadget_id];
9463   int xoffset_left = getTextWidthForGadget(selectbox_info[id].text_left);
9464   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
9465   int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
9466   int yoffset = (gi->height - font_height) / 2;
9467   int x_left = gi->x - xoffset_left;
9468   int x_right = gi->x + gi->width + xoffset_right;
9469   int y_above = gi->y - yoffset_above;
9470   int y = gi->y + yoffset;
9471
9472   if (selectbox_info[id].text_above)
9473     DrawText(x_left, y_above, selectbox_info[id].text_above, font_nr);
9474
9475   if (selectbox_info[id].text_left)
9476     DrawText(x_left, y, selectbox_info[id].text_left, font_nr);
9477
9478   if (selectbox_info[id].text_right)
9479     DrawText(x_right, y, selectbox_info[id].text_right, font_nr);
9480
9481   ModifyEditorSelectboxValue(id, *selectbox_info[id].value);
9482
9483   MapGadget(gi);
9484 }
9485
9486 static void MapTextbuttonGadget(int id)
9487 {
9488   int font_nr = FONT_TEXT_1;
9489   int font_height = getFontHeight(font_nr);
9490   struct GadgetInfo *gi = level_editor_gadget[textbutton_info[id].gadget_id];
9491   int xoffset_left = getTextWidthForGadget(textbutton_info[id].text_left);
9492   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
9493   int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
9494   int yoffset = (gi->height - font_height) / 2;
9495   int x_left = gi->x - xoffset_left;
9496   int x_right = gi->x + gi->width + xoffset_right;
9497   int y_above = gi->y - yoffset_above;
9498   int x = gi->x;
9499   int y = gi->y + yoffset;
9500
9501   // only show button to delete change pages when more than minimum pages
9502   if (id == ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE &&
9503       custom_element.num_change_pages == MIN_CHANGE_PAGES)
9504     return;
9505
9506   if (textbutton_info[id].text_above)
9507     DrawText(x, y_above, textbutton_info[id].text_above, font_nr);
9508
9509   if (textbutton_info[id].text_left)
9510     DrawText(x_left, y, textbutton_info[id].text_left, font_nr);
9511
9512   if (textbutton_info[id].text_right)
9513     DrawText(x_right, y, textbutton_info[id].text_right, font_nr);
9514
9515   MapGadget(gi);
9516 }
9517
9518 static void MapGraphicbuttonGadget(int id)
9519 {
9520   int font_nr = FONT_TEXT_1;
9521   int font_height = getFontHeight(font_nr);
9522   struct GadgetInfo *gi = level_editor_gadget[graphicbutton_info[id].gadget_id];
9523   int xoffset_left = getTextWidthForGadget(graphicbutton_info[id].text_left);
9524   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
9525   int yoffset = (gi->height - font_height) / 2;
9526   int x_left = gi->x - xoffset_left;
9527   int x_right = gi->x + gi->width + xoffset_right;
9528   int y = gi->y + yoffset;
9529
9530   if (graphicbutton_info[id].text_left)
9531     DrawText(x_left, y, graphicbutton_info[id].text_left, font_nr);
9532
9533   if (graphicbutton_info[id].text_right)
9534     DrawText(x_right, y, graphicbutton_info[id].text_right, font_nr);
9535
9536   MapGadget(gi);
9537 }
9538
9539 static void MapRadiobuttonGadget(int id)
9540 {
9541   int font_nr = FONT_TEXT_1;
9542   int font_height = getFontHeight(font_nr);
9543   struct GadgetInfo *gi = level_editor_gadget[radiobutton_info[id].gadget_id];
9544   int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
9545   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
9546   int yoffset = (gi->height - font_height) / 2;
9547   int x_left = gi->x - xoffset_left;
9548   int x_right = gi->x + gi->width + xoffset_right;
9549   int y = gi->y + yoffset;
9550   boolean checked =
9551     (*radiobutton_info[id].value == radiobutton_info[id].checked_value);
9552
9553   if (radiobutton_info[id].text_left)
9554     DrawText(x_left, y, radiobutton_info[id].text_left, font_nr);
9555
9556   if (radiobutton_info[id].text_right)
9557     DrawText(x_right, y, radiobutton_info[id].text_right, font_nr);
9558
9559   ModifyGadget(gi, GDI_CHECKED, checked, GDI_END);
9560
9561   MapGadget(gi);
9562 }
9563
9564 static void MapCheckbuttonGadget(int id)
9565 {
9566   int font_nr = FONT_TEXT_1;
9567   int font_height = getFontHeight(font_nr);
9568   struct GadgetInfo *gi = level_editor_gadget[checkbutton_info[id].gadget_id];
9569   int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
9570   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
9571   int yoffset_above = font_height + ED_GADGET_LINE_DISTANCE;
9572   int yoffset = (gi->height - font_height) / 2;
9573   int y_above = gi->y - yoffset_above;
9574   int x = gi->x;
9575   int x_left, x_right, y;       // set after gadget position was modified
9576
9577   // set position for gadgets with dynamically determined position
9578   if (checkbutton_info[id].x != -1)     // do not change dynamic positions
9579     ModifyGadget(gi, GDI_X, SX + ED_SETTINGS_X(checkbutton_info[id].x), GDI_END);
9580   ModifyGadget(gi, GDI_Y, SY + ED_SETTINGS_Y(checkbutton_info[id].y), GDI_END);
9581
9582   x_left = gi->x - xoffset_left;
9583   x_right = gi->x + gi->width + xoffset_right;
9584   y = gi->y + yoffset;
9585
9586   if (checkbutton_info[id].text_above)
9587     DrawText(x, y_above, checkbutton_info[id].text_above, font_nr);
9588
9589   if (checkbutton_info[id].text_left)
9590     DrawText(x_left, y, checkbutton_info[id].text_left, font_nr);
9591
9592   if (checkbutton_info[id].text_right)
9593     DrawText(x_right, y, checkbutton_info[id].text_right, font_nr);
9594
9595   ModifyGadget(gi, GDI_CHECKED, *checkbutton_info[id].value, GDI_END);
9596
9597   MapGadget(gi);
9598 }
9599
9600 static void MapMainDrawingArea(void)
9601 {
9602   boolean no_horizontal_scrollbar = (lev_fieldx + 2 <= ed_fieldx);
9603   boolean no_vertical_scrollbar = (lev_fieldy + 2 <= ed_fieldy);
9604   int i;
9605
9606   if (suppressBorderElement())
9607   {
9608     no_horizontal_scrollbar = (lev_fieldx <= ed_fieldx);
9609     no_vertical_scrollbar   = (lev_fieldy <= ed_fieldy);
9610   }
9611
9612   for (i = ED_SCROLLBUTTON_ID_AREA_FIRST; i <= ED_SCROLLBUTTON_ID_AREA_LAST; i++)
9613   {
9614     if (((i == ED_SCROLLBUTTON_ID_AREA_LEFT ||
9615           i == ED_SCROLLBUTTON_ID_AREA_RIGHT) &&
9616          no_horizontal_scrollbar) ||
9617         ((i == ED_SCROLLBUTTON_ID_AREA_UP ||
9618           i == ED_SCROLLBUTTON_ID_AREA_DOWN) &&
9619          no_vertical_scrollbar))
9620       continue;
9621
9622     MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
9623   }
9624
9625   for (i = ED_SCROLLBAR_ID_AREA_FIRST; i <= ED_SCROLLBAR_ID_AREA_LAST; i++)
9626   {
9627     if ((i == ED_SCROLLBAR_ID_AREA_HORIZONTAL && no_horizontal_scrollbar) ||
9628         (i == ED_SCROLLBAR_ID_AREA_VERTICAL && no_vertical_scrollbar))
9629       continue;
9630
9631     MapGadget(level_editor_gadget[scrollbar_info[i].gadget_id]);
9632   }
9633
9634   MapDrawingArea(ED_DRAWING_ID_DRAWING_LEVEL);
9635 }
9636
9637 static void MapOrUnmapLevelEditorToolboxCustomGadgets(boolean map)
9638 {
9639   int i;
9640
9641   for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
9642   {
9643     if (i == GADGET_ID_CUSTOM_COPY_FROM ||
9644         i == GADGET_ID_CUSTOM_COPY_TO ||
9645         i == GADGET_ID_CUSTOM_EXCHANGE ||
9646         i == GADGET_ID_CUSTOM_COPY ||
9647         i == GADGET_ID_CUSTOM_PASTE)
9648     {
9649       if (map)
9650         MapGadget(level_editor_gadget[i]);
9651       else
9652         UnmapGadget(level_editor_gadget[i]);
9653     }
9654   }
9655 }
9656
9657 static void MapLevelEditorToolboxCustomGadgets(void)
9658 {
9659   MapOrUnmapLevelEditorToolboxCustomGadgets(TRUE);
9660 }
9661
9662 static void MapLevelEditorToolboxCustomGadgetsIfNeeded(void)
9663 {
9664   if (IS_CUSTOM_ELEMENT(properties_element) ||
9665       IS_GROUP_ELEMENT(properties_element) ||
9666       IS_EMPTY_ELEMENT(properties_element))
9667     MapLevelEditorToolboxCustomGadgets();
9668 }
9669
9670 static void UnmapLevelEditorToolboxCustomGadgets(void)
9671 {
9672   MapOrUnmapLevelEditorToolboxCustomGadgets(FALSE);
9673 }
9674
9675 static void MapOrUnmapLevelEditorToolboxDrawingGadgets(boolean map)
9676 {
9677   int i;
9678
9679   for (i = 0; i < ED_NUM_CTRL1_BUTTONS; i++)
9680   {
9681     if (i != GADGET_ID_SINGLE_ITEMS &&
9682         i != GADGET_ID_PICK_ELEMENT)
9683     {
9684       struct GadgetInfo *gi = level_editor_gadget[i];
9685
9686       if (map)
9687       {
9688         MapGadget(gi);
9689       }
9690       else
9691       {
9692         int graphic = IMG_EDITOR_NO_TOOLBOX_BUTTON;
9693         struct GraphicInfo *gd = &graphic_info[graphic];
9694
9695         UnmapGadget(gi);
9696
9697         BlitBitmap(gd->bitmap, drawto, gd->src_x, gd->src_y,
9698                    gi->width, gi->height, gi->x, gi->y);
9699
9700         redraw_mask |= REDRAW_DOOR_3;
9701       }
9702     }
9703   }
9704 }
9705
9706 static void MapLevelEditorToolboxDrawingGadgets(void)
9707 {
9708   MapOrUnmapLevelEditorToolboxDrawingGadgets(TRUE);
9709 }
9710
9711 static void UnmapLevelEditorToolboxDrawingGadgets(void)
9712 {
9713   MapOrUnmapLevelEditorToolboxDrawingGadgets(FALSE);
9714 }
9715
9716 static void UnmapDrawingArea(int id)
9717 {
9718   UnmapGadget(level_editor_gadget[drawingarea_info[id].gadget_id]);
9719 }
9720
9721 static void UnmapLevelEditorFieldGadgets(void)
9722 {
9723   int i;
9724
9725   for (i = 0; i < num_editor_gadgets; i++)
9726     if (IN_GFX_FIELD_FULL(level_editor_gadget[i]->x,
9727                           level_editor_gadget[i]->y))
9728       UnmapGadget(level_editor_gadget[i]);
9729 }
9730
9731 void UnmapLevelEditorGadgets(void)
9732 {
9733   int i;
9734
9735   for (i = 0; i < num_editor_gadgets; i++)
9736     UnmapGadget(level_editor_gadget[i]);
9737 }
9738
9739 static void ResetUndoBuffer(void)
9740 {
9741   undo_buffer_position = -1;
9742   undo_buffer_steps = -1;
9743   redo_buffer_steps = 0;
9744
9745   CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
9746
9747   level.changed = FALSE;
9748 }
9749
9750 static void DrawEditModeWindowExt(boolean remap_toolbox_gadgets)
9751 {
9752   if (remap_toolbox_gadgets)
9753   {
9754     ModifyEditorElementList();
9755     RedrawDrawingElements();
9756   }
9757
9758   if (edit_mode == ED_MODE_LEVELCONFIG)
9759     DrawLevelConfigWindow();
9760   else if (edit_mode == ED_MODE_PROPERTIES)
9761     DrawPropertiesWindow();
9762   else if (edit_mode == ED_MODE_PALETTE)
9763     DrawPaletteWindow();
9764   else  // edit_mode == ED_MODE_DRAWING
9765     DrawDrawingWindowExt(remap_toolbox_gadgets);
9766 }
9767
9768 static void DrawEditModeWindow(void)
9769 {
9770   DrawEditModeWindowExt(TRUE);
9771 }
9772
9773 static void DrawEditModeWindow_PlayfieldOnly(void)
9774 {
9775   DrawEditModeWindowExt(FALSE);
9776 }
9777
9778 static void ChangeEditModeWindow(int new_edit_mode)
9779 {
9780   edit_mode = (new_edit_mode != edit_mode ? new_edit_mode : ED_MODE_DRAWING);
9781
9782   DrawEditModeWindow();
9783 }
9784
9785 static boolean LevelChanged(void)
9786 {
9787   boolean field_changed = FALSE;
9788   int x, y;
9789
9790   for (y = 0; y < lev_fieldy; y++) 
9791     for (x = 0; x < lev_fieldx; x++)
9792       if (Tile[x][y] != level.field[x][y])
9793         field_changed = TRUE;
9794
9795   return (level.changed || field_changed);
9796 }
9797
9798 static boolean PrepareSavingIntoPersonalLevelSet(void)
9799 {
9800   static LevelDirTree *last_copied_leveldir = NULL;
9801   static LevelDirTree *last_written_leveldir = NULL;
9802   static int last_copied_level_nr = -1;
9803   static int last_written_level_nr = -1;
9804   LevelDirTree *leveldir_former = leveldir_current;
9805   int level_nr_former = level_nr;
9806   int new_level_nr;
9807
9808   // remember last mod/save so that for current session, we write
9809   // back to the same personal copy, asking only about overwrite.
9810   if (leveldir_current == last_copied_leveldir &&
9811       level_nr == last_copied_level_nr)
9812   {
9813     // "cd" to personal level set dir (as used when writing last copy)
9814     leveldir_current = last_written_leveldir;
9815     level_nr = last_written_level_nr;
9816
9817     return TRUE;
9818   }
9819
9820   if (!Request("This level is read-only! "
9821                "Save into personal level set?", REQ_ASK))
9822     return FALSE;
9823
9824   // "cd" to personal level set dir (for writing copy the first time)
9825   leveldir_current =
9826     getTreeInfoFromIdentifier(leveldir_first, getLoginName());
9827
9828   // this may happen if "setup.internal.create_user_levelset" is FALSE
9829   // or if file "levelinfo.conf" is missing in personal user level set
9830   if (leveldir_current == NULL)
9831   {
9832     Request("Cannot find personal level set?!", REQ_CONFIRM);
9833
9834     leveldir_current = leveldir_former;
9835
9836     return FALSE;
9837   }
9838
9839   // find unused level number
9840   for (new_level_nr = leveldir_current->first_level; ; new_level_nr++)
9841   {
9842     static char *level_filename = NULL;
9843
9844     setString(&level_filename, getDefaultLevelFilename(new_level_nr));
9845
9846     if (!fileExists(level_filename))
9847       break;
9848   }
9849
9850   last_copied_leveldir = leveldir_former;
9851   last_copied_level_nr = level_nr_former;
9852
9853   last_written_leveldir = leveldir_current;
9854   last_written_level_nr = level_nr = new_level_nr;
9855
9856   return TRUE;
9857 }
9858
9859 static void ModifyLevelConfigForSavingIntoPersonalLevelSet(char *former_name)
9860 {
9861   static char *filename_levelinfo = NULL, *mod_name = NULL;
9862   FILE *file;
9863
9864   // annotate this copy-and-mod in personal levelinfo.conf
9865   setString(&filename_levelinfo,
9866             getPath2(getCurrentLevelDir(), LEVELINFO_FILENAME));
9867
9868   if ((file = fopen(filename_levelinfo, MODE_APPEND)))
9869   {
9870     fprintf(file, "\n");
9871     fprintf(file, "# level %d was modified from:\n", level_nr);
9872     fprintf(file, "# - previous level set name:    %s\n",
9873             former_name);
9874     fprintf(file, "# - level within previous set:  %d \"%s\"\n",
9875             level.file_info.nr, level.name);
9876     fprintf(file, "# - previous author:            %s\n",
9877             level.author);
9878     fprintf(file, "# - previous save date:         ");
9879
9880     if (level.creation_date.src == DATE_SRC_LEVELFILE)
9881     {
9882       fprintf(file, "%04d-%02d-%02d\n",
9883               level.creation_date.year,
9884               level.creation_date.month,
9885               level.creation_date.day);
9886     }
9887     else
9888     {
9889       fprintf(file, "not recorded\n");
9890     }
9891
9892     fclose(file);
9893   }
9894
9895   if (level_nr > leveldir_current->last_level)
9896     UpdateUserLevelSet(getLoginName(), NULL, NULL, level_nr + 9);
9897
9898   // else: allow the save even if annotation failed
9899
9900   // now... spray graffiti on the old level vital statistics
9901   // user can change these; just trying to set a good baseline
9902
9903   // don't truncate names for fear of making offensive or silly:
9904   // long-named original author only recorded in levelinfo.conf.
9905   // try to fit "Joe after Bob", "Joe (ed.)", then just "Joe"
9906   if (!strEqual(level.author, leveldir_current->author))
9907   {
9908     setString(&mod_name, getStringCat3(leveldir_current->author,
9909                                        " after ", level.author));
9910
9911     if (strlen(mod_name) > MAX_LEVEL_AUTHOR_LEN)
9912       setString(&mod_name,
9913                 getStringCat2(leveldir_current->author, " (ed.)"));
9914
9915     if (strlen(mod_name) > MAX_LEVEL_AUTHOR_LEN)
9916       setString(&mod_name, leveldir_current->author);
9917
9918     strncpy(level.author, mod_name, MAX_LEVEL_AUTHOR_LEN);
9919
9920     // less worried about truncation here
9921     setString(&mod_name, getStringCat2("Mod: ", level.name));
9922     strncpy(level.name, mod_name, MAX_LEVEL_NAME_LEN);
9923   }
9924 }
9925
9926 static void CopyPlayfield(short src[MAX_LEV_FIELDX][MAX_LEV_FIELDY],
9927                           short dst[MAX_LEV_FIELDX][MAX_LEV_FIELDY])
9928 {
9929   int x, y;
9930
9931   for (x = 0; x < lev_fieldx; x++)
9932     for (y = 0; y < lev_fieldy; y++) 
9933       dst[x][y] = src[x][y];
9934 }
9935
9936 static int setSelectboxValue(int selectbox_id, int new_value)
9937 {
9938   int new_index_value = 0;
9939   int i;
9940
9941   for (i = 0; selectbox_info[selectbox_id].options[i].text != NULL; i++)
9942     if (selectbox_info[selectbox_id].options[i].value == new_value)
9943       new_index_value = i;
9944
9945   *selectbox_info[selectbox_id].value =
9946     selectbox_info[selectbox_id].options[new_index_value].value;
9947
9948   return new_index_value;
9949 }
9950
9951 static void setSelectboxSpecialActionVariablesIfNeeded(void)
9952 {
9953   int i;
9954
9955   // change action mode and arg variables according to action type variable
9956   for (i = 0; action_arg_options[i].value != -1; i++)
9957   {
9958     if (action_arg_options[i].value == custom_element_change.action_type)
9959     {
9960       int mode = action_arg_options[i].mode;
9961
9962       // only change if corresponding selectbox has changed
9963       if (selectbox_info[ED_SELECTBOX_ID_ACTION_MODE].options !=
9964           action_arg_modes[mode])
9965         custom_element_change.action_mode = -1;
9966
9967       // only change if corresponding selectbox has changed
9968       if (selectbox_info[ED_SELECTBOX_ID_ACTION_ARG].options !=
9969           action_arg_options[i].options)
9970         custom_element_change.action_arg = -1;
9971
9972       break;
9973     }
9974   }
9975 }
9976
9977 static void setSelectboxSpecialActionOptions(void)
9978 {
9979   int i;
9980
9981   // change action mode and arg selectbox according to action type selectbox
9982   for (i = 0; action_arg_options[i].value != -1; i++)
9983   {
9984     if (action_arg_options[i].value == custom_element_change.action_type)
9985     {
9986       int mode = action_arg_options[i].mode;
9987
9988       ModifyEditorSelectboxOptions(ED_SELECTBOX_ID_ACTION_MODE,
9989                                    action_arg_modes[mode]);
9990       ModifyEditorSelectboxValue(ED_SELECTBOX_ID_ACTION_MODE,
9991                                  custom_element_change.action_mode);
9992
9993       ModifyEditorSelectboxOptions(ED_SELECTBOX_ID_ACTION_ARG,
9994                                    action_arg_options[i].options);
9995       ModifyEditorSelectboxValue(ED_SELECTBOX_ID_ACTION_ARG,
9996                                  custom_element_change.action_arg);
9997       break;
9998     }
9999   }
10000 }
10001
10002 static void copy_custom_element_settings(int element_from, int element_to)
10003 {
10004   struct ElementInfo *ei_from = &element_info[element_from];
10005   struct ElementInfo *ei_to = &element_info[element_to];
10006
10007   copyElementInfo(ei_from, ei_to);
10008 }
10009
10010 static void replace_custom_element_in_settings(int element_from,
10011                                                int element_to)
10012 {
10013   int i, j, x, y;
10014
10015   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
10016   {
10017     struct ElementInfo *ei = &element_info[i];
10018
10019     for (y = 0; y < 3; y++)
10020       for (x = 0; x < 3; x++)
10021         if (ei->content.e[x][y] == element_from)
10022           ei->content.e[x][y] = element_to;
10023
10024     for (j = 0; j < ei->num_change_pages; j++)
10025     {
10026       struct ElementChangeInfo *change = &ei->change_page[j];
10027
10028       if (change->target_element == element_from)
10029         change->target_element = element_to;
10030
10031       if (change->initial_trigger_element == element_from)
10032         change->initial_trigger_element = element_to;
10033
10034       if (change->action_element == element_from)
10035         change->action_element = element_to;
10036
10037       for (y = 0; y < 3; y++)
10038         for (x = 0; x < 3; x++)
10039           if (change->target_content.e[x][y] == element_from)
10040             change->target_content.e[x][y] = element_to;
10041     }
10042
10043     if (ei->group != NULL)                              // group or internal
10044       for (j = 0; j < MAX_ELEMENTS_IN_GROUP; j++)
10045         if (ei->group->element[j] == element_from)
10046           ei->group->element[j] = element_to;
10047   }
10048 }
10049
10050 static void replace_custom_element_in_playfield(int element_from,
10051                                                 int element_to)
10052 {
10053   int x, y;
10054
10055   for (x = 0; x < lev_fieldx; x++)
10056     for (y = 0; y < lev_fieldy; y++)
10057       if (Tile[x][y] == element_from)
10058         Tile[x][y] = element_to;
10059 }
10060
10061 static boolean CopyCustomElement(int element_old, int element_new,
10062                                  int copy_mode)
10063 {
10064   int copy_mode_orig = copy_mode;
10065
10066   if (copy_mode == GADGET_ID_CUSTOM_COPY)
10067   {
10068     element_new = (IS_CUSTOM_ELEMENT(element_old) ?
10069                    EL_INTERNAL_CLIPBOARD_CUSTOM : EL_INTERNAL_CLIPBOARD_GROUP);
10070     copy_mode = GADGET_ID_CUSTOM_COPY_TO;
10071   }
10072   else if (copy_mode == GADGET_ID_CUSTOM_PASTE)
10073   {
10074     element_old = (IS_CUSTOM_ELEMENT(element_new) ?
10075                    EL_INTERNAL_CLIPBOARD_CUSTOM : EL_INTERNAL_CLIPBOARD_GROUP);
10076     copy_mode = GADGET_ID_CUSTOM_COPY_TO;
10077
10078     level.changed = TRUE;
10079   }
10080   else if (IS_CUSTOM_ELEMENT(element_old) && !IS_CUSTOM_ELEMENT(element_new))
10081   {
10082     Request("Please choose custom element!", REQ_CONFIRM);
10083
10084     return FALSE;
10085   }
10086   else if (IS_GROUP_ELEMENT(element_old) && !IS_GROUP_ELEMENT(element_new))
10087   {
10088     Request("Please choose group element!", REQ_CONFIRM);
10089
10090     return FALSE;
10091   }
10092   else if (IS_EMPTY_ELEMENT(element_old) && !IS_EMPTY_ELEMENT(element_new))
10093   {
10094     Request("Please choose empty element!", REQ_CONFIRM);
10095
10096     return FALSE;
10097   }
10098   else
10099   {
10100     level.changed = TRUE;
10101   }
10102
10103   // when modifying custom/group element, ask for copying level template
10104   if (copy_mode_orig != GADGET_ID_CUSTOM_COPY && level.use_custom_template)
10105   {
10106     if (!AskToCopyAndModifyLevelTemplate())
10107       return FALSE;
10108   }
10109
10110   if (copy_mode == GADGET_ID_CUSTOM_COPY_FROM)
10111   {
10112     copy_custom_element_settings(element_new, element_old);
10113   }
10114   else if (copy_mode == GADGET_ID_CUSTOM_COPY_TO)
10115   {
10116     copy_custom_element_settings(element_old, element_new);
10117   }
10118   else if (copy_mode == GADGET_ID_CUSTOM_EXCHANGE)
10119   {
10120     copy_custom_element_settings(element_old, EL_INTERNAL_DUMMY);
10121     copy_custom_element_settings(element_new, element_old);
10122     copy_custom_element_settings(EL_INTERNAL_DUMMY, element_new);
10123
10124     replace_custom_element_in_settings(element_old, EL_INTERNAL_DUMMY);
10125     replace_custom_element_in_settings(element_new, element_old);
10126     replace_custom_element_in_settings(EL_INTERNAL_DUMMY, element_new);
10127
10128     replace_custom_element_in_playfield(element_old, EL_INTERNAL_DUMMY);
10129     replace_custom_element_in_playfield(element_new, element_old);
10130     replace_custom_element_in_playfield(EL_INTERNAL_DUMMY, element_new);
10131   }
10132
10133   UpdateCustomElementGraphicGadgets();
10134   DrawPropertiesWindow();
10135
10136   return TRUE;
10137 }
10138
10139 static void CopyCustomElementPropertiesToEditor(int element)
10140 {
10141   int i;
10142   int current_change_page = element_info[element].current_change_page;
10143
10144   // dynamically (re)build selectbox for selecting change page
10145   for (i = 0; i < element_info[element].num_change_pages; i++)
10146   {
10147     sprintf(options_change_page_strings[i], "%d", i + 1);
10148
10149     options_change_page[i].value = i;
10150     options_change_page[i].text = options_change_page_strings[i];
10151   }
10152
10153   options_change_page[i].value = -1;
10154   options_change_page[i].text = NULL;
10155
10156   // needed here to initialize combined element properties
10157   InitElementPropertiesEngine(level.game_version);
10158
10159   element_info[element].change =
10160     &element_info[element].change_page[current_change_page];
10161
10162   custom_element = element_info[element];
10163   custom_element_change = *element_info[element].change;
10164
10165   // needed to initially set selectbox options for special action options
10166   setSelectboxSpecialActionOptions();
10167
10168   // needed to initially set selectbox value variables to reliable defaults
10169   for (i = 0; i < ED_NUM_SELECTBOX; i++)
10170     setSelectboxValue(i, *selectbox_info[i].value);
10171
10172   for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
10173     custom_element_properties[i] = HAS_PROPERTY(element, i);
10174
10175   for (i = 0; i < NUM_CHANGE_EVENTS; i++)
10176     custom_element_change_events[i] = HAS_CHANGE_EVENT(element, i);
10177
10178   // ---------- element settings: configure (custom elements) -----------------
10179
10180   // set accessible layer selectbox help value
10181   custom_element.access_type =
10182     (IS_WALKABLE(element) ? EP_WALKABLE :
10183      IS_PASSABLE(element) ? EP_PASSABLE :
10184      custom_element.access_type);
10185   custom_element.access_layer =
10186     (IS_ACCESSIBLE_OVER(element) ? EP_ACCESSIBLE_OVER :
10187      IS_ACCESSIBLE_INSIDE(element) ? EP_ACCESSIBLE_INSIDE :
10188      IS_ACCESSIBLE_UNDER(element) ? EP_ACCESSIBLE_UNDER :
10189      custom_element.access_layer);
10190   custom_element.access_protected =
10191     (IS_PROTECTED(element) ? 1 : 0);
10192   custom_element_properties[EP_ACCESSIBLE] =
10193     (IS_ACCESSIBLE_OVER(element) ||
10194      IS_ACCESSIBLE_INSIDE(element) ||
10195      IS_ACCESSIBLE_UNDER(element));
10196
10197   // set walk-to-object action selectbox help value
10198   custom_element.walk_to_action =
10199     (IS_DIGGABLE(element) ? EP_DIGGABLE :
10200      IS_COLLECTIBLE_ONLY(element) ? EP_COLLECTIBLE_ONLY :
10201      IS_DROPPABLE(element) ? EP_DROPPABLE :
10202      IS_THROWABLE(element) ? EP_THROWABLE :
10203      IS_PUSHABLE(element) ? EP_PUSHABLE :
10204      custom_element.walk_to_action);
10205   custom_element_properties[EP_WALK_TO_OBJECT] =
10206     (IS_DIGGABLE(element) ||
10207      IS_COLLECTIBLE_ONLY(element) ||
10208      IS_DROPPABLE(element) ||
10209      IS_THROWABLE(element) ||
10210      IS_PUSHABLE(element));
10211
10212   // set smash targets selectbox help value
10213   custom_element.smash_targets =
10214     (CAN_SMASH_EVERYTHING(element) ? EP_CAN_SMASH_EVERYTHING :
10215      CAN_SMASH_ENEMIES(element) ? EP_CAN_SMASH_ENEMIES :
10216      CAN_SMASH_PLAYER(element) ? EP_CAN_SMASH_PLAYER :
10217      custom_element.smash_targets);
10218   custom_element_properties[EP_CAN_SMASH] =
10219     (CAN_SMASH_EVERYTHING(element) ||
10220      CAN_SMASH_ENEMIES(element) ||
10221      CAN_SMASH_PLAYER(element));
10222
10223   // set deadliness selectbox help value
10224   custom_element.deadliness =
10225     (DONT_TOUCH(element) ? EP_DONT_TOUCH :
10226      DONT_GET_HIT_BY(element) ? EP_DONT_GET_HIT_BY :
10227      DONT_COLLIDE_WITH(element) ? EP_DONT_COLLIDE_WITH :
10228      DONT_RUN_INTO(element) ? EP_DONT_RUN_INTO :
10229      custom_element.deadliness);
10230   custom_element_properties[EP_DEADLY] =
10231     (DONT_TOUCH(element) ||
10232      DONT_GET_HIT_BY(element) ||
10233      DONT_COLLIDE_WITH(element) ||
10234      DONT_RUN_INTO(element));
10235
10236   // ---------- element settings: advanced (custom elements) ------------------
10237
10238   // set "change by direct action" selectbox help value
10239   custom_element_change.direct_action =
10240     (HAS_CHANGE_EVENT(element, CE_NEXT_TO_PLAYER) ? CE_NEXT_TO_PLAYER :
10241      HAS_CHANGE_EVENT(element, CE_TOUCHED_BY_PLAYER) ? CE_TOUCHED_BY_PLAYER :
10242      HAS_CHANGE_EVENT(element, CE_PRESSED_BY_PLAYER) ? CE_PRESSED_BY_PLAYER :
10243      HAS_CHANGE_EVENT(element, CE_SWITCHED_BY_PLAYER) ? CE_SWITCHED_BY_PLAYER :
10244      HAS_CHANGE_EVENT(element, CE_SNAPPED_BY_PLAYER) ? CE_SNAPPED_BY_PLAYER :
10245      HAS_CHANGE_EVENT(element, CE_PUSHED_BY_PLAYER) ? CE_PUSHED_BY_PLAYER :
10246      HAS_CHANGE_EVENT(element, CE_ENTERED_BY_PLAYER) ? CE_ENTERED_BY_PLAYER :
10247      HAS_CHANGE_EVENT(element, CE_LEFT_BY_PLAYER) ? CE_LEFT_BY_PLAYER :
10248      HAS_CHANGE_EVENT(element, CE_DROPPED_BY_PLAYER) ? CE_DROPPED_BY_PLAYER :
10249      HAS_CHANGE_EVENT(element, CE_SWITCHED) ? CE_SWITCHED :
10250      HAS_CHANGE_EVENT(element, CE_HITTING_SOMETHING) ? CE_HITTING_SOMETHING :
10251      HAS_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING) ? CE_HIT_BY_SOMETHING :
10252      HAS_CHANGE_EVENT(element, CE_BLOCKED) ? CE_BLOCKED :
10253      HAS_CHANGE_EVENT(element, CE_IMPACT) ? CE_IMPACT :
10254      HAS_CHANGE_EVENT(element, CE_SMASHED) ? CE_SMASHED :
10255      HAS_CHANGE_EVENT(element, CE_VALUE_CHANGES) ? CE_VALUE_CHANGES :
10256      HAS_CHANGE_EVENT(element, CE_SCORE_CHANGES) ? CE_SCORE_CHANGES :
10257      HAS_CHANGE_EVENT(element, CE_VALUE_GETS_ZERO) ? CE_VALUE_GETS_ZERO :
10258      HAS_CHANGE_EVENT(element, CE_SCORE_GETS_ZERO) ? CE_SCORE_GETS_ZERO :
10259      HAS_CHANGE_EVENT(element, CE_CLICKED_BY_MOUSE) ? CE_CLICKED_BY_MOUSE :
10260      HAS_CHANGE_EVENT(element, CE_PRESSED_BY_MOUSE) ? CE_PRESSED_BY_MOUSE :
10261      custom_element_change.direct_action);
10262
10263   // set "change by other element action" selectbox help value
10264   custom_element_change.other_action =
10265     (HAS_CHANGE_EVENT(element, CE_PLAYER_NEXT_TO_X) ? CE_PLAYER_NEXT_TO_X :
10266      HAS_CHANGE_EVENT(element, CE_PLAYER_TOUCHES_X) ? CE_PLAYER_TOUCHES_X :
10267      HAS_CHANGE_EVENT(element, CE_PLAYER_PRESSES_X) ? CE_PLAYER_PRESSES_X :
10268      HAS_CHANGE_EVENT(element, CE_PLAYER_SWITCHES_X) ? CE_PLAYER_SWITCHES_X :
10269      HAS_CHANGE_EVENT(element, CE_PLAYER_SNAPS_X) ? CE_PLAYER_SNAPS_X :
10270      HAS_CHANGE_EVENT(element, CE_PLAYER_PUSHES_X) ? CE_PLAYER_PUSHES_X :
10271      HAS_CHANGE_EVENT(element, CE_PLAYER_ENTERS_X) ? CE_PLAYER_ENTERS_X :
10272      HAS_CHANGE_EVENT(element, CE_PLAYER_LEAVES_X) ? CE_PLAYER_LEAVES_X :
10273      HAS_CHANGE_EVENT(element, CE_PLAYER_DIGS_X) ? CE_PLAYER_DIGS_X :
10274      HAS_CHANGE_EVENT(element, CE_PLAYER_COLLECTS_X) ? CE_PLAYER_COLLECTS_X :
10275      HAS_CHANGE_EVENT(element, CE_PLAYER_DROPS_X) ? CE_PLAYER_DROPS_X :
10276      HAS_CHANGE_EVENT(element, CE_NEXT_TO_X) ? CE_NEXT_TO_X :
10277      HAS_CHANGE_EVENT(element, CE_TOUCHING_X) ? CE_TOUCHING_X :
10278      HAS_CHANGE_EVENT(element, CE_HITTING_X) ? CE_HITTING_X :
10279      HAS_CHANGE_EVENT(element, CE_DIGGING_X) ? CE_DIGGING_X :
10280      HAS_CHANGE_EVENT(element, CE_HIT_BY_X) ? CE_HIT_BY_X :
10281      HAS_CHANGE_EVENT(element, CE_SWITCH_OF_X) ? CE_SWITCH_OF_X :
10282      HAS_CHANGE_EVENT(element, CE_CHANGE_OF_X) ? CE_CHANGE_OF_X :
10283      HAS_CHANGE_EVENT(element, CE_EXPLOSION_OF_X) ? CE_EXPLOSION_OF_X :
10284      HAS_CHANGE_EVENT(element, CE_MOVE_OF_X) ? CE_MOVE_OF_X :
10285      HAS_CHANGE_EVENT(element, CE_CREATION_OF_X) ? CE_CREATION_OF_X :
10286      HAS_CHANGE_EVENT(element, CE_VALUE_CHANGES_OF_X) ? CE_VALUE_CHANGES_OF_X :
10287      HAS_CHANGE_EVENT(element, CE_SCORE_CHANGES_OF_X) ? CE_SCORE_CHANGES_OF_X :
10288      HAS_CHANGE_EVENT(element, CE_VALUE_GETS_ZERO_OF_X) ? CE_VALUE_GETS_ZERO_OF_X :
10289      HAS_CHANGE_EVENT(element, CE_SCORE_GETS_ZERO_OF_X) ? CE_SCORE_GETS_ZERO_OF_X :
10290      HAS_CHANGE_EVENT(element, CE_MOUSE_CLICKED_ON_X) ? CE_MOUSE_CLICKED_ON_X :
10291      HAS_CHANGE_EVENT(element, CE_MOUSE_PRESSED_ON_X) ? CE_MOUSE_PRESSED_ON_X :
10292      custom_element_change.other_action);
10293 }
10294
10295 static void CopyGroupElementPropertiesToEditor(int element)
10296 {
10297   group_element_info = *element_info[element].group;
10298   custom_element = element_info[element];       // needed for description
10299 }
10300
10301 static void CopyEmptyElementPropertiesToEditor(int element)
10302 {
10303   custom_element = element_info[element];
10304 }
10305
10306 static void CopyClassicElementPropertiesToEditor(int element)
10307 {
10308   if (IS_PLAYER_ELEMENT(element) || COULD_MOVE_INTO_ACID(element))
10309     custom_element_properties[EP_CAN_MOVE_INTO_ACID] =
10310       getMoveIntoAcidProperty(&level, element);
10311
10312   if (MAYBE_DONT_COLLIDE_WITH(element))
10313     custom_element_properties[EP_DONT_COLLIDE_WITH] =
10314       getDontCollideWithProperty(&level, element);
10315 }
10316
10317 static void CopyElementPropertiesToEditor(int element)
10318 {
10319   if (IS_CUSTOM_ELEMENT(element))
10320     CopyCustomElementPropertiesToEditor(element);
10321   else if (IS_GROUP_ELEMENT(element))
10322     CopyGroupElementPropertiesToEditor(element);
10323   else if (IS_EMPTY_ELEMENT(element))
10324     CopyEmptyElementPropertiesToEditor(element);
10325   else
10326     CopyClassicElementPropertiesToEditor(element);
10327 }
10328
10329 static boolean AskToCopyAndModifyLevelTemplate(void)
10330 {
10331   if (Request("Copy and modify settings from level template?", REQ_ASK))
10332   {
10333     level.use_custom_template = FALSE;
10334
10335     ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE_1],
10336                  GDI_CHECKED, FALSE, GDI_END);
10337     ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE_2],
10338                  GDI_CHECKED, FALSE, GDI_END);
10339
10340     return TRUE;
10341   }
10342   else
10343   {
10344     LoadLevelTemplate(-1);      // this resets all element modifications ...
10345
10346     DrawEditModeWindow();       // ... and copies them to 'custom_element'
10347
10348     return FALSE;
10349   }
10350 }
10351
10352 static void CopyCustomElementPropertiesToGame(int element)
10353 {
10354   int i;
10355   int access_type_and_layer;
10356
10357   // mark that this custom element has been modified
10358   custom_element.modified_settings = TRUE;
10359   level.changed = TRUE;
10360
10361   if (level.use_custom_template)
10362     AskToCopyAndModifyLevelTemplate();
10363
10364   element_info[element] = custom_element;
10365   *element_info[element].change = custom_element_change;
10366
10367   // ---------- element settings: configure (custom elements) -----------------
10368
10369   // set accessible property from checkbox and selectbox
10370   custom_element_properties[EP_WALKABLE_OVER] = FALSE;
10371   custom_element_properties[EP_WALKABLE_INSIDE] = FALSE;
10372   custom_element_properties[EP_WALKABLE_UNDER] = FALSE;
10373   custom_element_properties[EP_PASSABLE_OVER] = FALSE;
10374   custom_element_properties[EP_PASSABLE_INSIDE] = FALSE;
10375   custom_element_properties[EP_PASSABLE_UNDER] = FALSE;
10376   access_type_and_layer = ((custom_element.access_type == EP_WALKABLE ?
10377                             EP_WALKABLE_OVER : EP_PASSABLE_OVER) +
10378                            (custom_element.access_layer - EP_ACCESSIBLE_OVER));
10379   custom_element_properties[access_type_and_layer] =
10380     custom_element_properties[EP_ACCESSIBLE];
10381   custom_element_properties[EP_PROTECTED] =
10382     (custom_element.access_protected != 0 &&
10383      custom_element_properties[EP_ACCESSIBLE]);
10384
10385   // set walk-to-object property from checkbox and selectbox
10386   custom_element_properties[EP_DIGGABLE] = FALSE;
10387   custom_element_properties[EP_COLLECTIBLE_ONLY] = FALSE;
10388   custom_element_properties[EP_DROPPABLE] = FALSE;
10389   custom_element_properties[EP_THROWABLE] = FALSE;
10390   custom_element_properties[EP_PUSHABLE] = FALSE;
10391   custom_element_properties[custom_element.walk_to_action] =
10392     custom_element_properties[EP_WALK_TO_OBJECT];
10393
10394   // set smash property from checkbox and selectbox
10395   custom_element_properties[EP_CAN_SMASH_PLAYER] = FALSE;
10396   custom_element_properties[EP_CAN_SMASH_ENEMIES] = FALSE;
10397   custom_element_properties[EP_CAN_SMASH_EVERYTHING] = FALSE;
10398   custom_element_properties[custom_element.smash_targets] =
10399     custom_element_properties[EP_CAN_SMASH];
10400
10401   // set deadliness property from checkbox and selectbox
10402   custom_element_properties[EP_DONT_RUN_INTO] = FALSE;
10403   custom_element_properties[EP_DONT_COLLIDE_WITH] = FALSE;
10404   custom_element_properties[EP_DONT_GET_HIT_BY] = FALSE;
10405   custom_element_properties[EP_DONT_TOUCH] = FALSE;
10406   custom_element_properties[custom_element.deadliness] =
10407     custom_element_properties[EP_DEADLY];
10408
10409   // ---------- element settings: advanced (custom elements) ------------------
10410
10411   // set player change event from checkbox and selectbox
10412   custom_element_change_events[CE_NEXT_TO_PLAYER] = FALSE;
10413   custom_element_change_events[CE_TOUCHED_BY_PLAYER] = FALSE;
10414   custom_element_change_events[CE_PRESSED_BY_PLAYER] = FALSE;
10415   custom_element_change_events[CE_SWITCHED_BY_PLAYER] = FALSE;
10416   custom_element_change_events[CE_SNAPPED_BY_PLAYER] = FALSE;
10417   custom_element_change_events[CE_PUSHED_BY_PLAYER] = FALSE;
10418   custom_element_change_events[CE_ENTERED_BY_PLAYER] = FALSE;
10419   custom_element_change_events[CE_LEFT_BY_PLAYER] = FALSE;
10420   custom_element_change_events[CE_DROPPED_BY_PLAYER] = FALSE;
10421   custom_element_change_events[CE_SWITCHED] = FALSE;
10422   custom_element_change_events[CE_HITTING_SOMETHING] = FALSE;
10423   custom_element_change_events[CE_HIT_BY_SOMETHING] = FALSE;
10424   custom_element_change_events[CE_BLOCKED] = FALSE;
10425   custom_element_change_events[CE_IMPACT] = FALSE;
10426   custom_element_change_events[CE_SMASHED] = FALSE;
10427   custom_element_change_events[CE_VALUE_CHANGES] = FALSE;
10428   custom_element_change_events[CE_SCORE_CHANGES] = FALSE;
10429   custom_element_change_events[CE_VALUE_GETS_ZERO] = FALSE;
10430   custom_element_change_events[CE_SCORE_GETS_ZERO] = FALSE;
10431   custom_element_change_events[CE_CLICKED_BY_MOUSE] = FALSE;
10432   custom_element_change_events[CE_PRESSED_BY_MOUSE] = FALSE;
10433   custom_element_change_events[custom_element_change.direct_action] =
10434     custom_element_change_events[CE_BY_DIRECT_ACTION];
10435
10436   // set other element action change event from checkbox and selectbox
10437   custom_element_change_events[CE_PLAYER_NEXT_TO_X] = FALSE;
10438   custom_element_change_events[CE_PLAYER_TOUCHES_X] = FALSE;
10439   custom_element_change_events[CE_PLAYER_PRESSES_X] = FALSE;
10440   custom_element_change_events[CE_PLAYER_SWITCHES_X] = FALSE;
10441   custom_element_change_events[CE_PLAYER_SNAPS_X] = FALSE;
10442   custom_element_change_events[CE_PLAYER_PUSHES_X] = FALSE;
10443   custom_element_change_events[CE_PLAYER_ENTERS_X] = FALSE;
10444   custom_element_change_events[CE_PLAYER_LEAVES_X] = FALSE;
10445   custom_element_change_events[CE_PLAYER_DIGS_X] = FALSE;
10446   custom_element_change_events[CE_PLAYER_COLLECTS_X] = FALSE;
10447   custom_element_change_events[CE_PLAYER_DROPS_X] = FALSE;
10448   custom_element_change_events[CE_NEXT_TO_X] = FALSE;
10449   custom_element_change_events[CE_TOUCHING_X] = FALSE;
10450   custom_element_change_events[CE_HITTING_X] = FALSE;
10451   custom_element_change_events[CE_DIGGING_X] = FALSE;
10452   custom_element_change_events[CE_HIT_BY_X] = FALSE;
10453   custom_element_change_events[CE_SWITCH_OF_X] = FALSE;
10454   custom_element_change_events[CE_CHANGE_OF_X] = FALSE;
10455   custom_element_change_events[CE_EXPLOSION_OF_X] = FALSE;
10456   custom_element_change_events[CE_MOVE_OF_X] = FALSE;
10457   custom_element_change_events[CE_CREATION_OF_X] = FALSE;
10458   custom_element_change_events[CE_VALUE_CHANGES_OF_X] = FALSE;
10459   custom_element_change_events[CE_SCORE_CHANGES_OF_X] = FALSE;
10460   custom_element_change_events[CE_VALUE_GETS_ZERO_OF_X] = FALSE;
10461   custom_element_change_events[CE_SCORE_GETS_ZERO_OF_X] = FALSE;
10462   custom_element_change_events[CE_MOUSE_CLICKED_ON_X] = FALSE;
10463   custom_element_change_events[CE_MOUSE_PRESSED_ON_X] = FALSE;
10464   custom_element_change_events[custom_element_change.other_action] =
10465     custom_element_change_events[CE_BY_OTHER_ACTION];
10466
10467   for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
10468     SET_PROPERTY(element, i, custom_element_properties[i]);
10469
10470   for (i = 0; i < NUM_CHANGE_EVENTS; i++)
10471     SET_CHANGE_EVENT(element, i, custom_element_change_events[i]);
10472
10473   // copy change events also to special level editor variable
10474   custom_element = element_info[element];
10475   custom_element_change = *element_info[element].change;
10476
10477   // needed here to restore runtime value "element_info[element].gfx_element"
10478   InitElementPropertiesGfxElement();
10479 }
10480
10481 static void CopyGroupElementPropertiesToGame(int element)
10482 {
10483   // mark that this group element has been modified
10484   custom_element.modified_settings = TRUE;
10485   level.changed = TRUE;
10486
10487   if (level.use_custom_template)
10488     AskToCopyAndModifyLevelTemplate();
10489
10490   element_info[element] = custom_element;
10491   *element_info[element].group = group_element_info;
10492
10493   // needed here to restore runtime value "element_info[element].gfx_element"
10494   InitElementPropertiesGfxElement();
10495 }
10496
10497 static void CopyEmptyElementPropertiesToGame(int element)
10498 {
10499   // mark that this empty element has been modified
10500   custom_element.modified_settings = TRUE;
10501   level.changed = TRUE;
10502
10503   if (level.use_custom_template)
10504     AskToCopyAndModifyLevelTemplate();
10505
10506   element_info[element] = custom_element;
10507
10508   // needed here to restore runtime value "element_info[element].gfx_element"
10509   InitElementPropertiesGfxElement();
10510 }
10511
10512 static void CopyClassicElementPropertiesToGame(int element)
10513 {
10514   if (IS_PLAYER_ELEMENT(element) || COULD_MOVE_INTO_ACID(element))
10515     setMoveIntoAcidProperty(&level, element,
10516                             custom_element_properties[EP_CAN_MOVE_INTO_ACID]);
10517
10518   if (MAYBE_DONT_COLLIDE_WITH(element))
10519     setDontCollideWithProperty(&level, element,
10520                               custom_element_properties[EP_DONT_COLLIDE_WITH]);
10521 }
10522
10523 static void CopyElementPropertiesToGame(int element)
10524 {
10525   if (IS_CUSTOM_ELEMENT(element))
10526     CopyCustomElementPropertiesToGame(element);
10527   else if (IS_GROUP_ELEMENT(element))
10528     CopyGroupElementPropertiesToGame(element);
10529   else if (IS_EMPTY_ELEMENT(element))
10530     CopyEmptyElementPropertiesToGame(element);
10531   else
10532     CopyClassicElementPropertiesToGame(element);
10533 }
10534
10535 #if DEBUG
10536 static void CheckElementDescriptions(void)
10537 {
10538   int i;
10539
10540   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
10541     if (getElementDescriptionFilename(i) == NULL && !IS_OBSOLETE(i))
10542       Warn("no element description file for element '%s'", EL_NAME(i));
10543 }
10544 #endif
10545
10546 static int getMaxEdFieldX(boolean has_scrollbar)
10547 {
10548   int scrollbar_width = (has_scrollbar ? ED_SCROLLBUTTON_XSIZE : 0);
10549   int sxsize = SXSIZE - scrollbar_width;
10550   int max_ed_fieldx = sxsize / ed_tilesize;
10551
10552   return max_ed_fieldx;
10553 }
10554
10555 static int getMaxEdFieldY(boolean has_scrollbar)
10556 {
10557   int infotext_height = (IN_PIX_FIELD(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY) ?
10558                          INFOTEXT_YSIZE_FULL : 0);
10559   int scrollbar_height = (has_scrollbar ? ED_SCROLLBUTTON_YSIZE : 0);
10560   int sysize = SYSIZE - scrollbar_height - infotext_height;
10561   int max_ed_fieldy = sysize / ed_tilesize;
10562
10563   return max_ed_fieldy;
10564 }
10565
10566 static void InitZoomLevelSettings(int zoom_tilesize)
10567 {
10568   static int last_game_engine_type = GAME_ENGINE_TYPE_UNKNOWN;
10569
10570   if (zoom_tilesize == -1 && level.game_engine_type != last_game_engine_type)
10571   {
10572     ed_tilesize = setup.auto_setup.editor_zoom_tilesize;
10573     ed_tilesize_default = DEFAULT_EDITOR_TILESIZE;
10574
10575     // make sure that tile size is always a power of 2
10576     ed_tilesize = (1 << log_2(ed_tilesize));
10577
10578     if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
10579     {
10580       ed_tilesize = DEFAULT_EDITOR_TILESIZE_MM;
10581       ed_tilesize_default = DEFAULT_EDITOR_TILESIZE_MM;
10582     }
10583   }
10584
10585   last_game_engine_type = level.game_engine_type;
10586
10587   // limit zoom tilesize by upper and lower bound
10588   ed_tilesize = MIN(MAX(MICRO_TILESIZE, ed_tilesize), TILESIZE);
10589
10590   // store zoom tilesize in auto setup file only if it was manually changed
10591   if (zoom_tilesize != -1)
10592     setup.auto_setup.editor_zoom_tilesize = ed_tilesize;
10593
10594   MAX_ED_FIELDX = getMaxEdFieldX(FALSE);
10595   MAX_ED_FIELDY = getMaxEdFieldY(FALSE);
10596 }
10597
10598 static void InitDrawingElements(void)
10599 {
10600   static int game_engine_type_last = GAME_ENGINE_TYPE_UNKNOWN;
10601
10602   if (level.game_engine_type == game_engine_type_last)
10603     return;
10604
10605   // select drawing elements according to game engine type
10606   new_element1 = getDrawingElement(EL_WALL);
10607   new_element2 = getDrawingElement(EL_EMPTY);
10608   new_element3 = getDrawingElement(EL_SAND);
10609
10610   game_engine_type_last = level.game_engine_type;
10611 }
10612
10613 static void InitLevelSetInfo(void)
10614 {
10615   snprintf(levelset_name,   MAX_LEVEL_NAME_LEN + 1,
10616            "%s", leveldir_current->name);
10617   snprintf(levelset_author, MAX_LEVEL_AUTHOR_LEN + 1,
10618            "%s", leveldir_current->author);
10619
10620   levelset_num_levels = leveldir_current->levels;
10621
10622   levelset_use_levelset_artwork = FALSE;
10623   levelset_copy_level_template = FALSE;
10624
10625   levelset_save_mode = LEVELSET_SAVE_MODE_UPDATE;
10626 }
10627
10628 static void ChangeEditorToLevelSet(char *levelset_subdir)
10629 {
10630   leveldir_current = getTreeInfoFromIdentifier(leveldir_first, levelset_subdir);
10631
10632   // the previous level set might have used custom artwork
10633   ReloadCustomArtwork(0);
10634
10635   LoadLevelSetup_SeriesInfo();
10636
10637   SaveLevelSetup_LastSeries();
10638   SaveLevelSetup_SeriesInfo();
10639
10640   TapeErase();
10641
10642   LoadLevel(level_nr);
10643   LoadScore(level_nr);
10644
10645   DrawLevelEd();
10646 }
10647
10648 static boolean useEditorDoorAnimation(void)
10649 {
10650   struct RectWithBorder *vp_door_1 = &viewport.door_1[GAME_MODE_MAIN];
10651   boolean door_1_viewport_unchanged =
10652     (vp_door_1->x      == DX     &&
10653      vp_door_1->y      == DY     &&
10654      vp_door_1->width  == DXSIZE &&
10655      vp_door_1->height == DYSIZE);
10656   boolean door_1_contains_toolbox =
10657     (EX >= DX &&
10658      EY >= DY &&
10659      EX + EXSIZE <= DX + DXSIZE &&
10660      EY + EYSIZE <= DY + DYSIZE);
10661
10662   return (door_1_viewport_unchanged && door_1_contains_toolbox);
10663 }
10664
10665 static void DrawEditorDoorBackground(int graphic, int x, int y,
10666                                      int width, int height)
10667 {
10668   struct GraphicInfo *g = &graphic_info[graphic];
10669
10670   if (g->bitmap != NULL)
10671     BlitBitmap(g->bitmap, drawto, g->src_x, g->src_y,
10672                MIN(width, g->width), MIN(height, g->height), x, y);
10673   else
10674     ClearRectangle(drawto, x, y, width, height);
10675 }
10676
10677 static void DrawEditorDoorContent(void)
10678 {
10679   // needed for gadgets drawn on background (like palette scrollbar)
10680   SetDoorBackgroundImage(IMG_UNDEFINED);
10681
10682   // copy default editor door content to main double buffer
10683   DrawEditorDoorBackground(IMG_BACKGROUND_PALETTE, DX, DY, DXSIZE, DYSIZE);
10684
10685   // draw bigger door
10686   DrawSpecialEditorDoor();
10687
10688   // draw new control window
10689   DrawEditorDoorBackground(IMG_BACKGROUND_TOOLBOX, EX, EY, EXSIZE, EYSIZE);
10690
10691   // draw all toolbox gadgets to editor doors
10692   MapControlButtons();
10693
10694   // when returning from test game to properties page, redraw toolbox gadgets
10695   if (edit_mode == ED_MODE_PROPERTIES)
10696   {
10697     UnmapLevelEditorToolboxDrawingGadgets();
10698     UnmapLevelEditorToolboxCustomGadgets();
10699
10700     MapLevelEditorToolboxCustomGadgetsIfNeeded();
10701   }
10702
10703   // draw all palette gadgets to editor doors
10704   ModifyEditorElementList();
10705   RedrawDrawingElements();
10706
10707   // copy actual editor door content to door double buffer for OpenDoor()
10708   BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
10709 }
10710
10711 void DrawLevelEd(void)
10712 {
10713   int fade_mask = REDRAW_FIELD;
10714
10715   FadeSoundsAndMusic();
10716
10717   if (CheckFadeAll())
10718     fade_mask = REDRAW_ALL;
10719
10720   FadeOut(fade_mask);
10721
10722   // needed if different viewport properties defined for editor
10723   ChangeViewportPropertiesIfNeeded();
10724
10725   ClearField();
10726
10727   InitZoomLevelSettings(-1);
10728   InitDrawingElements();
10729   InitLevelSetInfo();
10730
10731 #if DEBUG
10732   CheckElementDescriptions();
10733 #endif
10734
10735   if (level_editor_test_game)
10736   {
10737     CopyPlayfield(level.field, Tile);
10738     CopyPlayfield(TileBackup, level.field);
10739
10740     level_editor_test_game = FALSE;
10741   }
10742   else
10743   {
10744     edit_mode = ED_MODE_DRAWING;
10745     edit_mode_levelconfig = ED_MODE_LEVELCONFIG_LEVEL;
10746     edit_mode_engineconfig = ED_MODE_ENGINECONFIG_CONFIG;
10747     edit_mode_properties = ED_MODE_PROPERTIES_INFO;
10748
10749     ResetUndoBuffer();
10750
10751     level_xpos = -1;
10752     level_ypos = -1;
10753   }
10754
10755   // redraw_mask |= REDRAW_ALL;
10756
10757   FreeLevelEditorGadgets();
10758   CreateLevelEditorGadgets();
10759
10760   ReinitializeElementList();            // update dynamic level element list
10761   ReinitializeElementListButtons();     // custom element may look different
10762
10763   InitElementPropertiesGfxElement();
10764
10765   UnmapAllGadgets();
10766
10767   DrawEditModeWindow_PlayfieldOnly();
10768
10769   DrawMaskedBorder(fade_mask);
10770
10771   // use door animation if door 1 viewport is unchanged and contains toolbox
10772   if (useEditorDoorAnimation())
10773   {
10774     FadeIn(fade_mask);
10775
10776     DrawEditorDoorContent();
10777
10778     OpenDoor(DOOR_OPEN_1 | DOOR_FORCE_ANIM);
10779   }
10780   else
10781   {
10782     DrawEditorDoorContent();
10783
10784     FadeIn(fade_mask);
10785   }
10786
10787   SetDoorState(DOOR_OPEN_1 | DOOR_OPEN_2);
10788 }
10789
10790 static void AdjustDrawingAreaGadgets(void)
10791 {
10792   int ed_xsize = lev_fieldx + 2;
10793   int ed_ysize = lev_fieldy + 2;
10794   int max_ed_fieldx = MAX_ED_FIELDX;
10795   int max_ed_fieldy = MAX_ED_FIELDY;
10796   boolean horizontal_scrollbar_needed;
10797   boolean vertical_scrollbar_needed;
10798   int x, y, width, height;
10799
10800   if (suppressBorderElement())
10801   {
10802     ed_xsize = lev_fieldx;
10803     ed_ysize = lev_fieldy;
10804   }
10805
10806   // check if we need any scrollbars
10807   horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
10808   vertical_scrollbar_needed   = (ed_ysize > max_ed_fieldy);
10809
10810   // check if we have a smaller editor field because of scrollbars
10811   max_ed_fieldx = getMaxEdFieldX(vertical_scrollbar_needed);
10812   max_ed_fieldy = getMaxEdFieldY(horizontal_scrollbar_needed);
10813
10814   // check again if we now need more scrollbars because of less space
10815   horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
10816   vertical_scrollbar_needed   = (ed_ysize > max_ed_fieldy);
10817
10818   // check if editor field gets even smaller after adding new scrollbars
10819   max_ed_fieldx = getMaxEdFieldX(vertical_scrollbar_needed);
10820   max_ed_fieldy = getMaxEdFieldY(horizontal_scrollbar_needed);
10821
10822   ed_fieldx = (ed_xsize > max_ed_fieldx ? max_ed_fieldx : ed_xsize);
10823   ed_fieldy = (ed_ysize > max_ed_fieldy ? max_ed_fieldy : ed_ysize);
10824
10825   x = SX + ed_fieldx * ed_tilesize;
10826   y = SY + ed_fieldy * ed_tilesize;
10827
10828   width  = ed_fieldx * ed_tilesize - 2 * ED_SCROLLBUTTON_XSIZE;
10829   height = ed_fieldy * ed_tilesize - 2 * ED_SCROLLBUTTON_YSIZE;
10830
10831   // adjust drawing area gadget
10832   ModifyGadget(level_editor_gadget[GADGET_ID_DRAWING_LEVEL],
10833                GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
10834                GDI_ITEM_SIZE, ed_tilesize, ed_tilesize,
10835                GDI_END);
10836
10837   // adjust horizontal scrollbar gadgets
10838   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LEFT],
10839                GDI_Y, y,
10840                GDI_END);
10841   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT],
10842                GDI_X, x - ED_SCROLLBUTTON_XSIZE,
10843                GDI_Y, y,
10844                GDI_END);
10845   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
10846                GDI_Y, y,
10847                GDI_WIDTH, width,
10848                GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldx,
10849                GDI_END);
10850
10851   // adjust vertical scrollbar gadgets
10852   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_UP],
10853                GDI_X, x,
10854                GDI_END);
10855   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN],
10856                GDI_X, x,
10857                GDI_Y, y - ED_SCROLLBUTTON_YSIZE,
10858                GDI_END);
10859   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
10860                GDI_X, x,
10861                GDI_HEIGHT, height,
10862                GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldy,
10863                GDI_END);
10864 }
10865
10866 static void AdjustLevelScrollPosition(void)
10867 {
10868   if (level_xpos < -1)
10869     level_xpos = -1;
10870   if (level_xpos > lev_fieldx - ed_fieldx + 1)
10871     level_xpos = lev_fieldx - ed_fieldx + 1;
10872   if (lev_fieldx < ed_fieldx - 2)
10873     level_xpos = -1;
10874
10875   if (level_ypos < -1)
10876     level_ypos = -1;
10877   if (level_ypos > lev_fieldy - ed_fieldy + 1)
10878     level_ypos = lev_fieldy - ed_fieldy + 1;
10879   if (lev_fieldy < ed_fieldy - 2)
10880     level_ypos = -1;
10881
10882   if (suppressBorderElement())
10883   {
10884     level_xpos = 0;
10885     level_ypos = 0;
10886   }
10887 }
10888
10889 static void AdjustEditorScrollbar(int id)
10890 {
10891   struct GadgetInfo *gi = level_editor_gadget[id];
10892   int items_max, items_visible, item_position;
10893
10894   if (id == GADGET_ID_SCROLL_HORIZONTAL)
10895   {
10896     items_max = MAX(lev_fieldx + 2, ed_fieldx);
10897     items_visible = ed_fieldx;
10898     item_position = level_xpos + 1;
10899   }
10900   else
10901   {
10902     items_max = MAX(lev_fieldy + 2, ed_fieldy);
10903     items_visible = ed_fieldy;
10904     item_position = level_ypos + 1;
10905   }
10906
10907   if (item_position > items_max - items_visible)
10908     item_position = items_max - items_visible;
10909
10910   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
10911                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
10912 }
10913
10914 static void AdjustElementListScrollbar(void)
10915 {
10916   struct GadgetInfo *gi = level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL];
10917   int items_max, items_visible, item_position;
10918
10919   // correct position of element list scrollbar
10920   if (element_shift < 0)
10921     element_shift = 0;
10922   if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
10923     element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
10924
10925   items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
10926   items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
10927   item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
10928
10929   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
10930                GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10931                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
10932 }
10933
10934 static void ModifyEditorCounterValue(int counter_id, int new_value)
10935 {
10936   int *counter_value = counterbutton_info[counter_id].value;
10937   int gadget_id = counterbutton_info[counter_id].gadget_id_text;
10938   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10939
10940   ModifyGadget(gi, GDI_NUMBER_VALUE, new_value, GDI_END);
10941
10942   if (counter_value != NULL)
10943     *counter_value = gi->textinput.number_value;
10944 }
10945
10946 static void ModifyEditorCounterLimits(int counter_id, int min, int max)
10947 {
10948   int gadget_id = counterbutton_info[counter_id].gadget_id_text;
10949   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10950
10951   ModifyGadget(gi, GDI_NUMBER_MIN, min, GDI_NUMBER_MAX, max, GDI_END);
10952
10953   if (counter_id >= ED_COUNTER_ID_ELEMENT_VALUE1 &&
10954       counter_id <= ED_COUNTER_ID_ELEMENT_VALUE4)
10955   {
10956     int gadget_id_up = counterbutton_info[counter_id].gadget_id_up;
10957     struct GadgetInfo *gi_up = level_editor_gadget[gadget_id_up];
10958
10959     ModifyGadget(gi, GDI_TEXT_SIZE, (max < 10 ? 1 : 3), GDI_END);
10960     ModifyGadget(gi_up, GDI_X, gi->x + gi->width + ED_GADGET_SMALL_DISTANCE,
10961                  GDI_END);
10962   }
10963 }
10964
10965 static void ModifyEditorSelectboxValue(int selectbox_id, int new_value)
10966 {
10967   int gadget_id = selectbox_info[selectbox_id].gadget_id;
10968   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10969   int new_index_value = setSelectboxValue(selectbox_id, new_value);
10970
10971   ModifyGadget(gi, GDI_SELECTBOX_INDEX, new_index_value, GDI_END);
10972 }
10973
10974 static void ModifyEditorSelectboxOptions(int selectbox_id,
10975                                          struct ValueTextInfo *options)
10976 {
10977   int gadget_id = selectbox_info[selectbox_id].gadget_id;
10978   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10979
10980   selectbox_info[selectbox_id].options = options;
10981
10982   // set index to zero -- list may be shorter now (correct later, if needed)
10983   ModifyGadget(gi, GDI_SELECTBOX_INDEX, 0,
10984                GDI_SELECTBOX_OPTIONS, options, GDI_END);
10985 }
10986
10987 static void ModifyEditorDrawingArea(int drawingarea_id, int xsize, int ysize)
10988 {
10989   int gadget_id = drawingarea_info[drawingarea_id].gadget_id;
10990   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10991
10992   drawingarea_info[drawingarea_id].area_xsize = xsize;
10993   drawingarea_info[drawingarea_id].area_ysize = ysize;
10994
10995   ModifyGadget(gi, GDI_AREA_SIZE, xsize, ysize, GDI_END);
10996 }
10997
10998 static void ModifyEditorElementList(void)
10999 {
11000   int i;
11001
11002   if (!use_permanent_palette && edit_mode != ED_MODE_PALETTE)
11003     return;
11004
11005   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
11006   {
11007     int gadget_id = GADGET_ID_ELEMENTLIST_FIRST + i;
11008     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11009     struct GadgetDesign *gd = &gi->deco.design;
11010     int element = editor_elements[element_shift + i];
11011     int tile_size = BUTTON_TILE_SIZE(editor.palette.tile_size);
11012
11013     UnmapGadget(gi);
11014
11015     getEditorGraphicSource(element, tile_size, &gd->bitmap, &gd->x, &gd->y);
11016
11017     ModifyGadget(gi, GDI_INFO_TEXT, getElementInfoText(element), GDI_END);
11018
11019     MapGadget(gi);
11020   }
11021 }
11022
11023 static void DrawDrawingElementGraphic(int element, struct XYTileSize *pos)
11024 {
11025   int graphic = el2edimg(element);
11026   int tile_size = BUTTON_TILE_SIZE(pos->tile_size);
11027
11028   if (pos->x == -1 &&
11029       pos->y == -1)
11030     return;
11031
11032   DrawSizedGraphicExt(drawto, DX + pos->x, DY + pos->y, graphic, 0, tile_size);
11033 }
11034
11035 static void ModifyDrawingElementButton(int element, int id)
11036 {
11037   struct GadgetInfo *gi = level_editor_gadget[id];
11038   Bitmap *deco_bitmap;
11039   int deco_x, deco_y;
11040   int tile_size = gi->deco.width;
11041
11042   getEditorGraphicSource(element, tile_size, &deco_bitmap, &deco_x, &deco_y);
11043
11044   ModifyGadget(gi, GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y, GDI_END);
11045 }
11046
11047 static void PickDrawingElement(int button, int element)
11048 {
11049   struct
11050   {
11051     int *new_element;
11052     struct XYTileSize *pos;
11053     int id;
11054   } de, drawing_elements[] =
11055   {
11056     { &new_element1, &editor.palette.element_left,   GADGET_ID_ELEMENT_LEFT   },
11057     { &new_element2, &editor.palette.element_middle, GADGET_ID_ELEMENT_MIDDLE },
11058     { &new_element3, &editor.palette.element_right,  GADGET_ID_ELEMENT_RIGHT  },
11059   };
11060
11061   if (button < 1 || button > 3)
11062     return;
11063
11064   if (IS_MM_WALL(element))
11065     element = map_mm_wall_element(element);
11066
11067   de = drawing_elements[button - 1];
11068
11069   *de.new_element = element;    // update global drawing element variable
11070
11071   DrawDrawingElementGraphic(element, de.pos);
11072   ModifyDrawingElementButton(element, de.id);
11073
11074   redraw_mask |= REDRAW_DOOR_1;
11075 }
11076
11077 static void RedrawDrawingElements(void)
11078 {
11079   PickDrawingElement(1, new_element1);
11080   PickDrawingElement(2, new_element2);
11081   PickDrawingElement(3, new_element3);
11082 }
11083
11084 static void DrawDrawingWindowExt(boolean remap_toolbox_gadgets)
11085 {
11086   stick_element_properties_window = FALSE;
11087
11088   SetMainBackgroundImage(IMG_UNDEFINED);
11089   ClearField();
11090
11091   UnmapLevelEditorFieldGadgets();
11092
11093   AdjustDrawingAreaGadgets();
11094   AdjustLevelScrollPosition();
11095   AdjustEditorScrollbar(GADGET_ID_SCROLL_HORIZONTAL);
11096   AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
11097
11098   DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
11099
11100   MapMainDrawingArea();
11101
11102   if (remap_toolbox_gadgets)
11103   {
11104     UnmapLevelEditorToolboxCustomGadgets();
11105     MapLevelEditorToolboxDrawingGadgets();
11106   }
11107 }
11108
11109 static void DrawDrawingWindow(void)
11110 {
11111   DrawDrawingWindowExt(TRUE);
11112 }
11113
11114 static int getTabulatorBarWidth(void)
11115 {
11116   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
11117   struct GadgetInfo *gd_gi4 = level_editor_gadget[GADGET_ID_PROPERTIES_CHANGE];
11118
11119   return gd_gi4->x - gd_gi1->x + gd_gi4->width;
11120 }
11121
11122 static int getTabulatorBarHeight(void)
11123 {
11124   return ED_TAB_BAR_HEIGHT;
11125 }
11126
11127 static Pixel getTabulatorBarColor(void)
11128 {
11129   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_LEVELCONFIG_LEVEL];
11130   struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
11131   int gd_x = gd->x + gd_gi1->border.width / 2;
11132   int gd_y = gd->y + gd_gi1->height - 1;
11133
11134   return GetPixel(gd->bitmap, gd_x, gd_y);
11135 }
11136
11137 static void DrawEngineConfigTabulatorGadgets(void)
11138 {
11139   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_ENGINECONFIG_CONFIG];
11140   Pixel tab_color = getTabulatorBarColor();
11141   int id_first = ED_TEXTBUTTON_ID_ENGINECONFIG_CONFIG;
11142   int id_last  = ED_TEXTBUTTON_ID_ENGINECONFIG_COLORS;
11143   int i;
11144
11145   for (i = id_first; i <= id_last; i++)
11146   {
11147     int gadget_id = textbutton_info[i].gadget_id;
11148     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11149     boolean active = (i != edit_mode_engineconfig);
11150
11151     // draw background line below tabulator button
11152     ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width, 1);
11153
11154     // draw solid line below inactive tabulator buttons
11155     if (!active && tab_color != BLACK_PIXEL)    // black => transparent
11156       FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,
11157                     ED_GADGET_TINY_DISTANCE, tab_color);
11158
11159     ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
11160     MapTextbuttonGadget(i);
11161   }
11162
11163   // draw little border line below tabulator buttons
11164   if (tab_color != BLACK_PIXEL)                 // black => transparent
11165     FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height +
11166                   ED_GADGET_TINY_DISTANCE,
11167                   getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
11168 }
11169
11170 static void DrawLevelConfigTabulatorGadgets(void)
11171 {
11172   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_LEVELCONFIG_LEVEL];
11173   Pixel tab_color = getTabulatorBarColor();
11174   int id_first = ED_TEXTBUTTON_ID_LEVELCONFIG_LEVEL;
11175   int id_last  = ED_TEXTBUTTON_ID_LEVELCONFIG_EDITOR;
11176   int i;
11177
11178   // draw additional "engine" tabulator when using native BD engine
11179   if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
11180     id_last = ED_TEXTBUTTON_ID_LEVELCONFIG_ENGINE;
11181
11182   for (i = id_first; i <= id_last; i++)
11183   {
11184     int gadget_id = textbutton_info[i].gadget_id;
11185     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11186     boolean active = (i != edit_mode_levelconfig);
11187
11188     // draw background line below tabulator button
11189     ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width, 1);
11190
11191     // draw solid line below inactive tabulator buttons
11192     if (!active && tab_color != BLACK_PIXEL)    // black => transparent
11193       FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,
11194                     ED_GADGET_TINY_DISTANCE, tab_color);
11195
11196     ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
11197     MapTextbuttonGadget(i);
11198   }
11199
11200   // draw little border line below tabulator buttons
11201   if (tab_color != BLACK_PIXEL)                 // black => transparent
11202     FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height +
11203                   ED_GADGET_TINY_DISTANCE,
11204                   getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
11205
11206   // draw second row of engine related tabulators when using native BD engine
11207   if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_ENGINE)
11208     DrawEngineConfigTabulatorGadgets();
11209 }
11210
11211 static void DrawPropertiesTabulatorGadgets(void)
11212 {
11213   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
11214   struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
11215   int gd_x = gd->x + gd_gi1->border.width / 2;
11216   int gd_y = gd->y + gd_gi1->height - 1;
11217   Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
11218   int id_first = ED_TEXTBUTTON_ID_PROPERTIES_INFO;
11219   int id_last  = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG;
11220   int i;
11221
11222   // draw two config tabulators for player elements
11223   if (IS_PLAYER_ELEMENT(properties_element))
11224     id_last = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2;
11225
11226   // draw two config and one "change" tabulator for custom elements
11227   if (IS_CUSTOM_ELEMENT(properties_element))
11228     id_last = ED_TEXTBUTTON_ID_PROPERTIES_CHANGE;
11229
11230   for (i = id_first; i <= id_last; i++)
11231   {
11232     int gadget_id = textbutton_info[i].gadget_id;
11233     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11234     boolean active = (i != edit_mode_properties);
11235
11236     // use "config 1" and "config 2" instead of "config" for players and CEs
11237     if (i == ED_TEXTBUTTON_ID_PROPERTIES_CONFIG &&
11238         (IS_PLAYER_ELEMENT(properties_element) ||
11239          IS_CUSTOM_ELEMENT(properties_element)))
11240       continue;
11241
11242     // draw background line below tabulator button
11243     ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width, 1);
11244
11245     // draw solid line below inactive tabulator buttons
11246     if (!active && tab_color != BLACK_PIXEL)    // black => transparent
11247       FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,
11248                     ED_GADGET_TINY_DISTANCE, tab_color);
11249
11250     ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
11251     MapTextbuttonGadget(i);
11252   }
11253
11254   // draw little border line below tabulator buttons
11255   if (tab_color != BLACK_PIXEL)                 // black => transparent
11256     FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height +
11257                   ED_GADGET_TINY_DISTANCE,
11258                   getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
11259 }
11260
11261 static void PrintInfoText(char *text, int font_nr, int xpos, int ypos)
11262 {
11263   DrawText(SX + xpos, SY + ypos, text, font_nr);
11264 }
11265
11266 static int PrintElementDescriptionFromFile(char *filename, int font_nr,
11267                                            int xpos, int ypos)
11268 {
11269   int font_width = getFontWidth(font_nr);
11270   int font_height = getFontHeight(font_nr);
11271   int max_chars_per_line = (SXSIZE - 2 * xpos) / font_width;
11272   int max_lines_drawable = (SYSIZE - ypos) / font_height - 1;
11273
11274   return DrawTextFile(SX + xpos, SY + ypos, filename, font_nr,
11275                       max_chars_per_line, -1, max_lines_drawable, 0, -1,
11276                       TRUE, FALSE, FALSE);
11277 }
11278
11279 static void DrawLevelConfigLevel(void)
11280 {
11281   int i;
11282
11283   // draw counter gadgets
11284   for (i = ED_COUNTER_ID_LEVEL_FIRST; i <= ED_COUNTER_ID_LEVEL_LAST; i++)
11285     MapCounterButtons(i);
11286
11287   // draw checkbutton gadgets
11288   for (i = ED_CHECKBUTTON_ID_LEVEL_FIRST; i<= ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
11289     MapCheckbuttonGadget(i);
11290
11291   // draw selectbox gadgets
11292   for (i = ED_SELECTBOX_ID_LEVEL_FIRST; i <= ED_SELECTBOX_ID_LEVEL_LAST; i++)
11293     MapSelectboxGadget(i);
11294
11295   // draw text input gadgets
11296   for (i = ED_TEXTINPUT_ID_LEVEL_FIRST; i <= ED_TEXTINPUT_ID_LEVEL_LAST; i++)
11297     MapTextInputGadget(i);
11298 }
11299
11300 static char *getLevelSubdirFromSaveMode(int save_mode)
11301 {
11302   if (save_mode == LEVELSET_SAVE_MODE_CREATE)
11303     return getNewUserLevelSubdir();
11304
11305   return leveldir_current->subdir;
11306 }
11307
11308 static void DrawLevelConfigLevelSet_DirectoryInfo(void)
11309 {
11310   char *directory_text = "Level set directory:";
11311   char *directory_name = getLevelSubdirFromSaveMode(levelset_save_mode);
11312   int font1_nr = FONT_TEXT_1;
11313   int font2_nr = FONT_TEXT_2;
11314   int font1_height = getFontHeight(font1_nr);
11315   int yoffset_above = font1_height + ED_GADGET_LINE_DISTANCE;
11316   int x = ED_LEVEL_SETTINGS_X(0);
11317   int y = ED_LEVEL_SETTINGS_Y(6);
11318
11319   PrintInfoText(directory_text, font1_nr, x, y - yoffset_above);
11320   PrintInfoText(directory_name, font2_nr, x, y);
11321 }
11322
11323 static void DrawLevelConfigLevelSet(void)
11324 {
11325   boolean artwork_exists = checkIfCustomArtworkExistsForCurrentLevelSet();
11326   boolean template_exists = fileExists(getLocalLevelTemplateFilename());
11327   int i;
11328
11329   // draw counter gadgets
11330   for (i = ED_COUNTER_ID_LEVELSET_FIRST; i <= ED_COUNTER_ID_LEVELSET_LAST; i++)
11331     MapCounterButtons(i);
11332
11333   // draw checkbutton gadgets
11334   for (i = ED_CHECKBUTTON_ID_LEVELSET_FIRST; i <= ED_CHECKBUTTON_ID_LEVELSET_LAST; i++)
11335   {
11336     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE ||
11337         (i == ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK && !artwork_exists) ||
11338         (i == ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE  && !template_exists))
11339       continue;
11340
11341     MapCheckbuttonGadget(i);
11342   }
11343
11344   // draw selectbox gadgets
11345   for (i = ED_SELECTBOX_ID_LEVELSET_FIRST; i <= ED_SELECTBOX_ID_LEVELSET_LAST; i++)
11346     MapSelectboxGadget(i);
11347
11348   // draw text input gadgets
11349   for (i = ED_TEXTINPUT_ID_LEVELSET_FIRST; i <= ED_TEXTINPUT_ID_LEVELSET_LAST; i++)
11350     MapTextInputGadget(i);
11351
11352   // draw textbutton gadgets
11353   MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_LEVELSET);
11354
11355   // draw info text
11356   DrawLevelConfigLevelSet_DirectoryInfo();
11357 }
11358
11359 static void DrawLevelConfigEditor(void)
11360 {
11361   int i;
11362
11363   // draw counter gadgets
11364   for (i = ED_COUNTER_ID_EDITOR_FIRST; i <= ED_COUNTER_ID_EDITOR_LAST; i++)
11365     MapCounterButtons(i);
11366
11367   // draw checkbutton gadgets
11368   for (i = ED_CHECKBUTTON_ID_EDITOR_FIRST; i <= ED_CHECKBUTTON_ID_EDITOR_LAST; i++)
11369     MapCheckbuttonGadget(i);
11370
11371   // draw radiobutton gadgets
11372   for (i = ED_RADIOBUTTON_ID_EDITOR_FIRST; i <= ED_RADIOBUTTON_ID_EDITOR_LAST; i++)
11373     MapRadiobuttonGadget(i);
11374
11375   // draw drawing area
11376   MapDrawingArea(ED_DRAWING_ID_RANDOM_BACKGROUND);
11377
11378   // draw textbutton gadgets
11379   MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_2);
11380 }
11381
11382 static void DrawEngineConfigConfig(void)
11383 {
11384   int i;
11385
11386   // draw counter gadgets
11387   if (level.bd_scheduling_type == GD_SCHEDULING_MILLISECONDS)
11388   {
11389     MapCounterButtons(ED_COUNTER_ID_BD_CYCLE_DELAY_MS);
11390     MapCounterButtons(ED_COUNTER_ID_BD_HATCHING_DELAY_CYCLES);
11391   }
11392   else
11393   {
11394     MapCounterButtons(ED_COUNTER_ID_BD_CYCLE_DELAY_C64);
11395     MapCounterButtons(ED_COUNTER_ID_BD_HATCHING_DELAY_SECONDS);
11396   }
11397
11398   // draw checkbutton gadgets
11399   for (i = ED_CHECKBUTTON_ID_ENGINE_FIRST; i <= ED_CHECKBUTTON_ID_ENGINE_LAST; i++)
11400     MapCheckbuttonGadget(i);
11401
11402   // draw selectbox gadgets
11403   for (i = ED_SELECTBOX_ID_ENGINE_FIRST; i <= ED_SELECTBOX_ID_ENGINE_LAST; i++)
11404     MapSelectboxGadget(i);
11405 }
11406
11407 static int GetCommonColorType_BD(void)
11408 {
11409   int bd_color_type = *bd_color[0] >> 24;
11410   int i;
11411
11412   // check if all colors have the same color type
11413   for (i = 1; i < MAX_BD_COLORS; i++)
11414     if ((*bd_color[i] >> 24) != bd_color_type)
11415       return GD_COLOR_TYPE_RGB;
11416
11417   return bd_color_type;
11418 }
11419
11420 void SetDefaultLevelColorType_BD(void)
11421 {
11422   bd_color_type_default = GetCommonColorType_BD();
11423
11424   level.bd_color_type = bd_color_type_default;
11425 }
11426
11427 void SetDefaultLevelColors_BD(void)
11428 {
11429   int i;
11430
11431   for (i = 0; i < MAX_BD_COLORS; i++)
11432     bd_color_default[i] = *bd_color[i];
11433 }
11434
11435 void SetRandomLevelColors_BD(int bd_color_type)
11436 {
11437   struct LevelInfo_BD *level_bd = level.native_bd_level;
11438   GdCave *cave = level_bd->cave;
11439
11440   // create random cave colors
11441   gd_cave_set_random_colors(cave, bd_color_type);
11442
11443   // copy colors to level editor
11444   level.bd_color_b = cave->colorb;
11445   level.bd_color_0 = cave->color0;
11446   level.bd_color_1 = cave->color1;
11447   level.bd_color_2 = cave->color2;
11448   level.bd_color_3 = cave->color3;
11449   level.bd_color_4 = cave->color4;
11450   level.bd_color_5 = cave->color5;
11451 }
11452
11453 static void DrawColorBox_BD(int nr)
11454 {
11455   int id = ED_SELECTBOX_ID_COLORS_FIRST + nr;
11456   struct GadgetInfo *gi = level_editor_gadget[selectbox_info[id].gadget_id];
11457   int graphic = IMG_EDITOR_CHECKBOX;
11458   struct GraphicInfo *gd = &graphic_info[graphic];
11459   int offset = ED_GADGET_TEXT_DISTANCE;
11460   int x1 = gi->x - offset - gd->width;
11461   int y1 = gi->y;
11462   int x2 = x1 + offset;
11463   int y2 = y1 + offset;
11464   int xsize1 = gd->width;
11465   int ysize1 = gd->height;
11466   int xsize2 = xsize1 - 2 * offset;
11467   int ysize2 = ysize1 - 2 * offset;
11468   int bd_color_x = *bd_color[nr];
11469   int r = gd_color_get_r(bd_color_x);
11470   int g = gd_color_get_g(bd_color_x);
11471   int b = gd_color_get_b(bd_color_x);
11472   Pixel color = SDL_MapRGB(drawto->surface->format, r, g, b);
11473
11474   BlitBitmap(gd->bitmap, drawto, gd->src_x, gd->src_y, xsize1, ysize1, x1, y1);
11475   FillRectangle(drawto, x2, y2, xsize2, ysize2, color);
11476 }
11477
11478 static void DrawEngineConfigColors(void)
11479 {
11480   int i;
11481
11482   if (bd_color_type_changed)
11483   {
11484     if (level.bd_color_type != GD_COLOR_TYPE_RGB && level.bd_color_type != GetCommonColorType_BD())
11485     {
11486       // color type switched to non-RGB colors, but using different color type => reset colors
11487
11488       if (level.bd_color_type == bd_color_type_default)
11489       {
11490         // color type switched to same color type as default colors => reset to defaults
11491         for (i = 0; i < MAX_BD_COLORS; i++)
11492           *bd_color[i] = bd_color_default[i];
11493       }
11494       else
11495       {
11496         // color type switched to different color type as default colors => use random colors
11497         SetRandomLevelColors_BD(level.bd_color_type);
11498       }
11499     }
11500
11501     bd_color_type_changed = FALSE;
11502   }
11503
11504   // copy level colors to either C64-style color index or color text
11505   for (i = 0; i < MAX_BD_COLORS; i++)
11506   {
11507     int bd_color_x = (level.bd_color_type == GD_COLOR_TYPE_C64 ? *bd_color[i] & 0x0f :
11508                       level.bd_color_type == GD_COLOR_TYPE_RGB ? gd_color_get_rgb(*bd_color[i]) :
11509                       *bd_color[i]);
11510
11511     if (level.bd_color_type == GD_COLOR_TYPE_C64)
11512       bd_color_c64[i] = bd_color_x;
11513     else
11514       snprintf(bd_color_text[i], sizeof(bd_color_text[i]), "%s", gd_color_get_string(bd_color_x));
11515   }
11516
11517   MapSelectboxGadget(ED_SELECTBOX_ID_BD_COLOR_TYPE);
11518
11519   if (level.bd_color_type == GD_COLOR_TYPE_C64)
11520   {
11521     // draw selectbox gadgets
11522     for (i = ED_SELECTBOX_ID_COLORS_FIRST; i <= ED_SELECTBOX_ID_COLORS_LAST; i++)
11523       MapSelectboxGadget(i);
11524   }
11525   else
11526   {
11527     // draw text input gadgets
11528     for (i = ED_TEXTINPUT_ID_COLORS_FIRST; i <= ED_TEXTINPUT_ID_COLORS_LAST; i++)
11529       MapTextInputGadget(i);
11530   }
11531
11532   for (i = 0; i < MAX_BD_COLORS; i++)
11533     DrawColorBox_BD(i);
11534
11535   MapTextbuttonGadget(ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS);
11536 }
11537
11538 static void DrawLevelConfigEngine(void)
11539 {
11540   if (edit_mode_engineconfig == ED_MODE_ENGINECONFIG_CONFIG)
11541     DrawEngineConfigConfig();
11542   else if (edit_mode_engineconfig == ED_MODE_ENGINECONFIG_COLORS)
11543     DrawEngineConfigColors();
11544 }
11545
11546 static void DrawLevelConfigWindow(void)
11547 {
11548   char *text = "Global Settings";
11549   int font_nr = FONT_TITLE_1;
11550   struct MenuPosInfo *pos = &editor.settings.headline;
11551   int sx = SX + ALIGNED_XPOS(pos->x, getTextWidth(text, font_nr), pos->align);
11552   int sy = SY + pos->y;
11553
11554   stick_element_properties_window = FALSE;
11555
11556   // make sure that previous level config edit mode exists for this level
11557   if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_ENGINE &&
11558       level.game_engine_type != GAME_ENGINE_TYPE_BD)
11559     edit_mode_levelconfig = ED_MODE_LEVELCONFIG_LEVEL;
11560
11561   SetAutomaticNumberOfGemsNeeded();
11562
11563   UnmapLevelEditorFieldGadgets();
11564
11565   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
11566   ClearField();
11567
11568   DrawText(sx, sy, text, font_nr);
11569
11570   DrawLevelConfigTabulatorGadgets();
11571
11572   if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_LEVEL)
11573     DrawLevelConfigLevel();
11574   else if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_LEVELSET)
11575     DrawLevelConfigLevelSet();
11576   else if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_EDITOR)
11577     DrawLevelConfigEditor();
11578   else if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_ENGINE)
11579     DrawLevelConfigEngine();
11580 }
11581
11582 static void DrawCustomContentArea(void)
11583 {
11584   int id = ED_DRAWING_ID_CUSTOM_CONTENT;
11585   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
11586   int x1 = right_gadget_border[GADGET_ID_CUSTOM_DEADLINESS];
11587   int x2 = right_gadget_border[GADGET_ID_CUSTOM_EXPLOSION_TYPE];
11588   int x3 = right_gadget_border[GADGET_ID_CUSTOM_EXPLODE_IMPACT];
11589   int xoffset = ED_GADGET_SPACE_DISTANCE;
11590
11591   // add distance for potential left text (without drawing area border)
11592   x2 += getTextWidthForGadget(drawingarea_info[id].text_left);
11593
11594   ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
11595
11596   MapDrawingArea(ED_DRAWING_ID_CUSTOM_CONTENT);
11597 }
11598
11599 static void DrawCustomChangeContentArea(void)
11600 {
11601   int id = ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT;
11602   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
11603   int x1 = right_gadget_border[GADGET_ID_CHANGE_USE_CONTENT];
11604   int x2 = right_gadget_border[GADGET_ID_CHANGE_REPLACE_WHEN];
11605   int x3 = right_gadget_border[GADGET_ID_CHANGE_ONLY_COMPLETE];
11606   int xoffset = ED_GADGET_SPACE_DISTANCE;
11607
11608   ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
11609
11610   MapDrawingArea(id);
11611 }
11612
11613 static void RemoveElementContentArea(int id, int font_height)
11614 {
11615   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11616
11617   DrawBackground(SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size,
11618                  SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size,
11619                  3 * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11620                  3 * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size +
11621                  ED_GADGET_TEXT_DISTANCE + font_height);
11622 }
11623
11624 static void DrawYamYamContentAreas(void)
11625 {
11626   int font_nr = FONT_TEXT_1;
11627   int font_height = getFontHeight(font_nr);
11628   int tilesize = ED_DRAWINGAREA_TILE_SIZE;
11629   int yoffset = (tilesize - font_height) / 2;
11630   int x = SX + ED_AREA_YAMYAM_CONTENT_X(3) + 4 * tilesize;
11631   int y = SY + ED_AREA_YAMYAM_CONTENT_Y(3) + yoffset;
11632   int i;
11633
11634   // display counter to choose number of element content areas
11635   MapCounterButtons(ED_COUNTER_ID_YAMYAM_CONTENT);
11636
11637   for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
11638   {
11639     int id = ED_DRAWING_ID_YAMYAM_CONTENT_0 + i;
11640
11641     if (i < level.num_yamyam_contents)
11642     {
11643       MapDrawingArea(id);
11644     }
11645     else
11646     {
11647       UnmapDrawingArea(id);
11648
11649       // delete content areas in case of reducing number of them
11650       RemoveElementContentArea(id, font_height);
11651     }
11652   }
11653
11654   DrawText(x, y + 0 * tilesize, "content", font_nr);
11655   DrawText(x, y + 1 * tilesize, "when",    font_nr);
11656   DrawText(x, y + 2 * tilesize, "smashed", font_nr);
11657 }
11658
11659 static void DrawMagicBallContentAreas(void)
11660 {
11661   int font_nr = FONT_TEXT_1;
11662   int font_height = getFontHeight(font_nr);
11663   int tilesize = ED_DRAWINGAREA_TILE_SIZE;
11664   int yoffset = (tilesize - font_height) / 2;
11665   int x = SX + ED_AREA_MAGIC_BALL_CONTENT_X(3) + 4 * tilesize;
11666   int y = SY + ED_AREA_MAGIC_BALL_CONTENT_Y(3) + yoffset;
11667   int i;
11668
11669   // display counter to choose number of element content areas
11670   MapCounterButtons(ED_COUNTER_ID_BALL_CONTENT);
11671
11672   for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
11673   {
11674     int id = ED_DRAWING_ID_MAGIC_BALL_CONTENT_0 + i;
11675
11676     if (i < level.num_ball_contents)
11677     {
11678       MapDrawingArea(id);
11679     }
11680     else
11681     {
11682       UnmapDrawingArea(id);
11683
11684       // delete content areas in case of reducing number of them
11685       RemoveElementContentArea(id, font_height);
11686     }
11687   }
11688
11689   DrawText(x, y + 0 * tilesize, "generated", font_nr);
11690   DrawText(x, y + 1 * tilesize, "when",      font_nr);
11691   DrawText(x, y + 2 * tilesize, "active",    font_nr);
11692 }
11693
11694 static void DrawAndroidElementArea(void)
11695 {
11696   int id = ED_DRAWING_ID_ANDROID_CONTENT;
11697   int num_elements = level.num_android_clone_elements;
11698   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11699   int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
11700   int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
11701   int xsize = MAX_ANDROID_ELEMENTS;
11702   int ysize = 1;
11703
11704   // display counter to choose number of element areas
11705   MapCounterButtons(ED_COUNTER_ID_ANDROID_CONTENT);
11706
11707   if (drawingarea_info[id].text_left != NULL)
11708     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
11709
11710   UnmapDrawingArea(id);
11711
11712   ModifyEditorDrawingArea(id, num_elements, 1);
11713
11714   // delete content areas in case of reducing number of them
11715   DrawBackground(sx, sy,
11716                  xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11717                  ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
11718
11719   MapDrawingArea(id);
11720 }
11721
11722 static void DrawGroupElementArea(void)
11723 {
11724   int id = ED_DRAWING_ID_GROUP_CONTENT;
11725   int num_elements = group_element_info.num_elements;
11726   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11727   int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
11728   int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
11729   int xsize = MAX_ELEMENTS_IN_GROUP;
11730   int ysize = 1;
11731
11732   if (drawingarea_info[id].text_left != NULL)
11733     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
11734
11735   UnmapDrawingArea(id);
11736
11737   ModifyEditorDrawingArea(id, num_elements, 1);
11738
11739   // delete content areas in case of reducing number of them
11740   DrawBackground(sx, sy,
11741                  xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11742                  ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
11743
11744   MapDrawingArea(id);
11745 }
11746
11747 static void DrawPlayerInitialInventoryArea(int element)
11748 {
11749   int id = ED_DRAWING_ID_INVENTORY_CONTENT;
11750   int player_nr = GET_PLAYER_NR(element);
11751   int num_elements = level.initial_inventory_size[player_nr];
11752   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11753   int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
11754   int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
11755   int xsize = MAX_INITIAL_INVENTORY_SIZE;
11756   int ysize = 1;
11757
11758   // determine horizontal position to the right of specified gadget
11759   if (drawingarea_info[id].gadget_id_align != GADGET_ID_NONE)
11760     sx = (right_gadget_border[drawingarea_info[id].gadget_id_align] +
11761           ED_DRAWINGAREA_TEXT_DISTANCE);
11762
11763   // determine horizontal offset for leading text
11764   if (drawingarea_info[id].text_left != NULL)
11765     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
11766
11767   UnmapDrawingArea(id);
11768
11769   ModifyEditorDrawingArea(id, num_elements, 1);
11770
11771   // delete content areas in case of reducing number of them
11772   DrawBackground(sx, sy,
11773                  xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11774                  ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
11775
11776   MapDrawingArea(id);
11777 }
11778
11779 static void DrawMMBallContentArea(void)
11780 {
11781   int id = ED_DRAWING_ID_MM_BALL_CONTENT;
11782   int num_elements = level.num_mm_ball_contents;
11783   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11784   int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
11785   int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
11786   int xsize = MAX_MM_BALL_CONTENTS;
11787   int ysize = 1;
11788
11789   if (drawingarea_info[id].text_left != NULL)
11790     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
11791
11792   UnmapDrawingArea(id);
11793
11794   ModifyEditorDrawingArea(id, num_elements, 1);
11795
11796   // delete content areas in case of reducing number of them
11797   DrawBackground(sx, sy,
11798                  xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11799                  ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
11800
11801   MapDrawingArea(id);
11802 }
11803
11804 static void DrawEnvelopeTextArea(int envelope_nr)
11805 {
11806   int id = ED_TEXTAREA_ID_ENVELOPE_INFO;
11807   struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
11808
11809   UnmapGadget(gi);
11810
11811   DrawBackground(gi->x, gi->y,
11812                  gi->textarea.crop_width, gi->textarea.crop_height);
11813
11814   if (envelope_nr != -1)
11815     textarea_info[id].value = level.envelope[envelope_nr].text;
11816
11817   ModifyGadget(gi, GDI_AREA_SIZE,
11818                *counterbutton_info[ED_COUNTER_ID_ENVELOPE_XSIZE].value,
11819                *counterbutton_info[ED_COUNTER_ID_ENVELOPE_YSIZE].value,
11820                GDI_END);
11821
11822   MapTextAreaGadget(ED_TEXTAREA_ID_ENVELOPE_INFO);
11823 }
11824
11825 static void DrawPropertiesInfo(void)
11826 {
11827   static struct
11828   {
11829     int value;
11830     char *text;
11831   }
11832   properties[] =
11833   {
11834     // configurable properties
11835
11836     { EP_WALKABLE_OVER,         "- player can walk over it"             },
11837     { EP_WALKABLE_INSIDE,       "- player can walk inside it"           },
11838     { EP_WALKABLE_UNDER,        "- player can walk under it"            },
11839     { EP_PASSABLE_OVER,         "- player can pass over it"             },
11840     { EP_PASSABLE_INSIDE,       "- player can pass through it"          },
11841     { EP_PASSABLE_UNDER,        "- player can pass under it"            },
11842     { EP_PROTECTED,             "- player is protected by it"           },
11843
11844     { EP_DIGGABLE,              "- can be digged away"                  },
11845     { EP_COLLECTIBLE,           "- can be collected"                    },
11846     { EP_DROPPABLE,             "- can be dropped after collecting"     },
11847     { EP_THROWABLE,             "- can be thrown after collecting"      },
11848     { EP_PUSHABLE,              "- can be pushed"                       },
11849
11850     { EP_CAN_FALL,              "- can fall"                            },
11851     { EP_CAN_MOVE,              "- can move"                            },
11852
11853     { EP_CAN_SMASH_PLAYER,      "- can smash player"                    },
11854 #if 0
11855     { EP_CAN_SMASH_ENEMIES,     "- can smash good and bad guys"         },
11856 #endif
11857     { EP_CAN_SMASH_EVERYTHING,  "- can smash everything smashable"      },
11858
11859     { EP_SLIPPERY,              "- slippery for falling elements"       },
11860     { EP_EM_SLIPPERY_WALL,      "- slippery for some gems (EM style)"   },
11861
11862     { EP_DONT_RUN_INTO,         "- deadly when running into"            },
11863     { EP_DONT_COLLIDE_WITH,     "- deadly when colliding with"          },
11864     { EP_DONT_GET_HIT_BY,       "- deadly when getting hit by"          },
11865     { EP_DONT_TOUCH,            "- deadly when touching"                },
11866
11867     { EP_INDESTRUCTIBLE,        "- indestructible"                      },
11868
11869     { EP_CAN_EXPLODE_BY_FIRE,   "- can explode by fire or explosions"   },
11870     { EP_CAN_EXPLODE_SMASHED,   "- can explode when smashed"            },
11871     { EP_CAN_EXPLODE_IMPACT,    "- can explode on impact"               },
11872
11873     { EP_CAN_CHANGE,            "- can change to other element"         },
11874
11875     // pre-defined properties
11876     { EP_CAN_PASS_MAGIC_WALL,   "- can pass magic walls"                },
11877     { EP_CAN_PASS_DC_MAGIC_WALL,"- can pass magic walls (DC style)"     },
11878     { EP_SWITCHABLE,            "- can be switched"                     },
11879 #if 0
11880     { EP_HAS_EDITOR_CONTENT,    "- can contain other elements"          },
11881 #endif
11882
11883     { -1,                       NULL                                    }
11884   };
11885   char *filename = getElementDescriptionFilename(properties_element);
11886   char *num_elements_text = "In this level: ";
11887   char *num_similar_text = "Similar tiles: ";
11888   char *properties_text = "Standard properties: ";
11889   char *description_text = "Description:";
11890   char *no_description_text = "No description available.";
11891   char *none_text = "None";
11892   float percentage;
11893   int num_elements_in_level = 0;
11894   int num_similar_in_level = 0;
11895   int num_hires_tiles_in_level = 0;
11896   int num_standard_properties = 0;
11897   int font1_nr = FONT_TEXT_1;
11898   int font2_nr = FONT_TEXT_2;
11899   int font1_width = getFontWidth(font1_nr);
11900   int font1_height = getFontHeight(font1_nr);
11901   int font2_height = getFontHeight(font2_nr);
11902   int line1_height = font1_height + ED_GADGET_LINE_DISTANCE;
11903   int font2_yoffset = (font1_height - font2_height) / 2;
11904   int num_elements_text_len = strlen(num_elements_text) * font1_width;
11905   int num_similar_text_len = strlen(num_similar_text) * font1_width;
11906   int properties_text_len = strlen(properties_text) * font1_width;
11907   int xpos = ED_ELEMENT_SETTINGS_X(0);
11908   int ypos = ED_ELEMENT_SETTINGS_Y(0) + ED_GADGET_SMALL_DISTANCE;
11909   int i, x, y;
11910
11911   if (setup.editor.show_element_token)
11912   {
11913     int font3_nr = FONT_TEXT_3;
11914     int font3_height = getFontHeight(font3_nr);
11915
11916     DrawTextF(xpos, ypos, font3_nr,
11917               "[%s]", element_info[properties_element].token_name);
11918
11919     ypos += 2 * font3_height;
11920   }
11921
11922   // ----- print number of elements / percentage of this element in level
11923
11924   for (y = 0; y < lev_fieldy; y++)
11925   {
11926     for (x = 0; x < lev_fieldx; x++)
11927     {
11928       if (Tile[x][y] == properties_element)
11929       {
11930         num_elements_in_level++;
11931       }
11932       else if (IS_MM_WALL(Tile[x][y]) &&
11933                map_mm_wall_element(Tile[x][y]) == properties_element)
11934       {
11935         num_hires_tiles_in_level += numHiresTiles(Tile[x][y]);
11936       }
11937     }
11938   }
11939
11940   percentage = num_elements_in_level * 100.0 / (lev_fieldx * lev_fieldy);
11941
11942   DrawTextS(xpos, ypos, font1_nr, num_elements_text);
11943
11944   if (num_hires_tiles_in_level > 0)
11945     DrawTextF(xpos + num_elements_text_len, ypos + font2_yoffset, font2_nr,
11946               "%d wall tiles", num_hires_tiles_in_level);
11947   else if (num_elements_in_level > 0)
11948     DrawTextF(xpos + num_elements_text_len, ypos + font2_yoffset, font2_nr,
11949               "%d (%.2f %%)", num_elements_in_level, percentage);
11950   else
11951     DrawTextF(xpos + num_elements_text_len, ypos + font2_yoffset, font2_nr,
11952               none_text);
11953
11954   // ----- print number of similar elements / percentage of them in level
11955
11956   for (y = 0; y < lev_fieldy; y++)
11957   {
11958     for (x = 0; x < lev_fieldx; x++)
11959     {
11960       if (strEqual(element_info[Tile[x][y]].class_name,
11961                    element_info[properties_element].class_name))
11962       {
11963         num_similar_in_level++;
11964       }
11965     }
11966   }
11967
11968   if (num_similar_in_level != num_elements_in_level)
11969   {
11970     ypos += 1 * MAX(font1_height, font2_height);
11971
11972     percentage = num_similar_in_level * 100.0 / (lev_fieldx * lev_fieldy);
11973
11974     DrawTextS(xpos, ypos, font1_nr, num_similar_text);
11975
11976     if (num_similar_in_level > 0)
11977       DrawTextF(xpos + num_similar_text_len, ypos + font2_yoffset, font2_nr,
11978                 "%d (%.2f %%)", num_similar_in_level, percentage);
11979     else
11980       DrawTextF(xpos + num_similar_text_len, ypos + font2_yoffset, font2_nr,
11981                 none_text);
11982   }
11983
11984   ypos += 2 * MAX(font1_height, font2_height);
11985
11986   // ----- print standard properties of this element (only for certain game engines)
11987
11988   if (level.game_engine_type == GAME_ENGINE_TYPE_RND ||
11989       level.game_engine_type == GAME_ENGINE_TYPE_EM ||
11990       level.game_engine_type == GAME_ENGINE_TYPE_SP)
11991   {
11992     DrawTextS(xpos, ypos, font1_nr, properties_text);
11993
11994     ypos += line1_height;
11995
11996     for (i = 0; properties[i].value != -1; i++)
11997     {
11998       if (!HAS_PROPERTY(properties_element, properties[i].value))
11999         continue;
12000
12001       DrawTextS(xpos, ypos, font2_nr, properties[i].text);
12002
12003       ypos += font2_height;
12004
12005       num_standard_properties++;
12006     }
12007
12008     if (num_standard_properties == 0)
12009     {
12010       DrawTextS(xpos + properties_text_len, ypos - line1_height + font2_yoffset,
12011                 font2_nr, none_text);
12012
12013       ypos -= (line1_height - font1_height);
12014     }
12015
12016     ypos += MAX(font1_height, font2_height);
12017   }
12018
12019   // ----- print special description of this element
12020
12021   PrintInfoText(description_text, font1_nr, xpos, ypos);
12022
12023   ypos += line1_height;
12024
12025   if (PrintElementDescriptionFromFile(filename, font2_nr, xpos, ypos) == 0)
12026     PrintInfoText(no_description_text, font1_nr, xpos, ypos - line1_height);
12027 }
12028
12029 #define TEXT_COLLECTING                 "Score for collecting"
12030 #define TEXT_COLLECTING_EXTRA           "Score for extra diamonds"
12031 #define TEXT_SMASHING                   "Score for smashing"
12032 #define TEXT_SLURPING                   "Score for slurping robot"
12033 #define TEXT_CRACKING                   "Score for cracking"
12034 #define TEXT_AMOEBA_SPEED               "Speed of amoeba growth"
12035 #define TEXT_AMOEBA_THRESHOED           "Size for turning to rocks"
12036 #define TEXT_AMOEBA_SLOW_TIME           "Slow growth time (seconds)"
12037 #define TEXT_AMOEBA_SLOW_RATE           "Slow growth rate (percent)"
12038 #define TEXT_AMOEBA_FAST_RATE           "Fast growth rate (percent)"
12039 #define TEXT_DURATION                   "Duration when activated"
12040 #define TEXT_DELAY_ON                   "Delay before activating"
12041 #define TEXT_DELAY_OFF                  "Delay before deactivating"
12042 #define TEXT_DELAY_CHANGING             "Delay before changing"
12043 #define TEXT_DELAY_EXPLODING            "Delay before exploding"
12044 #define TEXT_DELAY_MOVING               "Delay before moving"
12045 #define TEXT_BALL_DELAY                 "Element generation delay"
12046 #define TEXT_MOVE_SPEED                 "Speed of android moving"
12047 #define TEXT_CLONE_SPEED                "Speed of android cloning"
12048 #define TEXT_GAME_OF_LIFE_1             "Min neighbours to survive"
12049 #define TEXT_GAME_OF_LIFE_2             "Max neighbours to survive"
12050 #define TEXT_GAME_OF_LIFE_3             "Min neighbours to create"
12051 #define TEXT_GAME_OF_LIFE_4             "Max neighbours to create"
12052 #define TEXT_TIME_BONUS                 "Extra time to solve level"
12053 #define TEXT_TIME_PENALTY               "Time penalty if destroyed"
12054 #define TEXT_PERMEABILITY_RATE          "slime permeability rate"
12055 #define TEXT_PERMEABILITY_BITS          "slime permeability bits"
12056 #define TEXT_RANDOM_SEED                "slime random number seed"
12057 #define TEXT_ACID_SPREAD_RATE           "Spread rate (percent)"
12058 #define TEXT_BITER_MOVE_DELAY           "Move delay (BD frames)"
12059 #define TEXT_REPLICATION_DELAY          "Create delay (BD frames)"
12060 #define TEXT_HAMMER_BREAK_DELAY         "Delay for breaking walls"
12061 #define TEXT_HAMMER_REAPPEAR_DELAY      "Delay for reappearing walls"
12062 #define TEXT_SKELETONS_NEEDED           "Skeletons needed to use pot"
12063 #define TEXT_SKELETONS_WORTH            "Counts as this many diamonds"
12064 #define TEXT_AUTO_TURN_DELAY            "Creatures auto turn delay"
12065 #define TEXT_GRAVITY_DELAY              "Gravity switch change delay"
12066
12067 static struct
12068 {
12069   int element;
12070   int *value;
12071   char *text;
12072   int min_value;
12073   int max_value;
12074 } elements_with_counter[] =
12075 {
12076   { EL_EMERALD,                 &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12077   { EL_BD_DIAMOND,              &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12078   { EL_BD_DIAMOND,              &level.score[SC_DIAMOND_EXTRA],         TEXT_COLLECTING_EXTRA   },
12079   { EL_EMERALD_YELLOW,          &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12080   { EL_EMERALD_RED,             &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12081   { EL_EMERALD_PURPLE,          &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12082   { EL_SP_INFOTRON,             &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12083   { EL_DIAMOND,                 &level.score[SC_DIAMOND],               TEXT_COLLECTING         },
12084   { EL_CRYSTAL,                 &level.score[SC_CRYSTAL],               TEXT_COLLECTING         },
12085   { EL_PEARL,                   &level.score[SC_PEARL],                 TEXT_COLLECTING         },
12086   { EL_BUG,                     &level.score[SC_BUG],                   TEXT_SMASHING           },
12087   { EL_BUG_RIGHT,               &level.score[SC_BUG],                   TEXT_SMASHING           },
12088   { EL_BUG_UP,                  &level.score[SC_BUG],                   TEXT_SMASHING           },
12089   { EL_BUG_LEFT,                &level.score[SC_BUG],                   TEXT_SMASHING           },
12090   { EL_BUG_DOWN,                &level.score[SC_BUG],                   TEXT_SMASHING           },
12091   { EL_BD_BUTTERFLY,            &level.score[SC_BUG],                   TEXT_SMASHING           },
12092   { EL_BD_BUTTERFLY_RIGHT,      &level.score[SC_BUG],                   TEXT_SMASHING           },
12093   { EL_BD_BUTTERFLY_UP,         &level.score[SC_BUG],                   TEXT_SMASHING           },
12094   { EL_BD_BUTTERFLY_LEFT,       &level.score[SC_BUG],                   TEXT_SMASHING           },
12095   { EL_BD_BUTTERFLY_DOWN,       &level.score[SC_BUG],                   TEXT_SMASHING           },
12096   { EL_SP_ELECTRON,             &level.score[SC_BUG],                   TEXT_SMASHING           },
12097   { EL_SPACESHIP,               &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12098   { EL_SPACESHIP_RIGHT,         &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12099   { EL_SPACESHIP_UP,            &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12100   { EL_SPACESHIP_LEFT,          &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12101   { EL_SPACESHIP_DOWN,          &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12102   { EL_BD_FIREFLY,              &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12103   { EL_BD_FIREFLY_RIGHT,        &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12104   { EL_BD_FIREFLY_UP,           &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12105   { EL_BD_FIREFLY_LEFT,         &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12106   { EL_BD_FIREFLY_DOWN,         &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12107   { EL_SP_SNIKSNAK,             &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12108   { EL_YAMYAM,                  &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12109   { EL_YAMYAM_LEFT,             &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12110   { EL_YAMYAM_RIGHT,            &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12111   { EL_YAMYAM_UP,               &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12112   { EL_YAMYAM_DOWN,             &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12113   { EL_DARK_YAMYAM,             &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12114   { EL_ROBOT,                   &level.score[SC_ROBOT],                 TEXT_SMASHING           },
12115   { EL_PACMAN,                  &level.score[SC_PACMAN],                TEXT_SMASHING           },
12116   { EL_PACMAN_RIGHT,            &level.score[SC_PACMAN],                TEXT_SMASHING           },
12117   { EL_PACMAN_UP,               &level.score[SC_PACMAN],                TEXT_SMASHING           },
12118   { EL_PACMAN_LEFT,             &level.score[SC_PACMAN],                TEXT_SMASHING           },
12119   { EL_PACMAN_DOWN,             &level.score[SC_PACMAN],                TEXT_SMASHING           },
12120   { EL_NUT,                     &level.score[SC_NUT],                   TEXT_CRACKING           },
12121   { EL_DYNAMITE,                &level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12122   { EL_EM_DYNAMITE,             &level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12123   { EL_DYNABOMB_INCREASE_NUMBER,&level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12124   { EL_DYNABOMB_INCREASE_SIZE,  &level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12125   { EL_DYNABOMB_INCREASE_POWER, &level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12126   { EL_SHIELD_NORMAL,           &level.score[SC_SHIELD],                TEXT_COLLECTING         },
12127   { EL_SHIELD_DEADLY,           &level.score[SC_SHIELD],                TEXT_COLLECTING         },
12128   { EL_EXTRA_TIME,              &level.extra_time_score,                TEXT_COLLECTING         },
12129   { EL_KEY_1,                   &level.score[SC_KEY],                   TEXT_COLLECTING         },
12130   { EL_KEY_2,                   &level.score[SC_KEY],                   TEXT_COLLECTING         },
12131   { EL_KEY_3,                   &level.score[SC_KEY],                   TEXT_COLLECTING         },
12132   { EL_KEY_4,                   &level.score[SC_KEY],                   TEXT_COLLECTING         },
12133   { EL_EM_KEY_1,                &level.score[SC_KEY],                   TEXT_COLLECTING         },
12134   { EL_EM_KEY_2,                &level.score[SC_KEY],                   TEXT_COLLECTING         },
12135   { EL_EM_KEY_3,                &level.score[SC_KEY],                   TEXT_COLLECTING         },
12136   { EL_EM_KEY_4,                &level.score[SC_KEY],                   TEXT_COLLECTING         },
12137   { EL_EMC_KEY_5,               &level.score[SC_KEY],                   TEXT_COLLECTING         },
12138   { EL_EMC_KEY_6,               &level.score[SC_KEY],                   TEXT_COLLECTING         },
12139   { EL_EMC_KEY_7,               &level.score[SC_KEY],                   TEXT_COLLECTING         },
12140   { EL_EMC_KEY_8,               &level.score[SC_KEY],                   TEXT_COLLECTING         },
12141   { EL_DC_KEY_WHITE,            &level.score[SC_KEY],                   TEXT_COLLECTING         },
12142   { EL_MM_KETTLE,               &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12143   { EL_DF_CELL,                 &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12144   { EL_MM_KEY,                  &level.score[SC_KEY],                   TEXT_COLLECTING         },
12145   { EL_MM_LIGHTBALL,            &level.score[SC_ELEM_BONUS],            TEXT_COLLECTING         },
12146   { EL_MM_PACMAN,               &level.score[SC_PACMAN],                TEXT_SMASHING           },
12147   { EL_MM_PACMAN_RIGHT,         &level.score[SC_PACMAN],                TEXT_SMASHING           },
12148   { EL_MM_PACMAN_UP,            &level.score[SC_PACMAN],                TEXT_SMASHING           },
12149   { EL_MM_PACMAN_LEFT,          &level.score[SC_PACMAN],                TEXT_SMASHING           },
12150   { EL_MM_PACMAN_DOWN,          &level.score[SC_PACMAN],                TEXT_SMASHING           },
12151   { EL_AMOEBA_WET,              &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12152   { EL_AMOEBA_DRY,              &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12153   { EL_AMOEBA_FULL,             &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12154   { EL_BD_AMOEBA,               &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12155   { EL_EMC_DRIPPER,             &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12156   { EL_BD_AMOEBA,               &level.bd_amoeba_threshold_too_big,     TEXT_AMOEBA_THRESHOED   },
12157   { EL_BD_AMOEBA,               &level.bd_amoeba_slow_growth_time,      TEXT_AMOEBA_SLOW_TIME   },
12158   { EL_BD_AMOEBA,               &level.bd_amoeba_slow_growth_rate,      TEXT_AMOEBA_SLOW_RATE,
12159                                 0, 100                                                          },
12160   { EL_BD_AMOEBA,               &level.bd_amoeba_fast_growth_rate,      TEXT_AMOEBA_FAST_RATE,
12161                                 0, 100                                                          },
12162   { EL_BD_AMOEBA_2,             &level.bd_amoeba_2_threshold_too_big,   TEXT_AMOEBA_THRESHOED   },
12163   { EL_BD_AMOEBA_2,             &level.bd_amoeba_2_slow_growth_time,    TEXT_AMOEBA_SLOW_TIME   },
12164   { EL_BD_AMOEBA_2,             &level.bd_amoeba_2_slow_growth_rate,    TEXT_AMOEBA_SLOW_RATE,
12165                                 0, 100                                                          },
12166   { EL_BD_AMOEBA_2,             &level.bd_amoeba_2_fast_growth_rate,    TEXT_AMOEBA_FAST_RATE,
12167                                 0, 100                                                          },
12168   { EL_MAGIC_WALL,              &level.time_magic_wall,                 TEXT_DURATION           },
12169   { EL_BD_MAGIC_WALL,           &level.time_magic_wall,                 TEXT_DURATION           },
12170   { EL_DC_MAGIC_WALL,           &level.time_magic_wall,                 TEXT_DURATION           },
12171   { EL_ROBOT_WHEEL,             &level.time_wheel,                      TEXT_DURATION           },
12172   { EL_TIMEGATE_SWITCH,         &level.time_timegate,                   TEXT_DURATION           },
12173   { EL_DC_TIMEGATE_SWITCH,      &level.time_timegate,                   TEXT_DURATION           },
12174   { EL_LIGHT_SWITCH,            &level.time_light,                      TEXT_DURATION           },
12175   { EL_LIGHT_SWITCH_ACTIVE,     &level.time_light,                      TEXT_DURATION           },
12176   { EL_SHIELD_NORMAL,           &level.shield_normal_time,              TEXT_DURATION           },
12177   { EL_SHIELD_DEADLY,           &level.shield_deadly_time,              TEXT_DURATION           },
12178   { EL_BD_CLOCK,                &level.bd_clock_extra_time,             TEXT_TIME_BONUS,
12179                                 -100, 100                                                       },
12180   { EL_BD_VOODOO_DOLL,          &level.bd_voodoo_penalty_time,          TEXT_TIME_PENALTY,
12181                                 0, 100                                                          },
12182   { EL_BD_SLIME,                &level.bd_slime_permeability_rate,      TEXT_PERMEABILITY_RATE,
12183                                 0, 100                                                          },
12184   { EL_BD_SLIME,                &level.bd_slime_permeability_bits_c64,  TEXT_PERMEABILITY_BITS,
12185                                 0, 255                                                          },
12186   { EL_BD_SLIME,                &level.bd_slime_random_seed_c64,        TEXT_RANDOM_SEED,
12187                                 -1, 65535                                                       },
12188   { EL_BD_ACID,                 &level.bd_acid_spread_rate,             TEXT_ACID_SPREAD_RATE,
12189                                 0, 100                                                          },
12190   { EL_BD_BITER,                &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12191                                 0, 3                                                            },
12192   { EL_BD_BITER_RIGHT,          &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12193                                 0, 3                                                            },
12194   { EL_BD_BITER_UP,             &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12195                                 0, 3                                                            },
12196   { EL_BD_BITER_LEFT,           &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12197                                 0, 3                                                            },
12198   { EL_BD_BITER_DOWN,           &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12199                                 0, 3                                                            },
12200   { EL_BD_REPLICATOR,           &level.bd_replicator_create_delay,      TEXT_REPLICATION_DELAY,
12201                                 0, 100                                                          },
12202   { EL_BD_PNEUMATIC_HAMMER,     &level.bd_hammer_walls_break_delay,     TEXT_HAMMER_BREAK_DELAY,
12203                                 1, 100                                                          },
12204   { EL_BD_PNEUMATIC_HAMMER,     &level.bd_hammer_walls_reappear_delay,  TEXT_HAMMER_REAPPEAR_DELAY,
12205                                 1, 200                                                          },
12206   { EL_BD_POT,                  &level.bd_num_skeletons_needed_for_pot, TEXT_SKELETONS_NEEDED,
12207                                 0, 50                                                           },
12208   { EL_BD_SKELETON,             &level.bd_num_skeletons_needed_for_pot, TEXT_SKELETONS_NEEDED,
12209                                 0, 50                                                           },
12210   { EL_BD_SKELETON,             &level.bd_skeleton_worth_num_diamonds,  TEXT_SKELETONS_WORTH,
12211                                 0, 10                                                           },
12212   { EL_BD_CREATURE_SWITCH,      &level.bd_creatures_auto_turn_delay,    TEXT_AUTO_TURN_DELAY    },
12213   { EL_BD_GRAVITY_SWITCH,       &level.bd_gravity_switch_delay,         TEXT_GRAVITY_DELAY,
12214                                 1, 60                                                           },
12215   { EL_EXTRA_TIME,              &level.extra_time,                      TEXT_TIME_BONUS         },
12216   { EL_TIME_ORB_FULL,           &level.time_orb_time,                   TEXT_TIME_BONUS         },
12217   { EL_GAME_OF_LIFE,            &level.game_of_life[0],                 TEXT_GAME_OF_LIFE_1,0,8 },
12218   { EL_GAME_OF_LIFE,            &level.game_of_life[1],                 TEXT_GAME_OF_LIFE_2,0,8 },
12219   { EL_GAME_OF_LIFE,            &level.game_of_life[2],                 TEXT_GAME_OF_LIFE_3,0,8 },
12220   { EL_GAME_OF_LIFE,            &level.game_of_life[3],                 TEXT_GAME_OF_LIFE_4,0,8 },
12221   { EL_BIOMAZE,                 &level.biomaze[0],                      TEXT_GAME_OF_LIFE_1,0,8 },
12222   { EL_BIOMAZE,                 &level.biomaze[1],                      TEXT_GAME_OF_LIFE_2,0,8 },
12223   { EL_BIOMAZE,                 &level.biomaze[2],                      TEXT_GAME_OF_LIFE_3,0,8 },
12224   { EL_BIOMAZE,                 &level.biomaze[3],                      TEXT_GAME_OF_LIFE_4,0,8 },
12225   { EL_EMC_ANDROID,             &level.android_move_time,               TEXT_MOVE_SPEED         },
12226   { EL_EMC_ANDROID,             &level.android_clone_time,              TEXT_CLONE_SPEED        },
12227   { EL_EMC_MAGIC_BALL,          &level.ball_time,                       TEXT_BALL_DELAY         },
12228   { EL_EMC_LENSES,              &level.lenses_score,                    TEXT_COLLECTING         },
12229   { EL_EMC_MAGNIFIER,           &level.magnify_score,                   TEXT_COLLECTING         },
12230   { EL_SPRING,                  &level.slurp_score,                     TEXT_SLURPING           },
12231   { EL_SPRING_LEFT,             &level.slurp_score,                     TEXT_SLURPING           },
12232   { EL_SPRING_RIGHT,            &level.slurp_score,                     TEXT_SLURPING           },
12233   { EL_EMC_LENSES,              &level.lenses_time,                     TEXT_DURATION           },
12234   { EL_EMC_MAGNIFIER,           &level.magnify_time,                    TEXT_DURATION           },
12235   { EL_MM_FUSE_ACTIVE,          &level.mm_time_fuse,                    TEXT_DELAY_OFF          },
12236   { EL_MM_BOMB,                 &level.mm_time_bomb,                    TEXT_DELAY_EXPLODING    },
12237   { EL_MM_GRAY_BALL,            &level.mm_time_ball,                    TEXT_DELAY_CHANGING     },
12238   { EL_MM_STEEL_BLOCK,          &level.mm_time_block,                   TEXT_DELAY_MOVING       },
12239   { EL_MM_WOODEN_BLOCK,         &level.mm_time_block,                   TEXT_DELAY_MOVING       },
12240
12241   { -1,                         NULL,                                   NULL                    }
12242 };
12243
12244 static boolean checkPropertiesConfig(int element)
12245 {
12246   int i;
12247
12248   // special case: empty space customization only available in R'n'D game engine
12249   if (element == EL_EMPTY_SPACE && level.game_engine_type != GAME_ENGINE_TYPE_RND)
12250     return FALSE;
12251
12252   // special case: BD style rock customization only available in BD game engine
12253   if (element == EL_BD_ROCK && level.game_engine_type != GAME_ENGINE_TYPE_BD)
12254     return FALSE;
12255
12256   if (IS_GEM(element) ||
12257       IS_CUSTOM_ELEMENT(element) ||
12258       IS_GROUP_ELEMENT(element) ||
12259       IS_EMPTY_ELEMENT(element) ||
12260       IS_BALLOON_ELEMENT(element) ||
12261       IS_ENVELOPE(element) ||
12262       IS_MM_ENVELOPE(element) ||
12263       IS_MM_MCDUFFIN(element) ||
12264       IS_DF_LASER(element) ||
12265       IS_PLAYER_ELEMENT(element) ||
12266       IS_BD_PLAYER_ELEMENT(element) ||
12267       IS_BD_FIREFLY(properties_element) ||
12268       IS_BD_FIREFLY_2(properties_element) ||
12269       IS_BD_BUTTERFLY(properties_element) ||
12270       IS_BD_BUTTERFLY_2(properties_element) ||
12271       IS_BD_STONEFLY(properties_element) ||
12272       IS_BD_DRAGONFLY(properties_element) ||
12273       IS_BD_EXPANDABLE_WALL(properties_element) ||
12274       IS_BD_EXPANDABLE_STEELWALL(properties_element) ||
12275       IS_BD_CONVEYOR_BELT(properties_element) ||
12276       IS_BD_CONVEYOR_BELT_SWITCH(properties_element) ||
12277       IS_SOKOBAN_OBJECT_OR_FIELD(element) ||
12278       HAS_EDITOR_CONTENT(element) ||
12279       CAN_GROW(element) ||
12280       COULD_MOVE_INTO_ACID(element) ||
12281       MAYBE_DONT_COLLIDE_WITH(element) ||
12282       element == EL_BD_SAND ||
12283       element == EL_BD_ROCK ||
12284       element == EL_BD_MEGA_ROCK ||
12285       element == EL_BD_BOMB ||
12286       element == EL_BD_ROCKET_LAUNCHER ||
12287       element == EL_BD_NITRO_PACK ||
12288       element == EL_BD_SWEET ||
12289       element == EL_BD_VOODOO_DOLL ||
12290       element == EL_BD_WATER ||
12291       element == EL_BD_GRAVITY_SWITCH)
12292   {
12293     return TRUE;
12294   }
12295   else
12296   {
12297     for (i = 0; elements_with_counter[i].element != -1; i++)
12298       if (elements_with_counter[i].element == element)
12299         return TRUE;
12300   }
12301
12302   return FALSE;
12303 }
12304
12305 static void SetAutomaticNumberOfGemsNeeded(void)
12306 {
12307   int x, y;
12308
12309   if (!level.auto_count_gems)
12310     return;
12311
12312   level.gems_needed = 0;
12313
12314   for (x = 0; x < lev_fieldx; x++)
12315   {
12316     for (y = 0; y < lev_fieldy; y++)
12317     {
12318       int element = Tile[x][y];
12319
12320       switch (element)
12321       {
12322         case EL_EMERALD:
12323         case EL_EMERALD_YELLOW:
12324         case EL_EMERALD_RED:
12325         case EL_EMERALD_PURPLE:
12326         case EL_BD_DIAMOND:
12327         case EL_WALL_EMERALD:
12328         case EL_WALL_EMERALD_YELLOW:
12329         case EL_WALL_EMERALD_RED:
12330         case EL_WALL_EMERALD_PURPLE:
12331         case EL_WALL_BD_DIAMOND:
12332         case EL_NUT:
12333         case EL_SP_INFOTRON:
12334         case EL_MM_KETTLE:
12335         case EL_DF_CELL:
12336           level.gems_needed++;
12337           break;
12338
12339         case EL_DIAMOND:
12340         case EL_WALL_DIAMOND:
12341           level.gems_needed += 3;
12342           break;
12343
12344         case EL_PEARL:
12345         case EL_WALL_PEARL:
12346           level.gems_needed += 5;
12347           break;
12348
12349         case EL_CRYSTAL:
12350         case EL_WALL_CRYSTAL:
12351           level.gems_needed += 8;
12352           break;
12353
12354         default:
12355           break;
12356       }
12357     }
12358   }
12359
12360   ModifyEditorCounterValue(ED_COUNTER_ID_LEVEL_GEMSLIMIT, level.gems_needed);
12361 }
12362
12363 static void DrawPropertiesConfig(void)
12364 {
12365   boolean draw_footer_line = FALSE;
12366   int max_num_element_counters = 4;
12367   int num_element_counters = 0;
12368   int i;
12369
12370   if (!checkPropertiesConfig(properties_element))
12371   {
12372     int xpos = ED_ELEMENT_SETTINGS_X(0);
12373     int ypos = ED_ELEMENT_SETTINGS_Y(0) + ED_GADGET_SMALL_DISTANCE;
12374
12375     PrintInfoText("No configuration options available.", FONT_TEXT_1, xpos, ypos);
12376
12377     return;
12378   }
12379
12380   // check if there are elements where a value can be chosen for
12381   for (i = 0; elements_with_counter[i].element != -1; i++)
12382   {
12383     if (elements_with_counter[i].element != properties_element)
12384       continue;
12385
12386     // special case: score for extra diamonds only available in BD game engine
12387     if (elements_with_counter[i].element == EL_BD_DIAMOND &&
12388         elements_with_counter[i].value == &level.score[SC_DIAMOND_EXTRA] &&
12389         level.game_engine_type != GAME_ENGINE_TYPE_BD)
12390       continue;
12391
12392     // special case: some amoeba counters only available in BD game engine
12393     if (elements_with_counter[i].element == EL_BD_AMOEBA &&
12394         elements_with_counter[i].value != &level.amoeba_speed &&
12395         level.game_engine_type != GAME_ENGINE_TYPE_BD)
12396       continue;
12397
12398     // special case: score for smashing only available in R'n'D game engine
12399     if ((IS_BD_FIREFLY(elements_with_counter[i].element) ||
12400          IS_BD_BUTTERFLY(elements_with_counter[i].element)) &&
12401         (elements_with_counter[i].value == &level.score[SC_BUG] ||
12402          elements_with_counter[i].value == &level.score[SC_SPACESHIP]) &&
12403         level.game_engine_type == GAME_ENGINE_TYPE_BD)
12404       continue;
12405
12406     // special case: some amoeba counters only available in R'n'D game engine
12407     if (elements_with_counter[i].element == EL_BD_AMOEBA &&
12408         elements_with_counter[i].value == &level.amoeba_speed &&
12409         level.game_engine_type == GAME_ENGINE_TYPE_BD)
12410       continue;
12411
12412     int counter_id = ED_COUNTER_ID_ELEMENT_VALUE1 + num_element_counters;
12413
12414     counterbutton_info[counter_id].y =
12415       ED_ELEMENT_SETTINGS_YPOS((HAS_EDITOR_CONTENT(properties_element)      ? 1 : 0) +
12416                                (CAN_GROW(properties_element)                ? 1 : 0) +
12417                                (COULD_MOVE_INTO_ACID(properties_element)    ? 1 : 0) +
12418                                (MAYBE_DONT_COLLIDE_WITH(properties_element) ? 1 : 0) +
12419                                (properties_element == EL_BD_VOODOO_DOLL     ? 4 : 0) +
12420                                (properties_element == EL_BD_SLIME           ? 1 : 0) +
12421                                (properties_element == EL_BD_ACID            ? 1 : 0) +
12422                                (properties_element == EL_BD_REPLICATOR      ? 1 : 0) +
12423                                (properties_element == EL_BD_CREATURE_SWITCH ? 1 : 0) +
12424                                (properties_element == EL_BD_GRAVITY_SWITCH  ? 2 : 0) +
12425                                (properties_element == EL_EMC_MAGIC_BALL     ? 2 : 0) +
12426                                num_element_counters);
12427
12428     // special case: set magic wall counter for BD game engine separately
12429     if (properties_element == EL_BD_MAGIC_WALL && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12430       counterbutton_info[counter_id].y = ED_ELEMENT_SETTINGS_YPOS(1);
12431
12432     // special case: set amoeba counters for BD game engine separately
12433     if ((properties_element == EL_BD_AMOEBA && level.game_engine_type == GAME_ENGINE_TYPE_BD) ||
12434         (properties_element == EL_BD_AMOEBA_2))
12435       counterbutton_info[counter_id].y = ED_ELEMENT_SETTINGS_YPOS(3 + num_element_counters);
12436
12437     // special case: set position for delay counter for reappearing hammered walls
12438     if (properties_element == EL_BD_PNEUMATIC_HAMMER && num_element_counters > 0)
12439       counterbutton_info[counter_id].y += 1;
12440
12441     counterbutton_info[counter_id].value      = elements_with_counter[i].value;
12442     counterbutton_info[counter_id].text_right = elements_with_counter[i].text;
12443     counterbutton_info[counter_id].min_value  = elements_with_counter[i].min_value;
12444     counterbutton_info[counter_id].max_value  = elements_with_counter[i].max_value;
12445
12446     // default: counter values between 0 and 999
12447     if (counterbutton_info[counter_id].max_value == 0)
12448       counterbutton_info[counter_id].max_value = 999;
12449
12450     MapCounterButtons(counter_id);
12451
12452     num_element_counters++;
12453     if (num_element_counters >= max_num_element_counters)
12454       break;
12455   }
12456
12457   if (properties_element == EL_BD_MAGIC_WALL && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12458   {
12459     // draw stickybutton gadget
12460     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12461
12462     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_MAGIC_WALL_ZERO_INFINITE);
12463     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_MAGIC_WALL_WAIT_HATCHING);
12464     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_MAGIC_WALL_STOPS_AMOEBA);
12465     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_MAGIC_WALL_BREAK_SCAN);
12466
12467     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_DIAMOND_TO);
12468     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_ROCK_TO);
12469     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_MEGA_ROCK_TO);
12470     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_NUT_TO);
12471     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_NITRO_PACK_TO);
12472     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_FLYING_DIAMOND_TO);
12473     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_FLYING_ROCK_TO);
12474   }
12475
12476   if (HAS_EDITOR_CONTENT(properties_element))
12477   {
12478     // draw stickybutton gadget
12479     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12480
12481     if (properties_element == EL_BD_AMOEBA && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12482     {
12483       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_WAIT_FOR_HATCHING);
12484       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_START_IMMEDIATELY);
12485
12486       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_CONTENT_TOO_BIG);
12487       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_CONTENT_ENCLOSED);
12488     }
12489     else if (properties_element == EL_BD_AMOEBA_2)
12490     {
12491       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_WAIT_FOR_HATCHING);
12492       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_START_IMMEDIATELY);
12493       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_2_EXPLODE_BY_AMOEBA);
12494
12495       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_TOO_BIG);
12496       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_ENCLOSED);
12497       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_EXPLODING);
12498       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_LOOKS_LIKE);
12499     }
12500     else if (IS_AMOEBOID(properties_element))
12501     {
12502       MapDrawingArea(ED_DRAWING_ID_AMOEBA_CONTENT);
12503     }
12504     else if (properties_element == EL_BD_ACID)
12505     {
12506       MapDrawingArea(ED_DRAWING_ID_BD_ACID_EATS_ELEMENT);
12507       MapDrawingArea(ED_DRAWING_ID_BD_ACID_TURNS_TO_ELEMENT);
12508     }
12509     else if (IS_BD_BITER(properties_element))
12510     {
12511       MapDrawingArea(ED_DRAWING_ID_BD_BITER_EATS_ELEMENT);
12512     }
12513     else if (properties_element == EL_BD_BLADDER)
12514     {
12515       MapDrawingArea(ED_DRAWING_ID_BD_BLADDER_CONVERTS_BY_ELEMENT);
12516     }
12517     else if (properties_element == EL_YAMYAM ||
12518              properties_element == EL_YAMYAM_LEFT ||
12519              properties_element == EL_YAMYAM_RIGHT ||
12520              properties_element == EL_YAMYAM_UP ||
12521              properties_element == EL_YAMYAM_DOWN)
12522     {
12523       DrawYamYamContentAreas();
12524     }
12525     else if (properties_element == EL_EMC_MAGIC_BALL)
12526     {
12527       DrawMagicBallContentAreas();
12528
12529       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_RANDOM_BALL_CONTENT);
12530       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INITIAL_BALL_ACTIVE);
12531     }
12532     else if (properties_element == EL_EMC_ANDROID)
12533     {
12534       DrawAndroidElementArea();
12535     }
12536     else if (properties_element == EL_MM_GRAY_BALL)
12537     {
12538       MapCounterButtons(ED_COUNTER_ID_MM_BALL_CONTENT);
12539       MapSelectboxGadget(ED_SELECTBOX_ID_MM_BALL_CHOICE_MODE);
12540       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_ROTATE_MM_BALL_CONTENT);
12541       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EXPLODE_MM_BALL);
12542
12543       DrawMMBallContentArea();
12544     }
12545   }
12546
12547   if (IS_PLAYER_ELEMENT(properties_element))
12548   {
12549     int player_nr = GET_PLAYER_NR(properties_element);
12550
12551     // these properties can be set for every player individually
12552
12553     if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_1)
12554     {
12555       drawingarea_info[ED_DRAWING_ID_START_ELEMENT].value =
12556         &level.start_element[player_nr];
12557       drawingarea_info[ED_DRAWING_ID_ARTWORK_ELEMENT].value =
12558         &level.artwork_element[player_nr];
12559       drawingarea_info[ED_DRAWING_ID_EXPLOSION_ELEMENT].value =
12560         &level.explosion_element[player_nr];
12561
12562       checkbutton_info[ED_CHECKBUTTON_ID_USE_START_ELEMENT].value =
12563         &level.use_start_element[player_nr];
12564       checkbutton_info[ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT].value =
12565         &level.use_artwork_element[player_nr];
12566       checkbutton_info[ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT].value =
12567         &level.use_explosion_element[player_nr];
12568       checkbutton_info[ED_CHECKBUTTON_ID_INITIAL_GRAVITY].value =
12569         &level.initial_player_gravity[player_nr];
12570
12571       selectbox_info[ED_SELECTBOX_ID_PLAYER_SPEED].value =
12572         &level.initial_player_stepsize[player_nr];
12573
12574       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID);
12575       MapCheckbuttonGadget(properties_element == EL_SP_MURPHY ?
12576                            ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD :
12577                            ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD);
12578       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BLOCK_SNAP_FIELD);
12579       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CONTINUOUS_SNAPPING);
12580       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INSTANT_RELOCATION);
12581       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SHIFTED_RELOCATION);
12582       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_LAZY_RELOCATION);
12583       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_START_ELEMENT);
12584       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT);
12585       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT);
12586       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INITIAL_GRAVITY);
12587       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE);
12588       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SOLVED_BY_ONE_PLAYER);
12589
12590       MapDrawingArea(ED_DRAWING_ID_START_ELEMENT);
12591       MapDrawingArea(ED_DRAWING_ID_ARTWORK_ELEMENT);
12592       MapDrawingArea(ED_DRAWING_ID_EXPLOSION_ELEMENT);
12593
12594       MapSelectboxGadget(ED_SELECTBOX_ID_PLAYER_SPEED);
12595     }
12596     else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2)
12597     {
12598       drawingarea_info[ED_DRAWING_ID_INVENTORY_CONTENT].value =
12599         &level.initial_inventory_content[player_nr][0];
12600
12601       counterbutton_info[ED_COUNTER_ID_INVENTORY_SIZE].value =
12602         &level.initial_inventory_size[player_nr];
12603
12604       checkbutton_info[ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY].value =
12605         &level.use_initial_inventory[player_nr];
12606
12607       // draw checkbutton gadgets
12608       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY);
12609       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_FINISH_DIG_COLLECT);
12610       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_KEEP_WALKABLE_CE);
12611
12612       // draw counter gadgets
12613       MapCounterButtons(ED_COUNTER_ID_INVENTORY_SIZE);
12614
12615       // draw drawing area gadgets
12616       DrawPlayerInitialInventoryArea(properties_element);
12617     }
12618   }
12619
12620   if (IS_BD_PLAYER_ELEMENT(properties_element))
12621   {
12622     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB].y =
12623       ED_ELEMENT_SETTINGS_YPOS(2);
12624     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET].y =
12625       ED_ELEMENT_SETTINGS_YPOS(3);
12626     checkbutton_info[ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET].y =
12627       ED_ELEMENT_SETTINGS_YPOS(4);
12628
12629     // draw checkbutton gadgets
12630     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_DIAGONAL_MOVEMENTS);
12631     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_TOPMOST_PLAYER_ACTIVE);
12632     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET);
12633
12634     // draw counter gadgets
12635     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB);
12636     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET);
12637
12638     // draw drawing area gadgets
12639     MapDrawingArea(ED_DRAWING_ID_BD_SNAP_ELEMENT);
12640   }
12641
12642   if (properties_element == EL_BD_SAND)
12643   {
12644     MapDrawingArea(ED_DRAWING_ID_BD_SAND_LOOKS_LIKE);
12645   }
12646
12647   if (properties_element == EL_BD_ROCK && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12648   {
12649     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB].y =
12650       ED_ELEMENT_SETTINGS_YPOS(0);
12651     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET].y =
12652       ED_ELEMENT_SETTINGS_YPOS(1);
12653
12654     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB);
12655     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET);
12656
12657     MapDrawingArea(ED_DRAWING_ID_BD_ROCK_TURNS_TO_ON_FALLING);
12658     MapDrawingArea(ED_DRAWING_ID_BD_ROCK_TURNS_TO_ON_IMPACT);
12659   }
12660
12661   if (properties_element == EL_BD_DIAMOND && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12662   {
12663     MapDrawingArea(ED_DRAWING_ID_BD_DIAMOND_TURNS_TO_ON_FALLING);
12664     MapDrawingArea(ED_DRAWING_ID_BD_DIAMOND_TURNS_TO_ON_IMPACT);
12665   }
12666
12667   if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
12668   {
12669     if (IS_BD_FIREFLY(properties_element))
12670     {
12671       MapDrawingArea(ED_DRAWING_ID_BD_FIREFLY_EXPLODES_TO);
12672       MapDrawingArea(ED_DRAWING_ID_BD_EXPLOSION_TURNS_TO);
12673     }
12674     else if (IS_BD_FIREFLY_2(properties_element))
12675     {
12676       MapDrawingArea(ED_DRAWING_ID_BD_FIREFLY_2_EXPLODES_TO);
12677       MapDrawingArea(ED_DRAWING_ID_BD_EXPLOSION_TURNS_TO);
12678     }
12679     else if (IS_BD_BUTTERFLY(properties_element))
12680     {
12681       MapDrawingArea(ED_DRAWING_ID_BD_BUTTERFLY_EXPLODES_TO);
12682       MapDrawingArea(ED_DRAWING_ID_BD_DIAMOND_BIRTH_TURNS_TO);
12683     }
12684     else if (IS_BD_BUTTERFLY_2(properties_element))
12685     {
12686       MapDrawingArea(ED_DRAWING_ID_BD_BUTTERFLY_2_EXPLODES_TO);
12687       MapDrawingArea(ED_DRAWING_ID_BD_DIAMOND_BIRTH_TURNS_TO);
12688     }
12689     else if (IS_BD_STONEFLY(properties_element))
12690     {
12691       MapDrawingArea(ED_DRAWING_ID_BD_STONEFLY_EXPLODES_TO);
12692     }
12693     else if (IS_BD_DRAGONFLY(properties_element))
12694     {
12695       MapDrawingArea(ED_DRAWING_ID_BD_DRAGONFLY_EXPLODES_TO);
12696       MapDrawingArea(ED_DRAWING_ID_BD_EXPLOSION_TURNS_TO);
12697     }
12698     else if (properties_element == EL_BD_BOMB)
12699     {
12700       MapDrawingArea(ED_DRAWING_ID_BD_BOMB_EXPLOSION_TURNS_TO);
12701     }
12702     else if (properties_element == EL_BD_NITRO_PACK)
12703     {
12704       MapDrawingArea(ED_DRAWING_ID_BD_NITRO_EXPLOSION_TURNS_TO);
12705     }
12706   }
12707
12708   if (properties_element == EL_BD_MEGA_ROCK ||
12709       properties_element == EL_BD_SWEET)
12710   {
12711     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET].y =
12712       ED_ELEMENT_SETTINGS_YPOS(0);
12713     checkbutton_info[ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET].y =
12714       ED_ELEMENT_SETTINGS_YPOS(1);
12715
12716     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET);
12717     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET);
12718   }
12719
12720   if (properties_element == EL_BD_VOODOO_DOLL)
12721   {
12722     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_VOODOO_COLLECTS_DIAMONDS);
12723     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_VOODOO_HURT_KILLS_PLAYER);
12724     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_VOODOO_DIES_BY_ROCK);
12725     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_VOODOO_VANISH_BY_EXPLOSION);
12726   }
12727
12728   if (properties_element == EL_BD_SLIME)
12729   {
12730     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_SLIME_IS_PREDICTABLE);
12731
12732     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_1);
12733     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_1);
12734     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_2);
12735     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_2);
12736     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_3);
12737     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_3);
12738   }
12739
12740   if (IS_BD_EXPANDABLE_WALL(properties_element) ||
12741       IS_BD_EXPANDABLE_STEELWALL(properties_element))
12742   {
12743     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CHANGE_EXPANDING_WALL);
12744
12745     if (IS_BD_EXPANDABLE_WALL(properties_element))
12746       MapDrawingArea(ED_DRAWING_ID_BD_EXPANDING_WALL_LOOKS_LIKE);
12747   }
12748
12749   if (properties_element == EL_BD_REPLICATOR)
12750   {
12751     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_REPLICATORS_ACTIVE);
12752   }
12753
12754   if (IS_BD_CONVEYOR_BELT(properties_element) ||
12755       IS_BD_CONVEYOR_BELT_SWITCH(properties_element))
12756   {
12757     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_ACTIVE);
12758     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_CHANGED);
12759   }
12760
12761   if (properties_element == EL_BD_WATER)
12762   {
12763     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_WATER_CANNOT_FLOW_DOWN);
12764   }
12765
12766   if (properties_element == EL_BD_PNEUMATIC_HAMMER)
12767   {
12768     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_HAMMER_WALLS_REAPPEAR);
12769   }
12770
12771   if (properties_element == EL_BD_ROCKET_LAUNCHER)
12772   {
12773     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_INFINITE_ROCKETS);
12774   }
12775
12776   if (properties_element == EL_BD_CREATURE_SWITCH)
12777   {
12778     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CREATURES_START_BACKWARDS);
12779     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CREATURES_TURN_ON_HATCHING);
12780   }
12781
12782   if (properties_element == EL_BD_GRAVITY_SWITCH)
12783   {
12784     MapSelectboxGadget(ED_SELECTBOX_ID_BD_GRAVITY_DIRECTION);
12785
12786     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_GRAVITY_SWITCH_ACTIVE);
12787     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_GRAVITY_AFFECTS_ALL);
12788   }
12789
12790   if (properties_element == EL_BD_NUT)
12791   {
12792     MapDrawingArea(ED_DRAWING_ID_BD_NUT_CONTENT);
12793   }
12794
12795   // special case: slippery walls option for gems only available in R'n'D game engine
12796   if (IS_GEM(properties_element) && level.game_engine_type == GAME_ENGINE_TYPE_RND)
12797     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS);
12798
12799   if (properties_element == EL_EM_DYNAMITE)
12800     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_EXPLODES_BY_FIRE);
12801
12802   if (level.game_engine_type == GAME_ENGINE_TYPE_RND &&
12803       COULD_MOVE_INTO_ACID(properties_element) &&
12804       !IS_PLAYER_ELEMENT(properties_element) &&
12805       (!IS_CUSTOM_ELEMENT(properties_element) ||
12806        edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2))
12807   {
12808     // set position for checkbutton for "can move into acid"
12809     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].x =
12810       ED_ELEMENT_SETTINGS_XPOS(IS_CUSTOM_ELEMENT(properties_element) ? 1 : 0);
12811     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].y =
12812       ED_ELEMENT_SETTINGS_YPOS(IS_CUSTOM_ELEMENT(properties_element) ? 7 :
12813                                IS_BALLOON_ELEMENT(properties_element) ||
12814                                HAS_EDITOR_CONTENT(properties_element) ? 1 : 0);
12815
12816     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID);
12817   }
12818
12819   if (MAYBE_DONT_COLLIDE_WITH(properties_element))
12820     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH);
12821
12822   if (properties_element == EL_SPRING ||
12823       properties_element == EL_SPRING_LEFT ||
12824       properties_element == EL_SPRING_RIGHT)
12825     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_SPRING_BUG);
12826
12827   if (properties_element == EL_TIME_ORB_FULL)
12828     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_TIME_ORB_BUG);
12829
12830   if (properties_element == EL_GAME_OF_LIFE ||
12831       properties_element == EL_BIOMAZE)
12832     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_LIFE_BUGS);
12833
12834   if (CAN_GROW(properties_element) && level.game_engine_type != GAME_ENGINE_TYPE_BD)
12835   {
12836     checkbutton_info[ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE].y =
12837       ED_ELEMENT_SETTINGS_YPOS(HAS_EDITOR_CONTENT(properties_element) ? 1 : 0);
12838
12839     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE);
12840   }
12841
12842   if (properties_element == EL_SOKOBAN_FIELD_EMPTY)
12843     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SB_FIELDS_NEEDED);
12844
12845   if (properties_element == EL_SOKOBAN_OBJECT)
12846     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SB_OBJECTS_NEEDED);
12847
12848   if (properties_element == EL_SOKOBAN_OBJECT ||
12849       properties_element == EL_SOKOBAN_FIELD_EMPTY ||
12850       properties_element == EL_SOKOBAN_FIELD_FULL)
12851   {
12852     checkbutton_info[ED_CHECKBUTTON_ID_AUTO_EXIT_SOKOBAN].y =
12853       ED_ELEMENT_SETTINGS_XPOS(properties_element == EL_SOKOBAN_FIELD_FULL ?
12854                                0 : 1);
12855
12856     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_AUTO_EXIT_SOKOBAN);
12857   }
12858
12859   if (IS_BALLOON_ELEMENT(properties_element))
12860     MapSelectboxGadget(ED_SELECTBOX_ID_WIND_DIRECTION);
12861
12862   if (IS_ENVELOPE(properties_element) ||
12863       IS_MM_ENVELOPE(properties_element))
12864   {
12865     int counter1_id = ED_COUNTER_ID_ENVELOPE_XSIZE;
12866     int counter2_id = ED_COUNTER_ID_ENVELOPE_YSIZE;
12867     int button1_id = ED_CHECKBUTTON_ID_ENVELOPE_AUTOWRAP;
12868     int button2_id = ED_CHECKBUTTON_ID_ENVELOPE_CENTERED;
12869     int envelope_nr = ENVELOPE_NR(properties_element);
12870
12871     counterbutton_info[counter1_id].value = &level.envelope[envelope_nr].xsize;
12872     counterbutton_info[counter2_id].value = &level.envelope[envelope_nr].ysize;
12873
12874     checkbutton_info[button1_id].value = &level.envelope[envelope_nr].autowrap;
12875     checkbutton_info[button2_id].value = &level.envelope[envelope_nr].centered;
12876
12877     // display counter to choose size of envelope text area
12878     MapCounterButtons(counter1_id);
12879     MapCounterButtons(counter2_id);
12880
12881     // display checkbuttons to choose auto-wrap and alignment properties
12882     MapCheckbuttonGadget(button1_id);
12883     MapCheckbuttonGadget(button2_id);
12884
12885     DrawEnvelopeTextArea(envelope_nr);
12886   }
12887
12888   if (IS_MM_MCDUFFIN(properties_element))
12889   {
12890     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_RED);
12891     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_GREEN);
12892     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_BLUE);
12893   }
12894
12895   if (IS_DF_LASER(properties_element))
12896   {
12897     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_RED);
12898     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_GREEN);
12899     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_BLUE);
12900   }
12901
12902   if (IS_CUSTOM_ELEMENT(properties_element))
12903   {
12904     // draw stickybutton gadget
12905     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12906
12907     if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_1)
12908     {
12909       // draw checkbutton gadgets
12910       for (i =  ED_CHECKBUTTON_ID_CUSTOM1_FIRST;
12911            i <= ED_CHECKBUTTON_ID_CUSTOM1_LAST; i++)
12912         MapCheckbuttonGadget(i);
12913
12914       // draw counter gadgets
12915       for (i =  ED_COUNTER_ID_CUSTOM1_FIRST;
12916            i <= ED_COUNTER_ID_CUSTOM1_LAST; i++)
12917         MapCounterButtons(i);
12918
12919       // draw selectbox gadgets
12920       for (i =  ED_SELECTBOX_ID_CUSTOM1_FIRST;
12921            i <= ED_SELECTBOX_ID_CUSTOM1_LAST; i++)
12922         MapSelectboxGadget(i);
12923
12924       // draw textbutton gadgets
12925       MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
12926
12927       // draw text input gadgets
12928       MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
12929
12930       // draw drawing area gadgets
12931       MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
12932
12933       draw_footer_line = TRUE;
12934     }
12935     else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2)
12936     {
12937       // draw checkbutton gadgets
12938       for (i =  ED_CHECKBUTTON_ID_CUSTOM2_FIRST;
12939            i <= ED_CHECKBUTTON_ID_CUSTOM2_LAST; i++)
12940         MapCheckbuttonGadget(i);
12941
12942       // draw counter gadgets
12943       for (i =  ED_COUNTER_ID_CUSTOM2_FIRST;
12944            i <= ED_COUNTER_ID_CUSTOM2_LAST; i++)
12945         MapCounterButtons(i);
12946
12947       // draw selectbox gadgets
12948       for (i =  ED_SELECTBOX_ID_CUSTOM2_FIRST;
12949            i <= ED_SELECTBOX_ID_CUSTOM2_LAST; i++)
12950         MapSelectboxGadget(i);
12951
12952       // draw drawing area gadgets
12953       MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_ENTER);
12954       MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_LEAVE);
12955       DrawCustomContentArea();
12956     }
12957   }
12958   else if (IS_GROUP_ELEMENT(properties_element))
12959   {
12960     // draw stickybutton gadget
12961     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12962
12963     // draw checkbutton gadgets
12964     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
12965     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1);
12966
12967     // draw counter gadgets
12968     MapCounterButtons(ED_COUNTER_ID_GROUP_CONTENT);
12969
12970     // draw selectbox gadgets
12971     MapSelectboxGadget(ED_SELECTBOX_ID_GROUP_CHOICE_MODE);
12972
12973     // draw textbutton gadgets
12974     MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
12975
12976     // draw drawing area gadgets
12977     DrawGroupElementArea();
12978
12979     // draw text input gadgets
12980     MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
12981
12982     // draw drawing area gadgets
12983     MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
12984
12985     draw_footer_line = TRUE;
12986   }
12987   else if (IS_EMPTY_ELEMENT(properties_element))
12988   {
12989     // draw stickybutton gadget
12990     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12991
12992     // draw checkbutton gadgets
12993     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
12994     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1);
12995
12996     // draw textbutton gadgets
12997     MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
12998
12999     // draw drawing area gadgets
13000     MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
13001
13002     draw_footer_line = TRUE;
13003   }
13004
13005   // draw little footer border line above CE/GE use/save template gadgets
13006   if (draw_footer_line)
13007   {
13008     struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
13009     struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
13010     int gd_x = gd->x + gd_gi1->border.width / 2;
13011     int gd_y = gd->y + gd_gi1->height - 1;
13012     Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
13013
13014     if (tab_color != BLACK_PIXEL)               // black => transparent
13015       FillRectangle(drawto,
13016                     SX + ED_ELEMENT_SETTINGS_X(0),
13017                     SY + ED_ELEMENT_SETTINGS_Y(14) - ED_SETTINGS_TABS_YOFFSET -
13018                     ED_TAB_BAR_HEIGHT,
13019                     getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
13020   }
13021 }
13022
13023 static void DrawPropertiesChangeDrawingAreas(void)
13024 {
13025   if (IS_CUSTOM_ELEMENT(properties_element))
13026   {
13027     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TARGET);
13028     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER);
13029     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_ACTION);
13030
13031     DrawCustomChangeContentArea();
13032   }
13033
13034   redraw_mask |= REDRAW_FIELD;
13035 }
13036
13037 static void DrawPropertiesChange(void)
13038 {
13039   int i;
13040
13041   // needed to initially set selectbox options for special action options
13042   setSelectboxSpecialActionOptions();
13043
13044   // draw stickybutton gadget
13045   MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
13046
13047   // draw checkbutton gadgets
13048   for (i =  ED_CHECKBUTTON_ID_CHANGE_FIRST;
13049        i <= ED_CHECKBUTTON_ID_CHANGE_LAST; i++)
13050     MapCheckbuttonGadget(i);
13051
13052   // draw counter gadgets
13053   for (i =  ED_COUNTER_ID_CHANGE_FIRST;
13054        i <= ED_COUNTER_ID_CHANGE_LAST; i++)
13055     MapCounterButtons(i);
13056
13057   // draw selectbox gadgets
13058   for (i =  ED_SELECTBOX_ID_CHANGE_FIRST;
13059        i <= ED_SELECTBOX_ID_CHANGE_LAST; i++)
13060     MapSelectboxGadget(i);
13061
13062   // draw textbutton gadgets
13063   for (i =  ED_TEXTBUTTON_ID_CHANGE_FIRST;
13064        i <= ED_TEXTBUTTON_ID_CHANGE_LAST; i++)
13065     MapTextbuttonGadget(i);
13066
13067   // draw graphicbutton gadgets
13068   for (i =  ED_GRAPHICBUTTON_ID_CHANGE_FIRST;
13069        i <= ED_GRAPHICBUTTON_ID_CHANGE_LAST; i++)
13070     MapGraphicbuttonGadget(i);
13071
13072   // draw drawing area gadgets
13073   DrawPropertiesChangeDrawingAreas();
13074 }
13075
13076 static void DrawEditorElementAnimation(int x, int y)
13077 {
13078   int graphic;
13079   int frame;
13080
13081   getEditorGraphicAndFrame(properties_element, &graphic, &frame, FALSE);
13082
13083   DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
13084 }
13085
13086 static void DrawEditorElementName(int x, int y, int font_nr)
13087 {
13088   char *element_name = getElementInfoText(properties_element);
13089   int font_width = getFontWidth(font_nr);
13090   int font_height = getFontHeight(font_nr);
13091   int max_text_width = SXSIZE - x - ED_ELEMENT_SETTINGS_X(0);
13092   int max_chars_per_line = max_text_width / font_width;
13093
13094   if (strlen(element_name) <= max_chars_per_line)
13095     DrawTextS(x, y, font_nr, element_name);
13096   else
13097   {
13098     char buffer[max_chars_per_line + 1];
13099     int next_pos = max_chars_per_line;
13100
13101     strncpy(buffer, element_name, max_chars_per_line);
13102     buffer[max_chars_per_line] = '\0';
13103
13104     if (element_name[max_chars_per_line] == ' ')
13105       next_pos++;
13106     else
13107     {
13108       int i;
13109
13110       for (i = max_chars_per_line - 1; i >= 0; i--)
13111         if (buffer[i] == ' ')
13112           break;
13113
13114       if (strlen(&element_name[i + 1]) <= max_chars_per_line)
13115       {
13116         buffer[i] = '\0';
13117         next_pos = i + 1;
13118       }
13119     }
13120
13121     DrawTextS(x, y - font_height / 2, font_nr, buffer);
13122
13123     strncpy(buffer, &element_name[next_pos], max_chars_per_line);
13124     buffer[max_chars_per_line] = '\0';
13125
13126     DrawTextS(x, y + font_height / 2, font_nr, buffer);
13127   }
13128 }
13129
13130 static void DrawPropertiesWindow(void)
13131 {
13132   struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_TEXT];
13133   int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
13134   int border_size = gd->border_size;
13135   int font_nr = FONT_TEXT_1;
13136   int font_height = getFontHeight(font_nr);
13137   int xoffset = TILEX + element_border + 3 * border_size;
13138   int yoffset = (TILEY - font_height) / 2;
13139   int x1 = editor.settings.element_graphic.x + element_border;
13140   int y1 = editor.settings.element_graphic.y + element_border;
13141   int x2 = (editor.settings.element_name.x == -1 ? x1 + xoffset :
13142             editor.settings.element_name.x);
13143   int y2 = (editor.settings.element_name.y == -1 ? y1 + yoffset :
13144             editor.settings.element_name.y);
13145   char *text = "Element Settings";
13146   int font2_nr = FONT_TITLE_1;
13147   struct MenuPosInfo *pos = &editor.settings.headline;
13148   int sx = SX + ALIGNED_XPOS(pos->x, getTextWidth(text, font2_nr), pos->align);
13149   int sy = SY + pos->y;
13150
13151   stick_element_properties_window = FALSE;
13152
13153   // make sure that previous properties edit mode exists for this element
13154   if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG_2 &&
13155       !IS_CUSTOM_ELEMENT(properties_element))
13156     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_2;
13157
13158   if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG &&
13159       !IS_PLAYER_ELEMENT(properties_element) &&
13160       !IS_CUSTOM_ELEMENT(properties_element))
13161     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
13162
13163   if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG &&
13164       (IS_PLAYER_ELEMENT(properties_element) ||
13165        IS_CUSTOM_ELEMENT(properties_element)))
13166     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_1;
13167
13168   CopyElementPropertiesToEditor(properties_element);
13169
13170   UnmapLevelEditorFieldGadgets();
13171   UnmapLevelEditorToolboxDrawingGadgets();
13172   UnmapLevelEditorToolboxCustomGadgets();
13173
13174   MapLevelEditorToolboxCustomGadgetsIfNeeded();
13175
13176   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
13177   ClearField();
13178
13179   DrawText(sx, sy, text, font2_nr);
13180
13181   FrameCounter = 0;     // restart animation frame counter
13182
13183   DrawElementBorder(SX + x1, SY + y1, TILEX, TILEY, FALSE);
13184   DrawEditorElementAnimation(SX + x1, SY + y1);
13185   DrawEditorElementName(x2, y2, font_nr);
13186
13187   DrawPropertiesTabulatorGadgets();
13188
13189   if (edit_mode_properties == ED_MODE_PROPERTIES_INFO)
13190     DrawPropertiesInfo();
13191   else if (edit_mode_properties == ED_MODE_PROPERTIES_CHANGE)
13192     DrawPropertiesChange();
13193   else  // (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG[_1|_2])
13194     DrawPropertiesConfig();
13195 }
13196
13197 static void DrawPaletteWindow(void)
13198 {
13199   int i;
13200
13201   UnmapLevelEditorFieldGadgets();
13202
13203   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
13204   ClearField();
13205
13206   // map buttons to select elements
13207   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
13208     MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
13209   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
13210   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
13211   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
13212 }
13213
13214 static void UpdateCustomElementGraphicGadgets(void)
13215 {
13216   int i;
13217
13218   InitElementPropertiesGfxElement();
13219
13220   ModifyEditorElementList();
13221   RedrawDrawingElements();
13222
13223   // force redraw of all mapped drawing area gadgets
13224   for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
13225   {
13226     struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[i].gadget_id];
13227
13228     if (gi->mapped)
13229       MapDrawingArea(i);
13230   }
13231 }
13232
13233 static int getOpenDirectionFromTube(int element)
13234 {
13235   switch (element)
13236   {
13237     case EL_TUBE_LEFT_UP:               return (MV_LEFT | MV_UP);
13238     case EL_TUBE_LEFT_DOWN:             return (MV_LEFT | MV_DOWN);
13239     case EL_TUBE_RIGHT_UP:              return (MV_RIGHT | MV_UP);
13240     case EL_TUBE_RIGHT_DOWN:            return (MV_RIGHT | MV_DOWN);
13241     case EL_TUBE_HORIZONTAL:            return (MV_HORIZONTAL);
13242     case EL_TUBE_HORIZONTAL_UP:         return (MV_HORIZONTAL | MV_UP);
13243     case EL_TUBE_HORIZONTAL_DOWN:       return (MV_HORIZONTAL | MV_DOWN);
13244     case EL_TUBE_VERTICAL:              return (MV_VERTICAL);
13245     case EL_TUBE_VERTICAL_LEFT:         return (MV_VERTICAL | MV_LEFT);
13246     case EL_TUBE_VERTICAL_RIGHT:        return (MV_VERTICAL | MV_RIGHT);
13247     case EL_TUBE_ANY:                   return (MV_ANY_DIRECTION);
13248   }
13249
13250   return MV_NONE;
13251 }
13252
13253 static int getTubeFromOpenDirection(int direction)
13254 {
13255   switch (direction)
13256   {
13257     case (MV_LEFT | MV_UP):             return EL_TUBE_LEFT_UP;
13258     case (MV_LEFT | MV_DOWN):           return EL_TUBE_LEFT_DOWN;
13259     case (MV_RIGHT | MV_UP):            return EL_TUBE_RIGHT_UP;
13260     case (MV_RIGHT | MV_DOWN):          return EL_TUBE_RIGHT_DOWN;
13261     case (MV_HORIZONTAL):               return EL_TUBE_HORIZONTAL;
13262     case (MV_HORIZONTAL | MV_UP):       return EL_TUBE_HORIZONTAL_UP;
13263     case (MV_HORIZONTAL | MV_DOWN):     return EL_TUBE_HORIZONTAL_DOWN;
13264     case (MV_VERTICAL):                 return EL_TUBE_VERTICAL;
13265     case (MV_VERTICAL | MV_LEFT):       return EL_TUBE_VERTICAL_LEFT;
13266     case (MV_VERTICAL | MV_RIGHT):      return EL_TUBE_VERTICAL_RIGHT;
13267     case (MV_ANY_DIRECTION):            return EL_TUBE_ANY;
13268
13269     // if only one direction, fall back to simple tube with that direction
13270     case (MV_LEFT):                     return EL_TUBE_HORIZONTAL;
13271     case (MV_RIGHT):                    return EL_TUBE_HORIZONTAL;
13272     case (MV_UP):                       return EL_TUBE_VERTICAL;
13273     case (MV_DOWN):                     return EL_TUBE_VERTICAL;
13274   }
13275
13276   return EL_EMPTY;
13277 }
13278
13279 static int getTubeFromOpenDirectionNotEmpty(int direction, int element_old)
13280 {
13281   int element_new = getTubeFromOpenDirection(direction);
13282
13283   return (element_new != EL_EMPTY ? element_new : element_old);
13284 }
13285
13286 static int getOpenDirectionFromBelt(int element)
13287 {
13288   int belt_dir = getBeltDirFromBeltElement(element);
13289
13290   return (belt_dir == MV_LEFT ? MV_RIGHT :
13291           belt_dir == MV_RIGHT ? MV_LEFT :
13292           belt_dir == MV_NONE ? MV_HORIZONTAL : belt_dir);
13293 }
13294
13295 static int getBeltFromNrAndOpenDirection(int nr, int direction)
13296 {
13297   int belt_dir = (direction == MV_LEFT ? MV_RIGHT :
13298                   direction == MV_RIGHT ? MV_LEFT :
13299                   direction == MV_HORIZONTAL ? MV_NONE : direction);
13300
13301   if (direction == MV_NONE)
13302     return EL_EMPTY;
13303
13304   return getBeltElementFromBeltNrAndBeltDir(nr, belt_dir);
13305 }
13306
13307 static int getBeltFromNrAndOpenDirectionNotEmpty(int nr, int direction,
13308                                                  int element_old)
13309 {
13310   int element_new = getBeltFromNrAndOpenDirection(nr, direction);
13311
13312   return (element_new != EL_EMPTY ? element_new : element_old);
13313 }
13314
13315 static int getOpenDirectionFromPool(int element)
13316 {
13317   switch (element)
13318   {
13319     case EL_ACID_POOL_TOPLEFT:          return (MV_DOWN | MV_RIGHT);
13320     case EL_ACID_POOL_TOPRIGHT:         return (MV_DOWN | MV_LEFT);
13321     case EL_ACID_POOL_BOTTOMLEFT:       return (MV_UP | MV_RIGHT);
13322     case EL_ACID_POOL_BOTTOMRIGHT:      return (MV_UP | MV_LEFT);
13323     case EL_ACID_POOL_BOTTOM:           return (MV_HORIZONTAL | MV_UP);
13324     case EL_ACID:                       return (MV_HORIZONTAL | MV_DOWN);
13325   }
13326
13327   return MV_NONE;
13328 }
13329
13330 static int getPoolFromOpenDirection(int direction)
13331 {
13332   switch (direction)
13333   {
13334     case (MV_DOWN | MV_RIGHT):          return EL_ACID_POOL_TOPLEFT;
13335     case (MV_DOWN | MV_LEFT):           return EL_ACID_POOL_TOPRIGHT;
13336     case (MV_UP | MV_RIGHT):            return EL_ACID_POOL_BOTTOMLEFT;
13337     case (MV_UP | MV_LEFT):             return EL_ACID_POOL_BOTTOMRIGHT;
13338     case (MV_HORIZONTAL | MV_UP):       return EL_ACID_POOL_BOTTOM;
13339     case (MV_HORIZONTAL | MV_DOWN):     return EL_ACID;
13340   }
13341
13342   return EL_EMPTY;
13343 }
13344
13345 static int getPoolFromOpenDirectionExt(int direction, int help_element)
13346 {
13347   int element = getPoolFromOpenDirection(direction);
13348   int help_direction = getOpenDirectionFromPool(help_element);
13349
13350   if (element == EL_EMPTY)
13351   {
13352     int help_direction_vertical = help_direction & MV_VERTICAL;
13353
13354     element = getPoolFromOpenDirection(direction | help_direction_vertical);
13355   }
13356
13357   if (element == EL_EMPTY)
13358   {
13359     int help_direction_horizontal = help_direction & MV_HORIZONTAL;
13360
13361     element = getPoolFromOpenDirection(direction | help_direction_horizontal);
13362   }
13363
13364   return element;
13365 }
13366
13367 static int getPoolFromOpenDirectionNotEmpty(int direction, int element_old)
13368 {
13369   int element_new = getPoolFromOpenDirectionExt(direction, element_old);
13370
13371   return (element_new != EL_EMPTY ? element_new : element_old);
13372 }
13373
13374 static int getOpenDirectionFromPillar(int element)
13375 {
13376   switch (element)
13377   {
13378     case EL_EMC_WALL_1:                 return (MV_DOWN);
13379     case EL_EMC_WALL_2:                 return (MV_VERTICAL);
13380     case EL_EMC_WALL_3:                 return (MV_UP);
13381   }
13382
13383   return MV_NONE;
13384 }
13385
13386 static int getPillarFromOpenDirection(int direction)
13387 {
13388   switch (direction)
13389   {
13390     case (MV_DOWN):                     return EL_EMC_WALL_1;
13391     case (MV_VERTICAL):                 return EL_EMC_WALL_2;
13392     case (MV_UP):                       return EL_EMC_WALL_3;
13393   }
13394
13395   return EL_EMPTY;
13396 }
13397
13398 static int getPillarFromOpenDirectionNotEmpty(int direction, int element_old)
13399 {
13400   int element_new = getPillarFromOpenDirection(direction);
13401
13402   return (element_new != EL_EMPTY ? element_new : element_old);
13403 }
13404
13405 static int getOpenDirectionFromSteel2(int element)
13406 {
13407   switch (element)
13408   {
13409     case EL_DC_STEELWALL_2_LEFT:        return (MV_RIGHT);
13410     case EL_DC_STEELWALL_2_RIGHT:       return (MV_LEFT);
13411     case EL_DC_STEELWALL_2_TOP:         return (MV_DOWN);
13412     case EL_DC_STEELWALL_2_BOTTOM:      return (MV_UP);
13413     case EL_DC_STEELWALL_2_HORIZONTAL:  return (MV_HORIZONTAL);
13414     case EL_DC_STEELWALL_2_VERTICAL:    return (MV_VERTICAL);
13415     case EL_DC_STEELWALL_2_MIDDLE:      return (MV_ANY_DIRECTION);
13416     case EL_DC_STEELWALL_2_SINGLE:      return (MV_NONE);
13417   }
13418
13419   return MV_NONE;
13420 }
13421
13422 static int getSteel2FromOpenDirection(int direction)
13423 {
13424   switch (direction)
13425   {
13426     case (MV_RIGHT):                    return EL_DC_STEELWALL_2_LEFT;
13427     case (MV_LEFT):                     return EL_DC_STEELWALL_2_RIGHT;
13428     case (MV_DOWN):                     return EL_DC_STEELWALL_2_TOP;
13429     case (MV_UP):                       return EL_DC_STEELWALL_2_BOTTOM;
13430     case (MV_HORIZONTAL):               return EL_DC_STEELWALL_2_HORIZONTAL;
13431     case (MV_VERTICAL):                 return EL_DC_STEELWALL_2_VERTICAL;
13432     case (MV_ANY_DIRECTION):            return EL_DC_STEELWALL_2_MIDDLE;
13433     case (MV_NONE):                     return EL_DC_STEELWALL_2_SINGLE;
13434   }
13435
13436   return EL_EMPTY;
13437 }
13438
13439 static int getSteel2FromOpenDirectionNotEmpty(int direction, int element_old)
13440 {
13441   int element_new = getSteel2FromOpenDirection(direction);
13442
13443   return (element_new != EL_EMPTY ? element_new : element_old);
13444 }
13445
13446 static int getOpenDirectionFromChip(int element)
13447 {
13448   switch (element)
13449   {
13450     case EL_SP_CHIP_SINGLE:             return (MV_NONE);
13451     case EL_SP_CHIP_LEFT:               return (MV_RIGHT);
13452     case EL_SP_CHIP_RIGHT:              return (MV_LEFT);
13453     case EL_SP_CHIP_TOP:                return (MV_DOWN);
13454     case EL_SP_CHIP_BOTTOM:             return (MV_UP);
13455   }
13456
13457   return MV_NONE;
13458 }
13459
13460 static int getChipFromOpenDirection(int direction)
13461 {
13462   switch (direction)
13463   {
13464     case (MV_NONE):                     return EL_SP_CHIP_SINGLE;
13465     case (MV_LEFT):                     return EL_SP_CHIP_RIGHT;
13466     case (MV_RIGHT):                    return EL_SP_CHIP_LEFT;
13467     case (MV_UP):                       return EL_SP_CHIP_BOTTOM;
13468     case (MV_DOWN):                     return EL_SP_CHIP_TOP;
13469   }
13470
13471   return EL_EMPTY;
13472 }
13473
13474 static int getChipFromOpenDirectionNotEmpty(int direction, int element_old)
13475 {
13476   int element_new = getChipFromOpenDirection(direction);
13477
13478   return (element_new != EL_EMPTY ? element_new : element_old);
13479 }
13480
13481 static int getClosedTube(int x, int y)
13482 {
13483   struct XY *xy = xy_directions;
13484   int element_old = IntelliDrawBuffer[x][y];
13485   int direction_old = getOpenDirectionFromTube(element_old);
13486   int direction_new = MV_NONE;
13487   int i;
13488
13489   for (i = 0; i < NUM_DIRECTIONS; i++)
13490   {
13491     int xx = x + xy[i].x;
13492     int yy = y + xy[i].y;
13493     int dir = MV_DIR_FROM_BIT(i);
13494     int dir_opposite = MV_DIR_OPPOSITE(dir);
13495
13496     if (IN_LEV_FIELD(xx, yy) && IS_TUBE(IntelliDrawBuffer[xx][yy]) &&
13497         (direction_old & dir) &&
13498         (getOpenDirectionFromTube(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13499       direction_new |= dir;
13500   }
13501
13502   return getTubeFromOpenDirectionNotEmpty(direction_new, element_old);
13503 }
13504
13505 static int getClosedBelt(int x, int y)
13506 {
13507   struct XY *xy = xy_directions;
13508   int element_old = IntelliDrawBuffer[x][y];
13509   int nr = getBeltNrFromBeltElement(element_old);
13510   int direction_old = getOpenDirectionFromBelt(element_old);
13511   int direction_new = MV_NONE;
13512   int i;
13513
13514   for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
13515   {
13516     int xx = x + xy[i].x;
13517     int yy = y + xy[i].y;
13518     int dir = MV_DIR_FROM_BIT(i);
13519     int dir_opposite = MV_DIR_OPPOSITE(dir);
13520
13521     if (IN_LEV_FIELD(xx, yy) && IS_BELT(IntelliDrawBuffer[xx][yy]) &&
13522         (direction_old & dir) &&
13523         (getOpenDirectionFromBelt(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13524       direction_new |= dir;
13525   }
13526
13527   return getBeltFromNrAndOpenDirection(nr, direction_new);
13528 }
13529
13530 static int getClosedPool(int x, int y)
13531 {
13532   struct XY *xy = xy_directions;
13533   int element_old = IntelliDrawBuffer[x][y];
13534   int direction_old = getOpenDirectionFromPool(element_old);
13535   int direction_new = MV_NONE;
13536   int i;
13537
13538   for (i = 0; i < NUM_DIRECTIONS; i++)
13539   {
13540     int xx = x + xy[i].x;
13541     int yy = y + xy[i].y;
13542     int dir = MV_DIR_FROM_BIT(i);
13543     int dir_opposite = MV_DIR_OPPOSITE(dir);
13544
13545     if (IN_LEV_FIELD(xx, yy) &&
13546         IS_ACID_POOL_OR_ACID(IntelliDrawBuffer[xx][yy]) &&
13547         (direction_old & dir) &&
13548         (getOpenDirectionFromPool(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13549       direction_new |= dir;
13550   }
13551
13552   return getPoolFromOpenDirectionNotEmpty(direction_new, element_old);
13553 }
13554
13555 static int getClosedPillar(int x, int y)
13556 {
13557   struct XY *xy = xy_directions;
13558   int element_old = IntelliDrawBuffer[x][y];
13559   int direction_old = getOpenDirectionFromPillar(element_old);
13560   int direction_new = MV_NONE;
13561   int i;
13562
13563   for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
13564   {
13565     int xx = x + xy[i].x;
13566     int yy = y + xy[i].y;
13567     int dir = MV_DIR_FROM_BIT(i);
13568     int dir_opposite = MV_DIR_OPPOSITE(dir);
13569
13570     if (IN_LEV_FIELD(xx, yy) && IS_EMC_PILLAR(IntelliDrawBuffer[xx][yy]) &&
13571         (direction_old & dir) &&
13572         (getOpenDirectionFromPillar(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13573       direction_new |= dir;
13574   }
13575
13576   return getPillarFromOpenDirectionNotEmpty(direction_new, element_old);
13577 }
13578
13579 static int getClosedSteel2(int x, int y)
13580 {
13581   struct XY *xy = xy_directions;
13582   int element_old = IntelliDrawBuffer[x][y];
13583   int direction_old = getOpenDirectionFromSteel2(element_old);
13584   int direction_new = MV_NONE;
13585   int i;
13586
13587   for (i = 0; i < NUM_DIRECTIONS; i++)
13588   {
13589     int xx = x + xy[i].x;
13590     int yy = y + xy[i].y;
13591     int dir = MV_DIR_FROM_BIT(i);
13592     int dir_opposite = MV_DIR_OPPOSITE(dir);
13593
13594     if (IN_LEV_FIELD(xx, yy) && IS_DC_STEELWALL_2(IntelliDrawBuffer[xx][yy]) &&
13595         (direction_old & dir) &&
13596         (getOpenDirectionFromSteel2(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13597       direction_new |= dir;
13598   }
13599
13600   return getSteel2FromOpenDirectionNotEmpty(direction_new, element_old);
13601 }
13602
13603 static int getClosedChip(int x, int y)
13604 {
13605   struct XY *xy = xy_directions;
13606   int element_old = IntelliDrawBuffer[x][y];
13607   int direction_old = getOpenDirectionFromChip(element_old);
13608   int direction_new = MV_NONE;
13609   int i;
13610
13611   for (i = 0; i < NUM_DIRECTIONS; i++)
13612   {
13613     int xx = x + xy[i].x;
13614     int yy = y + xy[i].y;
13615     int dir = MV_DIR_FROM_BIT(i);
13616     int dir_opposite = MV_DIR_OPPOSITE(dir);
13617
13618     if (IN_LEV_FIELD(xx, yy) && IS_SP_CHIP(IntelliDrawBuffer[xx][yy]) &&
13619         (direction_old & dir) &&
13620         (getOpenDirectionFromChip(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13621       direction_new |= dir;
13622   }
13623
13624   return getChipFromOpenDirectionNotEmpty(direction_new, element_old);
13625 }
13626
13627 static void SetElementSimpleExt(int x, int y, int dx, int dy, int element,
13628                                 boolean change_level)
13629 {
13630   int sx = x - level_xpos;
13631   int sy = y - level_ypos;
13632   int old_element = Tile[x][y];
13633   int new_element = element;
13634   unsigned int new_bitmask = (getDrawModeHiRes() ? (dx + 1) << (dy * 2) : 0x0f);
13635   boolean draw_masked = FALSE;
13636
13637   if (IS_MM_WALL_EDITOR(element))
13638   {
13639     element = map_mm_wall_element_editor(element) | new_bitmask;
13640
13641     if (IS_MM_WALL(old_element))
13642       element |= MM_WALL_BITS(old_element);
13643
13644     if (!change_level)
13645       draw_masked = TRUE;
13646   }
13647   else if (IS_MM_WALL(old_element) && element == EL_EMPTY)
13648   {
13649     int element_changed = old_element & ~new_bitmask;
13650
13651     if (MM_WALL_BITS(element_changed) != 0)
13652       element = element_changed;
13653   }
13654
13655   IntelliDrawBuffer[x][y] = element;
13656
13657   if (change_level)
13658     Tile[x][y] = element;
13659
13660   if (IN_ED_FIELD(sx, sy))
13661   {
13662     if (IS_MM_WALL(old_element) && new_element == EL_EMPTY)
13663       DrawSizedWallParts_MM(sx, sy, EL_EMPTY, ed_tilesize, FALSE, new_bitmask);
13664     else if (draw_masked)
13665       DrawEditorElementThruMask(sx, sy, element);
13666     else
13667       DrawEditorElement(sx, sy, element);
13668   }
13669 }
13670
13671 static void SetElementSimple(int x, int y, int element, boolean change_level)
13672 {
13673   SetElementSimpleExt(x, y, 0, 0, element, change_level);
13674 }
13675
13676 static void MergeAndCloseNeighbourElements(int x1, int y1, int *element1,
13677                                            int x2, int y2, int *element2,
13678                                            int (*close_function)(int, int),
13679                                            boolean change_level)
13680 {
13681   // set neighbour elements to newly determined connections
13682   SetElementSimple(x1, y1, *element1, change_level);
13683   SetElementSimple(x2, y2, *element2, change_level);
13684
13685   // remove all open connections of neighbour elements
13686   *element1 = close_function(x1, y1);
13687   *element2 = close_function(x2, y2);
13688
13689   // set neighbour elements to new, minimized connections
13690   SetElementSimple(x1, y1, *element1, change_level);
13691   SetElementSimple(x2, y2, *element2, change_level);
13692 }
13693
13694 static void SetElementIntelliDraw(int x, int y, int dx, int dy, int new_element,
13695                                   boolean change_level, int button)
13696 {
13697   struct XY *xy = xy_directions;
13698   static int last_x = -1;
13699   static int last_y = -1;
13700
13701   if (new_element == EL_UNDEFINED)
13702   {
13703     last_x = -1;
13704     last_y = -1;
13705
13706     return;
13707   }
13708
13709   int old_element = IntelliDrawBuffer[x][y];
13710
13711   if (IS_TUBE(new_element))
13712   {
13713     int last_element_new = EL_UNDEFINED;
13714     int direction = MV_NONE;
13715     int i;
13716
13717     // if old element is of same kind, keep all existing directions
13718     if (IS_TUBE(old_element))
13719       direction |= getOpenDirectionFromTube(old_element);
13720
13721     for (i = 0; i < NUM_DIRECTIONS; i++)
13722     {
13723       int xx = x + xy[i].x;
13724       int yy = y + xy[i].y;
13725
13726       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13727           IS_TUBE(IntelliDrawBuffer[last_x][last_y]))
13728       {
13729         int dir = MV_DIR_FROM_BIT(i);
13730         int dir_opposite = MV_DIR_OPPOSITE(dir);
13731         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13732         int last_direction_old = getOpenDirectionFromTube(last_element_old);
13733         int last_direction_new = last_direction_old | dir_opposite;
13734
13735         last_element_new = getTubeFromOpenDirection(last_direction_new);
13736
13737         direction |= dir;
13738       }
13739     }
13740
13741     new_element = getTubeFromOpenDirectionNotEmpty(direction, new_element);
13742
13743     if (last_element_new != EL_UNDEFINED)
13744       MergeAndCloseNeighbourElements(x, y, &new_element,
13745                                      last_x, last_y, &last_element_new,
13746                                      getClosedTube, change_level);
13747   }
13748   else if (IS_BELT(new_element))
13749   {
13750     int belt_nr = getBeltNrFromBeltElement(new_element);
13751     int last_element_new = EL_UNDEFINED;
13752     int direction = MV_NONE;
13753     int i;
13754
13755     // if old element is of same kind, keep all existing directions
13756     if (IS_BELT(old_element))
13757       direction |= getOpenDirectionFromBelt(old_element);
13758
13759     for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
13760     {
13761       int xx = x + xy[i].x;
13762       int yy = y + xy[i].y;
13763
13764       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13765           IS_BELT(IntelliDrawBuffer[last_x][last_y]))
13766       {
13767         int dir = MV_DIR_FROM_BIT(i);
13768         int dir_opposite = MV_DIR_OPPOSITE(dir);
13769         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13770         int last_belt_nr = getBeltNrFromBeltElement(last_element_old);
13771         int last_direction_old = getOpenDirectionFromBelt(last_element_old);
13772         int last_direction_new = last_direction_old | dir_opposite;
13773
13774         last_element_new = getBeltFromNrAndOpenDirection(last_belt_nr,
13775                                                          last_direction_new);
13776         direction |= dir;
13777       }
13778     }
13779
13780     new_element = getBeltFromNrAndOpenDirectionNotEmpty(belt_nr, direction,
13781                                                         new_element);
13782     if (last_element_new != EL_UNDEFINED)
13783       MergeAndCloseNeighbourElements(x, y, &new_element,
13784                                      last_x, last_y, &last_element_new,
13785                                      getClosedBelt, change_level);
13786   }
13787   else if (IS_ACID_POOL_OR_ACID(new_element))
13788   {
13789     int last_element_new = EL_UNDEFINED;
13790     int direction = MV_NONE;
13791     int i;
13792
13793     // if old element is of same kind, keep all existing directions
13794     if (IS_ACID_POOL_OR_ACID(old_element))
13795       direction |= getOpenDirectionFromPool(old_element);
13796
13797     for (i = 0; i < NUM_DIRECTIONS; i++)
13798     {
13799       int xx = x + xy[i].x;
13800       int yy = y + xy[i].y;
13801
13802       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13803           IS_ACID_POOL_OR_ACID(IntelliDrawBuffer[last_x][last_y]))
13804       {
13805         int dir = MV_DIR_FROM_BIT(i);
13806         int dir_opposite = MV_DIR_OPPOSITE(dir);
13807         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13808         int last_direction_old = getOpenDirectionFromPool(last_element_old);
13809         int last_direction_new = last_direction_old | dir_opposite;
13810
13811         last_element_new = getPoolFromOpenDirection(last_direction_new);
13812
13813         direction |= dir;
13814       }
13815     }
13816
13817     // special corrections needed for intuitively correct acid pool drawing
13818     if (last_element_new == EL_EMPTY)
13819       last_element_new = new_element;
13820     else if (last_element_new != EL_UNDEFINED)
13821       new_element = last_element_new;
13822
13823     new_element = getPoolFromOpenDirectionNotEmpty(direction, new_element);
13824
13825     if (last_element_new != EL_UNDEFINED)
13826       MergeAndCloseNeighbourElements(x, y, &new_element,
13827                                      last_x, last_y, &last_element_new,
13828                                      getClosedPool, change_level);
13829   }
13830   else if (IS_EMC_PILLAR(new_element))
13831   {
13832     int last_element_new = EL_UNDEFINED;
13833     int direction = MV_NONE;
13834     int i;
13835
13836     // if old element is of same kind, keep all existing directions
13837     if (IS_EMC_PILLAR(old_element))
13838       direction |= getOpenDirectionFromPillar(old_element);
13839
13840     for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
13841     {
13842       int xx = x + xy[i].x;
13843       int yy = y + xy[i].y;
13844
13845       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13846           IS_EMC_PILLAR(IntelliDrawBuffer[last_x][last_y]))
13847       {
13848         int dir = MV_DIR_FROM_BIT(i);
13849         int dir_opposite = MV_DIR_OPPOSITE(dir);
13850         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13851         int last_direction_old = getOpenDirectionFromPillar(last_element_old);
13852         int last_direction_new = last_direction_old | dir_opposite;
13853
13854         last_element_new = getPillarFromOpenDirection(last_direction_new);
13855
13856         direction |= dir;
13857       }
13858     }
13859
13860     new_element = getPillarFromOpenDirectionNotEmpty(direction, new_element);
13861
13862     if (last_element_new != EL_UNDEFINED)
13863       MergeAndCloseNeighbourElements(x, y, &new_element,
13864                                      last_x, last_y, &last_element_new,
13865                                      getClosedPillar, change_level);
13866   }
13867   else if (IS_DC_STEELWALL_2(new_element))
13868   {
13869     int last_element_new = EL_UNDEFINED;
13870     int direction = MV_NONE;
13871     int i;
13872
13873     // if old element is of same kind, keep all existing directions
13874     if (IS_DC_STEELWALL_2(old_element))
13875       direction |= getOpenDirectionFromSteel2(old_element);
13876
13877     for (i = 0; i < NUM_DIRECTIONS; i++)
13878     {
13879       int xx = x + xy[i].x;
13880       int yy = y + xy[i].y;
13881
13882       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13883           IS_DC_STEELWALL_2(IntelliDrawBuffer[last_x][last_y]))
13884       {
13885         int dir = MV_DIR_FROM_BIT(i);
13886         int dir_opposite = MV_DIR_OPPOSITE(dir);
13887         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13888         int last_direction_old = getOpenDirectionFromSteel2(last_element_old);
13889         int last_direction_new = last_direction_old | dir_opposite;
13890
13891         last_element_new = getSteel2FromOpenDirection(last_direction_new);
13892
13893         direction |= dir;
13894       }
13895     }
13896
13897     new_element = getSteel2FromOpenDirectionNotEmpty(direction, new_element);
13898
13899     if (last_element_new != EL_UNDEFINED)
13900       MergeAndCloseNeighbourElements(x, y, &new_element,
13901                                      last_x, last_y, &last_element_new,
13902                                      getClosedSteel2, change_level);
13903   }
13904   else if (IS_SP_CHIP(new_element))
13905   {
13906     int last_element_new = EL_UNDEFINED;
13907     int direction = MV_NONE;
13908     int i;
13909
13910     // (do not keep existing directions, regardless of kind of old element)
13911
13912     for (i = 0; i < NUM_DIRECTIONS; i++)
13913     {
13914       int xx = x + xy[i].x;
13915       int yy = y + xy[i].y;
13916
13917       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13918           IS_SP_CHIP(IntelliDrawBuffer[last_x][last_y]))
13919       {
13920         int dir = MV_DIR_FROM_BIT(i);
13921         int dir_opposite = MV_DIR_OPPOSITE(dir);
13922         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13923         int last_direction_old = getOpenDirectionFromChip(last_element_old);
13924         int last_direction_new = last_direction_old | dir_opposite;
13925
13926         if (last_direction_old == MV_NONE)
13927         {
13928           last_element_new = getChipFromOpenDirection(last_direction_new);
13929           direction |= dir;
13930         }
13931         else if (last_direction_old & (dir | dir_opposite))
13932         {
13933           direction |= MV_DIR_OPPOSITE(last_direction_old);
13934         }
13935         else
13936         {
13937           direction |= MV_DIR_OPPOSITE(dir);
13938         }
13939       }
13940     }
13941
13942     new_element = getChipFromOpenDirectionNotEmpty(direction, new_element);
13943
13944     if (last_element_new != EL_UNDEFINED)
13945       MergeAndCloseNeighbourElements(x, y, &new_element,
13946                                      last_x, last_y, &last_element_new,
13947                                      getClosedChip, change_level);
13948   }
13949   else if (IS_SP_HARDWARE_BASE(new_element))
13950   {
13951     int nr = GetSimpleRandom(6);
13952
13953     new_element = (nr == 0 ? EL_SP_HARDWARE_BASE_1 :
13954                    nr == 1 ? EL_SP_HARDWARE_BASE_2 :
13955                    nr == 2 ? EL_SP_HARDWARE_BASE_3 :
13956                    nr == 3 ? EL_SP_HARDWARE_BASE_4 :
13957                    nr == 4 ? EL_SP_HARDWARE_BASE_5 : EL_SP_HARDWARE_BASE_6);
13958   }
13959   else if (new_element == EL_SP_HARDWARE_GREEN ||
13960            new_element == EL_SP_HARDWARE_BLUE ||
13961            new_element == EL_SP_HARDWARE_RED)
13962   {
13963     int nr = GetSimpleRandom(3);
13964
13965     new_element = (nr == 0 ? EL_SP_HARDWARE_GREEN :
13966                    nr == 1 ? EL_SP_HARDWARE_BLUE : EL_SP_HARDWARE_RED);
13967   }
13968   else if (IS_GROUP_ELEMENT(new_element))
13969   {
13970     boolean connected_drawing = FALSE;
13971     int i;
13972
13973     for (i = 0; i < NUM_DIRECTIONS; i++)
13974     {
13975       int xx = x + xy[i].x;
13976       int yy = y + xy[i].y;
13977
13978       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13979           IS_IN_GROUP_EL(IntelliDrawBuffer[last_x][last_y], new_element))
13980         connected_drawing = TRUE;
13981     }
13982
13983     if (!connected_drawing)
13984       ResolveGroupElement(new_element);
13985
13986     new_element = GetElementFromGroupElement(new_element);
13987   }
13988   else if (IS_BELT_SWITCH(old_element))
13989   {
13990     int belt_nr = getBeltNrFromBeltSwitchElement(old_element);
13991     int belt_dir = getBeltDirFromBeltSwitchElement(old_element);
13992
13993     belt_dir = (belt_dir == MV_LEFT ? MV_NONE :
13994                 belt_dir == MV_NONE ? MV_RIGHT : MV_LEFT);
13995
13996     new_element = getBeltSwitchElementFromBeltNrAndBeltDir(belt_nr, belt_dir);
13997   }
13998   else
13999   {
14000     static int swappable_elements[][2] =
14001     {
14002       { EL_EXIT_CLOSED,                 EL_EXIT_OPEN                    },
14003       { EL_DYNAMITE,                    EL_DYNAMITE_ACTIVE              },
14004       { EL_EM_DYNAMITE,                 EL_EM_DYNAMITE_ACTIVE           },
14005       { EL_QUICKSAND_EMPTY,             EL_QUICKSAND_FULL               },
14006       { EL_EMERALD,                     EL_WALL_EMERALD                 },
14007       { EL_EMERALD_YELLOW,              EL_WALL_EMERALD_YELLOW          },
14008       { EL_EMERALD_RED,                 EL_WALL_EMERALD_RED             },
14009       { EL_EMERALD_PURPLE,              EL_WALL_EMERALD_PURPLE          },
14010       { EL_DIAMOND,                     EL_WALL_DIAMOND                 },
14011       { EL_BD_DIAMOND,                  EL_WALL_BD_DIAMOND              },
14012       { EL_GATE_1,                      EL_GATE_1_GRAY                  },
14013       { EL_GATE_2,                      EL_GATE_2_GRAY                  },
14014       { EL_GATE_3,                      EL_GATE_3_GRAY                  },
14015       { EL_GATE_4,                      EL_GATE_4_GRAY                  },
14016       { EL_EM_GATE_1,                   EL_EM_GATE_1_GRAY               },
14017       { EL_EM_GATE_2,                   EL_EM_GATE_2_GRAY               },
14018       { EL_EM_GATE_3,                   EL_EM_GATE_3_GRAY               },
14019       { EL_EM_GATE_4,                   EL_EM_GATE_4_GRAY               },
14020       { EL_EMC_GATE_5,                  EL_EMC_GATE_5_GRAY              },
14021       { EL_EMC_GATE_6,                  EL_EMC_GATE_6_GRAY              },
14022       { EL_EMC_GATE_7,                  EL_EMC_GATE_7_GRAY              },
14023       { EL_EMC_GATE_8,                  EL_EMC_GATE_8_GRAY              },
14024       { EL_DC_GATE_WHITE,               EL_DC_GATE_WHITE_GRAY           },
14025       { EL_TIME_ORB_EMPTY,              EL_TIME_ORB_FULL                },
14026       { EL_LAMP,                        EL_LAMP_ACTIVE                  },
14027       { EL_SOKOBAN_FIELD_EMPTY,         EL_SOKOBAN_FIELD_FULL           },
14028       { EL_SP_BASE,                     EL_SP_BUGGY_BASE                },
14029       { EL_PEARL,                       EL_WALL_PEARL                   },
14030       { EL_CRYSTAL,                     EL_WALL_CRYSTAL                 },
14031       { EL_TIMEGATE_CLOSED,             EL_TIMEGATE_OPEN                },
14032       { EL_SWITCHGATE_CLOSED,           EL_SWITCHGATE_OPEN              },
14033       { EL_SWITCHGATE_SWITCH_UP,        EL_SWITCHGATE_SWITCH_DOWN       },
14034       { EL_DC_SWITCHGATE_SWITCH_UP,     EL_DC_SWITCHGATE_SWITCH_DOWN    },
14035       { EL_LIGHT_SWITCH,                EL_LIGHT_SWITCH_ACTIVE          },
14036       { EL_LANDMINE,                    EL_DC_LANDMINE                  },
14037       { EL_SHIELD_NORMAL,               EL_SHIELD_DEADLY                },
14038       { EL_STEEL_EXIT_CLOSED,           EL_STEEL_EXIT_OPEN              },
14039       { EL_EM_EXIT_CLOSED,              EL_EM_EXIT_OPEN                 },
14040       { EL_EM_STEEL_EXIT_CLOSED,        EL_EM_STEEL_EXIT_OPEN           },
14041       { EL_QUICKSAND_FAST_EMPTY,        EL_QUICKSAND_FAST_FULL          },
14042       { EL_MM_EXIT_CLOSED,              EL_MM_EXIT_OPEN                 },
14043       { EL_MM_FUSE,                     EL_MM_FUSE_ACTIVE               },
14044       { EL_MM_LIGHTBULB,                EL_MM_LIGHTBULB_ACTIVE          },
14045       { EL_MM_FUEL_EMPTY,               EL_MM_FUEL_FULL                 },
14046
14047       { -1,                             -1                              },
14048     };
14049     static int rotatable_elements_4[][4] =
14050     {
14051       {
14052         EL_BUG_UP,
14053         EL_BUG_RIGHT,
14054         EL_BUG_DOWN,
14055         EL_BUG_LEFT
14056       },
14057       {
14058         EL_SPACESHIP_UP,
14059         EL_SPACESHIP_RIGHT,
14060         EL_SPACESHIP_DOWN,
14061         EL_SPACESHIP_LEFT
14062       },
14063       {
14064         EL_BD_BUTTERFLY_UP,
14065         EL_BD_BUTTERFLY_RIGHT,
14066         EL_BD_BUTTERFLY_DOWN,
14067         EL_BD_BUTTERFLY_LEFT
14068       },
14069       {
14070         EL_BD_FIREFLY_UP,
14071         EL_BD_FIREFLY_RIGHT,
14072         EL_BD_FIREFLY_DOWN,
14073         EL_BD_FIREFLY_LEFT
14074       },
14075       {
14076         EL_PACMAN_UP,
14077         EL_PACMAN_RIGHT,
14078         EL_PACMAN_DOWN,
14079         EL_PACMAN_LEFT
14080       },
14081       {
14082         EL_YAMYAM_UP,
14083         EL_YAMYAM_RIGHT,
14084         EL_YAMYAM_DOWN,
14085         EL_YAMYAM_LEFT
14086       },
14087       {
14088         EL_ARROW_UP,
14089         EL_ARROW_RIGHT,
14090         EL_ARROW_DOWN,
14091         EL_ARROW_LEFT
14092       },
14093       {
14094         EL_SP_PORT_UP,
14095         EL_SP_PORT_RIGHT,
14096         EL_SP_PORT_DOWN,
14097         EL_SP_PORT_LEFT
14098       },
14099       {
14100         EL_SP_GRAVITY_PORT_UP,
14101         EL_SP_GRAVITY_PORT_RIGHT,
14102         EL_SP_GRAVITY_PORT_DOWN,
14103         EL_SP_GRAVITY_PORT_LEFT
14104       },
14105       {
14106         EL_SP_GRAVITY_ON_PORT_UP,
14107         EL_SP_GRAVITY_ON_PORT_RIGHT,
14108         EL_SP_GRAVITY_ON_PORT_DOWN,
14109         EL_SP_GRAVITY_ON_PORT_LEFT
14110       },
14111       {
14112         EL_SP_GRAVITY_OFF_PORT_UP,
14113         EL_SP_GRAVITY_OFF_PORT_RIGHT,
14114         EL_SP_GRAVITY_OFF_PORT_DOWN,
14115         EL_SP_GRAVITY_OFF_PORT_LEFT
14116       },
14117       {
14118         EL_MOLE_UP,
14119         EL_MOLE_RIGHT,
14120         EL_MOLE_DOWN,
14121         EL_MOLE_LEFT
14122       },
14123       {
14124         EL_BALLOON_SWITCH_UP,
14125         EL_BALLOON_SWITCH_RIGHT,
14126         EL_BALLOON_SWITCH_DOWN,
14127         EL_BALLOON_SWITCH_LEFT
14128       },
14129       {
14130         EL_MM_MCDUFFIN_UP,
14131         EL_MM_MCDUFFIN_RIGHT,
14132         EL_MM_MCDUFFIN_DOWN,
14133         EL_MM_MCDUFFIN_LEFT
14134       },
14135       {
14136         EL_MM_MIRROR_FIXED_1,
14137         EL_MM_MIRROR_FIXED_4,
14138         EL_MM_MIRROR_FIXED_3,
14139         EL_MM_MIRROR_FIXED_2
14140       },
14141       {
14142         EL_MM_STEEL_GRID_FIXED_1,
14143         EL_MM_STEEL_GRID_FIXED_4,
14144         EL_MM_STEEL_GRID_FIXED_2,
14145         EL_MM_STEEL_GRID_FIXED_3
14146       },
14147       {
14148         EL_MM_WOODEN_GRID_FIXED_1,
14149         EL_MM_WOODEN_GRID_FIXED_4,
14150         EL_MM_WOODEN_GRID_FIXED_2,
14151         EL_MM_WOODEN_GRID_FIXED_3
14152       },
14153       {
14154         EL_MM_POLARIZER_CROSS_1,
14155         EL_MM_POLARIZER_CROSS_4,
14156         EL_MM_POLARIZER_CROSS_3,
14157         EL_MM_POLARIZER_CROSS_2
14158       },
14159       {
14160         EL_MM_PACMAN_UP,
14161         EL_MM_PACMAN_RIGHT,
14162         EL_MM_PACMAN_DOWN,
14163         EL_MM_PACMAN_LEFT
14164       },
14165       {
14166         EL_DF_LASER_UP,
14167         EL_DF_LASER_RIGHT,
14168         EL_DF_LASER_DOWN,
14169         EL_DF_LASER_LEFT
14170       },
14171       {
14172         EL_DF_RECEIVER_UP,
14173         EL_DF_RECEIVER_RIGHT,
14174         EL_DF_RECEIVER_DOWN,
14175         EL_DF_RECEIVER_LEFT
14176       },
14177       {
14178         EL_DF_SLOPE_1,
14179         EL_DF_SLOPE_4,
14180         EL_DF_SLOPE_3,
14181         EL_DF_SLOPE_2
14182       },
14183
14184       {
14185         -1,
14186       },
14187     };
14188     static int rotatable_elements_8[][8] =
14189     {
14190       {
14191         EL_DF_STEEL_GRID_FIXED_1,
14192         EL_DF_STEEL_GRID_FIXED_8,
14193         EL_DF_STEEL_GRID_FIXED_7,
14194         EL_DF_STEEL_GRID_FIXED_6,
14195         EL_DF_STEEL_GRID_FIXED_5,
14196         EL_DF_STEEL_GRID_FIXED_4,
14197         EL_DF_STEEL_GRID_FIXED_3,
14198         EL_DF_STEEL_GRID_FIXED_2
14199       },
14200       {
14201         EL_DF_WOODEN_GRID_FIXED_1,
14202         EL_DF_WOODEN_GRID_FIXED_8,
14203         EL_DF_WOODEN_GRID_FIXED_7,
14204         EL_DF_WOODEN_GRID_FIXED_6,
14205         EL_DF_WOODEN_GRID_FIXED_5,
14206         EL_DF_WOODEN_GRID_FIXED_4,
14207         EL_DF_WOODEN_GRID_FIXED_3,
14208         EL_DF_WOODEN_GRID_FIXED_2
14209       },
14210       {
14211         EL_DF_STEEL_GRID_ROTATING_1,
14212         EL_DF_STEEL_GRID_ROTATING_8,
14213         EL_DF_STEEL_GRID_ROTATING_7,
14214         EL_DF_STEEL_GRID_ROTATING_6,
14215         EL_DF_STEEL_GRID_ROTATING_5,
14216         EL_DF_STEEL_GRID_ROTATING_4,
14217         EL_DF_STEEL_GRID_ROTATING_3,
14218         EL_DF_STEEL_GRID_ROTATING_2
14219       },
14220       {
14221         EL_DF_WOODEN_GRID_ROTATING_1,
14222         EL_DF_WOODEN_GRID_ROTATING_8,
14223         EL_DF_WOODEN_GRID_ROTATING_7,
14224         EL_DF_WOODEN_GRID_ROTATING_6,
14225         EL_DF_WOODEN_GRID_ROTATING_5,
14226         EL_DF_WOODEN_GRID_ROTATING_4,
14227         EL_DF_WOODEN_GRID_ROTATING_3,
14228         EL_DF_WOODEN_GRID_ROTATING_2
14229       },
14230
14231       {
14232         -1,
14233       },
14234     };
14235     static int rotatable_elements_16[][16] =
14236     {
14237       {
14238         EL_MM_MIRROR_1,
14239         EL_MM_MIRROR_16,
14240         EL_MM_MIRROR_15,
14241         EL_MM_MIRROR_14,
14242         EL_MM_MIRROR_13,
14243         EL_MM_MIRROR_12,
14244         EL_MM_MIRROR_11,
14245         EL_MM_MIRROR_10,
14246         EL_MM_MIRROR_9,
14247         EL_MM_MIRROR_8,
14248         EL_MM_MIRROR_7,
14249         EL_MM_MIRROR_6,
14250         EL_MM_MIRROR_5,
14251         EL_MM_MIRROR_4,
14252         EL_MM_MIRROR_3,
14253         EL_MM_MIRROR_2
14254       },
14255       {
14256         EL_MM_TELEPORTER_5,
14257         EL_MM_TELEPORTER_4,
14258         EL_MM_TELEPORTER_3,
14259         EL_MM_TELEPORTER_2,
14260         EL_MM_TELEPORTER_1,
14261         EL_MM_TELEPORTER_16,
14262         EL_MM_TELEPORTER_15,
14263         EL_MM_TELEPORTER_14,
14264         EL_MM_TELEPORTER_13,
14265         EL_MM_TELEPORTER_12,
14266         EL_MM_TELEPORTER_11,
14267         EL_MM_TELEPORTER_10,
14268         EL_MM_TELEPORTER_9,
14269         EL_MM_TELEPORTER_8,
14270         EL_MM_TELEPORTER_7,
14271         EL_MM_TELEPORTER_6
14272       },
14273       {
14274         EL_MM_TELEPORTER_RED_5,
14275         EL_MM_TELEPORTER_RED_4,
14276         EL_MM_TELEPORTER_RED_3,
14277         EL_MM_TELEPORTER_RED_2,
14278         EL_MM_TELEPORTER_RED_1,
14279         EL_MM_TELEPORTER_RED_16,
14280         EL_MM_TELEPORTER_RED_15,
14281         EL_MM_TELEPORTER_RED_14,
14282         EL_MM_TELEPORTER_RED_13,
14283         EL_MM_TELEPORTER_RED_12,
14284         EL_MM_TELEPORTER_RED_11,
14285         EL_MM_TELEPORTER_RED_10,
14286         EL_MM_TELEPORTER_RED_9,
14287         EL_MM_TELEPORTER_RED_8,
14288         EL_MM_TELEPORTER_RED_7,
14289         EL_MM_TELEPORTER_RED_6
14290       },
14291       {
14292         EL_MM_TELEPORTER_YELLOW_5,
14293         EL_MM_TELEPORTER_YELLOW_4,
14294         EL_MM_TELEPORTER_YELLOW_3,
14295         EL_MM_TELEPORTER_YELLOW_2,
14296         EL_MM_TELEPORTER_YELLOW_1,
14297         EL_MM_TELEPORTER_YELLOW_16,
14298         EL_MM_TELEPORTER_YELLOW_15,
14299         EL_MM_TELEPORTER_YELLOW_14,
14300         EL_MM_TELEPORTER_YELLOW_13,
14301         EL_MM_TELEPORTER_YELLOW_12,
14302         EL_MM_TELEPORTER_YELLOW_11,
14303         EL_MM_TELEPORTER_YELLOW_10,
14304         EL_MM_TELEPORTER_YELLOW_9,
14305         EL_MM_TELEPORTER_YELLOW_8,
14306         EL_MM_TELEPORTER_YELLOW_7,
14307         EL_MM_TELEPORTER_YELLOW_6
14308       },
14309       {
14310         EL_MM_TELEPORTER_GREEN_5,
14311         EL_MM_TELEPORTER_GREEN_4,
14312         EL_MM_TELEPORTER_GREEN_3,
14313         EL_MM_TELEPORTER_GREEN_2,
14314         EL_MM_TELEPORTER_GREEN_1,
14315         EL_MM_TELEPORTER_GREEN_16,
14316         EL_MM_TELEPORTER_GREEN_15,
14317         EL_MM_TELEPORTER_GREEN_14,
14318         EL_MM_TELEPORTER_GREEN_13,
14319         EL_MM_TELEPORTER_GREEN_12,
14320         EL_MM_TELEPORTER_GREEN_11,
14321         EL_MM_TELEPORTER_GREEN_10,
14322         EL_MM_TELEPORTER_GREEN_9,
14323         EL_MM_TELEPORTER_GREEN_8,
14324         EL_MM_TELEPORTER_GREEN_7,
14325         EL_MM_TELEPORTER_GREEN_6
14326       },
14327       {
14328         EL_MM_TELEPORTER_BLUE_5,
14329         EL_MM_TELEPORTER_BLUE_4,
14330         EL_MM_TELEPORTER_BLUE_3,
14331         EL_MM_TELEPORTER_BLUE_2,
14332         EL_MM_TELEPORTER_BLUE_1,
14333         EL_MM_TELEPORTER_BLUE_16,
14334         EL_MM_TELEPORTER_BLUE_15,
14335         EL_MM_TELEPORTER_BLUE_14,
14336         EL_MM_TELEPORTER_BLUE_13,
14337         EL_MM_TELEPORTER_BLUE_12,
14338         EL_MM_TELEPORTER_BLUE_11,
14339         EL_MM_TELEPORTER_BLUE_10,
14340         EL_MM_TELEPORTER_BLUE_9,
14341         EL_MM_TELEPORTER_BLUE_8,
14342         EL_MM_TELEPORTER_BLUE_7,
14343         EL_MM_TELEPORTER_BLUE_6
14344       },
14345       {
14346         EL_MM_POLARIZER_1,
14347         EL_MM_POLARIZER_16,
14348         EL_MM_POLARIZER_15,
14349         EL_MM_POLARIZER_14,
14350         EL_MM_POLARIZER_13,
14351         EL_MM_POLARIZER_12,
14352         EL_MM_POLARIZER_11,
14353         EL_MM_POLARIZER_10,
14354         EL_MM_POLARIZER_9,
14355         EL_MM_POLARIZER_8,
14356         EL_MM_POLARIZER_7,
14357         EL_MM_POLARIZER_6,
14358         EL_MM_POLARIZER_5,
14359         EL_MM_POLARIZER_4,
14360         EL_MM_POLARIZER_3,
14361         EL_MM_POLARIZER_2
14362       },
14363       {
14364         EL_DF_MIRROR_1,
14365         EL_DF_MIRROR_16,
14366         EL_DF_MIRROR_15,
14367         EL_DF_MIRROR_14,
14368         EL_DF_MIRROR_13,
14369         EL_DF_MIRROR_12,
14370         EL_DF_MIRROR_11,
14371         EL_DF_MIRROR_10,
14372         EL_DF_MIRROR_9,
14373         EL_DF_MIRROR_8,
14374         EL_DF_MIRROR_7,
14375         EL_DF_MIRROR_6,
14376         EL_DF_MIRROR_5,
14377         EL_DF_MIRROR_4,
14378         EL_DF_MIRROR_3,
14379         EL_DF_MIRROR_2
14380       },
14381       {
14382         EL_DF_MIRROR_ROTATING_1,
14383         EL_DF_MIRROR_ROTATING_16,
14384         EL_DF_MIRROR_ROTATING_15,
14385         EL_DF_MIRROR_ROTATING_14,
14386         EL_DF_MIRROR_ROTATING_13,
14387         EL_DF_MIRROR_ROTATING_12,
14388         EL_DF_MIRROR_ROTATING_11,
14389         EL_DF_MIRROR_ROTATING_10,
14390         EL_DF_MIRROR_ROTATING_9,
14391         EL_DF_MIRROR_ROTATING_8,
14392         EL_DF_MIRROR_ROTATING_7,
14393         EL_DF_MIRROR_ROTATING_6,
14394         EL_DF_MIRROR_ROTATING_5,
14395         EL_DF_MIRROR_ROTATING_4,
14396         EL_DF_MIRROR_ROTATING_3,
14397         EL_DF_MIRROR_ROTATING_2
14398       },
14399       {
14400         EL_DF_MIRROR_FIXED_1,
14401         EL_DF_MIRROR_FIXED_16,
14402         EL_DF_MIRROR_FIXED_15,
14403         EL_DF_MIRROR_FIXED_14,
14404         EL_DF_MIRROR_FIXED_13,
14405         EL_DF_MIRROR_FIXED_12,
14406         EL_DF_MIRROR_FIXED_11,
14407         EL_DF_MIRROR_FIXED_10,
14408         EL_DF_MIRROR_FIXED_9,
14409         EL_DF_MIRROR_FIXED_8,
14410         EL_DF_MIRROR_FIXED_7,
14411         EL_DF_MIRROR_FIXED_6,
14412         EL_DF_MIRROR_FIXED_5,
14413         EL_DF_MIRROR_FIXED_4,
14414         EL_DF_MIRROR_FIXED_3,
14415         EL_DF_MIRROR_FIXED_2
14416       },
14417
14418       {
14419         -1,
14420       },
14421     };
14422     int i, j;
14423
14424     for (i = 0; swappable_elements[i][0] != -1; i++)
14425     {
14426       int element1 = swappable_elements[i][0];
14427       int element2 = swappable_elements[i][1];
14428
14429       if (old_element == element1 || old_element == element2)
14430         new_element = (old_element == element1 ? element2 : element1);
14431     }
14432
14433     for (i = 0; rotatable_elements_4[i][0] != -1; i++)
14434     {
14435       for (j = 0; j < 4; j++)
14436       {
14437         int element = rotatable_elements_4[i][j];
14438
14439         if (old_element == element)
14440           new_element = (button == 1 ? rotatable_elements_4[i][(j + 3) % 4] :
14441                          button == 2 ? rotatable_elements_4[i][0]           :
14442                          button == 3 ? rotatable_elements_4[i][(j + 1) % 4] :
14443                          old_element);
14444       }
14445     }
14446
14447     for (i = 0; rotatable_elements_8[i][0] != -1; i++)
14448     {
14449       for (j = 0; j < 8; j++)
14450       {
14451         int element = rotatable_elements_8[i][j];
14452
14453         if (old_element == element)
14454           new_element = (button == 1 ? rotatable_elements_8[i][(j + 7) % 8] :
14455                          button == 2 ? rotatable_elements_8[i][0]           :
14456                          button == 3 ? rotatable_elements_8[i][(j + 1) % 8] :
14457                          old_element);
14458       }
14459     }
14460
14461     for (i = 0; rotatable_elements_16[i][0] != -1; i++)
14462     {
14463       for (j = 0; j < 16; j++)
14464       {
14465         int element = rotatable_elements_16[i][j];
14466
14467         if (old_element == element)
14468           new_element = (button == 1 ? rotatable_elements_16[i][(j + 15) % 16] :
14469                          button == 2 ? rotatable_elements_16[i][0]             :
14470                          button == 3 ? rotatable_elements_16[i][(j + 1)  % 16] :
14471                          old_element);
14472       }
14473     }
14474
14475     if (old_element != new_element)
14476     {
14477       int max_infotext_len = getMaxInfoTextLength();
14478       char infotext[MAX_OUTPUT_LINESIZE + 1];
14479
14480       strncpy(infotext, getElementInfoText(new_element), max_infotext_len);
14481       infotext[max_infotext_len] = '\0';
14482
14483       ClearEditorGadgetInfoText();
14484
14485       DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, INFOTEXT_FONT,
14486                 infotext);
14487     }
14488   }
14489
14490   if (IS_MM_WALL_EDITOR(new_element))
14491     SetElementSimpleExt(x, y, dx, dy, new_element, change_level);
14492   else
14493     SetElementSimple(x, y, new_element, change_level);
14494
14495   last_x = x;
14496   last_y = y;
14497 }
14498
14499 static void ResetIntelliDraw(void)
14500 {
14501   int x, y;
14502
14503   for (x = 0; x < lev_fieldx; x++)
14504     for (y = 0; y < lev_fieldy; y++)
14505       IntelliDrawBuffer[x][y] = Tile[x][y];
14506
14507   SetElementIntelliDraw(-1, -1, -1, -1, EL_UNDEFINED, FALSE, -1);
14508 }
14509
14510 static boolean draw_mode_hires = FALSE;
14511
14512 static boolean isHiresTileElement(int element)
14513 {
14514   return (IS_MM_WALL(element)        || element == EL_EMPTY);
14515 }
14516
14517 static boolean isHiresDrawElement(int element)
14518 {
14519   return (IS_MM_WALL_EDITOR(element) || element == EL_EMPTY);
14520 }
14521
14522 static int numHiresTiles(int element)
14523 {
14524   if (IS_MM_WALL(element))
14525     return get_number_of_bits(MM_WALL_BITS(element));
14526
14527   return 1;
14528 }
14529
14530 static void SetDrawModeHiRes(int element)
14531 {
14532   draw_mode_hires =
14533     (level.game_engine_type == GAME_ENGINE_TYPE_MM &&
14534      isHiresDrawElement(element));
14535 }
14536
14537 static boolean getDrawModeHiRes(void)
14538 {
14539   return draw_mode_hires;
14540 }
14541
14542 static int getLoResScreenPos(int pos)
14543 {
14544   return (getDrawModeHiRes() ? pos / 2 : pos);
14545 }
14546
14547 static int getLoResScreenMod(int pos)
14548 {
14549   return (getDrawModeHiRes() ? pos % 2 : 0);
14550 }
14551
14552 static void SetElementExt(int x, int y, int dx, int dy, int element,
14553                           boolean change_level, int button)
14554 {
14555   if (element < 0)
14556     SetElementSimple(x, y, Tile[x][y], change_level);
14557   else if (GetKeyModState() & KMOD_Shift)
14558     SetElementIntelliDraw(x, y, dx, dy, element, change_level, button);
14559   else
14560     SetElementSimpleExt(x, y, dx, dy, element, change_level);
14561 }
14562
14563 static void SetElement(int x, int y, int element)
14564 {
14565   SetElementExt(x, y, 0, 0, element, TRUE, -1);
14566 }
14567
14568 static void SetElementButton(int x, int y, int dx, int dy, int element,
14569                              int button)
14570 {
14571   SetElementExt(x, y, dx, dy, element, TRUE, button);
14572 }
14573
14574 static void SetElementHiRes(int sx2, int sy2, int element, boolean change_level)
14575 {
14576   int lx = getLoResScreenPos(sx2) + level_xpos;
14577   int ly = getLoResScreenPos(sy2) + level_ypos;
14578   int dx = getLoResScreenMod(sx2);
14579   int dy = getLoResScreenMod(sy2);
14580
14581   SetElementExt(lx, ly, dx, dy, element, change_level, -1);
14582 }
14583
14584 static void SetLevelElementHiRes(int lx2, int ly2, int element)
14585 {
14586   int lx = lx2 / 2;
14587   int ly = ly2 / 2;
14588   int dx = lx2 % 2;
14589   int dy = ly2 % 2;
14590
14591   SetElementExt(lx, ly, dx, dy, element, TRUE, -1);
14592 }
14593
14594 static int getLevelElementHiRes(int lx2, int ly2)
14595 {
14596   int lx = lx2 / 2;
14597   int ly = ly2 / 2;
14598   int dx = lx2 % 2;
14599   int dy = ly2 % 2;
14600   int element = Tile[lx][ly];
14601   unsigned int bitmask = (dx + 1) << (dy * 2);
14602
14603   if (IS_MM_WALL(element))
14604   {
14605     if (element & bitmask)
14606       return map_mm_wall_element(element);
14607     else
14608       return EL_EMPTY;
14609   }
14610
14611   return element;
14612 }
14613
14614 static void DrawLineElement(int x, int y, int element, boolean change_level)
14615 {
14616   SetElementHiRes(x, y, element, change_level);
14617 }
14618
14619 static void DrawLine(int from_x, int from_y, int to_x, int to_y,
14620                      int element, boolean change_level)
14621 {
14622   int xsize = ABS(to_x - from_x);
14623   int ysize = ABS(to_y - from_y);
14624   int dx = (to_x < from_x ? -1 : +1);
14625   int dy = (to_y < from_y ? -1 : +1);
14626   int i;
14627
14628   if (from_y == to_y)                   // horizontal line
14629   {
14630     for (i = 0; i <= xsize; i++)
14631       DrawLineElement(from_x + i * dx, from_y, element, change_level);
14632   }
14633   else if (from_x == to_x)              // vertical line
14634   {
14635     for (i = 0; i <= ysize; i++)
14636       DrawLineElement(from_x, from_y + i * dy, element, change_level);
14637   }
14638   else                                  // diagonal line
14639   {
14640     if (ysize < xsize)                  // a < 1
14641     {
14642       float a = (float)ysize / (float)xsize;
14643
14644       for (i = 0; i <= xsize; i++)
14645       {
14646         int x = dx * i;
14647         int y = dy * (int)(a * i + 0.5);
14648
14649         DrawLineElement(from_x + x, from_y + y, element, change_level);
14650       }
14651     }
14652     else                                // a >= 1
14653     {
14654       float a = (float)xsize / (float)ysize;
14655
14656       for (i = 0; i <= ysize; i++)
14657       {
14658         int x = dx * (int)(a * i + 0.5);
14659         int y = dy * i;
14660
14661         DrawLineElement(from_x + x, from_y + y, element, change_level);
14662       }
14663     }
14664   }
14665 }
14666
14667 static void DrawBox(int from_x, int from_y, int to_x, int to_y,
14668                     int element, boolean change_level)
14669 {
14670   DrawLine(from_x, from_y, from_x, to_y, element, change_level);
14671   DrawLine(from_x, to_y, to_x, to_y, element, change_level);
14672   DrawLine(to_x, to_y, to_x, from_y, element, change_level);
14673   DrawLine(to_x, from_y, from_x, from_y, element, change_level);
14674 }
14675
14676 static void DrawFilledBox(int from_x, int from_y, int to_x, int to_y,
14677                           int element, boolean change_level)
14678 {
14679   int y;
14680
14681   if (from_y > to_y)
14682     swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
14683
14684   for (y = from_y; y <= to_y; y++)
14685     DrawLine(from_x, y, to_x, y, element, change_level);
14686 }
14687
14688 static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
14689                        int element, boolean change_level)
14690 {
14691   int to_x = to_x2 - (to_x2 > from_x ? +1 : -1);
14692   int to_y = to_y2 - (to_y2 > from_y ? +1 : -1);
14693   int len_x = ABS(to_x - from_x);
14694   int len_y = ABS(to_y - from_y);
14695   int radius, x, y;
14696
14697   radius = (int)(sqrt((float)(len_x * len_x + len_y * len_y)) + 0.5);
14698
14699   // not optimal (some points get drawn twice) but simple,
14700   // and fast enough for the few points we are drawing
14701
14702   for (x = 0; x <= radius; x++)
14703   {
14704     int sx, sy, sx2, sy2, lx, ly;
14705
14706     y = (int)(sqrt((float)(radius * radius - x * x)) + 0.5);
14707
14708     sx2 = from_x + x * (from_x < to_x2 ? +1 : -1);
14709     sy2 = from_y + y * (from_y < to_y2 ? +1 : -1);
14710     sx = getLoResScreenPos(sx2);
14711     sy = getLoResScreenPos(sy2);
14712     lx = sx + level_xpos;
14713     ly = sy + level_ypos;
14714
14715     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
14716       DrawLineElement(sx2, sy2, element, change_level);
14717   }
14718
14719   for (y = 0; y <= radius; y++)
14720   {
14721     int sx, sy, sx2, sy2, lx, ly;
14722
14723     x = (int)(sqrt((float)(radius * radius - y * y)) + 0.5);
14724
14725     sx2 = from_x + x * (from_x < to_x2 ? +1 : -1);
14726     sy2 = from_y + y * (from_y < to_y2 ? +1 : -1);
14727     sx = getLoResScreenPos(sx2);
14728     sy = getLoResScreenPos(sy2);
14729     lx = sx + level_xpos;
14730     ly = sy + level_ypos;
14731
14732     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
14733       DrawLineElement(sx2, sy2, element, change_level);
14734   }
14735 }
14736
14737 static void DrawArc(int from_x, int from_y, int to_x, int to_y,
14738                     int element, boolean change_level)
14739 {
14740   int to_x2 = to_x + (to_x < from_x ? -1 : +1);
14741   int to_y2 = to_y + (to_y > from_y ? +1 : -1);
14742
14743   DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
14744 }
14745
14746 #define DRAW_CIRCLES_BUTTON_AVAILABLE   0
14747
14748 #if DRAW_CIRCLES_BUTTON_AVAILABLE
14749 static void DrawCircle(int from_x, int from_y, int to_x, int to_y,
14750                        int element, boolean change_level)
14751 {
14752   int to_x2 = to_x + (to_x < from_x ? -1 : +1);
14753   int to_y2 = to_y + (to_y > from_y ? +1 : -1);
14754   int mirror_to_x2 = from_x - (to_x2 - from_x);
14755   int mirror_to_y2 = from_y - (to_y2 - from_y);
14756
14757   DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
14758   DrawArcExt(from_x, from_y, mirror_to_x2, to_y2, element, change_level);
14759   DrawArcExt(from_x, from_y, to_x2, mirror_to_y2, element, change_level);
14760   DrawArcExt(from_x, from_y, mirror_to_x2, mirror_to_y2, element, change_level);
14761 }
14762 #endif
14763
14764 static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y)
14765 {
14766   int from_sx, from_sy;
14767   int to_sx, to_sy;
14768
14769   if (from_x > to_x)
14770     swap_numbers(&from_x, &to_x);
14771
14772   if (from_y > to_y)
14773     swap_numbers(&from_y, &to_y);
14774
14775   from_sx = SX + from_x * ed_tilesize;
14776   from_sy = SY + from_y * ed_tilesize;
14777   to_sx = SX + (to_x + 1) * ed_tilesize - 1;
14778   to_sy = SY + (to_y + 1) * ed_tilesize - 1;
14779
14780   DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx, from_sy);
14781   DrawSimpleWhiteLine(drawto, to_sx, from_sy, to_sx, to_sy);
14782   DrawSimpleWhiteLine(drawto, to_sx, to_sy, from_sx, to_sy);
14783   DrawSimpleWhiteLine(drawto, from_sx, to_sy, from_sx, from_sy);
14784
14785   if (from_x == to_x && from_y == to_y)
14786     MarkTileDirty(from_x/2, from_y/2);
14787   else
14788     redraw_mask |= REDRAW_FIELD;
14789 }
14790
14791 static void DrawAreaBox(int from_x, int from_y, int to_x, int to_y,
14792                         int element, boolean change_level)
14793 {
14794   DrawBox(from_x, from_y, to_x, to_y, element, change_level);
14795 }
14796
14797 static void SelectArea(int from_x, int from_y, int to_x, int to_y,
14798                        int element, boolean change_level)
14799 {
14800   if (element == -1 || change_level)
14801     DrawAreaBox(from_x, from_y, to_x, to_y, -1, FALSE);
14802   else
14803     DrawAreaBorder(from_x, from_y, to_x, to_y);
14804 }
14805
14806 // values for CopyBrushExt()
14807 #define CB_AREA_TO_BRUSH                0
14808 #define CB_BRUSH_TO_CURSOR              1
14809 #define CB_BRUSH_TO_LEVEL               2
14810 #define CB_DELETE_OLD_CURSOR            3
14811 #define CB_DUMP_BRUSH                   4
14812 #define CB_DUMP_BRUSH_SMALL             5
14813 #define CB_CLIPBOARD_TO_BRUSH           6
14814 #define CB_BRUSH_TO_CLIPBOARD           7
14815 #define CB_BRUSH_TO_CLIPBOARD_SMALL     8
14816 #define CB_UPDATE_BRUSH_POSITION        9
14817 #define CB_FLIP_BRUSH_X                 10
14818 #define CB_FLIP_BRUSH_Y                 11
14819 #define CB_FLIP_BRUSH_XY                12
14820
14821 #define MAX_CB_PART_SIZE        10
14822 #define MAX_CB_LINE_SIZE        (MAX_LEV_FIELDX + 1)    // text plus newline
14823 #define MAX_CB_NUM_LINES        (MAX_LEV_FIELDY)
14824 #define MAX_CB_TEXT_SIZE        (MAX_CB_LINE_SIZE *     \
14825                                  MAX_CB_NUM_LINES *     \
14826                                  MAX_CB_PART_SIZE)
14827
14828 static int getFlippedTileExt(int map[], int element)
14829 {
14830   int i;
14831
14832   for (i = 0; map[i] != -1; i++)
14833     if (map[i] == element)
14834       return map[i ^ 1];        // get flipped element by flipping LSB of index
14835
14836   return element;
14837 }
14838
14839 static int getFlippedTileX(int element)
14840 {
14841   int map[] =
14842   {
14843     EL_BD_BUTTERFLY_LEFT,               EL_BD_BUTTERFLY_RIGHT,
14844     EL_BD_FIREFLY_LEFT,                 EL_BD_FIREFLY_RIGHT,
14845     EL_BUG_LEFT,                        EL_BUG_RIGHT,
14846     EL_SPACESHIP_LEFT,                  EL_SPACESHIP_RIGHT,
14847     EL_PACMAN_LEFT,                     EL_PACMAN_RIGHT,
14848     EL_ARROW_LEFT,                      EL_ARROW_RIGHT,
14849     EL_MOLE_LEFT,                       EL_MOLE_RIGHT,
14850     EL_BALLOON_SWITCH_LEFT,             EL_BALLOON_SWITCH_RIGHT,
14851     EL_YAMYAM_LEFT,                     EL_YAMYAM_RIGHT,
14852     EL_SP_PORT_LEFT,                    EL_SP_PORT_RIGHT,
14853     EL_SP_GRAVITY_PORT_LEFT,            EL_SP_GRAVITY_PORT_RIGHT,
14854     EL_SP_GRAVITY_ON_PORT_LEFT,         EL_SP_GRAVITY_ON_PORT_RIGHT,
14855     EL_SP_GRAVITY_OFF_PORT_LEFT,        EL_SP_GRAVITY_OFF_PORT_RIGHT,
14856     EL_CONVEYOR_BELT_1_LEFT,            EL_CONVEYOR_BELT_1_RIGHT,
14857     EL_CONVEYOR_BELT_2_LEFT,            EL_CONVEYOR_BELT_2_RIGHT,
14858     EL_CONVEYOR_BELT_3_LEFT,            EL_CONVEYOR_BELT_3_RIGHT,
14859     EL_CONVEYOR_BELT_4_LEFT,            EL_CONVEYOR_BELT_4_RIGHT,
14860     EL_SPRING_LEFT,                     EL_SPRING_RIGHT,
14861     EL_SP_CHIP_LEFT,                    EL_SP_CHIP_RIGHT,
14862     EL_TUBE_VERTICAL_LEFT,              EL_TUBE_VERTICAL_RIGHT,
14863     EL_TUBE_LEFT_UP,                    EL_TUBE_RIGHT_UP,
14864     EL_TUBE_LEFT_DOWN,                  EL_TUBE_RIGHT_DOWN,
14865     EL_DC_STEELWALL_1_LEFT,             EL_DC_STEELWALL_1_RIGHT,
14866     EL_DC_STEELWALL_1_TOPLEFT,          EL_DC_STEELWALL_1_TOPRIGHT,
14867     EL_DC_STEELWALL_1_BOTTOMLEFT,       EL_DC_STEELWALL_1_BOTTOMRIGHT,
14868     EL_DC_STEELWALL_1_TOPLEFT_2,        EL_DC_STEELWALL_1_TOPRIGHT_2,
14869     EL_DC_STEELWALL_1_BOTTOMLEFT_2,     EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
14870     EL_DC_STEELWALL_2_LEFT,             EL_DC_STEELWALL_2_RIGHT,
14871     EL_ACID_POOL_TOPLEFT,               EL_ACID_POOL_TOPRIGHT,
14872     EL_ACID_POOL_BOTTOMLEFT,            EL_ACID_POOL_BOTTOMRIGHT,
14873
14874     -1
14875   };
14876
14877   return getFlippedTileExt(map, element);
14878 }
14879
14880 static int getFlippedTileY(int element)
14881 {
14882   int map[] =
14883   {
14884     EL_BD_BUTTERFLY_UP,                 EL_BD_BUTTERFLY_DOWN,
14885     EL_BD_FIREFLY_UP,                   EL_BD_FIREFLY_DOWN,
14886     EL_BUG_UP,                          EL_BUG_DOWN,
14887     EL_SPACESHIP_UP,                    EL_SPACESHIP_DOWN,
14888     EL_PACMAN_UP,                       EL_PACMAN_DOWN,
14889     EL_ARROW_UP,                        EL_ARROW_DOWN,
14890     EL_MOLE_UP,                         EL_MOLE_DOWN,
14891     EL_BALLOON_SWITCH_UP,               EL_BALLOON_SWITCH_DOWN,
14892     EL_YAMYAM_UP,                       EL_YAMYAM_DOWN,
14893     EL_SP_PORT_UP,                      EL_SP_PORT_DOWN,
14894     EL_SP_GRAVITY_PORT_UP,              EL_SP_GRAVITY_PORT_DOWN,
14895     EL_SP_GRAVITY_ON_PORT_UP,           EL_SP_GRAVITY_ON_PORT_DOWN,
14896     EL_SP_GRAVITY_OFF_PORT_UP,          EL_SP_GRAVITY_OFF_PORT_DOWN,
14897     EL_SP_CHIP_TOP,                     EL_SP_CHIP_BOTTOM,
14898     EL_TUBE_HORIZONTAL_UP,              EL_TUBE_HORIZONTAL_DOWN,
14899     EL_TUBE_LEFT_UP,                    EL_TUBE_LEFT_DOWN,
14900     EL_TUBE_RIGHT_UP,                   EL_TUBE_RIGHT_DOWN,
14901     EL_DC_STEELWALL_1_TOP,              EL_DC_STEELWALL_1_BOTTOM,
14902     EL_DC_STEELWALL_1_TOPLEFT,          EL_DC_STEELWALL_1_BOTTOMLEFT,
14903     EL_DC_STEELWALL_1_TOPRIGHT,         EL_DC_STEELWALL_1_BOTTOMRIGHT,
14904     EL_DC_STEELWALL_1_TOPLEFT_2,        EL_DC_STEELWALL_1_BOTTOMLEFT_2,
14905     EL_DC_STEELWALL_1_TOPRIGHT_2,       EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
14906     EL_DC_STEELWALL_2_TOP,              EL_DC_STEELWALL_2_BOTTOM,
14907     EL_EMC_WALL_1,                      EL_EMC_WALL_3,
14908
14909     -1
14910   };
14911
14912   return getFlippedTileExt(map, element);
14913 }
14914
14915 static int getFlippedTileXY(int element)
14916 {
14917   int map[] =
14918   {
14919     EL_BD_BUTTERFLY_LEFT,               EL_BD_BUTTERFLY_UP,
14920     EL_BD_BUTTERFLY_RIGHT,              EL_BD_BUTTERFLY_DOWN,
14921     EL_BD_FIREFLY_LEFT,                 EL_BD_FIREFLY_UP,
14922     EL_BD_FIREFLY_RIGHT,                EL_BD_FIREFLY_DOWN,
14923     EL_BUG_LEFT,                        EL_BUG_UP,
14924     EL_BUG_RIGHT,                       EL_BUG_DOWN,
14925     EL_SPACESHIP_LEFT,                  EL_SPACESHIP_UP,
14926     EL_SPACESHIP_RIGHT,                 EL_SPACESHIP_DOWN,
14927     EL_PACMAN_LEFT,                     EL_PACMAN_UP,
14928     EL_PACMAN_RIGHT,                    EL_PACMAN_DOWN,
14929     EL_ARROW_LEFT,                      EL_ARROW_UP,
14930     EL_ARROW_RIGHT,                     EL_ARROW_DOWN,
14931     EL_MOLE_LEFT,                       EL_MOLE_UP,
14932     EL_MOLE_RIGHT,                      EL_MOLE_DOWN,
14933     EL_BALLOON_SWITCH_LEFT,             EL_BALLOON_SWITCH_UP,
14934     EL_BALLOON_SWITCH_RIGHT,            EL_BALLOON_SWITCH_DOWN,
14935     EL_YAMYAM_LEFT,                     EL_YAMYAM_UP,
14936     EL_YAMYAM_RIGHT,                    EL_YAMYAM_DOWN,
14937     EL_SP_PORT_LEFT,                    EL_SP_PORT_UP,
14938     EL_SP_PORT_RIGHT,                   EL_SP_PORT_DOWN,
14939     EL_SP_GRAVITY_PORT_LEFT,            EL_SP_GRAVITY_PORT_UP,
14940     EL_SP_GRAVITY_PORT_RIGHT,           EL_SP_GRAVITY_PORT_DOWN,
14941     EL_SP_GRAVITY_ON_PORT_LEFT,         EL_SP_GRAVITY_ON_PORT_UP,
14942     EL_SP_GRAVITY_ON_PORT_RIGHT,        EL_SP_GRAVITY_ON_PORT_DOWN,
14943     EL_SP_GRAVITY_OFF_PORT_LEFT,        EL_SP_GRAVITY_OFF_PORT_UP,
14944     EL_SP_GRAVITY_OFF_PORT_RIGHT,       EL_SP_GRAVITY_OFF_PORT_DOWN,
14945     EL_SP_CHIP_LEFT,                    EL_SP_CHIP_TOP,
14946     EL_SP_CHIP_RIGHT,                   EL_SP_CHIP_BOTTOM,
14947     EL_TUBE_VERTICAL,                   EL_TUBE_HORIZONTAL,
14948     EL_TUBE_VERTICAL_LEFT,              EL_TUBE_HORIZONTAL_UP,
14949     EL_TUBE_VERTICAL_RIGHT,             EL_TUBE_HORIZONTAL_DOWN,
14950     EL_TUBE_LEFT_DOWN,                  EL_TUBE_RIGHT_UP,
14951     EL_DC_STEELWALL_1_LEFT,             EL_DC_STEELWALL_1_TOP,
14952     EL_DC_STEELWALL_1_RIGHT,            EL_DC_STEELWALL_1_BOTTOM,
14953     EL_DC_STEELWALL_1_HORIZONTAL,       EL_DC_STEELWALL_1_VERTICAL,
14954     EL_DC_STEELWALL_1_TOPRIGHT,         EL_DC_STEELWALL_1_BOTTOMLEFT,
14955     EL_DC_STEELWALL_1_TOPRIGHT_2,       EL_DC_STEELWALL_1_BOTTOMLEFT_2,
14956     EL_DC_STEELWALL_2_LEFT,             EL_DC_STEELWALL_2_TOP,
14957     EL_DC_STEELWALL_2_RIGHT,            EL_DC_STEELWALL_2_BOTTOM,
14958     EL_DC_STEELWALL_2_HORIZONTAL,       EL_DC_STEELWALL_2_VERTICAL,
14959     EL_EXPANDABLE_WALL_HORIZONTAL,      EL_EXPANDABLE_WALL_VERTICAL,
14960     EL_EXPANDABLE_STEELWALL_HORIZONTAL, EL_EXPANDABLE_STEELWALL_VERTICAL,
14961
14962     -1
14963   };
14964
14965   return getFlippedTileExt(map, element);
14966 }
14967
14968 static int getFlippedTile(int element, int mode)
14969 {
14970   if (IS_MM_ELEMENT(element))
14971   {
14972     // get MM game element
14973     element = map_element_RND_to_MM(element);
14974
14975     // get flipped game element
14976     element = (mode == CB_FLIP_BRUSH_X  ? getFlippedTileX_MM(element) :
14977                mode == CB_FLIP_BRUSH_Y  ? getFlippedTileY_MM(element) :
14978                mode == CB_FLIP_BRUSH_XY ? getFlippedTileXY_MM(element) :
14979                element);
14980
14981     // get RND game element again
14982     element = map_element_MM_to_RND(element);
14983   }
14984   else
14985   {
14986     // get flipped game element
14987     element = (mode == CB_FLIP_BRUSH_X  ? getFlippedTileX(element) :
14988                mode == CB_FLIP_BRUSH_Y  ? getFlippedTileY(element) :
14989                mode == CB_FLIP_BRUSH_XY ? getFlippedTileXY(element) :
14990                element);
14991   }
14992
14993   return element;
14994 }
14995
14996 static void SwapFlippedTiles(short *tile1, short *tile2, int mode)
14997 {
14998   // flip tiles
14999   short tile1_flipped = getFlippedTile(*tile1, mode);
15000   short tile2_flipped = getFlippedTile(*tile2, mode);
15001
15002   // swap tiles
15003   *tile1 = tile2_flipped;
15004   *tile2 = tile1_flipped;
15005 }
15006
15007 static void DrawBrushElement(int sx, int sy, int element, boolean change_level)
15008 {
15009   DrawLineElement(sx, sy, element, change_level);
15010 }
15011
15012 static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
15013                          int button, int mode)
15014 {
15015   static short brush_buffer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
15016   static int brush_width, brush_height;
15017   static int last_cursor_x = -1, last_cursor_y = -1;
15018   static boolean delete_old_brush = FALSE;
15019   int new_element = BUTTON_ELEMENT(button);
15020   int x, y;
15021
15022   if (mode == CB_DUMP_BRUSH ||
15023       mode == CB_DUMP_BRUSH_SMALL ||
15024       mode == CB_BRUSH_TO_CLIPBOARD ||
15025       mode == CB_BRUSH_TO_CLIPBOARD_SMALL)
15026   {
15027     if (edit_mode != ED_MODE_DRAWING)
15028       return;
15029
15030     char part[MAX_CB_PART_SIZE + 1] = "";
15031     char text[MAX_CB_TEXT_SIZE + 1] = "";
15032     int width  = (draw_with_brush ? brush_width  : lev_fieldx);
15033     int height = (draw_with_brush ? brush_height : lev_fieldy);
15034     char *format = "%s%03d";
15035
15036     for (y = 0; y < height; y++)
15037       for (x = 0; x < width; x++)
15038         if ((draw_with_brush ? brush_buffer[x][y] : Tile[x][y]) > 999)
15039           format = "%s%04d";
15040
15041     for (y = 0; y < height; y++)
15042     {
15043       for (x = 0; x < width; x++)
15044       {
15045         int element = (draw_with_brush ? brush_buffer[x][y] : Tile[x][y]);
15046         char *prefix = (mode == CB_DUMP_BRUSH ||
15047                         mode == CB_BRUSH_TO_CLIPBOARD ? "`" : "¸");
15048
15049         if (element >= NUM_FILE_ELEMENTS)
15050           element = EL_UNKNOWN;
15051
15052         // copy brush to level sketch text buffer for the R'n'D forum:
15053         // - large tiles: `xxx or `xxxx (0x60 ASCII)
15054         // - small tiles: Â¸xxx or Â¸xxxx (0xb8 ISO-8859-1, 0xc2b8 UTF-8)
15055         snprintf(part, MAX_CB_PART_SIZE + 1, format, prefix, element);
15056         strcat(text, part);
15057       }
15058
15059       strcat(text, "\n");
15060     }
15061
15062     if (mode == CB_BRUSH_TO_CLIPBOARD ||
15063         mode == CB_BRUSH_TO_CLIPBOARD_SMALL)
15064       SDL_SetClipboardText(text);
15065     else
15066       Print("%s", text);        // print brush data to console and log file
15067
15068     return;
15069   }
15070
15071   if (mode == CB_CLIPBOARD_TO_BRUSH)
15072   {
15073     if (edit_mode != ED_MODE_DRAWING)
15074       return;
15075
15076     if (!SDL_HasClipboardText())
15077     {
15078       Request("Clipboard is empty!", REQ_CONFIRM);
15079
15080       return;
15081     }
15082
15083     boolean copy_to_brush = (draw_with_brush ||
15084                              drawing_function == GADGET_ID_GRAB_BRUSH);
15085
15086     // this will delete the old brush, if already drawing with a brush
15087     if (copy_to_brush)
15088       ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS], MB_LEFTBUTTON);
15089
15090     // initialization is required for "odd" (incomplete) clipboard content
15091     for (x = 0; x < MAX_LEV_FIELDX; x++)
15092       for (y = 0; y < MAX_LEV_FIELDY; y++)
15093         brush_buffer[x][y] = EL_EMPTY;
15094
15095     brush_width  = 0;
15096     brush_height = 0;
15097     x = 0;
15098     y = 0;
15099
15100     char *clipboard_text = SDL_GetClipboardText();
15101     char *ptr = clipboard_text;
15102     boolean allow_new_row = FALSE;
15103     boolean stop = FALSE;
15104
15105     while (*ptr && !stop)
15106     {
15107       boolean prefix_found = FALSE;
15108       boolean start_new_row = FALSE;
15109
15110       // level sketch element number prefixes (may be multi-byte characters)
15111       char *prefix_list[] = { "`", "¸" };
15112       int i;
15113
15114       for (i = 0; i < ARRAY_SIZE(prefix_list); i++)
15115       {
15116         char *prefix = prefix_list[i];
15117
15118         // check if string is large enough for prefix
15119         if (strlen(ptr) < strlen(prefix))
15120         {
15121           stop = TRUE;
15122
15123           break;
15124         }
15125
15126         // check if string starts with prefix
15127         if (strPrefix(ptr, prefix))
15128         {
15129           ptr += strlen(prefix);
15130
15131           prefix_found = TRUE;
15132
15133           break;
15134         }
15135       }
15136
15137       // check if prefix found and followed by (at least) three digits
15138       if (prefix_found &&
15139           strlen(ptr) >= 3 &&
15140           ptr[0] >= '0' && ptr[0] <= '9' &&
15141           ptr[1] >= '0' && ptr[1] <= '9' &&
15142           ptr[2] >= '0' && ptr[2] <= '9')
15143       {
15144         int element = ((ptr[0] - '0') * 100 +
15145                        (ptr[1] - '0') * 10 +
15146                        (ptr[2] - '0'));
15147
15148         ptr += 3;
15149
15150         // level sketch element number might consist of four digits
15151         if (ptr[0] >= '0' && ptr[0] <= '9')
15152         {
15153           element = element * 10 + (ptr[0] - '0');
15154           ptr++;
15155         }
15156
15157         // remap some (historic, now obsolete) elements
15158         element = getMappedElement(element);
15159
15160         if (element >= NUM_FILE_ELEMENTS)
15161           element = EL_UNKNOWN;
15162
15163         brush_buffer[x][y] = element;
15164
15165         brush_width  = MAX(x + 1, brush_width);
15166         brush_height = MAX(y + 1, brush_height);
15167
15168         x++;
15169
15170         if (x >= MAX_LEV_FIELDX)
15171           start_new_row = TRUE;
15172
15173         allow_new_row = TRUE;
15174       }
15175       else
15176       {
15177         if ((*ptr == '\n' || *ptr == '\r') && allow_new_row)
15178           start_new_row = TRUE;
15179
15180         ptr++;          // !!! FIX THIS for real UTF-8 handling !!!
15181       }
15182
15183       if (start_new_row)
15184       {
15185         x = 0;
15186         y++;
15187
15188         if (y >= MAX_LEV_FIELDY)
15189           stop = TRUE;
15190
15191         allow_new_row = FALSE;
15192       }
15193     }
15194
15195     SDL_free(clipboard_text);
15196
15197     if (brush_width == 0 || brush_height == 0)
15198     {
15199       Request("No level sketch found in clipboard!", REQ_CONFIRM);
15200
15201       return;
15202     }
15203
15204     if (copy_to_brush)
15205     {
15206       struct GadgetInfo *gi = level_editor_gadget[GADGET_ID_DRAWING_LEVEL];
15207       int mx, my;
15208
15209       SDL_GetMouseState(&mx, &my);
15210
15211       // if inside drawing area, activate and draw brush at last mouse position
15212       if (mx >= gi->x && mx < gi->x + gi->width &&
15213           my >= gi->y && my < gi->y + gi->height)
15214         CopyBrushToCursor(last_cursor_x, last_cursor_y);
15215
15216       draw_with_brush = TRUE;
15217     }
15218     else
15219     {
15220       char request[100];
15221
15222       sprintf(request, "Replace level with %dx%d level sketch from clipboard?",
15223               brush_width, brush_height);
15224
15225       if (!Request(request, REQ_ASK))
15226         return;
15227
15228       for (x = 0; x < MAX_LEV_FIELDX; x++)
15229         for (y = 0; y < MAX_LEV_FIELDY; y++)
15230           Tile[x][y] = brush_buffer[x][y];
15231
15232       lev_fieldx = level.fieldx = brush_width;
15233       lev_fieldy = level.fieldy = brush_height;
15234
15235       boolean use_bd_engine = TRUE;
15236       boolean use_em_engine = TRUE;
15237       boolean use_sp_engine = TRUE;
15238       boolean use_mm_engine = TRUE;
15239
15240       for (x = 0; x < MAX_LEV_FIELDX; x++)
15241       {
15242         for (y = 0; y < MAX_LEV_FIELDY; y++)
15243         {
15244           int element = Tile[x][y];
15245
15246           if (!IS_BD_ELEMENT(element) && !IS_PLAYER_ELEMENT(element))
15247             use_bd_engine = FALSE;
15248
15249           if (!IS_EM_ELEMENT(element) && !IS_PLAYER_ELEMENT(element))
15250             use_em_engine = FALSE;
15251
15252           if (!IS_SP_ELEMENT(element))
15253             use_sp_engine = FALSE;
15254
15255           if (!IS_MM_ELEMENT(element) && element != EL_EMPTY)
15256             use_mm_engine = FALSE;
15257         }
15258       }
15259
15260       level.game_engine_type = (use_bd_engine ? GAME_ENGINE_TYPE_BD :
15261                                 use_em_engine ? GAME_ENGINE_TYPE_EM :
15262                                 use_sp_engine ? GAME_ENGINE_TYPE_SP :
15263                                 use_mm_engine ? GAME_ENGINE_TYPE_MM :
15264                                 GAME_ENGINE_TYPE_RND);
15265
15266       // update element selection list
15267       ReinitializeElementList();
15268       ModifyEditorElementList();
15269
15270       SetBorderElement();
15271
15272       DrawEditModeWindow();
15273       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
15274     }
15275
15276     return;
15277   }
15278
15279   if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush)
15280     return;
15281
15282   if (mode == CB_AREA_TO_BRUSH)
15283   {
15284     int from_lx, from_ly;
15285
15286     if (from_x > to_x)
15287       swap_numbers(&from_x, &to_x);
15288
15289     if (from_y > to_y)
15290       swap_numbers(&from_y, &to_y);
15291
15292     brush_width = to_x - from_x + 1;
15293     brush_height = to_y - from_y + 1;
15294
15295     from_lx = from_x + level_xpos;
15296     from_ly = from_y + level_ypos;
15297
15298     for (y = 0; y < brush_height; y++)
15299     {
15300       for (x = 0; x < brush_width; x++)
15301       {
15302         brush_buffer[x][y] = Tile[from_lx + x][from_ly + y];
15303
15304         if (button != 1)
15305           DrawBrushElement(from_x + x, from_y + y, new_element, TRUE);
15306       }
15307     }
15308
15309     if (button != 1)
15310       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
15311
15312     delete_old_brush = FALSE;
15313   }
15314   else if (mode == CB_BRUSH_TO_CURSOR || mode == CB_DELETE_OLD_CURSOR ||
15315            mode == CB_BRUSH_TO_LEVEL)
15316   {
15317     int cursor_x = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_x : from_x);
15318     int cursor_y = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_y : from_y);
15319     int cursor_from_x = cursor_x - brush_width / 2;
15320     int cursor_from_y = cursor_y - brush_height / 2;
15321     int border_from_x = cursor_x, border_from_y = cursor_y;
15322     int border_to_x = cursor_x, border_to_y = cursor_y;
15323
15324     if (mode != CB_DELETE_OLD_CURSOR && delete_old_brush)
15325       CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
15326
15327     if (!IN_ED_FIELD(cursor_x, cursor_y) ||
15328         !IN_LEV_FIELD(cursor_x + level_xpos, cursor_y + level_ypos))
15329     {
15330       delete_old_brush = FALSE;
15331
15332       return;
15333     }
15334
15335     for (y = 0; y < brush_height; y++)
15336     {
15337       for (x = 0; x < brush_width; x++)
15338       {
15339         int sx = cursor_from_x + x;
15340         int sy = cursor_from_y + y;
15341         int lx = sx + level_xpos;
15342         int ly = sy + level_ypos;
15343         boolean change_level = (mode == CB_BRUSH_TO_LEVEL);
15344         int element = (mode == CB_DELETE_OLD_CURSOR ? -1 :
15345                        mode == CB_BRUSH_TO_CURSOR || button == 1 ?
15346                        brush_buffer[x][y] : new_element);
15347
15348         if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
15349         {
15350           if (sx < border_from_x)
15351             border_from_x = sx;
15352           else if (sx > border_to_x)
15353             border_to_x = sx;
15354           if (sy < border_from_y)
15355             border_from_y = sy;
15356           else if (sy > border_to_y)
15357             border_to_y = sy;
15358
15359           DrawBrushElement(sx, sy, element, change_level);
15360         }
15361       }
15362     }
15363
15364     if (mode != CB_DELETE_OLD_CURSOR)
15365       DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y);
15366
15367     last_cursor_x = cursor_x;
15368     last_cursor_y = cursor_y;
15369
15370     delete_old_brush = TRUE;
15371   }
15372   else if (mode == CB_FLIP_BRUSH_X)
15373   {
15374     for (y = 0; y < brush_height; y++)
15375       for (x = 0; x < (brush_width + 1) / 2; x++)
15376         SwapFlippedTiles(&brush_buffer[x][y],
15377                          &brush_buffer[brush_width - x - 1][y], mode);
15378
15379     CopyBrushExt(last_cursor_x, last_cursor_y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
15380   }
15381   else if (mode == CB_FLIP_BRUSH_Y)
15382   {
15383     for (y = 0; y < (brush_height + 1) / 2; y++)
15384       for (x = 0; x < brush_width; x++)
15385         SwapFlippedTiles(&brush_buffer[x][y],
15386                          &brush_buffer[x][brush_height - y - 1], mode);
15387
15388     CopyBrushExt(last_cursor_x, last_cursor_y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
15389   }
15390   else if (mode == CB_FLIP_BRUSH_XY)
15391   {
15392     CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
15393
15394     for (y = 0; y < MAX(brush_width, brush_height); y++)
15395       for (x = 0; x <= y; x++)
15396         SwapFlippedTiles(&brush_buffer[x][y],
15397                          &brush_buffer[y][x], mode);
15398
15399     swap_numbers(&brush_width, &brush_height);
15400
15401     CopyBrushExt(last_cursor_x, last_cursor_y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
15402   }
15403
15404   if (mode == CB_UPDATE_BRUSH_POSITION)
15405   {
15406     last_cursor_x = from_x;
15407     last_cursor_y = from_y;
15408   }
15409 }
15410
15411 static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y,
15412                             int button)
15413 {
15414   CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH);
15415 }
15416
15417 static void CopyBrushToLevel(int x, int y, int button)
15418 {
15419   CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL);
15420 }
15421
15422 static void CopyBrushToCursor(int x, int y)
15423 {
15424   CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
15425 }
15426
15427 static void UpdateBrushPosition(int x, int y)
15428 {
15429   CopyBrushExt(x, y, 0, 0, 0, CB_UPDATE_BRUSH_POSITION);
15430 }
15431
15432 static void DeleteBrushFromCursor(void)
15433 {
15434   CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
15435 }
15436
15437 static void FlipBrushX(void)
15438 {
15439   CopyBrushExt(0, 0, 0, 0, 0, CB_FLIP_BRUSH_X);
15440 }
15441
15442 static void FlipBrushY(void)
15443 {
15444   CopyBrushExt(0, 0, 0, 0, 0, CB_FLIP_BRUSH_Y);
15445 }
15446
15447 static void RotateBrush(void)
15448 {
15449   CopyBrushExt(0, 0, 0, 0, 0, CB_FLIP_BRUSH_XY);
15450   CopyBrushExt(0, 0, 0, 0, 0, CB_FLIP_BRUSH_X);
15451 }
15452
15453 void DumpBrush(void)
15454 {
15455   CopyBrushExt(0, 0, 0, 0, 0, CB_DUMP_BRUSH);
15456 }
15457
15458 void DumpBrush_Small(void)
15459 {
15460   CopyBrushExt(0, 0, 0, 0, 0, CB_DUMP_BRUSH_SMALL);
15461 }
15462
15463 void CopyClipboardToBrush(void)
15464 {
15465   CopyBrushExt(0, 0, 0, 0, 0, CB_CLIPBOARD_TO_BRUSH);
15466 }
15467
15468 void CopyBrushToClipboard(void)
15469 {
15470   CopyBrushExt(0, 0, 0, 0, 0, CB_BRUSH_TO_CLIPBOARD);
15471 }
15472
15473 void CopyBrushToClipboard_Small(void)
15474 {
15475   CopyBrushExt(0, 0, 0, 0, 0, CB_BRUSH_TO_CLIPBOARD_SMALL);
15476 }
15477
15478 void UndoLevelEditorOperation(void)
15479 {
15480   ClickOnGadget(level_editor_gadget[GADGET_ID_UNDO], -1);
15481 }
15482
15483 void RedoLevelEditorOperation(void)
15484 {
15485   ClickOnGadget(level_editor_gadget[GADGET_ID_UNDO], 3);
15486 }
15487
15488 static void FloodFill(int from_x, int from_y, int fill_element)
15489 {
15490   FloodFillLevel(from_x, from_y, fill_element, Tile, lev_fieldx, lev_fieldy);
15491 }
15492
15493 static void FloodFillWall_MM(int from_sx2, int from_sy2, int fill_element)
15494 {
15495   int from_x = from_sx2 + 2 * level_xpos;
15496   int from_y = from_sy2 + 2 * level_ypos;
15497   int max_fillx = lev_fieldx * 2;
15498   int max_filly = lev_fieldy * 2;
15499   short Fill[max_fillx][max_filly];
15500   int x, y;
15501
15502   for (x = 0; x < max_fillx; x++)
15503     for (y = 0; y < max_filly; y++)
15504       Fill[x][y] = getLevelElementHiRes(x, y);
15505
15506   FloodFillLevelExt(from_x, from_y, fill_element, max_fillx, max_filly,
15507                     Fill, max_fillx, max_filly);
15508
15509   for (x = 0; x < max_fillx; x++)
15510     for (y = 0; y < max_filly; y++)
15511       if (Fill[x][y] == fill_element)
15512         SetLevelElementHiRes(x, y, Fill[x][y]);
15513 }
15514
15515 // values for DrawLevelText() modes
15516 #define TEXT_INIT               0
15517 #define TEXT_SETCURSOR          1
15518 #define TEXT_WRITECHAR          2
15519 #define TEXT_BACKSPACE          3
15520 #define TEXT_NEWLINE            4
15521 #define TEXT_END                5
15522 #define TEXT_QUERY_TYPING       6
15523
15524 static int DrawLevelText(int sx, int sy, char letter, int mode)
15525 {
15526   static short delete_buffer[MAX_LEV_FIELDX];
15527   static int start_sx;
15528   static int last_sx, last_sy;
15529   static boolean typing = FALSE;
15530   int letter_element;
15531   int lx = 0, ly = 0;
15532
15533   // map lower case letters to upper case and convert special characters
15534   if (letter >= 'a' && letter <= 'z')
15535     letter_element = EL_CHAR_ASCII0 + letter + (int)('A' - 'a');
15536   else if (letter == CHAR_BYTE_UMLAUT_a || letter == CHAR_BYTE_UMLAUT_A)
15537     letter_element = EL_CHAR_AUMLAUT;
15538   else if (letter == CHAR_BYTE_UMLAUT_o || letter == CHAR_BYTE_UMLAUT_O)
15539     letter_element = EL_CHAR_OUMLAUT;
15540   else if (letter == CHAR_BYTE_UMLAUT_u || letter == CHAR_BYTE_UMLAUT_U)
15541     letter_element = EL_CHAR_UUMLAUT;
15542   else if (letter == '^')
15543     letter_element = EL_CHAR_COPYRIGHT;
15544   else
15545     letter_element = EL_CHAR_ASCII0 + letter;
15546
15547   if (mode != TEXT_INIT)
15548   {
15549     if (!typing)
15550       return FALSE;
15551
15552     if (mode != TEXT_SETCURSOR)
15553     {
15554       sx = last_sx;
15555       sy = last_sy;
15556     }
15557
15558     lx = last_sx + level_xpos;
15559     ly = last_sy + level_ypos;
15560   }
15561
15562   switch (mode)
15563   {
15564     case TEXT_INIT:
15565       if (typing)
15566         DrawLevelText(0, 0, 0, TEXT_END);
15567
15568       typing = TRUE;
15569       start_sx = sx;
15570       last_sx = sx;
15571       last_sy = sy;
15572       DrawLevelText(sx, sy, 0, TEXT_SETCURSOR);
15573       break;
15574
15575     case TEXT_SETCURSOR:
15576       DrawEditorElement(last_sx, last_sy, Tile[lx][ly]);
15577       DrawAreaBorder(sx, sy, sx, sy);
15578       StartTextInput(SX + sx * ed_tilesize, SY + sy * ed_tilesize,
15579                      ed_tilesize, ed_tilesize);
15580       last_sx = sx;
15581       last_sy = sy;
15582       break;
15583
15584     case TEXT_WRITECHAR:
15585       if (letter_element >= EL_CHAR_START && letter_element <= EL_CHAR_END)
15586       {
15587         if (new_element1 >= EL_STEEL_CHAR_START &&
15588             new_element1 <= EL_STEEL_CHAR_END)
15589           letter_element = letter_element - EL_CHAR_START + EL_STEEL_CHAR_START;
15590
15591         delete_buffer[sx - start_sx] = Tile[lx][ly];
15592         Tile[lx][ly] = letter_element;
15593
15594         if (sx + 1 < ed_fieldx && lx + 1 < lev_fieldx)
15595           DrawLevelText(sx + 1, sy, 0, TEXT_SETCURSOR);
15596         else if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
15597           DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
15598         else
15599           DrawLevelText(0, 0, 0, TEXT_END);
15600
15601         level.changed = TRUE;
15602       }
15603       break;
15604
15605     case TEXT_BACKSPACE:
15606       if (sx > start_sx)
15607       {
15608         Tile[lx - 1][ly] = delete_buffer[sx - start_sx - 1];
15609         DrawEditorElement(sx - 1, sy, Tile[lx - 1][ly]);
15610         DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR);
15611       }
15612       break;
15613
15614     case TEXT_NEWLINE:
15615       if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
15616         DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
15617       else
15618         DrawLevelText(0, 0, 0, TEXT_END);
15619       break;
15620
15621     case TEXT_END:
15622       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
15623       DrawEditorElement(sx, sy, Tile[lx][ly]);
15624       StopTextInput();
15625       typing = FALSE;
15626       break;
15627
15628     case TEXT_QUERY_TYPING:
15629       break;
15630
15631     default:
15632       break;
15633   }
15634
15635   return typing;
15636 }
15637
15638 static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy,
15639                           int element, boolean change_level)
15640 {
15641   int lx = sx + level_xpos;
15642   int ly = sy + level_ypos;
15643
15644   if (element == -1)
15645     DrawEditorElement(sx, sy, Tile[lx][ly]);
15646   else
15647     DrawAreaBorder(sx, sy, sx, sy);
15648 }
15649
15650 static void CheckLevelBorderElement(boolean redraw_playfield)
15651 {
15652   int last_border_element = BorderElement;
15653
15654   SetBorderElement();
15655
15656   if (redraw_playfield && BorderElement != last_border_element)
15657     DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
15658 }
15659
15660 static void CopyLevelToUndoBuffer(int mode)
15661 {
15662   static boolean accumulated_undo = FALSE;
15663   boolean new_undo_buffer_position = TRUE;
15664   int x, y;
15665
15666   if (undo_buffer_steps == 0)
15667     accumulated_undo = FALSE;
15668
15669   switch (mode)
15670   {
15671     case UNDO_IMMEDIATE:
15672       accumulated_undo = FALSE;
15673       break;
15674
15675     case UNDO_ACCUMULATE:
15676       if (accumulated_undo)
15677         new_undo_buffer_position = FALSE;
15678       accumulated_undo = TRUE;
15679       break;
15680
15681     default:
15682       break;
15683   }
15684
15685   if (new_undo_buffer_position)
15686   {
15687     // advance position in undo buffer ring
15688     undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS;
15689
15690     if (undo_buffer_steps < NUM_UNDO_STEPS - 1)
15691       undo_buffer_steps++;
15692   }
15693
15694   // always reset redo buffer when storing level change into undo buffer
15695   redo_buffer_steps = 0;
15696
15697   for (x = 0; x < lev_fieldx; x++)
15698     for (y = 0; y < lev_fieldy; y++)
15699       UndoBuffer[undo_buffer_position][x][y] = Tile[x][y];
15700
15701   // check if drawing operation forces change of border style
15702   CheckLevelBorderElement(TRUE);
15703
15704   level.changed = TRUE;
15705 }
15706
15707 static void RandomPlacement(int new_element)
15708 {
15709   static boolean free_position[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
15710   int num_free_positions = 0;
15711   int num_percentage, num_elements;
15712   int x, y;
15713
15714   ResetIntelliDraw();
15715
15716   // determine number of free positions for randomly placing the new element
15717   for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
15718   {
15719     free_position[x][y] =
15720       (random_placement_background_restricted ?
15721        Tile[x][y] == random_placement_background_element :
15722        Tile[x][y] != new_element);
15723
15724     if (free_position[x][y])
15725       num_free_positions++;
15726   }
15727
15728   // determine number of new elements to place there
15729   num_percentage = num_free_positions * random_placement_value / 100;
15730   num_elements = (random_placement_method == RANDOM_USE_PERCENTAGE ?
15731                   num_percentage : random_placement_value);
15732
15733   // if less free positions than elements to place, fill all these positions
15734   if (num_free_positions < num_elements)
15735   {
15736     for (x = 0; x < lev_fieldx; x++)
15737       for (y = 0; y < lev_fieldy; y++)
15738         if (free_position[x][y])
15739           SetElement(x, y, new_element);
15740   }
15741   else
15742   {
15743     while (num_elements > 0)
15744     {
15745       x = GetSimpleRandom(lev_fieldx);
15746       y = GetSimpleRandom(lev_fieldy);
15747
15748       // don't place element at the same position twice
15749       if (free_position[x][y])
15750       {
15751         free_position[x][y] = FALSE;
15752         SetElement(x, y, new_element);
15753         num_elements--;
15754       }
15755     }
15756   }
15757
15758   DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
15759   CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
15760 }
15761
15762 static void WrapLevel(int dx, int dy)
15763 {
15764   int wrap_dx = lev_fieldx - dx;
15765   int wrap_dy = lev_fieldy - dy;
15766   int x, y;
15767
15768   for (x = 0; x < lev_fieldx; x++)
15769     for (y = 0; y < lev_fieldy; y++)
15770       TileBackup[x][y] = Tile[x][y];
15771
15772   for (x = 0; x < lev_fieldx; x++)
15773     for (y = 0; y < lev_fieldy; y++)
15774       Tile[x][y] =
15775         TileBackup[(x + wrap_dx) % lev_fieldx][(y + wrap_dy) % lev_fieldy];
15776
15777   DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
15778   CopyLevelToUndoBuffer(UNDO_ACCUMULATE);
15779 }
15780
15781 static void DrawAreaElementHighlight(boolean highlighted,
15782                                      boolean highlighted_similar)
15783 {
15784   DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
15785
15786   if (!highlighted)
15787     return;
15788
15789   int x, y;
15790
15791   for (x = 0; x < ed_fieldx; x++)
15792   {
15793     for (y = 0; y < ed_fieldy; y++)
15794     {
15795       boolean highlight = FALSE;
15796       int lx = x + level_xpos;
15797       int ly = y + level_ypos;
15798
15799       if (!IN_LEV_FIELD(lx, ly))
15800         continue;
15801
15802       // check if element is the same
15803       if (Tile[lx][ly] == new_element1)
15804         highlight = TRUE;
15805
15806       // check if element is similar
15807       if (highlighted_similar &&
15808           strEqual(element_info[Tile[lx][ly]].class_name,
15809                    element_info[new_element1].class_name))
15810         highlight = TRUE;
15811
15812       // check if element is matching MM style wall
15813       if (IS_MM_WALL(Tile[lx][ly]) &&
15814           map_mm_wall_element(Tile[lx][ly]) == new_element1)
15815         highlight = TRUE;
15816
15817       if (!highlight)
15818         continue;
15819
15820       if (IS_MM_WALL(Tile[lx][ly]) && !highlighted_similar)
15821       {
15822         int i;
15823
15824         for (i = 0; i < 4; i++)
15825         {
15826           if (!(MM_WALL_BITS(Tile[lx][ly]) & (1 << i)))
15827             continue;
15828
15829           int xx = x * 2 + (i % 2);
15830           int yy = y * 2 + (i / 2);
15831           int sx = SX + xx * ed_tilesize / 2;
15832           int sy = SY + yy * ed_tilesize / 2;
15833           int from_sx = sx;
15834           int from_sy = sy;
15835           int to_sx = sx + ed_tilesize / 2 - 1;
15836           int to_sy = sy + ed_tilesize / 2 - 1;
15837
15838           DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx,   from_sy);
15839           DrawSimpleWhiteLine(drawto, to_sx,   from_sy, to_sx,   to_sy);
15840           DrawSimpleWhiteLine(drawto, to_sx,   to_sy,   from_sx, to_sy);
15841           DrawSimpleWhiteLine(drawto, from_sx, to_sy,   from_sx, from_sy);
15842         }
15843       }
15844       else
15845       {
15846         int sx = SX + x * ed_tilesize;
15847         int sy = SY + y * ed_tilesize;
15848         int from_sx = sx;
15849         int from_sy = sy;
15850         int to_sx = sx + ed_tilesize - 1;
15851         int to_sy = sy + ed_tilesize - 1;
15852
15853         DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx,   from_sy);
15854         DrawSimpleWhiteLine(drawto, to_sx,   from_sy, to_sx,   to_sy);
15855         DrawSimpleWhiteLine(drawto, to_sx,   to_sy,   from_sx, to_sy);
15856         DrawSimpleWhiteLine(drawto, from_sx, to_sy,   from_sx, from_sy);
15857       }
15858     }
15859   }
15860 }
15861
15862 static void CopyLevelTemplateToUserLevelSet(char *levelset_subdir)
15863 {
15864   char *template_filename_old = getLocalLevelTemplateFilename();
15865   char *template_filename_new =
15866     getPath2(getUserLevelDir(levelset_subdir), LEVELTEMPLATE_FILENAME);
15867
15868   if (copyFile(template_filename_old, template_filename_new) != 0)
15869     Request("Cannot copy level template!", REQ_CONFIRM);
15870
15871   free(template_filename_new);
15872 }
15873
15874 static void HandleDrawingAreas(struct GadgetInfo *gi)
15875 {
15876   static boolean started_inside_drawing_area = FALSE;
15877   static int last_sx = -1;
15878   static int last_sy = -1;
15879   static int last_sx2 = -1;
15880   static int last_sy2 = -1;
15881   int id = gi->custom_id;
15882   int type_id = gi->custom_type_id;
15883   boolean button_press_event;
15884   boolean button_release_event;
15885   boolean inside_drawing_area = !gi->event.off_borders;
15886   boolean draw_level = (id == GADGET_ID_DRAWING_LEVEL);
15887   int actual_drawing_function;
15888   int button = gi->event.button;
15889   int new_element = BUTTON_ELEMENT(button);
15890   int sx = gi->event.x, sy = gi->event.y;
15891   int min_sx = 0, min_sy = 0;
15892   int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1;
15893   int item_xsize = gi->drawing.item_xsize, item_ysize = gi->drawing.item_ysize;
15894   int mini_item_xsize = item_xsize / 2, mini_item_ysize = item_ysize / 2;
15895   int sx2 = gi->event.mx / mini_item_xsize;
15896   int sy2 = gi->event.my / mini_item_ysize;
15897   int dx = sx2 % 2;
15898   int dy = sy2 % 2;
15899   int lx = 0, ly = 0;
15900   int x, y;
15901
15902   button_press_event = (gi->event.type == GD_EVENT_PRESSED);
15903   button_release_event = (gi->event.type == GD_EVENT_RELEASED);
15904
15905   // make sure to stay inside drawing area boundaries
15906   sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
15907   sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
15908
15909   if (draw_level)
15910   {
15911     int min_lx = 0, min_ly = 0;
15912     int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
15913
15914     // get positions inside level field
15915     lx = sx + level_xpos;
15916     ly = sy + level_ypos;
15917
15918     if (!IN_LEV_FIELD(lx, ly))
15919       inside_drawing_area = FALSE;
15920
15921     // make sure to stay inside level field boundaries
15922     lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
15923     ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
15924
15925     // correct drawing area positions accordingly
15926     sx = lx - level_xpos;
15927     sy = ly - level_ypos;
15928   }
15929
15930   // also correct MM wall-sized (double) drawing area positions accordingly
15931   if (sx2 / 2 < sx || sx2 / 2 > sx)
15932   {
15933     dx = (sx2 / 2 < sx ? 0 : 1);
15934     sx2 = sx * 2 + dx;
15935   }
15936   if (sy2 / 2 < sy || sy2 / 2 > sy)
15937   {
15938     dy = (sy2 / 2 < sy ? 0 : 1);
15939     sy2 = sy * 2 + dy;
15940   }
15941
15942   if (!button_press_event && !button_release_event)
15943   {
15944     int old_element = (IN_LEV_FIELD(lx, ly) ? Tile[lx][ly] : EL_UNDEFINED);
15945     boolean hires_drawing = (level.game_engine_type == GAME_ENGINE_TYPE_MM &&
15946                              isHiresTileElement(old_element) &&
15947                              isHiresDrawElement(new_element));
15948
15949     // prevent handling events for every pixel position when moving mouse
15950     if ((sx == last_sx && sy == last_sy && !hires_drawing) ||
15951         (sx2 == last_sx2 && sy2 == last_sy2))
15952       return;
15953   }
15954
15955   last_sx = sx;
15956   last_sy = sy;
15957   last_sx2 = sx2;
15958   last_sy2 = sy2;
15959
15960   if (button_press_event)
15961     started_inside_drawing_area = inside_drawing_area;
15962
15963   if (!started_inside_drawing_area)
15964     return;
15965
15966   if (!IS_VALID_BUTTON(button))
15967     return;
15968
15969   // handle info callback for each invocation of action callback
15970   gi->callback_info(gi);
15971
15972   // automatically switch to 'single item' drawing mode, if needed
15973   actual_drawing_function =
15974     (draw_level || drawing_function == GADGET_ID_PICK_ELEMENT ?
15975      drawing_function : GADGET_ID_SINGLE_ITEMS);
15976
15977   // clicking into drawing area with pressed Control key picks element
15978   if (GetKeyModState() & KMOD_Control)
15979   {
15980     last_drawing_function = drawing_function;
15981     actual_drawing_function = GADGET_ID_PICK_ELEMENT;
15982   }
15983
15984   if (GetKeyModState() & KMOD_Shift)
15985   {
15986     if (button_press_event || button_release_event)
15987       ResetIntelliDraw();
15988   }
15989
15990   SetDrawModeHiRes(-1);         // reset to normal draw mode
15991
15992   switch (actual_drawing_function)
15993   {
15994     case GADGET_ID_SINGLE_ITEMS:
15995       if (draw_level)
15996       {
15997         if (button_release_event)
15998         {
15999           CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
16000
16001           if (edit_mode == ED_MODE_DRAWING && draw_with_brush &&
16002               !inside_drawing_area)
16003             DeleteBrushFromCursor();
16004
16005           break;
16006         }
16007
16008         if (draw_with_brush)
16009         {
16010           CopyBrushToLevel(sx, sy, button);
16011         }
16012         else
16013         {
16014           SetDrawModeHiRes(new_element);
16015
16016           if (IS_PLAYER_ELEMENT(new_element) || IS_MM_MCDUFFIN(new_element))
16017           {
16018             // remove player at old position
16019             for (y = 0; y < lev_fieldy; y++)
16020             {
16021               for (x = 0; x < lev_fieldx; x++)
16022               {
16023                 int old_element = Tile[x][y];
16024
16025                 if (IS_PLAYER_ELEMENT(old_element) &&
16026                     IS_PLAYER_ELEMENT(new_element))
16027                 {
16028                   int replaced_with_element =
16029                     (old_element == EL_SOKOBAN_FIELD_PLAYER &&
16030                      new_element == EL_PLAYER_1 ? EL_SOKOBAN_FIELD_EMPTY :
16031
16032                      old_element == EL_SOKOBAN_FIELD_PLAYER &&
16033                      new_element == old_element ? EL_SOKOBAN_FIELD_EMPTY :
16034
16035                      new_element == EL_SOKOBAN_FIELD_PLAYER &&
16036                      old_element == EL_PLAYER_1 ? EL_EMPTY :
16037
16038                      new_element >= EL_PLAYER_1 &&
16039                      new_element <= EL_PLAYER_4 &&
16040                      new_element == old_element ? EL_EMPTY :
16041
16042                      old_element);
16043
16044                   SetElement(x, y, replaced_with_element);
16045                 }
16046                 else if (IS_MM_MCDUFFIN(old_element) &&
16047                          IS_MM_MCDUFFIN(new_element))
16048                 {
16049                   // remove McDuffin at old position
16050                   SetElement(x, y, EL_EMPTY);
16051                 }
16052               }
16053             }
16054           }
16055
16056           SetElementButton(lx, ly, dx, dy, new_element, button);
16057         }
16058       }
16059       else if (!button_release_event)
16060       {
16061         int pos = sx * drawingarea_info[type_id].area_ysize + sy;
16062
16063         if (item_xsize == MINI_TILEX && item_ysize == MINI_TILEY)
16064           DrawMiniGraphicExt(drawto,
16065                              gi->x + sx * MINI_TILEX,
16066                              gi->y + sy * MINI_TILEY,
16067                              el2edimg(new_element));
16068         else
16069           DrawFixedGraphicExt(drawto,
16070                               gi->x + sx * TILEX,
16071                               gi->y + sy * TILEY,
16072                               el2edimg(new_element), 0);
16073
16074         if (id == GADGET_ID_CUSTOM_GRAPHIC)
16075           new_element = GFX_ELEMENT(new_element);
16076
16077         drawingarea_info[type_id].value[pos] = new_element;
16078
16079         CopyElementPropertiesToGame(properties_element);
16080
16081         if (id == GADGET_ID_CUSTOM_GRAPHIC)
16082         {
16083           UpdateCustomElementGraphicGadgets();
16084
16085           FrameCounter = 0;     // restart animation frame counter
16086         }
16087       }
16088       break;
16089
16090     case GADGET_ID_CONNECTED_ITEMS:
16091       {
16092         static int last_sx = -1;
16093         static int last_sy = -1;
16094
16095         if (button_release_event)
16096           CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
16097
16098         SetDrawModeHiRes(new_element);
16099
16100         if (getDrawModeHiRes())
16101         {
16102           sx = sx2;
16103           sy = sy2;
16104         }
16105
16106         if (!button_press_event)
16107           DrawLine(last_sx, last_sy, sx, sy, new_element, TRUE);
16108
16109         last_sx = sx;
16110         last_sy = sy;
16111       }
16112       break;
16113
16114     case GADGET_ID_LINE:
16115     case GADGET_ID_ARC:
16116     case GADGET_ID_RECTANGLE:
16117     case GADGET_ID_FILLED_BOX:
16118       SetDrawModeHiRes(new_element);
16119
16120       if (getDrawModeHiRes())
16121       {
16122         sx = sx2;
16123         sy = sy2;
16124       }
16125       // FALLTHROUGH
16126     case GADGET_ID_GRAB_BRUSH:
16127     case GADGET_ID_TEXT:
16128       {
16129         static int last_sx = -1;
16130         static int last_sy = -1;
16131         static int start_sx = -1;
16132         static int start_sy = -1;
16133         void (*draw_func)(int, int, int, int, int, boolean);
16134
16135         if (drawing_function == GADGET_ID_LINE)
16136           draw_func = DrawLine;
16137         else if (drawing_function == GADGET_ID_ARC)
16138           draw_func = DrawArc;
16139         else if (drawing_function == GADGET_ID_RECTANGLE)
16140           draw_func = DrawBox;
16141         else if (drawing_function == GADGET_ID_FILLED_BOX)
16142           draw_func = DrawFilledBox;
16143         else if (drawing_function == GADGET_ID_GRAB_BRUSH)
16144           draw_func = SelectArea;
16145         else // (drawing_function == GADGET_ID_TEXT)
16146           draw_func = SetTextCursor;
16147
16148         if (button_press_event)
16149         {
16150           draw_func(sx, sy, sx, sy, new_element, FALSE);
16151           start_sx = last_sx = sx;
16152           start_sy = last_sy = sy;
16153
16154           if (drawing_function == GADGET_ID_TEXT)
16155             DrawLevelText(0, 0, 0, TEXT_END);
16156         }
16157         else if (button_release_event)
16158         {
16159           draw_func(start_sx, start_sy, sx, sy, new_element, TRUE);
16160           if (drawing_function == GADGET_ID_GRAB_BRUSH)
16161           {
16162             CopyAreaToBrush(start_sx, start_sy, sx, sy, button);
16163             CopyBrushToCursor(sx, sy);
16164             ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
16165                           MB_LEFTBUTTON);
16166             draw_with_brush = TRUE;
16167           }
16168           else if (drawing_function == GADGET_ID_TEXT)
16169             DrawLevelText(sx, sy, 0, TEXT_INIT);
16170           else
16171             CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
16172         }
16173         else if (last_sx != sx || last_sy != sy)
16174         {
16175           draw_func(start_sx, start_sy, last_sx, last_sy, -1, FALSE);
16176           if (IS_MM_WALL_EDITOR(new_element))   // clear wall background
16177             draw_func(start_sx, start_sy, sx, sy, EL_EMPTY, FALSE);
16178           draw_func(start_sx, start_sy, sx, sy, new_element, FALSE);
16179           last_sx = sx;
16180           last_sy = sy;
16181         }
16182       }
16183       break;
16184
16185     case GADGET_ID_FLOOD_FILL:
16186       if (button_press_event && Tile[lx][ly] != new_element)
16187       {
16188         if (IS_MM_WALL_EDITOR(new_element))
16189           FloodFillWall_MM(sx2, sy2, new_element);
16190         else
16191           FloodFill(lx, ly, new_element);
16192
16193         DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16194         CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
16195       }
16196       break;
16197
16198     case GADGET_ID_PICK_ELEMENT:
16199       if (button_release_event)
16200         ClickOnGadget(level_editor_gadget[last_drawing_function],
16201                       MB_LEFTBUTTON);
16202       else if (draw_level)
16203         PickDrawingElement(button, Tile[lx][ly]);
16204       else
16205       {
16206         int pos = sx * drawingarea_info[type_id].area_ysize + sy;
16207
16208         PickDrawingElement(button, drawingarea_info[type_id].value[pos]);
16209       }
16210
16211     default:
16212       break;
16213   }
16214
16215   // do not mark level as modified for certain non-level-changing gadgets
16216   if ((type_id >= ED_DRAWING_ID_EDITOR_FIRST &&
16217        type_id <= ED_DRAWING_ID_EDITOR_LAST) ||
16218       actual_drawing_function == GADGET_ID_GRAB_BRUSH ||
16219       actual_drawing_function == GADGET_ID_PICK_ELEMENT)
16220     return;
16221
16222   level.changed = TRUE;
16223 }
16224
16225 static void HandleCounterButtons(struct GadgetInfo *gi)
16226 {
16227   int gadget_id = gi->custom_id;
16228   int counter_id = gi->custom_type_id;
16229   int button = gi->event.button;
16230   int *counter_value = counterbutton_info[counter_id].value;
16231   int step = BUTTON_STEPSIZE(button) *
16232     (gadget_id == counterbutton_info[counter_id].gadget_id_down ? -1 : +1);
16233
16234   if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
16235   {
16236     boolean pressed = (gi->event.type == GD_EVENT_PRESSED);
16237     boolean released = (gi->event.type == GD_EVENT_RELEASED);
16238     boolean level_changed = LevelChanged();
16239
16240     if ((level_changed && pressed) || (!level_changed && released))
16241       return;
16242
16243     if (level_changed && !Request("Level has changed! Discard changes?",
16244                                   REQ_ASK))
16245     {
16246       if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
16247         ModifyEditorCounterValue(counter_id, *counter_value);
16248
16249       return;
16250     }
16251   }
16252
16253   if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
16254     *counter_value = gi->textinput.number_value;
16255   else
16256     ModifyEditorCounterValue(counter_id, *counter_value + step);
16257
16258   if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
16259   {
16260     int last_game_engine_type = level.game_engine_type;
16261
16262     LoadLevel(level_nr);
16263     LoadScore(level_nr);
16264
16265     SaveLevelSetup_SeriesInfo();
16266
16267     TapeErase();
16268
16269     ResetUndoBuffer();
16270     DrawEditModeWindow();
16271
16272     if (level.game_engine_type != last_game_engine_type)
16273     {
16274       // update element selection list
16275       ReinitializeElementList();
16276       ModifyEditorElementList();
16277     }
16278
16279     return;
16280   }
16281
16282   switch (counter_id)
16283   {
16284     case ED_COUNTER_ID_YAMYAM_CONTENT:
16285       DrawYamYamContentAreas();
16286       break;
16287
16288     case ED_COUNTER_ID_BALL_CONTENT:
16289       DrawMagicBallContentAreas();
16290       break;
16291
16292     case ED_COUNTER_ID_ANDROID_CONTENT:
16293       DrawAndroidElementArea();
16294       break;
16295
16296     case ED_COUNTER_ID_GROUP_CONTENT:
16297       DrawGroupElementArea();
16298       CopyGroupElementPropertiesToGame(properties_element);
16299       break;
16300
16301     case ED_COUNTER_ID_INVENTORY_SIZE:
16302       DrawPlayerInitialInventoryArea(properties_element);
16303       break;
16304
16305     case ED_COUNTER_ID_MM_BALL_CONTENT:
16306       DrawMMBallContentArea();
16307       break;
16308
16309     case ED_COUNTER_ID_ENVELOPE_XSIZE:
16310     case ED_COUNTER_ID_ENVELOPE_YSIZE:
16311       DrawEnvelopeTextArea(-1);
16312       break;
16313
16314     case ED_COUNTER_ID_LEVEL_XSIZE:
16315     case ED_COUNTER_ID_LEVEL_YSIZE:
16316       lev_fieldx = level.fieldx;
16317       lev_fieldy = level.fieldy;
16318
16319       // check if resizing of level results in change of border border
16320       SetBorderElement();
16321
16322       break;
16323
16324     default:
16325       break;
16326   }
16327
16328   if ((counter_id >= ED_COUNTER_ID_CUSTOM_FIRST &&
16329        counter_id <= ED_COUNTER_ID_CUSTOM_LAST) ||
16330       (counter_id >= ED_COUNTER_ID_CHANGE_FIRST &&
16331        counter_id <= ED_COUNTER_ID_CHANGE_LAST))
16332     CopyElementPropertiesToGame(properties_element);
16333
16334   // do not mark level as modified for certain non-level-changing gadgets
16335   if ((counter_id >= ED_COUNTER_ID_LEVELSET_FIRST &&
16336        counter_id <= ED_COUNTER_ID_LEVELSET_LAST) ||
16337       (counter_id >= ED_COUNTER_ID_EDITOR_FIRST &&
16338        counter_id <= ED_COUNTER_ID_EDITOR_LAST))
16339     return;
16340
16341   level.changed = TRUE;
16342 }
16343
16344 static void HandleTextInputGadgets(struct GadgetInfo *gi)
16345 {
16346   int type_id = gi->custom_type_id;
16347
16348   strcpy(textinput_info[type_id].value, gi->textinput.value);
16349
16350   if (type_id == ED_TEXTINPUT_ID_ELEMENT_NAME)
16351   {
16352     CopyElementPropertiesToGame(properties_element);
16353
16354     ModifyEditorElementList();  // update changed button info text
16355   }
16356   else if (type_id >= ED_TEXTINPUT_ID_COLORS_FIRST &&
16357            type_id <= ED_TEXTINPUT_ID_COLORS_LAST)
16358   {
16359     int pos = type_id - ED_TEXTINPUT_ID_COLORS_FIRST;
16360
16361     *bd_color[pos] = gd_color_get_from_string(bd_color_text[pos]);
16362
16363     DrawColorBox_BD(pos);
16364   }
16365
16366   // do not mark level as modified for certain non-level-changing gadgets
16367   if (type_id >= ED_TEXTINPUT_ID_LEVELSET_FIRST &&
16368       type_id <= ED_TEXTINPUT_ID_LEVELSET_LAST)
16369     return;
16370
16371   level.changed = TRUE;
16372 }
16373
16374 static void HandleTextAreaGadgets(struct GadgetInfo *gi)
16375 {
16376   int type_id = gi->custom_type_id;
16377
16378   strncpy(textarea_info[type_id].value, gi->textarea.value,
16379           MAX_ENVELOPE_TEXT_LEN);
16380   textarea_info[type_id].value[MAX_ENVELOPE_TEXT_LEN] = '\0';
16381
16382   level.changed = TRUE;
16383 }
16384
16385 static void HandleSelectboxGadgets(struct GadgetInfo *gi)
16386 {
16387   int type_id = gi->custom_type_id;
16388   int value_old = *selectbox_info[type_id].value;
16389   int value_new = selectbox_info[type_id].options[gi->selectbox.index].value;
16390
16391   *selectbox_info[type_id].value = value_new;
16392
16393   if (type_id == ED_SELECTBOX_ID_LEVELSET_SAVE_MODE)
16394   {
16395     DrawLevelConfigWindow();
16396   }
16397   else if (type_id == ED_SELECTBOX_ID_SELECT_CHANGE_PAGE)
16398   {
16399     element_info[properties_element].current_change_page = gi->selectbox.index;
16400
16401     DrawPropertiesWindow();
16402   }
16403   else if ((type_id >= ED_SELECTBOX_ID_CUSTOM_FIRST &&
16404             type_id <= ED_SELECTBOX_ID_CUSTOM_LAST) ||
16405            (type_id >= ED_SELECTBOX_ID_CHANGE_FIRST &&
16406             type_id <= ED_SELECTBOX_ID_CHANGE_LAST) ||
16407            (type_id == ED_SELECTBOX_ID_GROUP_CHOICE_MODE))
16408   {
16409     if (type_id == ED_SELECTBOX_ID_ACTION_TYPE)
16410     {
16411       // when changing action type, also check action mode and action arg
16412       if (value_old != value_new)
16413         setSelectboxSpecialActionVariablesIfNeeded();
16414
16415       DrawPropertiesChange();
16416     }
16417
16418     CopyElementPropertiesToGame(properties_element);
16419   }
16420   else if (type_id == ED_SELECTBOX_ID_GAME_ENGINE_TYPE)
16421   {
16422     // show or hide "engine" tabulator depending on game engine type
16423     DrawLevelConfigWindow();
16424
16425     // update element selection list depending on game engine type
16426     ReinitializeElementList();
16427     ModifyEditorElementList();
16428   }
16429   else if (type_id == ED_SELECTBOX_ID_BD_SCHEDULING_TYPE)
16430   {
16431     // update BD cycle delay counter gadgets depending on BD scheduling type
16432     DrawLevelConfigWindow();
16433   }
16434   else if (type_id == ED_SELECTBOX_ID_BD_COLOR_TYPE)
16435   {
16436     bd_color_type_changed = TRUE;
16437
16438     if (level.bd_color_type != GD_COLOR_TYPE_RGB && level.bd_color_type != GetCommonColorType_BD())
16439     {
16440       // color type switched to non-RGB colors, but using different color type => reset colors
16441       char *message = (level.bd_color_type == bd_color_type_default ?
16442                        "This will reset colors to defaults! Continue?" :
16443                        "This will reset colors to random colors! Continue?");
16444
16445       if (!Request(message, REQ_ASK))
16446       {
16447         // keep current RGB colors
16448         level.bd_color_type = GD_COLOR_TYPE_RGB;
16449         bd_color_type_changed = FALSE;
16450       }
16451     }
16452
16453     // update BD color palette gadgets depending on BD color type
16454     DrawLevelConfigWindow();
16455   }
16456   else if (type_id >= ED_SELECTBOX_ID_COLORS_FIRST &&
16457            type_id <= ED_SELECTBOX_ID_COLORS_LAST)
16458   {
16459     int pos = type_id - ED_SELECTBOX_ID_COLORS_FIRST;
16460
16461     *bd_color[pos] = gd_c64_color(bd_color_c64[pos]);
16462
16463     DrawColorBox_BD(pos);
16464   }
16465
16466   // do not mark level as modified for certain non-level-changing gadgets
16467   if (type_id == ED_SELECTBOX_ID_LEVELSET_SAVE_MODE ||
16468       type_id == ED_SELECTBOX_ID_SELECT_CHANGE_PAGE)
16469     return;
16470
16471   level.changed = TRUE;
16472 }
16473
16474 static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
16475 {
16476   int type_id = gi->custom_type_id;
16477   int i;
16478
16479   if (type_id >= ED_TAB_BUTTON_ID_LEVELCONFIG_FIRST &&
16480       type_id <= ED_TAB_BUTTON_ID_LEVELCONFIG_LAST)
16481   {
16482     edit_mode_levelconfig = gi->custom_type_id;
16483
16484     DrawLevelConfigWindow();
16485   }
16486   else if (type_id >= ED_TAB_BUTTON_ID_ENGINECONFIG_FIRST &&
16487            type_id <= ED_TAB_BUTTON_ID_ENGINECONFIG_LAST)
16488   {
16489     edit_mode_engineconfig = gi->custom_type_id;
16490
16491     DrawLevelConfigWindow();
16492   }
16493   else if (type_id >= ED_TAB_BUTTON_ID_PROPERTIES_FIRST &&
16494            type_id <= ED_TAB_BUTTON_ID_PROPERTIES_LAST)
16495   {
16496     edit_mode_properties = gi->custom_type_id;
16497
16498     DrawPropertiesWindow();
16499   }
16500   else if (type_id == ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1 ||
16501            type_id == ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_2)
16502   {
16503     boolean new_template = !fileExists(getLocalLevelTemplateFilename());
16504
16505     // backup original "level.field" (needed to track playfield changes)
16506     CopyPlayfield(level.field, TileBackup);
16507
16508     // "SaveLevelTemplate()" uses "level.field", so copy editor playfield
16509     CopyPlayfield(Tile, level.field);
16510
16511     if (new_template ||
16512         Request("Save this template and kill the old?", REQ_ASK))
16513       SaveLevelTemplate();
16514
16515     if (new_template)
16516       Request("Template saved!", REQ_CONFIRM);
16517
16518     // restore original "level.field" (needed to track playfield changes)
16519     CopyPlayfield(TileBackup, level.field);
16520   }
16521   else if (type_id == ED_TEXTBUTTON_ID_SAVE_LEVELSET)
16522   {
16523     char *levelset_subdir = getLevelSubdirFromSaveMode(levelset_save_mode);
16524
16525     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE &&
16526         leveldir_current->readonly)
16527     {
16528       Request("This level set is read-only!", REQ_CONFIRM);
16529
16530       return;
16531     }
16532
16533     if (strEqual(levelset_name, ""))
16534     {
16535       Request("Please enter level set title!", REQ_CONFIRM);
16536
16537       return;
16538     }
16539
16540     if (strEqual(levelset_author, ""))
16541     {
16542       Request("Please enter level set author!", REQ_CONFIRM);
16543
16544       return;
16545     }
16546
16547     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE)
16548     {
16549       if (UpdateUserLevelSet(levelset_subdir,
16550                              levelset_name,
16551                              levelset_author,
16552                              levelset_num_levels))
16553       {
16554         Request("Level set updated!", REQ_CONFIRM);
16555       }
16556       else
16557       {
16558         Request("Updating level set failed!", REQ_CONFIRM);
16559       }
16560     }
16561     else if (levelset_save_mode == LEVELSET_SAVE_MODE_CREATE)
16562     {
16563       if (level.changed && !Request("Level has changed! Discard changes?",
16564                                      REQ_ASK))
16565         return;
16566
16567       if (CreateUserLevelSet(levelset_subdir,
16568                              levelset_name,
16569                              levelset_author,
16570                              levelset_num_levels,
16571                              levelset_use_levelset_artwork))
16572       {
16573         if (levelset_copy_level_template)
16574           CopyLevelTemplateToUserLevelSet(levelset_subdir);
16575
16576         Request("New level set created!", REQ_CONFIRM);
16577
16578         AddUserLevelSetToLevelInfo(levelset_subdir);
16579         ChangeEditorToLevelSet(levelset_subdir);
16580       }
16581       else
16582       {
16583         Request("Creating new level set failed!", REQ_CONFIRM);
16584       }
16585     }
16586   }
16587   else if (type_id == ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE &&
16588            custom_element.num_change_pages < MAX_CHANGE_PAGES)
16589   {
16590     struct ElementInfo *ei = &element_info[properties_element];
16591
16592     // when modifying custom element, ask for copying level template
16593     if (level.use_custom_template && !AskToCopyAndModifyLevelTemplate())
16594       return;
16595
16596     setElementChangePages(ei, ei->num_change_pages + 1);
16597
16598     // set new change page to be new current change page
16599     ei->current_change_page = ei->num_change_pages - 1;
16600     ei->change = &ei->change_page[ei->current_change_page];
16601
16602     setElementChangeInfoToDefaults(ei->change);
16603
16604     DrawPropertiesWindow();
16605
16606     level.changed = TRUE;
16607   }
16608   else if (type_id == ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE &&
16609            custom_element.num_change_pages > MIN_CHANGE_PAGES)
16610   {
16611     struct ElementInfo *ei = &element_info[properties_element];
16612
16613     // when modifying custom element, ask for copying level template
16614     if (level.use_custom_template && !AskToCopyAndModifyLevelTemplate())
16615       return;
16616
16617     // copy all change pages after change page to be deleted
16618     for (i = ei->current_change_page; i < ei->num_change_pages - 1; i++)
16619       ei->change_page[i] = ei->change_page[i + 1];
16620
16621     setElementChangePages(ei, ei->num_change_pages - 1);
16622
16623     DrawPropertiesWindow();
16624
16625     level.changed = TRUE;
16626   }
16627   else if (type_id == ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS)
16628   {
16629     SetRandomLevelColors_BD(level.bd_color_type);
16630
16631     // update BD color palette gadgets after setting random colors
16632     DrawLevelConfigWindow();
16633   }
16634 }
16635
16636 static void HandleGraphicbuttonGadgets(struct GadgetInfo *gi)
16637 {
16638   int type_id = gi->custom_type_id;
16639
16640   if (type_id == ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE ||
16641       type_id == ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE)
16642   {
16643     struct ElementInfo *ei = &element_info[properties_element];
16644     int step = BUTTON_STEPSIZE(gi->event.button);
16645
16646     step *= (type_id == ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE ? -1 : +1);
16647     ei->current_change_page += step;
16648
16649     if (ei->current_change_page < 0)
16650       ei->current_change_page = 0;
16651     else if (ei->current_change_page >= ei->num_change_pages)
16652       ei->current_change_page = ei->num_change_pages - 1;
16653
16654     DrawPropertiesWindow();
16655   }
16656   else if (type_id == ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE ||
16657            type_id == ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE)
16658   {
16659     struct ElementInfo *ei = &element_info[properties_element];
16660     int current_change_page = ei->current_change_page;
16661
16662     if (type_id == ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE)
16663     {
16664       element_info[EL_INTERNAL_CLIPBOARD_CHANGE].change_page[0] =
16665         ei->change_page[current_change_page];
16666     }
16667     else if (type_id == ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE)
16668     {
16669       // when modifying custom element, ask for copying level template
16670       if (level.use_custom_template && !AskToCopyAndModifyLevelTemplate())
16671         return;
16672
16673       ei->change_page[current_change_page] =
16674         element_info[EL_INTERNAL_CLIPBOARD_CHANGE].change_page[0];
16675
16676       level.changed = TRUE;
16677     }
16678
16679     DrawPropertiesWindow();
16680   }
16681 }
16682
16683 static void HandleRadiobuttons(struct GadgetInfo *gi)
16684 {
16685   int type_id = gi->custom_type_id;
16686
16687   *radiobutton_info[type_id].value =
16688     radiobutton_info[type_id].checked_value;
16689
16690   // do not mark level as modified for certain non-level-changing gadgets
16691   if (type_id >= ED_RADIOBUTTON_ID_EDITOR_FIRST &&
16692       type_id <= ED_RADIOBUTTON_ID_EDITOR_LAST)
16693     return;
16694
16695   level.changed = TRUE;
16696 }
16697
16698 static void HandleCheckbuttons(struct GadgetInfo *gi)
16699 {
16700   int type_id = gi->custom_type_id;
16701
16702   *checkbutton_info[type_id].value ^= TRUE;
16703
16704   if (type_id == ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID ||
16705       type_id == ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID ||
16706       type_id == ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH ||
16707       (((type_id >= ED_CHECKBUTTON_ID_CUSTOM_FIRST &&
16708          type_id <= ED_CHECKBUTTON_ID_CUSTOM_LAST) ||
16709         (type_id >= ED_CHECKBUTTON_ID_CHANGE_FIRST &&
16710          type_id <= ED_CHECKBUTTON_ID_CHANGE_LAST)) &&
16711        type_id != ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1))
16712   {
16713     CopyElementPropertiesToGame(properties_element);
16714   }
16715
16716   if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC)
16717   {
16718     UpdateCustomElementGraphicGadgets();
16719   }
16720   else if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1 ||
16721            type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_2)
16722   {
16723     boolean template_related_changes_found = FALSE;
16724     int i;
16725
16726     // check if any custom, group or empty elements have been changed
16727     for (i = 0; i < NUM_FILE_ELEMENTS; i++)
16728       if ((IS_CUSTOM_ELEMENT(i) ||
16729            IS_GROUP_ELEMENT(i) ||
16730            IS_EMPTY_ELEMENT(i)) &&
16731           element_info[i].modified_settings)
16732         template_related_changes_found = TRUE;
16733
16734     if (level.use_custom_template &&
16735         !fileExists(getGlobalLevelTemplateFilename()))
16736     {
16737       Request("No level template found!", REQ_CONFIRM);
16738
16739       level.use_custom_template = FALSE;
16740
16741       ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
16742
16743       return;
16744     }
16745
16746     if (level.use_custom_template &&
16747         template_related_changes_found &&
16748         !Request("Discard changes and use level template?", REQ_ASK))
16749     {
16750       level.use_custom_template = FALSE;
16751
16752       ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
16753
16754       return;
16755     }
16756
16757     if (!level.use_custom_template &&
16758         Request("Copy settings from level template?", REQ_ASK))
16759     {
16760       return;
16761     }
16762
16763     LoadLevelTemplate(level.use_custom_template ? -1 : level_nr);
16764
16765     DrawEditModeWindow();
16766   }
16767   else if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_3)
16768   {
16769     if (setup.editor.use_template_for_new_levels &&
16770         !fileExists(getGlobalLevelTemplateFilename()))
16771     {
16772       Request("No level template found!", REQ_CONFIRM);
16773
16774       return;
16775     }
16776
16777     if (setup.editor.use_template_for_new_levels &&
16778         level.changed &&
16779         !Request("Discard level and load template?", REQ_ASK))
16780     {
16781       return;
16782     }
16783
16784     if (!setup.editor.use_template_for_new_levels &&
16785         level.changed &&
16786         !Request("Discard level and use empty level?", REQ_ASK))
16787     {
16788       return;
16789     }
16790
16791     LoadLevel(level_nr);
16792     LoadScore(level_nr);
16793
16794     TapeErase();
16795
16796     ResetUndoBuffer();
16797     DrawEditModeWindow();
16798   }
16799   else if (type_id == ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS)
16800   {
16801     SetAutomaticNumberOfGemsNeeded();
16802   }
16803
16804   // do not mark level as modified for certain non-level-changing gadgets
16805   if ((type_id >= ED_CHECKBUTTON_ID_LEVELSET_FIRST &&
16806        type_id <= ED_CHECKBUTTON_ID_LEVELSET_LAST) ||
16807       (type_id >= ED_CHECKBUTTON_ID_EDITOR_FIRST &&
16808        type_id <= ED_CHECKBUTTON_ID_EDITOR_LAST &&
16809        type_id != ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_2) ||
16810       type_id == ED_CHECKBUTTON_ID_STICK_ELEMENT)
16811     return;
16812
16813   level.changed = TRUE;
16814 }
16815
16816 static void HandleControlButtons(struct GadgetInfo *gi)
16817 {
16818   static int last_level_drawing_function = GADGET_ID_SINGLE_ITEMS;
16819   static int last_edit_mode = ED_MODE_DRAWING;
16820   static int last_custom_copy_mode = -1;
16821   static int last_button = 0;
16822   int id = gi->custom_id;
16823   int button = gi->event.button;
16824   int step = BUTTON_STEPSIZE(button);
16825   int new_element = BUTTON_ELEMENT(button);
16826   int last_properties_element = properties_element;
16827   int x, y;
16828
16829   if (edit_mode == ED_MODE_DRAWING && drawing_function == GADGET_ID_TEXT)
16830     DrawLevelText(0, 0, 0, TEXT_END);
16831
16832   if (id < ED_NUM_CTRL1_BUTTONS &&
16833       id != GADGET_ID_SINGLE_ITEMS &&
16834       id != GADGET_ID_PICK_ELEMENT &&
16835       edit_mode != ED_MODE_DRAWING &&
16836       drawing_function != GADGET_ID_PICK_ELEMENT &&
16837       !(GetKeyModState() & KMOD_Control))
16838     ChangeEditModeWindow(ED_MODE_DRAWING);
16839
16840   // element copy mode active, but no element button pressed => deactivate
16841   if (last_custom_copy_mode != -1 && id < ED_NUM_CTRL_BUTTONS)
16842     last_custom_copy_mode = -1;
16843
16844   // when showing palette on element buttons, change element of button used
16845   if (editor.palette.show_on_element_buttons &&
16846       id >= GADGET_ID_ELEMENT_LEFT && id <= GADGET_ID_ELEMENT_RIGHT)
16847   {
16848     last_button = id - GADGET_ID_ELEMENT_LEFT + 1;
16849
16850     id = GADGET_ID_PALETTE;
16851   }
16852
16853   switch (id)
16854   {
16855     case GADGET_ID_SCROLL_LEFT:
16856       if (level_xpos >= 0)
16857       {
16858         if (lev_fieldx < ed_fieldx - 2)
16859           break;
16860
16861         level_xpos -= step;
16862         if (level_xpos < -1)
16863           level_xpos = -1;
16864         if (button == 1)
16865           ScrollEditorLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT);
16866         else
16867           DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16868
16869         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
16870                      GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
16871       }
16872       break;
16873
16874     case GADGET_ID_SCROLL_RIGHT:
16875       if (level_xpos <= lev_fieldx - ed_fieldx)
16876       {
16877         if (lev_fieldx < ed_fieldx - 2)
16878           break;
16879
16880         level_xpos += step;
16881         if (level_xpos > lev_fieldx - ed_fieldx + 1)
16882           level_xpos = lev_fieldx - ed_fieldx + 1;
16883         if (button == 1)
16884           ScrollEditorLevel(level_xpos, level_ypos, ED_SCROLL_LEFT);
16885         else
16886           DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16887
16888         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
16889                      GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
16890       }
16891       break;
16892
16893     case GADGET_ID_SCROLL_UP:
16894       if (level_ypos >= 0)
16895       {
16896         if (lev_fieldy < ed_fieldy - 2)
16897           break;
16898
16899         level_ypos -= step;
16900         if (level_ypos < -1)
16901           level_ypos = -1;
16902         if (button == 1)
16903           ScrollEditorLevel(level_xpos, level_ypos, ED_SCROLL_DOWN);
16904         else
16905           DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16906
16907         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
16908                      GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
16909       }
16910       break;
16911
16912     case GADGET_ID_SCROLL_DOWN:
16913       if (level_ypos <= lev_fieldy - ed_fieldy)
16914       {
16915         if (lev_fieldy < ed_fieldy - 2)
16916           break;
16917
16918         level_ypos += step;
16919         if (level_ypos > lev_fieldy - ed_fieldy + 1)
16920           level_ypos = lev_fieldy - ed_fieldy + 1;
16921         if (button == 1)
16922           ScrollEditorLevel(level_xpos, level_ypos, ED_SCROLL_UP);
16923         else
16924           DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16925
16926         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
16927                      GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
16928       }
16929       break;
16930
16931     case GADGET_ID_SCROLL_HORIZONTAL:
16932       level_xpos = gi->event.item_position - 1;
16933
16934       DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16935       BackToFront();
16936
16937       break;
16938
16939     case GADGET_ID_SCROLL_VERTICAL:
16940       level_ypos = gi->event.item_position - 1;
16941
16942       DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16943       BackToFront();
16944
16945       break;
16946
16947     case GADGET_ID_SCROLL_LIST_UP:
16948     case GADGET_ID_SCROLL_LIST_DOWN:
16949     case GADGET_ID_SCROLL_LIST_VERTICAL:
16950       if (id == GADGET_ID_SCROLL_LIST_VERTICAL)
16951         element_shift = gi->event.item_position * ED_ELEMENTLIST_BUTTONS_HORIZ;
16952       else
16953       {
16954         step *= (id == GADGET_ID_SCROLL_LIST_UP ? -1 : +1);
16955         element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ;
16956
16957         if (element_shift < 0)
16958           element_shift = 0;
16959         if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
16960           element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
16961
16962         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
16963                      GDI_SCROLLBAR_ITEM_POSITION,
16964                      element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
16965       }
16966
16967       ModifyEditorElementList();
16968
16969       break;
16970
16971     case GADGET_ID_PROPERTIES:
16972       // always switch off element properties when they are already displayed
16973       last_properties_element = new_element;
16974     case GADGET_ID_ELEMENT_LEFT:
16975     case GADGET_ID_ELEMENT_MIDDLE:
16976     case GADGET_ID_ELEMENT_RIGHT:
16977       properties_element = (id == GADGET_ID_ELEMENT_LEFT   ? new_element1 :
16978                             id == GADGET_ID_ELEMENT_MIDDLE ? new_element2 :
16979                             id == GADGET_ID_ELEMENT_RIGHT  ? new_element3 :
16980                             new_element);
16981
16982       if (edit_mode != ED_MODE_PROPERTIES)
16983       {
16984         last_edit_mode = edit_mode;
16985
16986         ChangeEditModeWindow(ED_MODE_PROPERTIES);
16987
16988         last_level_drawing_function = drawing_function;
16989         ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
16990                       MB_LEFTBUTTON);
16991       }
16992       else if (properties_element != last_properties_element)
16993       {
16994         DrawEditModeWindow();
16995       }
16996       else
16997       {
16998         ChangeEditModeWindow(ED_MODE_DRAWING);
16999
17000         ClickOnGadget(level_editor_gadget[last_level_drawing_function],
17001                       MB_LEFTBUTTON);
17002       }
17003       break;
17004
17005     case GADGET_ID_PALETTE:
17006       if (edit_mode != ED_MODE_PALETTE)
17007       {
17008         last_edit_mode = edit_mode;
17009
17010         ChangeEditModeWindow(ED_MODE_PALETTE);
17011       }
17012       else
17013       {
17014         ChangeEditModeWindow(last_edit_mode);
17015       }
17016       break;
17017
17018     case GADGET_ID_WRAP_LEFT:
17019       WrapLevel(-step, 0);
17020       break;
17021
17022     case GADGET_ID_WRAP_RIGHT:
17023       WrapLevel(step, 0);
17024       break;
17025
17026     case GADGET_ID_WRAP_UP:
17027       WrapLevel(0, -step);
17028       break;
17029
17030     case GADGET_ID_WRAP_DOWN:
17031       WrapLevel(0, step);
17032       break;
17033
17034     case GADGET_ID_SINGLE_ITEMS:
17035     case GADGET_ID_CONNECTED_ITEMS:
17036     case GADGET_ID_LINE:
17037     case GADGET_ID_ARC:
17038     case GADGET_ID_TEXT:
17039     case GADGET_ID_RECTANGLE:
17040     case GADGET_ID_FILLED_BOX:
17041     case GADGET_ID_FLOOD_FILL:
17042     case GADGET_ID_GRAB_BRUSH:
17043     case GADGET_ID_PICK_ELEMENT:
17044       if (drawing_function != GADGET_ID_PICK_ELEMENT)
17045         last_drawing_function = drawing_function;
17046       drawing_function = id;
17047       draw_with_brush = FALSE;
17048       break;
17049
17050     case GADGET_ID_RANDOM_PLACEMENT:
17051       RandomPlacement(new_element);
17052       break;
17053
17054     case GADGET_ID_ZOOM:
17055       // zoom level editor tile size in or out (or reset to default size)
17056       ed_tilesize = (button == 1 ? ed_tilesize * 2 :
17057                      button == 2 ? ed_tilesize_default :
17058                      button == 3 ? ed_tilesize / 2 : ed_tilesize);
17059
17060       // when using touch device, cycle through all zoom tilesizes
17061       if (runtime.uses_touch_device && ed_tilesize > TILESIZE)
17062         ed_tilesize = MICRO_TILESIZE;
17063
17064       // limit zoom level by upper and lower bound
17065       ed_tilesize = MIN(MAX(MICRO_TILESIZE, ed_tilesize), TILESIZE);
17066
17067       InitZoomLevelSettings(ed_tilesize);
17068
17069       if (edit_mode == ED_MODE_DRAWING)
17070       {
17071         DrawDrawingWindow();
17072
17073         // redraw zoom gadget info text
17074         PrintEditorGadgetInfoText(level_editor_gadget[id]);
17075       }
17076
17077       // save current editor zoom tilesize
17078       SaveSetup_AutoSetup();
17079
17080       break;
17081
17082     case GADGET_ID_CUSTOM_COPY_FROM:
17083     case GADGET_ID_CUSTOM_COPY_TO:
17084     case GADGET_ID_CUSTOM_EXCHANGE:
17085       last_custom_copy_mode = id;
17086       last_drawing_function = drawing_function;
17087       break;
17088
17089     case GADGET_ID_CUSTOM_COPY:
17090       CopyCustomElement(properties_element, -1, id);
17091       break;
17092
17093     case GADGET_ID_CUSTOM_PASTE:
17094       CopyCustomElement(-1, properties_element, id);
17095       break;
17096
17097     case GADGET_ID_UNDO:
17098       if (button < 0)   // keep button value (even if modifier keys are pressed)
17099         button = -button;
17100       else if (button == 1 && GetKeyModState() & (KMOD_Shift | KMOD_Control))
17101         button = 3;
17102
17103       if (button == 1 && undo_buffer_steps == 0)
17104       {
17105         Request("Undo buffer empty!", REQ_CONFIRM);
17106
17107         break;
17108       }
17109       else if (button == 2)
17110       {
17111         break;
17112       }
17113       else if (button == 3 && redo_buffer_steps == 0)
17114       {
17115         Request("Redo buffer empty!", REQ_CONFIRM);
17116
17117         break;
17118       }
17119
17120       if (edit_mode != ED_MODE_DRAWING)
17121         ChangeEditModeWindow(ED_MODE_DRAWING);
17122
17123       if (button == 1)
17124       {
17125         // undo
17126
17127         undo_buffer_position =
17128           (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS;
17129
17130         undo_buffer_steps--;
17131         redo_buffer_steps++;
17132       }
17133       else
17134       {
17135         // redo
17136
17137         undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS;
17138
17139         undo_buffer_steps++;
17140         redo_buffer_steps--;
17141       }
17142
17143       for (x = 0; x < lev_fieldx; x++)
17144         for (y = 0; y < lev_fieldy; y++)
17145           Tile[x][y] = UndoBuffer[undo_buffer_position][x][y];
17146
17147       // check if undo operation forces change of border style
17148       CheckLevelBorderElement(FALSE);
17149
17150       DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
17151
17152       break;
17153
17154     case GADGET_ID_CONF:
17155       if (edit_mode != ED_MODE_LEVELCONFIG)
17156       {
17157         last_edit_mode = edit_mode;
17158
17159         ChangeEditModeWindow(ED_MODE_LEVELCONFIG);
17160       }
17161       else
17162       {
17163         ChangeEditModeWindow(ED_MODE_DRAWING);
17164       }
17165       break;
17166
17167     case GADGET_ID_CLEAR:
17168       if (edit_mode != ED_MODE_DRAWING)
17169         ChangeEditModeWindow(ED_MODE_DRAWING);
17170
17171       for (x = 0; x < MAX_LEV_FIELDX; x++)
17172         for (y = 0; y < MAX_LEV_FIELDY; y++)
17173           Tile[x][y] = (button == 1 ? EL_EMPTY : new_element);
17174
17175       CopyLevelToUndoBuffer(GADGET_ID_CLEAR);
17176
17177       DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
17178       break;
17179
17180     case GADGET_ID_SAVE:
17181     {
17182       // saving read-only levels into personal level set modifies global vars
17183       // "leveldir_current" and "level_nr"; restore them after saving level
17184       LevelDirTree *leveldir_former = leveldir_current;
17185       int level_nr_former = level_nr;
17186       char *level_filename;
17187       boolean new_level;
17188
17189       if (leveldir_current->readonly &&
17190           !PrepareSavingIntoPersonalLevelSet())
17191         break;
17192
17193       level_filename = getDefaultLevelFilename(level_nr);
17194       new_level = !fileExists(level_filename);
17195
17196       if (new_level ||
17197           Request("Save this level and kill the old?", REQ_ASK))
17198       {
17199         if (leveldir_former->readonly)
17200           ModifyLevelConfigForSavingIntoPersonalLevelSet(leveldir_former->name);
17201
17202         SetAutomaticNumberOfGemsNeeded();
17203
17204         CopyPlayfield(Tile, level.field);
17205         SaveLevel(level_nr);
17206
17207         level.changed = FALSE;
17208
17209         if (new_level)
17210         {
17211           char level_saved_msg[64];
17212
17213           if (leveldir_former->readonly)
17214             sprintf(level_saved_msg,
17215                     "Level saved as level %d into personal level set!",
17216                     level_nr);
17217           else
17218             strcpy(level_saved_msg, "Level saved!");
17219
17220           Request(level_saved_msg, REQ_CONFIRM);
17221         }
17222       }
17223
17224       // "cd" back to copied-from levelset (in case of saved read-only level)
17225       leveldir_current = leveldir_former;
17226       level_nr = level_nr_former;
17227
17228       break;
17229     }
17230
17231     case GADGET_ID_TEST:
17232       if (LevelChanged())
17233         level.game_version = GAME_VERSION_ACTUAL;
17234
17235       CopyPlayfield(level.field, TileBackup);
17236       CopyPlayfield(Tile, level.field);
17237
17238       CopyNativeLevel_RND_to_Native(&level);
17239
17240       UnmapLevelEditorGadgets();
17241       UndrawSpecialEditorDoor();
17242
17243       CloseDoor(DOOR_CLOSE_ALL);
17244
17245       // needed before playing if editor playfield area has different size
17246       ClearRectangle(drawto, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
17247
17248       // redraw_mask = REDRAW_ALL;
17249
17250       level_editor_test_game = TRUE;
17251
17252       StartGameActions(FALSE, setup.autorecord, level.random_seed);
17253
17254       break;
17255
17256     case GADGET_ID_EXIT:
17257       RequestExitLevelEditor(TRUE, FALSE);  // if level has changed, ask user
17258       break;
17259
17260     default:
17261       if (id >= GADGET_ID_ELEMENTLIST_FIRST &&
17262           id <= GADGET_ID_ELEMENTLIST_LAST)
17263       {
17264         int element_position = id - GADGET_ID_ELEMENTLIST_FIRST;
17265
17266         new_element = editor_elements[element_position + element_shift];
17267
17268         if (IS_EDITOR_CASCADE(new_element))
17269         {
17270           int i;
17271
17272           for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
17273           {
17274             int *cascade_element = &(*editor_elements_info[i].headline_list)[0];
17275             boolean *cascade_value = editor_elements_info[i].setup_cascade_value;
17276
17277             if (*cascade_element == new_element)
17278             {
17279               *cascade_element = EL_CASCADE_TOGGLE(*cascade_element);
17280               *cascade_value = IS_EDITOR_CASCADE_ACTIVE(*cascade_element);
17281
17282               // update element selection list
17283               ReinitializeElementList();
17284               ModifyEditorElementList();
17285
17286               // update cascading gadget info text
17287               PrintEditorGadgetInfoText(level_editor_gadget[id]);
17288
17289               // save current editor cascading state
17290               SaveSetup_EditorCascade();
17291
17292               break;
17293             }
17294           }
17295
17296           break;
17297         }
17298
17299         if (last_custom_copy_mode != -1)
17300         {
17301           if (CopyCustomElement(properties_element, new_element,
17302                                 last_custom_copy_mode))
17303           {
17304             ClickOnGadget(level_editor_gadget[last_drawing_function],
17305                           MB_LEFTBUTTON);
17306
17307             last_custom_copy_mode = -1;
17308           }
17309
17310           break;
17311         }
17312
17313         // change element of button used to show palette
17314         if (editor.palette.show_on_element_buttons)
17315           button = last_button;
17316
17317         PickDrawingElement(button, new_element);
17318
17319         if (!stick_element_properties_window &&
17320             drawing_function != GADGET_ID_PICK_ELEMENT &&
17321             !(GetKeyModState() & KMOD_Control))
17322         {
17323           properties_element = new_element;
17324           if (edit_mode == ED_MODE_PROPERTIES)
17325             DrawPropertiesWindow();
17326         }
17327
17328         if (drawing_function == GADGET_ID_PICK_ELEMENT)
17329           ClickOnGadget(level_editor_gadget[last_drawing_function],
17330                         MB_LEFTBUTTON);
17331
17332         if (!use_permanent_palette)
17333           ChangeEditModeWindow(last_edit_mode);
17334       }
17335 #ifdef DEBUG
17336       else if (gi->event.type == GD_EVENT_PRESSED)
17337         Debug("editor", "default: HandleControlButtons: GD_EVENT_PRESSED(%d)", id);
17338       else if (gi->event.type == GD_EVENT_RELEASED)
17339         Debug("editor", "default: HandleControlButtons: GD_EVENT_RELEASED(%d)", id);
17340       else if (gi->event.type == GD_EVENT_MOVING)
17341         Debug("editor", "default: HandleControlButtons: GD_EVENT_MOVING(%d)", id);
17342       else
17343         Debug("editor", "default: HandleControlButtons: ? (id == %d)", id);
17344 #endif
17345       break;
17346   }
17347 }
17348
17349 void HandleLevelEditorKeyInput(Key key)
17350 {
17351   char letter = getCharFromKey(key);
17352
17353   if (drawing_function == GADGET_ID_TEXT &&
17354       DrawLevelText(0, 0, 0, TEXT_QUERY_TYPING) == TRUE)
17355   {
17356     if (letter)
17357       DrawLevelText(0, 0, letter, TEXT_WRITECHAR);
17358     else if (key == KSYM_Delete || key == KSYM_BackSpace)
17359       DrawLevelText(0, 0, 0, TEXT_BACKSPACE);
17360     else if (key == KSYM_Return)
17361       DrawLevelText(0, 0, 0, TEXT_NEWLINE);
17362     else if (key == KSYM_Escape)
17363       DrawLevelText(0, 0, 0, TEXT_END);
17364
17365     return;
17366   }
17367
17368   int id = GADGET_ID_NONE;
17369   int new_element_shift = element_shift;
17370   int step = ED_ELEMENTLIST_BUTTONS_VERT - 1;
17371   int button = MB_LEFTBUTTON;
17372   int i;
17373
17374   switch (key)
17375   {
17376     case KSYM_Left:
17377       id = GADGET_ID_SCROLL_LEFT;
17378       break;
17379     case KSYM_Right:
17380       id = GADGET_ID_SCROLL_RIGHT;
17381       break;
17382     case KSYM_Up:
17383       id = GADGET_ID_SCROLL_UP;
17384       break;
17385     case KSYM_Down:
17386       id = GADGET_ID_SCROLL_DOWN;
17387       break;
17388
17389     case KSYM_Page_Up:
17390     case KSYM_Page_Down:
17391       step *= (key == KSYM_Page_Up ? -1 : +1);
17392       element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ;
17393
17394       if (element_shift < 0)
17395         element_shift = 0;
17396       if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
17397         element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
17398
17399       ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
17400                    GDI_SCROLLBAR_ITEM_POSITION,
17401                    element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
17402
17403       ModifyEditorElementList();
17404
17405       break;
17406
17407     case KSYM_Home:
17408     case KSYM_End:
17409       element_shift = (key == KSYM_Home ? 0 :
17410                        num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS);
17411
17412       ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
17413                    GDI_SCROLLBAR_ITEM_POSITION,
17414                    element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
17415
17416       ModifyEditorElementList();
17417
17418       break;
17419
17420     case KSYM_Insert:
17421     case KSYM_Delete:
17422
17423       // this is needed to prevent interference with running "True X-Mouse"
17424       if (GetKeyModStateFromEvents() & KMOD_Control)
17425         break;
17426
17427       // check for last or next editor cascade block in element list
17428       for (i = 0; i < num_editor_elements; i++)
17429       {
17430         if ((key == KSYM_Insert && i == element_shift) ||
17431             (key == KSYM_Delete && new_element_shift > element_shift))
17432           break;
17433
17434         // jump to next cascade block (or to start of element list)
17435         if (i == 0 || IS_EDITOR_CASCADE(editor_elements[i]))
17436           new_element_shift = i;
17437       }
17438
17439       if (i < num_editor_elements)
17440         element_shift = new_element_shift;
17441
17442       if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
17443         element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
17444
17445       ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
17446                    GDI_SCROLLBAR_ITEM_POSITION,
17447                    element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
17448
17449       ModifyEditorElementList();
17450
17451       break;
17452
17453     case KSYM_Escape:
17454       if (edit_mode == ED_MODE_DRAWING)
17455         RequestExitLevelEditor(setup.ask_on_escape_editor, TRUE);
17456       else if (edit_mode == ED_MODE_LEVELCONFIG)
17457         HandleControlButtons(level_editor_gadget[GADGET_ID_CONF]);
17458       else if (edit_mode == ED_MODE_PROPERTIES)
17459         HandleControlButtons(level_editor_gadget[GADGET_ID_PROPERTIES]);
17460       else if (edit_mode == ED_MODE_PALETTE)
17461         HandleControlButtons(level_editor_gadget[GADGET_ID_PALETTE]);
17462       else              // should never happen
17463         ChangeEditModeWindow(ED_MODE_DRAWING);
17464
17465       break;
17466
17467     default:
17468       break;
17469   }
17470
17471   if (id != GADGET_ID_NONE)
17472     ClickOnGadget(level_editor_gadget[id], button);
17473   else if (letter == '1' || letter == '?')
17474     ClickOnGadget(level_editor_gadget[GADGET_ID_ELEMENT_LEFT], button);
17475   else if (letter == '2')
17476     ClickOnGadget(level_editor_gadget[GADGET_ID_ELEMENT_MIDDLE], button);
17477   else if (letter == '3')
17478     ClickOnGadget(level_editor_gadget[GADGET_ID_ELEMENT_RIGHT], button);
17479   else if (letter == '.')
17480     ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS], button);
17481   else if (letter == 'U')
17482     ClickOnGadget(level_editor_gadget[GADGET_ID_UNDO], 3);
17483   else if (letter == '-' || key == KSYM_KP_Subtract)
17484     ClickOnGadget(level_editor_gadget[GADGET_ID_ZOOM], 3);
17485   else if (letter == '0' || key == KSYM_KP_0)
17486     ClickOnGadget(level_editor_gadget[GADGET_ID_ZOOM], 2);
17487   else if (letter == '+' || key == KSYM_KP_Add ||
17488            letter == '=')       // ("Shift-=" is "+" on US keyboards)
17489     ClickOnGadget(level_editor_gadget[GADGET_ID_ZOOM], 1);
17490   else if (key == KSYM_Return ||
17491            key == KSYM_space ||
17492            key == setup.shortcut.toggle_pause)
17493     ClickOnGadget(level_editor_gadget[GADGET_ID_TEST], button);
17494   else
17495     for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
17496       if (letter && letter == controlbutton_info[i].shortcut)
17497         if (!anyTextGadgetActive())
17498           ClickOnGadget(level_editor_gadget[i], button);
17499
17500   if (draw_with_brush)
17501   {
17502     if (letter == 'x')
17503       FlipBrushX();
17504     else if (letter == 'y')
17505       FlipBrushY();
17506     else if (letter == 'z')
17507       RotateBrush();
17508   }
17509 }
17510
17511 static void HandleLevelEditorIdle_Properties(void)
17512 {
17513   int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
17514   int x = editor.settings.element_graphic.x + element_border;
17515   int y = editor.settings.element_graphic.y + element_border;
17516   static DelayCounter action_delay = { 0 };
17517   int i;
17518
17519   action_delay.value = GameFrameDelay;
17520
17521   if (!DelayReached(&action_delay))
17522     return;
17523
17524   for (i = 0; i < ED_NUM_SELECTBOX; i++)
17525   {
17526     struct GadgetInfo *gi = level_editor_gadget[selectbox_info[i].gadget_id];
17527
17528     if (gi->mapped && gi->active && gi->selectbox.open)
17529       return;
17530   }
17531
17532   DrawEditorElementAnimation(SX + x, SY + y);
17533
17534   redraw_mask |= REDRAW_FIELD;
17535
17536   FrameCounter++;       // increase animation frame counter
17537 }
17538
17539 static void HandleLevelEditorIdle_Drawing(void)
17540 {
17541   static boolean last_highlighted = FALSE;
17542   static boolean last_highlighted_similar = FALSE;
17543   boolean highlighted = (GetKeyModState() & KMOD_Alt);
17544   boolean highlighted_similar = (GetKeyModState() & KMOD_Shift);
17545
17546   if (highlighted != last_highlighted ||
17547       (highlighted && highlighted_similar != last_highlighted_similar))
17548   {
17549     DrawAreaElementHighlight(highlighted, highlighted_similar);
17550
17551     redraw_mask |= REDRAW_FIELD;
17552   }
17553
17554   last_highlighted = highlighted;
17555   last_highlighted_similar = highlighted_similar;
17556 }
17557
17558 void HandleLevelEditorIdle(void)
17559 {
17560   if (edit_mode == ED_MODE_PROPERTIES)
17561     HandleLevelEditorIdle_Properties();
17562   else if (edit_mode == ED_MODE_DRAWING)
17563     HandleLevelEditorIdle_Drawing();
17564 }
17565
17566 static void ClearEditorGadgetInfoText(void)
17567 {
17568   DrawBackground(INFOTEXT_XPOS, INFOTEXT_YPOS, INFOTEXT_XSIZE, INFOTEXT_YSIZE);
17569 }
17570
17571 void PrintEditorGadgetInfoText(struct GadgetInfo *gi)
17572 {
17573   char infotext[MAX_OUTPUT_LINESIZE + 1];
17574   int max_infotext_len = getMaxInfoTextLength();
17575
17576   if (gi == NULL || strlen(gi->info_text) == 0)
17577     return;
17578
17579   strncpy(infotext, gi->info_text, max_infotext_len);
17580   infotext[max_infotext_len] = '\0';
17581
17582   if (gi->custom_id < ED_NUM_CTRL_BUTTONS)
17583   {
17584     int key = controlbutton_info[gi->custom_id].shortcut;
17585
17586     if (key)
17587     {
17588       char shortcut[MAX_OUTPUT_LINESIZE + 1];
17589
17590       if (gi->custom_id == GADGET_ID_SINGLE_ITEMS)
17591         sprintf(shortcut, " ('.' or '%c')", key);
17592       else if (gi->custom_id == GADGET_ID_PICK_ELEMENT)
17593         sprintf(shortcut, " ('%c' or 'Ctrl')", key);
17594       else if (gi->custom_id == GADGET_ID_TEST)
17595         sprintf(shortcut, " ('Enter' or 'Shift-%c')", key);
17596       else if (gi->custom_id == GADGET_ID_UNDO)
17597         sprintf(shortcut, " ('%c/Shift-U')", key);
17598       else if (gi->custom_id == GADGET_ID_ZOOM)
17599         sprintf(shortcut, " ('%c', '0', '-')", key);
17600       else
17601         sprintf(shortcut, " ('%s%c')",
17602                 (key >= 'A' && key <= 'Z' ? "Shift-" : ""), key);
17603
17604       if (strlen(infotext) + strlen(shortcut) <= max_infotext_len)
17605         strcat(infotext, shortcut);
17606     }
17607   }
17608
17609   DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, INFOTEXT_FONT);
17610 }
17611
17612 void HandleEditorGadgetInfoText(void *ptr)
17613 {
17614   struct GadgetInfo *gi = (struct GadgetInfo *)ptr;
17615
17616   if (game_status != GAME_MODE_EDITOR)
17617     return;
17618
17619   ClearEditorGadgetInfoText();
17620
17621   if (gi == NULL || gi->event.type == GD_EVENT_INFO_LEAVING)
17622     return;
17623
17624   // misuse this function to delete brush cursor, if needed
17625   if (edit_mode == ED_MODE_DRAWING && draw_with_brush)
17626     DeleteBrushFromCursor();
17627
17628   PrintEditorGadgetInfoText(gi);
17629 }
17630
17631 static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
17632 {
17633   int id = gi->custom_id;
17634   int type_id = gi->custom_type_id;
17635   int sx = gi->event.x;
17636   int sy = gi->event.y;
17637   int lx = sx + level_xpos;
17638   int ly = sy + level_ypos;
17639   int min_sx = 0, min_sy = 0;
17640   int max_sx = gi->drawing.area_xsize - 1;
17641   int max_sy = gi->drawing.area_ysize - 1;
17642   int actual_drawing_function = drawing_function;
17643   int max_infotext_len = getMaxInfoTextLength();
17644   char infotext[MAX_OUTPUT_LINESIZE + 1];
17645
17646   infotext[0] = '\0';           // start with empty info text
17647
17648   // pressed Control key: simulate picking element
17649   if (GetKeyModState() & KMOD_Control)
17650     actual_drawing_function = GADGET_ID_PICK_ELEMENT;
17651
17652   ClearEditorGadgetInfoText();
17653
17654   if (gi->event.type == GD_EVENT_INFO_LEAVING)
17655     return;
17656
17657   // make sure to stay inside drawing area boundaries
17658   sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
17659   sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
17660
17661   if (id == GADGET_ID_DRAWING_LEVEL)
17662   {
17663     if (button_status)
17664     {
17665       int min_lx = 0, min_ly = 0;
17666       int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
17667
17668       // get positions inside level field
17669       lx = sx + level_xpos;
17670       ly = sy + level_ypos;
17671
17672       // make sure to stay inside level field boundaries
17673       lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
17674       ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
17675
17676       // correct drawing area positions accordingly
17677       sx = lx - level_xpos;
17678       sy = ly - level_ypos;
17679     }
17680
17681     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
17682     {
17683       if (button_status)        // if (gi->state == GD_BUTTON_PRESSED)
17684       {
17685         static int start_lx = 0;
17686         static int start_ly = 0;
17687         char *text;
17688
17689         if (gi->event.type == GD_EVENT_PRESSED)
17690         {
17691           start_lx = lx;
17692           start_ly = ly;
17693         }
17694
17695         switch (actual_drawing_function)
17696         {
17697           case GADGET_ID_SINGLE_ITEMS:
17698             text = "Drawing single items";
17699             break;
17700           case GADGET_ID_CONNECTED_ITEMS:
17701             text = "Drawing connected items";
17702             break;
17703           case GADGET_ID_LINE:
17704             text = "Drawing line";
17705             break;
17706           case GADGET_ID_ARC:
17707             text = "Drawing arc";
17708             break;
17709           case GADGET_ID_TEXT:
17710             text = "Setting text cursor";
17711             break;
17712           case GADGET_ID_RECTANGLE:
17713             text = "Drawing rectangle";
17714             break;
17715           case GADGET_ID_FILLED_BOX:
17716             text = "Drawing filled box";
17717             break;
17718           case GADGET_ID_FLOOD_FILL:
17719             text = "Flood fill";
17720             break;
17721           case GADGET_ID_GRAB_BRUSH:
17722             text = "Grabbing brush";
17723             break;
17724           case GADGET_ID_PICK_ELEMENT:
17725             text = "Picking element";
17726             break;
17727
17728           default:
17729             text = "Drawing position";
17730             break;
17731         }
17732
17733         if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
17734           sprintf(infotext, "%s: %d, %d", text, lx, ly);
17735         else
17736           sprintf(infotext, "%s: %d, %d", text,
17737                   ABS(lx - start_lx) + 1, ABS(ly - start_ly) + 1);
17738       }
17739       else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
17740         strncpy(infotext, getElementInfoText(Tile[lx][ly]), max_infotext_len);
17741       else
17742         sprintf(infotext, "Level position: %d, %d", lx, ly);
17743     }
17744
17745     // misuse this function to draw brush cursor, if needed
17746     if (edit_mode == ED_MODE_DRAWING && draw_with_brush && !button_status)
17747     {
17748       if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
17749         CopyBrushToCursor(sx, sy);
17750       else
17751         DeleteBrushFromCursor();
17752     }
17753
17754     if (!draw_with_brush)
17755       UpdateBrushPosition(sx, sy);
17756   }
17757   else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
17758   {
17759     int pos = sx * drawingarea_info[type_id].area_ysize + sy;
17760     int element = drawingarea_info[type_id].value[pos];
17761
17762     strncpy(infotext, getElementInfoText(element), max_infotext_len);
17763   }
17764   else
17765   {
17766     if (id == GADGET_ID_CUSTOM_CONTENT)
17767       sprintf(infotext, "custom element content position: %d, %d", sx, sy);
17768     else if (id == GADGET_ID_GROUP_CONTENT)
17769       sprintf(infotext, "group element position: %d", sx + 1);
17770     else if (id >= GADGET_ID_YAMYAM_CONTENT_0 &&
17771              id <= GADGET_ID_YAMYAM_CONTENT_7)
17772       sprintf(infotext, "content area %d position: %d, %d",
17773               id - GADGET_ID_YAMYAM_CONTENT_0 + 1, sx, sy);
17774     else if (id >= GADGET_ID_MAGIC_BALL_CONTENT_0 &&
17775              id <= GADGET_ID_MAGIC_BALL_CONTENT_7)
17776       sprintf(infotext, "content area %d position: %d, %d",
17777               id - GADGET_ID_MAGIC_BALL_CONTENT_0 + 1, sx, sy);
17778     else if (id == GADGET_ID_ANDROID_CONTENT)
17779       sprintf(infotext, "android element position: %d", sx + 1);
17780     else if (drawingarea_info[type_id].infotext != NULL)
17781       strcpy(infotext, drawingarea_info[type_id].infotext);
17782   }
17783
17784   infotext[max_infotext_len] = '\0';
17785
17786   if (strlen(infotext) > 0)
17787     DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, INFOTEXT_FONT, infotext);
17788 }
17789
17790 void RequestExitLevelEditor(boolean ask_if_level_has_changed,
17791                             boolean quick_quit)
17792 {
17793   if (!ask_if_level_has_changed ||
17794       !LevelChanged() ||
17795       Request("Level has changed! Exit without saving?",
17796               REQ_ASK | REQ_STAY_OPEN))
17797   {
17798     struct RectWithBorder *vp_door_1 = &viewport.door_1[GAME_MODE_MAIN];
17799     struct RectWithBorder *vp_door_2 = &viewport.door_2[GAME_MODE_MAIN];
17800
17801     // draw normal door
17802     UndrawSpecialEditorDoor();
17803
17804     // use door animation if door 1 viewport is unchanged and contains toolbox
17805     if (useEditorDoorAnimation())
17806       CloseDoor(DOOR_CLOSE_1 | DOOR_FORCE_ANIM);
17807
17808     // close editor doors if viewport definition is the same as in main menu
17809     if (vp_door_1->x      == DX     &&
17810         vp_door_1->y      == DY     &&
17811         vp_door_1->width  == DXSIZE &&
17812         vp_door_1->height == DYSIZE &&
17813         vp_door_2->x      == VX     &&
17814         vp_door_2->y      == VY     &&
17815         vp_door_2->width  == VXSIZE &&
17816         vp_door_2->height == VYSIZE)
17817       CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
17818     else
17819       SetDoorState(DOOR_CLOSE_ALL);
17820
17821     BackToFront();
17822
17823     if (quick_quit)
17824       FadeSkipNextFadeIn();
17825
17826     SetGameStatus(GAME_MODE_MAIN);
17827
17828     DrawMainMenu();
17829   }
17830   else
17831   {
17832     if (!global.use_envelope_request)
17833     {
17834       CloseDoor(DOOR_CLOSE_1);
17835       OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
17836     }
17837   }
17838 }