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
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2000-01-14 20:41:00 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-03-02 03:32:41 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gui/info-window.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "gdisplay.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimpmagnifytool.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "tool_options.h"
|
2001-03-04 00:22:18 +08:00
|
|
|
#include "tool_manager.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gimprc.h"
|
|
|
|
#include "scale.h"
|
|
|
|
|
1998-12-16 08:37:09 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
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
|
|
|
|
{
|
2001-07-18 04:50:01 +08:00
|
|
|
GimpToolOptions tool_options;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
/* gint allow_resize_windows; (from gimprc) */
|
|
|
|
gint allow_resize_d;
|
|
|
|
GtkWidget *allow_resize_w;
|
2000-03-02 03:32:41 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
GimpZoomType type;
|
|
|
|
GimpZoomType type_d;
|
|
|
|
GtkWidget *type_w[2];
|
1999-04-09 06:25:54 +08:00
|
|
|
};
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* magnify action functions */
|
2001-03-04 00:22:18 +08:00
|
|
|
static void gimp_magnify_tool_class_init (GimpMagnifyToolClass *klass);
|
|
|
|
static void gimp_magnify_tool_init (GimpMagnifyTool *tool);
|
|
|
|
|
|
|
|
static void gimp_magnify_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_magnify_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_magnify_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_magnify_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_magnify_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_magnify_tool_draw (GimpDrawTool *draw_tool);
|
1999-06-22 06:12:07 +08:00
|
|
|
|
|
|
|
/* magnify utility functions */
|
2000-12-31 12:07:42 +08:00
|
|
|
static void zoom_in (gint *src,
|
|
|
|
gint *dest,
|
|
|
|
gint scale);
|
|
|
|
static void zoom_out (gint *src,
|
|
|
|
gint *dest,
|
|
|
|
gint scale);
|
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
static MagnifyOptions * magnify_options_new (void);
|
2001-07-18 04:50:01 +08:00
|
|
|
static void magnify_options_reset (GimpToolOptions *tool_options);
|
2001-03-04 00:22:18 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
static MagnifyOptions *magnify_options = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
static GimpDrawToolClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_magnify_tool_register (Gimp *gimp)
|
2001-03-04 00:22:18 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_MAGNIFY_TOOL,
|
2001-03-04 00:22:18 +08:00
|
|
|
FALSE,
|
|
|
|
"gimp:magnify_tool",
|
|
|
|
_("Magnify"),
|
|
|
|
_("Zoom in & out"),
|
|
|
|
N_("/Tools/Magnify"), NULL,
|
|
|
|
NULL, "tools/magnify.html",
|
2001-08-06 00:08:19 +08:00
|
|
|
GIMP_STOCK_TOOL_ZOOM);
|
2001-03-04 00:22:18 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_magnify_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-03-04 00:22:18 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-03-04 00:22:18 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
sizeof (GimpMagnifyToolClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_magnify_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2001-03-04 00:22:18 +08:00
|
|
|
sizeof (GimpMagnifyTool),
|
2001-08-14 22:53:55 +08:00
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_magnify_tool_init,
|
2001-03-04 00:22:18 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_DRAW_TOOL,
|
|
|
|
"GimpMagnifyTool",
|
|
|
|
&tool_info, 0);
|
2001-03-04 00:22:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_magnify_tool_class_init (GimpMagnifyToolClass *klass)
|
|
|
|
{
|
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_tool_class;
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2001-03-04 00:22:18 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-03-04 00:22:18 +08:00
|
|
|
|
|
|
|
tool_class->button_press = gimp_magnify_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_magnify_tool_button_release;
|
|
|
|
tool_class->motion = gimp_magnify_tool_motion;
|
|
|
|
tool_class->modifier_key = gimp_magnify_tool_modifier_key;
|
|
|
|
tool_class->cursor_update = gimp_magnify_tool_cursor_update;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_magnify_tool_draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_magnify_tool_init (GimpMagnifyTool *magnify_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (magnify_tool);
|
|
|
|
|
|
|
|
if (! magnify_options)
|
|
|
|
{
|
|
|
|
magnify_options = magnify_options_new ();
|
|
|
|
|
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_MAGNIFY_TOOL,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) magnify_options);
|
2001-03-04 00:22:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tool->scroll_lock = TRUE; /* Disallow scrolling */
|
|
|
|
tool->auto_snap_to = FALSE; /* Don't snap to guides */
|
|
|
|
|
|
|
|
magnify_tool->x = 0;
|
|
|
|
magnify_tool->y = 0;
|
|
|
|
magnify_tool->w = 0;
|
|
|
|
magnify_tool->h = 0;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* magnify tool options functions */
|
|
|
|
|
|
|
|
static void
|
2001-07-18 04:50:01 +08:00
|
|
|
magnify_options_reset (GimpToolOptions *tool_options)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
2001-04-01 04:41:39 +08:00
|
|
|
MagnifyOptions *options;
|
|
|
|
|
|
|
|
options = (MagnifyOptions *) tool_options;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->allow_resize_w),
|
|
|
|
options->allow_resize_d);
|
2000-03-02 03:32:41 +08:00
|
|
|
|
|
|
|
gtk_toggle_button_set_active
|
|
|
|
(GTK_TOGGLE_BUTTON (options->type_w[options->type_d]), TRUE);
|
1999-04-13 01:55:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static MagnifyOptions *
|
|
|
|
magnify_options_new (void)
|
|
|
|
{
|
|
|
|
MagnifyOptions *options;
|
|
|
|
|
|
|
|
GtkWidget *vbox;
|
2000-03-02 03:32:41 +08:00
|
|
|
GtkWidget *frame;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
|
|
|
/* the new magnify tool options structure */
|
2001-03-04 00:22:18 +08:00
|
|
|
options = g_new0 (MagnifyOptions, 1);
|
|
|
|
|
2001-07-18 04:50:01 +08:00
|
|
|
tool_options_init ((GimpToolOptions *) options,
|
1999-04-13 01:55:06 +08:00
|
|
|
magnify_options_reset);
|
2001-03-04 00:22:18 +08:00
|
|
|
|
2001-06-04 04:40:50 +08:00
|
|
|
options->allow_resize_d = gimprc.allow_resize_windows;
|
2001-03-04 00:22:18 +08:00
|
|
|
options->type_d = options->type = GIMP_ZOOM_IN;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
|
|
|
/* 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"));
|
2001-08-01 10:57:58 +08:00
|
|
|
g_signal_connect (G_OBJECT (options->allow_resize_w), "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&(gimprc.allow_resize_windows));
|
1999-04-13 01:55:06 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->allow_resize_w),
|
2001-06-04 04:40:50 +08:00
|
|
|
gimprc.allow_resize_windows);
|
2001-08-01 10:57:58 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox),
|
|
|
|
options->allow_resize_w, FALSE, FALSE, 0);
|
1999-04-13 01:55:06 +08:00
|
|
|
gtk_widget_show (options->allow_resize_w);
|
|
|
|
|
2000-03-02 03:32:41 +08:00
|
|
|
/* tool toggle */
|
|
|
|
frame =
|
|
|
|
gimp_radio_group_new2 (TRUE, _("Tool Toggle"),
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&options->type,
|
|
|
|
(gpointer) options->type,
|
2000-03-02 03:32:41 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
_("Zoom in"), (gpointer) GIMP_ZOOM_IN,
|
2000-03-02 03:32:41 +08:00
|
|
|
&options->type_w[0],
|
2001-03-04 00:22:18 +08:00
|
|
|
_("Zoom out"), (gpointer) GIMP_ZOOM_OUT,
|
2000-03-02 03:32:41 +08:00
|
|
|
&options->type_w[1],
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
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
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_magnify_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-04 00:22:18 +08:00
|
|
|
GimpMagnifyTool *magnify;
|
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
magnify = GIMP_MAGNIFY_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
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;
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool),
|
|
|
|
gdisp->canvas->window);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_magnify_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-04 00:22:18 +08:00
|
|
|
GimpMagnifyTool *magnify;
|
|
|
|
gint win_width, win_height;
|
|
|
|
gint width, height;
|
|
|
|
gint scalesrc, scaledest;
|
|
|
|
gint scale;
|
|
|
|
gint x1, y1, x2, y2, w, h;
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
magnify = GIMP_MAGNIFY_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
gdk_flush ();
|
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
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 */
|
2001-03-04 00:22:18 +08:00
|
|
|
scalesrc = SCALESRC (gdisp);
|
2000-01-26 07:06:12 +08:00
|
|
|
scaledest = SCALEDEST (gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
win_width = gdisp->disp_width;
|
1997-11-25 06:05:25 +08:00
|
|
|
win_height = gdisp->disp_height;
|
2001-03-04 00:22:18 +08:00
|
|
|
width = (win_width * scalesrc) / scaledest;
|
1997-11-25 06:05:25 +08:00
|
|
|
height = (win_height * scalesrc) / scaledest;
|
|
|
|
|
|
|
|
if (!w || !h)
|
|
|
|
scale = 1;
|
|
|
|
else
|
2000-01-26 07:06:12 +08:00
|
|
|
scale = MIN ((width / w), (height / h));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-03-02 03:32:41 +08:00
|
|
|
magnify->op = magnify_options->type;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (magnify->op)
|
|
|
|
{
|
2001-03-04 00:22:18 +08:00
|
|
|
case GIMP_ZOOM_IN:
|
1997-11-25 06:05:25 +08:00
|
|
|
zoom_in (&scalesrc, &scaledest, scale);
|
|
|
|
break;
|
2001-03-04 00:22:18 +08:00
|
|
|
case GIMP_ZOOM_OUT:
|
1997-11-25 06:05:25 +08:00
|
|
|
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 */
|
2001-06-04 04:40:50 +08:00
|
|
|
resize_display (gdisp, gimprc.allow_resize_windows, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_magnify_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-04 00:22:18 +08:00
|
|
|
GimpMagnifyTool *magnify;
|
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (tool->state != ACTIVE)
|
|
|
|
return;
|
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
magnify = GIMP_MAGNIFY_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, TRUE, 0);
|
|
|
|
magnify->w = (x - magnify->x);
|
|
|
|
magnify->h = (y - magnify->y);
|
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-03-02 03:32:41 +08:00
|
|
|
static void
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_magnify_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GDisplay *gdisp)
|
2000-03-02 03:32:41 +08:00
|
|
|
{
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_Alt_L: case GDK_Alt_R:
|
|
|
|
break;
|
|
|
|
case GDK_Shift_L: case GDK_Shift_R:
|
|
|
|
break;
|
|
|
|
case GDK_Control_L: case GDK_Control_R:
|
2001-03-04 00:22:18 +08:00
|
|
|
if (magnify_options->type == GIMP_ZOOM_IN)
|
2000-03-02 03:32:41 +08:00
|
|
|
gtk_toggle_button_set_active
|
2001-03-04 00:22:18 +08:00
|
|
|
(GTK_TOGGLE_BUTTON (magnify_options->type_w[GIMP_ZOOM_OUT]), TRUE);
|
2000-03-02 03:32:41 +08:00
|
|
|
else
|
|
|
|
gtk_toggle_button_set_active
|
2001-03-04 00:22:18 +08:00
|
|
|
(GTK_TOGGLE_BUTTON (magnify_options->type_w[GIMP_ZOOM_IN]), TRUE);
|
2000-03-02 03:32:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-03-04 00:22:18 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2001-03-04 00:22:18 +08:00
|
|
|
gimp_magnify_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-04 00:22:18 +08:00
|
|
|
if (magnify_options->type == GIMP_ZOOM_IN)
|
2000-03-02 03:32:41 +08:00
|
|
|
{
|
2001-02-25 03:29:47 +08:00
|
|
|
gdisplay_install_tool_cursor (gdisp,
|
|
|
|
GIMP_ZOOM_CURSOR,
|
2001-03-04 00:22:18 +08:00
|
|
|
GIMP_ZOOM_TOOL_CURSOR,
|
2001-02-25 03:29:47 +08:00
|
|
|
GIMP_CURSOR_MODIFIER_PLUS);
|
2000-03-02 03:32:41 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-02-25 03:29:47 +08:00
|
|
|
gdisplay_install_tool_cursor (gdisp,
|
|
|
|
GIMP_ZOOM_CURSOR,
|
2001-03-04 00:22:18 +08:00
|
|
|
GIMP_ZOOM_TOOL_CURSOR,
|
2001-02-25 03:29:47 +08:00
|
|
|
GIMP_CURSOR_MODIFIER_MINUS);
|
2000-03-02 03:32:41 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
static void
|
|
|
|
gimp_magnify_tool_draw (GimpDrawTool *draw_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-04 00:22:18 +08:00
|
|
|
GimpMagnifyTool *magnify;
|
|
|
|
GimpTool *tool;
|
|
|
|
gint x1, y1, x2, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
magnify = GIMP_MAGNIFY_TOOL (draw_tool);
|
|
|
|
tool = GIMP_TOOL (draw_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
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
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
gdisplay_transform_coords (tool->gdisp, x1, y1, &x1, &y1, 0);
|
|
|
|
gdisplay_transform_coords (tool->gdisp, x2, y2, &x2, &y2, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-04 00:22:18 +08:00
|
|
|
gdk_draw_rectangle (draw_tool->win, draw_tool->gc, 0,
|
1997-11-25 06:05:25 +08:00
|
|
|
x1, y1, (x2 - x1), (y2 - y1));
|
|
|
|
}
|