112
117
GimpTool *tool = GIMP_TOOL (magnify_tool);
119
119
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
120
120
gimp_tool_control_set_handle_empty_image (tool->control, TRUE);
121
121
gimp_tool_control_set_wants_click (tool->control, TRUE);
122
122
gimp_tool_control_set_snap_to (tool->control, FALSE);
124
gimp_tool_control_set_cursor (tool->control,
126
124
gimp_tool_control_set_tool_cursor (tool->control,
127
125
GIMP_TOOL_CURSOR_ZOOM);
128
126
gimp_tool_control_set_cursor_modifier (tool->control,
129
127
GIMP_CURSOR_MODIFIER_PLUS);
130
128
gimp_tool_control_set_toggle_cursor_modifier (tool->control,
131
129
GIMP_CURSOR_MODIFIER_MINUS);
135
gimp_magnify_tool_button_press (GimpTool *tool,
138
GdkModifierType state,
139
GimpDisplay *display)
138
gimp_magnify_tool_button_press (GimpTool *tool,
139
const GimpCoords *coords,
141
GdkModifierType state,
142
GimpButtonPressType press_type,
143
GimpDisplay *display)
141
145
GimpMagnifyTool *magnify = GIMP_MAGNIFY_TOOL (tool);
162
166
GimpMagnifyTool *magnify = GIMP_MAGNIFY_TOOL (tool);
163
167
GimpMagnifyOptions *options = GIMP_MAGNIFY_TOOL_GET_OPTIONS (tool);
164
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (tool->display->shell);
168
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
166
170
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
168
172
gimp_tool_control_halt (tool->control);
170
if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
174
switch (release_type)
172
gdouble x1, y1, x2, y2;
173
gdouble width, height;
174
gdouble current_scale;
177
x1 = (magnify->w < 0) ? magnify->x + magnify->w : magnify->x;
178
y1 = (magnify->h < 0) ? magnify->y + magnify->h : magnify->y;
179
width = (magnify->w < 0) ? -magnify->w : magnify->w;
180
height = (magnify->h < 0) ? -magnify->h : magnify->h;
184
width = MAX (1.0, width);
185
height = MAX (1.0, height);
187
current_scale = gimp_zoom_model_get_factor (shell->zoom);
189
if (release_type == GIMP_BUTTON_RELEASE_CLICK ||
190
release_type == GIMP_BUTTON_RELEASE_NO_MOTION)
192
gimp_display_shell_scale (shell,
195
GIMP_ZOOM_FOCUS_BEST_GUESS);
199
gdouble display_width;
200
gdouble display_height;
201
gdouble factor = 1.0;
203
display_width = FUNSCALEX (shell, shell->disp_width);
204
display_height = FUNSCALEY (shell, shell->disp_height);
206
switch (options->zoom_type)
209
factor = MIN ((display_width / width),
210
(display_height / height));
214
factor = MAX ((width / display_width),
215
(height / display_height));
222
new_scale = current_scale * factor;
224
if (new_scale != current_scale)
231
gimp_image_get_resolution (display->image, &xres, &yres);
233
switch (options->zoom_type)
236
/* move the center of the rectangle to the center of the
239
* new_offset = center of rectangle in new scale screen coords
242
* center of viewport in screen coords without
245
offset_x = RINT (new_scale * ((x1 + x2) / 2.0) *
246
SCREEN_XRES (shell) / xres -
247
(shell->disp_width / 2.0));
249
offset_y = RINT (new_scale * ((y1 + y2) / 2.0) *
250
SCREEN_YRES (shell) / yres -
251
(shell->disp_height / 2.0));
255
/* move the center of the viewport to the center of the
258
* new_offset = center of viewport in new scale screen coords
261
* center of rectangle in screen coords without
264
offset_x = RINT (new_scale * UNSCALEX (shell,
266
shell->disp_width / 2.0) *
267
SCREEN_XRES (shell) / xres -
268
(SCALEX (shell, (x1 + x2) / 2.0) -
271
offset_y = RINT (new_scale * UNSCALEY (shell,
273
shell->disp_height / 2.0) *
274
SCREEN_YRES (shell) / yres -
275
(SCALEY (shell, (y1 + y2) / 2.0) -
283
gimp_display_shell_scale_by_values (shell,
286
options->auto_resize);
176
case GIMP_BUTTON_RELEASE_CLICK:
177
case GIMP_BUTTON_RELEASE_NO_MOTION:
178
gimp_display_shell_scale (shell,
181
GIMP_ZOOM_FOCUS_POINTER);
184
case GIMP_BUTTON_RELEASE_NORMAL:
186
gdouble x1, y1, x2, y2;
187
gdouble width, height;
188
gdouble current_scale;
190
gdouble display_width;
191
gdouble display_height;
192
gdouble factor = 1.0;
194
x1 = (magnify->w < 0) ? magnify->x + magnify->w : magnify->x;
195
y1 = (magnify->h < 0) ? magnify->y + magnify->h : magnify->y;
196
width = (magnify->w < 0) ? -magnify->w : magnify->w;
197
height = (magnify->h < 0) ? -magnify->h : magnify->h;
201
width = MAX (1.0, width);
202
height = MAX (1.0, height);
204
current_scale = gimp_zoom_model_get_factor (shell->zoom);
206
display_width = FUNSCALEX (shell, shell->disp_width);
207
display_height = FUNSCALEY (shell, shell->disp_height);
209
switch (options->zoom_type)
212
factor = MIN ((display_width / width),
213
(display_height / height));
217
factor = MAX ((width / display_width),
218
(height / display_height));
225
new_scale = current_scale * factor;
227
if (new_scale != current_scale)
236
gimp_image_get_resolution (gimp_display_get_image (display),
238
gimp_display_shell_get_screen_resolution (shell,
239
&screen_xres, &screen_yres);
241
switch (options->zoom_type)
244
/* move the center of the rectangle to the center of the
247
* new_offset = center of rectangle in new scale screen coords
250
* center of viewport in screen coords without
253
offset_x = RINT (new_scale * ((x1 + x2) / 2.0) *
255
(shell->disp_width / 2.0));
257
offset_y = RINT (new_scale * ((y1 + y2) / 2.0) *
259
(shell->disp_height / 2.0));
263
/* move the center of the viewport to the center of the
266
* new_offset = center of viewport in new scale screen coords
269
* center of rectangle in screen coords without
272
offset_x = RINT (new_scale * UNSCALEX (shell,
274
shell->disp_width / 2.0) *
276
(SCALEX (shell, (x1 + x2) / 2.0) -
279
offset_y = RINT (new_scale * UNSCALEY (shell,
281
shell->disp_height / 2.0) *
283
(SCALEY (shell, (y1 + y2) / 2.0) -
291
gimp_display_shell_scale_by_values (shell,
294
options->auto_resize);
293
gimp_magnify_tool_motion (GimpTool *tool,
296
GdkModifierType state,
297
GimpDisplay *display)
305
gimp_magnify_tool_motion (GimpTool *tool,
306
const GimpCoords *coords,
308
GdkModifierType state,
309
GimpDisplay *display)
299
311
GimpMagnifyTool *magnify = GIMP_MAGNIFY_TOOL (tool);
301
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
303
313
magnify->w = coords->x - magnify->x;
304
314
magnify->h = coords->y - magnify->y;
306
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
316
gimp_magnify_tool_update_items (magnify);