From: Holger Schemel Date: Sat, 1 Dec 2018 10:50:32 +0000 (+0100) Subject: added support for dynamically sized (and placed) editor palette X-Git-Tag: 4.1.2.0~88 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=f0b6179ac5fd4ff548d4263488373408f92874e8;p=rocksndiamonds.git added support for dynamically sized (and placed) editor palette When using the value "-1" for columns or rows of the editor palette (that is, values "editor.palette.cols" and "editor.palette.rows"), these numbers are dynamically calculated according to the size of the editor playfield area. When setting "editor.palette.x" or "editor.palette.y" to "-1", also the position of the editor palette is dynamically calculated (to be centered within the playfield area). (As these values for columns and rows are used at a very early stage in the level editor to allocate memory for palette buttons, make sure that no negative numbers are used here for memory calculations.) --- diff --git a/src/editor.c b/src/editor.c index 9396d5ef..8338bbb3 100644 --- a/src/editor.c +++ b/src/editor.c @@ -65,8 +65,10 @@ #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++) diff --git a/src/files.c b/src/files.c index 7af56662..18759ae2 100644 --- a/src/files.c +++ b/src/files.c @@ -9894,6 +9894,40 @@ static void InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics(void) *editor_buttons_xy[i].dst = *editor_buttons_xy[i].src; } } + + // adjust editor palette rows and columns if specified to be dynamic + + if (editor.palette.cols == -1) + { + int vp_width = viewport.playfield[GFX_SPECIAL_ARG_EDITOR].width; + int bt_width = graphic_info[IMG_EDITOR_PALETTE_BUTTON].width; + int sc_width = graphic_info[IMG_EDITOR_PALETTE_SCROLLBAR].width; + + editor.palette.cols = (vp_width - sc_width) / bt_width; + + if (editor.palette.x == -1) + { + int palette_width = editor.palette.cols * bt_width + sc_width; + + editor.palette.x = (vp_width - palette_width) / 2; + } + } + + if (editor.palette.rows == -1) + { + int vp_height = viewport.playfield[GFX_SPECIAL_ARG_EDITOR].height; + int bt_height = graphic_info[IMG_EDITOR_PALETTE_BUTTON].height; + int tx_height = getFontHeight(FONT_TEXT_2); + + editor.palette.rows = (vp_height - tx_height) / bt_height; + + if (editor.palette.y == -1) + { + int palette_height = editor.palette.rows * bt_height + tx_height; + + editor.palette.y = (vp_height - palette_height) / 2; + } + } } static void LoadMenuDesignSettingsFromFilename(char *filename)