2004-09-29 07:23:09 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpaspectpreview.c
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2004-09-29 07:23:09 +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-09-29 07:23:09 +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-09-29 07:23:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-11-02 05:29:46 +08:00
|
|
|
#include <gegl.h>
|
2004-09-29 07:23:09 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "gimpuitypes.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
2023-10-27 03:48:07 +08:00
|
|
|
#include "gimppdb-private.h"
|
2004-09-29 07:23:09 +08:00
|
|
|
|
|
|
|
#include "libgimp-intl.h"
|
|
|
|
|
|
|
|
#include "gimpaspectpreview.h"
|
|
|
|
|
|
|
|
|
2010-07-07 17:48:10 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpaspectpreview
|
|
|
|
* @title: GimpAspectPreview
|
|
|
|
* @short_description: A widget providing a preview with fixed aspect ratio.
|
|
|
|
*
|
|
|
|
* A widget providing a preview with fixed aspect ratio.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2006-02-26 08:37:50 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2019-08-13 22:16:08 +08:00
|
|
|
PROP_DRAWABLE
|
2006-02-26 08:37:50 +08:00
|
|
|
};
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
typedef struct _GimpAspectPreviewPrivate
|
2015-09-17 06:24:03 +08:00
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
GimpDrawable *drawable;
|
2024-08-02 22:02:30 +08:00
|
|
|
} GimpAspectPreviewPrivate;
|
2015-09-17 06:24:03 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gboolean update;
|
|
|
|
} PreviewSettings;
|
|
|
|
|
2024-08-02 22:02:30 +08:00
|
|
|
#define GET_PRIVATE(obj) (gimp_aspect_preview_get_instance_private ((GimpAspectPreview *) (obj)))
|
2007-09-21 21:27:33 +08:00
|
|
|
|
2015-09-17 06:24:03 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
static void gimp_aspect_preview_constructed (GObject *object);
|
|
|
|
static void gimp_aspect_preview_dispose (GObject *object);
|
|
|
|
static void gimp_aspect_preview_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_aspect_preview_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_aspect_preview_style_updated (GtkWidget *widget);
|
|
|
|
static void gimp_aspect_preview_draw (GimpPreview *preview);
|
|
|
|
static void gimp_aspect_preview_draw_buffer (GimpPreview *preview,
|
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride);
|
|
|
|
static void gimp_aspect_preview_transform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y);
|
|
|
|
static void gimp_aspect_preview_untransform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y);
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
static void gimp_aspect_preview_set_drawable (GimpAspectPreview *preview,
|
|
|
|
GimpDrawable *drawable);
|
2004-09-29 23:33:02 +08:00
|
|
|
|
2004-09-29 07:23:09 +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 (GimpAspectPreview, gimp_aspect_preview,
|
|
|
|
GIMP_TYPE_PREVIEW)
|
2004-09-29 07:23:09 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_aspect_preview_parent_class
|
2004-09-29 07:23:09 +08:00
|
|
|
|
2007-09-21 21:27:33 +08:00
|
|
|
static gint gimp_aspect_preview_counter = 0;
|
|
|
|
|
2004-09-29 07:23:09 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_aspect_preview_class_init (GimpAspectPreviewClass *klass)
|
|
|
|
{
|
2010-10-15 18:04:36 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
|
2004-09-29 07:23:09 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
object_class->constructed = gimp_aspect_preview_constructed;
|
|
|
|
object_class->dispose = gimp_aspect_preview_dispose;
|
|
|
|
object_class->get_property = gimp_aspect_preview_get_property;
|
|
|
|
object_class->set_property = gimp_aspect_preview_set_property;
|
2006-02-26 08:37:50 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
widget_class->style_updated = gimp_aspect_preview_style_updated;
|
2004-09-29 23:33:02 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
preview_class->draw = gimp_aspect_preview_draw;
|
|
|
|
preview_class->draw_buffer = gimp_aspect_preview_draw_buffer;
|
|
|
|
preview_class->transform = gimp_aspect_preview_transform;
|
|
|
|
preview_class->untransform = gimp_aspect_preview_untransform;
|
2006-02-26 08:37:50 +08:00
|
|
|
|
2015-09-17 06:24:03 +08:00
|
|
|
/**
|
|
|
|
* GimpAspectPreview:drawable-id:
|
|
|
|
*
|
|
|
|
* The drawable the #GimpAspectPreview 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));
|
2004-09-29 07:23:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_aspect_preview_init (GimpAspectPreview *preview)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
g_object_set (gimp_preview_get_area (GIMP_PREVIEW (preview)),
|
2004-09-29 07:23:09 +08:00
|
|
|
"check-size", gimp_check_size (),
|
|
|
|
"check-type", gimp_check_type (),
|
2020-05-25 04:26:50 +08:00
|
|
|
"check-custom-color1", gimp_check_custom_color1 (),
|
|
|
|
"check-custom-color2", gimp_check_custom_color2 (),
|
2004-09-29 07:23:09 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2011-01-13 05:03:33 +08:00
|
|
|
static void
|
|
|
|
gimp_aspect_preview_constructed (GObject *object)
|
2007-09-21 21:27:33 +08:00
|
|
|
{
|
|
|
|
gchar *data_name;
|
|
|
|
PreviewSettings settings;
|
2023-10-27 03:48:07 +08:00
|
|
|
GBytes *settings_bytes = NULL;
|
2007-09-21 21:27:33 +08:00
|
|
|
|
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-aspect-preview-%d",
|
|
|
|
g_get_prgname (),
|
|
|
|
gimp_aspect_preview_counter++);
|
|
|
|
|
2023-10-27 03:48:07 +08:00
|
|
|
if (gimp_pdb_get_data (data_name, &settings_bytes) &&
|
|
|
|
g_bytes_get_size (settings_bytes) == sizeof (PreviewSettings))
|
2007-09-21 21:27:33 +08:00
|
|
|
{
|
2023-10-27 03:48:07 +08:00
|
|
|
settings = *((PreviewSettings *) g_bytes_get_data (settings_bytes, NULL));
|
2007-09-21 21:27:33 +08:00
|
|
|
gimp_preview_set_update (GIMP_PREVIEW (object), settings.update);
|
|
|
|
}
|
2023-10-27 03:48:07 +08:00
|
|
|
g_bytes_unref (settings_bytes);
|
2007-09-21 21:27:33 +08:00
|
|
|
|
|
|
|
g_object_set_data_full (object, "gimp-aspect-preview-data-name",
|
|
|
|
data_name, (GDestroyNotify) g_free);
|
|
|
|
}
|
|
|
|
|
2010-10-15 18:04:36 +08:00
|
|
|
static void
|
|
|
|
gimp_aspect_preview_dispose (GObject *object)
|
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
GimpAspectPreviewPrivate *priv = GET_PRIVATE (object);
|
|
|
|
const gchar *data_name;
|
2010-10-15 18:04:36 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
data_name = g_object_get_data (G_OBJECT (object),
|
|
|
|
"gimp-aspect-preview-data-name");
|
2010-10-15 18:04:36 +08:00
|
|
|
if (data_name)
|
|
|
|
{
|
|
|
|
GimpPreview *preview = GIMP_PREVIEW (object);
|
2023-10-27 03:48:07 +08:00
|
|
|
GBytes *bytes;
|
2010-10-15 18:04:36 +08:00
|
|
|
PreviewSettings settings;
|
|
|
|
|
|
|
|
settings.update = gimp_preview_get_update (preview);
|
|
|
|
|
2023-10-27 03:48:07 +08:00
|
|
|
bytes = g_bytes_new_static (&settings, sizeof (PreviewSettings));
|
|
|
|
gimp_pdb_set_data (data_name, bytes);
|
|
|
|
g_bytes_unref (bytes);
|
2010-10-15 18:04:36 +08:00
|
|
|
}
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
g_clear_object (&priv->drawable);
|
|
|
|
|
2010-10-15 18:04:36 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2006-02-26 08:37:50 +08:00
|
|
|
static void
|
|
|
|
gimp_aspect_preview_get_property (GObject *object,
|
2006-04-12 18:53:28 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-02-26 08:37:50 +08:00
|
|
|
{
|
2015-09-17 06:24:03 +08:00
|
|
|
GimpAspectPreview *preview = GIMP_ASPECT_PREVIEW (object);
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
|
2006-02-26 08:37:50 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
case PROP_DRAWABLE:
|
|
|
|
g_value_set_object (value, priv->drawable);
|
2015-09-17 06:24:03 +08:00
|
|
|
break;
|
|
|
|
|
2006-02-26 08:37:50 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_aspect_preview_set_property (GObject *object,
|
2019-08-13 22:16:08 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-02-26 08:37:50 +08:00
|
|
|
{
|
2018-04-29 05:32:47 +08:00
|
|
|
GimpAspectPreview *preview = GIMP_ASPECT_PREVIEW (object);
|
2006-02-26 08:37:50 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2019-08-13 22:16:08 +08:00
|
|
|
case PROP_DRAWABLE:
|
|
|
|
gimp_aspect_preview_set_drawable (preview, g_value_dup_object (value));
|
2006-02-26 08:37:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-29 07:23:09 +08:00
|
|
|
static void
|
2011-01-10 03:38:01 +08:00
|
|
|
gimp_aspect_preview_style_updated (GtkWidget *widget)
|
2004-09-29 07:23:09 +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);
|
2004-09-29 07:23:09 +08:00
|
|
|
|
2011-01-10 03:38:01 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
|
2004-09-29 07:23:09 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
if (area)
|
2004-09-29 07:23:09 +08:00
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
|
2011-01-10 03:38:01 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2018-05-04 15:46:37 +08:00
|
|
|
gint preview_width;
|
|
|
|
gint preview_height;
|
2011-01-10 03:38:01 +08:00
|
|
|
gint size;
|
|
|
|
|
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
|
|
|
|
|
|
|
gtk_widget_style_get (widget,
|
|
|
|
"size", &size,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
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);
|
2004-09-29 07:23:09 +08:00
|
|
|
}
|
2004-09-29 23:33:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_aspect_preview_draw (GimpPreview *preview)
|
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
GtkWidget *area = gimp_preview_get_area (preview);
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2004-09-29 23:33:02 +08:00
|
|
|
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
|
|
|
|
|
|
|
gimp_preview_area_fill (GIMP_PREVIEW_AREA (area),
|
2004-09-29 23:33:02 +08:00
|
|
|
0, 0,
|
2018-05-04 15:46:37 +08:00
|
|
|
width, height,
|
2004-09-29 23:33:02 +08:00
|
|
|
0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_aspect_preview_draw_buffer (GimpPreview *preview,
|
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
|
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;
|
2004-10-05 01:40:45 +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));
|
2004-09-29 23:33:02 +08:00
|
|
|
|
2019-08-11 23:12:20 +08:00
|
|
|
if (gimp_selection_is_empty (image))
|
2004-10-05 01:40:45 +08:00
|
|
|
{
|
2018-05-04 15:46:37 +08:00
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (area),
|
2004-10-05 01:40:45 +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),
|
2004-10-05 01:40:45 +08:00
|
|
|
buffer,
|
|
|
|
rowstride);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-24 05:37:46 +08:00
|
|
|
GBytes *sel;
|
|
|
|
GBytes *src;
|
2019-08-14 04:54:37 +08:00
|
|
|
GimpSelection *selection;
|
|
|
|
gint w, h;
|
|
|
|
gint bpp;
|
2004-10-05 01:40:45 +08:00
|
|
|
|
2019-08-14 04:54:37 +08:00
|
|
|
selection = gimp_image_get_selection (image);
|
2004-10-05 01:40:45 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
src = gimp_drawable_get_thumbnail_data (priv->drawable,
|
2023-05-24 05:37:46 +08:00
|
|
|
width, height,
|
2018-05-04 15:46:37 +08:00
|
|
|
&w, &h, &bpp);
|
2019-08-14 04:54:37 +08:00
|
|
|
sel = gimp_drawable_get_thumbnail_data (GIMP_DRAWABLE (selection),
|
2023-05-24 05:37:46 +08:00
|
|
|
width, height,
|
2018-05-04 15:46:37 +08:00
|
|
|
&w, &h, &bpp);
|
2004-10-05 01:40:45 +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),
|
2023-05-24 05:37:46 +08:00
|
|
|
g_bytes_get_data (src, NULL),
|
|
|
|
width * gimp_drawable_get_bpp (priv->drawable),
|
2004-10-05 01:40:45 +08:00
|
|
|
buffer, rowstride,
|
2023-05-24 05:37:46 +08:00
|
|
|
g_bytes_get_data (sel, NULL), width);
|
2004-10-05 01:40:45 +08:00
|
|
|
|
2023-05-24 05:37:46 +08:00
|
|
|
g_bytes_unref (sel);
|
|
|
|
g_bytes_unref (src);
|
2004-10-05 01:40:45 +08:00
|
|
|
}
|
2004-09-29 07:23:09 +08:00
|
|
|
}
|
|
|
|
|
2007-01-14 01:25:49 +08:00
|
|
|
static void
|
|
|
|
gimp_aspect_preview_transform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
2007-01-14 01:25:49 +08:00
|
|
|
|
2021-04-06 20:28:40 +08:00
|
|
|
*dest_x = (gdouble) src_x * width / gimp_drawable_get_width (priv->drawable);
|
|
|
|
*dest_y = (gdouble) src_y * height / gimp_drawable_get_height (priv->drawable);
|
2007-01-14 01:25:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_aspect_preview_untransform (GimpPreview *preview,
|
|
|
|
gint src_x,
|
|
|
|
gint src_y,
|
|
|
|
gint *dest_x,
|
|
|
|
gint *dest_y)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
|
2018-05-04 15:46:37 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
gimp_preview_get_size (preview, &width, &height);
|
2007-01-14 01:25:49 +08:00
|
|
|
|
2021-04-06 20:28:40 +08:00
|
|
|
*dest_x = (gdouble) src_x * gimp_drawable_get_width (priv->drawable) / width;
|
|
|
|
*dest_y = (gdouble) src_y * gimp_drawable_get_height (priv->drawable) / height;
|
2007-01-14 01:25:49 +08:00
|
|
|
}
|
|
|
|
|
2015-09-17 06:24:03 +08:00
|
|
|
static void
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_aspect_preview_set_drawable (GimpAspectPreview *preview,
|
|
|
|
GimpDrawable *drawable)
|
2015-09-17 06:24:03 +08:00
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpAspectPreviewPrivate *priv = GET_PRIVATE (preview);
|
2015-09-17 06:24:03 +08:00
|
|
|
gint d_width;
|
|
|
|
gint d_height;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
g_return_if_fail (priv->drawable == NULL);
|
2015-09-17 06:24:03 +08:00
|
|
|
|
2019-08-13 22:16:08 +08:00
|
|
|
priv->drawable = drawable;
|
2015-09-17 06:24:03 +08:00
|
|
|
|
2021-04-06 20:28:40 +08:00
|
|
|
d_width = gimp_drawable_get_width (priv->drawable);
|
|
|
|
d_height = gimp_drawable_get_height (priv->drawable);
|
2015-09-17 06:24:03 +08:00
|
|
|
|
|
|
|
if (d_width > d_height)
|
2006-02-26 08:37:50 +08:00
|
|
|
{
|
2015-09-17 06:24:03 +08:00
|
|
|
width = MIN (d_width, 512);
|
|
|
|
height = (d_height * width) / d_width;
|
2006-02-26 08:37:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-17 06:24:03 +08:00
|
|
|
height = MIN (d_height, 512);
|
|
|
|
width = (d_width * height) / d_height;
|
2006-02-26 08:37:50 +08:00
|
|
|
}
|
2015-09-17 06:24:03 +08:00
|
|
|
|
2007-01-14 01:25:49 +08:00
|
|
|
gimp_preview_set_bounds (GIMP_PREVIEW (preview), 0, 0, width, height);
|
2006-02-26 08:37:50 +08:00
|
|
|
|
|
|
|
if (height > 0)
|
2018-05-04 15:46:37 +08:00
|
|
|
g_object_set (gimp_preview_get_frame (GIMP_PREVIEW (preview)),
|
2007-01-14 01:25:49 +08:00
|
|
|
"ratio",
|
2015-09-17 06:24:03 +08:00
|
|
|
(gdouble) d_width / (gdouble) d_height,
|
2006-04-12 18:53:28 +08:00
|
|
|
NULL);
|
2006-02-26 08:37:50 +08:00
|
|
|
}
|
|
|
|
|
2015-09-17 06:24:03 +08:00
|
|
|
/**
|
2019-08-13 22:16:08 +08:00
|
|
|
* gimp_aspect_preview_new_from_drawable:
|
|
|
|
* @drawable: (transfer none): a drawable
|
2015-09-17 06:24:03 +08:00
|
|
|
*
|
2019-08-13 22:16:08 +08:00
|
|
|
* Creates a new #GimpAspectPreview widget for @drawable_. See also
|
|
|
|
* gimp_drawable_preview_new_from_drawable().
|
2015-09-17 06:24:03 +08:00
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
*
|
|
|
|
* Returns: a new #GimpAspectPreview.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
2019-08-13 22:16:08 +08:00
|
|
|
gimp_aspect_preview_new_from_drawable (GimpDrawable *drawable)
|
2015-09-17 06:24:03 +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-17 06:24:03 +08:00
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_ASPECT_PREVIEW,
|
2019-08-13 22:16:08 +08:00
|
|
|
"drawable", drawable,
|
2015-09-17 06:24:03 +08:00
|
|
|
NULL);
|
|
|
|
}
|