rnd-20040426-1-src
[rocksndiamonds.git] / src / editor.c
1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * editor.c                                                 *
12 ***********************************************************/
13
14 #include <math.h>
15
16 #include "libgame/libgame.h"
17
18 #include "editor.h"
19 #include "screens.h"
20 #include "tools.h"
21 #include "files.h"
22 #include "game.h"
23 #include "init.h"
24 #include "tape.h"
25
26
27 #define INFOTEXT_UNKNOWN_ELEMENT        "unknown"
28
29
30 /*
31   -----------------------------------------------------------------------------
32   screen and artwork graphic pixel position definitions
33   -----------------------------------------------------------------------------
34 */
35
36 /* positions in the level editor */
37 #define ED_WIN_MB_LEFT_XPOS             6
38 #define ED_WIN_MB_LEFT_YPOS             258
39 #define ED_WIN_MB_MIDDLE_XPOS           42
40 #define ED_WIN_MB_MIDDLE_YPOS           ED_WIN_MB_LEFT_YPOS
41 #define ED_WIN_MB_RIGHT_XPOS            78
42 #define ED_WIN_MB_RIGHT_YPOS            ED_WIN_MB_LEFT_YPOS
43
44 /* values for the control window */
45 #define ED_CTRL_NO_BUTTONS_GFX_XPOS     6
46 #define ED_CTRL_NO_BUTTONS_GFX_YPOS     286
47 #define ED_CTRL1_BUTTONS_GFX_YPOS       236
48 #define ED_CTRL2_BUTTONS_GFX_YPOS       236
49 #define ED_CTRL3_BUTTONS_GFX_YPOS       324
50 #define ED_CTRL4_BUTTONS_GFX_XPOS       44
51 #define ED_CTRL4_BUTTONS_GFX_YPOS       214
52 #define ED_CTRL1_BUTTONS_ALT_GFX_YPOS   142
53 #define ED_CTRL3_BUTTONS_ALT_GFX_YPOS   302
54
55 #define ED_CTRL1_BUTTON_XSIZE           22
56 #define ED_CTRL1_BUTTON_YSIZE           22
57 #define ED_CTRL1_BUTTONS_XPOS           6
58 #define ED_CTRL1_BUTTONS_YPOS           6
59 #define ED_CTRL2_BUTTON_XSIZE           30
60 #define ED_CTRL2_BUTTON_YSIZE           20
61 #define ED_CTRL2_BUTTONS_XPOS           5
62 #define ED_CTRL2_BUTTONS_YPOS           99
63 #define ED_CTRL3_BUTTON_XSIZE           22
64 #define ED_CTRL3_BUTTON_YSIZE           22
65 #define ED_CTRL3_BUTTONS_XPOS           6
66 #define ED_CTRL3_BUTTONS_YPOS           6
67 #define ED_CTRL4_BUTTON_XSIZE           22
68 #define ED_CTRL4_BUTTON_YSIZE           22
69 #define ED_CTRL4_BUTTONS_XPOS           6
70 #define ED_CTRL4_BUTTONS_YPOS           6
71
72 #define ED_CTRL1_BUTTONS_HORIZ          4
73 #define ED_CTRL1_BUTTONS_VERT           4
74 #define ED_CTRL2_BUTTONS_HORIZ          3
75 #define ED_CTRL2_BUTTONS_VERT           2
76 #define ED_CTRL3_BUTTONS_HORIZ          3
77 #define ED_CTRL3_BUTTONS_VERT           1
78 #define ED_CTRL4_BUTTONS_HORIZ          2
79 #define ED_CTRL4_BUTTONS_VERT           1
80
81 #define ED_NUM_CTRL1_BUTTONS   (ED_CTRL1_BUTTONS_HORIZ * ED_CTRL1_BUTTONS_VERT)
82 #define ED_NUM_CTRL2_BUTTONS   (ED_CTRL2_BUTTONS_HORIZ * ED_CTRL2_BUTTONS_VERT)
83 #define ED_NUM_CTRL3_BUTTONS   (ED_CTRL3_BUTTONS_HORIZ * ED_CTRL3_BUTTONS_VERT)
84 #define ED_NUM_CTRL4_BUTTONS   (ED_CTRL4_BUTTONS_HORIZ * ED_CTRL4_BUTTONS_VERT)
85 #define ED_NUM_CTRL1_2_BUTTONS (ED_NUM_CTRL1_BUTTONS   + ED_NUM_CTRL2_BUTTONS)
86 #define ED_NUM_CTRL1_3_BUTTONS (ED_NUM_CTRL1_2_BUTTONS + ED_NUM_CTRL3_BUTTONS)
87 #define ED_NUM_CTRL_BUTTONS    (ED_NUM_CTRL1_BUTTONS +  \
88                                 ED_NUM_CTRL2_BUTTONS +  \
89                                 ED_NUM_CTRL3_BUTTONS +  \
90                                 ED_NUM_CTRL4_BUTTONS)
91
92 /* values for the element list */
93 #define ED_ELEMENTLIST_XPOS             5
94 #define ED_ELEMENTLIST_YPOS             30
95 #define ED_ELEMENTLIST_XSIZE            20
96 #define ED_ELEMENTLIST_YSIZE            20
97 #define ED_ELEMENTLIST_BUTTONS_HORIZ    4
98 #define ED_ELEMENTLIST_BUTTONS_VERT     11
99 #define ED_NUM_ELEMENTLIST_BUTTONS      (ED_ELEMENTLIST_BUTTONS_HORIZ * \
100                                          ED_ELEMENTLIST_BUTTONS_VERT)
101
102 /* standard distances */
103 #define ED_BORDER_SIZE                  3
104 #define ED_BORDER_TEXT_XSIZE            5
105 #define ED_BORDER_AREA_YSIZE            1
106
107 #define ED_GADGET_DISTANCE              2
108 #define ED_GADGET_TEXT_DISTANCE         (2 * ED_GADGET_DISTANCE)
109 #define ED_DRAWINGAREA_TEXT_DISTANCE    (ED_GADGET_TEXT_DISTANCE +      \
110                                          MINI_TILEX / 2)
111
112 /* values for the settings windows */
113 #define ED_SETTINGS_XSTART              (3 * MINI_TILEX / 2)
114 #define ED_SETTINGS_YSTART              (MINI_TILEY * 10)
115
116 #define ED_XOFFSET_CHECKBOX             (ED_CHECKBUTTON_XSIZE +         \
117                                          2 * ED_GADGET_DISTANCE)
118
119 #define ED_SETTINGS_XOFFSET             ED_XOFFSET_CHECKBOX
120 #define ED_SETTINGS_YOFFSET             (3 * MINI_TILEY / 2)
121
122 #define ED_SETTINGS_XPOS(n)             (ED_SETTINGS_XSTART +           \
123                                          (n) * ED_SETTINGS_XOFFSET)
124 #define ED_SETTINGS_YPOS(n)             (ED_SETTINGS_YSTART +           \
125                                          (n) * ED_SETTINGS_YOFFSET)
126
127 #define ED_SETTINGS1_YPOS               MINI_TILEY
128 #define ED_SETTINGS2_XPOS               MINI_TILEX
129 #define ED_SETTINGS2_YPOS               (ED_SETTINGS1_YPOS + 12 * TILEY - 2)
130
131 /* values for counter gadgets */
132 #define ED_COUNTER_YSTART               (ED_SETTINGS1_YPOS + 2 * TILEY)
133 #define ED_COUNTER_YDISTANCE            (3 * MINI_TILEY)
134 #define ED_COUNTER_YPOS(n)              (ED_COUNTER_YSTART +            \
135                                          (n) * ED_COUNTER_YDISTANCE)
136 #define ED_COUNTER2_YPOS(n)             (ED_COUNTER_YSTART +            \
137                                          (n) * ED_COUNTER_YDISTANCE - 2)
138
139 /* values for element content drawing areas */
140 #define ED_AREA_1X1_SETTINGS_XPOS(n)    (ED_SETTINGS_XPOS(n))
141 #define ED_AREA_1X1_SETTINGS_YPOS(n)    (ED_SETTINGS_YPOS(n) +          \
142                                          ED_GADGET_DISTANCE)
143
144 #define ED_AREA_3X3_SETTINGS_XPOS(n)    (ED_SETTINGS_XPOS(n))
145 #define ED_AREA_3X3_SETTINGS_YPOS(n)    (ED_SETTINGS_YPOS(n) +          \
146                                          ED_GADGET_DISTANCE - MINI_TILEY)
147
148 /* yamyam content */
149 #define ED_AREA_YAMYAM_CONTENT_XPOS(n)  (2 * MINI_TILEX +               \
150                                          5 * ((n) % 4) * MINI_TILEX)
151 #define ED_AREA_YAMYAM_CONTENT_YPOS(n)  (17 * MINI_TILEY +              \
152                                          6 * ((n) / 4) * MINI_TILEY)
153
154 /* values for scrolling gadgets for drawing area */
155 #define ED_SCROLLBUTTON_XPOS            24
156 #define ED_SCROLLBUTTON_YPOS            0
157 #define ED_SCROLLBAR_XPOS               24
158 #define ED_SCROLLBAR_YPOS               64
159
160 #define ED_SCROLLBUTTON_XSIZE           16
161 #define ED_SCROLLBUTTON_YSIZE           16
162
163 #define ED_SCROLL_UP_XPOS               (SXSIZE - ED_SCROLLBUTTON_XSIZE)
164 #define ED_SCROLL_UP_YPOS               (0)
165 #define ED_SCROLL_DOWN_XPOS             ED_SCROLL_UP_XPOS
166 #define ED_SCROLL_DOWN_YPOS             (SYSIZE - 3 * ED_SCROLLBUTTON_YSIZE)
167 #define ED_SCROLL_LEFT_XPOS             (0)
168 #define ED_SCROLL_LEFT_YPOS             (SYSIZE - 2 * ED_SCROLLBUTTON_YSIZE)
169 #define ED_SCROLL_RIGHT_XPOS            (SXSIZE - 2 * ED_SCROLLBUTTON_XSIZE)
170 #define ED_SCROLL_RIGHT_YPOS            ED_SCROLL_LEFT_YPOS
171 #define ED_SCROLL_HORIZONTAL_XPOS       (ED_SCROLL_LEFT_XPOS +          \
172                                          ED_SCROLLBUTTON_XSIZE)
173 #define ED_SCROLL_HORIZONTAL_YPOS       ED_SCROLL_LEFT_YPOS
174 #define ED_SCROLL_HORIZONTAL_XSIZE      (SXSIZE - 3 * ED_SCROLLBUTTON_XSIZE)
175 #define ED_SCROLL_HORIZONTAL_YSIZE      ED_SCROLLBUTTON_YSIZE
176 #define ED_SCROLL_VERTICAL_XPOS         ED_SCROLL_UP_XPOS
177 #define ED_SCROLL_VERTICAL_YPOS         (ED_SCROLL_UP_YPOS +            \
178                                          ED_SCROLLBUTTON_YSIZE)
179 #define ED_SCROLL_VERTICAL_XSIZE        ED_SCROLLBUTTON_XSIZE
180 #define ED_SCROLL_VERTICAL_YSIZE        (SYSIZE - 4 * ED_SCROLLBUTTON_YSIZE)
181
182 /* values for scrolling gadgets for element list */
183 #define ED_SCROLLBUTTON2_XPOS           50
184 #define ED_SCROLLBUTTON2_YPOS           0
185 #define ED_SCROLLBAR2_XPOS              50
186 #define ED_SCROLLBAR2_YPOS              20
187
188 #define ED_SCROLLBUTTON2_XSIZE          10
189 #define ED_SCROLLBUTTON2_YSIZE          10
190
191 #define ED_SCROLL2_UP_XPOS              85
192 #define ED_SCROLL2_UP_YPOS              30
193 #define ED_SCROLL2_DOWN_XPOS            ED_SCROLL2_UP_XPOS
194 #define ED_SCROLL2_DOWN_YPOS            (ED_SCROLL2_UP_YPOS +           \
195                                          ED_ELEMENTLIST_BUTTONS_VERT *  \
196                                          ED_ELEMENTLIST_YSIZE -         \
197                                          ED_SCROLLBUTTON2_YSIZE)
198 #define ED_SCROLL2_VERTICAL_XPOS        ED_SCROLL2_UP_XPOS
199 #define ED_SCROLL2_VERTICAL_YPOS        (ED_SCROLL2_UP_YPOS +           \
200                                          ED_SCROLLBUTTON2_YSIZE)
201 #define ED_SCROLL2_VERTICAL_XSIZE       ED_SCROLLBUTTON2_XSIZE
202 #define ED_SCROLL2_VERTICAL_YSIZE       (ED_ELEMENTLIST_BUTTONS_VERT *  \
203                                          ED_ELEMENTLIST_YSIZE -         \
204                                          2 * ED_SCROLLBUTTON2_YSIZE)
205
206 /* values for checkbutton gadgets */
207 #define ED_CHECKBUTTON_XSIZE            ED_BUTTON_COUNT_XSIZE
208 #define ED_CHECKBUTTON_YSIZE            ED_BUTTON_COUNT_YSIZE
209 #define ED_CHECKBUTTON_UNCHECKED_XPOS   ED_BUTTON_MINUS_XPOS
210 #define ED_CHECKBUTTON_CHECKED_XPOS     ED_BUTTON_PLUS_XPOS
211 #define ED_CHECKBUTTON_YPOS             (ED_BUTTON_MINUS_YPOS + 22)
212 #define ED_RADIOBUTTON_YPOS             (ED_BUTTON_MINUS_YPOS + 44)
213 #define ED_STICKYBUTTON_YPOS            (ED_BUTTON_MINUS_YPOS + 66)
214
215 /* values for some special graphic buttons */
216 #define ED_COPY_CHANGE_PAGE_XPOS        25
217 #define ED_COPY_CHANGE_PAGE_YPOS        50
218 #define ED_PASTE_CHANGE_PAGE_XPOS       25
219 #define ED_PASTE_CHANGE_PAGE_YPOS       70
220
221 /* some values for text input, selectbox and counter gadgets */
222 #define ED_BUTTON_COUNT_YPOS            60
223 #define ED_BUTTON_COUNT_XSIZE           20
224 #define ED_BUTTON_COUNT_YSIZE           20
225 #define ED_WIN_COUNT_XPOS               (2 + ED_BUTTON_COUNT_XSIZE + 2)
226 #define ED_WIN_COUNT_YPOS               ED_BUTTON_COUNT_YPOS
227 #define ED_WIN_COUNT_XSIZE              52
228 #define ED_WIN_COUNT_YSIZE              ED_BUTTON_COUNT_YSIZE
229 #define ED_WIN_COUNT2_XPOS              27
230 #define ED_WIN_COUNT2_YPOS              3
231 #define ED_WIN_COUNT2_XSIZE             46
232 #define ED_WIN_COUNT2_YSIZE             ED_BUTTON_COUNT_YSIZE
233
234 #define ED_BUTTON_MINUS_XPOS            2
235 #define ED_BUTTON_MINUS_YPOS            ED_BUTTON_COUNT_YPOS
236 #define ED_BUTTON_MINUS_XSIZE           ED_BUTTON_COUNT_XSIZE
237 #define ED_BUTTON_MINUS_YSIZE           ED_BUTTON_COUNT_YSIZE
238 #define ED_BUTTON_PLUS_XPOS             (ED_WIN_COUNT_XPOS +            \
239                                          ED_WIN_COUNT_XSIZE + 2)
240 #define ED_BUTTON_PLUS_YPOS             ED_BUTTON_COUNT_YPOS
241 #define ED_BUTTON_PLUS_XSIZE            ED_BUTTON_COUNT_XSIZE
242 #define ED_BUTTON_PLUS_YSIZE            ED_BUTTON_COUNT_YSIZE
243
244 #define ED_SELECTBOX_XPOS               ED_WIN_COUNT_XPOS
245 #define ED_SELECTBOX_YPOS               (ED_WIN_COUNT_YPOS +            \
246                                          2 + ED_WIN_COUNT_YSIZE)
247 #define ED_SELECTBOX_XSIZE              ED_WIN_COUNT_XSIZE
248 #define ED_SELECTBOX_YSIZE              ED_WIN_COUNT_YSIZE
249
250 #define ED_SELECTBOX_BUTTON_XSIZE       14
251
252 #define ED_TEXTBUTTON_XPOS              ED_WIN_COUNT_XPOS
253 #define ED_TEXTBUTTON_YPOS              (ED_WIN_COUNT_YPOS +            \
254                                          4 * (2 + ED_WIN_COUNT_YSIZE))
255 #define ED_TEXTBUTTON_INACTIVE_YPOS     ED_TEXTBUTTON_YPOS
256
257 #define ED_TEXTBUTTON_TAB_XPOS          ED_WIN_COUNT_XPOS
258 #define ED_TEXTBUTTON_TAB_YPOS          (ED_WIN_COUNT_YPOS +            \
259                                          2 * (2 + ED_WIN_COUNT_YSIZE))
260 #define ED_TEXTBUTTON_TAB_INACTIVE_YPOS (ED_WIN_COUNT_YPOS +            \
261                                          3 * (2 + ED_WIN_COUNT_YSIZE))
262
263 #define ED_TEXTBUTTON_XSIZE             ED_WIN_COUNT_XSIZE
264 #define ED_TEXTBUTTON_YSIZE             ED_WIN_COUNT_YSIZE
265
266 /* values for ClearEditorGadgetInfoText() and HandleGadgetInfoText() */
267 #define INFOTEXT_XPOS                   SX
268 #define INFOTEXT_YPOS                   (SY + SYSIZE - MINI_TILEX + 2)
269 #define INFOTEXT_XSIZE                  SXSIZE
270 #define INFOTEXT_YSIZE                  MINI_TILEX
271
272
273 /*
274   -----------------------------------------------------------------------------
275   editor gadget definitions
276   -----------------------------------------------------------------------------
277 */
278
279 /* drawing toolbox buttons */
280 #define GADGET_ID_NONE                  -1
281 #define GADGET_ID_TOOLBOX_FIRST         0
282
283 #define GADGET_ID_SINGLE_ITEMS          (GADGET_ID_TOOLBOX_FIRST + 0)
284 #define GADGET_ID_CONNECTED_ITEMS       (GADGET_ID_TOOLBOX_FIRST + 1)
285 #define GADGET_ID_LINE                  (GADGET_ID_TOOLBOX_FIRST + 2)
286 #define GADGET_ID_ARC                   (GADGET_ID_TOOLBOX_FIRST + 3)
287 #define GADGET_ID_RECTANGLE             (GADGET_ID_TOOLBOX_FIRST + 4)
288 #define GADGET_ID_FILLED_BOX            (GADGET_ID_TOOLBOX_FIRST + 5)
289 #define GADGET_ID_WRAP_UP               (GADGET_ID_TOOLBOX_FIRST + 6)
290 #define GADGET_ID_TEXT                  (GADGET_ID_TOOLBOX_FIRST + 7)
291 #define GADGET_ID_FLOOD_FILL            (GADGET_ID_TOOLBOX_FIRST + 8)
292 #define GADGET_ID_WRAP_LEFT             (GADGET_ID_TOOLBOX_FIRST + 9)
293 #define GADGET_ID_PROPERTIES            (GADGET_ID_TOOLBOX_FIRST + 10)
294 #define GADGET_ID_WRAP_RIGHT            (GADGET_ID_TOOLBOX_FIRST + 11)
295 #define GADGET_ID_RANDOM_PLACEMENT      (GADGET_ID_TOOLBOX_FIRST + 12)
296 #define GADGET_ID_GRAB_BRUSH            (GADGET_ID_TOOLBOX_FIRST + 13)
297 #define GADGET_ID_WRAP_DOWN             (GADGET_ID_TOOLBOX_FIRST + 14)
298 #define GADGET_ID_PICK_ELEMENT          (GADGET_ID_TOOLBOX_FIRST + 15)
299
300 #define GADGET_ID_UNDO                  (GADGET_ID_TOOLBOX_FIRST + 16)
301 #define GADGET_ID_INFO                  (GADGET_ID_TOOLBOX_FIRST + 17)
302 #define GADGET_ID_SAVE                  (GADGET_ID_TOOLBOX_FIRST + 18)
303 #define GADGET_ID_CLEAR                 (GADGET_ID_TOOLBOX_FIRST + 19)
304 #define GADGET_ID_TEST                  (GADGET_ID_TOOLBOX_FIRST + 20)
305 #define GADGET_ID_EXIT                  (GADGET_ID_TOOLBOX_FIRST + 21)
306
307 #define GADGET_ID_CUSTOM_COPY_FROM      (GADGET_ID_TOOLBOX_FIRST + 22)
308 #define GADGET_ID_CUSTOM_COPY_TO        (GADGET_ID_TOOLBOX_FIRST + 23)
309 #define GADGET_ID_CUSTOM_EXCHANGE       (GADGET_ID_TOOLBOX_FIRST + 24)
310 #define GADGET_ID_CUSTOM_COPY           (GADGET_ID_TOOLBOX_FIRST + 25)
311 #define GADGET_ID_CUSTOM_PASTE          (GADGET_ID_TOOLBOX_FIRST + 26)
312
313 /* counter button identifiers */
314 #define GADGET_ID_COUNTER_FIRST         (GADGET_ID_TOOLBOX_FIRST + 27)
315
316 #define GADGET_ID_SELECT_LEVEL_DOWN     (GADGET_ID_COUNTER_FIRST + 0)
317 #define GADGET_ID_SELECT_LEVEL_TEXT     (GADGET_ID_COUNTER_FIRST + 1)
318 #define GADGET_ID_SELECT_LEVEL_UP       (GADGET_ID_COUNTER_FIRST + 2)
319 #define GADGET_ID_LEVEL_XSIZE_DOWN      (GADGET_ID_COUNTER_FIRST + 3)
320 #define GADGET_ID_LEVEL_XSIZE_TEXT      (GADGET_ID_COUNTER_FIRST + 4)
321 #define GADGET_ID_LEVEL_XSIZE_UP        (GADGET_ID_COUNTER_FIRST + 5)
322 #define GADGET_ID_LEVEL_YSIZE_DOWN      (GADGET_ID_COUNTER_FIRST + 6)
323 #define GADGET_ID_LEVEL_YSIZE_TEXT      (GADGET_ID_COUNTER_FIRST + 7)
324 #define GADGET_ID_LEVEL_YSIZE_UP        (GADGET_ID_COUNTER_FIRST + 8)
325 #define GADGET_ID_LEVEL_RANDOM_DOWN     (GADGET_ID_COUNTER_FIRST + 9)
326 #define GADGET_ID_LEVEL_RANDOM_TEXT     (GADGET_ID_COUNTER_FIRST + 10)
327 #define GADGET_ID_LEVEL_RANDOM_UP       (GADGET_ID_COUNTER_FIRST + 11)
328 #define GADGET_ID_LEVEL_GEMSLIMIT_DOWN  (GADGET_ID_COUNTER_FIRST + 12)
329 #define GADGET_ID_LEVEL_GEMSLIMIT_TEXT  (GADGET_ID_COUNTER_FIRST + 13)
330 #define GADGET_ID_LEVEL_GEMSLIMIT_UP    (GADGET_ID_COUNTER_FIRST + 14)
331 #define GADGET_ID_LEVEL_TIMELIMIT_DOWN  (GADGET_ID_COUNTER_FIRST + 15)
332 #define GADGET_ID_LEVEL_TIMELIMIT_TEXT  (GADGET_ID_COUNTER_FIRST + 16)
333 #define GADGET_ID_LEVEL_TIMELIMIT_UP    (GADGET_ID_COUNTER_FIRST + 17)
334 #define GADGET_ID_LEVEL_TIMESCORE_DOWN  (GADGET_ID_COUNTER_FIRST + 18)
335 #define GADGET_ID_LEVEL_TIMESCORE_TEXT  (GADGET_ID_COUNTER_FIRST + 19)
336 #define GADGET_ID_LEVEL_TIMESCORE_UP    (GADGET_ID_COUNTER_FIRST + 20)
337 #define GADGET_ID_ELEMENT_SCORE_DOWN    (GADGET_ID_COUNTER_FIRST + 21)
338 #define GADGET_ID_ELEMENT_SCORE_TEXT    (GADGET_ID_COUNTER_FIRST + 22)
339 #define GADGET_ID_ELEMENT_SCORE_UP      (GADGET_ID_COUNTER_FIRST + 23)
340 #define GADGET_ID_ELEMENT_CONTENT_DOWN  (GADGET_ID_COUNTER_FIRST + 24)
341 #define GADGET_ID_ELEMENT_CONTENT_TEXT  (GADGET_ID_COUNTER_FIRST + 25)
342 #define GADGET_ID_ELEMENT_CONTENT_UP    (GADGET_ID_COUNTER_FIRST + 26)
343 #define GADGET_ID_ENVELOPE_XSIZE_DOWN   (GADGET_ID_COUNTER_FIRST + 27)
344 #define GADGET_ID_ENVELOPE_XSIZE_TEXT   (GADGET_ID_COUNTER_FIRST + 28)
345 #define GADGET_ID_ENVELOPE_XSIZE_UP     (GADGET_ID_COUNTER_FIRST + 29)
346 #define GADGET_ID_ENVELOPE_YSIZE_DOWN   (GADGET_ID_COUNTER_FIRST + 30)
347 #define GADGET_ID_ENVELOPE_YSIZE_TEXT   (GADGET_ID_COUNTER_FIRST + 31)
348 #define GADGET_ID_ENVELOPE_YSIZE_UP     (GADGET_ID_COUNTER_FIRST + 32)
349 #define GADGET_ID_CUSTOM_SCORE_DOWN     (GADGET_ID_COUNTER_FIRST + 33)
350 #define GADGET_ID_CUSTOM_SCORE_TEXT     (GADGET_ID_COUNTER_FIRST + 34)
351 #define GADGET_ID_CUSTOM_SCORE_UP       (GADGET_ID_COUNTER_FIRST + 35)
352 #define GADGET_ID_CUSTOM_GEMCOUNT_DOWN  (GADGET_ID_COUNTER_FIRST + 36)
353 #define GADGET_ID_CUSTOM_GEMCOUNT_TEXT  (GADGET_ID_COUNTER_FIRST + 37)
354 #define GADGET_ID_CUSTOM_GEMCOUNT_UP    (GADGET_ID_COUNTER_FIRST + 38)
355 #define GADGET_ID_PUSH_DELAY_FIX_DOWN   (GADGET_ID_COUNTER_FIRST + 39)
356 #define GADGET_ID_PUSH_DELAY_FIX_TEXT   (GADGET_ID_COUNTER_FIRST + 40)
357 #define GADGET_ID_PUSH_DELAY_FIX_UP     (GADGET_ID_COUNTER_FIRST + 41)
358 #define GADGET_ID_PUSH_DELAY_RND_DOWN   (GADGET_ID_COUNTER_FIRST + 42)
359 #define GADGET_ID_PUSH_DELAY_RND_TEXT   (GADGET_ID_COUNTER_FIRST + 43)
360 #define GADGET_ID_PUSH_DELAY_RND_UP     (GADGET_ID_COUNTER_FIRST + 44)
361 #define GADGET_ID_DROP_DELAY_FIX_DOWN   (GADGET_ID_COUNTER_FIRST + 45)
362 #define GADGET_ID_DROP_DELAY_FIX_TEXT   (GADGET_ID_COUNTER_FIRST + 46)
363 #define GADGET_ID_DROP_DELAY_FIX_UP     (GADGET_ID_COUNTER_FIRST + 47)
364 #define GADGET_ID_DROP_DELAY_RND_DOWN   (GADGET_ID_COUNTER_FIRST + 48)
365 #define GADGET_ID_DROP_DELAY_RND_TEXT   (GADGET_ID_COUNTER_FIRST + 49)
366 #define GADGET_ID_DROP_DELAY_RND_UP     (GADGET_ID_COUNTER_FIRST + 50)
367 #define GADGET_ID_MOVE_DELAY_FIX_DOWN   (GADGET_ID_COUNTER_FIRST + 51)
368 #define GADGET_ID_MOVE_DELAY_FIX_TEXT   (GADGET_ID_COUNTER_FIRST + 52)
369 #define GADGET_ID_MOVE_DELAY_FIX_UP     (GADGET_ID_COUNTER_FIRST + 53)
370 #define GADGET_ID_MOVE_DELAY_RND_DOWN   (GADGET_ID_COUNTER_FIRST + 54)
371 #define GADGET_ID_MOVE_DELAY_RND_TEXT   (GADGET_ID_COUNTER_FIRST + 55)
372 #define GADGET_ID_MOVE_DELAY_RND_UP     (GADGET_ID_COUNTER_FIRST + 56)
373 #define GADGET_ID_EXPLOSION_DELAY_DOWN  (GADGET_ID_COUNTER_FIRST + 57)
374 #define GADGET_ID_EXPLOSION_DELAY_TEXT  (GADGET_ID_COUNTER_FIRST + 58)
375 #define GADGET_ID_EXPLOSION_DELAY_UP    (GADGET_ID_COUNTER_FIRST + 59)
376 #define GADGET_ID_IGNITION_DELAY_DOWN   (GADGET_ID_COUNTER_FIRST + 60)
377 #define GADGET_ID_IGNITION_DELAY_TEXT   (GADGET_ID_COUNTER_FIRST + 61)
378 #define GADGET_ID_IGNITION_DELAY_UP     (GADGET_ID_COUNTER_FIRST + 62)
379 #define GADGET_ID_CHANGE_DELAY_FIX_DOWN (GADGET_ID_COUNTER_FIRST + 63)
380 #define GADGET_ID_CHANGE_DELAY_FIX_TEXT (GADGET_ID_COUNTER_FIRST + 64)
381 #define GADGET_ID_CHANGE_DELAY_FIX_UP   (GADGET_ID_COUNTER_FIRST + 65)
382 #define GADGET_ID_CHANGE_DELAY_RND_DOWN (GADGET_ID_COUNTER_FIRST + 66)
383 #define GADGET_ID_CHANGE_DELAY_RND_TEXT (GADGET_ID_COUNTER_FIRST + 67)
384 #define GADGET_ID_CHANGE_DELAY_RND_UP   (GADGET_ID_COUNTER_FIRST + 68)
385 #define GADGET_ID_CHANGE_CONT_RND_DOWN  (GADGET_ID_COUNTER_FIRST + 69)
386 #define GADGET_ID_CHANGE_CONT_RND_TEXT  (GADGET_ID_COUNTER_FIRST + 70)
387 #define GADGET_ID_CHANGE_CONT_RND_UP    (GADGET_ID_COUNTER_FIRST + 71)
388 #define GADGET_ID_GROUP_CONTENT_DOWN    (GADGET_ID_COUNTER_FIRST + 72)
389 #define GADGET_ID_GROUP_CONTENT_TEXT    (GADGET_ID_COUNTER_FIRST + 73)
390 #define GADGET_ID_GROUP_CONTENT_UP      (GADGET_ID_COUNTER_FIRST + 74)
391
392 /* drawing area identifiers */
393 #define GADGET_ID_DRAWING_AREA_FIRST    (GADGET_ID_COUNTER_FIRST + 75)
394
395 #define GADGET_ID_DRAWING_LEVEL         (GADGET_ID_DRAWING_AREA_FIRST + 0)
396 #define GADGET_ID_ELEMENT_CONTENT_0     (GADGET_ID_DRAWING_AREA_FIRST + 1)
397 #define GADGET_ID_ELEMENT_CONTENT_1     (GADGET_ID_DRAWING_AREA_FIRST + 2)
398 #define GADGET_ID_ELEMENT_CONTENT_2     (GADGET_ID_DRAWING_AREA_FIRST + 3)
399 #define GADGET_ID_ELEMENT_CONTENT_3     (GADGET_ID_DRAWING_AREA_FIRST + 4)
400 #define GADGET_ID_ELEMENT_CONTENT_4     (GADGET_ID_DRAWING_AREA_FIRST + 5)
401 #define GADGET_ID_ELEMENT_CONTENT_5     (GADGET_ID_DRAWING_AREA_FIRST + 6)
402 #define GADGET_ID_ELEMENT_CONTENT_6     (GADGET_ID_DRAWING_AREA_FIRST + 7)
403 #define GADGET_ID_ELEMENT_CONTENT_7     (GADGET_ID_DRAWING_AREA_FIRST + 8)
404 #define GADGET_ID_AMOEBA_CONTENT        (GADGET_ID_DRAWING_AREA_FIRST + 9)
405 #define GADGET_ID_CUSTOM_GRAPHIC        (GADGET_ID_DRAWING_AREA_FIRST + 10)
406 #define GADGET_ID_CUSTOM_CONTENT        (GADGET_ID_DRAWING_AREA_FIRST + 11)
407 #define GADGET_ID_CUSTOM_MOVE_ENTER     (GADGET_ID_DRAWING_AREA_FIRST + 12)
408 #define GADGET_ID_CUSTOM_MOVE_LEAVE     (GADGET_ID_DRAWING_AREA_FIRST + 13)
409 #define GADGET_ID_CUSTOM_CHANGE_TARGET  (GADGET_ID_DRAWING_AREA_FIRST + 14)
410 #define GADGET_ID_CUSTOM_CHANGE_CONTENT (GADGET_ID_DRAWING_AREA_FIRST + 15)
411 #define GADGET_ID_CUSTOM_CHANGE_TRIGGER (GADGET_ID_DRAWING_AREA_FIRST + 16)
412 #define GADGET_ID_GROUP_CONTENT         (GADGET_ID_DRAWING_AREA_FIRST + 17)
413 #define GADGET_ID_RANDOM_BACKGROUND     (GADGET_ID_DRAWING_AREA_FIRST + 18)
414
415 /* text input identifiers */
416 #define GADGET_ID_TEXT_INPUT_FIRST      (GADGET_ID_DRAWING_AREA_FIRST + 19)
417
418 #define GADGET_ID_LEVEL_NAME            (GADGET_ID_TEXT_INPUT_FIRST + 0)
419 #define GADGET_ID_LEVEL_AUTHOR          (GADGET_ID_TEXT_INPUT_FIRST + 1)
420 #define GADGET_ID_ELEMENT_NAME          (GADGET_ID_TEXT_INPUT_FIRST + 2)
421
422 /* text area identifiers */
423 #define GADGET_ID_TEXT_AREA_FIRST       (GADGET_ID_TEXT_INPUT_FIRST + 3)
424
425 #define GADGET_ID_ENVELOPE_INFO         (GADGET_ID_TEXT_AREA_FIRST + 0)
426
427 /* selectbox identifiers */
428 #define GADGET_ID_SELECTBOX_FIRST       (GADGET_ID_TEXT_AREA_FIRST + 1)
429
430 #define GADGET_ID_TIME_OR_STEPS         (GADGET_ID_SELECTBOX_FIRST + 0)
431 #define GADGET_ID_CUSTOM_WALK_TO_ACTION (GADGET_ID_SELECTBOX_FIRST + 1)
432 #define GADGET_ID_CUSTOM_EXPLOSION_TYPE (GADGET_ID_SELECTBOX_FIRST + 2)
433 #define GADGET_ID_CUSTOM_DEADLINESS     (GADGET_ID_SELECTBOX_FIRST + 3)
434 #define GADGET_ID_CUSTOM_MOVE_PATTERN   (GADGET_ID_SELECTBOX_FIRST + 4)
435 #define GADGET_ID_CUSTOM_MOVE_DIRECTION (GADGET_ID_SELECTBOX_FIRST + 5)
436 #define GADGET_ID_CUSTOM_MOVE_STEPSIZE  (GADGET_ID_SELECTBOX_FIRST + 6)
437 #define GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE (GADGET_ID_SELECTBOX_FIRST + 7)
438 #define GADGET_ID_CUSTOM_SMASH_TARGETS  (GADGET_ID_SELECTBOX_FIRST + 8)
439 #define GADGET_ID_CUSTOM_SLIPPERY_TYPE  (GADGET_ID_SELECTBOX_FIRST + 9)
440 #define GADGET_ID_CUSTOM_ACCESS_TYPE    (GADGET_ID_SELECTBOX_FIRST + 10)
441 #define GADGET_ID_CUSTOM_ACCESS_LAYER   (GADGET_ID_SELECTBOX_FIRST + 11)
442 #define GADGET_ID_CUSTOM_ACCESS_PROTECTED (GADGET_ID_SELECTBOX_FIRST + 12)
443 #define GADGET_ID_CUSTOM_ACCESS_DIRECTION (GADGET_ID_SELECTBOX_FIRST + 13)
444 #define GADGET_ID_CHANGE_TIME_UNITS     (GADGET_ID_SELECTBOX_FIRST + 14)
445 #define GADGET_ID_CHANGE_DIRECT_ACTION  (GADGET_ID_SELECTBOX_FIRST + 15)
446 #define GADGET_ID_CHANGE_OTHER_ACTION   (GADGET_ID_SELECTBOX_FIRST + 16)
447 #define GADGET_ID_CHANGE_SIDE           (GADGET_ID_SELECTBOX_FIRST + 17)
448 #define GADGET_ID_CHANGE_PLAYER         (GADGET_ID_SELECTBOX_FIRST + 18)
449 #define GADGET_ID_CHANGE_PAGE           (GADGET_ID_SELECTBOX_FIRST + 19)
450 #define GADGET_ID_CHANGE_REPLACE_WHEN   (GADGET_ID_SELECTBOX_FIRST + 20)
451 #define GADGET_ID_SELECT_CHANGE_PAGE    (GADGET_ID_SELECTBOX_FIRST + 21)
452 #define GADGET_ID_GROUP_CHOICE_MODE     (GADGET_ID_SELECTBOX_FIRST + 22)
453
454 /* textbutton identifiers */
455 #define GADGET_ID_TEXTBUTTON_FIRST      (GADGET_ID_SELECTBOX_FIRST + 23)
456
457 #define GADGET_ID_PROPERTIES_INFO       (GADGET_ID_TEXTBUTTON_FIRST + 0)
458 #define GADGET_ID_PROPERTIES_CONFIG     (GADGET_ID_TEXTBUTTON_FIRST + 1)
459 #define GADGET_ID_PROPERTIES_CONFIG_1   (GADGET_ID_TEXTBUTTON_FIRST + 2)
460 #define GADGET_ID_PROPERTIES_CONFIG_2   (GADGET_ID_TEXTBUTTON_FIRST + 3)
461 #define GADGET_ID_PROPERTIES_CHANGE     (GADGET_ID_TEXTBUTTON_FIRST + 4)
462 #define GADGET_ID_SAVE_AS_TEMPLATE      (GADGET_ID_TEXTBUTTON_FIRST + 5)
463 #define GADGET_ID_ADD_CHANGE_PAGE       (GADGET_ID_TEXTBUTTON_FIRST + 6)
464 #define GADGET_ID_DEL_CHANGE_PAGE       (GADGET_ID_TEXTBUTTON_FIRST + 7)
465
466 /* graphicbutton identifiers */
467 #define GADGET_ID_GRAPHICBUTTON_FIRST   (GADGET_ID_TEXTBUTTON_FIRST + 8)
468
469 #define GADGET_ID_PREV_CHANGE_PAGE      (GADGET_ID_GRAPHICBUTTON_FIRST + 0)
470 #define GADGET_ID_NEXT_CHANGE_PAGE      (GADGET_ID_GRAPHICBUTTON_FIRST + 1)
471 #define GADGET_ID_COPY_CHANGE_PAGE      (GADGET_ID_GRAPHICBUTTON_FIRST + 2)
472 #define GADGET_ID_PASTE_CHANGE_PAGE     (GADGET_ID_GRAPHICBUTTON_FIRST + 3)
473
474 /* gadgets for scrolling of drawing area */
475 #define GADGET_ID_SCROLLING_FIRST       (GADGET_ID_GRAPHICBUTTON_FIRST + 4)
476
477 #define GADGET_ID_SCROLL_UP             (GADGET_ID_SCROLLING_FIRST + 0)
478 #define GADGET_ID_SCROLL_DOWN           (GADGET_ID_SCROLLING_FIRST + 1)
479 #define GADGET_ID_SCROLL_LEFT           (GADGET_ID_SCROLLING_FIRST + 2)
480 #define GADGET_ID_SCROLL_RIGHT          (GADGET_ID_SCROLLING_FIRST + 3)
481 #define GADGET_ID_SCROLL_HORIZONTAL     (GADGET_ID_SCROLLING_FIRST + 4)
482 #define GADGET_ID_SCROLL_VERTICAL       (GADGET_ID_SCROLLING_FIRST + 5)
483
484 /* gadgets for scrolling element list */
485 #define GADGET_ID_SCROLLING_LIST_FIRST  (GADGET_ID_SCROLLING_FIRST + 6)
486
487 #define GADGET_ID_SCROLL_LIST_UP        (GADGET_ID_SCROLLING_LIST_FIRST + 0)
488 #define GADGET_ID_SCROLL_LIST_DOWN      (GADGET_ID_SCROLLING_LIST_FIRST + 1)
489 #define GADGET_ID_SCROLL_LIST_VERTICAL  (GADGET_ID_SCROLLING_LIST_FIRST + 2)
490
491 /* checkbuttons/radiobuttons for level/element properties */
492 #define GADGET_ID_CHECKBUTTON_FIRST     (GADGET_ID_SCROLLING_LIST_FIRST + 3)
493
494 #define GADGET_ID_RANDOM_PERCENTAGE     (GADGET_ID_CHECKBUTTON_FIRST + 0)
495 #define GADGET_ID_RANDOM_QUANTITY       (GADGET_ID_CHECKBUTTON_FIRST + 1)
496 #define GADGET_ID_RANDOM_RESTRICTED     (GADGET_ID_CHECKBUTTON_FIRST + 2)
497 #define GADGET_ID_DOUBLE_SPEED          (GADGET_ID_CHECKBUTTON_FIRST + 3)
498 #define GADGET_ID_GRAVITY               (GADGET_ID_CHECKBUTTON_FIRST + 4)
499 #define GADGET_ID_STICK_ELEMENT         (GADGET_ID_CHECKBUTTON_FIRST + 5)
500 #define GADGET_ID_EM_SLIPPERY_GEMS      (GADGET_ID_CHECKBUTTON_FIRST + 6)
501 #define GADGET_ID_USE_SPRING_BUG        (GADGET_ID_CHECKBUTTON_FIRST + 7)
502 #define GADGET_ID_GROW_INTO_DIGGABLE    (GADGET_ID_CHECKBUTTON_FIRST + 8)
503 #define GADGET_ID_BLOCK_LAST_FIELD      (GADGET_ID_CHECKBUTTON_FIRST + 9)
504 #define GADGET_ID_SP_BLOCK_LAST_FIELD   (GADGET_ID_CHECKBUTTON_FIRST + 10)
505 #define GADGET_ID_INSTANT_RELOCATION    (GADGET_ID_CHECKBUTTON_FIRST + 11)
506 #define GADGET_ID_CAN_PASS_TO_WALKABLE  (GADGET_ID_CHECKBUTTON_FIRST + 12)
507 #define GADGET_ID_CAN_FALL_INTO_ACID    (GADGET_ID_CHECKBUTTON_FIRST + 13)
508 #define GADGET_ID_CAN_MOVE_INTO_ACID    (GADGET_ID_CHECKBUTTON_FIRST + 14)
509 #define GADGET_ID_DONT_COLLIDE_WITH     (GADGET_ID_CHECKBUTTON_FIRST + 15)
510 #define GADGET_ID_CUSTOM_INDESTRUCTIBLE (GADGET_ID_CHECKBUTTON_FIRST + 16)
511 #define GADGET_ID_CUSTOM_CAN_EXPLODE    (GADGET_ID_CHECKBUTTON_FIRST + 17)
512 #define GADGET_ID_CUSTOM_EXPLODE_FIRE   (GADGET_ID_CHECKBUTTON_FIRST + 18)
513 #define GADGET_ID_CUSTOM_EXPLODE_SMASH  (GADGET_ID_CHECKBUTTON_FIRST + 19)
514 #define GADGET_ID_CUSTOM_EXPLODE_IMPACT (GADGET_ID_CHECKBUTTON_FIRST + 20)
515 #define GADGET_ID_CUSTOM_WALK_TO_OBJECT (GADGET_ID_CHECKBUTTON_FIRST + 21)
516 #define GADGET_ID_CUSTOM_DEADLY         (GADGET_ID_CHECKBUTTON_FIRST + 22)
517 #define GADGET_ID_CUSTOM_CAN_MOVE       (GADGET_ID_CHECKBUTTON_FIRST + 23)
518 #define GADGET_ID_CUSTOM_CAN_FALL       (GADGET_ID_CHECKBUTTON_FIRST + 24)
519 #define GADGET_ID_CUSTOM_CAN_SMASH      (GADGET_ID_CHECKBUTTON_FIRST + 25)
520 #define GADGET_ID_CUSTOM_SLIPPERY       (GADGET_ID_CHECKBUTTON_FIRST + 26)
521 #define GADGET_ID_CUSTOM_ACCESSIBLE     (GADGET_ID_CHECKBUTTON_FIRST + 27)
522 #define GADGET_ID_CUSTOM_GRAV_REACHABLE (GADGET_ID_CHECKBUTTON_FIRST + 28)
523 #define GADGET_ID_CUSTOM_USE_GRAPHIC    (GADGET_ID_CHECKBUTTON_FIRST + 29)
524 #define GADGET_ID_CUSTOM_USE_TEMPLATE   (GADGET_ID_CHECKBUTTON_FIRST + 30)
525 #define GADGET_ID_CUSTOM_CAN_CHANGE     (GADGET_ID_CHECKBUTTON_FIRST + 31)
526 #define GADGET_ID_CHANGE_USE_CONTENT    (GADGET_ID_CHECKBUTTON_FIRST + 32)
527 #define GADGET_ID_CHANGE_USE_EXPLOSION  (GADGET_ID_CHECKBUTTON_FIRST + 33)
528 #define GADGET_ID_CHANGE_ONLY_COMPLETE  (GADGET_ID_CHECKBUTTON_FIRST + 34)
529 #define GADGET_ID_CHANGE_USE_RANDOM     (GADGET_ID_CHECKBUTTON_FIRST + 35)
530 #define GADGET_ID_CHANGE_DELAY          (GADGET_ID_CHECKBUTTON_FIRST + 36)
531 #define GADGET_ID_CHANGE_BY_DIRECT_ACT  (GADGET_ID_CHECKBUTTON_FIRST + 37)
532 #define GADGET_ID_CHANGE_BY_OTHER_ACT   (GADGET_ID_CHECKBUTTON_FIRST + 38)
533
534 /* gadgets for buttons in element list */
535 #define GADGET_ID_ELEMENTLIST_FIRST     (GADGET_ID_CHECKBUTTON_FIRST + 39)
536 #define GADGET_ID_ELEMENTLIST_LAST      (GADGET_ID_ELEMENTLIST_FIRST +  \
537                                         ED_NUM_ELEMENTLIST_BUTTONS - 1)
538
539 #define NUM_EDITOR_GADGETS              (GADGET_ID_ELEMENTLIST_LAST + 1)
540
541 /* radio button numbers */
542 #define RADIO_NR_NONE                   0
543 #define RADIO_NR_DRAWING_TOOLBOX        1
544 #define RADIO_NR_RANDOM_ELEMENTS        2
545
546 /* values for counter gadgets */
547 #define ED_COUNTER_ID_SELECT_LEVEL      0
548 #define ED_COUNTER_ID_LEVEL_XSIZE       1
549 #define ED_COUNTER_ID_LEVEL_YSIZE       2
550 #define ED_COUNTER_ID_LEVEL_GEMSLIMIT   3
551 #define ED_COUNTER_ID_LEVEL_TIMELIMIT   4
552 #define ED_COUNTER_ID_LEVEL_TIMESCORE   5
553 #define ED_COUNTER_ID_LEVEL_RANDOM      6
554 #define ED_COUNTER_ID_ELEMENT_SCORE     7
555 #define ED_COUNTER_ID_ELEMENT_CONTENT   8
556 #define ED_COUNTER_ID_ENVELOPE_XSIZE    9
557 #define ED_COUNTER_ID_ENVELOPE_YSIZE    10
558 #define ED_COUNTER_ID_CUSTOM_SCORE      11
559 #define ED_COUNTER_ID_CUSTOM_GEMCOUNT   12
560 #define ED_COUNTER_ID_PUSH_DELAY_FIX    13
561 #define ED_COUNTER_ID_PUSH_DELAY_RND    14
562 #define ED_COUNTER_ID_DROP_DELAY_FIX    15
563 #define ED_COUNTER_ID_DROP_DELAY_RND    16
564 #define ED_COUNTER_ID_MOVE_DELAY_FIX    17
565 #define ED_COUNTER_ID_MOVE_DELAY_RND    18
566 #define ED_COUNTER_ID_EXPLOSION_DELAY   19
567 #define ED_COUNTER_ID_IGNITION_DELAY    20
568 #define ED_COUNTER_ID_GROUP_CONTENT     21
569 #define ED_COUNTER_ID_CHANGE_DELAY_FIX  22
570 #define ED_COUNTER_ID_CHANGE_DELAY_RND  23
571 #define ED_COUNTER_ID_CHANGE_CONT_RND   24
572
573 #define ED_NUM_COUNTERBUTTONS           25
574
575 #define ED_COUNTER_ID_LEVEL_FIRST       ED_COUNTER_ID_LEVEL_XSIZE
576 #define ED_COUNTER_ID_LEVEL_LAST        ED_COUNTER_ID_LEVEL_RANDOM
577
578 #define ED_COUNTER_ID_CUSTOM1_FIRST     ED_COUNTER_ID_CUSTOM_SCORE
579 #define ED_COUNTER_ID_CUSTOM1_LAST      ED_COUNTER_ID_DROP_DELAY_RND
580 #define ED_COUNTER_ID_CUSTOM2_FIRST     ED_COUNTER_ID_MOVE_DELAY_FIX
581 #define ED_COUNTER_ID_CUSTOM2_LAST      ED_COUNTER_ID_IGNITION_DELAY
582 #define ED_COUNTER_ID_CUSTOM_FIRST      ED_COUNTER_ID_CUSTOM1_FIRST
583 #define ED_COUNTER_ID_CUSTOM_LAST       ED_COUNTER_ID_CUSTOM2_LAST
584
585 #define ED_COUNTER_ID_CHANGE_FIRST      ED_COUNTER_ID_CHANGE_DELAY_FIX
586 #define ED_COUNTER_ID_CHANGE_LAST       ED_COUNTER_ID_CHANGE_CONT_RND
587
588 /* values for scrollbutton gadgets */
589 #define ED_SCROLLBUTTON_ID_AREA_UP      0
590 #define ED_SCROLLBUTTON_ID_AREA_DOWN    1
591 #define ED_SCROLLBUTTON_ID_AREA_LEFT    2
592 #define ED_SCROLLBUTTON_ID_AREA_RIGHT   3
593 #define ED_SCROLLBUTTON_ID_LIST_UP      4
594 #define ED_SCROLLBUTTON_ID_LIST_DOWN    5
595
596 #define ED_NUM_SCROLLBUTTONS            6
597
598 #define ED_SCROLLBUTTON_ID_AREA_FIRST   ED_SCROLLBUTTON_ID_AREA_UP
599 #define ED_SCROLLBUTTON_ID_AREA_LAST    ED_SCROLLBUTTON_ID_AREA_RIGHT
600
601 /* values for scrollbar gadgets */
602 #define ED_SCROLLBAR_ID_AREA_HORIZONTAL 0
603 #define ED_SCROLLBAR_ID_AREA_VERTICAL   1
604 #define ED_SCROLLBAR_ID_LIST_VERTICAL   2
605
606 #define ED_NUM_SCROLLBARS               3
607
608 #define ED_SCROLLBAR_ID_AREA_FIRST      ED_SCROLLBAR_ID_AREA_HORIZONTAL
609 #define ED_SCROLLBAR_ID_AREA_LAST       ED_SCROLLBAR_ID_AREA_VERTICAL
610
611 /* values for text input gadgets */
612 #define ED_TEXTINPUT_ID_LEVEL_NAME      0
613 #define ED_TEXTINPUT_ID_LEVEL_AUTHOR    1
614 #define ED_TEXTINPUT_ID_ELEMENT_NAME    2
615
616 #define ED_NUM_TEXTINPUT                3
617
618 #define ED_TEXTINPUT_ID_LEVEL_FIRST     ED_TEXTINPUT_ID_LEVEL_NAME
619 #define ED_TEXTINPUT_ID_LEVEL_LAST      ED_TEXTINPUT_ID_LEVEL_AUTHOR
620
621 /* values for text area gadgets */
622 #define ED_TEXTAREA_ID_ENVELOPE_INFO    0
623
624 #define ED_NUM_TEXTAREAS                        1
625
626 #define ED_TEXTAREA_ID_LEVEL_FIRST      ED_TEXTAREA_ID_ENVELOPE
627 #define ED_TEXTAREA_ID_LEVEL_LAST       ED_TEXTAREA_ID_ENVELOPE
628
629 /* values for selectbox gadgets */
630 #define ED_SELECTBOX_ID_TIME_OR_STEPS           0
631 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE      1
632 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_LAYER     2
633 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_PROTECTED 3
634 #define ED_SELECTBOX_ID_CUSTOM_ACCESS_DIRECTION 4
635 #define ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION   5
636 #define ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN     6
637 #define ED_SELECTBOX_ID_CUSTOM_MOVE_DIRECTION   7
638 #define ED_SELECTBOX_ID_CUSTOM_MOVE_STEPSIZE    8
639 #define ED_SELECTBOX_ID_CUSTOM_MOVE_LEAVE_TYPE  9
640 #define ED_SELECTBOX_ID_CUSTOM_SMASH_TARGETS    10
641 #define ED_SELECTBOX_ID_CUSTOM_SLIPPERY_TYPE    11
642 #define ED_SELECTBOX_ID_CUSTOM_DEADLINESS       12
643 #define ED_SELECTBOX_ID_CUSTOM_EXPLOSION_TYPE   13
644 #define ED_SELECTBOX_ID_CHANGE_TIME_UNITS       14
645 #define ED_SELECTBOX_ID_CHANGE_DIRECT_ACTION    15
646 #define ED_SELECTBOX_ID_CHANGE_OTHER_ACTION     16
647 #define ED_SELECTBOX_ID_CHANGE_SIDE             17
648 #define ED_SELECTBOX_ID_CHANGE_PLAYER           18
649 #define ED_SELECTBOX_ID_CHANGE_PAGE             19
650 #define ED_SELECTBOX_ID_CHANGE_REPLACE_WHEN     20
651 #define ED_SELECTBOX_ID_SELECT_CHANGE_PAGE      21
652 #define ED_SELECTBOX_ID_GROUP_CHOICE_MODE       22
653
654 #define ED_NUM_SELECTBOX                        23
655
656 #define ED_SELECTBOX_ID_LEVEL_FIRST     ED_SELECTBOX_ID_TIME_OR_STEPS
657 #define ED_SELECTBOX_ID_LEVEL_LAST      ED_SELECTBOX_ID_TIME_OR_STEPS
658
659 #define ED_SELECTBOX_ID_CUSTOM1_FIRST   ED_SELECTBOX_ID_CUSTOM_ACCESS_TYPE
660 #define ED_SELECTBOX_ID_CUSTOM1_LAST    ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION
661 #define ED_SELECTBOX_ID_CUSTOM2_FIRST   ED_SELECTBOX_ID_CUSTOM_MOVE_PATTERN
662 #define ED_SELECTBOX_ID_CUSTOM2_LAST    ED_SELECTBOX_ID_CUSTOM_EXPLOSION_TYPE
663 #define ED_SELECTBOX_ID_CUSTOM_FIRST    ED_SELECTBOX_ID_CUSTOM1_FIRST
664 #define ED_SELECTBOX_ID_CUSTOM_LAST     ED_SELECTBOX_ID_CUSTOM2_LAST
665
666 #define ED_SELECTBOX_ID_CHANGE_FIRST    ED_SELECTBOX_ID_CHANGE_TIME_UNITS
667 #define ED_SELECTBOX_ID_CHANGE_LAST     ED_SELECTBOX_ID_SELECT_CHANGE_PAGE
668
669 /* values for textbutton gadgets */
670 #define ED_TEXTBUTTON_ID_PROPERTIES_INFO        0
671 #define ED_TEXTBUTTON_ID_PROPERTIES_CONFIG      1
672 #define ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_1    2
673 #define ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2    3
674 #define ED_TEXTBUTTON_ID_PROPERTIES_CHANGE      4
675 #define ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE       5
676 #define ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE        6
677 #define ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE        7
678
679 #define ED_NUM_TEXTBUTTONS                      8
680
681 #define ED_TEXTBUTTON_ID_PROPERTIES_FIRST ED_TEXTBUTTON_ID_PROPERTIES_INFO
682 #define ED_TEXTBUTTON_ID_PROPERTIES_LAST  ED_TEXTBUTTON_ID_PROPERTIES_CHANGE
683
684 #define ED_TEXTBUTTON_ID_CHANGE_FIRST   ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE
685 #define ED_TEXTBUTTON_ID_CHANGE_LAST    ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE
686
687 /* values for graphicbutton gadgets */
688 #define ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE    0
689 #define ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE    1
690 #define ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE    2
691 #define ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE   3
692
693 #define ED_NUM_GRAPHICBUTTONS                   4
694
695 #define ED_GRAPHICBUTTON_ID_CHANGE_FIRST  ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE
696 #define ED_GRAPHICBUTTON_ID_CHANGE_LAST   ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE
697
698 /* values for checkbutton gadgets */
699 #define ED_CHECKBUTTON_ID_DOUBLE_SPEED          0
700 #define ED_CHECKBUTTON_ID_GRAVITY               1
701 #define ED_CHECKBUTTON_ID_RANDOM_RESTRICTED     2
702 #define ED_CHECKBUTTON_ID_STICK_ELEMENT         3
703 #define ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS      4
704 #define ED_CHECKBUTTON_ID_USE_SPRING_BUG        5
705 #define ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE    6
706 #define ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD      7
707 #define ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD   8
708 #define ED_CHECKBUTTON_ID_INSTANT_RELOCATION    9
709 #define ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE  10
710 #define ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID    11
711 #define ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID    12
712 #define ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH     13
713 #define ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC    14
714 #define ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE   15
715 #define ED_CHECKBUTTON_ID_CUSTOM_ACCESSIBLE     16
716 #define ED_CHECKBUTTON_ID_CUSTOM_GRAV_REACHABLE 17
717 #define ED_CHECKBUTTON_ID_CUSTOM_WALK_TO_OBJECT 18
718 #define ED_CHECKBUTTON_ID_CUSTOM_INDESTRUCTIBLE 19
719 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_MOVE       20
720 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_FALL       21
721 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_SMASH      22
722 #define ED_CHECKBUTTON_ID_CUSTOM_SLIPPERY       23
723 #define ED_CHECKBUTTON_ID_CUSTOM_DEADLY         24
724 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_EXPLODE    25
725 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_FIRE   26
726 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_SMASH  27
727 #define ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT 28
728 #define ED_CHECKBUTTON_ID_CUSTOM_CAN_CHANGE     29
729 #define ED_CHECKBUTTON_ID_CHANGE_DELAY          30
730 #define ED_CHECKBUTTON_ID_CHANGE_BY_DIRECT_ACT  31
731 #define ED_CHECKBUTTON_ID_CHANGE_BY_OTHER_ACT   32
732 #define ED_CHECKBUTTON_ID_CHANGE_USE_EXPLOSION  33
733 #define ED_CHECKBUTTON_ID_CHANGE_USE_CONTENT    34
734 #define ED_CHECKBUTTON_ID_CHANGE_ONLY_COMPLETE  35
735 #define ED_CHECKBUTTON_ID_CHANGE_USE_RANDOM     36
736
737 #define ED_NUM_CHECKBUTTONS                     37
738
739 #define ED_CHECKBUTTON_ID_LEVEL_FIRST   ED_CHECKBUTTON_ID_DOUBLE_SPEED
740 #define ED_CHECKBUTTON_ID_LEVEL_LAST    ED_CHECKBUTTON_ID_RANDOM_RESTRICTED
741
742 #define ED_CHECKBUTTON_ID_CUSTOM1_FIRST ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC
743 #define ED_CHECKBUTTON_ID_CUSTOM1_LAST  ED_CHECKBUTTON_ID_CUSTOM_INDESTRUCTIBLE
744 #define ED_CHECKBUTTON_ID_CUSTOM2_FIRST ED_CHECKBUTTON_ID_CUSTOM_CAN_MOVE
745 #define ED_CHECKBUTTON_ID_CUSTOM2_LAST  ED_CHECKBUTTON_ID_CUSTOM_EXPLODE_IMPACT
746 #define ED_CHECKBUTTON_ID_CUSTOM_FIRST  ED_CHECKBUTTON_ID_CUSTOM1_FIRST
747 #define ED_CHECKBUTTON_ID_CUSTOM_LAST   ED_CHECKBUTTON_ID_CUSTOM2_LAST
748
749 #define ED_CHECKBUTTON_ID_CHANGE_FIRST  ED_CHECKBUTTON_ID_CUSTOM_CAN_CHANGE
750 #define ED_CHECKBUTTON_ID_CHANGE_LAST   ED_CHECKBUTTON_ID_CHANGE_USE_RANDOM
751
752 /* values for radiobutton gadgets */
753 #define ED_RADIOBUTTON_ID_PERCENTAGE    0
754 #define ED_RADIOBUTTON_ID_QUANTITY      1
755
756 #define ED_NUM_RADIOBUTTONS             2
757
758 #define ED_RADIOBUTTON_ID_LEVEL_FIRST   ED_RADIOBUTTON_ID_PERCENTAGE
759 #define ED_RADIOBUTTON_ID_LEVEL_LAST    ED_RADIOBUTTON_ID_QUANTITY
760
761 /* values for drawing area gadgets */
762 #define ED_DRAWING_ID_DRAWING_LEVEL             0
763 #define ED_DRAWING_ID_ELEMENT_CONTENT_0         1
764 #define ED_DRAWING_ID_ELEMENT_CONTENT_1         2
765 #define ED_DRAWING_ID_ELEMENT_CONTENT_2         3
766 #define ED_DRAWING_ID_ELEMENT_CONTENT_3         4
767 #define ED_DRAWING_ID_ELEMENT_CONTENT_4         5
768 #define ED_DRAWING_ID_ELEMENT_CONTENT_5         6
769 #define ED_DRAWING_ID_ELEMENT_CONTENT_6         7
770 #define ED_DRAWING_ID_ELEMENT_CONTENT_7         8
771 #define ED_DRAWING_ID_AMOEBA_CONTENT            9
772 #define ED_DRAWING_ID_CUSTOM_GRAPHIC            10
773 #define ED_DRAWING_ID_CUSTOM_CONTENT            11
774 #define ED_DRAWING_ID_CUSTOM_MOVE_ENTER         12
775 #define ED_DRAWING_ID_CUSTOM_MOVE_LEAVE         13
776 #define ED_DRAWING_ID_CUSTOM_CHANGE_TARGET      14
777 #define ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT     15
778 #define ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER     16
779 #define ED_DRAWING_ID_GROUP_CONTENT             17
780 #define ED_DRAWING_ID_RANDOM_BACKGROUND         18
781
782 #define ED_NUM_DRAWING_AREAS                    19
783
784
785 /*
786   -----------------------------------------------------------------------------
787   some internally used definitions
788   -----------------------------------------------------------------------------
789 */
790
791 /* values for CopyLevelToUndoBuffer() */
792 #define UNDO_IMMEDIATE                  0
793 #define UNDO_ACCUMULATE                 1
794
795 /* values for scrollbars */
796 #define ED_SCROLL_NO                    0
797 #define ED_SCROLL_LEFT                  1
798 #define ED_SCROLL_RIGHT                 2
799 #define ED_SCROLL_UP                    4
800 #define ED_SCROLL_DOWN                  8
801
802 /* screens in the level editor */
803 #define ED_MODE_DRAWING                 0
804 #define ED_MODE_INFO                    1
805 #define ED_MODE_PROPERTIES              2
806
807 /* sub-screens in the element properties section */
808 #define ED_MODE_PROPERTIES_INFO         ED_TEXTBUTTON_ID_PROPERTIES_INFO
809 #define ED_MODE_PROPERTIES_CONFIG       ED_TEXTBUTTON_ID_PROPERTIES_CONFIG
810 #define ED_MODE_PROPERTIES_CONFIG_1     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_1
811 #define ED_MODE_PROPERTIES_CONFIG_2     ED_TEXTBUTTON_ID_PROPERTIES_CONFIG_2
812 #define ED_MODE_PROPERTIES_CHANGE       ED_TEXTBUTTON_ID_PROPERTIES_CHANGE
813
814 /* how many steps can be cancelled */
815 #define NUM_UNDO_STEPS                  (10 + 1)
816
817 /* values for elements with score for certain actions */
818 #define MIN_SCORE                       0
819 #define MAX_SCORE                       255
820
821 /* values for elements with count for collecting */
822 #define MIN_COLLECT_COUNT               0
823 #define MAX_COLLECT_COUNT               100
824
825 /* values for random placement */
826 #define RANDOM_USE_PERCENTAGE           0
827 #define RANDOM_USE_QUANTITY             1
828
829 /* maximal size of level editor drawing area */
830 #define MAX_ED_FIELDX           (2 * SCR_FIELDX)
831 #define MAX_ED_FIELDY           (2 * SCR_FIELDY - 1)
832
833
834 /*
835   -----------------------------------------------------------------------------
836   some internally used data structure definitions
837   -----------------------------------------------------------------------------
838 */
839
840 static struct
841 {
842   char shortcut;
843   char *text;
844 } control_info[ED_NUM_CTRL_BUTTONS] =
845 {
846   { 's',        "draw single items"                     },
847   { 'd',        "draw connected items"                  },
848   { 'l',        "draw lines"                            },
849   { 'a',        "draw arcs"                             },
850   { 'r',        "draw outline rectangles"               },
851   { 'R',        "draw filled rectangles"                },
852   { '\0',       "wrap (rotate) level up"                },
853   { 't',        "enter text elements"                   },
854   { 'f',        "flood fill"                            },
855   { '\0',       "wrap (rotate) level left"              },
856   { '?',        "properties of drawing element"         },
857   { '\0',       "wrap (rotate) level right"             },
858   { '\0',       "random element placement"              },
859   { 'b',        "grab brush"                            },
860   { '\0',       "wrap (rotate) level down"              },
861   { ',',        "pick drawing element"                  },
862
863   { 'U',        "undo last operation"                   },
864   { 'I',        "level properties"                      },
865   { 'S',        "save level"                            },
866   { 'C',        "clear level"                           },
867   { 'T',        "test level"                            },
868   { 'E',        "exit level editor"                     },
869
870   { '\0',       "copy settings from other element"      },
871   { '\0',       "copy settings to other element"        },
872   { '\0',       "exchange element with other element"   },
873
874   { '\0',       "copy settings from this element"       },
875   { '\0',       "paste settings to this element"        },
876 };
877
878 static int random_placement_value = 10;
879 static int random_placement_method = RANDOM_USE_QUANTITY;
880 static int random_placement_background_element = EL_SAND;
881 static boolean random_placement_background_restricted = FALSE;
882 static boolean stick_element_properties_window = FALSE;
883 static boolean custom_element_properties[NUM_ELEMENT_PROPERTIES];
884 static boolean custom_element_change_events[NUM_CHANGE_EVENTS];
885 static struct ElementChangeInfo custom_element_change;
886 static struct ElementGroupInfo group_element_info;
887 static struct ElementInfo custom_element;
888
889 static struct
890 {
891   int x, y;
892   int min_value, max_value;
893   int gadget_id_down, gadget_id_up;
894   int gadget_id_text;
895   int gadget_id_align;
896   int *value;
897   char *text_above, *text_left, *text_right;
898 } counterbutton_info[ED_NUM_COUNTERBUTTONS] =
899 {
900   /* ---------- level and editor settings ---------------------------------- */
901
902   {
903     DX + 5 - SX,                        DY + 3 - SY,
904     1,                                  100,
905     GADGET_ID_SELECT_LEVEL_DOWN,        GADGET_ID_SELECT_LEVEL_UP,
906     GADGET_ID_SELECT_LEVEL_TEXT,        GADGET_ID_NONE,
907     &level_nr,
908     NULL,                               NULL, NULL
909   },
910   {
911     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(2),
912     MIN_LEV_FIELDX,                     MAX_LEV_FIELDX,
913     GADGET_ID_LEVEL_XSIZE_DOWN,         GADGET_ID_LEVEL_XSIZE_UP,
914     GADGET_ID_LEVEL_XSIZE_TEXT,         GADGET_ID_NONE,
915     &level.fieldx,
916     "playfield size:",                  NULL, "width",
917   },
918   {
919     -1,                                 ED_COUNTER_YPOS(2),
920     MIN_LEV_FIELDY,                     MAX_LEV_FIELDY,
921     GADGET_ID_LEVEL_YSIZE_DOWN,         GADGET_ID_LEVEL_YSIZE_UP,
922     GADGET_ID_LEVEL_YSIZE_TEXT,         GADGET_ID_LEVEL_XSIZE_UP,
923     &level.fieldy,
924     NULL,                               " ", "height",
925   },
926   {
927     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(3),
928     0,                                  999,
929     GADGET_ID_LEVEL_GEMSLIMIT_DOWN,     GADGET_ID_LEVEL_GEMSLIMIT_UP,
930     GADGET_ID_LEVEL_GEMSLIMIT_TEXT,     GADGET_ID_NONE,
931     &level.gems_needed,
932     "number of gems to collect:",       NULL, NULL
933   },
934   {
935     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(4),
936     0,                                  9999,
937     GADGET_ID_LEVEL_TIMELIMIT_DOWN,     GADGET_ID_LEVEL_TIMELIMIT_UP,
938     GADGET_ID_LEVEL_TIMELIMIT_TEXT,     GADGET_ID_NONE,
939     &level.time,
940     "time or step limit to solve level:", NULL, NULL
941   },
942   {
943     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(5),
944     0,                                  255,
945     GADGET_ID_LEVEL_TIMESCORE_DOWN,     GADGET_ID_LEVEL_TIMESCORE_UP,
946     GADGET_ID_LEVEL_TIMESCORE_TEXT,     GADGET_ID_NONE,
947     &level.score[SC_TIME_BONUS],
948     "score for each 10 sec/steps left:", NULL, NULL
949   },
950   {
951     ED_SETTINGS_XPOS(0),                ED_COUNTER2_YPOS(8),
952     1,                                  100,
953     GADGET_ID_LEVEL_RANDOM_DOWN,        GADGET_ID_LEVEL_RANDOM_UP,
954     GADGET_ID_LEVEL_RANDOM_TEXT,        GADGET_ID_NONE,
955     &random_placement_value,
956     "random element placement:",        NULL, "in"
957   },
958
959   /* ---------- element settings: configure (various elements) ------------- */
960
961   {
962     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(0),
963     MIN_SCORE,                          MAX_SCORE,
964     GADGET_ID_ELEMENT_SCORE_DOWN,       GADGET_ID_ELEMENT_SCORE_UP,
965     GADGET_ID_ELEMENT_SCORE_TEXT,       GADGET_ID_NONE,
966     NULL,                               /* will be set when used */
967     NULL,                               NULL, NULL
968   },
969   {
970     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(3),
971     MIN_ELEMENT_CONTENTS,               MAX_ELEMENT_CONTENTS,
972     GADGET_ID_ELEMENT_CONTENT_DOWN,     GADGET_ID_ELEMENT_CONTENT_UP,
973     GADGET_ID_ELEMENT_CONTENT_TEXT,     GADGET_ID_NONE,
974     &level.num_yamyam_contents,
975     NULL,                               NULL, "number of content areas"
976   },
977   {
978     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(0),
979     MIN_ENVELOPE_XSIZE,                 MAX_ENVELOPE_XSIZE,
980     GADGET_ID_ENVELOPE_XSIZE_DOWN,      GADGET_ID_ENVELOPE_XSIZE_UP,
981     GADGET_ID_ENVELOPE_XSIZE_TEXT,      GADGET_ID_NONE,
982     NULL,
983     NULL,                               NULL, "width",
984   },
985   {
986     -1,                                 ED_SETTINGS_YPOS(0),
987     MIN_ENVELOPE_YSIZE,                 MAX_ENVELOPE_YSIZE,
988     GADGET_ID_ENVELOPE_YSIZE_DOWN,      GADGET_ID_ENVELOPE_YSIZE_UP,
989     GADGET_ID_ENVELOPE_YSIZE_TEXT,      GADGET_ID_ENVELOPE_XSIZE_UP,
990     NULL,
991     NULL,                               " ", "height",
992   },
993
994   /* ---------- element settings: configure 1 (custom elements) ------------ */
995
996   {
997     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(6),
998     MIN_SCORE,                          MAX_SCORE,
999     GADGET_ID_CUSTOM_SCORE_DOWN,        GADGET_ID_CUSTOM_SCORE_UP,
1000     GADGET_ID_CUSTOM_SCORE_TEXT,        GADGET_ID_NONE,
1001     &custom_element.collect_score,
1002     NULL,                               "score", " "
1003   },
1004   {
1005     -1,                                 ED_SETTINGS_YPOS(6),
1006     MIN_COLLECT_COUNT,                  MAX_COLLECT_COUNT,
1007     GADGET_ID_CUSTOM_GEMCOUNT_DOWN,     GADGET_ID_CUSTOM_GEMCOUNT_UP,
1008     GADGET_ID_CUSTOM_GEMCOUNT_TEXT,     GADGET_ID_CUSTOM_SCORE_UP,
1009     &custom_element.collect_count,
1010     NULL,                               "count", NULL
1011   },
1012   {
1013     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(7),
1014     0,                                  255,
1015     GADGET_ID_PUSH_DELAY_FIX_DOWN,      GADGET_ID_PUSH_DELAY_FIX_UP,
1016     GADGET_ID_PUSH_DELAY_FIX_TEXT,      GADGET_ID_NONE,
1017     &custom_element.push_delay_fixed,
1018     NULL,                               "push delay", NULL
1019   },
1020   {
1021     -1,                                 ED_SETTINGS_YPOS(7),
1022     0,                                  255,
1023     GADGET_ID_PUSH_DELAY_RND_DOWN,      GADGET_ID_PUSH_DELAY_RND_UP,
1024     GADGET_ID_PUSH_DELAY_RND_TEXT,      GADGET_ID_PUSH_DELAY_FIX_UP,
1025     &custom_element.push_delay_random,
1026     NULL,                               "+random", NULL
1027   },
1028   {
1029     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(8),
1030     0,                                  255,
1031     GADGET_ID_DROP_DELAY_FIX_DOWN,      GADGET_ID_DROP_DELAY_FIX_UP,
1032     GADGET_ID_DROP_DELAY_FIX_TEXT,      GADGET_ID_NONE,
1033     &custom_element.drop_delay_fixed,
1034     NULL,                               "drop delay", NULL
1035   },
1036   {
1037     -1,                                 ED_SETTINGS_YPOS(8),
1038     0,                                  255,
1039     GADGET_ID_DROP_DELAY_RND_DOWN,      GADGET_ID_DROP_DELAY_RND_UP,
1040     GADGET_ID_DROP_DELAY_RND_TEXT,      GADGET_ID_DROP_DELAY_FIX_UP,
1041     &custom_element.drop_delay_random,
1042     NULL,                               "+random", NULL
1043   },
1044
1045   /* ---------- element settings: configure 2 (custom elements) ------------ */
1046
1047   {
1048     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(5),
1049     0,                                  999,
1050     GADGET_ID_MOVE_DELAY_FIX_DOWN,      GADGET_ID_MOVE_DELAY_FIX_UP,
1051     GADGET_ID_MOVE_DELAY_FIX_TEXT,      GADGET_ID_NONE,
1052     &custom_element.move_delay_fixed,
1053     NULL,                               "move delay", NULL
1054   },
1055   {
1056     -1,                                 ED_SETTINGS_YPOS(5),
1057     0,                                  999,
1058     GADGET_ID_MOVE_DELAY_RND_DOWN,      GADGET_ID_MOVE_DELAY_RND_UP,
1059     GADGET_ID_MOVE_DELAY_RND_TEXT,      GADGET_ID_MOVE_DELAY_FIX_UP,
1060     &custom_element.move_delay_random,
1061     NULL,                               "+random", NULL
1062   },
1063   {
1064     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(12),
1065     0,                                  255,
1066     GADGET_ID_EXPLOSION_DELAY_DOWN,     GADGET_ID_EXPLOSION_DELAY_UP,
1067     GADGET_ID_EXPLOSION_DELAY_TEXT,     GADGET_ID_NONE,
1068     &custom_element.explosion_delay,
1069     NULL,                               "explosion delay", NULL
1070   },
1071   {
1072     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(13),
1073     0,                                  255,
1074     GADGET_ID_IGNITION_DELAY_DOWN,      GADGET_ID_IGNITION_DELAY_UP,
1075     GADGET_ID_IGNITION_DELAY_TEXT,      GADGET_ID_NONE,
1076     &custom_element.ignition_delay,
1077     NULL,                               "ignition delay", "(by fire)"
1078   },
1079
1080   /* ---------- element settings: configure (group elements) --------------- */
1081
1082   {
1083     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(5),
1084     MIN_ELEMENTS_IN_GROUP,              MAX_ELEMENTS_IN_GROUP,
1085     GADGET_ID_GROUP_CONTENT_DOWN,       GADGET_ID_GROUP_CONTENT_UP,
1086     GADGET_ID_GROUP_CONTENT_TEXT,       GADGET_ID_NONE,
1087     &group_element_info.num_elements,
1088     NULL,                               NULL, "number of elements in group"
1089   },
1090
1091   /* ---------- element settings: advanced (custom elements) --------------- */
1092
1093   {
1094     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(2),
1095     0,                                  999,
1096     GADGET_ID_CHANGE_DELAY_FIX_DOWN,    GADGET_ID_CHANGE_DELAY_FIX_UP,
1097     GADGET_ID_CHANGE_DELAY_FIX_TEXT,    GADGET_ID_NONE,
1098     &custom_element_change.delay_fixed,
1099     NULL,                               "delay", NULL,
1100   },
1101   {
1102     -1,                                 ED_SETTINGS_YPOS(2),
1103     0,                                  999,
1104     GADGET_ID_CHANGE_DELAY_RND_DOWN,    GADGET_ID_CHANGE_DELAY_RND_UP,
1105     GADGET_ID_CHANGE_DELAY_RND_TEXT,    GADGET_ID_CHANGE_DELAY_FIX_UP,
1106     &custom_element_change.delay_random,
1107     NULL,                               "+random", NULL
1108   },
1109   {
1110     ED_SETTINGS_XPOS(3),                ED_SETTINGS_YPOS(12),
1111     0,                                  100,
1112     GADGET_ID_CHANGE_CONT_RND_DOWN,     GADGET_ID_CHANGE_CONT_RND_UP,
1113     GADGET_ID_CHANGE_CONT_RND_TEXT,     GADGET_ID_NONE,
1114     &custom_element_change.random_percentage,
1115     NULL,                               "use random replace:", "%"
1116   },
1117 };
1118
1119 static struct
1120 {
1121   int x, y;
1122   int gadget_id;
1123   int size;
1124   char *value;
1125   char *text_above, *infotext;
1126 } textinput_info[ED_NUM_TEXTINPUT] =
1127 {
1128   {
1129     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(0),
1130     GADGET_ID_LEVEL_NAME,
1131     MAX_LEVEL_NAME_LEN,
1132     level.name,
1133     "Title:", "Title"
1134   },
1135   {
1136     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(1),
1137     GADGET_ID_LEVEL_AUTHOR,
1138     MAX_LEVEL_AUTHOR_LEN,
1139     level.author,
1140     "Author:", "Author"
1141   },
1142   {
1143     5 * MINI_TILEX - 2,                 5 * MINI_TILEY - ED_BORDER_SIZE + 1,
1144     GADGET_ID_ELEMENT_NAME,
1145     MAX_ELEMENT_NAME_LEN - 2,           /* currently 2 chars less editable */
1146     custom_element.description,
1147     NULL, "Element name"
1148   }
1149 };
1150
1151 static struct
1152 {
1153   int x, y;
1154   int gadget_id;
1155   int xsize, ysize;
1156   char *value;
1157   char *text_above, *infotext;
1158 } textarea_info[ED_NUM_TEXTAREAS] =
1159 {
1160   {
1161     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(2),
1162     GADGET_ID_ENVELOPE_INFO,
1163     MAX_ENVELOPE_XSIZE, MAX_ENVELOPE_YSIZE,
1164     NULL,
1165     "Envelope Info:", "Envelope Info"
1166   }
1167 };
1168
1169 static struct ValueTextInfo options_time_or_steps[] =
1170 {
1171   { 0,                          "seconds"                       },
1172   { 1,                          "steps"                         },
1173
1174   { -1,                         NULL                            }
1175 };
1176
1177 static struct ValueTextInfo options_access_type[] =
1178 {
1179   { EP_WALKABLE,                "walkable"                      },
1180   { EP_PASSABLE,                "passable"                      },
1181
1182   { -1,                         NULL                            }
1183 };
1184
1185 static struct ValueTextInfo options_access_layer[] =
1186 {
1187   { EP_ACCESSIBLE_OVER,         "over"                          },
1188   { EP_ACCESSIBLE_INSIDE,       "inside"                        },
1189   { EP_ACCESSIBLE_UNDER,        "under"                         },
1190
1191   { -1,                         NULL                            }
1192 };
1193
1194 static struct ValueTextInfo options_access_protected[] =
1195 {
1196   { 0,                          "unprotected"                   },
1197   { 1,                          "protected"                     },
1198
1199   { -1,                         NULL                            }
1200 };
1201
1202 static struct ValueTextInfo options_access_direction[] =
1203 {
1204   { MV_LEFT,                    "left"                          },
1205   { MV_RIGHT,                   "right"                         },
1206   { MV_UP,                      "up"                            },
1207   { MV_DOWN,                    "down"                          },
1208   { MV_LEFT  | MV_UP,           "left + up"                     },
1209   { MV_LEFT  | MV_DOWN,         "left + down"                   },
1210   { MV_RIGHT | MV_UP,           "right + up"                    },
1211   { MV_RIGHT | MV_DOWN,         "right + down"                  },
1212   { MV_HORIZONTAL,              "horizontal"                    },
1213   { MV_VERTICAL,                "vertical"                      },
1214   { MV_HORIZONTAL | MV_UP,      "horizontal + up"               },
1215   { MV_HORIZONTAL | MV_DOWN,    "horizontal + down"             },
1216   { MV_VERTICAL   | MV_LEFT,    "vertical + left"               },
1217   { MV_VERTICAL   | MV_RIGHT,   "vertical + right"              },
1218   { MV_ALL_DIRECTIONS,          "all directions"                },
1219
1220   { -1,                         NULL                            }
1221 };
1222
1223 static struct ValueTextInfo options_walk_to_action[] =
1224 {
1225   { EP_DIGGABLE,                "diggable"                      },
1226   { EP_COLLECTIBLE_ONLY,        "collectible"                   },
1227   { EP_DROPPABLE,               "collectible & droppable"       },
1228   { EP_THROWABLE,               "collectible & throwable"       },
1229   { EP_PUSHABLE,                "pushable"                      },
1230
1231   { -1,                         NULL                            }
1232 };
1233
1234 static struct ValueTextInfo options_move_pattern[] =
1235 {
1236   { MV_LEFT,                    "left"                          },
1237   { MV_RIGHT,                   "right"                         },
1238   { MV_UP,                      "up"                            },
1239   { MV_DOWN,                    "down"                          },
1240   { MV_HORIZONTAL,              "horizontal"                    },
1241   { MV_VERTICAL,                "vertical"                      },
1242   { MV_ALL_DIRECTIONS,          "all directions"                },
1243   { MV_TOWARDS_PLAYER,          "towards player"                },
1244   { MV_AWAY_FROM_PLAYER,        "away from player"              },
1245   { MV_ALONG_LEFT_SIDE,         "along left side"               },
1246   { MV_ALONG_RIGHT_SIDE,        "along right side"              },
1247   { MV_TURNING_LEFT,            "turning left"                  },
1248   { MV_TURNING_RIGHT,           "turning right"                 },
1249   { MV_TURNING_LEFT_RIGHT,      "turning left, right"           },
1250   { MV_TURNING_RIGHT_LEFT,      "turning right, left"           },
1251   { MV_TURNING_RANDOM,          "turning random"                },
1252   { MV_MAZE_RUNNER,             "maze runner style"             },
1253   { MV_MAZE_HUNTER,             "maze hunter style"             },
1254   { MV_WHEN_PUSHED,             "when pushed"                   },
1255   { MV_WHEN_DROPPED,            "when dropped/thrown"           },
1256
1257   { -1,                         NULL                            }
1258 };
1259
1260 static struct ValueTextInfo options_move_direction[] =
1261 {
1262   { MV_START_AUTOMATIC,         "automatic"                     },
1263   { MV_START_LEFT,              "left"                          },
1264   { MV_START_RIGHT,             "right"                         },
1265   { MV_START_UP,                "up"                            },
1266   { MV_START_DOWN,              "down"                          },
1267   { MV_START_RANDOM,            "random"                        },
1268   { MV_START_PREVIOUS,          "previous"                      },
1269
1270   { -1,                         NULL                            }
1271 };
1272
1273 static struct ValueTextInfo options_move_stepsize[] =
1274 {
1275   { 1,                          "very slow"                     },
1276   { 2,                          "slow"                          },
1277   { 4,                          "normal"                        },
1278   { 8,                          "fast"                          },
1279   { 16,                         "very fast"                     },
1280 #if 1
1281   { 32,                         "even faster"                   },
1282 #endif
1283
1284   { -1,                         NULL                            }
1285 };
1286
1287 static struct ValueTextInfo options_move_leave_type[] =
1288 {
1289   { LEAVE_TYPE_UNLIMITED,       "leave behind"                  },
1290   { LEAVE_TYPE_LIMITED,         "change it to"                  },
1291
1292   { -1,                         NULL                            }
1293 };
1294
1295 static struct ValueTextInfo options_smash_targets[] =
1296 {
1297   { EP_CAN_SMASH_PLAYER,        "player"                        },
1298 #if 0
1299   { EP_CAN_SMASH_ENEMIES,       "enemies"                       },
1300 #endif
1301   { EP_CAN_SMASH_EVERYTHING,    "everything"                    },
1302
1303   { -1,                         NULL                            }
1304 };
1305
1306 static struct ValueTextInfo options_slippery_type[] =
1307 {
1308   { SLIPPERY_ANY_RANDOM,        "random"                        },
1309   { SLIPPERY_ANY_LEFT_RIGHT,    "left, right"                   },
1310   { SLIPPERY_ANY_RIGHT_LEFT,    "right, left"                   },
1311   { SLIPPERY_ONLY_LEFT,         "only left"                     },
1312   { SLIPPERY_ONLY_RIGHT,        "only right"                    },
1313
1314   { -1,                         NULL                            }
1315 };
1316
1317 static struct ValueTextInfo options_deadliness[] =
1318 {
1319   { EP_DONT_RUN_INTO,           "running into"                  },
1320   { EP_DONT_COLLIDE_WITH,       "colliding with"                },
1321   { EP_DONT_TOUCH,              "touching"                      },
1322
1323   { -1,                         NULL                            }
1324 };
1325
1326 static struct ValueTextInfo options_explosion_type[] =
1327 {
1328   { EXPLODES_3X3,               "3x3"                           },
1329   { EXPLODES_CROSS,             "3+3"                           },
1330   { EXPLODES_1X1,               "1x1"                           },
1331 #if 0
1332   { EP_INDESTRUCTIBLE,          "indestructible"                },
1333 #endif
1334
1335   { -1,                         NULL                            }
1336 };
1337
1338 static struct ValueTextInfo options_time_units[] =
1339 {
1340   { 1,                          "frames"                        },
1341   { FRAMES_PER_SECOND,          "seconds"                       },
1342
1343   { -1,                         NULL                            }
1344 };
1345
1346 static struct ValueTextInfo options_change_direct_action[] =
1347 {
1348   { CE_TOUCHED_BY_PLAYER,       "touched by player"             },
1349   { CE_PRESSED_BY_PLAYER,       "pressed by player"             },
1350   { CE_PUSHED_BY_PLAYER,        "pushed by player"              },
1351   { CE_ENTERED_BY_PLAYER,       "entered by player"             },
1352   { CE_LEFT_BY_PLAYER,          "left by player"                },
1353   { CE_DROPPED_BY_PLAYER,       "dropped/thrown by player"      },
1354   { CE_SWITCHED,                "switched"                      },
1355 #if 1
1356   { CE_HITTING_SOMETHING,       "hitting something"             },
1357   { CE_HIT_BY_SOMETHING,        "hit by something"              },
1358 #else
1359   { CE_HITTING_SOMETHING,       "collision"                     },
1360 #endif
1361 #if 1
1362   { CE_BLOCKED,                 "blocked"                       },
1363 #endif
1364   { CE_IMPACT,                  "impact (on something)"         },
1365   { CE_SMASHED,                 "smashed (from above)"          },
1366
1367   { -1,                         NULL                            }
1368 };
1369
1370 static struct ValueTextInfo options_change_other_action[] =
1371 {
1372   { CE_OTHER_GETS_TOUCHED,      "player touches"                },
1373   { CE_OTHER_GETS_PRESSED,      "player presses"                },
1374   { CE_OTHER_GETS_PUSHED,       "player pushes"                 },
1375   { CE_OTHER_GETS_ENTERED,      "player enters"                 },
1376   { CE_OTHER_GETS_LEFT,         "player leaves"                 },
1377   { CE_OTHER_GETS_DIGGED,       "player digs"                   },
1378   { CE_OTHER_GETS_COLLECTED,    "player collects"               },
1379   { CE_OTHER_GETS_DROPPED,      "player drops/throws"           },
1380   { CE_OTHER_IS_TOUCHING,       "touching"                      },
1381 #if 1
1382   { CE_OTHER_IS_HITTING,        "hitting"                       },
1383   { CE_OTHER_GETS_HIT,          "hit by"                        },
1384 #endif
1385   { CE_OTHER_IS_SWITCHING,      "switch of"                     },
1386   { CE_OTHER_IS_CHANGING,       "change by page of"             },
1387   { CE_OTHER_IS_EXPLODING,      "explosion of"                  },
1388
1389   { -1,                         NULL                            }
1390 };
1391
1392 static struct ValueTextInfo options_change_trigger_side[] =
1393 {
1394   { CH_SIDE_LEFT,               "left"                          },
1395   { CH_SIDE_RIGHT,              "right"                         },
1396   { CH_SIDE_TOP,                "top"                           },
1397   { CH_SIDE_BOTTOM,             "bottom"                        },
1398   { CH_SIDE_LEFT_RIGHT,         "left/right"                    },
1399   { CH_SIDE_TOP_BOTTOM,         "top/bottom"                    },
1400   { CH_SIDE_ANY,                "any"                           },
1401
1402   { -1,                         NULL                            }
1403 };
1404
1405 static struct ValueTextInfo options_change_trigger_player[] =
1406 {
1407   { CH_PLAYER_1,                "1"                             },
1408   { CH_PLAYER_2,                "2"                             },
1409   { CH_PLAYER_3,                "3"                             },
1410   { CH_PLAYER_4,                "4"                             },
1411   { CH_PLAYER_ANY,              "any"                           },
1412
1413   { -1,                         NULL                            }
1414 };
1415
1416 static struct ValueTextInfo options_change_trigger_page[] =
1417 {
1418   { (1 << 0),                   "1"                             },
1419   { (1 << 1),                   "2"                             },
1420   { (1 << 2),                   "3"                             },
1421   { (1 << 3),                   "4"                             },
1422   { (1 << 4),                   "5"                             },
1423   { (1 << 5),                   "6"                             },
1424   { (1 << 6),                   "7"                             },
1425   { (1 << 7),                   "8"                             },
1426   { (1 << 8),                   "9"                             },
1427   { (1 << 9),                   "10"                            },
1428   { (1 << 10),                  "11"                            },
1429   { (1 << 11),                  "12"                            },
1430   { (1 << 12),                  "13"                            },
1431   { (1 << 13),                  "14"                            },
1432   { (1 << 14),                  "15"                            },
1433   { (1 << 15),                  "16"                            },
1434   { (1 << 16),                  "17"                            },
1435   { (1 << 17),                  "18"                            },
1436   { (1 << 18),                  "19"                            },
1437   { (1 << 19),                  "20"                            },
1438   { (1 << 20),                  "21"                            },
1439   { (1 << 21),                  "22"                            },
1440   { (1 << 22),                  "23"                            },
1441   { (1 << 23),                  "24"                            },
1442   { (1 << 24),                  "25"                            },
1443   { (1 << 25),                  "26"                            },
1444   { (1 << 26),                  "27"                            },
1445   { (1 << 27),                  "28"                            },
1446   { (1 << 28),                  "29"                            },
1447   { (1 << 29),                  "30"                            },
1448   { (1 << 30),                  "31"                            },
1449   { (1 << 31),                  "32"                            },
1450   { CH_PAGE_ANY,                "any"                           },
1451
1452   { -1,                         NULL                            }
1453 };
1454
1455 static struct ValueTextInfo options_change_replace_when[] =
1456 {
1457   { CP_WHEN_EMPTY,              "empty"                         },
1458   { CP_WHEN_WALKABLE,           "walkable"                      },
1459   { CP_WHEN_DIGGABLE,           "diggable"                      },
1460   { CP_WHEN_COLLECTIBLE,        "collectible"                   },
1461   { CP_WHEN_REMOVABLE,          "removable"                     },
1462   { CP_WHEN_DESTRUCTIBLE,       "destructible"                  },
1463
1464   { -1,                         NULL                            }
1465 };
1466
1467 static char options_change_page_strings[MAX_CHANGE_PAGES][10];
1468 static struct ValueTextInfo options_change_page[MAX_CHANGE_PAGES + 1] =
1469 {
1470   { -1,                         NULL                            }
1471 };
1472
1473 static struct ValueTextInfo options_group_choice_mode[] =
1474 {
1475   { ANIM_RANDOM,                "random"                        },
1476   { ANIM_LOOP,                  "loop"                          },
1477   { ANIM_LINEAR,                "linear"                        },
1478   { ANIM_PINGPONG,              "pingpong"                      },
1479   { ANIM_PINGPONG2,             "pingpong 2"                    },
1480
1481   { -1,                         NULL                            }
1482 };
1483
1484 static struct
1485 {
1486   int x, y;
1487   int gadget_id;
1488   int gadget_id_align;
1489   int size;     /* char size of selectbox or '-1' (dynamically determined) */
1490   struct ValueTextInfo *options;
1491   int *value;
1492   char *text_left, *text_right, *infotext;
1493 } selectbox_info[ED_NUM_SELECTBOX] =
1494 {
1495   /* ---------- level and editor settings ---------------------------------- */
1496
1497   {
1498     -1,                                 ED_COUNTER_YPOS(4),
1499     GADGET_ID_TIME_OR_STEPS,            GADGET_ID_LEVEL_TIMELIMIT_UP,
1500     -1,
1501     options_time_or_steps,
1502     &level.use_step_counter,
1503     NULL, "(0 => no limit)",            "time or step limit"
1504   },
1505
1506   /* ---------- element settings: configure 1 (custom elements) ----------- */
1507
1508   {
1509     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(3),
1510     GADGET_ID_CUSTOM_ACCESS_TYPE,       GADGET_ID_NONE,
1511     -1,
1512     options_access_type,
1513     &custom_element.access_type,
1514     NULL, NULL,                         "type of access to this field"
1515   },
1516   {
1517     -1,                                 ED_SETTINGS_YPOS(3),
1518     GADGET_ID_CUSTOM_ACCESS_LAYER,      GADGET_ID_CUSTOM_ACCESS_TYPE,
1519     -1,
1520     options_access_layer,
1521     &custom_element.access_layer,
1522     NULL, NULL,                         "layer of access for this field"
1523   },
1524   {
1525     -1,                                 ED_SETTINGS_YPOS(3),
1526     GADGET_ID_CUSTOM_ACCESS_PROTECTED,  GADGET_ID_CUSTOM_ACCESS_LAYER,
1527     -1,
1528     options_access_protected,
1529     &custom_element.access_protected,
1530     NULL, NULL,                         "protected access for this field"
1531   },
1532   {
1533     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(4),
1534     GADGET_ID_CUSTOM_ACCESS_DIRECTION,  GADGET_ID_NONE,
1535     -1,
1536     options_access_direction,
1537     &custom_element.access_direction,
1538     "from", NULL,                       "access direction for this field"
1539   },
1540   {
1541     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(5),
1542     GADGET_ID_CUSTOM_WALK_TO_ACTION,    GADGET_ID_NONE,
1543     -1,
1544     options_walk_to_action,
1545     &custom_element.walk_to_action,
1546     NULL, NULL,                         "diggable/collectible/pushable"
1547   },
1548
1549   /* ---------- element settings: configure 2 (custom elements) ----------- */
1550
1551   {
1552     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(1),
1553     GADGET_ID_CUSTOM_MOVE_PATTERN,      GADGET_ID_NONE,
1554     -1,
1555     options_move_pattern,
1556     &custom_element.move_pattern,
1557     "can move", NULL,                   "element move pattern"
1558   },
1559   {
1560     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(2),
1561     GADGET_ID_CUSTOM_MOVE_DIRECTION,    GADGET_ID_NONE,
1562     -1,
1563     options_move_direction,
1564     &custom_element.move_direction_initial,
1565     "starts moving", NULL,              "initial element move direction"
1566   },
1567   {
1568     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(4),
1569     GADGET_ID_CUSTOM_MOVE_STEPSIZE,     GADGET_ID_NONE,
1570     -1,
1571     options_move_stepsize,
1572     &custom_element.move_stepsize,
1573     "move/fall speed", NULL,            "speed of element movement"
1574   },
1575   {
1576     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(3),
1577     GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE,   GADGET_ID_NONE,
1578     -1,
1579     options_move_leave_type,
1580     &custom_element.move_leave_type,
1581     "can dig:    can", ":",             "leave behind or change element"
1582   },
1583   {
1584     -1,                                 ED_SETTINGS_YPOS(7),
1585     GADGET_ID_CUSTOM_SMASH_TARGETS,     GADGET_ID_CUSTOM_CAN_SMASH,
1586     -1,
1587     options_smash_targets,
1588     &custom_element.smash_targets,
1589     "can smash", NULL,                  "elements that can be smashed"
1590   },
1591   {
1592     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(8),
1593     GADGET_ID_CUSTOM_SLIPPERY_TYPE,     GADGET_ID_NONE,
1594     -1,
1595     options_slippery_type,
1596     &custom_element.slippery_type,
1597     "slippery", NULL,                   "where other elements fall down"
1598   },
1599   {
1600     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(9),
1601     GADGET_ID_CUSTOM_DEADLINESS,        GADGET_ID_NONE,
1602     -1,
1603     options_deadliness,
1604     &custom_element.deadliness,
1605     "deadly when", NULL,                "deadliness of element"
1606   },
1607   {
1608     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(10),
1609     GADGET_ID_CUSTOM_EXPLOSION_TYPE,    GADGET_ID_NONE,
1610     -1,
1611     options_explosion_type,
1612     &custom_element.explosion_type,
1613     "can explode", NULL,                "explosion type"
1614   },
1615
1616   /* ---------- element settings: advanced (custom elements) --------------- */
1617
1618   {
1619     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(3),
1620     GADGET_ID_CHANGE_TIME_UNITS,        GADGET_ID_NONE,
1621     -1,
1622     options_time_units,
1623     &custom_element_change.delay_frames,
1624     "delay time given in", NULL,        "delay time units for change"
1625   },
1626   {
1627     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(4),
1628     GADGET_ID_CHANGE_DIRECT_ACTION,     GADGET_ID_NONE,
1629     -1,
1630     options_change_direct_action,
1631     &custom_element_change.direct_action,
1632     NULL, NULL,                         "type of direct action"
1633   },
1634   {
1635     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(5),
1636     GADGET_ID_CHANGE_OTHER_ACTION,      GADGET_ID_NONE,
1637     -1,
1638     options_change_other_action,
1639     &custom_element_change.other_action,
1640     NULL, "element:",                   "type of other element action"
1641   },
1642   {
1643     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(6),
1644     GADGET_ID_CHANGE_SIDE,              GADGET_ID_NONE,
1645     -1,
1646     options_change_trigger_side,
1647     &custom_element_change.trigger_side,
1648     "at", "side",                       "element side that causes change"
1649   },
1650   {
1651     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(7),
1652     GADGET_ID_CHANGE_PLAYER,            GADGET_ID_NONE,
1653     -1,
1654     options_change_trigger_player,
1655     &custom_element_change.trigger_player,
1656     "player:", " ",                     "player that causes change"
1657   },
1658   {
1659     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(7),
1660     GADGET_ID_CHANGE_PAGE,              GADGET_ID_CHANGE_PLAYER,
1661     -1,
1662     options_change_trigger_page,
1663     &custom_element_change.trigger_page,
1664     "page:", NULL,                      "change page that causes change"
1665   },
1666   {
1667     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(10),
1668     GADGET_ID_CHANGE_REPLACE_WHEN,      GADGET_ID_NONE,
1669     -1,
1670     options_change_replace_when,
1671     &custom_element_change.replace_when,
1672     "replace when", NULL,               "which elements can be replaced"
1673   },
1674   {
1675     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(14),
1676     GADGET_ID_SELECT_CHANGE_PAGE,       GADGET_ID_NONE,
1677     3,
1678     options_change_page,
1679     &custom_element.current_change_page,
1680     NULL, NULL,                         "element change page"
1681   },
1682
1683   /* ---------- element settings: configure (group elements) --------------- */
1684
1685   {
1686     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(6),
1687     GADGET_ID_GROUP_CHOICE_MODE,        GADGET_ID_NONE,
1688     -1,
1689     options_group_choice_mode,
1690     &group_element_info.choice_mode,
1691     "choice type:", NULL,               "type of group element choice"
1692   },
1693 };
1694
1695 static struct
1696 {
1697   int x, y;
1698   int gadget_id;
1699   int gadget_id_align;
1700   int size;
1701   char *text;
1702   char *text_left, *text_right, *infotext;
1703 } textbutton_info[ED_NUM_TEXTBUTTONS] =
1704 {
1705 #if 1
1706   {
1707     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(1),
1708     GADGET_ID_PROPERTIES_INFO,          GADGET_ID_NONE,
1709     8,                                  "Info",                 
1710     NULL, NULL,                         "Show information about element"
1711   },
1712   {
1713     ED_SETTINGS_XPOS(0) + 124,          ED_COUNTER_YPOS(1),
1714     GADGET_ID_PROPERTIES_CONFIG,        GADGET_ID_NONE,
1715     8,                                  "Config",
1716     NULL, NULL,                         "Configure element properties"
1717   },
1718   {
1719     ED_SETTINGS_XPOS(0) + 124,          ED_COUNTER_YPOS(1),
1720     GADGET_ID_PROPERTIES_CONFIG_1,      GADGET_ID_NONE,
1721     8,                                  "Config 1",
1722     NULL, NULL,                         "Configure custom element properties"
1723   },
1724   {
1725     ED_SETTINGS_XPOS(0) + 248,          ED_COUNTER_YPOS(1),
1726     GADGET_ID_PROPERTIES_CONFIG_2,      GADGET_ID_NONE,
1727     8,                                  "Config 2",
1728     NULL, NULL,                         "Configure custom element properties"
1729   },
1730   {
1731     ED_SETTINGS_XPOS(0) + 372,          ED_COUNTER_YPOS(1),
1732     GADGET_ID_PROPERTIES_CHANGE,        GADGET_ID_NONE,
1733     8,                                  "Change",
1734     NULL, NULL,                         "Custom element change configuration"
1735   },
1736 #else
1737   {
1738     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(1),
1739     GADGET_ID_PROPERTIES_INFO,          GADGET_ID_NONE,
1740     11,                                 "Information",                  
1741     NULL, NULL,                         "Show information about element"
1742   },
1743   {
1744     ED_SETTINGS_XPOS(0) + 166,          ED_COUNTER_YPOS(1),
1745     GADGET_ID_PROPERTIES_CONFIG,        GADGET_ID_NONE,
1746     11,                                 "Configure",
1747     NULL, NULL,                         "Configure element properties"
1748   },
1749   {
1750     ED_SETTINGS_XPOS(0) + 332,          ED_COUNTER_YPOS(1),
1751     GADGET_ID_PROPERTIES_CHANGE,        GADGET_ID_NONE,
1752     11,                                 "Advanced",
1753     NULL, NULL,                         "Advanced element configuration"
1754   },
1755 #endif
1756   {
1757     -1,                                 ED_SETTINGS_YPOS(2),
1758     GADGET_ID_SAVE_AS_TEMPLATE,         GADGET_ID_CUSTOM_USE_TEMPLATE,
1759     -1,                                 "Save",
1760     " ", "As Template",                 "Save current settings as new template"
1761   },
1762   {
1763     -1,                                 ED_SETTINGS_YPOS(14),
1764     GADGET_ID_ADD_CHANGE_PAGE,          GADGET_ID_PASTE_CHANGE_PAGE,
1765     -1,                                 "New",
1766     NULL, NULL,                         "Add new change page"
1767   },
1768   {
1769     -1,                                 ED_SETTINGS_YPOS(14),
1770     GADGET_ID_DEL_CHANGE_PAGE,          GADGET_ID_ADD_CHANGE_PAGE,
1771     -1,                                 "Delete",
1772     NULL, NULL,                         "Delete current change page"
1773   },
1774 };
1775
1776 static struct
1777 {
1778   int gd_x, gd_y;
1779   int x, y;
1780   int width, height;
1781   int gadget_id;
1782   int gadget_id_align;
1783   char *text_left, *text_right, *infotext;
1784 } graphicbutton_info[ED_NUM_GRAPHICBUTTONS] =
1785 {
1786   {
1787     ED_BUTTON_MINUS_XPOS,               ED_BUTTON_COUNT_YPOS,
1788     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(14),
1789     ED_BUTTON_COUNT_XSIZE,              ED_BUTTON_COUNT_YSIZE,
1790     GADGET_ID_PREV_CHANGE_PAGE,         GADGET_ID_NONE,
1791     NULL, NULL,                         "select previous change page"
1792   },
1793   {
1794     ED_BUTTON_PLUS_XPOS,                ED_BUTTON_COUNT_YPOS,
1795     -1,                                 ED_SETTINGS_YPOS(14),
1796     ED_BUTTON_COUNT_XSIZE,              ED_BUTTON_COUNT_YSIZE,
1797     GADGET_ID_NEXT_CHANGE_PAGE,         GADGET_ID_SELECT_CHANGE_PAGE,
1798     NULL, "change page",                "select next change page"
1799   },
1800   {
1801     ED_COPY_CHANGE_PAGE_XPOS,           ED_COPY_CHANGE_PAGE_YPOS,
1802     -1,                                 ED_SETTINGS_YPOS(14),
1803     ED_BUTTON_COUNT_XSIZE,              ED_BUTTON_COUNT_YSIZE,
1804     GADGET_ID_COPY_CHANGE_PAGE,         GADGET_ID_NEXT_CHANGE_PAGE,
1805     " ", NULL,                          "copy settings from this change page"
1806   },
1807   {
1808     ED_PASTE_CHANGE_PAGE_XPOS,          ED_PASTE_CHANGE_PAGE_YPOS,
1809     -1,                                 ED_SETTINGS_YPOS(14),
1810     ED_BUTTON_COUNT_XSIZE,              ED_BUTTON_COUNT_YSIZE,
1811     GADGET_ID_PASTE_CHANGE_PAGE,        GADGET_ID_COPY_CHANGE_PAGE,
1812     NULL, NULL,                         "paste settings to this change page"
1813   },
1814 };
1815
1816 static struct
1817 {
1818   int gd_x, gd_y;
1819   int x, y;
1820   int gadget_id;
1821   char *infotext;
1822 } scrollbutton_info[ED_NUM_SCROLLBUTTONS] =
1823 {
1824   {
1825     ED_SCROLLBUTTON_XPOS,   ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE,
1826     ED_SCROLL_UP_XPOS,      ED_SCROLL_UP_YPOS,
1827     GADGET_ID_SCROLL_UP,
1828     "scroll level editing area up"
1829   },
1830   {
1831     ED_SCROLLBUTTON_XPOS,   ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE,
1832     ED_SCROLL_DOWN_XPOS,    ED_SCROLL_DOWN_YPOS,
1833     GADGET_ID_SCROLL_DOWN,
1834     "scroll level editing area down"
1835   },
1836   {
1837     ED_SCROLLBUTTON_XPOS,   ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE,
1838     ED_SCROLL_LEFT_XPOS,    ED_SCROLL_LEFT_YPOS,
1839     GADGET_ID_SCROLL_LEFT,
1840     "scroll level editing area left"
1841   },
1842   {
1843     ED_SCROLLBUTTON_XPOS,   ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE,
1844     ED_SCROLL_RIGHT_XPOS,   ED_SCROLL_RIGHT_YPOS,
1845     GADGET_ID_SCROLL_RIGHT,
1846     "scroll level editing area right"
1847   },
1848   {
1849     ED_SCROLLBUTTON2_XPOS,  ED_SCROLLBUTTON2_YPOS + 0 * ED_SCROLLBUTTON2_YSIZE,
1850     ED_SCROLL2_UP_XPOS,     ED_SCROLL2_UP_YPOS,
1851     GADGET_ID_SCROLL_LIST_UP,
1852     "scroll element list up ('Page Up')"
1853   },
1854   {
1855     ED_SCROLLBUTTON2_XPOS,  ED_SCROLLBUTTON2_YPOS + 1 * ED_SCROLLBUTTON2_YSIZE,
1856     ED_SCROLL2_DOWN_XPOS,   ED_SCROLL2_DOWN_YPOS,
1857     GADGET_ID_SCROLL_LIST_DOWN,
1858     "scroll element list down ('Page Down')"
1859   },
1860 };
1861
1862 static struct
1863 {
1864   int gd_x, gd_y;
1865   int x, y;
1866   int width, height;
1867   int type;
1868   int gadget_id;
1869   char *infotext;
1870 } scrollbar_info[ED_NUM_SCROLLBARS] =
1871 {
1872   {
1873     ED_SCROLLBAR_XPOS,                  ED_SCROLLBAR_YPOS,
1874     SX + ED_SCROLL_HORIZONTAL_XPOS,     SY + ED_SCROLL_HORIZONTAL_YPOS,
1875     ED_SCROLL_HORIZONTAL_XSIZE,         ED_SCROLL_HORIZONTAL_YSIZE,
1876     GD_TYPE_SCROLLBAR_HORIZONTAL,
1877     GADGET_ID_SCROLL_HORIZONTAL,
1878     "scroll level editing area horizontally"
1879   },
1880   {
1881     ED_SCROLLBAR_XPOS,                  ED_SCROLLBAR_YPOS,
1882     SX + ED_SCROLL_VERTICAL_XPOS,       SY + ED_SCROLL_VERTICAL_YPOS,
1883     ED_SCROLL_VERTICAL_XSIZE,           ED_SCROLL_VERTICAL_YSIZE,
1884     GD_TYPE_SCROLLBAR_VERTICAL,
1885     GADGET_ID_SCROLL_VERTICAL,
1886     "scroll level editing area vertically"
1887   },
1888   {
1889     ED_SCROLLBAR2_XPOS,                 ED_SCROLLBAR2_YPOS,
1890     DX + ED_SCROLL2_VERTICAL_XPOS,      DY + ED_SCROLL2_VERTICAL_YPOS,
1891     ED_SCROLL2_VERTICAL_XSIZE,          ED_SCROLL2_VERTICAL_YSIZE,
1892     GD_TYPE_SCROLLBAR_VERTICAL,
1893     GADGET_ID_SCROLL_LIST_VERTICAL,
1894     "scroll element list vertically"
1895   }
1896 };
1897
1898 static struct
1899 {
1900   int x, y;
1901   int gadget_id;
1902   int gadget_id_align;
1903   int radio_button_nr;
1904   int *value;
1905   int checked_value;
1906   char *text_left, *text_right, *infotext;
1907 } radiobutton_info[ED_NUM_RADIOBUTTONS] =
1908 {
1909   {
1910     -1,                                 ED_COUNTER2_YPOS(8),
1911     GADGET_ID_RANDOM_PERCENTAGE,        GADGET_ID_LEVEL_RANDOM_UP,
1912     RADIO_NR_RANDOM_ELEMENTS,
1913     &random_placement_method,           RANDOM_USE_PERCENTAGE,
1914     " ", "percentage",                  "use percentage for random elements"
1915   },
1916   {
1917     -1,                                 ED_COUNTER2_YPOS(8),
1918     GADGET_ID_RANDOM_QUANTITY,          GADGET_ID_RANDOM_PERCENTAGE,
1919     RADIO_NR_RANDOM_ELEMENTS,
1920     &random_placement_method,           RANDOM_USE_QUANTITY,
1921     " ", "quantity",                    "use quantity for random elements"
1922   }
1923 };
1924
1925 static struct
1926 {
1927   int x, y;
1928   int gadget_id;
1929   int gadget_id_align;
1930   boolean *value;
1931   char *text_left, *text_right, *infotext;
1932 } checkbutton_info[ED_NUM_CHECKBUTTONS] =
1933 {
1934   /* ---------- level and editor settings ---------------------------------- */
1935
1936   {
1937     ED_SETTINGS_XPOS(0),                ED_COUNTER_YPOS(6) - MINI_TILEY,
1938     GADGET_ID_DOUBLE_SPEED,             GADGET_ID_NONE,
1939     &level.double_speed,
1940     NULL, "double speed movement",      "set movement speed of player"
1941   },
1942   {
1943     -1,                                 ED_COUNTER_YPOS(6) - MINI_TILEY,
1944     GADGET_ID_GRAVITY,                  GADGET_ID_DOUBLE_SPEED,
1945     &level.initial_gravity,
1946     " ", "gravity",                     "set level gravity"
1947   },
1948   {
1949     ED_SETTINGS_XPOS(0),                ED_COUNTER2_YPOS(9) - MINI_TILEY,
1950     GADGET_ID_RANDOM_RESTRICTED,        GADGET_ID_NONE,
1951     &random_placement_background_restricted,
1952     NULL,
1953     "restrict random placement to:",    "set random placement restriction"
1954   },
1955
1956   /* ---------- element settings: configure (various elements) ------------- */
1957
1958   {
1959     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(0),
1960     GADGET_ID_STICK_ELEMENT,            GADGET_ID_NONE,
1961     &stick_element_properties_window,
1962     NULL,
1963     "stick this screen to edit content","stick this screen to edit content"
1964   },
1965   {
1966     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(1),
1967     GADGET_ID_EM_SLIPPERY_GEMS,         GADGET_ID_NONE,
1968     &level.em_slippery_gems,
1969     NULL,
1970     "slip down from certain flat walls","use EM style slipping behaviour"
1971   },
1972   {
1973     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(1),
1974     GADGET_ID_USE_SPRING_BUG,           GADGET_ID_NONE,
1975     &level.use_spring_bug,
1976     NULL,
1977     "use spring pushing bug",           "use odd spring pushing behaviour"
1978   },
1979   {
1980     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(0),
1981     GADGET_ID_GROW_INTO_DIGGABLE,       GADGET_ID_NONE,
1982     &level.grow_into_diggable,
1983     NULL,
1984     "can grow into anything diggable",  "grow into more than just sand"
1985   },
1986   {
1987     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(1),
1988     GADGET_ID_BLOCK_LAST_FIELD,         GADGET_ID_NONE,
1989     &level.block_last_field,
1990     NULL,
1991     "block last field when moving",     "player blocks last field when moving"
1992   },
1993   {
1994     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(1),
1995     GADGET_ID_SP_BLOCK_LAST_FIELD,      GADGET_ID_NONE,
1996     &level.sp_block_last_field,
1997     NULL,
1998     "block last field when moving",     "player blocks last field when moving"
1999   },
2000   {
2001     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(2),
2002     GADGET_ID_INSTANT_RELOCATION,       GADGET_ID_NONE,
2003     &level.instant_relocation,
2004     NULL,
2005     "no scrolling when relocating",     "player gets relocated without delay"
2006   },
2007   {
2008     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(3),
2009     GADGET_ID_CAN_PASS_TO_WALKABLE,     GADGET_ID_NONE,
2010     &level.can_pass_to_walkable,
2011     NULL,
2012     "can pass to walkable element",     "player can pass to empty or walkable"
2013   },
2014   {
2015     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(0),
2016     GADGET_ID_CAN_FALL_INTO_ACID,       GADGET_ID_NONE,
2017     &custom_element_properties[EP_CAN_MOVE_INTO_ACID],
2018     NULL,
2019     "can fall into acid (with gravity)","player can fall into acid pool"
2020   },
2021   {
2022     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(0),
2023     GADGET_ID_CAN_MOVE_INTO_ACID,       GADGET_ID_NONE,
2024     &custom_element_properties[EP_CAN_MOVE_INTO_ACID],
2025     NULL,
2026     "can move into acid",               "element can move into acid pool"
2027   },
2028   {
2029     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(1),
2030     GADGET_ID_DONT_COLLIDE_WITH,        GADGET_ID_NONE,
2031     &custom_element_properties[EP_DONT_COLLIDE_WITH],
2032     NULL,
2033     "deadly when colliding with",       "element is deadly when hitting player"
2034   },
2035
2036   /* ---------- element settings: configure 1 (custom elements) ----------- */
2037
2038   {
2039     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(1),
2040     GADGET_ID_CUSTOM_USE_GRAPHIC,       GADGET_ID_NONE,
2041     &custom_element.use_gfx_element,
2042     NULL, "use graphic/sound of element:", "use existing graphic and sound"
2043   },
2044   {
2045     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(2),
2046     GADGET_ID_CUSTOM_USE_TEMPLATE,      GADGET_ID_NONE,
2047     &level.use_custom_template,
2048     NULL, "use template",               "use template for custom properties"
2049   },
2050   {
2051     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(3),
2052     GADGET_ID_CUSTOM_ACCESSIBLE,        GADGET_ID_NONE,
2053     &custom_element_properties[EP_ACCESSIBLE],
2054     NULL, NULL,                         "player can walk to or pass this field"
2055   },
2056   {
2057     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(10),
2058     GADGET_ID_CUSTOM_GRAV_REACHABLE,    GADGET_ID_NONE,
2059     &custom_element_properties[EP_GRAVITY_REACHABLE],
2060     NULL, "reachable despite gravity",  "player can walk/dig despite gravity"
2061   },
2062   {
2063     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(5),
2064     GADGET_ID_CUSTOM_WALK_TO_OBJECT,    GADGET_ID_NONE,
2065     &custom_element_properties[EP_WALK_TO_OBJECT],
2066     NULL, NULL,                         "player can dig/collect/push element"
2067   },
2068   {
2069     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(9),
2070     GADGET_ID_CUSTOM_INDESTRUCTIBLE,    GADGET_ID_NONE,
2071     &custom_element_properties[EP_INDESTRUCTIBLE],
2072     NULL, "indestructible",             "element is indestructible"
2073   },
2074
2075   /* ---------- element settings: configure 2 (custom elements) ----------- */
2076
2077   {
2078     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(1),
2079     GADGET_ID_CUSTOM_CAN_MOVE,          GADGET_ID_NONE,
2080     &custom_element_properties[EP_CAN_MOVE],
2081     NULL, NULL,                         "element can move with some pattern"
2082   },
2083   {
2084     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(7),
2085     GADGET_ID_CUSTOM_CAN_FALL,          GADGET_ID_NONE,
2086     &custom_element_properties[EP_CAN_FALL],
2087     NULL, "can fall",                   "element can fall down"
2088   },
2089   {
2090     -1,                                 ED_SETTINGS_YPOS(7),
2091     GADGET_ID_CUSTOM_CAN_SMASH,         GADGET_ID_CUSTOM_CAN_FALL,
2092     &custom_element_properties[EP_CAN_SMASH],
2093     " ", NULL,                          "element can smash other elements"
2094   },
2095   {
2096     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(8),
2097     GADGET_ID_CUSTOM_SLIPPERY,          GADGET_ID_NONE,
2098     &custom_element_properties[EP_SLIPPERY],
2099     NULL, NULL,                         "other elements can fall down from it"
2100   },
2101   {
2102     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(9),
2103     GADGET_ID_CUSTOM_DEADLY,            GADGET_ID_NONE,
2104     &custom_element_properties[EP_DEADLY],
2105     NULL, NULL,                         "element can kill the player"
2106   },
2107   {
2108     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(10),
2109     GADGET_ID_CUSTOM_CAN_EXPLODE,       GADGET_ID_NONE,
2110     &custom_element_properties[EP_CAN_EXPLODE],
2111     NULL, NULL,                         "element can explode"
2112   },
2113   {
2114     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(11),
2115     GADGET_ID_CUSTOM_EXPLODE_FIRE,      GADGET_ID_NONE,
2116     &custom_element_properties[EP_EXPLODES_BY_FIRE],
2117     NULL, "by fire",                    "element can explode by fire/explosion"
2118   },
2119   {
2120     -1,                                 ED_SETTINGS_YPOS(11),
2121     GADGET_ID_CUSTOM_EXPLODE_SMASH,     GADGET_ID_CUSTOM_EXPLODE_FIRE,
2122     &custom_element_properties[EP_EXPLODES_SMASHED],
2123     " ", "smashed",                     "element can explode when smashed"
2124   },
2125   {
2126     -1,                                 ED_SETTINGS_YPOS(11),
2127     GADGET_ID_CUSTOM_EXPLODE_IMPACT,    GADGET_ID_CUSTOM_EXPLODE_SMASH,
2128     &custom_element_properties[EP_EXPLODES_IMPACT],
2129     " ", "impact",                      "element can explode on impact"
2130   },
2131
2132   /* ---------- element settings: advanced (custom elements) --------------- */
2133
2134   {
2135     ED_SETTINGS_XPOS(0),                ED_SETTINGS_YPOS(1),
2136     GADGET_ID_CUSTOM_CAN_CHANGE,        GADGET_ID_NONE,
2137     &custom_element_change.can_change,
2138     NULL, "element changes to:",        "element can change to other element"
2139   },
2140   {
2141     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(2),
2142     GADGET_ID_CHANGE_DELAY,             GADGET_ID_NONE,
2143     &custom_element_change_events[CE_DELAY],
2144     NULL, NULL,                         "element changes after delay"
2145   },
2146   {
2147     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(4),
2148     GADGET_ID_CHANGE_BY_DIRECT_ACT,     GADGET_ID_NONE,
2149     &custom_element_change_events[CE_BY_DIRECT_ACTION],
2150     NULL, NULL,                         "element changes by direct action"
2151   },
2152   {
2153     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(5),
2154     GADGET_ID_CHANGE_BY_OTHER_ACT,      GADGET_ID_NONE,
2155     &custom_element_change_events[CE_BY_OTHER_ACTION],
2156     NULL, NULL,                         "element changes by other element"
2157   },
2158   {
2159     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(8),
2160     GADGET_ID_CHANGE_USE_EXPLOSION,     GADGET_ID_NONE,
2161     &custom_element_change.explode,
2162     NULL, "explode instead of change",  "element explodes instead of change"
2163   },
2164   {
2165     ED_SETTINGS_XPOS(1),                ED_SETTINGS_YPOS(9),
2166     GADGET_ID_CHANGE_USE_CONTENT,       GADGET_ID_NONE,
2167     &custom_element_change.use_target_content,
2168     NULL, "use extended change target:","element changes to more elements"
2169   },
2170   {
2171     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(11),
2172     GADGET_ID_CHANGE_ONLY_COMPLETE,     GADGET_ID_NONE,
2173     &custom_element_change.only_if_complete,
2174     NULL, "replace all or nothing",     "only replace when all can be changed"
2175   },
2176   {
2177     ED_SETTINGS_XPOS(2),                ED_SETTINGS_YPOS(12),
2178     GADGET_ID_CHANGE_USE_RANDOM,        GADGET_ID_NONE,
2179     &custom_element_change.use_random_replace,
2180     NULL, NULL,                         "use percentage for random replace"
2181   },
2182 };
2183
2184 static struct
2185 {
2186   int x, y;
2187   int area_xsize, area_ysize;
2188   int gadget_id;
2189   int gadget_id_align;
2190   char *text_left, *text_right, *text_below;
2191 } drawingarea_info[ED_NUM_DRAWING_AREAS] =
2192 {
2193   /* ---------- level playfield content ------------------------------------ */
2194
2195   {
2196     0, 0,
2197     MAX_ED_FIELDX, MAX_ED_FIELDY,
2198     GADGET_ID_DRAWING_LEVEL,            GADGET_ID_NONE,
2199     NULL, NULL,                         NULL
2200   },
2201
2202   /* ---------- yam yam content -------------------------------------------- */
2203
2204   {
2205     ED_AREA_YAMYAM_CONTENT_XPOS(0),     ED_AREA_YAMYAM_CONTENT_YPOS(0),
2206     3, 3,
2207     GADGET_ID_ELEMENT_CONTENT_0,        GADGET_ID_NONE,
2208     NULL, NULL,                         "1"
2209   },
2210   {
2211     ED_AREA_YAMYAM_CONTENT_XPOS(1),     ED_AREA_YAMYAM_CONTENT_YPOS(1),
2212     3, 3,
2213     GADGET_ID_ELEMENT_CONTENT_1,        GADGET_ID_NONE,
2214     NULL, NULL,                         "2"
2215   },
2216   {
2217     ED_AREA_YAMYAM_CONTENT_XPOS(2),     ED_AREA_YAMYAM_CONTENT_YPOS(2),
2218     3, 3,
2219     GADGET_ID_ELEMENT_CONTENT_2,        GADGET_ID_NONE,
2220     NULL, NULL,                         "3"
2221   },
2222   {
2223     ED_AREA_YAMYAM_CONTENT_XPOS(3),     ED_AREA_YAMYAM_CONTENT_YPOS(3),
2224     3, 3,
2225     GADGET_ID_ELEMENT_CONTENT_3,        GADGET_ID_NONE,
2226     NULL, NULL,                         "4"
2227   },
2228   {
2229     ED_AREA_YAMYAM_CONTENT_XPOS(4),     ED_AREA_YAMYAM_CONTENT_YPOS(4),
2230     3, 3,
2231     GADGET_ID_ELEMENT_CONTENT_4,        GADGET_ID_NONE,
2232     NULL, NULL,                         "5"
2233   },
2234   {
2235     ED_AREA_YAMYAM_CONTENT_XPOS(5),     ED_AREA_YAMYAM_CONTENT_YPOS(5),
2236     3, 3,
2237     GADGET_ID_ELEMENT_CONTENT_5,        GADGET_ID_NONE,
2238     NULL, NULL,                         "6"
2239   },
2240   {
2241     ED_AREA_YAMYAM_CONTENT_XPOS(6),     ED_AREA_YAMYAM_CONTENT_YPOS(6),
2242     3, 3,
2243     GADGET_ID_ELEMENT_CONTENT_6,        GADGET_ID_NONE,
2244     NULL, NULL,                         "7"
2245   },
2246   {
2247     ED_AREA_YAMYAM_CONTENT_XPOS(7),     ED_AREA_YAMYAM_CONTENT_YPOS(7),
2248     3, 3,
2249     GADGET_ID_ELEMENT_CONTENT_7,        GADGET_ID_NONE,
2250     NULL, NULL,                         "8"
2251   },
2252
2253   /* ---------- amoeba content --------------------------------------------- */
2254
2255   {
2256     ED_AREA_1X1_SETTINGS_XPOS(0),       ED_AREA_1X1_SETTINGS_YPOS(3),
2257     1, 1,
2258     GADGET_ID_AMOEBA_CONTENT,           GADGET_ID_NONE,
2259     "content:", NULL,                   NULL
2260   },
2261
2262   /* ---------- element settings: configure 1 (custom elements) ----------- */
2263
2264   /* ---------- custom graphic --------------------------------------------- */
2265
2266   {
2267     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(1),
2268     1, 1,
2269     GADGET_ID_CUSTOM_GRAPHIC,           GADGET_ID_CUSTOM_USE_GRAPHIC,
2270     NULL, NULL,                         NULL
2271   },
2272
2273   /* ---------- element settings: configure 2 (custom elements) ----------- */
2274
2275   /* ---------- custom content (when exploding) ---------------------------- */
2276
2277   {
2278     -1,                                 ED_AREA_3X3_SETTINGS_YPOS(10),
2279     3, 3,
2280     GADGET_ID_CUSTOM_CONTENT,           GADGET_ID_NONE, /* align three rows */
2281     "content:", NULL,                   NULL
2282   },
2283
2284   /* ---------- custom enter and leave element (when moving) --------------- */
2285
2286   {
2287     ED_AREA_1X1_SETTINGS_XPOS(1),       ED_AREA_1X1_SETTINGS_YPOS(3),
2288     1, 1,
2289     GADGET_ID_CUSTOM_MOVE_ENTER,        GADGET_ID_NONE,
2290     "can dig:", " ",                    NULL
2291   },
2292   {
2293     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(3),
2294     1, 1,
2295     GADGET_ID_CUSTOM_MOVE_LEAVE,        GADGET_ID_CUSTOM_MOVE_LEAVE_TYPE,
2296     NULL, NULL,                         NULL
2297   },
2298
2299   /* ---------- element settings: advanced (custom elements) --------------- */
2300
2301   /* ---------- custom change target --------------------------------------- */
2302
2303   {
2304     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(1),
2305     1, 1,
2306     GADGET_ID_CUSTOM_CHANGE_TARGET,     GADGET_ID_CUSTOM_CAN_CHANGE,
2307     NULL, "after/when:",                NULL
2308   },
2309
2310   /* ---------- custom change content (extended change target) ------------- */
2311
2312   {
2313     -1,                                 ED_AREA_3X3_SETTINGS_YPOS(10),
2314     3, 3,
2315     GADGET_ID_CUSTOM_CHANGE_CONTENT,    GADGET_ID_NONE, /* align three rows */
2316     NULL, NULL,                         NULL
2317   },
2318
2319   /* ---------- custom change trigger (element causing change) ------------- */
2320
2321   {
2322     -1,                                 ED_AREA_1X1_SETTINGS_YPOS(5),
2323     1, 1,
2324     GADGET_ID_CUSTOM_CHANGE_TRIGGER,    GADGET_ID_CHANGE_OTHER_ACTION,
2325     NULL, NULL,                         NULL
2326   },
2327
2328   /* ---------- group element content -------------------------------------- */
2329
2330   {
2331     ED_AREA_1X1_SETTINGS_XPOS(0),       ED_AREA_1X1_SETTINGS_YPOS(4),
2332     MAX_ELEMENTS_IN_GROUP, 1,
2333     GADGET_ID_GROUP_CONTENT,            GADGET_ID_NONE,
2334     "content:", NULL,                   NULL
2335   },
2336
2337   /* ---------- random background (for random painting) -------------------- */
2338
2339   {
2340     -1,                                 ED_SETTINGS_YPOS(14),
2341     1, 1,
2342     GADGET_ID_RANDOM_BACKGROUND,        GADGET_ID_RANDOM_RESTRICTED,
2343     NULL, NULL,                         NULL
2344   },
2345 };
2346
2347
2348 /*
2349   -----------------------------------------------------------------------------
2350   some internally used variables
2351   -----------------------------------------------------------------------------
2352 */
2353
2354 /* actual size of level editor drawing area */
2355 static int ed_fieldx = MAX_ED_FIELDX - 1, ed_fieldy = MAX_ED_FIELDY - 1;
2356
2357 /* actual position of level editor drawing area in level playfield */
2358 static int level_xpos = -1, level_ypos = -1;
2359
2360 #define IN_ED_FIELD(x,y)  ((x)>=0 && (x)<ed_fieldx && (y)>=0 &&(y)<ed_fieldy)
2361
2362 /* drawing elements on the three mouse buttons */
2363 static int new_element1 = EL_WALL;
2364 static int new_element2 = EL_EMPTY;
2365 static int new_element3 = EL_SAND;
2366
2367 #define BUTTON_ELEMENT(button) ((button) == 1 ? new_element1 : \
2368                                 (button) == 2 ? new_element2 : \
2369                                 (button) == 3 ? new_element3 : EL_EMPTY)
2370 #define BUTTON_STEPSIZE(button) ((button) == 1 ? 1 : (button) == 2 ? 5 : 10)
2371
2372 /* forward declaration for internal use */
2373 static void ModifyEditorCounter(int, int);
2374 static void ModifyEditorCounterLimits(int, int, int);
2375 static void ModifyEditorSelectbox(int, int);
2376 static void ModifyEditorDrawingArea(int, int, int);
2377 static void ModifyEditorElementList();
2378 static void RedrawDrawingElements();
2379 static void DrawDrawingWindow();
2380 static void DrawLevelInfoWindow();
2381 static void DrawPropertiesWindow();
2382 static void UpdateCustomElementGraphicGadgets();
2383 static boolean checkPropertiesConfig(int);
2384 static void CopyLevelToUndoBuffer(int);
2385 static void HandleDrawingAreas(struct GadgetInfo *);
2386 static void HandleCounterButtons(struct GadgetInfo *);
2387 static void HandleTextInputGadgets(struct GadgetInfo *);
2388 static void HandleTextAreaGadgets(struct GadgetInfo *);
2389 static void HandleSelectboxGadgets(struct GadgetInfo *);
2390 static void HandleTextbuttonGadgets(struct GadgetInfo *);
2391 static void HandleGraphicbuttonGadgets(struct GadgetInfo *);
2392 static void HandleRadiobuttons(struct GadgetInfo *);
2393 static void HandleCheckbuttons(struct GadgetInfo *);
2394 static void HandleControlButtons(struct GadgetInfo *);
2395 static void HandleDrawingAreaInfo(struct GadgetInfo *);
2396
2397 static struct GadgetInfo *level_editor_gadget[NUM_EDITOR_GADGETS];
2398 static int right_gadget_border[NUM_EDITOR_GADGETS];
2399
2400 static int drawing_function = GADGET_ID_SINGLE_ITEMS;
2401 static int last_drawing_function = GADGET_ID_SINGLE_ITEMS;
2402 static boolean draw_with_brush = FALSE;
2403 static int properties_element = 0;
2404
2405 static short FieldBackup[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
2406 static short UndoBuffer[NUM_UNDO_STEPS][MAX_LEV_FIELDX][MAX_LEV_FIELDY];
2407 static int undo_buffer_position = 0;
2408 static int undo_buffer_steps = 0;
2409
2410 static int edit_mode;
2411 static int edit_mode_properties;
2412
2413 static int element_shift = 0;
2414
2415 static int editor_hl_boulderdash[] =
2416 {
2417   EL_CHAR('B'),
2418   EL_CHAR('O'),
2419   EL_CHAR('U'),
2420   EL_CHAR('L'),
2421
2422   EL_CHAR('-'),
2423   EL_CHAR('D'),
2424   EL_CHAR('E'),
2425   EL_CHAR('R'),
2426
2427   EL_CHAR('D'),
2428   EL_CHAR('A'),
2429   EL_CHAR('S'),
2430   EL_CHAR('H'),
2431 };
2432
2433 static int editor_el_boulderdash[] =
2434 {
2435   EL_PLAYER_1,
2436   EL_EMPTY,
2437   EL_SAND,
2438   EL_STEELWALL,
2439
2440   EL_BD_WALL,
2441   EL_BD_MAGIC_WALL,
2442   EL_EXIT_CLOSED,
2443   EL_EXIT_OPEN,
2444
2445   EL_BD_DIAMOND,
2446   EL_BD_BUTTERFLY_UP,
2447   EL_BD_FIREFLY_UP,
2448   EL_BD_ROCK,
2449
2450   EL_BD_BUTTERFLY_LEFT,
2451   EL_BD_FIREFLY_LEFT,
2452   EL_BD_BUTTERFLY_RIGHT,
2453   EL_BD_FIREFLY_RIGHT,
2454
2455   EL_BD_AMOEBA,
2456   EL_BD_BUTTERFLY_DOWN,
2457   EL_BD_FIREFLY_DOWN,
2458   EL_EMPTY,
2459 };
2460 static int *editor_hl_boulderdash_ptr = editor_hl_boulderdash;
2461 static int *editor_el_boulderdash_ptr = editor_el_boulderdash;
2462 static int num_editor_hl_boulderdash = SIZEOF_ARRAY_INT(editor_hl_boulderdash);
2463 static int num_editor_el_boulderdash = SIZEOF_ARRAY_INT(editor_el_boulderdash);
2464
2465 static int editor_hl_emerald_mine[] =
2466 {
2467   EL_CHAR('E'),
2468   EL_CHAR('M'),
2469   EL_CHAR('E'),
2470   EL_CHAR('-'),
2471
2472   EL_CHAR('R'),
2473   EL_CHAR('A'),
2474   EL_CHAR('L'),
2475   EL_CHAR('D'),
2476
2477   EL_CHAR('M'),
2478   EL_CHAR('I'),
2479   EL_CHAR('N'),
2480   EL_CHAR('E'),
2481 };
2482
2483 static int editor_el_emerald_mine[] =
2484 {
2485   EL_PLAYER_1,
2486   EL_PLAYER_2,
2487   EL_PLAYER_3,
2488   EL_PLAYER_4,
2489
2490   EL_PLAYER_1,
2491   EL_EMPTY,
2492   EL_SAND,
2493   EL_ROCK,
2494
2495   EL_STEELWALL,
2496   EL_WALL,
2497   EL_WALL_SLIPPERY,
2498   EL_MAGIC_WALL,
2499
2500   EL_EMERALD,
2501   EL_DIAMOND,
2502   EL_NUT,
2503   EL_BOMB,
2504
2505   EL_WALL_EMERALD,
2506   EL_WALL_DIAMOND,
2507   EL_QUICKSAND_EMPTY,
2508   EL_QUICKSAND_FULL,
2509
2510   EL_DYNAMITE,
2511   EL_DYNAMITE_ACTIVE,
2512   EL_EXIT_CLOSED,
2513   EL_EXIT_OPEN,
2514
2515   EL_YAMYAM,
2516   EL_BUG_UP,
2517   EL_SPACESHIP_UP,
2518   EL_ROBOT,
2519
2520   EL_BUG_LEFT,
2521   EL_SPACESHIP_LEFT,
2522   EL_BUG_RIGHT,
2523   EL_SPACESHIP_RIGHT,
2524
2525   EL_ROBOT_WHEEL,
2526   EL_BUG_DOWN,
2527   EL_SPACESHIP_DOWN,
2528   EL_INVISIBLE_WALL,
2529
2530   EL_ACID_POOL_TOPLEFT,
2531   EL_ACID,
2532   EL_ACID_POOL_TOPRIGHT,
2533   EL_EMPTY,
2534
2535   EL_ACID_POOL_BOTTOMLEFT,
2536   EL_ACID_POOL_BOTTOM,
2537   EL_ACID_POOL_BOTTOMRIGHT,
2538   EL_EMPTY,
2539
2540   EL_AMOEBA_DROP,
2541   EL_AMOEBA_DEAD,
2542   EL_AMOEBA_WET,
2543   EL_AMOEBA_DRY,
2544
2545 #if 1
2546   EL_EM_KEY_1,
2547   EL_EM_KEY_2,
2548   EL_EM_KEY_3,
2549   EL_EM_KEY_4,
2550 #else
2551   EL_EM_KEY_1_FILE,
2552   EL_EM_KEY_2_FILE,
2553   EL_EM_KEY_3_FILE,
2554   EL_EM_KEY_4_FILE,
2555 #endif
2556
2557   EL_EM_GATE_1,
2558   EL_EM_GATE_2,
2559   EL_EM_GATE_3,
2560   EL_EM_GATE_4,
2561
2562   EL_EM_GATE_1_GRAY,
2563   EL_EM_GATE_2_GRAY,
2564   EL_EM_GATE_3_GRAY,
2565   EL_EM_GATE_4_GRAY,
2566 };
2567 static int *editor_hl_emerald_mine_ptr = editor_hl_emerald_mine;
2568 static int *editor_el_emerald_mine_ptr = editor_el_emerald_mine;
2569 static int num_editor_hl_emerald_mine=SIZEOF_ARRAY_INT(editor_hl_emerald_mine);
2570 static int num_editor_el_emerald_mine=SIZEOF_ARRAY_INT(editor_el_emerald_mine);
2571
2572 static int editor_hl_more[] =
2573 {
2574   EL_CHAR('M'),
2575   EL_CHAR('O'),
2576   EL_CHAR('R'),
2577   EL_CHAR('E'),
2578 };
2579
2580 static int editor_el_more[] =
2581 {
2582   EL_KEY_1,
2583   EL_KEY_2,
2584   EL_KEY_3,
2585   EL_KEY_4,
2586
2587   EL_GATE_1,
2588   EL_GATE_2,
2589   EL_GATE_3,
2590   EL_GATE_4,
2591
2592   EL_GATE_1_GRAY,
2593   EL_GATE_2_GRAY,
2594   EL_GATE_3_GRAY,
2595   EL_GATE_4_GRAY,
2596
2597   EL_ARROW_LEFT,
2598   EL_ARROW_RIGHT,
2599   EL_ARROW_UP,
2600   EL_ARROW_DOWN,
2601
2602   EL_AMOEBA_FULL,
2603   EL_EMERALD_YELLOW,
2604   EL_EMERALD_RED,
2605   EL_EMERALD_PURPLE,
2606
2607   EL_WALL_BD_DIAMOND,
2608   EL_WALL_EMERALD_YELLOW,
2609   EL_WALL_EMERALD_RED,
2610   EL_WALL_EMERALD_PURPLE,
2611
2612   EL_GAME_OF_LIFE,
2613   EL_PACMAN_UP,
2614   EL_TIME_ORB_FULL,
2615   EL_TIME_ORB_EMPTY,
2616
2617   EL_PACMAN_LEFT,
2618   EL_DARK_YAMYAM,
2619   EL_PACMAN_RIGHT,
2620   EL_EXPANDABLE_WALL,
2621
2622   EL_BIOMAZE,
2623   EL_PACMAN_DOWN,
2624   EL_LAMP,
2625   EL_LAMP_ACTIVE,
2626
2627   EL_DYNABOMB_INCREASE_NUMBER,
2628   EL_DYNABOMB_INCREASE_SIZE,
2629   EL_DYNABOMB_INCREASE_POWER,
2630   EL_STONEBLOCK,
2631
2632   EL_MOLE,
2633   EL_PENGUIN,
2634   EL_PIG,
2635   EL_DRAGON,
2636
2637   EL_BUG,
2638   EL_MOLE_UP,
2639   EL_BD_BUTTERFLY,
2640   EL_BD_FIREFLY,
2641
2642   EL_MOLE_LEFT,
2643   EL_EMPTY,
2644   EL_MOLE_RIGHT,
2645   EL_PACMAN,
2646
2647   EL_SPACESHIP,
2648   EL_MOLE_DOWN,
2649   EL_BALLOON,
2650   EL_BALLOON_SWITCH_ANY,
2651
2652   EL_BALLOON_SWITCH_LEFT,
2653   EL_BALLOON_SWITCH_RIGHT,
2654   EL_BALLOON_SWITCH_UP,
2655   EL_BALLOON_SWITCH_DOWN,
2656
2657   EL_SATELLITE,
2658   EL_EXPANDABLE_WALL_HORIZONTAL,
2659   EL_EXPANDABLE_WALL_VERTICAL,
2660   EL_EXPANDABLE_WALL_ANY,
2661
2662   EL_INVISIBLE_STEELWALL,
2663   EL_INVISIBLE_WALL,
2664   EL_SPEED_PILL,
2665   EL_BLACK_ORB,
2666
2667   EL_EMC_STEELWALL_1,
2668   EL_EMC_WALL_1,
2669   EL_EMC_WALL_2,
2670   EL_EMC_WALL_3,
2671
2672   EL_EMC_WALL_4,
2673   EL_EMC_WALL_5,
2674   EL_EMC_WALL_6,
2675   EL_EMC_WALL_7,
2676 };
2677 static int *editor_hl_more_ptr = editor_hl_more;
2678 static int *editor_el_more_ptr = editor_el_more;
2679 static int num_editor_hl_more = SIZEOF_ARRAY_INT(editor_hl_more);
2680 static int num_editor_el_more = SIZEOF_ARRAY_INT(editor_el_more);
2681
2682 static int editor_hl_sokoban[] =
2683 {
2684   EL_CHAR('S'),
2685   EL_CHAR('O'),
2686   EL_CHAR('K'),
2687   EL_CHAR('O'),
2688
2689   EL_CHAR('-'),
2690   EL_CHAR('B'),
2691   EL_CHAR('A'),
2692   EL_CHAR('N'),
2693 };
2694
2695 static int editor_el_sokoban[] =
2696 {
2697   EL_SOKOBAN_OBJECT,
2698   EL_SOKOBAN_FIELD_EMPTY,
2699   EL_SOKOBAN_FIELD_FULL,
2700   EL_SOKOBAN_FIELD_PLAYER,
2701 };
2702 static int *editor_hl_sokoban_ptr = editor_hl_sokoban;
2703 static int *editor_el_sokoban_ptr = editor_el_sokoban;
2704 static int num_editor_hl_sokoban = SIZEOF_ARRAY_INT(editor_hl_sokoban);
2705 static int num_editor_el_sokoban = SIZEOF_ARRAY_INT(editor_el_sokoban);
2706
2707 static int editor_hl_supaplex[] =
2708 {
2709   EL_CHAR('S'),
2710   EL_CHAR('U'),
2711   EL_CHAR('P'),
2712   EL_CHAR('A'),
2713
2714   EL_CHAR('P'),
2715   EL_CHAR('L'),
2716   EL_CHAR('E'),
2717   EL_CHAR('X'),
2718 };
2719
2720 static int editor_el_supaplex[] =
2721 {
2722 #if 1
2723   EL_EMPTY,
2724 #else
2725   EL_SP_EMPTY,
2726 #endif
2727   EL_SP_ZONK,
2728   EL_SP_BASE,
2729   EL_SP_MURPHY,
2730
2731   EL_SP_INFOTRON,
2732   EL_SP_CHIP_SINGLE,
2733   EL_SP_HARDWARE_GRAY,
2734   EL_SP_EXIT_CLOSED,
2735
2736   EL_SP_DISK_ORANGE,
2737   EL_SP_PORT_RIGHT,
2738   EL_SP_PORT_DOWN,
2739   EL_SP_PORT_LEFT,
2740
2741   EL_SP_PORT_UP,
2742   EL_SP_GRAVITY_PORT_RIGHT,
2743   EL_SP_GRAVITY_PORT_DOWN,
2744   EL_SP_GRAVITY_PORT_LEFT,
2745
2746   EL_SP_GRAVITY_PORT_UP,
2747   EL_SP_SNIKSNAK,
2748   EL_SP_DISK_YELLOW,
2749   EL_SP_TERMINAL,
2750
2751   EL_SP_DISK_RED,
2752   EL_SP_PORT_VERTICAL,
2753   EL_SP_PORT_HORIZONTAL,
2754   EL_SP_PORT_ANY,
2755
2756   EL_SP_ELECTRON,
2757   EL_SP_BUGGY_BASE,
2758   EL_SP_CHIP_LEFT,
2759   EL_SP_CHIP_RIGHT,
2760
2761   EL_SP_HARDWARE_BASE_1,
2762   EL_SP_HARDWARE_GREEN,
2763   EL_SP_HARDWARE_BLUE,
2764   EL_SP_HARDWARE_RED,
2765
2766   EL_SP_HARDWARE_YELLOW,
2767   EL_SP_HARDWARE_BASE_2,
2768   EL_SP_HARDWARE_BASE_3,
2769   EL_SP_HARDWARE_BASE_4,
2770
2771   EL_SP_HARDWARE_BASE_5,
2772   EL_SP_HARDWARE_BASE_6,
2773   EL_SP_CHIP_TOP,
2774   EL_SP_CHIP_BOTTOM,
2775 };
2776 static int *editor_hl_supaplex_ptr = editor_hl_supaplex;
2777 static int *editor_el_supaplex_ptr = editor_el_supaplex;
2778 static int num_editor_hl_supaplex = SIZEOF_ARRAY_INT(editor_hl_supaplex);
2779 static int num_editor_el_supaplex = SIZEOF_ARRAY_INT(editor_el_supaplex);
2780
2781 static int editor_hl_diamond_caves[] =
2782 {
2783   EL_CHAR('D'),
2784   EL_CHAR('I'),
2785   EL_CHAR('A'),
2786   EL_CHAR('-'),
2787
2788   EL_CHAR('M'),
2789   EL_CHAR('O'),
2790   EL_CHAR('N'),
2791   EL_CHAR('D'),
2792
2793   EL_CHAR('C'),
2794   EL_CHAR('A'),
2795   EL_CHAR('V'),
2796   EL_CHAR('E'),
2797
2798   EL_CHAR('S'),
2799   EL_CHAR(' '),
2800   EL_CHAR('I'),
2801   EL_CHAR('I'),
2802 };
2803
2804 static int editor_el_diamond_caves[] =
2805 {
2806   EL_PEARL,
2807   EL_CRYSTAL,
2808   EL_WALL_PEARL,
2809   EL_WALL_CRYSTAL,
2810
2811   EL_CONVEYOR_BELT_1_LEFT,
2812   EL_CONVEYOR_BELT_1_MIDDLE,
2813   EL_CONVEYOR_BELT_1_RIGHT,
2814   EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2815
2816   EL_CONVEYOR_BELT_2_LEFT,
2817   EL_CONVEYOR_BELT_2_MIDDLE,
2818   EL_CONVEYOR_BELT_2_RIGHT,
2819   EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2820
2821   EL_CONVEYOR_BELT_3_LEFT,
2822   EL_CONVEYOR_BELT_3_MIDDLE,
2823   EL_CONVEYOR_BELT_3_RIGHT,
2824   EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2825
2826   EL_CONVEYOR_BELT_4_LEFT,
2827   EL_CONVEYOR_BELT_4_MIDDLE,
2828   EL_CONVEYOR_BELT_4_RIGHT,
2829   EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2830
2831   EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2832   EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2833   EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2834   EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2835
2836   EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2837   EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2838   EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2839   EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2840
2841   EL_SWITCHGATE_OPEN,
2842   EL_SWITCHGATE_CLOSED,
2843   EL_SWITCHGATE_SWITCH_UP,
2844   EL_EMPTY,
2845
2846   EL_ENVELOPE_1,
2847   EL_ENVELOPE_2,
2848   EL_ENVELOPE_3,
2849   EL_ENVELOPE_4,
2850
2851   EL_TIMEGATE_CLOSED,
2852   EL_TIMEGATE_OPEN,
2853   EL_TIMEGATE_SWITCH,
2854   EL_EMPTY,
2855
2856   EL_LANDMINE,
2857   EL_INVISIBLE_SAND,
2858   EL_STEELWALL_SLIPPERY,
2859   EL_EMPTY,
2860
2861   EL_SIGN_EXCLAMATION,
2862   EL_SIGN_STOP,
2863   EL_LIGHT_SWITCH,
2864   EL_LIGHT_SWITCH_ACTIVE,
2865
2866   EL_SHIELD_NORMAL,
2867   EL_SHIELD_DEADLY,
2868   EL_EXTRA_TIME,
2869   EL_EMPTY,
2870 };
2871 static int *editor_hl_diamond_caves_ptr = editor_hl_diamond_caves;
2872 static int *editor_el_diamond_caves_ptr = editor_el_diamond_caves;
2873 static int num_editor_hl_diamond_caves = SIZEOF_ARRAY_INT(editor_hl_diamond_caves);
2874 static int num_editor_el_diamond_caves = SIZEOF_ARRAY_INT(editor_el_diamond_caves);
2875
2876 static int editor_hl_dx_boulderdash[] =
2877 {
2878   EL_CHAR('D'),
2879   EL_CHAR('X'),
2880   EL_CHAR('-'),
2881   EL_CHAR(' '),
2882
2883   EL_CHAR('B'),
2884   EL_CHAR('O'),
2885   EL_CHAR('U'),
2886   EL_CHAR('L'),
2887
2888   EL_CHAR('-'),
2889   EL_CHAR('D'),
2890   EL_CHAR('E'),
2891   EL_CHAR('R'),
2892
2893   EL_CHAR('D'),
2894   EL_CHAR('A'),
2895   EL_CHAR('S'),
2896   EL_CHAR('H'),
2897 };
2898
2899 static int editor_el_dx_boulderdash[] =
2900 {
2901   EL_SPRING,
2902   EL_TUBE_RIGHT_DOWN,
2903   EL_TUBE_HORIZONTAL_DOWN,
2904   EL_TUBE_LEFT_DOWN,
2905
2906   EL_TUBE_HORIZONTAL,
2907   EL_TUBE_VERTICAL_RIGHT,
2908   EL_TUBE_ANY,
2909   EL_TUBE_VERTICAL_LEFT,
2910
2911   EL_TUBE_VERTICAL,
2912   EL_TUBE_RIGHT_UP,
2913   EL_TUBE_HORIZONTAL_UP,
2914   EL_TUBE_LEFT_UP,
2915
2916   EL_TRAP,
2917   EL_DX_SUPABOMB,
2918   EL_EMPTY,
2919   EL_EMPTY
2920 };
2921 static int *editor_hl_dx_boulderdash_ptr = editor_hl_dx_boulderdash;
2922 static int *editor_el_dx_boulderdash_ptr = editor_el_dx_boulderdash;
2923 static int num_editor_hl_dx_boulderdash = SIZEOF_ARRAY_INT(editor_hl_dx_boulderdash);
2924 static int num_editor_el_dx_boulderdash = SIZEOF_ARRAY_INT(editor_el_dx_boulderdash);
2925
2926 static int editor_hl_chars[] =
2927 {
2928   EL_CHAR('T'),
2929   EL_CHAR('E'),
2930   EL_CHAR('X'),
2931   EL_CHAR('T'),
2932 };
2933
2934 static int editor_el_chars[] =
2935 {
2936   EL_CHAR(' '),
2937   EL_CHAR('!'),
2938   EL_CHAR('"'),
2939   EL_CHAR('#'),
2940
2941   EL_CHAR('$'),
2942   EL_CHAR('%'),
2943   EL_CHAR('&'),
2944   EL_CHAR('\''),
2945
2946   EL_CHAR('('),
2947   EL_CHAR(')'),
2948   EL_CHAR('*'),
2949   EL_CHAR('+'),
2950
2951   EL_CHAR(','),
2952   EL_CHAR('-'),
2953   EL_CHAR('.'),
2954   EL_CHAR('/'),
2955
2956   EL_CHAR('0'),
2957   EL_CHAR('1'),
2958   EL_CHAR('2'),
2959   EL_CHAR('3'),
2960
2961   EL_CHAR('4'),
2962   EL_CHAR('5'),
2963   EL_CHAR('6'),
2964   EL_CHAR('7'),
2965
2966   EL_CHAR('8'),
2967   EL_CHAR('9'),
2968   EL_CHAR(':'),
2969   EL_CHAR(';'),
2970
2971   EL_CHAR('<'),
2972   EL_CHAR('='),
2973   EL_CHAR('>'),
2974   EL_CHAR('?'),
2975
2976   EL_CHAR('@'),
2977   EL_CHAR('A'),
2978   EL_CHAR('B'),
2979   EL_CHAR('C'),
2980
2981   EL_CHAR('D'),
2982   EL_CHAR('E'),
2983   EL_CHAR('F'),
2984   EL_CHAR('G'),
2985
2986   EL_CHAR('H'),
2987   EL_CHAR('I'),
2988   EL_CHAR('J'),
2989   EL_CHAR('K'),
2990
2991   EL_CHAR('L'),
2992   EL_CHAR('M'),
2993   EL_CHAR('N'),
2994   EL_CHAR('O'),
2995
2996   EL_CHAR('P'),
2997   EL_CHAR('Q'),
2998   EL_CHAR('R'),
2999   EL_CHAR('S'),
3000
3001   EL_CHAR('T'),
3002   EL_CHAR('U'),
3003   EL_CHAR('V'),
3004   EL_CHAR('W'),
3005
3006   EL_CHAR('X'),
3007   EL_CHAR('Y'),
3008   EL_CHAR('Z'),
3009   EL_CHAR('['),
3010
3011   EL_CHAR('\\'),
3012   EL_CHAR(']'),
3013   EL_CHAR('^'),
3014   EL_CHAR('_'),
3015
3016   EL_CHAR('©'),
3017   EL_CHAR('Ä'),
3018   EL_CHAR('Ö'),
3019   EL_CHAR('Ãœ'),
3020
3021   EL_CHAR('°'),
3022   EL_CHAR('®'),
3023   EL_CHAR(FONT_ASCII_CURSOR),
3024   EL_CHAR(' ')
3025 };
3026 static int *editor_hl_chars_ptr = editor_hl_chars;
3027 static int *editor_el_chars_ptr = editor_el_chars;
3028 static int num_editor_hl_chars = SIZEOF_ARRAY_INT(editor_hl_chars);
3029 static int num_editor_el_chars = SIZEOF_ARRAY_INT(editor_el_chars);
3030
3031 static int editor_hl_custom[] =
3032 {
3033   EL_CHAR('C'),
3034   EL_CHAR('U'),
3035   EL_CHAR('S'),
3036   EL_CHAR('-'),
3037
3038   EL_CHAR('T'),
3039   EL_CHAR('O'),
3040   EL_CHAR('M'),
3041   EL_CHAR(' '),
3042
3043   EL_CHAR('E'),
3044   EL_CHAR('L'),
3045   EL_CHAR('E'),
3046   EL_CHAR('M'),
3047
3048   EL_CHAR('E'),
3049   EL_CHAR('N'),
3050   EL_CHAR('T'),
3051   EL_CHAR('S'),
3052 };
3053
3054 static int editor_el_custom[] =
3055 {
3056   EL_CUSTOM_START + 0,
3057   EL_CUSTOM_START + 1,
3058   EL_CUSTOM_START + 2,
3059   EL_CUSTOM_START + 3,
3060
3061   EL_CUSTOM_START + 4,
3062   EL_CUSTOM_START + 5,
3063   EL_CUSTOM_START + 6,
3064   EL_CUSTOM_START + 7,
3065
3066   EL_CUSTOM_START + 8,
3067   EL_CUSTOM_START + 9,
3068   EL_CUSTOM_START + 10,
3069   EL_CUSTOM_START + 11,
3070
3071   EL_CUSTOM_START + 12,
3072   EL_CUSTOM_START + 13,
3073   EL_CUSTOM_START + 14,
3074   EL_CUSTOM_START + 15,
3075
3076   EL_CUSTOM_START + 16,
3077   EL_CUSTOM_START + 17,
3078   EL_CUSTOM_START + 18,
3079   EL_CUSTOM_START + 19,
3080
3081   EL_CUSTOM_START + 20,
3082   EL_CUSTOM_START + 21,
3083   EL_CUSTOM_START + 22,
3084   EL_CUSTOM_START + 23,
3085
3086   EL_CUSTOM_START + 24,
3087   EL_CUSTOM_START + 25,
3088   EL_CUSTOM_START + 26,
3089   EL_CUSTOM_START + 27,
3090
3091   EL_CUSTOM_START + 28,
3092   EL_CUSTOM_START + 29,
3093   EL_CUSTOM_START + 30,
3094   EL_CUSTOM_START + 31,
3095
3096   EL_CUSTOM_START + 32,
3097   EL_CUSTOM_START + 33,
3098   EL_CUSTOM_START + 34,
3099   EL_CUSTOM_START + 35,
3100
3101   EL_CUSTOM_START + 36,
3102   EL_CUSTOM_START + 37,
3103   EL_CUSTOM_START + 38,
3104   EL_CUSTOM_START + 39,
3105
3106   EL_CUSTOM_START + 40,
3107   EL_CUSTOM_START + 41,
3108   EL_CUSTOM_START + 42,
3109   EL_CUSTOM_START + 43,
3110
3111   EL_CUSTOM_START + 44,
3112   EL_CUSTOM_START + 45,
3113   EL_CUSTOM_START + 46,
3114   EL_CUSTOM_START + 47,
3115
3116   EL_CUSTOM_START + 48,
3117   EL_CUSTOM_START + 49,
3118   EL_CUSTOM_START + 50,
3119   EL_CUSTOM_START + 51,
3120
3121   EL_CUSTOM_START + 52,
3122   EL_CUSTOM_START + 53,
3123   EL_CUSTOM_START + 54,
3124   EL_CUSTOM_START + 55,
3125
3126   EL_CUSTOM_START + 56,
3127   EL_CUSTOM_START + 57,
3128   EL_CUSTOM_START + 58,
3129   EL_CUSTOM_START + 59,
3130
3131   EL_CUSTOM_START + 60,
3132   EL_CUSTOM_START + 61,
3133   EL_CUSTOM_START + 62,
3134   EL_CUSTOM_START + 63,
3135
3136   EL_CUSTOM_START + 64,
3137   EL_CUSTOM_START + 65,
3138   EL_CUSTOM_START + 66,
3139   EL_CUSTOM_START + 67,
3140
3141   EL_CUSTOM_START + 68,
3142   EL_CUSTOM_START + 69,
3143   EL_CUSTOM_START + 70,
3144   EL_CUSTOM_START + 71,
3145
3146   EL_CUSTOM_START + 72,
3147   EL_CUSTOM_START + 73,
3148   EL_CUSTOM_START + 74,
3149   EL_CUSTOM_START + 75,
3150
3151   EL_CUSTOM_START + 76,
3152   EL_CUSTOM_START + 77,
3153   EL_CUSTOM_START + 78,
3154   EL_CUSTOM_START + 79,
3155
3156   EL_CUSTOM_START + 80,
3157   EL_CUSTOM_START + 81,
3158   EL_CUSTOM_START + 82,
3159   EL_CUSTOM_START + 83,
3160
3161   EL_CUSTOM_START + 84,
3162   EL_CUSTOM_START + 85,
3163   EL_CUSTOM_START + 86,
3164   EL_CUSTOM_START + 87,
3165
3166   EL_CUSTOM_START + 88,
3167   EL_CUSTOM_START + 89,
3168   EL_CUSTOM_START + 90,
3169   EL_CUSTOM_START + 91,
3170
3171   EL_CUSTOM_START + 92,
3172   EL_CUSTOM_START + 93,
3173   EL_CUSTOM_START + 94,
3174   EL_CUSTOM_START + 95,
3175
3176   EL_CUSTOM_START + 96,
3177   EL_CUSTOM_START + 97,
3178   EL_CUSTOM_START + 98,
3179   EL_CUSTOM_START + 99,
3180
3181   EL_CUSTOM_START + 100,
3182   EL_CUSTOM_START + 101,
3183   EL_CUSTOM_START + 102,
3184   EL_CUSTOM_START + 103,
3185
3186   EL_CUSTOM_START + 104,
3187   EL_CUSTOM_START + 105,
3188   EL_CUSTOM_START + 106,
3189   EL_CUSTOM_START + 107,
3190
3191   EL_CUSTOM_START + 108,
3192   EL_CUSTOM_START + 109,
3193   EL_CUSTOM_START + 110,
3194   EL_CUSTOM_START + 111,
3195
3196   EL_CUSTOM_START + 112,
3197   EL_CUSTOM_START + 113,
3198   EL_CUSTOM_START + 114,
3199   EL_CUSTOM_START + 115,
3200
3201   EL_CUSTOM_START + 116,
3202   EL_CUSTOM_START + 117,
3203   EL_CUSTOM_START + 118,
3204   EL_CUSTOM_START + 119,
3205
3206   EL_CUSTOM_START + 120,
3207   EL_CUSTOM_START + 121,
3208   EL_CUSTOM_START + 122,
3209   EL_CUSTOM_START + 123,
3210
3211   EL_CUSTOM_START + 124,
3212   EL_CUSTOM_START + 125,
3213   EL_CUSTOM_START + 126,
3214   EL_CUSTOM_START + 127
3215 };
3216 static int *editor_hl_custom_ptr = editor_hl_custom;
3217 static int *editor_el_custom_ptr = editor_el_custom;
3218 static int num_editor_hl_custom = SIZEOF_ARRAY_INT(editor_hl_custom);
3219 static int num_editor_el_custom = SIZEOF_ARRAY_INT(editor_el_custom);
3220
3221 static int editor_hl_custom_more[] =
3222 {
3223 };
3224
3225 static int editor_el_custom_more[] =
3226 {
3227   EL_CUSTOM_START + 128,
3228   EL_CUSTOM_START + 129,
3229   EL_CUSTOM_START + 130,
3230   EL_CUSTOM_START + 131,
3231
3232   EL_CUSTOM_START + 132,
3233   EL_CUSTOM_START + 133,
3234   EL_CUSTOM_START + 134,
3235   EL_CUSTOM_START + 135,
3236
3237   EL_CUSTOM_START + 136,
3238   EL_CUSTOM_START + 137,
3239   EL_CUSTOM_START + 138,
3240   EL_CUSTOM_START + 139,
3241
3242   EL_CUSTOM_START + 140,
3243   EL_CUSTOM_START + 141,
3244   EL_CUSTOM_START + 142,
3245   EL_CUSTOM_START + 143,
3246
3247   EL_CUSTOM_START + 144,
3248   EL_CUSTOM_START + 145,
3249   EL_CUSTOM_START + 146,
3250   EL_CUSTOM_START + 147,
3251
3252   EL_CUSTOM_START + 148,
3253   EL_CUSTOM_START + 149,
3254   EL_CUSTOM_START + 150,
3255   EL_CUSTOM_START + 151,
3256
3257   EL_CUSTOM_START + 152,
3258   EL_CUSTOM_START + 153,
3259   EL_CUSTOM_START + 154,
3260   EL_CUSTOM_START + 155,
3261
3262   EL_CUSTOM_START + 156,
3263   EL_CUSTOM_START + 157,
3264   EL_CUSTOM_START + 158,
3265   EL_CUSTOM_START + 159,
3266
3267   EL_CUSTOM_START + 160,
3268   EL_CUSTOM_START + 161,
3269   EL_CUSTOM_START + 162,
3270   EL_CUSTOM_START + 163,
3271
3272   EL_CUSTOM_START + 164,
3273   EL_CUSTOM_START + 165,
3274   EL_CUSTOM_START + 166,
3275   EL_CUSTOM_START + 167,
3276
3277   EL_CUSTOM_START + 168,
3278   EL_CUSTOM_START + 169,
3279   EL_CUSTOM_START + 170,
3280   EL_CUSTOM_START + 171,
3281
3282   EL_CUSTOM_START + 172,
3283   EL_CUSTOM_START + 173,
3284   EL_CUSTOM_START + 174,
3285   EL_CUSTOM_START + 175,
3286
3287   EL_CUSTOM_START + 176,
3288   EL_CUSTOM_START + 177,
3289   EL_CUSTOM_START + 178,
3290   EL_CUSTOM_START + 179,
3291
3292   EL_CUSTOM_START + 180,
3293   EL_CUSTOM_START + 181,
3294   EL_CUSTOM_START + 182,
3295   EL_CUSTOM_START + 183,
3296
3297   EL_CUSTOM_START + 184,
3298   EL_CUSTOM_START + 185,
3299   EL_CUSTOM_START + 186,
3300   EL_CUSTOM_START + 187,
3301
3302   EL_CUSTOM_START + 188,
3303   EL_CUSTOM_START + 189,
3304   EL_CUSTOM_START + 190,
3305   EL_CUSTOM_START + 191,
3306
3307   EL_CUSTOM_START + 192,
3308   EL_CUSTOM_START + 193,
3309   EL_CUSTOM_START + 194,
3310   EL_CUSTOM_START + 195,
3311
3312   EL_CUSTOM_START + 196,
3313   EL_CUSTOM_START + 197,
3314   EL_CUSTOM_START + 198,
3315   EL_CUSTOM_START + 199,
3316
3317   EL_CUSTOM_START + 200,
3318   EL_CUSTOM_START + 201,
3319   EL_CUSTOM_START + 202,
3320   EL_CUSTOM_START + 203,
3321
3322   EL_CUSTOM_START + 204,
3323   EL_CUSTOM_START + 205,
3324   EL_CUSTOM_START + 206,
3325   EL_CUSTOM_START + 207,
3326
3327   EL_CUSTOM_START + 208,
3328   EL_CUSTOM_START + 209,
3329   EL_CUSTOM_START + 210,
3330   EL_CUSTOM_START + 211,
3331
3332   EL_CUSTOM_START + 212,
3333   EL_CUSTOM_START + 213,
3334   EL_CUSTOM_START + 214,
3335   EL_CUSTOM_START + 215,
3336
3337   EL_CUSTOM_START + 216,
3338   EL_CUSTOM_START + 217,
3339   EL_CUSTOM_START + 218,
3340   EL_CUSTOM_START + 219,
3341
3342   EL_CUSTOM_START + 220,
3343   EL_CUSTOM_START + 221,
3344   EL_CUSTOM_START + 222,
3345   EL_CUSTOM_START + 223,
3346
3347   EL_CUSTOM_START + 224,
3348   EL_CUSTOM_START + 225,
3349   EL_CUSTOM_START + 226,
3350   EL_CUSTOM_START + 227,
3351
3352   EL_CUSTOM_START + 228,
3353   EL_CUSTOM_START + 229,
3354   EL_CUSTOM_START + 230,
3355   EL_CUSTOM_START + 231,
3356
3357   EL_CUSTOM_START + 232,
3358   EL_CUSTOM_START + 233,
3359   EL_CUSTOM_START + 234,
3360   EL_CUSTOM_START + 235,
3361
3362   EL_CUSTOM_START + 236,
3363   EL_CUSTOM_START + 237,
3364   EL_CUSTOM_START + 238,
3365   EL_CUSTOM_START + 239,
3366
3367   EL_CUSTOM_START + 240,
3368   EL_CUSTOM_START + 241,
3369   EL_CUSTOM_START + 242,
3370   EL_CUSTOM_START + 243,
3371
3372   EL_CUSTOM_START + 244,
3373   EL_CUSTOM_START + 245,
3374   EL_CUSTOM_START + 246,
3375   EL_CUSTOM_START + 247,
3376
3377   EL_CUSTOM_START + 248,
3378   EL_CUSTOM_START + 249,
3379   EL_CUSTOM_START + 250,
3380   EL_CUSTOM_START + 251,
3381
3382   EL_CUSTOM_START + 252,
3383   EL_CUSTOM_START + 253,
3384   EL_CUSTOM_START + 254,
3385   EL_CUSTOM_START + 255
3386 };
3387 static int *editor_hl_custom_more_ptr = editor_hl_custom_more;
3388 static int *editor_el_custom_more_ptr = editor_el_custom_more;
3389 static int num_editor_hl_custom_more = SIZEOF_ARRAY_INT(editor_hl_custom_more);
3390 static int num_editor_el_custom_more = SIZEOF_ARRAY_INT(editor_el_custom_more);
3391
3392 static int editor_hl_custom_special[] =
3393 {
3394 };
3395
3396 static int editor_el_custom_special[] =
3397 {
3398   EL_TRIGGER_ELEMENT,
3399   EL_TRIGGER_PLAYER,
3400   EL_EMPTY,
3401   EL_EMPTY
3402 };
3403 static int *editor_hl_custom_special_ptr = editor_hl_custom_special;
3404 static int *editor_el_custom_special_ptr = editor_el_custom_special;
3405 static int num_editor_hl_custom_special = SIZEOF_ARRAY_INT(editor_hl_custom_special);
3406 static int num_editor_el_custom_special = SIZEOF_ARRAY_INT(editor_el_custom_special);
3407
3408 static int editor_hl_group[] =
3409 {
3410   EL_CHAR('G'),
3411   EL_CHAR('R'),
3412   EL_CHAR('O'),
3413   EL_CHAR('U'),
3414
3415   EL_CHAR('P'),
3416   EL_CHAR(' '),
3417   EL_CHAR(' '),
3418   EL_CHAR(' '),
3419
3420   EL_CHAR('E'),
3421   EL_CHAR('L'),
3422   EL_CHAR('E'),
3423   EL_CHAR('M'),
3424
3425   EL_CHAR('E'),
3426   EL_CHAR('N'),
3427   EL_CHAR('T'),
3428   EL_CHAR('S'),
3429 };
3430
3431 static int editor_el_group[] =
3432 {
3433   EL_GROUP_START + 0,
3434   EL_GROUP_START + 1,
3435   EL_GROUP_START + 2,
3436   EL_GROUP_START + 3,
3437
3438   EL_GROUP_START + 4,
3439   EL_GROUP_START + 5,
3440   EL_GROUP_START + 6,
3441   EL_GROUP_START + 7,
3442
3443   EL_GROUP_START + 8,
3444   EL_GROUP_START + 9,
3445   EL_GROUP_START + 10,
3446   EL_GROUP_START + 11,
3447
3448   EL_GROUP_START + 12,
3449   EL_GROUP_START + 13,
3450   EL_GROUP_START + 14,
3451   EL_GROUP_START + 15
3452 };
3453 static int *editor_hl_group_ptr = editor_hl_group;
3454 static int *editor_el_group_ptr = editor_el_group;
3455 static int num_editor_hl_group = SIZEOF_ARRAY_INT(editor_hl_group);
3456 static int num_editor_el_group = SIZEOF_ARRAY_INT(editor_el_group);
3457
3458 static int editor_hl_group_more[] =
3459 {
3460 };
3461
3462 static int editor_el_group_more[] =
3463 {
3464   EL_GROUP_START + 16,
3465   EL_GROUP_START + 17,
3466   EL_GROUP_START + 18,
3467   EL_GROUP_START + 19,
3468
3469   EL_GROUP_START + 20,
3470   EL_GROUP_START + 21,
3471   EL_GROUP_START + 22,
3472   EL_GROUP_START + 23,
3473
3474   EL_GROUP_START + 24,
3475   EL_GROUP_START + 25,
3476   EL_GROUP_START + 26,
3477   EL_GROUP_START + 27,
3478
3479   EL_GROUP_START + 28,
3480   EL_GROUP_START + 29,
3481   EL_GROUP_START + 30,
3482   EL_GROUP_START + 31
3483 };
3484 static int *editor_hl_group_more_ptr = editor_hl_group_more;
3485 static int *editor_el_group_more_ptr = editor_el_group_more;
3486 static int num_editor_hl_group_more = SIZEOF_ARRAY_INT(editor_hl_group_more);
3487 static int num_editor_el_group_more = SIZEOF_ARRAY_INT(editor_el_group_more);
3488
3489 static int editor_hl_user_defined[] =
3490 {
3491   EL_CHAR('U'),
3492   EL_CHAR('S'),
3493   EL_CHAR('E'),
3494   EL_CHAR('R'),
3495
3496   EL_CHAR('D'),
3497   EL_CHAR('E'),
3498   EL_CHAR('F'),
3499   EL_CHAR('I'),
3500
3501   EL_CHAR('-'),
3502   EL_CHAR('N'),
3503   EL_CHAR('E'),
3504   EL_CHAR('D'),
3505 };
3506
3507 static int *editor_hl_user_defined_ptr = editor_hl_user_defined;
3508 static int *editor_el_user_defined_ptr = NULL;
3509 static int num_editor_hl_user_defined=SIZEOF_ARRAY_INT(editor_hl_user_defined);
3510 static int num_editor_el_user_defined = 0;
3511
3512 static int editor_hl_empty[] = { };
3513 static int editor_el_empty[ED_NUM_ELEMENTLIST_BUTTONS];
3514
3515 static int *editor_hl_empty_ptr = editor_hl_empty;
3516 static int *editor_el_empty_ptr = editor_el_empty;
3517 static int num_editor_hl_empty = 0;
3518 static int num_editor_el_empty = 0;     /* dynamically determined, if needed */
3519
3520 static boolean use_el_empty = FALSE;
3521
3522 static int *editor_elements = NULL;     /* dynamically allocated */
3523 static int num_editor_elements = 0;     /* dynamically determined */
3524
3525 static struct
3526 {
3527   boolean *setup_value;
3528
3529   int **headline_list;
3530   int *headline_list_size;
3531
3532   int **element_list;
3533   int *element_list_size;
3534
3535   boolean last_setup_value;
3536 }
3537 editor_elements_info[] =
3538 {
3539   {
3540     &setup.editor.el_boulderdash,
3541     &editor_hl_boulderdash_ptr,         &num_editor_hl_boulderdash,
3542     &editor_el_boulderdash_ptr,         &num_editor_el_boulderdash
3543   },
3544   {
3545     &setup.editor.el_emerald_mine,
3546     &editor_hl_emerald_mine_ptr,        &num_editor_hl_emerald_mine,
3547     &editor_el_emerald_mine_ptr,        &num_editor_el_emerald_mine
3548   },
3549   {
3550     &setup.editor.el_more,
3551     &editor_hl_more_ptr,                &num_editor_hl_more,
3552     &editor_el_more_ptr,                &num_editor_el_more
3553   },
3554   {
3555     &setup.editor.el_sokoban,
3556     &editor_hl_sokoban_ptr,             &num_editor_hl_sokoban,
3557     &editor_el_sokoban_ptr,             &num_editor_el_sokoban
3558   },
3559   {
3560     &setup.editor.el_supaplex,
3561     &editor_hl_supaplex_ptr,            &num_editor_hl_supaplex,
3562     &editor_el_supaplex_ptr,            &num_editor_el_supaplex
3563   },
3564   {
3565     &setup.editor.el_diamond_caves,
3566     &editor_hl_diamond_caves_ptr,       &num_editor_hl_diamond_caves,
3567     &editor_el_diamond_caves_ptr,       &num_editor_el_diamond_caves
3568   },
3569   {
3570     &setup.editor.el_dx_boulderdash,
3571     &editor_hl_dx_boulderdash_ptr,      &num_editor_hl_dx_boulderdash,
3572     &editor_el_dx_boulderdash_ptr,      &num_editor_el_dx_boulderdash
3573   },
3574   {
3575     &setup.editor.el_chars,
3576     &editor_hl_chars_ptr,               &num_editor_hl_chars,
3577     &editor_el_chars_ptr,               &num_editor_el_chars
3578   },
3579   {
3580     &setup.editor.el_custom,
3581     &editor_hl_custom_ptr,              &num_editor_hl_custom,
3582     &editor_el_custom_ptr,              &num_editor_el_custom
3583   },
3584   {
3585     &setup.editor.el_custom_more,
3586     &editor_hl_custom_more_ptr,         &num_editor_hl_custom_more,
3587     &editor_el_custom_more_ptr,         &num_editor_el_custom_more
3588   },
3589   {
3590     &setup.editor.el_custom,
3591     &editor_hl_custom_special_ptr,      &num_editor_hl_custom_special,
3592     &editor_el_custom_special_ptr,      &num_editor_el_custom_special
3593   },
3594   {
3595     &setup.editor.el_custom,
3596     &editor_hl_group_ptr,               &num_editor_hl_group,
3597     &editor_el_group_ptr,               &num_editor_el_group
3598   },
3599   {
3600     &setup.editor.el_custom_more,
3601     &editor_hl_group_more_ptr,          &num_editor_hl_group_more,
3602     &editor_el_group_more_ptr,          &num_editor_el_group_more
3603   },
3604   {
3605     &setup.editor.el_user_defined,
3606     &editor_hl_user_defined_ptr,        &num_editor_hl_user_defined,
3607     &editor_el_user_defined_ptr,        &num_editor_el_user_defined
3608   },
3609   {
3610     &use_el_empty,
3611     &editor_hl_empty_ptr,               &num_editor_hl_empty,
3612     &editor_el_empty_ptr,               &num_editor_el_empty,
3613   },
3614   {
3615     NULL,
3616     NULL,                               NULL,
3617     NULL,                               NULL
3618   }
3619 };
3620
3621 #if 0
3622
3623 static struct
3624 {
3625   short element;
3626   short element_mapped;
3627 }
3628 forum_sketch_element_mapping[] =
3629 {
3630   { EL_WALL_SLIPPERY,                   EL_WALL                 },
3631   { EL_EXPANDABLE_WALL,                 EL_WALL                 },
3632   { EL_EXPANDABLE_WALL_HORIZONTAL,      EL_WALL                 },
3633   { EL_EXPANDABLE_WALL_VERTICAL,        EL_WALL                 },
3634   { EL_EXPANDABLE_WALL_ANY,             EL_WALL                 },
3635   { EL_WALL_EMERALD,                    EL_WALL                 },
3636   { EL_WALL_DIAMOND,                    EL_WALL                 },
3637   { EL_WALL_BD_DIAMOND,                 EL_WALL                 },
3638   { EL_WALL_EMERALD_YELLOW,             EL_WALL                 },
3639   { EL_WALL_EMERALD_RED,                EL_WALL                 },
3640   { EL_WALL_EMERALD_PURPLE,             EL_WALL                 },
3641   { EL_ACID_POOL_TOPLEFT,               EL_WALL                 },
3642   { EL_ACID_POOL_TOPRIGHT,              EL_WALL                 },
3643   { EL_ACID_POOL_BOTTOMLEFT,            EL_WALL                 },
3644   { EL_ACID_POOL_BOTTOM,                EL_WALL                 },
3645   { EL_ACID_POOL_BOTTOMRIGHT,           EL_WALL                 },
3646   { EL_BD_WALL,                         EL_WALL                 },
3647
3648   { EL_BD_ROCK,                         EL_ROCK                 },
3649
3650   { EL_SP_ZONK,                         EL_ROCK                 },
3651   { EL_SP_BASE,                         EL_SAND                 },
3652   { EL_SP_MURPHY,                       EL_PLAYER_1             },
3653   { EL_SP_INFOTRON,                     EL_EMERALD              },
3654   { EL_SP_HARDWARE_GRAY,                EL_STEELWALL            },
3655   { EL_SP_EXIT_CLOSED,                  EL_EXIT_OPEN            },
3656   { EL_SP_DISK_ORANGE,                  EL_BOMB                 },
3657   { EL_SP_DISK_RED,                     EL_BOMB                 },
3658   { EL_SP_DISK_YELLOW,                  EL_BOMB                 },
3659   { EL_SP_PORT_RIGHT,                   EL_GATE_1_GRAY          },
3660   { EL_SP_PORT_DOWN,                    EL_GATE_1_GRAY          },
3661   { EL_SP_PORT_LEFT,                    EL_GATE_1_GRAY          },
3662   { EL_SP_PORT_UP,                      EL_GATE_1_GRAY          },
3663   { EL_SP_GRAVITY_PORT_RIGHT,           EL_GATE_1_GRAY          },
3664   { EL_SP_GRAVITY_PORT_DOWN,            EL_GATE_1_GRAY          },
3665   { EL_SP_GRAVITY_PORT_LEFT,            EL_GATE_1_GRAY          },
3666   { EL_SP_GRAVITY_PORT_UP,              EL_GATE_1_GRAY          },
3667   { EL_SP_PORT_VERTICAL,                EL_GATE_1_GRAY          },
3668   { EL_SP_PORT_HORIZONTAL,              EL_GATE_1_GRAY          },
3669   { EL_SP_PORT_ANY,                     EL_GATE_1_GRAY          },
3670   { EL_SP_SNIKSNAK,                     EL_BUG                  },
3671   { EL_SP_ELECTRON,                     EL_SPACESHIP            },
3672   { EL_SP_CHIP_SINGLE,                  EL_WALL                 },
3673   { EL_SP_CHIP_LEFT,                    EL_WALL                 },
3674   { EL_SP_CHIP_RIGHT,                   EL_WALL                 },
3675   { EL_SP_CHIP_TOP,                     EL_WALL                 },
3676   { EL_SP_CHIP_BOTTOM,                  EL_WALL                 },
3677   { EL_SP_HARDWARE_BASE_1,              EL_STEELWALL            },
3678   { EL_SP_HARDWARE_GREEN,               EL_STEELWALL            },
3679   { EL_SP_HARDWARE_BLUE,                EL_STEELWALL            },
3680   { EL_SP_HARDWARE_RED,                 EL_STEELWALL            },
3681   { EL_SP_HARDWARE_YELLOW,              EL_STEELWALL            },
3682   { EL_SP_HARDWARE_BASE_2,              EL_STEELWALL            },
3683   { EL_SP_HARDWARE_BASE_3,              EL_STEELWALL            },
3684   { EL_SP_HARDWARE_BASE_3,              EL_STEELWALL            },
3685   { EL_SP_HARDWARE_BASE_4,              EL_STEELWALL            },
3686   { EL_SP_HARDWARE_BASE_5,              EL_STEELWALL            },
3687   { EL_SP_HARDWARE_BASE_6,              EL_STEELWALL            },
3688
3689   { EL_STEELWALL_SLIPPERY,              EL_STEELWALL            },
3690
3691   { EL_EXIT_CLOSED,                     EL_EXIT_OPEN            },
3692
3693   { EL_DIAMOND,                         EL_EMERALD              },
3694   { EL_BD_DIAMOND,                      EL_EMERALD              },
3695   { EL_EMERALD_YELLOW,                  EL_EMERALD              },
3696   { EL_EMERALD_RED,                     EL_EMERALD              },
3697   { EL_EMERALD_PURPLE,                  EL_EMERALD              },
3698
3699   { EL_AMOEBA_DEAD,                     EL_AMOEBA               },
3700   { EL_AMOEBA_DROP,                     EL_AMOEBA               },
3701   { EL_AMOEBA_WET,                      EL_AMOEBA               },
3702   { EL_AMOEBA_DRY,                      EL_AMOEBA               },
3703   { EL_AMOEBA_FULL,                     EL_AMOEBA               },
3704   { EL_BD_AMOEBA,                       EL_AMOEBA               },
3705   { EL_AMOEBA_TO_DIAMOND,               EL_AMOEBA               },
3706
3707   { EL_DYNAMITE_ACTIVE,                 EL_DYNAMITE             },
3708
3709   { EL_GATE_2_GRAY,                     EL_GATE_1_GRAY          },
3710   { EL_GATE_3_GRAY,                     EL_GATE_1_GRAY          },
3711   { EL_GATE_4_GRAY,                     EL_GATE_1_GRAY          },
3712
3713   { EL_EM_KEY_1,                        EL_KEY_1                },
3714   { EL_EM_KEY_2,                        EL_KEY_2                },
3715   { EL_EM_KEY_3,                        EL_KEY_3                },
3716   { EL_EM_KEY_4,                        EL_KEY_4                },
3717
3718   { EL_EM_GATE_1,                       EL_GATE_1               },
3719   { EL_EM_GATE_2,                       EL_GATE_2               },
3720   { EL_EM_GATE_3,                       EL_GATE_3               },
3721   { EL_EM_GATE_4,                       EL_GATE_4               },
3722
3723   { EL_EM_GATE_1_GRAY,                  EL_GATE_1_GRAY          },
3724   { EL_EM_GATE_2_GRAY,                  EL_GATE_1_GRAY          },
3725   { EL_EM_GATE_3_GRAY,                  EL_GATE_1_GRAY          },
3726   { EL_EM_GATE_4_GRAY,                  EL_GATE_1_GRAY          },
3727
3728   { EL_INVISIBLE_SAND,                  EL_EMPTY                },
3729   { EL_INVISIBLE_WALL,                  EL_EMPTY                },
3730   { EL_INVISIBLE_STEELWALL,             EL_EMPTY                },
3731
3732   { EL_PACMAN,                          EL_YAMYAM               },
3733   { EL_DARK_YAMYAM,                     EL_YAMYAM               },
3734
3735   { EL_BD_MAGIC_WALL,                   EL_MAGIC_WALL           },
3736
3737   { EL_DYNABOMB_INCREASE_NUMBER,        EL_BOMB                 },
3738   { EL_DYNABOMB_INCREASE_SIZE,          EL_BOMB                 },
3739   { EL_DYNABOMB_INCREASE_POWER,         EL_BOMB                 },
3740   { EL_BLACK_ORB,                       EL_BOMB                 },
3741   { EL_DX_SUPABOMB,                     EL_BOMB                 },
3742
3743   { EL_SOKOBAN_OBJECT,                  EL_KEY_1                },
3744   { EL_SOKOBAN_FIELD_EMPTY,             EL_GATE_1_GRAY          },
3745   { EL_SOKOBAN_FIELD_FULL,              EL_GATE_1               },
3746   { EL_SOKOBAN_FIELD_PLAYER,            EL_PLAYER_1             },
3747
3748   { EL_BD_BUTTERFLY_RIGHT,              EL_BD_BUTTERFLY         },
3749   { EL_BD_BUTTERFLY_UP,                 EL_BD_BUTTERFLY         },
3750   { EL_BD_BUTTERFLY_LEFT,               EL_BD_BUTTERFLY         },
3751   { EL_BD_BUTTERFLY_DOWN,               EL_BD_BUTTERFLY         },
3752
3753   { EL_BD_FIREFLY_RIGHT,                EL_BD_FIREFLY           },
3754   { EL_BD_FIREFLY_UP,                   EL_BD_FIREFLY           },
3755   { EL_BD_FIREFLY_LEFT,                 EL_BD_FIREFLY           },
3756   { EL_BD_FIREFLY_DOWN,                 EL_BD_FIREFLY           },
3757
3758   { EL_PLAYER_2,                        EL_PLAYER_1             },
3759   { EL_PLAYER_3,                        EL_PLAYER_1             },
3760   { EL_PLAYER_4,                        EL_PLAYER_1             },
3761
3762   { EL_BUG_RIGHT,                       EL_BUG                  },
3763   { EL_BUG_UP,                          EL_BUG                  },
3764   { EL_BUG_LEFT,                        EL_BUG                  },
3765   { EL_BUG_DOWN,                        EL_BUG                  },
3766
3767   { EL_SPACESHIP_RIGHT,                 EL_SPACESHIP            },
3768   { EL_SPACESHIP_UP,                    EL_SPACESHIP            },
3769   { EL_SPACESHIP_LEFT,                  EL_SPACESHIP            },
3770   { EL_SPACESHIP_DOWN,                  EL_SPACESHIP            },
3771
3772   { EL_PACMAN_RIGHT,                    EL_YAMYAM               },
3773   { EL_PACMAN_UP,                       EL_YAMYAM               },
3774   { EL_PACMAN_LEFT,                     EL_YAMYAM               },
3775   { EL_PACMAN_DOWN,                     EL_YAMYAM               },
3776
3777   { -1,                                 -1                      }
3778 };
3779
3780 static struct
3781 {
3782   short element;
3783   char *element_string;
3784 }
3785 forum_sketch_element_strings[] =
3786 {
3787   { EL_PLAYER_1,                "p" },
3788   { EL_EMPTY,                   "_" },
3789   { EL_SAND,                    "s" },
3790   { EL_ROCK,                    "b" },
3791   { EL_EMERALD,                 "e" },
3792   { EL_BUG,                     "u" },
3793   { EL_SPACESHIP,               "h" },
3794   { EL_BD_FIREFLY,              "f" },
3795   { EL_BD_BUTTERFLY,            "b" },
3796   { EL_AMOEBA,                  "a" },
3797   { EL_YAMYAM,                  "y" },
3798   { EL_WALL,                    "w" },
3799   { EL_STEELWALL,               "t" },
3800   { EL_MAGIC_WALL,              "m" },
3801   { EL_EXIT_OPEN,               "x" },
3802   { EL_DYNAMITE,                "d" },
3803   { EL_KEY_1,                   "1" },
3804   { EL_KEY_2,                   "2" },
3805   { EL_KEY_3,                   "3" },
3806   { EL_KEY_4,                   "4" },
3807   { EL_GATE_1,                  "5" },
3808   { EL_GATE_2,                  "6" },
3809   { EL_GATE_3,                  "7" },
3810   { EL_GATE_4,                  "8" },
3811   { EL_GATE_1_GRAY,             "9" },
3812   { EL_BOMB,                    "@" },
3813   { EL_ROBOT,                   "r" },
3814   { EL_ROBOT_WHEEL,             "0" },
3815   { EL_NUT,                     "n" },
3816   { EL_CUSTOM_1,                "c" },
3817   { EL_CHAR_QUESTION,           "?" },
3818
3819   { -1,                         NULL }
3820 };
3821
3822 #endif
3823
3824
3825 /*
3826   -----------------------------------------------------------------------------
3827   functions
3828   -----------------------------------------------------------------------------
3829 */
3830
3831 static int getMaxInfoTextLength()
3832 {
3833   return (SXSIZE / getFontWidth(FONT_TEXT_2));
3834 }
3835
3836 static int getTextWidthForGadget(char *text)
3837 {
3838   if (text == NULL)
3839     return 0;
3840
3841   return (getTextWidth(text, FONT_TEXT_1) + ED_GADGET_TEXT_DISTANCE);
3842 }
3843
3844 static int getTextWidthForDrawingArea(char *text)
3845 {
3846   if (text == NULL)
3847     return 0;
3848
3849   return (getTextWidth(text, FONT_TEXT_1) + ED_DRAWINGAREA_TEXT_DISTANCE);
3850 }
3851
3852 static int getRightGadgetBorder(struct GadgetInfo *gi, char *text)
3853 {
3854   return (gi->x + gi->width + getTextWidthForGadget(text));
3855 }
3856
3857 static char *getElementInfoText(int element)
3858 {
3859   char *info_text = NULL;
3860
3861   if (element < NUM_FILE_ELEMENTS)
3862   {
3863     if (strlen(element_info[element].description) > 0)
3864       info_text = element_info[element].description;
3865     else if (element_info[element].custom_description != NULL)
3866       info_text = element_info[element].custom_description;
3867     else if (element_info[element].editor_description != NULL)
3868       info_text = element_info[element].editor_description;
3869   }
3870
3871   if (info_text == NULL)
3872     info_text = INFOTEXT_UNKNOWN_ELEMENT;
3873
3874   return info_text;
3875 }
3876
3877 static void ReinitializeElementList()
3878 {
3879   static boolean initialized = FALSE;
3880   int pos = 0;
3881   int i, j;
3882
3883   checked_free(editor_elements);
3884
3885   if (!initialized)
3886   {
3887     /* initialize optional user defined element list */
3888     LoadUserDefinedEditorElementList(&editor_el_user_defined_ptr,
3889                                      &num_editor_el_user_defined);
3890
3891     /* initialize list of empty elements (used for padding, if needed) */
3892     for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
3893       editor_el_empty[i] = EL_EMPTY;
3894
3895     /* do some sanity checks for each element from element list */
3896     for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
3897     {
3898       for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
3899       {
3900         int element = (*editor_elements_info[i].element_list)[j];
3901
3902         if (element >= NUM_FILE_ELEMENTS)
3903           Error(ERR_WARN, "editor element %d is runtime element", element);
3904
3905         if (strcmp(getElementInfoText(element), INFOTEXT_UNKNOWN_ELEMENT) == 0)
3906           Error(ERR_WARN, "no element description for element %d", element);
3907       }
3908     }
3909
3910     initialized = TRUE;
3911   }
3912
3913   num_editor_elements = 0;
3914   use_el_empty = FALSE;
3915
3916   /* determine size of element list */
3917   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
3918   {
3919     if (*editor_elements_info[i].setup_value)
3920     {
3921       if (setup.editor.el_headlines)
3922         num_editor_elements += *editor_elements_info[i].headline_list_size;
3923
3924       num_editor_elements += *editor_elements_info[i].element_list_size;
3925     }
3926   }
3927
3928   if (num_editor_elements < ED_NUM_ELEMENTLIST_BUTTONS)
3929   {
3930     /* offer at least as many elements as element buttons exist */
3931     use_el_empty = TRUE;
3932     num_editor_el_empty = ED_NUM_ELEMENTLIST_BUTTONS - num_editor_elements;
3933
3934     num_editor_elements += num_editor_el_empty;
3935   }
3936
3937   editor_elements = checked_malloc(num_editor_elements * sizeof(int));
3938
3939   /* fill element list */
3940   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
3941   {
3942     if (*editor_elements_info[i].setup_value)
3943     {
3944       if (setup.editor.el_headlines)
3945         for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
3946           editor_elements[pos++] = (*editor_elements_info[i].headline_list)[j];
3947
3948       for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
3949         editor_elements[pos++] = (*editor_elements_info[i].element_list)[j];
3950     }
3951   }
3952
3953   /* correct position of element list scrollbar */
3954   if (element_shift < 0)
3955     element_shift = 0;
3956   if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
3957     element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
3958 }
3959
3960 void PrintEditorElementList()
3961 {
3962   boolean *stop = &setup.editor.el_user_defined;
3963   int i, j;
3964
3965   for (i = 0; editor_elements_info[i].setup_value != stop; i++)
3966   {
3967     for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
3968     {
3969       int element = (*editor_elements_info[i].headline_list)[j];
3970
3971       printf("# %s\n", element_info[element].token_name);
3972     }
3973
3974     if (j > 0)
3975       printf("#\n");
3976
3977     for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
3978     {
3979       int element = (*editor_elements_info[i].element_list)[j];
3980
3981       printf("# %s\n", element_info[element].token_name);
3982     }
3983
3984     if (j > 0)
3985       printf("#\n");
3986   }
3987 }
3988
3989 static void ReinitializeElementListButtons()
3990 {
3991   static boolean last_setup_value_headlines = FALSE;
3992   static boolean initialization_needed = TRUE;
3993   int i;
3994
3995   if (!initialization_needed)   /* check if editor element setup has changed */
3996   {
3997     if (last_setup_value_headlines != setup.editor.el_headlines)
3998       initialization_needed = TRUE;
3999
4000     for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
4001       if (editor_elements_info[i].last_setup_value !=
4002           *editor_elements_info[i].setup_value)
4003         initialization_needed = TRUE;
4004   }
4005
4006   if (!initialization_needed)
4007     return;
4008
4009   FreeLevelEditorGadgets();
4010   CreateLevelEditorGadgets();
4011
4012   /* store current setup values for next invocation of this function */
4013   last_setup_value_headlines = setup.editor.el_headlines;
4014   for (i = 0; editor_elements_info[i].setup_value != NULL; i++)
4015     editor_elements_info[i].last_setup_value =
4016       *editor_elements_info[i].setup_value;
4017
4018   initialization_needed = FALSE;
4019 }
4020
4021 static void DrawElementBorder(int dest_x, int dest_y, int width, int height,
4022                               boolean input)
4023 {
4024   int border_graphic =
4025     (input ? IMG_EDITOR_ELEMENT_BORDER_INPUT : IMG_EDITOR_ELEMENT_BORDER);
4026   Bitmap *src_bitmap;
4027   int src_x, src_y;
4028   int num_mini_tilex = width  / MINI_TILEX + 1;
4029   int num_mini_tiley = height / MINI_TILEY + 1;
4030   int x, y;
4031
4032   getMiniGraphicSource(border_graphic, &src_bitmap, &src_x, &src_y);
4033
4034   for (y = 0; y < num_mini_tiley; y++)
4035     for (x = 0; x < num_mini_tilex; x++)
4036       BlitBitmap(src_bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
4037                  dest_x - MINI_TILEX / 2 + x * MINI_TILEX,
4038                  dest_y - MINI_TILEY / 2 + y * MINI_TILEY);
4039
4040   ClearRectangle(drawto, dest_x - 1, dest_y - 1, width + 2, height + 2);
4041 }
4042
4043 static void DrawDrawingArea(int id)
4044 {
4045   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
4046   int x, y;
4047
4048   if (id == ED_DRAWING_ID_RANDOM_BACKGROUND)
4049     DrawMiniGraphicExt(drawto, gi->x, gi->y,
4050                        el2edimg(random_placement_background_element));
4051   else if (id == ED_DRAWING_ID_AMOEBA_CONTENT)
4052     DrawMiniGraphicExt(drawto, gi->x, gi->y, el2edimg(level.amoeba_content));
4053   else if (id == ED_DRAWING_ID_CUSTOM_GRAPHIC)
4054     DrawMiniGraphicExt(drawto, gi->x, gi->y,
4055                        el2edimg(custom_element.gfx_element));
4056   else if (id == ED_DRAWING_ID_CUSTOM_CONTENT)
4057     for (y = 0; y < 3; y++)
4058       for (x = 0; x < 3; x++)
4059         DrawMiniGraphicExt(drawto,
4060                            gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
4061                            el2edimg(custom_element.content[x][y]));
4062   else if (id == ED_DRAWING_ID_CUSTOM_MOVE_ENTER)
4063     DrawMiniGraphicExt(drawto, gi->x, gi->y,
4064                        el2edimg(custom_element.move_enter_element));
4065   else if (id == ED_DRAWING_ID_CUSTOM_MOVE_LEAVE)
4066     DrawMiniGraphicExt(drawto, gi->x, gi->y,
4067                        el2edimg(custom_element.move_leave_element));
4068   else if (id == ED_DRAWING_ID_CUSTOM_CHANGE_TARGET)
4069     DrawMiniGraphicExt(drawto, gi->x, gi->y,
4070                        el2edimg(custom_element_change.target_element));
4071   else if (id == ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT)
4072     for (y = 0; y < 3; y++)
4073       for (x = 0; x < 3; x++)
4074         DrawMiniGraphicExt(drawto,
4075                            gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
4076                            el2edimg(custom_element_change.target_content[x][y]));
4077   else if (id == ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER)
4078     DrawMiniGraphicExt(drawto, gi->x, gi->y,
4079                        el2edimg(custom_element_change.trigger_element));
4080   else if (id == ED_DRAWING_ID_GROUP_CONTENT)
4081     for (x = 0; x < group_element_info.num_elements; x++)
4082       DrawMiniGraphicExt(drawto, gi->x + x * MINI_TILEX, gi->y,
4083                          el2edimg(group_element_info.element[x]));
4084   else if (id >= ED_DRAWING_ID_ELEMENT_CONTENT_0 &&
4085            id <= ED_DRAWING_ID_ELEMENT_CONTENT_7)
4086   {
4087     int nr = id - ED_DRAWING_ID_ELEMENT_CONTENT_0;
4088
4089     for (y = 0; y < 3; y++)
4090       for (x = 0; x < 3; x++)
4091         DrawMiniGraphicExt(drawto,
4092                            gi->x + x * MINI_TILEX, gi->y + y * MINI_TILEY,
4093                            el2edimg(level.yamyam_content[nr][x][y]));
4094   }
4095 }
4096
4097 static void ScrollMiniLevel(int from_x, int from_y, int scroll)
4098 {
4099   int x,y;
4100   int dx = (scroll == ED_SCROLL_LEFT ? -1 : scroll == ED_SCROLL_RIGHT ? 1 : 0);
4101   int dy = (scroll == ED_SCROLL_UP   ? -1 : scroll == ED_SCROLL_DOWN  ? 1 : 0);
4102
4103   BlitBitmap(drawto, drawto,
4104              SX + (dx == -1 ? MINI_TILEX : 0),
4105              SY + (dy == -1 ? MINI_TILEY : 0),
4106              (ed_fieldx * MINI_TILEX) - (dx != 0 ? MINI_TILEX : 0),
4107              (ed_fieldy * MINI_TILEY) - (dy != 0 ? MINI_TILEY : 0),
4108              SX + (dx == +1 ? MINI_TILEX : 0),
4109              SY + (dy == +1 ? MINI_TILEY : 0));
4110   if (dx)
4111   {
4112     x = (dx == 1 ? 0 : ed_fieldx - 1);
4113     for (y = 0; y < ed_fieldy; y++)
4114       DrawMiniElementOrWall(x, y, from_x, from_y);
4115   }
4116   else if (dy)
4117   {
4118     y = (dy == 1 ? 0 : ed_fieldy - 1);
4119     for (x = 0; x < ed_fieldx; x++)
4120       DrawMiniElementOrWall(x, y, from_x, from_y);
4121   }
4122
4123   redraw_mask |= REDRAW_FIELD;
4124   BackToFront();
4125 }
4126
4127 static void CreateControlButtons()
4128 {
4129   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4130   struct GadgetInfo *gi;
4131   unsigned long event_mask;
4132   int i;
4133
4134   /* create toolbox buttons */
4135   for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
4136   {
4137     int id = i;
4138     int width, height;
4139     int gd_xoffset, gd_yoffset;
4140     int gd_x1, gd_x2, gd_y1, gd_y2;
4141     int button_type;
4142     int radio_button_nr;
4143     boolean checked;
4144
4145     if (id == GADGET_ID_SINGLE_ITEMS ||
4146         id == GADGET_ID_CONNECTED_ITEMS ||
4147         id == GADGET_ID_LINE ||
4148         id == GADGET_ID_ARC ||
4149         id == GADGET_ID_TEXT ||
4150         id == GADGET_ID_RECTANGLE ||
4151         id == GADGET_ID_FILLED_BOX ||
4152         id == GADGET_ID_FLOOD_FILL ||
4153         id == GADGET_ID_GRAB_BRUSH ||
4154         id == GADGET_ID_PICK_ELEMENT ||
4155         id == GADGET_ID_CUSTOM_COPY_FROM ||
4156         id == GADGET_ID_CUSTOM_COPY_TO ||
4157         id == GADGET_ID_CUSTOM_EXCHANGE)
4158     {
4159       button_type = GD_TYPE_RADIO_BUTTON;
4160       radio_button_nr = RADIO_NR_DRAWING_TOOLBOX;
4161       checked = (id == drawing_function ? TRUE : FALSE);
4162       event_mask = GD_EVENT_PRESSED;
4163     }
4164     else
4165     {
4166       button_type = GD_TYPE_NORMAL_BUTTON;
4167       radio_button_nr = RADIO_NR_NONE;
4168       checked = FALSE;
4169
4170       if (id == GADGET_ID_WRAP_LEFT ||
4171           id == GADGET_ID_WRAP_RIGHT ||
4172           id == GADGET_ID_WRAP_UP ||
4173           id == GADGET_ID_WRAP_DOWN)
4174         event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4175       else
4176         event_mask = GD_EVENT_RELEASED;
4177     }
4178
4179     if (id < ED_NUM_CTRL1_BUTTONS)
4180     {
4181       int x = i % ED_CTRL1_BUTTONS_HORIZ;
4182       int y = i / ED_CTRL1_BUTTONS_HORIZ;
4183
4184       gd_xoffset = ED_CTRL1_BUTTONS_XPOS + x * ED_CTRL1_BUTTON_XSIZE;
4185       gd_yoffset = ED_CTRL1_BUTTONS_YPOS + y * ED_CTRL1_BUTTON_YSIZE;
4186       width  = ED_CTRL1_BUTTON_XSIZE;
4187       height = ED_CTRL1_BUTTON_YSIZE;
4188
4189       gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
4190       gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
4191       gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL1_BUTTONS_GFX_YPOS     + gd_yoffset;
4192       gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL1_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
4193     }
4194     else if (id < ED_NUM_CTRL1_2_BUTTONS)
4195     {
4196       int x = (i - ED_NUM_CTRL1_BUTTONS) % ED_CTRL2_BUTTONS_HORIZ;
4197       int y = (i - ED_NUM_CTRL1_BUTTONS) / ED_CTRL2_BUTTONS_HORIZ;
4198
4199       gd_xoffset = ED_CTRL2_BUTTONS_XPOS + x * ED_CTRL2_BUTTON_XSIZE;
4200       gd_yoffset = ED_CTRL2_BUTTONS_YPOS + y * ED_CTRL2_BUTTON_YSIZE;
4201       width  = ED_CTRL2_BUTTON_XSIZE;
4202       height = ED_CTRL2_BUTTON_YSIZE;
4203
4204       gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
4205       gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
4206       gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL2_BUTTONS_GFX_YPOS + gd_yoffset;
4207       gd_y2 = 0;        /* no alternative graphic for these buttons */
4208     }
4209     else if (id < ED_NUM_CTRL1_3_BUTTONS)
4210     {
4211       int x = (i - ED_NUM_CTRL1_2_BUTTONS) % ED_CTRL3_BUTTONS_HORIZ + 1;
4212       int y = (i - ED_NUM_CTRL1_2_BUTTONS) / ED_CTRL3_BUTTONS_HORIZ;
4213
4214       gd_xoffset = ED_CTRL3_BUTTONS_XPOS + x * ED_CTRL3_BUTTON_XSIZE;
4215       gd_yoffset = ED_CTRL3_BUTTONS_YPOS + y * ED_CTRL3_BUTTON_YSIZE;
4216       width  = ED_CTRL3_BUTTON_XSIZE;
4217       height = ED_CTRL3_BUTTON_YSIZE;
4218
4219       gd_x1 = DOOR_GFX_PAGEX6 + gd_xoffset;
4220       gd_x2 = DOOR_GFX_PAGEX5 + gd_xoffset;
4221       gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL3_BUTTONS_GFX_YPOS     + gd_yoffset;
4222       gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL3_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
4223     }
4224     else
4225     {
4226       int x = (i - ED_NUM_CTRL1_3_BUTTONS) % ED_CTRL4_BUTTONS_HORIZ;
4227       int y = (i - ED_NUM_CTRL1_3_BUTTONS) / ED_CTRL4_BUTTONS_HORIZ + 3;
4228
4229       gd_xoffset = ED_CTRL4_BUTTONS_XPOS + x * ED_CTRL4_BUTTON_XSIZE;
4230       gd_yoffset = ED_CTRL4_BUTTONS_YPOS + y * ED_CTRL4_BUTTON_YSIZE;
4231       width  = ED_CTRL4_BUTTON_XSIZE;
4232       height = ED_CTRL4_BUTTON_YSIZE;
4233
4234       gd_x1 = DOOR_GFX_PAGEX6 + ED_CTRL4_BUTTONS_GFX_XPOS + gd_xoffset;
4235       gd_x2 = DOOR_GFX_PAGEX5 + ED_CTRL4_BUTTONS_GFX_XPOS + gd_xoffset;
4236       gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL4_BUTTONS_GFX_YPOS + gd_yoffset;
4237       gd_y2 = 0;        /* no alternative graphic for these buttons */
4238     }
4239
4240     gi = CreateGadget(GDI_CUSTOM_ID, id,
4241                       GDI_CUSTOM_TYPE_ID, i,
4242                       GDI_INFO_TEXT, control_info[i].text,
4243                       GDI_X, EX + gd_xoffset,
4244                       GDI_Y, EY + gd_yoffset,
4245                       GDI_WIDTH, width,
4246                       GDI_HEIGHT, height,
4247                       GDI_TYPE, button_type,
4248                       GDI_STATE, GD_BUTTON_UNPRESSED,
4249                       GDI_RADIO_NR, radio_button_nr,
4250                       GDI_CHECKED, checked,
4251                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
4252                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
4253                       GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
4254                       GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
4255                       GDI_EVENT_MASK, event_mask,
4256                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4257                       GDI_CALLBACK_ACTION, HandleControlButtons,
4258                       GDI_END);
4259
4260     if (gi == NULL)
4261       Error(ERR_EXIT, "cannot create gadget");
4262
4263     level_editor_gadget[id] = gi;
4264   }
4265
4266   /* create buttons for scrolling of drawing area and element list */
4267   for (i = 0; i < ED_NUM_SCROLLBUTTONS; i++)
4268   {
4269     int id = scrollbutton_info[i].gadget_id;
4270     int x, y, width, height;
4271     int gd_x1, gd_x2, gd_y1, gd_y2;
4272
4273     x = scrollbutton_info[i].x;
4274     y = scrollbutton_info[i].y;
4275
4276     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4277
4278     if (id == GADGET_ID_SCROLL_LIST_UP ||
4279         id == GADGET_ID_SCROLL_LIST_DOWN)
4280     {
4281       x += DX;
4282       y += DY;
4283       width = ED_SCROLLBUTTON2_XSIZE;
4284       height = ED_SCROLLBUTTON2_YSIZE;
4285       gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x;
4286       gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y;
4287       gd_x2 = gd_x1 - ED_SCROLLBUTTON2_XSIZE;
4288       gd_y2 = gd_y1;
4289     }
4290     else
4291     {
4292       x += SX;
4293       y += SY;
4294       width = ED_SCROLLBUTTON_XSIZE;
4295       height = ED_SCROLLBUTTON_YSIZE;
4296       gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x;
4297       gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y;
4298       gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
4299       gd_y2 = gd_y1;
4300     }
4301
4302     gi = CreateGadget(GDI_CUSTOM_ID, id,
4303                       GDI_CUSTOM_TYPE_ID, i,
4304                       GDI_INFO_TEXT, scrollbutton_info[i].infotext,
4305                       GDI_X, x,
4306                       GDI_Y, y,
4307                       GDI_WIDTH, width,
4308                       GDI_HEIGHT, height,
4309                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4310                       GDI_STATE, GD_BUTTON_UNPRESSED,
4311                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
4312                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
4313                       GDI_EVENT_MASK, event_mask,
4314                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4315                       GDI_CALLBACK_ACTION, HandleControlButtons,
4316                       GDI_END);
4317
4318     if (gi == NULL)
4319       Error(ERR_EXIT, "cannot create gadget");
4320
4321     level_editor_gadget[id] = gi;
4322   }
4323
4324   /* create buttons for element list */
4325   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
4326   {
4327     Bitmap *deco_bitmap;
4328     int deco_x, deco_y, deco_xpos, deco_ypos;
4329     int gd_xoffset, gd_yoffset;
4330     int gd_x1, gd_x2, gd_y;
4331     int x = i % ED_ELEMENTLIST_BUTTONS_HORIZ;
4332     int y = i / ED_ELEMENTLIST_BUTTONS_HORIZ;
4333     int id = GADGET_ID_ELEMENTLIST_FIRST + i;
4334     int element = editor_elements[i];
4335
4336     event_mask = GD_EVENT_RELEASED;
4337
4338     gd_xoffset = ED_ELEMENTLIST_XPOS + x * ED_ELEMENTLIST_XSIZE;
4339     gd_yoffset = ED_ELEMENTLIST_YPOS + y * ED_ELEMENTLIST_YSIZE;
4340
4341     gd_x1 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS + ED_ELEMENTLIST_XSIZE;
4342     gd_x2 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS;
4343     gd_y  = DOOR_GFX_PAGEY1 + ED_ELEMENTLIST_YPOS;
4344
4345     getMiniGraphicSource(el2edimg(element), &deco_bitmap, &deco_x, &deco_y);
4346     deco_xpos = (ED_ELEMENTLIST_XSIZE - MINI_TILEX) / 2;
4347     deco_ypos = (ED_ELEMENTLIST_YSIZE - MINI_TILEY) / 2;
4348
4349     gi = CreateGadget(GDI_CUSTOM_ID, id,
4350                       GDI_CUSTOM_TYPE_ID, i,
4351                       GDI_INFO_TEXT, getElementInfoText(element),
4352                       GDI_X, DX + gd_xoffset,
4353                       GDI_Y, DY + gd_yoffset,
4354                       GDI_WIDTH, ED_ELEMENTLIST_XSIZE,
4355                       GDI_HEIGHT, ED_ELEMENTLIST_YSIZE,
4356                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4357                       GDI_STATE, GD_BUTTON_UNPRESSED,
4358                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
4359                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
4360                       GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
4361                       GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
4362                       GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY,
4363                       GDI_DECORATION_SHIFTING, 1, 1,
4364                       GDI_EVENT_MASK, event_mask,
4365                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4366                       GDI_CALLBACK_ACTION, HandleControlButtons,
4367                       GDI_END);
4368
4369     if (gi == NULL)
4370       Error(ERR_EXIT, "cannot create gadget");
4371
4372     level_editor_gadget[id] = gi;
4373   }
4374 }
4375
4376 static void CreateCounterButtons()
4377 {
4378   int max_infotext_len = getMaxInfoTextLength();
4379   int i;
4380
4381   for (i = 0; i < ED_NUM_COUNTERBUTTONS; i++)
4382   {
4383     int j;
4384     int x = SX + counterbutton_info[i].x;       /* down count button */
4385     int y = SY + counterbutton_info[i].y;
4386
4387     /* determine horizontal position to the right of specified gadget */
4388     if (counterbutton_info[i].gadget_id_align != GADGET_ID_NONE)
4389       x = (right_gadget_border[counterbutton_info[i].gadget_id_align] +
4390            ED_GADGET_TEXT_DISTANCE);
4391
4392     /* determine horizontal offset for leading text */
4393     if (counterbutton_info[i].text_left != NULL)
4394       x += getTextWidthForGadget(counterbutton_info[i].text_left);
4395
4396     for (j = 0; j < 2; j++)
4397     {
4398       Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4399       struct GadgetInfo *gi;
4400       int id = (j == 0 ?
4401                 counterbutton_info[i].gadget_id_down :
4402                 counterbutton_info[i].gadget_id_up);
4403       int gd_xoffset;
4404       int gd_x, gd_x1, gd_x2, gd_y;
4405       int x_size, y_size;
4406       unsigned long event_mask;
4407       char infotext[max_infotext_len + 1];
4408
4409       event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4410
4411       if (i == ED_COUNTER_ID_SELECT_LEVEL)
4412       {
4413         int sid = (j == 0 ?
4414                    ED_SCROLLBUTTON_ID_AREA_LEFT :
4415                    ED_SCROLLBUTTON_ID_AREA_RIGHT);
4416
4417         event_mask |= GD_EVENT_RELEASED;
4418
4419         if (j == 1)
4420           x += 2 * ED_GADGET_DISTANCE;
4421         y += ED_GADGET_DISTANCE;
4422
4423         gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[sid].gd_x;
4424         gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
4425         gd_y  = DOOR_GFX_PAGEY1 + scrollbutton_info[sid].gd_y;
4426         x_size = ED_SCROLLBUTTON_XSIZE;
4427         y_size = ED_SCROLLBUTTON_YSIZE;
4428       }
4429       else
4430       {
4431         gd_xoffset = (j == 0 ? ED_BUTTON_MINUS_XPOS : ED_BUTTON_PLUS_XPOS);
4432         gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
4433         gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
4434         gd_y  = DOOR_GFX_PAGEY1 + ED_BUTTON_COUNT_YPOS;
4435         x_size = ED_BUTTON_COUNT_XSIZE;
4436         y_size = ED_BUTTON_COUNT_YSIZE;
4437       }
4438
4439       sprintf(infotext, "%s counter value by 1, 5 or 10",
4440               (j == 0 ? "decrease" : "increase"));
4441
4442       gi = CreateGadget(GDI_CUSTOM_ID, id,
4443                         GDI_CUSTOM_TYPE_ID, i,
4444                         GDI_INFO_TEXT, infotext,
4445                         GDI_X, x,
4446                         GDI_Y, y,
4447                         GDI_WIDTH, x_size,
4448                         GDI_HEIGHT, y_size,
4449                         GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4450                         GDI_STATE, GD_BUTTON_UNPRESSED,
4451                         GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
4452                         GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
4453                         GDI_EVENT_MASK, event_mask,
4454                         GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4455                         GDI_CALLBACK_ACTION, HandleCounterButtons,
4456                         GDI_END);
4457
4458       if (gi == NULL)
4459         Error(ERR_EXIT, "cannot create gadget");
4460
4461       level_editor_gadget[id] = gi;
4462       right_gadget_border[id] =
4463         getRightGadgetBorder(gi, counterbutton_info[i].text_right);
4464
4465       x += gi->width + ED_GADGET_DISTANCE;      /* text count button */
4466
4467       if (j == 0)
4468       {
4469         int font_type = FONT_INPUT_1;
4470         int font_type_active = FONT_INPUT_1_ACTIVE;
4471         int gd_width = ED_WIN_COUNT_XSIZE;
4472
4473         id = counterbutton_info[i].gadget_id_text;
4474         event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
4475
4476         if (i == ED_COUNTER_ID_SELECT_LEVEL)
4477         {
4478           font_type = FONT_LEVEL_NUMBER;
4479           font_type_active = FONT_LEVEL_NUMBER;
4480
4481           x += 2 * ED_GADGET_DISTANCE;
4482           y -= ED_GADGET_DISTANCE;
4483
4484           gd_x = DOOR_GFX_PAGEX6 + ED_WIN_COUNT2_XPOS;
4485           gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT2_YPOS;
4486           gd_width = ED_WIN_COUNT2_XSIZE;
4487         }
4488         else
4489         {
4490           gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
4491           gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
4492         }
4493
4494         gi = CreateGadget(GDI_CUSTOM_ID, id,
4495                           GDI_CUSTOM_TYPE_ID, i,
4496                           GDI_INFO_TEXT, "enter counter value",
4497                           GDI_X, x,
4498                           GDI_Y, y,
4499                           GDI_TYPE, GD_TYPE_TEXT_INPUT_NUMERIC,
4500                           GDI_NUMBER_VALUE, 0,
4501                           GDI_NUMBER_MIN, counterbutton_info[i].min_value,
4502                           GDI_NUMBER_MAX, counterbutton_info[i].max_value,
4503                           GDI_TEXT_SIZE, 3,     /* minimal counter text size */
4504                           GDI_TEXT_FONT, font_type,
4505                           GDI_TEXT_FONT_ACTIVE, font_type_active,
4506                           GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
4507                           GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
4508                           GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
4509                           GDI_DESIGN_WIDTH, gd_width,
4510                           GDI_EVENT_MASK, event_mask,
4511                           GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4512                           GDI_CALLBACK_ACTION, HandleCounterButtons,
4513                           GDI_END);
4514
4515         if (gi == NULL)
4516           Error(ERR_EXIT, "cannot create gadget");
4517
4518         level_editor_gadget[id] = gi;
4519         right_gadget_border[id] =
4520           getRightGadgetBorder(gi, counterbutton_info[i].text_right);
4521
4522         x += gi->width + ED_GADGET_DISTANCE;    /* up count button */
4523       }
4524     }
4525   }
4526 }
4527
4528 static void CreateDrawingAreas()
4529 {
4530   int i;
4531
4532   for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
4533   {
4534     struct GadgetInfo *gi;
4535     unsigned long event_mask;
4536     int id = drawingarea_info[i].gadget_id;
4537     int x = SX + drawingarea_info[i].x;
4538     int y = SY + drawingarea_info[i].y;
4539     int area_xsize = drawingarea_info[i].area_xsize;
4540     int area_ysize = drawingarea_info[i].area_ysize;
4541
4542     event_mask =
4543       GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING |
4544       GD_EVENT_OFF_BORDERS;
4545
4546     /* determine horizontal position to the right of specified gadget */
4547     if (drawingarea_info[i].gadget_id_align != GADGET_ID_NONE)
4548       x = (right_gadget_border[drawingarea_info[i].gadget_id_align] +
4549            ED_DRAWINGAREA_TEXT_DISTANCE);
4550
4551     /* determine horizontal offset for leading text */
4552     if (drawingarea_info[i].text_left != NULL)
4553       x += getTextWidthForDrawingArea(drawingarea_info[i].text_left);
4554
4555     gi = CreateGadget(GDI_CUSTOM_ID, id,
4556                       GDI_CUSTOM_TYPE_ID, i,
4557                       GDI_X, x,
4558                       GDI_Y, y,
4559                       GDI_TYPE, GD_TYPE_DRAWING_AREA,
4560                       GDI_AREA_SIZE, area_xsize, area_ysize,
4561                       GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
4562                       GDI_EVENT_MASK, event_mask,
4563                       GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
4564                       GDI_CALLBACK_ACTION, HandleDrawingAreas,
4565                       GDI_END);
4566
4567     if (gi == NULL)
4568       Error(ERR_EXIT, "cannot create gadget");
4569
4570     level_editor_gadget[id] = gi;
4571     right_gadget_border[id] =
4572       getRightGadgetBorder(gi, drawingarea_info[i].text_right);
4573   }
4574 }
4575
4576 static void CreateTextInputGadgets()
4577 {
4578   int max_infotext_len = getMaxInfoTextLength();
4579   int i;
4580
4581   for (i = 0; i < ED_NUM_TEXTINPUT; i++)
4582   {
4583     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4584     int gd_x, gd_y;
4585     struct GadgetInfo *gi;
4586     unsigned long event_mask;
4587     char infotext[MAX_OUTPUT_LINESIZE + 1];
4588     int id = textinput_info[i].gadget_id;
4589
4590     event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
4591
4592     gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
4593     gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
4594
4595     sprintf(infotext, "Enter %s", textinput_info[i].infotext);
4596     infotext[max_infotext_len] = '\0';
4597
4598     gi = CreateGadget(GDI_CUSTOM_ID, id,
4599                       GDI_CUSTOM_TYPE_ID, i,
4600                       GDI_INFO_TEXT, infotext,
4601                       GDI_X, SX + textinput_info[i].x,
4602                       GDI_Y, SY + textinput_info[i].y,
4603                       GDI_TYPE, GD_TYPE_TEXT_INPUT_ALPHANUMERIC,
4604                       GDI_TEXT_VALUE, textinput_info[i].value,
4605                       GDI_TEXT_SIZE, textinput_info[i].size,
4606                       GDI_TEXT_FONT, FONT_INPUT_1,
4607                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
4608                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
4609                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
4610                       GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
4611                       GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
4612                       GDI_EVENT_MASK, event_mask,
4613                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4614                       GDI_CALLBACK_ACTION, HandleTextInputGadgets,
4615                       GDI_END);
4616
4617     if (gi == NULL)
4618       Error(ERR_EXIT, "cannot create gadget");
4619
4620     level_editor_gadget[id] = gi;
4621   }
4622 }
4623
4624 static void CreateTextAreaGadgets()
4625 {
4626   int max_infotext_len = getMaxInfoTextLength();
4627   int i;
4628
4629   for (i = 0; i < ED_NUM_TEXTAREAS; i++)
4630   {
4631     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4632     int gd_x, gd_y;
4633     struct GadgetInfo *gi;
4634     unsigned long event_mask;
4635     char infotext[MAX_OUTPUT_LINESIZE + 1];
4636     int id = textarea_info[i].gadget_id;
4637     int area_xsize = textarea_info[i].xsize;
4638     int area_ysize = textarea_info[i].ysize;
4639
4640     event_mask = GD_EVENT_TEXT_LEAVING;
4641
4642     gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
4643     gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
4644
4645     sprintf(infotext, "Enter %s", textarea_info[i].infotext);
4646     infotext[max_infotext_len] = '\0';
4647
4648     gi = CreateGadget(GDI_CUSTOM_ID, id,
4649                       GDI_CUSTOM_TYPE_ID, i,
4650                       GDI_INFO_TEXT, infotext,
4651                       GDI_X, SX + textarea_info[i].x,
4652                       GDI_Y, SY + textarea_info[i].y,
4653                       GDI_TYPE, GD_TYPE_TEXT_AREA,
4654                       GDI_AREA_SIZE, area_xsize, area_ysize,
4655                       GDI_TEXT_FONT, FONT_INPUT_1,
4656                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
4657                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
4658                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
4659                       GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
4660                       GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
4661                       GDI_EVENT_MASK, event_mask,
4662                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4663                       GDI_CALLBACK_ACTION, HandleTextAreaGadgets,
4664                       GDI_END);
4665
4666     if (gi == NULL)
4667       Error(ERR_EXIT, "cannot create gadget");
4668
4669     level_editor_gadget[id] = gi;
4670   }
4671 }
4672
4673 static void CreateSelectboxGadgets()
4674 {
4675   int max_infotext_len = getMaxInfoTextLength();
4676   int i, j;
4677
4678   for (i = 0; i < ED_NUM_SELECTBOX; i++)
4679   {
4680     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4681     int gd_x, gd_y;
4682     struct GadgetInfo *gi;
4683     unsigned long event_mask;
4684     char infotext[MAX_OUTPUT_LINESIZE + 1];
4685     int id = selectbox_info[i].gadget_id;
4686     int x = SX + selectbox_info[i].x;
4687     int y = SY + selectbox_info[i].y;
4688
4689     if (selectbox_info[i].size == -1)   /* dynamically determine size */
4690     {
4691       /* (we cannot use -1 for uninitialized values if we directly compare
4692          with results from strlen(), because the '<' and '>' operation will
4693          implicitely cast -1 to an unsigned integer value!) */
4694       selectbox_info[i].size = 0;
4695
4696       for (j = 0; selectbox_info[i].options[j].text != NULL; j++)
4697         if (strlen(selectbox_info[i].options[j].text) > selectbox_info[i].size)
4698           selectbox_info[i].size = strlen(selectbox_info[i].options[j].text);
4699
4700       selectbox_info[i].size++;         /* add one character empty space */
4701     }
4702
4703     event_mask = GD_EVENT_RELEASED |
4704       GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
4705
4706     gd_x = DOOR_GFX_PAGEX4 + ED_SELECTBOX_XPOS;
4707     gd_y = DOOR_GFX_PAGEY1 + ED_SELECTBOX_YPOS;
4708
4709     /* determine horizontal position to the right of specified gadget */
4710     if (selectbox_info[i].gadget_id_align != GADGET_ID_NONE)
4711       x = (right_gadget_border[selectbox_info[i].gadget_id_align] +
4712            ED_GADGET_TEXT_DISTANCE);
4713
4714     /* determine horizontal offset for leading text */
4715     if (selectbox_info[i].text_left != NULL)
4716       x += getTextWidthForGadget(selectbox_info[i].text_left);
4717
4718     sprintf(infotext, "Select %s", selectbox_info[i].infotext);
4719     infotext[max_infotext_len] = '\0';
4720
4721     gi = CreateGadget(GDI_CUSTOM_ID, id,
4722                       GDI_CUSTOM_TYPE_ID, i,
4723                       GDI_INFO_TEXT, infotext,
4724                       GDI_X, x,
4725                       GDI_Y, y,
4726                       GDI_TYPE, GD_TYPE_SELECTBOX,
4727                       GDI_SELECTBOX_OPTIONS, selectbox_info[i].options,
4728                       GDI_TEXT_SIZE, selectbox_info[i].size,
4729                       GDI_TEXT_FONT, FONT_INPUT_1,
4730                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_1_ACTIVE,
4731                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
4732                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
4733                       GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
4734                       GDI_BORDER_SIZE_SELECTBUTTON, ED_SELECTBOX_BUTTON_XSIZE,
4735                       GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
4736                       GDI_EVENT_MASK, event_mask,
4737                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4738                       GDI_CALLBACK_ACTION, HandleSelectboxGadgets,
4739                       GDI_END);
4740
4741     if (gi == NULL)
4742       Error(ERR_EXIT, "cannot create gadget");
4743
4744     level_editor_gadget[id] = gi;
4745     right_gadget_border[id] =
4746       getRightGadgetBorder(gi, selectbox_info[i].text_right);
4747   }
4748 }
4749
4750 static void CreateTextbuttonGadgets()
4751 {
4752   int max_infotext_len = getMaxInfoTextLength();
4753   int i;
4754
4755   for (i = 0; i < ED_NUM_TEXTBUTTONS; i++)
4756   {
4757     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4758     int gd_x1, gd_x2, gd_y1, gd_y2;
4759     struct GadgetInfo *gi;
4760     unsigned long event_mask;
4761     char infotext[MAX_OUTPUT_LINESIZE + 1];
4762     int id = textbutton_info[i].gadget_id;
4763     int x = SX + textbutton_info[i].x;
4764     int y = SY + textbutton_info[i].y;
4765
4766     if (textbutton_info[i].size == -1)  /* dynamically determine size */
4767       textbutton_info[i].size = strlen(textbutton_info[i].text);
4768
4769     event_mask = GD_EVENT_RELEASED;
4770
4771     if (id >= GADGET_ID_PROPERTIES_INFO && id <= GADGET_ID_PROPERTIES_CHANGE)
4772     {
4773       gd_x1 = DOOR_GFX_PAGEX4 + ED_TEXTBUTTON_TAB_XPOS;
4774       gd_x2 = DOOR_GFX_PAGEX3 + ED_TEXTBUTTON_TAB_XPOS;
4775       gd_y1 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_TAB_YPOS;
4776       gd_y2 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_TAB_INACTIVE_YPOS;
4777     }
4778     else
4779     {
4780       gd_x1 = DOOR_GFX_PAGEX4 + ED_TEXTBUTTON_XPOS;
4781       gd_x2 = DOOR_GFX_PAGEX3 + ED_TEXTBUTTON_XPOS;
4782       gd_y1 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_YPOS;
4783       gd_y2 = DOOR_GFX_PAGEY1 + ED_TEXTBUTTON_INACTIVE_YPOS;
4784     }
4785
4786     sprintf(infotext, "%s", textbutton_info[i].infotext);
4787     infotext[max_infotext_len] = '\0';
4788
4789     /* determine horizontal position to the right of specified gadget */
4790     if (textbutton_info[i].gadget_id_align != GADGET_ID_NONE)
4791       x = (right_gadget_border[textbutton_info[i].gadget_id_align] +
4792            ED_GADGET_TEXT_DISTANCE);
4793
4794     /* determine horizontal offset for leading text */
4795     if (textbutton_info[i].text_left != NULL)
4796       x += getTextWidthForGadget(textbutton_info[i].text_left);
4797
4798     gi = CreateGadget(GDI_CUSTOM_ID, id,
4799                       GDI_CUSTOM_TYPE_ID, i,
4800                       GDI_INFO_TEXT, infotext,
4801                       GDI_X, x,
4802                       GDI_Y, y,
4803                       GDI_TYPE, GD_TYPE_TEXT_BUTTON,
4804                       GDI_TEXT_VALUE, textbutton_info[i].text,
4805                       GDI_TEXT_SIZE, textbutton_info[i].size,
4806                       GDI_TEXT_FONT, FONT_INPUT_2_ACTIVE,
4807                       GDI_TEXT_FONT_ACTIVE, FONT_INPUT_2,
4808                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
4809                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
4810                       GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
4811                       GDI_BORDER_SIZE, ED_BORDER_TEXT_XSIZE, ED_BORDER_SIZE,
4812                       GDI_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
4813                       GDI_DECORATION_SHIFTING, 1, 1,
4814                       GDI_EVENT_MASK, event_mask,
4815                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4816                       GDI_CALLBACK_ACTION, HandleTextbuttonGadgets,
4817                       GDI_END);
4818
4819     if (gi == NULL)
4820       Error(ERR_EXIT, "cannot create gadget");
4821
4822     level_editor_gadget[id] = gi;
4823     right_gadget_border[id] =
4824       getRightGadgetBorder(gi, textbutton_info[i].text_right);
4825   }
4826 }
4827
4828 static void CreateGraphicbuttonGadgets()
4829 {
4830   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4831   struct GadgetInfo *gi;
4832   unsigned long event_mask;
4833   int i;
4834
4835   /* create buttons for scrolling of drawing area and element list */
4836   for (i = 0; i < ED_NUM_GRAPHICBUTTONS; i++)
4837   {
4838     int id = graphicbutton_info[i].gadget_id;
4839     int gd_x1, gd_x2, gd_y1, gd_y2;
4840     int x = SX + graphicbutton_info[i].x;
4841     int y = SY + graphicbutton_info[i].y;
4842
4843     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
4844
4845     if (i <= ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE)
4846     {
4847       gd_x1 = DOOR_GFX_PAGEX4 + graphicbutton_info[i].gd_x;
4848       gd_y1 = DOOR_GFX_PAGEY1 + graphicbutton_info[i].gd_y;
4849       gd_x2 = DOOR_GFX_PAGEX3 + graphicbutton_info[i].gd_x;
4850       gd_y2 = gd_y1;
4851     }
4852     else        /* (i <= ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE) */
4853     {
4854       gd_x1 = DOOR_GFX_PAGEX6 + graphicbutton_info[i].gd_x;
4855       gd_y1 = DOOR_GFX_PAGEY1 + graphicbutton_info[i].gd_y;
4856       gd_x2 = gd_x1 - ED_BUTTON_COUNT_XSIZE;
4857       gd_y2 = gd_y1;
4858     }
4859
4860     /* determine horizontal position to the right of specified gadget */
4861     if (graphicbutton_info[i].gadget_id_align != GADGET_ID_NONE)
4862       x = (right_gadget_border[graphicbutton_info[i].gadget_id_align] +
4863            ED_GADGET_TEXT_DISTANCE);
4864
4865     /* determine horizontal offset for leading text */
4866     if (graphicbutton_info[i].text_left != NULL)
4867       x += getTextWidthForGadget(graphicbutton_info[i].text_left);
4868
4869     gi = CreateGadget(GDI_CUSTOM_ID, id,
4870                       GDI_CUSTOM_TYPE_ID, i,
4871                       GDI_INFO_TEXT, graphicbutton_info[i].infotext,
4872                       GDI_X, x,
4873                       GDI_Y, y,
4874                       GDI_WIDTH, graphicbutton_info[i].width,
4875                       GDI_HEIGHT, graphicbutton_info[i].height,
4876                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
4877                       GDI_STATE, GD_BUTTON_UNPRESSED,
4878                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
4879                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
4880                       GDI_EVENT_MASK, event_mask,
4881                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4882                       GDI_CALLBACK_ACTION, HandleGraphicbuttonGadgets,
4883                       GDI_END);
4884
4885     if (gi == NULL)
4886       Error(ERR_EXIT, "cannot create gadget");
4887
4888     level_editor_gadget[id] = gi;
4889     right_gadget_border[id] =
4890       getRightGadgetBorder(gi, graphicbutton_info[i].text_right);
4891   }
4892 }
4893
4894 static void CreateScrollbarGadgets()
4895 {
4896   int i;
4897
4898   for (i = 0; i < ED_NUM_SCROLLBARS; i++)
4899   {
4900     int id = scrollbar_info[i].gadget_id;
4901     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4902     int gd_x1, gd_x2, gd_y1, gd_y2;
4903     struct GadgetInfo *gi;
4904     int items_max, items_visible, item_position;
4905     unsigned long event_mask;
4906
4907     if (i == ED_SCROLLBAR_ID_LIST_VERTICAL)
4908     {
4909       items_max = num_editor_elements / ED_ELEMENTLIST_BUTTONS_HORIZ;
4910       items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
4911       item_position = element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ;
4912     }
4913     else        /* drawing area scrollbars */
4914     {
4915       if (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL)
4916       {
4917         items_max = MAX(lev_fieldx + 2, ed_fieldx);
4918         items_visible = ed_fieldx;
4919         item_position = 0;
4920       }
4921       else
4922       {
4923         items_max = MAX(lev_fieldy + 2, ed_fieldy);
4924         items_visible = ed_fieldy;
4925         item_position = 0;
4926       }
4927     }
4928
4929     event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
4930
4931     gd_x1 = DOOR_GFX_PAGEX8 + scrollbar_info[i].gd_x;
4932     gd_x2 = (gd_x1 - (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL ?
4933                       scrollbar_info[i].height : scrollbar_info[i].width));
4934     gd_y1 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y;
4935     gd_y2 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y;
4936
4937     gi = CreateGadget(GDI_CUSTOM_ID, id,
4938                       GDI_CUSTOM_TYPE_ID, i,
4939                       GDI_INFO_TEXT, scrollbar_info[i].infotext,
4940                       GDI_X, scrollbar_info[i].x,
4941                       GDI_Y, scrollbar_info[i].y,
4942                       GDI_WIDTH, scrollbar_info[i].width,
4943                       GDI_HEIGHT, scrollbar_info[i].height,
4944                       GDI_TYPE, scrollbar_info[i].type,
4945                       GDI_SCROLLBAR_ITEMS_MAX, items_max,
4946                       GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
4947                       GDI_SCROLLBAR_ITEM_POSITION, item_position,
4948                       GDI_STATE, GD_BUTTON_UNPRESSED,
4949                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
4950                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
4951                       GDI_BORDER_SIZE, ED_BORDER_SIZE, ED_BORDER_SIZE,
4952                       GDI_EVENT_MASK, event_mask,
4953                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
4954                       GDI_CALLBACK_ACTION, HandleControlButtons,
4955                       GDI_END);
4956
4957     if (gi == NULL)
4958       Error(ERR_EXIT, "cannot create gadget");
4959
4960     level_editor_gadget[id] = gi;
4961   }
4962 }
4963
4964 static void CreateCheckbuttonGadgets()
4965 {
4966   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
4967   struct GadgetInfo *gi;
4968   unsigned long event_mask;
4969   int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
4970   int i;
4971
4972   event_mask = GD_EVENT_PRESSED;
4973
4974   gd_x1 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_UNCHECKED_XPOS;
4975   gd_x2 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_UNCHECKED_XPOS;
4976   gd_x3 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_CHECKED_XPOS;
4977   gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
4978   gd_y  = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
4979
4980   for (i = 0; i < ED_NUM_CHECKBUTTONS; i++)
4981   {
4982     int id = checkbutton_info[i].gadget_id;
4983     int x = SX + checkbutton_info[i].x;
4984     int y = SY + checkbutton_info[i].y;
4985
4986     if (id == GADGET_ID_STICK_ELEMENT)
4987       gd_y  = DOOR_GFX_PAGEY1 + ED_STICKYBUTTON_YPOS;
4988     else
4989       gd_y  = DOOR_GFX_PAGEY1 + ED_CHECKBUTTON_YPOS;
4990
4991     /* determine horizontal position to the right of specified gadget */
4992     if (checkbutton_info[i].gadget_id_align != GADGET_ID_NONE)
4993       x = (right_gadget_border[checkbutton_info[i].gadget_id_align] +
4994            ED_GADGET_TEXT_DISTANCE);
4995
4996     /* determine horizontal offset for leading text */
4997     if (checkbutton_info[i].text_left != NULL)
4998       x += getTextWidthForGadget(checkbutton_info[i].text_left);
4999
5000     gi = CreateGadget(GDI_CUSTOM_ID, id,
5001                       GDI_CUSTOM_TYPE_ID, i,
5002                       GDI_INFO_TEXT, checkbutton_info[i].infotext,
5003                       GDI_X, x,
5004                       GDI_Y, y,
5005                       GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
5006                       GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
5007                       GDI_TYPE, GD_TYPE_CHECK_BUTTON,
5008                       GDI_CHECKED, *checkbutton_info[i].value,
5009                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
5010                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
5011                       GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x3, gd_y,
5012                       GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x4, gd_y,
5013                       GDI_EVENT_MASK, event_mask,
5014                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5015                       GDI_CALLBACK_ACTION, HandleCheckbuttons,
5016                       GDI_END);
5017
5018     if (gi == NULL)
5019       Error(ERR_EXIT, "cannot create gadget");
5020
5021     level_editor_gadget[id] = gi;
5022     right_gadget_border[id] =
5023       getRightGadgetBorder(gi, checkbutton_info[i].text_right);
5024   }
5025 }
5026
5027 static void CreateRadiobuttonGadgets()
5028 {
5029   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5030   struct GadgetInfo *gi;
5031   unsigned long event_mask;
5032   int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
5033   int i;
5034
5035   event_mask = GD_EVENT_PRESSED;
5036
5037   gd_x1 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_UNCHECKED_XPOS;
5038   gd_x2 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_UNCHECKED_XPOS;
5039   gd_x3 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_CHECKED_XPOS;
5040   gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
5041   gd_y  = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
5042
5043   for (i = 0; i < ED_NUM_RADIOBUTTONS; i++)
5044   {
5045     int id = radiobutton_info[i].gadget_id;
5046     int x = SX + radiobutton_info[i].x;
5047     int y = SY + radiobutton_info[i].y;
5048
5049     int checked =
5050       (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
5051
5052     /* determine horizontal position to the right of specified gadget */
5053     if (radiobutton_info[i].gadget_id_align != GADGET_ID_NONE)
5054       x = (right_gadget_border[radiobutton_info[i].gadget_id_align] +
5055            ED_GADGET_TEXT_DISTANCE);
5056
5057     /* determine horizontal offset for leading text */
5058     if (radiobutton_info[i].text_left != NULL)
5059       x += getTextWidthForGadget(radiobutton_info[i].text_left);
5060
5061     gi = CreateGadget(GDI_CUSTOM_ID, id,
5062                       GDI_CUSTOM_TYPE_ID, i,
5063                       GDI_INFO_TEXT, radiobutton_info[i].infotext,
5064                       GDI_X, x,
5065                       GDI_Y, y,
5066                       GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
5067                       GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
5068                       GDI_TYPE, GD_TYPE_RADIO_BUTTON,
5069                       GDI_RADIO_NR, radiobutton_info[i].radio_button_nr,
5070                       GDI_CHECKED, checked,
5071                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
5072                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
5073                       GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x3, gd_y,
5074                       GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x4, gd_y,
5075                       GDI_EVENT_MASK, event_mask,
5076                       GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
5077                       GDI_CALLBACK_ACTION, HandleRadiobuttons,
5078                       GDI_END);
5079
5080     if (gi == NULL)
5081       Error(ERR_EXIT, "cannot create gadget");
5082
5083     level_editor_gadget[id] = gi;
5084     right_gadget_border[id] =
5085       getRightGadgetBorder(gi, radiobutton_info[i].text_right);
5086   }
5087 }
5088
5089 void CreateLevelEditorGadgets()
5090 {
5091   int old_game_status = game_status;
5092
5093   /* setting 'game_status' is needed to get the right fonts for the editor */
5094   game_status = GAME_MODE_EDITOR;
5095
5096   ReinitializeElementList();
5097
5098   CreateControlButtons();
5099   CreateScrollbarGadgets();
5100
5101   /* order of function calls is important because of cross-references */
5102   CreateCheckbuttonGadgets();
5103   CreateCounterButtons();
5104   CreateRadiobuttonGadgets();
5105   CreateTextInputGadgets();
5106   CreateTextAreaGadgets();
5107   CreateSelectboxGadgets();
5108   CreateGraphicbuttonGadgets();
5109   CreateTextbuttonGadgets();
5110   CreateDrawingAreas();
5111
5112   game_status = old_game_status;
5113 }
5114
5115 void FreeLevelEditorGadgets()
5116 {
5117   int i;
5118
5119   for (i = 0; i < NUM_EDITOR_GADGETS; i++)
5120     FreeGadget(level_editor_gadget[i]);
5121 }
5122
5123 static void MapCounterButtons(int id)
5124 {
5125   int gadget_id_down = counterbutton_info[id].gadget_id_down;
5126   int gadget_id_text = counterbutton_info[id].gadget_id_text;
5127   int gadget_id_up   = counterbutton_info[id].gadget_id_up;
5128   struct GadgetInfo *gi_down = level_editor_gadget[gadget_id_down];
5129   struct GadgetInfo *gi_text = level_editor_gadget[gadget_id_text];
5130   struct GadgetInfo *gi_up   = level_editor_gadget[gadget_id_up];
5131 #if 0
5132   char infotext[MAX_OUTPUT_LINESIZE + 1];
5133   int max_infotext_len = getMaxInfoTextLength();
5134   int xoffset_left = 0;
5135   int yoffset_left = ED_BORDER_SIZE;
5136   int xoffset_right = getCounterGadgetWidth();
5137   int yoffset_right = ED_BORDER_SIZE;
5138 #else
5139   int xoffset_left = getTextWidthForGadget(counterbutton_info[id].text_left);
5140   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5141   int yoffset_above = MINI_TILEX + ED_GADGET_DISTANCE;
5142   int yoffset = ED_BORDER_SIZE;
5143   int x_left = gi_down->x - xoffset_left;
5144   int x_right = gi_up->x + gi_up->width + xoffset_right;
5145   int y_above = gi_down->y - yoffset_above;
5146   int x = gi_down->x;
5147   int y;        /* set after gadget position was modified */
5148 #endif
5149
5150   /* set position for "score" counter gadget */
5151   if (id == ED_COUNTER_ID_ELEMENT_SCORE)
5152   {
5153     ModifyGadget(gi_down, GDI_Y, SY + counterbutton_info[id].y, GDI_END);
5154     ModifyGadget(gi_text, GDI_Y, SY + counterbutton_info[id].y, GDI_END);
5155     ModifyGadget(gi_up,   GDI_Y, SY + counterbutton_info[id].y, GDI_END);
5156   }
5157
5158   y = gi_up->y + yoffset;
5159
5160   if (counterbutton_info[id].text_above)
5161     DrawText(x, y_above, counterbutton_info[id].text_above, FONT_TEXT_1);
5162
5163   if (counterbutton_info[id].text_left)
5164     DrawText(x_left, y, counterbutton_info[id].text_left, FONT_TEXT_1);
5165
5166   if (counterbutton_info[id].text_right)
5167     DrawText(x_right, y, counterbutton_info[id].text_right, FONT_TEXT_1);
5168
5169   ModifyEditorCounter(id, *counterbutton_info[id].value);
5170
5171   MapGadget(gi_down);
5172   MapGadget(gi_text);
5173   MapGadget(gi_up);
5174 }
5175
5176 static void MapControlButtons()
5177 {
5178   int counter_id;
5179   int i;
5180
5181   /* map toolbox buttons (excluding special CE toolbox buttons) */
5182   for (i = 0; i < ED_NUM_CTRL1_2_BUTTONS; i++)
5183     MapGadget(level_editor_gadget[i]);
5184
5185   /* map buttons to select elements */
5186   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
5187     MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
5188   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
5189   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
5190   MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
5191
5192   /* map buttons to select level */
5193   counter_id = ED_COUNTER_ID_SELECT_LEVEL;
5194   ModifyEditorCounterLimits(counter_id,
5195                             leveldir_current->first_level,
5196                             leveldir_current->last_level);
5197   MapCounterButtons(counter_id);
5198 }
5199
5200 static void MapDrawingArea(int id)
5201 {
5202   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
5203   int area_xsize = gi->drawing.area_xsize;
5204   int area_ysize = gi->drawing.area_ysize;
5205   int xoffset_left= getTextWidthForDrawingArea(drawingarea_info[id].text_left);
5206   int xoffset_below= getTextWidth(drawingarea_info[id].text_below,FONT_TEXT_1);
5207   int x_left  = gi->x - xoffset_left;
5208   int x_right = gi->x + gi->width + ED_DRAWINGAREA_TEXT_DISTANCE;
5209   int x_below = gi->x + (gi->width - xoffset_below) / 2;
5210   int y_side  = gi->y + (gi->height - getFontHeight(FONT_TEXT_1)) / 2;
5211   int y_below = gi->y + gi->height + ED_DRAWINGAREA_TEXT_DISTANCE;
5212
5213   if (drawingarea_info[id].text_left)
5214     DrawText(x_left, y_side, drawingarea_info[id].text_left, FONT_TEXT_1);
5215
5216   if (drawingarea_info[id].text_right)
5217     DrawText(x_right, y_side, drawingarea_info[id].text_right, FONT_TEXT_1);
5218
5219   if (drawingarea_info[id].text_below)
5220     DrawText(x_below, y_below, drawingarea_info[id].text_below, FONT_TEXT_1);
5221
5222   if (id != ED_DRAWING_ID_DRAWING_LEVEL)
5223   {
5224     DrawElementBorder(gi->x, gi->y,
5225                       area_xsize * MINI_TILEX, area_ysize * MINI_TILEY, TRUE);
5226
5227     DrawDrawingArea(id);
5228   }
5229
5230   MapGadget(gi);
5231 }
5232
5233 static void MapTextInputGadget(int id)
5234 {
5235   struct GadgetInfo *gi = level_editor_gadget[textinput_info[id].gadget_id];
5236   int xoffset_above = 0;
5237   int yoffset_above = -(MINI_TILEX + ED_GADGET_DISTANCE);
5238   int x_above = textinput_info[id].x + xoffset_above;
5239   int y_above = textinput_info[id].y + yoffset_above;
5240
5241   if (textinput_info[id].text_above)
5242     DrawTextS(x_above, y_above, FONT_TEXT_1, textinput_info[id].text_above);
5243
5244   ModifyGadget(gi, GDI_TEXT_VALUE, textinput_info[id].value, GDI_END);
5245
5246   MapGadget(gi);
5247 }
5248
5249 static void MapTextAreaGadget(int id)
5250 {
5251   struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
5252   int xoffset_above = 0;
5253   int yoffset_above = -(MINI_TILEX + ED_GADGET_DISTANCE);
5254   int x_above = textarea_info[id].x + xoffset_above;
5255   int y_above = textarea_info[id].y + yoffset_above;
5256
5257   if (textarea_info[id].text_above)
5258     DrawTextS(x_above, y_above, FONT_TEXT_1, textarea_info[id].text_above);
5259
5260   ModifyGadget(gi, GDI_TEXT_VALUE, textarea_info[id].value, GDI_END);
5261
5262   MapGadget(gi);
5263 }
5264
5265 static void MapSelectboxGadget(int id)
5266 {
5267   struct GadgetInfo *gi = level_editor_gadget[selectbox_info[id].gadget_id];
5268   int xoffset_left = getTextWidthForGadget(selectbox_info[id].text_left);
5269   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5270   int yoffset = ED_BORDER_SIZE;
5271   int x_left = gi->x - xoffset_left;
5272   int x_right = gi->x + gi->width + xoffset_right;
5273   int y = gi->y + yoffset;
5274
5275   if (selectbox_info[id].text_left)
5276     DrawText(x_left, y, selectbox_info[id].text_left, FONT_TEXT_1);
5277
5278   if (selectbox_info[id].text_right)
5279     DrawText(x_right, y, selectbox_info[id].text_right, FONT_TEXT_1);
5280
5281   ModifyEditorSelectbox(id, *selectbox_info[id].value);
5282
5283   MapGadget(gi);
5284 }
5285
5286 static void MapTextbuttonGadget(int id)
5287 {
5288   struct GadgetInfo *gi = level_editor_gadget[textbutton_info[id].gadget_id];
5289   int xoffset_left = getTextWidthForGadget(textbutton_info[id].text_left);
5290   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5291   int yoffset = ED_BORDER_SIZE;
5292   int x_left = gi->x - xoffset_left;
5293   int x_right = gi->x + gi->width + xoffset_right;
5294   int y = gi->y + yoffset;
5295
5296   /* only show button to delete change pages when more than minimum pages */
5297   if (id == ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE &&
5298       custom_element.num_change_pages == MIN_CHANGE_PAGES)
5299     return;
5300
5301   if (textbutton_info[id].text_left)
5302     DrawText(x_left, y, textbutton_info[id].text_left, FONT_TEXT_1);
5303
5304   if (textbutton_info[id].text_right)
5305     DrawText(x_right, y, textbutton_info[id].text_right, FONT_TEXT_1);
5306
5307   MapGadget(gi);
5308 }
5309
5310 static void MapGraphicbuttonGadget(int id)
5311 {
5312   struct GadgetInfo *gi= level_editor_gadget[graphicbutton_info[id].gadget_id];
5313   int xoffset_left = getTextWidthForGadget(graphicbutton_info[id].text_left);
5314   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5315   int yoffset = ED_BORDER_SIZE;
5316   int x_left = gi->x - xoffset_left;
5317   int x_right = gi->x + gi->width + xoffset_right;
5318   int y = gi->y + yoffset;
5319
5320   if (graphicbutton_info[id].text_left)
5321     DrawText(x_left, y, graphicbutton_info[id].text_left, FONT_TEXT_1);
5322
5323   if (graphicbutton_info[id].text_right)
5324     DrawText(x_right, y, graphicbutton_info[id].text_right, FONT_TEXT_1);
5325
5326   MapGadget(gi);
5327 }
5328
5329 static void MapRadiobuttonGadget(int id)
5330 {
5331   struct GadgetInfo *gi = level_editor_gadget[radiobutton_info[id].gadget_id];
5332   int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
5333   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5334   int yoffset = ED_BORDER_SIZE;
5335   int x_left = gi->x - xoffset_left;
5336   int x_right = gi->x + gi->width + xoffset_right;
5337   int y = gi->y + yoffset;
5338   boolean checked =
5339     (*radiobutton_info[id].value == radiobutton_info[id].checked_value);
5340
5341   if (radiobutton_info[id].text_left)
5342     DrawText(x_left, y, radiobutton_info[id].text_left, FONT_TEXT_1);
5343
5344   if (radiobutton_info[id].text_right)
5345     DrawText(x_right, y, radiobutton_info[id].text_right, FONT_TEXT_1);
5346
5347   ModifyGadget(gi, GDI_CHECKED, checked, GDI_END);
5348
5349   MapGadget(gi);
5350 }
5351
5352 static void MapCheckbuttonGadget(int id)
5353 {
5354   struct GadgetInfo *gi = level_editor_gadget[checkbutton_info[id].gadget_id];
5355   int xoffset_left = getTextWidthForGadget(checkbutton_info[id].text_left);
5356   int xoffset_right = ED_GADGET_TEXT_DISTANCE;
5357   int yoffset = ED_BORDER_SIZE;
5358   int x_left, x_right, y;       /* set after gadget position was modified */
5359
5360   /* set position for gadgets with dynamically determined position */
5361   if (checkbutton_info[id].x != -1)     /* do not change dynamic positions */
5362     ModifyGadget(gi, GDI_X, SX + checkbutton_info[id].x, GDI_END);
5363   ModifyGadget(gi, GDI_Y, SY + checkbutton_info[id].y, GDI_END);
5364
5365   x_left = gi->x - xoffset_left;
5366   x_right = gi->x + gi->width + xoffset_right;
5367   y = gi->y + yoffset;
5368
5369   if (checkbutton_info[id].text_left)
5370     DrawText(x_left, y, checkbutton_info[id].text_left, FONT_TEXT_1);
5371
5372   if (checkbutton_info[id].text_right)
5373     DrawText(x_right, y, checkbutton_info[id].text_right, FONT_TEXT_1);
5374
5375   ModifyGadget(gi, GDI_CHECKED, *checkbutton_info[id].value, GDI_END);
5376
5377   MapGadget(gi);
5378 }
5379
5380 static void MapMainDrawingArea()
5381 {
5382   boolean no_horizontal_scrollbar = (lev_fieldx + 2 <= ed_fieldx);
5383   boolean no_vertical_scrollbar = (lev_fieldy + 2 <= ed_fieldy);
5384   int i;
5385
5386   for (i=ED_SCROLLBUTTON_ID_AREA_FIRST; i <= ED_SCROLLBUTTON_ID_AREA_LAST; i++)
5387   {
5388     if (((i == ED_SCROLLBUTTON_ID_AREA_LEFT ||
5389           i == ED_SCROLLBUTTON_ID_AREA_RIGHT) &&
5390          no_horizontal_scrollbar) ||
5391         ((i == ED_SCROLLBUTTON_ID_AREA_UP ||
5392           i == ED_SCROLLBUTTON_ID_AREA_DOWN) &&
5393          no_vertical_scrollbar))
5394       continue;
5395
5396     MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
5397   }
5398
5399   for (i = ED_SCROLLBAR_ID_AREA_FIRST; i <= ED_SCROLLBAR_ID_AREA_LAST; i++)
5400   {
5401     if ((i == ED_SCROLLBAR_ID_AREA_HORIZONTAL && no_horizontal_scrollbar) ||
5402         (i == ED_SCROLLBAR_ID_AREA_VERTICAL && no_vertical_scrollbar))
5403       continue;
5404
5405     MapGadget(level_editor_gadget[scrollbar_info[i].gadget_id]);
5406   }
5407
5408   MapDrawingArea(ED_DRAWING_ID_DRAWING_LEVEL);
5409 }
5410
5411 static void MapOrUnmapLevelEditorToolboxCustomGadgets(boolean map)
5412 {
5413   int i;
5414
5415   for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
5416   {
5417     if (i == GADGET_ID_CUSTOM_COPY_FROM ||
5418         i == GADGET_ID_CUSTOM_COPY_TO ||
5419         i == GADGET_ID_CUSTOM_EXCHANGE ||
5420         i == GADGET_ID_CUSTOM_COPY ||
5421         i == GADGET_ID_CUSTOM_PASTE)
5422     {
5423       if (map)
5424         MapGadget(level_editor_gadget[i]);
5425       else
5426         UnmapGadget(level_editor_gadget[i]);
5427     }
5428   }
5429 }
5430
5431 static void MapLevelEditorToolboxCustomGadgets()
5432 {
5433   MapOrUnmapLevelEditorToolboxCustomGadgets(TRUE);
5434 }
5435
5436 static void UnmapLevelEditorToolboxCustomGadgets()
5437 {
5438   MapOrUnmapLevelEditorToolboxCustomGadgets(FALSE);
5439 }
5440
5441 static void MapOrUnmapLevelEditorToolboxDrawingGadgets(boolean map)
5442 {
5443   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
5444   int i;
5445
5446   for (i = 0; i < ED_NUM_CTRL1_BUTTONS; i++)
5447   {
5448     if (i != GADGET_ID_SINGLE_ITEMS &&
5449         i != GADGET_ID_PROPERTIES &&
5450         i != GADGET_ID_PICK_ELEMENT)
5451     {
5452       struct GadgetInfo *gi = level_editor_gadget[i];
5453
5454       if (map)
5455         MapGadget(gi);
5456       else
5457       {
5458         UnmapGadget(gi);
5459
5460         BlitBitmap(gd_bitmap, drawto,
5461                    DOOR_GFX_PAGEX6 + ED_CTRL_NO_BUTTONS_GFX_XPOS,
5462                    DOOR_GFX_PAGEY1 + ED_CTRL_NO_BUTTONS_GFX_YPOS,
5463                    gi->width, gi->height, gi->x, gi->y);
5464
5465         redraw_mask |= REDRAW_DOOR_3;
5466       }
5467     }
5468   }
5469 }
5470
5471 static void MapLevelEditorToolboxDrawingGadgets()
5472 {
5473   MapOrUnmapLevelEditorToolboxDrawingGadgets(TRUE);
5474 }
5475
5476 static void UnmapLevelEditorToolboxDrawingGadgets()
5477 {
5478   MapOrUnmapLevelEditorToolboxDrawingGadgets(FALSE);
5479 }
5480
5481 static void UnmapDrawingArea(int id)
5482 {
5483   UnmapGadget(level_editor_gadget[drawingarea_info[id].gadget_id]);
5484 }
5485
5486 static void UnmapLevelEditorWindowGadgets()
5487 {
5488   int i;
5489
5490   for (i = 0; i < NUM_EDITOR_GADGETS; i++)
5491     if (level_editor_gadget[i]->x < SX + SXSIZE)
5492       UnmapGadget(level_editor_gadget[i]);
5493 }
5494
5495 void UnmapLevelEditorGadgets()
5496 {
5497   int i;
5498
5499   for (i = 0; i < NUM_EDITOR_GADGETS; i++)
5500     UnmapGadget(level_editor_gadget[i]);
5501 }
5502
5503 static void ResetUndoBuffer()
5504 {
5505   undo_buffer_position = -1;
5506   undo_buffer_steps = -1;
5507   CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
5508 }
5509
5510 static void DrawEditModeWindow()
5511 {
5512   ModifyEditorElementList();
5513   RedrawDrawingElements();
5514
5515   if (edit_mode == ED_MODE_INFO)
5516     DrawLevelInfoWindow();
5517   else if (edit_mode == ED_MODE_PROPERTIES)
5518     DrawPropertiesWindow();
5519   else  /* edit_mode == ED_MODE_DRAWING */
5520     DrawDrawingWindow();
5521 }
5522
5523 static boolean LevelChanged()
5524 {
5525   boolean level_changed = FALSE;
5526   int x, y;
5527
5528   for (y = 0; y < lev_fieldy; y++) 
5529     for (x = 0; x < lev_fieldx; x++)
5530       if (Feld[x][y] != level.field[x][y])
5531         level_changed = TRUE;
5532
5533   return level_changed;
5534 }
5535
5536 static boolean LevelContainsPlayer()
5537 {
5538   boolean player_found = FALSE;
5539   int x, y;
5540
5541   for (y = 0; y < lev_fieldy; y++) 
5542     for (x = 0; x < lev_fieldx; x++)
5543       if (Feld[x][y] == EL_PLAYER_1 ||
5544           Feld[x][y] == EL_SP_MURPHY) 
5545         player_found = TRUE;
5546
5547   return player_found;
5548 }
5549
5550 static void CopyPlayfield(short src[MAX_LEV_FIELDX][MAX_LEV_FIELDY],
5551                           short dst[MAX_LEV_FIELDX][MAX_LEV_FIELDY])
5552 {
5553   int x, y;
5554
5555   for (x = 0; x < lev_fieldx; x++)
5556     for (y = 0; y < lev_fieldy; y++) 
5557       dst[x][y] = src[x][y];
5558 }
5559
5560 static int setSelectboxValue(int selectbox_id, int new_value)
5561 {
5562   int new_index_value = 0;
5563   int i;
5564
5565   for (i = 0; selectbox_info[selectbox_id].options[i].text != NULL; i++)
5566     if (selectbox_info[selectbox_id].options[i].value == new_value)
5567       new_index_value = i;
5568
5569   *selectbox_info[selectbox_id].value =
5570     selectbox_info[selectbox_id].options[new_index_value].value;
5571
5572   return new_index_value;
5573 }
5574
5575 static void copy_custom_element_settings(int element_from, int element_to)
5576 {
5577 #if 0
5578   struct ElementInfo ei_to_old = element_info[element_to];
5579   struct ElementInfo *ei_from = &element_info[element_from];
5580   struct ElementInfo *ei_to = &element_info[element_to];
5581   int i;
5582
5583   /* ---------- copy whole element structure ---------- */
5584   *ei_to = *ei_from;
5585
5586   /* ---------- restore structure pointers which cannot be copied ---------- */
5587   ei_to->token_name         = ei_to_old.token_name;
5588   ei_to->class_name         = ei_to_old.class_name;
5589   ei_to->editor_description = ei_to_old.editor_description;
5590   ei_to->custom_description = ei_to_old.custom_description;
5591   ei_to->change_page        = ei_to_old.change_page;
5592   ei_to->change             = ei_to_old.change;
5593   ei_to->group              = ei_to_old.group;
5594
5595   /* ---------- copy element base properties ---------- */
5596   Properties[element_to][EP_BITFIELD_BASE] =
5597     Properties[element_from][EP_BITFIELD_BASE];
5598
5599   /* ---------- reinitialize and copy change pages ---------- */
5600   setElementChangePages(ei_to, ei_to->num_change_pages);
5601
5602   for (i=0; i < ei_to->num_change_pages; i++)
5603     ei_to->change_page[i] = ei_from->change_page[i];
5604
5605   /* ---------- copy group element info ---------- */
5606   if (ei_from->group != NULL && ei_to->group != NULL)   /* group or internal */
5607     *ei_to->group = *ei_from->group;
5608
5609 #else
5610
5611   struct ElementInfo *ei_from = &element_info[element_from];
5612   struct ElementInfo *ei_to = &element_info[element_to];
5613   int i, x, y;
5614
5615   /* ---------- copy element description ---------- */
5616   for (i = 0; i < MAX_ELEMENT_NAME_LEN + 1; i++)
5617     ei_to->description[i] = ei_from->description[i];
5618
5619   /* ---------- copy element base properties ---------- */
5620   Properties[element_to][EP_BITFIELD_BASE] =
5621     Properties[element_from][EP_BITFIELD_BASE];
5622
5623   /* ---------- copy custom property values ---------- */
5624
5625   ei_to->use_gfx_element = ei_from->use_gfx_element;
5626   ei_to->gfx_element = ei_from->gfx_element;
5627
5628   ei_to->access_direction = ei_from->access_direction;
5629
5630   ei_to->collect_score = ei_from->collect_score;
5631   ei_to->collect_count = ei_from->collect_count;
5632
5633   ei_to->push_delay_fixed = ei_from->push_delay_fixed;
5634   ei_to->push_delay_random = ei_from->push_delay_random;
5635   ei_to->drop_delay_fixed = ei_from->drop_delay_fixed;
5636   ei_to->drop_delay_random = ei_from->drop_delay_random;
5637   ei_to->move_delay_fixed = ei_from->move_delay_fixed;
5638   ei_to->move_delay_random = ei_from->move_delay_random;
5639
5640   ei_to->move_pattern = ei_from->move_pattern;
5641   ei_to->move_direction_initial = ei_from->move_direction_initial;
5642   ei_to->move_stepsize = ei_from->move_stepsize;
5643
5644   ei_to->move_enter_element = ei_from->move_enter_element;
5645   ei_to->move_leave_element = ei_from->move_leave_element;
5646   ei_to->move_leave_type = ei_from->move_leave_type;
5647
5648   ei_to->slippery_type = ei_from->slippery_type;
5649
5650   for (y = 0; y < 3; y++)
5651     for (x = 0; x < 3; x++)
5652       ei_to->content[x][y] = ei_from->content[x][y];
5653
5654   ei_to->explosion_delay = ei_from->explosion_delay;
5655   ei_to->ignition_delay = ei_from->ignition_delay;
5656
5657   /* ---------- reinitialize and copy change pages ---------- */
5658
5659   ei_to->num_change_pages = ei_from->num_change_pages;
5660   ei_to->current_change_page = ei_from->current_change_page;
5661
5662   setElementChangePages(ei_to, ei_to->num_change_pages);
5663
5664   for (i=0; i < ei_to->num_change_pages; i++)
5665     ei_to->change_page[i] = ei_from->change_page[i];
5666
5667   /* ---------- copy group element info ---------- */
5668   if (ei_from->group != NULL && ei_to->group != NULL)   /* group or internal */
5669     *ei_to->group = *ei_from->group;
5670
5671 #endif
5672
5673   /* mark this custom element as modified */
5674   ei_to->modified_settings = TRUE;
5675 }
5676
5677 static void replace_custom_element_in_settings(int element_from,
5678                                                int element_to)
5679 {
5680   int i, j, x, y;
5681
5682   for (i = 0; i < NUM_FILE_ELEMENTS; i++)
5683   {
5684     struct ElementInfo *ei = &element_info[i];
5685
5686     for (y = 0; y < 3; y++)
5687       for (x = 0; x < 3; x++)
5688         if (ei->content[x][y] == element_from)
5689           ei->content[x][y] = element_to;
5690
5691     for (j = 0; j < ei->num_change_pages; j++)
5692     {
5693       struct ElementChangeInfo *change = &ei->change_page[j];
5694
5695       if (change->target_element == element_from)
5696         change->target_element = element_to;
5697
5698       if (change->trigger_element == element_from)
5699         change->trigger_element = element_to;
5700
5701       for (y = 0; y < 3; y++)
5702         for (x = 0; x < 3; x++)
5703           if (change->target_content[x][y] == element_from)
5704             change->target_content[x][y] = element_to;
5705     }
5706
5707     if (ei->group != NULL)                              /* group or internal */
5708       for (j = 0; j < MAX_ELEMENTS_IN_GROUP; j++)
5709         if (ei->group->element[j] == element_from)
5710           ei->group->element[j] = element_to;
5711   }
5712 }
5713
5714 static void replace_custom_element_in_playfield(int element_from,
5715                                                 int element_to)
5716 {
5717   int x, y;
5718
5719   for (x = 0; x < lev_fieldx; x++)
5720     for (y = 0; y < lev_fieldy; y++)
5721       if (Feld[x][y] == element_from)
5722         Feld[x][y] = element_to;
5723 }
5724
5725 static boolean CopyCustomElement(int element_old, int element_new,
5726                                  int copy_mode)
5727 {
5728   if (copy_mode == GADGET_ID_CUSTOM_COPY)
5729   {
5730     element_new = (IS_CUSTOM_ELEMENT(element_old) ?
5731                    EL_INTERNAL_CLIPBOARD_CUSTOM : EL_INTERNAL_CLIPBOARD_GROUP);
5732     copy_mode = GADGET_ID_CUSTOM_COPY_TO;
5733   }
5734   else if (copy_mode == GADGET_ID_CUSTOM_PASTE)
5735   {
5736     element_old = (IS_CUSTOM_ELEMENT(element_new) ?
5737                    EL_INTERNAL_CLIPBOARD_CUSTOM : EL_INTERNAL_CLIPBOARD_GROUP);
5738     copy_mode = GADGET_ID_CUSTOM_COPY_TO;
5739   }
5740   else if (IS_CUSTOM_ELEMENT(element_old) && !IS_CUSTOM_ELEMENT(element_new))
5741   {
5742     Request("Please choose custom element !", REQ_CONFIRM);
5743
5744     return FALSE;
5745   }
5746   else if (IS_GROUP_ELEMENT(element_old) && !IS_GROUP_ELEMENT(element_new))
5747   {
5748     Request("Please choose group element !", REQ_CONFIRM);
5749
5750     return FALSE;
5751   }
5752
5753   if (copy_mode == GADGET_ID_CUSTOM_COPY_FROM)
5754   {
5755     copy_custom_element_settings(element_new, element_old);
5756   }
5757   else if (copy_mode == GADGET_ID_CUSTOM_COPY_TO)
5758   {
5759     copy_custom_element_settings(element_old, element_new);
5760   }
5761   else if (copy_mode == GADGET_ID_CUSTOM_EXCHANGE)
5762   {
5763     copy_custom_element_settings(element_old, EL_INTERNAL_DUMMY);
5764     copy_custom_element_settings(element_new, element_old);
5765     copy_custom_element_settings(EL_INTERNAL_DUMMY, element_new);
5766
5767     replace_custom_element_in_settings(element_old, EL_INTERNAL_DUMMY);
5768     replace_custom_element_in_settings(element_new, element_old);
5769     replace_custom_element_in_settings(EL_INTERNAL_DUMMY, element_new);
5770
5771     replace_custom_element_in_playfield(element_old, EL_INTERNAL_DUMMY);
5772     replace_custom_element_in_playfield(element_new, element_old);
5773     replace_custom_element_in_playfield(EL_INTERNAL_DUMMY, element_new);
5774   }
5775
5776   UpdateCustomElementGraphicGadgets();
5777   DrawPropertiesWindow();
5778
5779   return TRUE;
5780 }
5781
5782 static void CopyCustomElementPropertiesToEditor(int element)
5783 {
5784   int i;
5785   int current_change_page = element_info[element].current_change_page;
5786
5787   /* dynamically (re)build selectbox for selecting change page */
5788   for (i = 0; i < element_info[element].num_change_pages; i++)
5789   {
5790     sprintf(options_change_page_strings[i], "%d", i + 1);
5791
5792     options_change_page[i].value = i;
5793     options_change_page[i].text = options_change_page_strings[i];
5794   }
5795
5796   options_change_page[i].value = -1;
5797   options_change_page[i].text = NULL;
5798
5799   /* needed here to initialize combined element properties */
5800   InitElementPropertiesEngine(level.game_version);
5801
5802   element_info[element].change =
5803     &element_info[element].change_page[current_change_page];
5804
5805   custom_element = element_info[element];
5806   custom_element_change = *element_info[element].change;
5807
5808   /* needed to initially set selectbox value variables to reliable defaults */
5809   for (i = 0; i < ED_NUM_SELECTBOX; i++)
5810     setSelectboxValue(i, *selectbox_info[i].value);
5811
5812   for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
5813     custom_element_properties[i] = HAS_PROPERTY(element, i);
5814
5815   for (i = 0; i < NUM_CHANGE_EVENTS; i++)
5816     custom_element_change_events[i] = HAS_CHANGE_EVENT(element, i);
5817
5818   /* ---------- element settings: configure (custom elements) ------------- */
5819
5820   /* set accessible layer selectbox help value */
5821   custom_element.access_type =
5822     (IS_WALKABLE(element) ? EP_WALKABLE :
5823      IS_PASSABLE(element) ? EP_PASSABLE :
5824      custom_element.access_type);
5825   custom_element.access_layer =
5826     (IS_ACCESSIBLE_OVER(element) ? EP_ACCESSIBLE_OVER :
5827      IS_ACCESSIBLE_INSIDE(element) ? EP_ACCESSIBLE_INSIDE :
5828      IS_ACCESSIBLE_UNDER(element) ? EP_ACCESSIBLE_UNDER :
5829      custom_element.access_layer);
5830   custom_element.access_protected =
5831     (IS_PROTECTED(element) ? 1 : 0);
5832   custom_element_properties[EP_ACCESSIBLE] =
5833     (IS_ACCESSIBLE_OVER(element) ||
5834      IS_ACCESSIBLE_INSIDE(element) ||
5835      IS_ACCESSIBLE_UNDER(element));
5836
5837   /* set walk-to-object action selectbox help value */
5838   custom_element.walk_to_action =
5839     (IS_DIGGABLE(element) ? EP_DIGGABLE :
5840      IS_COLLECTIBLE_ONLY(element) ? EP_COLLECTIBLE_ONLY :
5841      IS_DROPPABLE(element) ? EP_DROPPABLE :
5842      IS_THROWABLE(element) ? EP_THROWABLE :
5843      IS_PUSHABLE(element) ? EP_PUSHABLE :
5844      custom_element.walk_to_action);
5845   custom_element_properties[EP_WALK_TO_OBJECT] =
5846     (IS_DIGGABLE(element) ||
5847      IS_COLLECTIBLE_ONLY(element) ||
5848      IS_DROPPABLE(element) ||
5849      IS_THROWABLE(element) ||
5850      IS_PUSHABLE(element));
5851
5852   /* set smash targets selectbox help value */
5853   custom_element.smash_targets =
5854     (CAN_SMASH_EVERYTHING(element) ? EP_CAN_SMASH_EVERYTHING :
5855      CAN_SMASH_ENEMIES(element) ? EP_CAN_SMASH_ENEMIES :
5856      CAN_SMASH_PLAYER(element) ? EP_CAN_SMASH_PLAYER :
5857      custom_element.smash_targets);
5858   custom_element_properties[EP_CAN_SMASH] =
5859     (CAN_SMASH_EVERYTHING(element) ||
5860      CAN_SMASH_ENEMIES(element) ||
5861      CAN_SMASH_PLAYER(element));
5862
5863   /* set deadliness selectbox help value */
5864   custom_element.deadliness =
5865     (DONT_TOUCH(element) ? EP_DONT_TOUCH :
5866      DONT_COLLIDE_WITH(element) ? EP_DONT_COLLIDE_WITH :
5867      DONT_RUN_INTO(element) ? EP_DONT_RUN_INTO :
5868      custom_element.deadliness);
5869   custom_element_properties[EP_DEADLY] =
5870     (DONT_TOUCH(element) ||
5871      DONT_COLLIDE_WITH(element) ||
5872      DONT_RUN_INTO(element));
5873
5874 #if 0
5875   /* set explosion type selectbox help value */
5876   custom_element.explosion_type =
5877     (
5878 #if 0
5879      IS_INDESTRUCTIBLE(element) ? EP_INDESTRUCTIBLE :
5880 #endif
5881      CAN_EXPLODE_1X1(element) ? EP_CAN_EXPLODE_1X1 :
5882      CAN_EXPLODE_3X3(element) ? EP_CAN_EXPLODE_3X3 :
5883      CAN_EXPLODE_CROSS(element) ? EP_CAN_EXPLODE_CROSS :
5884      custom_element.explosion_type);
5885   custom_element_properties[EP_CAN_EXPLODE_AT_ALL] =
5886     (
5887 #if 0
5888      IS_INDESTRUCTIBLE(element) ||
5889 #endif
5890      CAN_EXPLODE_1X1(element) ||
5891      CAN_EXPLODE_3X3(element) ||
5892      CAN_EXPLODE_CROSS(element));
5893 #endif
5894
5895 #if 0
5896   /* special case: sub-settings dependent from main setting */
5897 #if 0
5898   custom_element.can_explode_by_fire = CAN_EXPLODE_BY_FIRE(element);
5899   custom_element.can_explode_smashed = CAN_EXPLODE_SMASHED(element);
5900   custom_element.can_explode_impact  = CAN_EXPLODE_IMPACT(element);
5901 #else
5902   if (CAN_EXPLODE_BY_FIRE(element))
5903     custom_element.can_explode_by_fire = TRUE;
5904   if (CAN_EXPLODE_SMASHED(element))
5905     custom_element.can_explode_smashed = TRUE;
5906   if (CAN_EXPLODE_IMPACT(element))
5907     custom_element.can_explode_impact  = TRUE;
5908 #endif
5909 #endif
5910
5911   /* ---------- element settings: advanced (custom elements) --------------- */
5912
5913   /* set "change by direct action" selectbox help value */
5914   custom_element_change.direct_action =
5915     (HAS_CHANGE_EVENT(element, CE_TOUCHED_BY_PLAYER) ? CE_TOUCHED_BY_PLAYER :
5916      HAS_CHANGE_EVENT(element, CE_PRESSED_BY_PLAYER) ? CE_PRESSED_BY_PLAYER :
5917      HAS_CHANGE_EVENT(element, CE_PUSHED_BY_PLAYER) ? CE_PUSHED_BY_PLAYER :
5918      HAS_CHANGE_EVENT(element, CE_ENTERED_BY_PLAYER) ? CE_ENTERED_BY_PLAYER :
5919      HAS_CHANGE_EVENT(element, CE_LEFT_BY_PLAYER) ? CE_LEFT_BY_PLAYER :
5920      HAS_CHANGE_EVENT(element, CE_DROPPED_BY_PLAYER) ? CE_DROPPED_BY_PLAYER :
5921      HAS_CHANGE_EVENT(element, CE_SWITCHED) ? CE_SWITCHED :
5922      HAS_CHANGE_EVENT(element, CE_HITTING_SOMETHING) ? CE_HITTING_SOMETHING :
5923      HAS_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING) ? CE_HIT_BY_SOMETHING :
5924      HAS_CHANGE_EVENT(element, CE_BLOCKED) ? CE_BLOCKED :
5925      HAS_CHANGE_EVENT(element, CE_IMPACT) ? CE_IMPACT :
5926      HAS_CHANGE_EVENT(element, CE_SMASHED) ? CE_SMASHED :
5927      custom_element_change.direct_action);
5928
5929   /* set "change by other element action" selectbox help value */
5930   custom_element_change.other_action =
5931     (HAS_CHANGE_EVENT(element, CE_OTHER_GETS_TOUCHED) ? CE_OTHER_GETS_TOUCHED :
5932      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_PRESSED) ? CE_OTHER_GETS_PRESSED :
5933      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_PUSHED) ? CE_OTHER_GETS_PUSHED :
5934      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_ENTERED) ? CE_OTHER_GETS_ENTERED :
5935      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_LEFT) ? CE_OTHER_GETS_LEFT :
5936      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_DIGGED) ? CE_OTHER_GETS_DIGGED :
5937      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_COLLECTED) ? CE_OTHER_GETS_COLLECTED :
5938      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_DROPPED) ? CE_OTHER_GETS_DROPPED :
5939      HAS_CHANGE_EVENT(element, CE_OTHER_IS_TOUCHING) ? CE_OTHER_IS_TOUCHING :
5940      HAS_CHANGE_EVENT(element, CE_OTHER_IS_HITTING) ? CE_OTHER_IS_HITTING :
5941      HAS_CHANGE_EVENT(element, CE_OTHER_GETS_HIT) ? CE_OTHER_GETS_HIT :
5942      HAS_CHANGE_EVENT(element, CE_OTHER_IS_SWITCHING) ? CE_OTHER_IS_SWITCHING :
5943      HAS_CHANGE_EVENT(element, CE_OTHER_IS_CHANGING) ? CE_OTHER_IS_CHANGING :
5944      HAS_CHANGE_EVENT(element, CE_OTHER_IS_EXPLODING) ? CE_OTHER_IS_EXPLODING :
5945      custom_element_change.other_action);
5946 }
5947
5948 static void CopyGroupElementPropertiesToEditor(int element)
5949 {
5950   group_element_info = *element_info[element].group;
5951   custom_element = element_info[element];       /* needed for description */
5952 }
5953
5954 static void CopyClassicElementPropertiesToEditor(int element)
5955 {
5956 #if 1
5957   if (ELEM_IS_PLAYER(element) || COULD_MOVE_INTO_ACID(element))
5958     custom_element_properties[EP_CAN_MOVE_INTO_ACID] =
5959       getMoveIntoAcidProperty(&level, element);
5960
5961   if (MAYBE_DONT_COLLIDE_WITH(element))
5962     custom_element_properties[EP_DONT_COLLIDE_WITH] =
5963       getDontCollideWithProperty(&level, element);
5964 #else
5965
5966   if (COULD_MOVE_INTO_ACID(element))
5967   {
5968     int bit_nr = get_special_property_bit(element, EP_CAN_MOVE_INTO_ACID);
5969
5970     if (bit_nr > -1)
5971       custom_element_properties[EP_CAN_MOVE_INTO_ACID] =
5972         ((level.can_move_into_acid_bits & (1 << bit_nr)) != 0);
5973   }
5974 #endif
5975 }
5976
5977 static void CopyElementPropertiesToEditor(int element)
5978 {
5979   if (IS_CUSTOM_ELEMENT(element))
5980     CopyCustomElementPropertiesToEditor(element);
5981   else if (IS_GROUP_ELEMENT(element))
5982     CopyGroupElementPropertiesToEditor(element);
5983   else
5984     CopyClassicElementPropertiesToEditor(element);
5985 }
5986
5987 static void CopyCustomElementPropertiesToGame(int element)
5988 {
5989   int i;
5990   int access_type_and_layer;
5991 #if 0
5992   boolean can_explode;
5993 #endif
5994
5995   /* mark that this custom element has been modified */
5996   custom_element.modified_settings = TRUE;
5997
5998   if (level.use_custom_template)
5999   {
6000     if (Request("Copy and modify level template ?", REQ_ASK))
6001     {
6002       level.use_custom_template = FALSE;
6003       ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE],
6004                    GDI_CHECKED, FALSE, GDI_END);
6005     }
6006     else
6007     {
6008       LoadLevelTemplate(-1);    /* this resets all element modifications ... */
6009
6010       DrawEditModeWindow();     /* ... and copies them to 'custom_element' */
6011     }
6012   }
6013
6014   element_info[element] = custom_element;
6015   *element_info[element].change = custom_element_change;
6016
6017   /* ---------- element settings: configure (custom elements) ------------- */
6018
6019   /* set accessible property from checkbox and selectbox */
6020   custom_element_properties[EP_WALKABLE_OVER] = FALSE;
6021   custom_element_properties[EP_WALKABLE_INSIDE] = FALSE;
6022   custom_element_properties[EP_WALKABLE_UNDER] = FALSE;
6023   custom_element_properties[EP_PASSABLE_OVER] = FALSE;
6024   custom_element_properties[EP_PASSABLE_INSIDE] = FALSE;
6025   custom_element_properties[EP_PASSABLE_UNDER] = FALSE;
6026   access_type_and_layer = ((custom_element.access_type == EP_WALKABLE ?
6027                             EP_WALKABLE_OVER : EP_PASSABLE_OVER) +
6028                            (custom_element.access_layer - EP_ACCESSIBLE_OVER));
6029   custom_element_properties[access_type_and_layer] =
6030     custom_element_properties[EP_ACCESSIBLE];
6031   custom_element_properties[EP_PROTECTED] =
6032     (custom_element.access_protected != 0 &&
6033      custom_element_properties[EP_ACCESSIBLE]);
6034
6035   /* set walk-to-object property from checkbox and selectbox */
6036   custom_element_properties[EP_DIGGABLE] = FALSE;
6037   custom_element_properties[EP_COLLECTIBLE_ONLY] = FALSE;
6038   custom_element_properties[EP_DROPPABLE] = FALSE;
6039   custom_element_properties[EP_THROWABLE] = FALSE;
6040   custom_element_properties[EP_PUSHABLE] = FALSE;
6041   custom_element_properties[custom_element.walk_to_action] =
6042     custom_element_properties[EP_WALK_TO_OBJECT];
6043
6044   /* set smash property from checkbox and selectbox */
6045   custom_element_properties[EP_CAN_SMASH_PLAYER] = FALSE;
6046   custom_element_properties[EP_CAN_SMASH_ENEMIES] = FALSE;
6047   custom_element_properties[EP_CAN_SMASH_EVERYTHING] = FALSE;
6048   custom_element_properties[custom_element.smash_targets] =
6049     custom_element_properties[EP_CAN_SMASH];
6050
6051   /* set deadliness property from checkbox and selectbox */
6052   custom_element_properties[EP_DONT_RUN_INTO] = FALSE;
6053   custom_element_properties[EP_DONT_COLLIDE_WITH] = FALSE;
6054   custom_element_properties[EP_DONT_TOUCH] = FALSE;
6055   custom_element_properties[custom_element.deadliness] =
6056     custom_element_properties[EP_DEADLY];
6057
6058 #if 0
6059   /* set explosion type property from checkbox and selectbox */
6060 #if 0
6061   custom_element_properties[EP_INDESTRUCTIBLE] = FALSE;
6062 #endif
6063   custom_element_properties[EP_CAN_EXPLODE_1X1] = FALSE;
6064   custom_element_properties[EP_CAN_EXPLODE_3X3] = FALSE;
6065   custom_element_properties[EP_CAN_EXPLODE_CROSS] = FALSE;
6066   custom_element_properties[EP_CAN_EXPLODE_BY_FIRE] = FALSE;
6067   custom_element_properties[EP_CAN_EXPLODE_SMASHED] = FALSE;
6068   custom_element_properties[EP_CAN_EXPLODE_IMPACT] = FALSE;
6069   custom_element_properties[custom_element.explosion_type] =
6070     custom_element_properties[EP_CAN_EXPLODE_AT_ALL];
6071 #endif
6072
6073 #if 0
6074   /* special case: sub-settings dependent from main setting */
6075 #if 0
6076   can_explode = (custom_element_properties[EP_CAN_EXPLODE_1X1] ||
6077                  custom_element_properties[EP_CAN_EXPLODE_3X3] ||
6078                  custom_element_properties[EP_CAN_EXPLODE_CROSS]);
6079   custom_element_properties[EP_CAN_EXPLODE_BY_FIRE] =
6080     (can_explode && custom_element.can_explode_by_fire);
6081   custom_element_properties[EP_CAN_EXPLODE_SMASHED] =
6082     (can_explode && custom_element.can_explode_smashed);
6083   custom_element_properties[EP_CAN_EXPLODE_IMPACT] =
6084     (can_explode && custom_element.can_explode_impact);
6085 #else
6086   if (custom_element_properties[EP_CAN_EXPLODE_1X1] ||
6087       custom_element_properties[EP_CAN_EXPLODE_3X3] ||
6088       custom_element_properties[EP_CAN_EXPLODE_CROSS])
6089   {
6090     custom_element_properties[EP_CAN_EXPLODE_BY_FIRE] =
6091       custom_element.can_explode_by_fire;
6092     custom_element_properties[EP_CAN_EXPLODE_SMASHED] =
6093       custom_element.can_explode_smashed;
6094     custom_element_properties[EP_CAN_EXPLODE_IMPACT] =
6095       custom_element.can_explode_impact;
6096   }
6097 #endif
6098 #endif
6099
6100   /* ---------- element settings: advanced (custom elements) --------------- */
6101
6102   /* set player change event from checkbox and selectbox */
6103   custom_element_change_events[CE_TOUCHED_BY_PLAYER] = FALSE;
6104   custom_element_change_events[CE_PRESSED_BY_PLAYER] = FALSE;
6105   custom_element_change_events[CE_PUSHED_BY_PLAYER] = FALSE;
6106   custom_element_change_events[CE_ENTERED_BY_PLAYER] = FALSE;
6107   custom_element_change_events[CE_LEFT_BY_PLAYER] = FALSE;
6108   custom_element_change_events[CE_DROPPED_BY_PLAYER] = FALSE;
6109   custom_element_change_events[CE_SWITCHED] = FALSE;
6110   custom_element_change_events[CE_HITTING_SOMETHING] = FALSE;
6111   custom_element_change_events[CE_HIT_BY_SOMETHING] = FALSE;
6112   custom_element_change_events[CE_BLOCKED] = FALSE;
6113   custom_element_change_events[CE_IMPACT] = FALSE;
6114   custom_element_change_events[CE_SMASHED] = FALSE;
6115   custom_element_change_events[custom_element_change.direct_action] =
6116     custom_element_change_events[CE_BY_DIRECT_ACTION];
6117
6118   /* set other element action change event from checkbox and selectbox */
6119   custom_element_change_events[CE_OTHER_GETS_TOUCHED] = FALSE;
6120   custom_element_change_events[CE_OTHER_GETS_PRESSED] = FALSE;
6121   custom_element_change_events[CE_OTHER_GETS_PUSHED] = FALSE;
6122   custom_element_change_events[CE_OTHER_GETS_ENTERED] = FALSE;
6123   custom_element_change_events[CE_OTHER_GETS_LEFT] = FALSE;
6124   custom_element_change_events[CE_OTHER_GETS_DIGGED] = FALSE;
6125   custom_element_change_events[CE_OTHER_GETS_COLLECTED] = FALSE;
6126   custom_element_change_events[CE_OTHER_GETS_DROPPED] = FALSE;
6127   custom_element_change_events[CE_OTHER_IS_TOUCHING] = FALSE;
6128   custom_element_change_events[CE_OTHER_IS_HITTING] = FALSE;
6129   custom_element_change_events[CE_OTHER_GETS_HIT] = FALSE;
6130   custom_element_change_events[CE_OTHER_IS_SWITCHING] = FALSE;
6131   custom_element_change_events[CE_OTHER_IS_CHANGING] = FALSE;
6132   custom_element_change_events[CE_OTHER_IS_EXPLODING] = FALSE;
6133   custom_element_change_events[custom_element_change.other_action] =
6134     custom_element_change_events[CE_BY_OTHER_ACTION];
6135
6136   for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
6137     SET_PROPERTY(element, i, custom_element_properties[i]);
6138
6139   for (i = 0; i < NUM_CHANGE_EVENTS; i++)
6140     SET_CHANGE_EVENT(element, i, custom_element_change_events[i]);
6141
6142   /* copy change events also to special level editor variable */
6143   custom_element = element_info[element];
6144   custom_element_change = *element_info[element].change;
6145 }
6146
6147 static void CopyGroupElementPropertiesToGame(int element)
6148 {
6149   element_info[element] = custom_element;
6150   *element_info[element].group = group_element_info;
6151
6152   /* mark that this group element has been modified */
6153   element_info[element].modified_settings = TRUE;
6154 }
6155
6156 static void CopyClassicElementPropertiesToGame(int element)
6157 {
6158 #if 1
6159   if (ELEM_IS_PLAYER(element) || COULD_MOVE_INTO_ACID(element))
6160     setMoveIntoAcidProperty(&level, element,
6161                             custom_element_properties[EP_CAN_MOVE_INTO_ACID]);
6162
6163   if (MAYBE_DONT_COLLIDE_WITH(element))
6164     setDontCollideWithProperty(&level, element,
6165                               custom_element_properties[EP_DONT_COLLIDE_WITH]);
6166 #else
6167
6168   if (COULD_MOVE_INTO_ACID(element))
6169   {
6170     int bit_nr = get_special_property_bit(element, EP_CAN_MOVE_INTO_ACID);
6171
6172     if (bit_nr > -1)
6173     {
6174       level.can_move_into_acid_bits &= ~(1 << bit_nr);
6175
6176       if (custom_element_properties[EP_CAN_MOVE_INTO_ACID])
6177         level.can_move_into_acid_bits |= (1 << bit_nr);
6178     }
6179   }
6180 #endif
6181 }
6182
6183 static void CopyElementPropertiesToGame(int element)
6184 {
6185   if (IS_CUSTOM_ELEMENT(element))
6186     CopyCustomElementPropertiesToGame(element);
6187   else if (IS_GROUP_ELEMENT(element))
6188     CopyGroupElementPropertiesToGame(element);
6189   else
6190     CopyClassicElementPropertiesToGame(element);
6191 }
6192
6193 void DrawLevelEd()
6194 {
6195   CloseDoor(DOOR_CLOSE_ALL);
6196   OpenDoor(DOOR_OPEN_2 | DOOR_NO_DELAY);
6197
6198   if (level_editor_test_game)
6199   {
6200     CopyPlayfield(level.field, Feld);
6201     CopyPlayfield(FieldBackup, level.field);
6202
6203     level_editor_test_game = FALSE;
6204   }
6205   else
6206   {
6207     edit_mode = ED_MODE_DRAWING;
6208     edit_mode_properties = ED_MODE_PROPERTIES_INFO;
6209
6210     ResetUndoBuffer();
6211
6212     level_xpos = -1;
6213     level_ypos = -1;
6214   }
6215
6216   /* copy default editor door content to main double buffer */
6217   BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
6218              DOOR_GFX_PAGEX6, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
6219
6220 #if 0
6221   /* draw mouse button brush elements */
6222   RedrawDrawingElements();
6223 #endif
6224
6225   /* draw bigger door */
6226   DrawSpecialEditorDoor();
6227
6228   /* draw new control window */
6229   BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
6230              DOOR_GFX_PAGEX8, 236, EXSIZE, EYSIZE, EX, EY);
6231
6232   redraw_mask |= REDRAW_ALL;
6233
6234   ReinitializeElementListButtons();     /* custom element may look different */
6235 #if 0
6236   ModifyEditorElementList();            /* may be needed for custom elements */
6237 #endif
6238
6239   UnmapTapeButtons();
6240   MapControlButtons();
6241
6242   DrawEditModeWindow();
6243
6244   /* copy actual editor door content to door double buffer for OpenDoor() */
6245   BlitBitmap(drawto, bitmap_db_door,
6246              DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
6247
6248   OpenDoor(DOOR_OPEN_1);
6249 }
6250
6251 static void AdjustDrawingAreaGadgets()
6252 {
6253   int ed_xsize = lev_fieldx + 2;
6254   int ed_ysize = lev_fieldy + 2;
6255   int max_ed_fieldx = MAX_ED_FIELDX;
6256   int max_ed_fieldy = MAX_ED_FIELDY;
6257   boolean horizontal_scrollbar_needed;
6258   boolean vertical_scrollbar_needed;
6259   int x, y, width, height;
6260   int xoffset, yoffset;
6261
6262   /* check if we need any scrollbars */
6263   horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
6264   vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
6265
6266   /* check if we have a smaller editor field because of scrollbars */
6267   if (horizontal_scrollbar_needed)
6268     max_ed_fieldy = MAX_ED_FIELDY - 1;
6269   if (vertical_scrollbar_needed)
6270     max_ed_fieldx = MAX_ED_FIELDX - 1;
6271
6272   /* check again if we now need more scrollbars because of less space */
6273   horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
6274   vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
6275
6276   /* check if editor field gets even smaller after adding new scrollbars */
6277   if (horizontal_scrollbar_needed)
6278     max_ed_fieldy = MAX_ED_FIELDY - 1;
6279   if (vertical_scrollbar_needed)
6280     max_ed_fieldx = MAX_ED_FIELDX - 1;
6281
6282   ed_fieldx = (ed_xsize < MAX_ED_FIELDX ? ed_xsize : max_ed_fieldx);
6283   ed_fieldy = (ed_ysize < MAX_ED_FIELDY ? ed_ysize : max_ed_fieldy);
6284
6285   ModifyGadget(level_editor_gadget[GADGET_ID_DRAWING_LEVEL],
6286                GDI_WIDTH, ed_fieldx * MINI_TILEX,
6287                GDI_HEIGHT, ed_fieldy * MINI_TILEY,
6288                GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
6289                GDI_END);
6290
6291   xoffset = (ed_fieldx == MAX_ED_FIELDX ? ED_SCROLLBUTTON_XSIZE : 0);
6292   yoffset = (ed_fieldy == MAX_ED_FIELDY ? ED_SCROLLBUTTON_YSIZE : 0);
6293
6294   x = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset;
6295   y = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset;
6296
6297   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT], GDI_X, x, GDI_END);
6298   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN], GDI_Y, y, GDI_END);
6299
6300   width = scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset;
6301   height = scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset;
6302
6303   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
6304                GDI_WIDTH, width,
6305                GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldx,
6306                GDI_END);
6307   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
6308                GDI_HEIGHT, height,
6309                GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldy,
6310                GDI_END);
6311 }
6312
6313 static void AdjustLevelScrollPosition()
6314 {
6315   if (level_xpos < -1)
6316     level_xpos = -1;
6317   if (level_xpos > lev_fieldx - ed_fieldx + 1)
6318     level_xpos = lev_fieldx - ed_fieldx + 1;
6319   if (lev_fieldx < ed_fieldx - 2)
6320     level_xpos = -1;
6321
6322   if (level_ypos < -1)
6323     level_ypos = -1;
6324   if (level_ypos > lev_fieldy - ed_fieldy + 1)
6325     level_ypos = lev_fieldy - ed_fieldy + 1;
6326   if (lev_fieldy < ed_fieldy - 2)
6327     level_ypos = -1;
6328 }
6329
6330 static void AdjustEditorScrollbar(int id)
6331 {
6332   struct GadgetInfo *gi = level_editor_gadget[id];
6333   int items_max, items_visible, item_position;
6334
6335   if (id == GADGET_ID_SCROLL_HORIZONTAL)
6336   {
6337     items_max = MAX(lev_fieldx + 2, ed_fieldx);
6338     items_visible = ed_fieldx;
6339     item_position = level_xpos + 1;
6340   }
6341   else
6342   {
6343     items_max = MAX(lev_fieldy + 2, ed_fieldy);
6344     items_visible = ed_fieldy;
6345     item_position = level_ypos + 1;
6346   }
6347
6348   if (item_position > items_max - items_visible)
6349     item_position = items_max - items_visible;
6350
6351   ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
6352                GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
6353 }
6354
6355 static void ModifyEditorCounter(int counter_id, int new_value)
6356 {
6357   int *counter_value = counterbutton_info[counter_id].value;
6358   int gadget_id = counterbutton_info[counter_id].gadget_id_text;
6359   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6360
6361   ModifyGadget(gi, GDI_NUMBER_VALUE, new_value, GDI_END);
6362
6363   if (counter_value != NULL)
6364     *counter_value = gi->textinput.number_value;
6365 }
6366
6367 static void ModifyEditorCounterLimits(int counter_id, int min, int max)
6368 {
6369   int gadget_id = counterbutton_info[counter_id].gadget_id_text;
6370   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6371
6372   ModifyGadget(gi, GDI_NUMBER_MIN, min, GDI_NUMBER_MAX, max, GDI_END);
6373 }
6374
6375 static void ModifyEditorSelectbox(int selectbox_id, int new_value)
6376 {
6377   int gadget_id = selectbox_info[selectbox_id].gadget_id;
6378   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6379   int new_index_value = setSelectboxValue(selectbox_id, new_value);
6380
6381   ModifyGadget(gi, GDI_SELECTBOX_INDEX, new_index_value, GDI_END);
6382 }
6383
6384 static void ModifyEditorDrawingArea(int drawingarea_id, int xsize, int ysize)
6385 {
6386   int gadget_id = drawingarea_info[drawingarea_id].gadget_id;
6387   struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6388
6389   ModifyGadget(gi, GDI_AREA_SIZE, xsize, ysize, GDI_END);
6390 }
6391
6392 static void ModifyEditorElementList()
6393 {
6394   int i;
6395
6396   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
6397   {
6398     int gadget_id = GADGET_ID_ELEMENTLIST_FIRST + i;
6399     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6400     struct GadgetDesign *gd = &gi->deco.design;
6401     int element = editor_elements[element_shift + i];
6402
6403     UnmapGadget(gi);
6404     getMiniGraphicSource(el2edimg(element), &gd->bitmap, &gd->x, &gd->y);
6405     ModifyGadget(gi, GDI_INFO_TEXT, getElementInfoText(element), GDI_END);
6406     MapGadget(gi);
6407   }
6408 }
6409
6410 static void PickDrawingElement(int button, int element)
6411 {
6412   if (button < 1 || button > 3)
6413     return;
6414
6415   if (button == 1)
6416   {
6417     new_element1 = element;
6418     DrawMiniGraphicExt(drawto,
6419                        DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS,
6420                        el2edimg(new_element1));
6421   }
6422   else if (button == 2)
6423   {
6424     new_element2 = element;
6425     DrawMiniGraphicExt(drawto,
6426                        DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS,
6427                        el2edimg(new_element2));
6428   }
6429   else
6430   {
6431     new_element3 = element;
6432     DrawMiniGraphicExt(drawto,
6433                        DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS,
6434                        el2edimg(new_element3));
6435   }
6436
6437   redraw_mask |= REDRAW_DOOR_1;
6438 }
6439
6440 static void RedrawDrawingElements()
6441 {
6442   PickDrawingElement(1, new_element1);
6443   PickDrawingElement(2, new_element2);
6444   PickDrawingElement(3, new_element3);
6445 }
6446
6447 static void DrawDrawingWindow()
6448 {
6449   stick_element_properties_window = FALSE;
6450
6451   SetMainBackgroundImage(IMG_UNDEFINED);
6452   ClearWindow();
6453
6454   UnmapLevelEditorWindowGadgets();
6455   UnmapLevelEditorToolboxCustomGadgets();
6456
6457   AdjustDrawingAreaGadgets();
6458   AdjustLevelScrollPosition();
6459   AdjustEditorScrollbar(GADGET_ID_SCROLL_HORIZONTAL);
6460   AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
6461
6462   DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
6463
6464   MapMainDrawingArea();
6465   MapLevelEditorToolboxDrawingGadgets();
6466 }
6467
6468 static void DrawLevelInfoWindow()
6469 {
6470   int i;
6471
6472   stick_element_properties_window = FALSE;
6473
6474   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
6475   ClearWindow();
6476   UnmapLevelEditorWindowGadgets();
6477
6478   DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS1_YPOS,
6479            "Level Settings", FONT_TITLE_1);
6480   DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS2_YPOS,
6481            "Editor Settings", FONT_TITLE_1);
6482
6483   /* draw counter gadgets */
6484   for (i = ED_COUNTER_ID_LEVEL_FIRST; i <= ED_COUNTER_ID_LEVEL_LAST; i++)
6485     MapCounterButtons(i);
6486
6487   /* draw selectbox gadgets */
6488   for (i = ED_SELECTBOX_ID_LEVEL_FIRST; i <= ED_SELECTBOX_ID_LEVEL_LAST; i++)
6489     MapSelectboxGadget(i);
6490
6491   /* draw checkbutton gadgets */
6492   for (i=ED_CHECKBUTTON_ID_LEVEL_FIRST; i <= ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
6493     MapCheckbuttonGadget(i);
6494
6495   /* draw radiobutton gadgets */
6496   for (i=ED_RADIOBUTTON_ID_LEVEL_FIRST; i <= ED_RADIOBUTTON_ID_LEVEL_LAST; i++)
6497     MapRadiobuttonGadget(i);
6498
6499   /* draw text input gadgets */
6500   for (i = ED_TEXTINPUT_ID_LEVEL_FIRST; i <= ED_TEXTINPUT_ID_LEVEL_LAST; i++)
6501     MapTextInputGadget(i);
6502
6503   /* draw drawing area */
6504   MapDrawingArea(ED_DRAWING_ID_RANDOM_BACKGROUND);
6505 }
6506
6507 static void DrawCustomContentArea()
6508 {
6509   int id = ED_DRAWING_ID_CUSTOM_CONTENT;
6510   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
6511   int x1 = right_gadget_border[GADGET_ID_CUSTOM_DEADLINESS];
6512   int x2 = right_gadget_border[GADGET_ID_CUSTOM_EXPLOSION_TYPE];
6513   int x3 = right_gadget_border[GADGET_ID_CUSTOM_EXPLODE_IMPACT];
6514   int xoffset = ED_DRAWINGAREA_TEXT_DISTANCE;
6515
6516   /* add distance for potential left text (without drawing area border) */
6517   x2 += getTextWidthForGadget(drawingarea_info[id].text_left);
6518
6519   ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
6520
6521   MapDrawingArea(ED_DRAWING_ID_CUSTOM_CONTENT);
6522 }
6523
6524 static void DrawCustomChangeContentArea()
6525 {
6526   int id = ED_DRAWING_ID_CUSTOM_CHANGE_CONTENT;
6527   struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[id].gadget_id];
6528   int x1 = right_gadget_border[GADGET_ID_CHANGE_USE_CONTENT];
6529   int x2 = right_gadget_border[GADGET_ID_CHANGE_REPLACE_WHEN];
6530   int x3 = right_gadget_border[GADGET_ID_CHANGE_ONLY_COMPLETE];
6531   int xoffset = ED_DRAWINGAREA_TEXT_DISTANCE;
6532
6533   ModifyGadget(gi, GDI_X, MAX(x1, MAX(x2, x3)) + xoffset, GDI_END);
6534
6535   MapDrawingArea(id);
6536 }
6537
6538 static void DrawElementContentAreas()
6539 {
6540   int x = SX + ED_AREA_YAMYAM_CONTENT_XPOS(3) + 4 * MINI_TILEX;
6541   int y = SY + ED_AREA_YAMYAM_CONTENT_YPOS(0) + ED_BORDER_AREA_YSIZE;
6542   int i;
6543
6544   /* display counter to choose number of element content areas */
6545   MapCounterButtons(ED_COUNTER_ID_ELEMENT_CONTENT);
6546
6547   for (i = 0; i < MAX_ELEMENT_CONTENTS; i++)
6548   {
6549     int id = ED_DRAWING_ID_ELEMENT_CONTENT_0 + i;
6550     int font_height = getFontHeight(FONT_TEXT_1);
6551
6552     if (i < level.num_yamyam_contents)
6553       MapDrawingArea(id);
6554     else
6555     {
6556       UnmapDrawingArea(id);
6557
6558       /* delete content areas in case of reducing number of them */
6559       DrawBackground(SX + drawingarea_info[id].x - MINI_TILEX / 2,
6560                      SY + drawingarea_info[id].y - MINI_TILEY / 2,
6561                      4 * MINI_TILEX,
6562                      4 * MINI_TILEY + ED_GADGET_TEXT_DISTANCE + font_height);
6563     }
6564   }
6565
6566   DrawText(x, y + 0 * MINI_TILEY, "content", FONT_TEXT_1);
6567   DrawText(x, y + 1 * MINI_TILEY, "when",    FONT_TEXT_1);
6568   DrawText(x, y + 2 * MINI_TILEY, "smashed", FONT_TEXT_1);
6569 }
6570
6571 static void DrawGroupElementArea(int element)
6572 {
6573   int num_elements = group_element_info.num_elements;
6574   int id = ED_DRAWING_ID_GROUP_CONTENT;
6575   int sx = SX + drawingarea_info[id].x - MINI_TILEX / 2;
6576   int sy = SY + drawingarea_info[id].y - MINI_TILEY / 2;
6577   int xsize = MAX_ELEMENTS_IN_GROUP;
6578   int ysize = 1;
6579
6580   if (drawingarea_info[id].text_left != NULL)
6581     sx += getTextWidthForDrawingArea(drawingarea_info[id].text_left);
6582
6583   UnmapDrawingArea(id);
6584
6585   ModifyEditorDrawingArea(id, num_elements, 1);
6586
6587   /* delete content areas in case of reducing number of them */
6588   DrawBackground(sx, sy, (xsize + 1) * MINI_TILEX, (ysize + 1) * MINI_TILEY);
6589
6590   MapDrawingArea(id);
6591 }
6592
6593 static void DrawEnvelopeTextArea(int envelope_nr)
6594 {
6595   int id = ED_TEXTAREA_ID_ENVELOPE_INFO;
6596   struct GadgetInfo *gi = level_editor_gadget[textarea_info[id].gadget_id];
6597
6598   UnmapGadget(gi);
6599   DrawBackground(gi->x, gi->y, gi->width, gi->height);
6600
6601   if (envelope_nr != -1)
6602     textarea_info[id].value = level.envelope_text[envelope_nr];
6603
6604   ModifyGadget(gi, GDI_AREA_SIZE,
6605                *counterbutton_info[ED_COUNTER_ID_ENVELOPE_XSIZE].value,
6606                *counterbutton_info[ED_COUNTER_ID_ENVELOPE_YSIZE].value,
6607                GDI_END);
6608
6609   MapTextAreaGadget(ED_TEXTAREA_ID_ENVELOPE_INFO);
6610 }
6611
6612 char *getElementDescriptionFilename(int element)
6613 {
6614   char *docs_dir = options.docs_directory;
6615   char *elements_subdir = "elements";
6616   static char *filename = NULL;
6617   char basename[MAX_FILENAME_LEN];
6618
6619   checked_free(filename);
6620
6621   /* 1st try: look for element description file for exactly this element */
6622   sprintf(basename, "%s.txt", element_info[element].token_name);
6623   filename = getPath3(docs_dir, elements_subdir, basename);
6624   if (fileExists(filename))
6625     return filename;
6626
6627   free(filename);
6628
6629   /* 2nd try: look for element description file for this element's class */
6630   sprintf(basename, "%s.txt", element_info[element].class_name);
6631   filename = getPath3(docs_dir, elements_subdir, basename);
6632   if (fileExists(filename))
6633     return filename;
6634
6635   return NULL;
6636 }
6637
6638 static boolean PrintInfoText(char *text, int font_nr, int start_line)
6639 {
6640   int font_height = getFontHeight(font_nr);
6641   int pad_x = ED_SETTINGS_XPOS(0);
6642   int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
6643   int sx = SX + pad_x;
6644   int sy = SY + pad_y;
6645   int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
6646
6647   if (start_line >= max_lines_per_screen)
6648     return FALSE;
6649
6650   DrawText(sx, sy + start_line * font_height, text, font_nr);
6651
6652   return TRUE;
6653 }
6654
6655 #if 1
6656
6657 static int PrintElementDescriptionFromFile(char *filename, int start_line)
6658 {
6659   int font_nr = FONT_TEXT_2;
6660   int font_width = getFontWidth(font_nr);
6661   int font_height = getFontHeight(font_nr);
6662   int pad_x = ED_SETTINGS_XPOS(0);
6663   int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
6664   int sx = SX + pad_x;
6665   int sy = SY + pad_y + start_line * font_height;
6666   int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
6667   int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
6668
6669   return DrawTextFromFile(sx, sy, filename, font_nr, max_chars_per_line,
6670                           max_lines_per_screen);
6671 }
6672
6673 #else
6674
6675 static int PrintElementDescriptionFromFile(char *filename, int start_line)
6676 {
6677   int font_nr = FONT_TEXT_2;
6678   int font_width = getFontWidth(font_nr);
6679   int font_height = getFontHeight(font_nr);
6680   int pad_x = ED_SETTINGS_XPOS(0);
6681   int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
6682   int sx = SX + pad_x;
6683   int sy = SY + pad_y;
6684   int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
6685   int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
6686   int current_line = start_line;
6687   char line[MAX_LINE_LEN];
6688   char buffer[max_chars_per_line + 1];
6689   int buffer_len;
6690   FILE *file;
6691
6692   if (current_line >= max_lines_per_screen)
6693     return 0;
6694
6695   if (filename == NULL)
6696     return 0;
6697
6698   if (!(file = fopen(filename, MODE_READ)))
6699     return 0;
6700
6701   buffer[0] = '\0';
6702   buffer_len = 0;
6703
6704   while (!feof(file) && current_line < max_lines_per_screen)
6705   {
6706     char *line_ptr;
6707     boolean last_line_was_empty = TRUE;
6708
6709     /* read next line of input file */
6710     if (!fgets(line, MAX_LINE_LEN, file))
6711       break;
6712
6713     /* skip comments (lines directly beginning with '#') */
6714     if (line[0] == '#')
6715       continue;
6716
6717     /* cut trailing newline from input line */
6718     for (line_ptr = line; *line_ptr; line_ptr++)
6719     {
6720       if (*line_ptr == '\n' || *line_ptr == '\r')
6721       {
6722         *line_ptr = '\0';
6723         break;
6724       }
6725     }
6726
6727     if (strlen(line) == 0)              /* special case: force empty line */
6728       strcpy(line, "\n");
6729
6730     line_ptr = line;
6731
6732     while (*line_ptr && current_line < max_lines_per_screen)
6733     {
6734       boolean buffer_filled = RenderLineToBuffer(&line_ptr,
6735                                                  buffer, &buffer_len,
6736                                                  last_line_was_empty,
6737                                                  max_chars_per_line);
6738       if (buffer_filled)
6739       {
6740         DrawText(sx, sy + current_line * font_height, buffer, font_nr);
6741         current_line++;
6742
6743         last_line_was_empty = (buffer_len == 0);
6744
6745         buffer[0] = '\0';
6746         buffer_len = 0;
6747       }
6748     }
6749   }
6750
6751   fclose(file);
6752
6753   if (buffer_len > 0 && current_line < max_lines_per_screen)
6754   {
6755     DrawText(sx, sy + current_line * font_height, buffer, font_nr);
6756     current_line++;
6757   }
6758
6759   return (current_line - start_line);
6760 }
6761
6762 #endif
6763
6764 static void DrawPropertiesTabulatorGadgets()
6765 {
6766   struct GadgetInfo *gd_gi = level_editor_gadget[GADGET_ID_PROPERTIES_INFO];
6767   struct GadgetDesign *gd = &gd_gi->alt_design[GD_BUTTON_UNPRESSED];
6768   int gd_x = gd->x + gd_gi->border.width / 2;
6769   int gd_y = gd->y + gd_gi->height - 1;
6770   Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
6771   int id_first = ED_TEXTBUTTON_ID_PROPERTIES_INFO;
6772   int id_last  = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG;
6773   int max_tabs = 4;
6774   int i;
6775
6776   /* draw additional "advanced" tabulator for custom elements */
6777   if (IS_CUSTOM_ELEMENT(properties_element))
6778     id_last = ED_TEXTBUTTON_ID_PROPERTIES_CHANGE;
6779
6780   for (i = id_first; i <= id_last; i++)
6781   {
6782     int gadget_id = textbutton_info[i].gadget_id;
6783     struct GadgetInfo *gi = level_editor_gadget[gadget_id];
6784     boolean active = (i != edit_mode_properties);
6785
6786     /* use "config 1" and "config 2" instead of "config" */
6787     if (i == ED_TEXTBUTTON_ID_PROPERTIES_CONFIG &&
6788         IS_CUSTOM_ELEMENT(properties_element))
6789       continue;
6790
6791     /* draw background line below tabulator button */
6792     ClearRectangleOnBackground(drawto, gi->x, gi->y + gi->height, gi->width,1);
6793
6794     /* draw solid line below inactive tabulator buttons */
6795     if (!active && tab_color != BLACK_PIXEL)    /* black => transparent */
6796       FillRectangle(drawto, gi->x, gi->y + gi->height, gi->width,1, tab_color);
6797
6798     ModifyGadget(gi, GDI_ACTIVE, active, GDI_END);
6799     MapTextbuttonGadget(i);
6800   }
6801
6802   /* draw little border line below tabulator buttons */
6803   if (tab_color != BLACK_PIXEL)                 /* black => transparent */
6804     FillRectangle(drawto, gd_gi->x, gd_gi->y + gd_gi->height + 1,
6805                   max_tabs * gd_gi->width + (max_tabs -1) * ED_GADGET_DISTANCE,
6806                   ED_GADGET_DISTANCE, tab_color);
6807 }
6808
6809 static void DrawPropertiesInfo()
6810 {
6811   static struct
6812   {
6813     int value;
6814     char *text;
6815   }
6816   properties[] =
6817   {
6818     /* configurable properties */
6819
6820     { EP_WALKABLE_OVER,         "- player can walk over it"             },
6821     { EP_WALKABLE_INSIDE,       "- player can walk inside it"           },
6822     { EP_WALKABLE_UNDER,        "- player can walk under it"            },
6823     { EP_PASSABLE_OVER,         "- player can pass over it"             },
6824     { EP_PASSABLE_INSIDE,       "- player can pass through it"          },
6825     { EP_PASSABLE_UNDER,        "- player can pass under it"            },
6826     { EP_PROTECTED,             "- player is protected by it"           },
6827
6828     { EP_DIGGABLE,              "- can be digged away"                  },
6829     { EP_COLLECTIBLE,           "- can be collected"                    },
6830     { EP_DROPPABLE,             "- can be dropped after collecting"     },
6831     { EP_THROWABLE,             "- can be thrown after collecting"      },
6832     { EP_PUSHABLE,              "- can be pushed"                       },
6833
6834     { EP_CAN_FALL,              "- can fall"                            },
6835     { EP_CAN_MOVE,              "- can move"                            },
6836
6837     { EP_CAN_SMASH_PLAYER,      "- can smash player"                    },
6838 #if 0
6839     { EP_CAN_SMASH_ENEMIES,     "- can smash good and bad guys"         },
6840 #endif
6841     { EP_CAN_SMASH_EVERYTHING,  "- can smash everything smashable"      },
6842
6843     { EP_SLIPPERY,              "- slippery for falling elements"       },
6844     { EP_EM_SLIPPERY_WALL,      "- slippery for some gems (EM style)"   },
6845
6846     { EP_DONT_RUN_INTO,         "- deadly when running into"            },
6847     { EP_DONT_COLLIDE_WITH,     "- deadly when colliding with"          },
6848     { EP_DONT_TOUCH,            "- deadly when touching"                },
6849
6850     { EP_INDESTRUCTIBLE,        "- indestructible"                      },
6851
6852     { EP_CAN_EXPLODE_BY_FIRE,   "- can explode by fire or explosions"   },
6853     { EP_CAN_EXPLODE_SMASHED,   "- can explode when smashed"            },
6854     { EP_CAN_EXPLODE_IMPACT,    "- can explode on impact"               },
6855
6856     { EP_CAN_CHANGE,            "- can change to other element"         },
6857
6858     /* pre-defined properties */
6859     { EP_CAN_PASS_MAGIC_WALL,   "- can pass magic walls"                },
6860     { EP_SWITCHABLE,            "- can be switched"                     },
6861     { EP_HAS_CONTENT,           "- can contain other elements"          },
6862
6863     { -1,                       NULL                                    }
6864   };
6865   char *filename = getElementDescriptionFilename(properties_element);
6866   char *percentage_text = "In this level:";
6867   char *properties_text = "Standard properties:";
6868   float percentage;
6869   int num_elements_in_level;
6870   int num_standard_properties = 0;
6871   int font1_nr = FONT_TEXT_1;
6872   int font2_nr = FONT_TEXT_2;
6873   int font1_width = getFontWidth(font1_nr);
6874   int font2_height = getFontHeight(font2_nr);
6875   int pad_x = ED_SETTINGS_XPOS(0);
6876   int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
6877   int screen_line = 0;
6878   int i, x, y;
6879
6880 #if DEBUG
6881   if (IS_CUSTOM_ELEMENT(properties_element))
6882   {
6883     DrawTextF(pad_x, pad_y + screen_line++ * font2_height, FONT_TEXT_3,
6884               "[Custom Element %d]", properties_element - EL_CUSTOM_START + 1);
6885     screen_line++;
6886   }
6887   else if (IS_GROUP_ELEMENT(properties_element))
6888   {
6889     DrawTextF(pad_x, pad_y + screen_line++ * font2_height, FONT_TEXT_3,
6890               "[Group Element %d]", properties_element - EL_GROUP_START + 1);
6891     screen_line++;
6892   }
6893 #endif
6894
6895   /* ----- print number of elements / percentage of this element in level */
6896
6897   num_elements_in_level = 0;
6898   for (y = 0; y < lev_fieldy; y++) 
6899     for (x = 0; x < lev_fieldx; x++)
6900       if (Feld[x][y] == properties_element)
6901         num_elements_in_level++;
6902   percentage = num_elements_in_level * 100.0 / (lev_fieldx * lev_fieldy);
6903
6904   DrawTextS(pad_x, pad_y + screen_line * font2_height, font1_nr,
6905             percentage_text);
6906   DrawTextF(pad_x + strlen(percentage_text) * font1_width,
6907             pad_y + screen_line++ * font2_height, font2_nr,
6908             "%d (%.2f%%)", num_elements_in_level, percentage);
6909
6910   screen_line++;
6911
6912   /* ----- print standard properties of this element */
6913
6914   DrawTextS(pad_x, pad_y + screen_line++ * font2_height, font1_nr,
6915             properties_text);
6916
6917   for (i = 0; properties[i].value != -1; i++)
6918   {
6919     if (!HAS_PROPERTY(properties_element, properties[i].value))
6920       continue;
6921
6922     DrawTextS(pad_x, pad_y + screen_line++ * font2_height, font2_nr,
6923               properties[i].text);
6924     num_standard_properties++;
6925   }
6926
6927   if (num_standard_properties == 0)
6928     DrawTextS(pad_x + strlen(properties_text) * font1_width,
6929               pad_y + (screen_line - 1) * font2_height, font2_nr, "none");
6930
6931   screen_line++;
6932
6933   /* ----- print special description of this element */
6934
6935   PrintInfoText("Description:", FONT_TEXT_1, screen_line);
6936   if (PrintElementDescriptionFromFile(filename, screen_line + 1) == 0)
6937     PrintInfoText("No description available.", FONT_TEXT_1, screen_line);
6938 }
6939
6940 #define TEXT_COLLECTING         "Score for collecting"
6941 #define TEXT_SMASHING           "Score for smashing"
6942 #define TEXT_CRACKING           "Score for cracking"
6943 #define TEXT_SPEED              "Speed of amoeba growth"
6944 #define TEXT_DURATION           "Duration when activated"
6945
6946 static struct
6947 {
6948   int element;
6949   int *value;
6950   char *text;
6951 } elements_with_counter[] =
6952 {
6953   { EL_EMERALD,         &level.score[SC_EMERALD],       TEXT_COLLECTING },
6954   { EL_BD_DIAMOND,      &level.score[SC_EMERALD],       TEXT_COLLECTING },
6955   { EL_EMERALD_YELLOW,  &level.score[SC_EMERALD],       TEXT_COLLECTING },
6956   { EL_EMERALD_RED,     &level.score[SC_EMERALD],       TEXT_COLLECTING },
6957   { EL_EMERALD_PURPLE,  &level.score[SC_EMERALD],       TEXT_COLLECTING },
6958   { EL_SP_INFOTRON,     &level.score[SC_EMERALD],       TEXT_COLLECTING },
6959   { EL_DIAMOND,         &level.score[SC_DIAMOND],       TEXT_COLLECTING },
6960   { EL_CRYSTAL,         &level.score[SC_CRYSTAL],       TEXT_COLLECTING },
6961   { EL_PEARL,           &level.score[SC_PEARL],         TEXT_COLLECTING },
6962   { EL_BUG,             &level.score[SC_BUG],           TEXT_SMASHING   },
6963   { EL_BUG_RIGHT,       &level.score[SC_BUG],           TEXT_SMASHING   },
6964   { EL_BUG_UP,          &level.score[SC_BUG],           TEXT_SMASHING   },
6965   { EL_BUG_LEFT,        &level.score[SC_BUG],           TEXT_SMASHING   },
6966   { EL_BUG_DOWN,        &level.score[SC_BUG],           TEXT_SMASHING   },
6967   { EL_BD_BUTTERFLY,    &level.score[SC_BUG],           TEXT_SMASHING   },
6968   { EL_BD_BUTTERFLY_RIGHT,&level.score[SC_BUG],         TEXT_SMASHING   },
6969   { EL_BD_BUTTERFLY_UP,   &level.score[SC_BUG],         TEXT_SMASHING   },
6970   { EL_BD_BUTTERFLY_LEFT, &level.score[SC_BUG],         TEXT_SMASHING   },
6971   { EL_BD_BUTTERFLY_DOWN, &level.score[SC_BUG],         TEXT_SMASHING   },
6972   { EL_SP_ELECTRON,     &level.score[SC_BUG],           TEXT_SMASHING   },
6973   { EL_SPACESHIP,       &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6974   { EL_SPACESHIP_RIGHT, &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6975   { EL_SPACESHIP_UP,    &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6976   { EL_SPACESHIP_LEFT,  &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6977   { EL_SPACESHIP_DOWN,  &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6978   { EL_BD_FIREFLY,      &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6979   { EL_BD_FIREFLY_RIGHT,&level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6980   { EL_BD_FIREFLY_UP,   &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6981   { EL_BD_FIREFLY_LEFT, &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6982   { EL_BD_FIREFLY_DOWN, &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6983   { EL_SP_SNIKSNAK,     &level.score[SC_SPACESHIP],     TEXT_SMASHING   },
6984   { EL_YAMYAM,          &level.score[SC_YAMYAM],        TEXT_SMASHING   },
6985   { EL_DARK_YAMYAM,     &level.score[SC_YAMYAM],        TEXT_SMASHING   },
6986   { EL_ROBOT,           &level.score[SC_ROBOT],         TEXT_SMASHING   },
6987   { EL_PACMAN,          &level.score[SC_PACMAN],        TEXT_SMASHING   },
6988   { EL_PACMAN_RIGHT,    &level.score[SC_PACMAN],        TEXT_SMASHING   },
6989   { EL_PACMAN_UP,       &level.score[SC_PACMAN],        TEXT_SMASHING   },
6990   { EL_PACMAN_LEFT,     &level.score[SC_PACMAN],        TEXT_SMASHING   },
6991   { EL_PACMAN_DOWN,     &level.score[SC_PACMAN],        TEXT_SMASHING   },
6992   { EL_NUT,             &level.score[SC_NUT],           TEXT_CRACKING   },
6993   { EL_DYNAMITE,        &level.score[SC_DYNAMITE],      TEXT_COLLECTING },
6994   { EL_DYNABOMB_INCREASE_NUMBER,&level.score[SC_DYNAMITE],TEXT_COLLECTING },
6995   { EL_DYNABOMB_INCREASE_SIZE,  &level.score[SC_DYNAMITE],TEXT_COLLECTING },
6996   { EL_DYNABOMB_INCREASE_POWER, &level.score[SC_DYNAMITE],TEXT_COLLECTING },
6997   { EL_SHIELD_NORMAL,   &level.score[SC_SHIELD],        TEXT_COLLECTING },
6998   { EL_SHIELD_DEADLY,   &level.score[SC_SHIELD],        TEXT_COLLECTING },
6999   { EL_EXTRA_TIME,      &level.score[SC_TIME_BONUS],    TEXT_COLLECTING },
7000   { EL_KEY_1,           &level.score[SC_KEY],           TEXT_COLLECTING },
7001   { EL_KEY_2,           &level.score[SC_KEY],           TEXT_COLLECTING },
7002   { EL_KEY_3,           &level.score[SC_KEY],           TEXT_COLLECTING },
7003   { EL_KEY_4,           &level.score[SC_KEY],           TEXT_COLLECTING },
7004 #if 1
7005   { EL_EM_KEY_1,        &level.score[SC_KEY],           TEXT_COLLECTING },
7006   { EL_EM_KEY_2,        &level.score[SC_KEY],           TEXT_COLLECTING },
7007   { EL_EM_KEY_3,        &level.score[SC_KEY],           TEXT_COLLECTING },
7008   { EL_EM_KEY_4,        &level.score[SC_KEY],           TEXT_COLLECTING },
7009 #else
7010   { EL_EM_KEY_1_FILE,   &level.score[SC_KEY],           TEXT_COLLECTING },
7011   { EL_EM_KEY_2_FILE,   &level.score[SC_KEY],           TEXT_COLLECTING },
7012   { EL_EM_KEY_3_FILE,   &level.score[SC_KEY],           TEXT_COLLECTING },
7013   { EL_EM_KEY_4_FILE,   &level.score[SC_KEY],           TEXT_COLLECTING },
7014 #endif
7015   { EL_AMOEBA_WET,      &level.amoeba_speed,            TEXT_SPEED      },
7016   { EL_AMOEBA_DRY,      &level.amoeba_speed,            TEXT_SPEED      },
7017   { EL_AMOEBA_FULL,     &level.amoeba_speed,            TEXT_SPEED      },
7018   { EL_BD_AMOEBA,       &level.amoeba_speed,            TEXT_SPEED      },
7019   { EL_MAGIC_WALL,      &level.time_magic_wall,         TEXT_DURATION   },
7020   { EL_ROBOT_WHEEL,     &level.time_wheel,              TEXT_DURATION   },
7021   { -1,                 NULL,                           NULL            }
7022 };
7023
7024 static boolean checkPropertiesConfig(int element)
7025 {
7026   int i;
7027
7028   if (IS_GEM(element) ||
7029       IS_CUSTOM_ELEMENT(element) ||
7030       IS_GROUP_ELEMENT(element) ||
7031       IS_ENVELOPE(element) ||
7032       ELEM_IS_PLAYER(element) ||
7033       HAS_CONTENT(element) ||
7034       CAN_GROW(element) ||
7035       COULD_MOVE_INTO_ACID(element) ||
7036       MAYBE_DONT_COLLIDE_WITH(element))
7037     return TRUE;
7038   else
7039     for (i = 0; elements_with_counter[i].element != -1; i++)
7040       if (elements_with_counter[i].element == element)
7041         return TRUE;
7042
7043   return FALSE;
7044 }
7045
7046 static void DrawPropertiesConfig()
7047 {
7048   int i;
7049
7050   if (!checkPropertiesConfig(properties_element))
7051   {
7052     PrintInfoText("No configuration options available.", FONT_TEXT_1, 0);
7053
7054     return;
7055   }
7056
7057   /* check if there are elements where a score can be chosen for */
7058   for (i = 0; elements_with_counter[i].element != -1; i++)
7059   {
7060     if (elements_with_counter[i].element == properties_element)
7061     {
7062       int counter_id = ED_COUNTER_ID_ELEMENT_SCORE;
7063
7064       counterbutton_info[counter_id].y =
7065         ED_SETTINGS_YPOS((HAS_CONTENT(properties_element) ? 1 : 0) +
7066                          (CAN_GROW(properties_element) ? 1 : 0) +
7067                          (COULD_MOVE_INTO_ACID(properties_element) ? 1 : 0) +
7068                          (MAYBE_DONT_COLLIDE_WITH(properties_element) ? 1 :0));
7069
7070       counterbutton_info[counter_id].value = elements_with_counter[i].value;
7071       counterbutton_info[counter_id].text_right= elements_with_counter[i].text;
7072
7073       MapCounterButtons(counter_id);
7074
7075       break;
7076     }
7077   }
7078
7079   if (HAS_CONTENT(properties_element))
7080   {
7081     /* draw stickybutton gadget */
7082     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
7083
7084     if (IS_AMOEBOID(properties_element))
7085       MapDrawingArea(ED_DRAWING_ID_AMOEBA_CONTENT);
7086     else
7087       DrawElementContentAreas();
7088   }
7089
7090   if (ELEM_IS_PLAYER(properties_element))
7091   {
7092     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID);
7093     MapCheckbuttonGadget(properties_element == EL_SP_MURPHY ?
7094                          ED_CHECKBUTTON_ID_SP_BLOCK_LAST_FIELD :
7095                          ED_CHECKBUTTON_ID_BLOCK_LAST_FIELD);
7096     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_INSTANT_RELOCATION);
7097     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_PASS_TO_WALKABLE);
7098   }
7099
7100   if (IS_GEM(properties_element))
7101     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_EM_SLIPPERY_GEMS);
7102
7103   if (COULD_MOVE_INTO_ACID(properties_element) &&
7104       !ELEM_IS_PLAYER(properties_element) &&
7105       (!IS_CUSTOM_ELEMENT(properties_element) ||
7106        edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2))
7107   {
7108     /* set position for checkbutton for "can move into acid" */
7109     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].x =
7110       ED_SETTINGS_XPOS(IS_CUSTOM_ELEMENT(properties_element) ? 1 : 0);
7111     checkbutton_info[ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID].y =
7112       ED_SETTINGS_YPOS(IS_CUSTOM_ELEMENT(properties_element) ? 6 :
7113                        HAS_CONTENT(properties_element) ? 1 : 0);
7114
7115     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID);
7116   }
7117
7118   if (MAYBE_DONT_COLLIDE_WITH(properties_element))
7119     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH);
7120
7121   if (properties_element == EL_SPRING)
7122     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_USE_SPRING_BUG);
7123
7124   if (CAN_GROW(properties_element))
7125   {
7126     checkbutton_info[ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE].y =
7127       ED_SETTINGS_YPOS(HAS_CONTENT(properties_element) ? 1 : 0);
7128
7129     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_GROW_INTO_DIGGABLE);
7130   }
7131
7132   if (IS_ENVELOPE(properties_element))
7133   {
7134     int counter1_id = ED_COUNTER_ID_ENVELOPE_XSIZE;
7135     int counter2_id = ED_COUNTER_ID_ENVELOPE_YSIZE;
7136     int envelope_nr = properties_element - EL_ENVELOPE_1;
7137
7138     counterbutton_info[counter1_id].value = &level.envelope_xsize[envelope_nr];
7139     counterbutton_info[counter2_id].value = &level.envelope_ysize[envelope_nr];
7140
7141     /* display counter to choose size of envelope text area */
7142     MapCounterButtons(ED_COUNTER_ID_ENVELOPE_XSIZE);
7143     MapCounterButtons(ED_COUNTER_ID_ENVELOPE_YSIZE);
7144
7145     DrawEnvelopeTextArea(envelope_nr);
7146   }
7147
7148   if (IS_CUSTOM_ELEMENT(properties_element))
7149   {
7150     /* draw stickybutton gadget */
7151     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
7152
7153     if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_1)
7154     {
7155       /* draw checkbutton gadgets */
7156       for (i =  ED_CHECKBUTTON_ID_CUSTOM1_FIRST;
7157            i <= ED_CHECKBUTTON_ID_CUSTOM1_LAST; i++)
7158         MapCheckbuttonGadget(i);
7159
7160       /* draw counter gadgets */
7161       for (i =  ED_COUNTER_ID_CUSTOM1_FIRST;
7162            i <= ED_COUNTER_ID_CUSTOM1_LAST; i++)
7163         MapCounterButtons(i);
7164
7165       /* draw selectbox gadgets */
7166       for (i =  ED_SELECTBOX_ID_CUSTOM1_FIRST;
7167            i <= ED_SELECTBOX_ID_CUSTOM1_LAST; i++)
7168         MapSelectboxGadget(i);
7169
7170       /* draw textbutton gadgets */
7171       MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE);
7172
7173       /* draw text input gadgets */
7174       MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
7175
7176       /* draw drawing area gadgets */
7177       MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
7178     }
7179     else if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG_2)
7180     {
7181       /* draw checkbutton gadgets */
7182       for (i =  ED_CHECKBUTTON_ID_CUSTOM2_FIRST;
7183            i <= ED_CHECKBUTTON_ID_CUSTOM2_LAST; i++)
7184         MapCheckbuttonGadget(i);
7185
7186       /* draw counter gadgets */
7187       for (i =  ED_COUNTER_ID_CUSTOM2_FIRST;
7188            i <= ED_COUNTER_ID_CUSTOM2_LAST; i++)
7189         MapCounterButtons(i);
7190
7191       /* draw selectbox gadgets */
7192       for (i =  ED_SELECTBOX_ID_CUSTOM2_FIRST;
7193            i <= ED_SELECTBOX_ID_CUSTOM2_LAST; i++)
7194         MapSelectboxGadget(i);
7195
7196       /* draw drawing area gadgets */
7197       MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_ENTER);
7198       MapDrawingArea(ED_DRAWING_ID_CUSTOM_MOVE_LEAVE);
7199       DrawCustomContentArea();
7200     }
7201   }
7202   else if (IS_GROUP_ELEMENT(properties_element))
7203   {
7204     /* draw stickybutton gadget */
7205     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
7206
7207     /* draw checkbutton gadgets */
7208     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC);
7209     MapCheckbuttonGadget(ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE);
7210
7211     /* draw counter gadgets */
7212     MapCounterButtons(ED_COUNTER_ID_GROUP_CONTENT);
7213
7214     /* draw selectbox gadgets */
7215     MapSelectboxGadget(ED_SELECTBOX_ID_GROUP_CHOICE_MODE);
7216
7217     /* draw textbutton gadgets */
7218     MapTextbuttonGadget(ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE);
7219
7220     /* draw drawing area gadgets */
7221     DrawGroupElementArea(properties_element);
7222
7223     /* draw text input gadgets */
7224     MapTextInputGadget(ED_TEXTINPUT_ID_ELEMENT_NAME);
7225
7226     /* draw drawing area gadgets */
7227     MapDrawingArea(ED_DRAWING_ID_CUSTOM_GRAPHIC);
7228   }
7229 }
7230
7231 static void DrawPropertiesChangeDrawingAreas()
7232 {
7233   if (IS_CUSTOM_ELEMENT(properties_element))
7234   {
7235     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TARGET);
7236     MapDrawingArea(ED_DRAWING_ID_CUSTOM_CHANGE_TRIGGER);
7237
7238     DrawCustomChangeContentArea();
7239   }
7240
7241   redraw_mask |= REDRAW_FIELD;
7242 }
7243
7244 static void DrawPropertiesChange()
7245 {
7246   int i;
7247
7248   /* draw stickybutton gadget */
7249   MapCheckbuttonGadget(ED_CHECKBUTTON_ID_STICK_ELEMENT);
7250
7251   /* draw checkbutton gadgets */
7252   for (i =  ED_CHECKBUTTON_ID_CHANGE_FIRST;
7253        i <= ED_CHECKBUTTON_ID_CHANGE_LAST; i++)
7254     MapCheckbuttonGadget(i);
7255
7256   /* draw counter gadgets */
7257   for (i =  ED_COUNTER_ID_CHANGE_FIRST;
7258        i <= ED_COUNTER_ID_CHANGE_LAST; i++)
7259     MapCounterButtons(i);
7260
7261   /* draw selectbox gadgets */
7262   for (i =  ED_SELECTBOX_ID_CHANGE_FIRST;
7263        i <= ED_SELECTBOX_ID_CHANGE_LAST; i++)
7264     MapSelectboxGadget(i);
7265
7266   /* draw textbutton gadgets */
7267   for (i =  ED_TEXTBUTTON_ID_CHANGE_FIRST;
7268        i <= ED_TEXTBUTTON_ID_CHANGE_LAST; i++)
7269     MapTextbuttonGadget(i);
7270
7271   /* draw graphicbutton gadgets */
7272   for (i =  ED_GRAPHICBUTTON_ID_CHANGE_FIRST;
7273        i <= ED_GRAPHICBUTTON_ID_CHANGE_LAST; i++)
7274     MapGraphicbuttonGadget(i);
7275
7276   /* draw drawing area gadgets */
7277   DrawPropertiesChangeDrawingAreas();
7278 }
7279
7280 static void DrawElementName(int x, int y, int element)
7281 {
7282   char *element_name = getElementInfoText(element);
7283   int font_nr = FONT_TEXT_1;
7284   int font_width = getFontWidth(font_nr);
7285   int font_height = getFontHeight(font_nr);
7286   int max_text_width = SXSIZE - x - ED_SETTINGS_XPOS(0);
7287   int max_chars_per_line = max_text_width / font_width;
7288   char buffer[max_chars_per_line + 1];
7289
7290   if (strlen(element_name) <= max_chars_per_line)
7291     DrawTextS(x, y, font_nr, element_name);
7292   else
7293   {
7294     int next_pos = max_chars_per_line;
7295
7296     strncpy(buffer, element_name, max_chars_per_line);
7297     buffer[max_chars_per_line] = '\0';
7298
7299     if (element_name[max_chars_per_line] == ' ')
7300       next_pos++;
7301     else
7302     {
7303       int i;
7304
7305       for (i = max_chars_per_line - 1; i >= 0; i--)
7306         if (buffer[i] == ' ')
7307           break;
7308
7309       if (strlen(&element_name[i + 1]) <= max_chars_per_line)
7310       {
7311         buffer[i] = '\0';
7312         next_pos = i + 1;
7313       }
7314     }
7315
7316     DrawTextS(x, y - font_height / 2, font_nr, buffer);
7317
7318     strncpy(buffer, &element_name[next_pos], max_chars_per_line);
7319     buffer[max_chars_per_line] = '\0';
7320
7321     DrawTextS(x, y + font_height / 2, font_nr, buffer);
7322   }
7323 }
7324
7325 static void DrawPropertiesWindow()
7326 {
7327   int xstart = 2;
7328   int ystart = 4;
7329
7330   stick_element_properties_window = FALSE;
7331
7332   /* make sure that previous properties edit mode exists for this element */
7333   if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG &&
7334       !IS_CUSTOM_ELEMENT(properties_element))
7335     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
7336
7337   if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG &&
7338       IS_CUSTOM_ELEMENT(properties_element))
7339     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_1;
7340
7341   CopyElementPropertiesToEditor(properties_element);
7342
7343   UnmapLevelEditorWindowGadgets();
7344   UnmapLevelEditorToolboxDrawingGadgets();
7345   UnmapLevelEditorToolboxCustomGadgets();
7346
7347   if (IS_CUSTOM_ELEMENT(properties_element) ||
7348       IS_GROUP_ELEMENT(properties_element))
7349     MapLevelEditorToolboxCustomGadgets();
7350
7351   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
7352   ClearWindow();
7353
7354   DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS1_YPOS,
7355            "Element Settings", FONT_TITLE_1);
7356
7357   DrawElementBorder(SX + xstart * MINI_TILEX,
7358                     SY + ystart * MINI_TILEY + MINI_TILEY / 2,
7359                     TILEX, TILEY, FALSE);
7360   DrawGraphicAnimationExt(drawto,
7361                           SX + xstart * MINI_TILEX,
7362                           SY + ystart * MINI_TILEY + MINI_TILEY / 2,
7363                           el2img(properties_element), -1, NO_MASKING);
7364
7365   FrameCounter = 0;     /* restart animation frame counter */
7366
7367   DrawElementName((xstart + 3) * MINI_TILEX + 1, (ystart + 1) * MINI_TILEY + 1,
7368                   properties_element);
7369
7370   DrawPropertiesTabulatorGadgets();
7371
7372   if (edit_mode_properties == ED_MODE_PROPERTIES_INFO)
7373     DrawPropertiesInfo();
7374   else if (edit_mode_properties == ED_MODE_PROPERTIES_CHANGE)
7375     DrawPropertiesChange();
7376   else  /* (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG[_1|_2]) */
7377     DrawPropertiesConfig();
7378 }
7379
7380 static void UpdateCustomElementGraphicGadgets()
7381 {
7382   int i;
7383
7384   ModifyEditorElementList();
7385   RedrawDrawingElements();
7386
7387   /* force redraw of all mapped drawing area gadgets */
7388   for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
7389   {
7390     struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[i].gadget_id];
7391
7392     if (gi->mapped)
7393       MapDrawingArea(i);
7394   }
7395 }
7396
7397 static void DrawLineElement(int sx, int sy, int element, boolean change_level)
7398 {
7399   int lx = sx + level_xpos;
7400   int ly = sy + level_ypos;
7401
7402   DrawMiniElement(sx, sy, (element < 0 ? Feld[lx][ly] : element));
7403
7404   if (change_level)
7405     Feld[lx][ly] = element;
7406 }
7407
7408 static void DrawLine(int from_x, int from_y, int to_x, int to_y,
7409                      int element, boolean change_level)
7410 {
7411   if (from_y == to_y)                   /* horizontal line */
7412   {
7413     int x;
7414     int y = from_y;
7415
7416     if (from_x > to_x)
7417       swap_numbers(&from_x, &to_x);
7418
7419     for (x = from_x; x <= to_x; x++)
7420       DrawLineElement(x, y, element, change_level);
7421   }
7422   else if (from_x == to_x)              /* vertical line */
7423   {
7424     int x = from_x;
7425     int y;
7426
7427     if (from_y > to_y)
7428       swap_numbers(&from_y, &to_y);
7429
7430     for (y = from_y; y <= to_y; y++)
7431       DrawLineElement(x, y, element, change_level);
7432   }
7433   else                                  /* diagonal line */
7434   {
7435     int len_x = ABS(to_x - from_x);
7436     int len_y = ABS(to_y - from_y);
7437     int x, y;
7438
7439     if (len_y < len_x)                  /* a < 1 */
7440     {
7441       float a = (float)len_y / (float)len_x;
7442
7443       if (from_x > to_x)
7444         swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
7445
7446       for (x = 0; x <= len_x; x++)
7447       {
7448         y = (int)(a * x + 0.5) * (to_y < from_y ? -1 : +1);
7449         DrawLineElement(from_x + x, from_y + y, element, change_level);
7450       }
7451     }
7452     else                                /* a >= 1 */
7453     {
7454       float a = (float)len_x / (float)len_y;
7455
7456       if (from_y > to_y)
7457         swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
7458
7459       for (y = 0; y <= len_y; y++)
7460       {
7461         x = (int)(a * y + 0.5) * (to_x < from_x ? -1 : +1);
7462         DrawLineElement(from_x + x, from_y + y, element, change_level);
7463       }
7464     }
7465   }
7466 }
7467
7468 static void DrawBox(int from_x, int from_y, int to_x, int to_y,
7469                     int element, boolean change_level)
7470 {
7471   DrawLine(from_x, from_y, from_x, to_y, element, change_level);
7472   DrawLine(from_x, to_y, to_x, to_y, element, change_level);
7473   DrawLine(to_x, to_y, to_x, from_y, element, change_level);
7474   DrawLine(to_x, from_y, from_x, from_y, element, change_level);
7475 }
7476
7477 static void DrawFilledBox(int from_x, int from_y, int to_x, int to_y,
7478                           int element, boolean change_level)
7479 {
7480   int y;
7481
7482   if (from_y > to_y)
7483     swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
7484
7485   for (y = from_y; y <= to_y; y++)
7486     DrawLine(from_x, y, to_x, y, element, change_level);
7487 }
7488
7489 static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
7490                        int element, boolean change_level)
7491 {
7492   int to_x = to_x2 - (to_x2 > from_x ? +1 : -1);
7493   int to_y = to_y2 - (to_y2 > from_y ? +1 : -1);
7494   int len_x = ABS(to_x - from_x);
7495   int len_y = ABS(to_y - from_y);
7496   int radius, x, y;
7497
7498   radius = (int)(sqrt((float)(len_x * len_x + len_y * len_y)) + 0.5);
7499
7500   /* not optimal (some points get drawn twice) but simple,
7501      and fast enough for the few points we are drawing */
7502
7503   for (x = 0; x <= radius; x++)
7504   {
7505     int sx, sy, lx, ly;
7506
7507     y = (int)(sqrt((float)(radius * radius - x * x)) + 0.5);
7508
7509     sx = from_x + x * (from_x < to_x2 ? +1 : -1);
7510     sy = from_y + y * (from_y < to_y2 ? +1 : -1);
7511     lx = sx + level_xpos;
7512     ly = sy + level_ypos;
7513
7514     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
7515       DrawLineElement(sx, sy, element, change_level);
7516   }
7517
7518   for (y = 0; y <= radius; y++)
7519   {
7520     int sx, sy, lx, ly;
7521
7522     x = (int)(sqrt((float)(radius * radius - y * y)) + 0.5);
7523
7524     sx = from_x + x * (from_x < to_x2 ? +1 : -1);
7525     sy = from_y + y * (from_y < to_y2 ? +1 : -1);
7526     lx = sx + level_xpos;
7527     ly = sy + level_ypos;
7528
7529     if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
7530       DrawLineElement(sx, sy, element, change_level);
7531   }
7532 }
7533
7534 static void DrawArc(int from_x, int from_y, int to_x, int to_y,
7535                     int element, boolean change_level)
7536 {
7537   int to_x2 = to_x + (to_x < from_x ? -1 : +1);
7538   int to_y2 = to_y + (to_y > from_y ? +1 : -1);
7539
7540   DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
7541 }
7542
7543 #define DRAW_CIRCLES_BUTTON_AVAILABLE   0
7544 #if DRAW_CIRCLES_BUTTON_AVAILABLE
7545 static void DrawCircle(int from_x, int from_y, int to_x, int to_y,
7546                        int element, boolean change_level)
7547 {
7548   int to_x2 = to_x + (to_x < from_x ? -1 : +1);
7549   int to_y2 = to_y + (to_y > from_y ? +1 : -1);
7550   int mirror_to_x2 = from_x - (to_x2 - from_x);
7551   int mirror_to_y2 = from_y - (to_y2 - from_y);
7552
7553   DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
7554   DrawArcExt(from_x, from_y, mirror_to_x2, to_y2, element, change_level);
7555   DrawArcExt(from_x, from_y, to_x2, mirror_to_y2, element, change_level);
7556   DrawArcExt(from_x, from_y, mirror_to_x2, mirror_to_y2, element,change_level);
7557 }
7558 #endif
7559
7560 static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y)
7561 {
7562   int from_sx, from_sy;
7563   int to_sx, to_sy;
7564
7565   if (from_x > to_x)
7566     swap_numbers(&from_x, &to_x);
7567
7568   if (from_y > to_y)
7569     swap_numbers(&from_y, &to_y);
7570
7571   from_sx = SX + from_x * MINI_TILEX;
7572   from_sy = SY + from_y * MINI_TILEY;
7573   to_sx = SX + to_x * MINI_TILEX + MINI_TILEX - 1;
7574   to_sy = SY + to_y * MINI_TILEY + MINI_TILEY - 1;
7575
7576   DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx, from_sy);
7577   DrawSimpleWhiteLine(drawto, to_sx, from_sy, to_sx, to_sy);
7578   DrawSimpleWhiteLine(drawto, to_sx, to_sy, from_sx, to_sy);
7579   DrawSimpleWhiteLine(drawto, from_sx, to_sy, from_sx, from_sy);
7580
7581   if (from_x == to_x && from_y == to_y)
7582     MarkTileDirty(from_x/2, from_y/2);
7583   else
7584     redraw_mask |= REDRAW_FIELD;
7585 }
7586
7587 static void SelectArea(int from_x, int from_y, int to_x, int to_y,
7588                        int element, boolean change_level)
7589 {
7590   if (element == -1 || change_level)
7591     DrawBox(from_x, from_y, to_x, to_y, -1, FALSE);
7592   else
7593     DrawAreaBorder(from_x, from_y, to_x, to_y);
7594 }
7595
7596 /* values for CopyBrushExt() */
7597 #define CB_AREA_TO_BRUSH        0
7598 #define CB_BRUSH_TO_CURSOR      1
7599 #define CB_BRUSH_TO_LEVEL       2
7600 #define CB_DELETE_OLD_CURSOR    3
7601 #define CB_DUMP_BRUSH           4
7602
7603 static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
7604                          int button, int mode)
7605 {
7606   static short brush_buffer[MAX_ED_FIELDX][MAX_ED_FIELDY];
7607   static int brush_width, brush_height;
7608   static int last_cursor_x = -1, last_cursor_y = -1;
7609   static boolean delete_old_brush;
7610   int new_element = BUTTON_ELEMENT(button);
7611   int x, y;
7612
7613   if (mode == CB_DUMP_BRUSH)
7614   {
7615     if (!draw_with_brush)
7616     {
7617       Error(ERR_WARN, "no brush selected");
7618
7619       return;
7620     }
7621
7622     for (y = 0; y < brush_height; y++)
7623     {
7624       for (x = 0; x < brush_width; x++)
7625       {
7626         int element = brush_buffer[x][y];
7627         int element_mapped = element;
7628
7629 #if 0
7630         char *element_string = "?";
7631         int k;
7632
7633         for (k = 0; forum_sketch_element_mapping[k].element != -1; k++)
7634         {
7635           if (forum_sketch_element_mapping[k].element == element)
7636           {
7637             element_mapped = forum_sketch_element_mapping[k].element_mapped;
7638             break;
7639           }
7640         }
7641
7642         if (IS_CUSTOM_ELEMENT(element))
7643           element_mapped = EL_CUSTOM_1;
7644
7645         for (k = 0; forum_sketch_element_strings[k].element != -1; k++)
7646         {
7647           if (forum_sketch_element_strings[k].element == element_mapped)
7648           {
7649             element_string = forum_sketch_element_strings[k].element_string;
7650             break;
7651           }
7652         }
7653
7654         printf("`%s", element_string);
7655
7656 #else
7657
7658         if (IS_CUSTOM_ELEMENT(element))
7659           element_mapped = EL_CUSTOM_START;
7660         else if (element > EL_ENVELOPE_4)
7661           element_mapped = EL_CHAR_QUESTION;    /* change to EL_UNKNOWN ... */
7662
7663         printf("`%03d", element_mapped);
7664 #endif
7665       }
7666
7667       printf("\n");
7668     }
7669
7670     return;
7671   }
7672
7673   if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush)
7674     return;
7675
7676   if (mode == CB_AREA_TO_BRUSH)
7677   {
7678     int from_lx, from_ly;
7679
7680     if (from_x > to_x)
7681       swap_numbers(&from_x, &to_x);
7682
7683     if (from_y > to_y)
7684       swap_numbers(&from_y, &to_y);
7685
7686     brush_width = to_x - from_x + 1;
7687     brush_height = to_y - from_y + 1;
7688
7689     from_lx = from_x + level_xpos;
7690     from_ly = from_y + level_ypos;
7691
7692     for (y = 0; y < brush_height; y++)
7693     {
7694       for (x=0; x < brush_width; x++)
7695       {
7696         brush_buffer[x][y] = Feld[from_lx + x][from_ly + y];
7697
7698         if (button != 1)
7699           DrawLineElement(from_x + x, from_y + y, new_element, TRUE);
7700       }
7701     }
7702
7703     if (button != 1)
7704       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
7705
7706     delete_old_brush = FALSE;
7707   }
7708   else if (mode == CB_BRUSH_TO_CURSOR || mode == CB_DELETE_OLD_CURSOR ||
7709            mode == CB_BRUSH_TO_LEVEL)
7710   {
7711     int cursor_x = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_x : from_x);
7712     int cursor_y = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_y : from_y);
7713     int cursor_from_x = cursor_x - brush_width / 2;
7714     int cursor_from_y = cursor_y - brush_height / 2;
7715     int border_from_x = cursor_x, border_from_y = cursor_y;
7716     int border_to_x = cursor_x, border_to_y = cursor_y;
7717
7718     if (mode != CB_DELETE_OLD_CURSOR && delete_old_brush)
7719       CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
7720
7721     if (!IN_ED_FIELD(cursor_x, cursor_y) ||
7722         !IN_LEV_FIELD(cursor_x + level_xpos, cursor_y + level_ypos))
7723     {
7724       delete_old_brush = FALSE;
7725       return;
7726     }
7727
7728     for (y = 0; y < brush_height; y++)
7729     {
7730       for (x = 0; x < brush_width; x++)
7731       {
7732         int sx = cursor_from_x + x;
7733         int sy = cursor_from_y + y;
7734         int lx = sx + level_xpos;
7735         int ly = sy + level_ypos;
7736         boolean change_level = (mode == CB_BRUSH_TO_LEVEL);
7737         int element = (mode == CB_DELETE_OLD_CURSOR ? -1 :
7738                        mode == CB_BRUSH_TO_CURSOR || button == 1 ?
7739                        brush_buffer[x][y] : new_element);
7740
7741         if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
7742         {
7743           if (sx < border_from_x)
7744             border_from_x = sx;
7745           else if (sx > border_to_x)
7746             border_to_x = sx;
7747           if (sy < border_from_y)
7748             border_from_y = sy;
7749           else if (sy > border_to_y)
7750             border_to_y = sy;
7751
7752           DrawLineElement(sx, sy, element, change_level);
7753         }
7754       }
7755     }
7756
7757     if (mode != CB_DELETE_OLD_CURSOR)
7758       DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y);
7759
7760     last_cursor_x = cursor_x;
7761     last_cursor_y = cursor_y;
7762     delete_old_brush = TRUE;
7763   }
7764 }
7765
7766 static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y,
7767                             int button)
7768 {
7769   CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH);
7770 }
7771
7772 static void CopyBrushToLevel(int x, int y, int button)
7773 {
7774   CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL);
7775 }
7776
7777 static void CopyBrushToCursor(int x, int y)
7778 {
7779   CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
7780 }
7781
7782 static void DeleteBrushFromCursor()
7783 {
7784   CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
7785 }
7786
7787 void DumpBrush()
7788 {
7789   CopyBrushExt(0, 0, 0, 0, 0, CB_DUMP_BRUSH);
7790 }
7791
7792 static void FloodFill(int from_x, int from_y, int fill_element)
7793 {
7794   int i,x,y;
7795   int old_element;
7796   static int check[4][2] = { {-1,0}, {0,-1}, {1,0}, {0,1} };
7797   static int safety = 0;
7798
7799   /* check if starting field still has the desired content */
7800   if (Feld[from_x][from_y] == fill_element)
7801     return;
7802
7803   safety++;
7804
7805   if (safety > lev_fieldx*lev_fieldy)
7806     Error(ERR_EXIT, "Something went wrong in 'FloodFill()'. Please debug.");
7807
7808   old_element = Feld[from_x][from_y];
7809   Feld[from_x][from_y] = fill_element;
7810
7811   for (i = 0; i < 4; i++)
7812   {
7813     x = from_x + check[i][0];
7814     y = from_y + check[i][1];
7815
7816     if (IN_LEV_FIELD(x,y) && Feld[x][y] == old_element)
7817       FloodFill(x, y, fill_element);
7818   }
7819
7820   safety--;
7821 }
7822
7823 /* values for DrawLevelText() modes */
7824 #define TEXT_INIT               0
7825 #define TEXT_SETCURSOR          1
7826 #define TEXT_WRITECHAR          2
7827 #define TEXT_BACKSPACE          3
7828 #define TEXT_NEWLINE            4
7829 #define TEXT_END                5
7830 #define TEXT_QUERY_TYPING       6
7831
7832 static int DrawLevelText(int sx, int sy, char letter, int mode)
7833 {
7834   static short delete_buffer[MAX_LEV_FIELDX];
7835   static int start_sx, start_sy;
7836   static int last_sx, last_sy;
7837   static boolean typing = FALSE;
7838   int letter_element = EL_CHAR_ASCII0 + letter;
7839   int lx = 0, ly = 0;
7840
7841   /* map lower case letters to upper case and convert special characters */
7842   if (letter >= 'a' && letter <= 'z')
7843     letter_element = EL_CHAR_ASCII0 + letter + (int)('A' - 'a');
7844   else if (letter == 'ä' || letter == 'Ä')
7845     letter_element = EL_CHAR_AUMLAUT;
7846   else if (letter == 'ö' || letter == 'Ö')
7847     letter_element = EL_CHAR_OUMLAUT;
7848   else if (letter == 'ü' || letter == 'Ãœ')
7849     letter_element = EL_CHAR_UUMLAUT;
7850   else if (letter == '^')
7851     letter_element = EL_CHAR_COPYRIGHT;
7852   else
7853     letter_element = EL_CHAR_ASCII0 + letter;
7854
7855   if (mode != TEXT_INIT)
7856   {
7857     if (!typing)
7858       return FALSE;
7859
7860     if (mode != TEXT_SETCURSOR)
7861     {
7862       sx = last_sx;
7863       sy = last_sy;
7864     }
7865
7866     lx = last_sx + level_xpos;
7867     ly = last_sy + level_ypos;
7868   }
7869
7870   switch (mode)
7871   {
7872     case TEXT_INIT:
7873       if (typing)
7874         DrawLevelText(0, 0, 0, TEXT_END);
7875
7876       typing = TRUE;
7877       start_sx = last_sx = sx;
7878       start_sy = last_sy = sy;
7879       DrawLevelText(sx, sy, 0, TEXT_SETCURSOR);
7880       break;
7881
7882     case TEXT_SETCURSOR:
7883       DrawMiniElement(last_sx, last_sy, Feld[lx][ly]);
7884       DrawAreaBorder(sx, sy, sx, sy);
7885       last_sx = sx;
7886       last_sy = sy;
7887       break;
7888
7889     case TEXT_WRITECHAR:
7890       if (letter_element >= EL_CHAR_START && letter_element <= EL_CHAR_END)
7891       {
7892         delete_buffer[sx - start_sx] = Feld[lx][ly];
7893         Feld[lx][ly] = letter_element;
7894
7895         if (sx + 1 < ed_fieldx && lx + 1 < lev_fieldx)
7896           DrawLevelText(sx + 1, sy, 0, TEXT_SETCURSOR);
7897         else if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
7898           DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
7899         else
7900           DrawLevelText(0, 0, 0, TEXT_END);
7901       }
7902       break;
7903
7904     case TEXT_BACKSPACE:
7905       if (sx > start_sx)
7906       {
7907         Feld[lx - 1][ly] = delete_buffer[sx - start_sx - 1];
7908         DrawMiniElement(sx - 1, sy, Feld[lx - 1][ly]);
7909         DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR);
7910       }
7911       break;
7912
7913     case TEXT_NEWLINE:
7914       if (sy + 1 < ed_fieldy - 1 && ly + 1 < lev_fieldy - 1)
7915         DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
7916       else
7917         DrawLevelText(0, 0, 0, TEXT_END);
7918       break;
7919
7920     case TEXT_END:
7921       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
7922       DrawMiniElement(sx, sy, Feld[lx][ly]);
7923       typing = FALSE;
7924       break;
7925
7926     case TEXT_QUERY_TYPING:
7927       break;
7928
7929     default:
7930       break;
7931   }
7932
7933   return typing;
7934 }
7935
7936 static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy,
7937                           int element, boolean change_level)
7938 {
7939   int lx = sx + level_xpos;
7940   int ly = sy + level_ypos;
7941
7942   if (element == -1)
7943     DrawMiniElement(sx, sy, Feld[lx][ly]);
7944   else
7945     DrawAreaBorder(sx, sy, sx, sy);
7946 }
7947
7948 static void CopyLevelToUndoBuffer(int mode)
7949 {
7950   static boolean accumulated_undo = FALSE;
7951   boolean new_undo_buffer_position = TRUE;
7952   int last_border_element;
7953   int x, y;
7954
7955   switch (mode)
7956   {
7957     case UNDO_IMMEDIATE:
7958       accumulated_undo = FALSE;
7959       break;
7960
7961     case UNDO_ACCUMULATE:
7962       if (accumulated_undo)
7963         new_undo_buffer_position = FALSE;
7964       accumulated_undo = TRUE;
7965       break;
7966
7967     default:
7968       break;
7969   }
7970
7971   if (new_undo_buffer_position)
7972   {
7973     /* new position in undo buffer ring */
7974     undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS;
7975
7976     if (undo_buffer_steps < NUM_UNDO_STEPS - 1)
7977       undo_buffer_steps++;
7978   }
7979
7980   for (x = 0; x < lev_fieldx; x++)
7981     for (y = 0; y < lev_fieldy; y++)
7982       UndoBuffer[undo_buffer_position][x][y] = Feld[x][y];
7983
7984   /* check if drawing operation forces change of border style */
7985   last_border_element = BorderElement;
7986   SetBorderElement();
7987   if (BorderElement != last_border_element)
7988     DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
7989 }
7990
7991 static void RandomPlacement(int new_element)
7992 {
7993   static boolean free_position[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
7994   int num_free_positions;
7995   int num_percentage;
7996   int num_elements;
7997   int x, y;
7998
7999   /* determine number of free positions for the new elements */
8000   /* (maybe this statement should be formatted a bit more readable...) */
8001   num_free_positions = 0;
8002   for (x = 0; x < lev_fieldx; x++)
8003     for (y = 0; y < lev_fieldy; y++)
8004       if ((free_position[x][y] =
8005            ((random_placement_background_restricted &&
8006              Feld[x][y] == random_placement_background_element) ||
8007             (!random_placement_background_restricted &&
8008              Feld[x][y] != new_element))) == TRUE)
8009         num_free_positions++;
8010
8011   /* determine number of new elements to place there */
8012   num_percentage = num_free_positions * random_placement_value / 100;
8013   num_elements = (random_placement_method == RANDOM_USE_PERCENTAGE ?
8014                   num_percentage : random_placement_value);
8015
8016   /* if not more free positions than elements to place, fill whole level */
8017   if (num_elements >= num_free_positions)
8018   {
8019     for (x = 0; x < lev_fieldx; x++)
8020       for (y = 0; y < lev_fieldy; y++)
8021         Feld[x][y] = new_element;
8022
8023     DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8024     CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8025     return;
8026   }
8027
8028   while (num_elements > 0)
8029   {
8030     x = RND(lev_fieldx);
8031     y = RND(lev_fieldy);
8032
8033     /* don't place element at the same position twice */
8034     if (free_position[x][y])
8035     {
8036       free_position[x][y] = FALSE;
8037       Feld[x][y] = new_element;
8038       num_elements--;
8039     }
8040   }
8041
8042   DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8043   CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8044 }
8045
8046 void WrapLevel(int dx, int dy)
8047 {
8048   int wrap_dx = lev_fieldx - dx;
8049   int wrap_dy = lev_fieldy - dy;
8050   int x, y;
8051
8052   for (x = 0; x < lev_fieldx; x++)
8053     for (y = 0; y < lev_fieldy; y++)
8054       FieldBackup[x][y] = Feld[x][y];
8055
8056   for (x = 0; x < lev_fieldx; x++)
8057     for (y = 0; y < lev_fieldy; y++)
8058       Feld[x][y] =
8059         FieldBackup[(x + wrap_dx) % lev_fieldx][(y + wrap_dy) % lev_fieldy];
8060
8061   DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8062   CopyLevelToUndoBuffer(UNDO_ACCUMULATE);
8063 }
8064
8065 static void HandleDrawingAreas(struct GadgetInfo *gi)
8066 {
8067   static boolean started_inside_drawing_area = FALSE;
8068   int id = gi->custom_id;
8069   boolean button_press_event;
8070   boolean button_release_event;
8071   boolean inside_drawing_area = !gi->event.off_borders;
8072   boolean draw_level = (id == GADGET_ID_DRAWING_LEVEL);
8073   int actual_drawing_function;
8074   int button = gi->event.button;
8075   int new_element = BUTTON_ELEMENT(button);
8076   int sx = gi->event.x, sy = gi->event.y;
8077   int min_sx = 0, min_sy = 0;
8078   int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1;
8079   int item_xsize = gi->drawing.item_xsize, item_ysize = gi->drawing.item_ysize;
8080   int lx = 0, ly = 0;
8081   int min_lx = 0, min_ly = 0;
8082   int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
8083   int x, y;
8084
8085   /* handle info callback for each invocation of action callback */
8086   gi->callback_info(gi);
8087
8088   button_press_event = (gi->event.type == GD_EVENT_PRESSED);
8089   button_release_event = (gi->event.type == GD_EVENT_RELEASED);
8090
8091   /* make sure to stay inside drawing area boundaries */
8092   sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
8093   sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
8094
8095   if (draw_level)
8096   {
8097     /* get positions inside level field */
8098     lx = sx + level_xpos;
8099     ly = sy + level_ypos;
8100
8101     if (!IN_LEV_FIELD(lx, ly))
8102       inside_drawing_area = FALSE;
8103
8104     /* make sure to stay inside level field boundaries */
8105     lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
8106     ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
8107
8108     /* correct drawing area positions accordingly */
8109     sx = lx - level_xpos;
8110     sy = ly - level_ypos;
8111   }
8112
8113   if (button_press_event)
8114     started_inside_drawing_area = inside_drawing_area;
8115
8116   if (!started_inside_drawing_area)
8117     return;
8118
8119   if (!button && !button_release_event)
8120     return;
8121
8122   /* automatically switch to 'single item' drawing mode, if needed */
8123   actual_drawing_function =
8124     (draw_level || drawing_function == GADGET_ID_PICK_ELEMENT ?
8125      drawing_function : GADGET_ID_SINGLE_ITEMS);
8126
8127   /* clicking into drawing area with pressed Control key picks element */
8128   if (GetKeyModState() & KMOD_Control)
8129   {
8130     last_drawing_function = drawing_function;
8131     actual_drawing_function = GADGET_ID_PICK_ELEMENT;
8132   }
8133
8134   switch (actual_drawing_function)
8135   {
8136     case GADGET_ID_SINGLE_ITEMS:
8137       if (draw_level)
8138       {
8139         if (button_release_event)
8140         {
8141           CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8142
8143           if (edit_mode == ED_MODE_DRAWING && draw_with_brush &&
8144               !inside_drawing_area)
8145             DeleteBrushFromCursor();
8146         }
8147
8148         if (!button)
8149           break;
8150
8151         if (draw_with_brush)
8152         {
8153           if (!button_release_event)
8154             CopyBrushToLevel(sx, sy, button);
8155         }
8156         else if (new_element != Feld[lx][ly])
8157         {
8158           if (new_element == EL_PLAYER_1)
8159           {
8160             /* remove player at old position */
8161             for (y = 0; y < lev_fieldy; y++)
8162             {
8163               for (x = 0; x < lev_fieldx; x++)
8164               {
8165                 if (Feld[x][y] == EL_PLAYER_1)
8166                 {
8167                   Feld[x][y] = EL_EMPTY;
8168                   if (x - level_xpos >= 0 && x - level_xpos < ed_fieldx &&
8169                       y - level_ypos >= 0 && y - level_ypos < ed_fieldy)
8170                     DrawMiniElement(x - level_xpos, y - level_ypos,
8171                                     EL_EMPTY);
8172                 }
8173               }
8174             }
8175           }
8176
8177           Feld[lx][ly] = new_element;
8178           DrawMiniElement(sx, sy, new_element);
8179         }
8180       }
8181       else
8182       {
8183         if (item_xsize == MINI_TILEX && item_ysize == MINI_TILEY)
8184           DrawMiniGraphicExt(drawto,
8185                              gi->x + sx * MINI_TILEX,
8186                              gi->y + sy * MINI_TILEY,
8187                              el2edimg(new_element));
8188         else
8189           DrawGraphicExt(drawto,
8190                          gi->x + sx * TILEX,
8191                          gi->y + sy * TILEY,
8192                          el2img(new_element), 0);
8193
8194         if (id == GADGET_ID_AMOEBA_CONTENT)
8195           level.amoeba_content = new_element;
8196         else if (id == GADGET_ID_CUSTOM_GRAPHIC)
8197         {
8198           new_element = GFX_ELEMENT(new_element);
8199           custom_element.gfx_element = new_element;
8200
8201           CopyElementPropertiesToGame(properties_element);
8202
8203           UpdateCustomElementGraphicGadgets();
8204
8205           FrameCounter = 0;     /* restart animation frame counter */
8206         }
8207         else if (id == GADGET_ID_CUSTOM_CONTENT)
8208         {
8209           custom_element.content[sx][sy] = new_element;
8210
8211           CopyCustomElementPropertiesToGame(properties_element);
8212         }
8213         else if (id == GADGET_ID_CUSTOM_MOVE_ENTER)
8214         {
8215           custom_element.move_enter_element = new_element;
8216
8217           CopyCustomElementPropertiesToGame(properties_element);
8218         }
8219         else if (id == GADGET_ID_CUSTOM_MOVE_LEAVE)
8220         {
8221           custom_element.move_leave_element = new_element;
8222
8223           CopyCustomElementPropertiesToGame(properties_element);
8224         }
8225         else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
8226         {
8227           custom_element_change.target_element = new_element;
8228
8229           CopyCustomElementPropertiesToGame(properties_element);
8230         }
8231         else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
8232         {
8233           custom_element_change.target_content[sx][sy] = new_element;
8234
8235           CopyCustomElementPropertiesToGame(properties_element);
8236         }
8237         else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
8238         {
8239           custom_element_change.trigger_element = new_element;
8240
8241           CopyCustomElementPropertiesToGame(properties_element);
8242         }
8243         else if (id == GADGET_ID_GROUP_CONTENT)
8244         {
8245           group_element_info.element[sx] = new_element;
8246
8247           CopyGroupElementPropertiesToGame(properties_element);
8248         }
8249         else if (id == GADGET_ID_RANDOM_BACKGROUND)
8250           random_placement_background_element = new_element;
8251         else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
8252                  id <= GADGET_ID_ELEMENT_CONTENT_7)
8253           level.yamyam_content[id - GADGET_ID_ELEMENT_CONTENT_0][sx][sy] =
8254             new_element;
8255       }
8256       break;
8257
8258     case GADGET_ID_CONNECTED_ITEMS:
8259       {
8260         static int last_sx = -1;
8261         static int last_sy = -1;
8262
8263         if (button_release_event)
8264           CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8265
8266         if (button)
8267         {
8268           if (!button_press_event)
8269             DrawLine(last_sx, last_sy, sx, sy, new_element, TRUE);
8270
8271           last_sx = sx;
8272           last_sy = sy;
8273         }
8274       }
8275       break;
8276
8277     case GADGET_ID_LINE:
8278     case GADGET_ID_ARC:
8279     case GADGET_ID_RECTANGLE:
8280     case GADGET_ID_FILLED_BOX:
8281     case GADGET_ID_GRAB_BRUSH:
8282     case GADGET_ID_TEXT:
8283       {
8284         static int last_sx = -1;
8285         static int last_sy = -1;
8286         static int start_sx = -1;
8287         static int start_sy = -1;
8288         void (*draw_func)(int, int, int, int, int, boolean);
8289
8290         if (drawing_function == GADGET_ID_LINE)
8291           draw_func = DrawLine;
8292         else if (drawing_function == GADGET_ID_ARC)
8293           draw_func = DrawArc;
8294         else if (drawing_function == GADGET_ID_RECTANGLE)
8295           draw_func = DrawBox;
8296         else if (drawing_function == GADGET_ID_FILLED_BOX)
8297           draw_func = DrawFilledBox;
8298         else if (drawing_function == GADGET_ID_GRAB_BRUSH)
8299           draw_func = SelectArea;
8300         else /* (drawing_function == GADGET_ID_TEXT) */
8301           draw_func = SetTextCursor;
8302
8303         if (button_press_event)
8304         {
8305           draw_func(sx, sy, sx, sy, new_element, FALSE);
8306           start_sx = last_sx = sx;
8307           start_sy = last_sy = sy;
8308
8309           if (drawing_function == GADGET_ID_TEXT)
8310             DrawLevelText(0, 0, 0, TEXT_END);
8311         }
8312         else if (button_release_event)
8313         {
8314           draw_func(start_sx, start_sy, sx, sy, new_element, TRUE);
8315           if (drawing_function == GADGET_ID_GRAB_BRUSH)
8316           {
8317             CopyAreaToBrush(start_sx, start_sy, sx, sy, button);
8318             CopyBrushToCursor(sx, sy);
8319             ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
8320                           MB_LEFTBUTTON);
8321             draw_with_brush = TRUE;
8322           }
8323           else if (drawing_function == GADGET_ID_TEXT)
8324             DrawLevelText(sx, sy, 0, TEXT_INIT);
8325           else
8326             CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8327         }
8328         else if (last_sx != sx || last_sy != sy)
8329         {
8330           draw_func(start_sx, start_sy, last_sx, last_sy, -1, FALSE);
8331           draw_func(start_sx, start_sy, sx, sy, new_element, FALSE);
8332           last_sx = sx;
8333           last_sy = sy;
8334         }
8335       }
8336       break;
8337
8338     case GADGET_ID_FLOOD_FILL:
8339       if (button_press_event && Feld[lx][ly] != new_element)
8340       {
8341         FloodFill(lx, ly, new_element);
8342         DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8343         CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
8344       }
8345       break;
8346
8347     case GADGET_ID_PICK_ELEMENT:
8348       if (button_release_event)
8349         ClickOnGadget(level_editor_gadget[last_drawing_function],
8350                       MB_LEFTBUTTON);
8351       else if (draw_level)
8352         PickDrawingElement(button, Feld[lx][ly]);
8353       else if (id == GADGET_ID_AMOEBA_CONTENT)
8354         PickDrawingElement(button, level.amoeba_content);
8355       else if (id == GADGET_ID_CUSTOM_GRAPHIC)
8356         PickDrawingElement(button, custom_element.gfx_element);
8357       else if (id == GADGET_ID_CUSTOM_CONTENT)
8358         PickDrawingElement(button, custom_element.content[sx][sy]);
8359       else if (id == GADGET_ID_CUSTOM_MOVE_ENTER)
8360         PickDrawingElement(button, custom_element.move_enter_element);
8361       else if (id == GADGET_ID_CUSTOM_MOVE_LEAVE)
8362         PickDrawingElement(button, custom_element.move_leave_element);
8363       else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
8364         PickDrawingElement(button, custom_element_change.target_element);
8365       else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
8366         PickDrawingElement(button, custom_element_change.target_content[sx][sy]);
8367       else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
8368         PickDrawingElement(button, custom_element_change.trigger_element);
8369       else if (id == GADGET_ID_GROUP_CONTENT)
8370         PickDrawingElement(button, group_element_info.element[sx]);
8371       else if (id == GADGET_ID_RANDOM_BACKGROUND)
8372         PickDrawingElement(button, random_placement_background_element);
8373       else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
8374                id <= GADGET_ID_ELEMENT_CONTENT_7)
8375       {
8376         int i = id - GADGET_ID_ELEMENT_CONTENT_0;
8377
8378         PickDrawingElement(button, level.yamyam_content[i][sx][sy]);
8379       }
8380
8381       break;
8382
8383     default:
8384       break;
8385   }
8386 }
8387
8388 static void HandleCounterButtons(struct GadgetInfo *gi)
8389 {
8390   int gadget_id = gi->custom_id;
8391   int counter_id = gi->custom_type_id;
8392   int button = gi->event.button;
8393   int *counter_value = counterbutton_info[counter_id].value;
8394   int step = BUTTON_STEPSIZE(button) *
8395     (gadget_id == counterbutton_info[counter_id].gadget_id_down ? -1 : +1);
8396
8397   if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
8398   {
8399     boolean pressed = (gi->event.type == GD_EVENT_PRESSED);
8400     boolean released = (gi->event.type == GD_EVENT_RELEASED);
8401     boolean level_changed = LevelChanged();
8402
8403     if ((level_changed && pressed) || (!level_changed && released))
8404       return;
8405
8406     if (level_changed && !Request("Level has changed! Discard changes ?",
8407                                   REQ_ASK))
8408     {
8409       if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
8410         ModifyEditorCounter(counter_id, *counter_value);
8411       return;
8412     }
8413   }
8414
8415   if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
8416     *counter_value = gi->textinput.number_value;
8417   else
8418     ModifyEditorCounter(counter_id, *counter_value + step);
8419
8420   switch (counter_id)
8421   {
8422     case ED_COUNTER_ID_ELEMENT_CONTENT:
8423       DrawElementContentAreas();
8424       break;
8425
8426     case ED_COUNTER_ID_GROUP_CONTENT:
8427       DrawGroupElementArea(properties_element);
8428       CopyGroupElementPropertiesToGame(properties_element);
8429       break;
8430
8431     case ED_COUNTER_ID_ENVELOPE_XSIZE:
8432     case ED_COUNTER_ID_ENVELOPE_YSIZE:
8433       DrawEnvelopeTextArea(-1);
8434       break;
8435
8436     case ED_COUNTER_ID_LEVEL_XSIZE:
8437     case ED_COUNTER_ID_LEVEL_YSIZE:
8438       lev_fieldx = level.fieldx;
8439       lev_fieldy = level.fieldy;
8440       break;
8441
8442     case ED_COUNTER_ID_SELECT_LEVEL:
8443       LoadLevel(level_nr);
8444       TapeErase();
8445       ResetUndoBuffer();
8446       DrawEditModeWindow();
8447       break;
8448
8449     default:
8450       break;
8451   }
8452
8453   if ((counter_id >= ED_COUNTER_ID_CUSTOM_FIRST &&
8454        counter_id <= ED_COUNTER_ID_CUSTOM_LAST) ||
8455       (counter_id >= ED_COUNTER_ID_CHANGE_FIRST &&
8456        counter_id <= ED_COUNTER_ID_CHANGE_LAST))
8457     CopyElementPropertiesToGame(properties_element);
8458 }
8459
8460 static void HandleTextInputGadgets(struct GadgetInfo *gi)
8461 {
8462   int type_id = gi->custom_type_id;
8463
8464   strcpy(textinput_info[type_id].value, gi->textinput.value);
8465
8466   if (type_id == ED_TEXTINPUT_ID_ELEMENT_NAME)
8467   {
8468     CopyElementPropertiesToGame(properties_element);
8469
8470     ModifyEditorElementList();  /* update changed button info text */
8471   }
8472 }
8473
8474 static void HandleTextAreaGadgets(struct GadgetInfo *gi)
8475 {
8476   int type_id = gi->custom_type_id;
8477
8478   strcpy(textarea_info[type_id].value, gi->textarea.value);
8479 }
8480
8481 static void HandleSelectboxGadgets(struct GadgetInfo *gi)
8482 {
8483   int type_id = gi->custom_type_id;
8484
8485   *selectbox_info[type_id].value =
8486     selectbox_info[type_id].options[gi->selectbox.index].value;
8487
8488   if (type_id == ED_SELECTBOX_ID_SELECT_CHANGE_PAGE)
8489   {
8490     element_info[properties_element].current_change_page = gi->selectbox.index;
8491
8492     DrawPropertiesWindow();
8493   }
8494   else if ((type_id >= ED_SELECTBOX_ID_CUSTOM_FIRST &&
8495             type_id <= ED_SELECTBOX_ID_CUSTOM_LAST) ||
8496            (type_id >= ED_SELECTBOX_ID_CHANGE_FIRST &&
8497             type_id <= ED_SELECTBOX_ID_CHANGE_LAST) ||
8498            (type_id == ED_SELECTBOX_ID_GROUP_CHOICE_MODE))
8499     CopyElementPropertiesToGame(properties_element);
8500 }
8501
8502 static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
8503 {
8504   int type_id = gi->custom_type_id;
8505   int i;
8506
8507   if (type_id >= ED_TEXTBUTTON_ID_PROPERTIES_FIRST &&
8508       type_id <= ED_TEXTBUTTON_ID_PROPERTIES_LAST)
8509   {
8510     edit_mode_properties = gi->custom_type_id;
8511
8512     DrawPropertiesWindow();
8513   }
8514   else if (type_id == ED_TEXTBUTTON_ID_SAVE_AS_TEMPLATE)
8515   {
8516     char *template_filename = getDefaultLevelFilename(-1);
8517     boolean new_template = !fileExists(template_filename);
8518
8519     if (new_template ||
8520         Request("Save this template and kill the old ?", REQ_ASK))
8521       SaveLevelTemplate();
8522
8523     if (new_template)
8524       Request("Template saved !", REQ_CONFIRM);
8525   }
8526   else if (type_id == ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE &&
8527            custom_element.num_change_pages < MAX_CHANGE_PAGES)
8528   {
8529     struct ElementInfo *ei = &element_info[properties_element];
8530
8531     setElementChangePages(ei, ei->num_change_pages + 1);
8532
8533     /* set new change page to be new current change page */
8534     ei->current_change_page = ei->num_change_pages - 1;
8535     ei->change = &ei->change_page[ei->current_change_page];
8536
8537     setElementChangeInfoToDefaults(ei->change);
8538
8539     DrawPropertiesWindow();
8540   }
8541   else if (type_id == ED_TEXTBUTTON_ID_DEL_CHANGE_PAGE &&
8542            custom_element.num_change_pages > MIN_CHANGE_PAGES)
8543   {
8544     struct ElementInfo *ei = &element_info[properties_element];
8545
8546     /* copy all change pages after change page to be deleted */
8547     for (i = ei->current_change_page; i < ei->num_change_pages - 1; i++)
8548       ei->change_page[i] = ei->change_page[i + 1];
8549
8550     setElementChangePages(ei, ei->num_change_pages - 1);
8551
8552     DrawPropertiesWindow();
8553   }
8554 }
8555
8556 static void HandleGraphicbuttonGadgets(struct GadgetInfo *gi)
8557 {
8558   int type_id = gi->custom_type_id;
8559
8560   if (type_id == ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE ||
8561       type_id == ED_GRAPHICBUTTON_ID_NEXT_CHANGE_PAGE)
8562   {
8563     struct ElementInfo *ei = &element_info[properties_element];
8564     int step = BUTTON_STEPSIZE(gi->event.button);
8565
8566     step *= (type_id == ED_GRAPHICBUTTON_ID_PREV_CHANGE_PAGE ? -1 : +1);
8567     ei->current_change_page += step;
8568
8569     if (ei->current_change_page < 0)
8570       ei->current_change_page = 0;
8571     else if (ei->current_change_page >= ei->num_change_pages)
8572       ei->current_change_page = ei->num_change_pages - 1;
8573
8574     DrawPropertiesWindow();
8575   }
8576   else if (type_id == ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE ||
8577            type_id == ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE)
8578   {
8579     struct ElementInfo *ei = &element_info[properties_element];
8580     int current_change_page = ei->current_change_page;
8581
8582     if (type_id == ED_GRAPHICBUTTON_ID_COPY_CHANGE_PAGE)
8583       element_info[EL_INTERNAL_CLIPBOARD_CHANGE].change_page[0] =
8584         ei->change_page[current_change_page];
8585     else if (type_id == ED_GRAPHICBUTTON_ID_PASTE_CHANGE_PAGE)
8586       ei->change_page[current_change_page] =
8587         element_info[EL_INTERNAL_CLIPBOARD_CHANGE].change_page[0];
8588
8589     DrawPropertiesWindow();
8590   }
8591 }
8592
8593 static void HandleRadiobuttons(struct GadgetInfo *gi)
8594 {
8595   *radiobutton_info[gi->custom_type_id].value =
8596     radiobutton_info[gi->custom_type_id].checked_value;
8597 }
8598
8599 static void HandleCheckbuttons(struct GadgetInfo *gi)
8600 {
8601   int type_id = gi->custom_type_id;
8602
8603   *checkbutton_info[type_id].value ^= TRUE;
8604
8605   if (type_id == ED_CHECKBUTTON_ID_CAN_FALL_INTO_ACID ||
8606       type_id == ED_CHECKBUTTON_ID_CAN_MOVE_INTO_ACID ||
8607       type_id == ED_CHECKBUTTON_ID_DONT_COLLIDE_WITH ||
8608       (((type_id >= ED_CHECKBUTTON_ID_CUSTOM_FIRST &&
8609          type_id <= ED_CHECKBUTTON_ID_CUSTOM_LAST) ||
8610         (type_id >= ED_CHECKBUTTON_ID_CHANGE_FIRST &&
8611          type_id <= ED_CHECKBUTTON_ID_CHANGE_LAST)) &&
8612        type_id != ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE))
8613   {
8614     CopyElementPropertiesToGame(properties_element);
8615   }
8616
8617   if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC)
8618   {
8619     UpdateCustomElementGraphicGadgets();
8620   }
8621   else if (type_id == ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE)
8622   {
8623     char *template_filename = getDefaultLevelFilename(-1);
8624
8625     if (level.use_custom_template && !fileExists(template_filename))
8626     {
8627       Request("No level template found !", REQ_CONFIRM);
8628
8629       level.use_custom_template = FALSE;
8630       ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
8631
8632       return;
8633     }
8634
8635     LoadLevelTemplate(level.use_custom_template ? -1 : level_nr);
8636
8637     DrawEditModeWindow();
8638   }
8639 }
8640
8641 static void HandleControlButtons(struct GadgetInfo *gi)
8642 {
8643   static int last_level_drawing_function = GADGET_ID_SINGLE_ITEMS;
8644   static int last_edit_mode = ED_MODE_DRAWING;
8645   static int last_custom_copy_mode = -1;
8646   int id = gi->custom_id;
8647   int button = gi->event.button;
8648   int step = BUTTON_STEPSIZE(button);
8649   int new_element = BUTTON_ELEMENT(button);
8650   int x, y;
8651
8652   if (edit_mode == ED_MODE_DRAWING && drawing_function == GADGET_ID_TEXT)
8653     DrawLevelText(0, 0, 0, TEXT_END);
8654
8655   if (id < ED_NUM_CTRL1_BUTTONS &&
8656       id != GADGET_ID_SINGLE_ITEMS &&
8657       id != GADGET_ID_PROPERTIES &&
8658       id != GADGET_ID_PICK_ELEMENT &&
8659       edit_mode != ED_MODE_DRAWING &&
8660       drawing_function != GADGET_ID_PICK_ELEMENT &&
8661       !(GetKeyModState() & KMOD_Control))
8662   {
8663     DrawDrawingWindow();
8664     edit_mode = ED_MODE_DRAWING;
8665   }
8666
8667   /* element copy mode active, but no element button pressed => deactivate */
8668   if (last_custom_copy_mode != -1 && id < ED_NUM_CTRL_BUTTONS)
8669     last_custom_copy_mode = -1;
8670
8671   switch (id)
8672   {
8673     case GADGET_ID_SCROLL_LEFT:
8674       if (level_xpos >= 0)
8675       {
8676         if (lev_fieldx < ed_fieldx - 2)
8677           break;
8678
8679         level_xpos -= step;
8680         if (level_xpos < -1)
8681           level_xpos = -1;
8682         if (button == 1)
8683           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT);
8684         else
8685           DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8686
8687         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
8688                      GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
8689       }
8690       break;
8691
8692     case GADGET_ID_SCROLL_RIGHT:
8693       if (level_xpos <= lev_fieldx - ed_fieldx)
8694       {
8695         if (lev_fieldx < ed_fieldx - 2)
8696           break;
8697
8698         level_xpos += step;
8699         if (level_xpos > lev_fieldx - ed_fieldx + 1)
8700           level_xpos = lev_fieldx - ed_fieldx + 1;
8701         if (button == 1)
8702           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT);
8703         else
8704           DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8705
8706         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
8707                      GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
8708       }
8709       break;
8710
8711     case GADGET_ID_SCROLL_UP:
8712       if (level_ypos >= 0)
8713       {
8714         if (lev_fieldy < ed_fieldy - 2)
8715           break;
8716
8717         level_ypos -= step;
8718         if (level_ypos < -1)
8719           level_ypos = -1;
8720         if (button == 1)
8721           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN);
8722         else
8723           DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8724
8725         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
8726                      GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
8727       }
8728       break;
8729
8730     case GADGET_ID_SCROLL_DOWN:
8731       if (level_ypos <= lev_fieldy - ed_fieldy)
8732       {
8733         if (lev_fieldy < ed_fieldy - 2)
8734           break;
8735
8736         level_ypos += step;
8737         if (level_ypos > lev_fieldy - ed_fieldy + 1)
8738           level_ypos = lev_fieldy - ed_fieldy + 1;
8739         if (button == 1)
8740           ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP);
8741         else
8742           DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8743
8744         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
8745                      GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
8746       }
8747       break;
8748
8749     case GADGET_ID_SCROLL_HORIZONTAL:
8750       level_xpos = gi->event.item_position - 1;
8751       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8752       break;
8753
8754     case GADGET_ID_SCROLL_VERTICAL:
8755       level_ypos = gi->event.item_position - 1;
8756       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8757       break;
8758
8759     case GADGET_ID_SCROLL_LIST_UP:
8760     case GADGET_ID_SCROLL_LIST_DOWN:
8761     case GADGET_ID_SCROLL_LIST_VERTICAL:
8762       if (id == GADGET_ID_SCROLL_LIST_VERTICAL)
8763         element_shift = gi->event.item_position * ED_ELEMENTLIST_BUTTONS_HORIZ;
8764       else
8765       {
8766         step *= (id == GADGET_ID_SCROLL_LIST_UP ? -1 : +1);
8767         element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ;
8768
8769         if (element_shift < 0)
8770           element_shift = 0;
8771         if (element_shift > num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS)
8772           element_shift = num_editor_elements - ED_NUM_ELEMENTLIST_BUTTONS;
8773
8774         ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
8775                      GDI_SCROLLBAR_ITEM_POSITION,
8776                      element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
8777       }
8778
8779       ModifyEditorElementList();
8780
8781       break;
8782
8783     case GADGET_ID_WRAP_LEFT:
8784       WrapLevel(-step, 0);
8785       break;
8786
8787     case GADGET_ID_WRAP_RIGHT:
8788       WrapLevel(step, 0);
8789       break;
8790
8791     case GADGET_ID_WRAP_UP:
8792       WrapLevel(0, -step);
8793       break;
8794
8795     case GADGET_ID_WRAP_DOWN:
8796       WrapLevel(0, step);
8797       break;
8798
8799     case GADGET_ID_SINGLE_ITEMS:
8800     case GADGET_ID_CONNECTED_ITEMS:
8801     case GADGET_ID_LINE:
8802     case GADGET_ID_ARC:
8803     case GADGET_ID_TEXT:
8804     case GADGET_ID_RECTANGLE:
8805     case GADGET_ID_FILLED_BOX:
8806     case GADGET_ID_FLOOD_FILL:
8807     case GADGET_ID_GRAB_BRUSH:
8808     case GADGET_ID_PICK_ELEMENT:
8809       if (drawing_function != GADGET_ID_PICK_ELEMENT)
8810         last_drawing_function = drawing_function;
8811       drawing_function = id;
8812       draw_with_brush = FALSE;
8813       break;
8814
8815     case GADGET_ID_RANDOM_PLACEMENT:
8816       RandomPlacement(new_element);
8817       break;
8818
8819     case GADGET_ID_PROPERTIES:
8820       if (edit_mode != ED_MODE_PROPERTIES)
8821       {
8822         properties_element = new_element;
8823         DrawPropertiesWindow();
8824         edit_mode = ED_MODE_PROPERTIES;
8825
8826         last_level_drawing_function = drawing_function;
8827         ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
8828                       MB_LEFTBUTTON);
8829       }
8830       else
8831       {
8832         DrawDrawingWindow();
8833         edit_mode = ED_MODE_DRAWING;
8834
8835         ClickOnGadget(level_editor_gadget[last_level_drawing_function],
8836                       MB_LEFTBUTTON);
8837       }
8838       break;
8839
8840     case GADGET_ID_CUSTOM_COPY_FROM:
8841     case GADGET_ID_CUSTOM_COPY_TO:
8842     case GADGET_ID_CUSTOM_EXCHANGE:
8843       last_custom_copy_mode = id;
8844       last_drawing_function = drawing_function;
8845       break;
8846
8847     case GADGET_ID_CUSTOM_COPY:
8848       CopyCustomElement(properties_element, -1, id);
8849       break;
8850
8851     case GADGET_ID_CUSTOM_PASTE:
8852       CopyCustomElement(-1, properties_element, id);
8853       break;
8854
8855     case GADGET_ID_UNDO:
8856       if (undo_buffer_steps == 0)
8857       {
8858         Request("Undo buffer empty !", REQ_CONFIRM);
8859         break;
8860       }
8861
8862       if (edit_mode != ED_MODE_DRAWING)
8863       {
8864         DrawDrawingWindow();
8865         edit_mode = ED_MODE_DRAWING;
8866       }
8867
8868       undo_buffer_position =
8869         (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS;
8870       undo_buffer_steps--;
8871
8872       for (x = 0; x < lev_fieldx; x++)
8873         for (y = 0; y < lev_fieldy; y++)
8874           Feld[x][y] = UndoBuffer[undo_buffer_position][x][y];
8875       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos,level_ypos);
8876       break;
8877
8878     case GADGET_ID_INFO:
8879       if (edit_mode != ED_MODE_INFO)
8880       {
8881         last_edit_mode = edit_mode;
8882         edit_mode = ED_MODE_INFO;
8883
8884         DrawLevelInfoWindow();
8885       }
8886       else
8887       {
8888         edit_mode = last_edit_mode;
8889
8890         DrawEditModeWindow();
8891       }
8892       break;
8893
8894     case GADGET_ID_CLEAR:
8895       if (edit_mode != ED_MODE_DRAWING)
8896       {
8897         DrawDrawingWindow();
8898         edit_mode = ED_MODE_DRAWING;
8899       }
8900
8901       for (x = 0; x < MAX_LEV_FIELDX; x++) 
8902         for (y = 0; y < MAX_LEV_FIELDY; y++) 
8903           Feld[x][y] = (button == 1 ? EL_EMPTY : new_element);
8904       CopyLevelToUndoBuffer(GADGET_ID_CLEAR);
8905
8906       DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
8907       break;
8908
8909     case GADGET_ID_SAVE:
8910       if (leveldir_current->readonly)
8911       {
8912         Request("This level is read only !", REQ_CONFIRM);
8913         break;
8914       }
8915
8916       if (!LevelContainsPlayer)
8917         Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM);
8918       else
8919       {
8920         char *level_filename = getDefaultLevelFilename(level_nr);
8921         boolean new_level = !fileExists(level_filename);
8922
8923         if (new_level ||
8924             Request("Save this level and kill the old ?", REQ_ASK))
8925         {
8926           CopyPlayfield(Feld, level.field);
8927
8928           SaveLevel(level_nr);
8929         }
8930
8931         if (new_level)
8932           Request("Level saved !", REQ_CONFIRM);
8933       }
8934       break;
8935
8936     case GADGET_ID_TEST:
8937       if (!LevelContainsPlayer)
8938         Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM);
8939       else
8940       {
8941         if (LevelChanged())
8942           level.game_version = GAME_VERSION_ACTUAL;
8943
8944         CopyPlayfield(level.field, FieldBackup);
8945         CopyPlayfield(Feld, level.field);
8946
8947         UnmapLevelEditorGadgets();
8948         UndrawSpecialEditorDoor();
8949
8950         CloseDoor(DOOR_CLOSE_ALL);
8951
8952         DrawCompleteVideoDisplay();
8953
8954         if (setup.autorecord)
8955           TapeStartRecording();
8956
8957         level_editor_test_game = TRUE;
8958         game_status = GAME_MODE_PLAYING;
8959
8960         InitGame();
8961       }
8962       break;
8963
8964     case GADGET_ID_EXIT:
8965       RequestExitLevelEditor(TRUE);     /* if level has changed, ask user */
8966       break;
8967
8968     default:
8969       if (id >= GADGET_ID_ELEMENTLIST_FIRST &&
8970           id <= GADGET_ID_ELEMENTLIST_LAST)
8971       {
8972         int element_position = id - GADGET_ID_ELEMENTLIST_FIRST;
8973         int new_element = editor_elements[element_position + element_shift];
8974
8975         if (last_custom_copy_mode != -1)
8976         {
8977           if (CopyCustomElement(properties_element, new_element,
8978                                 last_custom_copy_mode))
8979           {
8980             ClickOnGadget(level_editor_gadget[last_drawing_function],
8981                           MB_LEFTBUTTON);
8982
8983             last_custom_copy_mode = -1;
8984           }
8985
8986           break;
8987         }
8988
8989         PickDrawingElement(button, new_element);
8990
8991         if (!stick_element_properties_window &&
8992             drawing_function != GADGET_ID_PICK_ELEMENT &&
8993             !(GetKeyModState() & KMOD_Control))
8994         {
8995           properties_element = new_element;
8996           if (edit_mode == ED_MODE_PROPERTIES)
8997             DrawPropertiesWindow();
8998         }
8999
9000         if (drawing_function == GADGET_ID_PICK_ELEMENT)
9001           ClickOnGadget(level_editor_gadget[last_drawing_function],
9002                         MB_LEFTBUTTON);
9003       }
9004 #ifdef DEBUG
9005       else if (gi->event.type == GD_EVENT_PRESSED)
9006         printf("default: HandleControlButtons: GD_EVENT_PRESSED(%d)\n", id);
9007       else if (gi->event.type == GD_EVENT_RELEASED)
9008         printf("default: HandleControlButtons: GD_EVENT_RELEASED(%d)\n", id);
9009       else if (gi->event.type == GD_EVENT_MOVING)
9010         printf("default: HandleControlButtons: GD_EVENT_MOVING(%d)\n", id);
9011       else
9012         printf("default: HandleControlButtons: ? (id == %d)\n", id);
9013 #endif
9014       break;
9015   }
9016 }
9017
9018 void HandleLevelEditorKeyInput(Key key)
9019 {
9020   char letter = getCharFromKey(key);
9021   int button = MB_LEFTBUTTON;
9022
9023   if (drawing_function == GADGET_ID_TEXT &&
9024       DrawLevelText(0, 0, 0, TEXT_QUERY_TYPING) == TRUE)
9025   {
9026     if (letter)
9027       DrawLevelText(0, 0, letter, TEXT_WRITECHAR);
9028     else if (key == KSYM_Delete || key == KSYM_BackSpace)
9029       DrawLevelText(0, 0, 0, TEXT_BACKSPACE);
9030     else if (key == KSYM_Return)
9031       DrawLevelText(0, 0, 0, TEXT_NEWLINE);
9032     else if (key == KSYM_Escape)
9033       DrawLevelText(0, 0, 0, TEXT_END);
9034   }
9035   else if (button_status == MB_RELEASED)
9036   {
9037     int i, id = GADGET_ID_NONE;
9038
9039     switch (key)
9040     {
9041       case KSYM_Left:
9042         id = GADGET_ID_SCROLL_LEFT;
9043         break;
9044       case KSYM_Right:
9045         id = GADGET_ID_SCROLL_RIGHT;
9046         break;
9047       case KSYM_Up:
9048         id = GADGET_ID_SCROLL_UP;
9049         break;
9050       case KSYM_Down:
9051         id = GADGET_ID_SCROLL_DOWN;
9052         break;
9053       case KSYM_Page_Up:
9054         id = GADGET_ID_SCROLL_LIST_UP;
9055         button = MB_RIGHTBUTTON;
9056         break;
9057       case KSYM_Page_Down:
9058         id = GADGET_ID_SCROLL_LIST_DOWN;
9059         button = MB_RIGHTBUTTON;
9060         break;
9061
9062       case KSYM_Escape:
9063         if (edit_mode == ED_MODE_DRAWING)
9064         {
9065           RequestExitLevelEditor(setup.ask_on_escape);
9066         }
9067         else
9068         {
9069           DrawDrawingWindow();
9070           edit_mode = ED_MODE_DRAWING;
9071         }
9072         break;
9073
9074       default:
9075         break;
9076     }
9077
9078     if (id != GADGET_ID_NONE)
9079       ClickOnGadget(level_editor_gadget[id], button);
9080     else if (letter == '.')
9081       ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS], button);
9082     else if (key == KSYM_Return || key == setup.shortcut.toggle_pause)
9083       ClickOnGadget(level_editor_gadget[GADGET_ID_TEST], button);
9084     else
9085       for (i = 0; i < ED_NUM_CTRL_BUTTONS; i++)
9086         if (letter && letter == control_info[i].shortcut)
9087           if (!anyTextGadgetActive())
9088             ClickOnGadget(level_editor_gadget[i], button);
9089   }
9090 }
9091
9092 void HandleLevelEditorIdle()
9093 {
9094   static unsigned long action_delay = 0;
9095   unsigned long action_delay_value = GameFrameDelay;
9096   int xpos = 1, ypos = 2;
9097
9098   if (edit_mode != ED_MODE_PROPERTIES)
9099     return;
9100
9101   if (!DelayReached(&action_delay, action_delay_value))
9102     return;
9103
9104   DrawGraphicAnimationExt(drawto,
9105                           SX + xpos * TILEX,
9106                           SY + ypos * TILEY + MINI_TILEY / 2,
9107                           el2img(properties_element), -1, NO_MASKING);
9108
9109   MarkTileDirty(xpos, ypos);
9110   MarkTileDirty(xpos, ypos + 1);
9111
9112   FrameCounter++;       /* increase animation frame counter */
9113 }
9114
9115 void ClearEditorGadgetInfoText()
9116 {
9117   DrawBackground(INFOTEXT_XPOS, INFOTEXT_YPOS, INFOTEXT_XSIZE, INFOTEXT_YSIZE);
9118 }
9119
9120 void HandleEditorGadgetInfoText(void *ptr)
9121 {
9122   struct GadgetInfo *gi = (struct GadgetInfo *)ptr;
9123   char infotext[MAX_OUTPUT_LINESIZE + 1];
9124   char shortcut[MAX_OUTPUT_LINESIZE + 1];
9125   int max_infotext_len = getMaxInfoTextLength();
9126
9127   if (game_status != GAME_MODE_EDITOR)
9128     return;
9129
9130   ClearEditorGadgetInfoText();
9131
9132   if (gi->event.type == GD_EVENT_INFO_LEAVING)
9133     return;
9134
9135   /* misuse this function to delete brush cursor, if needed */
9136   if (edit_mode == ED_MODE_DRAWING && draw_with_brush)
9137     DeleteBrushFromCursor();
9138
9139   if (gi == NULL || gi->info_text == NULL)
9140     return;
9141
9142   strncpy(infotext, gi->info_text, max_infotext_len);
9143   infotext[max_infotext_len] = '\0';
9144
9145   if (gi->custom_id < ED_NUM_CTRL_BUTTONS)
9146   {
9147     int key = control_info[gi->custom_id].shortcut;
9148
9149     if (key)
9150     {
9151       if (gi->custom_id == GADGET_ID_SINGLE_ITEMS)      /* special case 1 */
9152         sprintf(shortcut, " ('.' or '%c')", key);
9153       else if (gi->custom_id == GADGET_ID_PICK_ELEMENT) /* special case 2 */
9154         sprintf(shortcut, " ('%c' or 'Ctrl')", key);
9155       else if (gi->custom_id == GADGET_ID_TEST)         /* special case 3 */
9156         sprintf(shortcut, " ('Enter' or 'Shift-%c')", key);
9157       else                                              /* normal case */
9158         sprintf(shortcut, " ('%s%c')",
9159                 (key >= 'A' && key <= 'Z' ? "Shift-" : ""), key);
9160
9161       if (strlen(infotext) + strlen(shortcut) <= max_infotext_len)
9162         strcat(infotext, shortcut);
9163     }
9164   }
9165
9166   DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, FONT_TEXT_2);
9167 }
9168
9169 static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
9170 {
9171   static int start_lx, start_ly;
9172   int id = gi->custom_id;
9173   int sx = gi->event.x;
9174   int sy = gi->event.y;
9175   int lx = sx + level_xpos;
9176   int ly = sy + level_ypos;
9177   int min_sx = 0, min_sy = 0;
9178   int max_sx = gi->drawing.area_xsize - 1;
9179   int max_sy = gi->drawing.area_ysize - 1;
9180   int actual_drawing_function = drawing_function;
9181   int max_infotext_len = getMaxInfoTextLength();
9182   char infotext[MAX_OUTPUT_LINESIZE + 1];
9183   char *text;
9184
9185   infotext[0] = '\0';           /* start with empty info text */
9186
9187   /* pressed Control key: simulate picking element */
9188   if (GetKeyModState() & KMOD_Control)
9189     actual_drawing_function = GADGET_ID_PICK_ELEMENT;
9190
9191   ClearEditorGadgetInfoText();
9192
9193   if (gi->event.type == GD_EVENT_INFO_LEAVING)
9194     return;
9195
9196   /* make sure to stay inside drawing area boundaries */
9197   sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
9198   sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
9199
9200   if (id == GADGET_ID_DRAWING_LEVEL)
9201   {
9202     if (button_status)
9203     {
9204       int min_lx = 0, min_ly = 0;
9205       int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
9206
9207       /* get positions inside level field */
9208       lx = sx + level_xpos;
9209       ly = sy + level_ypos;
9210
9211       /* make sure to stay inside level field boundaries */
9212       lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
9213       ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
9214
9215       /* correct drawing area positions accordingly */
9216       sx = lx - level_xpos;
9217       sy = ly - level_ypos;
9218     }
9219
9220     if (IN_ED_FIELD(sx,sy) && IN_LEV_FIELD(lx, ly))
9221     {
9222       if (button_status)        /* if (gi->state == GD_BUTTON_PRESSED) */
9223       {
9224         if (gi->event.type == GD_EVENT_PRESSED)
9225         {
9226           start_lx = lx;
9227           start_ly = ly;
9228         }
9229
9230         switch (actual_drawing_function)
9231         {
9232           case GADGET_ID_SINGLE_ITEMS:
9233             text = "Drawing single items";
9234             break;
9235           case GADGET_ID_CONNECTED_ITEMS:
9236             text = "Drawing connected items";
9237             break;
9238           case GADGET_ID_LINE:
9239             text = "Drawing line";
9240             break;
9241           case GADGET_ID_ARC:
9242             text = "Drawing arc";
9243             break;
9244           case GADGET_ID_TEXT:
9245             text = "Setting text cursor";
9246             break;
9247           case GADGET_ID_RECTANGLE:
9248             text = "Drawing rectangle";
9249             break;
9250           case GADGET_ID_FILLED_BOX:
9251             text = "Drawing filled box";
9252             break;
9253           case GADGET_ID_FLOOD_FILL:
9254             text = "Flood fill";
9255             break;
9256           case GADGET_ID_GRAB_BRUSH:
9257             text = "Grabbing brush";
9258             break;
9259           case GADGET_ID_PICK_ELEMENT:
9260             text = "Picking element";
9261             break;
9262
9263           default:
9264             text = "Drawing position";
9265             break;
9266         }
9267
9268 #if 1
9269         if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
9270           sprintf(infotext, "%s: %d, %d", text, lx, ly);
9271         else
9272           sprintf(infotext, "%s: %d, %d", text,
9273                   ABS(lx - start_lx) + 1, ABS(ly - start_ly) + 1);
9274 #else
9275         if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
9276           DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
9277                     "%s: %d, %d", infotext, lx, ly);
9278         else
9279           DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
9280                     "%s: %d, %d", infotext,
9281                     ABS(lx - start_lx) + 1, ABS(ly - start_ly) + 1);
9282 #endif
9283       }
9284 #if 1
9285       else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
9286         strncpy(infotext, getElementInfoText(Feld[lx][ly]), max_infotext_len);
9287       else
9288         sprintf(infotext, "Level position: %d, %d", lx, ly);
9289 #else
9290       else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
9291         DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
9292                   "%s", getElementInfoText(Feld[lx][ly]));
9293       else
9294         DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2,
9295                   "Level position: %d, %d", lx, ly);
9296 #endif
9297     }
9298
9299     /* misuse this function to draw brush cursor, if needed */
9300     if (edit_mode == ED_MODE_DRAWING && draw_with_brush && !button_status)
9301     {
9302       if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
9303         CopyBrushToCursor(sx, sy);
9304       else
9305         DeleteBrushFromCursor();
9306     }
9307   }
9308   else if (actual_drawing_function == GADGET_ID_PICK_ELEMENT)
9309   {
9310     int element = EL_EMPTY;
9311
9312     if (id == GADGET_ID_AMOEBA_CONTENT)
9313       element = level.amoeba_content;
9314     else if (id == GADGET_ID_CUSTOM_GRAPHIC)
9315       element = custom_element.gfx_element;
9316     else if (id == GADGET_ID_CUSTOM_CONTENT)
9317       element = custom_element.content[sx][sy];
9318     else if (id == GADGET_ID_CUSTOM_MOVE_ENTER)
9319       element = custom_element.move_enter_element;
9320     else if (id == GADGET_ID_CUSTOM_MOVE_LEAVE)
9321       element = custom_element.move_leave_element;
9322     else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
9323       element = custom_element_change.target_element;
9324     else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
9325       element = custom_element_change.target_content[sx][sy];
9326     else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
9327       element = custom_element_change.trigger_element;
9328     else if (id == GADGET_ID_GROUP_CONTENT)
9329       element = group_element_info.element[sx];
9330     else if (id == GADGET_ID_RANDOM_BACKGROUND)
9331       element = random_placement_background_element;
9332     else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
9333              id <= GADGET_ID_ELEMENT_CONTENT_7)
9334       element = level.yamyam_content[id - GADGET_ID_ELEMENT_CONTENT_0][sx][sy];
9335
9336     strncpy(infotext, getElementInfoText(element), max_infotext_len);
9337   }
9338   else
9339   {
9340     if (id == GADGET_ID_AMOEBA_CONTENT)
9341       strcpy(infotext, "Amoeba content");
9342     else if (id == GADGET_ID_CUSTOM_GRAPHIC)
9343       strcpy(infotext, "Custom graphic element");
9344     else if (id == GADGET_ID_CUSTOM_CONTENT)
9345       sprintf(infotext, "Custom element content position: %d, %d", sx, sy);
9346     else if (id == GADGET_ID_CUSTOM_MOVE_ENTER)
9347       strcpy(infotext, "Element that can be digged/collected");
9348     else if (id == GADGET_ID_CUSTOM_MOVE_LEAVE)
9349       strcpy(infotext, "Element that will be left behind");
9350     else if (id == GADGET_ID_CUSTOM_CHANGE_TARGET)
9351       strcpy(infotext, "New element after change");
9352     else if (id == GADGET_ID_CUSTOM_CHANGE_CONTENT)
9353       strcpy(infotext, "New extended elements after change");
9354     else if (id == GADGET_ID_CUSTOM_CHANGE_TRIGGER)
9355       strcpy(infotext, "Other element triggering change");
9356     else if (id == GADGET_ID_GROUP_CONTENT)
9357       sprintf(infotext, "Group element position: %d", sx + 1);
9358     else if (id == GADGET_ID_RANDOM_BACKGROUND)
9359       strcpy(infotext, "Random placement background");
9360     else if (id >= GADGET_ID_ELEMENT_CONTENT_0 &&
9361              id <= GADGET_ID_ELEMENT_CONTENT_7)
9362       sprintf(infotext, "Content area %d position: %d, %d",
9363               id - GADGET_ID_ELEMENT_CONTENT_0 + 1, sx, sy);
9364   }
9365
9366   infotext[max_infotext_len] = '\0';
9367
9368   if (strlen(infotext) > 0)
9369     DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FONT_TEXT_2, infotext);
9370 }
9371
9372 void RequestExitLevelEditor(boolean ask_if_level_has_changed)
9373 {
9374   if (!ask_if_level_has_changed ||
9375       !LevelChanged() ||
9376       Request("Level has changed! Exit without saving ?",
9377               REQ_ASK | REQ_STAY_OPEN))
9378   {
9379 #if 1
9380     CloseDoor(DOOR_CLOSE_1);
9381     SetDoorState(DOOR_CLOSE_2);
9382 #else
9383     CloseDoor(DOOR_CLOSE_ALL);
9384 #endif
9385     game_status = GAME_MODE_MAIN;
9386     DrawMainMenu();
9387   }
9388   else
9389   {
9390     CloseDoor(DOOR_CLOSE_1);
9391     BlitBitmap(bitmap_db_door, bitmap_db_door,
9392                DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY1, DXSIZE,DYSIZE,
9393                DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
9394     OpenDoor(DOOR_OPEN_1);
9395   }
9396 }