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