1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <math.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "display-types.h"
#include "core/gimpimage.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-scale.h"
#include "gimpdisplayshell-scrollbars.h"
#define MINIMUM_STEP_AMOUNT 1.0
/**
* gimp_display_shell_scrollbars_update:
* @shell:
*
**/
void
gimp_display_shell_scrollbars_update (GimpDisplayShell *shell)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
if (! shell->display)
return;
/* Horizontal scrollbar */
g_object_freeze_notify (G_OBJECT (shell->hsbdata));
/* Update upper and lower value before we set the new value */
gimp_display_shell_scrollbars_setup_horizontal (shell, shell->offset_x);
g_object_set (shell->hsbdata,
"value", (gdouble) shell->offset_x,
"page-size", (gdouble) shell->disp_width,
"page-increment", (gdouble) shell->disp_width / 2,
NULL);
g_object_thaw_notify (G_OBJECT (shell->hsbdata)); /* emits "changed" */
/* Vertcal scrollbar */
g_object_freeze_notify (G_OBJECT (shell->vsbdata));
/* Update upper and lower value before we set the new value */
gimp_display_shell_scrollbars_setup_vertical (shell, shell->offset_y);
g_object_set (shell->vsbdata,
"value", (gdouble) shell->offset_y,
"page-size", (gdouble) shell->disp_height,
"page-increment", (gdouble) shell->disp_height / 2,
NULL);
g_object_thaw_notify (G_OBJECT (shell->vsbdata)); /* emits "changed" */
}
/**
* gimp_display_shell_scrollbars_setup_horizontal:
* @shell:
* @value:
*
* Setup the limits of the horizontal scrollbar
**/
void
gimp_display_shell_scrollbars_setup_horizontal (GimpDisplayShell *shell,
gdouble value)
{
gint bounds_x;
gint bounds_width;
gint bounding_box_x;
gint bounding_box_width;
gint x1;
gint x2;
gdouble lower;
gdouble upper;
gdouble scale_x;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
if (! shell->display || ! gimp_display_get_image (shell->display))
return;
gimp_display_shell_scale_get_image_bounds (shell,
&bounds_x, NULL,
&bounds_width, NULL);
if (! gimp_display_shell_get_infinite_canvas (shell))
{
bounding_box_x = bounds_x;
bounding_box_width = bounds_width;
}
else
{
gimp_display_shell_scale_get_image_bounding_box (
shell,
&bounding_box_x, NULL,
&bounding_box_width, NULL);
}
x1 = bounding_box_x;
x2 = bounding_box_x + bounding_box_width;
x1 = MIN (x1, bounds_x + bounds_width / 2 - shell->disp_width / 2);
x2 = MAX (x2, bounds_x + bounds_width / 2 + (shell->disp_width + 1) / 2);
lower = MIN (value, x1);
upper = MAX (value + shell->disp_width, x2);
gimp_display_shell_get_rotated_scale (shell, &scale_x, NULL);
g_object_set (shell->hsbdata,
"lower", lower,
"upper", upper,
"step-increment", (gdouble) MAX (scale_x, MINIMUM_STEP_AMOUNT),
NULL);
}
/**
* gimp_display_shell_scrollbars_setup_vertical:
* @shell:
* @value:
*
* Setup the limits of the vertical scrollbar
**/
void
gimp_display_shell_scrollbars_setup_vertical (GimpDisplayShell *shell,
gdouble value)
{
gint bounds_y;
gint bounds_height;
gint bounding_box_y;
gint bounding_box_height;
gint y1;
gint y2;
gdouble lower;
gdouble upper;
gdouble scale_y;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
if (! shell->display || ! gimp_display_get_image (shell->display))
return;
gimp_display_shell_scale_get_image_bounds (shell,
NULL, &bounds_y,
NULL, &bounds_height);
if (! gimp_display_shell_get_infinite_canvas (shell))
{
bounding_box_y = bounds_y;
bounding_box_height = bounds_height;
}
else
{
gimp_display_shell_scale_get_image_bounding_box (
shell,
NULL, &bounding_box_y,
NULL, &bounding_box_height);
}
y1 = bounding_box_y;
y2 = bounding_box_y + bounding_box_height;
y1 = MIN (y1, bounds_y + bounds_height / 2 - shell->disp_height / 2);
y2 = MAX (y2, bounds_y + bounds_height / 2 + (shell->disp_height + 1) / 2);
lower = MIN (value, y1);
upper = MAX (value + shell->disp_height, y2);
gimp_display_shell_get_rotated_scale (shell, NULL, &scale_y);
g_object_set (shell->vsbdata,
"lower", lower,
"upper", upper,
"step-increment", (gdouble) MAX (scale_y, MINIMUM_STEP_AMOUNT),
NULL);
}
/**
* gimp_display_shell_scrollbars_update_steppers:
* @shell:
* @min_offset_x:
* @max_offset_x:
* @min_offset_y:
* @max_offset_y:
*
* Sets the scrollbars' stepper sensitivity which is set differently
* from its adjustment limits because we support overscrolling.
**/
void
gimp_display_shell_scrollbars_update_steppers (GimpDisplayShell *shell,
gint min_offset_x,
gint max_offset_x,
gint min_offset_y,
gint max_offset_y)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
gtk_range_set_lower_stepper_sensitivity (GTK_RANGE (shell->hsb),
min_offset_x < shell->offset_x ?
GTK_SENSITIVITY_ON :
GTK_SENSITIVITY_OFF);
gtk_range_set_upper_stepper_sensitivity (GTK_RANGE (shell->hsb),
max_offset_x > shell->offset_x ?
GTK_SENSITIVITY_ON :
GTK_SENSITIVITY_OFF);
gtk_range_set_lower_stepper_sensitivity (GTK_RANGE (shell->vsb),
min_offset_y < shell->offset_y ?
GTK_SENSITIVITY_ON :
GTK_SENSITIVITY_OFF);
gtk_range_set_upper_stepper_sensitivity (GTK_RANGE (shell->vsb),
max_offset_y > shell->offset_y ?
GTK_SENSITIVITY_ON :
GTK_SENSITIVITY_OFF);
}
|