+static void ScrollMiniLevel(int from_x, int from_y, int scroll)
+{
+ int x,y;
+ int dx = (scroll == ED_SCROLL_LEFT ? -1 : scroll == ED_SCROLL_RIGHT ? 1 : 0);
+ int dy = (scroll == ED_SCROLL_UP ? -1 : scroll == ED_SCROLL_DOWN ? 1 : 0);
+
+ XCopyArea(display, drawto, drawto, gc,
+ SX + (dx == -1 ? MINI_TILEX : 0),
+ SY + (dy == -1 ? MINI_TILEY : 0),
+ (ed_fieldx * MINI_TILEX) - (dx != 0 ? MINI_TILEX : 0),
+ (ed_fieldy * MINI_TILEY) - (dy != 0 ? MINI_TILEY : 0),
+ SX + (dx == +1 ? MINI_TILEX : 0),
+ SY + (dy == +1 ? MINI_TILEY : 0));
+ if (dx)
+ {
+ x = (dx == 1 ? 0 : ed_fieldx - 1);
+ for(y=0; y<ed_fieldy; y++)
+ DrawMiniElementOrWall(x, y, from_x, from_y);
+ }
+ else if (dy)
+ {
+ y = (dy == 1 ? 0 : ed_fieldy - 1);
+ for(x=0; x<ed_fieldx; x++)
+ DrawMiniElementOrWall(x, y, from_x, from_y);
+ }
+
+ redraw_mask |= REDRAW_FIELD;
+ BackToFront();
+}
+
+static void CreateControlButtons()
+{
+ Pixmap gd_pixmap = pix[PIX_DOOR];
+ struct GadgetInfo *gi;
+ unsigned long event_mask;
+ int i;
+
+ /* create toolbox buttons */
+ for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
+ {
+ int id = i;
+ int width, height;
+ int gd_xoffset, gd_yoffset;
+ int gd_x1, gd_x2, gd_y1, gd_y2;
+ int button_type;
+ int radio_button_nr;
+ boolean checked;
+
+ if (id == GADGET_ID_SINGLE_ITEMS ||
+ id == GADGET_ID_CONNECTED_ITEMS ||
+ id == GADGET_ID_LINE ||
+ id == GADGET_ID_ARC ||
+ id == GADGET_ID_TEXT ||
+ id == GADGET_ID_RECTANGLE ||
+ id == GADGET_ID_FILLED_BOX ||
+ id == GADGET_ID_FLOOD_FILL ||
+ id == GADGET_ID_GRAB_BRUSH ||
+ id == GADGET_ID_PICK_ELEMENT)
+ {
+ button_type = GD_TYPE_RADIO_BUTTON;
+ radio_button_nr = RADIO_NR_DRAWING_TOOLBOX;
+ checked = (id == drawing_function ? TRUE : FALSE);
+ event_mask = GD_EVENT_PRESSED;
+ }
+ else
+ {
+ button_type = GD_TYPE_NORMAL_BUTTON;
+ radio_button_nr = RADIO_NR_NONE;
+ checked = FALSE;
+
+ if (id == GADGET_ID_WRAP_LEFT ||
+ id == GADGET_ID_WRAP_RIGHT ||
+ id == GADGET_ID_WRAP_UP ||
+ id == GADGET_ID_WRAP_DOWN)
+ event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
+ else
+ event_mask = GD_EVENT_RELEASED;
+ }
+
+ if (id < ED_NUM_CTRL1_BUTTONS)
+ {
+ int x = i % ED_CTRL1_BUTTONS_HORIZ;
+ int y = i / ED_CTRL1_BUTTONS_HORIZ;
+
+ gd_xoffset = ED_CTRL1_BUTTONS_XPOS + x * ED_CTRL1_BUTTON_XSIZE;
+ gd_yoffset = ED_CTRL1_BUTTONS_YPOS + y * ED_CTRL1_BUTTON_YSIZE;
+ width = ED_CTRL1_BUTTON_XSIZE;
+ height = ED_CTRL1_BUTTON_YSIZE;
+ }
+ else
+ {
+ int x = (i - ED_NUM_CTRL1_BUTTONS) % ED_CTRL2_BUTTONS_HORIZ;
+ int y = (i - ED_NUM_CTRL1_BUTTONS) / ED_CTRL2_BUTTONS_HORIZ;
+
+ gd_xoffset = ED_CTRL2_BUTTONS_XPOS + x * ED_CTRL2_BUTTON_XSIZE;
+ gd_yoffset = ED_CTRL2_BUTTONS_YPOS + y * ED_CTRL2_BUTTON_YSIZE;
+ width = ED_CTRL2_BUTTON_XSIZE;
+ height = ED_CTRL2_BUTTON_YSIZE;
+ }
+
+ gd_x1 = DOOR_GFX_PAGEX8 + gd_xoffset;
+ gd_x2 = DOOR_GFX_PAGEX7 + gd_xoffset;
+ gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_GFX_YPOS + gd_yoffset;
+ gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL_BUTTONS_ALT_GFX_YPOS + gd_yoffset;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, control_info[i].text,
+ GDI_X, EX + gd_xoffset,
+ GDI_Y, EY + gd_yoffset,
+ GDI_WIDTH, width,
+ GDI_HEIGHT, height,
+ GDI_TYPE, button_type,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_RADIO_NR, radio_button_nr,
+ GDI_CHECKED, checked,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y1,
+ GDI_ALT_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y2,
+ GDI_ALT_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y2,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+
+ /* create buttons for scrolling of drawing area and element list */
+ for (i=0; i<ED_NUM_SCROLLBUTTONS; i++)
+ {
+ int id = scrollbutton_info[i].gadget_id;
+ int x, y, width, height;
+ int gd_x1, gd_x2, gd_y1, gd_y2;
+
+ x = scrollbutton_info[i].x;
+ y = scrollbutton_info[i].y;
+
+ event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
+
+ if (id == GADGET_ID_ELEMENTLIST_UP ||
+ id == GADGET_ID_ELEMENTLIST_DOWN)
+ {
+ x += DX;
+ y += DY;
+ width = ED_ELEMENTLIST_UPDOWN_XSIZE;
+ height = ED_ELEMENTLIST_UPDOWN_YSIZE;
+ gd_x1 = DOOR_GFX_PAGEX6 + scrollbutton_info[i].xpos;
+ gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].y;
+ gd_x2 = gd_x1;
+ gd_y2 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].ypos;
+ }
+ else
+ {
+ x += SX;
+ y += SY;
+ width = ED_SCROLLBUTTON_XSIZE;
+ height = ED_SCROLLBUTTON_YSIZE;
+ gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].xpos;
+ gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].ypos;
+ gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
+ gd_y2 = gd_y1;
+ }
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, scrollbutton_info[i].infotext,
+ GDI_X, x,
+ GDI_Y, y,
+ GDI_WIDTH, width,
+ GDI_HEIGHT, height,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y2,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+
+ /* create buttons for element list */
+ for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
+ {
+ Pixmap deco_pixmap;
+ int deco_x, deco_y, deco_xpos, deco_ypos;
+ int gd_xoffset, gd_yoffset;
+ int gd_x, gd_y1, gd_y2;
+ int x = i % ED_ELEMENTLIST_BUTTONS_HORIZ;
+ int y = i / ED_ELEMENTLIST_BUTTONS_HORIZ;
+ int id = GADGET_ID_ELEMENTLIST_FIRST + i;
+
+ event_mask = GD_EVENT_RELEASED;
+
+ gd_xoffset = ED_ELEMENTLIST_XPOS + x * ED_ELEMENTLIST_XSIZE;
+ gd_yoffset = ED_ELEMENTLIST_YPOS + y * ED_ELEMENTLIST_YSIZE;
+
+ gd_x = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS;
+ gd_y1 = DOOR_GFX_PAGEY1 + ED_ELEMENTLIST_YPOS;
+ gd_y2 = DOOR_GFX_PAGEY1 + ED_ELEMENTLIST_ALT_YPOS;
+
+ getMiniGraphicSource(el2gfx(editor_element[i]),
+ &deco_pixmap, &deco_x, &deco_y);
+ deco_xpos = (ED_ELEMENTLIST_XSIZE - MINI_TILEX) / 2;
+ deco_ypos = (ED_ELEMENTLIST_YSIZE - MINI_TILEY) / 2;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, element_info[editor_element[i]],
+ GDI_X, DX + gd_xoffset,
+ GDI_Y, DY + gd_yoffset,
+ GDI_WIDTH, ED_ELEMENTLIST_XSIZE,
+ GDI_HEIGHT, ED_ELEMENTLIST_YSIZE,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x, gd_y1,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x, gd_y2,
+ GDI_DECORATION_DESIGN, deco_pixmap, deco_x, deco_y,
+ GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
+ GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY,
+ GDI_DECORATION_SHIFTING, 1, 1,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
+static void CreateCounterButtons()
+{
+ int i;
+
+ for (i=0; i<ED_NUM_COUNTERBUTTONS; i++)
+ {
+ int j;
+ int xpos = SX + counterbutton_info[i].x; /* xpos of down count button */
+ int ypos = SY + counterbutton_info[i].y;
+
+ for (j=0; j<2; j++)
+ {
+ Pixmap gd_pixmap = pix[PIX_DOOR];
+ struct GadgetInfo *gi;
+ int id = (j == 0 ?
+ counterbutton_info[i].gadget_id_down :
+ counterbutton_info[i].gadget_id_up);
+ int gd_xoffset;
+ int gd_x, gd_x1, gd_x2, gd_y;
+ unsigned long event_mask;
+ char infotext[MAX_INFOTEXT_LEN + 1];
+
+ event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
+
+ gd_xoffset = (j == 0 ? ED_BUTTON_MINUS_XPOS : ED_BUTTON_PLUS_XPOS);
+ gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
+ gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
+ gd_y = DOOR_GFX_PAGEY1 + ED_BUTTON_COUNT_YPOS;
+
+ sprintf(infotext, "%s counter value by 1, 5 or 10",
+ (j == 0 ? "decrease" : "increase"));
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, infotext,
+ GDI_X, xpos,
+ GDI_Y, ypos,
+ GDI_WIDTH, ED_BUTTON_COUNT_XSIZE,
+ GDI_HEIGHT, ED_BUTTON_COUNT_YSIZE,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleCounterButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ xpos += gi->width + ED_GADGET_DISTANCE; /* xpos of text count button */
+
+ if (j == 0)
+ {
+ id = counterbutton_info[i].gadget_id_text;
+ event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
+
+ gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
+ gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, "enter counter value",
+ GDI_X, xpos,
+ GDI_Y, ypos,
+ GDI_TYPE, GD_TYPE_TEXTINPUT_NUMERIC,
+ GDI_NUMBER_VALUE, 0,
+ GDI_NUMBER_MIN, counterbutton_info[i].min_value,
+ GDI_NUMBER_MAX, counterbutton_info[i].max_value,
+ GDI_TEXT_SIZE, 3,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x, gd_y,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x, gd_y,
+ GDI_DESIGN_BORDER, ED_BORDER_SIZE,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleCounterButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ xpos += gi->width + ED_GADGET_DISTANCE; /* xpos of up count button */
+ }
+ }
+ }
+}
+
+static void CreateDrawingAreas()
+{
+ struct GadgetInfo *gi;
+ unsigned long event_mask;
+ int id;
+ int i;
+
+ event_mask =
+ GD_EVENT_PRESSED | GD_EVENT_RELEASED | GD_EVENT_MOVING |
+ GD_EVENT_OFF_BORDERS;
+
+ /* one for the level drawing area ... */
+ id = GADGET_ID_DRAWING_LEVEL;
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_X, SX,
+ GDI_Y, SY,
+ GDI_TYPE, GD_TYPE_DRAWING_AREA,
+ GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
+ GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
+ GDI_CALLBACK_ACTION, HandleDrawingAreas,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+
+ /* ... up to eight areas for element content ... */
+ for (i=0; i<MAX_ELEM_CONTENT; i++)
+ {
+ int gx = SX + ED_AREA_ELEM_CONTENT_XPOS + 5 * (i % 4) * MINI_TILEX;
+ int gy = SX + ED_AREA_ELEM_CONTENT_YPOS + 6 * (i / 4) * MINI_TILEY;
+
+ id = GADGET_ID_ELEM_CONTENT_0 + i;
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_X, gx,
+ GDI_Y, gy,
+ GDI_WIDTH, 3 * MINI_TILEX,
+ GDI_HEIGHT, 3 * MINI_TILEY,
+ GDI_TYPE, GD_TYPE_DRAWING_AREA,
+ GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
+ GDI_CALLBACK_ACTION, HandleDrawingAreas,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+
+ /* ... one for the amoeba content */
+ id = GADGET_ID_AMOEBA_CONTENT;
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_X, SX + ED_AREA_ELEM_CONTENT_XPOS,
+ GDI_Y, SY + ED_AREA_ELEM_CONTENT_YPOS,
+ GDI_WIDTH, MINI_TILEX,
+ GDI_HEIGHT, MINI_TILEY,
+ GDI_TYPE, GD_TYPE_DRAWING_AREA,
+ GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
+ GDI_CALLBACK_ACTION, HandleDrawingAreas,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+
+ /* ... and one for random placement background restrictions */
+
+ id = GADGET_ID_RANDOM_BACKGROUND;
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_X, SX + ED_AREA_RANDOM_BACKGROUND_XPOS,
+ GDI_Y, SY + ED_AREA_RANDOM_BACKGROUND_YPOS,
+ GDI_WIDTH, MINI_TILEX,
+ GDI_HEIGHT, MINI_TILEY,
+ GDI_TYPE, GD_TYPE_DRAWING_AREA,
+ GDI_ITEM_SIZE, MINI_TILEX, MINI_TILEY,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_INFO, HandleDrawingAreaInfo,
+ GDI_CALLBACK_ACTION, HandleDrawingAreas,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+}
+
+static void CreateTextInputGadgets()
+{
+ int i;
+
+ for (i=0; i<ED_NUM_TEXTINPUT; i++)
+ {
+ Pixmap gd_pixmap = pix[PIX_DOOR];
+ int gd_x, gd_y;
+ struct GadgetInfo *gi;
+ unsigned long event_mask;
+ char infotext[1024];
+ int id = textinput_info[i].gadget_id;
+
+ event_mask = GD_EVENT_TEXT_RETURN | GD_EVENT_TEXT_LEAVING;
+
+ gd_x = DOOR_GFX_PAGEX4 + ED_WIN_COUNT_XPOS;
+ gd_y = DOOR_GFX_PAGEY1 + ED_WIN_COUNT_YPOS;
+
+ sprintf(infotext, "Enter %s", textinput_info[i].infotext);
+ infotext[MAX_INFOTEXT_LEN] = '\0';
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, infotext,
+ GDI_X, SX + textinput_info[i].x,
+ GDI_Y, SY + textinput_info[i].y,
+ GDI_TYPE, GD_TYPE_TEXTINPUT_ALPHANUMERIC,
+ GDI_TEXT_VALUE, textinput_info[i].value,
+ GDI_TEXT_SIZE, textinput_info[i].size,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x, gd_y,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x, gd_y,
+ GDI_DESIGN_BORDER, ED_BORDER_SIZE,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleTextInputGadgets,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
+static void CreateScrollbarGadgets()
+{
+ int i;
+
+ for (i=0; i<ED_NUM_SCROLLBARS; i++)
+ {
+ int id = scrollbar_info[i].gadget_id;
+ Pixmap gd_pixmap = pix[PIX_DOOR];
+ int gd_x1, gd_x2, gd_y1, gd_y2;
+ struct GadgetInfo *gi;
+ int items_max, items_visible, item_position;
+ unsigned long event_mask;
+
+ if (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL)
+ {
+ items_max = MAX(lev_fieldx + 2, ed_fieldx);
+ items_visible = ed_fieldx;
+ item_position = 0;
+ }
+ else
+ {
+ items_max = MAX(lev_fieldy + 2, ed_fieldy);
+ items_visible = ed_fieldy;
+ item_position = 0;
+ }
+
+ event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
+
+ gd_x1 = DOOR_GFX_PAGEX8 + scrollbar_info[i].xpos;
+ gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
+ gd_y1 = DOOR_GFX_PAGEY1 + scrollbar_info[i].ypos;
+ gd_y2 = DOOR_GFX_PAGEY1 + scrollbar_info[i].ypos;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, scrollbar_info[i].infotext,
+ GDI_X, SX + scrollbar_info[i].x,
+ GDI_Y, SY + scrollbar_info[i].y,
+ GDI_WIDTH, scrollbar_info[i].width,
+ GDI_HEIGHT, scrollbar_info[i].height,
+ GDI_TYPE, scrollbar_info[i].type,
+ GDI_SCROLLBAR_ITEMS_MAX, items_max,
+ GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
+ GDI_SCROLLBAR_ITEM_POSITION, item_position,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y1,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y2,
+ GDI_DESIGN_BORDER, ED_BORDER_SIZE,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
+static void CreateCheckbuttonGadgets()
+{
+ Pixmap gd_pixmap = pix[PIX_DOOR];
+ struct GadgetInfo *gi;
+ unsigned long event_mask;
+ int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
+ boolean checked;
+ int i;
+
+ event_mask = GD_EVENT_PRESSED;
+
+ gd_x1 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_UNCHECKED_XPOS;
+ gd_x2 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_UNCHECKED_XPOS;
+ gd_x3 = DOOR_GFX_PAGEX4 + ED_CHECKBUTTON_CHECKED_XPOS;
+ gd_x4 = DOOR_GFX_PAGEX3 + ED_CHECKBUTTON_CHECKED_XPOS;
+ gd_y = DOOR_GFX_PAGEY1 + ED_CHECKBUTTON_YPOS;
+
+ for (i=0; i<ED_NUM_RADIOBUTTONS; i++)
+ {
+ int id = radiobutton_info[i].gadget_id;
+
+ checked =
+ (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, radiobutton_info[i].infotext,
+ GDI_X, SX + radiobutton_info[i].x,
+ GDI_Y, SY + radiobutton_info[i].y,
+ GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
+ GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
+ GDI_TYPE, GD_TYPE_RADIO_BUTTON,
+ GDI_RADIO_NR, radiobutton_info[i].radio_button_nr,
+ GDI_CHECKED, checked,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y,
+ GDI_ALT_DESIGN_UNPRESSED, gd_pixmap, gd_x3, gd_y,
+ GDI_ALT_DESIGN_PRESSED, gd_pixmap, gd_x4, gd_y,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+
+ for (i=0; i<ED_NUM_CHECKBUTTONS; i++)
+ {
+ int id = checkbutton_info[i].gadget_id;
+
+ if (id == GADGET_ID_STICK_ELEMENT)
+ gd_y = DOOR_GFX_PAGEY1 + ED_STICKYBUTTON_YPOS;
+ else
+ gd_y = DOOR_GFX_PAGEY1 + ED_CHECKBUTTON_YPOS;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, checkbutton_info[i].infotext,
+ GDI_X, SX + checkbutton_info[i].x,
+ GDI_Y, SY + checkbutton_info[i].y,
+ GDI_WIDTH, ED_CHECKBUTTON_XSIZE,
+ GDI_HEIGHT, ED_CHECKBUTTON_YSIZE,
+ GDI_TYPE, GD_TYPE_CHECK_BUTTON,
+ GDI_CHECKED, *checkbutton_info[i].value,
+ GDI_DESIGN_UNPRESSED, gd_pixmap, gd_x1, gd_y,
+ GDI_DESIGN_PRESSED, gd_pixmap, gd_x2, gd_y,
+ GDI_ALT_DESIGN_UNPRESSED, gd_pixmap, gd_x3, gd_y,
+ GDI_ALT_DESIGN_PRESSED, gd_pixmap, gd_x4, gd_y,
+ GDI_EVENT_MASK, event_mask,
+ GDI_CALLBACK_ACTION, HandleControlButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ level_editor_gadget[id] = gi;
+ }
+}
+
+void CreateLevelEditorGadgets()
+{
+ CreateControlButtons();
+ CreateCounterButtons();
+ CreateDrawingAreas();
+ CreateTextInputGadgets();
+ CreateScrollbarGadgets();
+ CreateCheckbuttonGadgets();
+}
+
+static void MapControlButtons()
+{
+ int i;
+
+ for (i=0; i<ED_NUM_CTRL_BUTTONS; i++)
+ MapGadget(level_editor_gadget[i]);
+ for (i=0; i<ED_NUM_ELEMENTLIST_BUTTONS; i++)
+ MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
+}
+
+static void MapCounterButtons(int id)
+{
+ MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_down]);
+ MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_text]);
+ MapGadget(level_editor_gadget[counterbutton_info[id].gadget_id_up]);
+}
+
+static void MapDrawingArea(int id)
+{
+ MapGadget(level_editor_gadget[id]);
+}
+
+static void MapTextInputGadget(int id)
+{
+ MapGadget(level_editor_gadget[textinput_info[id].gadget_id]);
+}
+
+static void MapRadiobuttonGadget(int id)
+{
+ MapGadget(level_editor_gadget[radiobutton_info[id].gadget_id]);
+}
+
+static void MapCheckbuttonGadget(int id)
+{
+ MapGadget(level_editor_gadget[checkbutton_info[id].gadget_id]);
+}
+
+static void MapMainDrawingArea()
+{
+ boolean no_horizontal_scrollbar = (lev_fieldx + 2 <= ed_fieldx);
+ boolean no_vertical_scrollbar = (lev_fieldy + 2 <= ed_fieldy);
+ int i;
+
+ for (i=0; i<ED_NUM_SCROLLBUTTONS; i++)
+ {
+ if (((i == ED_SCROLLBUTTON_ID_AREA_LEFT ||
+ i == ED_SCROLLBUTTON_ID_AREA_RIGHT) &&
+ no_horizontal_scrollbar) ||
+ ((i == ED_SCROLLBUTTON_ID_AREA_UP ||
+ i == ED_SCROLLBUTTON_ID_AREA_DOWN) &&
+ no_vertical_scrollbar))
+ continue;
+
+ MapGadget(level_editor_gadget[scrollbutton_info[i].gadget_id]);
+ }
+
+ for (i=0; i<ED_NUM_SCROLLBARS; i++)
+ {
+ if ((i == ED_SCROLLBAR_ID_HORIZONTAL && no_horizontal_scrollbar) ||
+ (i == ED_SCROLLBAR_ID_VERTICAL && no_vertical_scrollbar))
+ continue;
+
+ MapGadget(level_editor_gadget[scrollbar_info[i].gadget_id]);
+ }
+
+ MapDrawingArea(GADGET_ID_DRAWING_LEVEL);
+}
+
+static void UnmapDrawingArea(int id)
+{
+ UnmapGadget(level_editor_gadget[id]);
+}
+
+void UnmapLevelEditorWindowGadgets()
+{
+ int i;
+
+ for (i=0; i<NUM_EDITOR_GADGETS; i++)
+ if (level_editor_gadget[i]->x < DX)
+ UnmapGadget(level_editor_gadget[i]);
+}
+
+void UnmapLevelEditorGadgets()
+{
+ int i;
+
+ for (i=0; i<NUM_EDITOR_GADGETS; i++)
+ UnmapGadget(level_editor_gadget[i]);
+}
+