updated contact info in source file headers
[rocksndiamonds.git] / src / editor.c
index 83df2e15c5048d51ef8dc7bce33d29cc7f367ec4..9ce3bd5b1369f4b622be84da24beb02da8af7865 100644 (file)
@@ -1,15 +1,13 @@
-/***********************************************************
-* Rocks'n'Diamonds -- McDuffin Strikes Back!               *
-*----------------------------------------------------------*
-* (c) 1995-2006 Artsoft Entertainment                      *
-*               Holger Schemel                             *
-*               Detmolder Strasse 189                      *
-*               33604 Bielefeld                            *
-*               Germany                                    *
-*               e-mail: info@artsoft.org                   *
-*----------------------------------------------------------*
-* editor.c                                                 *
-***********************************************************/
+// ============================================================================
+// Rocks'n'Diamonds - McDuffin Strikes Back!
+// ----------------------------------------------------------------------------
+// (c) 1995-2014 by Artsoft Entertainment
+//                         Holger Schemel
+//                 info@artsoft.org
+//                 http://www.artsoft.org/
+// ----------------------------------------------------------------------------
+// editor.c
+// ============================================================================
 
 #include <math.h>
 
 */
 
 /* positions in the level editor */
+#if 1
+#define ED_WIN_MB_LEFT_XPOS            (editor.palette.element_left.x)
+#define ED_WIN_MB_LEFT_YPOS            (editor.palette.element_left.y)
+#define ED_WIN_MB_MIDDLE_XPOS          (editor.palette.element_middle.x)
+#define ED_WIN_MB_MIDDLE_YPOS          (editor.palette.element_middle.y)
+#define ED_WIN_MB_RIGHT_XPOS           (editor.palette.element_right.x)
+#define ED_WIN_MB_RIGHT_YPOS           (editor.palette.element_right.y)
+#else
 #define ED_WIN_MB_LEFT_XPOS            6
 #define ED_WIN_MB_LEFT_YPOS            258
 #define ED_WIN_MB_MIDDLE_XPOS          42
 #define ED_WIN_MB_MIDDLE_YPOS          ED_WIN_MB_LEFT_YPOS
 #define ED_WIN_MB_RIGHT_XPOS           78
 #define ED_WIN_MB_RIGHT_YPOS           ED_WIN_MB_LEFT_YPOS
+#endif
 
 /* values for the control window */
 #define ED_CTRL_NO_BUTTONS_GFX_XPOS    6
                                ED_NUM_CTRL4_BUTTONS)
 
 /* values for the element list */
+#if 1
+#define ED_ELEMENTLIST_XPOS            (editor.palette.x)
+#define ED_ELEMENTLIST_YPOS            (editor.palette.y)
+#define ED_ELEMENTLIST_XSIZE           20
+#define ED_ELEMENTLIST_YSIZE           20
+#else
 #define ED_ELEMENTLIST_XPOS            5
 #define ED_ELEMENTLIST_YPOS            30
 #define ED_ELEMENTLIST_XSIZE           20
 #define ED_ELEMENTLIST_YSIZE           20
+#endif
+#if 1
+// #define ED_ELEMENTLIST_BUTTONS_HORIZ        4
+// #define ED_ELEMENTLIST_BUTTONS_VERT 9
+#define ED_ELEMENTLIST_BUTTONS_HORIZ   (editor.palette.cols)
+#define ED_ELEMENTLIST_BUTTONS_VERT    (editor.palette.rows)
+#else
 #define ED_ELEMENTLIST_BUTTONS_HORIZ   4
 #define ED_ELEMENTLIST_BUTTONS_VERT    11
+#endif
 #define ED_NUM_ELEMENTLIST_BUTTONS     (ED_ELEMENTLIST_BUTTONS_HORIZ * \
                                         ED_ELEMENTLIST_BUTTONS_VERT)
 
 #define ED_SCROLLBUTTON2_XSIZE         10
 #define ED_SCROLLBUTTON2_YSIZE         10
 
+#if 1
+#define ED_SCROLL2_UP_XPOS             (ED_ELEMENTLIST_XPOS +          \
+                                        ED_ELEMENTLIST_BUTTONS_HORIZ * \
+                                        ED_ELEMENTLIST_XSIZE)
+#define ED_SCROLL2_UP_YPOS             ED_ELEMENTLIST_YPOS
+#define ED_SCROLL2_DOWN_XPOS           ED_SCROLL2_UP_XPOS
+#define ED_SCROLL2_DOWN_YPOS           (ED_SCROLL2_UP_YPOS +           \
+                                        ED_ELEMENTLIST_BUTTONS_VERT *  \
+                                        ED_ELEMENTLIST_YSIZE -         \
+                                        ED_SCROLLBUTTON2_YSIZE)
+#define ED_SCROLL2_VERTICAL_XPOS       ED_SCROLL2_UP_XPOS
+#define ED_SCROLL2_VERTICAL_YPOS       (ED_SCROLL2_UP_YPOS +           \
+                                        ED_SCROLLBUTTON2_YSIZE)
+#define ED_SCROLL2_VERTICAL_XSIZE      ED_SCROLLBUTTON2_XSIZE
+#define ED_SCROLL2_VERTICAL_YSIZE      (ED_ELEMENTLIST_BUTTONS_VERT *  \
+                                        ED_ELEMENTLIST_YSIZE -         \
+                                        2 * ED_SCROLLBUTTON2_YSIZE)
+#else
 #define ED_SCROLL2_UP_XPOS             85
 #define ED_SCROLL2_UP_YPOS             30
 #define ED_SCROLL2_DOWN_XPOS           ED_SCROLL2_UP_XPOS
 #define ED_SCROLL2_VERTICAL_YSIZE      (ED_ELEMENTLIST_BUTTONS_VERT *  \
                                         ED_ELEMENTLIST_YSIZE -         \
                                         2 * ED_SCROLLBUTTON2_YSIZE)
+#endif
 
 /* values for checkbutton gadgets */
 #define ED_CHECKBUTTON_XSIZE           ED_BUTTON_COUNT_XSIZE
 #define RANDOM_USE_QUANTITY            1
 
 /* maximal size of level editor drawing area */
+#if NEW_TILESIZE
+#define MAX_ED_FIELDX          (SCR_FIELDX)
+#define MAX_ED_FIELDY          (SCR_FIELDY - 1)
+#else
 #define MAX_ED_FIELDX          (2 * SCR_FIELDX)
 #define MAX_ED_FIELDY          (2 * SCR_FIELDY - 1)
+#endif
 
 
 /*
@@ -2468,6 +2513,90 @@ static struct
   },
 };
 
+#if 1
+
+static struct
+{
+  int x, y;
+} scrollbutton_pos[ED_NUM_SCROLLBUTTONS];
+
+static struct
+{
+  int graphic;
+  int gadget_id;
+  char *infotext;
+} scrollbutton_info[ED_NUM_SCROLLBUTTONS] =
+{
+  {
+    IMG_EDITOR_PLAYFIELD_SCROLL_UP,
+    GADGET_ID_SCROLL_UP,
+    "scroll level editing area up"
+  },
+  {
+    IMG_EDITOR_PLAYFIELD_SCROLL_DOWN,
+    GADGET_ID_SCROLL_DOWN,
+    "scroll level editing area down"
+  },
+  {
+    IMG_EDITOR_PLAYFIELD_SCROLL_LEFT,
+    GADGET_ID_SCROLL_LEFT,
+    "scroll level editing area left"
+  },
+  {
+    IMG_EDITOR_PLAYFIELD_SCROLL_RIGHT,
+    GADGET_ID_SCROLL_RIGHT,
+    "scroll level editing area right"
+  },
+  {
+    IMG_EDITOR_PALETTE_SCROLL_UP,
+    GADGET_ID_SCROLL_LIST_UP,
+    "scroll element list up ('Page Up')"
+  },
+  {
+    IMG_EDITOR_PALETTE_SCROLL_DOWN,
+    GADGET_ID_SCROLL_LIST_DOWN,
+    "scroll element list down ('Page Down')"
+  },
+};
+
+static struct
+{
+  int x, y;
+  int width, height;
+  int wheel_x, wheel_y;
+  int wheel_width, wheel_height;
+} scrollbar_pos[ED_NUM_SCROLLBARS];
+
+static struct
+{
+  int graphic;
+  int type;
+  int gadget_id;
+  char *infotext;
+} scrollbar_info[ED_NUM_SCROLLBARS] =
+{
+  {
+    IMG_EDITOR_PLAYFIELD_SCROLLBAR,
+    GD_TYPE_SCROLLBAR_HORIZONTAL,
+    GADGET_ID_SCROLL_HORIZONTAL,
+    "scroll level editing area horizontally"
+  },
+  {
+    IMG_EDITOR_PLAYFIELD_SCROLLBAR,
+    GD_TYPE_SCROLLBAR_VERTICAL,
+    GADGET_ID_SCROLL_VERTICAL,
+    "scroll level editing area vertically"
+  },
+  {
+    IMG_EDITOR_PALETTE_SCROLLBAR,
+    GD_TYPE_SCROLLBAR_VERTICAL,
+    GADGET_ID_SCROLL_LIST_VERTICAL,
+    "scroll element list vertically"
+  }
+};
+
+#else
+
 static struct
 {
   int gd_x, gd_y;
@@ -2582,18 +2711,21 @@ static struct
     -1, -1,    /* these values are not constant, but can change at runtime */
     ED_SCROLL2_VERTICAL_XSIZE,         ED_SCROLL2_VERTICAL_YSIZE,
     -1, -1,    /* these values are not constant, but can change at runtime */
+    -1, -1,    /* these values are not constant, but can change at runtime */
 #else
     DX + ED_SCROLL2_VERTICAL_XPOS,     DY + ED_SCROLL2_VERTICAL_YPOS,
     ED_SCROLL2_VERTICAL_XSIZE,         ED_SCROLL2_VERTICAL_YSIZE,
     DX,                                        DY,
-#endif
     DXSIZE,                            DYSIZE,
+#endif
     GD_TYPE_SCROLLBAR_VERTICAL,
     GADGET_ID_SCROLL_LIST_VERTICAL,
     "scroll element list vertically"
   }
 };
 
+#endif
+
 static struct
 {
   int x, y;
@@ -2710,7 +2842,7 @@ static struct
     GADGET_ID_CONTINUOUS_SNAPPING,     GADGET_ID_NONE,
     &level.continuous_snapping,
     NULL,
-    "continuos snapping",              "use snapping without releasing key"
+    "continuous snapping",             "use snapping without releasing key"
   },
   {
     ED_ELEMENT_SETTINGS_XPOS(0),       ED_ELEMENT_SETTINGS_YPOS(7),
@@ -3353,8 +3485,15 @@ static void HandleControlButtons(struct GadgetInfo *);
 static void HandleDrawingAreaInfo(struct GadgetInfo *);
 static void PrintEditorGadgetInfoText(struct GadgetInfo *);
 
+static int num_editor_gadgets = 0;     /* dynamically determined */
+
+#if 1
+static struct GadgetInfo **level_editor_gadget = NULL;
+static int *right_gadget_border = NULL;
+#else
 static struct GadgetInfo *level_editor_gadget[NUM_EDITOR_GADGETS];
 static int right_gadget_border[NUM_EDITOR_GADGETS];
+#endif
 
 static int drawing_function = GADGET_ID_SINGLE_ITEMS;
 static int last_drawing_function = GADGET_ID_SINGLE_ITEMS;
@@ -4656,11 +4795,19 @@ static int *editor_el_dynamic_ptr = NULL;
 static int num_editor_hl_dynamic = SIZEOF_ARRAY_INT(editor_hl_dynamic);
 static int num_editor_el_dynamic = 0;
 
-static int editor_hl_empty[] = { };
+static int editor_hl_empty[] = { EL_EMPTY };
+#if 1
+static int *editor_el_empty = NULL;    /* dynamically allocated */
+#else
 static int editor_el_empty[ED_NUM_ELEMENTLIST_BUTTONS];
+#endif
 
 static int *editor_hl_empty_ptr = editor_hl_empty;
+#if 1
+static int *editor_el_empty_ptr = NULL;
+#else
 static int *editor_el_empty_ptr = editor_el_empty;
+#endif
 static int num_editor_hl_empty = 0;
 static int num_editor_el_empty = 0;    /* dynamically determined, if needed */
 
@@ -5143,7 +5290,7 @@ static void DrawElementBorder(int dest_x, int dest_y, int width, int height,
   int by2 = TILEY - by;
   int i;
 
-  getGraphicSource(border_graphic, 0, &src_bitmap, &src_x, &src_y);
+  getFixedGraphicSource(border_graphic, 0, &src_bitmap, &src_x, &src_y);
 
   BlitBitmap(src_bitmap, drawto, src_x, src_y,
             bx, by, dest_x - bx, dest_y - by);
@@ -5225,7 +5372,7 @@ static void CreateControlButtons()
 {
   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
   struct GadgetInfo *gi;
-  unsigned long event_mask;
+  unsigned int event_mask;
   int i;
 
   /* create toolbox buttons */
@@ -5361,6 +5508,20 @@ static void CreateControlButtons()
   }
 
   /* these values are not constant, but can change at runtime */
+#if 1
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_UP].x    = ED_SCROLL_UP_XPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_UP].y    = ED_SCROLL_UP_YPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_DOWN].x  = ED_SCROLL_DOWN_XPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_DOWN].y  = ED_SCROLL_DOWN_YPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_LEFT].x  = ED_SCROLL_LEFT_XPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_LEFT].y  = ED_SCROLL_LEFT_YPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_RIGHT].x = ED_SCROLL_RIGHT_XPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_RIGHT].y = ED_SCROLL_RIGHT_YPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_LIST_UP].x    = ED_SCROLL2_UP_XPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_LIST_UP].y    = ED_SCROLL2_UP_YPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_LIST_DOWN].x  = ED_SCROLL2_DOWN_XPOS;
+  scrollbutton_pos[ED_SCROLLBUTTON_ID_LIST_DOWN].y  = ED_SCROLL2_DOWN_YPOS;
+#else
   scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_UP].x    = ED_SCROLL_UP_XPOS;
   scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_UP].y    = ED_SCROLL_UP_YPOS;
   scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_DOWN].x  = ED_SCROLL_DOWN_XPOS;
@@ -5369,16 +5530,26 @@ static void CreateControlButtons()
   scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_LEFT].y  = ED_SCROLL_LEFT_YPOS;
   scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].x = ED_SCROLL_RIGHT_XPOS;
   scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].y = ED_SCROLL_RIGHT_YPOS;
+#endif
 
   /* 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;
+#if 1
+    int graphic = scrollbutton_info[i].graphic;
+    struct GraphicInfo *gd = &graphic_info[graphic];
+#endif
     int x, y, width, height;
     int gd_x1, gd_x2, gd_y1, gd_y2;
 
+#if 1
+    x = scrollbutton_pos[i].x;
+    y = scrollbutton_pos[i].y;
+#else
     x = scrollbutton_info[i].x;
     y = scrollbutton_info[i].y;
+#endif
 
     event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
 
@@ -5387,23 +5558,41 @@ static void CreateControlButtons()
     {
       x += DX;
       y += DY;
+#if 1
+      width  = gd->width;
+      height = gd->height;
+      gd_x1 = gd->src_x;
+      gd_y1 = gd->src_y;
+      gd_x2 = gd->src_x + gd->pressed_xoffset;
+      gd_y2 = gd->src_y + gd->pressed_yoffset;
+#else
       width = ED_SCROLLBUTTON2_XSIZE;
       height = ED_SCROLLBUTTON2_YSIZE;
       gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x;
       gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y;
       gd_x2 = gd_x1 - ED_SCROLLBUTTON2_XSIZE;
       gd_y2 = gd_y1;
+#endif
     }
     else
     {
       x += SX;
       y += SY;
+#if 1
+      width  = gd->width;
+      height = gd->height;
+      gd_x1 = gd->src_x;
+      gd_y1 = gd->src_y;
+      gd_x2 = gd->src_x + gd->pressed_xoffset;
+      gd_y2 = gd->src_y + gd->pressed_yoffset;
+#else
       width = ED_SCROLLBUTTON_XSIZE;
       height = ED_SCROLLBUTTON_YSIZE;
       gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x;
       gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y;
       gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
       gd_y2 = gd_y1;
+#endif
     }
 
     gi = CreateGadget(GDI_CUSTOM_ID, id,
@@ -5431,10 +5620,15 @@ static void CreateControlButtons()
   /* create buttons for element list */
   for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
   {
+    struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_PALETTE_BUTTON];
     Bitmap *deco_bitmap;
     int deco_x, deco_y, deco_xpos, deco_ypos;
     int gd_xoffset, gd_yoffset;
+#if 1
+    int gd_x1, gd_y1, gd_x2, gd_y2;
+#else
     int gd_x1, gd_x2, gd_y;
+#endif
     int x = i % ED_ELEMENTLIST_BUTTONS_HORIZ;
     int y = i / ED_ELEMENTLIST_BUTTONS_HORIZ;
     int id = GADGET_ID_ELEMENTLIST_FIRST + i;
@@ -5442,6 +5636,19 @@ static void CreateControlButtons()
 
     event_mask = GD_EVENT_RELEASED;
 
+#if 1
+    gd_xoffset = ED_ELEMENTLIST_XPOS + x * gd->width;
+    gd_yoffset = ED_ELEMENTLIST_YPOS + y * gd->height;
+
+    gd_x1 = gd->src_x;
+    gd_y1 = gd->src_y;
+    gd_x2 = gd->src_x + gd->pressed_xoffset;
+    gd_y2 = gd->src_y + gd->pressed_yoffset;
+
+    getMiniGraphicSource(el2edimg(element), &deco_bitmap, &deco_x, &deco_y);
+    deco_xpos = (gd->width  - MINI_TILEX) / 2;
+    deco_ypos = (gd->height - MINI_TILEY) / 2;
+#else
     gd_xoffset = ED_ELEMENTLIST_XPOS + x * ED_ELEMENTLIST_XSIZE;
     gd_yoffset = ED_ELEMENTLIST_YPOS + y * ED_ELEMENTLIST_YSIZE;
 
@@ -5452,18 +5659,29 @@ static void CreateControlButtons()
     getMiniGraphicSource(el2edimg(element), &deco_bitmap, &deco_x, &deco_y);
     deco_xpos = (ED_ELEMENTLIST_XSIZE - MINI_TILEX) / 2;
     deco_ypos = (ED_ELEMENTLIST_YSIZE - MINI_TILEY) / 2;
+#endif
 
     gi = CreateGadget(GDI_CUSTOM_ID, id,
                      GDI_CUSTOM_TYPE_ID, i,
                      GDI_INFO_TEXT, getElementInfoText(element),
                      GDI_X, DX + gd_xoffset,
                      GDI_Y, DY + gd_yoffset,
+#if 1
+                     GDI_WIDTH, gd->width,
+                     GDI_HEIGHT, gd->height,
+#else
                      GDI_WIDTH, ED_ELEMENTLIST_XSIZE,
                      GDI_HEIGHT, ED_ELEMENTLIST_YSIZE,
+#endif
                      GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
                      GDI_STATE, GD_BUTTON_UNPRESSED,
-                     GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
-                     GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
+#if 1
+                     GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1,
+                     GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2,
+#else
+                     GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y,
+                     GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y,
+#endif
                      GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y,
                      GDI_DECORATION_POSITION, deco_xpos, deco_ypos,
                      GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY,
@@ -5512,15 +5730,36 @@ static void CreateCounterButtons()
                counterbutton_info[i].gadget_id_down :
                counterbutton_info[i].gadget_id_up);
       int gd_xoffset;
-      int gd_x, gd_x1, gd_x2, gd_y;
+      int gd_x, gd_y, gd_x1, gd_x2, gd_y1, gd_y2;
       int x_size, y_size;
-      unsigned long event_mask;
+      unsigned int event_mask;
       char infotext[max_infotext_len + 1];
 
       event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED;
 
       if (i == ED_COUNTER_ID_SELECT_LEVEL)
       {
+#if 1
+       int graphic = (j == 0 ?
+                      IMG_EDITOR_BUTTON_GFX_PREV_LEVEL :
+                      IMG_EDITOR_BUTTON_GFX_NEXT_LEVEL);
+       struct GraphicInfo *gd = &graphic_info[graphic];
+
+       gd_bitmap = gd->bitmap;
+
+       event_mask |= GD_EVENT_RELEASED;
+
+       if (j == 1)
+         x += 2 * ED_GADGET_DISTANCE;
+       y += ED_GADGET_DISTANCE;
+
+       gd_x1 = gd->src_x;
+       gd_y1 = gd->src_y;
+       gd_x2 = gd->src_x + gd->pressed_xoffset;
+       gd_y2 = gd->src_y + gd->pressed_yoffset;
+       x_size = gd->width;
+       y_size = gd->height;
+#else
        int sid = (j == 0 ?
                   ED_SCROLLBUTTON_ID_AREA_LEFT :
                   ED_SCROLLBUTTON_ID_AREA_RIGHT);
@@ -5533,16 +5772,19 @@ static void CreateCounterButtons()
 
        gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[sid].gd_x;
        gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE;
-       gd_y  = DOOR_GFX_PAGEY1 + scrollbutton_info[sid].gd_y;
+       gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[sid].gd_y;
+       gd_y2 = gd_y1;
        x_size = ED_SCROLLBUTTON_XSIZE;
        y_size = ED_SCROLLBUTTON_YSIZE;
+#endif
       }
       else
       {
        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;
+       gd_y1 = DOOR_GFX_PAGEY1 + ED_BUTTON_COUNT_YPOS;
+       gd_y2 = gd_y1;
        x_size = ED_BUTTON_COUNT_XSIZE;
        y_size = ED_BUTTON_COUNT_YSIZE;
       }
@@ -5559,8 +5801,8 @@ static void CreateCounterButtons()
                        GDI_HEIGHT, y_size,
                        GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
                        GDI_STATE, GD_BUTTON_UNPRESSED,
-                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
-                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
+                       GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
+                       GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
                        GDI_EVENT_MASK, event_mask,
                        GDI_CALLBACK_INFO, HandleEditorGadgetInfoText,
                        GDI_CALLBACK_ACTION, HandleCounterButtons,
@@ -5650,7 +5892,7 @@ static void CreateDrawingAreas()
   for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
   {
     struct GadgetInfo *gi;
-    unsigned long event_mask;
+    unsigned int event_mask;
     int id = drawingarea_info[i].gadget_id;
     int x = SX + drawingarea_info[i].x;
     int y = SY + drawingarea_info[i].y;
@@ -5701,7 +5943,7 @@ static void CreateTextInputGadgets()
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     int gd_x, gd_y;
     struct GadgetInfo *gi;
-    unsigned long event_mask;
+    unsigned int event_mask;
     char infotext[MAX_OUTPUT_LINESIZE + 1];
     int id = textinput_info[i].gadget_id;
 
@@ -5749,7 +5991,7 @@ static void CreateTextAreaGadgets()
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     int gd_x, gd_y;
     struct GadgetInfo *gi;
-    unsigned long event_mask;
+    unsigned int event_mask;
     char infotext[MAX_OUTPUT_LINESIZE + 1];
     int id = textarea_info[i].gadget_id;
     int area_xsize = textarea_info[i].xsize;
@@ -5798,7 +6040,7 @@ static void CreateSelectboxGadgets()
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     int gd_x, gd_y;
     struct GadgetInfo *gi;
-    unsigned long event_mask;
+    unsigned int event_mask;
     char infotext[MAX_OUTPUT_LINESIZE + 1];
     int id = selectbox_info[i].gadget_id;
     int x = SX + selectbox_info[i].x;
@@ -5875,7 +6117,7 @@ static void CreateTextbuttonGadgets()
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
     int gd_x1, gd_x2, gd_y1, gd_y2;
     struct GadgetInfo *gi;
-    unsigned long event_mask;
+    unsigned int event_mask;
     char infotext[MAX_OUTPUT_LINESIZE + 1];
     int id = textbutton_info[i].gadget_id;
     int x = SX + textbutton_info[i].x;
@@ -5948,7 +6190,7 @@ static void CreateGraphicbuttonGadgets()
 {
   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
   struct GadgetInfo *gi;
-  unsigned long event_mask;
+  unsigned int event_mask;
   int i;
 
   /* create buttons for scrolling of drawing area and element list */
@@ -6015,6 +6257,46 @@ static void CreateScrollbarGadgets()
   int i;
 
   /* these values are not constant, but can change at runtime */
+#if 1
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].x =
+    SX + ED_SCROLL_HORIZONTAL_XPOS;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].y =
+    SY + ED_SCROLL_HORIZONTAL_YPOS;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width =
+    ED_SCROLL_HORIZONTAL_XSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].height =
+    ED_SCROLL_HORIZONTAL_YSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_x      = SX;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_y      = SY;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_width  = SXSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_height = SYSIZE;
+
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].x =
+    SX + ED_SCROLL_VERTICAL_XPOS;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].y =
+    SY + ED_SCROLL_VERTICAL_YPOS;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].width =
+    ED_SCROLL_VERTICAL_XSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].height =
+    ED_SCROLL_VERTICAL_YSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_x      = SX;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_y      = SY;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_width  = SXSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_height = SYSIZE;
+
+  scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].x =
+    DX + ED_SCROLL2_VERTICAL_XPOS;
+  scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].y =
+    DY + ED_SCROLL2_VERTICAL_YPOS;
+  scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].width =
+    ED_SCROLL2_VERTICAL_XSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].height =
+    ED_SCROLL2_VERTICAL_YSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_x = DX;
+  scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_y = DY;
+  scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_width  = DXSIZE;
+  scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_height = DYSIZE;
+#else
   scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].x =
     SX + ED_SCROLL_HORIZONTAL_XPOS;
   scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].y =
@@ -6045,17 +6327,30 @@ static void CreateScrollbarGadgets()
     DX + ED_SCROLL2_VERTICAL_XPOS;
   scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].y =
     DY + ED_SCROLL2_VERTICAL_YPOS;
+  scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].width =
+    ED_SCROLL2_VERTICAL_XSIZE;
+  scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].height =
+    ED_SCROLL2_VERTICAL_YSIZE;
   scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_x = DX;
   scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_y = DY;
+  scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_width  = DXSIZE;
+  scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_height = DYSIZE;
+#endif
 
   for (i = 0; i < ED_NUM_SCROLLBARS; i++)
   {
     int id = scrollbar_info[i].gadget_id;
+#if 1
+    int graphic = scrollbar_info[i].graphic;
+    struct GraphicInfo *gd = &graphic_info[graphic];
+    Bitmap *gd_bitmap = gd->bitmap;
+#else
     Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
+#endif
     int gd_x1, gd_x2, gd_y1, gd_y2;
     struct GadgetInfo *gi;
     int items_max, items_visible, item_position;
-    unsigned long event_mask;
+    unsigned int event_mask;
 
     if (i == ED_SCROLLBAR_ID_LIST_VERTICAL)
     {
@@ -6081,27 +6376,48 @@ static void CreateScrollbarGadgets()
 
     event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS;
 
+#if 1
+    gd_x1 = gd->src_x;
+    gd_y1 = gd->src_y;
+    gd_x2 = gd->src_x + gd->pressed_xoffset;
+    gd_y2 = gd->src_y + gd->pressed_yoffset;
+#else
     gd_x1 = DOOR_GFX_PAGEX8 + scrollbar_info[i].gd_x;
     gd_x2 = (gd_x1 - (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL ?
                      scrollbar_info[i].height : scrollbar_info[i].width));
     gd_y1 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y;
     gd_y2 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y;
+#endif
 
     gi = CreateGadget(GDI_CUSTOM_ID, id,
                      GDI_CUSTOM_TYPE_ID, i,
                      GDI_INFO_TEXT, scrollbar_info[i].infotext,
+#if 1
+                     GDI_X, scrollbar_pos[i].x,
+                     GDI_Y, scrollbar_pos[i].y,
+                     GDI_WIDTH, scrollbar_pos[i].width,
+                     GDI_HEIGHT, scrollbar_pos[i].height,
+#else
                      GDI_X, scrollbar_info[i].x,
                      GDI_Y, scrollbar_info[i].y,
                      GDI_WIDTH, scrollbar_info[i].width,
                      GDI_HEIGHT, scrollbar_info[i].height,
+#endif
                      GDI_TYPE, scrollbar_info[i].type,
                      GDI_SCROLLBAR_ITEMS_MAX, items_max,
                      GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible,
                      GDI_SCROLLBAR_ITEM_POSITION, item_position,
+#if 1
+                     GDI_WHEEL_AREA_X, scrollbar_pos[i].wheel_x,
+                     GDI_WHEEL_AREA_Y, scrollbar_pos[i].wheel_y,
+                     GDI_WHEEL_AREA_WIDTH, scrollbar_pos[i].wheel_width,
+                     GDI_WHEEL_AREA_HEIGHT, scrollbar_pos[i].wheel_height,
+#else
                      GDI_WHEEL_AREA_X, scrollbar_info[i].wheel_x,
                      GDI_WHEEL_AREA_Y, scrollbar_info[i].wheel_y,
                      GDI_WHEEL_AREA_WIDTH, scrollbar_info[i].wheel_width,
                      GDI_WHEEL_AREA_HEIGHT, scrollbar_info[i].wheel_height,
+#endif
                      GDI_STATE, GD_BUTTON_UNPRESSED,
                      GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
                      GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
@@ -6122,7 +6438,7 @@ static void CreateCheckbuttonGadgets()
 {
   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
   struct GadgetInfo *gi;
-  unsigned long event_mask;
+  unsigned int event_mask;
   int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
   int i;
 
@@ -6185,7 +6501,7 @@ static void CreateRadiobuttonGadgets()
 {
   Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
   struct GadgetInfo *gi;
-  unsigned long event_mask;
+  unsigned int event_mask;
   int gd_x1, gd_x2, gd_x3, gd_x4, gd_y;
   int i;
 
@@ -6254,6 +6570,18 @@ void CreateLevelEditorGadgets()
   ed_fieldx = MAX_ED_FIELDX - 1;
   ed_fieldy = MAX_ED_FIELDY - 1;
 
+  num_editor_gadgets = NUM_EDITOR_GADGETS;
+
+  // printf("::: allocating %d gadgets ...\n", num_editor_gadgets);
+
+  level_editor_gadget =
+    checked_calloc(num_editor_gadgets * sizeof(struct GadgetInfo *));
+  right_gadget_border =
+    checked_calloc(num_editor_gadgets * sizeof(int));
+
+  editor_el_empty = checked_calloc(ED_NUM_ELEMENTLIST_BUTTONS * sizeof(int));
+  editor_el_empty_ptr = editor_el_empty;
+
   ReinitializeElementList();
 
   CreateControlButtons();
@@ -6277,12 +6605,19 @@ void FreeLevelEditorGadgets()
 {
   int i;
 
-  for (i = 0; i < NUM_EDITOR_GADGETS; i++)
+  // printf("::: freeing %d gadgets ...\n", num_editor_gadgets);
+
+  for (i = 0; i < num_editor_gadgets; i++)
   {
     FreeGadget(level_editor_gadget[i]);
 
     level_editor_gadget[i] = NULL;
   }
+
+  checked_free(level_editor_gadget);
+  checked_free(right_gadget_border);
+
+  checked_free(editor_el_empty);
 }
 
 static void MapCounterButtons(int id)
@@ -6647,20 +6982,27 @@ static void UnmapDrawingArea(int id)
   UnmapGadget(level_editor_gadget[drawingarea_info[id].gadget_id]);
 }
 
-static void UnmapLevelEditorWindowGadgets()
+static void UnmapLevelEditorFieldGadgets()
 {
   int i;
 
+#if 1
+  for (i = 0; i < num_editor_gadgets; i++)
+    if (IN_GFX_FIELD_FULL(level_editor_gadget[i]->x,
+                         level_editor_gadget[i]->y))
+      UnmapGadget(level_editor_gadget[i]);
+#else
   for (i = 0; i < NUM_EDITOR_GADGETS; i++)
     if (level_editor_gadget[i]->x < SX + SXSIZE)
       UnmapGadget(level_editor_gadget[i]);
+#endif
 }
 
 void UnmapLevelEditorGadgets()
 {
   int i;
 
-  for (i = 0; i < NUM_EDITOR_GADGETS; i++)
+  for (i = 0; i < num_editor_gadgets; i++)
     UnmapGadget(level_editor_gadget[i]);
 }
 
@@ -6728,8 +7070,8 @@ static boolean PrepareSavingIntoPersonalLevelSet()
     return TRUE;
   }
 
-  if (!Request("This level is read only ! "
-              "Save into personal level set ?", REQ_ASK))
+  if (!Request("This level is read only! "
+              "Save into personal level set?", REQ_ASK))
     return FALSE;
 
   // "cd" to personal level set dir (for writing copy the first time)
@@ -7007,13 +7349,13 @@ static boolean CopyCustomElement(int element_old, int element_new,
   }
   else if (IS_CUSTOM_ELEMENT(element_old) && !IS_CUSTOM_ELEMENT(element_new))
   {
-    Request("Please choose custom element !", REQ_CONFIRM);
+    Request("Please choose custom element!", REQ_CONFIRM);
 
     return FALSE;
   }
   else if (IS_GROUP_ELEMENT(element_old) && !IS_GROUP_ELEMENT(element_new))
   {
-    Request("Please choose group element !", REQ_CONFIRM);
+    Request("Please choose group element!", REQ_CONFIRM);
 
     return FALSE;
   }
@@ -7238,7 +7580,7 @@ static void CopyCustomElementPropertiesToGame(int element)
 
   if (level.use_custom_template)
   {
-    if (Request("Copy and modify level template ?", REQ_ASK))
+    if (Request("Copy and modify level template?", REQ_ASK))
     {
       level.use_custom_template = FALSE;
       ModifyGadget(level_editor_gadget[GADGET_ID_CUSTOM_USE_TEMPLATE],
@@ -7399,17 +7741,55 @@ void CheckElementDescriptions()
       Error(ERR_WARN, "no element description for element '%s'", EL_NAME(i));
 }
 
+static boolean playfield_area_changed = FALSE;
+
 void DrawLevelEd()
 {
+  int old_sx = SX;
+  int old_sy = SY;
+  int old_sxsize = SXSIZE;
+  int old_sysize = SYSIZE;
+
   StopAnimation();
 
   CloseDoor(DOOR_CLOSE_ALL);
 
 #if 1
   FadeOut(REDRAW_FIELD);
+  // FadeOut(REDRAW_ALL);
+#endif
+
+#if 1
+  /* needed after playing if editor playfield area has different size */
+  ClearRectangle(drawto, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+#endif
+
+#if 1
+  /* needed if different viewport properties defined for editor */
+  ChangeViewportPropertiesIfNeeded();
 #endif
 
+  if (old_sx != SX ||
+      old_sy != SY ||
+      old_sxsize != SXSIZE ||
+      old_sysize != SYSIZE)
+  {
+    playfield_area_changed = TRUE;
+
+#if 0
+    printf("::: %d, %d, %d, %d != %d, %d, %d, %d\n",
+          old_sx, old_sy, old_sxsize, old_sysize,
+          SX, SY, SXSIZE, SYSIZE);
+#endif
+  }
+  else
+    playfield_area_changed = FALSE;
+
+#if 1
+  OpenDoor(DOOR_OPEN_1 | DOOR_OPEN_2 | DOOR_NO_DELAY);
+#else
   OpenDoor(DOOR_OPEN_2 | DOOR_NO_DELAY);
+#endif
 
 #if DEBUG
   CheckElementDescriptions();
@@ -7435,8 +7815,19 @@ void DrawLevelEd()
   }
 
   /* copy default editor door content to main double buffer */
+#if 1
+  BlitBitmap(graphic_info[IMG_BACKGROUND_PALETTE].bitmap, drawto,
+            graphic_info[IMG_BACKGROUND_PALETTE].src_x,
+            graphic_info[IMG_BACKGROUND_PALETTE].src_y,
+            DXSIZE, DYSIZE, DX, DY);
+#else
   BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
             DOOR_GFX_PAGEX6, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
+#endif
+
+#if 0
+  printf("::: %d, %d  /  %d, %d\n", VX, VY, EX, EY);
+#endif
 
   /* draw bigger door */
   DrawSpecialEditorDoor();
@@ -7471,20 +7862,29 @@ void DrawLevelEd()
   DrawEditModeWindow();
 
 #if 1
+  FadeIn(playfield_area_changed ? REDRAW_ALL : REDRAW_FIELD);
+#else
   FadeIn(REDRAW_FIELD);
+  // FadeIn(REDRAW_ALL);
 #endif
 
   /* copy actual editor door content to door double buffer for OpenDoor() */
+#if 1
+  BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0);
+#else
   BlitBitmap(drawto, bitmap_db_door,
             DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
+#endif
 
-#if 1
+#if 0
   /* draw new control window (with border) to window */
   redraw_mask |= REDRAW_ALL;
   BackToFront();
 #endif
 
+#if 0
   OpenDoor(DOOR_OPEN_1);
+#endif
 }
 
 static void AdjustDrawingAreaGadgets()
@@ -7530,14 +7930,24 @@ static void AdjustDrawingAreaGadgets()
   xoffset = (ed_fieldx == MAX_ED_FIELDX ? ED_SCROLLBUTTON_XSIZE : 0);
   yoffset = (ed_fieldy == MAX_ED_FIELDY ? ED_SCROLLBUTTON_YSIZE : 0);
 
+#if 1
+  x = SX + scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset;
+  y = SX + scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset;
+#else
   x = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset;
   y = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset;
+#endif
 
   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;
+#if 1
+  width  = scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset;
+  height = scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset;
+#else
+  width  = scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset;
   height = scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset;
+#endif
 
   ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL],
               GDI_WIDTH, width,
@@ -7738,7 +8148,7 @@ static void DrawDrawingWindow()
   SetMainBackgroundImage(IMG_UNDEFINED);
   ClearField();
 
-  UnmapLevelEditorWindowGadgets();
+  UnmapLevelEditorFieldGadgets();
   UnmapLevelEditorToolboxCustomGadgets();
 
   AdjustDrawingAreaGadgets();
@@ -7909,7 +8319,7 @@ static void DrawLevelInfoWindow()
 {
   stick_element_properties_window = FALSE;
 
-  UnmapLevelEditorWindowGadgets();
+  UnmapLevelEditorFieldGadgets();
 
   SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
   ClearField();
@@ -8162,9 +8572,23 @@ static int PrintElementDescriptionFromFile(char *filename, int start_line)
   int sy = SY + pad_y + start_line * font_height;
   int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
   int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
+  int max_lines_drawable = max_lines_per_screen - start_line;
 
+#if 0
+  printf("::: SYSIZE == %d [%d / %d / %d]\n", SYSIZE,
+        max_chars_per_line, max_lines_per_screen, max_lines_drawable);
+#endif
+
+  if (start_line >= max_lines_per_screen)
+    return FALSE;
+
+#if 1
   return DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
-                     max_lines_per_screen, -1, TRUE, FALSE, FALSE);
+                     max_lines_drawable, 0, -1, TRUE, FALSE, FALSE);
+#else
+  return DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1,
+                     max_lines_per_screen, 0, -1, TRUE, FALSE, FALSE);
+#endif
 }
 
 static void DrawPropertiesInfo()
@@ -8228,8 +8652,8 @@ static void DrawPropertiesInfo()
     { -1,                      NULL                                    }
   };
   char *filename = getElementDescriptionFilename(properties_element);
-  char *percentage_text = "In this level:";
-  char *properties_text = "Standard properties:";
+  char *percentage_text = "In this level: ";
+  char *properties_text = "Standard properties: ";
   float percentage;
   int num_elements_in_level;
   int num_standard_properties = 0;
@@ -8803,7 +9227,7 @@ static void DrawEditorElementAnimation(int x, int y)
               ANIM_MODE(graphic) == ANIM_CE_SCORE ?
               custom_element.collect_score_initial : FrameCounter);
 
-  DrawGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
+  DrawFixedGraphicAnimationExt(drawto, x, y, graphic, frame, NO_MASKING);
 }
 
 static void DrawEditorElementName(int x, int y, int element)
@@ -8875,7 +9299,7 @@ static void DrawPropertiesWindow()
 
   CopyElementPropertiesToEditor(properties_element);
 
-  UnmapLevelEditorWindowGadgets();
+  UnmapLevelEditorFieldGadgets();
   UnmapLevelEditorToolboxDrawingGadgets();
   UnmapLevelEditorToolboxCustomGadgets();
 
@@ -10300,7 +10724,10 @@ static void FloodFill(int from_x, int from_y, int fill_element)
 static int DrawLevelText(int sx, int sy, char letter, int mode)
 {
   static short delete_buffer[MAX_LEV_FIELDX];
-  static int start_sx, start_sy;
+  static int start_sx;
+#if 0
+  static int start_sy;
+#endif
   static int last_sx, last_sy;
   static boolean typing = FALSE;
   int letter_element = EL_CHAR_ASCII0 + letter;
@@ -10342,8 +10769,12 @@ static int DrawLevelText(int sx, int sy, char letter, int mode)
        DrawLevelText(0, 0, 0, TEXT_END);
 
       typing = TRUE;
-      start_sx = last_sx = sx;
-      start_sy = last_sy = sy;
+      start_sx = sx;
+#if 0
+      start_sy = sy;
+#endif
+      last_sx = sx;
+      last_sy = sy;
       DrawLevelText(sx, sy, 0, TEXT_SETCURSOR);
       break;
 
@@ -10708,10 +11139,10 @@ static void HandleDrawingAreas(struct GadgetInfo *gi)
                             gi->y + sy * MINI_TILEY,
                             el2edimg(new_element));
        else
-         DrawGraphicExt(drawto,
-                        gi->x + sx * TILEX,
-                        gi->y + sy * TILEY,
-                        el2img(new_element), 0);
+         DrawFixedGraphicExt(drawto,
+                             gi->x + sx * TILEX,
+                             gi->y + sy * TILEY,
+                             el2img(new_element), 0);
 
        if (id == GADGET_ID_CUSTOM_GRAPHIC)
          new_element = GFX_ELEMENT(new_element);
@@ -10857,7 +11288,7 @@ static void HandleCounterButtons(struct GadgetInfo *gi)
     if ((level_changed && pressed) || (!level_changed && released))
       return;
 
-    if (level_changed && !Request("Level has changed ! Discard changes ?",
+    if (level_changed && !Request("Level has changed! Discard changes?",
                                  REQ_ASK))
     {
       if (gadget_id == counterbutton_info[counter_id].gadget_id_text)
@@ -11030,11 +11461,11 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
     CopyPlayfield(Feld, level.field);
 
     if (new_template ||
-       Request("Save this template and kill the old ?", REQ_ASK))
+       Request("Save this template and kill the old?", REQ_ASK))
       SaveLevelTemplate();
 
     if (new_template)
-      Request("Template saved !", REQ_CONFIRM);
+      Request("Template saved!", REQ_CONFIRM);
 
     /* restore original "level.field" (needed to track playfield changes) */
     CopyPlayfield(FieldBackup, level.field);
@@ -11150,7 +11581,7 @@ static void HandleCheckbuttons(struct GadgetInfo *gi)
 
     if (level.use_custom_template && !fileExists(template_filename))
     {
-      Request("No level template found !", REQ_CONFIRM);
+      Request("No level template found!", REQ_CONFIRM);
 
       level.use_custom_template = FALSE;
       ModifyGadget(gi, GDI_CHECKED, FALSE, GDI_END);
@@ -11383,7 +11814,7 @@ static void HandleControlButtons(struct GadgetInfo *gi)
     case GADGET_ID_UNDO:
       if (undo_buffer_steps == 0)
       {
-       Request("Undo buffer empty !", REQ_CONFIRM);
+       Request("Undo buffer empty!", REQ_CONFIRM);
        break;
       }
 
@@ -11457,7 +11888,7 @@ static void HandleControlButtons(struct GadgetInfo *gi)
       new_level = !fileExists(level_filename);
 
       if (new_level ||
-         Request("Save this level and kill the old ?", REQ_ASK))
+         Request("Save this level and kill the old?", REQ_ASK))
       {
        if (leveldir_former->readonly)
          ModifyLevelInfoForSavingIntoPersonalLevelSet(leveldir_former->name);
@@ -11473,10 +11904,10 @@ static void HandleControlButtons(struct GadgetInfo *gi)
 
          if (leveldir_former->readonly)
            sprintf(level_saved_msg,
-                   "Level saved as level %d into personal level set !",
+                   "Level saved as level %d into personal level set!",
                    level_nr);
          else
-           strcpy(level_saved_msg, "Level saved !");
+           strcpy(level_saved_msg, "Level saved!");
 
          Request(level_saved_msg, REQ_CONFIRM);
        }
@@ -11503,9 +11934,20 @@ static void HandleControlButtons(struct GadgetInfo *gi)
 
       CloseDoor(DOOR_CLOSE_ALL);
 
+#if 0
       BackToFront();           /* force redraw of undrawn special door */
+#endif
 
+#if 1
+      /* needed before playing if editor playfield area has different size */
+      ClearRectangle(drawto, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+
+      redraw_mask = REDRAW_ALL;
+#endif
+
+#if 0
       DrawCompleteVideoDisplay();
+#endif
 
       level_editor_test_game = TRUE;
 
@@ -11733,8 +12175,8 @@ void HandleLevelEditorKeyInput(Key key)
 
 void HandleLevelEditorIdle()
 {
-  static unsigned long action_delay = 0;
-  unsigned long action_delay_value = GameFrameDelay;
+  static unsigned int action_delay = 0;
+  unsigned int action_delay_value = GameFrameDelay;
   int xpos = 1, ypos = 2;
   int i;
 
@@ -11980,11 +12422,16 @@ void RequestExitLevelEditor(boolean ask_if_level_has_changed,
 {
   if (!ask_if_level_has_changed ||
       !LevelChanged() ||
-      Request("Level has changed ! Exit without saving ?",
+      Request("Level has changed! Exit without saving?",
              REQ_ASK | REQ_STAY_OPEN))
   {
+#if 1
+    // CloseDoor(DOOR_CLOSE_1);
+    SetDoorState(DOOR_CLOSE_2);
+#else
     CloseDoor(DOOR_CLOSE_1);
     SetDoorState(DOOR_CLOSE_2);
+#endif
 
 #if 1
     if (quick_quit)
@@ -11995,15 +12442,24 @@ void RequestExitLevelEditor(boolean ask_if_level_has_changed,
 #endif
 
     game_status = GAME_MODE_MAIN;
+#if 1
+    DrawAndFadeInMainMenu(playfield_area_changed ? REDRAW_ALL : REDRAW_FIELD);
+#else
 #if 1
     DrawAndFadeInMainMenu(REDRAW_FIELD);
 #else
     DrawMainMenu();
+#endif
 #endif
   }
   else
   {
+#if 1
+    // CloseDoor(DOOR_CLOSE_1);
+    OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
+#else
     CloseDoor(DOOR_CLOSE_1);
     OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
+#endif
   }
 }