Commit 9e2713db authored by ROOL's avatar ROOL 🤖
Browse files

Reduce redraws of colour panel

Detail:
  The colour panel swatch was being redrawn unnecessarily on every open window request due to not knowing whether the furniture icons had changed size. Now, only recalculate the sizes and force a redraw on a mode change event, this eliminates the flicker when moving the sprite window around.
Admin:
  Submission for the Paint bounty.
parent ea656225
......@@ -141,6 +141,71 @@ void colourpanel_redraw (main_window *window)
}
}
/*************************************************************************
* *
* Recalculates the size of a colour panel and initiates a redraw *
* *
*************************************************************************/
void colourpanel_resize (main_window *window)
{ if (window->data->sprite.colourpanel != NULL)
{ int x_eig, y_eig, max_eig;
int colpanelwidth, colpanelheight, coloursize;
wimp_wstate sprite_w_state;
wimp_redrawstr sprite_redraw_str;
wimp_openstr colpanel_openstr;
wimp_redrawstr colpanel_redraw_str;
int linkage = 0x05550000;
x_eig = bbc_vduvar (bbc_XEigFactor);
y_eig = bbc_vduvar (bbc_YEigFactor);
max_eig = MAX(x_eig, y_eig);
colpanelheight = get_horizontal_scrollbar_height (window->handle);
ftracef2 ("Updated colour panel height: %d due to wimp_EOPEN Old height: %d\n",
colpanelheight, window->data->sprite.colourpanel->size);
window->data->sprite.colourpanel->size = colpanelheight;
coloursize = colpanelheight - (4 << y_eig);
/* Round DOWN to nearest whole number of pixels*/
coloursize = (coloursize >> max_eig) << max_eig;
colpanelwidth = coloursize * 2 + (4 << x_eig );
/* We will prevent the user from making the window narrow enough to
squash the buttons. With the colour panel present, this is possible
for very short sprite names */
window->data->sprite.minwidth =
get_horizontal_arrows_width (window->handle) +
colpanelwidth + (14 << x_eig);
/* Get the new state of the sprite window */
wimpt_noerr (wimp_get_wind_state (window->handle, &sprite_w_state));
/* And its outline */
sprite_redraw_str.w = window->handle;
wimpt_noerr (wimp_getwindowoutline (&sprite_redraw_str));
colpanel_openstr.w = window->data->sprite.colourpanel->handle;
colpanel_openstr.behind = -1;
colpanel_openstr.x = 0;
colpanel_openstr.y = 0;
colpanel_openstr.box.x0 = sprite_redraw_str.box.x0;
colpanel_openstr.box.y1 = sprite_w_state.o.box.y0 - 2;
colpanel_openstr.box.x1 = colpanel_openstr.box.x0 + colpanelwidth;
colpanel_openstr.box.y0 = colpanel_openstr.box.y1 - colpanelheight + 4;
colpanel_redraw_str.w = colpanel_openstr.w;
colpanel_redraw_str.box.y1 = 0;
colpanel_redraw_str.box.y0 = -colpanelheight + 4;
colpanel_redraw_str.box.x0 = 0;
colpanel_redraw_str.box.x1 = colpanelwidth;
wimpt_complain (wimp_set_extent (&colpanel_redraw_str));
wimpt_complain (os_swix5 (Wimp_OpenWindow, 0, &colpanel_openstr, *(int*)"TASK", window->handle, linkage));
wimpt_noerr (wimp_force_redraw (&colpanel_redraw_str));
}
}
/***********************************************************************
* *
* Drag processor to swap colours on the colour panel *
......
......@@ -3267,8 +3267,8 @@ static void Background_Events (wimp_eventstr *e, void *handle)
if (sprite->bgcolourhandle != 0 && sprite->bgcolourdialogue == 0)
main_force_redraw (sprite->bgcolourhandle);
/*Redraw all colour panels.*/
colourpanel_redraw (window);
/*Resize and redraw all colour panels.*/
colourpanel_resize (window);
}
for (window = main_windows; window != NULL; window = window->link)
......
......@@ -795,64 +795,6 @@ void sprwindow_event_handler (wimp_eventstr *e, void *handle)
resize_start->sprite_width = spritewidth;
resize_start->sprite_height = spriteheight;
}
/* Handle the colour panel in case the dimensions changed */
if (window->data->sprite.colourpanel != NULL)
{ int x_eig, y_eig, max_eig;
int colpanelwidth, colpanelheight, coloursize;
wimp_wstate sprite_w_state;
wimp_redrawstr sprite_redraw_str;
wimp_openstr colpanel_openstr;
wimp_redrawstr colpanel_redraw_str;
int linkage = 0x5550000;
x_eig = bbc_vduvar (bbc_XEigFactor);
y_eig = bbc_vduvar (bbc_YEigFactor);
if (x_eig > y_eig) max_eig = x_eig; else max_eig = y_eig;
colpanelheight = get_horizontal_scrollbar_height (window->handle);
ftracef2 ("Updated colour panel height: %d due to wimp_EOPEN Old height: %d\n",
colpanelheight, window->data->sprite.colourpanel->size);
window->data->sprite.colourpanel->size = colpanelheight;
coloursize = colpanelheight - (4 << y_eig);
/*Round DOWN to nearest whole number of pixels*/
coloursize = (coloursize >> max_eig) << max_eig;
colpanelwidth = coloursize * 2 + (4 << x_eig );
/* We will prevent the user from making the window narrow enough to
squash the buttons. With the colour panel present, this is possible
for very short sprite names */
window->data->sprite.minwidth =
(char)(get_horizontal_arrows_width (window->handle) +
colpanelwidth + (14 << x_eig));
/*Get the new state of the sprite window*/
wimpt_noerr (wimp_get_wind_state (window->handle,
&sprite_w_state));
/*And its outline*/
sprite_redraw_str.w = window->handle;
wimpt_noerr (wimp_getwindowoutline (&sprite_redraw_str));
colpanel_openstr.w = window->data->sprite.colourpanel->handle;
colpanel_openstr.behind = -1;
colpanel_openstr.x = 0;
colpanel_openstr.y = 0;
colpanel_openstr.box.x0 = sprite_redraw_str.box.x0;
colpanel_openstr.box.y1 = sprite_w_state.o.box.y0 - 2;
colpanel_openstr.box.x1 = colpanel_openstr.box.x0 + colpanelwidth;
colpanel_openstr.box.y0 = colpanel_openstr.box.y1 - colpanelheight + 4;
colpanel_redraw_str.w = colpanel_openstr.w;
colpanel_redraw_str.box.y1 = 0;
colpanel_redraw_str.box.y0 = -colpanelheight + 4;
colpanel_redraw_str.box.x0 = 0;
colpanel_redraw_str.box.x1 = colpanelwidth;
wimpt_complain (wimp_set_extent (&colpanel_redraw_str));
wimpt_complain (os_swix5 (Wimp_OpenWindow, 0, &colpanel_openstr, *(int*)"TASK", window->handle, linkage));
wimpt_noerr (wimp_force_redraw (&colpanel_redraw_str));
}
}
break;
......
......@@ -22,6 +22,7 @@ extern main_template colourpanel_template;
extern int get_horizontal_scrollbar_height (wimp_w);
extern int get_horizontal_arrows_width (wimp_w);
extern void colourpanel_redraw (main_window *);
extern void colourpanel_resize (main_window *);
extern void colourpanel_event_handler (wimp_eventstr *e, void *handle);
extern colour_panel *colourpanel_new (main_sprite_window *);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment