From a33d80107b3bca443414a8d2ed385a1c319ab72c Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 12 Jul 2008 07:00:46 +0000 Subject: [PATCH] Kill disp_[xy]offset! We now keep store that information by using negative 2008-07-12 Martin Nordholts * app/display/gimpdisplayshell.c: Kill disp_[xy]offset! We now keep store that information by using negative values in offset_[xy]. * app/display/gimpdisplayshell-scroll.[ch] (gimp_display_shell_scroll_clamp_offsets) (gimp_display_shell_get_scaled_image_viewport_offset): Adjust accordingly to preserve current behaviour. (gimp_display_shell_get_disp_offset): New function to get the old disp_[xy]offset based on the new offset_[xy]. (gimp_display_shell_get_render_start_offset): New function to get th old offset_[xy] based on the new offset_[xy]. * app/display/gimpdisplayshell-draw.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-render.c: Get rid of disp_[xy]offset and use gimp_display_shell_get_render_start_offset() and gimp_display_shell_get_disp_offset() instead. svn path=/trunk/; revision=26146 --- ChangeLog | 24 +++++++ app/display/gimpdisplayshell-draw.c | 9 ++- app/display/gimpdisplayshell-render.c | 35 +++++++--- app/display/gimpdisplayshell-scale.c | 31 ++------- app/display/gimpdisplayshell-scroll.c | 93 +++++++++++++++++++++++++-- app/display/gimpdisplayshell-scroll.h | 8 +++ app/display/gimpdisplayshell.c | 2 - app/display/gimpdisplayshell.h | 2 - 8 files changed, 158 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53eb5a4c73..2e0eb2cf7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2008-07-12 Martin Nordholts + + * app/display/gimpdisplayshell.c: Kill disp_[xy]offset! We now + keep store that information by using negative values in + offset_[xy]. + + * app/display/gimpdisplayshell-scroll.[ch] + (gimp_display_shell_scroll_clamp_offsets) + (gimp_display_shell_get_scaled_image_viewport_offset): Adjust + accordingly to preserve current behaviour. + + (gimp_display_shell_get_disp_offset): New function to get the old + disp_[xy]offset based on the new offset_[xy]. + + (gimp_display_shell_get_render_start_offset): New function to get + th old offset_[xy] based on the new offset_[xy]. + + * app/display/gimpdisplayshell-draw.c + * app/display/gimpdisplayshell-scale.c + * app/display/gimpdisplayshell-render.c: Get rid of + disp_[xy]offset and use + gimp_display_shell_get_render_start_offset() and + gimp_display_shell_get_disp_offset() instead. + 2008-07-11 Martin Nordholts * app/display/gimpdisplayshell-scale.c diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c index 64cb417e2a..30321d8637 100644 --- a/app/display/gimpdisplayshell-draw.c +++ b/app/display/gimpdisplayshell-draw.c @@ -572,14 +572,19 @@ gimp_display_shell_draw_area (GimpDisplayShell *shell, { for (j = x; j < x2; j += GIMP_DISPLAY_RENDER_BUF_WIDTH) { + gint disp_xoffset, disp_yoffset; gint dx, dy; dx = MIN (x2 - j, GIMP_DISPLAY_RENDER_BUF_WIDTH); dy = MIN (y2 - i, GIMP_DISPLAY_RENDER_BUF_HEIGHT); + gimp_display_shell_get_disp_offset (shell, + &disp_xoffset, + &disp_yoffset); + gimp_display_shell_render (shell, - j - shell->disp_xoffset, - i - shell->disp_yoffset, + j - disp_xoffset, + i - disp_yoffset, dx, dy, shell->highlight ? &rect : NULL); } diff --git a/app/display/gimpdisplayshell-render.c b/app/display/gimpdisplayshell-render.c index 5d8315055a..1680e0d42f 100644 --- a/app/display/gimpdisplayshell-render.c +++ b/app/display/gimpdisplayshell-render.c @@ -44,6 +44,7 @@ #include "gimpdisplayshell.h" #include "gimpdisplayshell-filter.h" #include "gimpdisplayshell-render.h" +#include "gimpdisplayshell-scroll.h" #define GIMP_DISPLAY_ZOOM_FAST (1 << 0) /* use the fastest possible code path trading quality for speed @@ -223,6 +224,8 @@ gimp_display_shell_render (GimpDisplayShell *shell, GimpImage *image; RenderInfo info; GimpImageType type; + gint offset_x; + gint offset_y; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); g_return_if_fail (w > 0 && h > 0); @@ -230,13 +233,15 @@ gimp_display_shell_render (GimpDisplayShell *shell, image = shell->display->image; projection = image->projection; + gimp_display_shell_get_render_start_offset (shell, &offset_x, &offset_y); + /* Initialize RenderInfo with values that don't change during the * call of this function. */ info.shell = shell; - info.x = x + shell->offset_x; - info.y = y + shell->offset_y; + info.x = x + offset_x; + info.y = y + offset_y; info.w = w; info.h = h; @@ -310,12 +315,20 @@ gimp_display_shell_render (GimpDisplayShell *shell, } /* put it to the screen */ - gimp_canvas_draw_rgb (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_RENDER, - x + shell->disp_xoffset, y + shell->disp_yoffset, + { + gint disp_xoffset, disp_yoffset; + gint offset_x, offset_y; + + gimp_display_shell_get_disp_offset (shell, &disp_xoffset, &disp_yoffset); + gimp_display_shell_get_render_start_offset (shell, &offset_x, &offset_y); + + gimp_canvas_draw_rgb (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_RENDER, + x + disp_xoffset, y + disp_yoffset, w, h, shell->render_buf, 3 * GIMP_DISPLAY_RENDER_BUF_WIDTH, - shell->offset_x, shell->offset_y); + offset_x, offset_y); + } } @@ -338,16 +351,20 @@ gimp_display_shell_render_highlight (GimpDisplayShell *shell, { guchar *buf = shell->render_buf; GdkRectangle rect; + gint offset_x; + gint offset_y; - rect.x = shell->offset_x + x; - rect.y = shell->offset_y + y; + gimp_display_shell_get_render_start_offset (shell, &offset_x, &offset_y); + + rect.x = x + offset_x; + rect.y = y + offset_y; rect.width = w; rect.height = h; if (gdk_rectangle_intersect (highlight, &rect, &rect)) { - rect.x -= shell->offset_x + x; - rect.y -= shell->offset_y + y; + rect.x -= x + offset_x; + rect.y -= y + offset_y; for (y = 0; y < rect.y; y++) { diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index 5e78d4ff6d..da883ef935 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -92,6 +92,8 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) gfloat sx, sy; gint image_width; gint image_height; + gint offset_x; + gint offset_y; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); @@ -117,13 +119,15 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) sy = image_height; } - shell->hsbdata->value = shell->offset_x; + gimp_display_shell_get_render_start_offset (shell, &offset_x, &offset_y); + + shell->hsbdata->value = offset_x; shell->hsbdata->upper = sx; shell->hsbdata->page_size = MIN (sx, shell->disp_width); shell->hsbdata->page_increment = shell->disp_width / 2; shell->hsbdata->step_increment = shell->scale_x; - shell->vsbdata->value = shell->offset_y; + shell->vsbdata->value = offset_y; shell->vsbdata->upper = sy; shell->vsbdata->page_size = MIN (sy, shell->disp_height); shell->vsbdata->page_increment = shell->disp_height / 2; @@ -167,29 +171,6 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) } - /* Center the image if its scaled width/height fits within the - * viewport - */ - - if (image && sx < shell->disp_width) - { - shell->disp_xoffset = (shell->disp_width - sx) / 2; - } - else - { - shell->disp_xoffset = 0; - } - - if (image && sy < shell->disp_height) - { - shell->disp_yoffset = (shell->disp_height - sy) / 2; - } - else - { - shell->disp_yoffset = 0; - } - - /* Adjust due to scrolling */ gimp_display_shell_get_scaled_image_viewport_offset (shell, diff --git a/app/display/gimpdisplayshell-scroll.c b/app/display/gimpdisplayshell-scroll.c index b4a740fba4..3ea6ccf913 100644 --- a/app/display/gimpdisplayshell-scroll.c +++ b/app/display/gimpdisplayshell-scroll.c @@ -121,11 +121,29 @@ gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell) sw = SCALEX (shell, gimp_image_get_width (shell->display->image)); sh = SCALEY (shell, gimp_image_get_height (shell->display->image)); - shell->offset_x = CLAMP (shell->offset_x, 0, - MAX (sw - shell->disp_width, 0)); + if (shell->disp_width > sw) + { + shell->offset_x = -(shell->disp_width - sw) / 2; + } + else + { + gint min_offset_x = 0; + gint max_offset_x = sw - shell->disp_width; - shell->offset_y = CLAMP (shell->offset_y, 0, - MAX (sh - shell->disp_height, 0)); + shell->offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x); + } + + if (shell->disp_height > sh) + { + shell->offset_y = -(shell->disp_height - sh) / 2; + } + else + { + gint min_offset_y = 0; + gint max_offset_y = sh - shell->disp_height; + + shell->offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y); + } } else { @@ -211,6 +229,69 @@ gimp_display_shell_get_scaled_image_viewport_offset (const GimpDisplayShell *she { g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); - if (x) *x = shell->disp_xoffset - shell->offset_x; - if (y) *y = shell->disp_yoffset - shell->offset_y; + if (x) *x = -shell->offset_x; + if (y) *y = -shell->offset_y; +} + +/** + * gimp_display_shell_get_disp_offset: + * @shell: + * @disp_xoffset: + * @disp_yoffset: + * + * In viewport coordinates, get the offset of where to start rendering + * the scaled image. + * + **/ +void +gimp_display_shell_get_disp_offset (const GimpDisplayShell *shell, + gint *disp_xoffset, + gint *disp_yoffset) +{ + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); + + if (disp_xoffset) + { + if (shell->offset_x < 0) + { + *disp_xoffset = -shell->offset_x; + } + else + { + *disp_xoffset = 0; + } + } + + if (disp_yoffset) + { + if (shell->offset_y < 0) + { + *disp_yoffset = -shell->offset_y; + } + else + { + *disp_yoffset = 0; + } + } +} + +/** + * gimp_display_shell_get_render_start_offset: + * @shell: + * @offset_x: + * @offset_y: + * + * Get the offset into the scaled image that we should start render + * from + * + **/ +void +gimp_display_shell_get_render_start_offset (const GimpDisplayShell *shell, + gint *offset_x, + gint *offset_y) +{ + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); + + if (offset_x) *offset_x = MAX (0, shell->offset_x); + if (offset_y) *offset_y = MAX (0, shell->offset_y); } diff --git a/app/display/gimpdisplayshell-scroll.h b/app/display/gimpdisplayshell-scroll.h index f2d5364e15..ede260b634 100644 --- a/app/display/gimpdisplayshell-scroll.h +++ b/app/display/gimpdisplayshell-scroll.h @@ -42,5 +42,13 @@ void gimp_display_shell_get_scaled_image_viewport_offset (const GimpDispla gint *x, gint *y); +void gimp_display_shell_get_disp_offset (const GimpDisplayShell *shell, + gint *disp_xoffset, + gint *disp_yoffset); + +void gimp_display_shell_get_render_start_offset (const GimpDisplayShell *shell, + gint *offset_x, + gint *offset_y); + #endif /* __GIMP_DISPLAY_SHELL_SCROLL_H__ */ diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 144ef1abd9..cb43066056 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -257,8 +257,6 @@ gimp_display_shell_init (GimpDisplayShell *shell) shell->disp_width = 0; shell->disp_height = 0; - shell->disp_xoffset = 0; - shell->disp_yoffset = 0; shell->proximity = FALSE; shell->snap_to_guides = TRUE; diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index ded2d1e5f6..2350ca830a 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -99,8 +99,6 @@ struct _GimpDisplayShell gint disp_width; /* width of drawing area */ gint disp_height; /* height of drawing area */ - gint disp_xoffset; - gint disp_yoffset; gboolean proximity; /* is a device in proximity */ gboolean snap_to_guides; /* should the guides be snapped to? */