From 4aeaa83f9ee7b8045b943a49e784a1b3ea4fbb7b Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 12 Jul 2008 14:48:09 +0000 Subject: [PATCH] The following change is conceptually based on a patch by Alexia Death and 2008-07-12 Martin Nordholts The following change is conceptually based on a patch by Alexia Death and implements the core functionality for bug #362915. * app/display/gimpdisplayshell-scroll.[ch] (gimp_display_shell_scroll_clamp_offsets): Clamp the offsets in such a way that allows to scroll beyond the image border. (gimp_display_shell_setup_hscrollbar_with_value) (gimp_display_shell_setup_vscrollbar_with_value): Put common scrollbar range setup code here. * app/display/gimpdisplayshell-scale.c (gimp_display_shell_scale_setup): Use above helper functions for setting up scrollbar range. * app/display/gimpdisplayshell-callbacks.c: Handle adjustment of the scrollbar range when they are about to change value. * app/display/gimpdisplayshell.c: Always keep the scrollbar steppers sensitive to user input. svn path=/trunk/; revision=26166 --- ChangeLog | 24 +++++ app/display/gimpdisplayshell-callbacks.c | 62 ++++++++++++ app/display/gimpdisplayshell-scale.c | 20 +++- app/display/gimpdisplayshell-scroll.c | 116 +++++++++++++++++++++-- app/display/gimpdisplayshell-scroll.h | 5 + app/display/gimpdisplayshell.c | 8 ++ 6 files changed, 220 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index ada1648677..41252f84f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2008-07-12 Martin Nordholts + + The following change is conceptually based on a patch by + Alexia Death and implements the core functionality for + bug #362915. + + * app/display/gimpdisplayshell-scroll.[ch] + (gimp_display_shell_scroll_clamp_offsets): Clamp the offsets in + such a way that allows to scroll beyond the image border. + + (gimp_display_shell_setup_hscrollbar_with_value) + (gimp_display_shell_setup_vscrollbar_with_value): Put common + scrollbar range setup code here. + + * app/display/gimpdisplayshell-scale.c + (gimp_display_shell_scale_setup): Use above helper functions for + setting up scrollbar range. + + * app/display/gimpdisplayshell-callbacks.c: Handle adjustment of + the scrollbar range when they are about to change value. + + * app/display/gimpdisplayshell.c: Always keep the scrollbar + steppers sensitive to user input. + 2008-07-12 Martin Nordholts * app/display/gimpdisplayshell-scroll.c: diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c index 1c1465d671..58bea39a67 100644 --- a/app/display/gimpdisplayshell-callbacks.c +++ b/app/display/gimpdisplayshell-callbacks.c @@ -85,7 +85,15 @@ static void gimp_display_shell_vscrollbar_update (GtkAdjustment * GimpDisplayShell *shell); static void gimp_display_shell_hscrollbar_update (GtkAdjustment *adjustment, GimpDisplayShell *shell); +static gboolean gimp_display_shell_vscrollbar_update_range (GtkRange *range, + GtkScrollType scroll, + gdouble value, + GimpDisplayShell *shell); +static gboolean gimp_display_shell_hscrollbar_update_range (GtkRange *range, + GtkScrollType scroll, + gdouble value, + GimpDisplayShell *shell); static GdkModifierType gimp_display_shell_key_to_state (gint key); @@ -239,6 +247,14 @@ gimp_display_shell_canvas_realize (GtkWidget *canvas, G_CALLBACK (gimp_display_shell_vscrollbar_update), shell); + g_signal_connect (shell->hsb, "change-value", + G_CALLBACK (gimp_display_shell_hscrollbar_update_range), + shell); + + g_signal_connect (shell->vsb, "change-value", + G_CALLBACK (gimp_display_shell_vscrollbar_update_range), + shell); + /* allow shrinking */ gtk_widget_set_size_request (GTK_WIDGET (shell), 0, 0); @@ -324,6 +340,52 @@ gimp_display_shell_canvas_expose (GtkWidget *widget, } } +gboolean +gimp_display_shell_hscrollbar_update_range (GtkRange *range, + GtkScrollType scroll, + gdouble value, + GimpDisplayShell *shell) +{ + g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), TRUE); + + if (! shell->display) + return TRUE; + + if ((scroll == GTK_SCROLL_JUMP) || + (scroll == GTK_SCROLL_PAGE_BACKWARD) || + (scroll == GTK_SCROLL_PAGE_FORWARD)) + return FALSE; + + gimp_display_shell_setup_hscrollbar_with_value (shell, value); + + gtk_adjustment_changed (shell->hsbdata); + + return FALSE; +} + +gboolean +gimp_display_shell_vscrollbar_update_range (GtkRange *range, + GtkScrollType scroll, + gdouble value, + GimpDisplayShell *shell) +{ + g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), TRUE); + + if (! shell->display) + return TRUE; + + if ((scroll == GTK_SCROLL_JUMP) || + (scroll == GTK_SCROLL_PAGE_BACKWARD) || + (scroll == GTK_SCROLL_PAGE_FORWARD)) + return FALSE; + + gimp_display_shell_setup_vscrollbar_with_value (shell, value); + + gtk_adjustment_changed (shell->vsbdata); + + return FALSE; +} + static void gimp_display_shell_check_device_cursor (GimpDisplayShell *shell) { diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index 631efce5ff..de753a6e7b 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -117,21 +117,31 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) sh = image_height; } + + /* Horizontal scrollbar */ + shell->hsbdata->value = shell->offset_x; - shell->hsbdata->upper = sw; - shell->hsbdata->page_size = MIN (sw, shell->disp_width); + shell->hsbdata->page_size = shell->disp_width; shell->hsbdata->page_increment = shell->disp_width / 2; shell->hsbdata->step_increment = shell->scale_x; + gimp_display_shell_setup_hscrollbar_with_value (shell, shell->offset_x); + + gtk_adjustment_changed (shell->hsbdata); + + + /* Vertcal scrollbar */ + shell->vsbdata->value = shell->offset_y; - shell->vsbdata->upper = sh; - shell->vsbdata->page_size = MIN (sh, shell->disp_height); + shell->vsbdata->page_size = shell->disp_height; shell->vsbdata->page_increment = shell->disp_height / 2; shell->vsbdata->step_increment = shell->scale_y; - gtk_adjustment_changed (shell->hsbdata); + gimp_display_shell_setup_vscrollbar_with_value (shell, shell->offset_y); + gtk_adjustment_changed (shell->vsbdata); + /* Setup rulers */ { gdouble horizontal_lower; diff --git a/app/display/gimpdisplayshell-scroll.c b/app/display/gimpdisplayshell-scroll.c index 20d1fd5127..61b78d65c5 100644 --- a/app/display/gimpdisplayshell-scroll.c +++ b/app/display/gimpdisplayshell-scroll.c @@ -36,6 +36,9 @@ #include "gimpdisplayshell-scroll.h" +#define OVERPAN_FACTOR 0.5 + + /** * gimp_display_shell_center_around_image_coordinate: * @shell: @@ -122,33 +125,46 @@ gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell) if (shell->display->image) { gint sw, sh; + gint min_offset_x; + gint max_offset_x; + gint min_offset_y; + gint max_offset_y; sw = SCALEX (shell, gimp_image_get_width (shell->display->image)); sh = SCALEY (shell, gimp_image_get_height (shell->display->image)); - if (shell->disp_width > sw) + if (shell->disp_width < sw) { - shell->offset_x = -(shell->disp_width - sw) / 2; + min_offset_x = 0 - shell->disp_width * OVERPAN_FACTOR; + max_offset_x = sw - shell->disp_width * (1.0 - OVERPAN_FACTOR); } else { - gint min_offset_x = 0; - gint max_offset_x = sw - shell->disp_width; + gint overpan_amount; - shell->offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x); + overpan_amount = shell->disp_width - sw * (1.0 - OVERPAN_FACTOR); + + min_offset_x = 0 - overpan_amount; + max_offset_x = sw + overpan_amount - shell->disp_width; } - if (shell->disp_height > sh) + if (shell->disp_height < sh) { - shell->offset_y = -(shell->disp_height - sh) / 2; + min_offset_y = 0 - shell->disp_height * OVERPAN_FACTOR; + max_offset_y = sh - shell->disp_height * (1.0 - OVERPAN_FACTOR); } else { - gint min_offset_y = 0; - gint max_offset_y = sh - shell->disp_height; + gint overpan_amount; - shell->offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y); + overpan_amount = shell->disp_height - sh * (1.0 - OVERPAN_FACTOR); + + min_offset_y = 0 - overpan_amount; + max_offset_y = sh + overpan_amount - shell->disp_height; } + + shell->offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x); + shell->offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y); } else { @@ -298,3 +314,83 @@ gimp_display_shell_get_render_start_offset (const GimpDisplayShell *shell, if (offset_x) *offset_x = MAX (0, shell->offset_x); if (offset_y) *offset_y = MAX (0, shell->offset_y); } + +/** + * gimp_display_shell_setup_hscrollbar_with_value: + * @shell: + * @value: + * + * Setup the limits of the horizontal scrollbar + * + **/ +void +gimp_display_shell_setup_hscrollbar_with_value (GimpDisplayShell *shell, + gdouble value) +{ + gint sw; + + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); + + if (! shell->display || + ! shell->display->image) + return; + + sw = SCALEX (shell, gimp_image_get_width (shell->display->image)); + + if (shell->disp_width < sw) + { + shell->hsbdata->upper = MAX (value + shell->disp_width, + sw); + + shell->hsbdata->lower = MIN (value, + 0); + } + else + { + shell->hsbdata->lower = MIN (value, + -(shell->disp_width - sw) / 2); + + shell->hsbdata->upper = MAX (value + shell->disp_width, + sw + (shell->disp_width - sw) / 2); + } +} + +/** + * gimp_display_shell_setup_vscrollbar_with_value: + * @shell: + * @value: + * + * Setup the limits of the vertical scrollbar + * + **/ +void +gimp_display_shell_setup_vscrollbar_with_value (GimpDisplayShell *shell, + gdouble value) +{ + gint sh; + + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); + + if (! shell->display || + ! shell->display->image) + return; + + sh = SCALEY (shell, gimp_image_get_height (shell->display->image)); + + if (shell->disp_height < sh) + { + shell->vsbdata->upper = MAX (value + shell->disp_height, + sh); + + shell->vsbdata->lower = MIN (value, + 0); + } + else + { + shell->vsbdata->lower = MIN (value, + -(shell->disp_height - sh) / 2); + + shell->vsbdata->upper = MAX (value + shell->disp_height, + sh + (shell->disp_height - sh) / 2); + } +} diff --git a/app/display/gimpdisplayshell-scroll.h b/app/display/gimpdisplayshell-scroll.h index 7682c71bc3..f61d7bb3e0 100644 --- a/app/display/gimpdisplayshell-scroll.h +++ b/app/display/gimpdisplayshell-scroll.h @@ -50,5 +50,10 @@ void gimp_display_shell_get_render_start_offset (const GimpDispla gint *offset_x, gint *offset_y); +void gimp_display_shell_setup_hscrollbar_with_value (GimpDisplayShell *shell, + gdouble value); +void gimp_display_shell_setup_vscrollbar_with_value (GimpDisplayShell *shell, + gdouble value); + #endif /* __GIMP_DISPLAY_SHELL_SCROLL_H__ */ diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index cb43066056..d5c77ae984 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -935,12 +935,20 @@ gimp_display_shell_new (GimpDisplay *display, shell->hsbdata = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, image_width, 1, 1, image_width)); shell->hsb = gtk_hscrollbar_new (shell->hsbdata); + + gtk_range_set_lower_stepper_sensitivity (GTK_RANGE (shell->hsb), GTK_SENSITIVITY_ON); + gtk_range_set_upper_stepper_sensitivity (GTK_RANGE (shell->hsb), GTK_SENSITIVITY_ON); + GTK_WIDGET_UNSET_FLAGS (shell->hsb, GTK_CAN_FOCUS); /* the vertical scrollbar */ shell->vsbdata = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, image_height, 1, 1, image_height)); shell->vsb = gtk_vscrollbar_new (shell->vsbdata); + + gtk_range_set_lower_stepper_sensitivity (GTK_RANGE (shell->vsb), GTK_SENSITIVITY_ON); + gtk_range_set_upper_stepper_sensitivity (GTK_RANGE (shell->vsb), GTK_SENSITIVITY_ON); + GTK_WIDGET_UNSET_FLAGS (shell->vsb, GTK_CAN_FOCUS); /* create the contents of the inner_table ********************************/