diff options
author | Benjamin Otte <otte@redhat.com> | 2012-07-11 06:56:07 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-08-28 15:40:56 +0200 |
commit | 9b953829fbf1332d00c2ca8a99c7da5e4bda8c64 (patch) | |
tree | d11d83a1dbe54909d5ee729a77b55bfa4393649d /gtk/gtkcssnumbervalue.c | |
parent | 3f00801e9aedd971378a6aad70e945903db7a798 (diff) | |
download | gtk+-9b953829fbf1332d00c2ca8a99c7da5e4bda8c64.tar.gz |
css: Introduce _gtk_css_value_compute()
This commit is essentially a large reorganization. Instead of all value
subtypes having their own compute function, there is the general
_gtk_css_value_compute() function that then calls a vfunc on the
subtype.
Diffstat (limited to 'gtk/gtkcssnumbervalue.c')
-rw-r--r-- | gtk/gtkcssnumbervalue.c | 121 |
1 files changed, 60 insertions, 61 deletions
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c index aab2bc2d56..c198e43764 100644 --- a/gtk/gtkcssnumbervalue.c +++ b/gtk/gtkcssnumbervalue.c @@ -33,6 +33,65 @@ gtk_css_value_number_free (GtkCssValue *value) g_slice_free (GtkCssValue, value); } +static GtkCssValue * +gtk_css_value_number_compute (GtkCssValue *number, + GtkStyleContext *context) +{ + switch (number->unit) + { + default: + g_assert_not_reached(); + /* fall through */ + case GTK_CSS_PERCENT: + case GTK_CSS_NUMBER: + case GTK_CSS_PX: + case GTK_CSS_DEG: + case GTK_CSS_S: + return _gtk_css_value_ref (number); + case GTK_CSS_PT: + return _gtk_css_number_value_new (number->value * 96.0 / 72.0, + GTK_CSS_PX); + case GTK_CSS_PC: + return _gtk_css_number_value_new (number->value * 96.0 / 72.0 * 12.0, + GTK_CSS_PX); + break; + case GTK_CSS_IN: + return _gtk_css_number_value_new (number->value * 96.0, + GTK_CSS_PX); + break; + case GTK_CSS_CM: + return _gtk_css_number_value_new (number->value * 96.0 * 0.39370078740157477, + GTK_CSS_PX); + break; + case GTK_CSS_MM: + return _gtk_css_number_value_new (number->value * 96.0 * 0.039370078740157477, + GTK_CSS_PX); + break; + case GTK_CSS_EM: + return _gtk_css_number_value_new (number->value * + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100), + GTK_CSS_PX); + break; + case GTK_CSS_EX: + /* for now we pretend ex is half of em */ + return _gtk_css_number_value_new (number->value * 0.5 * + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100), + GTK_CSS_PX); + case GTK_CSS_RAD: + return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI), + GTK_CSS_DEG); + case GTK_CSS_GRAD: + return _gtk_css_number_value_new (number->value * 360.0 / 400.0, + GTK_CSS_DEG); + case GTK_CSS_TURN: + return _gtk_css_number_value_new (number->value * 360.0, + GTK_CSS_DEG); + case GTK_CSS_MS: + return _gtk_css_number_value_new (number->value / 1000.0, + GTK_CSS_S); + } +} + static gboolean gtk_css_value_number_equal (const GtkCssValue *number1, const GtkCssValue *number2) @@ -88,6 +147,7 @@ gtk_css_value_number_print (const GtkCssValue *number, static const GtkCssValueClass GTK_CSS_VALUE_NUMBER = { gtk_css_value_number_free, + gtk_css_value_number_compute, gtk_css_value_number_equal, gtk_css_value_number_transition, gtk_css_value_number_print @@ -148,64 +208,3 @@ _gtk_css_number_value_get (const GtkCssValue *number, return number->value; } -GtkCssValue * -_gtk_css_number_value_compute (GtkCssValue *number, - GtkStyleContext *context) -{ - g_return_val_if_fail (number->class == >K_CSS_VALUE_NUMBER, NULL); - - switch (number->unit) - { - default: - g_assert_not_reached(); - /* fall through */ - case GTK_CSS_PERCENT: - case GTK_CSS_NUMBER: - case GTK_CSS_PX: - case GTK_CSS_DEG: - case GTK_CSS_S: - return _gtk_css_value_ref (number); - case GTK_CSS_PT: - return _gtk_css_number_value_new (number->value * 96.0 / 72.0, - GTK_CSS_PX); - case GTK_CSS_PC: - return _gtk_css_number_value_new (number->value * 96.0 / 72.0 * 12.0, - GTK_CSS_PX); - break; - case GTK_CSS_IN: - return _gtk_css_number_value_new (number->value * 96.0, - GTK_CSS_PX); - break; - case GTK_CSS_CM: - return _gtk_css_number_value_new (number->value * 96.0 * 0.39370078740157477, - GTK_CSS_PX); - break; - case GTK_CSS_MM: - return _gtk_css_number_value_new (number->value * 96.0 * 0.039370078740157477, - GTK_CSS_PX); - break; - case GTK_CSS_EM: - return _gtk_css_number_value_new (number->value * - _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100), - GTK_CSS_PX); - break; - case GTK_CSS_EX: - /* for now we pretend ex is half of em */ - return _gtk_css_number_value_new (number->value * 0.5 * - _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100), - GTK_CSS_PX); - case GTK_CSS_RAD: - return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI), - GTK_CSS_DEG); - case GTK_CSS_GRAD: - return _gtk_css_number_value_new (number->value * 360.0 / 400.0, - GTK_CSS_DEG); - case GTK_CSS_TURN: - return _gtk_css_number_value_new (number->value * 360.0, - GTK_CSS_DEG); - case GTK_CSS_MS: - return _gtk_css_number_value_new (number->value / 1000.0, - GTK_CSS_S); - } -} - |