gimp r25838 - in trunk: . libgimpwidgets
- From: neo svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r25838 - in trunk: . libgimpwidgets
- Date: Wed, 28 May 2008 11:49:24 +0000 (UTC)
Author: neo
Date: Wed May 28 11:49:24 2008
New Revision: 25838
URL: http://svn.gnome.org/viewvc/gimp?rev=25838&view=rev
Log:
2008-05-28 Sven Neumann <sven gimp org>
* libgimpwidgets/gimpruler.[ch]
* libgimpwidgets/gimphruler.c
* libgimpwidgets/gimpvruler.c: removed GimpRulerMetric struct from
public API. Removed gimp_ruler_draw_pos() and gimp_ruler_draw_ticks()
methods. Added a "unit" property with getter and setter.
* libgimpwidgets/gimpwidgets.def: updated.
Modified:
trunk/ChangeLog
trunk/libgimpwidgets/gimphruler.c
trunk/libgimpwidgets/gimpruler.c
trunk/libgimpwidgets/gimpruler.h
trunk/libgimpwidgets/gimpvruler.c
trunk/libgimpwidgets/gimpwidgets.def
Modified: trunk/libgimpwidgets/gimphruler.c
==============================================================================
--- trunk/libgimpwidgets/gimphruler.c (original)
+++ trunk/libgimpwidgets/gimphruler.c Wed May 28 11:49:24 2008
@@ -35,6 +35,17 @@
#define MAXIMUM_SUBDIVIDE 5
+static const struct
+{
+ gdouble ruler_scale[16];
+ gint subdivide[5]; /* five possible modes of subdivision */
+} ruler_metric =
+{
+ { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
+ { 1, 5, 10, 50, 100 }
+};
+
+
typedef struct
{
gint xsrc;
@@ -99,11 +110,9 @@
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
- position = lower + ((upper - lower) * x) / widget->allocation.width;
-
- g_object_set (ruler, "position", position, NULL);
-
- gimp_ruler_draw_pos (ruler);
+ gimp_ruler_set_position (ruler,
+ lower +
+ ((upper - lower) * x) / widget->allocation.width);
return FALSE;
}
@@ -111,8 +120,7 @@
static void
gimp_hruler_draw_ticks (GimpRuler *ruler)
{
- GtkWidget *widget = GTK_WIDGET (ruler);
- const GimpRulerMetric *metric;
+ GtkWidget *widget = GTK_WIDGET (ruler);
GdkDrawable *backing_store;
cairo_t *cr;
gint i;
@@ -167,8 +175,6 @@
gimp_ruler_get_range (ruler, &lower, &upper, &max_size);
- metric = _gimp_ruler_get_metric (ruler);
-
if ((upper - lower) == 0)
goto out;
@@ -183,19 +189,19 @@
g_snprintf (unit_str, sizeof (unit_str), "%d", scale);
text_width = strlen (unit_str) * digit_height + 1;
- for (scale = 0; scale < G_N_ELEMENTS (metric->ruler_scale); scale++)
- if (metric->ruler_scale[scale] * fabs (increment) > 2 * text_width)
+ for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++)
+ if (ruler_metric.ruler_scale[scale] * fabs (increment) > 2 * text_width)
break;
- if (scale == G_N_ELEMENTS (metric->ruler_scale))
- scale = G_N_ELEMENTS (metric->ruler_scale) - 1;
+ if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale))
+ scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1;
/* drawing starts here */
length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
{
- gdouble subd_incr = ((gdouble) metric->ruler_scale[scale] /
- (gdouble) metric->subdivide[i]);
+ gdouble subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] /
+ (gdouble) ruler_metric.subdivide[i]);
if (subd_incr * fabs (increment) <= MINIMUM_INCR)
continue;
Modified: trunk/libgimpwidgets/gimpruler.c
==============================================================================
--- trunk/libgimpwidgets/gimpruler.c (original)
+++ trunk/libgimpwidgets/gimpruler.c Wed May 28 11:49:24 2008
@@ -21,6 +21,8 @@
#include <gtk/gtk.h>
+#include "libgimpbase/gimpbase.h"
+
#include "gimpwidgetstypes.h"
#include "gimpruler.h"
@@ -31,51 +33,43 @@
*/
typedef struct
{
- GdkPixmap *backing_store;
- GdkGC *non_gr_exp_gc;
-
- /* The upper limit of the ruler (in points) */
+ GimpUnit unit;
gdouble lower;
- /* The lower limit of the ruler */
gdouble upper;
- /* The position of the mark on the ruler */
gdouble position;
- /* The maximum size of the ruler */
gdouble max_size;
+
+ GdkPixmap *backing_store;
+ GdkGC *non_gr_exp_gc;
} GimpRulerPrivate;
enum
{
PROP_0,
+ PROP_UNIT,
PROP_LOWER,
PROP_UPPER,
PROP_POSITION,
PROP_MAX_SIZE
};
-static void gimp_ruler_realize (GtkWidget *widget);
-static void gimp_ruler_unrealize (GtkWidget *widget);
-static void gimp_ruler_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static gint gimp_ruler_expose (GtkWidget *widget,
- GdkEventExpose *event);
-static void gimp_ruler_make_pixmap (GimpRuler *ruler);
-static void gimp_ruler_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gimp_ruler_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static const GimpRulerMetric ruler_metric =
-{
- {
- { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
- { 1, 5, 10, 50, 100 }
- }
-};
+static void gimp_ruler_realize (GtkWidget *widget);
+static void gimp_ruler_unrealize (GtkWidget *widget);
+static void gimp_ruler_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gint gimp_ruler_expose (GtkWidget *widget,
+ GdkEventExpose *event);
+static void gimp_ruler_draw_ticks (GimpRuler *ruler);
+static void gimp_ruler_draw_pos (GimpRuler *ruler);
+static void gimp_ruler_make_pixmap (GimpRuler *ruler);
+static void gimp_ruler_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gimp_ruler_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
G_DEFINE_TYPE (GimpRuler, gimp_ruler, GTK_TYPE_WIDGET)
@@ -104,6 +98,15 @@
g_object_class_install_property (object_class,
PROP_LOWER,
+ gimp_param_spec_unit ("unit",
+ "Unit",
+ "Unit of ruler",
+ TRUE, TRUE,
+ GIMP_UNIT_PIXEL,
+ GIMP_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_LOWER,
g_param_spec_double ("lower",
"Lower",
"Lower limit of ruler",
@@ -148,11 +151,13 @@
{
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
- priv->backing_store = NULL;
+ priv->unit = GIMP_PIXELS;
priv->lower = 0;
priv->upper = 0;
priv->position = 0;
priv->max_size = 0;
+ priv->backing_store = NULL;
+ priv->non_gr_exp_gc = NULL;
}
static void
@@ -166,6 +171,9 @@
switch (prop_id)
{
+ case PROP_UNIT:
+ gimp_ruler_set_unit (ruler, g_value_get_int (value));
+ break;
case PROP_LOWER:
gimp_ruler_set_range (ruler,
g_value_get_double (value),
@@ -204,6 +212,9 @@
switch (prop_id)
{
+ case PROP_UNIT:
+ g_value_set_int (value, priv->unit);
+ break;
case PROP_LOWER:
g_value_set_double (value, priv->lower);
break;
@@ -222,6 +233,59 @@
}
}
+/**
+ * gimp_ruler_set_position:
+ * @ruler: a #GimpRuler
+ * @unit: the #GimpUnit to set the ruler to
+ *
+ * This sets the unit of the ruler.
+ *
+ * Since: GIMP 2.8
+ */
+void
+gimp_ruler_set_unit (GimpRuler *ruler,
+ GimpUnit unit)
+{
+ GimpRulerPrivate *priv;
+
+ g_return_if_fail (GIMP_IS_RULER (ruler));
+
+ priv = GIMP_RULER_GET_PRIVATE (ruler);
+
+ if (priv->unit != unit)
+ {
+ priv->unit = unit;
+ g_object_notify (G_OBJECT (ruler), "unit");
+
+ gtk_widget_queue_draw (GTK_WIDGET (ruler));
+ }
+}
+
+/**
+ * gimp_ruler_get_unit:
+ * @ruler: a #GimpRuler
+ *
+ * Return value: the unit currently used in the @ruler widget.
+ *
+ * Since: GIMP 2.8
+ **/
+GimpUnit
+gimp_ruler_get_unit (GimpRuler *ruler)
+{
+ g_return_val_if_fail (GIMP_IS_RULER (ruler), 0);
+
+ return GIMP_RULER_GET_PRIVATE (ruler)->unit;
+}
+
+/**
+ * gimp_ruler_set_position:
+ * @ruler: a #GimpRuler
+ * @position: the position to set the ruler to
+ *
+ * This sets the position of the ruler.
+ *
+ * Since: GIMP 2.8
+ */
void
gimp_ruler_set_position (GimpRuler *ruler,
gdouble position)
@@ -236,13 +300,19 @@
{
priv->position = position;
g_object_notify (G_OBJECT (ruler), "position");
- }
- if (GTK_WIDGET_DRAWABLE (ruler))
- gtk_widget_queue_draw (GTK_WIDGET (ruler));
+ gimp_ruler_draw_pos (ruler);
+ }
}
-
+/**
+ * gimp_ruler_get_position:
+ * @ruler: a #GimpRuler
+ *
+ * Return value: the current position of the @ruler widget.
+ *
+ * Since: GIMP 2.8
+ **/
gdouble
gimp_ruler_get_position (GimpRuler *ruler)
{
@@ -253,7 +323,7 @@
/**
* gimp_ruler_set_range:
- * @ruler: the gtkruler
+ * @ruler: a #GimpRuler
* @lower: the lower limit of the ruler
* @upper: the upper limit of the ruler
* @max_size: the maximum size of the ruler used when calculating the space to
@@ -293,8 +363,7 @@
}
g_object_thaw_notify (G_OBJECT (ruler));
- if (GTK_WIDGET_DRAWABLE (ruler))
- gtk_widget_queue_draw (GTK_WIDGET (ruler));
+ gtk_widget_queue_draw (GTK_WIDGET (ruler));
}
/**
@@ -302,8 +371,8 @@
* @ruler: a #GimpRuler
* @lower: location to store lower limit of the ruler, or %NULL
* @upper: location to store upper limit of the ruler, or %NULL
- * @max_size: location to store the maximum size of the ruler used when calculating
- * the space to leave for the text, or %NULL.
+ * @max_size: location to store the maximum size of the ruler used when
+ * calculating the space to leave for the text, or %NULL.
*
* Retrieves values indicating the range and current position of a #GimpRuler.
* See gimp_ruler_set_range().
@@ -330,37 +399,12 @@
*max_size = priv->max_size;
}
-void
-gimp_ruler_draw_ticks (GimpRuler *ruler)
-{
- g_return_if_fail (GIMP_IS_RULER (ruler));
-
- if (GIMP_RULER_GET_CLASS (ruler)->draw_ticks)
- GIMP_RULER_GET_CLASS (ruler)->draw_ticks (ruler);
-}
-
-void
-gimp_ruler_draw_pos (GimpRuler *ruler)
-{
- g_return_if_fail (GIMP_IS_RULER (ruler));
-
- if (GIMP_RULER_GET_CLASS (ruler)->draw_pos)
- GIMP_RULER_GET_CLASS (ruler)->draw_pos (ruler);
-}
-
-
GdkDrawable *
_gimp_ruler_get_backing_store (GimpRuler *ruler)
{
return GIMP_RULER_GET_PRIVATE (ruler)->backing_store;
}
-const GimpRulerMetric *
-_gimp_ruler_get_metric (GimpRuler *ruler)
-{
- return &ruler_metric;
-}
-
PangoLayout *
_gimp_ruler_create_pango_layout (GtkWidget *widget,
const gchar *text)
@@ -483,6 +527,24 @@
}
static void
+gimp_ruler_draw_ticks (GimpRuler *ruler)
+{
+ g_return_if_fail (GIMP_IS_RULER (ruler));
+
+ if (GIMP_RULER_GET_CLASS (ruler)->draw_ticks)
+ GIMP_RULER_GET_CLASS (ruler)->draw_ticks (ruler);
+}
+
+static void
+gimp_ruler_draw_pos (GimpRuler *ruler)
+{
+ g_return_if_fail (GIMP_IS_RULER (ruler));
+
+ if (GIMP_RULER_GET_CLASS (ruler)->draw_pos)
+ GIMP_RULER_GET_CLASS (ruler)->draw_pos (ruler);
+}
+
+static void
gimp_ruler_make_pixmap (GimpRuler *ruler)
{
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
Modified: trunk/libgimpwidgets/gimpruler.h
==============================================================================
--- trunk/libgimpwidgets/gimpruler.h (original)
+++ trunk/libgimpwidgets/gimpruler.h Wed May 28 11:49:24 2008
@@ -32,7 +32,6 @@
typedef struct _GimpRulerClass GimpRulerClass;
-typedef struct _GimpRulerMetric GimpRulerMetric;
struct _GimpRuler
{
@@ -53,35 +52,28 @@
void (*_gimp_reserved4) (void);
};
-struct _GimpRulerMetric
-{
- gdouble ruler_scale[16];
- gint subdivide[5]; /* five possible modes of subdivision */
-};
-
-GType gimp_ruler_get_type (void) G_GNUC_CONST;
+GType gimp_ruler_get_type (void) G_GNUC_CONST;
-void gimp_ruler_set_position (GimpRuler *ruler,
- gdouble position);
-gdouble gimp_ruler_get_position (GimpRuler *ruler);
-void gimp_ruler_set_range (GimpRuler *ruler,
- gdouble lower,
- gdouble upper,
- gdouble max_size);
-void gimp_ruler_get_range (GimpRuler *ruler,
- gdouble *lower,
- gdouble *upper,
- gdouble *max_size);
-
-void gimp_ruler_draw_ticks (GimpRuler *ruler);
-void gimp_ruler_draw_pos (GimpRuler *ruler);
-
-
-GdkDrawable * _gimp_ruler_get_backing_store (GimpRuler *ruler) G_GNUC_INTERNAL;
-const GimpRulerMetric * _gimp_ruler_get_metric (GimpRuler *ruler) G_GNUC_INTERNAL;
-PangoLayout * _gimp_ruler_create_pango_layout (GtkWidget *widget,
- const gchar *text) G_GNUC_INTERNAL;
+void gimp_ruler_set_unit (GimpRuler *ruler,
+ GimpUnit unit);
+GimpUnit gimp_ruler_get_unit (GimpRuler *ruler);
+void gimp_ruler_set_position (GimpRuler *ruler,
+ gdouble position);
+gdouble gimp_ruler_get_position (GimpRuler *ruler);
+void gimp_ruler_set_range (GimpRuler *ruler,
+ gdouble lower,
+ gdouble upper,
+ gdouble max_size);
+void gimp_ruler_get_range (GimpRuler *ruler,
+ gdouble *lower,
+ gdouble *upper,
+ gdouble *max_size);
+
+
+GdkDrawable * _gimp_ruler_get_backing_store (GimpRuler *ruler) G_GNUC_INTERNAL;
+PangoLayout * _gimp_ruler_create_pango_layout (GtkWidget *widget,
+ const gchar *text) G_GNUC_INTERNAL;
G_END_DECLS
Modified: trunk/libgimpwidgets/gimpvruler.c
==============================================================================
--- trunk/libgimpwidgets/gimpvruler.c (original)
+++ trunk/libgimpwidgets/gimpvruler.c Wed May 28 11:49:24 2008
@@ -34,6 +34,16 @@
#define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
+static const struct
+{
+ gdouble ruler_scale[16];
+ gint subdivide[5]; /* five possible modes of subdivision */
+} ruler_metric =
+{
+ { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
+ { 1, 5, 10, 50, 100 }
+};
+
typedef struct
{
@@ -92,7 +102,6 @@
GimpRuler *ruler = GIMP_RULER (widget);
gdouble lower;
gdouble upper;
- gdouble position;
gint y;
gdk_event_request_motions (event);
@@ -100,10 +109,9 @@
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
- position = lower + ((upper - lower) * y) / widget->allocation.height;
- g_object_set (ruler, "position", position, NULL);
-
- gimp_ruler_draw_pos (ruler);
+ gimp_ruler_set_position (ruler,
+ lower +
+ ((upper - lower) * y) / widget->allocation.height);
return FALSE;
}
@@ -111,8 +119,7 @@
static void
gimp_vruler_draw_ticks (GimpRuler *ruler)
{
- GtkWidget *widget = GTK_WIDGET (ruler);
- const GimpRulerMetric *metric;
+ GtkWidget *widget = GTK_WIDGET (ruler);
GdkDrawable *backing_store;
cairo_t *cr;
gint i, j;
@@ -167,11 +174,6 @@
gimp_ruler_get_range (ruler, &lower, &upper, &max_size);
- metric = _gimp_ruler_get_metric (ruler);
-
- upper = upper;
- lower = lower;
-
if ((upper - lower) == 0)
goto out;
@@ -187,19 +189,19 @@
g_snprintf (unit_str, sizeof (unit_str), "%d", scale);
text_height = strlen (unit_str) * digit_height + 1;
- for (scale = 0; scale < G_N_ELEMENTS (metric->ruler_scale); scale++)
- if (metric->ruler_scale[scale] * fabs (increment) > 2 * text_height)
+ for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++)
+ if (ruler_metric.ruler_scale[scale] * fabs (increment) > 2 * text_height)
break;
- if (scale == G_N_ELEMENTS (metric->ruler_scale))
- scale = G_N_ELEMENTS (metric->ruler_scale) - 1;
+ if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale))
+ scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1;
/* drawing starts here */
length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
{
- gdouble subd_incr = ((gdouble) metric->ruler_scale[scale] /
- (gdouble) metric->subdivide[i]);
+ gdouble subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] /
+ (gdouble) ruler_metric.subdivide[i]);
if (subd_incr * fabs (increment) <= MINIMUM_INCR)
continue;
Modified: trunk/libgimpwidgets/gimpwidgets.def
==============================================================================
--- trunk/libgimpwidgets/gimpwidgets.def (original)
+++ trunk/libgimpwidgets/gimpwidgets.def Wed May 28 11:49:24 2008
@@ -303,13 +303,13 @@
gimp_radio_group_new2
gimp_radio_group_set_active
gimp_random_seed_new
- gimp_ruler_draw_pos
- gimp_ruler_draw_ticks
gimp_ruler_get_position
gimp_ruler_get_range
gimp_ruler_get_type
+ gimp_ruler_get_unit
gimp_ruler_set_position
gimp_ruler_set_range
+ gimp_ruler_set_unit
gimp_scale_entry_get_logarithmic
gimp_scale_entry_new
gimp_scale_entry_set_logarithmic
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]