[gimp] app: add gimp_prop_widget_set_factor()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add gimp_prop_widget_set_factor()
- Date: Fri, 14 Jun 2013 23:38:54 +0000 (UTC)
commit 731360a8f7ea6857b05401a6910876fa6da12aa0
Author: Michael Natterer <mitch gimp org>
Date: Sat Jun 15 01:28:54 2013 +0200
app: add gimp_prop_widget_set_factor()
which allows adjustment-based prop widgets to display the property
value multiplied by factor. Remove gimp_prop_opacity_spin_scale_new()
because that's simply a factor of 100.0.
app/tools/gimppaintoptions-gui.c | 6 +-
app/tools/gimptransformoptions.c | 6 +-
app/widgets/gimppropwidgets.c | 125 +++++++++++++++++---------------------
app/widgets/gimppropwidgets.h | 86 +++++++++++++-------------
4 files changed, 106 insertions(+), 117 deletions(-)
---
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index 0275db9..eb78f33 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -98,8 +98,10 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
}
/* the opacity scale */
- scale = gimp_prop_opacity_spin_scale_new (config, "opacity",
- _("Opacity"));
+ scale = gimp_prop_spin_scale_new (config, "opacity",
+ _("Opacity"),
+ 0.01, 0.1, 0);
+ gimp_prop_widget_set_factor (scale, 100.0, 1);
gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
gtk_widget_show (scale);
diff --git a/app/tools/gimptransformoptions.c b/app/tools/gimptransformoptions.c
index 769781a..d6b6c09 100644
--- a/app/tools/gimptransformoptions.c
+++ b/app/tools/gimptransformoptions.c
@@ -412,8 +412,10 @@ gimp_transform_options_gui (GimpToolOptions *tool_options)
gtk_widget_show (combo);
/* the preview frame */
- scale = gimp_prop_opacity_spin_scale_new (config, "preview-opacity",
- _("Image opacity"));
+ scale = gimp_prop_spin_scale_new (config, "preview-opacity",
+ _("Image opacity"),
+ 0.01, 0.1, 0);
+ gimp_prop_widget_set_factor (scale, 100.0, 1);
frame = gimp_prop_expanding_frame_new (config, "show-preview",
_("Show image preview"),
scale, NULL);
diff --git a/app/widgets/gimppropwidgets.c b/app/widgets/gimppropwidgets.c
index f97b564..ad72d17 100644
--- a/app/widgets/gimppropwidgets.c
+++ b/app/widgets/gimppropwidgets.c
@@ -528,58 +528,51 @@ gimp_prop_spin_scale_new (GObject *config,
return scale;
}
-/**
- * gimp_prop_opacity_spin_scale_new:
- * @config: #GimpConfig object to which property is attached.
- * @property_name: Name of gdouble property
- *
- * Creates a #GimpSpinScale to set and display the value of a
- * gdouble property in a very space-efficient way.
- *
- * Return value: A new #GimpSpinScale widget.
- *
- * Since GIMP 2.8
- */
-GtkWidget *
-gimp_prop_opacity_spin_scale_new (GObject *config,
- const gchar *property_name,
- const gchar *label)
+void
+gimp_prop_widget_set_factor (GtkWidget *widget,
+ gdouble factor,
+ gint digits)
{
- GParamSpec *param_spec;
- GtkObject *adjustment;
- GtkWidget *scale;
- gdouble value;
- gdouble lower;
- gdouble upper;
+ GtkAdjustment *adjustment;
+ gdouble *factor_store;
+ gdouble old_factor = 1.0;
+ gdouble f;
- param_spec = check_param_spec_w (config, property_name,
- G_TYPE_PARAM_DOUBLE, G_STRFUNC);
- if (! param_spec)
- return NULL;
-
- g_object_get (config, property_name, &value, NULL);
+ g_return_if_fail (GTK_IS_SPIN_BUTTON (widget));
+ g_return_if_fail (factor != 0.0);
+ g_return_if_fail (digits >= 0);
- value *= 100.0;
- lower = G_PARAM_SPEC_DOUBLE (param_spec)->minimum * 100.0;
- upper = G_PARAM_SPEC_DOUBLE (param_spec)->maximum * 100.0;
+ adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
- adjustment = gtk_adjustment_new (value, lower, upper, 1.0, 10.0, 0.0);
+ g_return_if_fail (get_param_spec (G_OBJECT (adjustment)) != NULL);
- scale = gimp_spin_scale_new (GTK_ADJUSTMENT (adjustment), label, 1);
+ factor_store = g_object_get_data (G_OBJECT (adjustment),
+ "gimp-prop-adjustment-factor");
+ if (factor_store)
+ {
+ old_factor = *factor_store;
+ }
+ else
+ {
+ factor_store = g_new (gdouble, 1);
+ g_object_set_data_full (G_OBJECT (adjustment),
+ "gimp-prop-adjustment-factor",
+ factor_store, (GDestroyNotify) g_free);
+ }
- set_param_spec (G_OBJECT (adjustment), scale, param_spec);
- g_object_set_data (G_OBJECT (adjustment),
- "opacity-scale", GINT_TO_POINTER (TRUE));
+ *factor_store = factor;
- g_signal_connect (adjustment, "value-changed",
- G_CALLBACK (gimp_prop_adjustment_callback),
- config);
+ f = factor / old_factor;
- connect_notify (config, property_name,
- G_CALLBACK (gimp_prop_adjustment_notify),
- adjustment);
+ gtk_adjustment_configure (adjustment,
+ f * gtk_adjustment_get_value (adjustment),
+ f * gtk_adjustment_get_lower (adjustment),
+ f * gtk_adjustment_get_upper (adjustment),
+ f * gtk_adjustment_get_step_increment (adjustment),
+ f * gtk_adjustment_get_page_increment (adjustment),
+ f * gtk_adjustment_get_page_size (adjustment));
- return scale;
+ gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), digits);
}
static void
@@ -588,6 +581,7 @@ gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
{
GParamSpec *param_spec;
gdouble value;
+ gdouble *factor;
param_spec = get_param_spec (G_OBJECT (adjustment));
if (! param_spec)
@@ -595,48 +589,37 @@ gimp_prop_adjustment_callback (GtkAdjustment *adjustment,
value = gtk_adjustment_get_value (adjustment);
+ factor = g_object_get_data (G_OBJECT (adjustment),
+ "gimp-prop-adjustment-factor");
+ if (factor)
+ value /= *factor;
+
if (G_IS_PARAM_SPEC_INT (param_spec))
{
- g_object_set (config,
- param_spec->name, (gint) value,
- NULL);
+ g_object_set (config, param_spec->name, (gint) value, NULL);
}
else if (G_IS_PARAM_SPEC_UINT (param_spec))
{
- g_object_set (config,
- param_spec->name, (guint) value,
- NULL);
+ g_object_set (config, param_spec->name, (guint) value, NULL);
}
else if (G_IS_PARAM_SPEC_LONG (param_spec))
{
- g_object_set (config,
- param_spec->name, (glong) value,
- NULL);
+ g_object_set (config, param_spec->name, (glong) value, NULL);
}
else if (G_IS_PARAM_SPEC_ULONG (param_spec))
{
- g_object_set (config,
- param_spec->name, (gulong) value,
- NULL);
+ g_object_set (config, param_spec->name, (gulong) value, NULL);
}
else if (G_IS_PARAM_SPEC_INT64 (param_spec))
{
- g_object_set (config,
- param_spec->name, (gint64) value,
- NULL);
+ g_object_set (config, param_spec->name, (gint64) value, NULL);
}
else if (G_IS_PARAM_SPEC_UINT64 (param_spec))
{
- g_object_set (config,
- param_spec->name, (guint64) value,
- NULL);
+ g_object_set (config, param_spec->name, (guint64) value, NULL);
}
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
{
- if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
- "opacity-scale")))
- value /= 100.0;
-
g_object_set (config, param_spec->name, value, NULL);
}
}
@@ -646,7 +629,8 @@ gimp_prop_adjustment_notify (GObject *config,
GParamSpec *param_spec,
GtkAdjustment *adjustment)
{
- gdouble value;
+ gdouble value;
+ gdouble *factor;
if (G_IS_PARAM_SPEC_INT (param_spec))
{
@@ -703,10 +687,6 @@ gimp_prop_adjustment_notify (GObject *config,
else if (G_IS_PARAM_SPEC_DOUBLE (param_spec))
{
g_object_get (config, param_spec->name, &value, NULL);
-
- if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (adjustment),
- "opacity-scale")))
- value *= 100.0;
}
else
{
@@ -715,6 +695,11 @@ gimp_prop_adjustment_notify (GObject *config,
return;
}
+ factor = g_object_get_data (G_OBJECT (adjustment),
+ "gimp-prop-adjustment-factor");
+ if (factor)
+ value *= *factor;
+
if (gtk_adjustment_get_value (adjustment) != value)
{
g_signal_handlers_block_by_func (adjustment,
diff --git a/app/widgets/gimppropwidgets.h b/app/widgets/gimppropwidgets.h
index f1efe21..212c8ad 100644
--- a/app/widgets/gimppropwidgets.h
+++ b/app/widgets/gimppropwidgets.h
@@ -24,69 +24,69 @@
/* GParamBoolean */
-GtkWidget * gimp_prop_expanding_frame_new (GObject *config,
- const gchar *property_name,
- const gchar *button_label,
- GtkWidget *child,
- GtkWidget **button);
+GtkWidget * gimp_prop_expanding_frame_new (GObject *config,
+ const gchar *property_name,
+ const gchar *button_label,
+ GtkWidget *child,
+ GtkWidget **button);
/* GParamEnum */
-GtkWidget * gimp_prop_paint_mode_menu_new (GObject *config,
- const gchar *property_name,
- gboolean with_behind_mode,
- gboolean with_replace_modes);
+GtkWidget * gimp_prop_paint_mode_menu_new (GObject *config,
+ const gchar *property_name,
+ gboolean with_behind_mode,
+ gboolean with_replace_modes);
/* GimpParamColor */
-GtkWidget * gimp_prop_color_button_new (GObject *config,
- const gchar *property_name,
- const gchar *title,
- gint width,
- gint height,
- GimpColorAreaType type);
+GtkWidget * gimp_prop_color_button_new (GObject *config,
+ const gchar *property_name,
+ const gchar *title,
+ gint width,
+ gint height,
+ GimpColorAreaType type);
/* GParamDouble */
-GtkWidget * gimp_prop_scale_button_new (GObject *config,
- const gchar *property_name);
-GtkWidget * gimp_prop_spin_scale_new (GObject *config,
- const gchar *property_name,
- const gchar *label,
- gdouble step_increment,
- gdouble page_increment,
- gint digits);
-GtkWidget * gimp_prop_opacity_spin_scale_new (GObject *config,
- const gchar *property_name,
- const gchar *label);
+GtkWidget * gimp_prop_scale_button_new (GObject *config,
+ const gchar *property_name);
+GtkWidget * gimp_prop_spin_scale_new (GObject *config,
+ const gchar *property_name,
+ const gchar *label,
+ gdouble step_increment,
+ gdouble page_increment,
+ gint digits);
+
+void gimp_prop_widget_set_factor (GtkWidget *widget,
+ gdouble factor,
+ gint digits);
/* GParamObject (GimpViewable) */
-GtkWidget * gimp_prop_view_new (GObject *config,
- const gchar *property_name,
- GimpContext *context,
- gint size);
+GtkWidget * gimp_prop_view_new (GObject *config,
+ const gchar *property_name,
+ GimpContext *context,
+ gint size);
/* GParamDouble, GParamDouble, GParamDouble, GParamDouble, GParamBoolean */
-GtkWidget * gimp_prop_number_pair_entry_new
- (GObject *config,
- const gchar *left_number_property,
- const gchar *right_number_property,
- const gchar *default_left_number_property,
- const gchar *default_right_number_property,
- const gchar *user_override_property,
- gboolean connect_numbers_changed,
- gboolean connect_ratio_changed,
- const gchar *separators,
- gboolean allow_simplification,
- gdouble min_valid_value,
- gdouble max_valid_value);
+GtkWidget * gimp_prop_number_pair_entry_new (GObject *config,
+ const gchar *left_number_property,
+ const gchar *right_number_property,
+ const gchar *default_left_number_property,
+ const gchar *default_right_number_property,
+ const gchar *user_override_property,
+ gboolean connect_numbers_changed,
+ gboolean connect_ratio_changed,
+ const gchar *separators,
+ gboolean allow_simplification,
+ gdouble min_valid_value,
+ gdouble max_valid_value);
/* GParamString */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]