2005-09-20 06:58:16 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpzoompreview.c
|
|
|
|
* Copyright (C) 2005 David Odin <dindinx@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2005-09-20 06:58:16 +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.
|
2005-09-20 06:58:16 +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/>.
|
2005-09-20 06:58:16 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-11-02 05:29:46 +08:00
|
|
|
#include <gegl.h>
|
2005-09-20 06:58:16 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "gimpuitypes.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
|
2006-02-07 23:52:53 +08:00
|
|
|
#include "gimpdrawablepreview.h"
|
2005-09-20 06:58:16 +08:00
|
|
|
#include "gimpzoompreview.h"
|
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2010-07-07 17:48:10 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpzoompreview
|
|
|
|
* @title: GimpZoomPreview
|
|
|
|
* @short_description: A drawable preview with zooming capabilities.
|
|
|
|
*
|
|
|
|
* A drawable preview with zooming capabilities.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2019-08-13 22:16:08 +08:00
|
|
|
PROP_DRAWABLE,
|
2006-08-09 18:30:01 +08:00
|
|
|
PROP_MODEL
|
2006-02-26 08:55:35 +08:00
|
|
|
};
|
|
|
|
|
2018-05-03 18:51:36 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gboolean update;
|
|
|
|
} PreviewSettings;
|
|
|
|
|
2010-07-07 17:48:10 +08:00
|
|
|
|
2015-09-15 03:49:47 +08:00
|
|
|
struct _GimpZoomPreviewPrivate
|
2005-09-21 05:52:54 +08:00
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
GimpDrawable *drawable;
|
2005-10-03 02:00:49 +08:00
|
|
|
GimpZoomModel *model;
|
2005-09-21 05:52:54 +08:00
|
|
|
GdkRectangle extents;
|
2015-09-15 03:49:47 +08:00
|
|
|
};
|
2006-01-25 22:40:31 +08:00
|
|
|
|
2018-05-03 18:51:36 +08:00
|
|
|
#define GET_PRIVATE(obj) (((GimpZoomPreview *) (obj))->priv)
|
2006-02-26 08:55:35 +08:00
|
|
|
|
2005-09-21 05:52:54 +08:00
|
|
|
|
2011-01-13 05:03:33 +08:00
|
|
|
static void gimp_zoom_preview_constructed (GObject *object);
|
2010-10-15 18:17:10 +08:00
|
|
|
static void gimp_zoom_preview_finalize (GObject *object);
|
|
|
|
static void gimp_zoom_preview_dispose (GObject *object);
|
2006-02-26 08:55:35 +08:00
|
|
|
static void gimp_zoom_preview_get_property (GObject *object,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2006-02-26 08:55:35 +08:00
|
|
|
static void gimp_zoom_preview_set_property (GObject *object,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2006-08-09 18:30:01 +08:00
|
|
|
|
2005-10-01 23:12:59 +08:00
|
|
|
static void gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
|
|
|
|
gdouble old_factor,
|
|
|
|
gdouble new_factor);
|
|
|
|
static void gimp_zoom_preview_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpZoomPreview *preview);
|
2011-01-10 03:38:01 +08:00
|
|
|
static void gimp_zoom_preview_style_updated (GtkWidget *widget);
|
2005-11-22 19:50:29 +08:00
|
|
|
static gboolean gimp_zoom_preview_scroll_event (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event,
|
|
|
|
GimpZoomPreview *preview);
|
2005-10-01 23:12:59 +08:00
|
|
|
static void gimp_zoom_preview_draw (GimpPreview *preview);
|
|
|
|
static void gimp_zoom_preview_draw_buffer (GimpPreview *preview,
|
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride);
|
|
|
|
static void gimp_zoom_preview_draw_thumb (GimpPreview *preview,
|
|
|
|
GimpPreviewArea *area,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
2006-02-06 19:07:48 +08:00
|
|
|
static void gimp_zoom_preview_set_cursor (GimpPreview *preview);
|
2007-01-12 07:41:45 +08:00
|
|
|
static void gimp_zoom_preview_transform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y);
|
|
|
|
static void gimp_zoom_preview_untransform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
static void gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
|
|
|
|
GimpDrawable *drawable);
|
2006-08-09 18:30:01 +08:00
|
|
|
static void gimp_zoom_preview_set_model (GimpZoomPreview *preview,
|
|
|
|
GimpZoomModel *model);
|
2006-02-26 08:55:35 +08:00
|
|
|
|
2007-01-12 05:35:53 +08:00
|
|
|
static void gimp_zoom_preview_get_source_area (GimpPreview *preview,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *w,
|
|
|
|
gint *h);
|
|
|
|
|
2006-02-06 19:07:48 +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 (GimpZoomPreview, gimp_zoom_preview,
|
|
|
|
GIMP_TYPE_SCROLLED_PREVIEW)
|
2006-05-15 17:46:31 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
#define parent_class gimp_zoom_preview_parent_class
|
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
static gint gimp_zoom_preview_counter = 0;
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
|
|
|
|
{
|
2010-10-15 18:17:10 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
object_class->constructed = gimp_zoom_preview_constructed;
|
|
|
|
object_class->finalize = gimp_zoom_preview_finalize;
|
|
|
|
object_class->dispose = gimp_zoom_preview_dispose;
|
|
|
|
object_class->get_property = gimp_zoom_preview_get_property;
|
|
|
|
object_class->set_property = gimp_zoom_preview_set_property;
|
2007-09-21 21:27:33 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
widget_class->style_updated = gimp_zoom_preview_style_updated;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
preview_class->draw = gimp_zoom_preview_draw;
|
|
|
|
preview_class->draw_buffer = gimp_zoom_preview_draw_buffer;
|
|
|
|
preview_class->draw_thumb = gimp_zoom_preview_draw_thumb;
|
|
|
|
preview_class->set_cursor = gimp_zoom_preview_set_cursor;
|
|
|
|
preview_class->transform = gimp_zoom_preview_transform;
|
|
|
|
preview_class->untransform = gimp_zoom_preview_untransform;
|
2005-09-21 05:52:54 +08:00
|
|
|
|
2015-09-15 03:49:47 +08:00
|
|
|
/**
|
|
|
|
* GimpZoomPreview:drawable-id:
|
|
|
|
*
|
|
|
|
* The drawable the #GimpZoomPreview is attached to.
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
*/
|
2019-08-13 22:16:08 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_DRAWABLE,
|
|
|
|
g_param_spec_object ("drawable",
|
|
|
|
"Drawable",
|
|
|
|
"The drawable this preview is attached to",
|
|
|
|
GIMP_TYPE_DRAWABLE,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2015-09-15 03:49:47 +08:00
|
|
|
|
2006-08-09 18:30:01 +08:00
|
|
|
/**
|
|
|
|
* GimpZoomPreview:model:
|
|
|
|
*
|
|
|
|
* The #GimpZoomModel used by this #GimpZoomPreview.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2006-08-09 18:30:01 +08:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class, PROP_MODEL,
|
2017-06-07 03:19:17 +08:00
|
|
|
g_param_spec_object ("model",
|
|
|
|
"Model",
|
|
|
|
"The zoom preview's GimpZoomModel",
|
2006-08-09 18:30:01 +08:00
|
|
|
GIMP_TYPE_ZOOM_MODEL,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_init (GimpZoomPreview *preview)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *area = gimp_preview_get_area (GIMP_PREVIEW (preview));
|
|
|
|
|
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
|
|
|
preview->priv = gimp_zoom_preview_get_instance_private (preview);
|
2006-01-25 22:40:31 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect (area, "size-allocate",
|
2005-09-20 06:58:16 +08:00
|
|
|
G_CALLBACK (gimp_zoom_preview_size_allocate),
|
|
|
|
preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
g_signal_connect (area, "scroll-event",
|
2005-11-22 19:50:29 +08:00
|
|
|
G_CALLBACK (gimp_zoom_preview_scroll_event),
|
|
|
|
preview);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_object_set (area,
|
2005-09-20 06:58:16 +08:00
|
|
|
"check-size", gimp_check_size (),
|
|
|
|
"check-type", gimp_check_type (),
|
|
|
|
NULL);
|
2005-09-28 10:46:06 +08:00
|
|
|
|
|
|
|
gimp_scrolled_preview_set_policy (GIMP_SCROLLED_PREVIEW (preview),
|
|
|
|
GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
2011-01-13 05:03:33 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_constructed (GObject *object)
|
2006-02-26 08:55:35 +08:00
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GET_PRIVATE (object);
|
2007-09-21 21:27:33 +08:00
|
|
|
gchar *data_name;
|
|
|
|
PreviewSettings settings;
|
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2011-01-13 05:03:33 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
data_name = g_strdup_printf ("%s-zoom-preview-%d",
|
|
|
|
g_get_prgname (),
|
|
|
|
gimp_zoom_preview_counter++);
|
2006-02-26 08:55:35 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
if (gimp_get_data (data_name, &settings))
|
|
|
|
{
|
|
|
|
gimp_preview_set_update (GIMP_PREVIEW (object), settings.update);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_set_data_full (object, "gimp-zoom-preview-data-name",
|
|
|
|
data_name, (GDestroyNotify) g_free);
|
|
|
|
|
2006-08-09 18:30:01 +08:00
|
|
|
if (! priv->model)
|
|
|
|
{
|
|
|
|
GimpZoomModel *model = gimp_zoom_model_new ();
|
|
|
|
|
|
|
|
gimp_zoom_model_set_range (model, 1.0, 256.0);
|
|
|
|
gimp_zoom_preview_set_model (GIMP_ZOOM_PREVIEW (object), model);
|
|
|
|
|
|
|
|
g_object_unref (model);
|
|
|
|
}
|
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
gimp_zoom_preview_set_adjustments (GIMP_ZOOM_PREVIEW (object), 1.0, 1.0);
|
|
|
|
}
|
|
|
|
|
2010-10-15 18:17:10 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_finalize (GObject *object)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GET_PRIVATE (object);
|
2010-10-15 18:17:10 +08:00
|
|
|
|
2017-09-03 21:14:51 +08:00
|
|
|
g_clear_object (&priv->model);
|
2019-08-13 22:16:08 +08:00
|
|
|
g_clear_object (&priv->drawable);
|
2010-10-15 18:17:10 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
const gchar *data_name = g_object_get_data (G_OBJECT (object),
|
|
|
|
"gimp-zoom-preview-data-name");
|
|
|
|
|
|
|
|
if (data_name)
|
|
|
|
{
|
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
|
|
|
PreviewSettings settings;
|
|
|
|
|
|
|
|
settings.update = gimp_preview_get_update (preview);
|
|
|
|
|
|
|
|
gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_get_property (GObject *object,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-02-26 08:55:35 +08:00
|
|
|
{
|
|
|
|
GimpZoomPreview *preview = GIMP_ZOOM_PREVIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
case PROP_DRAWABLE:
|
|
|
|
g_value_set_object (value, gimp_zoom_preview_get_drawable (preview));
|
2015-09-15 03:49:47 +08:00
|
|
|
break;
|
|
|
|
|
2006-08-09 18:30:01 +08:00
|
|
|
case PROP_MODEL:
|
|
|
|
g_value_set_object (value, gimp_zoom_preview_get_model (preview));
|
|
|
|
break;
|
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_set_property (GObject *object,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-02-26 08:55:35 +08:00
|
|
|
{
|
|
|
|
GimpZoomPreview *preview = GIMP_ZOOM_PREVIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
case PROP_DRAWABLE:
|
|
|
|
gimp_zoom_preview_set_drawable (preview, g_value_dup_object (value));
|
2006-08-09 18:30:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_MODEL:
|
|
|
|
gimp_zoom_preview_set_model (preview, g_value_get_object (value));
|
2006-02-26 08:55:35 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
static void
|
2005-10-01 23:12:59 +08:00
|
|
|
gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
|
|
|
|
gdouble old_factor,
|
|
|
|
gdouble new_factor)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2005-10-01 23:12:59 +08:00
|
|
|
GimpScrolledPreview *scrolled_preview = GIMP_SCROLLED_PREVIEW (preview);
|
2018-05-03 22:32:33 +08:00
|
|
|
GtkAdjustment *hadj;
|
|
|
|
GtkAdjustment *vadj;
|
2018-05-04 15:46:37 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2005-10-01 23:12:59 +08:00
|
|
|
gdouble ratio;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
gimp_scrolled_preview_freeze (scrolled_preview);
|
2005-11-22 20:09:17 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-10-01 23:12:59 +08:00
|
|
|
ratio = new_factor / old_factor;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2018-05-03 22:32:33 +08:00
|
|
|
gimp_scrolled_preview_get_adjustments (scrolled_preview, &hadj, &vadj);
|
|
|
|
|
|
|
|
gtk_adjustment_configure (hadj,
|
|
|
|
(gtk_adjustment_get_value (vadj) + width / 2.0) * ratio
|
2009-03-23 06:36:43 +08:00
|
|
|
- width / 2.0,
|
|
|
|
0,
|
|
|
|
width * new_factor,
|
|
|
|
new_factor,
|
|
|
|
MAX (width / 2.0, new_factor),
|
|
|
|
width);
|
2005-09-28 10:46:06 +08:00
|
|
|
|
2018-05-03 22:32:33 +08:00
|
|
|
gtk_adjustment_configure (vadj,
|
|
|
|
(gtk_adjustment_get_value (vadj) + height / 2.0) * ratio
|
2009-03-23 06:36:43 +08:00
|
|
|
- height / 2.0,
|
|
|
|
0,
|
|
|
|
height * new_factor,
|
|
|
|
new_factor,
|
|
|
|
MAX (height / 2.0, new_factor),
|
|
|
|
height);
|
2006-01-25 22:35:56 +08:00
|
|
|
|
|
|
|
gimp_scrolled_preview_thaw (scrolled_preview);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpZoomPreview *preview)
|
|
|
|
{
|
2015-09-15 03:49:47 +08:00
|
|
|
gdouble zoom;
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
#if 0
|
2005-09-21 05:52:54 +08:00
|
|
|
gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
|
|
|
|
gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
|
|
|
GIMP_PREVIEW (preview)->width = MIN (width, allocation->width);
|
|
|
|
GIMP_PREVIEW (preview)->height = MIN (height, allocation->height);
|
2018-05-04 15:46:37 +08:00
|
|
|
#endif
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2015-09-15 03:49:47 +08:00
|
|
|
zoom = gimp_zoom_model_get_factor (preview->priv->model);
|
2007-01-12 05:35:53 +08:00
|
|
|
|
|
|
|
gimp_zoom_preview_set_adjustments (preview, zoom, zoom);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-10 03:38:01 +08:00
|
|
|
gimp_zoom_preview_style_updated (GtkWidget *widget)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2011-01-10 03:38:01 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (widget);
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *area = gimp_preview_get_area (preview);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
if (area)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GET_PRIVATE (preview);
|
2011-01-10 03:38:01 +08:00
|
|
|
gint size;
|
2018-05-04 15:46:37 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint preview_width;
|
|
|
|
gint preview_height;
|
2011-01-10 03:38:01 +08:00
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
|
|
|
|
|
|
|
gtk_widget_style_get (widget, "size", &size, NULL);
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (_gimp_drawable_preview_get_bounds (priv->drawable,
|
2011-01-10 03:38:01 +08:00
|
|
|
&x1, &y1, &x2, &y2))
|
|
|
|
{
|
|
|
|
width = x2 - x1;
|
|
|
|
height = y2 - y1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-06 20:28:40 +08:00
|
|
|
width = gimp_drawable_get_width (priv->drawable);
|
|
|
|
height = gimp_drawable_get_height (priv->drawable);
|
2011-01-10 03:38:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (width > height)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
preview_width = MIN (width, size);
|
|
|
|
preview_height = (height * preview_width) / width;
|
2011-01-10 03:38:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
preview_height = MIN (height, size);
|
|
|
|
preview_width = (width * preview_height) / height;
|
2011-01-10 03:38:01 +08:00
|
|
|
}
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_set_size (preview, preview_width, preview_height);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_zoom_preview_scroll_event (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event,
|
|
|
|
GimpZoomPreview *preview)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2005-11-22 19:50:29 +08:00
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GET_PRIVATE (preview);
|
2018-05-11 08:08:51 +08:00
|
|
|
gdouble delta;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
gimp_scrolled_preview_freeze (GIMP_SCROLLED_PREVIEW (preview));
|
2005-11-22 20:09:17 +08:00
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
switch (event->direction)
|
|
|
|
{
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
gimp_zoom_model_zoom (priv->model, GIMP_ZOOM_IN, 0.0);
|
|
|
|
break;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
gimp_zoom_model_zoom (priv->model, GIMP_ZOOM_OUT, 0.0);
|
|
|
|
break;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2018-05-11 08:08:51 +08:00
|
|
|
case GDK_SCROLL_SMOOTH:
|
|
|
|
gdk_event_get_scroll_deltas ((GdkEvent *) event, NULL, &delta);
|
|
|
|
gimp_zoom_model_zoom (priv->model, GIMP_ZOOM_SMOOTH, delta);
|
|
|
|
break;
|
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-11-22 20:09:17 +08:00
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
gimp_scrolled_preview_thaw (GIMP_SCROLLED_PREVIEW (preview));
|
2005-11-22 19:50:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-21 05:52:54 +08:00
|
|
|
gimp_zoom_preview_draw (GimpPreview *preview)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2015-09-15 03:49:47 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
|
2005-09-21 05:52:54 +08:00
|
|
|
guchar *data;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint bpp;
|
|
|
|
|
2006-08-09 18:30:01 +08:00
|
|
|
if (! priv->model)
|
|
|
|
return;
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (priv->drawable == NULL)
|
2005-09-20 06:58:16 +08:00
|
|
|
return;
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2007-01-12 07:41:45 +08:00
|
|
|
data = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
|
|
|
|
&width, &height, &bpp);
|
2005-11-22 20:09:17 +08:00
|
|
|
|
2007-01-12 05:35:53 +08:00
|
|
|
if (data)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *area = gimp_preview_get_area (preview);
|
|
|
|
|
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
|
2007-01-12 05:35:53 +08:00
|
|
|
0, 0, width, height,
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_type (priv->drawable),
|
2007-01-12 05:35:53 +08:00
|
|
|
data, width * bpp);
|
|
|
|
g_free (data);
|
|
|
|
}
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_draw_buffer (GimpPreview *preview,
|
2005-09-21 05:52:54 +08:00
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2015-09-15 03:49:47 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *area = gimp_preview_get_area (preview);
|
2019-08-11 23:12:20 +08:00
|
|
|
GimpImage *image;
|
2018-05-04 15:46:37 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
2019-08-13 22:16:08 +08:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (priv->drawable));
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
if (gimp_selection_is_empty (image))
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
|
2005-09-20 06:58:16 +08:00
|
|
|
0, 0,
|
2018-05-04 15:46:37 +08:00
|
|
|
width, height,
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_type (priv->drawable),
|
2005-09-20 06:58:16 +08:00
|
|
|
buffer,
|
|
|
|
rowstride);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-14 04:54:37 +08:00
|
|
|
guchar *sel;
|
|
|
|
guchar *src;
|
|
|
|
GimpSelection *selection;
|
|
|
|
gint w, h;
|
|
|
|
gint bpp;
|
|
|
|
gint src_x;
|
|
|
|
gint src_y;
|
|
|
|
gint src_width;
|
|
|
|
gint src_height;
|
|
|
|
gint offsx = 0;
|
|
|
|
gint offsy = 0;
|
|
|
|
|
|
|
|
selection = gimp_image_get_selection (image);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
w = width;
|
|
|
|
h = height;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2007-01-12 07:41:45 +08:00
|
|
|
gimp_zoom_preview_get_source_area (preview,
|
|
|
|
&src_x, &src_y,
|
|
|
|
&src_width, &src_height);
|
2005-10-10 01:07:56 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
src = gimp_drawable_get_sub_thumbnail_data (priv->drawable,
|
2005-10-10 01:07:56 +08:00
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
2018-05-04 15:46:37 +08:00
|
|
|
&w, &h, &bpp);
|
2021-04-06 20:28:40 +08:00
|
|
|
gimp_drawable_get_offsets (priv->drawable, &offsx, &offsy);
|
2019-08-14 04:54:37 +08:00
|
|
|
sel = gimp_drawable_get_sub_thumbnail_data (GIMP_DRAWABLE (selection),
|
2008-09-03 01:56:48 +08:00
|
|
|
src_x + offsx, src_y + offsy,
|
2005-10-10 01:07:56 +08:00
|
|
|
src_width, src_height,
|
|
|
|
&width, &height, &bpp);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_area_mask (GIMP_PREVIEW_AREA (area),
|
|
|
|
0, 0, width, height,
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_drawable_type (priv->drawable),
|
2021-04-06 20:28:40 +08:00
|
|
|
src, width * gimp_drawable_get_bpp (priv->drawable),
|
2005-09-20 06:58:16 +08:00
|
|
|
buffer, rowstride,
|
|
|
|
sel, width);
|
|
|
|
|
|
|
|
g_free (sel);
|
|
|
|
g_free (src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_draw_thumb (GimpPreview *preview,
|
|
|
|
GimpPreviewArea *area,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2015-09-15 03:49:47 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
|
2005-10-09 21:54:03 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (priv->drawable != NULL)
|
|
|
|
_gimp_drawable_preview_area_draw_thumb (area, priv->drawable,
|
2015-09-15 01:47:18 +08:00
|
|
|
width, height);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
2006-02-06 19:07:48 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_set_cursor (GimpPreview *preview)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *area = gimp_preview_get_area (preview);
|
|
|
|
|
|
|
|
if (! gtk_widget_get_realized (area))
|
2006-02-06 19:07:48 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview)) > 1.0)
|
|
|
|
{
|
2018-05-03 22:32:33 +08:00
|
|
|
GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (preview));
|
|
|
|
GdkCursor *cursor;
|
|
|
|
|
|
|
|
cursor = gdk_cursor_new_for_display (display, GDK_HAND1);
|
2018-05-04 15:46:37 +08:00
|
|
|
gdk_window_set_cursor (gtk_widget_get_window (area),
|
2018-05-03 22:32:33 +08:00
|
|
|
cursor);
|
|
|
|
g_object_unref (cursor);
|
2006-02-06 19:07:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
gdk_window_set_cursor (gtk_widget_get_window (area),
|
|
|
|
gimp_preview_get_default_cursor (preview));
|
2006-02-06 19:07:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-12 07:41:45 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_transform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y)
|
|
|
|
{
|
2015-09-15 03:49:47 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
|
2018-05-04 15:46:37 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint xoff;
|
|
|
|
gint yoff;
|
|
|
|
gdouble zoom;
|
|
|
|
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
|
|
|
gimp_preview_get_offsets (preview, &xoff, &yoff);
|
2007-01-12 07:41:45 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
|
2007-01-12 07:41:45 +08:00
|
|
|
|
|
|
|
*dest_x = ((gdouble) (src_x - priv->extents.x) *
|
2018-05-04 15:46:37 +08:00
|
|
|
width / priv->extents.width * zoom) - xoff;
|
2007-01-12 07:41:45 +08:00
|
|
|
|
|
|
|
*dest_y = ((gdouble) (src_y - priv->extents.y) *
|
2018-05-04 15:46:37 +08:00
|
|
|
height / priv->extents.height * zoom) - yoff;
|
2007-01-12 07:41:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_untransform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y)
|
|
|
|
{
|
2015-09-15 03:49:47 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
|
2018-05-04 15:46:37 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint xoff;
|
|
|
|
gint yoff;
|
|
|
|
gdouble zoom;
|
|
|
|
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
|
|
|
gimp_preview_get_offsets (preview, &xoff, &yoff);
|
2007-01-12 07:41:45 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
|
2007-01-12 07:41:45 +08:00
|
|
|
|
|
|
|
*dest_x = (priv->extents.x +
|
2018-05-04 15:46:37 +08:00
|
|
|
((gdouble) (src_x + xoff) *
|
|
|
|
priv->extents.width / width / zoom));
|
2007-01-12 07:41:45 +08:00
|
|
|
|
|
|
|
*dest_y = (priv->extents.y +
|
2018-05-04 15:46:37 +08:00
|
|
|
((gdouble) (src_y + yoff) *
|
|
|
|
priv->extents.height / height / zoom));
|
2007-01-12 07:41:45 +08:00
|
|
|
}
|
|
|
|
|
2015-09-15 03:49:47 +08:00
|
|
|
static void
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
|
|
|
|
GimpDrawable *drawable)
|
2015-09-15 03:49:47 +08:00
|
|
|
{
|
|
|
|
GimpZoomPreviewPrivate *priv = preview->priv;
|
2011-05-02 05:23:19 +08:00
|
|
|
gint x, y;
|
2005-09-21 05:52:54 +08:00
|
|
|
gint width, height;
|
|
|
|
gint max_width, max_height;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
g_return_if_fail (preview->priv->drawable == NULL);
|
2006-08-09 18:30:01 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
priv->drawable = drawable;
|
2005-10-05 21:50:09 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
|
2005-10-09 21:54:03 +08:00
|
|
|
{
|
2011-05-02 05:23:19 +08:00
|
|
|
priv->extents.x = x;
|
|
|
|
priv->extents.y = y;
|
2005-10-09 21:54:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-06 20:28:40 +08:00
|
|
|
width = gimp_drawable_get_width (drawable);
|
|
|
|
height = gimp_drawable_get_height (drawable);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2005-10-09 21:54:03 +08:00
|
|
|
priv->extents.x = 0;
|
|
|
|
priv->extents.y = 0;
|
|
|
|
}
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-09-21 05:52:54 +08:00
|
|
|
priv->extents.width = width;
|
|
|
|
priv->extents.height = height;
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
if (width > height)
|
|
|
|
{
|
|
|
|
max_width = MIN (width, 512);
|
|
|
|
max_height = (height * max_width) / width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
max_height = MIN (height, 512);
|
|
|
|
max_width = (width * max_height) / height;
|
|
|
|
}
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
gimp_preview_set_bounds (GIMP_PREVIEW (preview),
|
|
|
|
0, 0, max_width, max_height);
|
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
g_object_set (gimp_preview_get_frame (GIMP_PREVIEW (preview)),
|
2005-09-20 06:58:16 +08:00
|
|
|
"ratio", (gdouble) width / (gdouble) height,
|
|
|
|
NULL);
|
2006-02-26 08:55:35 +08:00
|
|
|
}
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2006-08-09 18:30:01 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_set_model (GimpZoomPreview *preview,
|
|
|
|
GimpZoomModel *model)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GET_PRIVATE (preview);
|
2006-08-09 18:30:01 +08:00
|
|
|
GtkWidget *button_bar;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *box;
|
|
|
|
|
|
|
|
g_return_if_fail (priv->model == NULL);
|
|
|
|
|
|
|
|
if (! model)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->model = g_object_ref (model);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (priv->model, "zoomed",
|
|
|
|
G_CALLBACK (gimp_zoom_preview_set_adjustments),
|
|
|
|
preview);
|
|
|
|
|
|
|
|
box = gimp_preview_get_controls (GIMP_PREVIEW (preview));
|
|
|
|
g_return_if_fail (GTK_IS_BOX (box));
|
|
|
|
|
2011-09-30 16:53:32 +08:00
|
|
|
button_bar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2006-08-09 18:30:01 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (box), button_bar, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button_bar);
|
|
|
|
|
|
|
|
/* zoom out */
|
|
|
|
button = gimp_zoom_button_new (priv->model,
|
|
|
|
GIMP_ZOOM_OUT, GTK_ICON_SIZE_SMALL_TOOLBAR);
|
|
|
|
gtk_box_pack_start (GTK_BOX (button_bar), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
/* zoom in */
|
|
|
|
button = gimp_zoom_button_new (priv->model,
|
|
|
|
GIMP_ZOOM_IN, GTK_ICON_SIZE_SMALL_TOOLBAR);
|
|
|
|
gtk_box_pack_start (GTK_BOX (button_bar), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
}
|
|
|
|
|
2007-01-12 05:35:53 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_get_source_area (GimpPreview *preview,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *w,
|
|
|
|
gint *h)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GET_PRIVATE (preview);
|
2007-01-12 07:41:45 +08:00
|
|
|
gdouble zoom = gimp_zoom_model_get_factor (priv->model);
|
2007-01-12 05:35:53 +08:00
|
|
|
|
2007-01-12 07:41:45 +08:00
|
|
|
gimp_zoom_preview_untransform (preview, 0, 0, x, y);
|
2007-01-12 05:35:53 +08:00
|
|
|
|
|
|
|
*w = priv->extents.width / zoom;
|
|
|
|
*h = priv->extents.height / zoom;
|
|
|
|
}
|
|
|
|
|
2006-08-09 18:30:01 +08:00
|
|
|
|
2015-09-15 03:49:47 +08:00
|
|
|
/**
|
2019-08-13 22:16:08 +08:00
|
|
|
* gimp_zoom_preview_new_from_drawable:
|
|
|
|
* @drawable: (transfer none): a drawable
|
2015-09-15 03:49:47 +08:00
|
|
|
*
|
2019-08-13 22:16:08 +08:00
|
|
|
* Creates a new #GimpZoomPreview widget for @drawable.
|
2015-09-15 03:49:47 +08:00
|
|
|
*
|
2019-08-13 22:16:08 +08:00
|
|
|
* Since: 3.0
|
2015-09-15 03:49:47 +08:00
|
|
|
*
|
|
|
|
* Returns: a new #GimpZoomPreview.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_zoom_preview_new_from_drawable (GimpDrawable *drawable)
|
2015-09-15 03:49:47 +08:00
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
g_return_val_if_fail (gimp_item_is_valid (GIMP_ITEM (drawable)), NULL);
|
2015-09-15 03:49:47 +08:00
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_ZOOM_PREVIEW,
|
2019-08-13 22:16:08 +08:00
|
|
|
"drawable", drawable,
|
2015-09-15 03:49:47 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-08 22:30:55 +08:00
|
|
|
* gimp_zoom_preview_new_with_model_from_drawable:
|
|
|
|
* @drawable: a #GimpDrawable
|
|
|
|
* @model: a #GimpZoomModel
|
2015-09-15 03:49:47 +08:00
|
|
|
*
|
2020-05-08 22:30:55 +08:00
|
|
|
* Creates a new #GimpZoomPreview widget for @drawable using the
|
2015-09-15 03:49:47 +08:00
|
|
|
* given @model.
|
|
|
|
*
|
2019-08-13 22:16:08 +08:00
|
|
|
* This variant of gimp_zoom_preview_new_from_drawable() allows you
|
2015-09-15 03:49:47 +08:00
|
|
|
* to create a preview using an existing zoom model. This may be
|
|
|
|
* useful if for example you want to have two zoom previews that keep
|
|
|
|
* their zoom factor in sync.
|
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
*
|
|
|
|
* Returns: a new #GimpZoomPreview.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_zoom_preview_new_with_model_from_drawable (GimpDrawable *drawable,
|
|
|
|
GimpZoomModel *model)
|
2015-09-15 03:49:47 +08:00
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
g_return_val_if_fail (gimp_item_is_valid (GIMP_ITEM (drawable)), NULL);
|
2015-09-15 03:49:47 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_ZOOM_MODEL (model), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_ZOOM_PREVIEW,
|
2019-08-13 22:16:08 +08:00
|
|
|
"drawable", drawable,
|
|
|
|
"model", model,
|
2015-09-15 03:49:47 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-13 22:16:08 +08:00
|
|
|
* gimp_zoom_preview_get_drawable:
|
2015-09-15 03:49:47 +08:00
|
|
|
* @preview: a #GimpZoomPreview widget
|
|
|
|
*
|
2019-08-13 22:16:08 +08:00
|
|
|
* Returns the drawable the #GimpZoomPreview is attached to.
|
2015-09-15 03:49:47 +08:00
|
|
|
*
|
2019-08-13 22:16:08 +08:00
|
|
|
* Returns: (transfer none): the drawable that was passed to
|
|
|
|
* gimp_zoom_preview_new_from_drawable().
|
2015-09-15 03:49:47 +08:00
|
|
|
*
|
2019-08-13 22:16:08 +08:00
|
|
|
* Since: 3.0
|
2015-09-15 03:49:47 +08:00
|
|
|
**/
|
2019-08-13 22:16:08 +08:00
|
|
|
GimpDrawable *
|
|
|
|
gimp_zoom_preview_get_drawable (GimpZoomPreview *preview)
|
2015-09-15 03:49:47 +08:00
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), NULL);
|
2015-09-15 03:49:47 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
return GET_PRIVATE (preview)->drawable;
|
2015-09-15 03:49:47 +08:00
|
|
|
}
|
|
|
|
|
2006-08-09 18:30:01 +08:00
|
|
|
/**
|
|
|
|
* gimp_zoom_preview_get_model:
|
|
|
|
* @preview: a #GimpZoomPreview widget
|
|
|
|
*
|
|
|
|
* Returns the #GimpZoomModel the preview is using.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer none): a pointer to the #GimpZoomModel owned
|
2019-08-13 22:16:08 +08:00
|
|
|
* by the @preview
|
2006-08-09 18:30:01 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2006-08-09 18:30:01 +08:00
|
|
|
**/
|
|
|
|
GimpZoomModel *
|
|
|
|
gimp_zoom_preview_get_model (GimpZoomPreview *preview)
|
|
|
|
{
|
2007-01-12 05:35:53 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), NULL);
|
2006-08-09 18:30:01 +08:00
|
|
|
|
2018-05-03 18:51:36 +08:00
|
|
|
return GET_PRIVATE (preview)->model;
|
2006-08-09 18:30:01 +08:00
|
|
|
}
|
|
|
|
|
2005-10-05 21:50:09 +08:00
|
|
|
/**
|
2006-08-09 00:46:12 +08:00
|
|
|
* gimp_zoom_preview_get_factor:
|
2005-10-05 21:50:09 +08:00
|
|
|
* @preview: a #GimpZoomPreview widget
|
|
|
|
*
|
2006-08-09 00:46:12 +08:00
|
|
|
* Returns the zoom factor the preview is currently using.
|
2006-04-06 19:28:02 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the current zoom factor
|
2005-10-05 21:50:09 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-10-05 21:50:09 +08:00
|
|
|
**/
|
2005-10-03 02:00:49 +08:00
|
|
|
gdouble
|
|
|
|
gimp_zoom_preview_get_factor (GimpZoomPreview *preview)
|
|
|
|
{
|
2007-01-12 05:35:53 +08:00
|
|
|
GimpZoomPreviewPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), 1.0);
|
|
|
|
|
2018-05-03 18:51:36 +08:00
|
|
|
priv = GET_PRIVATE (preview);
|
2005-10-03 02:00:49 +08:00
|
|
|
|
2006-08-09 18:30:01 +08:00
|
|
|
return priv->model ? gimp_zoom_model_get_factor (priv->model) : 1.0;
|
2005-10-03 02:00:49 +08:00
|
|
|
}
|
2005-11-22 19:50:29 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_zoom_preview_get_source:
|
2006-04-06 19:28:02 +08:00
|
|
|
* @preview: a #GimpZoomPreview widget
|
2020-05-03 23:57:23 +08:00
|
|
|
* @width: (out): a pointer to an int where the current width of the zoom widget
|
2006-04-06 19:28:02 +08:00
|
|
|
* will be put.
|
2020-05-03 23:57:23 +08:00
|
|
|
* @height: (out): a pointer to an int where the current width of the zoom widget
|
2006-04-06 19:28:02 +08:00
|
|
|
* will be put.
|
2020-05-03 23:57:23 +08:00
|
|
|
* @bpp: (out): return location for the number of bytes per pixel
|
2005-11-22 19:50:29 +08:00
|
|
|
*
|
2006-04-06 19:28:02 +08:00
|
|
|
* Returns the scaled image data of the part of the drawable the
|
|
|
|
* #GimpZoomPreview is currently showing, as a newly allocated array of guchar.
|
|
|
|
* This function also allow to get the current width, height and bpp of the
|
|
|
|
* #GimpZoomPreview.
|
2005-11-22 19:50:29 +08:00
|
|
|
*
|
2020-05-08 22:57:45 +08:00
|
|
|
* Returns: (transfer full) (array): newly allocated data that should be
|
|
|
|
* released using g_free() when it is not any longer needed
|
2005-11-22 19:50:29 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-11-22 19:50:29 +08:00
|
|
|
*/
|
|
|
|
guchar *
|
|
|
|
gimp_zoom_preview_get_source (GimpZoomPreview *preview,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
gint *bpp)
|
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
GimpDrawable *drawable;
|
2007-01-12 05:35:53 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), NULL);
|
|
|
|
g_return_val_if_fail (width != NULL && height != NULL && bpp != NULL, NULL);
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
drawable = gimp_zoom_preview_get_drawable (preview);
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
if (drawable)
|
2007-01-12 05:35:53 +08:00
|
|
|
{
|
2007-01-12 07:41:45 +08:00
|
|
|
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
|
|
|
|
gint src_x;
|
|
|
|
gint src_y;
|
|
|
|
gint src_width;
|
|
|
|
gint src_height;
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_get_size (gimp_preview, width, height);
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2007-01-12 07:41:45 +08:00
|
|
|
gimp_zoom_preview_get_source_area (gimp_preview,
|
2007-01-12 05:35:53 +08:00
|
|
|
&src_x, &src_y,
|
|
|
|
&src_width, &src_height);
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
return gimp_drawable_get_sub_thumbnail_data (drawable,
|
2007-01-12 05:35:53 +08:00
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
|
|
|
width, height, bpp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
*bpp = 0;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-11-22 19:50:29 +08:00
|
|
|
}
|