[gimp/blend-tool-fun: 51/163] libgimp: deprecate GimpZoomPreview's GimpDrawable API
- From: Michael Henning <mhenning src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/blend-tool-fun: 51/163] libgimp: deprecate GimpZoomPreview's GimpDrawable API
- Date: Mon, 26 Oct 2015 02:22:30 +0000 (UTC)
commit e7a9706d3cbf0b62401ef86a1a2bc862233bd6c8
Author: Michael Natterer <mitch gimp org>
Date: Mon Sep 14 21:49:47 2015 +0200
libgimp: deprecate GimpZoomPreview's GimpDrawable API
and add drawable_ID functions instead.
libgimp/gimpui.def | 3 +
libgimp/gimpzoompreview.c | 207 ++++++++++++++++++++++++++++++++++----------
libgimp/gimpzoompreview.h | 25 ++++--
3 files changed, 182 insertions(+), 53 deletions(-)
---
diff --git a/libgimp/gimpui.def b/libgimp/gimpui.def
index 79d6660..58ecd59 100644
--- a/libgimp/gimpui.def
+++ b/libgimp/gimpui.def
@@ -76,9 +76,12 @@ EXPORTS
gimp_window_set_transient
gimp_window_set_transient_for_display
gimp_zoom_preview_get_drawable
+ gimp_zoom_preview_get_drawable_id
gimp_zoom_preview_get_factor
gimp_zoom_preview_get_model
gimp_zoom_preview_get_source
gimp_zoom_preview_get_type
gimp_zoom_preview_new
+ gimp_zoom_preview_new_from_drawable
gimp_zoom_preview_new_with_model
+ gimp_zoom_preview_new_with_model_from_drawable
diff --git a/libgimp/gimpzoompreview.c b/libgimp/gimpzoompreview.c
index b40e516..8c61bb1 100644
--- a/libgimp/gimpzoompreview.c
+++ b/libgimp/gimpzoompreview.c
@@ -47,16 +47,18 @@ enum
{
PROP_0,
PROP_DRAWABLE,
+ PROP_DRAWABLE_ID,
PROP_MODEL
};
-typedef struct GimpZoomPreviewPrivate
+struct _GimpZoomPreviewPrivate
{
+ gint32 drawable_ID;
GimpDrawable *drawable;
GimpZoomModel *model;
GdkRectangle extents;
-} GimpZoomPreviewPrivate;
+};
typedef struct
{
@@ -112,6 +114,8 @@ static void gimp_zoom_preview_untransform (GimpPreview *preview,
static void gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
GimpDrawable *drawable);
+static void gimp_zoom_preview_set_drawable_id (GimpZoomPreview *preview,
+ gint32 drawable_ID);
static void gimp_zoom_preview_set_model (GimpZoomPreview *preview,
GimpZoomModel *model);
@@ -158,6 +162,8 @@ gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
*
* The drawable the #GimpZoomPreview is attached to.
*
+ * Deprecated: use the drawable-id property instead.
+ *
* Since: 2.4
*/
g_object_class_install_property (object_class, PROP_DRAWABLE,
@@ -166,6 +172,19 @@ gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
G_PARAM_CONSTRUCT_ONLY));
/**
+ * GimpZoomPreview:drawable-id:
+ *
+ * The drawable the #GimpZoomPreview is attached to.
+ *
+ * Since: 2.10
+ */
+ g_object_class_install_property (object_class, PROP_DRAWABLE_ID,
+ g_param_spec_int ("drawable-id", NULL, NULL,
+ -1, G_MAXINT, -1,
+ GIMP_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ /**
* GimpZoomPreview:model:
*
* The #GimpZoomModel used by this #GimpZoomPreview.
@@ -283,6 +302,10 @@ gimp_zoom_preview_get_property (GObject *object,
g_value_set_pointer (value, gimp_zoom_preview_get_drawable (preview));
break;
+ case PROP_DRAWABLE_ID:
+ g_value_set_int (value, gimp_zoom_preview_get_drawable_id (preview));
+ break;
+
case PROP_MODEL:
g_value_set_object (value, gimp_zoom_preview_get_model (preview));
break;
@@ -304,7 +327,13 @@ gimp_zoom_preview_set_property (GObject *object,
switch (property_id)
{
case PROP_DRAWABLE:
- gimp_zoom_preview_set_drawable (preview, g_value_get_pointer (value));
+ g_return_if_fail (preview->priv->drawable_ID < 1);
+ if (g_value_get_pointer (value))
+ gimp_zoom_preview_set_drawable (preview, g_value_get_pointer (value));
+ break;
+
+ case PROP_DRAWABLE_ID:
+ gimp_zoom_preview_set_drawable_id (preview, g_value_get_int (value));
break;
case PROP_MODEL:
@@ -363,8 +392,7 @@ gimp_zoom_preview_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
GimpZoomPreview *preview)
{
- GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
- gdouble zoom;
+ gdouble zoom;
gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
@@ -372,7 +400,7 @@ gimp_zoom_preview_size_allocate (GtkWidget *widget,
GIMP_PREVIEW (preview)->width = MIN (width, allocation->width);
GIMP_PREVIEW (preview)->height = MIN (height, allocation->height);
- zoom = gimp_zoom_model_get_factor (priv->model);
+ zoom = gimp_zoom_model_get_factor (preview->priv->model);
gimp_zoom_preview_set_adjustments (preview, zoom, zoom);
}
@@ -381,9 +409,8 @@ static void
gimp_zoom_preview_style_set (GtkWidget *widget,
GtkStyle *prev_style)
{
- GimpPreview *preview = GIMP_PREVIEW (widget);
- GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
- GimpDrawable *drawable = priv->drawable;
+ GimpPreview *preview = GIMP_PREVIEW (widget);
+ GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
gint size;
gint width, height;
gint x1, y1;
@@ -394,7 +421,7 @@ gimp_zoom_preview_style_set (GtkWidget *widget,
gtk_widget_style_get (widget, "size", &size, NULL);
- if (_gimp_drawable_preview_get_bounds (drawable->drawable_id,
+ if (_gimp_drawable_preview_get_bounds (priv->drawable_ID,
&x1, &y1, &x2, &y2))
{
width = x2 - x1;
@@ -402,8 +429,8 @@ gimp_zoom_preview_style_set (GtkWidget *widget,
}
else
{
- width = gimp_drawable_width (drawable->drawable_id);
- height = gimp_drawable_height (drawable->drawable_id);
+ width = gimp_drawable_width (priv->drawable_ID);
+ height = gimp_drawable_height (priv->drawable_ID);
}
if (width > height)
@@ -455,8 +482,7 @@ gimp_zoom_preview_scroll_event (GtkWidget *widget,
static void
gimp_zoom_preview_draw (GimpPreview *preview)
{
- GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
- GimpDrawable *drawable;
+ GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
guchar *data;
gint width;
gint height;
@@ -465,8 +491,7 @@ gimp_zoom_preview_draw (GimpPreview *preview)
if (! priv->model)
return;
- drawable = priv->drawable;
- if (! drawable)
+ if (priv->drawable_ID < 1)
return;
data = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
@@ -476,7 +501,7 @@ gimp_zoom_preview_draw (GimpPreview *preview)
{
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
0, 0, width, height,
- gimp_drawable_type (drawable->drawable_id),
+ gimp_drawable_type (priv->drawable_ID),
data, width * bpp);
g_free (data);
}
@@ -487,18 +512,17 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
const guchar *buffer,
gint rowstride)
{
- GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
- GimpDrawable *drawable = priv->drawable;
- gint32 image_id;
+ GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
+ gint32 image_ID;
- image_id = gimp_item_get_image (drawable->drawable_id);
+ image_ID = gimp_item_get_image (priv->drawable_ID);
- if (gimp_selection_is_empty (image_id))
+ if (gimp_selection_is_empty (image_ID))
{
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
0, 0,
preview->width, preview->height,
- gimp_drawable_type (drawable->drawable_id),
+ gimp_drawable_type (priv->drawable_ID),
buffer,
rowstride);
}
@@ -506,7 +530,7 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
{
guchar *sel;
guchar *src;
- gint selection_id;
+ gint selection_ID;
gint width, height;
gint bpp;
gint src_x;
@@ -516,7 +540,7 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
gint offsx = 0;
gint offsy = 0;
- selection_id = gimp_image_get_selection (image_id);
+ selection_ID = gimp_image_get_selection (image_ID);
width = preview->width;
height = preview->height;
@@ -525,20 +549,20 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
&src_x, &src_y,
&src_width, &src_height);
- src = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
+ src = gimp_drawable_get_sub_thumbnail_data (priv->drawable_ID,
src_x, src_y,
src_width, src_height,
&width, &height, &bpp);
- gimp_drawable_offsets (drawable->drawable_id, &offsx, &offsy);
- sel = gimp_drawable_get_sub_thumbnail_data (selection_id,
+ gimp_drawable_offsets (priv->drawable_ID, &offsx, &offsy);
+ sel = gimp_drawable_get_sub_thumbnail_data (selection_ID,
src_x + offsx, src_y + offsy,
src_width, src_height,
&width, &height, &bpp);
gimp_preview_area_mask (GIMP_PREVIEW_AREA (preview->area),
0, 0, preview->width, preview->height,
- gimp_drawable_type (drawable->drawable_id),
- src, width * drawable->bpp,
+ gimp_drawable_type (priv->drawable_ID),
+ src, width * gimp_drawable_bpp (priv->drawable_ID),
buffer, rowstride,
sel, width);
@@ -554,11 +578,10 @@ gimp_zoom_preview_draw_thumb (GimpPreview *preview,
gint width,
gint height)
{
- GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
- GimpDrawable *drawable = priv->drawable;
+ GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
- if (drawable)
- _gimp_drawable_preview_area_draw_thumb (area, drawable->drawable_id,
+ if (priv->drawable_ID > 0)
+ _gimp_drawable_preview_area_draw_thumb (area, priv->drawable_ID,
width, height);
}
@@ -587,7 +610,7 @@ gimp_zoom_preview_transform (GimpPreview *preview,
gint *dest_x,
gint *dest_y)
{
- GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
+ GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
gdouble zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
@@ -605,7 +628,7 @@ gimp_zoom_preview_untransform (GimpPreview *preview,
gint *dest_x,
gint *dest_y)
{
- GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
+ GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW (preview)->priv;
gdouble zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
@@ -622,25 +645,36 @@ static void
gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
GimpDrawable *drawable)
{
- GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
+ g_return_if_fail (preview->priv->drawable == NULL);
+ g_return_if_fail (preview->priv->drawable_ID < 1);
+
+ preview->priv->drawable = drawable;
+
+ gimp_zoom_preview_set_drawable_id (preview, drawable->drawable_id);
+}
+
+static void
+gimp_zoom_preview_set_drawable_id (GimpZoomPreview *preview,
+ gint32 drawable_ID)
+{
+ GimpZoomPreviewPrivate *priv = preview->priv;
gint x, y;
gint width, height;
gint max_width, max_height;
- g_return_if_fail (priv->drawable == NULL);
+ g_return_if_fail (preview->priv->drawable_ID < 1);
- priv->drawable = drawable;
+ priv->drawable_ID = drawable_ID;
- if (gimp_drawable_mask_intersect (drawable->drawable_id,
- &x, &y, &width, &height))
+ if (gimp_drawable_mask_intersect (drawable_ID, &x, &y, &width, &height))
{
priv->extents.x = x;
priv->extents.y = y;
}
else
{
- width = gimp_drawable_width (drawable->drawable_id);
- height = gimp_drawable_height (drawable->drawable_id);
+ width = gimp_drawable_width (drawable_ID);
+ height = gimp_drawable_height (drawable_ID);
priv->extents.x = 0;
priv->extents.y = 0;
@@ -726,11 +760,66 @@ gimp_zoom_preview_get_source_area (GimpPreview *preview,
/**
+ * gimp_zoom_preview_new_from_drawable_id:
+ * @drawable_ID: a drawable ID
+ *
+ * Creates a new #GimpZoomPreview widget for @drawable_ID.
+ *
+ * Since: 2.10
+ *
+ * Returns: a new #GimpZoomPreview.
+ **/
+GtkWidget *
+gimp_zoom_preview_new_from_drawable_id (gint32 drawable_ID)
+{
+ g_return_val_if_fail (gimp_item_is_valid (drawable_ID), NULL);
+ g_return_val_if_fail (gimp_item_is_drawable (drawable_ID), NULL);
+
+ return g_object_new (GIMP_TYPE_ZOOM_PREVIEW,
+ "drawable-id", drawable_ID,
+ NULL);
+}
+
+/**
+ * gimp_zoom_preview_new_with_model_from_drawable_id:
+ * @drawable_ID: a drawable ID
+ * @model: a #GimpZoomModel
+ *
+ * Creates a new #GimpZoomPreview widget for @drawable_ID using the
+ * given @model.
+ *
+ * This variant of gimp_zoom_preview_new_from_drawable_id() allows you
+ * 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 *
+gimp_zoom_preview_new_with_model_from_drawable_id (gint32 drawable_ID,
+ GimpZoomModel *model)
+
+{
+ g_return_val_if_fail (gimp_item_is_valid (drawable_ID), NULL);
+ g_return_val_if_fail (gimp_item_is_drawable (drawable_ID), NULL);
+ g_return_val_if_fail (GIMP_IS_ZOOM_MODEL (model), NULL);
+
+ return g_object_new (GIMP_TYPE_ZOOM_PREVIEW,
+ "drawable-id", drawable_ID,
+ "model", model,
+ NULL);
+}
+
+/**
* gimp_zoom_preview_new:
* @drawable: a #GimpDrawable
*
* Creates a new #GimpZoomPreview widget for @drawable.
*
+ * Deprecated: 2.10: Use gimp_zoom_preview_new_from_drawable_id() instead.
+ *
* Since: 2.4
*
* Returns: a new #GimpZoomPreview.
@@ -758,6 +847,9 @@ gimp_zoom_preview_new (GimpDrawable *drawable)
* example you want to have two zoom previews that keep their zoom
* factor in sync.
*
+ * Deprecated: 2.10: Use gimp_zoom_preview_new_with_model_from_drawable_id()
+ * instead.
+ *
* Since: 2.4
*
* Returns: a new #GimpZoomPreview.
@@ -778,6 +870,25 @@ gimp_zoom_preview_new_with_model (GimpDrawable *drawable,
/**
+ * gimp_zoom_preview_get_drawable_id:
+ * @preview: a #GimpZoomPreview widget
+ *
+ * Returns the drawable_ID the #GimpZoomPreview is attached to.
+ *
+ * Return Value: the drawable_ID that was passed to
+ * gimp_zoom_preview_new_from_drawable_id().
+ *
+ * Since: 2.10
+ **/
+gint32
+gimp_zoom_preview_get_drawable_id (GimpZoomPreview *preview)
+{
+ g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), NULL);
+
+ return GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview)->drawable_ID;
+}
+
+/**
* gimp_zoom_preview_get_drawable:
* @preview: a #GimpZoomPreview widget
*
@@ -785,6 +896,8 @@ gimp_zoom_preview_new_with_model (GimpDrawable *drawable,
*
* Return Value: the #GimpDrawable that was passed to gimp_zoom_preview_new().
*
+ * Deprecated: 2.10: Use gimp_zoom_preview_get_drawable_id() instead.
+ *
* Since: 2.4
**/
GimpDrawable *
@@ -860,14 +973,14 @@ gimp_zoom_preview_get_source (GimpZoomPreview *preview,
gint *height,
gint *bpp)
{
- GimpDrawable *drawable;
+ gint32 drawable_ID;
g_return_val_if_fail (GIMP_IS_ZOOM_PREVIEW (preview), NULL);
g_return_val_if_fail (width != NULL && height != NULL && bpp != NULL, NULL);
- drawable = gimp_zoom_preview_get_drawable (preview);
+ drawable_ID = gimp_zoom_preview_get_drawable_id (preview);
- if (drawable)
+ if (drawable_ID > 0)
{
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
gint src_x;
@@ -882,7 +995,7 @@ gimp_zoom_preview_get_source (GimpZoomPreview *preview,
&src_x, &src_y,
&src_width, &src_height);
- return gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
+ return gimp_drawable_get_sub_thumbnail_data (drawable_ID,
src_x, src_y,
src_width, src_height,
width, height, bpp);
diff --git a/libgimp/gimpzoompreview.h b/libgimp/gimpzoompreview.h
index f6ae383..ef7f45f 100644
--- a/libgimp/gimpzoompreview.h
+++ b/libgimp/gimpzoompreview.h
@@ -40,14 +40,15 @@ G_BEGIN_DECLS
#define GIMP_ZOOM_PREVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ZOOM_PREVIEW,
GimpZoomPreviewClass))
-typedef struct _GimpZoomPreviewClass GimpZoomPreviewClass;
+typedef struct _GimpZoomPreviewPrivate GimpZoomPreviewPrivate;
+typedef struct _GimpZoomPreviewClass GimpZoomPreviewClass;
struct _GimpZoomPreview
{
- GimpScrolledPreview parent_instance;
+ GimpScrolledPreview parent_instance;
/*< private >*/
- gpointer priv;
+ GimpZoomPreviewPrivate *priv;
};
struct _GimpZoomPreviewClass
@@ -64,8 +65,10 @@ struct _GimpZoomPreviewClass
GType gimp_zoom_preview_get_type (void) G_GNUC_CONST;
-GtkWidget * gimp_zoom_preview_new (GimpDrawable *drawable);
-GtkWidget * gimp_zoom_preview_new_with_model (GimpDrawable *drawable,
+GtkWidget * gimp_zoom_preview_new_from_drawable_id
+ (gint32 drawable_ID);
+GtkWidget * gimp_zoom_preview_new_with_model_from_drawable_id
+ (gint32 drawable_ID,
GimpZoomModel *model);
guchar * gimp_zoom_preview_get_source (GimpZoomPreview *preview,
@@ -73,10 +76,20 @@ guchar * gimp_zoom_preview_get_source (GimpZoomPreview *preview,
gint *height,
gint *bpp);
-GimpDrawable * gimp_zoom_preview_get_drawable (GimpZoomPreview *preview);
+gint32 gimp_zoom_preview_get_drawable_id(GimpZoomPreview *preview);
GimpZoomModel * gimp_zoom_preview_get_model (GimpZoomPreview *preview);
gdouble gimp_zoom_preview_get_factor (GimpZoomPreview *preview);
+GIMP_DEPRECATED_FOR(gimp_zoom_preview_new_from_drawable_id)
+GtkWidget * gimp_zoom_preview_new (GimpDrawable *drawable);
+GIMP_DEPRECATED_FOR(gimp_zoom_preview_new_with_model_from_drawable_id)
+GtkWidget * gimp_zoom_preview_new_with_model (GimpDrawable *drawable,
+ GimpZoomModel *model);
+
+GIMP_DEPRECATED_FOR(gimp_zoom_preview_get_drawable_id)
+GimpDrawable * gimp_zoom_preview_get_drawable (GimpZoomPreview *preview);
+
+
G_END_DECLS
#endif /* __GIMP_ZOOM_PREVIEW_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]