added support for dynamically sized (and placed) editor palette
[rocksndiamonds.git] / src / editor.c
index c993b6ea5803e052b90f3a1fb037dff3cf60e0e1..8338bbb37973bb5fa8cb3456982e1484c53d1455 100644 (file)
 #define ED_ELEMENTLIST_YPOS            (editor.palette.y)
 #define ED_ELEMENTLIST_XSIZE           (graphic_info[IMG_EDITOR_PALETTE_BUTTON].width)
 #define ED_ELEMENTLIST_YSIZE           (graphic_info[IMG_EDITOR_PALETTE_BUTTON].height)
-#define ED_ELEMENTLIST_BUTTONS_HORIZ   (editor.palette.cols)
-#define ED_ELEMENTLIST_BUTTONS_VERT    (editor.palette.rows)
+#define ED_ELEMENTLIST_COLS            MAX(1, editor.palette.cols)
+#define ED_ELEMENTLIST_ROWS            MAX(1, editor.palette.rows)
+#define ED_ELEMENTLIST_BUTTONS_HORIZ   (ED_ELEMENTLIST_COLS)
+#define ED_ELEMENTLIST_BUTTONS_VERT    (ED_ELEMENTLIST_ROWS)
 #define ED_NUM_ELEMENTLIST_BUTTONS     (ED_ELEMENTLIST_BUTTONS_HORIZ * \
                                         ED_ELEMENTLIST_BUTTONS_VERT)
 
@@ -5758,7 +5760,7 @@ static void ReinitializeElementList(void)
       {
        // required for correct padding of palette headline buttons
        if (*editor_elements_info[i].headline_list_size > 0)
-         num_editor_elements += editor.palette.cols;
+         num_editor_elements += ED_ELEMENTLIST_COLS;
 
        for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
        {
@@ -5775,8 +5777,8 @@ static void ReinitializeElementList(void)
       // required for correct padding of palette element buttons
       int element_list_size = *editor_elements_info[i].element_list_size;
       int element_rows =
-       (element_list_size + editor.palette.cols - 1) / editor.palette.cols;
-      int element_buttons = editor.palette.cols * element_rows;
+       (element_list_size + ED_ELEMENTLIST_COLS - 1) / ED_ELEMENTLIST_COLS;
+      int element_buttons = ED_ELEMENTLIST_COLS * element_rows;
 
       num_editor_elements += element_buttons;
     }
@@ -5808,7 +5810,7 @@ static void ReinitializeElementList(void)
       {
        // required for correct padding of palette headline buttons
        int headline_size = (*editor_elements_info[i].headline_list_size > 0 ?
-                            editor.palette.cols : 0);
+                            ED_ELEMENTLIST_COLS : 0);
 
        for (j = 0; j < headline_size; j++)
        {
@@ -5830,8 +5832,8 @@ static void ReinitializeElementList(void)
       // required for correct padding of palette element buttons
       int element_list_size = *editor_elements_info[i].element_list_size;
       int element_rows =
-       (element_list_size + editor.palette.cols - 1) / editor.palette.cols;
-      int element_buttons = editor.palette.cols * element_rows;
+       (element_list_size + ED_ELEMENTLIST_COLS - 1) / ED_ELEMENTLIST_COLS;
+      int element_buttons = ED_ELEMENTLIST_COLS * element_rows;
 
       // copy all elements from element list
       for (j = 0; j < element_list_size; j++)
@@ -7146,7 +7148,10 @@ void CreateLevelEditorGadgets(void)
   right_gadget_border =
     checked_calloc(num_editor_gadgets * sizeof(int));
 
-  editor_el_empty = checked_calloc(ED_NUM_ELEMENTLIST_BUTTONS * sizeof(int));
+  // set number of empty (padding) element buttons to maximum number of buttons
+  num_editor_el_empty = ED_NUM_ELEMENTLIST_BUTTONS;
+
+  editor_el_empty = checked_calloc(num_editor_el_empty * sizeof(int));
   editor_el_empty_ptr = editor_el_empty;
 
   use_permanent_palette = !editor.palette.show_as_separate_screen;
@@ -12376,6 +12381,8 @@ static int DrawLevelText(int sx, int sy, char letter, int mode)
     case TEXT_SETCURSOR:
       DrawEditorElement(last_sx, last_sy, Feld[lx][ly]);
       DrawAreaBorder(sx, sy, sx, sy);
+      StartTextInput(SX + sx * ed_tilesize, SY + sy * ed_tilesize,
+                    ed_tilesize, ed_tilesize);
       last_sx = sx;
       last_sy = sy;
       break;
@@ -12411,7 +12418,7 @@ static int DrawLevelText(int sx, int sy, char letter, int mode)
       break;
 
     case TEXT_NEWLINE:
-      if (sy + 1 < ed_fieldy - 1 && ly + 1 < lev_fieldy - 1)
+      if (sy + 1 < ed_fieldy && ly + 1 < lev_fieldy)
        DrawLevelText(start_sx, sy + 1, 0, TEXT_SETCURSOR);
       else
        DrawLevelText(0, 0, 0, TEXT_END);
@@ -12420,6 +12427,7 @@ static int DrawLevelText(int sx, int sy, char letter, int mode)
     case TEXT_END:
       CopyLevelToUndoBuffer(UNDO_IMMEDIATE);
       DrawEditorElement(sx, sy, Feld[lx][ly]);
+      StopTextInput();
       typing = FALSE;
       break;