2012-03-27 22:04:29 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2016-02-12 05:25:50 +00:00
|
|
|
* Copyright (C) 2016 Benjamin Otte <otte@gnome.org>
|
2012-03-27 22:04:29 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
|
|
|
|
2016-02-12 05:56:14 +00:00
|
|
|
#include "gtkcsscalcvalueprivate.h"
|
2016-02-12 05:25:50 +00:00
|
|
|
#include "gtkcssdimensionvalueprivate.h"
|
2016-02-13 23:54:37 +00:00
|
|
|
#include "gtkcsswin32sizevalueprivate.h"
|
2015-12-23 10:58:42 +00:00
|
|
|
|
2012-03-27 22:04:29 +00:00
|
|
|
struct _GtkCssValue {
|
|
|
|
GTK_CSS_VALUE_BASE
|
|
|
|
};
|
|
|
|
|
2016-02-12 05:25:50 +00:00
|
|
|
GtkCssDimension
|
|
|
|
gtk_css_number_value_get_dimension (const GtkCssValue *value)
|
2012-03-30 15:47:26 +00:00
|
|
|
{
|
2016-02-12 05:25:50 +00:00
|
|
|
GtkCssNumberValueClass *number_value_class = (GtkCssNumberValueClass *) value->class;
|
2012-03-30 15:47:26 +00:00
|
|
|
|
2016-02-12 05:25:50 +00:00
|
|
|
return number_value_class->get_dimension (value);
|
2012-03-30 15:47:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 05:25:50 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_number_value_has_percent (const GtkCssValue *value)
|
2012-03-27 22:04:29 +00:00
|
|
|
{
|
2016-02-12 05:25:50 +00:00
|
|
|
GtkCssNumberValueClass *number_value_class = (GtkCssNumberValueClass *) value->class;
|
2012-03-27 22:04:29 +00:00
|
|
|
|
2016-02-12 05:25:50 +00:00
|
|
|
return number_value_class->has_percent (value);
|
2012-03-27 22:04:29 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 06:59:06 +00:00
|
|
|
GtkCssValue *
|
|
|
|
gtk_css_number_value_multiply (const GtkCssValue *value,
|
|
|
|
double factor)
|
|
|
|
{
|
|
|
|
GtkCssNumberValueClass *number_value_class = (GtkCssNumberValueClass *) value->class;
|
|
|
|
|
|
|
|
return number_value_class->multiply (value, factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssValue *
|
|
|
|
gtk_css_number_value_add (GtkCssValue *value1,
|
|
|
|
GtkCssValue *value2)
|
|
|
|
{
|
|
|
|
GtkCssValue *sum;
|
|
|
|
|
|
|
|
sum = gtk_css_number_value_try_add (value1, value2);
|
|
|
|
if (sum == NULL)
|
|
|
|
sum = gtk_css_calc_value_new_sum (value1, value2);
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssValue *
|
|
|
|
gtk_css_number_value_try_add (const GtkCssValue *value1,
|
|
|
|
const GtkCssValue *value2)
|
|
|
|
{
|
|
|
|
GtkCssNumberValueClass *number_value_class;
|
|
|
|
|
|
|
|
if (value1->class != value2->class)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
number_value_class = (GtkCssNumberValueClass *) value1->class;
|
|
|
|
|
|
|
|
return number_value_class->try_add (value1, value2);
|
|
|
|
}
|
|
|
|
|
2016-02-13 01:31:47 +00:00
|
|
|
/*
|
|
|
|
* gtk_css_number_value_get_calc_term_order:
|
|
|
|
* @value: Value to compute order for
|
|
|
|
*
|
|
|
|
* Determines the position of @value when printed as part of a calc()
|
|
|
|
* expression. Values with lower numbers are printed first. Note that
|
|
|
|
* these numbers are arbitrary, so when adding new types of values to
|
|
|
|
* print, feel free to change them in implementations so that they
|
|
|
|
* match.
|
|
|
|
*
|
|
|
|
* Returns: Magic value determining placement when printing calc()
|
|
|
|
* expression.
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gtk_css_number_value_get_calc_term_order (const GtkCssValue *value)
|
|
|
|
{
|
|
|
|
GtkCssNumberValueClass *number_value_class = (GtkCssNumberValueClass *) value->class;
|
|
|
|
|
|
|
|
return number_value_class->get_calc_term_order (value);
|
|
|
|
}
|
|
|
|
|
2012-03-27 22:04:29 +00:00
|
|
|
GtkCssValue *
|
|
|
|
_gtk_css_number_value_new (double value,
|
|
|
|
GtkCssUnit unit)
|
|
|
|
{
|
2016-02-12 05:25:50 +00:00
|
|
|
return gtk_css_dimension_value_new (value, unit);
|
2012-03-27 22:04:29 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 03:47:51 +00:00
|
|
|
GtkCssValue *
|
|
|
|
gtk_css_number_value_transition (GtkCssValue *start,
|
|
|
|
GtkCssValue *end,
|
|
|
|
guint property_id,
|
|
|
|
double progress)
|
|
|
|
{
|
|
|
|
GtkCssValue *result, *mul_start, *mul_end;
|
|
|
|
|
|
|
|
mul_start = gtk_css_number_value_multiply (start, 1 - progress);
|
|
|
|
mul_end = gtk_css_number_value_multiply (end, progress);
|
|
|
|
|
|
|
|
result = gtk_css_number_value_add (mul_start, mul_end);
|
|
|
|
|
|
|
|
_gtk_css_value_unref (mul_start);
|
|
|
|
_gtk_css_value_unref (mul_end);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-12 05:45:06 +00:00
|
|
|
gboolean
|
|
|
|
gtk_css_number_value_can_parse (GtkCssParser *parser)
|
|
|
|
{
|
2016-02-12 05:56:14 +00:00
|
|
|
return _gtk_css_parser_has_number (parser)
|
2016-02-13 23:54:37 +00:00
|
|
|
|| _gtk_css_parser_has_prefix (parser, "calc")
|
2016-02-14 23:49:29 +00:00
|
|
|
|| _gtk_css_parser_has_prefix (parser, "-gtk-win32-size")
|
|
|
|
|| _gtk_css_parser_has_prefix (parser, "-gtk-win32-part-width")
|
|
|
|
|| _gtk_css_parser_has_prefix (parser, "-gtk-win32-part-height");
|
2016-02-12 05:45:06 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 05:25:50 +00:00
|
|
|
GtkCssValue *
|
|
|
|
_gtk_css_number_value_parse (GtkCssParser *parser,
|
|
|
|
GtkCssNumberParseFlags flags)
|
2016-02-12 03:40:35 +00:00
|
|
|
{
|
2016-02-12 05:56:14 +00:00
|
|
|
if (_gtk_css_parser_has_prefix (parser, "calc"))
|
|
|
|
return gtk_css_calc_value_parse (parser, flags);
|
2016-02-14 23:49:29 +00:00
|
|
|
if (_gtk_css_parser_has_prefix (parser, "-gtk-win32-size") ||
|
|
|
|
_gtk_css_parser_has_prefix (parser, "-gtk-win32-part-width") ||
|
|
|
|
_gtk_css_parser_has_prefix (parser, "-gtk-win32-part-height"))
|
2016-02-13 23:54:37 +00:00
|
|
|
return gtk_css_win32_size_value_parse (parser, flags);
|
2016-02-12 05:56:14 +00:00
|
|
|
|
2016-02-12 05:25:50 +00:00
|
|
|
return gtk_css_dimension_value_parse (parser, flags);
|
2012-04-04 15:42:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 22:04:29 +00:00
|
|
|
double
|
|
|
|
_gtk_css_number_value_get (const GtkCssValue *number,
|
|
|
|
double one_hundred_percent)
|
|
|
|
{
|
2016-02-12 05:25:50 +00:00
|
|
|
GtkCssNumberValueClass *number_value_class;
|
|
|
|
|
2012-03-27 22:04:29 +00:00
|
|
|
g_return_val_if_fail (number != NULL, 0.0);
|
|
|
|
|
2016-02-12 05:25:50 +00:00
|
|
|
number_value_class = (GtkCssNumberValueClass *) number->class;
|
|
|
|
|
|
|
|
return number_value_class->get (number, one_hundred_percent);
|
2012-03-27 22:04:29 +00:00
|
|
|
}
|
|
|
|
|