1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an 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 2 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, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
2000-01-14 20:41:00 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "appenv.h"
|
|
|
|
#include "draw_core.h"
|
|
|
|
#include "gdisplay.h"
|
|
|
|
#include "gimprc.h"
|
2000-01-14 20:41:00 +08:00
|
|
|
#include "gimpui.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "info_window.h"
|
|
|
|
#include "magnify.h"
|
|
|
|
#include "scale.h"
|
|
|
|
|
1998-12-16 08:37:09 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* types of magnify operations */
|
1999-06-22 06:12:07 +08:00
|
|
|
#define ZOOMIN 0
|
|
|
|
#define ZOOMOUT 1
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the magnify structures */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
typedef struct _Magnify Magnify;
|
2000-01-14 20:41:00 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
struct _Magnify
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
DrawCore *core; /* Core select object */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
gint x, y; /* upper left hand coordinate */
|
|
|
|
gint w, h; /* width and height */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
gint op; /* magnify operation */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
typedef struct _MagnifyOptions MagnifyOptions;
|
2000-01-14 20:41:00 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
struct _MagnifyOptions
|
|
|
|
{
|
1999-04-13 01:55:06 +08:00
|
|
|
ToolOptions tool_options;
|
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
/* gint allow_resize_windows; (from gimprc) */
|
|
|
|
gint allow_resize_d;
|
1999-04-13 01:55:06 +08:00
|
|
|
GtkWidget *allow_resize_w;
|
1999-04-09 06:25:54 +08:00
|
|
|
};
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
|
|
|
|
/* the magnify tool options */
|
|
|
|
static MagnifyOptions *magnify_options = NULL;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* magnify action functions */
|
|
|
|
static void magnify_button_press (Tool *, GdkEventButton *, gpointer);
|
|
|
|
static void magnify_button_release (Tool *, GdkEventButton *, gpointer);
|
|
|
|
static void magnify_motion (Tool *, GdkEventMotion *, gpointer);
|
|
|
|
static void magnify_cursor_update (Tool *, GdkEventMotion *, gpointer);
|
1999-06-22 06:12:07 +08:00
|
|
|
static void magnify_control (Tool *, ToolAction, gpointer);
|
|
|
|
|
|
|
|
/* magnify utility functions */
|
|
|
|
static void zoom_in (int *, int *, int);
|
|
|
|
static void zoom_out (int *, int *, int);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* magnify tool options functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
magnify_options_reset (void)
|
|
|
|
{
|
|
|
|
MagnifyOptions *options = magnify_options;
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->allow_resize_w),
|
|
|
|
options->allow_resize_d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MagnifyOptions *
|
|
|
|
magnify_options_new (void)
|
|
|
|
{
|
|
|
|
MagnifyOptions *options;
|
|
|
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
|
|
|
/* the new magnify tool options structure */
|
2000-01-14 20:41:00 +08:00
|
|
|
options = g_new (MagnifyOptions, 1);
|
1999-04-13 01:55:06 +08:00
|
|
|
tool_options_init ((ToolOptions *) options,
|
1999-06-22 06:12:07 +08:00
|
|
|
_("Magnify Options"),
|
1999-04-13 01:55:06 +08:00
|
|
|
magnify_options_reset);
|
|
|
|
options->allow_resize_d = allow_resize_windows;
|
|
|
|
|
|
|
|
/* the main vbox */
|
|
|
|
vbox = options->tool_options.main_vbox;
|
|
|
|
|
|
|
|
/* the allow_resize toggle button */
|
|
|
|
options->allow_resize_w =
|
|
|
|
gtk_check_button_new_with_label (_("Allow Window Resizing"));
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->allow_resize_w), "toggled",
|
2000-01-14 20:41:00 +08:00
|
|
|
GTK_SIGNAL_FUNC (gimp_toggle_button_update),
|
1999-04-13 01:55:06 +08:00
|
|
|
&allow_resize_windows);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->allow_resize_w),
|
|
|
|
allow_resize_windows);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->allow_resize_w, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (options->allow_resize_w);
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* magnify utility functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2000-01-14 20:41:00 +08:00
|
|
|
zoom_in (gint *src,
|
|
|
|
gint *dest,
|
|
|
|
gint scale)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
while (scale--)
|
|
|
|
{
|
|
|
|
if (*src > 1)
|
|
|
|
(*src)--;
|
|
|
|
else
|
|
|
|
if (*dest < 0x10)
|
|
|
|
(*dest)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2000-01-14 20:41:00 +08:00
|
|
|
zoom_out (gint *src,
|
|
|
|
gint *dest,
|
|
|
|
gint scale)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
while (scale--)
|
|
|
|
{
|
|
|
|
if (*dest > 1)
|
|
|
|
(*dest)--;
|
|
|
|
else
|
|
|
|
if (*src < 0x10)
|
|
|
|
(*src)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* magnify action functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
magnify_button_press (Tool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
GDisplay *gdisp;
|
|
|
|
Magnify *magnify;
|
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
magnify = (Magnify *) tool->private;
|
|
|
|
|
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y, TRUE, 0);
|
|
|
|
|
|
|
|
magnify->x = x;
|
|
|
|
magnify->y = y;
|
|
|
|
magnify->w = 0;
|
|
|
|
magnify->h = 0;
|
|
|
|
|
|
|
|
gdk_pointer_grab (gdisp->canvas->window, FALSE,
|
2000-01-14 20:41:00 +08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK,
|
1997-11-25 06:05:25 +08:00
|
|
|
NULL, NULL, bevent->time);
|
|
|
|
|
|
|
|
tool->state = ACTIVE;
|
|
|
|
tool->gdisp_ptr = gdisp_ptr;
|
|
|
|
|
|
|
|
if (bevent->state & GDK_SHIFT_MASK)
|
|
|
|
magnify->op = ZOOMOUT;
|
|
|
|
else
|
|
|
|
magnify->op = ZOOMIN; /* default */
|
|
|
|
|
|
|
|
draw_core_start (magnify->core,
|
|
|
|
gdisp->canvas->window,
|
|
|
|
tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
magnify_button_release (Tool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
Magnify *magnify;
|
|
|
|
GDisplay *gdisp;
|
|
|
|
gint win_width, win_height;
|
|
|
|
gint width, height;
|
|
|
|
gint scalesrc, scaledest;
|
|
|
|
gint scale;
|
|
|
|
gint x1, y1, x2, y2, w, h;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
magnify = (Magnify *) tool->private;
|
|
|
|
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
gdk_flush ();
|
|
|
|
|
|
|
|
draw_core_stop (magnify->core, tool);
|
|
|
|
tool->state = INACTIVE;
|
|
|
|
|
|
|
|
/* First take care of the case where the user "cancels" the action */
|
|
|
|
if (! (bevent->state & GDK_BUTTON3_MASK))
|
|
|
|
{
|
|
|
|
x1 = (magnify->w < 0) ? magnify->x + magnify->w : magnify->x;
|
|
|
|
y1 = (magnify->h < 0) ? magnify->y + magnify->h : magnify->y;
|
|
|
|
w = (magnify->w < 0) ? -magnify->w : magnify->w;
|
|
|
|
h = (magnify->h < 0) ? -magnify->h : magnify->h;
|
|
|
|
x2 = x1 + w;
|
|
|
|
y2 = y1 + h;
|
|
|
|
|
1998-12-06 05:48:37 +08:00
|
|
|
/* these change the user zoom level, so should not be changed to
|
|
|
|
* the resolution-aware scale macros -- austin */
|
1997-11-25 06:05:25 +08:00
|
|
|
scalesrc = SCALESRC(gdisp);
|
|
|
|
scaledest = SCALEDEST(gdisp);
|
|
|
|
|
|
|
|
win_width = gdisp->disp_width;
|
|
|
|
win_height = gdisp->disp_height;
|
|
|
|
width = (win_width * scalesrc) / scaledest;
|
|
|
|
height = (win_height * scalesrc) / scaledest;
|
|
|
|
|
|
|
|
if (!w || !h)
|
|
|
|
scale = 1;
|
|
|
|
else
|
|
|
|
scale = MINIMUM ((width / w), (height / h));
|
|
|
|
|
|
|
|
switch (magnify->op)
|
|
|
|
{
|
|
|
|
case ZOOMIN:
|
|
|
|
zoom_in (&scalesrc, &scaledest, scale);
|
|
|
|
break;
|
|
|
|
case ZOOMOUT:
|
|
|
|
zoom_out (&scalesrc, &scaledest, scale);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdisp->scale = (scaledest << 8) + scalesrc;
|
|
|
|
gdisp->offset_x = (scaledest * ((x1 + x2) / 2)) / scalesrc -
|
|
|
|
(win_width / 2);
|
|
|
|
gdisp->offset_y = (scaledest * ((y1 + y2) / 2)) / scalesrc -
|
|
|
|
(win_height / 2);
|
|
|
|
|
|
|
|
/* resize the image */
|
|
|
|
resize_display (gdisp, allow_resize_windows, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
magnify_motion (Tool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
Magnify *magnify;
|
|
|
|
GDisplay *gdisp;
|
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (tool->state != ACTIVE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
magnify = (Magnify *) tool->private;
|
|
|
|
|
|
|
|
draw_core_pause (magnify->core, tool);
|
|
|
|
|
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, TRUE, 0);
|
|
|
|
magnify->w = (x - magnify->x);
|
|
|
|
magnify->h = (y - magnify->y);
|
|
|
|
|
|
|
|
draw_core_resume (magnify->core, tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
magnify_cursor_update (Tool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
gpointer gdisp_ptr)
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
GDisplay *gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisp = (GDisplay *) gdisp_ptr;
|
|
|
|
|
|
|
|
gdisplay_install_tool_cursor (gdisp, GDK_TCROSS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
magnify_draw (Tool *tool)
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
GDisplay *gdisp;
|
|
|
|
Magnify *magnify;
|
|
|
|
gint x1, y1, x2, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisp = (GDisplay *) tool->gdisp_ptr;
|
|
|
|
magnify = (Magnify *) tool->private;
|
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
x1 = MIN (magnify->x, magnify->x + magnify->w);
|
|
|
|
y1 = MIN (magnify->y, magnify->y + magnify->h);
|
|
|
|
x2 = MAX (magnify->x, magnify->x + magnify->w);
|
|
|
|
y2 = MAX (magnify->y, magnify->y + magnify->h);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisplay_transform_coords (gdisp, x1, y1, &x1, &y1, 0);
|
|
|
|
gdisplay_transform_coords (gdisp, x2, y2, &x2, &y2, 0);
|
|
|
|
|
|
|
|
gdk_draw_rectangle (magnify->core->win, magnify->core->gc, 0,
|
|
|
|
x1, y1, (x2 - x1), (y2 - y1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1999-06-22 06:12:07 +08:00
|
|
|
magnify_control (Tool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
gpointer gdisp_ptr)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
Magnify *magnify;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
magnify = (Magnify *) tool->private;
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
1999-06-22 06:12:07 +08:00
|
|
|
case PAUSE:
|
1997-11-25 06:05:25 +08:00
|
|
|
draw_core_pause (magnify->core, tool);
|
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
|
|
|
case RESUME:
|
1997-11-25 06:05:25 +08:00
|
|
|
draw_core_resume (magnify->core, tool);
|
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
|
|
|
case HALT:
|
1997-11-25 06:05:25 +08:00
|
|
|
draw_core_stop (magnify->core, tool);
|
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tool *
|
|
|
|
tools_new_magnify (void)
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
Tool *tool;
|
|
|
|
Magnify *private;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* The tool options */
|
1997-11-25 06:05:25 +08:00
|
|
|
if (! magnify_options)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
|
|
|
magnify_options = magnify_options_new ();
|
|
|
|
tools_register (MAGNIFY, (ToolOptions *) magnify_options);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-03 01:40:10 +08:00
|
|
|
tool = tools_new_tool (MAGNIFY);
|
|
|
|
private = g_new (Magnify, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
private->core = draw_core_new (magnify_draw);
|
|
|
|
private->x = private->y = 0;
|
|
|
|
private->w = private->h = 0;
|
|
|
|
|
1999-07-03 01:40:10 +08:00
|
|
|
tool->scroll_lock = TRUE; /* Disallow scrolling */
|
|
|
|
tool->auto_snap_to = FALSE; /* Don't snap to guides */
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-07-03 01:40:10 +08:00
|
|
|
tool->private = (void *) private;
|
1999-06-26 19:16:47 +08:00
|
|
|
|
1999-07-03 01:40:10 +08:00
|
|
|
tool->button_press_func = magnify_button_press;
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->button_release_func = magnify_button_release;
|
1999-07-03 01:40:10 +08:00
|
|
|
tool->motion_func = magnify_motion;
|
|
|
|
tool->cursor_update_func = magnify_cursor_update;
|
|
|
|
tool->control_func = magnify_control;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
tools_free_magnify (Tool *tool)
|
|
|
|
{
|
2000-01-14 20:41:00 +08:00
|
|
|
Magnify *magnify;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
magnify = (Magnify *) tool->private;
|
|
|
|
|
|
|
|
draw_core_free (magnify->core);
|
|
|
|
g_free (magnify);
|
|
|
|
}
|