2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-06-18 13:10:03 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-08-27 00:42:46 +00:00
|
|
|
* GimpNavigationView Widget
|
2002-05-07 16:23:14 +00: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 13:10:03 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-06-18 13:10:03 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-06-18 13:10:03 +00: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-17 22:28:01 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-06-18 13:10:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-07-16 21:37:02 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2001-06-18 13:10:03 +00: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-24 21:27:11 +00:00
|
|
|
#include "core/gimpmarshal.h"
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
#include "gimpnavigationview.h"
|
2004-08-25 22:31:44 +00:00
|
|
|
#include "gimpviewrenderer.h"
|
2011-10-06 23:59:49 +02:00
|
|
|
#include "gimpwidgets-utils.h"
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
|
2008-08-24 07:10:31 +00:00
|
|
|
#define BORDER_WIDTH 2
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MARKER_CHANGED,
|
2001-08-09 16:39:08 +00:00
|
|
|
ZOOM,
|
|
|
|
SCROLL,
|
2001-06-18 13:10:03 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-19 19:00:08 +00:00
|
|
|
struct _GimpNavigationView
|
|
|
|
{
|
|
|
|
GimpView parent_instance;
|
|
|
|
|
|
|
|
/* values in image coordinates */
|
2016-01-05 15:14:08 +01:00
|
|
|
gdouble center_x;
|
|
|
|
gdouble center_y;
|
2008-07-19 19:00:08 +00:00
|
|
|
gdouble width;
|
|
|
|
gdouble height;
|
2016-07-16 21:37:02 +00:00
|
|
|
gboolean flip_horizontally;
|
|
|
|
gboolean flip_vertically;
|
|
|
|
gdouble rotate_angle;
|
2008-07-19 19:00:08 +00:00
|
|
|
|
|
|
|
/* values in view coordinates */
|
2016-01-05 15:14:08 +01:00
|
|
|
gint p_center_x;
|
|
|
|
gint p_center_y;
|
2008-07-19 19:00:08 +00:00
|
|
|
gint p_width;
|
|
|
|
gint p_height;
|
|
|
|
|
|
|
|
gint motion_offset_x;
|
|
|
|
gint motion_offset_y;
|
|
|
|
gboolean has_grab;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-16 21:37:02 +00:00
|
|
|
static void gimp_navigation_view_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
2010-10-15 14:35:13 +02:00
|
|
|
static gboolean gimp_navigation_view_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
2016-07-16 21:37:02 +00: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);
|
|
|
|
|
|
|
|
static void gimp_navigation_view_transform (GimpNavigationView *nav_view);
|
|
|
|
static void gimp_navigation_view_draw_marker (GimpNavigationView *nav_view,
|
|
|
|
cairo_t *cr);
|
|
|
|
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);
|
|
|
|
static gboolean gimp_navigation_view_point_in_marker (GimpNavigationView *nav_view,
|
|
|
|
gint x,
|
|
|
|
gint y);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
|
2006-05-15 09:46:31 +00:00
|
|
|
G_DEFINE_TYPE (GimpNavigationView, gimp_navigation_view, GIMP_TYPE_VIEW)
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
#define parent_class gimp_navigation_view_parent_class
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
static guint view_signals[LAST_SIGNAL] = { 0 };
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_class_init (GimpNavigationViewClass *klass)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2005-07-14 18:51:32 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
view_signals[MARKER_CHANGED] =
|
2005-05-27 13:05:26 +00:00
|
|
|
g_signal_new ("marker-changed",
|
2004-08-24 17:16:46 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2004-08-27 00:42:46 +00:00
|
|
|
G_STRUCT_OFFSET (GimpNavigationViewClass, marker_changed),
|
2004-08-24 17:16:46 +00:00
|
|
|
NULL, NULL,
|
2008-07-12 13:53:31 +00:00
|
|
|
gimp_marshal_VOID__DOUBLE_DOUBLE_DOUBLE_DOUBLE,
|
|
|
|
G_TYPE_NONE, 4,
|
|
|
|
G_TYPE_DOUBLE,
|
|
|
|
G_TYPE_DOUBLE,
|
2004-08-24 17:16:46 +00:00
|
|
|
G_TYPE_DOUBLE,
|
|
|
|
G_TYPE_DOUBLE);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
view_signals[ZOOM] =
|
2001-08-09 16:39:08 +00:00
|
|
|
g_signal_new ("zoom",
|
2004-08-24 17:16:46 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2004-08-27 00:42:46 +00:00
|
|
|
G_STRUCT_OFFSET (GimpNavigationViewClass, zoom),
|
2004-08-24 17:16:46 +00:00
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__ENUM,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GIMP_TYPE_ZOOM_TYPE);
|
2001-08-09 16:39:08 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
view_signals[SCROLL] =
|
2001-08-09 16:39:08 +00:00
|
|
|
g_signal_new ("scroll",
|
2004-08-24 17:16:46 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2004-08-27 00:42:46 +00:00
|
|
|
G_STRUCT_OFFSET (GimpNavigationViewClass, scroll),
|
2004-08-24 17:16:46 +00:00
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__ENUM,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GDK_TYPE_SCROLL_DIRECTION);
|
2001-08-09 16:39:08 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
widget_class->size_allocate = gimp_navigation_view_size_allocate;
|
2010-10-15 14:35:13 +02:00
|
|
|
widget_class->draw = gimp_navigation_view_draw;
|
2004-08-27 00:42:46 +00:00
|
|
|
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 13:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_init (GimpNavigationView *view)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2009-10-17 20:20:39 +02: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 13:10:03 +00:00
|
|
|
|
2016-07-16 21:37:02 +00:00
|
|
|
view->center_x = 0.0;
|
|
|
|
view->center_y = 0.0;
|
|
|
|
view->width = 0.0;
|
|
|
|
view->height = 0.0;
|
|
|
|
view->flip_horizontally = FALSE;
|
|
|
|
view->flip_vertically = FALSE;
|
|
|
|
view->rotate_angle = 0.0;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2016-01-05 15:14:08 +01:00
|
|
|
view->p_center_x = 0;
|
|
|
|
view->p_center_y = 0;
|
2004-08-27 00:42:46 +00:00
|
|
|
view->p_width = 0;
|
|
|
|
view->p_height = 0;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
view->motion_offset_x = 0;
|
|
|
|
view->motion_offset_y = 0;
|
|
|
|
view->has_grab = FALSE;
|
2003-11-10 02:00:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-10 14:07:22 +00:00
|
|
|
static void
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
2003-03-10 14:07:22 +00:00
|
|
|
{
|
2005-07-14 18:51:32 +00:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
2003-03-10 14:07:22 +00:00
|
|
|
|
2004-08-24 17:16:46 +00:00
|
|
|
if (GIMP_VIEW (widget)->renderer->viewable)
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_transform (GIMP_NAVIGATION_VIEW (widget));
|
2003-03-10 14:07:22 +00:00
|
|
|
}
|
|
|
|
|
2001-06-18 13:10:03 +00:00
|
|
|
static gboolean
|
2010-10-15 14:35:13 +02:00
|
|
|
gimp_navigation_view_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2010-10-15 14:35:13 +02:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
|
2008-08-22 20:58:46 +00:00
|
|
|
|
2010-10-15 14:35:13 +02:00
|
|
|
gimp_navigation_view_draw_marker (GIMP_NAVIGATION_VIEW (widget), cr);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2001-07-31 16:55:59 +00:00
|
|
|
return TRUE;
|
2001-06-18 13:10:03 +00:00
|
|
|
}
|
|
|
|
|
2002-05-05 19:17:41 +00:00
|
|
|
void
|
2018-05-01 13:42:19 +02:00
|
|
|
gimp_navigation_view_grab_pointer (GimpNavigationView *nav_view,
|
|
|
|
GdkEvent *event)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2005-07-14 18:51:32 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (nav_view);
|
2003-11-01 20:06:01 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
GdkCursor *cursor;
|
|
|
|
GdkWindow *window;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
nav_view->has_grab = TRUE;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
gtk_grab_add (widget);
|
|
|
|
|
2003-11-01 20:06:01 +00:00
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
window = GIMP_VIEW (nav_view)->event_window;
|
2003-04-11 08:37:26 +00:00
|
|
|
|
2018-05-01 13:42:19 +02:00
|
|
|
gdk_seat_grab (gdk_event_get_seat (event),
|
|
|
|
window,
|
|
|
|
GDK_SEAT_CAPABILITY_ALL,
|
|
|
|
FALSE, cursor, event, NULL, NULL);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2010-12-29 15:30:20 +01:00
|
|
|
g_object_unref (cursor);
|
2001-06-18 13:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2005-07-14 18:51:32 +00:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
2004-08-27 00:42:46 +00:00
|
|
|
gint tx, ty;
|
|
|
|
GdkDisplay *display;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
tx = bevent->x;
|
|
|
|
ty = bevent->y;
|
|
|
|
|
2011-09-18 01:29:51 +02:00
|
|
|
if (bevent->type == GDK_BUTTON_PRESS && bevent->button == 1)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2016-07-16 21:37:02 +00:00
|
|
|
if (! gimp_navigation_view_point_in_marker (nav_view, tx, ty))
|
2004-08-24 17:16:46 +00:00
|
|
|
{
|
2002-05-07 16:23:14 +00:00
|
|
|
GdkCursor *cursor;
|
|
|
|
|
2016-01-05 15:14:08 +01:00
|
|
|
nav_view->motion_offset_x = 0;
|
|
|
|
nav_view->motion_offset_y = 0;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_move_to (nav_view, tx, ty);
|
2002-05-07 16:23:14 +00:00
|
|
|
|
2003-11-01 20:06:01 +00:00
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
|
2004-08-24 17:16:46 +00:00
|
|
|
gdk_window_set_cursor (GIMP_VIEW (widget)->event_window, cursor);
|
2010-12-29 15:30:20 +01:00
|
|
|
g_object_unref (cursor);
|
2004-08-24 17:16:46 +00:00
|
|
|
}
|
2001-06-18 13:10:03 +00:00
|
|
|
else
|
2004-08-24 17:16:46 +00:00
|
|
|
{
|
2016-01-05 15:14:08 +01:00
|
|
|
nav_view->motion_offset_x = tx - nav_view->p_center_x;
|
|
|
|
nav_view->motion_offset_y = ty - nav_view->p_center_y;
|
2004-08-24 17:16:46 +00:00
|
|
|
}
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2018-05-01 13:42:19 +02:00
|
|
|
gimp_navigation_view_grab_pointer (nav_view, (GdkEvent *) bevent);
|
2001-06-18 13:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2005-07-14 18:51:32 +00:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2011-09-18 01:29:51 +02:00
|
|
|
if (bevent->button == 1 && nav_view->has_grab)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2004-08-27 00:42:46 +00:00
|
|
|
nav_view->has_grab = FALSE;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
gtk_grab_remove (widget);
|
2018-05-01 13:42:19 +02:00
|
|
|
gdk_seat_ungrab (gdk_event_get_seat ((GdkEvent *) bevent));
|
2001-06-18 13:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-08-09 16:39:08 +00:00
|
|
|
static gboolean
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_scroll (GtkWidget *widget,
|
|
|
|
GdkEventScroll *sevent)
|
2001-08-09 16:39:08 +00:00
|
|
|
{
|
2011-10-06 23:59:49 +02:00
|
|
|
if (sevent->state & gimp_get_toggle_behavior_mask ())
|
2001-08-09 16:39:08 +00:00
|
|
|
{
|
2005-11-18 20:00:02 +00:00
|
|
|
switch (sevent->direction)
|
2004-08-24 17:16:46 +00:00
|
|
|
{
|
2005-11-18 20:00:02 +00:00
|
|
|
case GDK_SCROLL_UP:
|
2004-08-27 00:42:46 +00:00
|
|
|
g_signal_emit (widget, view_signals[ZOOM], 0, GIMP_ZOOM_IN);
|
2005-11-18 20:00:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_SCROLL_DOWN:
|
2004-08-27 00:42:46 +00:00
|
|
|
g_signal_emit (widget, view_signals[ZOOM], 0, GIMP_ZOOM_OUT);
|
2005-11-18 20:00:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-24 17:16:46 +00:00
|
|
|
}
|
2001-08-09 16:39:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-18 20:00:02 +00: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-09 16:39:08 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
g_signal_emit (widget, view_signals[SCROLL], 0, direction);
|
2001-08-09 16:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-06-18 13:10:03 +00:00
|
|
|
static gboolean
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *mevent)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2005-07-14 18:51:32 +00:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
|
|
|
GimpView *view = GIMP_VIEW (widget);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2004-08-27 00:42:46 +00:00
|
|
|
if (! nav_view->has_grab)
|
2002-05-07 16:23:14 +00:00
|
|
|
{
|
2007-11-04 13:12:04 +00:00
|
|
|
GdkDisplay *display = gtk_widget_get_display (widget);
|
2003-11-01 20:06:01 +00:00
|
|
|
GdkCursor *cursor;
|
2016-01-05 15:14:08 +01:00
|
|
|
|
|
|
|
if (nav_view->p_center_x == view->renderer->width / 2 &&
|
|
|
|
nav_view->p_center_y == view->renderer->height / 2 &&
|
|
|
|
nav_view->p_width == view->renderer->width &&
|
|
|
|
nav_view->p_height == view->renderer->height)
|
2002-05-07 16:23:14 +00:00
|
|
|
{
|
2004-08-24 17:16:46 +00:00
|
|
|
gdk_window_set_cursor (view->event_window, NULL);
|
2002-05-07 16:23:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-07-16 21:37:02 +00:00
|
|
|
else if (gimp_navigation_view_point_in_marker (nav_view,
|
|
|
|
mevent->x, mevent->y))
|
2002-05-07 16:23:14 +00:00
|
|
|
{
|
2003-11-01 20:06:01 +00:00
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
|
2002-05-07 16:23:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-01 20:06:01 +00:00
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
|
2002-05-07 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
2004-08-24 17:16:46 +00:00
|
|
|
gdk_window_set_cursor (view->event_window, cursor);
|
2010-12-29 15:30:20 +01:00
|
|
|
g_object_unref (cursor);
|
2002-05-07 16:23:14 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2007-11-04 13:12:04 +00:00
|
|
|
gimp_navigation_view_move_to (nav_view,
|
2008-09-03 20:13:35 +00:00
|
|
|
mevent->x - nav_view->motion_offset_x,
|
|
|
|
mevent->y - nav_view->motion_offset_y);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2007-11-04 13:12:04 +00:00
|
|
|
gdk_event_request_motions (mevent);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *kevent)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2005-07-14 18:51:32 +00:00
|
|
|
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
|
|
|
|
gint scroll_x = 0;
|
|
|
|
gint scroll_y = 0;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
2011-03-29 15:27:25 +02:00
|
|
|
case GDK_KEY_Up:
|
2001-06-18 13:10:03 +00:00
|
|
|
scroll_y = -1;
|
|
|
|
break;
|
|
|
|
|
2011-03-29 15:27:25 +02:00
|
|
|
case GDK_KEY_Left:
|
2001-06-18 13:10:03 +00:00
|
|
|
scroll_x = -1;
|
|
|
|
break;
|
|
|
|
|
2011-03-29 15:27:25 +02:00
|
|
|
case GDK_KEY_Right:
|
2001-06-18 13:10:03 +00:00
|
|
|
scroll_x = 1;
|
|
|
|
break;
|
|
|
|
|
2011-03-29 15:27:25 +02:00
|
|
|
case GDK_KEY_Down:
|
2001-06-18 13:10:03 +00:00
|
|
|
scroll_y = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scroll_x || scroll_y)
|
|
|
|
{
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_move_to (nav_view,
|
2016-01-05 15:14:08 +01:00
|
|
|
nav_view->p_center_x + scroll_x,
|
|
|
|
nav_view->p_center_y + scroll_y);
|
2001-06-18 13:10:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-26 18:21:36 +00:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_navigation_view_set_marker (GimpNavigationView *nav_view,
|
2016-01-05 15:14:08 +01:00
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
2008-09-26 18:21:36 +00:00
|
|
|
gdouble width,
|
2016-07-16 21:37:02 +00:00
|
|
|
gdouble height,
|
|
|
|
gboolean flip_horizontally,
|
|
|
|
gboolean flip_vertically,
|
|
|
|
gdouble rotate_angle)
|
2008-09-26 18:21:36 +00:00
|
|
|
{
|
|
|
|
GimpView *view;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_NAVIGATION_VIEW (nav_view));
|
|
|
|
|
|
|
|
view = GIMP_VIEW (nav_view);
|
|
|
|
|
|
|
|
g_return_if_fail (view->renderer->viewable);
|
|
|
|
|
2016-07-16 21:37:02 +00:00
|
|
|
nav_view->center_x = center_x;
|
|
|
|
nav_view->center_y = center_y;
|
|
|
|
nav_view->width = MAX (1.0, width);
|
|
|
|
nav_view->height = MAX (1.0, height);
|
|
|
|
nav_view->flip_horizontally = flip_horizontally ? TRUE : FALSE;
|
|
|
|
nav_view->flip_vertically = flip_vertically ? TRUE : FALSE;
|
|
|
|
nav_view->rotate_angle = rotate_angle;
|
2008-09-26 18:21:36 +00:00
|
|
|
|
|
|
|
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,
|
2016-01-05 15:14:08 +01:00
|
|
|
gint *center_x,
|
|
|
|
gint *center_y,
|
2008-09-26 18:21:36 +00:00
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_NAVIGATION_VIEW (view));
|
|
|
|
|
2016-01-05 15:14:08 +01:00
|
|
|
if (center_x) *center_x = view->p_center_x;
|
|
|
|
if (center_y) *center_y = view->p_center_y;
|
|
|
|
if (width) *width = view->p_width;
|
|
|
|
if (height) *height = view->p_height;
|
2008-09-26 18:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2003-03-10 14:07:22 +00:00
|
|
|
static void
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_transform (GimpNavigationView *nav_view)
|
2003-03-10 14:07:22 +00:00
|
|
|
{
|
2008-08-22 06:50:52 +00:00
|
|
|
gdouble ratiox, ratioy;
|
2003-03-10 14:07:22 +00:00
|
|
|
|
2008-08-22 06:50:52 +00:00
|
|
|
gimp_navigation_view_get_ratio (nav_view, &ratiox, &ratioy);
|
2003-03-10 14:07:22 +00:00
|
|
|
|
2016-01-05 15:14:08 +01:00
|
|
|
nav_view->p_center_x = RINT (nav_view->center_x * ratiox);
|
|
|
|
nav_view->p_center_y = RINT (nav_view->center_y * ratioy);
|
2003-03-10 14:07:22 +00:00
|
|
|
|
2008-08-22 21:44:52 +00:00
|
|
|
nav_view->p_width = ceil (nav_view->width * ratiox);
|
|
|
|
nav_view->p_height = ceil (nav_view->height * ratioy);
|
2003-03-10 14:07:22 +00:00
|
|
|
}
|
|
|
|
|
2001-06-18 13:10:03 +00:00
|
|
|
static void
|
2004-08-27 00:42:46 +00:00
|
|
|
gimp_navigation_view_draw_marker (GimpNavigationView *nav_view,
|
2008-08-22 20:58:46 +00:00
|
|
|
cairo_t *cr)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2005-07-14 18:51:32 +00:00
|
|
|
GimpView *view = GIMP_VIEW (nav_view);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2008-08-22 20:58:46 +00:00
|
|
|
if (view->renderer->viewable && nav_view->width && nav_view->height)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2010-01-15 15:33:08 +01:00
|
|
|
GtkWidget *widget = GTK_WIDGET (view);
|
|
|
|
GtkAllocation allocation;
|
2016-01-05 15:14:08 +01:00
|
|
|
gint p_width_2;
|
|
|
|
gint p_height_2;
|
2016-07-16 21:37:02 +00:00
|
|
|
gdouble angle;
|
2016-01-05 15:14:08 +01:00
|
|
|
|
|
|
|
p_width_2 = nav_view->p_width / 2;
|
|
|
|
p_height_2 = nav_view->p_height / 2;
|
2010-01-15 15:33:08 +01:00
|
|
|
|
2016-07-16 21:37:02 +00:00
|
|
|
angle = G_PI * nav_view->rotate_angle / 180.0;
|
|
|
|
if (nav_view->flip_horizontally != nav_view->flip_vertically)
|
|
|
|
angle = -angle;
|
|
|
|
|
2010-01-15 15:33:08 +01:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2008-08-22 20:58:46 +00:00
|
|
|
|
|
|
|
cairo_rectangle (cr,
|
2008-08-22 21:04:28 +00:00
|
|
|
0, 0,
|
2010-01-15 15:33:08 +01:00
|
|
|
allocation.width, allocation.height);
|
2016-07-16 21:37:02 +00:00
|
|
|
cairo_translate (cr, nav_view->p_center_x, nav_view->p_center_y);
|
|
|
|
cairo_rotate (cr, -angle);
|
2008-08-22 20:58:46 +00:00
|
|
|
cairo_rectangle (cr,
|
2016-07-16 21:37:02 +00:00
|
|
|
-p_width_2, -p_height_2,
|
|
|
|
nav_view->p_width, nav_view->p_height);
|
2008-08-22 20:58:46 +00:00
|
|
|
|
2008-08-22 21:44:52 +00:00
|
|
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
|
2008-08-22 20:58:46 +00:00
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
cairo_rectangle (cr,
|
2016-07-16 21:37:02 +00:00
|
|
|
-p_width_2, -p_height_2,
|
|
|
|
nav_view->p_width, nav_view->p_height);
|
2008-08-22 20:58:46 +00:00
|
|
|
|
2008-08-22 21:44:52 +00:00
|
|
|
cairo_set_source_rgb (cr, 1, 1, 1);
|
2008-08-24 07:10:31 +00:00
|
|
|
cairo_set_line_width (cr, BORDER_WIDTH);
|
2008-08-22 20:58:46 +00:00
|
|
|
cairo_stroke (cr);
|
2001-06-18 13:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 18:21:36 +00:00
|
|
|
static void
|
|
|
|
gimp_navigation_view_move_to (GimpNavigationView *nav_view,
|
|
|
|
gint tx,
|
|
|
|
gint ty)
|
2001-06-18 13:10:03 +00:00
|
|
|
{
|
2008-09-26 18:21:36 +00:00
|
|
|
GimpView *view = GIMP_VIEW (nav_view);
|
|
|
|
gdouble ratiox, ratioy;
|
|
|
|
gdouble x, y;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2008-09-26 18:21:36 +00:00
|
|
|
if (! view->renderer->viewable)
|
|
|
|
return;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2008-09-26 18:21:36 +00:00
|
|
|
gimp_navigation_view_get_ratio (nav_view, &ratiox, &ratioy);
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2008-09-26 18:21:36 +00:00
|
|
|
x = tx / ratiox;
|
|
|
|
y = ty / ratioy;
|
2001-06-18 13:10:03 +00:00
|
|
|
|
2008-09-26 18:21:36 +00:00
|
|
|
g_signal_emit (view, view_signals[MARKER_CHANGED], 0,
|
|
|
|
x, y, nav_view->width, nav_view->height);
|
2001-06-18 13:10:03 +00:00
|
|
|
}
|
2008-07-19 19:00:08 +00:00
|
|
|
|
2008-09-26 18:21:36 +00:00
|
|
|
static void
|
|
|
|
gimp_navigation_view_get_ratio (GimpNavigationView *nav_view,
|
|
|
|
gdouble *ratiox,
|
|
|
|
gdouble *ratioy)
|
2008-07-19 19:00:08 +00:00
|
|
|
{
|
2008-09-26 18:21:36 +00:00
|
|
|
GimpView *view = GIMP_VIEW (nav_view);
|
|
|
|
GimpImage *image;
|
2008-07-19 19:00:08 +00:00
|
|
|
|
2008-09-26 18:21:36 +00:00
|
|
|
image = GIMP_IMAGE (view->renderer->viewable);
|
2008-07-19 19:00:08 +00:00
|
|
|
|
2008-09-26 18:21:36 +00: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-19 19:00:08 +00:00
|
|
|
}
|
2016-07-16 21:37:02 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_navigation_view_point_in_marker (GimpNavigationView *nav_view,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
gint p_width_2, p_height_2;
|
|
|
|
gdouble angle;
|
|
|
|
gdouble tx, ty;
|
|
|
|
|
|
|
|
p_width_2 = nav_view->p_width / 2;
|
|
|
|
p_height_2 = nav_view->p_height / 2;
|
|
|
|
|
|
|
|
angle = G_PI * nav_view->rotate_angle / 180.0;
|
|
|
|
if (nav_view->flip_horizontally != nav_view->flip_vertically)
|
|
|
|
angle = -angle;
|
|
|
|
|
|
|
|
x -= nav_view->p_center_x;
|
|
|
|
y -= nav_view->p_center_y;
|
|
|
|
|
|
|
|
tx = cos (angle) * x - sin (angle) * y;
|
|
|
|
ty = sin (angle) * x + cos (angle) * y;
|
|
|
|
|
|
|
|
return tx >= -p_width_2 && tx < p_width_2 &&
|
|
|
|
ty >= -p_height_2 && ty < p_height_2;
|
|
|
|
}
|