mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 09:23:24 +00:00
This fixes all our GObject Introspection issues with GimpUnit which was both an enum and an int-derived type of user-defined units *completing* the enum values. GIR clearly didn't like this! Now GimpUnit is a proper class and units are unique objects, allowing to compare them with an identity test (i.e. `unit == gimp_unit_pixel ()` tells us if unit is the pixel unit or not), which makes it easy to use, just like with int, yet adding also methods, making for nicer introspected API. As an aside, this also fixes #10738, by having all the built-in units retrievable even if libgimpbase had not been properly initialized with gimp_base_init(). I haven't checked in details how GIR works to introspect, but it looks like it loads the library to inspect and runs functions, hence triggering some CRITICALS because virtual methods (supposed to be initialized with gimp_base_init() run by libgimp) are not set. This new code won't trigger any critical because the vtable method are now not necessary, at least for all built-in units. Note that GimpUnit is still in libgimpbase. It could have been moved to libgimp in order to avoid any virtual method table (since we need to keep core and libgimp side's units in sync, PDB is required), but too many libgimpwidgets widgets were already using GimpUnit. And technically most of GimpUnit logic doesn't require PDB (only the creation/sync part). This is one of the reasons why user-created GimpUnit list is handled and stored differently from other types of objects. Globally this simplifies the code a lot too and we don't need separate implementations of various utils for core and libgimp, which means less prone to errors.
This commit is contained in:
parent
f9df980585
commit
d493f0537f
170 changed files with 2362 additions and 3353 deletions
|
@ -3461,7 +3461,7 @@ gimp_prop_size_entry_new (GObject *config,
|
|||
gdouble value;
|
||||
gdouble lower;
|
||||
gdouble upper;
|
||||
GimpUnit unit_value;
|
||||
GimpUnit *unit_value;
|
||||
gint scaled_resolution;
|
||||
|
||||
param_spec = find_param_spec (config, property_name, G_STRFUNC);
|
||||
|
@ -3483,11 +3483,11 @@ gimp_prop_size_entry_new (GObject *config,
|
|||
|
||||
g_value_init (&value, unit_param_spec->value_type);
|
||||
|
||||
g_value_set_int (&value, GIMP_UNIT_PIXEL);
|
||||
g_value_set_object (&value, gimp_unit_pixel ());
|
||||
show_pixels = (g_param_value_validate (unit_param_spec,
|
||||
&value) == FALSE);
|
||||
|
||||
g_value_set_int (&value, GIMP_UNIT_PERCENT);
|
||||
g_value_set_object (&value, gimp_unit_percent ());
|
||||
show_percent = (g_param_value_validate (unit_param_spec,
|
||||
&value) == FALSE);
|
||||
|
||||
|
@ -3500,12 +3500,12 @@ gimp_prop_size_entry_new (GObject *config,
|
|||
else
|
||||
{
|
||||
unit_param_spec = NULL;
|
||||
unit_value = GIMP_UNIT_INCH;
|
||||
unit_value = gimp_unit_inch ();
|
||||
show_pixels = FALSE;
|
||||
show_percent = FALSE;
|
||||
}
|
||||
|
||||
if (unit_value != GIMP_UNIT_PIXEL)
|
||||
if (unit_value != gimp_unit_pixel ())
|
||||
scaled_resolution = gimp_unit_get_scaled_digits (unit_value, resolution);
|
||||
else
|
||||
scaled_resolution = (gint) resolution;
|
||||
|
@ -3584,7 +3584,7 @@ gimp_prop_size_entry_callback (GimpSizeEntry *entry,
|
|||
GParamSpec *unit_param_spec;
|
||||
gdouble value;
|
||||
gboolean value_is_pixel;
|
||||
GimpUnit unit_value;
|
||||
GimpUnit *unit_value;
|
||||
|
||||
param_spec = g_object_get_data (G_OBJECT (entry), "gimp-config-param-spec");
|
||||
if (! param_spec)
|
||||
|
@ -3605,7 +3605,7 @@ gimp_prop_size_entry_callback (GimpSizeEntry *entry,
|
|||
|
||||
if (unit_param_spec)
|
||||
{
|
||||
GimpUnit old_unit;
|
||||
GimpUnit *old_unit;
|
||||
|
||||
g_object_get (config,
|
||||
unit_param_spec->name, &old_unit,
|
||||
|
@ -3693,7 +3693,7 @@ gimp_prop_size_entry_notify_unit (GObject *config,
|
|||
GParamSpec *param_spec,
|
||||
GimpSizeEntry *entry)
|
||||
{
|
||||
GimpUnit value;
|
||||
GimpUnit *value;
|
||||
|
||||
g_object_get (config,
|
||||
param_spec->name, &value,
|
||||
|
@ -3783,7 +3783,7 @@ gimp_prop_coordinates_new (GObject *config,
|
|||
GtkWidget *entry;
|
||||
GtkWidget *chainbutton = NULL;
|
||||
|
||||
entry = gimp_size_entry_new (2, GIMP_UNIT_INCH, unit_format,
|
||||
entry = gimp_size_entry_new (2, gimp_unit_inch (), unit_format,
|
||||
FALSE, FALSE, TRUE, 10,
|
||||
update_policy);
|
||||
|
||||
|
@ -3829,7 +3829,7 @@ gimp_prop_coordinates_connect (GObject *config,
|
|||
GParamSpec *unit_param_spec;
|
||||
gdouble x_value, x_lower, x_upper;
|
||||
gdouble y_value, y_lower, y_upper;
|
||||
GimpUnit unit_value;
|
||||
GimpUnit *unit_value;
|
||||
gdouble *old_x_value;
|
||||
gdouble *old_y_value;
|
||||
GimpUnit *old_unit_value;
|
||||
|
@ -3869,7 +3869,7 @@ gimp_prop_coordinates_connect (GObject *config,
|
|||
else
|
||||
{
|
||||
unit_param_spec = NULL;
|
||||
unit_value = GIMP_UNIT_INCH;
|
||||
unit_value = gimp_unit_inch ();
|
||||
}
|
||||
|
||||
set_param_spec (NULL,
|
||||
|
@ -3957,11 +3957,10 @@ gimp_prop_coordinates_connect (GObject *config,
|
|||
g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec-unit",
|
||||
unit_param_spec);
|
||||
|
||||
old_unit_value = g_new0 (GimpUnit, 1);
|
||||
*old_unit_value = unit_value;
|
||||
old_unit_value = unit_value;
|
||||
g_object_set_data_full (G_OBJECT (entry), "old-unit-value",
|
||||
old_unit_value,
|
||||
(GDestroyNotify) g_free);
|
||||
(GDestroyNotify) NULL);
|
||||
|
||||
g_signal_connect (entry, "unit-changed",
|
||||
G_CALLBACK (gimp_prop_coordinates_callback),
|
||||
|
@ -3984,7 +3983,7 @@ gimp_prop_coordinates_callback (GimpSizeEntry *entry,
|
|||
GParamSpec *unit_param_spec;
|
||||
gdouble x_value;
|
||||
gdouble y_value;
|
||||
GimpUnit unit_value;
|
||||
GimpUnit *unit_value;
|
||||
gdouble *old_x_value;
|
||||
gdouble *old_y_value;
|
||||
GimpUnit *old_unit_value;
|
||||
|
@ -4038,14 +4037,14 @@ gimp_prop_coordinates_callback (GimpSizeEntry *entry,
|
|||
|
||||
if (*old_x_value == x_value &&
|
||||
*old_y_value == y_value &&
|
||||
(old_unit_value == NULL || *old_unit_value == unit_value))
|
||||
(old_unit_value == NULL || old_unit_value == unit_value))
|
||||
return;
|
||||
|
||||
*old_x_value = x_value;
|
||||
*old_y_value = y_value;
|
||||
|
||||
if (old_unit_value)
|
||||
*old_unit_value = unit_value;
|
||||
old_unit_value = unit_value;
|
||||
|
||||
if (unit_param_spec)
|
||||
g_object_set (config,
|
||||
|
@ -4182,7 +4181,7 @@ gimp_prop_coordinates_notify_unit (GObject *config,
|
|||
GParamSpec *param_spec,
|
||||
GimpSizeEntry *entry)
|
||||
{
|
||||
GimpUnit value;
|
||||
GimpUnit *value;
|
||||
|
||||
g_object_get (config,
|
||||
param_spec->name, &value,
|
||||
|
@ -4449,7 +4448,7 @@ gimp_prop_unit_combo_box_new (GObject *config,
|
|||
GParamSpec *param_spec;
|
||||
GtkWidget *combo;
|
||||
GtkTreeModel *model;
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit;
|
||||
GValue value = G_VALUE_INIT;
|
||||
gboolean show_pixels;
|
||||
gboolean show_percent;
|
||||
|
@ -4461,10 +4460,10 @@ gimp_prop_unit_combo_box_new (GObject *config,
|
|||
|
||||
g_value_init (&value, param_spec->value_type);
|
||||
|
||||
g_value_set_int (&value, GIMP_UNIT_PIXEL);
|
||||
g_value_set_object (&value, gimp_unit_pixel ());
|
||||
show_pixels = (g_param_value_validate (param_spec, &value) == FALSE);
|
||||
|
||||
g_value_set_int (&value, GIMP_UNIT_PERCENT);
|
||||
g_value_set_object (&value, gimp_unit_percent ());
|
||||
show_percent = (g_param_value_validate (param_spec, &value) == FALSE);
|
||||
|
||||
g_value_unset (&value);
|
||||
|
@ -4502,8 +4501,8 @@ gimp_prop_unit_combo_box_callback (GtkWidget *combo,
|
|||
GObject *config)
|
||||
{
|
||||
GParamSpec *param_spec;
|
||||
GimpUnit value;
|
||||
GimpUnit v;
|
||||
GimpUnit *value;
|
||||
GimpUnit *v;
|
||||
|
||||
param_spec = get_param_spec (G_OBJECT (combo));
|
||||
if (! param_spec)
|
||||
|
@ -4534,7 +4533,7 @@ gimp_prop_unit_combo_box_notify (GObject *config,
|
|||
GParamSpec *param_spec,
|
||||
GtkWidget *combo)
|
||||
{
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit;
|
||||
|
||||
g_object_get (config,
|
||||
param_spec->name, &unit,
|
||||
|
|
|
@ -459,7 +459,7 @@ gimp_query_size_box (const gchar *title,
|
|||
gdouble lower,
|
||||
gdouble upper,
|
||||
gint digits,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
gdouble resolution,
|
||||
gboolean dot_for_dot,
|
||||
GObject *object,
|
||||
|
@ -487,7 +487,7 @@ gimp_query_size_box (const gchar *title,
|
|||
sizeentry = gimp_size_entry_new (1, unit, "%p", TRUE, FALSE, FALSE, 12,
|
||||
GIMP_SIZE_ENTRY_UPDATE_SIZE);
|
||||
if (dot_for_dot)
|
||||
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), GIMP_UNIT_PIXEL);
|
||||
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), gimp_unit_pixel ());
|
||||
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
|
||||
resolution, FALSE);
|
||||
gimp_size_entry_set_refval_digits (GIMP_SIZE_ENTRY (sizeentry), 0, digits);
|
||||
|
@ -669,8 +669,8 @@ size_query_box_response (GtkWidget *widget,
|
|||
gint response_id,
|
||||
QueryBox *query_box)
|
||||
{
|
||||
gdouble size;
|
||||
GimpUnit unit;
|
||||
gdouble size;
|
||||
GimpUnit *unit;
|
||||
|
||||
query_box_disconnect (query_box);
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ typedef void (* GimpQueryDoubleCallback) (GtkWidget *query_box,
|
|||
**/
|
||||
typedef void (* GimpQuerySizeCallback) (GtkWidget *query_box,
|
||||
gdouble size,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
gpointer data);
|
||||
|
||||
/**
|
||||
|
@ -156,7 +156,7 @@ GtkWidget * gimp_query_size_box (const gchar *title,
|
|||
gdouble lower,
|
||||
gdouble upper,
|
||||
gint digits,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
gdouble resolution,
|
||||
gboolean dot_for_dot,
|
||||
GObject *object,
|
||||
|
|
|
@ -64,7 +64,7 @@ struct _GimpRuler
|
|||
GtkWidget parent_instance;
|
||||
|
||||
GtkOrientation orientation;
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit;
|
||||
gdouble lower;
|
||||
gdouble upper;
|
||||
gdouble position;
|
||||
|
@ -162,7 +162,7 @@ static void gimp_ruler_make_pixmap (GimpRuler *ruler);
|
|||
static PangoLayout * gimp_ruler_get_layout (GtkWidget *widget,
|
||||
const gchar *text);
|
||||
static const RulerMetric *
|
||||
gimp_ruler_get_metric (GimpUnit unit);
|
||||
gimp_ruler_get_metric (GimpUnit *unit);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpRuler, gimp_ruler, GTK_TYPE_WIDGET)
|
||||
|
@ -201,8 +201,7 @@ gimp_ruler_class_init (GimpRulerClass *klass)
|
|||
object_props[PROP_UNIT] = gimp_param_spec_unit ("unit",
|
||||
"Unit",
|
||||
"Unit of ruler",
|
||||
TRUE, TRUE,
|
||||
GIMP_UNIT_PIXEL,
|
||||
TRUE, TRUE, gimp_unit_pixel (),
|
||||
GIMP_PARAM_READWRITE);
|
||||
|
||||
object_props[PROP_LOWER] = g_param_spec_double ("lower",
|
||||
|
@ -248,7 +247,7 @@ gimp_ruler_init (GimpRuler *ruler)
|
|||
gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE);
|
||||
|
||||
ruler->orientation = GTK_ORIENTATION_HORIZONTAL;
|
||||
ruler->unit = GIMP_UNIT_PIXEL;
|
||||
ruler->unit = gimp_unit_pixel ();
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -284,7 +283,7 @@ gimp_ruler_set_property (GObject *object,
|
|||
break;
|
||||
|
||||
case PROP_UNIT:
|
||||
gimp_ruler_set_unit (ruler, g_value_get_int (value));
|
||||
gimp_ruler_set_unit (ruler, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
case PROP_LOWER:
|
||||
|
@ -332,7 +331,7 @@ gimp_ruler_get_property (GObject *object,
|
|||
break;
|
||||
|
||||
case PROP_UNIT:
|
||||
g_value_set_int (value, ruler->unit);
|
||||
g_value_set_object (value, ruler->unit);
|
||||
break;
|
||||
|
||||
case PROP_LOWER:
|
||||
|
@ -567,9 +566,10 @@ gimp_ruler_remove_track_widget (GimpRuler *ruler,
|
|||
*/
|
||||
void
|
||||
gimp_ruler_set_unit (GimpRuler *ruler,
|
||||
GimpUnit unit)
|
||||
GimpUnit *unit)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_RULER (ruler));
|
||||
g_return_if_fail (GIMP_IS_UNIT (unit));
|
||||
|
||||
if (ruler->unit != unit)
|
||||
{
|
||||
|
@ -589,7 +589,7 @@ gimp_ruler_set_unit (GimpRuler *ruler,
|
|||
*
|
||||
* Since: 2.8
|
||||
**/
|
||||
GimpUnit
|
||||
GimpUnit *
|
||||
gimp_ruler_get_unit (GimpRuler *ruler)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_RULER (ruler), 0);
|
||||
|
@ -976,7 +976,7 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
|
|||
gint text_size;
|
||||
gint pos;
|
||||
gdouble max_size;
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle logical_rect, ink_rect;
|
||||
const RulerMetric *ruler_metric;
|
||||
|
@ -1070,7 +1070,7 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
|
|||
gdouble subd_incr;
|
||||
|
||||
/* hack to get proper subdivisions at full pixels */
|
||||
if (unit == GIMP_UNIT_PIXEL && scale == 1 && i == 1)
|
||||
if (unit == gimp_unit_pixel () && scale == 1 && i == 1)
|
||||
subd_incr = 1.0;
|
||||
else
|
||||
subd_incr = ((gdouble) ruler_metric->ruler_scale[scale] /
|
||||
|
@ -1080,7 +1080,7 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
|
|||
continue;
|
||||
|
||||
/* don't subdivide pixels */
|
||||
if (unit == GIMP_UNIT_PIXEL && subd_incr < 1.0)
|
||||
if (unit == gimp_unit_pixel () && subd_incr < 1.0)
|
||||
continue;
|
||||
|
||||
/* Calculate the length of the tickmarks. Make sure that
|
||||
|
@ -1362,9 +1362,9 @@ gimp_ruler_get_layout (GtkWidget *widget,
|
|||
#define FACTOR_EQUAL(u, f) (ABS (f - gimp_unit_get_factor (u)) < FACTOR_EPSILON)
|
||||
|
||||
static const RulerMetric *
|
||||
gimp_ruler_get_metric (GimpUnit unit)
|
||||
gimp_ruler_get_metric (GimpUnit *unit)
|
||||
{
|
||||
if (unit == GIMP_UNIT_INCH)
|
||||
if (unit == gimp_unit_inch ())
|
||||
{
|
||||
return &ruler_metric_inches;
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ void gimp_ruler_remove_track_widget (GimpRuler *ruler,
|
|||
GtkWidget *widget);
|
||||
|
||||
void gimp_ruler_set_unit (GimpRuler *ruler,
|
||||
GimpUnit unit);
|
||||
GimpUnit gimp_ruler_get_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);
|
||||
|
|
|
@ -109,7 +109,7 @@ typedef struct _GimpSizeEntryPrivate
|
|||
gint number_of_fields;
|
||||
|
||||
GtkWidget *unit_combo;
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit;
|
||||
gboolean menu_show_pixels;
|
||||
gboolean menu_show_percent;
|
||||
|
||||
|
@ -128,7 +128,7 @@ static void gimp_size_entry_update_refval (GimpSizeEntryField *gsef,
|
|||
static void gimp_size_entry_refval_callback (GtkAdjustment *adjustment,
|
||||
gpointer data);
|
||||
static void gimp_size_entry_update_unit (GimpSizeEntry *gse,
|
||||
GimpUnit unit);
|
||||
GimpUnit *unit);
|
||||
static void gimp_size_entry_unit_callback (GtkWidget *widget,
|
||||
GimpSizeEntry *sizeentry);
|
||||
static void gimp_size_entry_attach_eevl (GtkSpinButton *spin_button,
|
||||
|
@ -192,7 +192,7 @@ gimp_size_entry_init (GimpSizeEntry *gse)
|
|||
|
||||
priv = gimp_size_entry_get_instance_private (gse);
|
||||
|
||||
priv->unit = GIMP_UNIT_PIXEL;
|
||||
priv->unit = gimp_unit_pixel ();
|
||||
priv->menu_show_pixels = TRUE;
|
||||
priv->menu_show_percent = TRUE;
|
||||
priv->show_refval = FALSE;
|
||||
|
@ -269,7 +269,7 @@ gimp_size_entry_finalize (GObject *object)
|
|||
**/
|
||||
GtkWidget *
|
||||
gimp_size_entry_new (gint number_of_fields,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
const gchar *unit_format,
|
||||
gboolean menu_show_pixels,
|
||||
gboolean menu_show_percent,
|
||||
|
@ -333,8 +333,8 @@ gimp_size_entry_new (gint number_of_fields,
|
|||
(update_policy == GIMP_SIZE_ENTRY_UPDATE_SIZE) ? 0 : 3;
|
||||
gsef->stop_recursion = 0;
|
||||
|
||||
digits = ((unit == GIMP_UNIT_PIXEL) ?
|
||||
gsef->refval_digits : ((unit == GIMP_UNIT_PERCENT) ?
|
||||
digits = ((unit == gimp_unit_pixel ()) ?
|
||||
gsef->refval_digits : ((unit == gimp_unit_percent ()) ?
|
||||
2 : GIMP_SIZE_ENTRY_DIGITS (unit)));
|
||||
|
||||
gsef->value_adjustment = gtk_adjustment_new (gsef->value,
|
||||
|
@ -391,7 +391,7 @@ gimp_size_entry_new (gint number_of_fields,
|
|||
gtk_widget_show (gsef->refval_spinbutton);
|
||||
}
|
||||
|
||||
if (priv->menu_show_pixels && (unit == GIMP_UNIT_PIXEL) &&
|
||||
if (priv->menu_show_pixels && (unit == gimp_unit_pixel ()) &&
|
||||
! priv->show_refval)
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
|
||||
gsef->refval_digits);
|
||||
|
@ -507,15 +507,15 @@ gimp_size_entry_add_field (GimpSizeEntry *gse,
|
|||
gsef);
|
||||
}
|
||||
|
||||
digits = ((priv->unit == GIMP_UNIT_PIXEL) ? gsef->refval_digits :
|
||||
(priv->unit == GIMP_UNIT_PERCENT) ? 2 :
|
||||
digits = ((priv->unit == gimp_unit_pixel ()) ? gsef->refval_digits :
|
||||
(priv->unit == gimp_unit_percent ()) ? 2 :
|
||||
GIMP_SIZE_ENTRY_DIGITS (priv->unit));
|
||||
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (value_spinbutton), digits);
|
||||
|
||||
if (priv->menu_show_pixels &&
|
||||
!priv->show_refval &&
|
||||
(priv->unit == GIMP_UNIT_PIXEL))
|
||||
(priv->unit == gimp_unit_pixel ()))
|
||||
{
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
|
||||
gsef->refval_digits);
|
||||
|
@ -773,32 +773,26 @@ gimp_size_entry_set_value_boundaries (GimpSizeEntry *gse,
|
|||
break;
|
||||
|
||||
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
|
||||
switch (priv->unit)
|
||||
{
|
||||
case GIMP_UNIT_PIXEL:
|
||||
gimp_size_entry_set_refval_boundaries (gse, field,
|
||||
gsef->min_value,
|
||||
gsef->max_value);
|
||||
break;
|
||||
case GIMP_UNIT_PERCENT:
|
||||
gimp_size_entry_set_refval_boundaries (gse, field,
|
||||
gsef->lower +
|
||||
(gsef->upper - gsef->lower) *
|
||||
gsef->min_value / 100,
|
||||
gsef->lower +
|
||||
(gsef->upper - gsef->lower) *
|
||||
gsef->max_value / 100);
|
||||
break;
|
||||
default:
|
||||
gimp_size_entry_set_refval_boundaries (gse, field,
|
||||
gsef->min_value *
|
||||
gsef->resolution /
|
||||
gimp_unit_get_factor (priv->unit),
|
||||
gsef->max_value *
|
||||
gsef->resolution /
|
||||
gimp_unit_get_factor (priv->unit));
|
||||
break;
|
||||
}
|
||||
if (priv->unit == gimp_unit_pixel ())
|
||||
gimp_size_entry_set_refval_boundaries (gse, field,
|
||||
gsef->min_value,
|
||||
gsef->max_value);
|
||||
else if (priv->unit == gimp_unit_percent ())
|
||||
gimp_size_entry_set_refval_boundaries (gse, field,
|
||||
gsef->lower +
|
||||
(gsef->upper - gsef->lower) *
|
||||
gsef->min_value / 100,
|
||||
gsef->lower +
|
||||
(gsef->upper - gsef->lower) *
|
||||
gsef->max_value / 100);
|
||||
else
|
||||
gimp_size_entry_set_refval_boundaries (gse, field,
|
||||
gsef->min_value *
|
||||
gsef->resolution /
|
||||
gimp_unit_get_factor (priv->unit),
|
||||
gsef->max_value *
|
||||
gsef->resolution /
|
||||
gimp_unit_get_factor (priv->unit));
|
||||
break;
|
||||
|
||||
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
|
||||
|
@ -871,23 +865,16 @@ gimp_size_entry_update_value (GimpSizeEntryField *gsef,
|
|||
break;
|
||||
|
||||
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
|
||||
switch (priv->unit)
|
||||
{
|
||||
case GIMP_UNIT_PIXEL:
|
||||
gsef->refval = value;
|
||||
break;
|
||||
case GIMP_UNIT_PERCENT:
|
||||
gsef->refval =
|
||||
CLAMP (gsef->lower + (gsef->upper - gsef->lower) * value / 100,
|
||||
gsef->min_refval, gsef->max_refval);
|
||||
break;
|
||||
default:
|
||||
gsef->refval =
|
||||
CLAMP (value * gsef->resolution /
|
||||
gimp_unit_get_factor (priv->unit),
|
||||
gsef->min_refval, gsef->max_refval);
|
||||
break;
|
||||
}
|
||||
if (priv->unit == gimp_unit_pixel ())
|
||||
gsef->refval = value;
|
||||
else if (priv->unit == gimp_unit_percent ())
|
||||
gsef->refval = CLAMP (gsef->lower + (gsef->upper - gsef->lower) * value / 100,
|
||||
gsef->min_refval, gsef->max_refval);
|
||||
else
|
||||
gsef->refval = CLAMP (value * gsef->resolution /
|
||||
gimp_unit_get_factor (priv->unit),
|
||||
gsef->min_refval, gsef->max_refval);
|
||||
|
||||
if (priv->show_refval)
|
||||
gtk_adjustment_set_value (gsef->refval_adjustment, gsef->refval);
|
||||
break;
|
||||
|
@ -1018,32 +1005,26 @@ gimp_size_entry_set_refval_boundaries (GimpSizeEntry *gse,
|
|||
break;
|
||||
|
||||
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
|
||||
switch (priv->unit)
|
||||
{
|
||||
case GIMP_UNIT_PIXEL:
|
||||
gimp_size_entry_set_value_boundaries (gse, field,
|
||||
gsef->min_refval,
|
||||
gsef->max_refval);
|
||||
break;
|
||||
case GIMP_UNIT_PERCENT:
|
||||
gimp_size_entry_set_value_boundaries (gse, field,
|
||||
100 * (gsef->min_refval -
|
||||
gsef->lower) /
|
||||
(gsef->upper - gsef->lower),
|
||||
100 * (gsef->max_refval -
|
||||
gsef->lower) /
|
||||
(gsef->upper - gsef->lower));
|
||||
break;
|
||||
default:
|
||||
gimp_size_entry_set_value_boundaries (gse, field,
|
||||
gsef->min_refval *
|
||||
gimp_unit_get_factor (priv->unit) /
|
||||
gsef->resolution,
|
||||
gsef->max_refval *
|
||||
gimp_unit_get_factor (priv->unit) /
|
||||
gsef->resolution);
|
||||
break;
|
||||
}
|
||||
if (priv->unit == gimp_unit_pixel ())
|
||||
gimp_size_entry_set_value_boundaries (gse, field,
|
||||
gsef->min_refval,
|
||||
gsef->max_refval);
|
||||
else if (priv->unit == gimp_unit_percent ())
|
||||
gimp_size_entry_set_value_boundaries (gse, field,
|
||||
100 * (gsef->min_refval -
|
||||
gsef->lower) /
|
||||
(gsef->upper - gsef->lower),
|
||||
100 * (gsef->max_refval -
|
||||
gsef->lower) /
|
||||
(gsef->upper - gsef->lower));
|
||||
else
|
||||
gimp_size_entry_set_value_boundaries (gse, field,
|
||||
gsef->min_refval *
|
||||
gimp_unit_get_factor (priv->unit) /
|
||||
gsef->resolution,
|
||||
gsef->max_refval *
|
||||
gimp_unit_get_factor (priv->unit) /
|
||||
gsef->resolution);
|
||||
break;
|
||||
|
||||
case GIMP_SIZE_ENTRY_UPDATE_RESOLUTION:
|
||||
|
@ -1102,7 +1083,7 @@ gimp_size_entry_set_refval_digits (GimpSizeEntry *gse,
|
|||
if (priv->show_refval)
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->refval_spinbutton),
|
||||
gsef->refval_digits);
|
||||
else if (priv->unit == GIMP_UNIT_PIXEL)
|
||||
else if (priv->unit == gimp_unit_pixel ())
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
|
||||
gsef->refval_digits);
|
||||
}
|
||||
|
@ -1157,23 +1138,16 @@ gimp_size_entry_update_refval (GimpSizeEntryField *gsef,
|
|||
break;
|
||||
|
||||
case GIMP_SIZE_ENTRY_UPDATE_SIZE:
|
||||
switch (priv->unit)
|
||||
{
|
||||
case GIMP_UNIT_PIXEL:
|
||||
gsef->value = refval;
|
||||
break;
|
||||
case GIMP_UNIT_PERCENT:
|
||||
gsef->value =
|
||||
CLAMP (100 * (refval - gsef->lower) / (gsef->upper - gsef->lower),
|
||||
gsef->min_value, gsef->max_value);
|
||||
break;
|
||||
default:
|
||||
gsef->value =
|
||||
CLAMP (refval * gimp_unit_get_factor (priv->unit) /
|
||||
gsef->resolution,
|
||||
gsef->min_value, gsef->max_value);
|
||||
break;
|
||||
}
|
||||
if (priv->unit == gimp_unit_pixel ())
|
||||
gsef->value = refval;
|
||||
else if (priv->unit == gimp_unit_percent ())
|
||||
gsef->value = CLAMP (100 * (refval - gsef->lower) / (gsef->upper - gsef->lower),
|
||||
gsef->min_value, gsef->max_value);
|
||||
else
|
||||
gsef->value = CLAMP (refval * gimp_unit_get_factor (priv->unit) /
|
||||
gsef->resolution,
|
||||
gsef->min_value, gsef->max_value);
|
||||
|
||||
gtk_adjustment_set_value (gsef->value_adjustment, gsef->value);
|
||||
break;
|
||||
|
||||
|
@ -1252,12 +1226,12 @@ gimp_size_entry_refval_callback (GtkAdjustment *adjustment,
|
|||
*
|
||||
* Returns: (transfer none): The sizeentry's unit.
|
||||
**/
|
||||
GimpUnit
|
||||
GimpUnit *
|
||||
gimp_size_entry_get_unit (GimpSizeEntry *gse)
|
||||
{
|
||||
GimpSizeEntryPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_SIZE_ENTRY (gse), GIMP_UNIT_INCH);
|
||||
g_return_val_if_fail (GIMP_IS_SIZE_ENTRY (gse), gimp_unit_inch ());
|
||||
|
||||
priv = gimp_size_entry_get_instance_private (gse);
|
||||
|
||||
|
@ -1266,7 +1240,7 @@ gimp_size_entry_get_unit (GimpSizeEntry *gse)
|
|||
|
||||
static void
|
||||
gimp_size_entry_update_unit (GimpSizeEntry *gse,
|
||||
GimpUnit unit)
|
||||
GimpUnit *unit)
|
||||
{
|
||||
GimpSizeEntryPrivate *priv = gimp_size_entry_get_instance_private (gse);
|
||||
GimpSizeEntryField *gsef;
|
||||
|
@ -1284,10 +1258,10 @@ gimp_size_entry_update_unit (GimpSizeEntry *gse,
|
|||
|
||||
if (priv->update_policy == GIMP_SIZE_ENTRY_UPDATE_SIZE)
|
||||
{
|
||||
if (unit == GIMP_UNIT_PIXEL)
|
||||
if (unit == gimp_unit_pixel ())
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
|
||||
gsef->refval_digits + digits);
|
||||
else if (unit == GIMP_UNIT_PERCENT)
|
||||
else if (unit == gimp_unit_percent ())
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
|
||||
2 + digits);
|
||||
else
|
||||
|
@ -1296,8 +1270,7 @@ gimp_size_entry_update_unit (GimpSizeEntry *gse,
|
|||
}
|
||||
else if (priv->update_policy == GIMP_SIZE_ENTRY_UPDATE_RESOLUTION)
|
||||
{
|
||||
digits = (gimp_unit_get_digits (GIMP_UNIT_INCH) -
|
||||
gimp_unit_get_digits (unit));
|
||||
digits = (gimp_unit_get_digits (gimp_unit_inch ()) - gimp_unit_get_digits (unit));
|
||||
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gsef->value_spinbutton),
|
||||
MAX (3 + digits, 3));
|
||||
}
|
||||
|
@ -1325,7 +1298,7 @@ gimp_size_entry_update_unit (GimpSizeEntry *gse,
|
|||
**/
|
||||
void
|
||||
gimp_size_entry_set_unit (GimpSizeEntry *gse,
|
||||
GimpUnit unit)
|
||||
GimpUnit *unit)
|
||||
{
|
||||
GimpSizeEntryPrivate *priv;
|
||||
|
||||
|
@ -1333,8 +1306,8 @@ gimp_size_entry_set_unit (GimpSizeEntry *gse,
|
|||
|
||||
priv = gimp_size_entry_get_instance_private (gse);
|
||||
|
||||
g_return_if_fail (priv->menu_show_pixels || (unit != GIMP_UNIT_PIXEL));
|
||||
g_return_if_fail (priv->menu_show_percent || (unit != GIMP_UNIT_PERCENT));
|
||||
g_return_if_fail (priv->menu_show_pixels || (unit != gimp_unit_pixel ()));
|
||||
g_return_if_fail (priv->menu_show_percent || (unit != gimp_unit_percent ()));
|
||||
|
||||
gimp_unit_combo_box_set_active (GIMP_UNIT_COMBO_BOX (priv->unit_combo), unit);
|
||||
gimp_size_entry_update_unit (gse, unit);
|
||||
|
@ -1345,7 +1318,7 @@ gimp_size_entry_unit_callback (GtkWidget *widget,
|
|||
GimpSizeEntry *gse)
|
||||
{
|
||||
GimpSizeEntryPrivate *priv;
|
||||
GimpUnit new_unit;
|
||||
GimpUnit *new_unit;
|
||||
|
||||
new_unit = gimp_unit_combo_box_get_active (GIMP_UNIT_COMBO_BOX (widget));
|
||||
|
||||
|
@ -1449,14 +1422,14 @@ gimp_size_entry_eevl_input_callback (GtkSpinButton *spinner,
|
|||
gtk_widget_error_bell (GTK_WIDGET (spinner));
|
||||
return GTK_INPUT_ERROR;
|
||||
}
|
||||
else if (result.dimension != 1 && priv->unit != GIMP_UNIT_PERCENT)
|
||||
else if (result.dimension != 1 && priv->unit != gimp_unit_percent ())
|
||||
{
|
||||
g_printerr ("ERROR: result has wrong dimension (expected 1, got %d)\n", result.dimension);
|
||||
|
||||
gtk_widget_error_bell (GTK_WIDGET (spinner));
|
||||
return GTK_INPUT_ERROR;
|
||||
}
|
||||
else if (result.dimension != 0 && priv->unit == GIMP_UNIT_PERCENT)
|
||||
else if (result.dimension != 0 && priv->unit == gimp_unit_percent ())
|
||||
{
|
||||
g_printerr ("ERROR: result has wrong dimension (expected 0, got %d)\n", result.dimension);
|
||||
|
||||
|
@ -1470,20 +1443,20 @@ gimp_size_entry_eevl_input_callback (GtkSpinButton *spinner,
|
|||
GtkAdjustment *adj;
|
||||
gdouble val;
|
||||
|
||||
switch (priv->unit)
|
||||
if (priv->unit == gimp_unit_pixel ())
|
||||
{
|
||||
case GIMP_UNIT_PIXEL:
|
||||
ui_unit.value = gsef->resolution;
|
||||
ui_unit.dimension = 1;
|
||||
break;
|
||||
case GIMP_UNIT_PERCENT:
|
||||
}
|
||||
else if (priv->unit == gimp_unit_percent ())
|
||||
{
|
||||
ui_unit.value = 1.0;
|
||||
ui_unit.dimension = 0;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
else
|
||||
{
|
||||
ui_unit.value = gimp_unit_get_factor(priv->unit);
|
||||
ui_unit.dimension = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
*return_val = result.value * ui_unit.value;
|
||||
|
@ -1517,7 +1490,8 @@ gimp_size_entry_eevl_unit_resolver (const gchar *identifier,
|
|||
GimpSizeEntryField *gsef = (GimpSizeEntryField *) data;
|
||||
GimpSizeEntryPrivate *priv;
|
||||
gboolean resolve_default_unit = (identifier == NULL);
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit = gimp_unit_pixel ();
|
||||
gint i = 1;
|
||||
|
||||
g_return_val_if_fail (gsef, FALSE);
|
||||
g_return_val_if_fail (factor != NULL, FALSE);
|
||||
|
@ -1528,23 +1502,16 @@ gimp_size_entry_eevl_unit_resolver (const gchar *identifier,
|
|||
|
||||
*offset = 0.0;
|
||||
|
||||
for (unit = 0;
|
||||
unit <= gimp_unit_get_number_of_units ();
|
||||
unit++)
|
||||
while (unit != NULL)
|
||||
{
|
||||
/* Hack to handle percent within the loop */
|
||||
if (unit == gimp_unit_get_number_of_units ())
|
||||
unit = GIMP_UNIT_PERCENT;
|
||||
|
||||
if ((resolve_default_unit && unit == priv->unit) ||
|
||||
(identifier &&
|
||||
(strcmp (gimp_unit_get_symbol (unit), identifier) == 0 ||
|
||||
strcmp (gimp_unit_get_abbreviation (unit), identifier) == 0)))
|
||||
{
|
||||
switch (unit)
|
||||
if (unit == gimp_unit_percent ())
|
||||
{
|
||||
case GIMP_UNIT_PERCENT:
|
||||
if (priv->unit == GIMP_UNIT_PERCENT)
|
||||
if (priv->unit == gimp_unit_percent ())
|
||||
{
|
||||
factor->value = 1;
|
||||
factor->dimension = 0;
|
||||
|
@ -1559,15 +1526,17 @@ gimp_size_entry_eevl_unit_resolver (const gchar *identifier,
|
|||
}
|
||||
/* return here, don't perform percentage conversion */
|
||||
return TRUE;
|
||||
case GIMP_UNIT_PIXEL:
|
||||
factor->value = gsef->resolution;
|
||||
break;
|
||||
default:
|
||||
factor->value = gimp_unit_get_factor (unit);
|
||||
break;
|
||||
}
|
||||
else if (unit == gimp_unit_pixel ())
|
||||
{
|
||||
factor->value = gsef->resolution;
|
||||
}
|
||||
else
|
||||
{
|
||||
factor->value = gimp_unit_get_factor (unit);
|
||||
}
|
||||
|
||||
if (priv->unit == GIMP_UNIT_PERCENT)
|
||||
if (priv->unit == gimp_unit_percent ())
|
||||
{
|
||||
/* map non-percentages onto percent */
|
||||
factor->value = gsef->upper/(100*gsef->resolution);
|
||||
|
@ -1581,6 +1550,12 @@ gimp_size_entry_eevl_unit_resolver (const gchar *identifier,
|
|||
/* We are done */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
unit = gimp_unit_get_by_id (i++);
|
||||
|
||||
/* Hack to handle percent within the loop */
|
||||
if (unit == NULL && unit != gimp_unit_percent ())
|
||||
unit = gimp_unit_percent ();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
|
|
@ -58,7 +58,7 @@ struct _GimpSizeEntryClass
|
|||
/* For information look into the C source or the html documentation */
|
||||
|
||||
GtkWidget * gimp_size_entry_new (gint number_of_fields,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
const gchar *unit_format,
|
||||
gboolean menu_show_pixels,
|
||||
gboolean menu_show_percent,
|
||||
|
@ -116,9 +116,9 @@ void gimp_size_entry_set_refval (GimpSizeEntry *gse,
|
|||
gint field,
|
||||
gdouble refval);
|
||||
|
||||
GimpUnit gimp_size_entry_get_unit (GimpSizeEntry *gse);
|
||||
GimpUnit * gimp_size_entry_get_unit (GimpSizeEntry *gse);
|
||||
void gimp_size_entry_set_unit (GimpSizeEntry *gse,
|
||||
GimpUnit unit);
|
||||
GimpUnit *unit);
|
||||
void gimp_size_entry_show_unit_menu (GimpSizeEntry *gse,
|
||||
gboolean show);
|
||||
|
||||
|
|
|
@ -173,13 +173,13 @@ gimp_unit_combo_box_new_with_model (GimpUnitStore *model)
|
|||
*
|
||||
* Returns: (transfer none): The selected #GimpUnit.
|
||||
**/
|
||||
GimpUnit
|
||||
GimpUnit *
|
||||
gimp_unit_combo_box_get_active (GimpUnitComboBox *combo)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gint unit;
|
||||
GtkTreeIter iter;
|
||||
GimpUnit *unit;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo), -1);
|
||||
g_return_val_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo), NULL);
|
||||
|
||||
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
|
||||
|
||||
|
@ -187,7 +187,7 @@ gimp_unit_combo_box_get_active (GimpUnitComboBox *combo)
|
|||
GIMP_UNIT_STORE_UNIT, &unit,
|
||||
-1);
|
||||
|
||||
return (GimpUnit) unit;
|
||||
return unit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,7 +199,7 @@ gimp_unit_combo_box_get_active (GimpUnitComboBox *combo)
|
|||
**/
|
||||
void
|
||||
gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
|
||||
GimpUnit unit)
|
||||
GimpUnit *unit)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
|
@ -215,13 +215,13 @@ gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
|
|||
iter_valid;
|
||||
iter_valid = gtk_tree_model_iter_next (model, &iter))
|
||||
{
|
||||
gint iter_unit;
|
||||
GimpUnit *iter_unit;
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
GIMP_UNIT_STORE_UNIT, &iter_unit,
|
||||
-1);
|
||||
|
||||
if (unit == (GimpUnit) iter_unit)
|
||||
if (unit == iter_unit)
|
||||
{
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
|
||||
break;
|
||||
|
|
|
@ -68,9 +68,9 @@ GType gimp_unit_combo_box_get_type (void) G_GNUC_CONST;
|
|||
GtkWidget * gimp_unit_combo_box_new (void);
|
||||
GtkWidget * gimp_unit_combo_box_new_with_model (GimpUnitStore *model);
|
||||
|
||||
GimpUnit gimp_unit_combo_box_get_active (GimpUnitComboBox *combo);
|
||||
GimpUnit * gimp_unit_combo_box_get_active (GimpUnitComboBox *combo);
|
||||
void gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
|
||||
GimpUnit unit);
|
||||
GimpUnit *unit);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -51,17 +51,17 @@ enum
|
|||
|
||||
struct _GimpUnitStorePrivate
|
||||
{
|
||||
gint num_values;
|
||||
gboolean has_pixels;
|
||||
gboolean has_percent;
|
||||
gint num_values;
|
||||
gboolean has_pixels;
|
||||
gboolean has_percent;
|
||||
|
||||
gchar *short_format;
|
||||
gchar *long_format;
|
||||
gchar *short_format;
|
||||
gchar *long_format;
|
||||
|
||||
gdouble *values;
|
||||
gdouble *resolutions;
|
||||
gdouble *values;
|
||||
gdouble *resolutions;
|
||||
|
||||
GimpUnit synced_unit;
|
||||
GimpUnitID synced_ID;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(obj) (((GimpUnitStore *) (obj))->priv)
|
||||
|
@ -194,7 +194,7 @@ gimp_unit_store_init (GimpUnitStore *store)
|
|||
private->has_percent = FALSE;
|
||||
private->short_format = g_strdup ("%a");
|
||||
private->long_format = g_strdup ("%p");
|
||||
private->synced_unit = gimp_unit_get_number_of_units () - 1;
|
||||
private->synced_ID = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -340,43 +340,41 @@ gimp_unit_store_get_iter (GtkTreeModel *tree_model,
|
|||
{
|
||||
GimpUnitStorePrivate *private = GET_PRIVATE (tree_model);
|
||||
gint index;
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit = NULL;
|
||||
|
||||
g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
|
||||
|
||||
index = gtk_tree_path_get_indices (path)[0];
|
||||
|
||||
unit = index;
|
||||
|
||||
if (! private->has_pixels)
|
||||
unit++;
|
||||
index++;
|
||||
else if (index == 0)
|
||||
unit = gimp_unit_pixel ();
|
||||
|
||||
if (private->has_percent)
|
||||
if (unit == NULL && private->has_percent)
|
||||
{
|
||||
unit--;
|
||||
|
||||
if (private->has_pixels)
|
||||
{
|
||||
if (index == 0)
|
||||
unit = GIMP_UNIT_PIXEL;
|
||||
else if (index == 1)
|
||||
unit = GIMP_UNIT_PERCENT;
|
||||
if (index == 1)
|
||||
unit = gimp_unit_percent ();
|
||||
}
|
||||
else
|
||||
else if (index == 0)
|
||||
{
|
||||
if (index == 0)
|
||||
unit = GIMP_UNIT_PERCENT;
|
||||
unit = gimp_unit_percent ();
|
||||
}
|
||||
index--;
|
||||
}
|
||||
|
||||
if ((unit >= 0 && unit < gimp_unit_get_number_of_units ()) ||
|
||||
((unit == GIMP_UNIT_PERCENT && private->has_percent)))
|
||||
if (unit == NULL)
|
||||
unit = gimp_unit_get_by_id (index);
|
||||
|
||||
if (unit != NULL)
|
||||
{
|
||||
iter->user_data = GINT_TO_POINTER (unit);
|
||||
return TRUE;
|
||||
iter->user_data = unit;
|
||||
private->synced_ID = MAX (private->synced_ID, gimp_unit_get_id (unit));
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return (unit != NULL);
|
||||
}
|
||||
|
||||
static GtkTreePath *
|
||||
|
@ -385,10 +383,10 @@ gimp_unit_store_get_path (GtkTreeModel *tree_model,
|
|||
{
|
||||
GimpUnitStorePrivate *private = GET_PRIVATE (tree_model);
|
||||
GtkTreePath *path = gtk_tree_path_new ();
|
||||
GimpUnit unit = GPOINTER_TO_INT (iter->user_data);
|
||||
GimpUnit *unit = iter->user_data;
|
||||
gint index;
|
||||
|
||||
index = unit;
|
||||
index = gimp_unit_get_id (unit);
|
||||
|
||||
if (! private->has_pixels)
|
||||
index--;
|
||||
|
@ -399,14 +397,14 @@ gimp_unit_store_get_path (GtkTreeModel *tree_model,
|
|||
|
||||
if (private->has_pixels)
|
||||
{
|
||||
if (unit == GIMP_UNIT_PIXEL)
|
||||
if (unit == gimp_unit_pixel ())
|
||||
index = 0;
|
||||
else if (unit == GIMP_UNIT_PERCENT)
|
||||
else if (unit == gimp_unit_percent ())
|
||||
index = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (unit == GIMP_UNIT_PERCENT)
|
||||
if (unit == gimp_unit_percent ())
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
@ -423,7 +421,7 @@ gimp_unit_store_tree_model_get_value (GtkTreeModel *tree_model,
|
|||
GValue *value)
|
||||
{
|
||||
GimpUnitStorePrivate *private = GET_PRIVATE (tree_model);
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit;
|
||||
|
||||
g_return_if_fail (column >= 0 &&
|
||||
column < GIMP_UNIT_STORE_UNIT_COLUMNS + private->num_values);
|
||||
|
@ -433,63 +431,59 @@ gimp_unit_store_tree_model_get_value (GtkTreeModel *tree_model,
|
|||
column_types[column] :
|
||||
G_TYPE_DOUBLE);
|
||||
|
||||
unit = GPOINTER_TO_INT (iter->user_data);
|
||||
unit = iter->user_data;
|
||||
|
||||
if ((unit >= 0 && unit < gimp_unit_get_number_of_units ()) ||
|
||||
((unit == GIMP_UNIT_PERCENT && private->has_percent)))
|
||||
switch (column)
|
||||
{
|
||||
switch (column)
|
||||
{
|
||||
case GIMP_UNIT_STORE_UNIT:
|
||||
g_value_set_int (value, unit);
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_FACTOR:
|
||||
g_value_set_double (value, gimp_unit_get_factor (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_DIGITS:
|
||||
g_value_set_int (value, gimp_unit_get_digits (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_IDENTIFIER:
|
||||
g_value_set_static_string (value, gimp_unit_get_identifier (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_SYMBOL:
|
||||
g_value_set_static_string (value, gimp_unit_get_symbol (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_ABBREVIATION:
|
||||
g_value_set_static_string (value, gimp_unit_get_abbreviation (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_SINGULAR:
|
||||
g_value_set_static_string (value, gimp_unit_get_singular (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_PLURAL:
|
||||
g_value_set_static_string (value, gimp_unit_get_plural (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_SHORT_FORMAT:
|
||||
g_value_take_string (value,
|
||||
gimp_unit_format_string (private->short_format,
|
||||
unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_LONG_FORMAT:
|
||||
g_value_take_string (value,
|
||||
gimp_unit_format_string (private->long_format,
|
||||
unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT:
|
||||
g_value_set_object (value, unit);
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_FACTOR:
|
||||
g_value_set_double (value, gimp_unit_get_factor (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_DIGITS:
|
||||
g_value_set_int (value, gimp_unit_get_digits (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_IDENTIFIER:
|
||||
g_value_set_static_string (value, gimp_unit_get_identifier (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_SYMBOL:
|
||||
g_value_set_static_string (value, gimp_unit_get_symbol (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_ABBREVIATION:
|
||||
g_value_set_static_string (value, gimp_unit_get_abbreviation (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_SINGULAR:
|
||||
g_value_set_static_string (value, gimp_unit_get_singular (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_PLURAL:
|
||||
g_value_set_static_string (value, gimp_unit_get_plural (unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_SHORT_FORMAT:
|
||||
g_value_take_string (value,
|
||||
gimp_unit_format_string (private->short_format,
|
||||
unit));
|
||||
break;
|
||||
case GIMP_UNIT_STORE_UNIT_LONG_FORMAT:
|
||||
g_value_take_string (value,
|
||||
gimp_unit_format_string (private->long_format,
|
||||
unit));
|
||||
break;
|
||||
|
||||
default:
|
||||
column -= GIMP_UNIT_STORE_UNIT_COLUMNS;
|
||||
if (unit == GIMP_UNIT_PIXEL)
|
||||
{
|
||||
g_value_set_double (value, private->values[column]);
|
||||
}
|
||||
else if (private->resolutions[column])
|
||||
{
|
||||
g_value_set_double (value,
|
||||
private->values[column] *
|
||||
gimp_unit_get_factor (unit) /
|
||||
private->resolutions[column]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
column -= GIMP_UNIT_STORE_UNIT_COLUMNS;
|
||||
if (unit == gimp_unit_pixel ())
|
||||
{
|
||||
g_value_set_double (value, private->values[column]);
|
||||
}
|
||||
else if (private->resolutions[column])
|
||||
{
|
||||
g_value_set_double (value,
|
||||
private->values[column] *
|
||||
gimp_unit_get_factor (unit) /
|
||||
private->resolutions[column]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -498,28 +492,18 @@ gimp_unit_store_iter_next (GtkTreeModel *tree_model,
|
|||
GtkTreeIter *iter)
|
||||
{
|
||||
GimpUnitStorePrivate *private = GET_PRIVATE (tree_model);
|
||||
GimpUnit unit = GPOINTER_TO_INT (iter->user_data);
|
||||
GimpUnit *unit = iter->user_data;
|
||||
|
||||
if (unit == GIMP_UNIT_PIXEL && private->has_percent)
|
||||
{
|
||||
unit = GIMP_UNIT_PERCENT;
|
||||
}
|
||||
else if (unit == GIMP_UNIT_PERCENT)
|
||||
{
|
||||
unit = GIMP_UNIT_INCH;
|
||||
}
|
||||
else if (unit >= 0 && unit < gimp_unit_get_number_of_units () - 1)
|
||||
{
|
||||
unit++;
|
||||
}
|
||||
if (unit == gimp_unit_pixel () && private->has_percent)
|
||||
unit = gimp_unit_percent ();
|
||||
else if (unit == gimp_unit_percent () || unit == gimp_unit_pixel ())
|
||||
unit = gimp_unit_inch ();
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
unit = gimp_unit_get_by_id (gimp_unit_get_id (unit) + 1);
|
||||
|
||||
iter->user_data = GINT_TO_POINTER (unit);
|
||||
iter->user_data = unit;
|
||||
|
||||
return TRUE;
|
||||
return (unit != NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -528,26 +512,20 @@ gimp_unit_store_iter_children (GtkTreeModel *tree_model,
|
|||
GtkTreeIter *parent)
|
||||
{
|
||||
GimpUnitStorePrivate *private = GET_PRIVATE (tree_model);
|
||||
GimpUnit unit;
|
||||
GimpUnit *unit;
|
||||
|
||||
/* this is a list, nodes have no children */
|
||||
if (parent)
|
||||
return FALSE;
|
||||
|
||||
if (private->has_pixels)
|
||||
{
|
||||
unit = GIMP_UNIT_PIXEL;
|
||||
}
|
||||
unit = gimp_unit_pixel ();
|
||||
else if (private->has_percent)
|
||||
{
|
||||
unit = GIMP_UNIT_PERCENT;
|
||||
}
|
||||
unit = gimp_unit_percent ();
|
||||
else
|
||||
{
|
||||
unit = GIMP_UNIT_INCH;
|
||||
}
|
||||
unit = gimp_unit_inch ();
|
||||
|
||||
iter->user_data = GINT_TO_POINTER (unit);
|
||||
iter->user_data = unit;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -563,13 +541,18 @@ static gint
|
|||
gimp_unit_store_iter_n_children (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GimpUnitStorePrivate *private = GET_PRIVATE (tree_model);
|
||||
gint n_children;
|
||||
GimpUnitStorePrivate *private = GET_PRIVATE (tree_model);
|
||||
GimpUnit *unit;
|
||||
gint n_children = GIMP_UNIT_END;
|
||||
|
||||
if (iter)
|
||||
return 0;
|
||||
|
||||
n_children = gimp_unit_get_number_of_units ();
|
||||
do
|
||||
unit = gimp_unit_get_by_id (n_children++);
|
||||
while (unit != NULL);
|
||||
|
||||
n_children--;
|
||||
|
||||
if (! private->has_pixels)
|
||||
n_children--;
|
||||
|
@ -596,30 +579,30 @@ gimp_unit_store_iter_nth_child (GtkTreeModel *tree_model,
|
|||
|
||||
if (n >= 0 && n < n_children)
|
||||
{
|
||||
GimpUnit unit = n;
|
||||
gint index = n;
|
||||
|
||||
if (! private->has_pixels)
|
||||
unit++;
|
||||
index++;
|
||||
|
||||
if (private->has_percent)
|
||||
{
|
||||
unit--;
|
||||
index--;
|
||||
|
||||
if (private->has_pixels)
|
||||
{
|
||||
if (n == 0)
|
||||
unit = GIMP_UNIT_PIXEL;
|
||||
index = GIMP_UNIT_PIXEL;
|
||||
else if (n == 1)
|
||||
unit = GIMP_UNIT_PERCENT;
|
||||
index = GIMP_UNIT_PERCENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n == 0)
|
||||
unit = GIMP_UNIT_PERCENT;
|
||||
index = GIMP_UNIT_PERCENT;
|
||||
}
|
||||
}
|
||||
|
||||
iter->user_data = GINT_TO_POINTER (unit);
|
||||
iter->user_data = gimp_unit_get_by_id (index);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -852,7 +835,7 @@ gimp_unit_store_set_resolutions (GimpUnitStore *store,
|
|||
|
||||
gdouble
|
||||
gimp_unit_store_get_nth_value (GimpUnitStore *store,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
gint index)
|
||||
{
|
||||
GimpUnitStorePrivate *private;
|
||||
|
@ -865,7 +848,7 @@ gimp_unit_store_get_nth_value (GimpUnitStore *store,
|
|||
|
||||
g_return_val_if_fail (index >= 0 && index < private->num_values, 0.0);
|
||||
|
||||
iter.user_data = GINT_TO_POINTER (unit);
|
||||
iter.user_data = unit;
|
||||
|
||||
gimp_unit_store_tree_model_get_value (GTK_TREE_MODEL (store),
|
||||
&iter,
|
||||
|
@ -877,7 +860,7 @@ gimp_unit_store_get_nth_value (GimpUnitStore *store,
|
|||
|
||||
void
|
||||
gimp_unit_store_get_values (GimpUnitStore *store,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
gdouble *first_value,
|
||||
...)
|
||||
{
|
||||
|
@ -920,14 +903,14 @@ _gimp_unit_store_sync_units (GimpUnitStore *store)
|
|||
iter_valid;
|
||||
iter_valid = gtk_tree_model_iter_next (model, &iter))
|
||||
{
|
||||
gint unit;
|
||||
GimpUnit *unit;
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
GIMP_UNIT_STORE_UNIT, &unit,
|
||||
-1);
|
||||
|
||||
if (unit != GIMP_UNIT_PERCENT &&
|
||||
unit > private->synced_unit)
|
||||
if (unit != gimp_unit_percent () &&
|
||||
gimp_unit_get_id (unit) > private->synced_ID)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
|
||||
|
@ -935,7 +918,7 @@ _gimp_unit_store_sync_units (GimpUnitStore *store)
|
|||
gtk_tree_model_row_inserted (model, path, &iter);
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
}
|
||||
|
||||
private->synced_unit = gimp_unit_get_number_of_units () - 1;
|
||||
g_object_unref (unit);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,10 +105,10 @@ void gimp_unit_store_set_resolutions (GimpUnitStore *store,
|
|||
gdouble first_resolution,
|
||||
...);
|
||||
gdouble gimp_unit_store_get_nth_value (GimpUnitStore *store,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
gint index);
|
||||
void gimp_unit_store_get_values (GimpUnitStore *store,
|
||||
GimpUnit unit,
|
||||
GimpUnit *unit,
|
||||
gdouble *first_value,
|
||||
...);
|
||||
|
||||
|
|
|
@ -449,7 +449,7 @@ gimp_coordinates_chainbutton_toggled (GimpChainButton *button,
|
|||
* Returns: (transfer full): The new #GimpSizeEntry.
|
||||
**/
|
||||
GtkWidget *
|
||||
gimp_coordinates_new (GimpUnit unit,
|
||||
gimp_coordinates_new (GimpUnit *unit,
|
||||
const gchar *unit_format,
|
||||
gboolean menu_show_pixels,
|
||||
gboolean menu_show_percent,
|
||||
|
@ -507,7 +507,7 @@ gimp_coordinates_new (GimpUnit unit,
|
|||
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry),
|
||||
(update_policy == GIMP_SIZE_ENTRY_UPDATE_RESOLUTION) ||
|
||||
(menu_show_pixels == FALSE) ?
|
||||
GIMP_UNIT_INCH : GIMP_UNIT_PIXEL);
|
||||
gimp_unit_inch () : gimp_unit_pixel ());
|
||||
|
||||
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0, xres, TRUE);
|
||||
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 1, yres, TRUE);
|
||||
|
|
|
@ -160,7 +160,7 @@ GtkWidget * gimp_random_seed_new (guint32 *seed,
|
|||
#define GIMP_COORDINATES_CHAINBUTTON(sizeentry) \
|
||||
(g_object_get_data (G_OBJECT (sizeentry), "chainbutton"))
|
||||
|
||||
GtkWidget * gimp_coordinates_new (GimpUnit unit,
|
||||
GtkWidget * gimp_coordinates_new (GimpUnit *unit,
|
||||
const gchar *unit_format,
|
||||
gboolean menu_show_pixels,
|
||||
gboolean menu_show_percent,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue