+ if (level_editor_test_game)
+ {
+ CopyPlayfield(Ur, Feld);
+ CopyPlayfield(FieldBackup, Ur);
+
+ level_editor_test_game = FALSE;
+ }
+ else
+ {
+ edit_mode = ED_MODE_DRAWING;
+
+ ResetUndoBuffer();
+ level_xpos = -1;
+ level_ypos = -1;
+ }
+
+ /* copy default editor door content to main double buffer */
+ BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
+ DOOR_GFX_PAGEX6, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
+
+ /* draw mouse button brush elements */
+ DrawMiniGraphicExt(drawto,
+ DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS,
+ el2edimg(new_element1));
+ DrawMiniGraphicExt(drawto,
+ DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS,
+ el2edimg(new_element2));
+ DrawMiniGraphicExt(drawto,
+ DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS,
+ el2edimg(new_element3));
+
+ /* draw bigger door */
+ DrawSpecialEditorDoor();
+
+ /* draw new control window */
+ BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
+ DOOR_GFX_PAGEX8, 236, EXSIZE, EYSIZE, EX, EY);
+
+ redraw_mask |= REDRAW_ALL;
+
+ ReinitializeElementListButtons(); /* only needed after setup changes */
+
+ UnmapTapeButtons();
+ MapControlButtons();
+
+ /* copy actual editor door content to door double buffer for OpenDoor() */
+ BlitBitmap(drawto, bitmap_db_door,
+ DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
+
+ DrawEditModeWindow();
+
+ OpenDoor(DOOR_OPEN_1);
+}
+
+static void AdjustDrawingAreaGadgets()
+{
+ int ed_xsize = lev_fieldx + 2;
+ int ed_ysize = lev_fieldy + 2;
+ int max_ed_fieldx = MAX_ED_FIELDX;
+ int max_ed_fieldy = MAX_ED_FIELDY;
+ boolean horizontal_scrollbar_needed;
+ boolean vertical_scrollbar_needed;
+ int x, y, width, height;
+ int xoffset, yoffset;
+
+ /* check if we need any scrollbars */
+ horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
+ vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
+
+ /* check if we have a smaller editor field because of scrollbars */
+ if (horizontal_scrollbar_needed)
+ max_ed_fieldy = MAX_ED_FIELDY - 1;
+ if (vertical_scrollbar_needed)
+ max_ed_fieldx = MAX_ED_FIELDX - 1;
+
+ /* check again if we now need more scrollbars because of less space */
+ horizontal_scrollbar_needed = (ed_xsize > max_ed_fieldx);
+ vertical_scrollbar_needed = (ed_ysize > max_ed_fieldy);
+
+ /* check if editor field gets even smaller after adding new scrollbars */
+ if (horizontal_scrollbar_needed)
+ max_ed_fieldy = MAX_ED_FIELDY - 1;
+ if (vertical_scrollbar_needed)
+ max_ed_fieldx = MAX_ED_FIELDX - 1;
+
+ ed_fieldx = (ed_xsize < MAX_ED_FIELDX ? ed_xsize : max_ed_fieldx);
+ ed_fieldy = (ed_ysize < MAX_ED_FIELDY ? ed_ysize : max_ed_fieldy);
+
+ ModifyGadget(level_editor_gadget[GADGET_ID_DRAWING_LEVEL],
+ GDI_WIDTH, ed_fieldx * MINI_TILEX,
+ GDI_HEIGHT, ed_fieldy * MINI_TILEY,
+ GDI_AREA_SIZE, ed_fieldx, ed_fieldy,
+ GDI_END);
+
+ xoffset = (ed_fieldx == MAX_ED_FIELDX ? ED_SCROLLBUTTON_XSIZE : 0);
+ yoffset = (ed_fieldy == MAX_ED_FIELDY ? ED_SCROLLBUTTON_YSIZE : 0);
+
+ x = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset;
+ y = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset;
+
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT], GDI_X, x, GDI_END);
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN], GDI_Y, y, GDI_END);
+
+ width = scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset;
+ height = scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset;
+
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
+ GDI_WIDTH, width,
+ GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldx,
+ GDI_END);
+ ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_VERTICAL],
+ GDI_HEIGHT, height,
+ GDI_SCROLLBAR_ITEMS_VISIBLE, ed_fieldy,
+ GDI_END);
+}
+
+static void AdjustLevelScrollPosition()
+{
+ if (level_xpos < -1)
+ level_xpos = -1;
+ if (level_xpos > lev_fieldx - ed_fieldx + 1)
+ level_xpos = lev_fieldx - ed_fieldx + 1;
+ if (lev_fieldx < ed_fieldx - 2)
+ level_xpos = -1;
+
+ if (level_ypos < -1)
+ level_ypos = -1;
+ if (level_ypos > lev_fieldy - ed_fieldy + 1)
+ level_ypos = lev_fieldy - ed_fieldy + 1;
+ if (lev_fieldy < ed_fieldy - 2)
+ level_ypos = -1;
+}
+
+static void AdjustEditorScrollbar(int id)
+{
+ struct GadgetInfo *gi = level_editor_gadget[id];
+ int items_max, items_visible, item_position;
+
+ if (id == GADGET_ID_SCROLL_HORIZONTAL)
+ {
+ items_max = MAX(lev_fieldx + 2, ed_fieldx);
+ items_visible = ed_fieldx;
+ item_position = level_xpos + 1;
+ }
+ else
+ {
+ items_max = MAX(lev_fieldy + 2, ed_fieldy);
+ items_visible = ed_fieldy;
+ item_position = level_ypos + 1;
+ }
+
+ if (item_position > items_max - items_visible)
+ item_position = items_max - items_visible;
+
+ ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max,
+ GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END);
+}
+
+static void ModifyEditorTextInput(int textinput_id, char *new_text)
+{
+ int gadget_id = textinput_info[textinput_id].gadget_id;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+
+ ModifyGadget(gi, GDI_TEXT_VALUE, new_text, GDI_END);
+}
+
+static void ModifyEditorCounter(int counter_id, int new_value)
+{
+ int *counter_value = counterbutton_info[counter_id].value;
+ int gadget_id = counterbutton_info[counter_id].gadget_id_text;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+
+ ModifyGadget(gi, GDI_NUMBER_VALUE, new_value, GDI_END);
+
+ if (counter_value != NULL)
+ *counter_value = gi->text.number_value;
+}
+
+static void ModifyEditorCounterLimits(int counter_id, int min, int max)
+{
+ int gadget_id = counterbutton_info[counter_id].gadget_id_text;
+ struct GadgetInfo *gi = level_editor_gadget[gadget_id];
+
+ ModifyGadget(gi, GDI_NUMBER_MIN, min, GDI_NUMBER_MAX, max, GDI_END);
+}
+
+static void PickDrawingElement(int button, int element)
+{
+ if (button < 1 || button > 3)
+ return;
+
+ if (button == 1)
+ {
+ new_element1 = element;
+ DrawMiniGraphicExt(drawto,
+ DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS,
+ el2edimg(new_element1));
+ }
+ else if (button == 2)
+ {
+ new_element2 = element;
+ DrawMiniGraphicExt(drawto,
+ DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS,
+ el2edimg(new_element2));
+ }
+ else
+ {
+ new_element3 = element;
+ DrawMiniGraphicExt(drawto,
+ DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS,
+ el2edimg(new_element3));
+ }
+
+ redraw_mask |= REDRAW_DOOR_1;
+}
+
+static void DrawDrawingWindow()
+{
+ SetMainBackgroundImage(IMG_UNDEFINED);
+ ClearWindow();
+ UnmapLevelEditorWindowGadgets();
+
+ AdjustDrawingAreaGadgets();
+ AdjustLevelScrollPosition();
+ AdjustEditorScrollbar(GADGET_ID_SCROLL_HORIZONTAL);
+ AdjustEditorScrollbar(GADGET_ID_SCROLL_VERTICAL);
+
+ DrawMiniLevel(ed_fieldx, ed_fieldy, level_xpos, level_ypos);
+ MapMainDrawingArea();
+}
+
+static void DrawElementBorder(int dest_x, int dest_y, int width, int height)
+{
+ int border_graphic = IMG_EDITOR_ELEMENT_BORDER;
+ Bitmap *src_bitmap;
+ int src_x, src_y;
+ int num_mini_tilex = width / MINI_TILEX + 1;
+ int num_mini_tiley = width / MINI_TILEY + 1;
+ int x, y;
+
+ getMiniGraphicSource(border_graphic, &src_bitmap, &src_x, &src_y);
+
+ for (y=0; y < num_mini_tiley; y++)
+ for (x=0; x < num_mini_tilex; x++)
+ BlitBitmap(src_bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
+ dest_x - MINI_TILEX / 2 + x * MINI_TILEX,
+ dest_y - MINI_TILEY / 2 + y * MINI_TILEY);
+
+ ClearRectangle(drawto, dest_x - 1, dest_y - 1, width + 2, height + 2);
+}
+
+static void DrawRandomPlacementBackgroundArea()
+{
+ int area_x = ED_AREA_RANDOM_BACKGROUND_XPOS / MINI_TILEX;
+ int area_y = ED_AREA_RANDOM_BACKGROUND_YPOS / MINI_TILEY;
+ int area_sx = SX + ED_AREA_RANDOM_BACKGROUND_XPOS;
+ int area_sy = SY + ED_AREA_RANDOM_BACKGROUND_YPOS;
+
+ ElementContent[0][0][0] = random_placement_background_element;
+
+ DrawElementBorder(area_sx, area_sy, MINI_TILEX, MINI_TILEY);
+ DrawMiniElement(area_x, area_y, ElementContent[0][0][0]);
+
+ MapDrawingArea(GADGET_ID_RANDOM_BACKGROUND);
+}
+
+static void DrawLevelInfoWindow()
+{
+ char infotext[MAX_OUTPUT_LINESIZE + 1];
+ int max_infotext_len = getMaxInfoTextLength();
+ int xoffset_above = 0;
+ int yoffset_above = -(MINI_TILEX + ED_GADGET_DISTANCE);
+ int xoffset_right = getCounterGadgetWidth();
+ int yoffset_right = ED_BORDER_SIZE;
+ int xoffset_right2 = ED_CHECKBUTTON_XSIZE + 2 * ED_GADGET_DISTANCE;
+ int yoffset_right2 = ED_BORDER_SIZE;
+ int i, x, y;
+
+ SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
+ ClearWindow();
+ UnmapLevelEditorWindowGadgets();
+
+ DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS_YPOS,
+ "Level Settings", FONT_TITLE_1);
+ DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS2_YPOS,
+ "Editor Settings", FONT_TITLE_1);
+
+ /* draw counter gadgets */
+ for (i=ED_COUNTER_ID_LEVEL_FIRST; i<=ED_COUNTER_ID_LEVEL_LAST; i++)
+ {
+ if (counterbutton_info[i].infotext_above)
+ {
+ x = counterbutton_info[i].x + xoffset_above;
+ y = counterbutton_info[i].y + yoffset_above;
+
+ sprintf(infotext, "%s:", counterbutton_info[i].infotext_above);
+ infotext[max_infotext_len] = '\0';
+ DrawTextF(x, y, FONT_TEXT_1, infotext);
+ }
+
+ if (counterbutton_info[i].infotext_right)
+ {
+ x = counterbutton_info[i].x + xoffset_right;
+ y = counterbutton_info[i].y + yoffset_right;
+
+ sprintf(infotext, "%s", counterbutton_info[i].infotext_right);
+ infotext[max_infotext_len] = '\0';
+ DrawTextF(x, y, FONT_TEXT_1, infotext);
+ }
+
+ ModifyEditorCounter(i, *counterbutton_info[i].value);
+ MapCounterButtons(i);
+ }
+
+ /* draw text input gadgets */
+ for (i=ED_TEXTINPUT_ID_LEVEL_FIRST; i<=ED_TEXTINPUT_ID_LEVEL_LAST; i++)
+ {
+ x = textinput_info[i].x + xoffset_above;
+ y = textinput_info[i].y + yoffset_above;
+
+ sprintf(infotext, "%s:", textinput_info[i].infotext);
+ infotext[max_infotext_len] = '\0';
+
+ DrawTextF(x, y, FONT_TEXT_1, infotext);
+ ModifyEditorTextInput(i, textinput_info[i].value);
+ MapTextInputGadget(i);
+ }
+
+ /* draw radiobutton gadgets */
+ for (i=ED_RADIOBUTTON_ID_LEVEL_FIRST; i<=ED_RADIOBUTTON_ID_LEVEL_LAST; i++)
+ {
+ boolean checked =
+ (*radiobutton_info[i].value == radiobutton_info[i].checked_value);
+
+ x = radiobutton_info[i].x + xoffset_right2;
+ y = radiobutton_info[i].y + yoffset_right2;
+
+ DrawTextF(x, y, FONT_TEXT_1, radiobutton_info[i].text);
+ ModifyGadget(level_editor_gadget[radiobutton_info[i].gadget_id],
+ GDI_CHECKED, checked, GDI_END);
+ MapRadiobuttonGadget(i);
+ }
+
+ /* draw checkbutton gadgets */
+ for (i=ED_CHECKBUTTON_ID_LEVEL_FIRST; i<=ED_CHECKBUTTON_ID_LEVEL_LAST; i++)
+ {
+ x = checkbutton_info[i].x + xoffset_right2;
+ y = checkbutton_info[i].y + yoffset_right2;
+
+ DrawTextF(x, y, FONT_TEXT_1, checkbutton_info[i].text);
+ ModifyGadget(level_editor_gadget[checkbutton_info[i].gadget_id],
+ GDI_CHECKED, *checkbutton_info[i].value, GDI_END);
+ MapCheckbuttonGadget(i);
+ }
+
+ /* draw drawing area */
+ DrawRandomPlacementBackgroundArea();
+}
+
+static void DrawAmoebaContentArea()
+{
+ int area_x = ED_AREA_ELEM_CONTENT_XPOS / MINI_TILEX;
+ int area_y = ED_AREA_ELEM_CONTENT_YPOS / MINI_TILEY;
+ int area_sx = SX + ED_AREA_ELEM_CONTENT_XPOS;
+ int area_sy = SY + ED_AREA_ELEM_CONTENT_YPOS;
+
+ ElementContent[0][0][0] = level.amoeba_content;
+
+ DrawElementBorder(area_sx, area_sy, MINI_TILEX, MINI_TILEY);
+ DrawMiniElement(area_x, area_y, ElementContent[0][0][0]);
+
+ DrawText(area_sx + TILEX, area_sy + 1, "Content of amoeba", FONT_TEXT_1);
+
+ MapDrawingArea(GADGET_ID_AMOEBA_CONTENT);
+}
+
+static void DrawElementContentAreas()
+{
+ int counter_id = ED_COUNTER_ID_ELEM_CONTENT;
+ int area_x = ED_AREA_ELEM_CONTENT_XPOS / MINI_TILEX;
+ int area_y = ED_AREA_ELEM_CONTENT_YPOS / MINI_TILEY;
+ int area_sx = SX + ED_AREA_ELEM_CONTENT_XPOS;
+ int area_sy = SY + ED_AREA_ELEM_CONTENT_YPOS;
+ int xoffset_right = getCounterGadgetWidth();
+ int yoffset_right = ED_BORDER_SIZE;
+ int i, x, y;
+
+ for (i=0; i<MAX_ELEMENT_CONTENTS; i++)
+ for (y=0; y<3; y++)
+ for (x=0; x<3; x++)
+ ElementContent[i][x][y] = level.yam_content[i][x][y];
+
+ for (i=0; i<MAX_ELEMENT_CONTENTS; i++)
+ UnmapDrawingArea(GADGET_ID_ELEM_CONTENT_0 + i);
+
+ /* display counter to choose number of element content areas */
+ x = counterbutton_info[counter_id].x + xoffset_right;
+ y = counterbutton_info[counter_id].y + yoffset_right;
+ DrawTextF(x, y, FONT_TEXT_1, "number of content areas");
+
+ ModifyEditorCounter(counter_id, *counterbutton_info[counter_id].value);
+ MapCounterButtons(counter_id);
+
+ /* delete content areas in case of reducing number of them */
+ DrawBackground(SX, area_sy - MINI_TILEX, SXSIZE, 12 * MINI_TILEY);
+
+ for (i=0; i<level.num_yam_contents; i++)
+ DrawElementBorder(area_sx + 5 * (i % 4) * MINI_TILEX,
+ area_sy + 6 * (i / 4) * MINI_TILEY,
+ 3 * MINI_TILEX, 3 * MINI_TILEY);