1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
16 #include "libgame/libgame.h"
25 /* positions in the level editor */
26 #define ED_WIN_MB_LEFT_XPOS 6
27 #define ED_WIN_MB_LEFT_YPOS 258
28 #define ED_WIN_MB_MIDDLE_XPOS 42
29 #define ED_WIN_MB_MIDDLE_YPOS ED_WIN_MB_LEFT_YPOS
30 #define ED_WIN_MB_RIGHT_XPOS 78
31 #define ED_WIN_MB_RIGHT_YPOS ED_WIN_MB_LEFT_YPOS
33 /* other constants for the editor */
34 #define ED_SCROLL_NO 0
35 #define ED_SCROLL_LEFT 1
36 #define ED_SCROLL_RIGHT 2
37 #define ED_SCROLL_UP 4
38 #define ED_SCROLL_DOWN 8
40 /* screens in the level editor */
41 #define ED_MODE_DRAWING 0
42 #define ED_MODE_INFO 1
43 #define ED_MODE_PROPERTIES 2
45 /* how many steps can be cancelled */
46 #define NUM_UNDO_STEPS (10 + 1)
48 /* values for elements with score */
52 /* values for the control window */
53 #define ED_CTRL_BUTTONS_GFX_YPOS 236
54 #define ED_CTRL_BUTTONS_ALT_GFX_YPOS 142
56 #define ED_CTRL1_BUTTONS_HORIZ 4
57 #define ED_CTRL1_BUTTONS_VERT 4
58 #define ED_CTRL1_BUTTON_XSIZE 22
59 #define ED_CTRL1_BUTTON_YSIZE 22
60 #define ED_CTRL1_BUTTONS_XPOS 6
61 #define ED_CTRL1_BUTTONS_YPOS 6
62 #define ED_CTRL2_BUTTONS_HORIZ 3
63 #define ED_CTRL2_BUTTONS_VERT 2
64 #define ED_CTRL2_BUTTON_XSIZE 30
65 #define ED_CTRL2_BUTTON_YSIZE 20
66 #define ED_CTRL2_BUTTONS_XPOS 5
67 #define ED_CTRL2_BUTTONS_YPOS 99
68 #define ED_NUM_CTRL1_BUTTONS (ED_CTRL1_BUTTONS_HORIZ * ED_CTRL1_BUTTONS_VERT)
69 #define ED_NUM_CTRL2_BUTTONS (ED_CTRL2_BUTTONS_HORIZ * ED_CTRL2_BUTTONS_VERT)
70 #define ED_NUM_CTRL_BUTTONS (ED_NUM_CTRL1_BUTTONS + ED_NUM_CTRL2_BUTTONS)
72 /* values for the element list */
73 #define ED_ELEMENTLIST_XPOS 5
74 #define ED_ELEMENTLIST_YPOS 30
75 #define ED_ELEMENTLIST_XSIZE 20
76 #define ED_ELEMENTLIST_YSIZE 20
77 #define ED_ELEMENTLIST_BUTTONS_HORIZ 4
78 #define ED_ELEMENTLIST_BUTTONS_VERT 11
79 #define ED_NUM_ELEMENTLIST_BUTTONS (ED_ELEMENTLIST_BUTTONS_HORIZ * \
80 ED_ELEMENTLIST_BUTTONS_VERT)
82 /* values for the setting windows */
83 #define ED_SETTINGS_XPOS (MINI_TILEX + 8)
84 #define ED_SETTINGS2_XPOS MINI_TILEX
85 #define ED_SETTINGS_YPOS MINI_TILEY
86 #define ED_SETTINGS2_YPOS (ED_SETTINGS_YPOS + 12 * TILEY - 2)
88 /* values for counter gadgets */
89 #define ED_COUNT_ELEM_SCORE_XPOS ED_SETTINGS_XPOS
90 #define ED_COUNT_ELEM_SCORE_YPOS (14 * MINI_TILEY)
91 #define ED_COUNT_ELEM_CONTENT_XPOS ED_SETTINGS_XPOS
92 #define ED_COUNT_ELEM_CONTENT_YPOS (19 * MINI_TILEY)
94 #define ED_COUNTER_YSTART (ED_SETTINGS_YPOS + 2 * TILEY)
95 #define ED_COUNTER_YDISTANCE (3 * MINI_TILEY)
96 #define ED_COUNTER_YPOS(n) (ED_COUNTER_YSTART + \
97 n * ED_COUNTER_YDISTANCE)
98 #define ED_COUNTER2_YPOS(n) (ED_COUNTER_YSTART + \
99 n * ED_COUNTER_YDISTANCE - 2)
100 /* standard distances */
101 #define ED_BORDER_SIZE 3
102 #define ED_GADGET_DISTANCE 2
104 /* values for element content drawing areas */
105 #define ED_AREA_ELEM_CONTENT_XPOS ( 2 * MINI_TILEX)
106 #define ED_AREA_ELEM_CONTENT_YPOS (22 * MINI_TILEY)
108 /* values for random placement background drawing area */
109 #define ED_AREA_RANDOM_BACKGROUND_XPOS (29 * MINI_TILEX)
110 #define ED_AREA_RANDOM_BACKGROUND_YPOS (31 * MINI_TILEY)
112 /* values for scrolling gadgets for drawing area */
113 #define ED_SCROLLBUTTON_XPOS 24
114 #define ED_SCROLLBUTTON_YPOS 0
115 #define ED_SCROLLBAR_XPOS 24
116 #define ED_SCROLLBAR_YPOS 64
118 #define ED_SCROLLBUTTON_XSIZE 16
119 #define ED_SCROLLBUTTON_YSIZE 16
121 #define ED_SCROLL_UP_XPOS (SXSIZE - ED_SCROLLBUTTON_XSIZE)
122 #define ED_SCROLL_UP_YPOS (0)
123 #define ED_SCROLL_DOWN_XPOS ED_SCROLL_UP_XPOS
124 #define ED_SCROLL_DOWN_YPOS (SYSIZE - 3 * ED_SCROLLBUTTON_YSIZE)
125 #define ED_SCROLL_LEFT_XPOS (0)
126 #define ED_SCROLL_LEFT_YPOS (SYSIZE - 2 * ED_SCROLLBUTTON_YSIZE)
127 #define ED_SCROLL_RIGHT_XPOS (SXSIZE - 2 * ED_SCROLLBUTTON_XSIZE)
128 #define ED_SCROLL_RIGHT_YPOS ED_SCROLL_LEFT_YPOS
129 #define ED_SCROLL_HORIZONTAL_XPOS (ED_SCROLL_LEFT_XPOS + ED_SCROLLBUTTON_XSIZE)
130 #define ED_SCROLL_HORIZONTAL_YPOS ED_SCROLL_LEFT_YPOS
131 #define ED_SCROLL_HORIZONTAL_XSIZE (SXSIZE - 3 * ED_SCROLLBUTTON_XSIZE)
132 #define ED_SCROLL_HORIZONTAL_YSIZE ED_SCROLLBUTTON_YSIZE
133 #define ED_SCROLL_VERTICAL_XPOS ED_SCROLL_UP_XPOS
134 #define ED_SCROLL_VERTICAL_YPOS (ED_SCROLL_UP_YPOS + ED_SCROLLBUTTON_YSIZE)
135 #define ED_SCROLL_VERTICAL_XSIZE ED_SCROLLBUTTON_XSIZE
136 #define ED_SCROLL_VERTICAL_YSIZE (SYSIZE - 4 * ED_SCROLLBUTTON_YSIZE)
138 /* values for scrolling gadgets for element list */
139 #define ED_SCROLLBUTTON2_XPOS 50
140 #define ED_SCROLLBUTTON2_YPOS 0
141 #define ED_SCROLLBAR2_XPOS 50
142 #define ED_SCROLLBAR2_YPOS 20
144 #define ED_SCROLLBUTTON2_XSIZE 10
145 #define ED_SCROLLBUTTON2_YSIZE 10
147 #define ED_SCROLL2_UP_XPOS 85
148 #define ED_SCROLL2_UP_YPOS 30
149 #define ED_SCROLL2_DOWN_XPOS ED_SCROLL2_UP_XPOS
150 #define ED_SCROLL2_DOWN_YPOS (ED_SCROLL2_UP_YPOS + \
151 ED_ELEMENTLIST_BUTTONS_VERT * \
152 ED_ELEMENTLIST_YSIZE - \
153 ED_SCROLLBUTTON2_YSIZE)
154 #define ED_SCROLL2_VERTICAL_XPOS ED_SCROLL2_UP_XPOS
155 #define ED_SCROLL2_VERTICAL_YPOS (ED_SCROLL2_UP_YPOS + \
156 ED_SCROLLBUTTON2_YSIZE)
157 #define ED_SCROLL2_VERTICAL_XSIZE ED_SCROLLBUTTON2_XSIZE
158 #define ED_SCROLL2_VERTICAL_YSIZE (ED_ELEMENTLIST_BUTTONS_VERT * \
159 ED_ELEMENTLIST_YSIZE - \
160 2 * ED_SCROLLBUTTON2_YSIZE)
162 /* values for checkbutton gadgets */
163 #define ED_CHECKBUTTON_XSIZE ED_BUTTON_COUNT_XSIZE
164 #define ED_CHECKBUTTON_YSIZE ED_BUTTON_COUNT_YSIZE
165 #define ED_CHECKBUTTON_UNCHECKED_XPOS ED_BUTTON_MINUS_XPOS
166 #define ED_CHECKBUTTON_CHECKED_XPOS ED_BUTTON_PLUS_XPOS
167 #define ED_CHECKBUTTON_YPOS (ED_BUTTON_MINUS_YPOS + 22)
168 #define ED_RADIOBUTTON_YPOS (ED_BUTTON_MINUS_YPOS + 44)
169 #define ED_STICKYBUTTON_YPOS (ED_BUTTON_MINUS_YPOS + 66)
171 /* some positions in the editor control window */
172 #define ED_BUTTON_ELEM_XPOS 6
173 #define ED_BUTTON_ELEM_YPOS 30
174 #define ED_BUTTON_ELEM_XSIZE 22
175 #define ED_BUTTON_ELEM_YSIZE 22
177 /* some values for text input and counter gadgets */
178 #define ED_BUTTON_COUNT_YPOS 60
179 #define ED_BUTTON_COUNT_XSIZE 20
180 #define ED_BUTTON_COUNT_YSIZE 20
181 #define ED_WIN_COUNT_XPOS (2 + ED_BUTTON_COUNT_XSIZE + 2)
182 #define ED_WIN_COUNT_YPOS ED_BUTTON_COUNT_YPOS
183 #define ED_WIN_COUNT_XSIZE 52
184 #define ED_WIN_COUNT_YSIZE ED_BUTTON_COUNT_YSIZE
185 #define ED_WIN_COUNT2_XPOS 27
186 #define ED_WIN_COUNT2_YPOS 3
187 #define ED_WIN_COUNT2_XSIZE 46
188 #define ED_WIN_COUNT2_YSIZE ED_BUTTON_COUNT_YSIZE
190 #define ED_BUTTON_MINUS_XPOS 2
191 #define ED_BUTTON_MINUS_YPOS ED_BUTTON_COUNT_YPOS
192 #define ED_BUTTON_MINUS_XSIZE ED_BUTTON_COUNT_XSIZE
193 #define ED_BUTTON_MINUS_YSIZE ED_BUTTON_COUNT_YSIZE
194 #define ED_BUTTON_PLUS_XPOS (ED_WIN_COUNT_XPOS + ED_WIN_COUNT_XSIZE + 2)
195 #define ED_BUTTON_PLUS_YPOS ED_BUTTON_COUNT_YPOS
196 #define ED_BUTTON_PLUS_XSIZE ED_BUTTON_COUNT_XSIZE
197 #define ED_BUTTON_PLUS_YSIZE ED_BUTTON_COUNT_YSIZE
199 /* editor gadget identifiers */
201 /* drawing toolbox buttons */
202 #define GADGET_ID_NONE -1
203 #define GADGET_ID_SINGLE_ITEMS 0
204 #define GADGET_ID_CONNECTED_ITEMS 1
205 #define GADGET_ID_LINE 2
206 #define GADGET_ID_ARC 3
207 #define GADGET_ID_RECTANGLE 4
208 #define GADGET_ID_FILLED_BOX 5
209 #define GADGET_ID_WRAP_UP 6
210 #define GADGET_ID_TEXT 7
211 #define GADGET_ID_FLOOD_FILL 8
212 #define GADGET_ID_WRAP_LEFT 9
213 #define GADGET_ID_PROPERTIES 10
214 #define GADGET_ID_WRAP_RIGHT 11
215 #define GADGET_ID_RANDOM_PLACEMENT 12
216 #define GADGET_ID_GRAB_BRUSH 13
217 #define GADGET_ID_WRAP_DOWN 14
218 #define GADGET_ID_PICK_ELEMENT 15
219 #define GADGET_ID_UNDO 16
220 #define GADGET_ID_INFO 17
221 #define GADGET_ID_SAVE 18
222 #define GADGET_ID_CLEAR 19
223 #define GADGET_ID_TEST 20
224 #define GADGET_ID_EXIT 21
226 /* counter button identifiers */
227 #define GADGET_ID_ELEM_SCORE_DOWN 22
228 #define GADGET_ID_ELEM_SCORE_TEXT 23
229 #define GADGET_ID_ELEM_SCORE_UP 24
230 #define GADGET_ID_ELEM_CONTENT_DOWN 25
231 #define GADGET_ID_ELEM_CONTENT_TEXT 26
232 #define GADGET_ID_ELEM_CONTENT_UP 27
233 #define GADGET_ID_LEVEL_XSIZE_DOWN 28
234 #define GADGET_ID_LEVEL_XSIZE_TEXT 29
235 #define GADGET_ID_LEVEL_XSIZE_UP 30
236 #define GADGET_ID_LEVEL_YSIZE_DOWN 31
237 #define GADGET_ID_LEVEL_YSIZE_TEXT 32
238 #define GADGET_ID_LEVEL_YSIZE_UP 33
239 #define GADGET_ID_LEVEL_RANDOM_DOWN 34
240 #define GADGET_ID_LEVEL_RANDOM_TEXT 35
241 #define GADGET_ID_LEVEL_RANDOM_UP 36
242 #define GADGET_ID_LEVEL_COLLECT_DOWN 37
243 #define GADGET_ID_LEVEL_COLLECT_TEXT 38
244 #define GADGET_ID_LEVEL_COLLECT_UP 39
245 #define GADGET_ID_LEVEL_TIMELIMIT_DOWN 40
246 #define GADGET_ID_LEVEL_TIMELIMIT_TEXT 41
247 #define GADGET_ID_LEVEL_TIMELIMIT_UP 42
248 #define GADGET_ID_LEVEL_TIMESCORE_DOWN 43
249 #define GADGET_ID_LEVEL_TIMESCORE_TEXT 44
250 #define GADGET_ID_LEVEL_TIMESCORE_UP 45
251 #define GADGET_ID_SELECT_LEVEL_DOWN 46
252 #define GADGET_ID_SELECT_LEVEL_TEXT 47
253 #define GADGET_ID_SELECT_LEVEL_UP 48
255 /* drawing area identifiers */
256 #define GADGET_ID_DRAWING_LEVEL 49
257 #define GADGET_ID_ELEM_CONTENT_0 50
258 #define GADGET_ID_ELEM_CONTENT_1 51
259 #define GADGET_ID_ELEM_CONTENT_2 52
260 #define GADGET_ID_ELEM_CONTENT_3 53
261 #define GADGET_ID_ELEM_CONTENT_4 54
262 #define GADGET_ID_ELEM_CONTENT_5 55
263 #define GADGET_ID_ELEM_CONTENT_6 56
264 #define GADGET_ID_ELEM_CONTENT_7 57
265 #define GADGET_ID_AMOEBA_CONTENT 58
267 /* text input identifiers */
268 #define GADGET_ID_LEVEL_NAME 59
269 #define GADGET_ID_LEVEL_AUTHOR 60
271 /* gadgets for scrolling of drawing area */
272 #define GADGET_ID_SCROLL_UP 61
273 #define GADGET_ID_SCROLL_DOWN 62
274 #define GADGET_ID_SCROLL_LEFT 63
275 #define GADGET_ID_SCROLL_RIGHT 64
276 #define GADGET_ID_SCROLL_HORIZONTAL 65
277 #define GADGET_ID_SCROLL_VERTICAL 66
279 /* gadgets for scrolling element list */
280 #define GADGET_ID_SCROLL_LIST_UP 67
281 #define GADGET_ID_SCROLL_LIST_DOWN 68
282 #define GADGET_ID_SCROLL_LIST_VERTICAL 69
284 /* buttons for level settings */
285 #define GADGET_ID_RANDOM_PERCENTAGE 70
286 #define GADGET_ID_RANDOM_QUANTITY 71
287 #define GADGET_ID_RANDOM_RESTRICTED 72
288 #define GADGET_ID_DOUBLE_SPEED 73
289 #define GADGET_ID_GRAVITY 74
290 #define GADGET_ID_STICK_ELEMENT 75
292 /* another drawing area for random placement */
293 #define GADGET_ID_RANDOM_BACKGROUND 76
295 /* gadgets for buttons in element list */
296 #define GADGET_ID_ELEMENTLIST_FIRST 77
297 #define GADGET_ID_ELEMENTLIST_LAST (77 + ED_NUM_ELEMENTLIST_BUTTONS - 1)
299 #define NUM_EDITOR_GADGETS (GADGET_ID_ELEMENTLIST_LAST + 1)
301 /* radio button numbers */
302 #define RADIO_NR_NONE 0
303 #define RADIO_NR_DRAWING_TOOLBOX 1
304 #define RADIO_NR_RANDOM_ELEMENTS 2
306 /* values for counter gadgets */
307 #define ED_COUNTER_ID_ELEM_SCORE 0
308 #define ED_COUNTER_ID_ELEM_CONTENT 1
309 #define ED_COUNTER_ID_LEVEL_XSIZE 2
310 #define ED_COUNTER_ID_LEVEL_YSIZE 3
311 #define ED_COUNTER_ID_LEVEL_COLLECT 4
312 #define ED_COUNTER_ID_LEVEL_TIMELIMIT 5
313 #define ED_COUNTER_ID_LEVEL_TIMESCORE 6
314 #define ED_COUNTER_ID_LEVEL_RANDOM 7
315 #define ED_COUNTER_ID_SELECT_LEVEL 8
317 #define ED_NUM_COUNTERBUTTONS 9
319 #define ED_COUNTER_ID_LEVEL_FIRST ED_COUNTER_ID_LEVEL_XSIZE
320 #define ED_COUNTER_ID_LEVEL_LAST ED_COUNTER_ID_LEVEL_RANDOM
322 /* values for scrollbutton gadgets */
323 #define ED_SCROLLBUTTON_ID_AREA_UP 0
324 #define ED_SCROLLBUTTON_ID_AREA_DOWN 1
325 #define ED_SCROLLBUTTON_ID_AREA_LEFT 2
326 #define ED_SCROLLBUTTON_ID_AREA_RIGHT 3
327 #define ED_SCROLLBUTTON_ID_LIST_UP 4
328 #define ED_SCROLLBUTTON_ID_LIST_DOWN 5
330 #define ED_NUM_SCROLLBUTTONS 6
332 #define ED_SCROLLBUTTON_ID_AREA_FIRST ED_SCROLLBUTTON_ID_AREA_UP
333 #define ED_SCROLLBUTTON_ID_AREA_LAST ED_SCROLLBUTTON_ID_AREA_RIGHT
335 /* values for scrollbar gadgets */
336 #define ED_SCROLLBAR_ID_AREA_HORIZONTAL 0
337 #define ED_SCROLLBAR_ID_AREA_VERTICAL 1
338 #define ED_SCROLLBAR_ID_LIST_VERTICAL 2
340 #define ED_NUM_SCROLLBARS 3
342 #define ED_SCROLLBAR_ID_AREA_FIRST ED_SCROLLBAR_ID_AREA_HORIZONTAL
343 #define ED_SCROLLBAR_ID_AREA_LAST ED_SCROLLBAR_ID_AREA_VERTICAL
345 /* values for text input gadgets */
346 #define ED_TEXTINPUT_ID_LEVEL_NAME 0
347 #define ED_TEXTINPUT_ID_LEVEL_AUTHOR 1
349 #define ED_NUM_TEXTINPUT 2
351 #define ED_TEXTINPUT_ID_LEVEL_FIRST ED_TEXTINPUT_ID_LEVEL_NAME
352 #define ED_TEXTINPUT_ID_LEVEL_LAST ED_TEXTINPUT_ID_LEVEL_AUTHOR
354 /* values for checkbutton gadgets */
355 #define ED_CHECKBUTTON_ID_DOUBLE_SPEED 0
356 #define ED_CHECKBUTTON_ID_GRAVITY 1
357 #define ED_CHECKBUTTON_ID_RANDOM_RESTRICTED 2
358 #define ED_CHECKBUTTON_ID_STICK_ELEMENT 3
360 #define ED_NUM_CHECKBUTTONS 4
362 #define ED_CHECKBUTTON_ID_LEVEL_FIRST ED_CHECKBUTTON_ID_DOUBLE_SPEED
363 #define ED_CHECKBUTTON_ID_LEVEL_LAST ED_CHECKBUTTON_ID_RANDOM_RESTRICTED
365 /* values for radiobutton gadgets */
366 #define ED_RADIOBUTTON_ID_PERCENTAGE 0
367 #define ED_RADIOBUTTON_ID_QUANTITY 1
369 #define ED_NUM_RADIOBUTTONS 2
371 #define ED_RADIOBUTTON_ID_LEVEL_FIRST ED_RADIOBUTTON_ID_PERCENTAGE
372 #define ED_RADIOBUTTON_ID_LEVEL_LAST ED_RADIOBUTTON_ID_QUANTITY
374 /* values for CopyLevelToUndoBuffer() */
375 #define UNDO_IMMEDIATE 0
376 #define UNDO_ACCUMULATE 1
378 /* values for ClearEditorGadgetInfoText() and HandleGadgetInfoText() */
379 #define INFOTEXT_XPOS SX
380 #define INFOTEXT_YPOS (SY + SYSIZE - MINI_TILEX + 2)
381 #define INFOTEXT_XSIZE SXSIZE
382 #define INFOTEXT_YSIZE MINI_TILEX
383 #define MAX_INFOTEXT_LEN (SXSIZE / FONT2_XSIZE)
389 } control_info[ED_NUM_CTRL_BUTTONS] =
391 { 's', "draw single items" },
392 { 'd', "draw connected items" },
393 { 'l', "draw lines" },
394 { 'a', "draw arcs" },
395 { 'r', "draw outline rectangles" },
396 { 'R', "draw filled rectangles" },
397 { '\0', "wrap (rotate) level up" },
398 { 't', "enter text elements" },
399 { 'f', "flood fill" },
400 { '\0', "wrap (rotate) level left" },
401 { '?', "properties of drawing element" },
402 { '\0', "wrap (rotate) level right" },
403 { '\0', "random element placement" },
404 { 'b', "grab brush" },
405 { '\0', "wrap (rotate) level down" },
406 { ',', "pick drawing element" },
407 { 'U', "undo last operation" },
408 { 'I', "level properties" },
409 { 'S', "save level" },
410 { 'C', "clear level" },
411 { 'T', "test level" },
412 { 'E', "exit level editor" }
415 /* values for random placement */
416 #define RANDOM_USE_PERCENTAGE 0
417 #define RANDOM_USE_QUANTITY 1
419 static int random_placement_value = 10;
420 static int random_placement_method = RANDOM_USE_QUANTITY;
421 static int random_placement_background_element = EL_ERDREICH;
422 static boolean random_placement_background_restricted = FALSE;
423 static boolean stick_element_properties_window = FALSE;
428 int min_value, max_value;
429 int gadget_id_down, gadget_id_up;
432 char *infotext_above, *infotext_right;
433 } counterbutton_info[ED_NUM_COUNTERBUTTONS] =
436 ED_COUNT_ELEM_SCORE_XPOS, ED_COUNT_ELEM_SCORE_YPOS,
437 MIN_SCORE, MAX_SCORE,
438 GADGET_ID_ELEM_SCORE_DOWN, GADGET_ID_ELEM_SCORE_UP,
439 GADGET_ID_ELEM_SCORE_TEXT,
440 NULL, /* will be set when used */
441 "element score", NULL
444 ED_COUNT_ELEM_CONTENT_XPOS, ED_COUNT_ELEM_CONTENT_YPOS,
445 MIN_ELEMENT_CONTENTS, MAX_ELEMENT_CONTENTS,
446 GADGET_ID_ELEM_CONTENT_DOWN, GADGET_ID_ELEM_CONTENT_UP,
447 GADGET_ID_ELEM_CONTENT_TEXT,
448 &level.num_yam_contents,
449 "element content", NULL
452 ED_SETTINGS_XPOS, ED_COUNTER_YPOS(2),
453 MIN_LEV_FIELDX, MAX_LEV_FIELDX,
454 GADGET_ID_LEVEL_XSIZE_DOWN, GADGET_ID_LEVEL_XSIZE_UP,
455 GADGET_ID_LEVEL_XSIZE_TEXT,
457 "playfield size", "width",
460 ED_SETTINGS_XPOS + 2 * DXSIZE, ED_COUNTER_YPOS(2),
461 MIN_LEV_FIELDY, MAX_LEV_FIELDY,
462 GADGET_ID_LEVEL_YSIZE_DOWN, GADGET_ID_LEVEL_YSIZE_UP,
463 GADGET_ID_LEVEL_YSIZE_TEXT,
468 ED_SETTINGS_XPOS, ED_COUNTER_YPOS(3),
470 GADGET_ID_LEVEL_COLLECT_DOWN, GADGET_ID_LEVEL_COLLECT_UP,
471 GADGET_ID_LEVEL_COLLECT_TEXT,
473 "number of emeralds to collect", NULL
476 ED_SETTINGS_XPOS, ED_COUNTER_YPOS(4),
478 GADGET_ID_LEVEL_TIMELIMIT_DOWN, GADGET_ID_LEVEL_TIMELIMIT_UP,
479 GADGET_ID_LEVEL_TIMELIMIT_TEXT,
481 "time available to solve level", "(0 => no time limit)"
484 ED_SETTINGS_XPOS, ED_COUNTER_YPOS(5),
486 GADGET_ID_LEVEL_TIMESCORE_DOWN, GADGET_ID_LEVEL_TIMESCORE_UP,
487 GADGET_ID_LEVEL_TIMESCORE_TEXT,
488 &level.score[SC_ZEITBONUS],
489 "score for each 10 seconds left", NULL
492 ED_SETTINGS_XPOS, ED_COUNTER2_YPOS(8),
494 GADGET_ID_LEVEL_RANDOM_DOWN, GADGET_ID_LEVEL_RANDOM_UP,
495 GADGET_ID_LEVEL_RANDOM_TEXT,
496 &random_placement_value,
497 "random element placement", "in"
500 DX + 5 - SX, DY + 3 - SY,
502 GADGET_ID_SELECT_LEVEL_DOWN, GADGET_ID_SELECT_LEVEL_UP,
503 GADGET_ID_SELECT_LEVEL_TEXT,
516 } textinput_info[ED_NUM_TEXTINPUT] =
519 ED_SETTINGS_XPOS, ED_COUNTER_YPOS(0),
520 GADGET_ID_LEVEL_NAME,
526 ED_SETTINGS_XPOS, ED_COUNTER_YPOS(1),
527 GADGET_ID_LEVEL_AUTHOR,
528 MAX_LEVEL_AUTHOR_LEN,
540 } scrollbutton_info[ED_NUM_SCROLLBUTTONS] =
543 ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE,
544 ED_SCROLL_UP_XPOS, ED_SCROLL_UP_YPOS,
546 "scroll level editing area up"
549 ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE,
550 ED_SCROLL_DOWN_XPOS, ED_SCROLL_DOWN_YPOS,
551 GADGET_ID_SCROLL_DOWN,
552 "scroll level editing area down"
555 ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE,
556 ED_SCROLL_LEFT_XPOS, ED_SCROLL_LEFT_YPOS,
557 GADGET_ID_SCROLL_LEFT,
558 "scroll level editing area left"
561 ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE,
562 ED_SCROLL_RIGHT_XPOS, ED_SCROLL_RIGHT_YPOS,
563 GADGET_ID_SCROLL_RIGHT,
564 "scroll level editing area right"
567 ED_SCROLLBUTTON2_XPOS, ED_SCROLLBUTTON2_YPOS + 0 * ED_SCROLLBUTTON2_YSIZE,
568 ED_SCROLL2_UP_XPOS, ED_SCROLL2_UP_YPOS,
569 GADGET_ID_SCROLL_LIST_UP,
570 "scroll element list up ('Page Up')"
573 ED_SCROLLBUTTON2_XPOS, ED_SCROLLBUTTON2_YPOS + 1 * ED_SCROLLBUTTON2_YSIZE,
574 ED_SCROLL2_DOWN_XPOS, ED_SCROLL2_DOWN_YPOS,
575 GADGET_ID_SCROLL_LIST_DOWN,
576 "scroll element list down ('Page Down')"
588 } scrollbar_info[ED_NUM_SCROLLBARS] =
591 ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS,
592 SX + ED_SCROLL_HORIZONTAL_XPOS, SY + ED_SCROLL_HORIZONTAL_YPOS,
593 ED_SCROLL_HORIZONTAL_XSIZE, ED_SCROLL_HORIZONTAL_YSIZE,
594 GD_TYPE_SCROLLBAR_HORIZONTAL,
595 GADGET_ID_SCROLL_HORIZONTAL,
596 "scroll level editing area horizontally"
599 ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS,
600 SX + ED_SCROLL_VERTICAL_XPOS, SY + ED_SCROLL_VERTICAL_YPOS,
601 ED_SCROLL_VERTICAL_XSIZE, ED_SCROLL_VERTICAL_YSIZE,
602 GD_TYPE_SCROLLBAR_VERTICAL,
603 GADGET_ID_SCROLL_VERTICAL,
604 "scroll level editing area vertically"
607 ED_SCROLLBAR2_XPOS, ED_SCROLLBAR2_YPOS,
608 DX + ED_SCROLL2_VERTICAL_XPOS, DY + ED_SCROLL2_VERTICAL_YPOS,
609 ED_SCROLL2_VERTICAL_XSIZE, ED_SCROLL2_VERTICAL_YSIZE,
610 GD_TYPE_SCROLLBAR_VERTICAL,
611 GADGET_ID_SCROLL_LIST_VERTICAL,
612 "scroll element list vertically"
623 char *text, *infotext;
624 } radiobutton_info[ED_NUM_RADIOBUTTONS] =
627 ED_SETTINGS_XPOS + 160, ED_COUNTER2_YPOS(8),
628 GADGET_ID_RANDOM_PERCENTAGE,
629 RADIO_NR_RANDOM_ELEMENTS,
630 &random_placement_method, RANDOM_USE_PERCENTAGE,
631 "percentage", "use percentage for random elements"
634 ED_SETTINGS_XPOS + 340, ED_COUNTER2_YPOS(8),
635 GADGET_ID_RANDOM_QUANTITY,
636 RADIO_NR_RANDOM_ELEMENTS,
637 &random_placement_method, RANDOM_USE_QUANTITY,
638 "quantity", "use quantity for random elements"
647 char *text, *infotext;
648 } checkbutton_info[ED_NUM_CHECKBUTTONS] =
651 ED_SETTINGS_XPOS, ED_COUNTER_YPOS(6) - MINI_TILEY,
652 GADGET_ID_DOUBLE_SPEED,
654 "double speed movement", "set movement speed of player"
657 ED_SETTINGS_XPOS + 340, ED_COUNTER_YPOS(6) - MINI_TILEY,
660 "gravity", "set level gravity"
663 ED_SETTINGS_XPOS, ED_COUNTER2_YPOS(9) - MINI_TILEY,
664 GADGET_ID_RANDOM_RESTRICTED,
665 &random_placement_background_restricted,
666 "restrict random placement to", "set random placement restriction"
669 ED_SETTINGS_XPOS, ED_COUNTER_YPOS(4),
670 GADGET_ID_STICK_ELEMENT,
671 &stick_element_properties_window,
672 "stick window to edit content", "stick window to edit content"
676 /* maximal size of level editor drawing area */
677 #define MAX_ED_FIELDX (2 * SCR_FIELDX)
678 #define MAX_ED_FIELDY (2 * SCR_FIELDY - 1)
680 /* actual size of level editor drawing area */
681 static int ed_fieldx = MAX_ED_FIELDX - 1, ed_fieldy = MAX_ED_FIELDY - 1;
683 /* actual position of level editor drawing area in level playfield */
684 static int level_xpos = -1, level_ypos = -1;
686 #define IN_ED_FIELD(x,y) ((x)>=0 && (x)<ed_fieldx && (y)>=0 &&(y)<ed_fieldy)
688 /* drawing elements on the three mouse buttons */
689 static int new_element1 = EL_MAUERWERK;
690 static int new_element2 = EL_LEERRAUM;
691 static int new_element3 = EL_ERDREICH;
693 #define BUTTON_ELEMENT(button) ((button) == 1 ? new_element1 : \
694 (button) == 2 ? new_element2 : \
695 (button) == 3 ? new_element3 : EL_LEERRAUM)
696 #define BUTTON_STEPSIZE(button) ((button) == 1 ? 1 : (button) == 2 ? 5 : 10)
698 /* forward declaration for internal use */
699 static void ModifyEditorCounter(int, int);
700 static void ModifyEditorCounterLimits(int, int, int);
701 static void DrawDrawingWindow();
702 static void DrawLevelInfoWindow();
703 static void DrawPropertiesWindow();
704 static void CopyLevelToUndoBuffer(int);
705 static void HandleDrawingAreas(struct GadgetInfo *);
706 static void HandleCounterButtons(struct GadgetInfo *);
707 static void HandleTextInputGadgets(struct GadgetInfo *);
708 static void HandleRadiobuttons(struct GadgetInfo *);
709 static void HandleCheckbuttons(struct GadgetInfo *);
710 static void HandleControlButtons(struct GadgetInfo *);
711 static void HandleDrawingAreaInfo(struct GadgetInfo *);
713 static struct GadgetInfo *level_editor_gadget[NUM_EDITOR_GADGETS];
715 static int drawing_function = GADGET_ID_SINGLE_ITEMS;
716 static int last_drawing_function = GADGET_ID_SINGLE_ITEMS;
717 static boolean draw_with_brush = FALSE;
718 static int properties_element = 0;
720 static short ElementContent[MAX_ELEMENT_CONTENTS][3][3];
721 static short FieldBackup[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
722 static short UndoBuffer[NUM_UNDO_STEPS][MAX_LEV_FIELDX][MAX_LEV_FIELDY];
723 static int undo_buffer_position = 0;
724 static int undo_buffer_steps = 0;
726 static int edit_mode;
728 static int counter_xsize = DXSIZE + FONT2_XSIZE - 2 * ED_GADGET_DISTANCE;
730 int element_shift = 0;
732 int editor_element[] =
755 EL_MAGIC_WALL_BD_OFF,
814 EL_DYNAMITE_INACTIVE,
939 EL_BALLOON_SEND_LEFT,
940 EL_BALLOON_SEND_RIGHT,
942 EL_BALLOON_SEND_DOWN,
976 EL_SOKOBAN_FELD_LEER,
977 EL_SOKOBAN_FELD_VOLL,
1068 EL_BELT1_SWITCH_MIDDLE,
1073 EL_BELT2_SWITCH_MIDDLE,
1078 EL_BELT3_SWITCH_MIDDLE,
1083 EL_BELT4_SWITCH_MIDDLE,
1085 EL_BELT1_SWITCH_LEFT,
1086 EL_BELT2_SWITCH_LEFT,
1087 EL_BELT3_SWITCH_LEFT,
1088 EL_BELT4_SWITCH_LEFT,
1090 EL_BELT1_SWITCH_RIGHT,
1091 EL_BELT2_SWITCH_RIGHT,
1092 EL_BELT3_SWITCH_RIGHT,
1093 EL_BELT4_SWITCH_RIGHT,
1096 EL_SWITCHGATE_CLOSED,
1097 EL_SWITCHGATE_SWITCH_1,
1102 EL_TIMEGATE_SWITCH_OFF,
1110 EL_SIGN_EXCLAMATION,
1112 EL_LIGHT_SWITCH_OFF,
1262 int elements_in_list = sizeof(editor_element)/sizeof(int);
1264 static char *getElementInfoText(int element)
1266 char *info_text = "unknown";
1268 if (element < num_element_info)
1269 info_text = element_info[element];
1271 Error(ERR_WARN, "no element description for element %d", element);
1276 static void ScrollMiniLevel(int from_x, int from_y, int scroll)
1279 int dx = (scroll == ED_SCROLL_LEFT ? -1 : scroll == ED_SCROLL_RIGHT ? 1 : 0);
1280 int dy = (scroll == ED_SCROLL_UP ? -1 : scroll == ED_SCROLL_DOWN ? 1 : 0);
1282 BlitBitmap(drawto, drawto,
1283 SX + (dx == -1 ? MINI_TILEX : 0),
1284 SY + (dy == -1 ? MINI_TILEY : 0),
1285 (ed_fieldx * MINI_TILEX) - (dx != 0 ? MINI_TILEX : 0),
1286 (ed_fieldy * MINI_TILEY) - (dy != 0 ? MINI_TILEY : 0),
1287 SX + (dx == +1 ? MINI_TILEX : 0),
1288 SY + (dy == +1 ? MINI_TILEY : 0));
1291 x = (dx == 1 ? 0 : ed_fieldx - 1);
1292 for(y=0; y<ed_fieldy; y++)
1293 DrawMiniElementOrWall(x, y, from_x, from_y);
1297 y = (dy == 1 ? 0 : ed_fieldy - 1);
1298 for(x=0; x<ed_fieldx; x++)
1299 DrawMiniElementOrWall(x, y, from_x, from_y);
1302 redraw_mask |= REDRAW_FIELD;
1306 static void CreateControlButtons()
1308 Bitmap *gd_bitmap = pix[PIX_DOOR];
1309 struct GadgetInfo *gi;
1310 unsigned long event_mask;
1313 /* create toolbox buttons */
1314 for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
1318 int gd_xoffset, gd_yoffset;
1319 int gd_x1, gd_x2, gd_y1, gd_y2;
1321 int radio_button_nr;
1324 if (id == GADGET_ID_SINGLE_ITEMS ||
1325 id == GADGET_ID_CONNECTED_ITEMS ||
1326 id == GADGET_ID_LINE ||
1327 id == GADGET_ID_ARC ||
1328 id == GADGET_ID_TEXT ||
1329 id == GADGET_ID_RECTANGLE ||
1330 id == GADGET_ID_FILLED_BOX ||
1331 id == GADGET_ID_FLOOD_FILL ||
1332 id == GADGET_ID_GRAB_BRUSH ||
1333 id == GADGET_ID_PICK_ELEMENT)
1335 button_type = GD_TYPE_RADIO_BUTTON;
1336 radio_button_nr = RADIO_NR_DRAWING_TOOLBOX;
1337 checked = (id == drawing_function ? TRUE : FALSE);
1338 event_mask = GD_EVENT_PRESSED;
1342 button_type = GD_TYPE_NORMAL_BUTTON;
1343 radio_button_nr = RADIO_NR_NONE;
1346 if (id == GADGET_ID_WRAP_LEFT ||
1347 id == GADGET_ID_WRAP_RIGHT ||
1348 id == GADGET_ID_WRAP_UP ||
1349 id == GADGET_ID_WRAP_DOWN)
1350 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
1352 event_mask = GD_EVENT_RELEASED;
1355 if (id < ED_NUM_CTRL1_BUTTONS)
1357 int x = i % ED_CTRL1_BUTTONS_HORIZ;
1358 int y = i / ED_CTRL1_BUTTONS_HORIZ;
1360 gd_xoffset = ED_CTRL1_BUTTONS_XPOS + x * ED_CTRL1_BUTTON_XSIZE;
1361 gd_yoffset = ED_CTRL1_BUTTONS_YPOS + y * ED_CTRL1_BUTTON_YSIZE;
1362 width = ED_CTRL1_BUTTON_XSIZE;
1363 height = ED_CTRL1_BUTTON_YSIZE;
1367 int x = (i - ED_NUM_CTRL1_BUTTONS) % ED_CTRL2_BUTTONS_HORIZ;
1368 int y = (i - ED_NUM_CTRL1_BUTTONS) / ED_CTRL2_BUTTONS_HORIZ;
1370 gd_xoffset = ED_CTRL2_BUTTONS_XPOS + x * ED_CTRL2_BUTTON_XSIZE;
1371 gd_yoffset = ED_CTRL2_BUTTONS_YPOS + y * ED_CTRL2_BUTTON_YSIZE;
1372 width = ED_CTRL2_BUTTON_XSIZE;
1373 height = ED_CTRL2_BUTTON_YSIZE;
1376 gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
1377 gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
1378 gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_GFX_YPOS + gd_yoffset;
1379 gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
1381 gi = CreateGadget(GDI_CUSTOM_ID, id,
1382 GDI_CUSTOM_TYPE_ID, i,
1383 GDI_INFO_TEXT, control_info[i].text,
1384 GDI_X, EX + gd_xoffset,
1385 GDI_Y, EY + gd_yoffset,
1388 GDI_TYPE, button_type,
1389 GDI_STATE, GD_BUTTON_UNPRESSED,
1390 GDI_RADIO_NR, radio_button_nr,
1391 GDI_CHECKED, checked,
1392 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
1393 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
1394 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
1395 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
1396 GDI_EVENT_MASK, event_mask,
1397 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1398 GDI_CALLBACK_ACTION, HandleControlButtons,
1402 Error(ERR_EXIT, "cannot create gadget");
1404 level_editor_gadget[id] = gi;
1407 /* create buttons for scrolling of drawing area and element list */
1408 for (i=0; i<ED_NUM_SCROLLBUTTONS; i++)
1410 int id = scrollbutton_info[i].gadget_id;
1411 int x, y, width, height;
1412 int gd_x1, gd_x2, gd_y1, gd_y2;
1414 x = scrollbutton_info[i].x;
1415 y = scrollbutton_info[i].y;
1417 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
1419 if (id == GADGET_ID_SCROLL_LIST_UP ||
1420 id == GADGET_ID_SCROLL_LIST_DOWN)
1424 width = ED_SCROLLBUTTON2_XSIZE;
1425 height = ED_SCROLLBUTTON2_YSIZE;
1426 gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].xpos;
1427 gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].ypos;
1428 gd_x2 = gd_x1 - ED_SCROLLBUTTON2_XSIZE;
1435 width = ED_SCROLLBUTTON_XSIZE;
1436 height = ED_SCROLLBUTTON_YSIZE;
1437 gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].xpos;
1438 gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].ypos;
1439 gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
1443 gi = CreateGadget(GDI_CUSTOM_ID, id,
1444 GDI_CUSTOM_TYPE_ID, i,
1445 GDI_INFO_TEXT, scrollbutton_info[i].infotext,
1450 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1451 GDI_STATE, GD_BUTTON_UNPRESSED,
1452 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
1453 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
1454 GDI_EVENT_MASK, event_mask,
1455 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1456 GDI_CALLBACK_ACTION, HandleControlButtons,
1460 Error(ERR_EXIT, "cannot create gadget");
1462 level_editor_gadget[id] = gi;
1465 /* create buttons for element list */
1466 for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
1468 Bitmap *deco_bitmap;
1469 int deco_x, deco_y, deco_xpos, deco_ypos;
1470 int gd_xoffset, gd_yoffset;
1471 int gd_x1, gd_x2, gd_y;
1472 int x = i % ED_ELEMENTLIST_BUTTONS_HORIZ;
1473 int y = i / ED_ELEMENTLIST_BUTTONS_HORIZ;
1474 int id = GADGET_ID_ELEMENTLIST_FIRST + i;
1476 event_mask = GD_EVENT_RELEASED;
1478 gd_xoffset = ED_ELEMENTLIST_XPOS + x * ED_ELEMENTLIST_XSIZE;
1479 gd_yoffset = ED_ELEMENTLIST_YPOS + y * ED_ELEMENTLIST_YSIZE;
1481 gd_x1 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS + ED_ELEMENTLIST_XSIZE;
1482 gd_x2 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS;
1483 gd_y = DOOR_GFX_PAGEY1 + ED_ELEMENTLIST_YPOS;
1485 getMiniGraphicSource(el2gfx(editor_element[i]),
1486 &deco_bitmap, &deco_x, &deco_y);
1487 deco_xpos = (ED_ELEMENTLIST_XSIZE - MINI_TILEX) / 2;
1488 deco_ypos = (ED_ELEMENTLIST_YSIZE - MINI_TILEY) / 2;
1490 gi = CreateGadget(GDI_CUSTOM_ID, id,
1491 GDI_CUSTOM_TYPE_ID, i,
1492 GDI_INFO_TEXT, getElementInfoText(editor_element[i]),
1493 GDI_X, DX + gd_xoffset,
1494 GDI_Y, DY + gd_yoffset,
1495 GDI_WIDTH, ED_ELEMENTLIST_XSIZE,
1496 GDI_HEIGHT, ED_ELEMENTLIST_YSIZE,
1497 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1498 GDI_STATE, GD_BUTTON_UNPRESSED,
1499 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
1500 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
1501 GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
1502 GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
1503 GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY,
1504 GDI_DECORATION_SHIFTING, 1, 1,
1505 GDI_EVENT_MASK, event_mask,
1506 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1507 GDI_CALLBACK_ACTION, HandleControlButtons,
1511 Error(ERR_EXIT, "cannot create gadget");
1513 level_editor_gadget[id] = gi;
1517 static void CreateCounterButtons()
1521 for (i=0; i<ED_NUM_COUNTERBUTTONS; i++)
1524 int xpos = SX + counterbutton_info[i].x; /* xpos of down count button */
1525 int ypos = SY + counterbutton_info[i].y;
1529 Bitmap *gd_bitmap = pix[PIX_DOOR];
1530 struct GadgetInfo *gi;
1532 counterbutton_info[i].gadget_id_down :
1533 counterbutton_info[i].gadget_id_up);
1535 int gd_x, gd_x1, gd_x2, gd_y;
1537 unsigned long event_mask;
1538 char infotext[MAX_INFOTEXT_LEN + 1];
1540 event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
1542 if (i == ED_COUNTER_ID_SELECT_LEVEL)
1545 ED_SCROLLBUTTON_ID_AREA_LEFT :
1546 ED_SCROLLBUTTON_ID_AREA_RIGHT);
1548 event_mask |= GD_EVENT_RELEASED;
1551 xpos += 2 * ED_GADGET_DISTANCE;
1552 ypos += ED_GADGET_DISTANCE;
1554 gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[sid].xpos;
1555 gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
1556 gd_y = DOOR_GFX_PAGEY1 + scrollbutton_info[sid].ypos;
1557 x_size = ED_SCROLLBUTTON_XSIZE;
1558 y_size = ED_SCROLLBUTTON_YSIZE;
1562 gd_xoffset = (j == 0 ? ED_BUTTON_MINUS_XPOS : ED_BUTTON_PLUS_XPOS);
1563 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
1564 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
1565 gd_y = DOOR_GFX_PAGEY1 + ED_BUTTON_COUNT_YPOS;
1566 x_size = ED_BUTTON_COUNT_XSIZE;
1567 y_size = ED_BUTTON_COUNT_YSIZE;
1570 sprintf(infotext, "%s counter value by 1, 5 or 10",
1571 (j == 0 ? "decrease" : "increase"));
1573 gi = CreateGadget(GDI_CUSTOM_ID, id,
1574 GDI_CUSTOM_TYPE_ID, i,
1575 GDI_INFO_TEXT, infotext,
1580 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1581 GDI_STATE, GD_BUTTON_UNPRESSED,
1582 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
1583 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
1584 GDI_EVENT_MASK, event_mask,
1585 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1586 GDI_CALLBACK_ACTION, HandleCounterButtons,
1590 Error(ERR_EXIT, "cannot create gadget");
1592 level_editor_gadget[id] = gi;
1593 xpos += gi->width + ED_GADGET_DISTANCE; /* xpos of text count button */
1597 int font_type = FC_YELLOW;
1598 int gd_width = ED_WIN_COUNT_XSIZE;
1600 id = counterbutton_info[i].gadget_id_text;
1601 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
1603 if (i == ED_COUNTER_ID_SELECT_LEVEL)
1605 font_type = FC_SPECIAL3;
1607 xpos += 2 * ED_GADGET_DISTANCE;
1608 ypos -= ED_GADGET_DISTANCE;
1610 gd_x = DOOR_GFX_PAGEX6 + ED_WIN_COUNT2_XPOS;
1611 gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT2_YPOS;
1612 gd_width = ED_WIN_COUNT2_XSIZE;
1616 gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
1617 gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
1620 gi = CreateGadget(GDI_CUSTOM_ID, id,
1621 GDI_CUSTOM_TYPE_ID, i,
1622 GDI_INFO_TEXT, "enter counter value",
1625 GDI_TYPE, GD_TYPE_TEXTINPUT_NUMERIC,
1626 GDI_NUMBER_VALUE, 0,
1627 GDI_NUMBER_MIN, counterbutton_info[i].min_value,
1628 GDI_NUMBER_MAX, counterbutton_info[i].max_value,
1630 GDI_TEXT_FONT, font_type,
1631 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
1632 GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
1633 GDI_BORDER_SIZE, ED_BORDER_SIZE,
1634 GDI_TEXTINPUT_DESIGN_WIDTH, gd_width,
1635 GDI_EVENT_MASK, event_mask,
1636 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1637 GDI_CALLBACK_ACTION, HandleCounterButtons,
1641 Error(ERR_EXIT, "cannot create gadget");
1643 level_editor_gadget[id] = gi;
1644 xpos += gi->width + ED_GADGET_DISTANCE; /* xpos of up count button */
1650 static void CreateDrawingAreas()
1652 struct GadgetInfo *gi;
1653 unsigned long event_mask;
1658 GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING |
1659 GD_EVENT_OFF_BORDERS;
1661 /* one for the level drawing area ... */
1662 id = GADGET_ID_DRAWING_LEVEL;
1663 gi = CreateGadget(GDI_CUSTOM_ID, id,
1666 GDI_TYPE, GD_TYPE_DRAWING_AREA,
1667 GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
1668 GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
1669 GDI_EVENT_MASK, event_mask,
1670 GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
1671 GDI_CALLBACK_ACTION, HandleDrawingAreas,
1675 Error(ERR_EXIT, "cannot create gadget");
1677 level_editor_gadget[id] = gi;
1679 /* ... up to eight areas for element content ... */
1680 for (i=0; i<MAX_ELEMENT_CONTENTS; i++)
1682 int gx = SX + ED_AREA_ELEM_CONTENT_XPOS + 5 * (i % 4) * MINI_TILEX;
1683 int gy = SX + ED_AREA_ELEM_CONTENT_YPOS + 6 * (i / 4) * MINI_TILEY;
1685 id = GADGET_ID_ELEM_CONTENT_0 + i;
1686 gi = CreateGadget(GDI_CUSTOM_ID, id,
1687 GDI_CUSTOM_TYPE_ID, i,
1690 GDI_WIDTH, 3 * MINI_TILEX,
1691 GDI_HEIGHT, 3 * MINI_TILEY,
1692 GDI_TYPE, GD_TYPE_DRAWING_AREA,
1693 GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
1694 GDI_EVENT_MASK, event_mask,
1695 GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
1696 GDI_CALLBACK_ACTION, HandleDrawingAreas,
1700 Error(ERR_EXIT, "cannot create gadget");
1702 level_editor_gadget[id] = gi;
1705 /* ... one for the amoeba content */
1706 id = GADGET_ID_AMOEBA_CONTENT;
1707 gi = CreateGadget(GDI_CUSTOM_ID, id,
1708 GDI_X, SX + ED_AREA_ELEM_CONTENT_XPOS,
1709 GDI_Y, SY + ED_AREA_ELEM_CONTENT_YPOS,
1710 GDI_WIDTH, MINI_TILEX,
1711 GDI_HEIGHT, MINI_TILEY,
1712 GDI_TYPE, GD_TYPE_DRAWING_AREA,
1713 GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
1714 GDI_EVENT_MASK, event_mask,
1715 GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
1716 GDI_CALLBACK_ACTION, HandleDrawingAreas,
1720 Error(ERR_EXIT, "cannot create gadget");
1722 level_editor_gadget[id] = gi;
1724 /* ... and one for random placement background restrictions */
1726 id = GADGET_ID_RANDOM_BACKGROUND;
1727 gi = CreateGadget(GDI_CUSTOM_ID, id,
1728 GDI_X, SX + ED_AREA_RANDOM_BACKGROUND_XPOS,
1729 GDI_Y, SY + ED_AREA_RANDOM_BACKGROUND_YPOS,
1730 GDI_WIDTH, MINI_TILEX,
1731 GDI_HEIGHT, MINI_TILEY,
1732 GDI_TYPE, GD_TYPE_DRAWING_AREA,
1733 GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
1734 GDI_EVENT_MASK, event_mask,
1735 GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
1736 GDI_CALLBACK_ACTION, HandleDrawingAreas,
1740 Error(ERR_EXIT, "cannot create gadget");
1742 level_editor_gadget[id] = gi;
1745 static void CreateTextInputGadgets()
1749 for (i=0; i<ED_NUM_TEXTINPUT; i++)
1751 Bitmap *gd_bitmap = pix[PIX_DOOR];
1753 struct GadgetInfo *gi;
1754 unsigned long event_mask;
1755 char infotext[1024];
1756 int id = textinput_info[i].gadget_id;
1758 event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
1760 gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
1761 gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
1763 sprintf(infotext, "Enter %s", textinput_info[i].infotext);
1764 infotext[MAX_INFOTEXT_LEN] = '\0';
1766 gi = CreateGadget(GDI_CUSTOM_ID, id,
1767 GDI_CUSTOM_TYPE_ID, i,
1768 GDI_INFO_TEXT, infotext,
1769 GDI_X, SX + textinput_info[i].x,
1770 GDI_Y, SY + textinput_info[i].y,
1771 GDI_TYPE, GD_TYPE_TEXTINPUT_ALPHANUMERIC,
1772 GDI_TEXT_VALUE, textinput_info[i].value,
1773 GDI_TEXT_SIZE, textinput_info[i].size,
1774 GDI_TEXT_FONT, FC_YELLOW,
1775 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x, gd_y,
1776 GDI_DESIGN_PRESSED, gd_bitmap, gd_x, gd_y,
1777 GDI_BORDER_SIZE, ED_BORDER_SIZE,
1778 GDI_TEXTINPUT_DESIGN_WIDTH, ED_WIN_COUNT_XSIZE,
1779 GDI_EVENT_MASK, event_mask,
1780 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1781 GDI_CALLBACK_ACTION, HandleTextInputGadgets,
1785 Error(ERR_EXIT, "cannot create gadget");
1787 level_editor_gadget[id] = gi;
1791 static void CreateScrollbarGadgets()
1795 for (i=0; i<ED_NUM_SCROLLBARS; i++)
1797 int id = scrollbar_info[i].gadget_id;
1798 Bitmap *gd_bitmap = pix[PIX_DOOR];
1799 int gd_x1, gd_x2, gd_y1, gd_y2;
1800 struct GadgetInfo *gi;
1801 int items_max, items_visible, item_position;
1802 unsigned long event_mask;
1804 if (i == ED_SCROLLBAR_ID_LIST_VERTICAL)
1806 items_max = elements_in_list / ED_ELEMENTLIST_BUTTONS_HORIZ;
1807 items_visible = ED_ELEMENTLIST_BUTTONS_VERT;
1810 else /* drawing area scrollbars */
1812 if (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL)
1814 items_max = MAX(lev_fieldx + 2, ed_fieldx);
1815 items_visible = ed_fieldx;
1820 items_max = MAX(lev_fieldy + 2, ed_fieldy);
1821 items_visible = ed_fieldy;
1826 event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
1828 gd_x1 = DOOR_GFX_PAGEX8 + scrollbar_info[i].xpos;
1829 gd_x2 = (gd_x1 - (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL ?
1830 scrollbar_info[i].height : scrollbar_info[i].width));
1831 gd_y1 = DOOR_GFX_PAGEY1 + scrollbar_info[i].ypos;
1832 gd_y2 = DOOR_GFX_PAGEY1 + scrollbar_info[i].ypos;
1834 gi = CreateGadget(GDI_CUSTOM_ID, id,
1835 GDI_CUSTOM_TYPE_ID, i,
1836 GDI_INFO_TEXT, scrollbar_info[i].infotext,
1837 GDI_X, scrollbar_info[i].x,
1838 GDI_Y, scrollbar_info[i].y,
1839 GDI_WIDTH, scrollbar_info[i].width,
1840 GDI_HEIGHT, scrollbar_info[i].height,
1841 GDI_TYPE, scrollbar_info[i].type,
1842 GDI_SCROLLBAR_ITEMS_MAX, items_max,
1843 GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
1844 GDI_SCROLLBAR_ITEM_POSITION, item_position,
1845 GDI_STATE, GD_BUTTON_UNPRESSED,
1846 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
1847 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
1848 GDI_BORDER_SIZE, ED_BORDER_SIZE,
1849 GDI_EVENT_MASK, event_mask,
1850 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1851 GDI_CALLBACK_ACTION, HandleControlButtons,
1855 Error(ERR_EXIT, "cannot create gadget");
1857 level_editor_gadget[id] = gi;
1861 static void CreateCheckbuttonGadgets()
1863 Bitmap *gd_bitmap = pix[PIX_DOOR];
1864 struct GadgetInfo *gi;
1865 unsigned long event_mask;
1866 int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
1870 event_mask = GD_EVENT_PRESSED;
1872 gd_x1 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_UNCHECKED_XPOS;
1873 gd_x2 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_UNCHECKED_XPOS;
1874 gd_x3 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_CHECKED_XPOS;
1875 gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
1876 gd_y = DOOR_GFX_PAGEY1 + ED_RADIOBUTTON_YPOS;
1878 for (i=0; i<ED_NUM_RADIOBUTTONS; i++)
1880 int id = radiobutton_info[i].gadget_id;
1883 (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
1885 gi = CreateGadget(GDI_CUSTOM_ID, id,
1886 GDI_CUSTOM_TYPE_ID, i,
1887 GDI_INFO_TEXT, radiobutton_info[i].infotext,
1888 GDI_X, SX + radiobutton_info[i].x,
1889 GDI_Y, SY + radiobutton_info[i].y,
1890 GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
1891 GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
1892 GDI_TYPE, GD_TYPE_RADIO_BUTTON,
1893 GDI_RADIO_NR, radiobutton_info[i].radio_button_nr,
1894 GDI_CHECKED, checked,
1895 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
1896 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
1897 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x3, gd_y,
1898 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x4, gd_y,
1899 GDI_EVENT_MASK, event_mask,
1900 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1901 GDI_CALLBACK_ACTION, HandleRadiobuttons,
1905 Error(ERR_EXIT, "cannot create gadget");
1907 level_editor_gadget[id] = gi;
1910 for (i=0; i<ED_NUM_CHECKBUTTONS; i++)
1912 int id = checkbutton_info[i].gadget_id;
1914 if (id == GADGET_ID_STICK_ELEMENT)
1915 gd_y = DOOR_GFX_PAGEY1 + ED_STICKYBUTTON_YPOS;
1917 gd_y = DOOR_GFX_PAGEY1 + ED_CHECKBUTTON_YPOS;
1919 gi = CreateGadget(GDI_CUSTOM_ID, id,
1920 GDI_CUSTOM_TYPE_ID, i,
1921 GDI_INFO_TEXT, checkbutton_info[i].infotext,
1922 GDI_X, SX + checkbutton_info[i].x,
1923 GDI_Y, SY + checkbutton_info[i].y,
1924 GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
1925 GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
1926 GDI_TYPE, GD_TYPE_CHECK_BUTTON,
1927 GDI_CHECKED, *checkbutton_info[i].value,
1928 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
1929 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
1930 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x3, gd_y,
1931 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x4, gd_y,
1932 GDI_EVENT_MASK, event_mask,
1933 GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
1934 GDI_CALLBACK_ACTION, HandleCheckbuttons,
1938 Error(ERR_EXIT, "cannot create gadget");
1940 level_editor_gadget[id] = gi;
1944 void CreateLevelEditorGadgets()
1946 CreateControlButtons();
1947 CreateCounterButtons();
1948 CreateDrawingAreas();
1949 CreateTextInputGadgets();
1950 CreateScrollbarGadgets();
1951 CreateCheckbuttonGadgets();
1954 static void MapCounterButtons(int id)
1956 MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_down]);
1957 MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_text]);
1958 MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_up]);
1961 static void MapControlButtons()
1966 /* map toolbox buttons */
1967 for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
1968 MapGadget(level_editor_gadget[i]);
1970 /* map buttons to select elements */
1971 for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
1972 MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
1973 MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
1974 MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
1975 MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
1977 /* map buttons to select level */
1978 counter_id = ED_COUNTER_ID_SELECT_LEVEL;
1979 ModifyEditorCounterLimits(counter_id,
1980 leveldir_current->first_level,
1981 leveldir_current->last_level);
1982 ModifyEditorCounter(counter_id, *counterbutton_info[counter_id].value);
1983 MapCounterButtons(counter_id);
1986 static void MapDrawingArea(int id)
1988 MapGadget(level_editor_gadget[id]);
1991 static void MapTextInputGadget(int id)
1993 MapGadget(level_editor_gadget[textinput_info[id].gadget_id]);
1996 static void MapRadiobuttonGadget(int id)
1998 MapGadget(level_editor_gadget[radiobutton_info[id].gadget_id]);
2001 static void MapCheckbuttonGadget(int id)
2003 MapGadget(level_editor_gadget[checkbutton_info[id].gadget_id]);
2006 static void MapMainDrawingArea()
2008 boolean no_horizontal_scrollbar = (lev_fieldx + 2 <= ed_fieldx);
2009 boolean no_vertical_scrollbar = (lev_fieldy + 2 <= ed_fieldy);
2012 for (i=ED_SCROLLBUTTON_ID_AREA_FIRST; i<=ED_SCROLLBUTTON_ID_AREA_LAST; i++)
2014 if (((i == ED_SCROLLBUTTON_ID_AREA_LEFT ||
2015 i == ED_SCROLLBUTTON_ID_AREA_RIGHT) &&
2016 no_horizontal_scrollbar) ||
2017 ((i == ED_SCROLLBUTTON_ID_AREA_UP ||
2018 i == ED_SCROLLBUTTON_ID_AREA_DOWN) &&
2019 no_vertical_scrollbar))
2022 MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
2025 for (i=ED_SCROLLBAR_ID_AREA_FIRST; i<=ED_SCROLLBAR_ID_AREA_LAST; i++)
2027 if ((i == ED_SCROLLBAR_ID_AREA_HORIZONTAL && no_horizontal_scrollbar) ||
2028 (i == ED_SCROLLBAR_ID_AREA_VERTICAL && no_vertical_scrollbar))
2031 MapGadget(level_editor_gadget[scrollbar_info[i].gadget_id]);
2034 MapDrawingArea(GADGET_ID_DRAWING_LEVEL);
2037 static void UnmapDrawingArea(int id)
2039 UnmapGadget(level_editor_gadget[id]);
2042 void UnmapLevelEditorWindowGadgets()
2046 for (i=0; i<NUM_EDITOR_GADGETS; i++)
2047 if (level_editor_gadget[i]->x < SX + SXSIZE)
2048 UnmapGadget(level_editor_gadget[i]);
2051 void UnmapLevelEditorGadgets()
2055 for (i=0; i<NUM_EDITOR_GADGETS; i++)
2056 UnmapGadget(level_editor_gadget[i]);
2059 static void ResetUndoBuffer()
2061 undo_buffer_position = -1;
2062 undo_buffer_steps = -1;
2063 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
2066 static void DrawEditModeWindow()
2068 if (edit_mode == ED_MODE_INFO)
2069 DrawLevelInfoWindow();
2070 else if (edit_mode == ED_MODE_PROPERTIES)
2071 DrawPropertiesWindow();
2072 else /* edit_mode == ED_MODE_DRAWING */
2073 DrawDrawingWindow();
2076 static boolean LevelChanged()
2078 boolean level_changed = FALSE;
2081 for(y=0; y<lev_fieldy; y++)
2082 for(x=0; x<lev_fieldx; x++)
2083 if (Feld[x][y] != Ur[x][y])
2084 level_changed = TRUE;
2086 return level_changed;
2089 static boolean LevelContainsPlayer()
2091 boolean player_found = FALSE;
2094 for(y=0; y<lev_fieldy; y++)
2095 for(x=0; x<lev_fieldx; x++)
2096 if (Feld[x][y] == EL_SPIELFIGUR ||
2097 Feld[x][y] == EL_SPIELER1 ||
2098 Feld[x][y] == EL_SP_MURPHY)
2099 player_found = TRUE;
2101 return player_found;
2106 CloseDoor(DOOR_CLOSE_ALL);
2107 OpenDoor(DOOR_OPEN_2 | DOOR_NO_DELAY);
2109 if (level_editor_test_game)
2113 for(x=0; x<lev_fieldx; x++)
2114 for(y=0; y<lev_fieldy; y++)
2115 Feld[x][y] = Ur[x][y];
2117 for(x=0; x<lev_fieldx; x++)
2118 for(y=0; y<lev_fieldy; y++)
2119 Ur[x][y] = FieldBackup[x][y];
2121 level_editor_test_game = FALSE;
2125 edit_mode = ED_MODE_DRAWING;
2132 /* copy default editor door content to main double buffer */
2133 BlitBitmap(pix[PIX_DOOR], drawto,
2134 DOOR_GFX_PAGEX6, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2136 /* draw mouse button brush elements */
2137 DrawMiniGraphicExt(drawto,
2138 DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS,
2139 el2gfx(new_element1));
2140 DrawMiniGraphicExt(drawto,
2141 DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS,
2142 el2gfx(new_element2));
2143 DrawMiniGraphicExt(drawto,
2144 DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS,
2145 el2gfx(new_element3));
2147 /* draw bigger door */
2148 DrawSpecialEditorDoor();
2150 /* draw new control window */
2151 BlitBitmap(pix[PIX_DOOR], drawto,
2152 DOOR_GFX_PAGEX8, 236, EXSIZE, EYSIZE, EX, EY);
2154 redraw_mask |= REDRAW_ALL;
2156 MapControlButtons();
2158 /* copy actual editor door content to door double buffer for OpenDoor() */
2159 BlitBitmap(drawto, pix[PIX_DB_DOOR],
2160 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2162 DrawEditModeWindow();
2169 OpenDoor(DOOR_OPEN_1);
2172 OpenDoor(DOOR_OPEN_1 | DOOR_OPEN_2);
2176 static void AdjustDrawingAreaGadgets()
2178 int ed_xsize = lev_fieldx + 2;
2179 int ed_ysize = lev_fieldy + 2;
2180 int max_ed_fieldx = MAX_ED_FIELDX;
2181 int max_ed_fieldy = MAX_ED_FIELDY;
2182 boolean horizontal_scrollbar_needed;
2183 boolean vertical_scrollbar_needed;
2184 int x, y, width, height;
2185 int xoffset, yoffset;
2187 /* check if we need any scrollbars */
2188 horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
2189 vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
2191 /* check if we have a smaller editor field because of scrollbars */
2192 if (horizontal_scrollbar_needed)
2193 max_ed_fieldy = MAX_ED_FIELDY - 1;
2194 if (vertical_scrollbar_needed)
2195 max_ed_fieldx = MAX_ED_FIELDX - 1;
2197 /* check again if we now need more scrollbars because of less space */
2198 horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
2199 vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
2201 /* check if editor field gets even smaller after adding new scrollbars */
2202 if (horizontal_scrollbar_needed)
2203 max_ed_fieldy = MAX_ED_FIELDY - 1;
2204 if (vertical_scrollbar_needed)
2205 max_ed_fieldx = MAX_ED_FIELDX - 1;
2207 ed_fieldx = (ed_xsize < MAX_ED_FIELDX ? ed_xsize : max_ed_fieldx);
2208 ed_fieldy = (ed_ysize < MAX_ED_FIELDY ? ed_ysize : max_ed_fieldy);
2210 ModifyGadget(level_editor_gadget[GADGET_ID_DRAWING_LEVEL],
2211 GDI_WIDTH, ed_fieldx * MINI_TILEX,
2212 GDI_HEIGHT, ed_fieldy * MINI_TILEY,
2213 GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
2216 xoffset = (ed_fieldx == MAX_ED_FIELDX ? ED_SCROLLBUTTON_XSIZE : 0);
2217 yoffset = (ed_fieldy == MAX_ED_FIELDY ? ED_SCROLLBUTTON_YSIZE : 0);
2219 x = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset;
2220 y = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset;
2222 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT], GDI_X, x, GDI_END);
2223 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN], GDI_Y, y, GDI_END);
2225 width = scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset;
2226 height = scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset;
2228 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
2230 GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldx,
2232 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
2234 GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldy,
2238 static void AdjustLevelScrollPosition()
2240 if (level_xpos < -1)
2242 if (level_xpos > lev_fieldx - ed_fieldx + 1)
2243 level_xpos = lev_fieldx - ed_fieldx + 1;
2244 if (lev_fieldx < ed_fieldx - 2)
2247 if (level_ypos < -1)
2249 if (level_ypos > lev_fieldy - ed_fieldy + 1)
2250 level_ypos = lev_fieldy - ed_fieldy + 1;
2251 if (lev_fieldy < ed_fieldy - 2)
2255 static void AdjustEditorScrollbar(int id)
2257 struct GadgetInfo *gi = level_editor_gadget[id];
2258 int items_max, items_visible, item_position;
2260 if (id == GADGET_ID_SCROLL_HORIZONTAL)
2262 items_max = MAX(lev_fieldx + 2, ed_fieldx);
2263 items_visible = ed_fieldx;
2264 item_position = level_xpos + 1;
2268 items_max = MAX(lev_fieldy + 2, ed_fieldy);
2269 items_visible = ed_fieldy;
2270 item_position = level_ypos + 1;
2273 if (item_position > items_max - items_visible)
2274 item_position = items_max - items_visible;
2276 ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
2277 GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
2280 static void ModifyEditorTextInput(int textinput_id, char *new_text)
2282 int gadget_id = textinput_info[textinput_id].gadget_id;
2283 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
2285 ModifyGadget(gi, GDI_TEXT_VALUE, new_text, GDI_END);
2288 static void ModifyEditorCounter(int counter_id, int new_value)
2290 int *counter_value = counterbutton_info[counter_id].value;
2291 int gadget_id = counterbutton_info[counter_id].gadget_id_text;
2292 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
2294 ModifyGadget(gi, GDI_NUMBER_VALUE, new_value, GDI_END);
2296 if (counter_value != NULL)
2297 *counter_value = gi->text.number_value;
2300 static void ModifyEditorCounterLimits(int counter_id, int min, int max)
2302 int gadget_id = counterbutton_info[counter_id].gadget_id_text;
2303 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
2305 ModifyGadget(gi, GDI_NUMBER_MIN, min, GDI_NUMBER_MAX, max, GDI_END);
2308 static void PickDrawingElement(int button, int element)
2310 if (button < 1 || button > 3)
2315 new_element1 = element;
2316 DrawMiniGraphicExt(drawto,
2317 DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS,
2318 el2gfx(new_element1));
2320 else if (button == 2)
2322 new_element2 = element;
2323 DrawMiniGraphicExt(drawto,
2324 DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS,
2325 el2gfx(new_element2));
2329 new_element3 = element;
2330 DrawMiniGraphicExt(drawto,
2331 DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS,
2332 el2gfx(new_element3));
2335 redraw_mask |= REDRAW_DOOR_1;
2338 static void DrawDrawingWindow()
2341 UnmapLevelEditorWindowGadgets();
2342 AdjustDrawingAreaGadgets();
2343 AdjustLevelScrollPosition();
2344 AdjustEditorScrollbar(GADGET_ID_SCROLL_HORIZONTAL);
2345 AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
2346 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
2347 MapMainDrawingArea();
2350 static void DrawRandomPlacementBackgroundArea()
2352 int area_x = ED_AREA_RANDOM_BACKGROUND_XPOS / MINI_TILEX;
2353 int area_y = ED_AREA_RANDOM_BACKGROUND_YPOS / MINI_TILEY;
2354 int area_sx = SX + ED_AREA_RANDOM_BACKGROUND_XPOS;
2355 int area_sy = SY + ED_AREA_RANDOM_BACKGROUND_YPOS;
2358 ElementContent[0][0][0] = random_placement_background_element;
2360 /* draw decorative border for the object */
2363 DrawMiniElement(area_x + x, area_y + y, EL_ERDREICH);
2365 ClearRectangle(drawto,
2366 area_sx + MINI_TILEX/2 - 1, area_sy + MINI_TILEY/2 - 1,
2367 MINI_TILEX + 2, MINI_TILEY + 2);
2369 /* copy border to the right location */
2370 BlitBitmap(drawto, drawto,
2371 area_sx, area_sy, 3 * MINI_TILEX, 3 * MINI_TILEY,
2372 area_sx - MINI_TILEX/2, area_sy - MINI_TILEY/2);
2374 DrawMiniElement(area_x, area_y, ElementContent[0][0][0]);
2376 MapDrawingArea(GADGET_ID_RANDOM_BACKGROUND);
2379 static void DrawLevelInfoWindow()
2381 char infotext[1024];
2382 int xoffset_above = 0;
2383 int yoffset_above = -(MINI_TILEX + ED_GADGET_DISTANCE);
2384 int xoffset_right = counter_xsize;
2385 int yoffset_right = ED_BORDER_SIZE;
2386 int xoffset_right2 = ED_CHECKBUTTON_XSIZE + 2 * ED_GADGET_DISTANCE;
2387 int yoffset_right2 = ED_BORDER_SIZE;
2388 int font_color = FC_GREEN;
2392 UnmapLevelEditorWindowGadgets();
2394 DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS_YPOS,
2395 "Level Settings", FS_BIG, FC_YELLOW);
2396 DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS2_YPOS,
2397 "Editor Settings", FS_BIG, FC_YELLOW);
2399 /* draw counter gadgets */
2400 for (i=ED_COUNTER_ID_LEVEL_FIRST; i<=ED_COUNTER_ID_LEVEL_LAST; i++)
2402 if (counterbutton_info[i].infotext_above)
2404 x = counterbutton_info[i].x + xoffset_above;
2405 y = counterbutton_info[i].y + yoffset_above;
2407 sprintf(infotext, "%s:", counterbutton_info[i].infotext_above);
2408 infotext[MAX_INFOTEXT_LEN] = '\0';
2409 DrawTextF(x, y, font_color, infotext);
2412 if (counterbutton_info[i].infotext_right)
2414 x = counterbutton_info[i].x + xoffset_right;
2415 y = counterbutton_info[i].y + yoffset_right;
2417 sprintf(infotext, "%s", counterbutton_info[i].infotext_right);
2418 infotext[MAX_INFOTEXT_LEN] = '\0';
2419 DrawTextF(x, y, font_color, infotext);
2422 ModifyEditorCounter(i, *counterbutton_info[i].value);
2423 MapCounterButtons(i);
2426 /* draw text input gadgets */
2427 for (i=ED_TEXTINPUT_ID_LEVEL_FIRST; i<=ED_TEXTINPUT_ID_LEVEL_LAST; i++)
2429 x = textinput_info[i].x + xoffset_above;
2430 y = textinput_info[i].y + yoffset_above;
2432 sprintf(infotext, "%s:", textinput_info[i].infotext);
2433 infotext[MAX_INFOTEXT_LEN] = '\0';
2435 DrawTextF(x, y, font_color, infotext);
2436 ModifyEditorTextInput(i, textinput_info[i].value);
2437 MapTextInputGadget(i);
2440 /* draw radiobutton gadgets */
2441 for (i=ED_RADIOBUTTON_ID_LEVEL_FIRST; i<=ED_RADIOBUTTON_ID_LEVEL_LAST; i++)
2444 (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
2446 x = radiobutton_info[i].x + xoffset_right2;
2447 y = radiobutton_info[i].y + yoffset_right2;
2449 DrawTextF(x, y, font_color, radiobutton_info[i].text);
2450 ModifyGadget(level_editor_gadget[radiobutton_info[i].gadget_id],
2451 GDI_CHECKED, checked, GDI_END);
2452 MapRadiobuttonGadget(i);
2455 /* draw checkbutton gadgets */
2456 for (i=ED_CHECKBUTTON_ID_LEVEL_FIRST; i<=ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
2458 x = checkbutton_info[i].x + xoffset_right2;
2459 y = checkbutton_info[i].y + yoffset_right2;
2461 DrawTextF(x, y, font_color, checkbutton_info[i].text);
2462 ModifyGadget(level_editor_gadget[checkbutton_info[i].gadget_id],
2463 GDI_CHECKED, *checkbutton_info[i].value, GDI_END);
2464 MapCheckbuttonGadget(i);
2467 /* draw drawing area */
2468 DrawRandomPlacementBackgroundArea();
2471 static void DrawAmoebaContentArea()
2473 int area_x = ED_AREA_ELEM_CONTENT_XPOS / MINI_TILEX;
2474 int area_y = ED_AREA_ELEM_CONTENT_YPOS / MINI_TILEY;
2475 int area_sx = SX + ED_AREA_ELEM_CONTENT_XPOS;
2476 int area_sy = SY + ED_AREA_ELEM_CONTENT_YPOS;
2477 int font_color = FC_GREEN;
2480 ElementContent[0][0][0] = level.amoeba_content;
2482 /* draw decorative border for the object */
2485 DrawMiniElement(area_x + x, area_y + y, EL_ERDREICH);
2487 ClearRectangle(drawto,
2488 area_sx + MINI_TILEX/2 - 1, area_sy + MINI_TILEY/2 - 1,
2489 MINI_TILEX + 2, MINI_TILEY + 2);
2491 /* copy border to the right location */
2492 BlitBitmap(drawto, drawto,
2493 area_sx, area_sy, 3 * MINI_TILEX, 3 * MINI_TILEY,
2494 area_sx - MINI_TILEX/2, area_sy - MINI_TILEY/2);
2496 DrawText(area_sx + TILEX, area_sy + 1, "Content of amoeba",
2497 FS_SMALL, font_color);
2499 DrawMiniElement(area_x, area_y, ElementContent[0][0][0]);
2501 MapDrawingArea(GADGET_ID_AMOEBA_CONTENT);
2504 static void DrawElementContentAreas()
2506 int counter_id = ED_COUNTER_ID_ELEM_CONTENT;
2507 int area_x = ED_AREA_ELEM_CONTENT_XPOS / MINI_TILEX;
2508 int area_y = ED_AREA_ELEM_CONTENT_YPOS / MINI_TILEY;
2509 int area_sx = SX + ED_AREA_ELEM_CONTENT_XPOS;
2510 int area_sy = SY + ED_AREA_ELEM_CONTENT_YPOS;
2511 int xoffset_right = counter_xsize;
2512 int yoffset_right = ED_BORDER_SIZE;
2513 int font_color = FC_GREEN;
2516 for (i=0; i<MAX_ELEMENT_CONTENTS; i++)
2519 ElementContent[i][x][y] = level.yam_content[i][x][y];
2521 for (i=0; i<MAX_ELEMENT_CONTENTS; i++)
2522 UnmapDrawingArea(GADGET_ID_ELEM_CONTENT_0 + i);
2524 /* display counter to choose number of element content areas */
2525 x = counterbutton_info[counter_id].x + xoffset_right;
2526 y = counterbutton_info[counter_id].y + yoffset_right;
2527 DrawTextF(x, y, font_color, "number of content areas");
2529 ModifyEditorCounter(counter_id, *counterbutton_info[counter_id].value);
2530 MapCounterButtons(counter_id);
2532 /* delete content areas in case of reducing number of them */
2533 ClearRectangle(backbuffer,
2534 SX, area_sy - MINI_TILEX,
2535 SXSIZE, 12 * MINI_TILEY);
2537 /* draw some decorative border for the objects */
2538 for (i=0; i<level.num_yam_contents; i++)
2542 DrawMiniElement(area_x + 5 * (i % 4) + x, area_y + 6 * (i / 4) + y,
2545 ClearRectangle(drawto,
2546 area_sx + 5 * (i % 4) * MINI_TILEX + MINI_TILEX/2 - 1,
2547 area_sy + 6 * (i / 4) * MINI_TILEY + MINI_TILEY/2 - 1,
2548 3 * MINI_TILEX + 2, 3 * MINI_TILEY + 2);
2551 /* copy border to the right location */
2552 BlitBitmap(drawto, drawto,
2553 area_sx, area_sy, (5 * 4 + 1) * MINI_TILEX, 11 * MINI_TILEY,
2554 area_sx - MINI_TILEX/2, area_sy - MINI_TILEY/2);
2556 DrawText(area_sx + (5 * 4 - 1) * MINI_TILEX, area_sy + 0 * MINI_TILEY + 1,
2557 "Content", FS_SMALL, font_color);
2558 DrawText(area_sx + (5 * 4 - 1) * MINI_TILEX, area_sy + 1 * MINI_TILEY + 1,
2559 "when", FS_SMALL, font_color);
2560 DrawText(area_sx + (5 * 4 - 1) * MINI_TILEX, area_sy + 2 * MINI_TILEY + 1,
2561 "smashed", FS_SMALL, font_color);
2563 for (i=0; i<level.num_yam_contents; i++)
2567 DrawMiniElement(area_x + 5 * (i % 4) + x, area_y + 6 * (i / 4) + y,
2568 ElementContent[i][x][y]);
2570 DrawTextF(area_sx - SX + 5 * (i % 4) * MINI_TILEX + MINI_TILEX + 1,
2571 area_sy - SY + 6 * (i / 4) * MINI_TILEY + 4 * MINI_TILEY - 4,
2572 font_color, "%d", i + 1);
2575 for (i=0; i<level.num_yam_contents; i++)
2576 MapDrawingArea(GADGET_ID_ELEM_CONTENT_0 + i);
2579 #define TEXT_COLLECTING "Score for collecting"
2580 #define TEXT_SMASHING "Score for smashing"
2581 #define TEXT_CRACKING "Score for cracking"
2582 #define TEXT_SPEED "Speed of amoeba growth"
2583 #define TEXT_DURATION "Duration when activated"
2585 static void DrawPropertiesWindow()
2587 int counter_id = ED_COUNTER_ID_ELEM_SCORE;
2588 int num_elements_in_level;
2590 int xoffset_right = counter_xsize;
2591 int yoffset_right = ED_BORDER_SIZE;
2592 int xoffset_right2 = ED_CHECKBUTTON_XSIZE + 2 * ED_GADGET_DISTANCE;
2593 int yoffset_right2 = ED_BORDER_SIZE;
2596 int font_color = FC_GREEN;
2603 } elements_with_counter[] =
2605 { EL_EDELSTEIN, &level.score[SC_EDELSTEIN], TEXT_COLLECTING },
2606 { EL_EDELSTEIN_BD, &level.score[SC_EDELSTEIN], TEXT_COLLECTING },
2607 { EL_EDELSTEIN_GELB,&level.score[SC_EDELSTEIN], TEXT_COLLECTING },
2608 { EL_EDELSTEIN_ROT, &level.score[SC_EDELSTEIN], TEXT_COLLECTING },
2609 { EL_EDELSTEIN_LILA,&level.score[SC_EDELSTEIN], TEXT_COLLECTING },
2610 { EL_DIAMANT, &level.score[SC_DIAMANT], TEXT_COLLECTING },
2611 { EL_KAEFER_RIGHT, &level.score[SC_KAEFER], TEXT_SMASHING },
2612 { EL_KAEFER_UP, &level.score[SC_KAEFER], TEXT_SMASHING },
2613 { EL_KAEFER_LEFT, &level.score[SC_KAEFER], TEXT_SMASHING },
2614 { EL_KAEFER_DOWN, &level.score[SC_KAEFER], TEXT_SMASHING },
2615 { EL_BUTTERFLY_RIGHT,&level.score[SC_KAEFER], TEXT_SMASHING },
2616 { EL_BUTTERFLY_UP, &level.score[SC_KAEFER], TEXT_SMASHING },
2617 { EL_BUTTERFLY_LEFT,&level.score[SC_KAEFER], TEXT_SMASHING },
2618 { EL_BUTTERFLY_DOWN,&level.score[SC_KAEFER], TEXT_SMASHING },
2619 { EL_FLIEGER_RIGHT, &level.score[SC_FLIEGER], TEXT_SMASHING },
2620 { EL_FLIEGER_UP, &level.score[SC_FLIEGER], TEXT_SMASHING },
2621 { EL_FLIEGER_LEFT, &level.score[SC_FLIEGER], TEXT_SMASHING },
2622 { EL_FLIEGER_DOWN, &level.score[SC_FLIEGER], TEXT_SMASHING },
2623 { EL_FIREFLY_RIGHT, &level.score[SC_FLIEGER], TEXT_SMASHING },
2624 { EL_FIREFLY_UP, &level.score[SC_FLIEGER], TEXT_SMASHING },
2625 { EL_FIREFLY_LEFT, &level.score[SC_FLIEGER], TEXT_SMASHING },
2626 { EL_FIREFLY_DOWN, &level.score[SC_FLIEGER], TEXT_SMASHING },
2627 { EL_MAMPFER, &level.score[SC_MAMPFER], TEXT_SMASHING },
2628 { EL_MAMPFER2, &level.score[SC_MAMPFER], TEXT_SMASHING },
2629 { EL_ROBOT, &level.score[SC_ROBOT], TEXT_SMASHING },
2630 { EL_PACMAN_RIGHT, &level.score[SC_PACMAN], TEXT_SMASHING },
2631 { EL_PACMAN_UP, &level.score[SC_PACMAN], TEXT_SMASHING },
2632 { EL_PACMAN_LEFT, &level.score[SC_PACMAN], TEXT_SMASHING },
2633 { EL_PACMAN_DOWN, &level.score[SC_PACMAN], TEXT_SMASHING },
2634 { EL_KOKOSNUSS, &level.score[SC_KOKOSNUSS], TEXT_CRACKING },
2635 { EL_DYNAMITE_INACTIVE,&level.score[SC_DYNAMIT], TEXT_COLLECTING },
2636 { EL_SCHLUESSEL1, &level.score[SC_SCHLUESSEL], TEXT_COLLECTING },
2637 { EL_SCHLUESSEL2, &level.score[SC_SCHLUESSEL], TEXT_COLLECTING },
2638 { EL_SCHLUESSEL3, &level.score[SC_SCHLUESSEL], TEXT_COLLECTING },
2639 { EL_SCHLUESSEL4, &level.score[SC_SCHLUESSEL], TEXT_COLLECTING },
2640 { EL_EM_KEY_1_FILE, &level.score[SC_SCHLUESSEL], TEXT_COLLECTING },
2641 { EL_EM_KEY_2_FILE, &level.score[SC_SCHLUESSEL], TEXT_COLLECTING },
2642 { EL_EM_KEY_3_FILE, &level.score[SC_SCHLUESSEL], TEXT_COLLECTING },
2643 { EL_EM_KEY_4_FILE, &level.score[SC_SCHLUESSEL], TEXT_COLLECTING },
2644 { EL_AMOEBE_NASS, &level.amoeba_speed, TEXT_SPEED },
2645 { EL_AMOEBE_NORM, &level.amoeba_speed, TEXT_SPEED },
2646 { EL_AMOEBE_VOLL, &level.amoeba_speed, TEXT_SPEED },
2647 { EL_AMOEBE_BD, &level.amoeba_speed, TEXT_SPEED },
2648 { EL_MAGIC_WALL_OFF,&level.time_magic_wall, TEXT_DURATION },
2649 { EL_ABLENK_AUS, &level.time_wheel, TEXT_DURATION },
2654 UnmapLevelEditorWindowGadgets();
2656 DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS_YPOS,
2657 "Element Settings", FS_BIG, FC_YELLOW);
2659 /* draw some decorative border for the object */
2662 DrawMiniElement(xstart + x , ystart + y, EL_ERDREICH);
2664 ClearRectangle(drawto,
2665 SX + xstart * MINI_TILEX + MINI_TILEX/2 - 1,
2666 SY + ystart * MINI_TILEY + MINI_TILEY/2 - 1,
2667 TILEX + 2, TILEY + 2);
2669 /* copy border to the right location */
2670 BlitBitmap(drawto, drawto,
2671 SX + xstart * MINI_TILEX,
2672 SY + ystart * MINI_TILEY,
2673 2 * TILEX, 2 * TILEY,
2674 SX + xstart * MINI_TILEX - MINI_TILEX/2,
2675 SY + ystart * MINI_TILEY - MINI_TILEY/2);
2677 DrawGraphic(xstart/2, ystart/2, el2gfx(properties_element));
2679 /* copy the whole stuff to the definitive location */
2680 BlitBitmap(drawto, drawto,
2681 SX + xstart * MINI_TILEX - MINI_TILEX/2,
2682 SY + ystart * MINI_TILEY - MINI_TILEY,
2683 2 * TILEX, 2 * TILEY,
2684 SX + xstart * MINI_TILEX - MINI_TILEX/2,
2685 SY + ystart * MINI_TILEY - MINI_TILEY/2);
2687 DrawTextF((xstart + 3) * MINI_TILEX, (ystart + 1) * MINI_TILEY,
2688 font_color, getElementInfoText(properties_element));
2690 num_elements_in_level = 0;
2691 for (y=0; y<lev_fieldy; y++)
2692 for (x=0; x<lev_fieldx; x++)
2693 if (Feld[x][y] == properties_element)
2694 num_elements_in_level++;
2695 percentage = num_elements_in_level * 100.0 / (lev_fieldx * lev_fieldy);
2697 DrawTextF(ED_SETTINGS_XPOS, 5 * TILEY, font_color, "In this level:");
2698 DrawTextF(ED_SETTINGS_XPOS + 15 * FONT2_XSIZE, 5 * TILEY, FC_YELLOW,
2699 "%d (%.2f%%)", num_elements_in_level, percentage);
2701 /* check if there are elements where a score can be chosen for */
2702 for (i=0; elements_with_counter[i].element != -1; i++)
2704 if (elements_with_counter[i].element == properties_element)
2706 int x = counterbutton_info[counter_id].x + xoffset_right;
2707 int y = counterbutton_info[counter_id].y + yoffset_right;
2709 counterbutton_info[counter_id].value = elements_with_counter[i].value;
2710 DrawTextF(x, y, font_color, elements_with_counter[i].text);
2712 ModifyEditorCounter(counter_id, *counterbutton_info[counter_id].value);
2713 MapCounterButtons(counter_id);
2718 if (HAS_CONTENT(properties_element))
2720 /* draw stickybutton gadget */
2721 i = ED_CHECKBUTTON_ID_STICK_ELEMENT;
2722 x = checkbutton_info[i].x + xoffset_right2;
2723 y = checkbutton_info[i].y + yoffset_right2;
2725 DrawTextF(x, y, font_color, checkbutton_info[i].text);
2726 ModifyGadget(level_editor_gadget[checkbutton_info[i].gadget_id],
2727 GDI_CHECKED, *checkbutton_info[i].value, GDI_END);
2728 MapCheckbuttonGadget(i);
2730 if (IS_AMOEBOID(properties_element))
2731 DrawAmoebaContentArea();
2733 DrawElementContentAreas();
2737 static void DrawLineElement(int sx, int sy, int element, boolean change_level)
2739 int lx = sx + level_xpos;
2740 int ly = sy + level_ypos;
2742 DrawMiniElement(sx, sy, (element < 0 ? Feld[lx][ly] : element));
2745 Feld[lx][ly] = element;
2748 static void DrawLine(int from_x, int from_y, int to_x, int to_y,
2749 int element, boolean change_level)
2751 if (from_y == to_y) /* horizontal line */
2757 swap_numbers(&from_x, &to_x);
2759 for (x=from_x; x<=to_x; x++)
2760 DrawLineElement(x, y, element, change_level);
2762 else if (from_x == to_x) /* vertical line */
2768 swap_numbers(&from_y, &to_y);
2770 for (y=from_y; y<=to_y; y++)
2771 DrawLineElement(x, y, element, change_level);
2773 else /* diagonal line */
2775 int len_x = ABS(to_x - from_x);
2776 int len_y = ABS(to_y - from_y);
2779 if (len_y < len_x) /* a < 1 */
2781 float a = (float)len_y / (float)len_x;
2784 swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
2786 for (x=0; x<=len_x; x++)
2788 y = (int)(a * x + 0.5) * (to_y < from_y ? -1 : +1);
2789 DrawLineElement(from_x + x, from_y + y, element, change_level);
2794 float a = (float)len_x / (float)len_y;
2797 swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
2799 for (y=0; y<=len_y; y++)
2801 x = (int)(a * y + 0.5) * (to_x < from_x ? -1 : +1);
2802 DrawLineElement(from_x + x, from_y + y, element, change_level);
2808 static void DrawRectangle(int from_x, int from_y, int to_x, int to_y,
2809 int element, boolean change_level)
2811 DrawLine(from_x, from_y, from_x, to_y, element, change_level);
2812 DrawLine(from_x, to_y, to_x, to_y, element, change_level);
2813 DrawLine(to_x, to_y, to_x, from_y, element, change_level);
2814 DrawLine(to_x, from_y, from_x, from_y, element, change_level);
2817 static void DrawFilledBox(int from_x, int from_y, int to_x, int to_y,
2818 int element, boolean change_level)
2823 swap_number_pairs(&from_x, &from_y, &to_x, &to_y);
2825 for (y=from_y; y<=to_y; y++)
2826 DrawLine(from_x, y, to_x, y, element, change_level);
2829 static void DrawArcExt(int from_x, int from_y, int to_x2, int to_y2,
2830 int element, boolean change_level)
2832 int to_x = to_x2 - (to_x2 > from_x ? +1 : -1);
2833 int to_y = to_y2 - (to_y2 > from_y ? +1 : -1);
2834 int len_x = ABS(to_x - from_x);
2835 int len_y = ABS(to_y - from_y);
2838 radius = (int)(sqrt((float)(len_x * len_x + len_y * len_y)) + 0.5);
2840 /* not optimal (some points get drawn twice) but simple,
2841 and fast enough for the few points we are drawing */
2843 for (x=0; x<=radius; x++)
2847 y = (int)(sqrt((float)(radius * radius - x * x)) + 0.5);
2849 sx = from_x + x * (from_x < to_x2 ? +1 : -1);
2850 sy = from_y + y * (from_y < to_y2 ? +1 : -1);
2851 lx = sx + level_xpos;
2852 ly = sy + level_ypos;
2854 if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
2855 DrawLineElement(sx, sy, element, change_level);
2858 for (y=0; y<=radius; y++)
2862 x = (int)(sqrt((float)(radius * radius - y * y)) + 0.5);
2864 sx = from_x + x * (from_x < to_x2 ? +1 : -1);
2865 sy = from_y + y * (from_y < to_y2 ? +1 : -1);
2866 lx = sx + level_xpos;
2867 ly = sy + level_ypos;
2869 if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
2870 DrawLineElement(sx, sy, element, change_level);
2874 static void DrawArc(int from_x, int from_y, int to_x, int to_y,
2875 int element, boolean change_level)
2877 int to_x2 = to_x + (to_x < from_x ? -1 : +1);
2878 int to_y2 = to_y + (to_y > from_y ? +1 : -1);
2880 DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
2883 #define DRAW_CIRCLES_BUTTON_AVAILABLE 0
2884 #if DRAW_CIRCLES_BUTTON_AVAILABLE
2885 static void DrawCircle(int from_x, int from_y, int to_x, int to_y,
2886 int element, boolean change_level)
2888 int to_x2 = to_x + (to_x < from_x ? -1 : +1);
2889 int to_y2 = to_y + (to_y > from_y ? +1 : -1);
2890 int mirror_to_x2 = from_x - (to_x2 - from_x);
2891 int mirror_to_y2 = from_y - (to_y2 - from_y);
2893 DrawArcExt(from_x, from_y, to_x2, to_y2, element, change_level);
2894 DrawArcExt(from_x, from_y, mirror_to_x2, to_y2, element, change_level);
2895 DrawArcExt(from_x, from_y, to_x2, mirror_to_y2, element, change_level);
2896 DrawArcExt(from_x, from_y, mirror_to_x2, mirror_to_y2, element,change_level);
2900 static void DrawAreaBorder(int from_x, int from_y, int to_x, int to_y)
2902 int from_sx, from_sy;
2906 swap_numbers(&from_x, &to_x);
2909 swap_numbers(&from_y, &to_y);
2911 from_sx = SX + from_x * MINI_TILEX;
2912 from_sy = SY + from_y * MINI_TILEY;
2913 to_sx = SX + to_x * MINI_TILEX + MINI_TILEX - 1;
2914 to_sy = SY + to_y * MINI_TILEY + MINI_TILEY - 1;
2916 DrawSimpleWhiteLine(drawto, from_sx, from_sy, to_sx, from_sy);
2917 DrawSimpleWhiteLine(drawto, to_sx, from_sy, to_sx, to_sy);
2918 DrawSimpleWhiteLine(drawto, to_sx, to_sy, from_sx, to_sy);
2919 DrawSimpleWhiteLine(drawto, from_sx, to_sy, from_sx, from_sy);
2921 if (from_x == to_x && from_y == to_y)
2922 MarkTileDirty(from_x/2, from_y/2);
2924 redraw_mask |= REDRAW_FIELD;
2927 static void SelectArea(int from_x, int from_y, int to_x, int to_y,
2928 int element, boolean change_level)
2930 if (element == -1 || change_level)
2931 DrawRectangle(from_x, from_y, to_x, to_y, -1, FALSE);
2933 DrawAreaBorder(from_x, from_y, to_x, to_y);
2936 /* values for CopyBrushExt() */
2937 #define CB_AREA_TO_BRUSH 0
2938 #define CB_BRUSH_TO_CURSOR 1
2939 #define CB_BRUSH_TO_LEVEL 2
2940 #define CB_DELETE_OLD_CURSOR 3
2942 static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
2943 int button, int mode)
2945 static short brush_buffer[MAX_ED_FIELDX][MAX_ED_FIELDY];
2946 static int brush_width, brush_height;
2947 static int last_cursor_x = -1, last_cursor_y = -1;
2948 static boolean delete_old_brush;
2949 int new_element = BUTTON_ELEMENT(button);
2952 if (mode == CB_DELETE_OLD_CURSOR && !delete_old_brush)
2955 if (mode == CB_AREA_TO_BRUSH)
2957 int from_lx, from_ly;
2960 swap_numbers(&from_x, &to_x);
2963 swap_numbers(&from_y, &to_y);
2965 brush_width = to_x - from_x + 1;
2966 brush_height = to_y - from_y + 1;
2968 from_lx = from_x + level_xpos;
2969 from_ly = from_y + level_ypos;
2971 for (y=0; y<brush_height; y++)
2973 for (x=0; x<brush_width; x++)
2975 brush_buffer[x][y] = Feld[from_lx + x][from_ly + y];
2978 DrawLineElement(from_x + x, from_y + y, new_element, TRUE);
2983 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
2985 delete_old_brush = FALSE;
2987 else if (mode == CB_BRUSH_TO_CURSOR || mode == CB_DELETE_OLD_CURSOR ||
2988 mode == CB_BRUSH_TO_LEVEL)
2990 int cursor_x = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_x : from_x);
2991 int cursor_y = (mode == CB_DELETE_OLD_CURSOR ? last_cursor_y : from_y);
2992 int cursor_from_x = cursor_x - brush_width / 2;
2993 int cursor_from_y = cursor_y - brush_height / 2;
2994 int border_from_x = cursor_x, border_from_y = cursor_y;
2995 int border_to_x = cursor_x, border_to_y = cursor_y;
2997 if (mode != CB_DELETE_OLD_CURSOR && delete_old_brush)
2998 CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
3000 if (!IN_ED_FIELD(cursor_x, cursor_y) ||
3001 !IN_LEV_FIELD(cursor_x + level_xpos, cursor_y + level_ypos))
3003 delete_old_brush = FALSE;
3007 for (y=0; y<brush_height; y++)
3009 for (x=0; x<brush_width; x++)
3011 int sx = cursor_from_x + x;
3012 int sy = cursor_from_y + y;
3013 int lx = sx + level_xpos;
3014 int ly = sy + level_ypos;
3015 boolean change_level = (mode == CB_BRUSH_TO_LEVEL);
3016 int element = (mode == CB_DELETE_OLD_CURSOR ? -1 :
3017 mode == CB_BRUSH_TO_CURSOR || button == 1 ?
3018 brush_buffer[x][y] : new_element);
3020 if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
3022 if (sx < border_from_x)
3024 else if (sx > border_to_x)
3026 if (sy < border_from_y)
3028 else if (sy > border_to_y)
3031 DrawLineElement(sx, sy, element, change_level);
3036 if (mode != CB_DELETE_OLD_CURSOR)
3037 DrawAreaBorder(border_from_x, border_from_y, border_to_x, border_to_y);
3039 last_cursor_x = cursor_x;
3040 last_cursor_y = cursor_y;
3041 delete_old_brush = TRUE;
3045 static void CopyAreaToBrush(int from_x, int from_y, int to_x, int to_y,
3048 CopyBrushExt(from_x, from_y, to_x, to_y, button, CB_AREA_TO_BRUSH);
3051 static void CopyBrushToLevel(int x, int y, int button)
3053 CopyBrushExt(x, y, 0, 0, button, CB_BRUSH_TO_LEVEL);
3056 static void CopyBrushToCursor(int x, int y)
3058 CopyBrushExt(x, y, 0, 0, 0, CB_BRUSH_TO_CURSOR);
3061 static void DeleteBrushFromCursor()
3063 CopyBrushExt(0, 0, 0, 0, 0, CB_DELETE_OLD_CURSOR);
3066 static void FloodFill(int from_x, int from_y, int fill_element)
3070 static int check[4][2] = { {-1,0}, {0,-1}, {1,0}, {0,1} };
3071 static int safety = 0;
3073 /* check if starting field still has the desired content */
3074 if (Feld[from_x][from_y] == fill_element)
3079 if (safety > lev_fieldx*lev_fieldy)
3080 Error(ERR_EXIT, "Something went wrong in 'FloodFill()'. Please debug.");
3082 old_element = Feld[from_x][from_y];
3083 Feld[from_x][from_y] = fill_element;
3087 x = from_x + check[i][0];
3088 y = from_y + check[i][1];
3090 if (IN_LEV_FIELD(x,y) && Feld[x][y] == old_element)
3091 FloodFill(x, y, fill_element);
3097 /* values for DrawLevelText() modes */
3099 #define TEXT_SETCURSOR 1
3100 #define TEXT_WRITECHAR 2
3101 #define TEXT_BACKSPACE 3
3102 #define TEXT_NEWLINE 4
3104 #define TEXT_QUERY_TYPING 6
3106 static int DrawLevelText(int sx, int sy, char letter, int mode)
3108 static short delete_buffer[MAX_LEV_FIELDX];
3109 static int start_sx, start_sy;
3110 static int last_sx, last_sy;
3111 static boolean typing = FALSE;
3112 int letter_element = EL_CHAR_ASCII0 + letter;
3115 /* map lower case letters to upper case and convert special characters */
3116 if (letter >= 'a' && letter <= 'z')
3117 letter_element = EL_CHAR_ASCII0 + letter + (int)('A' - 'a');
3118 else if (letter == 'ä' || letter == 'Ä')
3119 letter_element = EL_CHAR_AE;
3120 else if (letter == 'ö' || letter == 'Ö')
3121 letter_element = EL_CHAR_OE;
3122 else if (letter == 'ü' || letter == 'Ü')
3123 letter_element = EL_CHAR_UE;
3124 else if (letter == '^')
3125 letter_element = EL_CHAR_COPY;
3127 letter_element = EL_CHAR_ASCII0 + letter;
3129 if (mode != TEXT_INIT)
3134 if (mode != TEXT_SETCURSOR)
3140 lx = last_sx + level_xpos;
3141 ly = last_sy + level_ypos;
3148 DrawLevelText(0, 0, 0, TEXT_END);
3151 start_sx = last_sx = sx;
3152 start_sy = last_sy = sy;
3153 DrawLevelText(sx, sy, 0, TEXT_SETCURSOR);
3156 case TEXT_SETCURSOR:
3157 DrawMiniElement(last_sx, last_sy, Feld[lx][ly]);
3158 DrawAreaBorder(sx, sy, sx, sy);
3163 case TEXT_WRITECHAR:
3164 if (letter_element >= EL_CHAR_START && letter_element <= EL_CHAR_END)
3166 delete_buffer[sx - start_sx] = Feld[lx][ly];
3167 Feld[lx][ly] = letter_element;
3169 if (sx + 1 < ed_fieldx && lx + 1 < lev_fieldx)
3170 DrawLevelText(sx + 1, sy, 0, TEXT_SETCURSOR);
3171 else if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
3172 DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
3174 DrawLevelText(0, 0, 0, TEXT_END);
3178 case TEXT_BACKSPACE:
3181 Feld[lx - 1][ly] = delete_buffer[sx - start_sx - 1];
3182 DrawMiniElement(sx - 1, sy, Feld[lx - 1][ly]);
3183 DrawLevelText(sx - 1, sy, 0, TEXT_SETCURSOR);
3188 if (sy + 1 < ed_fieldy - 1 && ly + 1 < lev_fieldy - 1)
3189 DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
3191 DrawLevelText(0, 0, 0, TEXT_END);
3195 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
3196 DrawMiniElement(sx, sy, Feld[lx][ly]);
3200 case TEXT_QUERY_TYPING:
3210 static void SetTextCursor(int unused_sx, int unused_sy, int sx, int sy,
3211 int element, boolean change_level)
3213 int lx = sx + level_xpos;
3214 int ly = sy + level_ypos;
3217 DrawMiniElement(sx, sy, Feld[lx][ly]);
3219 DrawAreaBorder(sx, sy, sx, sy);
3222 static void CopyLevelToUndoBuffer(int mode)
3224 static boolean accumulated_undo = FALSE;
3225 boolean new_undo_buffer_position = TRUE;
3226 int last_border_element;
3231 case UNDO_IMMEDIATE:
3232 accumulated_undo = FALSE;
3235 case UNDO_ACCUMULATE:
3236 if (accumulated_undo)
3237 new_undo_buffer_position = FALSE;
3238 accumulated_undo = TRUE;
3245 if (new_undo_buffer_position)
3247 /* new position in undo buffer ring */
3248 undo_buffer_position = (undo_buffer_position + 1) % NUM_UNDO_STEPS;
3250 if (undo_buffer_steps < NUM_UNDO_STEPS - 1)
3251 undo_buffer_steps++;
3254 for(x=0; x<lev_fieldx; x++)
3255 for(y=0; y<lev_fieldy; y++)
3256 UndoBuffer[undo_buffer_position][x][y] = Feld[x][y];
3258 /* check if drawing operation forces change of border style */
3259 last_border_element = BorderElement;
3261 if (BorderElement != last_border_element)
3262 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3266 printf("level saved to undo buffer\n");
3271 static void RandomPlacement(int new_element)
3273 static boolean free_position[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
3274 int num_free_positions;
3279 /* determine number of free positions for the new elements */
3280 /* (maybe this statement should be formatted a bit more readable...) */
3281 num_free_positions = 0;
3282 for (x=0; x<lev_fieldx; x++)
3283 for (y=0; y<lev_fieldy; y++)
3284 if ((free_position[x][y] =
3285 ((random_placement_background_restricted &&
3286 Feld[x][y] == random_placement_background_element) ||
3287 (!random_placement_background_restricted &&
3288 Feld[x][y] != new_element))) == TRUE)
3289 num_free_positions++;
3291 /* determine number of new elements to place there */
3292 num_percentage = num_free_positions * random_placement_value / 100;
3293 num_elements = (random_placement_method == RANDOM_USE_PERCENTAGE ?
3294 num_percentage : random_placement_value);
3296 /* if not more free positions than elements to place, fill whole level */
3297 if (num_elements >= num_free_positions)
3299 for (x=0; x<lev_fieldx; x++)
3300 for (y=0; y<lev_fieldy; y++)
3301 Feld[x][y] = new_element;
3303 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3304 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
3308 while (num_elements > 0)
3310 x = RND(lev_fieldx);
3311 y = RND(lev_fieldy);
3313 /* don't place element at the same position twice */
3314 if (free_position[x][y])
3316 free_position[x][y] = FALSE;
3317 Feld[x][y] = new_element;
3322 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3323 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
3326 void WrapLevel(int dx, int dy)
3328 int wrap_dx = lev_fieldx - dx;
3329 int wrap_dy = lev_fieldy - dy;
3332 for(x=0; x<lev_fieldx; x++)
3333 for(y=0; y<lev_fieldy; y++)
3334 FieldBackup[x][y] = Feld[x][y];
3336 for(x=0; x<lev_fieldx; x++)
3337 for(y=0; y<lev_fieldy; y++)
3339 FieldBackup[(x + wrap_dx) % lev_fieldx][(y + wrap_dy) % lev_fieldy];
3341 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3342 CopyLevelToUndoBuffer(UNDO_ACCUMULATE);
3345 static void HandleDrawingAreas(struct GadgetInfo *gi)
3347 static boolean started_inside_drawing_area = FALSE;
3348 int id = gi->custom_id;
3349 boolean button_press_event;
3350 boolean button_release_event;
3351 boolean inside_drawing_area = !gi->event.off_borders;
3352 boolean draw_level = (id == GADGET_ID_DRAWING_LEVEL);
3353 int actual_drawing_function;
3354 int button = gi->event.button;
3355 int new_element = BUTTON_ELEMENT(button);
3356 int sx = gi->event.x, sy = gi->event.y;
3357 int min_sx = 0, min_sy = 0;
3358 int max_sx = gi->drawing.area_xsize - 1, max_sy = gi->drawing.area_ysize - 1;
3360 int min_lx = 0, min_ly = 0;
3361 int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
3364 /* handle info callback for each invocation of action callback */
3365 gi->callback_info(gi);
3367 button_press_event = (gi->event.type == GD_EVENT_PRESSED);
3368 button_release_event = (gi->event.type == GD_EVENT_RELEASED);
3370 /* make sure to stay inside drawing area boundaries */
3371 sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
3372 sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
3376 /* get positions inside level field */
3377 lx = sx + level_xpos;
3378 ly = sy + level_ypos;
3380 if (!IN_LEV_FIELD(lx, ly))
3381 inside_drawing_area = FALSE;
3383 /* make sure to stay inside level field boundaries */
3384 lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
3385 ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
3387 /* correct drawing area positions accordingly */
3388 sx = lx - level_xpos;
3389 sy = ly - level_ypos;
3392 if (button_press_event)
3393 started_inside_drawing_area = inside_drawing_area;
3395 if (!started_inside_drawing_area)
3398 if (!button && !button_release_event)
3401 /* automatically switch to 'single item' drawing mode, if needed */
3402 actual_drawing_function =
3403 (draw_level ? drawing_function : GADGET_ID_SINGLE_ITEMS);
3405 switch (actual_drawing_function)
3407 case GADGET_ID_SINGLE_ITEMS:
3410 if (button_release_event)
3412 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
3414 if (edit_mode == ED_MODE_DRAWING && draw_with_brush &&
3415 !inside_drawing_area)
3416 DeleteBrushFromCursor();
3422 if (draw_with_brush)
3424 if (!button_release_event)
3425 CopyBrushToLevel(sx, sy, button);
3427 else if (new_element != Feld[lx][ly])
3429 if (new_element == EL_SPIELFIGUR)
3431 /* remove player at old position */
3432 for(y=0; y<lev_fieldy; y++)
3434 for(x=0; x<lev_fieldx; x++)
3436 if (Feld[x][y] == EL_SPIELFIGUR || Feld[x][y] == EL_SPIELER1)
3438 Feld[x][y] = EL_LEERRAUM;
3439 if (x - level_xpos >= 0 && x - level_xpos < ed_fieldx &&
3440 y - level_ypos >= 0 && y - level_ypos < ed_fieldy)
3441 DrawMiniElement(x - level_xpos, y - level_ypos,
3448 Feld[lx][ly] = new_element;
3449 DrawMiniElement(sx, sy, new_element);
3454 DrawMiniGraphicExt(drawto,
3455 gi->x + sx * MINI_TILEX,
3456 gi->y + sy * MINI_TILEY,
3457 el2gfx(new_element));
3458 DrawMiniGraphicExt(window,
3459 gi->x + sx * MINI_TILEX,
3460 gi->y + sy * MINI_TILEY,
3461 el2gfx(new_element));
3463 if (id == GADGET_ID_AMOEBA_CONTENT)
3464 level.amoeba_content = new_element;
3465 else if (id == GADGET_ID_RANDOM_BACKGROUND)
3466 random_placement_background_element = new_element;
3467 else if (id >= GADGET_ID_ELEM_CONTENT_0 &&
3468 id <= GADGET_ID_ELEM_CONTENT_7)
3469 level.yam_content[id - GADGET_ID_ELEM_CONTENT_0][sx][sy] =
3474 case GADGET_ID_CONNECTED_ITEMS:
3476 static int last_sx = -1;
3477 static int last_sy = -1;
3479 if (button_release_event)
3480 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
3484 if (!button_press_event)
3485 DrawLine(last_sx, last_sy, sx, sy, new_element, TRUE);
3493 case GADGET_ID_LINE:
3495 case GADGET_ID_RECTANGLE:
3496 case GADGET_ID_FILLED_BOX:
3497 case GADGET_ID_GRAB_BRUSH:
3498 case GADGET_ID_TEXT:
3500 static int last_sx = -1;
3501 static int last_sy = -1;
3502 static int start_sx = -1;
3503 static int start_sy = -1;
3504 void (*draw_func)(int, int, int, int, int, boolean);
3506 if (drawing_function == GADGET_ID_LINE)
3507 draw_func = DrawLine;
3508 else if (drawing_function == GADGET_ID_ARC)
3509 draw_func = DrawArc;
3510 else if (drawing_function == GADGET_ID_RECTANGLE)
3511 draw_func = DrawRectangle;
3512 else if (drawing_function == GADGET_ID_FILLED_BOX)
3513 draw_func = DrawFilledBox;
3514 else if (drawing_function == GADGET_ID_GRAB_BRUSH)
3515 draw_func = SelectArea;
3516 else /* (drawing_function == GADGET_ID_TEXT) */
3517 draw_func = SetTextCursor;
3519 if (button_press_event)
3521 draw_func(sx, sy, sx, sy, new_element, FALSE);
3522 start_sx = last_sx = sx;
3523 start_sy = last_sy = sy;
3525 if (drawing_function == GADGET_ID_TEXT)
3526 DrawLevelText(0, 0, 0, TEXT_END);
3528 else if (button_release_event)
3530 draw_func(start_sx, start_sy, sx, sy, new_element, TRUE);
3531 if (drawing_function == GADGET_ID_GRAB_BRUSH)
3533 CopyAreaToBrush(start_sx, start_sy, sx, sy, button);
3534 CopyBrushToCursor(sx, sy);
3535 ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS],
3537 draw_with_brush = TRUE;
3539 else if (drawing_function == GADGET_ID_TEXT)
3540 DrawLevelText(sx, sy, 0, TEXT_INIT);
3542 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
3544 else if (last_sx != sx || last_sy != sy)
3546 draw_func(start_sx, start_sy, last_sx, last_sy, -1, FALSE);
3547 draw_func(start_sx, start_sy, sx, sy, new_element, FALSE);
3554 case GADGET_ID_FLOOD_FILL:
3555 if (button_press_event && Feld[lx][ly] != new_element)
3557 FloodFill(lx, ly, new_element);
3558 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3559 CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
3563 case GADGET_ID_PICK_ELEMENT:
3564 if (button_release_event)
3565 ClickOnGadget(level_editor_gadget[last_drawing_function],
3568 PickDrawingElement(button, Feld[lx][ly]);
3577 static void HandleCounterButtons(struct GadgetInfo *gi)
3579 int gadget_id = gi->custom_id;
3580 int counter_id = gi->custom_type_id;
3581 int button = gi->event.button;
3582 int *counter_value = counterbutton_info[counter_id].value;
3583 int step = BUTTON_STEPSIZE(button) *
3584 (gadget_id == counterbutton_info[counter_id].gadget_id_down ? -1 : +1);
3586 if (counter_id == ED_COUNTER_ID_SELECT_LEVEL)
3588 boolean pressed = (gi->event.type == GD_EVENT_PRESSED);
3589 boolean released = (gi->event.type == GD_EVENT_RELEASED);
3590 boolean level_changed = LevelChanged();
3592 if ((level_changed && pressed) || (!level_changed && released))
3595 if (level_changed && !Request("Level has changed! Discard changes ?",
3598 if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
3599 ModifyEditorCounter(counter_id, *counter_value);
3604 if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
3605 *counter_value = gi->text.number_value;
3607 ModifyEditorCounter(counter_id, *counter_value + step);
3611 case ED_COUNTER_ID_ELEM_CONTENT:
3612 DrawElementContentAreas();
3615 case ED_COUNTER_ID_LEVEL_XSIZE:
3616 case ED_COUNTER_ID_LEVEL_YSIZE:
3617 lev_fieldx = level.fieldx;
3618 lev_fieldy = level.fieldy;
3621 case ED_COUNTER_ID_SELECT_LEVEL:
3622 LoadLevel(level_nr);
3624 DrawEditModeWindow();
3632 static void HandleTextInputGadgets(struct GadgetInfo *gi)
3634 strcpy(textinput_info[gi->custom_type_id].value, gi->text.value);
3637 static void HandleRadiobuttons(struct GadgetInfo *gi)
3639 *radiobutton_info[gi->custom_type_id].value =
3640 radiobutton_info[gi->custom_type_id].checked_value;
3643 static void HandleCheckbuttons(struct GadgetInfo *gi)
3645 *checkbutton_info[gi->custom_type_id].value ^= TRUE;
3648 static void HandleControlButtons(struct GadgetInfo *gi)
3650 int id = gi->custom_id;
3651 int button = gi->event.button;
3652 int step = BUTTON_STEPSIZE(button);
3653 int new_element = BUTTON_ELEMENT(button);
3656 if (edit_mode == ED_MODE_DRAWING && drawing_function == GADGET_ID_TEXT)
3657 DrawLevelText(0, 0, 0, TEXT_END);
3659 if (id < ED_NUM_CTRL1_BUTTONS && id != GADGET_ID_PROPERTIES &&
3660 edit_mode != ED_MODE_DRAWING)
3662 DrawDrawingWindow();
3663 edit_mode = ED_MODE_DRAWING;
3668 case GADGET_ID_SCROLL_LEFT:
3669 if (level_xpos >= 0)
3671 if (lev_fieldx < ed_fieldx - 2)
3675 if (level_xpos < -1)
3678 ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_RIGHT);
3680 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3682 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
3683 GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
3687 case GADGET_ID_SCROLL_RIGHT:
3688 if (level_xpos <= lev_fieldx - ed_fieldx)
3690 if (lev_fieldx < ed_fieldx - 2)
3694 if (level_xpos > lev_fieldx - ed_fieldx + 1)
3695 level_xpos = lev_fieldx - ed_fieldx + 1;
3697 ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_LEFT);
3699 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3701 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
3702 GDI_SCROLLBAR_ITEM_POSITION, level_xpos + 1, GDI_END);
3706 case GADGET_ID_SCROLL_UP:
3707 if (level_ypos >= 0)
3709 if (lev_fieldy < ed_fieldy - 2)
3713 if (level_ypos < -1)
3716 ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_DOWN);
3718 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3720 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
3721 GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
3725 case GADGET_ID_SCROLL_DOWN:
3726 if (level_ypos <= lev_fieldy - ed_fieldy)
3728 if (lev_fieldy < ed_fieldy - 2)
3732 if (level_ypos > lev_fieldy - ed_fieldy + 1)
3733 level_ypos = lev_fieldy - ed_fieldy + 1;
3735 ScrollMiniLevel(level_xpos, level_ypos, ED_SCROLL_UP);
3737 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3739 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
3740 GDI_SCROLLBAR_ITEM_POSITION, level_ypos + 1, GDI_END);
3744 case GADGET_ID_SCROLL_HORIZONTAL:
3745 level_xpos = gi->event.item_position - 1;
3746 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3749 case GADGET_ID_SCROLL_VERTICAL:
3750 level_ypos = gi->event.item_position - 1;
3751 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3754 case GADGET_ID_SCROLL_LIST_UP:
3755 case GADGET_ID_SCROLL_LIST_DOWN:
3756 case GADGET_ID_SCROLL_LIST_VERTICAL:
3757 if (id == GADGET_ID_SCROLL_LIST_VERTICAL)
3758 element_shift = gi->event.item_position * ED_ELEMENTLIST_BUTTONS_HORIZ;
3761 step *= (id == GADGET_ID_SCROLL_LIST_UP ? -1 : +1);
3762 element_shift += step * ED_ELEMENTLIST_BUTTONS_HORIZ;
3764 if (element_shift < 0)
3766 if (element_shift > elements_in_list - ED_NUM_ELEMENTLIST_BUTTONS)
3767 element_shift = elements_in_list - ED_NUM_ELEMENTLIST_BUTTONS;
3769 ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL],
3770 GDI_SCROLLBAR_ITEM_POSITION,
3771 element_shift / ED_ELEMENTLIST_BUTTONS_HORIZ, GDI_END);
3774 for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
3776 int gadget_id = GADGET_ID_ELEMENTLIST_FIRST + i;
3777 struct GadgetInfo *gi = level_editor_gadget[gadget_id];
3778 struct GadgetDesign *gd = &gi->deco.design;
3779 int element = editor_element[element_shift + i];
3782 getMiniGraphicSource(el2gfx(element), &gd->bitmap, &gd->x, &gd->y);
3783 ModifyGadget(gi, GDI_INFO_TEXT, getElementInfoText(element), GDI_END);
3788 case GADGET_ID_WRAP_LEFT:
3789 WrapLevel(-step, 0);
3792 case GADGET_ID_WRAP_RIGHT:
3796 case GADGET_ID_WRAP_UP:
3797 WrapLevel(0, -step);
3800 case GADGET_ID_WRAP_DOWN:
3804 case GADGET_ID_SINGLE_ITEMS:
3805 case GADGET_ID_CONNECTED_ITEMS:
3806 case GADGET_ID_LINE:
3808 case GADGET_ID_TEXT:
3809 case GADGET_ID_RECTANGLE:
3810 case GADGET_ID_FILLED_BOX:
3811 case GADGET_ID_FLOOD_FILL:
3812 case GADGET_ID_GRAB_BRUSH:
3813 case GADGET_ID_PICK_ELEMENT:
3814 last_drawing_function = drawing_function;
3815 drawing_function = id;
3816 draw_with_brush = FALSE;
3819 case GADGET_ID_RANDOM_PLACEMENT:
3820 RandomPlacement(new_element);
3823 case GADGET_ID_PROPERTIES:
3824 if (edit_mode != ED_MODE_PROPERTIES)
3826 properties_element = new_element;
3827 DrawPropertiesWindow();
3828 edit_mode = ED_MODE_PROPERTIES;
3832 DrawDrawingWindow();
3833 edit_mode = ED_MODE_DRAWING;
3837 case GADGET_ID_UNDO:
3838 if (undo_buffer_steps == 0)
3840 Request("Undo buffer empty !", REQ_CONFIRM);
3844 undo_buffer_position =
3845 (undo_buffer_position - 1 + NUM_UNDO_STEPS) % NUM_UNDO_STEPS;
3846 undo_buffer_steps--;
3848 for(x=0; x<lev_fieldx; x++)
3849 for(y=0; y<lev_fieldy; y++)
3850 Feld[x][y] = UndoBuffer[undo_buffer_position][x][y];
3851 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos,level_ypos);
3854 case GADGET_ID_INFO:
3855 if (edit_mode != ED_MODE_INFO)
3857 DrawLevelInfoWindow();
3858 edit_mode = ED_MODE_INFO;
3862 DrawDrawingWindow();
3863 edit_mode = ED_MODE_DRAWING;
3867 case GADGET_ID_CLEAR:
3868 for(x=0; x<MAX_LEV_FIELDX; x++)
3869 for(y=0; y<MAX_LEV_FIELDY; y++)
3870 Feld[x][y] = (button == 1 ? EL_LEERRAUM : new_element);
3871 CopyLevelToUndoBuffer(GADGET_ID_CLEAR);
3873 DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
3876 case GADGET_ID_SAVE:
3877 if (leveldir_current->readonly)
3879 Request("This level is read only !", REQ_CONFIRM);
3883 if (!LevelContainsPlayer)
3884 Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM);
3887 if (Request("Save this level and kill the old ?", REQ_ASK))
3889 for(x=0; x<lev_fieldx; x++)
3890 for(y=0; y<lev_fieldy; y++)
3891 Ur[x][y] = Feld[x][y];
3892 SaveLevel(level_nr);
3897 case GADGET_ID_TEST:
3898 if (!LevelContainsPlayer)
3899 Request("No Level without Gregor Mc Duffin please !", REQ_CONFIRM);
3902 for(x=0; x<lev_fieldx; x++)
3903 for(y=0; y<lev_fieldy; y++)
3904 FieldBackup[x][y] = Ur[x][y];
3906 for(x=0; x<lev_fieldx; x++)
3907 for(y=0; y<lev_fieldy; y++)
3908 Ur[x][y] = Feld[x][y];
3910 UnmapLevelEditorGadgets();
3911 UndrawSpecialEditorDoor();
3913 CloseDoor(DOOR_CLOSE_ALL);
3915 DrawCompleteVideoDisplay();
3917 if (setup.autorecord)
3918 TapeStartRecording();
3920 level_editor_test_game = TRUE;
3921 game_status = PLAYING;
3927 case GADGET_ID_EXIT:
3928 if (!LevelChanged() ||
3929 Request("Level has changed! Exit without saving ?",
3930 REQ_ASK | REQ_STAY_OPEN))
3932 CloseDoor(DOOR_CLOSE_1);
3935 CloseDoor(DOOR_CLOSE_ALL);
3938 game_status = MAINMENU;
3943 CloseDoor(DOOR_CLOSE_1);
3944 BlitBitmap(pix[PIX_DB_DOOR], pix[PIX_DB_DOOR],
3945 DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY1, DXSIZE,DYSIZE,
3946 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
3947 OpenDoor(DOOR_OPEN_1);
3952 if (id >= GADGET_ID_ELEMENTLIST_FIRST &&
3953 id <= GADGET_ID_ELEMENTLIST_LAST)
3955 int element_position = id - GADGET_ID_ELEMENTLIST_FIRST;
3956 int new_element = editor_element[element_position + element_shift];
3958 PickDrawingElement(button, new_element);
3960 if (!HAS_CONTENT(properties_element) ||
3961 !stick_element_properties_window)
3963 properties_element = new_element;
3964 if (edit_mode == ED_MODE_PROPERTIES)
3965 DrawPropertiesWindow();
3968 if (drawing_function == GADGET_ID_PICK_ELEMENT)
3969 ClickOnGadget(level_editor_gadget[last_drawing_function],
3973 else if (gi->event.type == GD_EVENT_PRESSED)
3974 printf("default: HandleControlButtons: GD_EVENT_PRESSED(%d)\n", id);
3975 else if (gi->event.type == GD_EVENT_RELEASED)
3976 printf("default: HandleControlButtons: GD_EVENT_RELEASED(%d)\n", id);
3977 else if (gi->event.type == GD_EVENT_MOVING)
3978 printf("default: HandleControlButtons: GD_EVENT_MOVING(%d)\n", id);
3980 printf("default: HandleControlButtons: ? (id == %d)\n", id);
3986 void HandleLevelEditorKeyInput(Key key)
3988 char letter = getCharFromKey(key);
3989 int button = MB_LEFTBUTTON;
3991 if (drawing_function == GADGET_ID_TEXT &&
3992 DrawLevelText(0, 0, 0, TEXT_QUERY_TYPING) == TRUE)
3995 DrawLevelText(0, 0, letter, TEXT_WRITECHAR);
3996 else if (key == KSYM_Delete || key == KSYM_BackSpace)
3997 DrawLevelText(0, 0, 0, TEXT_BACKSPACE);
3998 else if (key == KSYM_Return)
3999 DrawLevelText(0, 0, 0, TEXT_NEWLINE);
4001 else if (button_status == MB_RELEASED)
4008 id = GADGET_ID_SCROLL_LEFT;
4011 id = GADGET_ID_SCROLL_RIGHT;
4014 id = GADGET_ID_SCROLL_UP;
4017 id = GADGET_ID_SCROLL_DOWN;
4020 id = GADGET_ID_SCROLL_LIST_UP;
4021 button = MB_RIGHTBUTTON;
4023 case KSYM_Page_Down:
4024 id = GADGET_ID_SCROLL_LIST_DOWN;
4025 button = MB_RIGHTBUTTON;
4029 id = GADGET_ID_NONE;
4033 if (id != GADGET_ID_NONE)
4034 ClickOnGadget(level_editor_gadget[id], button);
4035 else if (letter == '.')
4036 ClickOnGadget(level_editor_gadget[GADGET_ID_SINGLE_ITEMS], button);
4037 else if (key == KSYM_space || key == KSYM_Return)
4038 ClickOnGadget(level_editor_gadget[GADGET_ID_TEST], button);
4040 for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
4041 if (letter && letter == control_info[i].shortcut)
4042 if (!anyTextGadgetActive())
4043 ClickOnGadget(level_editor_gadget[i], button);
4047 void ClearEditorGadgetInfoText()
4049 ClearRectangle(drawto,
4050 INFOTEXT_XPOS, INFOTEXT_YPOS, INFOTEXT_XSIZE, INFOTEXT_YSIZE);
4051 redraw_mask |= REDRAW_FIELD;
4054 void HandleEditorGadgetInfoText(void *ptr)
4056 struct GadgetInfo *gi = (struct GadgetInfo *)ptr;
4057 char infotext[MAX_INFOTEXT_LEN + 1];
4058 char shortcut[MAX_INFOTEXT_LEN + 1];
4060 if (game_status != LEVELED)
4063 ClearEditorGadgetInfoText();
4065 /* misuse this function to delete brush cursor, if needed */
4066 if (edit_mode == ED_MODE_DRAWING && draw_with_brush)
4067 DeleteBrushFromCursor();
4069 if (gi == NULL || gi->info_text == NULL)
4072 strncpy(infotext, gi->info_text, MAX_INFOTEXT_LEN);
4073 infotext[MAX_INFOTEXT_LEN] = '\0';
4075 if (gi->custom_id < ED_NUM_CTRL_BUTTONS)
4077 int key = control_info[gi->custom_id].shortcut;
4081 if (gi->custom_id == GADGET_ID_SINGLE_ITEMS) /* special case 1 */
4082 sprintf(shortcut, " ('.' or '%c')", key);
4083 else if (gi->custom_id == GADGET_ID_TEST) /* special case 2 */
4084 sprintf(shortcut, " ('Enter' or 'Shift-%c')", key);
4085 else /* normal case */
4086 sprintf(shortcut, " ('%s%c')",
4087 (key >= 'A' && key <= 'Z' ? "Shift-" : ""), key);
4089 if (strlen(infotext) + strlen(shortcut) <= MAX_INFOTEXT_LEN)
4090 strcat(infotext, shortcut);
4094 DrawText(INFOTEXT_XPOS, INFOTEXT_YPOS, infotext, FS_SMALL, FC_YELLOW);
4097 static void HandleDrawingAreaInfo(struct GadgetInfo *gi)
4099 static int start_lx, start_ly;
4101 int id = gi->custom_id;
4102 int sx = gi->event.x;
4103 int sy = gi->event.y;
4104 int lx = sx + level_xpos;
4105 int ly = sy + level_ypos;
4106 int min_sx = 0, min_sy = 0;
4107 int max_sx = gi->drawing.area_xsize - 1;
4108 int max_sy = gi->drawing.area_ysize - 1;
4110 ClearEditorGadgetInfoText();
4112 /* make sure to stay inside drawing area boundaries */
4113 sx = (sx < min_sx ? min_sx : sx > max_sx ? max_sx : sx);
4114 sy = (sy < min_sy ? min_sy : sy > max_sy ? max_sy : sy);
4116 if (id == GADGET_ID_DRAWING_LEVEL)
4120 int min_lx = 0, min_ly = 0;
4121 int max_lx = lev_fieldx - 1, max_ly = lev_fieldy - 1;
4123 /* get positions inside level field */
4124 lx = sx + level_xpos;
4125 ly = sy + level_ypos;
4127 /* make sure to stay inside level field boundaries */
4128 lx = (lx < min_lx ? min_lx : lx > max_lx ? max_lx : lx);
4129 ly = (ly < min_ly ? min_ly : ly > max_ly ? max_ly : ly);
4131 /* correct drawing area positions accordingly */
4132 sx = lx - level_xpos;
4133 sy = ly - level_ypos;
4136 if (IN_ED_FIELD(sx,sy) && IN_LEV_FIELD(lx, ly))
4138 if (button_status) /* if (gi->state == GD_BUTTON_PRESSED) */
4140 if (gi->event.type == GD_EVENT_PRESSED)
4146 switch (drawing_function)
4148 case GADGET_ID_SINGLE_ITEMS:
4149 infotext = "Drawing single items";
4151 case GADGET_ID_CONNECTED_ITEMS:
4152 infotext = "Drawing connected items";
4154 case GADGET_ID_LINE:
4155 infotext = "Drawing line";
4158 infotext = "Drawing arc";
4160 case GADGET_ID_TEXT:
4161 infotext = "Setting text cursor";
4163 case GADGET_ID_RECTANGLE:
4164 infotext = "Drawing rectangle";
4166 case GADGET_ID_FILLED_BOX:
4167 infotext = "Drawing filled box";
4169 case GADGET_ID_FLOOD_FILL:
4170 infotext = "Flood fill";
4172 case GADGET_ID_GRAB_BRUSH:
4173 infotext = "Grabbing brush";
4175 case GADGET_ID_PICK_ELEMENT:
4176 infotext = "Picking element";
4180 infotext = "Drawing position";
4184 if (drawing_function == GADGET_ID_PICK_ELEMENT)
4185 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
4186 "%s: %d, %d", infotext, lx, ly);
4188 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
4189 "%s: %d, %d", infotext,
4190 ABS(lx - start_lx) + 1, ABS(ly - start_ly) + 1);
4192 else if (drawing_function == GADGET_ID_PICK_ELEMENT)
4193 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
4194 "%s", getElementInfoText(Feld[lx][ly]));
4196 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
4197 "Level position: %d, %d", lx, ly);
4200 /* misuse this function to draw brush cursor, if needed */
4201 if (edit_mode == ED_MODE_DRAWING && draw_with_brush && !button_status)
4203 if (IN_ED_FIELD(sx, sy) && IN_LEV_FIELD(lx, ly))
4204 CopyBrushToCursor(sx, sy);
4206 DeleteBrushFromCursor();
4209 else if (id == GADGET_ID_AMOEBA_CONTENT)
4210 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
4212 else if (id == GADGET_ID_RANDOM_BACKGROUND)
4213 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
4214 "Random placement background");
4216 DrawTextF(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, FC_YELLOW,
4217 "Content area %d position: %d, %d",
4218 id - GADGET_ID_ELEM_CONTENT_0 + 1, sx, sy);