fixed updating color box when changing BD engine color in level 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   if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
10606   {
10607     new_element1 = EL_BD_WALL;
10608     new_element2 = EL_EMPTY;
10609     new_element3 = EL_BD_SAND;
10610   }
10611   else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
10612   {
10613     new_element1 = EL_SP_CHIP_SINGLE;
10614     new_element2 = EL_EMPTY;
10615     new_element3 = EL_SP_BASE;
10616   }
10617   else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
10618   {
10619     new_element1 = EL_MM_MIRROR_START;
10620     new_element2 = EL_EMPTY;
10621     new_element3 = EL_MM_WOODEN_WALL;
10622   }
10623   else
10624   {
10625     new_element1 = EL_WALL;
10626     new_element2 = EL_EMPTY;
10627     new_element3 = EL_SAND;
10628   }
10629
10630   game_engine_type_last = level.game_engine_type;
10631 }
10632
10633 static void InitLevelSetInfo(void)
10634 {
10635   snprintf(levelset_name,   MAX_LEVEL_NAME_LEN + 1,
10636            "%s", leveldir_current->name);
10637   snprintf(levelset_author, MAX_LEVEL_AUTHOR_LEN + 1,
10638            "%s", leveldir_current->author);
10639
10640   levelset_num_levels = leveldir_current->levels;
10641
10642   levelset_use_levelset_artwork = FALSE;
10643   levelset_copy_level_template = FALSE;
10644
10645   levelset_save_mode = LEVELSET_SAVE_MODE_UPDATE;
10646 }
10647
10648 static void ChangeEditorToLevelSet(char *levelset_subdir)
10649 {
10650   leveldir_current = getTreeInfoFromIdentifier(leveldir_first, levelset_subdir);
10651
10652   // the previous level set might have used custom artwork
10653   ReloadCustomArtwork(0);
10654
10655   LoadLevelSetup_SeriesInfo();
10656
10657   SaveLevelSetup_LastSeries();
10658   SaveLevelSetup_SeriesInfo();
10659
10660   TapeErase();
10661
10662   LoadLevel(level_nr);
10663   LoadScore(level_nr);
10664
10665   DrawLevelEd();
10666 }
10667
10668 static boolean useEditorDoorAnimation(void)
10669 {
10670   struct RectWithBorder *vp_door_1 = &viewport.door_1[GAME_MODE_MAIN];
10671   boolean door_1_viewport_unchanged =
10672     (vp_door_1->x      == DX     &&
10673      vp_door_1->y      == DY     &&
10674      vp_door_1->width  == DXSIZE &&
10675      vp_door_1->height == DYSIZE);
10676   boolean door_1_contains_toolbox =
10677     (EX >= DX &&
10678      EY >= DY &&
10679      EX + EXSIZE <= DX + DXSIZE &&
10680      EY + EYSIZE <= DY + DYSIZE);
10681
10682   return (door_1_viewport_unchanged && door_1_contains_toolbox);
10683 }
10684
10685 static void DrawEditorDoorBackground(int graphic, int x, int y,
10686                                      int width, int height)
10687 {
10688   struct GraphicInfo *g = &graphic_info[graphic];
10689
10690   if (g->bitmap != NULL)
10691     BlitBitmap(g->bitmap, drawto, g->src_x, g->src_y,
10692                MIN(width, g->width), MIN(height, g->height), x, y);
10693   else
10694     ClearRectangle(drawto, x, y, width, height);
10695 }
10696
10697 static void DrawEditorDoorContent(void)
10698 {
10699   // needed for gadgets drawn on background (like palette scrollbar)
10700   SetDoorBackgroundImage(IMG_UNDEFINED);
10701
10702   // copy default editor door content to main double buffer
10703   DrawEditorDoorBackground(IMG_BACKGROUND_PALETTE, DX, DY, DXSIZE, DYSIZE);
10704
10705   // draw bigger door
10706   DrawSpecialEditorDoor();
10707
10708   // draw new control window
10709   DrawEditorDoorBackground(IMG_BACKGROUND_TOOLBOX, EX, EY, EXSIZE, EYSIZE);
10710
10711   // draw all toolbox gadgets to editor doors
10712   MapControlButtons();
10713
10714   // when returning from test game to properties page, redraw toolbox gadgets
10715   if (edit_mode == ED_MODE_PROPERTIES)
10716   {
10717     UnmapLevelEditorToolboxDrawingGadgets();
10718     UnmapLevelEditorToolboxCustomGadgets();
10719
10720     MapLevelEditorToolboxCustomGadgetsIfNeeded();
10721   }
10722
10723   // draw all palette gadgets to editor doors
10724   ModifyEditorElementList();
10725   RedrawDrawingElements();
10726
10727   // copy actual editor door content to door double buffer for OpenDoor()
10728   BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
10729 }
10730
10731 void DrawLevelEd(void)
10732 {
10733   int fade_mask = REDRAW_FIELD;
10734
10735   FadeSoundsAndMusic();
10736
10737   if (CheckFadeAll())
10738     fade_mask = REDRAW_ALL;
10739
10740   FadeOut(fade_mask);
10741
10742   // needed if different viewport properties defined for editor
10743   ChangeViewportPropertiesIfNeeded();
10744
10745   ClearField();
10746
10747   InitZoomLevelSettings(-1);
10748   InitDrawingElements();
10749   InitLevelSetInfo();
10750
10751 #if DEBUG
10752   CheckElementDescriptions();
10753 #endif
10754
10755   if (level_editor_test_game)
10756   {
10757     CopyPlayfield(level.field, Tile);
10758     CopyPlayfield(TileBackup, level.field);
10759
10760     level_editor_test_game = FALSE;
10761   }
10762   else
10763   {
10764     edit_mode = ED_MODE_DRAWING;
10765     edit_mode_levelconfig = ED_MODE_LEVELCONFIG_LEVEL;
10766     edit_mode_engineconfig = ED_MODE_ENGINECONFIG_CONFIG;
10767     edit_mode_properties = ED_MODE_PROPERTIES_INFO;
10768
10769     ResetUndoBuffer();
10770
10771     level_xpos = -1;
10772     level_ypos = -1;
10773   }
10774
10775   // redraw_mask |= REDRAW_ALL;
10776
10777   FreeLevelEditorGadgets();
10778   CreateLevelEditorGadgets();
10779
10780   ReinitializeElementList();            // update dynamic level element list
10781   ReinitializeElementListButtons();     // custom element may look different
10782
10783   InitElementPropertiesGfxElement();
10784
10785   UnmapAllGadgets();
10786
10787   DrawEditModeWindow_PlayfieldOnly();
10788
10789   DrawMaskedBorder(fade_mask);
10790
10791   // use door animation if door 1 viewport is unchanged and contains toolbox
10792   if (useEditorDoorAnimation())
10793   {
10794     FadeIn(fade_mask);
10795
10796     DrawEditorDoorContent();
10797
10798     OpenDoor(DOOR_OPEN_1 | DOOR_FORCE_ANIM);
10799   }
10800   else
10801   {
10802     DrawEditorDoorContent();
10803
10804     FadeIn(fade_mask);
10805   }
10806
10807   SetDoorState(DOOR_OPEN_1 | DOOR_OPEN_2);
10808 }
10809
10810 static void AdjustDrawingAreaGadgets(void)
10811 {
10812   int ed_xsize = lev_fieldx + 2;
10813   int ed_ysize = lev_fieldy + 2;
10814   int max_ed_fieldx = MAX_ED_FIELDX;
10815   int max_ed_fieldy = MAX_ED_FIELDY;
10816   boolean horizontal_scrollbar_needed;
10817   boolean vertical_scrollbar_needed;
10818   int x, y, width, height;
10819
10820   if (suppressBorderElement())
10821   {
10822     ed_xsize = lev_fieldx;
10823     ed_ysize = lev_fieldy;
10824   }
10825
10826   // check if we need any scrollbars
10827   horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
10828   vertical_scrollbar_needed   = (ed_ysize > max_ed_fieldy);
10829
10830   // check if we have a smaller editor field because of scrollbars
10831   max_ed_fieldx = getMaxEdFieldX(vertical_scrollbar_needed);
10832   max_ed_fieldy = getMaxEdFieldY(horizontal_scrollbar_needed);
10833
10834   // check again if we now need more scrollbars because of less space
10835   horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
10836   vertical_scrollbar_needed   = (ed_ysize > max_ed_fieldy);
10837
10838   // check if editor field gets even smaller after adding new scrollbars
10839   max_ed_fieldx = getMaxEdFieldX(vertical_scrollbar_needed);
10840   max_ed_fieldy = getMaxEdFieldY(horizontal_scrollbar_needed);
10841
10842   ed_fieldx = (ed_xsize > max_ed_fieldx ? max_ed_fieldx : ed_xsize);
10843   ed_fieldy = (ed_ysize > max_ed_fieldy ? max_ed_fieldy : ed_ysize);
10844
10845   x = SX + ed_fieldx * ed_tilesize;
10846   y = SY + ed_fieldy * ed_tilesize;
10847
10848   width  = ed_fieldx * ed_tilesize - 2 * ED_SCROLLBUTTON_XSIZE;
10849   height = ed_fieldy * ed_tilesize - 2 * ED_SCROLLBUTTON_YSIZE;
10850
10851   // adjust drawing area gadget
10852   ModifyGadget(level_editor_gadget[GADGET_ID_DRAWING_LEVEL],
10853                GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
10854                GDI_ITEM_SIZE, ed_tilesize, ed_tilesize,
10855                GDI_END);
10856
10857   // adjust horizontal scrollbar gadgets
10858   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LEFT],
10859                GDI_Y, y,
10860                GDI_END);
10861   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT],
10862                GDI_X, x - ED_SCROLLBUTTON_XSIZE,
10863                GDI_Y, y,
10864                GDI_END);
10865   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
10866                GDI_Y, y,
10867                GDI_WIDTH, width,
10868                GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldx,
10869                GDI_END);
10870
10871   // adjust vertical scrollbar gadgets
10872   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_UP],
10873                GDI_X, x,
10874                GDI_END);
10875   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN],
10876                GDI_X, x,
10877                GDI_Y, y - ED_SCROLLBUTTON_YSIZE,
10878                GDI_END);
10879   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
10880                GDI_X, x,
10881                GDI_HEIGHT, height,
10882                GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldy,
10883                GDI_END);
10884 }
10885
10886 static void AdjustLevelScrollPosition(void)
10887 {
10888   if (level_xpos < -1)
10889     level_xpos = -1;
10890   if (level_xpos > lev_fieldx - ed_fieldx + 1)
10891     level_xpos = lev_fieldx - ed_fieldx + 1;
10892   if (lev_fieldx < ed_fieldx - 2)
10893     level_xpos = -1;
10894
10895   if (level_ypos < -1)
10896     level_ypos = -1;
10897   if (level_ypos > lev_fieldy - ed_fieldy + 1)
10898     level_ypos = lev_fieldy - ed_fieldy + 1;
10899   if (lev_fieldy < ed_fieldy - 2)
10900     level_ypos = -1;
10901
10902   if (suppressBorderElement())
10903   {
10904     level_xpos = 0;
10905     level_ypos = 0;
10906   }
10907 }
10908
10909 static void AdjustEditorScrollbar(int id)
10910 {
10911   struct GadgetInfo *gi = level_editor_gadget[id];
10912   int items_max, items_visible, item_position;
10913
10914   if (id == GADGET_ID_SCROLL_HORIZONTAL)
10915   {
10916     items_max = MAX(lev_fieldx + 2, ed_fieldx);
10917     items_visible = ed_fieldx;
10918     item_position = level_xpos + 1;
10919   }
10920   else
10921   {
10922     items_max = MAX(lev_fieldy + 2, ed_fieldy);
10923     items_visible = ed_fieldy;
10924     item_position = level_ypos + 1;
10925   }
10926
10927   if (item_position > items_max - items_visible)
10928     item_position = items_max - items_visible;
10929
10930   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
10931                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
10932 }
10933
10934 static void AdjustElementListScrollbar(void)
10935 {
10936   struct GadgetInfo *gi = level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL];
10937   int items_max, items_visible, item_position;
10938
10939   // correct position of element list scrollbar
10940   if (element_shift < 0)
10941     element_shift = 0;
10942   if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
10943     element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
10944
10945   items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
10946   items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
10947   item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
10948
10949   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
10950                GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
10951                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
10952 }
10953
10954 static void ModifyEditorCounterValue(int counter_id, int new_value)
10955 {
10956   int *counter_value = counterbutton_info[counter_id].value;
10957   int gadget_id = counterbutton_info[counter_id].gadget_id_text;
10958   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10959
10960   ModifyGadget(gi, GDI_NUMBER_VALUE, new_value, GDI_END);
10961
10962   if (counter_value != NULL)
10963     *counter_value = gi->textinput.number_value;
10964 }
10965
10966 static void ModifyEditorCounterLimits(int counter_id, int min, int max)
10967 {
10968   int gadget_id = counterbutton_info[counter_id].gadget_id_text;
10969   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10970
10971   ModifyGadget(gi, GDI_NUMBER_MIN, min, GDI_NUMBER_MAX, max, GDI_END);
10972
10973   if (counter_id >= ED_COUNTER_ID_ELEMENT_VALUE1 &&
10974       counter_id <= ED_COUNTER_ID_ELEMENT_VALUE4)
10975   {
10976     int gadget_id_up = counterbutton_info[counter_id].gadget_id_up;
10977     struct GadgetInfo *gi_up = level_editor_gadget[gadget_id_up];
10978
10979     ModifyGadget(gi, GDI_TEXT_SIZE, (max < 10 ? 1 : 3), GDI_END);
10980     ModifyGadget(gi_up, GDI_X, gi->x + gi->width + ED_GADGET_SMALL_DISTANCE,
10981                  GDI_END);
10982   }
10983 }
10984
10985 static void ModifyEditorSelectboxValue(int selectbox_id, int new_value)
10986 {
10987   int gadget_id = selectbox_info[selectbox_id].gadget_id;
10988   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10989   int new_index_value = setSelectboxValue(selectbox_id, new_value);
10990
10991   ModifyGadget(gi, GDI_SELECTBOX_INDEX, new_index_value, GDI_END);
10992 }
10993
10994 static void ModifyEditorSelectboxOptions(int selectbox_id,
10995                                          struct ValueTextInfo *options)
10996 {
10997   int gadget_id = selectbox_info[selectbox_id].gadget_id;
10998   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
10999
11000   selectbox_info[selectbox_id].options = options;
11001
11002   // set index to zero -- list may be shorter now (correct later, if needed)
11003   ModifyGadget(gi, GDI_SELECTBOX_INDEX, 0,
11004                GDI_SELECTBOX_OPTIONS, options, GDI_END);
11005 }
11006
11007 static void ModifyEditorDrawingArea(int drawingarea_id, int xsize, int ysize)
11008 {
11009   int gadget_id = drawingarea_info[drawingarea_id].gadget_id;
11010   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11011
11012   drawingarea_info[drawingarea_id].area_xsize = xsize;
11013   drawingarea_info[drawingarea_id].area_ysize = ysize;
11014
11015   ModifyGadget(gi, GDI_AREA_SIZE, xsize, ysize, GDI_END);
11016 }
11017
11018 static void ModifyEditorElementList(void)
11019 {
11020   int i;
11021
11022   if (!use_permanent_palette && edit_mode != ED_MODE_PALETTE)
11023     return;
11024
11025   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
11026   {
11027     int gadget_id = GADGET_ID_ELEMENTLIST_FIRST + i;
11028     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11029     struct GadgetDesign *gd = &gi->deco.design;
11030     int element = editor_elements[element_shift + i];
11031     int tile_size = BUTTON_TILE_SIZE(editor.palette.tile_size);
11032
11033     UnmapGadget(gi);
11034
11035     getEditorGraphicSource(element, tile_size, &gd->bitmap, &gd->x, &gd->y);
11036
11037     ModifyGadget(gi, GDI_INFO_TEXT, getElementInfoText(element), GDI_END);
11038
11039     MapGadget(gi);
11040   }
11041 }
11042
11043 static void DrawDrawingElementGraphic(int element, struct XYTileSize *pos)
11044 {
11045   int graphic = el2edimg(element);
11046   int tile_size = BUTTON_TILE_SIZE(pos->tile_size);
11047
11048   if (pos->x == -1 &&
11049       pos->y == -1)
11050     return;
11051
11052   DrawSizedGraphicExt(drawto, DX + pos->x, DY + pos->y, graphic, 0, tile_size);
11053 }
11054
11055 static void ModifyDrawingElementButton(int element, int id)
11056 {
11057   struct GadgetInfo *gi = level_editor_gadget[id];
11058   Bitmap *deco_bitmap;
11059   int deco_x, deco_y;
11060   int tile_size = gi->deco.width;
11061
11062   getEditorGraphicSource(element, tile_size, &deco_bitmap, &deco_x, &deco_y);
11063
11064   ModifyGadget(gi, GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y, GDI_END);
11065 }
11066
11067 static void PickDrawingElement(int button, int element)
11068 {
11069   struct
11070   {
11071     int *new_element;
11072     struct XYTileSize *pos;
11073     int id;
11074   } de, drawing_elements[] =
11075   {
11076     { &new_element1, &editor.palette.element_left,   GADGET_ID_ELEMENT_LEFT   },
11077     { &new_element2, &editor.palette.element_middle, GADGET_ID_ELEMENT_MIDDLE },
11078     { &new_element3, &editor.palette.element_right,  GADGET_ID_ELEMENT_RIGHT  },
11079   };
11080
11081   if (button < 1 || button > 3)
11082     return;
11083
11084   if (IS_MM_WALL(element))
11085     element = map_mm_wall_element(element);
11086
11087   de = drawing_elements[button - 1];
11088
11089   *de.new_element = element;    // update global drawing element variable
11090
11091   DrawDrawingElementGraphic(element, de.pos);
11092   ModifyDrawingElementButton(element, de.id);
11093
11094   redraw_mask |= REDRAW_DOOR_1;
11095 }
11096
11097 static void RedrawDrawingElements(void)
11098 {
11099   PickDrawingElement(1, new_element1);
11100   PickDrawingElement(2, new_element2);
11101   PickDrawingElement(3, new_element3);
11102 }
11103
11104 static void DrawDrawingWindowExt(boolean remap_toolbox_gadgets)
11105 {
11106   stick_element_properties_window = FALSE;
11107
11108   SetMainBackgroundImage(IMG_UNDEFINED);
11109   ClearField();
11110
11111   UnmapLevelEditorFieldGadgets();
11112
11113   AdjustDrawingAreaGadgets();
11114   AdjustLevelScrollPosition();
11115   AdjustEditorScrollbar(GADGET_ID_SCROLL_HORIZONTAL);
11116   AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
11117
11118   DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
11119
11120   MapMainDrawingArea();
11121
11122   if (remap_toolbox_gadgets)
11123   {
11124     UnmapLevelEditorToolboxCustomGadgets();
11125     MapLevelEditorToolboxDrawingGadgets();
11126   }
11127 }
11128
11129 static void DrawDrawingWindow(void)
11130 {
11131   DrawDrawingWindowExt(TRUE);
11132 }
11133
11134 static int getTabulatorBarWidth(void)
11135 {
11136   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
11137   struct GadgetInfo *gd_gi4 = level_editor_gadget[GADGET_ID_PROPERTIES_CHANGE];
11138
11139   return gd_gi4->x - gd_gi1->x + gd_gi4->width;
11140 }
11141
11142 static int getTabulatorBarHeight(void)
11143 {
11144   return ED_TAB_BAR_HEIGHT;
11145 }
11146
11147 static Pixel getTabulatorBarColor(void)
11148 {
11149   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_LEVELCONFIG_LEVEL];
11150   struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
11151   int gd_x = gd->x + gd_gi1->border.width / 2;
11152   int gd_y = gd->y + gd_gi1->height - 1;
11153
11154   return GetPixel(gd->bitmap, gd_x, gd_y);
11155 }
11156
11157 static void DrawEngineConfigTabulatorGadgets(void)
11158 {
11159   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_ENGINECONFIG_CONFIG];
11160   Pixel tab_color = getTabulatorBarColor();
11161   int id_first = ED_TEXTBUTTON_ID_ENGINECONFIG_CONFIG;
11162   int id_last  = ED_TEXTBUTTON_ID_ENGINECONFIG_COLORS;
11163   int i;
11164
11165   for (i = id_first; i <= id_last; i++)
11166   {
11167     int gadget_id = textbutton_info[i].gadget_id;
11168     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11169     boolean active = (i != edit_mode_engineconfig);
11170
11171     // draw background line below tabulator button
11172     ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width, 1);
11173
11174     // draw solid line below inactive tabulator buttons
11175     if (!active && tab_color != BLACK_PIXEL)    // black => transparent
11176       FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,
11177                     ED_GADGET_TINY_DISTANCE, tab_color);
11178
11179     ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
11180     MapTextbuttonGadget(i);
11181   }
11182
11183   // draw little border line below tabulator buttons
11184   if (tab_color != BLACK_PIXEL)                 // black => transparent
11185     FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height +
11186                   ED_GADGET_TINY_DISTANCE,
11187                   getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
11188 }
11189
11190 static void DrawLevelConfigTabulatorGadgets(void)
11191 {
11192   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_LEVELCONFIG_LEVEL];
11193   Pixel tab_color = getTabulatorBarColor();
11194   int id_first = ED_TEXTBUTTON_ID_LEVELCONFIG_LEVEL;
11195   int id_last  = ED_TEXTBUTTON_ID_LEVELCONFIG_EDITOR;
11196   int i;
11197
11198   // draw additional "engine" tabulator when using native BD engine
11199   if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
11200     id_last = ED_TEXTBUTTON_ID_LEVELCONFIG_ENGINE;
11201
11202   for (i = id_first; i <= id_last; i++)
11203   {
11204     int gadget_id = textbutton_info[i].gadget_id;
11205     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11206     boolean active = (i != edit_mode_levelconfig);
11207
11208     // draw background line below tabulator button
11209     ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width, 1);
11210
11211     // draw solid line below inactive tabulator buttons
11212     if (!active && tab_color != BLACK_PIXEL)    // black => transparent
11213       FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,
11214                     ED_GADGET_TINY_DISTANCE, tab_color);
11215
11216     ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
11217     MapTextbuttonGadget(i);
11218   }
11219
11220   // draw little border line below tabulator buttons
11221   if (tab_color != BLACK_PIXEL)                 // black => transparent
11222     FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height +
11223                   ED_GADGET_TINY_DISTANCE,
11224                   getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
11225
11226   // draw second row of engine related tabulators when using native BD engine
11227   if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_ENGINE)
11228     DrawEngineConfigTabulatorGadgets();
11229 }
11230
11231 static void DrawPropertiesTabulatorGadgets(void)
11232 {
11233   struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
11234   struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
11235   int gd_x = gd->x + gd_gi1->border.width / 2;
11236   int gd_y = gd->y + gd_gi1->height - 1;
11237   Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
11238   int id_first = ED_TEXTBUTTON_ID_PROPERTIES_INFO;
11239   int id_last  = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG;
11240   int i;
11241
11242   // draw two config tabulators for player elements
11243   if (IS_PLAYER_ELEMENT(properties_element))
11244     id_last = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2;
11245
11246   // draw two config and one "change" tabulator for custom elements
11247   if (IS_CUSTOM_ELEMENT(properties_element))
11248     id_last = ED_TEXTBUTTON_ID_PROPERTIES_CHANGE;
11249
11250   for (i = id_first; i <= id_last; i++)
11251   {
11252     int gadget_id = textbutton_info[i].gadget_id;
11253     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
11254     boolean active = (i != edit_mode_properties);
11255
11256     // use "config 1" and "config 2" instead of "config" for players and CEs
11257     if (i == ED_TEXTBUTTON_ID_PROPERTIES_CONFIG &&
11258         (IS_PLAYER_ELEMENT(properties_element) ||
11259          IS_CUSTOM_ELEMENT(properties_element)))
11260       continue;
11261
11262     // draw background line below tabulator button
11263     ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width, 1);
11264
11265     // draw solid line below inactive tabulator buttons
11266     if (!active && tab_color != BLACK_PIXEL)    // black => transparent
11267       FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,
11268                     ED_GADGET_TINY_DISTANCE, tab_color);
11269
11270     ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
11271     MapTextbuttonGadget(i);
11272   }
11273
11274   // draw little border line below tabulator buttons
11275   if (tab_color != BLACK_PIXEL)                 // black => transparent
11276     FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height +
11277                   ED_GADGET_TINY_DISTANCE,
11278                   getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
11279 }
11280
11281 static void PrintInfoText(char *text, int font_nr, int xpos, int ypos)
11282 {
11283   DrawText(SX + xpos, SY + ypos, text, font_nr);
11284 }
11285
11286 static int PrintElementDescriptionFromFile(char *filename, int font_nr,
11287                                            int xpos, int ypos)
11288 {
11289   int font_width = getFontWidth(font_nr);
11290   int font_height = getFontHeight(font_nr);
11291   int max_chars_per_line = (SXSIZE - 2 * xpos) / font_width;
11292   int max_lines_drawable = (SYSIZE - ypos) / font_height - 1;
11293
11294   return DrawTextFile(SX + xpos, SY + ypos, filename, font_nr,
11295                       max_chars_per_line, -1, max_lines_drawable, 0, -1,
11296                       TRUE, FALSE, FALSE);
11297 }
11298
11299 static void DrawLevelConfigLevel(void)
11300 {
11301   int i;
11302
11303   // draw counter gadgets
11304   for (i = ED_COUNTER_ID_LEVEL_FIRST; i <= ED_COUNTER_ID_LEVEL_LAST; i++)
11305     MapCounterButtons(i);
11306
11307   // draw checkbutton gadgets
11308   for (i = ED_CHECKBUTTON_ID_LEVEL_FIRST; i<= ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
11309     MapCheckbuttonGadget(i);
11310
11311   // draw selectbox gadgets
11312   for (i = ED_SELECTBOX_ID_LEVEL_FIRST; i <= ED_SELECTBOX_ID_LEVEL_LAST; i++)
11313     MapSelectboxGadget(i);
11314
11315   // draw text input gadgets
11316   for (i = ED_TEXTINPUT_ID_LEVEL_FIRST; i <= ED_TEXTINPUT_ID_LEVEL_LAST; i++)
11317     MapTextInputGadget(i);
11318 }
11319
11320 static char *getLevelSubdirFromSaveMode(int save_mode)
11321 {
11322   if (save_mode == LEVELSET_SAVE_MODE_CREATE)
11323     return getNewUserLevelSubdir();
11324
11325   return leveldir_current->subdir;
11326 }
11327
11328 static void DrawLevelConfigLevelSet_DirectoryInfo(void)
11329 {
11330   char *directory_text = "Level set directory:";
11331   char *directory_name = getLevelSubdirFromSaveMode(levelset_save_mode);
11332   int font1_nr = FONT_TEXT_1;
11333   int font2_nr = FONT_TEXT_2;
11334   int font1_height = getFontHeight(font1_nr);
11335   int yoffset_above = font1_height + ED_GADGET_LINE_DISTANCE;
11336   int x = ED_LEVEL_SETTINGS_X(0);
11337   int y = ED_LEVEL_SETTINGS_Y(6);
11338
11339   PrintInfoText(directory_text, font1_nr, x, y - yoffset_above);
11340   PrintInfoText(directory_name, font2_nr, x, y);
11341 }
11342
11343 static void DrawLevelConfigLevelSet(void)
11344 {
11345   boolean artwork_exists = checkIfCustomArtworkExistsForCurrentLevelSet();
11346   boolean template_exists = fileExists(getLocalLevelTemplateFilename());
11347   int i;
11348
11349   // draw counter gadgets
11350   for (i = ED_COUNTER_ID_LEVELSET_FIRST; i <= ED_COUNTER_ID_LEVELSET_LAST; i++)
11351     MapCounterButtons(i);
11352
11353   // draw checkbutton gadgets
11354   for (i = ED_CHECKBUTTON_ID_LEVELSET_FIRST; i <= ED_CHECKBUTTON_ID_LEVELSET_LAST; i++)
11355   {
11356     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE ||
11357         (i == ED_CHECKBUTTON_ID_USE_LEVELSET_ARTWORK && !artwork_exists) ||
11358         (i == ED_CHECKBUTTON_ID_COPY_LEVEL_TEMPLATE  && !template_exists))
11359       continue;
11360
11361     MapCheckbuttonGadget(i);
11362   }
11363
11364   // draw selectbox gadgets
11365   for (i = ED_SELECTBOX_ID_LEVELSET_FIRST; i <= ED_SELECTBOX_ID_LEVELSET_LAST; i++)
11366     MapSelectboxGadget(i);
11367
11368   // draw text input gadgets
11369   for (i = ED_TEXTINPUT_ID_LEVELSET_FIRST; i <= ED_TEXTINPUT_ID_LEVELSET_LAST; i++)
11370     MapTextInputGadget(i);
11371
11372   // draw textbutton gadgets
11373   MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_LEVELSET);
11374
11375   // draw info text
11376   DrawLevelConfigLevelSet_DirectoryInfo();
11377 }
11378
11379 static void DrawLevelConfigEditor(void)
11380 {
11381   int i;
11382
11383   // draw counter gadgets
11384   for (i = ED_COUNTER_ID_EDITOR_FIRST; i <= ED_COUNTER_ID_EDITOR_LAST; i++)
11385     MapCounterButtons(i);
11386
11387   // draw checkbutton gadgets
11388   for (i = ED_CHECKBUTTON_ID_EDITOR_FIRST; i <= ED_CHECKBUTTON_ID_EDITOR_LAST; i++)
11389     MapCheckbuttonGadget(i);
11390
11391   // draw radiobutton gadgets
11392   for (i = ED_RADIOBUTTON_ID_EDITOR_FIRST; i <= ED_RADIOBUTTON_ID_EDITOR_LAST; i++)
11393     MapRadiobuttonGadget(i);
11394
11395   // draw drawing area
11396   MapDrawingArea(ED_DRAWING_ID_RANDOM_BACKGROUND);
11397
11398   // draw textbutton gadgets
11399   MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_2);
11400 }
11401
11402 static void DrawEngineConfigConfig(void)
11403 {
11404   int i;
11405
11406   // draw counter gadgets
11407   if (level.bd_scheduling_type == GD_SCHEDULING_MILLISECONDS)
11408   {
11409     MapCounterButtons(ED_COUNTER_ID_BD_CYCLE_DELAY_MS);
11410     MapCounterButtons(ED_COUNTER_ID_BD_HATCHING_DELAY_CYCLES);
11411   }
11412   else
11413   {
11414     MapCounterButtons(ED_COUNTER_ID_BD_CYCLE_DELAY_C64);
11415     MapCounterButtons(ED_COUNTER_ID_BD_HATCHING_DELAY_SECONDS);
11416   }
11417
11418   // draw checkbutton gadgets
11419   for (i = ED_CHECKBUTTON_ID_ENGINE_FIRST; i <= ED_CHECKBUTTON_ID_ENGINE_LAST; i++)
11420     MapCheckbuttonGadget(i);
11421
11422   // draw selectbox gadgets
11423   for (i = ED_SELECTBOX_ID_ENGINE_FIRST; i <= ED_SELECTBOX_ID_ENGINE_LAST; i++)
11424     MapSelectboxGadget(i);
11425 }
11426
11427 static int GetCommonColorType_BD(void)
11428 {
11429   int bd_color_type = *bd_color[0] >> 24;
11430   int i;
11431
11432   // check if all colors have the same color type
11433   for (i = 1; i < MAX_BD_COLORS; i++)
11434     if ((*bd_color[i] >> 24) != bd_color_type)
11435       return GD_COLOR_TYPE_RGB;
11436
11437   return bd_color_type;
11438 }
11439
11440 void SetDefaultLevelColorType_BD(void)
11441 {
11442   bd_color_type_default = GetCommonColorType_BD();
11443
11444   level.bd_color_type = bd_color_type_default;
11445 }
11446
11447 void SetDefaultLevelColors_BD(void)
11448 {
11449   int i;
11450
11451   for (i = 0; i < MAX_BD_COLORS; i++)
11452     bd_color_default[i] = *bd_color[i];
11453 }
11454
11455 static void SetRandomLevelColors_BD(void)
11456 {
11457   struct LevelInfo_BD *level_bd = level.native_bd_level;
11458   GdCave *cave = level_bd->cave;
11459
11460   // create random cave colors
11461   gd_cave_set_random_colors(cave, level.bd_color_type);
11462
11463   // copy colors to level editor
11464   level.bd_color_b = cave->colorb;
11465   level.bd_color_0 = cave->color0;
11466   level.bd_color_1 = cave->color1;
11467   level.bd_color_2 = cave->color2;
11468   level.bd_color_3 = cave->color3;
11469   level.bd_color_4 = cave->color4;
11470   level.bd_color_5 = cave->color5;
11471 }
11472
11473 static void DrawColorBox_BD(int nr)
11474 {
11475   int id = ED_SELECTBOX_ID_COLORS_FIRST + nr;
11476   struct GadgetInfo *gi = level_editor_gadget[selectbox_info[id].gadget_id];
11477   int graphic = IMG_EDITOR_CHECKBOX;
11478   struct GraphicInfo *gd = &graphic_info[graphic];
11479   int offset = ED_GADGET_TEXT_DISTANCE;
11480   int x1 = gi->x - offset - gd->width;
11481   int y1 = gi->y;
11482   int x2 = x1 + offset;
11483   int y2 = y1 + offset;
11484   int xsize1 = gd->width;
11485   int ysize1 = gd->height;
11486   int xsize2 = xsize1 - 2 * offset;
11487   int ysize2 = ysize1 - 2 * offset;
11488   int bd_color_x = *bd_color[nr];
11489   int r = gd_color_get_r(bd_color_x);
11490   int g = gd_color_get_g(bd_color_x);
11491   int b = gd_color_get_b(bd_color_x);
11492   Pixel color = SDL_MapRGB(drawto->surface->format, r, g, b);
11493
11494   BlitBitmap(gd->bitmap, drawto, gd->src_x, gd->src_y, xsize1, ysize1, x1, y1);
11495   FillRectangle(drawto, x2, y2, xsize2, ysize2, color);
11496 }
11497
11498 static void DrawEngineConfigColors(void)
11499 {
11500   int i;
11501
11502   if (bd_color_type_changed)
11503   {
11504     if (level.bd_color_type != GD_COLOR_TYPE_RGB && level.bd_color_type != GetCommonColorType_BD())
11505     {
11506       // color type switched to non-RGB colors, but using different color type => reset colors
11507
11508       if (level.bd_color_type == bd_color_type_default)
11509       {
11510         // color type switched to same color type as default colors => reset to defaults
11511         for (i = 0; i < MAX_BD_COLORS; i++)
11512           *bd_color[i] = bd_color_default[i];
11513       }
11514       else
11515       {
11516         // color type switched to different color type as default colors => use random colors
11517         SetRandomLevelColors_BD();
11518       }
11519     }
11520
11521     bd_color_type_changed = FALSE;
11522   }
11523
11524   // copy level colors to either C64-style color index or color text
11525   for (i = 0; i < MAX_BD_COLORS; i++)
11526   {
11527     int bd_color_x = (level.bd_color_type == GD_COLOR_TYPE_C64 ? *bd_color[i] & 0x0f :
11528                       level.bd_color_type == GD_COLOR_TYPE_RGB ? gd_color_get_rgb(*bd_color[i]) :
11529                       *bd_color[i]);
11530
11531     if (level.bd_color_type == GD_COLOR_TYPE_C64)
11532       bd_color_c64[i] = bd_color_x;
11533     else
11534       snprintf(bd_color_text[i], sizeof(bd_color_text[i]), "%s", gd_color_get_string(bd_color_x));
11535   }
11536
11537   MapSelectboxGadget(ED_SELECTBOX_ID_BD_COLOR_TYPE);
11538
11539   if (level.bd_color_type == GD_COLOR_TYPE_C64)
11540   {
11541     // draw selectbox gadgets
11542     for (i = ED_SELECTBOX_ID_COLORS_FIRST; i <= ED_SELECTBOX_ID_COLORS_LAST; i++)
11543       MapSelectboxGadget(i);
11544   }
11545   else
11546   {
11547     // draw text input gadgets
11548     for (i = ED_TEXTINPUT_ID_COLORS_FIRST; i <= ED_TEXTINPUT_ID_COLORS_LAST; i++)
11549       MapTextInputGadget(i);
11550   }
11551
11552   for (i = 0; i < MAX_BD_COLORS; i++)
11553     DrawColorBox_BD(i);
11554
11555   MapTextbuttonGadget(ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS);
11556 }
11557
11558 static void DrawLevelConfigEngine(void)
11559 {
11560   if (edit_mode_engineconfig == ED_MODE_ENGINECONFIG_CONFIG)
11561     DrawEngineConfigConfig();
11562   else if (edit_mode_engineconfig == ED_MODE_ENGINECONFIG_COLORS)
11563     DrawEngineConfigColors();
11564 }
11565
11566 static void DrawLevelConfigWindow(void)
11567 {
11568   char *text = "Global Settings";
11569   int font_nr = FONT_TITLE_1;
11570   struct MenuPosInfo *pos = &editor.settings.headline;
11571   int sx = SX + ALIGNED_XPOS(pos->x, getTextWidth(text, font_nr), pos->align);
11572   int sy = SY + pos->y;
11573
11574   stick_element_properties_window = FALSE;
11575
11576   SetAutomaticNumberOfGemsNeeded();
11577
11578   UnmapLevelEditorFieldGadgets();
11579
11580   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
11581   ClearField();
11582
11583   DrawText(sx, sy, text, font_nr);
11584
11585   DrawLevelConfigTabulatorGadgets();
11586
11587   if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_LEVEL)
11588     DrawLevelConfigLevel();
11589   else if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_LEVELSET)
11590     DrawLevelConfigLevelSet();
11591   else if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_EDITOR)
11592     DrawLevelConfigEditor();
11593   else if (edit_mode_levelconfig == ED_MODE_LEVELCONFIG_ENGINE)
11594     DrawLevelConfigEngine();
11595 }
11596
11597 static void DrawCustomContentArea(void)
11598 {
11599   int id = ED_DRAWING_ID_CUSTOM_CONTENT;
11600   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
11601   int x1 = right_gadget_border[GADGET_ID_CUSTOM_DEADLINESS];
11602   int x2 = right_gadget_border[GADGET_ID_CUSTOM_EXPLOSION_TYPE];
11603   int x3 = right_gadget_border[GADGET_ID_CUSTOM_EXPLODE_IMPACT];
11604   int xoffset = ED_GADGET_SPACE_DISTANCE;
11605
11606   // add distance for potential left text (without drawing area border)
11607   x2 += getTextWidthForGadget(drawingarea_info[id].text_left);
11608
11609   ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
11610
11611   MapDrawingArea(ED_DRAWING_ID_CUSTOM_CONTENT);
11612 }
11613
11614 static void DrawCustomChangeContentArea(void)
11615 {
11616   int id = ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT;
11617   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
11618   int x1 = right_gadget_border[GADGET_ID_CHANGE_USE_CONTENT];
11619   int x2 = right_gadget_border[GADGET_ID_CHANGE_REPLACE_WHEN];
11620   int x3 = right_gadget_border[GADGET_ID_CHANGE_ONLY_COMPLETE];
11621   int xoffset = ED_GADGET_SPACE_DISTANCE;
11622
11623   ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
11624
11625   MapDrawingArea(id);
11626 }
11627
11628 static void RemoveElementContentArea(int id, int font_height)
11629 {
11630   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11631
11632   DrawBackground(SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size,
11633                  SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size,
11634                  3 * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11635                  3 * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size +
11636                  ED_GADGET_TEXT_DISTANCE + font_height);
11637 }
11638
11639 static void DrawYamYamContentAreas(void)
11640 {
11641   int font_nr = FONT_TEXT_1;
11642   int font_height = getFontHeight(font_nr);
11643   int tilesize = ED_DRAWINGAREA_TILE_SIZE;
11644   int yoffset = (tilesize - font_height) / 2;
11645   int x = SX + ED_AREA_YAMYAM_CONTENT_X(3) + 4 * tilesize;
11646   int y = SY + ED_AREA_YAMYAM_CONTENT_Y(3) + yoffset;
11647   int i;
11648
11649   // display counter to choose number of element content areas
11650   MapCounterButtons(ED_COUNTER_ID_YAMYAM_CONTENT);
11651
11652   for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
11653   {
11654     int id = ED_DRAWING_ID_YAMYAM_CONTENT_0 + i;
11655
11656     if (i < level.num_yamyam_contents)
11657     {
11658       MapDrawingArea(id);
11659     }
11660     else
11661     {
11662       UnmapDrawingArea(id);
11663
11664       // delete content areas in case of reducing number of them
11665       RemoveElementContentArea(id, font_height);
11666     }
11667   }
11668
11669   DrawText(x, y + 0 * tilesize, "content", font_nr);
11670   DrawText(x, y + 1 * tilesize, "when",    font_nr);
11671   DrawText(x, y + 2 * tilesize, "smashed", font_nr);
11672 }
11673
11674 static void DrawMagicBallContentAreas(void)
11675 {
11676   int font_nr = FONT_TEXT_1;
11677   int font_height = getFontHeight(font_nr);
11678   int tilesize = ED_DRAWINGAREA_TILE_SIZE;
11679   int yoffset = (tilesize - font_height) / 2;
11680   int x = SX + ED_AREA_MAGIC_BALL_CONTENT_X(3) + 4 * tilesize;
11681   int y = SY + ED_AREA_MAGIC_BALL_CONTENT_Y(3) + yoffset;
11682   int i;
11683
11684   // display counter to choose number of element content areas
11685   MapCounterButtons(ED_COUNTER_ID_BALL_CONTENT);
11686
11687   for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
11688   {
11689     int id = ED_DRAWING_ID_MAGIC_BALL_CONTENT_0 + i;
11690
11691     if (i < level.num_ball_contents)
11692     {
11693       MapDrawingArea(id);
11694     }
11695     else
11696     {
11697       UnmapDrawingArea(id);
11698
11699       // delete content areas in case of reducing number of them
11700       RemoveElementContentArea(id, font_height);
11701     }
11702   }
11703
11704   DrawText(x, y + 0 * tilesize, "generated", font_nr);
11705   DrawText(x, y + 1 * tilesize, "when",      font_nr);
11706   DrawText(x, y + 2 * tilesize, "active",    font_nr);
11707 }
11708
11709 static void DrawAndroidElementArea(void)
11710 {
11711   int id = ED_DRAWING_ID_ANDROID_CONTENT;
11712   int num_elements = level.num_android_clone_elements;
11713   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11714   int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
11715   int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
11716   int xsize = MAX_ANDROID_ELEMENTS;
11717   int ysize = 1;
11718
11719   // display counter to choose number of element areas
11720   MapCounterButtons(ED_COUNTER_ID_ANDROID_CONTENT);
11721
11722   if (drawingarea_info[id].text_left != NULL)
11723     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
11724
11725   UnmapDrawingArea(id);
11726
11727   ModifyEditorDrawingArea(id, num_elements, 1);
11728
11729   // delete content areas in case of reducing number of them
11730   DrawBackground(sx, sy,
11731                  xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11732                  ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
11733
11734   MapDrawingArea(id);
11735 }
11736
11737 static void DrawGroupElementArea(void)
11738 {
11739   int id = ED_DRAWING_ID_GROUP_CONTENT;
11740   int num_elements = group_element_info.num_elements;
11741   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11742   int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
11743   int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
11744   int xsize = MAX_ELEMENTS_IN_GROUP;
11745   int ysize = 1;
11746
11747   if (drawingarea_info[id].text_left != NULL)
11748     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
11749
11750   UnmapDrawingArea(id);
11751
11752   ModifyEditorDrawingArea(id, num_elements, 1);
11753
11754   // delete content areas in case of reducing number of them
11755   DrawBackground(sx, sy,
11756                  xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11757                  ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
11758
11759   MapDrawingArea(id);
11760 }
11761
11762 static void DrawPlayerInitialInventoryArea(int element)
11763 {
11764   int id = ED_DRAWING_ID_INVENTORY_CONTENT;
11765   int player_nr = GET_PLAYER_NR(element);
11766   int num_elements = level.initial_inventory_size[player_nr];
11767   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11768   int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
11769   int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
11770   int xsize = MAX_INITIAL_INVENTORY_SIZE;
11771   int ysize = 1;
11772
11773   // determine horizontal position to the right of specified gadget
11774   if (drawingarea_info[id].gadget_id_align != GADGET_ID_NONE)
11775     sx = (right_gadget_border[drawingarea_info[id].gadget_id_align] +
11776           ED_DRAWINGAREA_TEXT_DISTANCE);
11777
11778   // determine horizontal offset for leading text
11779   if (drawingarea_info[id].text_left != NULL)
11780     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
11781
11782   UnmapDrawingArea(id);
11783
11784   ModifyEditorDrawingArea(id, num_elements, 1);
11785
11786   // delete content areas in case of reducing number of them
11787   DrawBackground(sx, sy,
11788                  xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11789                  ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
11790
11791   MapDrawingArea(id);
11792 }
11793
11794 static void DrawMMBallContentArea(void)
11795 {
11796   int id = ED_DRAWING_ID_MM_BALL_CONTENT;
11797   int num_elements = level.num_mm_ball_contents;
11798   int border_size = ED_DRAWINGAREA_BORDER_SIZE;
11799   int sx = SX + ED_AREA_SETTINGS_X(drawingarea_info[id]) - border_size;
11800   int sy = SY + ED_AREA_SETTINGS_Y(drawingarea_info[id]) - border_size;
11801   int xsize = MAX_MM_BALL_CONTENTS;
11802   int ysize = 1;
11803
11804   if (drawingarea_info[id].text_left != NULL)
11805     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
11806
11807   UnmapDrawingArea(id);
11808
11809   ModifyEditorDrawingArea(id, num_elements, 1);
11810
11811   // delete content areas in case of reducing number of them
11812   DrawBackground(sx, sy,
11813                  xsize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size,
11814                  ysize * ED_DRAWINGAREA_TILE_SIZE + 2 * border_size);
11815
11816   MapDrawingArea(id);
11817 }
11818
11819 static void DrawEnvelopeTextArea(int envelope_nr)
11820 {
11821   int id = ED_TEXTAREA_ID_ENVELOPE_INFO;
11822   struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
11823
11824   UnmapGadget(gi);
11825
11826   DrawBackground(gi->x, gi->y,
11827                  gi->textarea.crop_width, gi->textarea.crop_height);
11828
11829   if (envelope_nr != -1)
11830     textarea_info[id].value = level.envelope[envelope_nr].text;
11831
11832   ModifyGadget(gi, GDI_AREA_SIZE,
11833                *counterbutton_info[ED_COUNTER_ID_ENVELOPE_XSIZE].value,
11834                *counterbutton_info[ED_COUNTER_ID_ENVELOPE_YSIZE].value,
11835                GDI_END);
11836
11837   MapTextAreaGadget(ED_TEXTAREA_ID_ENVELOPE_INFO);
11838 }
11839
11840 static void DrawPropertiesInfo(void)
11841 {
11842   static struct
11843   {
11844     int value;
11845     char *text;
11846   }
11847   properties[] =
11848   {
11849     // configurable properties
11850
11851     { EP_WALKABLE_OVER,         "- player can walk over it"             },
11852     { EP_WALKABLE_INSIDE,       "- player can walk inside it"           },
11853     { EP_WALKABLE_UNDER,        "- player can walk under it"            },
11854     { EP_PASSABLE_OVER,         "- player can pass over it"             },
11855     { EP_PASSABLE_INSIDE,       "- player can pass through it"          },
11856     { EP_PASSABLE_UNDER,        "- player can pass under it"            },
11857     { EP_PROTECTED,             "- player is protected by it"           },
11858
11859     { EP_DIGGABLE,              "- can be digged away"                  },
11860     { EP_COLLECTIBLE,           "- can be collected"                    },
11861     { EP_DROPPABLE,             "- can be dropped after collecting"     },
11862     { EP_THROWABLE,             "- can be thrown after collecting"      },
11863     { EP_PUSHABLE,              "- can be pushed"                       },
11864
11865     { EP_CAN_FALL,              "- can fall"                            },
11866     { EP_CAN_MOVE,              "- can move"                            },
11867
11868     { EP_CAN_SMASH_PLAYER,      "- can smash player"                    },
11869 #if 0
11870     { EP_CAN_SMASH_ENEMIES,     "- can smash good and bad guys"         },
11871 #endif
11872     { EP_CAN_SMASH_EVERYTHING,  "- can smash everything smashable"      },
11873
11874     { EP_SLIPPERY,              "- slippery for falling elements"       },
11875     { EP_EM_SLIPPERY_WALL,      "- slippery for some gems (EM style)"   },
11876
11877     { EP_DONT_RUN_INTO,         "- deadly when running into"            },
11878     { EP_DONT_COLLIDE_WITH,     "- deadly when colliding with"          },
11879     { EP_DONT_GET_HIT_BY,       "- deadly when getting hit by"          },
11880     { EP_DONT_TOUCH,            "- deadly when touching"                },
11881
11882     { EP_INDESTRUCTIBLE,        "- indestructible"                      },
11883
11884     { EP_CAN_EXPLODE_BY_FIRE,   "- can explode by fire or explosions"   },
11885     { EP_CAN_EXPLODE_SMASHED,   "- can explode when smashed"            },
11886     { EP_CAN_EXPLODE_IMPACT,    "- can explode on impact"               },
11887
11888     { EP_CAN_CHANGE,            "- can change to other element"         },
11889
11890     // pre-defined properties
11891     { EP_CAN_PASS_MAGIC_WALL,   "- can pass magic walls"                },
11892     { EP_CAN_PASS_DC_MAGIC_WALL,"- can pass magic walls (DC style)"     },
11893     { EP_SWITCHABLE,            "- can be switched"                     },
11894 #if 0
11895     { EP_HAS_EDITOR_CONTENT,    "- can contain other elements"          },
11896 #endif
11897
11898     { -1,                       NULL                                    }
11899   };
11900   char *filename = getElementDescriptionFilename(properties_element);
11901   char *num_elements_text = "In this level: ";
11902   char *num_similar_text = "Similar tiles: ";
11903   char *properties_text = "Standard properties: ";
11904   char *description_text = "Description:";
11905   char *no_description_text = "No description available.";
11906   char *none_text = "None";
11907   float percentage;
11908   int num_elements_in_level = 0;
11909   int num_similar_in_level = 0;
11910   int num_hires_tiles_in_level = 0;
11911   int num_standard_properties = 0;
11912   int font1_nr = FONT_TEXT_1;
11913   int font2_nr = FONT_TEXT_2;
11914   int font1_width = getFontWidth(font1_nr);
11915   int font1_height = getFontHeight(font1_nr);
11916   int font2_height = getFontHeight(font2_nr);
11917   int line1_height = font1_height + ED_GADGET_LINE_DISTANCE;
11918   int font2_yoffset = (font1_height - font2_height) / 2;
11919   int num_elements_text_len = strlen(num_elements_text) * font1_width;
11920   int num_similar_text_len = strlen(num_similar_text) * font1_width;
11921   int properties_text_len = strlen(properties_text) * font1_width;
11922   int xpos = ED_ELEMENT_SETTINGS_X(0);
11923   int ypos = ED_ELEMENT_SETTINGS_Y(0) + ED_GADGET_SMALL_DISTANCE;
11924   int i, x, y;
11925
11926   if (setup.editor.show_element_token)
11927   {
11928     int font3_nr = FONT_TEXT_3;
11929     int font3_height = getFontHeight(font3_nr);
11930
11931     DrawTextF(xpos, ypos, font3_nr,
11932               "[%s]", element_info[properties_element].token_name);
11933
11934     ypos += 2 * font3_height;
11935   }
11936
11937   // ----- print number of elements / percentage of this element in level
11938
11939   for (y = 0; y < lev_fieldy; y++)
11940   {
11941     for (x = 0; x < lev_fieldx; x++)
11942     {
11943       if (Tile[x][y] == properties_element)
11944       {
11945         num_elements_in_level++;
11946       }
11947       else if (IS_MM_WALL(Tile[x][y]) &&
11948                map_mm_wall_element(Tile[x][y]) == properties_element)
11949       {
11950         num_hires_tiles_in_level += numHiresTiles(Tile[x][y]);
11951       }
11952     }
11953   }
11954
11955   percentage = num_elements_in_level * 100.0 / (lev_fieldx * lev_fieldy);
11956
11957   DrawTextS(xpos, ypos, font1_nr, num_elements_text);
11958
11959   if (num_hires_tiles_in_level > 0)
11960     DrawTextF(xpos + num_elements_text_len, ypos + font2_yoffset, font2_nr,
11961               "%d wall tiles", num_hires_tiles_in_level);
11962   else if (num_elements_in_level > 0)
11963     DrawTextF(xpos + num_elements_text_len, ypos + font2_yoffset, font2_nr,
11964               "%d (%.2f %%)", num_elements_in_level, percentage);
11965   else
11966     DrawTextF(xpos + num_elements_text_len, ypos + font2_yoffset, font2_nr,
11967               none_text);
11968
11969   // ----- print number of similar elements / percentage of them in level
11970
11971   for (y = 0; y < lev_fieldy; y++)
11972   {
11973     for (x = 0; x < lev_fieldx; x++)
11974     {
11975       if (strEqual(element_info[Tile[x][y]].class_name,
11976                    element_info[properties_element].class_name))
11977       {
11978         num_similar_in_level++;
11979       }
11980     }
11981   }
11982
11983   if (num_similar_in_level != num_elements_in_level)
11984   {
11985     ypos += 1 * MAX(font1_height, font2_height);
11986
11987     percentage = num_similar_in_level * 100.0 / (lev_fieldx * lev_fieldy);
11988
11989     DrawTextS(xpos, ypos, font1_nr, num_similar_text);
11990
11991     if (num_similar_in_level > 0)
11992       DrawTextF(xpos + num_similar_text_len, ypos + font2_yoffset, font2_nr,
11993                 "%d (%.2f %%)", num_similar_in_level, percentage);
11994     else
11995       DrawTextF(xpos + num_similar_text_len, ypos + font2_yoffset, font2_nr,
11996                 none_text);
11997   }
11998
11999   ypos += 2 * MAX(font1_height, font2_height);
12000
12001   // ----- print standard properties of this element
12002
12003   DrawTextS(xpos, ypos, font1_nr, properties_text);
12004
12005   ypos += line1_height;
12006
12007   for (i = 0; properties[i].value != -1; i++)
12008   {
12009     if (!HAS_PROPERTY(properties_element, properties[i].value))
12010       continue;
12011
12012     DrawTextS(xpos, ypos, font2_nr, properties[i].text);
12013
12014     ypos += font2_height;
12015
12016     num_standard_properties++;
12017   }
12018
12019   if (num_standard_properties == 0)
12020   {
12021     DrawTextS(xpos + properties_text_len, ypos - line1_height + font2_yoffset,
12022               font2_nr, none_text);
12023
12024     ypos -= (line1_height - font1_height);
12025   }
12026
12027   ypos += MAX(font1_height, font2_height);
12028
12029   // ----- print special description of this element
12030
12031   PrintInfoText(description_text, font1_nr, xpos, ypos);
12032
12033   ypos += line1_height;
12034
12035   if (PrintElementDescriptionFromFile(filename, font2_nr, xpos, ypos) == 0)
12036     PrintInfoText(no_description_text, font1_nr, xpos, ypos - line1_height);
12037 }
12038
12039 #define TEXT_COLLECTING                 "Score for collecting"
12040 #define TEXT_COLLECTING_EXTRA           "Score for extra diamonds"
12041 #define TEXT_SMASHING                   "Score for smashing"
12042 #define TEXT_SLURPING                   "Score for slurping robot"
12043 #define TEXT_CRACKING                   "Score for cracking"
12044 #define TEXT_AMOEBA_SPEED               "Speed of amoeba growth"
12045 #define TEXT_AMOEBA_THRESHOED           "Size for turning to rocks"
12046 #define TEXT_AMOEBA_SLOW_TIME           "Slow growth time (seconds)"
12047 #define TEXT_AMOEBA_SLOW_RATE           "Slow growth rate (percent)"
12048 #define TEXT_AMOEBA_FAST_RATE           "Fast growth rate (percent)"
12049 #define TEXT_DURATION                   "Duration when activated"
12050 #define TEXT_DELAY_ON                   "Delay before activating"
12051 #define TEXT_DELAY_OFF                  "Delay before deactivating"
12052 #define TEXT_DELAY_CHANGING             "Delay before changing"
12053 #define TEXT_DELAY_EXPLODING            "Delay before exploding"
12054 #define TEXT_DELAY_MOVING               "Delay before moving"
12055 #define TEXT_BALL_DELAY                 "Element generation delay"
12056 #define TEXT_MOVE_SPEED                 "Speed of android moving"
12057 #define TEXT_CLONE_SPEED                "Speed of android cloning"
12058 #define TEXT_GAME_OF_LIFE_1             "Min neighbours to survive"
12059 #define TEXT_GAME_OF_LIFE_2             "Max neighbours to survive"
12060 #define TEXT_GAME_OF_LIFE_3             "Min neighbours to create"
12061 #define TEXT_GAME_OF_LIFE_4             "Max neighbours to create"
12062 #define TEXT_TIME_BONUS                 "Extra time to solve level"
12063 #define TEXT_TIME_PENALTY               "Time penalty if destroyed"
12064 #define TEXT_PERMEABILITY_RATE          "slime permeability rate"
12065 #define TEXT_PERMEABILITY_BITS          "slime permeability bits"
12066 #define TEXT_RANDOM_SEED                "slime random number seed"
12067 #define TEXT_ACID_SPREAD_RATE           "Spread rate (percent)"
12068 #define TEXT_BITER_MOVE_DELAY           "Move delay (BD frames)"
12069 #define TEXT_REPLICATION_DELAY          "Create delay (BD frames)"
12070 #define TEXT_HAMMER_BREAK_DELAY         "Delay for breaking walls"
12071 #define TEXT_HAMMER_REAPPEAR_DELAY      "Delay for reappearing walls"
12072 #define TEXT_SKELETONS_NEEDED           "Skeletons needed to use pot"
12073 #define TEXT_SKELETONS_WORTH            "Counts as this many diamonds"
12074 #define TEXT_AUTO_TURN_DELAY            "Creatures auto turn delay"
12075 #define TEXT_GRAVITY_DELAY              "Gravity switch change delay"
12076
12077 static struct
12078 {
12079   int element;
12080   int *value;
12081   char *text;
12082   int min_value;
12083   int max_value;
12084 } elements_with_counter[] =
12085 {
12086   { EL_EMERALD,                 &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12087   { EL_BD_DIAMOND,              &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12088   { EL_BD_DIAMOND,              &level.score[SC_DIAMOND_EXTRA],         TEXT_COLLECTING_EXTRA   },
12089   { EL_EMERALD_YELLOW,          &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12090   { EL_EMERALD_RED,             &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12091   { EL_EMERALD_PURPLE,          &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12092   { EL_SP_INFOTRON,             &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12093   { EL_DIAMOND,                 &level.score[SC_DIAMOND],               TEXT_COLLECTING         },
12094   { EL_CRYSTAL,                 &level.score[SC_CRYSTAL],               TEXT_COLLECTING         },
12095   { EL_PEARL,                   &level.score[SC_PEARL],                 TEXT_COLLECTING         },
12096   { EL_BUG,                     &level.score[SC_BUG],                   TEXT_SMASHING           },
12097   { EL_BUG_RIGHT,               &level.score[SC_BUG],                   TEXT_SMASHING           },
12098   { EL_BUG_UP,                  &level.score[SC_BUG],                   TEXT_SMASHING           },
12099   { EL_BUG_LEFT,                &level.score[SC_BUG],                   TEXT_SMASHING           },
12100   { EL_BUG_DOWN,                &level.score[SC_BUG],                   TEXT_SMASHING           },
12101   { EL_BD_BUTTERFLY,            &level.score[SC_BUG],                   TEXT_SMASHING           },
12102   { EL_BD_BUTTERFLY_RIGHT,      &level.score[SC_BUG],                   TEXT_SMASHING           },
12103   { EL_BD_BUTTERFLY_UP,         &level.score[SC_BUG],                   TEXT_SMASHING           },
12104   { EL_BD_BUTTERFLY_LEFT,       &level.score[SC_BUG],                   TEXT_SMASHING           },
12105   { EL_BD_BUTTERFLY_DOWN,       &level.score[SC_BUG],                   TEXT_SMASHING           },
12106   { EL_SP_ELECTRON,             &level.score[SC_BUG],                   TEXT_SMASHING           },
12107   { EL_SPACESHIP,               &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12108   { EL_SPACESHIP_RIGHT,         &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12109   { EL_SPACESHIP_UP,            &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12110   { EL_SPACESHIP_LEFT,          &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12111   { EL_SPACESHIP_DOWN,          &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12112   { EL_BD_FIREFLY,              &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12113   { EL_BD_FIREFLY_RIGHT,        &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12114   { EL_BD_FIREFLY_UP,           &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12115   { EL_BD_FIREFLY_LEFT,         &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12116   { EL_BD_FIREFLY_DOWN,         &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12117   { EL_SP_SNIKSNAK,             &level.score[SC_SPACESHIP],             TEXT_SMASHING           },
12118   { EL_YAMYAM,                  &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12119   { EL_YAMYAM_LEFT,             &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12120   { EL_YAMYAM_RIGHT,            &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12121   { EL_YAMYAM_UP,               &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12122   { EL_YAMYAM_DOWN,             &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12123   { EL_DARK_YAMYAM,             &level.score[SC_YAMYAM],                TEXT_SMASHING           },
12124   { EL_ROBOT,                   &level.score[SC_ROBOT],                 TEXT_SMASHING           },
12125   { EL_PACMAN,                  &level.score[SC_PACMAN],                TEXT_SMASHING           },
12126   { EL_PACMAN_RIGHT,            &level.score[SC_PACMAN],                TEXT_SMASHING           },
12127   { EL_PACMAN_UP,               &level.score[SC_PACMAN],                TEXT_SMASHING           },
12128   { EL_PACMAN_LEFT,             &level.score[SC_PACMAN],                TEXT_SMASHING           },
12129   { EL_PACMAN_DOWN,             &level.score[SC_PACMAN],                TEXT_SMASHING           },
12130   { EL_NUT,                     &level.score[SC_NUT],                   TEXT_CRACKING           },
12131   { EL_DYNAMITE,                &level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12132   { EL_EM_DYNAMITE,             &level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12133   { EL_DYNABOMB_INCREASE_NUMBER,&level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12134   { EL_DYNABOMB_INCREASE_SIZE,  &level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12135   { EL_DYNABOMB_INCREASE_POWER, &level.score[SC_DYNAMITE],              TEXT_COLLECTING         },
12136   { EL_SHIELD_NORMAL,           &level.score[SC_SHIELD],                TEXT_COLLECTING         },
12137   { EL_SHIELD_DEADLY,           &level.score[SC_SHIELD],                TEXT_COLLECTING         },
12138   { EL_EXTRA_TIME,              &level.extra_time_score,                TEXT_COLLECTING         },
12139   { EL_KEY_1,                   &level.score[SC_KEY],                   TEXT_COLLECTING         },
12140   { EL_KEY_2,                   &level.score[SC_KEY],                   TEXT_COLLECTING         },
12141   { EL_KEY_3,                   &level.score[SC_KEY],                   TEXT_COLLECTING         },
12142   { EL_KEY_4,                   &level.score[SC_KEY],                   TEXT_COLLECTING         },
12143   { EL_EM_KEY_1,                &level.score[SC_KEY],                   TEXT_COLLECTING         },
12144   { EL_EM_KEY_2,                &level.score[SC_KEY],                   TEXT_COLLECTING         },
12145   { EL_EM_KEY_3,                &level.score[SC_KEY],                   TEXT_COLLECTING         },
12146   { EL_EM_KEY_4,                &level.score[SC_KEY],                   TEXT_COLLECTING         },
12147   { EL_EMC_KEY_5,               &level.score[SC_KEY],                   TEXT_COLLECTING         },
12148   { EL_EMC_KEY_6,               &level.score[SC_KEY],                   TEXT_COLLECTING         },
12149   { EL_EMC_KEY_7,               &level.score[SC_KEY],                   TEXT_COLLECTING         },
12150   { EL_EMC_KEY_8,               &level.score[SC_KEY],                   TEXT_COLLECTING         },
12151   { EL_DC_KEY_WHITE,            &level.score[SC_KEY],                   TEXT_COLLECTING         },
12152   { EL_MM_KETTLE,               &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12153   { EL_DF_CELL,                 &level.score[SC_EMERALD],               TEXT_COLLECTING         },
12154   { EL_MM_KEY,                  &level.score[SC_KEY],                   TEXT_COLLECTING         },
12155   { EL_MM_LIGHTBALL,            &level.score[SC_ELEM_BONUS],            TEXT_COLLECTING         },
12156   { EL_MM_PACMAN,               &level.score[SC_PACMAN],                TEXT_SMASHING           },
12157   { EL_MM_PACMAN_RIGHT,         &level.score[SC_PACMAN],                TEXT_SMASHING           },
12158   { EL_MM_PACMAN_UP,            &level.score[SC_PACMAN],                TEXT_SMASHING           },
12159   { EL_MM_PACMAN_LEFT,          &level.score[SC_PACMAN],                TEXT_SMASHING           },
12160   { EL_MM_PACMAN_DOWN,          &level.score[SC_PACMAN],                TEXT_SMASHING           },
12161   { EL_AMOEBA_WET,              &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12162   { EL_AMOEBA_DRY,              &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12163   { EL_AMOEBA_FULL,             &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12164   { EL_BD_AMOEBA,               &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12165   { EL_EMC_DRIPPER,             &level.amoeba_speed,                    TEXT_AMOEBA_SPEED       },
12166   { EL_BD_AMOEBA,               &level.bd_amoeba_threshold_too_big,     TEXT_AMOEBA_THRESHOED   },
12167   { EL_BD_AMOEBA,               &level.bd_amoeba_slow_growth_time,      TEXT_AMOEBA_SLOW_TIME   },
12168   { EL_BD_AMOEBA,               &level.bd_amoeba_slow_growth_rate,      TEXT_AMOEBA_SLOW_RATE,
12169                                 0, 100                                                          },
12170   { EL_BD_AMOEBA,               &level.bd_amoeba_fast_growth_rate,      TEXT_AMOEBA_FAST_RATE,
12171                                 0, 100                                                          },
12172   { EL_BD_AMOEBA_2,             &level.bd_amoeba_2_threshold_too_big,   TEXT_AMOEBA_THRESHOED   },
12173   { EL_BD_AMOEBA_2,             &level.bd_amoeba_2_slow_growth_time,    TEXT_AMOEBA_SLOW_TIME   },
12174   { EL_BD_AMOEBA_2,             &level.bd_amoeba_2_slow_growth_rate,    TEXT_AMOEBA_SLOW_RATE,
12175                                 0, 100                                                          },
12176   { EL_BD_AMOEBA_2,             &level.bd_amoeba_2_fast_growth_rate,    TEXT_AMOEBA_FAST_RATE,
12177                                 0, 100                                                          },
12178   { EL_MAGIC_WALL,              &level.time_magic_wall,                 TEXT_DURATION           },
12179   { EL_BD_MAGIC_WALL,           &level.time_magic_wall,                 TEXT_DURATION           },
12180   { EL_DC_MAGIC_WALL,           &level.time_magic_wall,                 TEXT_DURATION           },
12181   { EL_ROBOT_WHEEL,             &level.time_wheel,                      TEXT_DURATION           },
12182   { EL_TIMEGATE_SWITCH,         &level.time_timegate,                   TEXT_DURATION           },
12183   { EL_DC_TIMEGATE_SWITCH,      &level.time_timegate,                   TEXT_DURATION           },
12184   { EL_LIGHT_SWITCH,            &level.time_light,                      TEXT_DURATION           },
12185   { EL_LIGHT_SWITCH_ACTIVE,     &level.time_light,                      TEXT_DURATION           },
12186   { EL_SHIELD_NORMAL,           &level.shield_normal_time,              TEXT_DURATION           },
12187   { EL_SHIELD_DEADLY,           &level.shield_deadly_time,              TEXT_DURATION           },
12188   { EL_BD_CLOCK,                &level.bd_clock_extra_time,             TEXT_TIME_BONUS,
12189                                 -100, 100                                                       },
12190   { EL_BD_VOODOO_DOLL,          &level.bd_voodoo_penalty_time,          TEXT_TIME_PENALTY,
12191                                 0, 100                                                          },
12192   { EL_BD_SLIME,                &level.bd_slime_permeability_rate,      TEXT_PERMEABILITY_RATE,
12193                                 0, 100                                                          },
12194   { EL_BD_SLIME,                &level.bd_slime_permeability_bits_c64,  TEXT_PERMEABILITY_BITS,
12195                                 0, 255                                                          },
12196   { EL_BD_SLIME,                &level.bd_slime_random_seed_c64,        TEXT_RANDOM_SEED,
12197                                 -1, 65535                                                       },
12198   { EL_BD_ACID,                 &level.bd_acid_spread_rate,             TEXT_ACID_SPREAD_RATE,
12199                                 0, 100                                                          },
12200   { EL_BD_BITER,                &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12201                                 0, 3                                                            },
12202   { EL_BD_BITER_RIGHT,          &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12203                                 0, 3                                                            },
12204   { EL_BD_BITER_UP,             &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12205                                 0, 3                                                            },
12206   { EL_BD_BITER_LEFT,           &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12207                                 0, 3                                                            },
12208   { EL_BD_BITER_DOWN,           &level.bd_biter_move_delay,             TEXT_BITER_MOVE_DELAY,
12209                                 0, 3                                                            },
12210   { EL_BD_REPLICATOR,           &level.bd_replicator_create_delay,      TEXT_REPLICATION_DELAY,
12211                                 0, 100                                                          },
12212   { EL_BD_PNEUMATIC_HAMMER,     &level.bd_hammer_walls_break_delay,     TEXT_HAMMER_BREAK_DELAY,
12213                                 1, 100                                                          },
12214   { EL_BD_PNEUMATIC_HAMMER,     &level.bd_hammer_walls_reappear_delay,  TEXT_HAMMER_REAPPEAR_DELAY,
12215                                 1, 200                                                          },
12216   { EL_BD_POT,                  &level.bd_num_skeletons_needed_for_pot, TEXT_SKELETONS_NEEDED,
12217                                 0, 50                                                           },
12218   { EL_BD_SKELETON,             &level.bd_num_skeletons_needed_for_pot, TEXT_SKELETONS_NEEDED,
12219                                 0, 50                                                           },
12220   { EL_BD_SKELETON,             &level.bd_skeleton_worth_num_diamonds,  TEXT_SKELETONS_WORTH,
12221                                 0, 10                                                           },
12222   { EL_BD_CREATURE_SWITCH,      &level.bd_creatures_auto_turn_delay,    TEXT_AUTO_TURN_DELAY    },
12223   { EL_BD_GRAVITY_SWITCH,       &level.bd_gravity_switch_delay,         TEXT_GRAVITY_DELAY,
12224                                 1, 60                                                           },
12225   { EL_EXTRA_TIME,              &level.extra_time,                      TEXT_TIME_BONUS         },
12226   { EL_TIME_ORB_FULL,           &level.time_orb_time,                   TEXT_TIME_BONUS         },
12227   { EL_GAME_OF_LIFE,            &level.game_of_life[0],                 TEXT_GAME_OF_LIFE_1,0,8 },
12228   { EL_GAME_OF_LIFE,            &level.game_of_life[1],                 TEXT_GAME_OF_LIFE_2,0,8 },
12229   { EL_GAME_OF_LIFE,            &level.game_of_life[2],                 TEXT_GAME_OF_LIFE_3,0,8 },
12230   { EL_GAME_OF_LIFE,            &level.game_of_life[3],                 TEXT_GAME_OF_LIFE_4,0,8 },
12231   { EL_BIOMAZE,                 &level.biomaze[0],                      TEXT_GAME_OF_LIFE_1,0,8 },
12232   { EL_BIOMAZE,                 &level.biomaze[1],                      TEXT_GAME_OF_LIFE_2,0,8 },
12233   { EL_BIOMAZE,                 &level.biomaze[2],                      TEXT_GAME_OF_LIFE_3,0,8 },
12234   { EL_BIOMAZE,                 &level.biomaze[3],                      TEXT_GAME_OF_LIFE_4,0,8 },
12235   { EL_EMC_ANDROID,             &level.android_move_time,               TEXT_MOVE_SPEED         },
12236   { EL_EMC_ANDROID,             &level.android_clone_time,              TEXT_CLONE_SPEED        },
12237   { EL_EMC_MAGIC_BALL,          &level.ball_time,                       TEXT_BALL_DELAY         },
12238   { EL_EMC_LENSES,              &level.lenses_score,                    TEXT_COLLECTING         },
12239   { EL_EMC_MAGNIFIER,           &level.magnify_score,                   TEXT_COLLECTING         },
12240   { EL_SPRING,                  &level.slurp_score,                     TEXT_SLURPING           },
12241   { EL_SPRING_LEFT,             &level.slurp_score,                     TEXT_SLURPING           },
12242   { EL_SPRING_RIGHT,            &level.slurp_score,                     TEXT_SLURPING           },
12243   { EL_EMC_LENSES,              &level.lenses_time,                     TEXT_DURATION           },
12244   { EL_EMC_MAGNIFIER,           &level.magnify_time,                    TEXT_DURATION           },
12245   { EL_MM_FUSE_ACTIVE,          &level.mm_time_fuse,                    TEXT_DELAY_OFF          },
12246   { EL_MM_BOMB,                 &level.mm_time_bomb,                    TEXT_DELAY_EXPLODING    },
12247   { EL_MM_GRAY_BALL,            &level.mm_time_ball,                    TEXT_DELAY_CHANGING     },
12248   { EL_MM_STEEL_BLOCK,          &level.mm_time_block,                   TEXT_DELAY_MOVING       },
12249   { EL_MM_WOODEN_BLOCK,         &level.mm_time_block,                   TEXT_DELAY_MOVING       },
12250
12251   { -1,                         NULL,                                   NULL                    }
12252 };
12253
12254 static boolean checkPropertiesConfig(int element)
12255 {
12256   int i;
12257
12258   // special case: empty space customization only available in R'n'D game engine
12259   if (element == EL_EMPTY_SPACE && level.game_engine_type != GAME_ENGINE_TYPE_RND)
12260     return FALSE;
12261
12262   // special case: BD style rock customization only available in BD game engine
12263   if (element == EL_BD_ROCK && level.game_engine_type != GAME_ENGINE_TYPE_BD)
12264     return FALSE;
12265
12266   if (IS_GEM(element) ||
12267       IS_CUSTOM_ELEMENT(element) ||
12268       IS_GROUP_ELEMENT(element) ||
12269       IS_EMPTY_ELEMENT(element) ||
12270       IS_BALLOON_ELEMENT(element) ||
12271       IS_ENVELOPE(element) ||
12272       IS_MM_ENVELOPE(element) ||
12273       IS_MM_MCDUFFIN(element) ||
12274       IS_DF_LASER(element) ||
12275       IS_PLAYER_ELEMENT(element) ||
12276       IS_BD_PLAYER_ELEMENT(element) ||
12277       IS_BD_FIREFLY(properties_element) ||
12278       IS_BD_FIREFLY_2(properties_element) ||
12279       IS_BD_BUTTERFLY(properties_element) ||
12280       IS_BD_BUTTERFLY_2(properties_element) ||
12281       IS_BD_STONEFLY(properties_element) ||
12282       IS_BD_DRAGONFLY(properties_element) ||
12283       IS_BD_EXPANDABLE_WALL(properties_element) ||
12284       IS_BD_EXPANDABLE_STEELWALL(properties_element) ||
12285       IS_BD_CONVEYOR_BELT(properties_element) ||
12286       IS_BD_CONVEYOR_BELT_SWITCH(properties_element) ||
12287       IS_SOKOBAN_OBJECT_OR_FIELD(element) ||
12288       HAS_EDITOR_CONTENT(element) ||
12289       CAN_GROW(element) ||
12290       COULD_MOVE_INTO_ACID(element) ||
12291       MAYBE_DONT_COLLIDE_WITH(element) ||
12292       element == EL_BD_SAND ||
12293       element == EL_BD_ROCK ||
12294       element == EL_BD_MEGA_ROCK ||
12295       element == EL_BD_BOMB ||
12296       element == EL_BD_ROCKET_LAUNCHER ||
12297       element == EL_BD_NITRO_PACK ||
12298       element == EL_BD_SWEET ||
12299       element == EL_BD_VOODOO_DOLL ||
12300       element == EL_BD_WATER ||
12301       element == EL_BD_GRAVITY_SWITCH)
12302   {
12303     return TRUE;
12304   }
12305   else
12306   {
12307     for (i = 0; elements_with_counter[i].element != -1; i++)
12308       if (elements_with_counter[i].element == element)
12309         return TRUE;
12310   }
12311
12312   return FALSE;
12313 }
12314
12315 static void SetAutomaticNumberOfGemsNeeded(void)
12316 {
12317   int x, y;
12318
12319   if (!level.auto_count_gems)
12320     return;
12321
12322   level.gems_needed = 0;
12323
12324   for (x = 0; x < lev_fieldx; x++)
12325   {
12326     for (y = 0; y < lev_fieldy; y++)
12327     {
12328       int element = Tile[x][y];
12329
12330       switch (element)
12331       {
12332         case EL_EMERALD:
12333         case EL_EMERALD_YELLOW:
12334         case EL_EMERALD_RED:
12335         case EL_EMERALD_PURPLE:
12336         case EL_BD_DIAMOND:
12337         case EL_WALL_EMERALD:
12338         case EL_WALL_EMERALD_YELLOW:
12339         case EL_WALL_EMERALD_RED:
12340         case EL_WALL_EMERALD_PURPLE:
12341         case EL_WALL_BD_DIAMOND:
12342         case EL_NUT:
12343         case EL_SP_INFOTRON:
12344         case EL_MM_KETTLE:
12345         case EL_DF_CELL:
12346           level.gems_needed++;
12347           break;
12348
12349         case EL_DIAMOND:
12350         case EL_WALL_DIAMOND:
12351           level.gems_needed += 3;
12352           break;
12353
12354         case EL_PEARL:
12355         case EL_WALL_PEARL:
12356           level.gems_needed += 5;
12357           break;
12358
12359         case EL_CRYSTAL:
12360         case EL_WALL_CRYSTAL:
12361           level.gems_needed += 8;
12362           break;
12363
12364         default:
12365           break;
12366       }
12367     }
12368   }
12369
12370   ModifyEditorCounterValue(ED_COUNTER_ID_LEVEL_GEMSLIMIT, level.gems_needed);
12371 }
12372
12373 static void DrawPropertiesConfig(void)
12374 {
12375   boolean draw_footer_line = FALSE;
12376   int max_num_element_counters = 4;
12377   int num_element_counters = 0;
12378   int i;
12379
12380   if (!checkPropertiesConfig(properties_element))
12381   {
12382     int xpos = ED_ELEMENT_SETTINGS_X(0);
12383     int ypos = ED_ELEMENT_SETTINGS_Y(0) + ED_GADGET_SMALL_DISTANCE;
12384
12385     PrintInfoText("No configuration options available.", FONT_TEXT_1, xpos, ypos);
12386
12387     return;
12388   }
12389
12390   // check if there are elements where a value can be chosen for
12391   for (i = 0; elements_with_counter[i].element != -1; i++)
12392   {
12393     if (elements_with_counter[i].element != properties_element)
12394       continue;
12395
12396     // special case: score for extra diamonds only available in BD game engine
12397     if (elements_with_counter[i].element == EL_BD_DIAMOND &&
12398         elements_with_counter[i].value == &level.score[SC_DIAMOND_EXTRA] &&
12399         level.game_engine_type != GAME_ENGINE_TYPE_BD)
12400       continue;
12401
12402     // special case: some amoeba counters only available in BD game engine
12403     if (elements_with_counter[i].element == EL_BD_AMOEBA &&
12404         elements_with_counter[i].value != &level.amoeba_speed &&
12405         level.game_engine_type != GAME_ENGINE_TYPE_BD)
12406       continue;
12407
12408     // special case: score for smashing only available in R'n'D game engine
12409     if ((IS_BD_FIREFLY(elements_with_counter[i].element) ||
12410          IS_BD_BUTTERFLY(elements_with_counter[i].element)) &&
12411         (elements_with_counter[i].value == &level.score[SC_BUG] ||
12412          elements_with_counter[i].value == &level.score[SC_SPACESHIP]) &&
12413         level.game_engine_type == GAME_ENGINE_TYPE_BD)
12414       continue;
12415
12416     // special case: some amoeba counters only available in R'n'D game engine
12417     if (elements_with_counter[i].element == EL_BD_AMOEBA &&
12418         elements_with_counter[i].value == &level.amoeba_speed &&
12419         level.game_engine_type == GAME_ENGINE_TYPE_BD)
12420       continue;
12421
12422     int counter_id = ED_COUNTER_ID_ELEMENT_VALUE1 + num_element_counters;
12423
12424     counterbutton_info[counter_id].y =
12425       ED_ELEMENT_SETTINGS_YPOS((HAS_EDITOR_CONTENT(properties_element)      ? 1 : 0) +
12426                                (CAN_GROW(properties_element)                ? 1 : 0) +
12427                                (COULD_MOVE_INTO_ACID(properties_element)    ? 1 : 0) +
12428                                (MAYBE_DONT_COLLIDE_WITH(properties_element) ? 1 : 0) +
12429                                (properties_element == EL_BD_VOODOO_DOLL     ? 4 : 0) +
12430                                (properties_element == EL_BD_SLIME           ? 1 : 0) +
12431                                (properties_element == EL_BD_ACID            ? 1 : 0) +
12432                                (properties_element == EL_BD_REPLICATOR      ? 1 : 0) +
12433                                (properties_element == EL_BD_CREATURE_SWITCH ? 1 : 0) +
12434                                (properties_element == EL_BD_GRAVITY_SWITCH  ? 2 : 0) +
12435                                (properties_element == EL_EMC_MAGIC_BALL     ? 2 : 0) +
12436                                num_element_counters);
12437
12438     // special case: set magic wall counter for BD game engine separately
12439     if (properties_element == EL_BD_MAGIC_WALL && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12440       counterbutton_info[counter_id].y = ED_ELEMENT_SETTINGS_YPOS(1);
12441
12442     // special case: set amoeba counters for BD game engine separately
12443     if ((properties_element == EL_BD_AMOEBA && level.game_engine_type == GAME_ENGINE_TYPE_BD) ||
12444         (properties_element == EL_BD_AMOEBA_2))
12445       counterbutton_info[counter_id].y = ED_ELEMENT_SETTINGS_YPOS(3 + num_element_counters);
12446
12447     // special case: set position for delay counter for reappearing hammered walls
12448     if (properties_element == EL_BD_PNEUMATIC_HAMMER && num_element_counters > 0)
12449       counterbutton_info[counter_id].y += 1;
12450
12451     counterbutton_info[counter_id].value      = elements_with_counter[i].value;
12452     counterbutton_info[counter_id].text_right = elements_with_counter[i].text;
12453     counterbutton_info[counter_id].min_value  = elements_with_counter[i].min_value;
12454     counterbutton_info[counter_id].max_value  = elements_with_counter[i].max_value;
12455
12456     // default: counter values between 0 and 999
12457     if (counterbutton_info[counter_id].max_value == 0)
12458       counterbutton_info[counter_id].max_value = 999;
12459
12460     MapCounterButtons(counter_id);
12461
12462     num_element_counters++;
12463     if (num_element_counters >= max_num_element_counters)
12464       break;
12465   }
12466
12467   if (properties_element == EL_BD_MAGIC_WALL && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12468   {
12469     // draw stickybutton gadget
12470     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12471
12472     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_MAGIC_WALL_ZERO_INFINITE);
12473     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_MAGIC_WALL_WAIT_HATCHING);
12474     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_MAGIC_WALL_STOPS_AMOEBA);
12475     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_MAGIC_WALL_BREAK_SCAN);
12476
12477     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_DIAMOND_TO);
12478     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_ROCK_TO);
12479     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_MEGA_ROCK_TO);
12480     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_NUT_TO);
12481     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_NITRO_PACK_TO);
12482     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_FLYING_DIAMOND_TO);
12483     MapDrawingArea(ED_DRAWING_ID_BD_MAGIC_WALL_FLYING_ROCK_TO);
12484   }
12485
12486   if (HAS_EDITOR_CONTENT(properties_element))
12487   {
12488     // draw stickybutton gadget
12489     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12490
12491     if (properties_element == EL_BD_AMOEBA && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12492     {
12493       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_WAIT_FOR_HATCHING);
12494       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_START_IMMEDIATELY);
12495
12496       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_CONTENT_TOO_BIG);
12497       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_CONTENT_ENCLOSED);
12498     }
12499     else if (properties_element == EL_BD_AMOEBA_2)
12500     {
12501       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_WAIT_FOR_HATCHING);
12502       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_START_IMMEDIATELY);
12503       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_AMOEBA_2_EXPLODE_BY_AMOEBA);
12504
12505       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_TOO_BIG);
12506       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_ENCLOSED);
12507       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_EXPLODING);
12508       MapDrawingArea(ED_DRAWING_ID_BD_AMOEBA_2_CONTENT_LOOKS_LIKE);
12509     }
12510     else if (IS_AMOEBOID(properties_element))
12511     {
12512       MapDrawingArea(ED_DRAWING_ID_AMOEBA_CONTENT);
12513     }
12514     else if (properties_element == EL_BD_ACID)
12515     {
12516       MapDrawingArea(ED_DRAWING_ID_BD_ACID_EATS_ELEMENT);
12517       MapDrawingArea(ED_DRAWING_ID_BD_ACID_TURNS_TO_ELEMENT);
12518     }
12519     else if (IS_BD_BITER(properties_element))
12520     {
12521       MapDrawingArea(ED_DRAWING_ID_BD_BITER_EATS_ELEMENT);
12522     }
12523     else if (properties_element == EL_BD_BLADDER)
12524     {
12525       MapDrawingArea(ED_DRAWING_ID_BD_BLADDER_CONVERTS_BY_ELEMENT);
12526     }
12527     else if (properties_element == EL_YAMYAM ||
12528              properties_element == EL_YAMYAM_LEFT ||
12529              properties_element == EL_YAMYAM_RIGHT ||
12530              properties_element == EL_YAMYAM_UP ||
12531              properties_element == EL_YAMYAM_DOWN)
12532     {
12533       DrawYamYamContentAreas();
12534     }
12535     else if (properties_element == EL_EMC_MAGIC_BALL)
12536     {
12537       DrawMagicBallContentAreas();
12538
12539       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_RANDOM_BALL_CONTENT);
12540       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INITIAL_BALL_ACTIVE);
12541     }
12542     else if (properties_element == EL_EMC_ANDROID)
12543     {
12544       DrawAndroidElementArea();
12545     }
12546     else if (properties_element == EL_MM_GRAY_BALL)
12547     {
12548       MapCounterButtons(ED_COUNTER_ID_MM_BALL_CONTENT);
12549       MapSelectboxGadget(ED_SELECTBOX_ID_MM_BALL_CHOICE_MODE);
12550       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_ROTATE_MM_BALL_CONTENT);
12551       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EXPLODE_MM_BALL);
12552
12553       DrawMMBallContentArea();
12554     }
12555   }
12556
12557   if (IS_PLAYER_ELEMENT(properties_element))
12558   {
12559     int player_nr = GET_PLAYER_NR(properties_element);
12560
12561     // these properties can be set for every player individually
12562
12563     if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_1)
12564     {
12565       drawingarea_info[ED_DRAWING_ID_START_ELEMENT].value =
12566         &level.start_element[player_nr];
12567       drawingarea_info[ED_DRAWING_ID_ARTWORK_ELEMENT].value =
12568         &level.artwork_element[player_nr];
12569       drawingarea_info[ED_DRAWING_ID_EXPLOSION_ELEMENT].value =
12570         &level.explosion_element[player_nr];
12571
12572       checkbutton_info[ED_CHECKBUTTON_ID_USE_START_ELEMENT].value =
12573         &level.use_start_element[player_nr];
12574       checkbutton_info[ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT].value =
12575         &level.use_artwork_element[player_nr];
12576       checkbutton_info[ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT].value =
12577         &level.use_explosion_element[player_nr];
12578       checkbutton_info[ED_CHECKBUTTON_ID_INITIAL_GRAVITY].value =
12579         &level.initial_player_gravity[player_nr];
12580
12581       selectbox_info[ED_SELECTBOX_ID_PLAYER_SPEED].value =
12582         &level.initial_player_stepsize[player_nr];
12583
12584       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID);
12585       MapCheckbuttonGadget(properties_element == EL_SP_MURPHY ?
12586                            ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD :
12587                            ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD);
12588       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BLOCK_SNAP_FIELD);
12589       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CONTINUOUS_SNAPPING);
12590       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INSTANT_RELOCATION);
12591       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SHIFTED_RELOCATION);
12592       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_LAZY_RELOCATION);
12593       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_START_ELEMENT);
12594       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_ARTWORK_ELEMENT);
12595       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_EXPLOSION_ELEMENT);
12596       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INITIAL_GRAVITY);
12597       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE);
12598       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SOLVED_BY_ONE_PLAYER);
12599
12600       MapDrawingArea(ED_DRAWING_ID_START_ELEMENT);
12601       MapDrawingArea(ED_DRAWING_ID_ARTWORK_ELEMENT);
12602       MapDrawingArea(ED_DRAWING_ID_EXPLOSION_ELEMENT);
12603
12604       MapSelectboxGadget(ED_SELECTBOX_ID_PLAYER_SPEED);
12605     }
12606     else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2)
12607     {
12608       drawingarea_info[ED_DRAWING_ID_INVENTORY_CONTENT].value =
12609         &level.initial_inventory_content[player_nr][0];
12610
12611       counterbutton_info[ED_COUNTER_ID_INVENTORY_SIZE].value =
12612         &level.initial_inventory_size[player_nr];
12613
12614       checkbutton_info[ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY].value =
12615         &level.use_initial_inventory[player_nr];
12616
12617       // draw checkbutton gadgets
12618       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_INITIAL_INVENTORY);
12619       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_FINISH_DIG_COLLECT);
12620       MapCheckbuttonGadget(ED_CHECKBUTTON_ID_KEEP_WALKABLE_CE);
12621
12622       // draw counter gadgets
12623       MapCounterButtons(ED_COUNTER_ID_INVENTORY_SIZE);
12624
12625       // draw drawing area gadgets
12626       DrawPlayerInitialInventoryArea(properties_element);
12627     }
12628   }
12629
12630   if (IS_BD_PLAYER_ELEMENT(properties_element))
12631   {
12632     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB].y =
12633       ED_ELEMENT_SETTINGS_YPOS(2);
12634     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET].y =
12635       ED_ELEMENT_SETTINGS_YPOS(3);
12636     checkbutton_info[ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET].y =
12637       ED_ELEMENT_SETTINGS_YPOS(4);
12638
12639     // draw checkbutton gadgets
12640     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_DIAGONAL_MOVEMENTS);
12641     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_TOPMOST_PLAYER_ACTIVE);
12642     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET);
12643
12644     // draw counter gadgets
12645     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB);
12646     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET);
12647
12648     // draw drawing area gadgets
12649     MapDrawingArea(ED_DRAWING_ID_BD_SNAP_ELEMENT);
12650   }
12651
12652   if (properties_element == EL_BD_SAND)
12653   {
12654     MapDrawingArea(ED_DRAWING_ID_BD_SAND_LOOKS_LIKE);
12655   }
12656
12657   if (properties_element == EL_BD_ROCK && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12658   {
12659     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB].y =
12660       ED_ELEMENT_SETTINGS_YPOS(0);
12661     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET].y =
12662       ED_ELEMENT_SETTINGS_YPOS(1);
12663
12664     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB);
12665     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET);
12666
12667     MapDrawingArea(ED_DRAWING_ID_BD_ROCK_TURNS_TO_ON_FALLING);
12668     MapDrawingArea(ED_DRAWING_ID_BD_ROCK_TURNS_TO_ON_IMPACT);
12669   }
12670
12671   if (properties_element == EL_BD_DIAMOND && level.game_engine_type == GAME_ENGINE_TYPE_BD)
12672   {
12673     MapDrawingArea(ED_DRAWING_ID_BD_DIAMOND_TURNS_TO_ON_FALLING);
12674     MapDrawingArea(ED_DRAWING_ID_BD_DIAMOND_TURNS_TO_ON_IMPACT);
12675   }
12676
12677   if (level.game_engine_type == GAME_ENGINE_TYPE_BD)
12678   {
12679     if (IS_BD_FIREFLY(properties_element))
12680     {
12681       MapDrawingArea(ED_DRAWING_ID_BD_FIREFLY_EXPLODES_TO);
12682       MapDrawingArea(ED_DRAWING_ID_BD_EXPLOSION_TURNS_TO);
12683     }
12684     else if (IS_BD_FIREFLY_2(properties_element))
12685     {
12686       MapDrawingArea(ED_DRAWING_ID_BD_FIREFLY_2_EXPLODES_TO);
12687       MapDrawingArea(ED_DRAWING_ID_BD_EXPLOSION_TURNS_TO);
12688     }
12689     else if (IS_BD_BUTTERFLY(properties_element))
12690     {
12691       MapDrawingArea(ED_DRAWING_ID_BD_BUTTERFLY_EXPLODES_TO);
12692       MapDrawingArea(ED_DRAWING_ID_BD_DIAMOND_BIRTH_TURNS_TO);
12693     }
12694     else if (IS_BD_BUTTERFLY_2(properties_element))
12695     {
12696       MapDrawingArea(ED_DRAWING_ID_BD_BUTTERFLY_2_EXPLODES_TO);
12697       MapDrawingArea(ED_DRAWING_ID_BD_DIAMOND_BIRTH_TURNS_TO);
12698     }
12699     else if (IS_BD_STONEFLY(properties_element))
12700     {
12701       MapDrawingArea(ED_DRAWING_ID_BD_STONEFLY_EXPLODES_TO);
12702     }
12703     else if (IS_BD_DRAGONFLY(properties_element))
12704     {
12705       MapDrawingArea(ED_DRAWING_ID_BD_DRAGONFLY_EXPLODES_TO);
12706       MapDrawingArea(ED_DRAWING_ID_BD_EXPLOSION_TURNS_TO);
12707     }
12708     else if (properties_element == EL_BD_BOMB)
12709     {
12710       MapDrawingArea(ED_DRAWING_ID_BD_BOMB_EXPLOSION_TURNS_TO);
12711     }
12712     else if (properties_element == EL_BD_NITRO_PACK)
12713     {
12714       MapDrawingArea(ED_DRAWING_ID_BD_NITRO_EXPLOSION_TURNS_TO);
12715     }
12716   }
12717
12718   if (properties_element == EL_BD_MEGA_ROCK ||
12719       properties_element == EL_BD_SWEET)
12720   {
12721     counterbutton_info[ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET].y =
12722       ED_ELEMENT_SETTINGS_YPOS(0);
12723     checkbutton_info[ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET].y =
12724       ED_ELEMENT_SETTINGS_YPOS(1);
12725
12726     MapCounterButtons(ED_COUNTER_ID_BD_PUSHING_PROB_WITH_SWEET);
12727     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_PUSH_MEGA_ROCK_WITH_SWEET);
12728   }
12729
12730   if (properties_element == EL_BD_VOODOO_DOLL)
12731   {
12732     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_VOODOO_COLLECTS_DIAMONDS);
12733     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_VOODOO_HURT_KILLS_PLAYER);
12734     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_VOODOO_DIES_BY_ROCK);
12735     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_VOODOO_VANISH_BY_EXPLOSION);
12736   }
12737
12738   if (properties_element == EL_BD_SLIME)
12739   {
12740     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_SLIME_IS_PREDICTABLE);
12741
12742     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_1);
12743     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_1);
12744     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_2);
12745     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_2);
12746     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_EATS_ELEMENT_3);
12747     MapDrawingArea(ED_DRAWING_ID_BD_SLIME_CONVERTS_TO_ELEMENT_3);
12748   }
12749
12750   if (IS_BD_EXPANDABLE_WALL(properties_element) ||
12751       IS_BD_EXPANDABLE_STEELWALL(properties_element))
12752   {
12753     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CHANGE_EXPANDING_WALL);
12754
12755     if (IS_BD_EXPANDABLE_WALL(properties_element))
12756       MapDrawingArea(ED_DRAWING_ID_BD_EXPANDING_WALL_LOOKS_LIKE);
12757   }
12758
12759   if (properties_element == EL_BD_REPLICATOR)
12760   {
12761     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_REPLICATORS_ACTIVE);
12762   }
12763
12764   if (IS_BD_CONVEYOR_BELT(properties_element) ||
12765       IS_BD_CONVEYOR_BELT_SWITCH(properties_element))
12766   {
12767     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_ACTIVE);
12768     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CONVEYOR_BELTS_CHANGED);
12769   }
12770
12771   if (properties_element == EL_BD_WATER)
12772   {
12773     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_WATER_CANNOT_FLOW_DOWN);
12774   }
12775
12776   if (properties_element == EL_BD_PNEUMATIC_HAMMER)
12777   {
12778     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_HAMMER_WALLS_REAPPEAR);
12779   }
12780
12781   if (properties_element == EL_BD_ROCKET_LAUNCHER)
12782   {
12783     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_INFINITE_ROCKETS);
12784   }
12785
12786   if (properties_element == EL_BD_CREATURE_SWITCH)
12787   {
12788     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CREATURES_START_BACKWARDS);
12789     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_CREATURES_TURN_ON_HATCHING);
12790   }
12791
12792   if (properties_element == EL_BD_GRAVITY_SWITCH)
12793   {
12794     MapSelectboxGadget(ED_SELECTBOX_ID_BD_GRAVITY_DIRECTION);
12795
12796     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_GRAVITY_SWITCH_ACTIVE);
12797     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_BD_GRAVITY_AFFECTS_ALL);
12798   }
12799
12800   if (properties_element == EL_BD_NUT)
12801   {
12802     MapDrawingArea(ED_DRAWING_ID_BD_NUT_CONTENT);
12803   }
12804
12805   // special case: slippery walls option for gems only available in R'n'D game engine
12806   if (IS_GEM(properties_element) && level.game_engine_type == GAME_ENGINE_TYPE_RND)
12807     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS);
12808
12809   if (properties_element == EL_EM_DYNAMITE)
12810     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_EXPLODES_BY_FIRE);
12811
12812   if (level.game_engine_type == GAME_ENGINE_TYPE_RND &&
12813       COULD_MOVE_INTO_ACID(properties_element) &&
12814       !IS_PLAYER_ELEMENT(properties_element) &&
12815       (!IS_CUSTOM_ELEMENT(properties_element) ||
12816        edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2))
12817   {
12818     // set position for checkbutton for "can move into acid"
12819     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].x =
12820       ED_ELEMENT_SETTINGS_XPOS(IS_CUSTOM_ELEMENT(properties_element) ? 1 : 0);
12821     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].y =
12822       ED_ELEMENT_SETTINGS_YPOS(IS_CUSTOM_ELEMENT(properties_element) ? 7 :
12823                                IS_BALLOON_ELEMENT(properties_element) ||
12824                                HAS_EDITOR_CONTENT(properties_element) ? 1 : 0);
12825
12826     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID);
12827   }
12828
12829   if (MAYBE_DONT_COLLIDE_WITH(properties_element))
12830     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH);
12831
12832   if (properties_element == EL_SPRING ||
12833       properties_element == EL_SPRING_LEFT ||
12834       properties_element == EL_SPRING_RIGHT)
12835     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_SPRING_BUG);
12836
12837   if (properties_element == EL_TIME_ORB_FULL)
12838     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_TIME_ORB_BUG);
12839
12840   if (properties_element == EL_GAME_OF_LIFE ||
12841       properties_element == EL_BIOMAZE)
12842     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_LIFE_BUGS);
12843
12844   if (CAN_GROW(properties_element) && level.game_engine_type != GAME_ENGINE_TYPE_BD)
12845   {
12846     checkbutton_info[ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE].y =
12847       ED_ELEMENT_SETTINGS_YPOS(HAS_EDITOR_CONTENT(properties_element) ? 1 : 0);
12848
12849     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE);
12850   }
12851
12852   if (properties_element == EL_SOKOBAN_FIELD_EMPTY)
12853     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SB_FIELDS_NEEDED);
12854
12855   if (properties_element == EL_SOKOBAN_OBJECT)
12856     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_SB_OBJECTS_NEEDED);
12857
12858   if (properties_element == EL_SOKOBAN_OBJECT ||
12859       properties_element == EL_SOKOBAN_FIELD_EMPTY ||
12860       properties_element == EL_SOKOBAN_FIELD_FULL)
12861   {
12862     checkbutton_info[ED_CHECKBUTTON_ID_AUTO_EXIT_SOKOBAN].y =
12863       ED_ELEMENT_SETTINGS_XPOS(properties_element == EL_SOKOBAN_FIELD_FULL ?
12864                                0 : 1);
12865
12866     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_AUTO_EXIT_SOKOBAN);
12867   }
12868
12869   if (IS_BALLOON_ELEMENT(properties_element))
12870     MapSelectboxGadget(ED_SELECTBOX_ID_WIND_DIRECTION);
12871
12872   if (IS_ENVELOPE(properties_element) ||
12873       IS_MM_ENVELOPE(properties_element))
12874   {
12875     int counter1_id = ED_COUNTER_ID_ENVELOPE_XSIZE;
12876     int counter2_id = ED_COUNTER_ID_ENVELOPE_YSIZE;
12877     int button1_id = ED_CHECKBUTTON_ID_ENVELOPE_AUTOWRAP;
12878     int button2_id = ED_CHECKBUTTON_ID_ENVELOPE_CENTERED;
12879     int envelope_nr = ENVELOPE_NR(properties_element);
12880
12881     counterbutton_info[counter1_id].value = &level.envelope[envelope_nr].xsize;
12882     counterbutton_info[counter2_id].value = &level.envelope[envelope_nr].ysize;
12883
12884     checkbutton_info[button1_id].value = &level.envelope[envelope_nr].autowrap;
12885     checkbutton_info[button2_id].value = &level.envelope[envelope_nr].centered;
12886
12887     // display counter to choose size of envelope text area
12888     MapCounterButtons(counter1_id);
12889     MapCounterButtons(counter2_id);
12890
12891     // display checkbuttons to choose auto-wrap and alignment properties
12892     MapCheckbuttonGadget(button1_id);
12893     MapCheckbuttonGadget(button2_id);
12894
12895     DrawEnvelopeTextArea(envelope_nr);
12896   }
12897
12898   if (IS_MM_MCDUFFIN(properties_element))
12899   {
12900     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_RED);
12901     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_GREEN);
12902     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_MM_LASER_BLUE);
12903   }
12904
12905   if (IS_DF_LASER(properties_element))
12906   {
12907     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_RED);
12908     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_GREEN);
12909     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DF_LASER_BLUE);
12910   }
12911
12912   if (IS_CUSTOM_ELEMENT(properties_element))
12913   {
12914     // draw stickybutton gadget
12915     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12916
12917     if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_1)
12918     {
12919       // draw checkbutton gadgets
12920       for (i =  ED_CHECKBUTTON_ID_CUSTOM1_FIRST;
12921            i <= ED_CHECKBUTTON_ID_CUSTOM1_LAST; i++)
12922         MapCheckbuttonGadget(i);
12923
12924       // draw counter gadgets
12925       for (i =  ED_COUNTER_ID_CUSTOM1_FIRST;
12926            i <= ED_COUNTER_ID_CUSTOM1_LAST; i++)
12927         MapCounterButtons(i);
12928
12929       // draw selectbox gadgets
12930       for (i =  ED_SELECTBOX_ID_CUSTOM1_FIRST;
12931            i <= ED_SELECTBOX_ID_CUSTOM1_LAST; i++)
12932         MapSelectboxGadget(i);
12933
12934       // draw textbutton gadgets
12935       MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
12936
12937       // draw text input gadgets
12938       MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
12939
12940       // draw drawing area gadgets
12941       MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
12942
12943       draw_footer_line = TRUE;
12944     }
12945     else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2)
12946     {
12947       // draw checkbutton gadgets
12948       for (i =  ED_CHECKBUTTON_ID_CUSTOM2_FIRST;
12949            i <= ED_CHECKBUTTON_ID_CUSTOM2_LAST; i++)
12950         MapCheckbuttonGadget(i);
12951
12952       // draw counter gadgets
12953       for (i =  ED_COUNTER_ID_CUSTOM2_FIRST;
12954            i <= ED_COUNTER_ID_CUSTOM2_LAST; i++)
12955         MapCounterButtons(i);
12956
12957       // draw selectbox gadgets
12958       for (i =  ED_SELECTBOX_ID_CUSTOM2_FIRST;
12959            i <= ED_SELECTBOX_ID_CUSTOM2_LAST; i++)
12960         MapSelectboxGadget(i);
12961
12962       // draw drawing area gadgets
12963       MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_ENTER);
12964       MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_LEAVE);
12965       DrawCustomContentArea();
12966     }
12967   }
12968   else if (IS_GROUP_ELEMENT(properties_element))
12969   {
12970     // draw stickybutton gadget
12971     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
12972
12973     // draw checkbutton gadgets
12974     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
12975     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1);
12976
12977     // draw counter gadgets
12978     MapCounterButtons(ED_COUNTER_ID_GROUP_CONTENT);
12979
12980     // draw selectbox gadgets
12981     MapSelectboxGadget(ED_SELECTBOX_ID_GROUP_CHOICE_MODE);
12982
12983     // draw textbutton gadgets
12984     MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
12985
12986     // draw drawing area gadgets
12987     DrawGroupElementArea();
12988
12989     // draw text input gadgets
12990     MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
12991
12992     // draw drawing area gadgets
12993     MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
12994
12995     draw_footer_line = TRUE;
12996   }
12997   else if (IS_EMPTY_ELEMENT(properties_element))
12998   {
12999     // draw stickybutton gadget
13000     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
13001
13002     // draw checkbutton gadgets
13003     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
13004     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1);
13005
13006     // draw textbutton gadgets
13007     MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1);
13008
13009     // draw drawing area gadgets
13010     MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
13011
13012     draw_footer_line = TRUE;
13013   }
13014
13015   // draw little footer border line above CE/GE use/save template gadgets
13016   if (draw_footer_line)
13017   {
13018     struct GadgetInfo *gd_gi1 = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
13019     struct GadgetDesign *gd = &gd_gi1->alt_design[GD_BUTTON_UNPRESSED];
13020     int gd_x = gd->x + gd_gi1->border.width / 2;
13021     int gd_y = gd->y + gd_gi1->height - 1;
13022     Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
13023
13024     if (tab_color != BLACK_PIXEL)               // black => transparent
13025       FillRectangle(drawto,
13026                     SX + ED_ELEMENT_SETTINGS_X(0),
13027                     SY + ED_ELEMENT_SETTINGS_Y(14) - ED_SETTINGS_TABS_YOFFSET -
13028                     ED_TAB_BAR_HEIGHT,
13029                     getTabulatorBarWidth(), getTabulatorBarHeight(), tab_color);
13030   }
13031 }
13032
13033 static void DrawPropertiesChangeDrawingAreas(void)
13034 {
13035   if (IS_CUSTOM_ELEMENT(properties_element))
13036   {
13037     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TARGET);
13038     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER);
13039     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_ACTION);
13040
13041     DrawCustomChangeContentArea();
13042   }
13043
13044   redraw_mask |= REDRAW_FIELD;
13045 }
13046
13047 static void DrawPropertiesChange(void)
13048 {
13049   int i;
13050
13051   // needed to initially set selectbox options for special action options
13052   setSelectboxSpecialActionOptions();
13053
13054   // draw stickybutton gadget
13055   MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
13056
13057   // draw checkbutton gadgets
13058   for (i =  ED_CHECKBUTTON_ID_CHANGE_FIRST;
13059        i <= ED_CHECKBUTTON_ID_CHANGE_LAST; i++)
13060     MapCheckbuttonGadget(i);
13061
13062   // draw counter gadgets
13063   for (i =  ED_COUNTER_ID_CHANGE_FIRST;
13064        i <= ED_COUNTER_ID_CHANGE_LAST; i++)
13065     MapCounterButtons(i);
13066
13067   // draw selectbox gadgets
13068   for (i =  ED_SELECTBOX_ID_CHANGE_FIRST;
13069        i <= ED_SELECTBOX_ID_CHANGE_LAST; i++)
13070     MapSelectboxGadget(i);
13071
13072   // draw textbutton gadgets
13073   for (i =  ED_TEXTBUTTON_ID_CHANGE_FIRST;
13074        i <= ED_TEXTBUTTON_ID_CHANGE_LAST; i++)
13075     MapTextbuttonGadget(i);
13076
13077   // draw graphicbutton gadgets
13078   for (i =  ED_GRAPHICBUTTON_ID_CHANGE_FIRST;
13079        i <= ED_GRAPHICBUTTON_ID_CHANGE_LAST; i++)
13080     MapGraphicbuttonGadget(i);
13081
13082   // draw drawing area gadgets
13083   DrawPropertiesChangeDrawingAreas();
13084 }
13085
13086 static void DrawEditorElementAnimation(int x, int y)
13087 {
13088   int graphic;
13089   int frame;
13090
13091   getEditorGraphicAndFrame(properties_element, &graphic, &frame, FALSE);
13092
13093   DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
13094 }
13095
13096 static void DrawEditorElementName(int x, int y, int font_nr)
13097 {
13098   char *element_name = getElementInfoText(properties_element);
13099   int font_width = getFontWidth(font_nr);
13100   int font_height = getFontHeight(font_nr);
13101   int max_text_width = SXSIZE - x - ED_ELEMENT_SETTINGS_X(0);
13102   int max_chars_per_line = max_text_width / font_width;
13103
13104   if (strlen(element_name) <= max_chars_per_line)
13105     DrawTextS(x, y, font_nr, element_name);
13106   else
13107   {
13108     char buffer[max_chars_per_line + 1];
13109     int next_pos = max_chars_per_line;
13110
13111     strncpy(buffer, element_name, max_chars_per_line);
13112     buffer[max_chars_per_line] = '\0';
13113
13114     if (element_name[max_chars_per_line] == ' ')
13115       next_pos++;
13116     else
13117     {
13118       int i;
13119
13120       for (i = max_chars_per_line - 1; i >= 0; i--)
13121         if (buffer[i] == ' ')
13122           break;
13123
13124       if (strlen(&element_name[i + 1]) <= max_chars_per_line)
13125       {
13126         buffer[i] = '\0';
13127         next_pos = i + 1;
13128       }
13129     }
13130
13131     DrawTextS(x, y - font_height / 2, font_nr, buffer);
13132
13133     strncpy(buffer, &element_name[next_pos], max_chars_per_line);
13134     buffer[max_chars_per_line] = '\0';
13135
13136     DrawTextS(x, y + font_height / 2, font_nr, buffer);
13137   }
13138 }
13139
13140 static void DrawPropertiesWindow(void)
13141 {
13142   struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_TEXT];
13143   int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
13144   int border_size = gd->border_size;
13145   int font_nr = FONT_TEXT_1;
13146   int font_height = getFontHeight(font_nr);
13147   int xoffset = TILEX + element_border + 3 * border_size;
13148   int yoffset = (TILEY - font_height) / 2;
13149   int x1 = editor.settings.element_graphic.x + element_border;
13150   int y1 = editor.settings.element_graphic.y + element_border;
13151   int x2 = (editor.settings.element_name.x == -1 ? x1 + xoffset :
13152             editor.settings.element_name.x);
13153   int y2 = (editor.settings.element_name.y == -1 ? y1 + yoffset :
13154             editor.settings.element_name.y);
13155   char *text = "Element Settings";
13156   int font2_nr = FONT_TITLE_1;
13157   struct MenuPosInfo *pos = &editor.settings.headline;
13158   int sx = SX + ALIGNED_XPOS(pos->x, getTextWidth(text, font2_nr), pos->align);
13159   int sy = SY + pos->y;
13160
13161   stick_element_properties_window = FALSE;
13162
13163   // make sure that previous properties edit mode exists for this element
13164   if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG_2 &&
13165       !IS_CUSTOM_ELEMENT(properties_element))
13166     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_2;
13167
13168   if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG &&
13169       !IS_PLAYER_ELEMENT(properties_element) &&
13170       !IS_CUSTOM_ELEMENT(properties_element))
13171     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
13172
13173   if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG &&
13174       (IS_PLAYER_ELEMENT(properties_element) ||
13175        IS_CUSTOM_ELEMENT(properties_element)))
13176     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_1;
13177
13178   CopyElementPropertiesToEditor(properties_element);
13179
13180   UnmapLevelEditorFieldGadgets();
13181   UnmapLevelEditorToolboxDrawingGadgets();
13182   UnmapLevelEditorToolboxCustomGadgets();
13183
13184   MapLevelEditorToolboxCustomGadgetsIfNeeded();
13185
13186   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
13187   ClearField();
13188
13189   DrawText(sx, sy, text, font2_nr);
13190
13191   FrameCounter = 0;     // restart animation frame counter
13192
13193   DrawElementBorder(SX + x1, SY + y1, TILEX, TILEY, FALSE);
13194   DrawEditorElementAnimation(SX + x1, SY + y1);
13195   DrawEditorElementName(x2, y2, font_nr);
13196
13197   DrawPropertiesTabulatorGadgets();
13198
13199   if (edit_mode_properties == ED_MODE_PROPERTIES_INFO)
13200     DrawPropertiesInfo();
13201   else if (edit_mode_properties == ED_MODE_PROPERTIES_CHANGE)
13202     DrawPropertiesChange();
13203   else  // (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG[_1|_2])
13204     DrawPropertiesConfig();
13205 }
13206
13207 static void DrawPaletteWindow(void)
13208 {
13209   int i;
13210
13211   UnmapLevelEditorFieldGadgets();
13212
13213   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
13214   ClearField();
13215
13216   // map buttons to select elements
13217   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
13218     MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
13219   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
13220   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
13221   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
13222 }
13223
13224 static void UpdateCustomElementGraphicGadgets(void)
13225 {
13226   int i;
13227
13228   InitElementPropertiesGfxElement();
13229
13230   ModifyEditorElementList();
13231   RedrawDrawingElements();
13232
13233   // force redraw of all mapped drawing area gadgets
13234   for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
13235   {
13236     struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[i].gadget_id];
13237
13238     if (gi->mapped)
13239       MapDrawingArea(i);
13240   }
13241 }
13242
13243 static int getOpenDirectionFromTube(int element)
13244 {
13245   switch (element)
13246   {
13247     case EL_TUBE_LEFT_UP:               return (MV_LEFT | MV_UP);
13248     case EL_TUBE_LEFT_DOWN:             return (MV_LEFT | MV_DOWN);
13249     case EL_TUBE_RIGHT_UP:              return (MV_RIGHT | MV_UP);
13250     case EL_TUBE_RIGHT_DOWN:            return (MV_RIGHT | MV_DOWN);
13251     case EL_TUBE_HORIZONTAL:            return (MV_HORIZONTAL);
13252     case EL_TUBE_HORIZONTAL_UP:         return (MV_HORIZONTAL | MV_UP);
13253     case EL_TUBE_HORIZONTAL_DOWN:       return (MV_HORIZONTAL | MV_DOWN);
13254     case EL_TUBE_VERTICAL:              return (MV_VERTICAL);
13255     case EL_TUBE_VERTICAL_LEFT:         return (MV_VERTICAL | MV_LEFT);
13256     case EL_TUBE_VERTICAL_RIGHT:        return (MV_VERTICAL | MV_RIGHT);
13257     case EL_TUBE_ANY:                   return (MV_ANY_DIRECTION);
13258   }
13259
13260   return MV_NONE;
13261 }
13262
13263 static int getTubeFromOpenDirection(int direction)
13264 {
13265   switch (direction)
13266   {
13267     case (MV_LEFT | MV_UP):             return EL_TUBE_LEFT_UP;
13268     case (MV_LEFT | MV_DOWN):           return EL_TUBE_LEFT_DOWN;
13269     case (MV_RIGHT | MV_UP):            return EL_TUBE_RIGHT_UP;
13270     case (MV_RIGHT | MV_DOWN):          return EL_TUBE_RIGHT_DOWN;
13271     case (MV_HORIZONTAL):               return EL_TUBE_HORIZONTAL;
13272     case (MV_HORIZONTAL | MV_UP):       return EL_TUBE_HORIZONTAL_UP;
13273     case (MV_HORIZONTAL | MV_DOWN):     return EL_TUBE_HORIZONTAL_DOWN;
13274     case (MV_VERTICAL):                 return EL_TUBE_VERTICAL;
13275     case (MV_VERTICAL | MV_LEFT):       return EL_TUBE_VERTICAL_LEFT;
13276     case (MV_VERTICAL | MV_RIGHT):      return EL_TUBE_VERTICAL_RIGHT;
13277     case (MV_ANY_DIRECTION):            return EL_TUBE_ANY;
13278
13279     // if only one direction, fall back to simple tube with that direction
13280     case (MV_LEFT):                     return EL_TUBE_HORIZONTAL;
13281     case (MV_RIGHT):                    return EL_TUBE_HORIZONTAL;
13282     case (MV_UP):                       return EL_TUBE_VERTICAL;
13283     case (MV_DOWN):                     return EL_TUBE_VERTICAL;
13284   }
13285
13286   return EL_EMPTY;
13287 }
13288
13289 static int getTubeFromOpenDirectionNotEmpty(int direction, int element_old)
13290 {
13291   int element_new = getTubeFromOpenDirection(direction);
13292
13293   return (element_new != EL_EMPTY ? element_new : element_old);
13294 }
13295
13296 static int getOpenDirectionFromBelt(int element)
13297 {
13298   int belt_dir = getBeltDirFromBeltElement(element);
13299
13300   return (belt_dir == MV_LEFT ? MV_RIGHT :
13301           belt_dir == MV_RIGHT ? MV_LEFT :
13302           belt_dir == MV_NONE ? MV_HORIZONTAL : belt_dir);
13303 }
13304
13305 static int getBeltFromNrAndOpenDirection(int nr, int direction)
13306 {
13307   int belt_dir = (direction == MV_LEFT ? MV_RIGHT :
13308                   direction == MV_RIGHT ? MV_LEFT :
13309                   direction == MV_HORIZONTAL ? MV_NONE : direction);
13310
13311   if (direction == MV_NONE)
13312     return EL_EMPTY;
13313
13314   return getBeltElementFromBeltNrAndBeltDir(nr, belt_dir);
13315 }
13316
13317 static int getBeltFromNrAndOpenDirectionNotEmpty(int nr, int direction,
13318                                                  int element_old)
13319 {
13320   int element_new = getBeltFromNrAndOpenDirection(nr, direction);
13321
13322   return (element_new != EL_EMPTY ? element_new : element_old);
13323 }
13324
13325 static int getOpenDirectionFromPool(int element)
13326 {
13327   switch (element)
13328   {
13329     case EL_ACID_POOL_TOPLEFT:          return (MV_DOWN | MV_RIGHT);
13330     case EL_ACID_POOL_TOPRIGHT:         return (MV_DOWN | MV_LEFT);
13331     case EL_ACID_POOL_BOTTOMLEFT:       return (MV_UP | MV_RIGHT);
13332     case EL_ACID_POOL_BOTTOMRIGHT:      return (MV_UP | MV_LEFT);
13333     case EL_ACID_POOL_BOTTOM:           return (MV_HORIZONTAL | MV_UP);
13334     case EL_ACID:                       return (MV_HORIZONTAL | MV_DOWN);
13335   }
13336
13337   return MV_NONE;
13338 }
13339
13340 static int getPoolFromOpenDirection(int direction)
13341 {
13342   switch (direction)
13343   {
13344     case (MV_DOWN | MV_RIGHT):          return EL_ACID_POOL_TOPLEFT;
13345     case (MV_DOWN | MV_LEFT):           return EL_ACID_POOL_TOPRIGHT;
13346     case (MV_UP | MV_RIGHT):            return EL_ACID_POOL_BOTTOMLEFT;
13347     case (MV_UP | MV_LEFT):             return EL_ACID_POOL_BOTTOMRIGHT;
13348     case (MV_HORIZONTAL | MV_UP):       return EL_ACID_POOL_BOTTOM;
13349     case (MV_HORIZONTAL | MV_DOWN):     return EL_ACID;
13350   }
13351
13352   return EL_EMPTY;
13353 }
13354
13355 static int getPoolFromOpenDirectionExt(int direction, int help_element)
13356 {
13357   int element = getPoolFromOpenDirection(direction);
13358   int help_direction = getOpenDirectionFromPool(help_element);
13359
13360   if (element == EL_EMPTY)
13361   {
13362     int help_direction_vertical = help_direction & MV_VERTICAL;
13363
13364     element = getPoolFromOpenDirection(direction | help_direction_vertical);
13365   }
13366
13367   if (element == EL_EMPTY)
13368   {
13369     int help_direction_horizontal = help_direction & MV_HORIZONTAL;
13370
13371     element = getPoolFromOpenDirection(direction | help_direction_horizontal);
13372   }
13373
13374   return element;
13375 }
13376
13377 static int getPoolFromOpenDirectionNotEmpty(int direction, int element_old)
13378 {
13379   int element_new = getPoolFromOpenDirectionExt(direction, element_old);
13380
13381   return (element_new != EL_EMPTY ? element_new : element_old);
13382 }
13383
13384 static int getOpenDirectionFromPillar(int element)
13385 {
13386   switch (element)
13387   {
13388     case EL_EMC_WALL_1:                 return (MV_DOWN);
13389     case EL_EMC_WALL_2:                 return (MV_VERTICAL);
13390     case EL_EMC_WALL_3:                 return (MV_UP);
13391   }
13392
13393   return MV_NONE;
13394 }
13395
13396 static int getPillarFromOpenDirection(int direction)
13397 {
13398   switch (direction)
13399   {
13400     case (MV_DOWN):                     return EL_EMC_WALL_1;
13401     case (MV_VERTICAL):                 return EL_EMC_WALL_2;
13402     case (MV_UP):                       return EL_EMC_WALL_3;
13403   }
13404
13405   return EL_EMPTY;
13406 }
13407
13408 static int getPillarFromOpenDirectionNotEmpty(int direction, int element_old)
13409 {
13410   int element_new = getPillarFromOpenDirection(direction);
13411
13412   return (element_new != EL_EMPTY ? element_new : element_old);
13413 }
13414
13415 static int getOpenDirectionFromSteel2(int element)
13416 {
13417   switch (element)
13418   {
13419     case EL_DC_STEELWALL_2_LEFT:        return (MV_RIGHT);
13420     case EL_DC_STEELWALL_2_RIGHT:       return (MV_LEFT);
13421     case EL_DC_STEELWALL_2_TOP:         return (MV_DOWN);
13422     case EL_DC_STEELWALL_2_BOTTOM:      return (MV_UP);
13423     case EL_DC_STEELWALL_2_HORIZONTAL:  return (MV_HORIZONTAL);
13424     case EL_DC_STEELWALL_2_VERTICAL:    return (MV_VERTICAL);
13425     case EL_DC_STEELWALL_2_MIDDLE:      return (MV_ANY_DIRECTION);
13426     case EL_DC_STEELWALL_2_SINGLE:      return (MV_NONE);
13427   }
13428
13429   return MV_NONE;
13430 }
13431
13432 static int getSteel2FromOpenDirection(int direction)
13433 {
13434   switch (direction)
13435   {
13436     case (MV_RIGHT):                    return EL_DC_STEELWALL_2_LEFT;
13437     case (MV_LEFT):                     return EL_DC_STEELWALL_2_RIGHT;
13438     case (MV_DOWN):                     return EL_DC_STEELWALL_2_TOP;
13439     case (MV_UP):                       return EL_DC_STEELWALL_2_BOTTOM;
13440     case (MV_HORIZONTAL):               return EL_DC_STEELWALL_2_HORIZONTAL;
13441     case (MV_VERTICAL):                 return EL_DC_STEELWALL_2_VERTICAL;
13442     case (MV_ANY_DIRECTION):            return EL_DC_STEELWALL_2_MIDDLE;
13443     case (MV_NONE):                     return EL_DC_STEELWALL_2_SINGLE;
13444   }
13445
13446   return EL_EMPTY;
13447 }
13448
13449 static int getSteel2FromOpenDirectionNotEmpty(int direction, int element_old)
13450 {
13451   int element_new = getSteel2FromOpenDirection(direction);
13452
13453   return (element_new != EL_EMPTY ? element_new : element_old);
13454 }
13455
13456 static int getOpenDirectionFromChip(int element)
13457 {
13458   switch (element)
13459   {
13460     case EL_SP_CHIP_SINGLE:             return (MV_NONE);
13461     case EL_SP_CHIP_LEFT:               return (MV_RIGHT);
13462     case EL_SP_CHIP_RIGHT:              return (MV_LEFT);
13463     case EL_SP_CHIP_TOP:                return (MV_DOWN);
13464     case EL_SP_CHIP_BOTTOM:             return (MV_UP);
13465   }
13466
13467   return MV_NONE;
13468 }
13469
13470 static int getChipFromOpenDirection(int direction)
13471 {
13472   switch (direction)
13473   {
13474     case (MV_NONE):                     return EL_SP_CHIP_SINGLE;
13475     case (MV_LEFT):                     return EL_SP_CHIP_RIGHT;
13476     case (MV_RIGHT):                    return EL_SP_CHIP_LEFT;
13477     case (MV_UP):                       return EL_SP_CHIP_BOTTOM;
13478     case (MV_DOWN):                     return EL_SP_CHIP_TOP;
13479   }
13480
13481   return EL_EMPTY;
13482 }
13483
13484 static int getChipFromOpenDirectionNotEmpty(int direction, int element_old)
13485 {
13486   int element_new = getChipFromOpenDirection(direction);
13487
13488   return (element_new != EL_EMPTY ? element_new : element_old);
13489 }
13490
13491 static int getClosedTube(int x, int y)
13492 {
13493   struct XY *xy = xy_directions;
13494   int element_old = IntelliDrawBuffer[x][y];
13495   int direction_old = getOpenDirectionFromTube(element_old);
13496   int direction_new = MV_NONE;
13497   int i;
13498
13499   for (i = 0; i < NUM_DIRECTIONS; i++)
13500   {
13501     int xx = x + xy[i].x;
13502     int yy = y + xy[i].y;
13503     int dir = MV_DIR_FROM_BIT(i);
13504     int dir_opposite = MV_DIR_OPPOSITE(dir);
13505
13506     if (IN_LEV_FIELD(xx, yy) && IS_TUBE(IntelliDrawBuffer[xx][yy]) &&
13507         (direction_old & dir) &&
13508         (getOpenDirectionFromTube(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13509       direction_new |= dir;
13510   }
13511
13512   return getTubeFromOpenDirectionNotEmpty(direction_new, element_old);
13513 }
13514
13515 static int getClosedBelt(int x, int y)
13516 {
13517   struct XY *xy = xy_directions;
13518   int element_old = IntelliDrawBuffer[x][y];
13519   int nr = getBeltNrFromBeltElement(element_old);
13520   int direction_old = getOpenDirectionFromBelt(element_old);
13521   int direction_new = MV_NONE;
13522   int i;
13523
13524   for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
13525   {
13526     int xx = x + xy[i].x;
13527     int yy = y + xy[i].y;
13528     int dir = MV_DIR_FROM_BIT(i);
13529     int dir_opposite = MV_DIR_OPPOSITE(dir);
13530
13531     if (IN_LEV_FIELD(xx, yy) && IS_BELT(IntelliDrawBuffer[xx][yy]) &&
13532         (direction_old & dir) &&
13533         (getOpenDirectionFromBelt(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13534       direction_new |= dir;
13535   }
13536
13537   return getBeltFromNrAndOpenDirection(nr, direction_new);
13538 }
13539
13540 static int getClosedPool(int x, int y)
13541 {
13542   struct XY *xy = xy_directions;
13543   int element_old = IntelliDrawBuffer[x][y];
13544   int direction_old = getOpenDirectionFromPool(element_old);
13545   int direction_new = MV_NONE;
13546   int i;
13547
13548   for (i = 0; i < NUM_DIRECTIONS; i++)
13549   {
13550     int xx = x + xy[i].x;
13551     int yy = y + xy[i].y;
13552     int dir = MV_DIR_FROM_BIT(i);
13553     int dir_opposite = MV_DIR_OPPOSITE(dir);
13554
13555     if (IN_LEV_FIELD(xx, yy) &&
13556         IS_ACID_POOL_OR_ACID(IntelliDrawBuffer[xx][yy]) &&
13557         (direction_old & dir) &&
13558         (getOpenDirectionFromPool(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13559       direction_new |= dir;
13560   }
13561
13562   return getPoolFromOpenDirectionNotEmpty(direction_new, element_old);
13563 }
13564
13565 static int getClosedPillar(int x, int y)
13566 {
13567   struct XY *xy = xy_directions;
13568   int element_old = IntelliDrawBuffer[x][y];
13569   int direction_old = getOpenDirectionFromPillar(element_old);
13570   int direction_new = MV_NONE;
13571   int i;
13572
13573   for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
13574   {
13575     int xx = x + xy[i].x;
13576     int yy = y + xy[i].y;
13577     int dir = MV_DIR_FROM_BIT(i);
13578     int dir_opposite = MV_DIR_OPPOSITE(dir);
13579
13580     if (IN_LEV_FIELD(xx, yy) && IS_EMC_PILLAR(IntelliDrawBuffer[xx][yy]) &&
13581         (direction_old & dir) &&
13582         (getOpenDirectionFromPillar(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13583       direction_new |= dir;
13584   }
13585
13586   return getPillarFromOpenDirectionNotEmpty(direction_new, element_old);
13587 }
13588
13589 static int getClosedSteel2(int x, int y)
13590 {
13591   struct XY *xy = xy_directions;
13592   int element_old = IntelliDrawBuffer[x][y];
13593   int direction_old = getOpenDirectionFromSteel2(element_old);
13594   int direction_new = MV_NONE;
13595   int i;
13596
13597   for (i = 0; i < NUM_DIRECTIONS; i++)
13598   {
13599     int xx = x + xy[i].x;
13600     int yy = y + xy[i].y;
13601     int dir = MV_DIR_FROM_BIT(i);
13602     int dir_opposite = MV_DIR_OPPOSITE(dir);
13603
13604     if (IN_LEV_FIELD(xx, yy) && IS_DC_STEELWALL_2(IntelliDrawBuffer[xx][yy]) &&
13605         (direction_old & dir) &&
13606         (getOpenDirectionFromSteel2(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13607       direction_new |= dir;
13608   }
13609
13610   return getSteel2FromOpenDirectionNotEmpty(direction_new, element_old);
13611 }
13612
13613 static int getClosedChip(int x, int y)
13614 {
13615   struct XY *xy = xy_directions;
13616   int element_old = IntelliDrawBuffer[x][y];
13617   int direction_old = getOpenDirectionFromChip(element_old);
13618   int direction_new = MV_NONE;
13619   int i;
13620
13621   for (i = 0; i < NUM_DIRECTIONS; i++)
13622   {
13623     int xx = x + xy[i].x;
13624     int yy = y + xy[i].y;
13625     int dir = MV_DIR_FROM_BIT(i);
13626     int dir_opposite = MV_DIR_OPPOSITE(dir);
13627
13628     if (IN_LEV_FIELD(xx, yy) && IS_SP_CHIP(IntelliDrawBuffer[xx][yy]) &&
13629         (direction_old & dir) &&
13630         (getOpenDirectionFromChip(IntelliDrawBuffer[xx][yy]) & dir_opposite))
13631       direction_new |= dir;
13632   }
13633
13634   return getChipFromOpenDirectionNotEmpty(direction_new, element_old);
13635 }
13636
13637 static void SetElementSimpleExt(int x, int y, int dx, int dy, int element,
13638                                 boolean change_level)
13639 {
13640   int sx = x - level_xpos;
13641   int sy = y - level_ypos;
13642   int old_element = Tile[x][y];
13643   int new_element = element;
13644   unsigned int new_bitmask = (getDrawModeHiRes() ? (dx + 1) << (dy * 2) : 0x0f);
13645   boolean draw_masked = FALSE;
13646
13647   if (IS_MM_WALL_EDITOR(element))
13648   {
13649     element = map_mm_wall_element_editor(element) | new_bitmask;
13650
13651     if (IS_MM_WALL(old_element))
13652       element |= MM_WALL_BITS(old_element);
13653
13654     if (!change_level)
13655       draw_masked = TRUE;
13656   }
13657   else if (IS_MM_WALL(old_element) && element == EL_EMPTY)
13658   {
13659     int element_changed = old_element & ~new_bitmask;
13660
13661     if (MM_WALL_BITS(element_changed) != 0)
13662       element = element_changed;
13663   }
13664
13665   IntelliDrawBuffer[x][y] = element;
13666
13667   if (change_level)
13668     Tile[x][y] = element;
13669
13670   if (IN_ED_FIELD(sx, sy))
13671   {
13672     if (IS_MM_WALL(old_element) && new_element == EL_EMPTY)
13673       DrawSizedWallParts_MM(sx, sy, EL_EMPTY, ed_tilesize, FALSE, new_bitmask);
13674     else if (draw_masked)
13675       DrawEditorElementThruMask(sx, sy, element);
13676     else
13677       DrawEditorElement(sx, sy, element);
13678   }
13679 }
13680
13681 static void SetElementSimple(int x, int y, int element, boolean change_level)
13682 {
13683   SetElementSimpleExt(x, y, 0, 0, element, change_level);
13684 }
13685
13686 static void MergeAndCloseNeighbourElements(int x1, int y1, int *element1,
13687                                            int x2, int y2, int *element2,
13688                                            int (*close_function)(int, int),
13689                                            boolean change_level)
13690 {
13691   // set neighbour elements to newly determined connections
13692   SetElementSimple(x1, y1, *element1, change_level);
13693   SetElementSimple(x2, y2, *element2, change_level);
13694
13695   // remove all open connections of neighbour elements
13696   *element1 = close_function(x1, y1);
13697   *element2 = close_function(x2, y2);
13698
13699   // set neighbour elements to new, minimized connections
13700   SetElementSimple(x1, y1, *element1, change_level);
13701   SetElementSimple(x2, y2, *element2, change_level);
13702 }
13703
13704 static void SetElementIntelliDraw(int x, int y, int dx, int dy, int new_element,
13705                                   boolean change_level, int button)
13706 {
13707   struct XY *xy = xy_directions;
13708   static int last_x = -1;
13709   static int last_y = -1;
13710
13711   if (new_element == EL_UNDEFINED)
13712   {
13713     last_x = -1;
13714     last_y = -1;
13715
13716     return;
13717   }
13718
13719   int old_element = IntelliDrawBuffer[x][y];
13720
13721   if (IS_TUBE(new_element))
13722   {
13723     int last_element_new = EL_UNDEFINED;
13724     int direction = MV_NONE;
13725     int i;
13726
13727     // if old element is of same kind, keep all existing directions
13728     if (IS_TUBE(old_element))
13729       direction |= getOpenDirectionFromTube(old_element);
13730
13731     for (i = 0; i < NUM_DIRECTIONS; i++)
13732     {
13733       int xx = x + xy[i].x;
13734       int yy = y + xy[i].y;
13735
13736       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13737           IS_TUBE(IntelliDrawBuffer[last_x][last_y]))
13738       {
13739         int dir = MV_DIR_FROM_BIT(i);
13740         int dir_opposite = MV_DIR_OPPOSITE(dir);
13741         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13742         int last_direction_old = getOpenDirectionFromTube(last_element_old);
13743         int last_direction_new = last_direction_old | dir_opposite;
13744
13745         last_element_new = getTubeFromOpenDirection(last_direction_new);
13746
13747         direction |= dir;
13748       }
13749     }
13750
13751     new_element = getTubeFromOpenDirectionNotEmpty(direction, new_element);
13752
13753     if (last_element_new != EL_UNDEFINED)
13754       MergeAndCloseNeighbourElements(x, y, &new_element,
13755                                      last_x, last_y, &last_element_new,
13756                                      getClosedTube, change_level);
13757   }
13758   else if (IS_BELT(new_element))
13759   {
13760     int belt_nr = getBeltNrFromBeltElement(new_element);
13761     int last_element_new = EL_UNDEFINED;
13762     int direction = MV_NONE;
13763     int i;
13764
13765     // if old element is of same kind, keep all existing directions
13766     if (IS_BELT(old_element))
13767       direction |= getOpenDirectionFromBelt(old_element);
13768
13769     for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
13770     {
13771       int xx = x + xy[i].x;
13772       int yy = y + xy[i].y;
13773
13774       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13775           IS_BELT(IntelliDrawBuffer[last_x][last_y]))
13776       {
13777         int dir = MV_DIR_FROM_BIT(i);
13778         int dir_opposite = MV_DIR_OPPOSITE(dir);
13779         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13780         int last_belt_nr = getBeltNrFromBeltElement(last_element_old);
13781         int last_direction_old = getOpenDirectionFromBelt(last_element_old);
13782         int last_direction_new = last_direction_old | dir_opposite;
13783
13784         last_element_new = getBeltFromNrAndOpenDirection(last_belt_nr,
13785                                                          last_direction_new);
13786         direction |= dir;
13787       }
13788     }
13789
13790     new_element = getBeltFromNrAndOpenDirectionNotEmpty(belt_nr, direction,
13791                                                         new_element);
13792     if (last_element_new != EL_UNDEFINED)
13793       MergeAndCloseNeighbourElements(x, y, &new_element,
13794                                      last_x, last_y, &last_element_new,
13795                                      getClosedBelt, change_level);
13796   }
13797   else if (IS_ACID_POOL_OR_ACID(new_element))
13798   {
13799     int last_element_new = EL_UNDEFINED;
13800     int direction = MV_NONE;
13801     int i;
13802
13803     // if old element is of same kind, keep all existing directions
13804     if (IS_ACID_POOL_OR_ACID(old_element))
13805       direction |= getOpenDirectionFromPool(old_element);
13806
13807     for (i = 0; i < NUM_DIRECTIONS; i++)
13808     {
13809       int xx = x + xy[i].x;
13810       int yy = y + xy[i].y;
13811
13812       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13813           IS_ACID_POOL_OR_ACID(IntelliDrawBuffer[last_x][last_y]))
13814       {
13815         int dir = MV_DIR_FROM_BIT(i);
13816         int dir_opposite = MV_DIR_OPPOSITE(dir);
13817         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13818         int last_direction_old = getOpenDirectionFromPool(last_element_old);
13819         int last_direction_new = last_direction_old | dir_opposite;
13820
13821         last_element_new = getPoolFromOpenDirection(last_direction_new);
13822
13823         direction |= dir;
13824       }
13825     }
13826
13827     // special corrections needed for intuitively correct acid pool drawing
13828     if (last_element_new == EL_EMPTY)
13829       last_element_new = new_element;
13830     else if (last_element_new != EL_UNDEFINED)
13831       new_element = last_element_new;
13832
13833     new_element = getPoolFromOpenDirectionNotEmpty(direction, new_element);
13834
13835     if (last_element_new != EL_UNDEFINED)
13836       MergeAndCloseNeighbourElements(x, y, &new_element,
13837                                      last_x, last_y, &last_element_new,
13838                                      getClosedPool, change_level);
13839   }
13840   else if (IS_EMC_PILLAR(new_element))
13841   {
13842     int last_element_new = EL_UNDEFINED;
13843     int direction = MV_NONE;
13844     int i;
13845
13846     // if old element is of same kind, keep all existing directions
13847     if (IS_EMC_PILLAR(old_element))
13848       direction |= getOpenDirectionFromPillar(old_element);
13849
13850     for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
13851     {
13852       int xx = x + xy[i].x;
13853       int yy = y + xy[i].y;
13854
13855       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13856           IS_EMC_PILLAR(IntelliDrawBuffer[last_x][last_y]))
13857       {
13858         int dir = MV_DIR_FROM_BIT(i);
13859         int dir_opposite = MV_DIR_OPPOSITE(dir);
13860         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13861         int last_direction_old = getOpenDirectionFromPillar(last_element_old);
13862         int last_direction_new = last_direction_old | dir_opposite;
13863
13864         last_element_new = getPillarFromOpenDirection(last_direction_new);
13865
13866         direction |= dir;
13867       }
13868     }
13869
13870     new_element = getPillarFromOpenDirectionNotEmpty(direction, new_element);
13871
13872     if (last_element_new != EL_UNDEFINED)
13873       MergeAndCloseNeighbourElements(x, y, &new_element,
13874                                      last_x, last_y, &last_element_new,
13875                                      getClosedPillar, change_level);
13876   }
13877   else if (IS_DC_STEELWALL_2(new_element))
13878   {
13879     int last_element_new = EL_UNDEFINED;
13880     int direction = MV_NONE;
13881     int i;
13882
13883     // if old element is of same kind, keep all existing directions
13884     if (IS_DC_STEELWALL_2(old_element))
13885       direction |= getOpenDirectionFromSteel2(old_element);
13886
13887     for (i = 0; i < NUM_DIRECTIONS; i++)
13888     {
13889       int xx = x + xy[i].x;
13890       int yy = y + xy[i].y;
13891
13892       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13893           IS_DC_STEELWALL_2(IntelliDrawBuffer[last_x][last_y]))
13894       {
13895         int dir = MV_DIR_FROM_BIT(i);
13896         int dir_opposite = MV_DIR_OPPOSITE(dir);
13897         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13898         int last_direction_old = getOpenDirectionFromSteel2(last_element_old);
13899         int last_direction_new = last_direction_old | dir_opposite;
13900
13901         last_element_new = getSteel2FromOpenDirection(last_direction_new);
13902
13903         direction |= dir;
13904       }
13905     }
13906
13907     new_element = getSteel2FromOpenDirectionNotEmpty(direction, new_element);
13908
13909     if (last_element_new != EL_UNDEFINED)
13910       MergeAndCloseNeighbourElements(x, y, &new_element,
13911                                      last_x, last_y, &last_element_new,
13912                                      getClosedSteel2, change_level);
13913   }
13914   else if (IS_SP_CHIP(new_element))
13915   {
13916     int last_element_new = EL_UNDEFINED;
13917     int direction = MV_NONE;
13918     int i;
13919
13920     // (do not keep existing directions, regardless of kind of old element)
13921
13922     for (i = 0; i < NUM_DIRECTIONS; i++)
13923     {
13924       int xx = x + xy[i].x;
13925       int yy = y + xy[i].y;
13926
13927       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13928           IS_SP_CHIP(IntelliDrawBuffer[last_x][last_y]))
13929       {
13930         int dir = MV_DIR_FROM_BIT(i);
13931         int dir_opposite = MV_DIR_OPPOSITE(dir);
13932         int last_element_old = IntelliDrawBuffer[last_x][last_y];
13933         int last_direction_old = getOpenDirectionFromChip(last_element_old);
13934         int last_direction_new = last_direction_old | dir_opposite;
13935
13936         if (last_direction_old == MV_NONE)
13937         {
13938           last_element_new = getChipFromOpenDirection(last_direction_new);
13939           direction |= dir;
13940         }
13941         else if (last_direction_old & (dir | dir_opposite))
13942         {
13943           direction |= MV_DIR_OPPOSITE(last_direction_old);
13944         }
13945         else
13946         {
13947           direction |= MV_DIR_OPPOSITE(dir);
13948         }
13949       }
13950     }
13951
13952     new_element = getChipFromOpenDirectionNotEmpty(direction, new_element);
13953
13954     if (last_element_new != EL_UNDEFINED)
13955       MergeAndCloseNeighbourElements(x, y, &new_element,
13956                                      last_x, last_y, &last_element_new,
13957                                      getClosedChip, change_level);
13958   }
13959   else if (IS_SP_HARDWARE_BASE(new_element))
13960   {
13961     int nr = GetSimpleRandom(6);
13962
13963     new_element = (nr == 0 ? EL_SP_HARDWARE_BASE_1 :
13964                    nr == 1 ? EL_SP_HARDWARE_BASE_2 :
13965                    nr == 2 ? EL_SP_HARDWARE_BASE_3 :
13966                    nr == 3 ? EL_SP_HARDWARE_BASE_4 :
13967                    nr == 4 ? EL_SP_HARDWARE_BASE_5 : EL_SP_HARDWARE_BASE_6);
13968   }
13969   else if (new_element == EL_SP_HARDWARE_GREEN ||
13970            new_element == EL_SP_HARDWARE_BLUE ||
13971            new_element == EL_SP_HARDWARE_RED)
13972   {
13973     int nr = GetSimpleRandom(3);
13974
13975     new_element = (nr == 0 ? EL_SP_HARDWARE_GREEN :
13976                    nr == 1 ? EL_SP_HARDWARE_BLUE : EL_SP_HARDWARE_RED);
13977   }
13978   else if (IS_GROUP_ELEMENT(new_element))
13979   {
13980     boolean connected_drawing = FALSE;
13981     int i;
13982
13983     for (i = 0; i < NUM_DIRECTIONS; i++)
13984     {
13985       int xx = x + xy[i].x;
13986       int yy = y + xy[i].y;
13987
13988       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
13989           IS_IN_GROUP_EL(IntelliDrawBuffer[last_x][last_y], new_element))
13990         connected_drawing = TRUE;
13991     }
13992
13993     if (!connected_drawing)
13994       ResolveGroupElement(new_element);
13995
13996     new_element = GetElementFromGroupElement(new_element);
13997   }
13998   else if (IS_BELT_SWITCH(old_element))
13999   {
14000     int belt_nr = getBeltNrFromBeltSwitchElement(old_element);
14001     int belt_dir = getBeltDirFromBeltSwitchElement(old_element);
14002
14003     belt_dir = (belt_dir == MV_LEFT ? MV_NONE :
14004                 belt_dir == MV_NONE ? MV_RIGHT : MV_LEFT);
14005
14006     new_element = getBeltSwitchElementFromBeltNrAndBeltDir(belt_nr, belt_dir);
14007   }
14008   else
14009   {
14010     static int swappable_elements[][2] =
14011     {
14012       { EL_EXIT_CLOSED,                 EL_EXIT_OPEN                    },
14013       { EL_DYNAMITE,                    EL_DYNAMITE_ACTIVE              },
14014       { EL_EM_DYNAMITE,                 EL_EM_DYNAMITE_ACTIVE           },
14015       { EL_QUICKSAND_EMPTY,             EL_QUICKSAND_FULL               },
14016       { EL_EMERALD,                     EL_WALL_EMERALD                 },
14017       { EL_EMERALD_YELLOW,              EL_WALL_EMERALD_YELLOW          },
14018       { EL_EMERALD_RED,                 EL_WALL_EMERALD_RED             },
14019       { EL_EMERALD_PURPLE,              EL_WALL_EMERALD_PURPLE          },
14020       { EL_DIAMOND,                     EL_WALL_DIAMOND                 },
14021       { EL_BD_DIAMOND,                  EL_WALL_BD_DIAMOND              },
14022       { EL_GATE_1,                      EL_GATE_1_GRAY                  },
14023       { EL_GATE_2,                      EL_GATE_2_GRAY                  },
14024       { EL_GATE_3,                      EL_GATE_3_GRAY                  },
14025       { EL_GATE_4,                      EL_GATE_4_GRAY                  },
14026       { EL_EM_GATE_1,                   EL_EM_GATE_1_GRAY               },
14027       { EL_EM_GATE_2,                   EL_EM_GATE_2_GRAY               },
14028       { EL_EM_GATE_3,                   EL_EM_GATE_3_GRAY               },
14029       { EL_EM_GATE_4,                   EL_EM_GATE_4_GRAY               },
14030       { EL_EMC_GATE_5,                  EL_EMC_GATE_5_GRAY              },
14031       { EL_EMC_GATE_6,                  EL_EMC_GATE_6_GRAY              },
14032       { EL_EMC_GATE_7,                  EL_EMC_GATE_7_GRAY              },
14033       { EL_EMC_GATE_8,                  EL_EMC_GATE_8_GRAY              },
14034       { EL_DC_GATE_WHITE,               EL_DC_GATE_WHITE_GRAY           },
14035       { EL_TIME_ORB_EMPTY,              EL_TIME_ORB_FULL                },
14036       { EL_LAMP,                        EL_LAMP_ACTIVE                  },
14037       { EL_SOKOBAN_FIELD_EMPTY,         EL_SOKOBAN_FIELD_FULL           },
14038       { EL_SP_BASE,                     EL_SP_BUGGY_BASE                },
14039       { EL_PEARL,                       EL_WALL_PEARL                   },
14040       { EL_CRYSTAL,                     EL_WALL_CRYSTAL                 },
14041       { EL_TIMEGATE_CLOSED,             EL_TIMEGATE_OPEN                },
14042       { EL_SWITCHGATE_CLOSED,           EL_SWITCHGATE_OPEN              },
14043       { EL_SWITCHGATE_SWITCH_UP,        EL_SWITCHGATE_SWITCH_DOWN       },
14044       { EL_DC_SWITCHGATE_SWITCH_UP,     EL_DC_SWITCHGATE_SWITCH_DOWN    },
14045       { EL_LIGHT_SWITCH,                EL_LIGHT_SWITCH_ACTIVE          },
14046       { EL_LANDMINE,                    EL_DC_LANDMINE                  },
14047       { EL_SHIELD_NORMAL,               EL_SHIELD_DEADLY                },
14048       { EL_STEEL_EXIT_CLOSED,           EL_STEEL_EXIT_OPEN              },
14049       { EL_EM_EXIT_CLOSED,              EL_EM_EXIT_OPEN                 },
14050       { EL_EM_STEEL_EXIT_CLOSED,        EL_EM_STEEL_EXIT_OPEN           },
14051       { EL_QUICKSAND_FAST_EMPTY,        EL_QUICKSAND_FAST_FULL          },
14052       { EL_MM_EXIT_CLOSED,              EL_MM_EXIT_OPEN                 },
14053       { EL_MM_FUSE,                     EL_MM_FUSE_ACTIVE               },
14054       { EL_MM_LIGHTBULB,                EL_MM_LIGHTBULB_ACTIVE          },
14055       { EL_MM_FUEL_EMPTY,               EL_MM_FUEL_FULL                 },
14056
14057       { -1,                             -1                              },
14058     };
14059     static int rotatable_elements_4[][4] =
14060     {
14061       {
14062         EL_BUG_UP,
14063         EL_BUG_RIGHT,
14064         EL_BUG_DOWN,
14065         EL_BUG_LEFT
14066       },
14067       {
14068         EL_SPACESHIP_UP,
14069         EL_SPACESHIP_RIGHT,
14070         EL_SPACESHIP_DOWN,
14071         EL_SPACESHIP_LEFT
14072       },
14073       {
14074         EL_BD_BUTTERFLY_UP,
14075         EL_BD_BUTTERFLY_RIGHT,
14076         EL_BD_BUTTERFLY_DOWN,
14077         EL_BD_BUTTERFLY_LEFT
14078       },
14079       {
14080         EL_BD_FIREFLY_UP,
14081         EL_BD_FIREFLY_RIGHT,
14082         EL_BD_FIREFLY_DOWN,
14083         EL_BD_FIREFLY_LEFT
14084       },
14085       {
14086         EL_PACMAN_UP,
14087         EL_PACMAN_RIGHT,
14088         EL_PACMAN_DOWN,
14089         EL_PACMAN_LEFT
14090       },
14091       {
14092         EL_YAMYAM_UP,
14093         EL_YAMYAM_RIGHT,
14094         EL_YAMYAM_DOWN,
14095         EL_YAMYAM_LEFT
14096       },
14097       {
14098         EL_ARROW_UP,
14099         EL_ARROW_RIGHT,
14100         EL_ARROW_DOWN,
14101         EL_ARROW_LEFT
14102       },
14103       {
14104         EL_SP_PORT_UP,
14105         EL_SP_PORT_RIGHT,
14106         EL_SP_PORT_DOWN,
14107         EL_SP_PORT_LEFT
14108       },
14109       {
14110         EL_SP_GRAVITY_PORT_UP,
14111         EL_SP_GRAVITY_PORT_RIGHT,
14112         EL_SP_GRAVITY_PORT_DOWN,
14113         EL_SP_GRAVITY_PORT_LEFT
14114       },
14115       {
14116         EL_SP_GRAVITY_ON_PORT_UP,
14117         EL_SP_GRAVITY_ON_PORT_RIGHT,
14118         EL_SP_GRAVITY_ON_PORT_DOWN,
14119         EL_SP_GRAVITY_ON_PORT_LEFT
14120       },
14121       {
14122         EL_SP_GRAVITY_OFF_PORT_UP,
14123         EL_SP_GRAVITY_OFF_PORT_RIGHT,
14124         EL_SP_GRAVITY_OFF_PORT_DOWN,
14125         EL_SP_GRAVITY_OFF_PORT_LEFT
14126       },
14127       {
14128         EL_MOLE_UP,
14129         EL_MOLE_RIGHT,
14130         EL_MOLE_DOWN,
14131         EL_MOLE_LEFT
14132       },
14133       {
14134         EL_BALLOON_SWITCH_UP,
14135         EL_BALLOON_SWITCH_RIGHT,
14136         EL_BALLOON_SWITCH_DOWN,
14137         EL_BALLOON_SWITCH_LEFT
14138       },
14139       {
14140         EL_MM_MCDUFFIN_UP,
14141         EL_MM_MCDUFFIN_RIGHT,
14142         EL_MM_MCDUFFIN_DOWN,
14143         EL_MM_MCDUFFIN_LEFT
14144       },
14145       {
14146         EL_MM_MIRROR_FIXED_1,
14147         EL_MM_MIRROR_FIXED_4,
14148         EL_MM_MIRROR_FIXED_3,
14149         EL_MM_MIRROR_FIXED_2
14150       },
14151       {
14152         EL_MM_STEEL_GRID_FIXED_1,
14153         EL_MM_STEEL_GRID_FIXED_4,
14154         EL_MM_STEEL_GRID_FIXED_2,
14155         EL_MM_STEEL_GRID_FIXED_3
14156       },
14157       {
14158         EL_MM_WOODEN_GRID_FIXED_1,
14159         EL_MM_WOODEN_GRID_FIXED_4,
14160         EL_MM_WOODEN_GRID_FIXED_2,
14161         EL_MM_WOODEN_GRID_FIXED_3
14162       },
14163       {
14164         EL_MM_POLARIZER_CROSS_1,
14165         EL_MM_POLARIZER_CROSS_4,
14166         EL_MM_POLARIZER_CROSS_3,
14167         EL_MM_POLARIZER_CROSS_2
14168       },
14169       {
14170         EL_MM_PACMAN_UP,
14171         EL_MM_PACMAN_RIGHT,
14172         EL_MM_PACMAN_DOWN,
14173         EL_MM_PACMAN_LEFT
14174       },
14175       {
14176         EL_DF_LASER_UP,
14177         EL_DF_LASER_RIGHT,
14178         EL_DF_LASER_DOWN,
14179         EL_DF_LASER_LEFT
14180       },
14181       {
14182         EL_DF_RECEIVER_UP,
14183         EL_DF_RECEIVER_RIGHT,
14184         EL_DF_RECEIVER_DOWN,
14185         EL_DF_RECEIVER_LEFT
14186       },
14187       {
14188         EL_DF_SLOPE_1,
14189         EL_DF_SLOPE_4,
14190         EL_DF_SLOPE_3,
14191         EL_DF_SLOPE_2
14192       },
14193
14194       {
14195         -1,
14196       },
14197     };
14198     static int rotatable_elements_8[][8] =
14199     {
14200       {
14201         EL_DF_STEEL_GRID_FIXED_1,
14202         EL_DF_STEEL_GRID_FIXED_8,
14203         EL_DF_STEEL_GRID_FIXED_7,
14204         EL_DF_STEEL_GRID_FIXED_6,
14205         EL_DF_STEEL_GRID_FIXED_5,
14206         EL_DF_STEEL_GRID_FIXED_4,
14207         EL_DF_STEEL_GRID_FIXED_3,
14208         EL_DF_STEEL_GRID_FIXED_2
14209       },
14210       {
14211         EL_DF_WOODEN_GRID_FIXED_1,
14212         EL_DF_WOODEN_GRID_FIXED_8,
14213         EL_DF_WOODEN_GRID_FIXED_7,
14214         EL_DF_WOODEN_GRID_FIXED_6,
14215         EL_DF_WOODEN_GRID_FIXED_5,
14216         EL_DF_WOODEN_GRID_FIXED_4,
14217         EL_DF_WOODEN_GRID_FIXED_3,
14218         EL_DF_WOODEN_GRID_FIXED_2
14219       },
14220       {
14221         EL_DF_STEEL_GRID_ROTATING_1,
14222         EL_DF_STEEL_GRID_ROTATING_8,
14223         EL_DF_STEEL_GRID_ROTATING_7,
14224         EL_DF_STEEL_GRID_ROTATING_6,
14225         EL_DF_STEEL_GRID_ROTATING_5,
14226         EL_DF_STEEL_GRID_ROTATING_4,
14227         EL_DF_STEEL_GRID_ROTATING_3,
14228         EL_DF_STEEL_GRID_ROTATING_2
14229       },
14230       {
14231         EL_DF_WOODEN_GRID_ROTATING_1,
14232         EL_DF_WOODEN_GRID_ROTATING_8,
14233         EL_DF_WOODEN_GRID_ROTATING_7,
14234         EL_DF_WOODEN_GRID_ROTATING_6,
14235         EL_DF_WOODEN_GRID_ROTATING_5,
14236         EL_DF_WOODEN_GRID_ROTATING_4,
14237         EL_DF_WOODEN_GRID_ROTATING_3,
14238         EL_DF_WOODEN_GRID_ROTATING_2
14239       },
14240
14241       {
14242         -1,
14243       },
14244     };
14245     static int rotatable_elements_16[][16] =
14246     {
14247       {
14248         EL_MM_MIRROR_1,
14249         EL_MM_MIRROR_16,
14250         EL_MM_MIRROR_15,
14251         EL_MM_MIRROR_14,
14252         EL_MM_MIRROR_13,
14253         EL_MM_MIRROR_12,
14254         EL_MM_MIRROR_11,
14255         EL_MM_MIRROR_10,
14256         EL_MM_MIRROR_9,
14257         EL_MM_MIRROR_8,
14258         EL_MM_MIRROR_7,
14259         EL_MM_MIRROR_6,
14260         EL_MM_MIRROR_5,
14261         EL_MM_MIRROR_4,
14262         EL_MM_MIRROR_3,
14263         EL_MM_MIRROR_2
14264       },
14265       {
14266         EL_MM_TELEPORTER_5,
14267         EL_MM_TELEPORTER_4,
14268         EL_MM_TELEPORTER_3,
14269         EL_MM_TELEPORTER_2,
14270         EL_MM_TELEPORTER_1,
14271         EL_MM_TELEPORTER_16,
14272         EL_MM_TELEPORTER_15,
14273         EL_MM_TELEPORTER_14,
14274         EL_MM_TELEPORTER_13,
14275         EL_MM_TELEPORTER_12,
14276         EL_MM_TELEPORTER_11,
14277         EL_MM_TELEPORTER_10,
14278         EL_MM_TELEPORTER_9,
14279         EL_MM_TELEPORTER_8,
14280         EL_MM_TELEPORTER_7,
14281         EL_MM_TELEPORTER_6
14282       },
14283       {
14284         EL_MM_TELEPORTER_RED_5,
14285         EL_MM_TELEPORTER_RED_4,
14286         EL_MM_TELEPORTER_RED_3,
14287         EL_MM_TELEPORTER_RED_2,
14288         EL_MM_TELEPORTER_RED_1,
14289         EL_MM_TELEPORTER_RED_16,
14290         EL_MM_TELEPORTER_RED_15,
14291         EL_MM_TELEPORTER_RED_14,
14292         EL_MM_TELEPORTER_RED_13,
14293         EL_MM_TELEPORTER_RED_12,
14294         EL_MM_TELEPORTER_RED_11,
14295         EL_MM_TELEPORTER_RED_10,
14296         EL_MM_TELEPORTER_RED_9,
14297         EL_MM_TELEPORTER_RED_8,
14298         EL_MM_TELEPORTER_RED_7,
14299         EL_MM_TELEPORTER_RED_6
14300       },
14301       {
14302         EL_MM_TELEPORTER_YELLOW_5,
14303         EL_MM_TELEPORTER_YELLOW_4,
14304         EL_MM_TELEPORTER_YELLOW_3,
14305         EL_MM_TELEPORTER_YELLOW_2,
14306         EL_MM_TELEPORTER_YELLOW_1,
14307         EL_MM_TELEPORTER_YELLOW_16,
14308         EL_MM_TELEPORTER_YELLOW_15,
14309         EL_MM_TELEPORTER_YELLOW_14,
14310         EL_MM_TELEPORTER_YELLOW_13,
14311         EL_MM_TELEPORTER_YELLOW_12,
14312         EL_MM_TELEPORTER_YELLOW_11,
14313         EL_MM_TELEPORTER_YELLOW_10,
14314         EL_MM_TELEPORTER_YELLOW_9,
14315         EL_MM_TELEPORTER_YELLOW_8,
14316         EL_MM_TELEPORTER_YELLOW_7,
14317         EL_MM_TELEPORTER_YELLOW_6
14318       },
14319       {
14320         EL_MM_TELEPORTER_GREEN_5,
14321         EL_MM_TELEPORTER_GREEN_4,
14322         EL_MM_TELEPORTER_GREEN_3,
14323         EL_MM_TELEPORTER_GREEN_2,
14324         EL_MM_TELEPORTER_GREEN_1,
14325         EL_MM_TELEPORTER_GREEN_16,
14326         EL_MM_TELEPORTER_GREEN_15,
14327         EL_MM_TELEPORTER_GREEN_14,
14328         EL_MM_TELEPORTER_GREEN_13,
14329         EL_MM_TELEPORTER_GREEN_12,
14330         EL_MM_TELEPORTER_GREEN_11,
14331         EL_MM_TELEPORTER_GREEN_10,
14332         EL_MM_TELEPORTER_GREEN_9,
14333         EL_MM_TELEPORTER_GREEN_8,
14334         EL_MM_TELEPORTER_GREEN_7,
14335         EL_MM_TELEPORTER_GREEN_6
14336       },
14337       {
14338         EL_MM_TELEPORTER_BLUE_5,
14339         EL_MM_TELEPORTER_BLUE_4,
14340         EL_MM_TELEPORTER_BLUE_3,
14341         EL_MM_TELEPORTER_BLUE_2,
14342         EL_MM_TELEPORTER_BLUE_1,
14343         EL_MM_TELEPORTER_BLUE_16,
14344         EL_MM_TELEPORTER_BLUE_15,
14345         EL_MM_TELEPORTER_BLUE_14,
14346         EL_MM_TELEPORTER_BLUE_13,
14347         EL_MM_TELEPORTER_BLUE_12,
14348         EL_MM_TELEPORTER_BLUE_11,
14349         EL_MM_TELEPORTER_BLUE_10,
14350         EL_MM_TELEPORTER_BLUE_9,
14351         EL_MM_TELEPORTER_BLUE_8,
14352         EL_MM_TELEPORTER_BLUE_7,
14353         EL_MM_TELEPORTER_BLUE_6
14354       },
14355       {
14356         EL_MM_POLARIZER_1,
14357         EL_MM_POLARIZER_16,
14358         EL_MM_POLARIZER_15,
14359         EL_MM_POLARIZER_14,
14360         EL_MM_POLARIZER_13,
14361         EL_MM_POLARIZER_12,
14362         EL_MM_POLARIZER_11,
14363         EL_MM_POLARIZER_10,
14364         EL_MM_POLARIZER_9,
14365         EL_MM_POLARIZER_8,
14366         EL_MM_POLARIZER_7,
14367         EL_MM_POLARIZER_6,
14368         EL_MM_POLARIZER_5,
14369         EL_MM_POLARIZER_4,
14370         EL_MM_POLARIZER_3,
14371         EL_MM_POLARIZER_2
14372       },
14373       {
14374         EL_DF_MIRROR_1,
14375         EL_DF_MIRROR_16,
14376         EL_DF_MIRROR_15,
14377         EL_DF_MIRROR_14,
14378         EL_DF_MIRROR_13,
14379         EL_DF_MIRROR_12,
14380         EL_DF_MIRROR_11,
14381         EL_DF_MIRROR_10,
14382         EL_DF_MIRROR_9,
14383         EL_DF_MIRROR_8,
14384         EL_DF_MIRROR_7,
14385         EL_DF_MIRROR_6,
14386         EL_DF_MIRROR_5,
14387         EL_DF_MIRROR_4,
14388         EL_DF_MIRROR_3,
14389         EL_DF_MIRROR_2
14390       },
14391       {
14392         EL_DF_MIRROR_ROTATING_1,
14393         EL_DF_MIRROR_ROTATING_16,
14394         EL_DF_MIRROR_ROTATING_15,
14395         EL_DF_MIRROR_ROTATING_14,
14396         EL_DF_MIRROR_ROTATING_13,
14397         EL_DF_MIRROR_ROTATING_12,
14398         EL_DF_MIRROR_ROTATING_11,
14399         EL_DF_MIRROR_ROTATING_10,
14400         EL_DF_MIRROR_ROTATING_9,
14401         EL_DF_MIRROR_ROTATING_8,
14402         EL_DF_MIRROR_ROTATING_7,
14403         EL_DF_MIRROR_ROTATING_6,
14404         EL_DF_MIRROR_ROTATING_5,
14405         EL_DF_MIRROR_ROTATING_4,
14406         EL_DF_MIRROR_ROTATING_3,
14407         EL_DF_MIRROR_ROTATING_2
14408       },
14409       {
14410         EL_DF_MIRROR_FIXED_1,
14411         EL_DF_MIRROR_FIXED_16,
14412         EL_DF_MIRROR_FIXED_15,
14413         EL_DF_MIRROR_FIXED_14,
14414         EL_DF_MIRROR_FIXED_13,
14415         EL_DF_MIRROR_FIXED_12,
14416         EL_DF_MIRROR_FIXED_11,
14417         EL_DF_MIRROR_FIXED_10,
14418         EL_DF_MIRROR_FIXED_9,
14419         EL_DF_MIRROR_FIXED_8,
14420         EL_DF_MIRROR_FIXED_7,
14421         EL_DF_MIRROR_FIXED_6,
14422         EL_DF_MIRROR_FIXED_5,
14423         EL_DF_MIRROR_FIXED_4,
14424         EL_DF_MIRROR_FIXED_3,
14425         EL_DF_MIRROR_FIXED_2
14426       },
14427
14428       {
14429         -1,
14430       },
14431     };
14432     int i, j;
14433
14434     for (i = 0; swappable_elements[i][0] != -1; i++)
14435     {
14436       int element1 = swappable_elements[i][0];
14437       int element2 = swappable_elements[i][1];
14438
14439       if (old_element == element1 || old_element == element2)
14440         new_element = (old_element == element1 ? element2 : element1);
14441     }
14442
14443     for (i = 0; rotatable_elements_4[i][0] != -1; i++)
14444     {
14445       for (j = 0; j < 4; j++)
14446       {
14447         int element = rotatable_elements_4[i][j];
14448
14449         if (old_element == element)
14450           new_element = (button == 1 ? rotatable_elements_4[i][(j + 3) % 4] :
14451                          button == 2 ? rotatable_elements_4[i][0]           :
14452                          button == 3 ? rotatable_elements_4[i][(j + 1) % 4] :
14453                          old_element);
14454       }
14455     }
14456
14457     for (i = 0; rotatable_elements_8[i][0] != -1; i++)
14458     {
14459       for (j = 0; j < 8; j++)
14460       {
14461         int element = rotatable_elements_8[i][j];
14462
14463         if (old_element == element)
14464           new_element = (button == 1 ? rotatable_elements_8[i][(j + 7) % 8] :
14465                          button == 2 ? rotatable_elements_8[i][0]           :
14466                          button == 3 ? rotatable_elements_8[i][(j + 1) % 8] :
14467                          old_element);
14468       }
14469     }
14470
14471     for (i = 0; rotatable_elements_16[i][0] != -1; i++)
14472     {
14473       for (j = 0; j < 16; j++)
14474       {
14475         int element = rotatable_elements_16[i][j];
14476
14477         if (old_element == element)
14478           new_element = (button == 1 ? rotatable_elements_16[i][(j + 15) % 16] :
14479                          button == 2 ? rotatable_elements_16[i][0]             :
14480                          button == 3 ? rotatable_elements_16[i][(j + 1)  % 16] :
14481                          old_element);
14482       }
14483     }
14484
14485     if (old_element != new_element)
14486     {
14487       int max_infotext_len = getMaxInfoTextLength();
14488       char infotext[MAX_OUTPUT_LINESIZE + 1];
14489
14490       strncpy(infotext, getElementInfoText(new_element), max_infotext_len);
14491       infotext[max_infotext_len] = '\0';
14492
14493       ClearEditorGadgetInfoText();
14494
14495       DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, INFOTEXT_FONT,
14496                 infotext);
14497     }
14498   }
14499
14500   if (IS_MM_WALL_EDITOR(new_element))
14501     SetElementSimpleExt(x, y, dx, dy, new_element, change_level);
14502   else
14503     SetElementSimple(x, y, new_element, change_level);
14504
14505   last_x = x;
14506   last_y = y;
14507 }
14508
14509 static void ResetIntelliDraw(void)
14510 {
14511   int x, y;
14512
14513   for (x = 0; x < lev_fieldx; x++)
14514     for (y = 0; y < lev_fieldy; y++)
14515       IntelliDrawBuffer[x][y] = Tile[x][y];
14516
14517   SetElementIntelliDraw(-1, -1, -1, -1, EL_UNDEFINED, FALSE, -1);
14518 }
14519
14520 static boolean draw_mode_hires = FALSE;
14521
14522 static boolean isHiresTileElement(int element)
14523 {
14524   return (IS_MM_WALL(element)        || element == EL_EMPTY);
14525 }
14526
14527 static boolean isHiresDrawElement(int element)
14528 {
14529   return (IS_MM_WALL_EDITOR(element) || element == EL_EMPTY);
14530 }
14531
14532 static int numHiresTiles(int element)
14533 {
14534   if (IS_MM_WALL(element))
14535     return get_number_of_bits(MM_WALL_BITS(element));
14536
14537   return 1;
14538 }
14539
14540 static void SetDrawModeHiRes(int element)
14541 {
14542   draw_mode_hires =
14543     (level.game_engine_type == GAME_ENGINE_TYPE_MM &&
14544      isHiresDrawElement(element));
14545 }
14546
14547 static boolean getDrawModeHiRes(void)
14548 {
14549   return draw_mode_hires;
14550 }
14551
14552 static int getLoResScreenPos(int pos)
14553 {
14554   return (getDrawModeHiRes() ? pos / 2 : pos);
14555 }
14556
14557 static int getLoResScreenMod(int pos)
14558 {
14559   return (getDrawModeHiRes() ? pos % 2 : 0);
14560 }
14561
14562 static void SetElementExt(int x, int y, int dx, int dy, int element,
14563                           boolean change_level, int button)
14564 {
14565   if (element < 0)
14566     SetElementSimple(x, y, Tile[x][y], change_level);
14567   else if (GetKeyModState() & KMOD_Shift)
14568     SetElementIntelliDraw(x, y, dx, dy, element, change_level, button);
14569   else
14570     SetElementSimpleExt(x, y, dx, dy, element, change_level);
14571 }
14572
14573 static void SetElement(int x, int y, int element)
14574 {
14575   SetElementExt(x, y, 0, 0, element, TRUE, -1);
14576 }
14577
14578 static void SetElementButton(int x, int y, int dx, int dy, int element,
14579                              int button)
14580 {
14581   SetElementExt(x, y, dx, dy, element, TRUE, button);
14582 }
14583
14584 static void SetElementHiRes(int sx2, int sy2, int element, boolean change_level)
14585 {
14586   int lx = getLoResScreenPos(sx2) + level_xpos;
14587   int ly = getLoResScreenPos(sy2) + level_ypos;
14588   int dx = getLoResScreenMod(sx2);
14589   int dy = getLoResScreenMod(sy2);
14590
14591   SetElementExt(lx, ly, dx, dy, element, change_level, -1);
14592 }
14593
14594 static void SetLevelElementHiRes(int lx2, int ly2, int element)
14595 {
14596   int lx = lx2 / 2;
14597   int ly = ly2 / 2;
14598   int dx = lx2 % 2;
14599   int dy = ly2 % 2;
14600
14601   SetElementExt(lx, ly, dx, dy, element, TRUE, -1);
14602 }
14603
14604 static int getLevelElementHiRes(int lx2, int ly2)
14605 {
14606   int lx = lx2 / 2;
14607   int ly = ly2 / 2;
14608   int dx = lx2 % 2;
14609   int dy = ly2 % 2;
14610   int element = Tile[lx][ly];
14611   unsigned int bitmask = (dx + 1) << (dy * 2);
14612
14613   if (IS_MM_WALL(element))
14614   {
14615     if (element & bitmask)
14616       return map_mm_wall_element(element);
14617     else
14618       return EL_EMPTY;
14619   }
14620
14621   return element;
14622 }
14623
14624 static void DrawLineElement(int x, int y, int element, boolean change_level)
14625 {
14626   SetElementHiRes(x, y, element, change_level);
14627 }
14628
14629 static void DrawLine(int from_x, int from_y, int to_x, int to_y,
14630                      int element, boolean change_level)
14631 {
14632   int xsize = ABS(to_x - from_x);
14633   int ysize = ABS(to_y - from_y);
14634   int dx = (to_x < from_x ? -1 : +1);
14635   int dy = (to_y < from_y ? -1 : +1);
14636   int i;
14637
14638   if (from_y == to_y)                   // horizontal line
14639   {
14640     for (i = 0; i <= xsize; i++)
14641       DrawLineElement(from_x + i * dx, from_y, element, change_level);
14642   }
14643   else if (from_x == to_x)              // vertical line
14644   {
14645     for (i = 0; i <= ysize; i++)
14646       DrawLineElement(from_x, from_y + i * dy, element, change_level);
14647   }
14648   else                                  // diagonal line
14649   {
14650     if (ysize < xsize)                  // a < 1
14651     {
14652       float a = (float)ysize / (float)xsize;
14653
14654       for (i = 0; i <= xsize; i++)
14655       {
14656         int x = dx * i;
14657         int y = dy * (int)(a * i + 0.5);
14658
14659         DrawLineElement(from_x + x, from_y + y, element, change_level);
14660       }
14661     }
14662     else                                // a >= 1
14663     {
14664       float a = (float)xsize / (float)ysize;
14665
14666       for (i = 0; i <= ysize; i++)
14667       {
14668         int x = dx * (int)(a * i + 0.5);
14669         int y = dy * i;
14670
14671         DrawLineElement(from_x + x, from_y + y, element, change_level);
14672       }
14673     }
14674   }
14675 }
14676
14677 static void DrawBox(int from_x, int from_y, int to_x, int to_y,
14678                     int element, boolean change_level)
14679 {
14680   DrawLine(from_x, from_y, from_x, to_y, element, change_level);
14681   DrawLine(from_x, to_y, to_x, to_y, element, change_level);
14682   DrawLine(to_x, to_y, to_x, from_y, element, change_level);
14683   DrawLine(to_x, from_y, from_x, from_y, element, change_level);
14684 }
14685
14686 static void DrawFilledBox(int from_x, int from_y, int to_x, int to_y,
14687                           int element, boolean change_level)
14688 {
14689   int y;
14690
14691   if (from_y > to_y)
14692     swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
14693
14694   for (y = from_y; y <= to_y; y++)
14695     DrawLine(from_x, y, to_x, y, element, change_level);
14696 }
14697
14698 static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
14699                        int element, boolean change_level)
14700 {
14701   int to_x = to_x2 - (to_x2 > from_x ? +1 : -1);
14702   int to_y = to_y2 - (to_y2 > from_y ? +1 : -1);
14703   int len_x = ABS(to_x - from_x);
14704   int len_y = ABS(to_y - from_y);
14705   int radius, x, y;
14706
14707   radius = (int)(sqrt((float)(len_x * len_x + len_y * len_y)) + 0.5);
14708
14709   // not optimal (some points get drawn twice) but simple,
14710   // and fast enough for the few points we are drawing
14711
14712   for (x = 0; x <= radius; x++)
14713   {
14714     int sx, sy, sx2, sy2, lx, ly;
14715
14716     y = (int)(sqrt((float)(radius * radius - x * x)) + 0.5);
14717
14718     sx2 = from_x + x * (from_x < to_x2 ? +1 : -1);
14719     sy2 = from_y + y * (from_y < to_y2 ? +1 : -1);
14720     sx = getLoResScreenPos(sx2);
14721     sy = getLoResScreenPos(sy2);
14722     lx = sx + level_xpos;
14723     ly = sy + level_ypos;
14724
14725     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
14726       DrawLineElement(sx2, sy2, element, change_level);
14727   }
14728
14729   for (y = 0; y <= radius; y++)
14730   {
14731     int sx, sy, sx2, sy2, lx, ly;
14732
14733     x = (int)(sqrt((float)(radius * radius - y * y)) + 0.5);
14734
14735     sx2 = from_x + x * (from_x < to_x2 ? +1 : -1);
14736     sy2 = from_y + y * (from_y < to_y2 ? +1 : -1);
14737     sx = getLoResScreenPos(sx2);
14738     sy = getLoResScreenPos(sy2);
14739     lx = sx + level_xpos;
14740     ly = sy + level_ypos;
14741
14742     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
14743       DrawLineElement(sx2, sy2, element, change_level);
14744   }
14745 }
14746
14747 static void DrawArc(int from_x, int from_y, int to_x, int to_y,
14748                     int element, boolean change_level)
14749 {
14750   int to_x2 = to_x + (to_x < from_x ? -1 : +1);
14751   int to_y2 = to_y + (to_y > from_y ? +1 : -1);
14752
14753   DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
14754 }
14755
14756 #define DRAW_CIRCLES_BUTTON_AVAILABLE   0
14757
14758 #if DRAW_CIRCLES_BUTTON_AVAILABLE
14759 static void DrawCircle(int from_x, int from_y, int to_x, int to_y,
14760                        int element, boolean change_level)
14761 {
14762   int to_x2 = to_x + (to_x < from_x ? -1 : +1);
14763   int to_y2 = to_y + (to_y > from_y ? +1 : -1);
14764   int mirror_to_x2 = from_x - (to_x2 - from_x);
14765   int mirror_to_y2 = from_y - (to_y2 - from_y);
14766
14767   DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
14768   DrawArcExt(from_x, from_y, mirror_to_x2, to_y2, element, change_level);
14769   DrawArcExt(from_x, from_y, to_x2, mirror_to_y2, element, change_level);
14770   DrawArcExt(from_x, from_y, mirror_to_x2, mirror_to_y2, element, change_level);
14771 }
14772 #endif
14773
14774 static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y)
14775 {
14776   int from_sx, from_sy;
14777   int to_sx, to_sy;
14778
14779   if (from_x > to_x)
14780     swap_numbers(&from_x, &to_x);
14781
14782   if (from_y > to_y)
14783     swap_numbers(&from_y, &to_y);
14784
14785   from_sx = SX + from_x * ed_tilesize;
14786   from_sy = SY + from_y * ed_tilesize;
14787   to_sx = SX + (to_x + 1) * ed_tilesize - 1;
14788   to_sy = SY + (to_y + 1) * ed_tilesize - 1;
14789
14790   DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx, from_sy);
14791   DrawSimpleWhiteLine(drawto, to_sx, from_sy, to_sx, to_sy);
14792   DrawSimpleWhiteLine(drawto, to_sx, to_sy, from_sx, to_sy);
14793   DrawSimpleWhiteLine(drawto, from_sx, to_sy, from_sx, from_sy);
14794
14795   if (from_x == to_x && from_y == to_y)
14796     MarkTileDirty(from_x/2, from_y/2);
14797   else
14798     redraw_mask |= REDRAW_FIELD;
14799 }
14800
14801 static void DrawAreaBox(int from_x, int from_y, int to_x, int to_y,
14802                         int element, boolean change_level)
14803 {
14804   DrawBox(from_x, from_y, to_x, to_y, element, change_level);
14805 }
14806
14807 static void SelectArea(int from_x, int from_y, int to_x, int to_y,
14808                        int element, boolean change_level)
14809 {
14810   if (element == -1 || change_level)
14811     DrawAreaBox(from_x, from_y, to_x, to_y, -1, FALSE);
14812   else
14813     DrawAreaBorder(from_x, from_y, to_x, to_y);
14814 }
14815
14816 // values for CopyBrushExt()
14817 #define CB_AREA_TO_BRUSH                0
14818 #define CB_BRUSH_TO_CURSOR              1
14819 #define CB_BRUSH_TO_LEVEL               2
14820 #define CB_DELETE_OLD_CURSOR            3
14821 #define CB_DUMP_BRUSH                   4
14822 #define CB_DUMP_BRUSH_SMALL             5
14823 #define CB_CLIPBOARD_TO_BRUSH           6
14824 #define CB_BRUSH_TO_CLIPBOARD           7
14825 #define CB_BRUSH_TO_CLIPBOARD_SMALL     8
14826 #define CB_UPDATE_BRUSH_POSITION        9
14827 #define CB_FLIP_BRUSH_X                 10
14828 #define CB_FLIP_BRUSH_Y                 11
14829 #define CB_FLIP_BRUSH_XY                12
14830
14831 #define MAX_CB_PART_SIZE        10
14832 #define MAX_CB_LINE_SIZE        (MAX_LEV_FIELDX + 1)    // text plus newline
14833 #define MAX_CB_NUM_LINES        (MAX_LEV_FIELDY)
14834 #define MAX_CB_TEXT_SIZE        (MAX_CB_LINE_SIZE *     \
14835                                  MAX_CB_NUM_LINES *     \
14836                                  MAX_CB_PART_SIZE)
14837
14838 static int getFlippedTileExt(int map[], int element)
14839 {
14840   int i;
14841
14842   for (i = 0; map[i] != -1; i++)
14843     if (map[i] == element)
14844       return map[i ^ 1];        // get flipped element by flipping LSB of index
14845
14846   return element;
14847 }
14848
14849 static int getFlippedTileX(int element)
14850 {
14851   int map[] =
14852   {
14853     EL_BD_BUTTERFLY_LEFT,               EL_BD_BUTTERFLY_RIGHT,
14854     EL_BD_FIREFLY_LEFT,                 EL_BD_FIREFLY_RIGHT,
14855     EL_BUG_LEFT,                        EL_BUG_RIGHT,
14856     EL_SPACESHIP_LEFT,                  EL_SPACESHIP_RIGHT,
14857     EL_PACMAN_LEFT,                     EL_PACMAN_RIGHT,
14858     EL_ARROW_LEFT,                      EL_ARROW_RIGHT,
14859     EL_MOLE_LEFT,                       EL_MOLE_RIGHT,
14860     EL_BALLOON_SWITCH_LEFT,             EL_BALLOON_SWITCH_RIGHT,
14861     EL_YAMYAM_LEFT,                     EL_YAMYAM_RIGHT,
14862     EL_SP_PORT_LEFT,                    EL_SP_PORT_RIGHT,
14863     EL_SP_GRAVITY_PORT_LEFT,            EL_SP_GRAVITY_PORT_RIGHT,
14864     EL_SP_GRAVITY_ON_PORT_LEFT,         EL_SP_GRAVITY_ON_PORT_RIGHT,
14865     EL_SP_GRAVITY_OFF_PORT_LEFT,        EL_SP_GRAVITY_OFF_PORT_RIGHT,
14866     EL_CONVEYOR_BELT_1_LEFT,            EL_CONVEYOR_BELT_1_RIGHT,
14867     EL_CONVEYOR_BELT_2_LEFT,            EL_CONVEYOR_BELT_2_RIGHT,
14868     EL_CONVEYOR_BELT_3_LEFT,            EL_CONVEYOR_BELT_3_RIGHT,
14869     EL_CONVEYOR_BELT_4_LEFT,            EL_CONVEYOR_BELT_4_RIGHT,
14870     EL_SPRING_LEFT,                     EL_SPRING_RIGHT,
14871     EL_SP_CHIP_LEFT,                    EL_SP_CHIP_RIGHT,
14872     EL_TUBE_VERTICAL_LEFT,              EL_TUBE_VERTICAL_RIGHT,
14873     EL_TUBE_LEFT_UP,                    EL_TUBE_RIGHT_UP,
14874     EL_TUBE_LEFT_DOWN,                  EL_TUBE_RIGHT_DOWN,
14875     EL_DC_STEELWALL_1_LEFT,             EL_DC_STEELWALL_1_RIGHT,
14876     EL_DC_STEELWALL_1_TOPLEFT,          EL_DC_STEELWALL_1_TOPRIGHT,
14877     EL_DC_STEELWALL_1_BOTTOMLEFT,       EL_DC_STEELWALL_1_BOTTOMRIGHT,
14878     EL_DC_STEELWALL_1_TOPLEFT_2,        EL_DC_STEELWALL_1_TOPRIGHT_2,
14879     EL_DC_STEELWALL_1_BOTTOMLEFT_2,     EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
14880     EL_DC_STEELWALL_2_LEFT,             EL_DC_STEELWALL_2_RIGHT,
14881     EL_ACID_POOL_TOPLEFT,               EL_ACID_POOL_TOPRIGHT,
14882     EL_ACID_POOL_BOTTOMLEFT,            EL_ACID_POOL_BOTTOMRIGHT,
14883
14884     -1
14885   };
14886
14887   return getFlippedTileExt(map, element);
14888 }
14889
14890 static int getFlippedTileY(int element)
14891 {
14892   int map[] =
14893   {
14894     EL_BD_BUTTERFLY_UP,                 EL_BD_BUTTERFLY_DOWN,
14895     EL_BD_FIREFLY_UP,                   EL_BD_FIREFLY_DOWN,
14896     EL_BUG_UP,                          EL_BUG_DOWN,
14897     EL_SPACESHIP_UP,                    EL_SPACESHIP_DOWN,
14898     EL_PACMAN_UP,                       EL_PACMAN_DOWN,
14899     EL_ARROW_UP,                        EL_ARROW_DOWN,
14900     EL_MOLE_UP,                         EL_MOLE_DOWN,
14901     EL_BALLOON_SWITCH_UP,               EL_BALLOON_SWITCH_DOWN,
14902     EL_YAMYAM_UP,                       EL_YAMYAM_DOWN,
14903     EL_SP_PORT_UP,                      EL_SP_PORT_DOWN,
14904     EL_SP_GRAVITY_PORT_UP,              EL_SP_GRAVITY_PORT_DOWN,
14905     EL_SP_GRAVITY_ON_PORT_UP,           EL_SP_GRAVITY_ON_PORT_DOWN,
14906     EL_SP_GRAVITY_OFF_PORT_UP,          EL_SP_GRAVITY_OFF_PORT_DOWN,
14907     EL_SP_CHIP_TOP,                     EL_SP_CHIP_BOTTOM,
14908     EL_TUBE_HORIZONTAL_UP,              EL_TUBE_HORIZONTAL_DOWN,
14909     EL_TUBE_LEFT_UP,                    EL_TUBE_LEFT_DOWN,
14910     EL_TUBE_RIGHT_UP,                   EL_TUBE_RIGHT_DOWN,
14911     EL_DC_STEELWALL_1_TOP,              EL_DC_STEELWALL_1_BOTTOM,
14912     EL_DC_STEELWALL_1_TOPLEFT,          EL_DC_STEELWALL_1_BOTTOMLEFT,
14913     EL_DC_STEELWALL_1_TOPRIGHT,         EL_DC_STEELWALL_1_BOTTOMRIGHT,
14914     EL_DC_STEELWALL_1_TOPLEFT_2,        EL_DC_STEELWALL_1_BOTTOMLEFT_2,
14915     EL_DC_STEELWALL_1_TOPRIGHT_2,       EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
14916     EL_DC_STEELWALL_2_TOP,              EL_DC_STEELWALL_2_BOTTOM,
14917     EL_EMC_WALL_1,                      EL_EMC_WALL_3,
14918
14919     -1
14920   };
14921
14922   return getFlippedTileExt(map, element);
14923 }
14924
14925 static int getFlippedTileXY(int element)
14926 {
14927   int map[] =
14928   {
14929     EL_BD_BUTTERFLY_LEFT,               EL_BD_BUTTERFLY_UP,
14930     EL_BD_BUTTERFLY_RIGHT,              EL_BD_BUTTERFLY_DOWN,
14931     EL_BD_FIREFLY_LEFT,                 EL_BD_FIREFLY_UP,
14932     EL_BD_FIREFLY_RIGHT,                EL_BD_FIREFLY_DOWN,
14933     EL_BUG_LEFT,                        EL_BUG_UP,
14934     EL_BUG_RIGHT,                       EL_BUG_DOWN,
14935     EL_SPACESHIP_LEFT,                  EL_SPACESHIP_UP,
14936     EL_SPACESHIP_RIGHT,                 EL_SPACESHIP_DOWN,
14937     EL_PACMAN_LEFT,                     EL_PACMAN_UP,
14938     EL_PACMAN_RIGHT,                    EL_PACMAN_DOWN,
14939     EL_ARROW_LEFT,                      EL_ARROW_UP,
14940     EL_ARROW_RIGHT,                     EL_ARROW_DOWN,
14941     EL_MOLE_LEFT,                       EL_MOLE_UP,
14942     EL_MOLE_RIGHT,                      EL_MOLE_DOWN,
14943     EL_BALLOON_SWITCH_LEFT,             EL_BALLOON_SWITCH_UP,
14944     EL_BALLOON_SWITCH_RIGHT,            EL_BALLOON_SWITCH_DOWN,
14945     EL_YAMYAM_LEFT,                     EL_YAMYAM_UP,
14946     EL_YAMYAM_RIGHT,                    EL_YAMYAM_DOWN,
14947     EL_SP_PORT_LEFT,                    EL_SP_PORT_UP,
14948     EL_SP_PORT_RIGHT,                   EL_SP_PORT_DOWN,
14949     EL_SP_GRAVITY_PORT_LEFT,            EL_SP_GRAVITY_PORT_UP,
14950     EL_SP_GRAVITY_PORT_RIGHT,           EL_SP_GRAVITY_PORT_DOWN,
14951     EL_SP_GRAVITY_ON_PORT_LEFT,         EL_SP_GRAVITY_ON_PORT_UP,
14952     EL_SP_GRAVITY_ON_PORT_RIGHT,        EL_SP_GRAVITY_ON_PORT_DOWN,
14953     EL_SP_GRAVITY_OFF_PORT_LEFT,        EL_SP_GRAVITY_OFF_PORT_UP,
14954     EL_SP_GRAVITY_OFF_PORT_RIGHT,       EL_SP_GRAVITY_OFF_PORT_DOWN,
14955     EL_SP_CHIP_LEFT,                    EL_SP_CHIP_TOP,
14956     EL_SP_CHIP_RIGHT,                   EL_SP_CHIP_BOTTOM,
14957     EL_TUBE_VERTICAL,                   EL_TUBE_HORIZONTAL,
14958     EL_TUBE_VERTICAL_LEFT,              EL_TUBE_HORIZONTAL_UP,
14959     EL_TUBE_VERTICAL_RIGHT,             EL_TUBE_HORIZONTAL_DOWN,
14960     EL_TUBE_LEFT_DOWN,                  EL_TUBE_RIGHT_UP,
14961     EL_DC_STEELWALL_1_LEFT,             EL_DC_STEELWALL_1_TOP,
14962     EL_DC_STEELWALL_1_RIGHT,            EL_DC_STEELWALL_1_BOTTOM,
14963     EL_DC_STEELWALL_1_HORIZONTAL,       EL_DC_STEELWALL_1_VERTICAL,
14964     EL_DC_STEELWALL_1_TOPRIGHT,         EL_DC_STEELWALL_1_BOTTOMLEFT,
14965     EL_DC_STEELWALL_1_TOPRIGHT_2,       EL_DC_STEELWALL_1_BOTTOMLEFT_2,
14966     EL_DC_STEELWALL_2_LEFT,             EL_DC_STEELWALL_2_TOP,
14967     EL_DC_STEELWALL_2_RIGHT,            EL_DC_STEELWALL_2_BOTTOM,
14968     EL_DC_STEELWALL_2_HORIZONTAL,       EL_DC_STEELWALL_2_VERTICAL,
14969     EL_EXPANDABLE_WALL_HORIZONTAL,      EL_EXPANDABLE_WALL_VERTICAL,
14970     EL_EXPANDABLE_STEELWALL_HORIZONTAL, EL_EXPANDABLE_STEELWALL_VERTICAL,
14971
14972     -1
14973   };
14974
14975   return getFlippedTileExt(map, element);
14976 }
14977
14978 static int getFlippedTile(int element, int mode)
14979 {
14980   if (IS_MM_ELEMENT(element))
14981   {
14982     // get MM game element
14983     element = map_element_RND_to_MM(element);
14984
14985     // get flipped game element
14986     element = (mode == CB_FLIP_BRUSH_X  ? getFlippedTileX_MM(element) :
14987                mode == CB_FLIP_BRUSH_Y  ? getFlippedTileY_MM(element) :
14988                mode == CB_FLIP_BRUSH_XY ? getFlippedTileXY_MM(element) :
14989                element);
14990
14991     // get RND game element again
14992     element = map_element_MM_to_RND(element);
14993   }
14994   else
14995   {
14996     // get flipped game element
14997     element = (mode == CB_FLIP_BRUSH_X  ? getFlippedTileX(element) :
14998                mode == CB_FLIP_BRUSH_Y  ? getFlippedTileY(element) :
14999                mode == CB_FLIP_BRUSH_XY ? getFlippedTileXY(element) :
15000                element);
15001   }
15002
15003   return element;
15004 }
15005
15006 static void SwapFlippedTiles(short *tile1, short *tile2, int mode)
15007 {
15008   // flip tiles
15009   short tile1_flipped = getFlippedTile(*tile1, mode);
15010   short tile2_flipped = getFlippedTile(*tile2, mode);
15011
15012   // swap tiles
15013   *tile1 = tile2_flipped;
15014   *tile2 = tile1_flipped;
15015 }
15016
15017 static void DrawBrushElement(int sx, int sy, int element, boolean change_level)
15018 {
15019   DrawLineElement(sx, sy, element, change_level);
15020 }
15021
15022 static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
15023                          int button, int mode)
15024 {
15025   static short brush_buffer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
15026   static int brush_width, brush_height;
15027   static int last_cursor_x = -1, last_cursor_y = -1;
15028   static boolean delete_old_brush = FALSE;
15029   int new_element = BUTTON_ELEMENT(button);
15030   int x, y;
15031
15032   if (mode == CB_DUMP_BRUSH ||
15033       mode == CB_DUMP_BRUSH_SMALL ||
15034       mode == CB_BRUSH_TO_CLIPBOARD ||
15035       mode == CB_BRUSH_TO_CLIPBOARD_SMALL)
15036   {
15037     if (edit_mode != ED_MODE_DRAWING)
15038       return;
15039
15040     char part[MAX_CB_PART_SIZE + 1] = "";
15041     char text[MAX_CB_TEXT_SIZE + 1] = "";
15042     int width  = (draw_with_brush ? brush_width  : lev_fieldx);
15043     int height = (draw_with_brush ? brush_height : lev_fieldy);
15044     char *format = "%s%03d";
15045
15046     for (y = 0; y < height; y++)
15047       for (x = 0; x < width; x++)
15048         if ((draw_with_brush ? brush_buffer[x][y] : Tile[x][y]) > 999)
15049           format = "%s%04d";
15050
15051     for (y = 0; y < height; y++)
15052     {
15053       for (x = 0; x < width; x++)
15054       {
15055         int element = (draw_with_brush ? brush_buffer[x][y] : Tile[x][y]);
15056         char *prefix = (mode == CB_DUMP_BRUSH ||
15057                         mode == CB_BRUSH_TO_CLIPBOARD ? "`" : "¸");
15058
15059         if (element >= NUM_FILE_ELEMENTS)
15060           element = EL_UNKNOWN;
15061
15062         // copy brush to level sketch text buffer for the R'n'D forum:
15063         // - large tiles: `xxx or `xxxx (0x60 ASCII)
15064         // - small tiles: Â¸xxx or Â¸xxxx (0xb8 ISO-8859-1, 0xc2b8 UTF-8)
15065         snprintf(part, MAX_CB_PART_SIZE + 1, format, prefix, element);
15066         strcat(text, part);
15067       }
15068
15069       strcat(text, "\n");
15070     }
15071
15072     if (mode == CB_BRUSH_TO_CLIPBOARD ||
15073         mode == CB_BRUSH_TO_CLIPBOARD_SMALL)
15074       SDL_SetClipboardText(text);
15075     else
15076       Print("%s", text);        // print brush data to console and log file
15077
15078     return;
15079   }
15080
15081   if (mode == CB_CLIPBOARD_TO_BRUSH)
15082   {
15083     if (edit_mode != ED_MODE_DRAWING)
15084       return;
15085
15086     if (!SDL_HasClipboardText())
15087     {
15088       Request("Clipboard is empty!", REQ_CONFIRM);
15089
15090       return;
15091     }
15092
15093     boolean copy_to_brush = (draw_with_brush ||
15094                              drawing_function == GADGET_ID_GRAB_BRUSH);
15095
15096     // this will delete the old brush, if already drawing with a brush
15097     if (copy_to_brush)
15098       ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS], MB_LEFTBUTTON);
15099
15100     // initialization is required for "odd" (incomplete) clipboard content
15101     for (x = 0; x < MAX_LEV_FIELDX; x++)
15102       for (y = 0; y < MAX_LEV_FIELDY; y++)
15103         brush_buffer[x][y] = EL_EMPTY;
15104
15105     brush_width  = 0;
15106     brush_height = 0;
15107     x = 0;
15108     y = 0;
15109
15110     char *clipboard_text = SDL_GetClipboardText();
15111     char *ptr = clipboard_text;
15112     boolean allow_new_row = FALSE;
15113     boolean stop = FALSE;
15114
15115     while (*ptr && !stop)
15116     {
15117       boolean prefix_found = FALSE;
15118       boolean start_new_row = FALSE;
15119
15120       // level sketch element number prefixes (may be multi-byte characters)
15121       char *prefix_list[] = { "`", "¸" };
15122       int i;
15123
15124       for (i = 0; i < ARRAY_SIZE(prefix_list); i++)
15125       {
15126         char *prefix = prefix_list[i];
15127
15128         // check if string is large enough for prefix
15129         if (strlen(ptr) < strlen(prefix))
15130         {
15131           stop = TRUE;
15132
15133           break;
15134         }
15135
15136         // check if string starts with prefix
15137         if (strPrefix(ptr, prefix))
15138         {
15139           ptr += strlen(prefix);
15140
15141           prefix_found = TRUE;
15142
15143           break;
15144         }
15145       }
15146
15147       // check if prefix found and followed by (at least) three digits
15148       if (prefix_found &&
15149           strlen(ptr) >= 3 &&
15150           ptr[0] >= '0' && ptr[0] <= '9' &&
15151           ptr[1] >= '0' && ptr[1] <= '9' &&
15152           ptr[2] >= '0' && ptr[2] <= '9')
15153       {
15154         int element = ((ptr[0] - '0') * 100 +
15155                        (ptr[1] - '0') * 10 +
15156                        (ptr[2] - '0'));
15157
15158         ptr += 3;
15159
15160         // level sketch element number might consist of four digits
15161         if (ptr[0] >= '0' && ptr[0] <= '9')
15162         {
15163           element = element * 10 + (ptr[0] - '0');
15164           ptr++;
15165         }
15166
15167         // remap some (historic, now obsolete) elements
15168         element = getMappedElement(element);
15169
15170         if (element >= NUM_FILE_ELEMENTS)
15171           element = EL_UNKNOWN;
15172
15173         brush_buffer[x][y] = element;
15174
15175         brush_width  = MAX(x + 1, brush_width);
15176         brush_height = MAX(y + 1, brush_height);
15177
15178         x++;
15179
15180         if (x >= MAX_LEV_FIELDX)
15181           start_new_row = TRUE;
15182
15183         allow_new_row = TRUE;
15184       }
15185       else
15186       {
15187         if ((*ptr == '\n' || *ptr == '\r') && allow_new_row)
15188           start_new_row = TRUE;
15189
15190         ptr++;          // !!! FIX THIS for real UTF-8 handling !!!
15191       }
15192
15193       if (start_new_row)
15194       {
15195         x = 0;
15196         y++;
15197
15198         if (y >= MAX_LEV_FIELDY)
15199           stop = TRUE;
15200
15201         allow_new_row = FALSE;
15202       }
15203     }
15204
15205     SDL_free(clipboard_text);
15206
15207     if (brush_width == 0 || brush_height == 0)
15208     {
15209       Request("No level sketch found in clipboard!", REQ_CONFIRM);
15210
15211       return;
15212     }
15213
15214     if (copy_to_brush)
15215     {
15216       struct GadgetInfo *gi = level_editor_gadget[GADGET_ID_DRAWING_LEVEL];
15217       int mx, my;
15218
15219       SDL_GetMouseState(&mx, &my);
15220
15221       // if inside drawing area, activate and draw brush at last mouse position
15222       if (mx >= gi->x && mx < gi->x + gi->width &&
15223           my >= gi->y && my < gi->y + gi->height)
15224         CopyBrushToCursor(last_cursor_x, last_cursor_y);
15225
15226       draw_with_brush = TRUE;
15227     }
15228     else
15229     {
15230       char request[100];
15231
15232       sprintf(request, "Replace level with %dx%d level sketch from clipboard?",
15233               brush_width, brush_height);
15234
15235       if (!Request(request, REQ_ASK))
15236         return;
15237
15238       for (x = 0; x < MAX_LEV_FIELDX; x++)
15239         for (y = 0; y < MAX_LEV_FIELDY; y++)
15240           Tile[x][y] = brush_buffer[x][y];
15241
15242       lev_fieldx = level.fieldx = brush_width;
15243       lev_fieldy = level.fieldy = brush_height;
15244
15245       boolean use_bd_engine = TRUE;
15246       boolean use_em_engine = TRUE;
15247       boolean use_sp_engine = TRUE;
15248       boolean use_mm_engine = TRUE;
15249
15250       for (x = 0; x < MAX_LEV_FIELDX; x++)
15251       {
15252         for (y = 0; y < MAX_LEV_FIELDY; y++)
15253         {
15254           int element = Tile[x][y];
15255
15256           if (!IS_BD_ELEMENT(element) && !IS_PLAYER_ELEMENT(element))
15257             use_bd_engine = FALSE;
15258
15259           if (!IS_EM_ELEMENT(element) && !IS_PLAYER_ELEMENT(element))
15260             use_em_engine = FALSE;
15261
15262           if (!IS_SP_ELEMENT(element))
15263             use_sp_engine = FALSE;
15264
15265           if (!IS_MM_ELEMENT(element) && element != EL_EMPTY)
15266             use_mm_engine = FALSE;
15267         }
15268       }
15269
15270       level.game_engine_type = (use_bd_engine ? GAME_ENGINE_TYPE_BD :
15271                                 use_em_engine ? GAME_ENGINE_TYPE_EM :
15272                                 use_sp_engine ? GAME_ENGINE_TYPE_SP :
15273                                 use_mm_engine ? GAME_ENGINE_TYPE_MM :
15274                                 GAME_ENGINE_TYPE_RND);
15275
15276       // update element selection list
15277       ReinitializeElementList();
15278       ModifyEditorElementList();
15279
15280       SetBorderElement();
15281
15282       DrawEditModeWindow();
15283       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
15284     }
15285
15286     return;
15287   }
15288
15289   if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush)
15290     return;
15291
15292   if (mode == CB_AREA_TO_BRUSH)
15293   {
15294     int from_lx, from_ly;
15295
15296     if (from_x > to_x)
15297       swap_numbers(&from_x, &to_x);
15298
15299     if (from_y > to_y)
15300       swap_numbers(&from_y, &to_y);
15301
15302     brush_width = to_x - from_x + 1;
15303     brush_height = to_y - from_y + 1;
15304
15305     from_lx = from_x + level_xpos;
15306     from_ly = from_y + level_ypos;
15307
15308     for (y = 0; y < brush_height; y++)
15309     {
15310       for (x = 0; x < brush_width; x++)
15311       {
15312         brush_buffer[x][y] = Tile[from_lx + x][from_ly + y];
15313
15314         if (button != 1)
15315           DrawBrushElement(from_x + x, from_y + y, new_element, TRUE);
15316       }
15317     }
15318
15319     if (button != 1)
15320       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
15321
15322     delete_old_brush = FALSE;
15323   }
15324   else if (mode == CB_BRUSH_TO_CURSOR || mode == CB_DELETE_OLD_CURSOR ||
15325            mode == CB_BRUSH_TO_LEVEL)
15326   {
15327     int cursor_x = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_x : from_x);
15328     int cursor_y = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_y : from_y);
15329     int cursor_from_x = cursor_x - brush_width / 2;
15330     int cursor_from_y = cursor_y - brush_height / 2;
15331     int border_from_x = cursor_x, border_from_y = cursor_y;
15332     int border_to_x = cursor_x, border_to_y = cursor_y;
15333
15334     if (mode != CB_DELETE_OLD_CURSOR && delete_old_brush)
15335       CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
15336
15337     if (!IN_ED_FIELD(cursor_x, cursor_y) ||
15338         !IN_LEV_FIELD(cursor_x + level_xpos, cursor_y + level_ypos))
15339     {
15340       delete_old_brush = FALSE;
15341
15342       return;
15343     }
15344
15345     for (y = 0; y < brush_height; y++)
15346     {
15347       for (x = 0; x < brush_width; x++)
15348       {
15349         int sx = cursor_from_x + x;
15350         int sy = cursor_from_y + y;
15351         int lx = sx + level_xpos;
15352         int ly = sy + level_ypos;
15353         boolean change_level = (mode == CB_BRUSH_TO_LEVEL);
15354         int element = (mode == CB_DELETE_OLD_CURSOR ? -1 :
15355                        mode == CB_BRUSH_TO_CURSOR || button == 1 ?
15356                        brush_buffer[x][y] : new_element);
15357
15358         if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
15359         {
15360           if (sx < border_from_x)
15361             border_from_x = sx;
15362           else if (sx > border_to_x)
15363             border_to_x = sx;
15364           if (sy < border_from_y)
15365             border_from_y = sy;
15366           else if (sy > border_to_y)
15367             border_to_y = sy;
15368
15369           DrawBrushElement(sx, sy, element, change_level);
15370         }
15371       }
15372     }
15373
15374     if (mode != CB_DELETE_OLD_CURSOR)
15375       DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y);
15376
15377     last_cursor_x = cursor_x;
15378     last_cursor_y = cursor_y;
15379
15380     delete_old_brush = TRUE;
15381   }
15382   else if (mode == CB_FLIP_BRUSH_X)
15383   {
15384     for (y = 0; y < brush_height; y++)
15385       for (x = 0; x < (brush_width + 1) / 2; x++)
15386         SwapFlippedTiles(&brush_buffer[x][y],
15387                          &brush_buffer[brush_width - x - 1][y], mode);
15388
15389     CopyBrushExt(last_cursor_x, last_cursor_y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
15390   }
15391   else if (mode == CB_FLIP_BRUSH_Y)
15392   {
15393     for (y = 0; y < (brush_height + 1) / 2; y++)
15394       for (x = 0; x < brush_width; x++)
15395         SwapFlippedTiles(&brush_buffer[x][y],
15396                          &brush_buffer[x][brush_height - y - 1], mode);
15397
15398     CopyBrushExt(last_cursor_x, last_cursor_y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
15399   }
15400   else if (mode == CB_FLIP_BRUSH_XY)
15401   {
15402     CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
15403
15404     for (y = 0; y < MAX(brush_width, brush_height); y++)
15405       for (x = 0; x <= y; x++)
15406         SwapFlippedTiles(&brush_buffer[x][y],
15407                          &brush_buffer[y][x], mode);
15408
15409     swap_numbers(&brush_width, &brush_height);
15410
15411     CopyBrushExt(last_cursor_x, last_cursor_y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
15412   }
15413
15414   if (mode == CB_UPDATE_BRUSH_POSITION)
15415   {
15416     last_cursor_x = from_x;
15417     last_cursor_y = from_y;
15418   }
15419 }
15420
15421 static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y,
15422                             int button)
15423 {
15424   CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH);
15425 }
15426
15427 static void CopyBrushToLevel(int x, int y, int button)
15428 {
15429   CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL);
15430 }
15431
15432 static void CopyBrushToCursor(int x, int y)
15433 {
15434   CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
15435 }
15436
15437 static void UpdateBrushPosition(int x, int y)
15438 {
15439   CopyBrushExt(x, y, 0, 0, 0, CB_UPDATE_BRUSH_POSITION);
15440 }
15441
15442 static void DeleteBrushFromCursor(void)
15443 {
15444   CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
15445 }
15446
15447 static void FlipBrushX(void)
15448 {
15449   CopyBrushExt(0, 0, 0, 0, 0, CB_FLIP_BRUSH_X);
15450 }
15451
15452 static void FlipBrushY(void)
15453 {
15454   CopyBrushExt(0, 0, 0, 0, 0, CB_FLIP_BRUSH_Y);
15455 }
15456
15457 static void RotateBrush(void)
15458 {
15459   CopyBrushExt(0, 0, 0, 0, 0, CB_FLIP_BRUSH_XY);
15460   CopyBrushExt(0, 0, 0, 0, 0, CB_FLIP_BRUSH_X);
15461 }
15462
15463 void DumpBrush(void)
15464 {
15465   CopyBrushExt(0, 0, 0, 0, 0, CB_DUMP_BRUSH);
15466 }
15467
15468 void DumpBrush_Small(void)
15469 {
15470   CopyBrushExt(0, 0, 0, 0, 0, CB_DUMP_BRUSH_SMALL);
15471 }
15472
15473 void CopyClipboardToBrush(void)
15474 {
15475   CopyBrushExt(0, 0, 0, 0, 0, CB_CLIPBOARD_TO_BRUSH);
15476 }
15477
15478 void CopyBrushToClipboard(void)
15479 {
15480   CopyBrushExt(0, 0, 0, 0, 0, CB_BRUSH_TO_CLIPBOARD);
15481 }
15482
15483 void CopyBrushToClipboard_Small(void)
15484 {
15485   CopyBrushExt(0, 0, 0, 0, 0, CB_BRUSH_TO_CLIPBOARD_SMALL);
15486 }
15487
15488 void UndoLevelEditorOperation(void)
15489 {
15490   ClickOnGadget(level_editor_gadget[GADGET_ID_UNDO], -1);
15491 }
15492
15493 void RedoLevelEditorOperation(void)
15494 {
15495   ClickOnGadget(level_editor_gadget[GADGET_ID_UNDO], 3);
15496 }
15497
15498 static void FloodFill(int from_x, int from_y, int fill_element)
15499 {
15500   FloodFillLevel(from_x, from_y, fill_element, Tile, lev_fieldx, lev_fieldy);
15501 }
15502
15503 static void FloodFillWall_MM(int from_sx2, int from_sy2, int fill_element)
15504 {
15505   int from_x = from_sx2 + 2 * level_xpos;
15506   int from_y = from_sy2 + 2 * level_ypos;
15507   int max_fillx = lev_fieldx * 2;
15508   int max_filly = lev_fieldy * 2;
15509   short Fill[max_fillx][max_filly];
15510   int x, y;
15511
15512   for (x = 0; x < max_fillx; x++)
15513     for (y = 0; y < max_filly; y++)
15514       Fill[x][y] = getLevelElementHiRes(x, y);
15515
15516   FloodFillLevelExt(from_x, from_y, fill_element, max_fillx, max_filly,
15517                     Fill, max_fillx, max_filly);
15518
15519   for (x = 0; x < max_fillx; x++)
15520     for (y = 0; y < max_filly; y++)
15521       if (Fill[x][y] == fill_element)
15522         SetLevelElementHiRes(x, y, Fill[x][y]);
15523 }
15524
15525 // values for DrawLevelText() modes
15526 #define TEXT_INIT               0
15527 #define TEXT_SETCURSOR          1
15528 #define TEXT_WRITECHAR          2
15529 #define TEXT_BACKSPACE          3
15530 #define TEXT_NEWLINE            4
15531 #define TEXT_END                5
15532 #define TEXT_QUERY_TYPING       6
15533
15534 static int DrawLevelText(int sx, int sy, char letter, int mode)
15535 {
15536   static short delete_buffer[MAX_LEV_FIELDX];
15537   static int start_sx;
15538   static int last_sx, last_sy;
15539   static boolean typing = FALSE;
15540   int letter_element;
15541   int lx = 0, ly = 0;
15542
15543   // map lower case letters to upper case and convert special characters
15544   if (letter >= 'a' && letter <= 'z')
15545     letter_element = EL_CHAR_ASCII0 + letter + (int)('A' - 'a');
15546   else if (letter == CHAR_BYTE_UMLAUT_a || letter == CHAR_BYTE_UMLAUT_A)
15547     letter_element = EL_CHAR_AUMLAUT;
15548   else if (letter == CHAR_BYTE_UMLAUT_o || letter == CHAR_BYTE_UMLAUT_O)
15549     letter_element = EL_CHAR_OUMLAUT;
15550   else if (letter == CHAR_BYTE_UMLAUT_u || letter == CHAR_BYTE_UMLAUT_U)
15551     letter_element = EL_CHAR_UUMLAUT;
15552   else if (letter == '^')
15553     letter_element = EL_CHAR_COPYRIGHT;
15554   else
15555     letter_element = EL_CHAR_ASCII0 + letter;
15556
15557   if (mode != TEXT_INIT)
15558   {
15559     if (!typing)
15560       return FALSE;
15561
15562     if (mode != TEXT_SETCURSOR)
15563     {
15564       sx = last_sx;
15565       sy = last_sy;
15566     }
15567
15568     lx = last_sx + level_xpos;
15569     ly = last_sy + level_ypos;
15570   }
15571
15572   switch (mode)
15573   {
15574     case TEXT_INIT:
15575       if (typing)
15576         DrawLevelText(0, 0, 0, TEXT_END);
15577
15578       typing = TRUE;
15579       start_sx = sx;
15580       last_sx = sx;
15581       last_sy = sy;
15582       DrawLevelText(sx, sy, 0, TEXT_SETCURSOR);
15583       break;
15584
15585     case TEXT_SETCURSOR:
15586       DrawEditorElement(last_sx, last_sy, Tile[lx][ly]);
15587       DrawAreaBorder(sx, sy, sx, sy);
15588       StartTextInput(SX + sx * ed_tilesize, SY + sy * ed_tilesize,
15589                      ed_tilesize, ed_tilesize);
15590       last_sx = sx;
15591       last_sy = sy;
15592       break;
15593
15594     case TEXT_WRITECHAR:
15595       if (letter_element >= EL_CHAR_START && letter_element <= EL_CHAR_END)
15596       {
15597         if (new_element1 >= EL_STEEL_CHAR_START &&
15598             new_element1 <= EL_STEEL_CHAR_END)
15599           letter_element = letter_element - EL_CHAR_START + EL_STEEL_CHAR_START;
15600
15601         delete_buffer[sx - start_sx] = Tile[lx][ly];
15602         Tile[lx][ly] = letter_element;
15603
15604         if (sx + 1 < ed_fieldx && lx + 1 < lev_fieldx)
15605           DrawLevelText(sx + 1, sy, 0, TEXT_SETCURSOR);
15606         else if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
15607           DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
15608         else
15609           DrawLevelText(0, 0, 0, TEXT_END);
15610
15611         level.changed = TRUE;
15612       }
15613       break;
15614
15615     case TEXT_BACKSPACE:
15616       if (sx > start_sx)
15617       {
15618         Tile[lx - 1][ly] = delete_buffer[sx - start_sx - 1];
15619         DrawEditorElement(sx - 1, sy, Tile[lx - 1][ly]);
15620         DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR);
15621       }
15622       break;
15623
15624     case TEXT_NEWLINE:
15625       if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
15626         DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
15627       else
15628         DrawLevelText(0, 0, 0, TEXT_END);
15629       break;
15630
15631     case TEXT_END:
15632       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
15633       DrawEditorElement(sx, sy, Tile[lx][ly]);
15634       StopTextInput();
15635       typing = FALSE;
15636       break;
15637
15638     case TEXT_QUERY_TYPING:
15639       break;
15640
15641     default:
15642       break;
15643   }
15644
15645   return typing;
15646 }
15647
15648 static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy,
15649                           int element, boolean change_level)
15650 {
15651   int lx = sx + level_xpos;
15652   int ly = sy + level_ypos;
15653
15654   if (element == -1)
15655     DrawEditorElement(sx, sy, Tile[lx][ly]);
15656   else
15657     DrawAreaBorder(sx, sy, sx, sy);
15658 }
15659
15660 static void CheckLevelBorderElement(boolean redraw_playfield)
15661 {
15662   int last_border_element = BorderElement;
15663
15664   SetBorderElement();
15665
15666   if (redraw_playfield && BorderElement != last_border_element)
15667     DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
15668 }
15669
15670 static void CopyLevelToUndoBuffer(int mode)
15671 {
15672   static boolean accumulated_undo = FALSE;
15673   boolean new_undo_buffer_position = TRUE;
15674   int x, y;
15675
15676   if (undo_buffer_steps == 0)
15677     accumulated_undo = FALSE;
15678
15679   switch (mode)
15680   {
15681     case UNDO_IMMEDIATE:
15682       accumulated_undo = FALSE;
15683       break;
15684
15685     case UNDO_ACCUMULATE:
15686       if (accumulated_undo)
15687         new_undo_buffer_position = FALSE;
15688       accumulated_undo = TRUE;
15689       break;
15690
15691     default:
15692       break;
15693   }
15694
15695   if (new_undo_buffer_position)
15696   {
15697     // advance position in undo buffer ring
15698     undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS;
15699
15700     if (undo_buffer_steps < NUM_UNDO_STEPS - 1)
15701       undo_buffer_steps++;
15702   }
15703
15704   // always reset redo buffer when storing level change into undo buffer
15705   redo_buffer_steps = 0;
15706
15707   for (x = 0; x < lev_fieldx; x++)
15708     for (y = 0; y < lev_fieldy; y++)
15709       UndoBuffer[undo_buffer_position][x][y] = Tile[x][y];
15710
15711   // check if drawing operation forces change of border style
15712   CheckLevelBorderElement(TRUE);
15713
15714   level.changed = TRUE;
15715 }
15716
15717 static void RandomPlacement(int new_element)
15718 {
15719   static boolean free_position[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
15720   int num_free_positions = 0;
15721   int num_percentage, num_elements;
15722   int x, y;
15723
15724   ResetIntelliDraw();
15725
15726   // determine number of free positions for randomly placing the new element
15727   for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
15728   {
15729     free_position[x][y] =
15730       (random_placement_background_restricted ?
15731        Tile[x][y] == random_placement_background_element :
15732        Tile[x][y] != new_element);
15733
15734     if (free_position[x][y])
15735       num_free_positions++;
15736   }
15737
15738   // determine number of new elements to place there
15739   num_percentage = num_free_positions * random_placement_value / 100;
15740   num_elements = (random_placement_method == RANDOM_USE_PERCENTAGE ?
15741                   num_percentage : random_placement_value);
15742
15743   // if less free positions than elements to place, fill all these positions
15744   if (num_free_positions < num_elements)
15745   {
15746     for (x = 0; x < lev_fieldx; x++)
15747       for (y = 0; y < lev_fieldy; y++)
15748         if (free_position[x][y])
15749           SetElement(x, y, new_element);
15750   }
15751   else
15752   {
15753     while (num_elements > 0)
15754     {
15755       x = GetSimpleRandom(lev_fieldx);
15756       y = GetSimpleRandom(lev_fieldy);
15757
15758       // don't place element at the same position twice
15759       if (free_position[x][y])
15760       {
15761         free_position[x][y] = FALSE;
15762         SetElement(x, y, new_element);
15763         num_elements--;
15764       }
15765     }
15766   }
15767
15768   DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
15769   CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
15770 }
15771
15772 static void WrapLevel(int dx, int dy)
15773 {
15774   int wrap_dx = lev_fieldx - dx;
15775   int wrap_dy = lev_fieldy - dy;
15776   int x, y;
15777
15778   for (x = 0; x < lev_fieldx; x++)
15779     for (y = 0; y < lev_fieldy; y++)
15780       TileBackup[x][y] = Tile[x][y];
15781
15782   for (x = 0; x < lev_fieldx; x++)
15783     for (y = 0; y < lev_fieldy; y++)
15784       Tile[x][y] =
15785         TileBackup[(x + wrap_dx) % lev_fieldx][(y + wrap_dy) % lev_fieldy];
15786
15787   DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
15788   CopyLevelToUndoBuffer(UNDO_ACCUMULATE);
15789 }
15790
15791 static void DrawAreaElementHighlight(boolean highlighted,
15792                                      boolean highlighted_similar)
15793 {
15794   DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
15795
15796   if (!highlighted)
15797     return;
15798
15799   int x, y;
15800
15801   for (x = 0; x < ed_fieldx; x++)
15802   {
15803     for (y = 0; y < ed_fieldy; y++)
15804     {
15805       boolean highlight = FALSE;
15806       int lx = x + level_xpos;
15807       int ly = y + level_ypos;
15808
15809       if (!IN_LEV_FIELD(lx, ly))
15810         continue;
15811
15812       // check if element is the same
15813       if (Tile[lx][ly] == new_element1)
15814         highlight = TRUE;
15815
15816       // check if element is similar
15817       if (highlighted_similar &&
15818           strEqual(element_info[Tile[lx][ly]].class_name,
15819                    element_info[new_element1].class_name))
15820         highlight = TRUE;
15821
15822       // check if element is matching MM style wall
15823       if (IS_MM_WALL(Tile[lx][ly]) &&
15824           map_mm_wall_element(Tile[lx][ly]) == new_element1)
15825         highlight = TRUE;
15826
15827       if (!highlight)
15828         continue;
15829
15830       if (IS_MM_WALL(Tile[lx][ly]) && !highlighted_similar)
15831       {
15832         int i;
15833
15834         for (i = 0; i < 4; i++)
15835         {
15836           if (!(MM_WALL_BITS(Tile[lx][ly]) & (1 << i)))
15837             continue;
15838
15839           int xx = x * 2 + (i % 2);
15840           int yy = y * 2 + (i / 2);
15841           int sx = SX + xx * ed_tilesize / 2;
15842           int sy = SY + yy * ed_tilesize / 2;
15843           int from_sx = sx;
15844           int from_sy = sy;
15845           int to_sx = sx + ed_tilesize / 2 - 1;
15846           int to_sy = sy + ed_tilesize / 2 - 1;
15847
15848           DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx,   from_sy);
15849           DrawSimpleWhiteLine(drawto, to_sx,   from_sy, to_sx,   to_sy);
15850           DrawSimpleWhiteLine(drawto, to_sx,   to_sy,   from_sx, to_sy);
15851           DrawSimpleWhiteLine(drawto, from_sx, to_sy,   from_sx, from_sy);
15852         }
15853       }
15854       else
15855       {
15856         int sx = SX + x * ed_tilesize;
15857         int sy = SY + y * ed_tilesize;
15858         int from_sx = sx;
15859         int from_sy = sy;
15860         int to_sx = sx + ed_tilesize - 1;
15861         int to_sy = sy + ed_tilesize - 1;
15862
15863         DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx,   from_sy);
15864         DrawSimpleWhiteLine(drawto, to_sx,   from_sy, to_sx,   to_sy);
15865         DrawSimpleWhiteLine(drawto, to_sx,   to_sy,   from_sx, to_sy);
15866         DrawSimpleWhiteLine(drawto, from_sx, to_sy,   from_sx, from_sy);
15867       }
15868     }
15869   }
15870 }
15871
15872 static void CopyLevelTemplateToUserLevelSet(char *levelset_subdir)
15873 {
15874   char *template_filename_old = getLocalLevelTemplateFilename();
15875   char *template_filename_new =
15876     getPath2(getUserLevelDir(levelset_subdir), LEVELTEMPLATE_FILENAME);
15877
15878   if (copyFile(template_filename_old, template_filename_new) != 0)
15879     Request("Cannot copy level template!", REQ_CONFIRM);
15880
15881   free(template_filename_new);
15882 }
15883
15884 static void HandleDrawingAreas(struct GadgetInfo *gi)
15885 {
15886   static boolean started_inside_drawing_area = FALSE;
15887   static int last_sx = -1;
15888   static int last_sy = -1;
15889   static int last_sx2 = -1;
15890   static int last_sy2 = -1;
15891   int id = gi->custom_id;
15892   int type_id = gi->custom_type_id;
15893   boolean button_press_event;
15894   boolean button_release_event;
15895   boolean inside_drawing_area = !gi->event.off_borders;
15896   boolean draw_level = (id == GADGET_ID_DRAWING_LEVEL);
15897   int actual_drawing_function;
15898   int button = gi->event.button;
15899   int new_element = BUTTON_ELEMENT(button);
15900   int sx = gi->event.x, sy = gi->event.y;
15901   int min_sx = 0, min_sy = 0;
15902   int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1;
15903   int item_xsize = gi->drawing.item_xsize, item_ysize = gi->drawing.item_ysize;
15904   int mini_item_xsize = item_xsize / 2, mini_item_ysize = item_ysize / 2;
15905   int sx2 = gi->event.mx / mini_item_xsize;
15906   int sy2 = gi->event.my / mini_item_ysize;
15907   int dx = sx2 % 2;
15908   int dy = sy2 % 2;
15909   int lx = 0, ly = 0;
15910   int x, y;
15911
15912   button_press_event = (gi->event.type == GD_EVENT_PRESSED);
15913   button_release_event = (gi->event.type == GD_EVENT_RELEASED);
15914
15915   // make sure to stay inside drawing area boundaries
15916   sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
15917   sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
15918
15919   if (draw_level)
15920   {
15921     int min_lx = 0, min_ly = 0;
15922     int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
15923
15924     // get positions inside level field
15925     lx = sx + level_xpos;
15926     ly = sy + level_ypos;
15927
15928     if (!IN_LEV_FIELD(lx, ly))
15929       inside_drawing_area = FALSE;
15930
15931     // make sure to stay inside level field boundaries
15932     lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
15933     ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
15934
15935     // correct drawing area positions accordingly
15936     sx = lx - level_xpos;
15937     sy = ly - level_ypos;
15938   }
15939
15940   // also correct MM wall-sized (double) drawing area positions accordingly
15941   if (sx2 / 2 < sx || sx2 / 2 > sx)
15942   {
15943     dx = (sx2 / 2 < sx ? 0 : 1);
15944     sx2 = sx * 2 + dx;
15945   }
15946   if (sy2 / 2 < sy || sy2 / 2 > sy)
15947   {
15948     dy = (sy2 / 2 < sy ? 0 : 1);
15949     sy2 = sy * 2 + dy;
15950   }
15951
15952   if (!button_press_event && !button_release_event)
15953   {
15954     int old_element = (IN_LEV_FIELD(lx, ly) ? Tile[lx][ly] : EL_UNDEFINED);
15955     boolean hires_drawing = (level.game_engine_type == GAME_ENGINE_TYPE_MM &&
15956                              isHiresTileElement(old_element) &&
15957                              isHiresDrawElement(new_element));
15958
15959     // prevent handling events for every pixel position when moving mouse
15960     if ((sx == last_sx && sy == last_sy && !hires_drawing) ||
15961         (sx2 == last_sx2 && sy2 == last_sy2))
15962       return;
15963   }
15964
15965   last_sx = sx;
15966   last_sy = sy;
15967   last_sx2 = sx2;
15968   last_sy2 = sy2;
15969
15970   if (button_press_event)
15971     started_inside_drawing_area = inside_drawing_area;
15972
15973   if (!started_inside_drawing_area)
15974     return;
15975
15976   if (!IS_VALID_BUTTON(button))
15977     return;
15978
15979   // handle info callback for each invocation of action callback
15980   gi->callback_info(gi);
15981
15982   // automatically switch to 'single item' drawing mode, if needed
15983   actual_drawing_function =
15984     (draw_level || drawing_function == GADGET_ID_PICK_ELEMENT ?
15985      drawing_function : GADGET_ID_SINGLE_ITEMS);
15986
15987   // clicking into drawing area with pressed Control key picks element
15988   if (GetKeyModState() & KMOD_Control)
15989   {
15990     last_drawing_function = drawing_function;
15991     actual_drawing_function = GADGET_ID_PICK_ELEMENT;
15992   }
15993
15994   if (GetKeyModState() & KMOD_Shift)
15995   {
15996     if (button_press_event || button_release_event)
15997       ResetIntelliDraw();
15998   }
15999
16000   SetDrawModeHiRes(-1);         // reset to normal draw mode
16001
16002   switch (actual_drawing_function)
16003   {
16004     case GADGET_ID_SINGLE_ITEMS:
16005       if (draw_level)
16006       {
16007         if (button_release_event)
16008         {
16009           CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
16010
16011           if (edit_mode == ED_MODE_DRAWING && draw_with_brush &&
16012               !inside_drawing_area)
16013             DeleteBrushFromCursor();
16014
16015           break;
16016         }
16017
16018         if (draw_with_brush)
16019         {
16020           CopyBrushToLevel(sx, sy, button);
16021         }
16022         else
16023         {
16024           SetDrawModeHiRes(new_element);
16025
16026           if (IS_PLAYER_ELEMENT(new_element) || IS_MM_MCDUFFIN(new_element))
16027           {
16028             // remove player at old position
16029             for (y = 0; y < lev_fieldy; y++)
16030             {
16031               for (x = 0; x < lev_fieldx; x++)
16032               {
16033                 int old_element = Tile[x][y];
16034
16035                 if (IS_PLAYER_ELEMENT(old_element) &&
16036                     IS_PLAYER_ELEMENT(new_element))
16037                 {
16038                   int replaced_with_element =
16039                     (old_element == EL_SOKOBAN_FIELD_PLAYER &&
16040                      new_element == EL_PLAYER_1 ? EL_SOKOBAN_FIELD_EMPTY :
16041
16042                      old_element == EL_SOKOBAN_FIELD_PLAYER &&
16043                      new_element == old_element ? EL_SOKOBAN_FIELD_EMPTY :
16044
16045                      new_element == EL_SOKOBAN_FIELD_PLAYER &&
16046                      old_element == EL_PLAYER_1 ? EL_EMPTY :
16047
16048                      new_element >= EL_PLAYER_1 &&
16049                      new_element <= EL_PLAYER_4 &&
16050                      new_element == old_element ? EL_EMPTY :
16051
16052                      old_element);
16053
16054                   SetElement(x, y, replaced_with_element);
16055                 }
16056                 else if (IS_MM_MCDUFFIN(old_element) &&
16057                          IS_MM_MCDUFFIN(new_element))
16058                 {
16059                   // remove McDuffin at old position
16060                   SetElement(x, y, EL_EMPTY);
16061                 }
16062               }
16063             }
16064           }
16065
16066           SetElementButton(lx, ly, dx, dy, new_element, button);
16067         }
16068       }
16069       else if (!button_release_event)
16070       {
16071         int pos = sx * drawingarea_info[type_id].area_ysize + sy;
16072
16073         if (item_xsize == MINI_TILEX && item_ysize == MINI_TILEY)
16074           DrawMiniGraphicExt(drawto,
16075                              gi->x + sx * MINI_TILEX,
16076                              gi->y + sy * MINI_TILEY,
16077                              el2edimg(new_element));
16078         else
16079           DrawFixedGraphicExt(drawto,
16080                               gi->x + sx * TILEX,
16081                               gi->y + sy * TILEY,
16082                               el2edimg(new_element), 0);
16083
16084         if (id == GADGET_ID_CUSTOM_GRAPHIC)
16085           new_element = GFX_ELEMENT(new_element);
16086
16087         drawingarea_info[type_id].value[pos] = new_element;
16088
16089         CopyElementPropertiesToGame(properties_element);
16090
16091         if (id == GADGET_ID_CUSTOM_GRAPHIC)
16092         {
16093           UpdateCustomElementGraphicGadgets();
16094
16095           FrameCounter = 0;     // restart animation frame counter
16096         }
16097       }
16098       break;
16099
16100     case GADGET_ID_CONNECTED_ITEMS:
16101       {
16102         static int last_sx = -1;
16103         static int last_sy = -1;
16104
16105         if (button_release_event)
16106           CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
16107
16108         SetDrawModeHiRes(new_element);
16109
16110         if (getDrawModeHiRes())
16111         {
16112           sx = sx2;
16113           sy = sy2;
16114         }
16115
16116         if (!button_press_event)
16117           DrawLine(last_sx, last_sy, sx, sy, new_element, TRUE);
16118
16119         last_sx = sx;
16120         last_sy = sy;
16121       }
16122       break;
16123
16124     case GADGET_ID_LINE:
16125     case GADGET_ID_ARC:
16126     case GADGET_ID_RECTANGLE:
16127     case GADGET_ID_FILLED_BOX:
16128       SetDrawModeHiRes(new_element);
16129
16130       if (getDrawModeHiRes())
16131       {
16132         sx = sx2;
16133         sy = sy2;
16134       }
16135       // FALLTHROUGH
16136     case GADGET_ID_GRAB_BRUSH:
16137     case GADGET_ID_TEXT:
16138       {
16139         static int last_sx = -1;
16140         static int last_sy = -1;
16141         static int start_sx = -1;
16142         static int start_sy = -1;
16143         void (*draw_func)(int, int, int, int, int, boolean);
16144
16145         if (drawing_function == GADGET_ID_LINE)
16146           draw_func = DrawLine;
16147         else if (drawing_function == GADGET_ID_ARC)
16148           draw_func = DrawArc;
16149         else if (drawing_function == GADGET_ID_RECTANGLE)
16150           draw_func = DrawBox;
16151         else if (drawing_function == GADGET_ID_FILLED_BOX)
16152           draw_func = DrawFilledBox;
16153         else if (drawing_function == GADGET_ID_GRAB_BRUSH)
16154           draw_func = SelectArea;
16155         else // (drawing_function == GADGET_ID_TEXT)
16156           draw_func = SetTextCursor;
16157
16158         if (button_press_event)
16159         {
16160           draw_func(sx, sy, sx, sy, new_element, FALSE);
16161           start_sx = last_sx = sx;
16162           start_sy = last_sy = sy;
16163
16164           if (drawing_function == GADGET_ID_TEXT)
16165             DrawLevelText(0, 0, 0, TEXT_END);
16166         }
16167         else if (button_release_event)
16168         {
16169           draw_func(start_sx, start_sy, sx, sy, new_element, TRUE);
16170           if (drawing_function == GADGET_ID_GRAB_BRUSH)
16171           {
16172             CopyAreaToBrush(start_sx, start_sy, sx, sy, button);
16173             CopyBrushToCursor(sx, sy);
16174             ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
16175                           MB_LEFTBUTTON);
16176             draw_with_brush = TRUE;
16177           }
16178           else if (drawing_function == GADGET_ID_TEXT)
16179             DrawLevelText(sx, sy, 0, TEXT_INIT);
16180           else
16181             CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
16182         }
16183         else if (last_sx != sx || last_sy != sy)
16184         {
16185           draw_func(start_sx, start_sy, last_sx, last_sy, -1, FALSE);
16186           if (IS_MM_WALL_EDITOR(new_element))   // clear wall background
16187             draw_func(start_sx, start_sy, sx, sy, EL_EMPTY, FALSE);
16188           draw_func(start_sx, start_sy, sx, sy, new_element, FALSE);
16189           last_sx = sx;
16190           last_sy = sy;
16191         }
16192       }
16193       break;
16194
16195     case GADGET_ID_FLOOD_FILL:
16196       if (button_press_event && Tile[lx][ly] != new_element)
16197       {
16198         if (IS_MM_WALL_EDITOR(new_element))
16199           FloodFillWall_MM(sx2, sy2, new_element);
16200         else
16201           FloodFill(lx, ly, new_element);
16202
16203         DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16204         CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
16205       }
16206       break;
16207
16208     case GADGET_ID_PICK_ELEMENT:
16209       if (button_release_event)
16210         ClickOnGadget(level_editor_gadget[last_drawing_function],
16211                       MB_LEFTBUTTON);
16212       else if (draw_level)
16213         PickDrawingElement(button, Tile[lx][ly]);
16214       else
16215       {
16216         int pos = sx * drawingarea_info[type_id].area_ysize + sy;
16217
16218         PickDrawingElement(button, drawingarea_info[type_id].value[pos]);
16219       }
16220
16221     default:
16222       break;
16223   }
16224
16225   // do not mark level as modified for certain non-level-changing gadgets
16226   if ((type_id >= ED_DRAWING_ID_EDITOR_FIRST &&
16227        type_id <= ED_DRAWING_ID_EDITOR_LAST) ||
16228       actual_drawing_function == GADGET_ID_GRAB_BRUSH ||
16229       actual_drawing_function == GADGET_ID_PICK_ELEMENT)
16230     return;
16231
16232   level.changed = TRUE;
16233 }
16234
16235 static void HandleCounterButtons(struct GadgetInfo *gi)
16236 {
16237   int gadget_id = gi->custom_id;
16238   int counter_id = gi->custom_type_id;
16239   int button = gi->event.button;
16240   int *counter_value = counterbutton_info[counter_id].value;
16241   int step = BUTTON_STEPSIZE(button) *
16242     (gadget_id == counterbutton_info[counter_id].gadget_id_down ? -1 : +1);
16243
16244   if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
16245   {
16246     boolean pressed = (gi->event.type == GD_EVENT_PRESSED);
16247     boolean released = (gi->event.type == GD_EVENT_RELEASED);
16248     boolean level_changed = LevelChanged();
16249
16250     if ((level_changed && pressed) || (!level_changed && released))
16251       return;
16252
16253     if (level_changed && !Request("Level has changed! Discard changes?",
16254                                   REQ_ASK))
16255     {
16256       if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
16257         ModifyEditorCounterValue(counter_id, *counter_value);
16258
16259       return;
16260     }
16261   }
16262
16263   if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
16264     *counter_value = gi->textinput.number_value;
16265   else
16266     ModifyEditorCounterValue(counter_id, *counter_value + step);
16267
16268   if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
16269   {
16270     int last_game_engine_type = level.game_engine_type;
16271
16272     LoadLevel(level_nr);
16273     LoadScore(level_nr);
16274
16275     SaveLevelSetup_SeriesInfo();
16276
16277     TapeErase();
16278
16279     ResetUndoBuffer();
16280     DrawEditModeWindow();
16281
16282     if (level.game_engine_type != last_game_engine_type)
16283     {
16284       // update element selection list
16285       ReinitializeElementList();
16286       ModifyEditorElementList();
16287     }
16288
16289     return;
16290   }
16291
16292   switch (counter_id)
16293   {
16294     case ED_COUNTER_ID_YAMYAM_CONTENT:
16295       DrawYamYamContentAreas();
16296       break;
16297
16298     case ED_COUNTER_ID_BALL_CONTENT:
16299       DrawMagicBallContentAreas();
16300       break;
16301
16302     case ED_COUNTER_ID_ANDROID_CONTENT:
16303       DrawAndroidElementArea();
16304       break;
16305
16306     case ED_COUNTER_ID_GROUP_CONTENT:
16307       DrawGroupElementArea();
16308       CopyGroupElementPropertiesToGame(properties_element);
16309       break;
16310
16311     case ED_COUNTER_ID_INVENTORY_SIZE:
16312       DrawPlayerInitialInventoryArea(properties_element);
16313       break;
16314
16315     case ED_COUNTER_ID_MM_BALL_CONTENT:
16316       DrawMMBallContentArea();
16317       break;
16318
16319     case ED_COUNTER_ID_ENVELOPE_XSIZE:
16320     case ED_COUNTER_ID_ENVELOPE_YSIZE:
16321       DrawEnvelopeTextArea(-1);
16322       break;
16323
16324     case ED_COUNTER_ID_LEVEL_XSIZE:
16325     case ED_COUNTER_ID_LEVEL_YSIZE:
16326       lev_fieldx = level.fieldx;
16327       lev_fieldy = level.fieldy;
16328
16329       // check if resizing of level results in change of border border
16330       SetBorderElement();
16331
16332       break;
16333
16334     default:
16335       break;
16336   }
16337
16338   if ((counter_id >= ED_COUNTER_ID_CUSTOM_FIRST &&
16339        counter_id <= ED_COUNTER_ID_CUSTOM_LAST) ||
16340       (counter_id >= ED_COUNTER_ID_CHANGE_FIRST &&
16341        counter_id <= ED_COUNTER_ID_CHANGE_LAST))
16342     CopyElementPropertiesToGame(properties_element);
16343
16344   // do not mark level as modified for certain non-level-changing gadgets
16345   if ((counter_id >= ED_COUNTER_ID_LEVELSET_FIRST &&
16346        counter_id <= ED_COUNTER_ID_LEVELSET_LAST) ||
16347       (counter_id >= ED_COUNTER_ID_EDITOR_FIRST &&
16348        counter_id <= ED_COUNTER_ID_EDITOR_LAST))
16349     return;
16350
16351   level.changed = TRUE;
16352 }
16353
16354 static void HandleTextInputGadgets(struct GadgetInfo *gi)
16355 {
16356   int type_id = gi->custom_type_id;
16357
16358   strcpy(textinput_info[type_id].value, gi->textinput.value);
16359
16360   if (type_id == ED_TEXTINPUT_ID_ELEMENT_NAME)
16361   {
16362     CopyElementPropertiesToGame(properties_element);
16363
16364     ModifyEditorElementList();  // update changed button info text
16365   }
16366   else if (type_id >= ED_TEXTINPUT_ID_COLORS_FIRST &&
16367            type_id <= ED_TEXTINPUT_ID_COLORS_LAST)
16368   {
16369     int pos = type_id - ED_TEXTINPUT_ID_COLORS_FIRST;
16370
16371     *bd_color[pos] = gd_color_get_from_string(bd_color_text[pos]);
16372
16373     DrawColorBox_BD(pos);
16374   }
16375
16376   // do not mark level as modified for certain non-level-changing gadgets
16377   if (type_id >= ED_TEXTINPUT_ID_LEVELSET_FIRST &&
16378       type_id <= ED_TEXTINPUT_ID_LEVELSET_LAST)
16379     return;
16380
16381   level.changed = TRUE;
16382 }
16383
16384 static void HandleTextAreaGadgets(struct GadgetInfo *gi)
16385 {
16386   int type_id = gi->custom_type_id;
16387
16388   strncpy(textarea_info[type_id].value, gi->textarea.value,
16389           MAX_ENVELOPE_TEXT_LEN);
16390   textarea_info[type_id].value[MAX_ENVELOPE_TEXT_LEN] = '\0';
16391
16392   level.changed = TRUE;
16393 }
16394
16395 static void HandleSelectboxGadgets(struct GadgetInfo *gi)
16396 {
16397   int type_id = gi->custom_type_id;
16398   int value_old = *selectbox_info[type_id].value;
16399   int value_new = selectbox_info[type_id].options[gi->selectbox.index].value;
16400
16401   *selectbox_info[type_id].value = value_new;
16402
16403   if (type_id == ED_SELECTBOX_ID_LEVELSET_SAVE_MODE)
16404   {
16405     DrawLevelConfigWindow();
16406   }
16407   else if (type_id == ED_SELECTBOX_ID_SELECT_CHANGE_PAGE)
16408   {
16409     element_info[properties_element].current_change_page = gi->selectbox.index;
16410
16411     DrawPropertiesWindow();
16412   }
16413   else if ((type_id >= ED_SELECTBOX_ID_CUSTOM_FIRST &&
16414             type_id <= ED_SELECTBOX_ID_CUSTOM_LAST) ||
16415            (type_id >= ED_SELECTBOX_ID_CHANGE_FIRST &&
16416             type_id <= ED_SELECTBOX_ID_CHANGE_LAST) ||
16417            (type_id == ED_SELECTBOX_ID_GROUP_CHOICE_MODE))
16418   {
16419     if (type_id == ED_SELECTBOX_ID_ACTION_TYPE)
16420     {
16421       // when changing action type, also check action mode and action arg
16422       if (value_old != value_new)
16423         setSelectboxSpecialActionVariablesIfNeeded();
16424
16425       DrawPropertiesChange();
16426     }
16427
16428     CopyElementPropertiesToGame(properties_element);
16429   }
16430   else if (type_id == ED_SELECTBOX_ID_GAME_ENGINE_TYPE)
16431   {
16432     // show or hide "engine" tabulator depending on game engine type
16433     DrawLevelConfigWindow();
16434
16435     // update element selection list depending on game engine type
16436     ReinitializeElementList();
16437     ModifyEditorElementList();
16438   }
16439   else if (type_id == ED_SELECTBOX_ID_BD_SCHEDULING_TYPE)
16440   {
16441     // update BD cycle delay counter gadgets depending on BD scheduling type
16442     DrawLevelConfigWindow();
16443   }
16444   else if (type_id == ED_SELECTBOX_ID_BD_COLOR_TYPE)
16445   {
16446     bd_color_type_changed = TRUE;
16447
16448     if (level.bd_color_type != GD_COLOR_TYPE_RGB && level.bd_color_type != GetCommonColorType_BD())
16449     {
16450       // color type switched to non-RGB colors, but using different color type => reset colors
16451       char *message = (level.bd_color_type == bd_color_type_default ?
16452                        "This will reset colors to defaults! Continue?" :
16453                        "This will reset colors to random colors! Continue?");
16454
16455       if (!Request(message, REQ_ASK))
16456       {
16457         // keep current RGB colors
16458         level.bd_color_type = GD_COLOR_TYPE_RGB;
16459         bd_color_type_changed = FALSE;
16460       }
16461     }
16462
16463     // update BD color palette gadgets depending on BD color type
16464     DrawLevelConfigWindow();
16465   }
16466   else if (type_id >= ED_SELECTBOX_ID_COLORS_FIRST &&
16467            type_id <= ED_SELECTBOX_ID_COLORS_LAST)
16468   {
16469     int pos = type_id - ED_SELECTBOX_ID_COLORS_FIRST;
16470
16471     *bd_color[pos] = gd_c64_color(bd_color_c64[pos]);
16472
16473     DrawColorBox_BD(pos);
16474   }
16475
16476   // do not mark level as modified for certain non-level-changing gadgets
16477   if (type_id == ED_SELECTBOX_ID_LEVELSET_SAVE_MODE ||
16478       type_id == ED_SELECTBOX_ID_SELECT_CHANGE_PAGE)
16479     return;
16480
16481   level.changed = TRUE;
16482 }
16483
16484 static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
16485 {
16486   int type_id = gi->custom_type_id;
16487   int i;
16488
16489   if (type_id >= ED_TAB_BUTTON_ID_LEVELCONFIG_FIRST &&
16490       type_id <= ED_TAB_BUTTON_ID_LEVELCONFIG_LAST)
16491   {
16492     edit_mode_levelconfig = gi->custom_type_id;
16493
16494     DrawLevelConfigWindow();
16495   }
16496   else if (type_id >= ED_TAB_BUTTON_ID_ENGINECONFIG_FIRST &&
16497            type_id <= ED_TAB_BUTTON_ID_ENGINECONFIG_LAST)
16498   {
16499     edit_mode_engineconfig = gi->custom_type_id;
16500
16501     DrawLevelConfigWindow();
16502   }
16503   else if (type_id >= ED_TAB_BUTTON_ID_PROPERTIES_FIRST &&
16504            type_id <= ED_TAB_BUTTON_ID_PROPERTIES_LAST)
16505   {
16506     edit_mode_properties = gi->custom_type_id;
16507
16508     DrawPropertiesWindow();
16509   }
16510   else if (type_id == ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_1 ||
16511            type_id == ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE_2)
16512   {
16513     boolean new_template = !fileExists(getLocalLevelTemplateFilename());
16514
16515     // backup original "level.field" (needed to track playfield changes)
16516     CopyPlayfield(level.field, TileBackup);
16517
16518     // "SaveLevelTemplate()" uses "level.field", so copy editor playfield
16519     CopyPlayfield(Tile, level.field);
16520
16521     if (new_template ||
16522         Request("Save this template and kill the old?", REQ_ASK))
16523       SaveLevelTemplate();
16524
16525     if (new_template)
16526       Request("Template saved!", REQ_CONFIRM);
16527
16528     // restore original "level.field" (needed to track playfield changes)
16529     CopyPlayfield(TileBackup, level.field);
16530   }
16531   else if (type_id == ED_TEXTBUTTON_ID_SAVE_LEVELSET)
16532   {
16533     char *levelset_subdir = getLevelSubdirFromSaveMode(levelset_save_mode);
16534
16535     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE &&
16536         leveldir_current->readonly)
16537     {
16538       Request("This level set is read-only!", REQ_CONFIRM);
16539
16540       return;
16541     }
16542
16543     if (strEqual(levelset_name, ""))
16544     {
16545       Request("Please enter level set title!", REQ_CONFIRM);
16546
16547       return;
16548     }
16549
16550     if (strEqual(levelset_author, ""))
16551     {
16552       Request("Please enter level set author!", REQ_CONFIRM);
16553
16554       return;
16555     }
16556
16557     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE)
16558     {
16559       if (UpdateUserLevelSet(levelset_subdir,
16560                              levelset_name,
16561                              levelset_author,
16562                              levelset_num_levels))
16563       {
16564         Request("Level set updated!", REQ_CONFIRM);
16565       }
16566       else
16567       {
16568         Request("Updating level set failed!", REQ_CONFIRM);
16569       }
16570     }
16571     else if (levelset_save_mode == LEVELSET_SAVE_MODE_CREATE)
16572     {
16573       if (level.changed && !Request("Level has changed! Discard changes?",
16574                                      REQ_ASK))
16575         return;
16576
16577       if (CreateUserLevelSet(levelset_subdir,
16578                              levelset_name,
16579                              levelset_author,
16580                              levelset_num_levels,
16581                              levelset_use_levelset_artwork))
16582       {
16583         if (levelset_copy_level_template)
16584           CopyLevelTemplateToUserLevelSet(levelset_subdir);
16585
16586         Request("New level set created!", REQ_CONFIRM);
16587
16588         AddUserLevelSetToLevelInfo(levelset_subdir);
16589         ChangeEditorToLevelSet(levelset_subdir);
16590       }
16591       else
16592       {
16593         Request("Creating new level set failed!", REQ_CONFIRM);
16594       }
16595     }
16596   }
16597   else if (type_id == ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE &&
16598            custom_element.num_change_pages < MAX_CHANGE_PAGES)
16599   {
16600     struct ElementInfo *ei = &element_info[properties_element];
16601
16602     // when modifying custom element, ask for copying level template
16603     if (level.use_custom_template && !AskToCopyAndModifyLevelTemplate())
16604       return;
16605
16606     setElementChangePages(ei, ei->num_change_pages + 1);
16607
16608     // set new change page to be new current change page
16609     ei->current_change_page = ei->num_change_pages - 1;
16610     ei->change = &ei->change_page[ei->current_change_page];
16611
16612     setElementChangeInfoToDefaults(ei->change);
16613
16614     DrawPropertiesWindow();
16615
16616     level.changed = TRUE;
16617   }
16618   else if (type_id == ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE &&
16619            custom_element.num_change_pages > MIN_CHANGE_PAGES)
16620   {
16621     struct ElementInfo *ei = &element_info[properties_element];
16622
16623     // when modifying custom element, ask for copying level template
16624     if (level.use_custom_template && !AskToCopyAndModifyLevelTemplate())
16625       return;
16626
16627     // copy all change pages after change page to be deleted
16628     for (i = ei->current_change_page; i < ei->num_change_pages - 1; i++)
16629       ei->change_page[i] = ei->change_page[i + 1];
16630
16631     setElementChangePages(ei, ei->num_change_pages - 1);
16632
16633     DrawPropertiesWindow();
16634
16635     level.changed = TRUE;
16636   }
16637   else if (type_id == ED_TEXTBUTTON_ID_BD_SET_RANDOM_COLORS)
16638   {
16639     SetRandomLevelColors_BD();
16640
16641     // update BD color palette gadgets after setting random colors
16642     DrawLevelConfigWindow();
16643   }
16644 }
16645
16646 static void HandleGraphicbuttonGadgets(struct GadgetInfo *gi)
16647 {
16648   int type_id = gi->custom_type_id;
16649
16650   if (type_id == ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE ||
16651       type_id == ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE)
16652   {
16653     struct ElementInfo *ei = &element_info[properties_element];
16654     int step = BUTTON_STEPSIZE(gi->event.button);
16655
16656     step *= (type_id == ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE ? -1 : +1);
16657     ei->current_change_page += step;
16658
16659     if (ei->current_change_page < 0)
16660       ei->current_change_page = 0;
16661     else if (ei->current_change_page >= ei->num_change_pages)
16662       ei->current_change_page = ei->num_change_pages - 1;
16663
16664     DrawPropertiesWindow();
16665   }
16666   else if (type_id == ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE ||
16667            type_id == ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE)
16668   {
16669     struct ElementInfo *ei = &element_info[properties_element];
16670     int current_change_page = ei->current_change_page;
16671
16672     if (type_id == ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE)
16673     {
16674       element_info[EL_INTERNAL_CLIPBOARD_CHANGE].change_page[0] =
16675         ei->change_page[current_change_page];
16676     }
16677     else if (type_id == ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE)
16678     {
16679       // when modifying custom element, ask for copying level template
16680       if (level.use_custom_template && !AskToCopyAndModifyLevelTemplate())
16681         return;
16682
16683       ei->change_page[current_change_page] =
16684         element_info[EL_INTERNAL_CLIPBOARD_CHANGE].change_page[0];
16685
16686       level.changed = TRUE;
16687     }
16688
16689     DrawPropertiesWindow();
16690   }
16691 }
16692
16693 static void HandleRadiobuttons(struct GadgetInfo *gi)
16694 {
16695   int type_id = gi->custom_type_id;
16696
16697   *radiobutton_info[type_id].value =
16698     radiobutton_info[type_id].checked_value;
16699
16700   // do not mark level as modified for certain non-level-changing gadgets
16701   if (type_id >= ED_RADIOBUTTON_ID_EDITOR_FIRST &&
16702       type_id <= ED_RADIOBUTTON_ID_EDITOR_LAST)
16703     return;
16704
16705   level.changed = TRUE;
16706 }
16707
16708 static void HandleCheckbuttons(struct GadgetInfo *gi)
16709 {
16710   int type_id = gi->custom_type_id;
16711
16712   *checkbutton_info[type_id].value ^= TRUE;
16713
16714   if (type_id == ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID ||
16715       type_id == ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID ||
16716       type_id == ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH ||
16717       (((type_id >= ED_CHECKBUTTON_ID_CUSTOM_FIRST &&
16718          type_id <= ED_CHECKBUTTON_ID_CUSTOM_LAST) ||
16719         (type_id >= ED_CHECKBUTTON_ID_CHANGE_FIRST &&
16720          type_id <= ED_CHECKBUTTON_ID_CHANGE_LAST)) &&
16721        type_id != ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1))
16722   {
16723     CopyElementPropertiesToGame(properties_element);
16724   }
16725
16726   if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC)
16727   {
16728     UpdateCustomElementGraphicGadgets();
16729   }
16730   else if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_1 ||
16731            type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_2)
16732   {
16733     boolean template_related_changes_found = FALSE;
16734     int i;
16735
16736     // check if any custom, group or empty elements have been changed
16737     for (i = 0; i < NUM_FILE_ELEMENTS; i++)
16738       if ((IS_CUSTOM_ELEMENT(i) ||
16739            IS_GROUP_ELEMENT(i) ||
16740            IS_EMPTY_ELEMENT(i)) &&
16741           element_info[i].modified_settings)
16742         template_related_changes_found = TRUE;
16743
16744     if (level.use_custom_template &&
16745         !fileExists(getGlobalLevelTemplateFilename()))
16746     {
16747       Request("No level template found!", REQ_CONFIRM);
16748
16749       level.use_custom_template = FALSE;
16750
16751       ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
16752
16753       return;
16754     }
16755
16756     if (level.use_custom_template &&
16757         template_related_changes_found &&
16758         !Request("Discard changes and use level template?", REQ_ASK))
16759     {
16760       level.use_custom_template = FALSE;
16761
16762       ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
16763
16764       return;
16765     }
16766
16767     if (!level.use_custom_template &&
16768         Request("Copy settings from level template?", REQ_ASK))
16769     {
16770       return;
16771     }
16772
16773     LoadLevelTemplate(level.use_custom_template ? -1 : level_nr);
16774
16775     DrawEditModeWindow();
16776   }
16777   else if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_3)
16778   {
16779     if (setup.editor.use_template_for_new_levels &&
16780         !fileExists(getGlobalLevelTemplateFilename()))
16781     {
16782       Request("No level template found!", REQ_CONFIRM);
16783
16784       return;
16785     }
16786
16787     if (setup.editor.use_template_for_new_levels &&
16788         level.changed &&
16789         !Request("Discard level and load template?", REQ_ASK))
16790     {
16791       return;
16792     }
16793
16794     if (!setup.editor.use_template_for_new_levels &&
16795         level.changed &&
16796         !Request("Discard level and use empty level?", REQ_ASK))
16797     {
16798       return;
16799     }
16800
16801     LoadLevel(level_nr);
16802     LoadScore(level_nr);
16803
16804     TapeErase();
16805
16806     ResetUndoBuffer();
16807     DrawEditModeWindow();
16808   }
16809   else if (type_id == ED_CHECKBUTTON_ID_AUTO_COUNT_GEMS)
16810   {
16811     SetAutomaticNumberOfGemsNeeded();
16812   }
16813
16814   // do not mark level as modified for certain non-level-changing gadgets
16815   if ((type_id >= ED_CHECKBUTTON_ID_LEVELSET_FIRST &&
16816        type_id <= ED_CHECKBUTTON_ID_LEVELSET_LAST) ||
16817       (type_id >= ED_CHECKBUTTON_ID_EDITOR_FIRST &&
16818        type_id <= ED_CHECKBUTTON_ID_EDITOR_LAST &&
16819        type_id != ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE_2) ||
16820       type_id == ED_CHECKBUTTON_ID_STICK_ELEMENT)
16821     return;
16822
16823   level.changed = TRUE;
16824 }
16825
16826 static void HandleControlButtons(struct GadgetInfo *gi)
16827 {
16828   static int last_level_drawing_function = GADGET_ID_SINGLE_ITEMS;
16829   static int last_edit_mode = ED_MODE_DRAWING;
16830   static int last_custom_copy_mode = -1;
16831   static int last_button = 0;
16832   int id = gi->custom_id;
16833   int button = gi->event.button;
16834   int step = BUTTON_STEPSIZE(button);
16835   int new_element = BUTTON_ELEMENT(button);
16836   int last_properties_element = properties_element;
16837   int x, y;
16838
16839   if (edit_mode == ED_MODE_DRAWING && drawing_function == GADGET_ID_TEXT)
16840     DrawLevelText(0, 0, 0, TEXT_END);
16841
16842   if (id < ED_NUM_CTRL1_BUTTONS &&
16843       id != GADGET_ID_SINGLE_ITEMS &&
16844       id != GADGET_ID_PICK_ELEMENT &&
16845       edit_mode != ED_MODE_DRAWING &&
16846       drawing_function != GADGET_ID_PICK_ELEMENT &&
16847       !(GetKeyModState() & KMOD_Control))
16848     ChangeEditModeWindow(ED_MODE_DRAWING);
16849
16850   // element copy mode active, but no element button pressed => deactivate
16851   if (last_custom_copy_mode != -1 && id < ED_NUM_CTRL_BUTTONS)
16852     last_custom_copy_mode = -1;
16853
16854   // when showing palette on element buttons, change element of button used
16855   if (editor.palette.show_on_element_buttons &&
16856       id >= GADGET_ID_ELEMENT_LEFT && id <= GADGET_ID_ELEMENT_RIGHT)
16857   {
16858     last_button = id - GADGET_ID_ELEMENT_LEFT + 1;
16859
16860     id = GADGET_ID_PALETTE;
16861   }
16862
16863   switch (id)
16864   {
16865     case GADGET_ID_SCROLL_LEFT:
16866       if (level_xpos >= 0)
16867       {
16868         if (lev_fieldx < ed_fieldx - 2)
16869           break;
16870
16871         level_xpos -= step;
16872         if (level_xpos < -1)
16873           level_xpos = -1;
16874         if (button == 1)
16875           ScrollEditorLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT);
16876         else
16877           DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16878
16879         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
16880                      GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
16881       }
16882       break;
16883
16884     case GADGET_ID_SCROLL_RIGHT:
16885       if (level_xpos <= lev_fieldx - ed_fieldx)
16886       {
16887         if (lev_fieldx < ed_fieldx - 2)
16888           break;
16889
16890         level_xpos += step;
16891         if (level_xpos > lev_fieldx - ed_fieldx + 1)
16892           level_xpos = lev_fieldx - ed_fieldx + 1;
16893         if (button == 1)
16894           ScrollEditorLevel(level_xpos, level_ypos, ED_SCROLL_LEFT);
16895         else
16896           DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16897
16898         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
16899                      GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
16900       }
16901       break;
16902
16903     case GADGET_ID_SCROLL_UP:
16904       if (level_ypos >= 0)
16905       {
16906         if (lev_fieldy < ed_fieldy - 2)
16907           break;
16908
16909         level_ypos -= step;
16910         if (level_ypos < -1)
16911           level_ypos = -1;
16912         if (button == 1)
16913           ScrollEditorLevel(level_xpos, level_ypos, ED_SCROLL_DOWN);
16914         else
16915           DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16916
16917         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
16918                      GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
16919       }
16920       break;
16921
16922     case GADGET_ID_SCROLL_DOWN:
16923       if (level_ypos <= lev_fieldy - ed_fieldy)
16924       {
16925         if (lev_fieldy < ed_fieldy - 2)
16926           break;
16927
16928         level_ypos += step;
16929         if (level_ypos > lev_fieldy - ed_fieldy + 1)
16930           level_ypos = lev_fieldy - ed_fieldy + 1;
16931         if (button == 1)
16932           ScrollEditorLevel(level_xpos, level_ypos, ED_SCROLL_UP);
16933         else
16934           DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16935
16936         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
16937                      GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
16938       }
16939       break;
16940
16941     case GADGET_ID_SCROLL_HORIZONTAL:
16942       level_xpos = gi->event.item_position - 1;
16943
16944       DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16945       BackToFront();
16946
16947       break;
16948
16949     case GADGET_ID_SCROLL_VERTICAL:
16950       level_ypos = gi->event.item_position - 1;
16951
16952       DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
16953       BackToFront();
16954
16955       break;
16956
16957     case GADGET_ID_SCROLL_LIST_UP:
16958     case GADGET_ID_SCROLL_LIST_DOWN:
16959     case GADGET_ID_SCROLL_LIST_VERTICAL:
16960       if (id == GADGET_ID_SCROLL_LIST_VERTICAL)
16961         element_shift = gi->event.item_position * ED_ELEMENTLIST_BUTTONS_HORIZ;
16962       else
16963       {
16964         step *= (id == GADGET_ID_SCROLL_LIST_UP ? -1 : +1);
16965         element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ;
16966
16967         if (element_shift < 0)
16968           element_shift = 0;
16969         if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
16970           element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
16971
16972         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
16973                      GDI_SCROLLBAR_ITEM_POSITION,
16974                      element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
16975       }
16976
16977       ModifyEditorElementList();
16978
16979       break;
16980
16981     case GADGET_ID_PROPERTIES:
16982       // always switch off element properties when they are already displayed
16983       last_properties_element = new_element;
16984     case GADGET_ID_ELEMENT_LEFT:
16985     case GADGET_ID_ELEMENT_MIDDLE:
16986     case GADGET_ID_ELEMENT_RIGHT:
16987       properties_element = (id == GADGET_ID_ELEMENT_LEFT   ? new_element1 :
16988                             id == GADGET_ID_ELEMENT_MIDDLE ? new_element2 :
16989                             id == GADGET_ID_ELEMENT_RIGHT  ? new_element3 :
16990                             new_element);
16991
16992       if (edit_mode != ED_MODE_PROPERTIES)
16993       {
16994         last_edit_mode = edit_mode;
16995
16996         ChangeEditModeWindow(ED_MODE_PROPERTIES);
16997
16998         last_level_drawing_function = drawing_function;
16999         ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
17000                       MB_LEFTBUTTON);
17001       }
17002       else if (properties_element != last_properties_element)
17003       {
17004         DrawEditModeWindow();
17005       }
17006       else
17007       {
17008         ChangeEditModeWindow(ED_MODE_DRAWING);
17009
17010         ClickOnGadget(level_editor_gadget[last_level_drawing_function],
17011                       MB_LEFTBUTTON);
17012       }
17013       break;
17014
17015     case GADGET_ID_PALETTE:
17016       if (edit_mode != ED_MODE_PALETTE)
17017       {
17018         last_edit_mode = edit_mode;
17019
17020         ChangeEditModeWindow(ED_MODE_PALETTE);
17021       }
17022       else
17023       {
17024         ChangeEditModeWindow(last_edit_mode);
17025       }
17026       break;
17027
17028     case GADGET_ID_WRAP_LEFT:
17029       WrapLevel(-step, 0);
17030       break;
17031
17032     case GADGET_ID_WRAP_RIGHT:
17033       WrapLevel(step, 0);
17034       break;
17035
17036     case GADGET_ID_WRAP_UP:
17037       WrapLevel(0, -step);
17038       break;
17039
17040     case GADGET_ID_WRAP_DOWN:
17041       WrapLevel(0, step);
17042       break;
17043
17044     case GADGET_ID_SINGLE_ITEMS:
17045     case GADGET_ID_CONNECTED_ITEMS:
17046     case GADGET_ID_LINE:
17047     case GADGET_ID_ARC:
17048     case GADGET_ID_TEXT:
17049     case GADGET_ID_RECTANGLE:
17050     case GADGET_ID_FILLED_BOX:
17051     case GADGET_ID_FLOOD_FILL:
17052     case GADGET_ID_GRAB_BRUSH:
17053     case GADGET_ID_PICK_ELEMENT:
17054       if (drawing_function != GADGET_ID_PICK_ELEMENT)
17055         last_drawing_function = drawing_function;
17056       drawing_function = id;
17057       draw_with_brush = FALSE;
17058       break;
17059
17060     case GADGET_ID_RANDOM_PLACEMENT:
17061       RandomPlacement(new_element);
17062       break;
17063
17064     case GADGET_ID_ZOOM:
17065       // zoom level editor tile size in or out (or reset to default size)
17066       ed_tilesize = (button == 1 ? ed_tilesize * 2 :
17067                      button == 2 ? ed_tilesize_default :
17068                      button == 3 ? ed_tilesize / 2 : ed_tilesize);
17069
17070       // when using touch device, cycle through all zoom tilesizes
17071       if (runtime.uses_touch_device && ed_tilesize > TILESIZE)
17072         ed_tilesize = MICRO_TILESIZE;
17073
17074       // limit zoom level by upper and lower bound
17075       ed_tilesize = MIN(MAX(MICRO_TILESIZE, ed_tilesize), TILESIZE);
17076
17077       InitZoomLevelSettings(ed_tilesize);
17078
17079       if (edit_mode == ED_MODE_DRAWING)
17080       {
17081         DrawDrawingWindow();
17082
17083         // redraw zoom gadget info text
17084         PrintEditorGadgetInfoText(level_editor_gadget[id]);
17085       }
17086
17087       // save current editor zoom tilesize
17088       SaveSetup_AutoSetup();
17089
17090       break;
17091
17092     case GADGET_ID_CUSTOM_COPY_FROM:
17093     case GADGET_ID_CUSTOM_COPY_TO:
17094     case GADGET_ID_CUSTOM_EXCHANGE:
17095       last_custom_copy_mode = id;
17096       last_drawing_function = drawing_function;
17097       break;
17098
17099     case GADGET_ID_CUSTOM_COPY:
17100       CopyCustomElement(properties_element, -1, id);
17101       break;
17102
17103     case GADGET_ID_CUSTOM_PASTE:
17104       CopyCustomElement(-1, properties_element, id);
17105       break;
17106
17107     case GADGET_ID_UNDO:
17108       if (button < 0)   // keep button value (even if modifier keys are pressed)
17109         button = -button;
17110       else if (button == 1 && GetKeyModState() & (KMOD_Shift | KMOD_Control))
17111         button = 3;
17112
17113       if (button == 1 && undo_buffer_steps == 0)
17114       {
17115         Request("Undo buffer empty!", REQ_CONFIRM);
17116
17117         break;
17118       }
17119       else if (button == 2)
17120       {
17121         break;
17122       }
17123       else if (button == 3 && redo_buffer_steps == 0)
17124       {
17125         Request("Redo buffer empty!", REQ_CONFIRM);
17126
17127         break;
17128       }
17129
17130       if (edit_mode != ED_MODE_DRAWING)
17131         ChangeEditModeWindow(ED_MODE_DRAWING);
17132
17133       if (button == 1)
17134       {
17135         // undo
17136
17137         undo_buffer_position =
17138           (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS;
17139
17140         undo_buffer_steps--;
17141         redo_buffer_steps++;
17142       }
17143       else
17144       {
17145         // redo
17146
17147         undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS;
17148
17149         undo_buffer_steps++;
17150         redo_buffer_steps--;
17151       }
17152
17153       for (x = 0; x < lev_fieldx; x++)
17154         for (y = 0; y < lev_fieldy; y++)
17155           Tile[x][y] = UndoBuffer[undo_buffer_position][x][y];
17156
17157       // check if undo operation forces change of border style
17158       CheckLevelBorderElement(FALSE);
17159
17160       DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
17161
17162       break;
17163
17164     case GADGET_ID_CONF:
17165       if (edit_mode != ED_MODE_LEVELCONFIG)
17166       {
17167         last_edit_mode = edit_mode;
17168
17169         ChangeEditModeWindow(ED_MODE_LEVELCONFIG);
17170       }
17171       else
17172       {
17173         ChangeEditModeWindow(ED_MODE_DRAWING);
17174       }
17175       break;
17176
17177     case GADGET_ID_CLEAR:
17178       if (edit_mode != ED_MODE_DRAWING)
17179         ChangeEditModeWindow(ED_MODE_DRAWING);
17180
17181       for (x = 0; x < MAX_LEV_FIELDX; x++)
17182         for (y = 0; y < MAX_LEV_FIELDY; y++)
17183           Tile[x][y] = (button == 1 ? EL_EMPTY : new_element);
17184
17185       CopyLevelToUndoBuffer(GADGET_ID_CLEAR);
17186
17187       DrawEditorLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
17188       break;
17189
17190     case GADGET_ID_SAVE:
17191     {
17192       // saving read-only levels into personal level set modifies global vars
17193       // "leveldir_current" and "level_nr"; restore them after saving level
17194       LevelDirTree *leveldir_former = leveldir_current;
17195       int level_nr_former = level_nr;
17196       char *level_filename;
17197       boolean new_level;
17198
17199       if (leveldir_current->readonly &&
17200           !PrepareSavingIntoPersonalLevelSet())
17201         break;
17202
17203       level_filename = getDefaultLevelFilename(level_nr);
17204       new_level = !fileExists(level_filename);
17205
17206       if (new_level ||
17207           Request("Save this level and kill the old?", REQ_ASK))
17208       {
17209         if (leveldir_former->readonly)
17210           ModifyLevelConfigForSavingIntoPersonalLevelSet(leveldir_former->name);
17211
17212         SetAutomaticNumberOfGemsNeeded();
17213
17214         CopyPlayfield(Tile, level.field);
17215         SaveLevel(level_nr);
17216
17217         level.changed = FALSE;
17218
17219         if (new_level)
17220         {
17221           char level_saved_msg[64];
17222
17223           if (leveldir_former->readonly)
17224             sprintf(level_saved_msg,
17225                     "Level saved as level %d into personal level set!",
17226                     level_nr);
17227           else
17228             strcpy(level_saved_msg, "Level saved!");
17229
17230           Request(level_saved_msg, REQ_CONFIRM);
17231         }
17232       }
17233
17234       // "cd" back to copied-from levelset (in case of saved read-only level)
17235       leveldir_current = leveldir_former;
17236       level_nr = level_nr_former;
17237
17238       break;
17239     }
17240
17241     case GADGET_ID_TEST:
17242       if (LevelChanged())
17243         level.game_version = GAME_VERSION_ACTUAL;
17244
17245       CopyPlayfield(level.field, TileBackup);
17246       CopyPlayfield(Tile, level.field);
17247
17248       CopyNativeLevel_RND_to_Native(&level);
17249
17250       UnmapLevelEditorGadgets();
17251       UndrawSpecialEditorDoor();
17252
17253       CloseDoor(DOOR_CLOSE_ALL);
17254
17255       // needed before playing if editor playfield area has different size
17256       ClearRectangle(drawto, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
17257
17258       // redraw_mask = REDRAW_ALL;
17259
17260       level_editor_test_game = TRUE;
17261
17262       StartGameActions(FALSE, setup.autorecord, level.random_seed);
17263
17264       break;
17265
17266     case GADGET_ID_EXIT:
17267       RequestExitLevelEditor(TRUE, FALSE);  // if level has changed, ask user
17268       break;
17269
17270     default:
17271       if (id >= GADGET_ID_ELEMENTLIST_FIRST &&
17272           id <= GADGET_ID_ELEMENTLIST_LAST)
17273       {
17274         int element_position = id - GADGET_ID_ELEMENTLIST_FIRST;
17275
17276         new_element = editor_elements[element_position + element_shift];
17277
17278         if (IS_EDITOR_CASCADE(new_element))
17279         {
17280           int i;
17281
17282           for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
17283           {
17284             int *cascade_element = &(*editor_elements_info[i].headline_list)[0];
17285             boolean *cascade_value = editor_elements_info[i].setup_cascade_value;
17286
17287             if (*cascade_element == new_element)
17288             {
17289               *cascade_element = EL_CASCADE_TOGGLE(*cascade_element);
17290               *cascade_value = IS_EDITOR_CASCADE_ACTIVE(*cascade_element);
17291
17292               // update element selection list
17293               ReinitializeElementList();
17294               ModifyEditorElementList();
17295
17296               // update cascading gadget info text
17297               PrintEditorGadgetInfoText(level_editor_gadget[id]);
17298
17299               // save current editor cascading state
17300               SaveSetup_EditorCascade();
17301
17302               break;
17303             }
17304           }
17305
17306           break;
17307         }
17308
17309         if (last_custom_copy_mode != -1)
17310         {
17311           if (CopyCustomElement(properties_element, new_element,
17312                                 last_custom_copy_mode))
17313           {
17314             ClickOnGadget(level_editor_gadget[last_drawing_function],
17315                           MB_LEFTBUTTON);
17316
17317             last_custom_copy_mode = -1;
17318           }
17319
17320           break;
17321         }
17322
17323         // change element of button used to show palette
17324         if (editor.palette.show_on_element_buttons)
17325           button = last_button;
17326
17327         PickDrawingElement(button, new_element);
17328
17329         if (!stick_element_properties_window &&
17330             drawing_function != GADGET_ID_PICK_ELEMENT &&
17331             !(GetKeyModState() & KMOD_Control))
17332         {
17333           properties_element = new_element;
17334           if (edit_mode == ED_MODE_PROPERTIES)
17335             DrawPropertiesWindow();
17336         }
17337
17338         if (drawing_function == GADGET_ID_PICK_ELEMENT)
17339           ClickOnGadget(level_editor_gadget[last_drawing_function],
17340                         MB_LEFTBUTTON);
17341
17342         if (!use_permanent_palette)
17343           ChangeEditModeWindow(last_edit_mode);
17344       }
17345 #ifdef DEBUG
17346       else if (gi->event.type == GD_EVENT_PRESSED)
17347         Debug("editor", "default: HandleControlButtons: GD_EVENT_PRESSED(%d)", id);
17348       else if (gi->event.type == GD_EVENT_RELEASED)
17349         Debug("editor", "default: HandleControlButtons: GD_EVENT_RELEASED(%d)", id);
17350       else if (gi->event.type == GD_EVENT_MOVING)
17351         Debug("editor", "default: HandleControlButtons: GD_EVENT_MOVING(%d)", id);
17352       else
17353         Debug("editor", "default: HandleControlButtons: ? (id == %d)", id);
17354 #endif
17355       break;
17356   }
17357 }
17358
17359 void HandleLevelEditorKeyInput(Key key)
17360 {
17361   char letter = getCharFromKey(key);
17362
17363   if (drawing_function == GADGET_ID_TEXT &&
17364       DrawLevelText(0, 0, 0, TEXT_QUERY_TYPING) == TRUE)
17365   {
17366     if (letter)
17367       DrawLevelText(0, 0, letter, TEXT_WRITECHAR);
17368     else if (key == KSYM_Delete || key == KSYM_BackSpace)
17369       DrawLevelText(0, 0, 0, TEXT_BACKSPACE);
17370     else if (key == KSYM_Return)
17371       DrawLevelText(0, 0, 0, TEXT_NEWLINE);
17372     else if (key == KSYM_Escape)
17373       DrawLevelText(0, 0, 0, TEXT_END);
17374
17375     return;
17376   }
17377
17378   int id = GADGET_ID_NONE;
17379   int new_element_shift = element_shift;
17380   int step = ED_ELEMENTLIST_BUTTONS_VERT - 1;
17381   int button = MB_LEFTBUTTON;
17382   int i;
17383
17384   switch (key)
17385   {
17386     case KSYM_Left:
17387       id = GADGET_ID_SCROLL_LEFT;
17388       break;
17389     case KSYM_Right:
17390       id = GADGET_ID_SCROLL_RIGHT;
17391       break;
17392     case KSYM_Up:
17393       id = GADGET_ID_SCROLL_UP;
17394       break;
17395     case KSYM_Down:
17396       id = GADGET_ID_SCROLL_DOWN;
17397       break;
17398
17399     case KSYM_Page_Up:
17400     case KSYM_Page_Down:
17401       step *= (key == KSYM_Page_Up ? -1 : +1);
17402       element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ;
17403
17404       if (element_shift < 0)
17405         element_shift = 0;
17406       if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
17407         element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
17408
17409       ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
17410                    GDI_SCROLLBAR_ITEM_POSITION,
17411                    element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
17412
17413       ModifyEditorElementList();
17414
17415       break;
17416
17417     case KSYM_Home:
17418     case KSYM_End:
17419       element_shift = (key == KSYM_Home ? 0 :
17420                        num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS);
17421
17422       ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
17423                    GDI_SCROLLBAR_ITEM_POSITION,
17424                    element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
17425
17426       ModifyEditorElementList();
17427
17428       break;
17429
17430     case KSYM_Insert:
17431     case KSYM_Delete:
17432
17433       // this is needed to prevent interference with running "True X-Mouse"
17434       if (GetKeyModStateFromEvents() & KMOD_Control)
17435         break;
17436
17437       // check for last or next editor cascade block in element list
17438       for (i = 0; i < num_editor_elements; i++)
17439       {
17440         if ((key == KSYM_Insert && i == element_shift) ||
17441             (key == KSYM_Delete && new_element_shift > element_shift))
17442           break;
17443
17444         // jump to next cascade block (or to start of element list)
17445         if (i == 0 || IS_EDITOR_CASCADE(editor_elements[i]))
17446           new_element_shift = i;
17447       }
17448
17449       if (i < num_editor_elements)
17450         element_shift = new_element_shift;
17451
17452       if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
17453         element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
17454
17455       ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
17456                    GDI_SCROLLBAR_ITEM_POSITION,
17457                    element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
17458
17459       ModifyEditorElementList();
17460
17461       break;
17462
17463     case KSYM_Escape:
17464       if (edit_mode == ED_MODE_DRAWING)
17465         RequestExitLevelEditor(setup.ask_on_escape_editor, TRUE);
17466       else if (edit_mode == ED_MODE_LEVELCONFIG)
17467         HandleControlButtons(level_editor_gadget[GADGET_ID_CONF]);
17468       else if (edit_mode == ED_MODE_PROPERTIES)
17469         HandleControlButtons(level_editor_gadget[GADGET_ID_PROPERTIES]);
17470       else if (edit_mode == ED_MODE_PALETTE)
17471         HandleControlButtons(level_editor_gadget[GADGET_ID_PALETTE]);
17472       else              // should never happen
17473         ChangeEditModeWindow(ED_MODE_DRAWING);
17474
17475       break;
17476
17477     default:
17478       break;
17479   }
17480
17481   if (id != GADGET_ID_NONE)
17482     ClickOnGadget(level_editor_gadget[id], button);
17483   else if (letter == '1' || letter == '?')
17484     ClickOnGadget(level_editor_gadget[GADGET_ID_ELEMENT_LEFT], button);
17485   else if (letter == '2')
17486     ClickOnGadget(level_editor_gadget[GADGET_ID_ELEMENT_MIDDLE], button);
17487   else if (letter == '3')
17488     ClickOnGadget(level_editor_gadget[GADGET_ID_ELEMENT_RIGHT], button);
17489   else if (letter == '.')
17490     ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS], button);
17491   else if (letter == 'U')
17492     ClickOnGadget(level_editor_gadget[GADGET_ID_UNDO], 3);
17493   else if (letter == '-' || key == KSYM_KP_Subtract)
17494     ClickOnGadget(level_editor_gadget[GADGET_ID_ZOOM], 3);
17495   else if (letter == '0' || key == KSYM_KP_0)
17496     ClickOnGadget(level_editor_gadget[GADGET_ID_ZOOM], 2);
17497   else if (letter == '+' || key == KSYM_KP_Add ||
17498            letter == '=')       // ("Shift-=" is "+" on US keyboards)
17499     ClickOnGadget(level_editor_gadget[GADGET_ID_ZOOM], 1);
17500   else if (key == KSYM_Return ||
17501            key == KSYM_space ||
17502            key == setup.shortcut.toggle_pause)
17503     ClickOnGadget(level_editor_gadget[GADGET_ID_TEST], button);
17504   else
17505     for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
17506       if (letter && letter == controlbutton_info[i].shortcut)
17507         if (!anyTextGadgetActive())
17508           ClickOnGadget(level_editor_gadget[i], button);
17509
17510   if (draw_with_brush)
17511   {
17512     if (letter == 'x')
17513       FlipBrushX();
17514     else if (letter == 'y')
17515       FlipBrushY();
17516     else if (letter == 'z')
17517       RotateBrush();
17518   }
17519 }
17520
17521 static void HandleLevelEditorIdle_Properties(void)
17522 {
17523   int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
17524   int x = editor.settings.element_graphic.x + element_border;
17525   int y = editor.settings.element_graphic.y + element_border;
17526   static DelayCounter action_delay = { 0 };
17527   int i;
17528
17529   action_delay.value = GameFrameDelay;
17530
17531   if (!DelayReached(&action_delay))
17532     return;
17533
17534   for (i = 0; i < ED_NUM_SELECTBOX; i++)
17535   {
17536     struct GadgetInfo *gi = level_editor_gadget[selectbox_info[i].gadget_id];
17537
17538     if (gi->mapped && gi->active && gi->selectbox.open)
17539       return;
17540   }
17541
17542   DrawEditorElementAnimation(SX + x, SY + y);
17543
17544   redraw_mask |= REDRAW_FIELD;
17545
17546   FrameCounter++;       // increase animation frame counter
17547 }
17548
17549 static void HandleLevelEditorIdle_Drawing(void)
17550 {
17551   static boolean last_highlighted = FALSE;
17552   static boolean last_highlighted_similar = FALSE;
17553   boolean highlighted = (GetKeyModState() & KMOD_Alt);
17554   boolean highlighted_similar = (GetKeyModState() & KMOD_Shift);
17555
17556   if (highlighted != last_highlighted ||
17557       (highlighted && highlighted_similar != last_highlighted_similar))
17558   {
17559     DrawAreaElementHighlight(highlighted, highlighted_similar);
17560
17561     redraw_mask |= REDRAW_FIELD;
17562   }
17563
17564   last_highlighted = highlighted;
17565   last_highlighted_similar = highlighted_similar;
17566 }
17567
17568 void HandleLevelEditorIdle(void)
17569 {
17570   if (edit_mode == ED_MODE_PROPERTIES)
17571     HandleLevelEditorIdle_Properties();
17572   else if (edit_mode == ED_MODE_DRAWING)
17573     HandleLevelEditorIdle_Drawing();
17574 }
17575
17576 static void ClearEditorGadgetInfoText(void)
17577 {
17578   DrawBackground(INFOTEXT_XPOS, INFOTEXT_YPOS, INFOTEXT_XSIZE, INFOTEXT_YSIZE);
17579 }
17580
17581 void PrintEditorGadgetInfoText(struct GadgetInfo *gi)
17582 {
17583   char infotext[MAX_OUTPUT_LINESIZE + 1];
17584   int max_infotext_len = getMaxInfoTextLength();
17585
17586   if (gi == NULL || strlen(gi->info_text) == 0)
17587     return;
17588
17589   strncpy(infotext, gi->info_text, max_infotext_len);
17590   infotext[max_infotext_len] = '\0';
17591
17592   if (gi->custom_id < ED_NUM_CTRL_BUTTONS)
17593   {
17594     int key = controlbutton_info[gi->custom_id].shortcut;
17595
17596     if (key)
17597     {
17598       char shortcut[MAX_OUTPUT_LINESIZE + 1];
17599
17600       if (gi->custom_id == GADGET_ID_SINGLE_ITEMS)
17601         sprintf(shortcut, " ('.' or '%c')", key);
17602       else if (gi->custom_id == GADGET_ID_PICK_ELEMENT)
17603         sprintf(shortcut, " ('%c' or 'Ctrl')", key);
17604       else if (gi->custom_id == GADGET_ID_TEST)
17605         sprintf(shortcut, " ('Enter' or 'Shift-%c')", key);
17606       else if (gi->custom_id == GADGET_ID_UNDO)
17607         sprintf(shortcut, " ('%c/Shift-U')", key);
17608       else if (gi->custom_id == GADGET_ID_ZOOM)
17609         sprintf(shortcut, " ('%c', '0', '-')", key);
17610       else
17611         sprintf(shortcut, " ('%s%c')",
17612                 (key >= 'A' && key <= 'Z' ? "Shift-" : ""), key);
17613
17614       if (strlen(infotext) + strlen(shortcut) <= max_infotext_len)
17615         strcat(infotext, shortcut);
17616     }
17617   }
17618
17619   DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, INFOTEXT_FONT);
17620 }
17621
17622 void HandleEditorGadgetInfoText(void *ptr)
17623 {
17624   struct GadgetInfo *gi = (struct GadgetInfo *)ptr;
17625
17626   if (game_status != GAME_MODE_EDITOR)
17627     return;
17628
17629   ClearEditorGadgetInfoText();
17630
17631   if (gi == NULL || gi->event.type == GD_EVENT_INFO_LEAVING)
17632     return;
17633
17634   // misuse this function to delete brush cursor, if needed
17635   if (edit_mode == ED_MODE_DRAWING && draw_with_brush)
17636     DeleteBrushFromCursor();
17637
17638   PrintEditorGadgetInfoText(gi);
17639 }
17640
17641 static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
17642 {
17643   int id = gi->custom_id;
17644   int type_id = gi->custom_type_id;
17645   int sx = gi->event.x;
17646   int sy = gi->event.y;
17647   int lx = sx + level_xpos;
17648   int ly = sy + level_ypos;
17649   int min_sx = 0, min_sy = 0;
17650   int max_sx = gi->drawing.area_xsize - 1;
17651   int max_sy = gi->drawing.area_ysize - 1;
17652   int actual_drawing_function = drawing_function;
17653   int max_infotext_len = getMaxInfoTextLength();
17654   char infotext[MAX_OUTPUT_LINESIZE + 1];
17655
17656   infotext[0] = '\0';           // start with empty info text
17657
17658   // pressed Control key: simulate picking element
17659   if (GetKeyModState() & KMOD_Control)
17660     actual_drawing_function = GADGET_ID_PICK_ELEMENT;
17661
17662   ClearEditorGadgetInfoText();
17663
17664   if (gi->event.type == GD_EVENT_INFO_LEAVING)
17665     return;
17666
17667   // make sure to stay inside drawing area boundaries
17668   sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
17669   sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
17670
17671   if (id == GADGET_ID_DRAWING_LEVEL)
17672   {
17673     if (button_status)
17674     {
17675       int min_lx = 0, min_ly = 0;
17676       int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
17677
17678       // get positions inside level field
17679       lx = sx + level_xpos;
17680       ly = sy + level_ypos;
17681
17682       // make sure to stay inside level field boundaries
17683       lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
17684       ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
17685
17686       // correct drawing area positions accordingly
17687       sx = lx - level_xpos;
17688       sy = ly - level_ypos;
17689     }
17690
17691     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
17692     {
17693       if (button_status)        // if (gi->state == GD_BUTTON_PRESSED)
17694       {
17695         static int start_lx = 0;
17696         static int start_ly = 0;
17697         char *text;
17698
17699         if (gi->event.type == GD_EVENT_PRESSED)
17700         {
17701           start_lx = lx;
17702           start_ly = ly;
17703         }
17704
17705         switch (actual_drawing_function)
17706         {
17707           case GADGET_ID_SINGLE_ITEMS:
17708             text = "Drawing single items";
17709             break;
17710           case GADGET_ID_CONNECTED_ITEMS:
17711             text = "Drawing connected items";
17712             break;
17713           case GADGET_ID_LINE:
17714             text = "Drawing line";
17715             break;
17716           case GADGET_ID_ARC:
17717             text = "Drawing arc";
17718             break;
17719           case GADGET_ID_TEXT:
17720             text = "Setting text cursor";
17721             break;
17722           case GADGET_ID_RECTANGLE:
17723             text = "Drawing rectangle";
17724             break;
17725           case GADGET_ID_FILLED_BOX:
17726             text = "Drawing filled box";
17727             break;
17728           case GADGET_ID_FLOOD_FILL:
17729             text = "Flood fill";
17730             break;
17731           case GADGET_ID_GRAB_BRUSH:
17732             text = "Grabbing brush";
17733             break;
17734           case GADGET_ID_PICK_ELEMENT:
17735             text = "Picking element";
17736             break;
17737
17738           default:
17739             text = "Drawing position";
17740             break;
17741         }
17742
17743         if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
17744           sprintf(infotext, "%s: %d, %d", text, lx, ly);
17745         else
17746           sprintf(infotext, "%s: %d, %d", text,
17747                   ABS(lx - start_lx) + 1, ABS(ly - start_ly) + 1);
17748       }
17749       else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
17750         strncpy(infotext, getElementInfoText(Tile[lx][ly]), max_infotext_len);
17751       else
17752         sprintf(infotext, "Level position: %d, %d", lx, ly);
17753     }
17754
17755     // misuse this function to draw brush cursor, if needed
17756     if (edit_mode == ED_MODE_DRAWING && draw_with_brush && !button_status)
17757     {
17758       if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
17759         CopyBrushToCursor(sx, sy);
17760       else
17761         DeleteBrushFromCursor();
17762     }
17763
17764     if (!draw_with_brush)
17765       UpdateBrushPosition(sx, sy);
17766   }
17767   else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
17768   {
17769     int pos = sx * drawingarea_info[type_id].area_ysize + sy;
17770     int element = drawingarea_info[type_id].value[pos];
17771
17772     strncpy(infotext, getElementInfoText(element), max_infotext_len);
17773   }
17774   else
17775   {
17776     if (id == GADGET_ID_CUSTOM_CONTENT)
17777       sprintf(infotext, "custom element content position: %d, %d", sx, sy);
17778     else if (id == GADGET_ID_GROUP_CONTENT)
17779       sprintf(infotext, "group element position: %d", sx + 1);
17780     else if (id >= GADGET_ID_YAMYAM_CONTENT_0 &&
17781              id <= GADGET_ID_YAMYAM_CONTENT_7)
17782       sprintf(infotext, "content area %d position: %d, %d",
17783               id - GADGET_ID_YAMYAM_CONTENT_0 + 1, sx, sy);
17784     else if (id >= GADGET_ID_MAGIC_BALL_CONTENT_0 &&
17785              id <= GADGET_ID_MAGIC_BALL_CONTENT_7)
17786       sprintf(infotext, "content area %d position: %d, %d",
17787               id - GADGET_ID_MAGIC_BALL_CONTENT_0 + 1, sx, sy);
17788     else if (id == GADGET_ID_ANDROID_CONTENT)
17789       sprintf(infotext, "android element position: %d", sx + 1);
17790     else if (drawingarea_info[type_id].infotext != NULL)
17791       strcpy(infotext, drawingarea_info[type_id].infotext);
17792   }
17793
17794   infotext[max_infotext_len] = '\0';
17795
17796   if (strlen(infotext) > 0)
17797     DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, INFOTEXT_FONT, infotext);
17798 }
17799
17800 void RequestExitLevelEditor(boolean ask_if_level_has_changed,
17801                             boolean quick_quit)
17802 {
17803   if (!ask_if_level_has_changed ||
17804       !LevelChanged() ||
17805       Request("Level has changed! Exit without saving?",
17806               REQ_ASK | REQ_STAY_OPEN))
17807   {
17808     struct RectWithBorder *vp_door_1 = &viewport.door_1[GAME_MODE_MAIN];
17809     struct RectWithBorder *vp_door_2 = &viewport.door_2[GAME_MODE_MAIN];
17810
17811     // draw normal door
17812     UndrawSpecialEditorDoor();
17813
17814     // use door animation if door 1 viewport is unchanged and contains toolbox
17815     if (useEditorDoorAnimation())
17816       CloseDoor(DOOR_CLOSE_1 | DOOR_FORCE_ANIM);
17817
17818     // close editor doors if viewport definition is the same as in main menu
17819     if (vp_door_1->x      == DX     &&
17820         vp_door_1->y      == DY     &&
17821         vp_door_1->width  == DXSIZE &&
17822         vp_door_1->height == DYSIZE &&
17823         vp_door_2->x      == VX     &&
17824         vp_door_2->y      == VY     &&
17825         vp_door_2->width  == VXSIZE &&
17826         vp_door_2->height == VYSIZE)
17827       CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
17828     else
17829       SetDoorState(DOOR_CLOSE_ALL);
17830
17831     BackToFront();
17832
17833     if (quick_quit)
17834       FadeSkipNextFadeIn();
17835
17836     SetGameStatus(GAME_MODE_MAIN);
17837
17838     DrawMainMenu();
17839   }
17840   else
17841   {
17842     if (!global.use_envelope_request)
17843     {
17844       CloseDoor(DOOR_CLOSE_1);
17845       OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
17846     }
17847   }
17848 }