From 866d4ce9bbc1daca05db949c79b3899725da2573 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 15 May 2014 13:56:01 +0100 Subject: Cache scale in gui window. + Uses previously unused scale param of struct gui_window. + Avoids needing to get the scale from the core. + Simplifies code and avoids dereffing bw. --- windows/gui.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/windows/gui.c b/windows/gui.c index 285ef9fc3..e40680f93 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -78,6 +78,22 @@ static struct nsws_pointers nsws_pointer; void gui_window_set_scroll(struct gui_window *w, int sx, int sy); static bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy); +static void nsws_set_scale(struct gui_window *gw, float scale) +{ + assert(gw != NULL); + + if (gw->scale == scale) + return; + + gw->scale = scale; + + if (gw->bw == NULL) + return; + + browser_window_set_scale(gw->bw, scale, true); + browser_window_reformat(gw->bw, false, gw->width, gw->height); +} + static void win32_poll(bool active) { @@ -904,8 +920,7 @@ nsws_window_command(HWND hwnd, int x, y; gui_window_get_scroll(gw, &x, &y); if (gw->bw != NULL) { - browser_window_set_scale(gw->bw, gw->bw->scale * 1.1, true); - browser_window_reformat(gw->bw, false, gw->width, gw->height); + nsws_set_scale(gw, gw->scale * 1.1); } gui_window_redraw_window(gw); gui_window_set_scroll(gw, x, y); @@ -916,9 +931,7 @@ nsws_window_command(HWND hwnd, int x, y; gui_window_get_scroll(gw, &x, &y); if (gw->bw != NULL) { - browser_window_set_scale(gw->bw, - gw->bw->scale * 0.9, true); - browser_window_reformat(gw->bw, false, gw->width, gw->height); + nsws_set_scale(gw, gw->scale * 0.9); } gui_window_redraw_window(gw); gui_window_set_scroll(gw, x, y); @@ -929,8 +942,7 @@ nsws_window_command(HWND hwnd, int x, y; gui_window_get_scroll(gw, &x, &y); if (gw->bw != NULL) { - browser_window_set_scale(gw->bw, 1.0, true); - browser_window_reformat(gw->bw, false, gw->width, gw->height); + nsws_set_scale(gw, 1.0); } gui_window_redraw_window(gw); gui_window_set_scroll(gw, x, y); @@ -1248,6 +1260,7 @@ gui_window_create(struct browser_window *bw, gw->width = 800; gw->height = 600; + gw->scale = 1.0; gw->toolbuttonsize = 24; gw->requestscrollx = 0; gw->requestscrolly = 0; @@ -1456,8 +1469,8 @@ static void gui_window_update_box(struct gui_window *gw, const struct rect *rect RECT redrawrect; - redrawrect.left = (long)rect->x0 - (gw->scrollx / gw->bw->scale); - redrawrect.top = (long)rect->y0 - (gw->scrolly / gw->bw->scale); + redrawrect.left = (long)rect->x0 - (gw->scrollx / gw->scale); + redrawrect.top = (long)rect->y0 - (gw->scrolly / gw->scale); redrawrect.right =(long)rect->x1; redrawrect.bottom = (long)rect->y1; @@ -1708,9 +1721,9 @@ static void gui_window_place_caret(struct gui_window *w, int x, int y, { if (w == NULL) return; - CreateCaret(w->drawingarea, (HBITMAP)NULL, 1, height * w->bw->scale); - SetCaretPos(x * w->bw->scale - w->scrollx, - y * w->bw->scale - w->scrolly); + CreateCaret(w->drawingarea, (HBITMAP)NULL, 1, height * w->scale); + SetCaretPos(x * w->scale - w->scrollx, + y * w->scale - w->scrolly); ShowCaret(w->drawingarea); } -- cgit v1.2.3