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>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 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
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
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);
|
|
|
|
static gboolean gimp_offset_area_expose_event (GtkWidget *widget,
|
|
|
|
GdkEventExpose *eevent);
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (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;
|
|
|
|
widget_class->expose_event = gimp_offset_area_expose_event;
|
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
|
|
|
{
|
2004-05-05 07:12:59 +08:00
|
|
|
area->orig_width = 0;
|
|
|
|
area->orig_height = 0;
|
|
|
|
area->width = 0;
|
|
|
|
area->height = 0;
|
|
|
|
area->offset_x = 0;
|
|
|
|
area->offset_y = 0;
|
|
|
|
area->display_ratio_x = 1.0;
|
|
|
|
area->display_ratio_y = 1.0;
|
|
|
|
|
2007-07-20 20:29:38 +08:00
|
|
|
gtk_widget_add_events (GTK_WIDGET (area), GDK_BUTTON_PRESS_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
|
|
|
*
|
2001-05-07 05:51:20 +08:00
|
|
|
* Return value: the new #GimpOffsetArea widget.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_offset_area_new (gint orig_width,
|
|
|
|
gint orig_height)
|
|
|
|
{
|
2004-05-05 07:12:59 +08:00
|
|
|
GimpOffsetArea *area;
|
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);
|
|
|
|
|
|
|
|
area->orig_width = area->width = orig_width;
|
|
|
|
area->orig_height = area->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.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
|
|
|
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)
|
|
|
|
{
|
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);
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->width != width || area->height != height)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2004-11-09 08:40:25 +08:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
area->width = width;
|
|
|
|
area->height = height;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_width <= area->width)
|
|
|
|
offset_x = CLAMP (area->offset_x, 0, area->width - area->orig_width);
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2004-05-05 07:12:59 +08:00
|
|
|
offset_x = CLAMP (area->offset_x, area->width - area->orig_width, 0);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_height <= area->height)
|
|
|
|
offset_y = CLAMP (area->offset_y, 0, area->height - area->orig_height);
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2004-05-05 07:12:59 +08:00
|
|
|
offset_y = CLAMP (area->offset_y, area->height - area->orig_height, 0);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (offset_x != area->offset_x || offset_y != area->offset_y)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2004-11-09 08:40:25 +08:00
|
|
|
area->offset_x = offset_x;
|
|
|
|
area->offset_y = offset_y;
|
|
|
|
|
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)
|
|
|
|
{
|
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
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->offset_x != offset_x || area->offset_y != offset_y)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_width <= area->width)
|
|
|
|
area->offset_x = CLAMP (offset_x, 0, area->width - area->orig_width);
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2004-05-05 07:12:59 +08:00
|
|
|
area->offset_x = CLAMP (offset_x, area->width - area->orig_width, 0);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_height <= area->height)
|
|
|
|
area->offset_y = CLAMP (offset_y, 0, area->height - area->orig_height);
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2004-05-05 07:12:59 +08:00
|
|
|
area->offset_y = CLAMP (offset_y, area->height - area->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
|
|
|
{
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gdouble ratio;
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_width == 0 || area->orig_height == 0)
|
2001-05-07 05:51:20 +08:00
|
|
|
return;
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_width <= area->width)
|
|
|
|
width = area->width;
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2004-05-05 07:12:59 +08:00
|
|
|
width = area->orig_width * 2 - area->width;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_height <= area->height)
|
|
|
|
height = area->height;
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2004-05-05 07:12:59 +08:00
|
|
|
height = area->orig_height * 2 - area->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)
|
|
|
|
{
|
|
|
|
GimpOffsetArea *area = GIMP_OFFSET_AREA (widget);
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
|
|
|
|
|
|
|
area->display_ratio_x = ((gdouble) allocation->width /
|
|
|
|
((area->orig_width <= area->width) ?
|
|
|
|
area->width :
|
|
|
|
area->orig_width * 2 - area->width));
|
|
|
|
|
|
|
|
area->display_ratio_y = ((gdouble) allocation->height /
|
|
|
|
((area->orig_height <= area->height) ?
|
|
|
|
area->height :
|
|
|
|
area->orig_height * 2 - area->height));
|
|
|
|
|
|
|
|
pixbuf = g_object_get_data (G_OBJECT (area), "pixbuf");
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
{
|
|
|
|
GdkPixbuf *copy;
|
|
|
|
gint pixbuf_width;
|
|
|
|
gint pixbuf_height;
|
|
|
|
|
|
|
|
pixbuf_width = area->display_ratio_x * area->orig_width;
|
2007-08-03 21:11:00 +08:00
|
|
|
pixbuf_width = MAX (pixbuf_width, 1);
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
pixbuf_height = area->display_ratio_y * area->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);
|
|
|
|
gdk_window_set_cursor (widget->window, cursor);
|
|
|
|
gdk_cursor_unref (cursor);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
GimpOffsetArea *area = GIMP_OFFSET_AREA (widget);
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_width == 0 || area->orig_height == 0)
|
2001-05-07 05:51:20 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
gdk_pointer_grab (widget->window, FALSE,
|
2006-04-12 18:53:28 +08:00
|
|
|
(GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK),
|
|
|
|
NULL, NULL, event->button.time);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
orig_offset_x = area->offset_x;
|
|
|
|
orig_offset_y = area->offset_y;
|
2001-05-07 05:51:20 +08:00
|
|
|
start_x = event->button.x;
|
|
|
|
start_y = event->button.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_MOTION_NOTIFY:
|
2004-05-05 07:12:59 +08:00
|
|
|
offset_x = (orig_offset_x +
|
|
|
|
(event->motion.x - start_x) / area->display_ratio_x);
|
|
|
|
offset_y = (orig_offset_y +
|
|
|
|
(event->motion.y - start_y) / area->display_ratio_y);
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->offset_x != offset_x || area->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,
|
2004-05-05 07:12:59 +08:00
|
|
|
area->offset_x, area->offset_y);
|
2001-05-07 05:51:20 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_BUTTON_RELEASE:
|
2003-10-30 04:57:21 +08:00
|
|
|
gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
|
|
|
|
event->button.time);
|
2001-05-07 05:51:20 +08:00
|
|
|
start_x = start_y = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_offset_area_expose_event (GtkWidget *widget,
|
|
|
|
GdkEventExpose *eevent)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2004-05-05 07:12:59 +08:00
|
|
|
GimpOffsetArea *area = GIMP_OFFSET_AREA (widget);
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
gint w, h;
|
|
|
|
gint x, y;
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
x = (area->display_ratio_x *
|
|
|
|
((area->orig_width <= area->width) ?
|
|
|
|
area->offset_x :
|
|
|
|
area->offset_x + area->orig_width - area->width));
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
y = (area->display_ratio_y *
|
|
|
|
((area->orig_height <= area->height) ?
|
|
|
|
area->offset_y :
|
|
|
|
area->offset_y + area->orig_height - area->height));
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
w = area->display_ratio_x * area->orig_width;
|
2007-08-03 21:11:00 +08:00
|
|
|
w = MAX (w, 1);
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
h = area->display_ratio_y * area->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)
|
|
|
|
{
|
|
|
|
gdk_draw_pixbuf (widget->window, widget->style->black_gc,
|
|
|
|
pixbuf, 0, 0, x, y, w, h, GDK_RGB_DITHER_NORMAL, 0, 0);
|
|
|
|
gdk_draw_rectangle (widget->window, widget->style->black_gc, FALSE,
|
|
|
|
x, y, w - 1, h - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL,
|
|
|
|
GTK_SHADOW_OUT,
|
|
|
|
NULL, widget, NULL,
|
|
|
|
x, y, w, h);
|
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_width > area->width || area->orig_height > area->height)
|
2001-05-07 05:51:20 +08:00
|
|
|
{
|
2004-05-05 07:12:59 +08:00
|
|
|
if (area->orig_width > area->width)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
x = area->display_ratio_x * (area->orig_width - area->width);
|
|
|
|
w = area->display_ratio_x * area->width;
|
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
x = -1;
|
|
|
|
w = widget->allocation.width + 2;
|
|
|
|
}
|
2004-05-05 07:12:59 +08:00
|
|
|
|
|
|
|
if (area->orig_height > area->height)
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
y = area->display_ratio_y * (area->orig_height - area->height);
|
|
|
|
h = area->display_ratio_y * area->height;
|
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
else
|
2006-04-12 18:53:28 +08:00
|
|
|
{
|
|
|
|
y = -1;
|
|
|
|
h = widget->allocation.height + 2;
|
|
|
|
}
|
2001-05-07 05:51:20 +08:00
|
|
|
|
2005-05-25 19:49:54 +08:00
|
|
|
w = MAX (w, 1);
|
|
|
|
h = MAX (h, 1);
|
|
|
|
|
2004-05-05 07:12:59 +08:00
|
|
|
if (pixbuf)
|
|
|
|
{
|
2005-05-25 19:49:54 +08:00
|
|
|
GdkGC *gc = gdk_gc_new (widget->window);
|
|
|
|
gint line = MIN (3, MIN (w, h));
|
2004-05-05 07:12:59 +08:00
|
|
|
|
|
|
|
gdk_gc_set_function (gc, GDK_INVERT);
|
2005-05-25 19:49:54 +08:00
|
|
|
gdk_gc_set_line_attributes (gc, line,
|
2004-05-05 07:12:59 +08:00
|
|
|
GDK_LINE_SOLID, GDK_CAP_BUTT,
|
|
|
|
GDK_JOIN_ROUND);
|
|
|
|
|
|
|
|
gdk_draw_rectangle (widget->window, gc, FALSE,
|
2005-05-25 19:49:54 +08:00
|
|
|
x + line / 2,
|
|
|
|
y + line / 2,
|
|
|
|
MAX (w - line, 1),
|
|
|
|
MAX (h - line, 1));
|
2004-05-05 07:12:59 +08:00
|
|
|
|
2004-05-12 01:19:24 +08:00
|
|
|
g_object_unref (gc);
|
2004-05-05 07:12:59 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_draw_rectangle (widget->window, widget->style->black_gc, FALSE,
|
|
|
|
x, y, w, h);
|
|
|
|
}
|
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
|
|
|
}
|