2003-10-30 04:57:21 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2001-05-07 05:51:20 +08:00
|
|
|
*
|
|
|
|
* gimpoffsetarea.c
|
|
|
|
* Copyright (C) 2001 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2001-05-07 05:51:20 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2003-10-30 04:57:21 +08:00
|
|
|
*
|
2001-05-07 05:51:20 +08:00
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2001-05-07 05:51:20 +08:00
|
|
|
*/
|
|
|
|
|
2004-11-09 08:40:25 +08:00
|
|
|
#include "config.h"
|
2001-05-07 05:51:20 +08:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
2002-01-30 16:31:00 +08:00
|
|
|
#include "gimpwidgetsmarshal.h"
|
2001-05-07 05:51:20 +08:00
|
|
|
#include "gimpoffsetarea.h"
|
|
|
|
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpoffsetarea
|
|
|
|
* @title: GimpOffsetArea
|
|
|
|
* @short_description: Widget to control image offsets.
|
|
|
|
*
|
|
|
|
* Widget to control image offsets.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2001-05-07 05:51:20 +08:00
|
|
|
#define DRAWING_AREA_SIZE 200
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
OFFSETS_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
struct _GimpOffsetAreaPrivate
|
|
|
|
{
|
|
|
|
gint orig_width;
|
|
|
|
gint orig_height;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
gdouble display_ratio_x;
|
|
|
|
gdouble display_ratio_y;
|
|
|
|
};
|
|
|
|
|
2018-05-03 18:51:36 +08:00
|
|
|
#define GET_PRIVATE(obj) (((GimpOffsetArea *) (obj))->priv)
|
2010-12-29 23:49:38 +08:00
|
|
|
|
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static void gimp_offset_area_resize (GimpOffsetArea *area);
|
2007-07-20 20:29:38 +08:00
|
|
|
|
|
|
|
static void gimp_offset_area_realize (GtkWidget *widget);
|
2005-12-21 04:35:23 +08:00
|
|
|
static void gimp_offset_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static gboolean gimp_offset_area_event (GtkWidget *widget,
|
|
|
|
GdkEvent *event);
|
2010-10-15 17:20:14 +08:00
|
|
|
static gboolean gimp_offset_area_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2001-05-07 05:51:20 +08:00
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpOffsetArea, gimp_offset_area,
|
|
|
|
GTK_TYPE_DRAWING_AREA)
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_offset_area_parent_class
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static guint gimp_offset_area_signals[LAST_SIGNAL] = { 0 };
|
2001-05-07 05:51:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
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
|
|
|
gimp_offset_area_class_init (GimpOffsetAreaClass *klass)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2004-05-05 07:12:59 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
gimp_offset_area_signals[OFFSETS_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("offsets-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpOffsetAreaClass, offsets_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
_gimp_widgets_marshal_VOID__INT_INT,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_INT);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2007-07-20 20:29:38 +08:00
|
|
|
widget_class->size_allocate = gimp_offset_area_size_allocate;
|
|
|
|
widget_class->realize = gimp_offset_area_realize;
|
2004-05-05 07:12:59 +08:00
|
|
|
widget_class->event = gimp_offset_area_event;
|
2010-10-15 17:20:14 +08:00
|
|
|
widget_class->draw = gimp_offset_area_draw;
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-05-05 07:12:59 +08:00
|
|
|
gimp_offset_area_init (GimpOffsetArea *area)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpOffsetAreaPrivate *private;
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
area->priv = gimp_offset_area_get_instance_private (area);
|
2018-05-03 18:51:36 +08:00
|
|
|
|
|
|
|
private = GET_PRIVATE (area);
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
private->display_ratio_x = 1.0;
|
|
|
|
private->display_ratio_y = 1.0;
|
2004-05-05 07:12:59 +08:00
|
|
|
|
2011-12-11 04:51:05 +08:00
|
|
|
gtk_widget_add_events (GTK_WIDGET (area),
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK);
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_offset_area_new:
|
|
|
|
* @orig_width: the original width
|
|
|
|
* @orig_height: the original height
|
2003-10-30 04:57:21 +08:00
|
|
|
*
|
|
|
|
* Creates a new #GimpOffsetArea widget. A #GimpOffsetArea can be used
|
|
|
|
* when resizing an image or a drawable to allow the user to interactively
|
2001-05-07 05:51:20 +08:00
|
|
|
* specify the new offsets.
|
2003-10-30 04:57:21 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the new #GimpOffsetArea widget.
|
2001-05-07 05:51:20 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_offset_area_new (gint orig_width,
|
|
|
|
gint orig_height)
|
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
GimpOffsetArea *area;
|
|
|
|
GimpOffsetAreaPrivate *private;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (orig_width > 0, NULL);
|
|
|
|
g_return_val_if_fail (orig_height > 0, NULL);
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
area = g_object_new (GIMP_TYPE_OFFSET_AREA, NULL);
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
private = GET_PRIVATE (area);
|
|
|
|
|
|
|
|
private->orig_width = private->width = orig_width;
|
|
|
|
private->orig_height = private->height = orig_height;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
gimp_offset_area_resize (area);
|
|
|
|
|
|
|
|
return GTK_WIDGET (area);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_offset_area_set_pixbuf:
|
|
|
|
* @offset_area: a #GimpOffsetArea.
|
|
|
|
* @pixbuf: a #GdkPixbuf.
|
|
|
|
*
|
|
|
|
* Sets the pixbuf which represents the original image/drawable which
|
|
|
|
* is being offset.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-05-05 07:12:59 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_offset_area_set_pixbuf (GimpOffsetArea *area,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_OFFSET_AREA (area));
|
|
|
|
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
g_object_set_data_full (G_OBJECT (area), "pixbuf",
|
|
|
|
gdk_pixbuf_copy (pixbuf),
|
|
|
|
(GDestroyNotify) g_object_unref);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (area));
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_offset_area_set_size:
|
|
|
|
* @offset_area: a #GimpOffsetArea.
|
|
|
|
* @width: the new width
|
|
|
|
* @height: the new height
|
2003-10-30 04:57:21 +08:00
|
|
|
*
|
2001-05-07 05:51:20 +08:00
|
|
|
* Sets the size of the image/drawable displayed by the #GimpOffsetArea.
|
2005-05-27 21:05:26 +08:00
|
|
|
* If the offsets change as a result of this change, the "offsets-changed"
|
2001-05-07 05:51:20 +08:00
|
|
|
* signal is emitted.
|
|
|
|
**/
|
|
|
|
void
|
2004-05-05 07:12:59 +08:00
|
|
|
gimp_offset_area_set_size (GimpOffsetArea *area,
|
2001-05-07 05:51:20 +08:00
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
GimpOffsetAreaPrivate *private;
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
g_return_if_fail (GIMP_IS_OFFSET_AREA (area));
|
2001-05-07 05:51:20 +08:00
|
|
|
g_return_if_fail (width > 0 && height > 0);
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
private = GET_PRIVATE (area);
|
|
|
|
|
|
|
|
if (private->width != width || private->height != height)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2004-11-09 08:40:25 +08:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
private->width = width;
|
|
|
|
private->height = height;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_width <= private->width)
|
|
|
|
offset_x = CLAMP (private->offset_x,
|
|
|
|
0, private->width - private->orig_width);
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2010-12-29 23:49:38 +08:00
|
|
|
offset_x = CLAMP (private->offset_x,
|
|
|
|
private->width - private->orig_width, 0);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_height <= private->height)
|
|
|
|
offset_y = CLAMP (private->offset_y,
|
|
|
|
0, private->height - private->orig_height);
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2010-12-29 23:49:38 +08:00
|
|
|
offset_y = CLAMP (private->offset_y,
|
|
|
|
private->height - private->orig_height, 0);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (offset_x != private->offset_x || offset_y != private->offset_y)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
private->offset_x = offset_x;
|
|
|
|
private->offset_y = offset_y;
|
2004-11-09 08:40:25 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
g_signal_emit (area,
|
2003-10-30 04:57:21 +08:00
|
|
|
gimp_offset_area_signals[OFFSETS_CHANGED], 0,
|
2004-11-09 08:40:25 +08:00
|
|
|
offset_x, offset_y);
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
2004-11-09 08:40:25 +08:00
|
|
|
|
|
|
|
gimp_offset_area_resize (area);
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-01-05 23:41:23 +08:00
|
|
|
* gimp_offset_area_set_offsets:
|
2001-05-07 05:51:20 +08:00
|
|
|
* @offset_area: a #GimpOffsetArea.
|
2003-01-05 23:41:23 +08:00
|
|
|
* @offset_x: the X offset
|
|
|
|
* @offset_y: the Y offset
|
2003-10-30 04:57:21 +08:00
|
|
|
*
|
2001-05-07 05:51:20 +08:00
|
|
|
* Sets the offsets of the image/drawable displayed by the #GimpOffsetArea.
|
2005-05-27 21:05:26 +08:00
|
|
|
* It does not emit the "offsets-changed" signal.
|
2001-05-07 05:51:20 +08:00
|
|
|
**/
|
|
|
|
void
|
2004-05-05 07:12:59 +08:00
|
|
|
gimp_offset_area_set_offsets (GimpOffsetArea *area,
|
2001-05-07 05:51:20 +08:00
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
GimpOffsetAreaPrivate *private;
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
g_return_if_fail (GIMP_IS_OFFSET_AREA (area));
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
private = GET_PRIVATE (area);
|
|
|
|
|
|
|
|
if (private->offset_x != offset_x || private->offset_y != offset_y)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_width <= private->width)
|
|
|
|
private->offset_x = CLAMP (offset_x,
|
|
|
|
0, private->width - private->orig_width);
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2010-12-29 23:49:38 +08:00
|
|
|
private->offset_x = CLAMP (offset_x,
|
|
|
|
private->width - private->orig_width, 0);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_height <= private->height)
|
|
|
|
private->offset_y = CLAMP (offset_y,
|
|
|
|
0, private->height - private->orig_height);
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2010-12-29 23:49:38 +08:00
|
|
|
private->offset_y = CLAMP (offset_y,
|
|
|
|
private->height - private->orig_height, 0);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (area));
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-05-05 07:12:59 +08:00
|
|
|
gimp_offset_area_resize (GimpOffsetArea *area)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gdouble ratio;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_width == 0 || private->orig_height == 0)
|
2001-05-07 05:51:20 +08:00
|
|
|
return;
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_width <= private->width)
|
|
|
|
width = private->width;
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2010-12-29 23:49:38 +08:00
|
|
|
width = private->orig_width * 2 - private->width;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_height <= private->height)
|
|
|
|
height = private->height;
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2010-12-29 23:49:38 +08:00
|
|
|
height = private->orig_height * 2 - private->height;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
|
|
|
ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) MAX (width, height);
|
|
|
|
|
|
|
|
width = ratio * (gdouble) width;
|
|
|
|
height = ratio * (gdouble) height;
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (area), width, height);
|
2004-11-09 08:40:25 +08:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (area));
|
2004-05-05 07:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_offset_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
GimpOffsetArea *area = GIMP_OFFSET_AREA (widget);
|
|
|
|
GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
|
|
|
|
GdkPixbuf *pixbuf;
|
2004-05-05 07:12:59 +08:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
private->display_ratio_x = ((gdouble) allocation->width /
|
|
|
|
((private->orig_width <= private->width) ?
|
|
|
|
private->width :
|
|
|
|
private->orig_width * 2 - private->width));
|
2004-05-05 07:12:59 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
private->display_ratio_y = ((gdouble) allocation->height /
|
|
|
|
((private->orig_height <= private->height) ?
|
|
|
|
private->height :
|
|
|
|
private->orig_height * 2 - private->height));
|
2004-05-05 07:12:59 +08:00
|
|
|
|
|
|
|
pixbuf = g_object_get_data (G_OBJECT (area), "pixbuf");
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
{
|
|
|
|
GdkPixbuf *copy;
|
|
|
|
gint pixbuf_width;
|
|
|
|
gint pixbuf_height;
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
pixbuf_width = private->display_ratio_x * private->orig_width;
|
2007-08-03 21:11:00 +08:00
|
|
|
pixbuf_width = MAX (pixbuf_width, 1);
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
pixbuf_height = private->display_ratio_y * private->orig_height;
|
2007-08-03 21:11:00 +08:00
|
|
|
pixbuf_height = MAX (pixbuf_height, 1);
|
2004-05-05 07:12:59 +08:00
|
|
|
|
|
|
|
copy = g_object_get_data (G_OBJECT (area), "pixbuf-copy");
|
|
|
|
|
|
|
|
if (copy &&
|
|
|
|
(pixbuf_width != gdk_pixbuf_get_width (copy) ||
|
|
|
|
pixbuf_height != gdk_pixbuf_get_height (copy)))
|
|
|
|
{
|
|
|
|
copy = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! copy)
|
|
|
|
{
|
|
|
|
copy = gdk_pixbuf_scale_simple (pixbuf, pixbuf_width, pixbuf_height,
|
|
|
|
GDK_INTERP_NEAREST);
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (area), "pixbuf-copy",
|
|
|
|
copy, (GDestroyNotify) g_object_unref);
|
|
|
|
}
|
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
|
2007-07-20 20:29:38 +08:00
|
|
|
static void
|
|
|
|
gimp_offset_area_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GdkCursor *cursor;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->realize (widget);
|
|
|
|
|
|
|
|
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
|
|
|
|
GDK_FLEUR);
|
2009-03-22 23:42:42 +08:00
|
|
|
gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
|
2010-12-23 04:53:10 +08:00
|
|
|
g_object_unref (cursor);
|
2007-07-20 20:29:38 +08:00
|
|
|
}
|
|
|
|
|
2001-05-07 05:51:20 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_offset_area_event (GtkWidget *widget,
|
|
|
|
GdkEvent *event)
|
|
|
|
{
|
|
|
|
static gint orig_offset_x = 0;
|
|
|
|
static gint orig_offset_y = 0;
|
|
|
|
static gint start_x = 0;
|
|
|
|
static gint start_y = 0;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
GimpOffsetArea *area = GIMP_OFFSET_AREA (widget);
|
|
|
|
GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_width == 0 || private->orig_height == 0)
|
2001-05-07 05:51:20 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
2011-12-11 04:51:05 +08:00
|
|
|
if (event->button.button == 1)
|
|
|
|
{
|
|
|
|
gtk_grab_add (widget);
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
orig_offset_x = private->offset_x;
|
|
|
|
orig_offset_y = private->offset_y;
|
2011-12-11 04:51:05 +08:00
|
|
|
start_x = event->button.x;
|
|
|
|
start_y = event->button.y;
|
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_MOTION_NOTIFY:
|
2004-05-05 07:12:59 +08:00
|
|
|
offset_x = (orig_offset_x +
|
2010-12-29 23:49:38 +08:00
|
|
|
(event->motion.x - start_x) / private->display_ratio_x);
|
2004-05-05 07:12:59 +08:00
|
|
|
offset_y = (orig_offset_y +
|
2010-12-29 23:49:38 +08:00
|
|
|
(event->motion.y - start_y) / private->display_ratio_y);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->offset_x != offset_x || private->offset_y != offset_y)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2004-05-05 07:12:59 +08:00
|
|
|
gimp_offset_area_set_offsets (area, offset_x, offset_y);
|
|
|
|
|
|
|
|
g_signal_emit (area,
|
2003-10-30 04:57:21 +08:00
|
|
|
gimp_offset_area_signals[OFFSETS_CHANGED], 0,
|
2010-12-29 23:49:38 +08:00
|
|
|
private->offset_x, private->offset_y);
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_BUTTON_RELEASE:
|
2011-12-11 04:51:05 +08:00
|
|
|
if (event->button.button == 1)
|
|
|
|
{
|
|
|
|
gtk_grab_remove (widget);
|
|
|
|
|
|
|
|
start_x = start_y = 0;
|
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-12-11 04:51:05 +08:00
|
|
|
return FALSE;
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
|
2011-12-11 04:51:05 +08:00
|
|
|
return TRUE;
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
static gboolean
|
2010-10-15 17:20:14 +08:00
|
|
|
gimp_offset_area_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
GimpOffsetArea *area = GIMP_OFFSET_AREA (widget);
|
|
|
|
GimpOffsetAreaPrivate *private = GET_PRIVATE (area);
|
|
|
|
GtkStyleContext *context = gtk_widget_get_style_context (widget);
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
gint w, h;
|
|
|
|
gint x, y;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2009-10-18 00:51:48 +08:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
x = (private->display_ratio_x *
|
|
|
|
((private->orig_width <= private->width) ?
|
|
|
|
private->offset_x :
|
|
|
|
private->offset_x + private->orig_width - private->width));
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
y = (private->display_ratio_y *
|
|
|
|
((private->orig_height <= private->height) ?
|
|
|
|
private->offset_y :
|
|
|
|
private->offset_y + private->orig_height - private->height));
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
w = private->display_ratio_x * private->orig_width;
|
2007-08-03 21:11:00 +08:00
|
|
|
w = MAX (w, 1);
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
h = private->display_ratio_y * private->orig_height;
|
2007-08-03 21:11:00 +08:00
|
|
|
h = MAX (h, 1);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
pixbuf = g_object_get_data (G_OBJECT (widget), "pixbuf-copy");
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (pixbuf)
|
|
|
|
{
|
2010-09-12 04:39:05 +08:00
|
|
|
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
cairo_rectangle (cr, x + 0.5, y + 0.5, w - 1, h - 1);
|
|
|
|
cairo_set_line_width (cr, 1.0);
|
2010-12-16 19:25:58 +08:00
|
|
|
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
|
2010-09-12 04:39:05 +08:00
|
|
|
cairo_stroke (cr);
|
2004-05-05 07:12:59 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-16 19:25:58 +08:00
|
|
|
gtk_render_frame (context, cr, x, y, w, h);
|
2004-05-05 07:12:59 +08:00
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_width > private->width ||
|
|
|
|
private->orig_height > private->height)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2010-09-12 04:39:05 +08:00
|
|
|
gint line_width;
|
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_width > private->width)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
x = private->display_ratio_x * (private->orig_width - private->width);
|
|
|
|
w = private->display_ratio_x * private->width;
|
2006-04-12 18:53:28 +08:00
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
x = -1;
|
2009-10-18 00:51:48 +08:00
|
|
|
w = allocation.width + 2;
|
2006-04-12 18:53:28 +08:00
|
|
|
}
|
2004-05-05 07:12:59 +08:00
|
|
|
|
2010-12-29 23:49:38 +08:00
|
|
|
if (private->orig_height > private->height)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
2010-12-29 23:49:38 +08:00
|
|
|
y = private->display_ratio_y * (private->orig_height - private->height);
|
|
|
|
h = private->display_ratio_y * private->height;
|
2006-04-12 18:53:28 +08:00
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
y = -1;
|
2009-10-18 00:51:48 +08:00
|
|
|
h = allocation.height + 2;
|
2006-04-12 18:53:28 +08:00
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2005-05-25 19:49:54 +08:00
|
|
|
w = MAX (w, 1);
|
|
|
|
h = MAX (h, 1);
|
|
|
|
|
2010-09-12 04:39:05 +08:00
|
|
|
line_width = MIN (3, MIN (w, h));
|
|
|
|
|
|
|
|
cairo_rectangle (cr,
|
|
|
|
x + line_width / 2.0,
|
|
|
|
y + line_width / 2.0,
|
|
|
|
MAX (w - line_width, 1),
|
|
|
|
MAX (h - line_width, 1));
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, line_width);
|
|
|
|
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.6);
|
|
|
|
cairo_stroke_preserve (cr);
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, 1.0);
|
|
|
|
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.8);
|
|
|
|
cairo_stroke (cr);
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
2004-05-05 07:12:59 +08:00
|
|
|
|
|
|
|
return FALSE;
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|