2004-08-31 06:10:26 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimppreview.c
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2004-08-31 06:10:26 +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.
|
2004-08-31 06:10:26 +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/>.
|
2004-08-31 06:10:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-11-02 05:32:06 +08:00
|
|
|
#include <gegl.h>
|
2004-08-31 06:10:26 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2019-07-31 16:16:21 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2004-09-10 05:36:52 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
#include "gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "gimppreview.h"
|
|
|
|
|
|
|
|
#include "libgimp/libgimp-intl.h"
|
|
|
|
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimppreview
|
|
|
|
* @title: GimpPreview
|
|
|
|
* @short_description: A widget providing a #GimpPreviewArea plus
|
|
|
|
* framework to update the preview.
|
|
|
|
*
|
|
|
|
* A widget providing a #GimpPreviewArea plus framework to update the
|
|
|
|
* preview.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2005-09-28 10:46:06 +08:00
|
|
|
#define DEFAULT_SIZE 200
|
2004-09-01 07:37:04 +08:00
|
|
|
#define PREVIEW_TIMEOUT 200
|
|
|
|
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
enum
|
|
|
|
{
|
2004-08-31 22:29:25 +08:00
|
|
|
INVALIDATED,
|
2004-08-31 06:10:26 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2004-09-01 22:01:10 +08:00
|
|
|
PROP_UPDATE
|
2004-08-31 06:10:26 +08:00
|
|
|
};
|
|
|
|
|
2018-05-03 18:51:36 +08:00
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
typedef struct _GimpPreviewPrivate
|
2005-09-28 10:46:06 +08:00
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *area;
|
2018-05-08 18:29:01 +08:00
|
|
|
GtkWidget *grid;
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *toggle;
|
2005-09-28 19:02:02 +08:00
|
|
|
GtkWidget *controls;
|
2018-05-04 15:46:37 +08:00
|
|
|
GdkCursor *cursor_busy;
|
|
|
|
GdkCursor *default_cursor;
|
|
|
|
|
|
|
|
gint xoff, yoff;
|
|
|
|
gint xmin, xmax, ymin, ymax;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
gboolean update_preview;
|
|
|
|
guint timeout_id;
|
2024-08-02 22:02:30 +08:00
|
|
|
} GimpPreviewPrivate;
|
2005-09-28 10:46:06 +08:00
|
|
|
|
2004-08-31 23:13:31 +08:00
|
|
|
|
2004-09-10 05:36:52 +08:00
|
|
|
static void gimp_preview_dispose (GObject *object);
|
|
|
|
static void gimp_preview_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_preview_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_preview_direction_changed (GtkWidget *widget,
|
|
|
|
GtkTextDirection prev_dir);
|
|
|
|
static gboolean gimp_preview_popup_menu (GtkWidget *widget);
|
|
|
|
|
|
|
|
static void gimp_preview_area_realize (GtkWidget *widget,
|
|
|
|
GimpPreview *preview);
|
|
|
|
static void gimp_preview_area_unrealize (GtkWidget *widget,
|
|
|
|
GimpPreview *preview);
|
|
|
|
static void gimp_preview_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpPreview *preview);
|
2006-02-06 19:07:48 +08:00
|
|
|
static void gimp_preview_area_set_cursor (GimpPreview *preview);
|
2004-09-10 05:36:52 +08:00
|
|
|
static gboolean gimp_preview_area_event (GtkWidget *area,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpPreview *preview);
|
|
|
|
|
|
|
|
static void gimp_preview_toggle_callback (GtkWidget *toggle,
|
|
|
|
GimpPreview *preview);
|
|
|
|
|
|
|
|
static void gimp_preview_notify_checks (GimpPreview *preview);
|
|
|
|
|
|
|
|
static gboolean gimp_preview_invalidate_now (GimpPreview *preview);
|
2006-02-06 19:07:48 +08:00
|
|
|
static void gimp_preview_real_set_cursor (GimpPreview *preview);
|
2007-01-12 07:41:45 +08:00
|
|
|
static void gimp_preview_real_transform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y);
|
|
|
|
static void gimp_preview_real_untransform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y);
|
2004-09-02 18:23:52 +08:00
|
|
|
|
2004-08-31 06:10:26 +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_ABSTRACT_TYPE_WITH_PRIVATE (GimpPreview, gimp_preview, GTK_TYPE_BOX)
|
2018-05-03 18:51:36 +08:00
|
|
|
|
2018-05-28 23:24:58 +08:00
|
|
|
#define parent_class gimp_preview_parent_class
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2018-05-28 23:24:58 +08:00
|
|
|
static guint preview_signals[LAST_SIGNAL] = { 0 };
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_class_init (GimpPreviewClass *klass)
|
|
|
|
{
|
2004-09-01 22:01:10 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
preview_signals[INVALIDATED] =
|
|
|
|
g_signal_new ("invalidated",
|
2004-09-04 07:32:35 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpPreviewClass, invalidated),
|
2020-01-12 18:06:05 +08:00
|
|
|
NULL, NULL, NULL,
|
2004-09-04 07:32:35 +08:00
|
|
|
G_TYPE_NONE, 0);
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-09 23:27:34 +08:00
|
|
|
object_class->dispose = gimp_preview_dispose;
|
|
|
|
object_class->get_property = gimp_preview_get_property;
|
|
|
|
object_class->set_property = gimp_preview_set_property;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-09 23:27:34 +08:00
|
|
|
widget_class->direction_changed = gimp_preview_direction_changed;
|
|
|
|
widget_class->popup_menu = gimp_preview_popup_menu;
|
2004-09-04 07:41:39 +08:00
|
|
|
|
2004-09-09 23:27:34 +08:00
|
|
|
klass->draw = NULL;
|
2004-09-29 21:39:23 +08:00
|
|
|
klass->draw_thumb = NULL;
|
2004-09-29 23:33:02 +08:00
|
|
|
klass->draw_buffer = NULL;
|
2006-02-06 19:07:48 +08:00
|
|
|
klass->set_cursor = gimp_preview_real_set_cursor;
|
2007-01-12 07:41:45 +08:00
|
|
|
klass->transform = gimp_preview_real_transform;
|
|
|
|
klass->untransform = gimp_preview_real_untransform;
|
2004-09-04 07:41:39 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
g_object_class_install_property (object_class,
|
2004-08-31 22:29:25 +08:00
|
|
|
PROP_UPDATE,
|
|
|
|
g_param_spec_boolean ("update",
|
2017-06-07 03:19:17 +08:00
|
|
|
"Update",
|
|
|
|
"Whether the preview should update automatically",
|
2004-08-31 06:10:26 +08:00
|
|
|
TRUE,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-08-31 06:10:26 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
2004-09-01 22:01:10 +08:00
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
|
|
|
g_param_spec_int ("size",
|
2017-06-07 03:19:17 +08:00
|
|
|
"Size",
|
|
|
|
"The preview's size",
|
2004-09-01 22:01:10 +08:00
|
|
|
1, 1024,
|
|
|
|
DEFAULT_SIZE,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READABLE));
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_init (GimpPreview *preview)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
2005-09-28 10:46:06 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
gdouble xalign = 0.0;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2018-05-03 18:51:36 +08:00
|
|
|
|
2011-07-28 01:53:34 +08:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (preview),
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
2004-09-09 22:47:39 +08:00
|
|
|
gtk_box_set_homogeneous (GTK_BOX (preview), FALSE);
|
|
|
|
gtk_box_set_spacing (GTK_BOX (preview), 6);
|
|
|
|
|
2004-09-09 23:27:34 +08:00
|
|
|
if (gtk_widget_get_direction (GTK_WIDGET (preview)) == GTK_TEXT_DIR_RTL)
|
|
|
|
xalign = 1.0;
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->frame = gtk_aspect_frame_new (NULL, xalign, 0.0, 1.0, TRUE);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), GTK_SHADOW_NONE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (preview), priv->frame, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (priv->frame);
|
2004-09-09 22:47:39 +08:00
|
|
|
|
2018-05-08 18:29:01 +08:00
|
|
|
priv->grid = gtk_grid_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->frame), priv->grid);
|
|
|
|
gtk_widget_show (priv->grid);
|
2004-09-01 03:58:25 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->timeout_id = 0;
|
2004-10-14 02:56:28 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->xmin = priv->ymin = 0;
|
|
|
|
priv->xmax = priv->ymax = 1;
|
|
|
|
priv->width = priv->xmax - priv->xmin;
|
|
|
|
priv->height = priv->ymax - priv->ymin;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->xoff = 0;
|
|
|
|
priv->yoff = 0;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->default_cursor = NULL;
|
2004-09-29 21:39:23 +08:00
|
|
|
|
2004-09-10 05:36:52 +08:00
|
|
|
/* preview area */
|
2004-08-31 06:10:26 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2018-05-08 18:29:01 +08:00
|
|
|
gtk_widget_set_hexpand (frame, TRUE);
|
|
|
|
gtk_widget_set_vexpand (frame, TRUE);
|
|
|
|
gtk_grid_attach (GTK_GRID (priv->grid), frame, 0, 0, 1, 1);
|
2004-08-31 06:10:26 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->area = gimp_preview_area_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), priv->area);
|
|
|
|
gtk_widget_show (priv->area);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect_swapped (priv->area, "notify::check-size",
|
2004-09-04 03:34:59 +08:00
|
|
|
G_CALLBACK (gimp_preview_notify_checks),
|
|
|
|
preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect_swapped (priv->area, "notify::check-type",
|
2004-09-04 03:34:59 +08:00
|
|
|
G_CALLBACK (gimp_preview_notify_checks),
|
|
|
|
preview);
|
2020-05-25 04:26:50 +08:00
|
|
|
g_signal_connect_swapped (priv->area, "notify::check-custom-color1",
|
|
|
|
G_CALLBACK (gimp_preview_notify_checks),
|
|
|
|
preview);
|
|
|
|
g_signal_connect_swapped (priv->area, "notify::check-custom-color2",
|
|
|
|
G_CALLBACK (gimp_preview_notify_checks),
|
|
|
|
preview);
|
2004-09-04 03:34:59 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gtk_widget_add_events (priv->area,
|
2004-09-01 02:06:36 +08:00
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
2018-05-11 05:23:39 +08:00
|
|
|
GDK_SCROLL_MASK |
|
2018-05-11 08:08:51 +08:00
|
|
|
GDK_SMOOTH_SCROLL_MASK |
|
2004-08-31 06:10:26 +08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON_MOTION_MASK);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect (priv->area, "event",
|
2004-08-31 23:13:31 +08:00
|
|
|
G_CALLBACK (gimp_preview_area_event),
|
|
|
|
preview);
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect (priv->area, "realize",
|
2004-08-31 23:13:31 +08:00
|
|
|
G_CALLBACK (gimp_preview_area_realize),
|
2004-09-01 10:10:40 +08:00
|
|
|
preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect (priv->area, "unrealize",
|
2004-09-01 10:10:40 +08:00
|
|
|
G_CALLBACK (gimp_preview_area_unrealize),
|
|
|
|
preview);
|
2004-08-31 23:13:31 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect_data (priv->area, "realize",
|
2006-02-06 19:07:48 +08:00
|
|
|
G_CALLBACK (gimp_preview_area_set_cursor),
|
|
|
|
preview, NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect (priv->area, "size-allocate",
|
2004-09-01 03:58:25 +08:00
|
|
|
G_CALLBACK (gimp_preview_area_size_allocate),
|
|
|
|
preview);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect_data (priv->area, "size-allocate",
|
2006-02-06 19:07:48 +08:00
|
|
|
G_CALLBACK (gimp_preview_area_set_cursor),
|
|
|
|
preview, NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
|
|
|
|
|
2011-09-30 16:50:50 +08:00
|
|
|
priv->controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2018-05-08 18:29:01 +08:00
|
|
|
gtk_widget_set_margin_top (priv->controls, 3);
|
|
|
|
gtk_grid_attach (GTK_GRID (priv->grid), priv->controls, 0, 2, 2, 1);
|
2005-09-28 19:02:02 +08:00
|
|
|
gtk_widget_show (priv->controls);
|
2005-09-28 10:46:06 +08:00
|
|
|
|
2007-09-21 20:19:00 +08:00
|
|
|
/* toggle button to (de)activate the instant preview */
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->toggle = gtk_check_button_new_with_mnemonic (_("_Preview"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->toggle),
|
|
|
|
priv->update_preview);
|
|
|
|
gtk_box_pack_start (GTK_BOX (priv->controls), priv->toggle, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (priv->toggle);
|
2004-09-01 20:10:09 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect (priv->toggle, "toggled",
|
2004-09-01 20:10:09 +08:00
|
|
|
G_CALLBACK (gimp_preview_toggle_callback),
|
|
|
|
preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
2004-09-01 07:37:04 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_dispose (GObject *object)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2004-09-01 07:37:04 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
if (priv->timeout_id)
|
2004-09-01 07:37:04 +08:00
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
g_source_remove (priv->timeout_id);
|
|
|
|
priv->timeout_id = 0;
|
2004-09-01 07:37:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_get_property (GObject *object,
|
2004-09-01 02:06:36 +08:00
|
|
|
guint property_id,
|
2004-08-31 06:10:26 +08:00
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-01 02:06:36 +08:00
|
|
|
switch (property_id)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-08-31 22:29:25 +08:00
|
|
|
case PROP_UPDATE:
|
2018-05-04 15:46:37 +08:00
|
|
|
g_value_set_boolean (value, priv->update_preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
break;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
default:
|
2004-09-01 02:06:36 +08:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2004-08-31 06:10:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_set_property (GObject *object,
|
2004-09-01 02:06:36 +08:00
|
|
|
guint property_id,
|
2004-08-31 06:10:26 +08:00
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-09-01 02:06:36 +08:00
|
|
|
switch (property_id)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2004-08-31 22:29:25 +08:00
|
|
|
case PROP_UPDATE:
|
2018-05-04 15:46:37 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->toggle),
|
2004-08-31 06:10:26 +08:00
|
|
|
g_value_get_boolean (value));
|
|
|
|
break;
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
default:
|
2004-09-01 02:06:36 +08:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2004-08-31 06:10:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-09 23:27:34 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_direction_changed (GtkWidget *widget,
|
|
|
|
GtkTextDirection prev_dir)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (widget);
|
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
gdouble xalign = 0.0;
|
2004-09-09 23:27:34 +08:00
|
|
|
|
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
|
|
|
xalign = 1.0;
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gtk_aspect_frame_set (GTK_ASPECT_FRAME (priv->frame),
|
2004-09-09 23:27:34 +08:00
|
|
|
xalign, 0.0, 1.0, TRUE);
|
|
|
|
}
|
|
|
|
|
2004-09-04 07:41:39 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_preview_popup_menu (GtkWidget *widget)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (widget);
|
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2004-09-04 07:41:39 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_area_menu_popup (GIMP_PREVIEW_AREA (priv->area), NULL);
|
2004-09-04 07:41:39 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
static void
|
2004-09-01 10:10:40 +08:00
|
|
|
gimp_preview_area_realize (GtkWidget *widget,
|
|
|
|
GimpPreview *preview)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
GdkDisplay *display = gtk_widget_get_display (widget);
|
2004-08-31 23:13:31 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_return_if_fail (priv->cursor_busy == NULL);
|
2004-09-01 10:10:40 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->cursor_busy = gdk_cursor_new_for_display (display, GDK_WATCH);
|
2004-08-31 23:13:31 +08:00
|
|
|
|
2004-09-01 10:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_area_unrealize (GtkWidget *widget,
|
|
|
|
GimpPreview *preview)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
g_clear_object (&priv->cursor_busy);
|
2004-08-31 23:13:31 +08:00
|
|
|
}
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2004-08-31 23:13:31 +08:00
|
|
|
static void
|
2004-09-01 03:58:25 +08:00
|
|
|
gimp_preview_area_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpPreview *preview)
|
2004-08-31 23:13:31 +08:00
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
gint width = priv->xmax - priv->xmin;
|
|
|
|
gint height = priv->ymax - priv->ymin;
|
2004-09-01 03:58:25 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->width = MIN (width, allocation->width);
|
|
|
|
priv->height = MIN (height, allocation->height);
|
2004-09-01 03:58:25 +08:00
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
gimp_preview_draw (preview);
|
|
|
|
gimp_preview_invalidate (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
2006-02-06 19:07:48 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_area_set_cursor (GimpPreview *preview)
|
|
|
|
{
|
|
|
|
GIMP_PREVIEW_GET_CLASS (preview)->set_cursor (preview);
|
|
|
|
}
|
2004-08-31 06:10:26 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_preview_area_event (GtkWidget *area,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpPreview *preview)
|
|
|
|
{
|
2004-09-04 00:52:26 +08:00
|
|
|
GdkEventButton *button_event = (GdkEventButton *) event;
|
2004-08-31 06:10:26 +08:00
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
2004-09-04 03:34:59 +08:00
|
|
|
switch (button_event->button)
|
2004-09-04 00:52:26 +08:00
|
|
|
{
|
2004-09-04 03:34:59 +08:00
|
|
|
case 3:
|
2004-09-04 07:41:39 +08:00
|
|
|
gimp_preview_area_menu_popup (GIMP_PREVIEW_AREA (area), button_event);
|
|
|
|
return TRUE;
|
2004-09-04 00:52:26 +08:00
|
|
|
}
|
2004-08-31 06:10:26 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_toggle_callback (GtkWidget *toggle,
|
|
|
|
GimpPreview *preview)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle)))
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->update_preview = TRUE;
|
2004-09-02 18:23:52 +08:00
|
|
|
|
2004-11-29 20:15:19 +08:00
|
|
|
g_object_notify (G_OBJECT (preview), "update");
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
if (priv->timeout_id)
|
|
|
|
g_source_remove (priv->timeout_id);
|
2004-09-02 18:23:52 +08:00
|
|
|
|
|
|
|
gimp_preview_invalidate_now (preview);
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
else
|
2004-08-31 06:49:06 +08:00
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->update_preview = FALSE;
|
2004-09-02 18:23:52 +08:00
|
|
|
|
2004-11-29 20:15:19 +08:00
|
|
|
g_object_notify (G_OBJECT (preview), "update");
|
|
|
|
|
2004-09-01 20:10:09 +08:00
|
|
|
gimp_preview_draw (preview);
|
2004-08-31 06:49:06 +08:00
|
|
|
}
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
2004-09-04 03:34:59 +08:00
|
|
|
static void
|
|
|
|
gimp_preview_notify_checks (GimpPreview *preview)
|
|
|
|
{
|
|
|
|
gimp_preview_draw (preview);
|
|
|
|
gimp_preview_invalidate (preview);
|
|
|
|
}
|
|
|
|
|
2004-09-01 07:37:04 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_preview_invalidate_now (GimpPreview *preview)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (preview));
|
|
|
|
GimpPreviewClass *class = GIMP_PREVIEW_GET_CLASS (preview);
|
2004-09-29 07:23:09 +08:00
|
|
|
|
2007-09-21 20:19:00 +08:00
|
|
|
gimp_preview_draw (preview);
|
2004-09-01 20:10:09 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->timeout_id = 0;
|
2004-09-01 07:37:04 +08:00
|
|
|
|
2010-04-20 01:21:07 +08:00
|
|
|
if (toplevel && gtk_widget_get_realized (toplevel))
|
2004-09-01 20:10:09 +08:00
|
|
|
{
|
2009-03-22 23:42:42 +08:00
|
|
|
gdk_window_set_cursor (gtk_widget_get_window (toplevel),
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->cursor_busy);
|
|
|
|
gdk_window_set_cursor (gtk_widget_get_window (priv->area),
|
|
|
|
priv->cursor_busy);
|
2004-09-01 20:10:09 +08:00
|
|
|
|
2018-05-08 06:54:02 +08:00
|
|
|
gdk_display_flush (gtk_widget_get_display (toplevel));
|
2004-09-01 20:10:09 +08:00
|
|
|
|
|
|
|
g_signal_emit (preview, preview_signals[INVALIDATED], 0);
|
|
|
|
|
2004-09-29 07:23:09 +08:00
|
|
|
class->set_cursor (preview);
|
2009-03-22 23:42:42 +08:00
|
|
|
gdk_window_set_cursor (gtk_widget_get_window (toplevel), NULL);
|
2004-09-01 20:10:09 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_signal_emit (preview, preview_signals[INVALIDATED], 0);
|
|
|
|
}
|
2004-09-01 07:37:04 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-09-29 07:23:09 +08:00
|
|
|
static void
|
2006-02-06 19:07:48 +08:00
|
|
|
gimp_preview_real_set_cursor (GimpPreview *preview)
|
2004-09-29 07:23:09 +08:00
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
if (gtk_widget_get_realized (priv->area))
|
|
|
|
gdk_window_set_cursor (gtk_widget_get_window (priv->area),
|
|
|
|
priv->default_cursor);
|
2007-01-12 07:41:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_real_transform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
*dest_x = src_x - priv->xoff - priv->xmin;
|
|
|
|
*dest_y = src_y - priv->yoff - priv->ymin;
|
2007-01-12 07:41:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_real_untransform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
*dest_x = src_x + priv->xoff + priv->xmin;
|
|
|
|
*dest_y = src_y + priv->yoff + priv->ymin;
|
2004-09-29 07:23:09 +08:00
|
|
|
}
|
|
|
|
|
2004-09-01 22:01:10 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_set_update:
|
|
|
|
* @preview: a #GimpPreview widget
|
2004-09-02 18:23:52 +08:00
|
|
|
* @update: %TRUE if the preview should invalidate itself when being
|
|
|
|
* scrolled or when gimp_preview_invalidate() is being called
|
|
|
|
*
|
|
|
|
* Sets the state of the "Preview" check button.
|
2004-09-01 22:01:10 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-01 22:01:10 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_set_update (GimpPreview *preview,
|
|
|
|
gboolean update)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
|
|
|
g_object_set (preview,
|
|
|
|
"update", update,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_preview_get_update:
|
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the state of the "Preview" check button.
|
2004-09-01 22:01:10 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-01 22:01:10 +08:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_preview_get_update (GimpPreview *preview)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2004-09-01 22:01:10 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), FALSE);
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
|
|
|
|
|
|
|
return priv->update_preview;
|
2004-09-01 22:01:10 +08:00
|
|
|
}
|
|
|
|
|
2004-09-09 22:47:39 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_set_bounds:
|
|
|
|
* @preview: a #GimpPreview widget
|
2010-07-06 01:04:15 +08:00
|
|
|
* @xmin: the minimum X value
|
|
|
|
* @ymin: the minimum Y value
|
|
|
|
* @xmax: the maximum X value
|
|
|
|
* @ymax: the maximum Y value
|
2004-09-09 22:47:39 +08:00
|
|
|
*
|
2004-09-10 06:36:15 +08:00
|
|
|
* Sets the lower and upper limits for the previewed area. The
|
|
|
|
* difference between the upper and lower value is used to set the
|
|
|
|
* maximum size of the #GimpPreviewArea used in the @preview.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-09 22:47:39 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_set_bounds (GimpPreview *preview,
|
|
|
|
gint xmin,
|
|
|
|
gint ymin,
|
|
|
|
gint xmax,
|
|
|
|
gint ymax)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2004-09-09 22:47:39 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
g_return_if_fail (xmax > xmin);
|
|
|
|
g_return_if_fail (ymax > ymin);
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2004-09-09 22:47:39 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->xmin = xmin;
|
|
|
|
priv->ymin = ymin;
|
|
|
|
priv->xmax = xmax;
|
|
|
|
priv->ymax = ymax;
|
|
|
|
|
|
|
|
gimp_preview_area_set_max_size (GIMP_PREVIEW_AREA (priv->area),
|
2004-09-09 22:47:39 +08:00
|
|
|
xmax - xmin,
|
|
|
|
ymax - ymin);
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:11:14 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_get_bounds:
|
|
|
|
* @preview: A #GimpPreview:
|
|
|
|
* @xmin: (out) (optional): Lower bound for x
|
|
|
|
* @ymin: (out) (optional): Lower bound for y
|
|
|
|
* @xmax: (out) (optional): Higher bound for x
|
|
|
|
* @ymax: (out) (optional): Higher bound for y
|
|
|
|
*/
|
2018-05-04 15:46:37 +08:00
|
|
|
void
|
|
|
|
gimp_preview_get_bounds (GimpPreview *preview,
|
|
|
|
gint *xmin,
|
|
|
|
gint *ymin,
|
|
|
|
gint *xmax,
|
|
|
|
gint *ymax)
|
|
|
|
{
|
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
if (xmin) *xmin = priv->xmin;
|
|
|
|
if (ymin) *ymin = priv->ymin;
|
|
|
|
if (xmax) *xmax = priv->xmax;
|
|
|
|
if (ymax) *ymax = priv->ymax;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_preview_set_size (GimpPreview *preview,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
priv->width = width;
|
|
|
|
priv->height = height;
|
|
|
|
|
|
|
|
gtk_widget_set_size_request (priv->area, width, height);
|
|
|
|
}
|
|
|
|
|
2004-08-31 06:10:26 +08:00
|
|
|
/**
|
2004-08-31 22:29:25 +08:00
|
|
|
* gimp_preview_get_size:
|
2004-08-31 06:49:06 +08:00
|
|
|
* @preview: a #GimpPreview widget
|
2020-05-03 23:57:23 +08:00
|
|
|
* @width: (out) (optional): return location for the preview area width
|
|
|
|
* @height: (out) (optional): return location for the preview area height
|
2004-08-31 06:49:06 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-08-31 06:10:26 +08:00
|
|
|
**/
|
2004-08-31 22:29:25 +08:00
|
|
|
void
|
|
|
|
gimp_preview_get_size (GimpPreview *preview,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
2004-08-31 06:10:26 +08:00
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
if (width) *width = priv->width;
|
|
|
|
if (height) *height = priv->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_preview_set_offsets (GimpPreview *preview,
|
|
|
|
gint xoff,
|
|
|
|
gint yoff)
|
|
|
|
{
|
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
priv->xoff = xoff;
|
|
|
|
priv->yoff = yoff;
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:11:14 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_get_offsets:
|
|
|
|
* @preview: A #GimpPreview:
|
|
|
|
* @xoff: (out) (optional): X offset
|
|
|
|
* @yoff: (out) (optional): Y offset
|
|
|
|
*/
|
2018-05-04 15:46:37 +08:00
|
|
|
void
|
|
|
|
gimp_preview_get_offsets (GimpPreview *preview,
|
|
|
|
gint *xoff,
|
|
|
|
gint *yoff)
|
|
|
|
{
|
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
2004-08-31 06:10:26 +08:00
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2004-08-31 06:49:06 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
if (xoff) *xoff = priv->xoff;
|
|
|
|
if (yoff) *yoff = priv->yoff;
|
2004-08-31 06:10:26 +08:00
|
|
|
}
|
|
|
|
|
2004-09-29 21:39:23 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_get_position:
|
|
|
|
* @preview: a #GimpPreview widget
|
2020-05-03 23:57:23 +08:00
|
|
|
* @x: (out) (optional): return location for the horizontal offset
|
|
|
|
* @y: (out) (optional): return location for the vertical offset
|
2004-09-29 21:39:23 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-29 21:39:23 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_get_position (GimpPreview *preview,
|
|
|
|
gint *x,
|
|
|
|
gint *y)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2004-09-29 21:39:23 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2004-09-29 21:39:23 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
if (x) *x = priv->xoff + priv->xmin;
|
|
|
|
if (y) *y = priv->yoff + priv->ymin;
|
2004-09-29 21:39:23 +08:00
|
|
|
}
|
|
|
|
|
2007-01-12 07:41:45 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_transform:
|
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
* @src_x: horizontal position on the previewed image
|
|
|
|
* @src_y: vertical position on the previewed image
|
2020-05-08 23:11:14 +08:00
|
|
|
* @dest_x: (out): returns the transformed horizontal position
|
|
|
|
* @dest_y: (out): returns the transformed vertical position
|
2007-01-12 07:41:45 +08:00
|
|
|
*
|
|
|
|
* Transforms from image to widget coordinates.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2007-01-12 07:41:45 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_transform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
g_return_if_fail (dest_x != NULL && dest_y != NULL);
|
|
|
|
|
|
|
|
GIMP_PREVIEW_GET_CLASS (preview)->transform (preview,
|
|
|
|
src_x, src_y, dest_x, dest_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_preview_untransform:
|
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
* @src_x: horizontal position relative to the preview area's origin
|
|
|
|
* @src_y: vertical position relative to preview area's origin
|
2020-05-08 23:11:14 +08:00
|
|
|
* @dest_x: (out): returns the untransformed horizontal position
|
|
|
|
* @dest_y: (out): returns the untransformed vertical position
|
2007-01-12 07:41:45 +08:00
|
|
|
*
|
|
|
|
* Transforms from widget to image coordinates.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2007-01-12 07:41:45 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_untransform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
g_return_if_fail (dest_x != NULL && dest_y != NULL);
|
|
|
|
|
|
|
|
GIMP_PREVIEW_GET_CLASS (preview)->untransform (preview,
|
|
|
|
src_x, src_y, dest_x, dest_y);
|
|
|
|
}
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_get_frame:
|
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
*
|
GIR: Try to return more specific GtkWidget subclass
In GTK, a common scheme is to let a function creating a specific widget
to return a `GtkWidget *`, rather than the specific subtype, since you
often need to call API of GtkWidget, avoiding some useless casts.
For bindings however (and especially bindings to compiled languages),
this is a bit annoying, as you have to explicitly change the type of the
return value (downcast), which is not trivial (or at least desirable) in
each language.
Luckily, we can use `(type ...)` annotation for this use case, leaving
the C API unchanged, while improving the experience for bindings.
2020-12-25 22:05:16 +08:00
|
|
|
* Returns: (transfer none) (type GtkAspectFrame): a pointer to the
|
|
|
|
* #GtkAspectFrame used in the @preview.
|
2018-05-04 15:46:37 +08:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_preview_get_frame (GimpPreview *preview)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
|
|
|
|
|
|
|
return priv->frame;
|
2018-05-04 15:46:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-08 18:29:01 +08:00
|
|
|
* gimp_preview_get_grid:
|
2018-05-04 15:46:37 +08:00
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
*
|
GIR: Try to return more specific GtkWidget subclass
In GTK, a common scheme is to let a function creating a specific widget
to return a `GtkWidget *`, rather than the specific subtype, since you
often need to call API of GtkWidget, avoiding some useless casts.
For bindings however (and especially bindings to compiled languages),
this is a bit annoying, as you have to explicitly change the type of the
return value (downcast), which is not trivial (or at least desirable) in
each language.
Luckily, we can use `(type ...)` annotation for this use case, leaving
the C API unchanged, while improving the experience for bindings.
2020-12-25 22:05:16 +08:00
|
|
|
* Returns: (transfer none) (type GtkGrid): a pointer to
|
|
|
|
* the #GtkGrid used in the @preview.
|
2018-05-04 15:46:37 +08:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
2018-05-08 18:29:01 +08:00
|
|
|
gimp_preview_get_grid (GimpPreview *preview)
|
2018-05-04 15:46:37 +08:00
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
|
|
|
|
|
|
|
return priv->grid;
|
2018-05-04 15:46:37 +08:00
|
|
|
}
|
|
|
|
|
2005-07-21 22:02:29 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_get_area:
|
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
*
|
|
|
|
* In most cases, you shouldn't need to access the #GimpPreviewArea
|
|
|
|
* that is being used in the @preview. Sometimes however, you need to.
|
|
|
|
* For example if you want to receive mouse events from the area. In
|
|
|
|
* such cases, use gimp_preview_get_area().
|
|
|
|
*
|
GIR: Try to return more specific GtkWidget subclass
In GTK, a common scheme is to let a function creating a specific widget
to return a `GtkWidget *`, rather than the specific subtype, since you
often need to call API of GtkWidget, avoiding some useless casts.
For bindings however (and especially bindings to compiled languages),
this is a bit annoying, as you have to explicitly change the type of the
return value (downcast), which is not trivial (or at least desirable) in
each language.
Luckily, we can use `(type ...)` annotation for this use case, leaving
the C API unchanged, while improving the experience for bindings.
2020-12-25 22:05:16 +08:00
|
|
|
* Returns: (transfer none) (type GimpPreviewArea): a pointer to the
|
|
|
|
* #GimpPreviewArea used in the @preview.
|
2005-07-21 22:02:29 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-07-21 22:02:29 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_preview_get_area (GimpPreview *preview)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2005-07-21 22:02:29 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
|
|
|
|
|
|
|
return priv->area;
|
2005-07-21 22:02:29 +08:00
|
|
|
}
|
|
|
|
|
2004-10-14 02:56:28 +08:00
|
|
|
/**
|
2004-09-02 18:23:52 +08:00
|
|
|
* gimp_preview_draw:
|
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
*
|
|
|
|
* Calls the GimpPreview::draw method. GimpPreview itself doesn't
|
2023-07-22 03:35:23 +08:00
|
|
|
* implement a default draw method so the behavior is determined by
|
2004-09-02 18:23:52 +08:00
|
|
|
* the derived class implementing this method.
|
|
|
|
*
|
|
|
|
* #GimpDrawablePreview implements gimp_preview_draw() by drawing the
|
|
|
|
* original, unmodified drawable to the @preview.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-02 18:23:52 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_draw (GimpPreview *preview)
|
|
|
|
{
|
|
|
|
GimpPreviewClass *class = GIMP_PREVIEW_GET_CLASS (preview);
|
|
|
|
|
|
|
|
if (class->draw)
|
|
|
|
class->draw (preview);
|
|
|
|
}
|
|
|
|
|
2004-10-14 02:56:28 +08:00
|
|
|
/**
|
2004-09-29 23:33:02 +08:00
|
|
|
* gimp_preview_draw_buffer:
|
|
|
|
* @preview: a #GimpPreview widget
|
2020-05-08 23:11:14 +08:00
|
|
|
* @buffer: (array): a pixel buffer the size of the preview
|
2004-09-29 23:33:02 +08:00
|
|
|
* @rowstride: the @buffer's rowstride
|
|
|
|
*
|
|
|
|
* Calls the GimpPreview::draw_buffer method. GimpPreview itself
|
2023-07-22 03:35:23 +08:00
|
|
|
* doesn't implement this method so the behavior is determined by the
|
2004-09-29 23:33:02 +08:00
|
|
|
* derived class implementing this method.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-09-29 23:33:02 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_draw_buffer (GimpPreview *preview,
|
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride)
|
|
|
|
{
|
|
|
|
GimpPreviewClass *class = GIMP_PREVIEW_GET_CLASS (preview);
|
|
|
|
|
|
|
|
if (class->draw_buffer)
|
|
|
|
class->draw_buffer (preview, buffer, rowstride);
|
|
|
|
}
|
|
|
|
|
2004-10-14 02:56:28 +08:00
|
|
|
/**
|
2004-08-31 22:29:25 +08:00
|
|
|
* gimp_preview_invalidate:
|
2004-08-31 23:13:31 +08:00
|
|
|
* @preview: a #GimpPreview widget
|
2004-08-31 22:29:25 +08:00
|
|
|
*
|
2004-09-02 18:23:52 +08:00
|
|
|
* This function starts or renews a short low-priority timeout. When
|
|
|
|
* the timeout expires, the GimpPreview::invalidated signal is emitted
|
|
|
|
* which will usually cause the @preview to be updated.
|
|
|
|
*
|
|
|
|
* This function does nothing unless the "Preview" button is checked.
|
|
|
|
*
|
|
|
|
* During the emission of the signal a busy cursor is set on the
|
|
|
|
* toplevel window containing the @preview and on the preview area
|
|
|
|
* itself.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-08-31 22:29:25 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_invalidate (GimpPreview *preview)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2004-08-31 22:29:25 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
|
|
|
if (priv->update_preview)
|
2004-09-01 07:37:04 +08:00
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
if (priv->timeout_id)
|
|
|
|
g_source_remove (priv->timeout_id);
|
2004-08-31 22:29:25 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
priv->timeout_id =
|
2004-09-01 07:37:04 +08:00
|
|
|
g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, PREVIEW_TIMEOUT,
|
|
|
|
(GSourceFunc) gimp_preview_invalidate_now,
|
|
|
|
preview, NULL);
|
|
|
|
}
|
|
|
|
}
|
2004-10-14 02:56:28 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_preview_set_default_cursor:
|
|
|
|
* @preview: a #GimpPreview widget
|
2004-10-14 03:06:40 +08:00
|
|
|
* @cursor: a #GdkCursor or %NULL
|
|
|
|
*
|
|
|
|
* Sets the default mouse cursor for the preview. Note that this will
|
2018-04-19 02:57:03 +08:00
|
|
|
* be overridden by a %GDK_FLEUR if the preview has scrollbars, or by a
|
2004-10-14 03:06:40 +08:00
|
|
|
* %GDK_WATCH when the preview is invalidated.
|
2004-10-14 02:56:28 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-10-14 02:56:28 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_preview_set_default_cursor (GimpPreview *preview,
|
|
|
|
GdkCursor *cursor)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2004-10-14 02:56:28 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PREVIEW (preview));
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
|
2018-06-01 18:59:52 +08:00
|
|
|
g_set_object (&priv->default_cursor, cursor);
|
2018-05-04 15:46:37 +08:00
|
|
|
}
|
|
|
|
|
2019-08-09 18:59:41 +08:00
|
|
|
/**
|
|
|
|
* gimp_preview_get_default_cursor:
|
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
*
|
|
|
|
* See gimp_preview_set_default_cursor():
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): The @preview's default #GdkCursor.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
2018-05-04 15:46:37 +08:00
|
|
|
GdkCursor *
|
|
|
|
gimp_preview_get_default_cursor (GimpPreview *preview)
|
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
|
2004-10-14 02:56:28 +08:00
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
|
|
|
|
|
|
|
return priv->default_cursor;
|
2004-10-14 02:56:28 +08:00
|
|
|
}
|
|
|
|
|
2005-09-28 10:46:06 +08:00
|
|
|
/**
|
2005-09-28 19:02:02 +08:00
|
|
|
* gimp_preview_get_controls:
|
2005-09-28 10:46:06 +08:00
|
|
|
* @preview: a #GimpPreview widget
|
|
|
|
*
|
GIR: Try to return more specific GtkWidget subclass
In GTK, a common scheme is to let a function creating a specific widget
to return a `GtkWidget *`, rather than the specific subtype, since you
often need to call API of GtkWidget, avoiding some useless casts.
For bindings however (and especially bindings to compiled languages),
this is a bit annoying, as you have to explicitly change the type of the
return value (downcast), which is not trivial (or at least desirable) in
each language.
Luckily, we can use `(type ...)` annotation for this use case, leaving
the C API unchanged, while improving the experience for bindings.
2020-12-25 22:05:16 +08:00
|
|
|
* Gives access to the horizontal #GtkBox at the bottom of the preview
|
|
|
|
* that contains the update toggle. Derived widgets can use this function
|
2005-09-28 10:46:06 +08:00
|
|
|
* if they need to add controls to this area.
|
|
|
|
*
|
GIR: Try to return more specific GtkWidget subclass
In GTK, a common scheme is to let a function creating a specific widget
to return a `GtkWidget *`, rather than the specific subtype, since you
often need to call API of GtkWidget, avoiding some useless casts.
For bindings however (and especially bindings to compiled languages),
this is a bit annoying, as you have to explicitly change the type of the
return value (downcast), which is not trivial (or at least desirable) in
each language.
Luckily, we can use `(type ...)` annotation for this use case, leaving
the C API unchanged, while improving the experience for bindings.
2020-12-25 22:05:16 +08:00
|
|
|
* Returns: (transfer none) (type GtkBox): the horizontal #GtkBox at the
|
|
|
|
* bottom of the preview.
|
2005-09-28 10:46:06 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-09-28 10:46:06 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
2005-09-28 19:02:02 +08:00
|
|
|
gimp_preview_get_controls (GimpPreview *preview)
|
2005-09-28 10:46:06 +08:00
|
|
|
{
|
2024-08-02 22:02:30 +08:00
|
|
|
GimpPreviewPrivate *priv;
|
|
|
|
|
2005-09-28 10:46:06 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), NULL);
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
priv = gimp_preview_get_instance_private (preview);
|
|
|
|
|
|
|
|
return priv->controls;
|
2005-09-28 10:46:06 +08:00
|
|
|
}
|