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
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-06-18 21:10:03 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-06-18 21:10:03 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-06-18 21:10:03 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-06-18 21:10:03 +08:00
|
|
|
#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
|
|
|
|
|
|
|
|
2008-08-24 15:10:31 +08:00
|
|
|
#define BORDER_WIDTH 2
|
2001-06-18 21:10:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MARKER_CHANGED,
|
2001-08-10 00:39:08 +08:00
|
|
|
ZOOM,
|
|
|
|
SCROLL,
|
2001-06-18 21:10:03 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-20 03:00:08 +08:00
|
|
|
struct _GimpNavigationView
|
|
|
|
{
|
|
|
|
GimpView parent_instance;
|
|
|
|
|
|
|
|
/* values in image coordinates */
|
|
|
|
gdouble x;
|
|
|
|
gdouble y;
|
|
|
|
gdouble width;
|
|
|
|
gdouble height;
|
|
|
|
|
|
|
|
/* values in view coordinates */
|
|
|
|
gint p_x;
|
|
|
|
gint p_y;
|
|
|
|
gint p_width;
|
|
|
|
gint p_height;
|
|
|
|
|
|
|
|
gint motion_offset_x;
|
|
|
|
gint motion_offset_y;
|
|
|
|
gboolean has_grab;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-08-27 08:42:46 +08:00
|
|
|
static void gimp_navigation_view_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static gboolean gimp_navigation_view_expose (GtkWidget *widget,
|
2008-08-23 04:58:46 +08:00
|
|
|
GdkEventExpose *event);
|
2004-08-27 08:42:46 +08:00
|
|
|
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,
|
2008-08-23 04:58:46 +08:00
|
|
|
cairo_t *cr);
|
2008-09-27 02:21:36 +08:00
|
|
|
static void gimp_navigation_view_move_to (GimpNavigationView *nav_view,
|
|
|
|
gint tx,
|
|
|
|
gint ty);
|
|
|
|
static void gimp_navigation_view_get_ratio (GimpNavigationView *nav_view,
|
|
|
|
gdouble *ratiox,
|
|
|
|
gdouble *ratioy);
|
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,
|
2008-07-12 21:53:31 +08:00
|
|
|
gimp_marshal_VOID__DOUBLE_DOUBLE_DOUBLE_DOUBLE,
|
|
|
|
G_TYPE_NONE, 4,
|
|
|
|
G_TYPE_DOUBLE,
|
|
|
|
G_TYPE_DOUBLE,
|
2004-08-25 01:16:46 +08:00
|
|
|
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->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
|
|
|
{
|
2009-10-18 02:20:39 +08:00
|
|
|
gtk_widget_set_can_focus (GTK_WIDGET (view), TRUE);
|
|
|
|
gtk_widget_add_events (GTK_WIDGET (view),
|
|
|
|
GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_KEY_PRESS_MASK);
|
2001-06-18 21:10:03 +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;
|
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,
|
2008-08-23 04:58:46 +08:00
|
|
|
GdkEventExpose *event)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2009-10-18 02:20:39 +08:00
|
|
|
if (gtk_widget_is_drawable (widget))
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2008-08-23 04:58:46 +08:00
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
cr = gdk_cairo_create (gtk_widget_get_window (widget));
|
2008-08-23 04:58:46 +08:00
|
|
|
|
|
|
|
gdk_cairo_region (cr, event->region);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
|
|
|
gimp_navigation_view_draw_marker (GIMP_NAVIGATION_VIEW (widget), cr);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2008-08-23 04:58:46 +08:00
|
|
|
cairo_destroy (cr);
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2008-09-04 04:13:35 +08:00
|
|
|
gdk_pointer_grab (window, FALSE,
|
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,
|
2008-08-23 00:30:52 +08:00
|
|
|
NULL, 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);
|
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
|
|
|
{
|
2007-11-04 21:12:04 +08:00
|
|
|
GdkDisplay *display = gtk_widget_get_display (widget);
|
2003-11-02 04:06:01 +08:00
|
|
|
GdkCursor *cursor;
|
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
|
|
|
|
2007-11-04 21:12:04 +08:00
|
|
|
gimp_navigation_view_move_to (nav_view,
|
2008-09-04 04:13:35 +08:00
|
|
|
mevent->x - nav_view->motion_offset_x,
|
|
|
|
mevent->y - nav_view->motion_offset_y);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2007-11-04 21:12:04 +08:00
|
|
|
gdk_event_request_motions (mevent);
|
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)
|
|
|
|
{
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Up:
|
2001-06-18 21:10:03 +08:00
|
|
|
scroll_y = -1;
|
|
|
|
break;
|
|
|
|
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Left:
|
2001-06-18 21:10:03 +08:00
|
|
|
scroll_x = -1;
|
|
|
|
break;
|
|
|
|
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Right:
|
2001-06-18 21:10:03 +08:00
|
|
|
scroll_x = 1;
|
|
|
|
break;
|
|
|
|
|
2011-03-29 21:27:25 +08:00
|
|
|
case GDK_KEY_Down:
|
2001-06-18 21:10:03 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_navigation_view_set_marker (GimpNavigationView *nav_view,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
|
|
|
GimpView *view;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_NAVIGATION_VIEW (nav_view));
|
|
|
|
|
|
|
|
view = GIMP_VIEW (nav_view);
|
|
|
|
|
|
|
|
g_return_if_fail (view->renderer->viewable);
|
|
|
|
|
|
|
|
nav_view->x = x;
|
|
|
|
nav_view->y = y;
|
|
|
|
nav_view->width = MAX (1.0, width);
|
|
|
|
nav_view->height = MAX (1.0, height);
|
|
|
|
|
|
|
|
gimp_navigation_view_transform (nav_view);
|
|
|
|
|
|
|
|
/* Marker changed, redraw */
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (view));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_navigation_view_set_motion_offset (GimpNavigationView *view,
|
|
|
|
gint motion_offset_x,
|
|
|
|
gint motion_offset_y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_NAVIGATION_VIEW (view));
|
|
|
|
|
|
|
|
view->motion_offset_x = motion_offset_x;
|
|
|
|
view->motion_offset_y = motion_offset_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_navigation_view_get_local_marker (GimpNavigationView *view,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_NAVIGATION_VIEW (view));
|
|
|
|
|
|
|
|
if (x) *x = view->p_x;
|
|
|
|
if (y) *y = view->p_y;
|
|
|
|
if (width) *width = view->p_width;
|
|
|
|
if (height) *height = view->p_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
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
|
|
|
{
|
2008-08-22 14:50:52 +08:00
|
|
|
gdouble ratiox, ratioy;
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2008-08-22 14:50:52 +08:00
|
|
|
gimp_navigation_view_get_ratio (nav_view, &ratiox, &ratioy);
|
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
|
|
|
|
2008-08-23 05:44:52 +08:00
|
|
|
nav_view->p_width = ceil (nav_view->width * ratiox);
|
|
|
|
nav_view->p_height = ceil (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,
|
2008-08-23 04:58:46 +08:00
|
|
|
cairo_t *cr)
|
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
|
|
|
|
2008-08-23 04:58:46 +08:00
|
|
|
if (view->renderer->viewable && nav_view->width && nav_view->height)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2010-01-15 22:33:08 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (view);
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2008-08-23 04:58:46 +08:00
|
|
|
|
2010-01-15 22:33:08 +08:00
|
|
|
cairo_translate (cr, allocation.x, allocation.y);
|
2008-08-23 04:58:46 +08:00
|
|
|
cairo_rectangle (cr,
|
2008-08-23 05:04:28 +08:00
|
|
|
0, 0,
|
2010-01-15 22:33:08 +08:00
|
|
|
allocation.width, allocation.height);
|
2008-08-23 04:58:46 +08:00
|
|
|
cairo_rectangle (cr,
|
2008-08-23 05:04:28 +08:00
|
|
|
nav_view->p_x, nav_view->p_y,
|
|
|
|
nav_view->p_width, nav_view->p_height);
|
2008-08-23 04:58:46 +08:00
|
|
|
|
2008-08-23 05:44:52 +08:00
|
|
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
|
2008-08-23 04:58:46 +08:00
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
cairo_rectangle (cr,
|
2008-08-23 05:04:28 +08:00
|
|
|
nav_view->p_x, nav_view->p_y,
|
|
|
|
nav_view->p_width, nav_view->p_height);
|
2008-08-23 04:58:46 +08:00
|
|
|
|
2008-08-23 05:44:52 +08:00
|
|
|
cairo_set_source_rgb (cr, 1, 1, 1);
|
2008-08-24 15:10:31 +08:00
|
|
|
cairo_set_line_width (cr, BORDER_WIDTH);
|
2008-08-23 04:58:46 +08:00
|
|
|
cairo_stroke (cr);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
static void
|
|
|
|
gimp_navigation_view_move_to (GimpNavigationView *nav_view,
|
|
|
|
gint tx,
|
|
|
|
gint ty)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2008-09-27 02:21:36 +08:00
|
|
|
GimpView *view = GIMP_VIEW (nav_view);
|
|
|
|
gdouble ratiox, ratioy;
|
|
|
|
gdouble x, y;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
if (! view->renderer->viewable)
|
|
|
|
return;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
gimp_navigation_view_get_ratio (nav_view, &ratiox, &ratioy);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
x = tx / ratiox;
|
|
|
|
y = ty / ratioy;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
g_signal_emit (view, view_signals[MARKER_CHANGED], 0,
|
|
|
|
x, y, nav_view->width, nav_view->height);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
2008-07-20 03:00:08 +08:00
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
static void
|
|
|
|
gimp_navigation_view_get_ratio (GimpNavigationView *nav_view,
|
|
|
|
gdouble *ratiox,
|
|
|
|
gdouble *ratioy)
|
2008-07-20 03:00:08 +08:00
|
|
|
{
|
2008-09-27 02:21:36 +08:00
|
|
|
GimpView *view = GIMP_VIEW (nav_view);
|
|
|
|
GimpImage *image;
|
2008-07-20 03:00:08 +08:00
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
image = GIMP_IMAGE (view->renderer->viewable);
|
2008-07-20 03:00:08 +08:00
|
|
|
|
2008-09-27 02:21:36 +08:00
|
|
|
*ratiox = (gdouble) view->renderer->width /
|
|
|
|
(gdouble) gimp_image_get_width (image);
|
|
|
|
*ratioy = (gdouble) view->renderer->height /
|
|
|
|
(gdouble) gimp_image_get_height (image);
|
2008-07-20 03:00:08 +08:00
|
|
|
}
|