fixed configurability of editor element palette (for columns != 4)
[rocksndiamonds.git] / src / editor.c
index a9d575a50d3ceae155d908df2126b5c530c4ba70..d993af342fb1ee0cc1837b07c33722b7b2a50c9a 100644 (file)
@@ -4946,7 +4946,9 @@ static void ReinitializeElementList()
     {
       if (setup.editor.el_headlines)
       {
-       num_editor_elements += *editor_elements_info[i].headline_list_size;
+       // required for correct padding of palette headline buttons
+       if (*editor_elements_info[i].headline_list_size > 0)
+         num_editor_elements += editor.palette.cols;
 
        for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
        {
@@ -4960,7 +4962,13 @@ static void ReinitializeElementList()
       if (found_inactive_cascade)
        continue;
 
-      num_editor_elements += *editor_elements_info[i].element_list_size;
+      // 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;
+
+      num_editor_elements += element_buttons;
     }
   }
 
@@ -4984,9 +4992,16 @@ static void ReinitializeElementList()
     {
       if (setup.editor.el_headlines)
       {
-       for (j = 0; j < *editor_elements_info[i].headline_list_size; j++)
+       // required for correct padding of palette headline buttons
+       int headline_size = (*editor_elements_info[i].headline_list_size > 0 ?
+                            editor.palette.cols : 0);
+
+       for (j = 0; j < headline_size; j++)
        {
-         int element = (*editor_elements_info[i].headline_list)[j];
+         // use empty elements for padding of palette headline buttons
+         int element = (j < *editor_elements_info[i].headline_list_size ?
+                        (*editor_elements_info[i].headline_list)[j] :
+                        editor_el_empty[0]);
 
          editor_elements[pos++] = element;
 
@@ -4998,8 +5013,19 @@ static void ReinitializeElementList()
       if (found_inactive_cascade)
        continue;
 
-      for (j = 0; j < *editor_elements_info[i].element_list_size; j++)
+      // 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;
+
+      // copy all elements from element list
+      for (j = 0; j < element_list_size; j++)
        editor_elements[pos++] = (*editor_elements_info[i].element_list)[j];
+
+      // use empty elements for padding of palette element buttons
+      for (j = 0; j < element_buttons - element_list_size; j++)
+       editor_elements[pos++] = editor_el_empty[0];
     }
   }
 
@@ -5298,15 +5324,20 @@ static void CreateControlButtons()
     }
     else
     {
-      gd_xoffset = DX - EX + ED_CTRL5_BUTTONS_XPOS;
-      gd_yoffset = DY - EY + ED_CTRL5_BUTTONS_YPOS;
-      width  = ED_CTRL5_BUTTON_XSIZE;
-      height = ED_CTRL5_BUTTON_YSIZE;
+      int graphic = IMG_EDITOR_BUTTON_GFX_PROPERTIES;
+      struct GraphicInfo *gd = &graphic_info[graphic];
+      struct XY ebi = editor.button.properties;
 
-      gd_x1 = DOOR_GFX_PAGEX6 + ED_CTRL5_BUTTONS_GFX_XPOS;
+      gd_bitmap = gd->bitmap;
+      gd_xoffset = DX - EX + ebi.x;
+      gd_yoffset = DY - EY + ebi.y;
+      width  = gd->width;
+      height = gd->height;
+
+      gd_x1 = gd->src_x;
       gd_x2 = 0;       /* no alternative graphic for these buttons */
-      gd_y1 = DOOR_GFX_PAGEY1 + ED_CTRL5_BUTTONS_GFX_YPOS;
-      gd_y2 = DOOR_GFX_PAGEY1 + ED_CTRL5_BUTTONS_GFX_YPOS - height;
+      gd_y1 = gd->src_y;
+      gd_y2 = gd->src_y + gd->pressed_yoffset;
     }
 
     if (id < ED_NUM_CTRL1_4_BUTTONS)