2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-06-18 21:10:03 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-08-27 08:42:46 +08:00
|
|
|
* GimpNavigationView Widget
|
2002-05-08 00:23:14 +08:00
|
|
|
* Copyright (C) 2001-2002 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
|
|
|
* partly based on app/nav_window
|
|
|
|
* Copyright (C) 1999 Andy Thomas <alt@gimp.org>
|
2001-06-18 21:10:03 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpimage.h"
|
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
|
|
|
#include "core/gimpmarshal.h"
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
#include "gimpnavigationview.h"
|
2004-08-26 06:31:44 +08:00
|
|
|
#include "gimpviewrenderer.h"
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define BORDER_PEN_WIDTH 3
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MARKER_CHANGED,
|
2001-08-10 00:39:08 +08:00
|
|
|
ZOOM,
|
|
|
|
SCROLL,
|
2001-06-18 21:10:03 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
static void gimp_navigation_view_realize (GtkWidget *widget);
|
|
|
|
static void gimp_navigation_view_unrealize (GtkWidget *widget);
|
|
|
|
static void gimp_navigation_view_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static gboolean gimp_navigation_view_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *eevent);
|
|
|
|
static gboolean gimp_navigation_view_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
|
|
|
static gboolean gimp_navigation_view_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent);
|
|
|
|
static gboolean gimp_navigation_view_scroll (GtkWidget *widget,
|
|
|
|
GdkEventScroll *sevent);
|
|
|
|
static gboolean gimp_navigation_view_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *mevent);
|
|
|
|
static gboolean gimp_navigation_view_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *kevent);
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
static void gimp_navigation_view_transform (GimpNavigationView *nav_view);
|
|
|
|
static void gimp_navigation_view_draw_marker (GimpNavigationView *nav_view,
|
|
|
|
GdkRectangle *area);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpNavigationView, gimp_navigation_view, GIMP_TYPE_VIEW)
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_navigation_view_parent_class
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
static guint view_signals[LAST_SIGNAL] = { 0 };
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_class_init (GimpNavigationViewClass *klass)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
view_signals[MARKER_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("marker-changed",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2004-08-27 08:42:46 +08:00
|
|
|
G_STRUCT_OFFSET (GimpNavigationViewClass, marker_changed),
|
2004-08-25 01:16:46 +08:00
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__DOUBLE_DOUBLE,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_DOUBLE,
|
|
|
|
G_TYPE_DOUBLE);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
view_signals[ZOOM] =
|
2001-08-10 00:39:08 +08:00
|
|
|
g_signal_new ("zoom",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2004-08-27 08:42:46 +08:00
|
|
|
G_STRUCT_OFFSET (GimpNavigationViewClass, zoom),
|
2004-08-25 01:16:46 +08:00
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__ENUM,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GIMP_TYPE_ZOOM_TYPE);
|
2001-08-10 00:39:08 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
view_signals[SCROLL] =
|
2001-08-10 00:39:08 +08:00
|
|
|
g_signal_new ("scroll",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2004-08-27 08:42:46 +08:00
|
|
|
G_STRUCT_OFFSET (GimpNavigationViewClass, scroll),
|
2004-08-25 01:16:46 +08:00
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__ENUM,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GDK_TYPE_SCROLL_DIRECTION);
|
2001-08-10 00:39:08 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
widget_class->realize = gimp_navigation_view_realize;
|
|
|
|
widget_class->unrealize = gimp_navigation_view_unrealize;
|
|
|
|
widget_class->size_allocate = gimp_navigation_view_size_allocate;
|
|
|
|
widget_class->expose_event = gimp_navigation_view_expose;
|
|
|
|
widget_class->button_press_event = gimp_navigation_view_button_press;
|
|
|
|
widget_class->button_release_event = gimp_navigation_view_button_release;
|
|
|
|
widget_class->scroll_event = gimp_navigation_view_scroll;
|
|
|
|
widget_class->motion_notify_event = gimp_navigation_view_motion_notify;
|
|
|
|
widget_class->key_press_event = gimp_navigation_view_key_press;
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_init (GimpNavigationView *view)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-08-27 08:42:46 +08:00
|
|
|
GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
gtk_widget_add_events (GTK_WIDGET (view), (GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_KEY_PRESS_MASK));
|
2002-05-08 00:23:14 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
view->x = 0.0;
|
|
|
|
view->y = 0.0;
|
|
|
|
view->width = 0.0;
|
|
|
|
view->height = 0.0;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
view->p_x = 0;
|
|
|
|
view->p_y = 0;
|
|
|
|
view->p_width = 0;
|
|
|
|
view->p_height = 0;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
view->motion_offset_x = 0;
|
|
|
|
view->motion_offset_y = 0;
|
|
|
|
view->has_grab = FALSE;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
view->gc = NULL;
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_realize (GtkWidget *widget)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-08-27 08:42:46 +08:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->realize (widget);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
nav_view->gc = gdk_gc_new (widget->window);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
gdk_gc_set_function (nav_view->gc, GDK_INVERT);
|
|
|
|
gdk_gc_set_line_attributes (nav_view->gc,
|
2004-08-25 01:16:46 +08:00
|
|
|
BORDER_PEN_WIDTH,
|
|
|
|
GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_ROUND);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
|
2003-11-10 10:00:19 +08:00
|
|
|
static void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_unrealize (GtkWidget *widget)
|
2003-11-10 10:00:19 +08:00
|
|
|
{
|
2004-08-27 08:42:46 +08:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
2003-11-10 10:00:19 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
if (nav_view->gc)
|
2003-11-10 10:00:19 +08:00
|
|
|
{
|
2004-08-27 08:42:46 +08:00
|
|
|
g_object_unref (nav_view->gc);
|
|
|
|
nav_view->gc = NULL;
|
2003-11-10 10:00:19 +08:00
|
|
|
}
|
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
|
2003-11-10 10:00:19 +08:00
|
|
|
}
|
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
static void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
2003-03-10 22:07:22 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (GIMP_VIEW (widget)->renderer->viewable)
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_transform (GIMP_NAVIGATION_VIEW (widget));
|
2003-03-10 22:07:22 +08:00
|
|
|
}
|
|
|
|
|
2001-06-18 21:10:03 +08:00
|
|
|
static gboolean
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *eevent)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
|
|
|
if (GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_draw_marker (GIMP_NAVIGATION_VIEW (widget),
|
|
|
|
&eevent->area);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
|
2001-08-01 00:55:59 +08:00
|
|
|
return TRUE;
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_move_to (GimpNavigationView *nav_view,
|
|
|
|
gint tx,
|
|
|
|
gint ty)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpView *view = GIMP_VIEW (nav_view);
|
|
|
|
GimpImage *image;
|
|
|
|
gdouble ratiox, ratioy;
|
|
|
|
gdouble x, y;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (! view->renderer->viewable)
|
2002-05-08 00:23:14 +08:00
|
|
|
return;
|
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
tx = CLAMP (tx, 0, view->renderer->width - nav_view->p_width);
|
|
|
|
ty = CLAMP (ty, 0, view->renderer->height - nav_view->p_height);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
image = GIMP_IMAGE (view->renderer->viewable);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
/* transform to image coordinates */
|
2004-08-27 08:42:46 +08:00
|
|
|
if (view->renderer->width != nav_view->p_width)
|
2005-07-15 02:51:32 +08:00
|
|
|
ratiox = ((image->width - nav_view->width + 1.0) /
|
2004-08-27 08:42:46 +08:00
|
|
|
(view->renderer->width - nav_view->p_width));
|
2003-04-05 00:32:13 +08:00
|
|
|
else
|
2003-04-01 18:32:03 +08:00
|
|
|
ratiox = 1.0;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
if (view->renderer->height != nav_view->p_height)
|
2005-07-15 02:51:32 +08:00
|
|
|
ratioy = ((image->height - nav_view->height + 1.0) /
|
2004-08-27 08:42:46 +08:00
|
|
|
(view->renderer->height - nav_view->p_height));
|
2003-04-01 18:32:03 +08:00
|
|
|
else
|
|
|
|
ratioy = 1.0;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2003-04-05 00:32:13 +08:00
|
|
|
x = tx * ratiox;
|
|
|
|
y = ty * ratioy;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
g_signal_emit (view, view_signals[MARKER_CHANGED], 0, x, y);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
|
2002-05-06 03:17:41 +08:00
|
|
|
void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_grab_pointer (GimpNavigationView *nav_view)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (nav_view);
|
2003-11-02 04:06:01 +08:00
|
|
|
GdkDisplay *display;
|
|
|
|
GdkCursor *cursor;
|
|
|
|
GdkWindow *window;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
nav_view->has_grab = TRUE;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
gtk_grab_add (widget);
|
|
|
|
|
2003-11-02 04:06:01 +08:00
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
window = GIMP_VIEW (nav_view)->event_window;
|
2003-04-11 16:37:26 +08:00
|
|
|
|
|
|
|
gdk_pointer_grab (window, TRUE,
|
2004-08-25 01:16:46 +08:00
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON_MOTION_MASK |
|
|
|
|
GDK_EXTENSION_EVENTS_ALL,
|
|
|
|
window, cursor, GDK_CURRENT_TIME);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2001-08-01 08:35:59 +08:00
|
|
|
gdk_cursor_unref (cursor);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
2004-08-27 08:42:46 +08:00
|
|
|
gint tx, ty;
|
|
|
|
GdkDisplay *display;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
tx = bevent->x;
|
|
|
|
ty = bevent->y;
|
|
|
|
|
|
|
|
switch (bevent->button)
|
|
|
|
{
|
|
|
|
case 1:
|
2004-08-27 08:42:46 +08:00
|
|
|
if (! (tx > nav_view->p_x &&
|
|
|
|
tx < (nav_view->p_x + nav_view->p_width) &&
|
|
|
|
ty > nav_view->p_y &&
|
|
|
|
ty < (nav_view->p_y + nav_view->p_height)))
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
2002-05-08 00:23:14 +08:00
|
|
|
GdkCursor *cursor;
|
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
nav_view->motion_offset_x = nav_view->p_width / 2;
|
|
|
|
nav_view->motion_offset_y = nav_view->p_height / 2;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
tx -= nav_view->motion_offset_x;
|
|
|
|
ty -= nav_view->motion_offset_y;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_move_to (nav_view, tx, ty);
|
2002-05-08 00:23:14 +08:00
|
|
|
|
2003-11-02 04:06:01 +08:00
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
|
2004-08-25 01:16:46 +08:00
|
|
|
gdk_window_set_cursor (GIMP_VIEW (widget)->event_window, cursor);
|
2002-05-08 00:23:14 +08:00
|
|
|
gdk_cursor_unref (cursor);
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
2001-06-18 21:10:03 +08:00
|
|
|
else
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
2004-08-27 08:42:46 +08:00
|
|
|
nav_view->motion_offset_x = tx - nav_view->p_x;
|
|
|
|
nav_view->motion_offset_y = ty - nav_view->p_y;
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_grab_pointer (nav_view);
|
2001-06-18 21:10:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
switch (bevent->button)
|
|
|
|
{
|
|
|
|
case 1:
|
2004-08-27 08:42:46 +08:00
|
|
|
nav_view->has_grab = FALSE;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
gtk_grab_remove (widget);
|
2003-10-30 04:57:21 +08:00
|
|
|
gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
|
|
|
|
GDK_CURRENT_TIME);
|
2001-06-18 21:10:03 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-08-10 00:39:08 +08:00
|
|
|
static gboolean
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_scroll (GtkWidget *widget,
|
|
|
|
GdkEventScroll *sevent)
|
2001-08-10 00:39:08 +08:00
|
|
|
{
|
2005-11-19 04:00:02 +08:00
|
|
|
if (sevent->state & GDK_CONTROL_MASK)
|
2001-08-10 00:39:08 +08:00
|
|
|
{
|
2005-11-19 04:00:02 +08:00
|
|
|
switch (sevent->direction)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
2005-11-19 04:00:02 +08:00
|
|
|
case GDK_SCROLL_UP:
|
2004-08-27 08:42:46 +08:00
|
|
|
g_signal_emit (widget, view_signals[ZOOM], 0, GIMP_ZOOM_IN);
|
2005-11-19 04:00:02 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_SCROLL_DOWN:
|
2004-08-27 08:42:46 +08:00
|
|
|
g_signal_emit (widget, view_signals[ZOOM], 0, GIMP_ZOOM_OUT);
|
2005-11-19 04:00:02 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
2001-08-10 00:39:08 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-19 04:00:02 +08:00
|
|
|
GdkScrollDirection direction = sevent->direction;
|
|
|
|
|
|
|
|
if (sevent->state & GDK_SHIFT_MASK)
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case GDK_SCROLL_UP: direction = GDK_SCROLL_LEFT; break;
|
|
|
|
case GDK_SCROLL_DOWN: direction = GDK_SCROLL_RIGHT; break;
|
|
|
|
case GDK_SCROLL_LEFT: direction = GDK_SCROLL_UP; break;
|
|
|
|
case GDK_SCROLL_RIGHT: direction = GDK_SCROLL_DOWN; break;
|
|
|
|
}
|
2001-08-10 00:39:08 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
g_signal_emit (widget, view_signals[SCROLL], 0, direction);
|
2001-08-10 00:39:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-06-18 21:10:03 +08:00
|
|
|
static gboolean
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *mevent)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2004-08-27 08:42:46 +08:00
|
|
|
gint tx, ty;
|
|
|
|
GdkModifierType mask;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
if (! nav_view->has_grab)
|
2002-05-08 00:23:14 +08:00
|
|
|
{
|
2003-11-02 04:06:01 +08:00
|
|
|
GdkCursor *cursor;
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
|
|
|
display = gtk_widget_get_display (widget);
|
2002-05-08 00:23:14 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
if (nav_view->p_x == 0 &&
|
|
|
|
nav_view->p_y == 0 &&
|
|
|
|
nav_view->p_width == view->renderer->width &&
|
|
|
|
nav_view->p_height == view->renderer->height)
|
2002-05-08 00:23:14 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
gdk_window_set_cursor (view->event_window, NULL);
|
2002-05-08 00:23:14 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-08-27 08:42:46 +08:00
|
|
|
else if (mevent->x >= nav_view->p_x &&
|
|
|
|
mevent->y >= nav_view->p_y &&
|
|
|
|
mevent->x < nav_view->p_x + nav_view->p_width &&
|
|
|
|
mevent->y < nav_view->p_y + nav_view->p_height)
|
2002-05-08 00:23:14 +08:00
|
|
|
{
|
2003-11-02 04:06:01 +08:00
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
|
2002-05-08 00:23:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-02 04:06:01 +08:00
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
|
2002-05-08 00:23:14 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gdk_window_set_cursor (view->event_window, cursor);
|
2002-05-08 00:23:14 +08:00
|
|
|
gdk_cursor_unref (cursor);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gdk_window_get_pointer (view->event_window, &tx, &ty, &mask);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
tx -= nav_view->motion_offset_x;
|
|
|
|
ty -= nav_view->motion_offset_y;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_move_to (nav_view, tx, ty);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *kevent)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
|
|
|
gint scroll_x = 0;
|
|
|
|
gint scroll_y = 0;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_Up:
|
|
|
|
scroll_y = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Left:
|
|
|
|
scroll_x = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Right:
|
|
|
|
scroll_x = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Down:
|
|
|
|
scroll_y = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scroll_x || scroll_y)
|
|
|
|
{
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_move_to (nav_view,
|
|
|
|
nav_view->p_x + scroll_x,
|
|
|
|
nav_view->p_y + scroll_y);
|
2001-06-18 21:10:03 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
static void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_transform (GimpNavigationView *nav_view)
|
2003-03-10 22:07:22 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpView *view = GIMP_VIEW (nav_view);
|
|
|
|
GimpImage *image;
|
2004-08-25 01:16:46 +08:00
|
|
|
gdouble ratiox, ratioy;
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
image = GIMP_IMAGE (view->renderer->viewable);
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
ratiox = ((gdouble) view->renderer->width / (gdouble) image->width);
|
|
|
|
ratioy = ((gdouble) view->renderer->height / (gdouble) image->height);
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
nav_view->p_x = RINT (nav_view->x * ratiox);
|
|
|
|
nav_view->p_y = RINT (nav_view->y * ratioy);
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
nav_view->p_width = RINT (nav_view->width * ratiox);
|
|
|
|
nav_view->p_height = RINT (nav_view->height * ratioy);
|
2003-03-10 22:07:22 +08:00
|
|
|
}
|
|
|
|
|
2001-06-18 21:10:03 +08:00
|
|
|
static void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_draw_marker (GimpNavigationView *nav_view,
|
|
|
|
GdkRectangle *area)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpView *view = GIMP_VIEW (nav_view);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (view->renderer->viewable &&
|
2004-08-27 08:42:46 +08:00
|
|
|
nav_view->width &&
|
|
|
|
nav_view->height)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpImage *image;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
image = GIMP_IMAGE (view->renderer->viewable);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
if (nav_view->x > 0 ||
|
|
|
|
nav_view->y > 0 ||
|
2005-07-15 02:51:32 +08:00
|
|
|
nav_view->width < image->width ||
|
|
|
|
nav_view->height < image->height)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (view);
|
|
|
|
|
|
|
|
if (area)
|
2004-08-27 08:42:46 +08:00
|
|
|
gdk_gc_set_clip_rectangle (nav_view->gc, area);
|
2004-08-25 01:16:46 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
gdk_draw_rectangle (widget->window, nav_view->gc,
|
2004-08-25 01:16:46 +08:00
|
|
|
FALSE,
|
2004-08-27 08:42:46 +08:00
|
|
|
widget->allocation.x + nav_view->p_x + 1,
|
|
|
|
widget->allocation.y + nav_view->p_y + 1,
|
|
|
|
MAX (1, nav_view->p_width - BORDER_PEN_WIDTH),
|
|
|
|
MAX (1, nav_view->p_height - BORDER_PEN_WIDTH));
|
2004-08-25 01:16:46 +08:00
|
|
|
|
|
|
|
if (area)
|
2004-08-27 08:42:46 +08:00
|
|
|
gdk_gc_set_clip_rectangle (nav_view->gc, NULL);
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_set_marker (GimpNavigationView *nav_view,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpView *view;
|
2005-07-15 02:51:32 +08:00
|
|
|
GimpImage *image;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
g_return_if_fail (GIMP_IS_NAVIGATION_VIEW (nav_view));
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
view = GIMP_VIEW (nav_view);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
g_return_if_fail (view->renderer->viewable);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
image = GIMP_IMAGE (view->renderer->viewable);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
/* remove old marker */
|
2004-08-25 01:16:46 +08:00
|
|
|
if (GTK_WIDGET_DRAWABLE (view))
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_draw_marker (nav_view, NULL);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
nav_view->x = CLAMP (x, 0.0, image->width - 1.0);
|
|
|
|
nav_view->y = CLAMP (y, 0.0, image->height - 1.0);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-04-01 18:32:03 +08:00
|
|
|
if (width < 0.0)
|
2005-07-15 02:51:32 +08:00
|
|
|
width = image->width;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-04-01 18:32:03 +08:00
|
|
|
if (height < 0.0)
|
2005-07-15 02:51:32 +08:00
|
|
|
height = image->height;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2005-07-15 02:51:32 +08:00
|
|
|
nav_view->width = CLAMP (width, 1.0, image->width - nav_view->x);
|
|
|
|
nav_view->height = CLAMP (height, 1.0, image->height - nav_view->y);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_transform (nav_view);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
/* draw new marker */
|
2004-08-25 01:16:46 +08:00
|
|
|
if (GTK_WIDGET_DRAWABLE (view))
|
2004-08-27 08:42:46 +08:00
|
|
|
gimp_navigation_view_draw_marker (nav_view, NULL);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|