mirror of
https://github.com/brl/mutter.git
synced 2024-11-29 19:40:43 -05:00
clutter: Drop ClutterUnits
As nothing uses it now that ClutterScript was dropped Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3354>
This commit is contained in:
parent
8a3181f741
commit
306ff81004
@ -521,7 +521,6 @@
|
|||||||
#include "clutter/clutter-stage-view-private.h"
|
#include "clutter/clutter-stage-view-private.h"
|
||||||
#include "clutter/clutter-timeline.h"
|
#include "clutter/clutter-timeline.h"
|
||||||
#include "clutter/clutter-transition.h"
|
#include "clutter/clutter-transition.h"
|
||||||
#include "clutter/clutter-units.h"
|
|
||||||
|
|
||||||
/* Internal enum used to control mapped state update. This is a hint
|
/* Internal enum used to control mapped state update. This is a hint
|
||||||
* which indicates when to do something other than just enforce
|
* which indicates when to do something other than just enforce
|
||||||
|
@ -49,9 +49,6 @@ struct _ClutterBackend
|
|||||||
|
|
||||||
gchar *font_name;
|
gchar *font_name;
|
||||||
|
|
||||||
gfloat units_per_em;
|
|
||||||
gint32 units_serial;
|
|
||||||
|
|
||||||
float fallback_resource_scale;
|
float fallback_resource_scale;
|
||||||
|
|
||||||
ClutterStageWindow *stage_window;
|
ClutterStageWindow *stage_window;
|
||||||
@ -98,10 +95,6 @@ gboolean _clutter_backend_create_context (Clutter
|
|||||||
gboolean _clutter_backend_finish_init (ClutterBackend *backend,
|
gboolean _clutter_backend_finish_init (ClutterBackend *backend,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
gfloat _clutter_backend_get_units_per_em (ClutterBackend *backend,
|
|
||||||
PangoFontDescription *font_desc);
|
|
||||||
gint32 _clutter_backend_get_units_serial (ClutterBackend *backend);
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
CLUTTER_EXPORT
|
||||||
ClutterStageWindow * clutter_backend_get_stage_window (ClutterBackend *backend);
|
ClutterStageWindow * clutter_backend_get_stage_window (ClutterBackend *backend);
|
||||||
|
|
||||||
|
@ -90,62 +90,6 @@ clutter_backend_dispose (GObject *gobject)
|
|||||||
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
|
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gfloat
|
|
||||||
get_units_per_em (ClutterBackend *backend,
|
|
||||||
PangoFontDescription *font_desc)
|
|
||||||
{
|
|
||||||
gfloat units_per_em = -1.0;
|
|
||||||
gboolean free_font_desc = FALSE;
|
|
||||||
gdouble dpi;
|
|
||||||
|
|
||||||
dpi = clutter_backend_get_resolution (backend);
|
|
||||||
|
|
||||||
if (font_desc == NULL)
|
|
||||||
{
|
|
||||||
ClutterSettings *settings;
|
|
||||||
gchar *font_name = NULL;
|
|
||||||
|
|
||||||
settings = clutter_settings_get_default ();
|
|
||||||
g_object_get (settings, "font-name", &font_name, NULL);
|
|
||||||
|
|
||||||
if (G_LIKELY (font_name != NULL && *font_name != '\0'))
|
|
||||||
{
|
|
||||||
font_desc = pango_font_description_from_string (font_name);
|
|
||||||
free_font_desc = TRUE;
|
|
||||||
|
|
||||||
g_free (font_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (font_desc != NULL)
|
|
||||||
{
|
|
||||||
gdouble font_size = 0;
|
|
||||||
gint pango_size;
|
|
||||||
gboolean is_absolute;
|
|
||||||
|
|
||||||
pango_size = pango_font_description_get_size (font_desc);
|
|
||||||
is_absolute = pango_font_description_get_size_is_absolute (font_desc);
|
|
||||||
|
|
||||||
/* "absolute" means "device units" (usually, pixels); otherwise,
|
|
||||||
* it means logical units (points)
|
|
||||||
*/
|
|
||||||
if (is_absolute)
|
|
||||||
font_size = (gdouble) pango_size / PANGO_SCALE;
|
|
||||||
else
|
|
||||||
font_size = dpi * ((gdouble) pango_size / PANGO_SCALE) / 72.0f;
|
|
||||||
|
|
||||||
/* 10 points at 96 DPI is 13.3 pixels */
|
|
||||||
units_per_em = (1.2f * font_size) * dpi / 96.0f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
units_per_em = -1.0f;
|
|
||||||
|
|
||||||
if (free_font_desc)
|
|
||||||
pango_font_description_free (font_desc);
|
|
||||||
|
|
||||||
return units_per_em;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_backend_real_resolution_changed (ClutterBackend *backend)
|
clutter_backend_real_resolution_changed (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
@ -165,20 +109,6 @@ clutter_backend_real_resolution_changed (ClutterBackend *backend)
|
|||||||
context = _clutter_context_get_default ();
|
context = _clutter_context_get_default ();
|
||||||
if (context->font_map != NULL)
|
if (context->font_map != NULL)
|
||||||
cogl_pango_font_map_set_resolution (context->font_map, resolution);
|
cogl_pango_font_map_set_resolution (context->font_map, resolution);
|
||||||
|
|
||||||
backend->units_per_em = get_units_per_em (backend, NULL);
|
|
||||||
backend->units_serial += 1;
|
|
||||||
|
|
||||||
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->units_per_em);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
clutter_backend_real_font_changed (ClutterBackend *backend)
|
|
||||||
{
|
|
||||||
backend->units_per_em = get_units_per_em (backend, NULL);
|
|
||||||
backend->units_serial += 1;
|
|
||||||
|
|
||||||
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->units_per_em);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -395,7 +325,6 @@ clutter_backend_class_init (ClutterBackendClass *klass)
|
|||||||
G_TYPE_NONE, 0);
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
klass->resolution_changed = clutter_backend_real_resolution_changed;
|
klass->resolution_changed = clutter_backend_real_resolution_changed;
|
||||||
klass->font_changed = clutter_backend_real_font_changed;
|
|
||||||
|
|
||||||
klass->create_context = clutter_backend_real_create_context;
|
klass->create_context = clutter_backend_real_create_context;
|
||||||
}
|
}
|
||||||
@ -403,9 +332,6 @@ clutter_backend_class_init (ClutterBackendClass *klass)
|
|||||||
static void
|
static void
|
||||||
clutter_backend_init (ClutterBackend *self)
|
clutter_backend_init (ClutterBackend *self)
|
||||||
{
|
{
|
||||||
self->units_per_em = -1.0;
|
|
||||||
self->units_serial = 1;
|
|
||||||
|
|
||||||
self->dummy_onscreen = NULL;
|
self->dummy_onscreen = NULL;
|
||||||
|
|
||||||
self->fallback_resource_scale = 1.f;
|
self->fallback_resource_scale = 1.f;
|
||||||
@ -466,20 +392,6 @@ _clutter_backend_create_context (ClutterBackend *backend,
|
|||||||
return klass->create_context (backend, error);
|
return klass->create_context (backend, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
gfloat
|
|
||||||
_clutter_backend_get_units_per_em (ClutterBackend *backend,
|
|
||||||
PangoFontDescription *font_desc)
|
|
||||||
{
|
|
||||||
/* recompute for the font description, but do not cache the result */
|
|
||||||
if (font_desc != NULL)
|
|
||||||
return get_units_per_em (backend, font_desc);
|
|
||||||
|
|
||||||
if (backend->units_per_em < 0)
|
|
||||||
backend->units_per_em = get_units_per_em (backend, NULL);
|
|
||||||
|
|
||||||
return backend->units_per_em;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_get_default_backend:
|
* clutter_get_default_backend:
|
||||||
*
|
*
|
||||||
@ -599,12 +511,6 @@ clutter_backend_get_font_options (ClutterBackend *backend)
|
|||||||
return backend->font_options;
|
return backend->font_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint32
|
|
||||||
_clutter_backend_get_units_serial (ClutterBackend *backend)
|
|
||||||
{
|
|
||||||
return backend->units_serial;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_backend_get_cogl_context:
|
* clutter_backend_get_cogl_context:
|
||||||
* @backend: a #ClutterBackend
|
* @backend: a #ClutterBackend
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
#include "clutter/clutter-color.h"
|
#include "clutter/clutter-color.h"
|
||||||
#include "clutter/clutter-interval.h"
|
#include "clutter/clutter-interval.h"
|
||||||
#include "clutter/clutter-private.h"
|
#include "clutter/clutter-private.h"
|
||||||
#include "clutter/clutter-units.h"
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,6 @@
|
|||||||
#include "clutter/clutter-private.h" /* includes <cogl-pango/cogl-pango.h> */
|
#include "clutter/clutter-private.h" /* includes <cogl-pango/cogl-pango.h> */
|
||||||
#include "clutter/clutter-property-transition.h"
|
#include "clutter/clutter-property-transition.h"
|
||||||
#include "clutter/clutter-text-buffer.h"
|
#include "clutter/clutter-text-buffer.h"
|
||||||
#include "clutter/clutter-units.h"
|
|
||||||
#include "clutter/clutter-paint-volume-private.h"
|
#include "clutter/clutter-paint-volume-private.h"
|
||||||
#include "clutter/clutter-input-focus.h"
|
#include "clutter/clutter-input-focus.h"
|
||||||
|
|
||||||
|
@ -1,897 +0,0 @@
|
|||||||
/* -*- mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
||||||
/*
|
|
||||||
* Clutter.
|
|
||||||
*
|
|
||||||
* An OpenGL based 'interactive canvas' library.
|
|
||||||
*
|
|
||||||
* Authored By: Tomas Frydrych <tf@openedhand.com>
|
|
||||||
* Emmanuele Bassi <ebassi@openedhand.com>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007 OpenedHand
|
|
||||||
*
|
|
||||||
* 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/>.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ClutterUnits:
|
|
||||||
*
|
|
||||||
* A logical distance unit
|
|
||||||
*
|
|
||||||
* #ClutterUnits is a structure holding a logical distance value along with
|
|
||||||
* its type, expressed as a value of the [enum@UnitType] enumeration. It is
|
|
||||||
* possible to use #ClutterUnits to store a position or a size in units
|
|
||||||
* different than pixels, and convert them whenever needed (for instance
|
|
||||||
* inside the [vfunc@Actor.allocate] virtual function, or inside the
|
|
||||||
* [vfunc@Actor.get_preferred_width] and [vfunc@Actor.get_preferred_height]
|
|
||||||
* virtual functions.
|
|
||||||
*
|
|
||||||
* In order to register a #ClutterUnits property, the [class@ParamSpecUnit]
|
|
||||||
* [class@GObject.ParamSpec] sub-class should be used:
|
|
||||||
*
|
|
||||||
* ```c
|
|
||||||
* GParamSpec *pspec;
|
|
||||||
*
|
|
||||||
* pspec = clutter_param_spec_units ("active-width", NULL, NULL,
|
|
||||||
* CLUTTER_UNIT_MM,
|
|
||||||
* 0.0, 12.0,
|
|
||||||
* 12.0,
|
|
||||||
* G_PARAM_READWRITE);
|
|
||||||
* g_object_class_install_property (gobject_class, PROP_WIDTH, pspec);
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* A [struct@GObject.Value] holding units can be manipulated using [func@value_set_units]
|
|
||||||
* and [func@value_get_units]. [struct@GObject.Value]s containing a #ClutterUnits
|
|
||||||
* value can also be transformed to [struct@GObject.Value]s initialized with
|
|
||||||
* %G_TYPE_INT, %G_TYPE_FLOAT and %G_TYPE_STRING through implicit conversion
|
|
||||||
* and using [method@GObject.Value.transform].
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "clutter/clutter-build-config.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <glib-object.h>
|
|
||||||
#include <gobject/gvaluecollector.h>
|
|
||||||
|
|
||||||
#include "clutter/clutter-backend-private.h"
|
|
||||||
#include "clutter/clutter-interval.h"
|
|
||||||
#include "clutter/clutter-private.h"
|
|
||||||
#include "clutter/clutter-units.h"
|
|
||||||
|
|
||||||
#define DPI_FALLBACK (96.0)
|
|
||||||
|
|
||||||
#define FLOAT_EPSILON (1e-30)
|
|
||||||
|
|
||||||
static gfloat
|
|
||||||
units_mm_to_pixels (gfloat mm)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
gdouble dpi;
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
dpi = clutter_backend_get_resolution (backend);
|
|
||||||
if (dpi < 0)
|
|
||||||
dpi = DPI_FALLBACK;
|
|
||||||
|
|
||||||
return mm * dpi / 25.4;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gfloat
|
|
||||||
units_cm_to_pixels (gfloat cm)
|
|
||||||
{
|
|
||||||
return units_mm_to_pixels (cm * 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gfloat
|
|
||||||
units_pt_to_pixels (gfloat pt)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
gdouble dpi;
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
dpi = clutter_backend_get_resolution (backend);
|
|
||||||
if (dpi < 0)
|
|
||||||
dpi = DPI_FALLBACK;
|
|
||||||
|
|
||||||
return pt * dpi / 72.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gfloat
|
|
||||||
units_em_to_pixels (const gchar *font_name,
|
|
||||||
gfloat em)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend = clutter_get_default_backend ();
|
|
||||||
|
|
||||||
if (font_name == NULL || *font_name == '\0')
|
|
||||||
return em * _clutter_backend_get_units_per_em (backend, NULL);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PangoFontDescription *font_desc;
|
|
||||||
gfloat res;
|
|
||||||
|
|
||||||
font_desc = pango_font_description_from_string (font_name);
|
|
||||||
if (font_desc == NULL)
|
|
||||||
res = -1.0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
res = em * _clutter_backend_get_units_per_em (backend, font_desc);
|
|
||||||
|
|
||||||
pango_font_description_free (font_desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_from_mm:
|
|
||||||
* @units: (out caller-allocates): a #ClutterUnits
|
|
||||||
* @mm: millimeters
|
|
||||||
*
|
|
||||||
* Stores a value in millimeters inside @units
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_units_from_mm (ClutterUnits *units,
|
|
||||||
gfloat mm)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
|
|
||||||
g_return_if_fail (units != NULL);
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
|
|
||||||
units->unit_type = CLUTTER_UNIT_MM;
|
|
||||||
units->value = mm;
|
|
||||||
units->pixels = units_mm_to_pixels (mm);
|
|
||||||
units->pixels_set = TRUE;
|
|
||||||
units->serial = _clutter_backend_get_units_serial (backend);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_from_cm:
|
|
||||||
* @units: (out caller-allocates): a #ClutterUnits
|
|
||||||
* @cm: centimeters
|
|
||||||
*
|
|
||||||
* Stores a value in centimeters inside @units
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_units_from_cm (ClutterUnits *units,
|
|
||||||
gfloat cm)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
|
|
||||||
g_return_if_fail (units != NULL);
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
|
|
||||||
units->unit_type = CLUTTER_UNIT_CM;
|
|
||||||
units->value = cm;
|
|
||||||
units->pixels = units_cm_to_pixels (cm);
|
|
||||||
units->pixels_set = TRUE;
|
|
||||||
units->serial = _clutter_backend_get_units_serial (backend);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_from_pt:
|
|
||||||
* @units: (out caller-allocates): a #ClutterUnits
|
|
||||||
* @pt: typographic points
|
|
||||||
*
|
|
||||||
* Stores a value in typographic points inside @units
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_units_from_pt (ClutterUnits *units,
|
|
||||||
gfloat pt)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
|
|
||||||
g_return_if_fail (units != NULL);
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
|
|
||||||
units->unit_type = CLUTTER_UNIT_POINT;
|
|
||||||
units->value = pt;
|
|
||||||
units->pixels = units_pt_to_pixels (pt);
|
|
||||||
units->pixels_set = TRUE;
|
|
||||||
units->serial = _clutter_backend_get_units_serial (backend);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_from_em:
|
|
||||||
* @units: (out caller-allocates): a #ClutterUnits
|
|
||||||
* @em: em
|
|
||||||
*
|
|
||||||
* Stores a value in em inside @units, using the default font
|
|
||||||
* name
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_units_from_em (ClutterUnits *units,
|
|
||||||
gfloat em)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
|
|
||||||
g_return_if_fail (units != NULL);
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
|
|
||||||
units->unit_type = CLUTTER_UNIT_EM;
|
|
||||||
units->value = em;
|
|
||||||
units->pixels = units_em_to_pixels (NULL, em);
|
|
||||||
units->pixels_set = TRUE;
|
|
||||||
units->serial = _clutter_backend_get_units_serial (backend);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_from_em_for_font:
|
|
||||||
* @units: (out caller-allocates): a #ClutterUnits
|
|
||||||
* @font_name: (allow-none): the font name and size
|
|
||||||
* @em: em
|
|
||||||
*
|
|
||||||
* Stores a value in em inside @units using @font_name
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_units_from_em_for_font (ClutterUnits *units,
|
|
||||||
const gchar *font_name,
|
|
||||||
gfloat em)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
|
|
||||||
g_return_if_fail (units != NULL);
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
|
|
||||||
units->unit_type = CLUTTER_UNIT_EM;
|
|
||||||
units->value = em;
|
|
||||||
units->pixels = units_em_to_pixels (font_name, em);
|
|
||||||
units->pixels_set = TRUE;
|
|
||||||
units->serial = _clutter_backend_get_units_serial (backend);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_from_pixels:
|
|
||||||
* @units: (out caller-allocates): a #ClutterUnits
|
|
||||||
* @px: pixels
|
|
||||||
*
|
|
||||||
* Stores a value in pixels inside @units
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_units_from_pixels (ClutterUnits *units,
|
|
||||||
gint px)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
|
|
||||||
g_return_if_fail (units != NULL);
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
|
|
||||||
units->unit_type = CLUTTER_UNIT_PIXEL;
|
|
||||||
units->value = px;
|
|
||||||
units->pixels = px;
|
|
||||||
units->pixels_set = TRUE;
|
|
||||||
units->serial = _clutter_backend_get_units_serial (backend);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_get_unit_type:
|
|
||||||
* @units: a #ClutterUnits
|
|
||||||
*
|
|
||||||
* Retrieves the unit type of the value stored inside @units
|
|
||||||
*
|
|
||||||
* Return value: a unit type
|
|
||||||
*/
|
|
||||||
ClutterUnitType
|
|
||||||
clutter_units_get_unit_type (const ClutterUnits *units)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (units != NULL, CLUTTER_UNIT_PIXEL);
|
|
||||||
|
|
||||||
return units->unit_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_get_unit_value:
|
|
||||||
* @units: a #ClutterUnits
|
|
||||||
*
|
|
||||||
* Retrieves the value stored inside @units
|
|
||||||
*
|
|
||||||
* Return value: the value stored inside a #ClutterUnits
|
|
||||||
*/
|
|
||||||
gfloat
|
|
||||||
clutter_units_get_unit_value (const ClutterUnits *units)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (units != NULL, 0.0);
|
|
||||||
|
|
||||||
return units->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_copy:
|
|
||||||
* @units: the #ClutterUnits to copy
|
|
||||||
*
|
|
||||||
* Copies @units
|
|
||||||
*
|
|
||||||
* Return value: (transfer full): the newly created copy of a
|
|
||||||
* #ClutterUnits structure. Use [method@Units.free] to free
|
|
||||||
* the allocated resources
|
|
||||||
*/
|
|
||||||
ClutterUnits *
|
|
||||||
clutter_units_copy (const ClutterUnits *units)
|
|
||||||
{
|
|
||||||
if (units != NULL)
|
|
||||||
return g_memdup2 (units, sizeof (ClutterUnits));
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_free:
|
|
||||||
* @units: the #ClutterUnits to free
|
|
||||||
*
|
|
||||||
* Frees the resources allocated by @units
|
|
||||||
*
|
|
||||||
* You should only call this function on a #ClutterUnits
|
|
||||||
* created using [method@Units.copy]
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_units_free (ClutterUnits *units)
|
|
||||||
{
|
|
||||||
if (units != NULL)
|
|
||||||
g_free (units);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_to_pixels:
|
|
||||||
* @units: units to convert
|
|
||||||
*
|
|
||||||
* Converts a value in #ClutterUnits to pixels
|
|
||||||
*
|
|
||||||
* Return value: the value in pixels
|
|
||||||
*/
|
|
||||||
gfloat
|
|
||||||
clutter_units_to_pixels (ClutterUnits *units)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
|
|
||||||
g_return_val_if_fail (units != NULL, 0.0);
|
|
||||||
|
|
||||||
/* if the backend settings changed we evict the cached value */
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
if (units->serial != _clutter_backend_get_units_serial (backend))
|
|
||||||
units->pixels_set = FALSE;
|
|
||||||
|
|
||||||
if (units->pixels_set)
|
|
||||||
return units->pixels;
|
|
||||||
|
|
||||||
switch (units->unit_type)
|
|
||||||
{
|
|
||||||
case CLUTTER_UNIT_MM:
|
|
||||||
units->pixels = units_mm_to_pixels (units->value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_CM:
|
|
||||||
units->pixels = units_cm_to_pixels (units->value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_POINT:
|
|
||||||
units->pixels = units_pt_to_pixels (units->value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_EM:
|
|
||||||
units->pixels = units_em_to_pixels (NULL, units->value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_PIXEL:
|
|
||||||
units->pixels = units->value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
units->pixels_set = TRUE;
|
|
||||||
units->serial = _clutter_backend_get_units_serial (backend);
|
|
||||||
|
|
||||||
return units->pixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_from_string:
|
|
||||||
* @units: (out caller-allocates): a #ClutterUnits
|
|
||||||
* @str: the string to convert
|
|
||||||
*
|
|
||||||
* Parses a value and updates @units with it
|
|
||||||
*
|
|
||||||
* A #ClutterUnits expressed in string should match:
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* units: wsp* unit-value wsp* unit-name? wsp*
|
|
||||||
* unit-value: number
|
|
||||||
* unit-name: 'px' | 'pt' | 'mm' | 'em' | 'cm'
|
|
||||||
* number: digit+
|
|
||||||
* | digit* sep digit+
|
|
||||||
* sep: '.' | ','
|
|
||||||
* digit: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
|
|
||||||
* wsp: (#0x20 | #0x9 | #0xA | #0xB | #0xC | #0xD)+
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* For instance, these are valid strings:
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* 10 px
|
|
||||||
* 5.1 em
|
|
||||||
* 24 pt
|
|
||||||
* 12.6 mm
|
|
||||||
* .3 cm
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* While these are not:
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* 42 cats
|
|
||||||
* omg!1!ponies
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* If no unit is specified, pixels are assumed.
|
|
||||||
*
|
|
||||||
* Return value: %TRUE if the string was successfully parsed,
|
|
||||||
* and %FALSE otherwise
|
|
||||||
*/
|
|
||||||
gboolean
|
|
||||||
clutter_units_from_string (ClutterUnits *units,
|
|
||||||
const gchar *str)
|
|
||||||
{
|
|
||||||
ClutterBackend *backend;
|
|
||||||
ClutterUnitType unit_type;
|
|
||||||
gfloat value;
|
|
||||||
|
|
||||||
g_return_val_if_fail (units != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (str != NULL, FALSE);
|
|
||||||
|
|
||||||
/* strip leading space */
|
|
||||||
while (g_ascii_isspace (*str))
|
|
||||||
str++;
|
|
||||||
|
|
||||||
if (*str == '\0')
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* integer part */
|
|
||||||
value = (gfloat) strtoul (str, (char **) &str, 10);
|
|
||||||
|
|
||||||
if (*str == '.' || *str == ',')
|
|
||||||
{
|
|
||||||
gfloat divisor = 0.1;
|
|
||||||
|
|
||||||
/* 5.cm is not a valid number */
|
|
||||||
if (!g_ascii_isdigit (*++str))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
while (g_ascii_isdigit (*str))
|
|
||||||
{
|
|
||||||
value += (*str - '0') * divisor;
|
|
||||||
divisor *= 0.1;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (g_ascii_isspace (*str))
|
|
||||||
str++;
|
|
||||||
|
|
||||||
/* assume pixels by default, if no unit is specified */
|
|
||||||
if (*str == '\0')
|
|
||||||
unit_type = CLUTTER_UNIT_PIXEL;
|
|
||||||
else if (strncmp (str, "em", 2) == 0)
|
|
||||||
{
|
|
||||||
unit_type = CLUTTER_UNIT_EM;
|
|
||||||
str += 2;
|
|
||||||
}
|
|
||||||
else if (strncmp (str, "mm", 2) == 0)
|
|
||||||
{
|
|
||||||
unit_type = CLUTTER_UNIT_MM;
|
|
||||||
str += 2;
|
|
||||||
}
|
|
||||||
else if (strncmp (str, "cm", 2) == 0)
|
|
||||||
{
|
|
||||||
unit_type = CLUTTER_UNIT_CM;
|
|
||||||
str += 2;
|
|
||||||
}
|
|
||||||
else if (strncmp (str, "pt", 2) == 0)
|
|
||||||
{
|
|
||||||
unit_type = CLUTTER_UNIT_POINT;
|
|
||||||
str += 2;
|
|
||||||
}
|
|
||||||
else if (strncmp (str, "px", 2) == 0)
|
|
||||||
{
|
|
||||||
unit_type = CLUTTER_UNIT_PIXEL;
|
|
||||||
str += 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* ensure the unit is only followed by white space */
|
|
||||||
while (g_ascii_isspace (*str))
|
|
||||||
str++;
|
|
||||||
if (*str != '\0')
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
|
||||||
|
|
||||||
units->unit_type = unit_type;
|
|
||||||
units->value = value;
|
|
||||||
units->pixels_set = FALSE;
|
|
||||||
units->serial = _clutter_backend_get_units_serial (backend);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const gchar *
|
|
||||||
clutter_unit_type_name (ClutterUnitType unit_type)
|
|
||||||
{
|
|
||||||
switch (unit_type)
|
|
||||||
{
|
|
||||||
case CLUTTER_UNIT_MM:
|
|
||||||
return "mm";
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_CM:
|
|
||||||
return "cm";
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_POINT:
|
|
||||||
return "pt";
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_EM:
|
|
||||||
return "em";
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_PIXEL:
|
|
||||||
return "px";
|
|
||||||
}
|
|
||||||
|
|
||||||
g_warning ("Invalid unit type %d", (int) unit_type);
|
|
||||||
|
|
||||||
return "<invalid>";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_units_to_string:
|
|
||||||
* @units: a #ClutterUnits
|
|
||||||
*
|
|
||||||
* Converts @units into a string
|
|
||||||
*
|
|
||||||
* See [func@Units.from_string] for the units syntax and for
|
|
||||||
* examples of output
|
|
||||||
*
|
|
||||||
* Fractional values are truncated to the second decimal
|
|
||||||
* position for em, mm and cm, and to the first decimal position for
|
|
||||||
* typographic points. Pixels are integers.
|
|
||||||
*
|
|
||||||
* Return value: a newly allocated string containing the encoded
|
|
||||||
* #ClutterUnits value. Use [func@GLib.free] to free the string
|
|
||||||
*/
|
|
||||||
gchar *
|
|
||||||
clutter_units_to_string (const ClutterUnits *units)
|
|
||||||
{
|
|
||||||
const gchar *unit_name = NULL;
|
|
||||||
const gchar *fmt = NULL;
|
|
||||||
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
|
||||||
|
|
||||||
g_return_val_if_fail (units != NULL, NULL);
|
|
||||||
|
|
||||||
switch (units->unit_type)
|
|
||||||
{
|
|
||||||
/* special case: there is no such thing as "half a pixel", so
|
|
||||||
* we round up to the nearest integer using C default
|
|
||||||
*/
|
|
||||||
case CLUTTER_UNIT_PIXEL:
|
|
||||||
return g_strdup_printf ("%d px", (int) units->value);
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_MM:
|
|
||||||
unit_name = "mm";
|
|
||||||
fmt = "%.2f";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_CM:
|
|
||||||
unit_name = "cm";
|
|
||||||
fmt = "%.2f";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_POINT:
|
|
||||||
unit_name = "pt";
|
|
||||||
fmt = "%.1f";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLUTTER_UNIT_EM:
|
|
||||||
unit_name = "em";
|
|
||||||
fmt = "%.2f";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, units->value);
|
|
||||||
|
|
||||||
return g_strconcat (buf, " ", unit_name, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ClutterInterval integration
|
|
||||||
*/
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
clutter_units_progress (const GValue *a,
|
|
||||||
const GValue *b,
|
|
||||||
gdouble progress,
|
|
||||||
GValue *retval)
|
|
||||||
{
|
|
||||||
ClutterUnits *a_units = (ClutterUnits *) clutter_value_get_units (a);
|
|
||||||
ClutterUnits *b_units = (ClutterUnits *) clutter_value_get_units (b);
|
|
||||||
ClutterUnits res;
|
|
||||||
gfloat a_px, b_px, value;
|
|
||||||
|
|
||||||
a_px = clutter_units_to_pixels (a_units);
|
|
||||||
b_px = clutter_units_to_pixels (b_units);
|
|
||||||
value = progress * (b_px - a_px) + a_px;
|
|
||||||
|
|
||||||
clutter_units_from_pixels (&res, value);
|
|
||||||
clutter_value_set_units (retval, &res);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GValue and GParamSpec integration
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* units to integer */
|
|
||||||
static void
|
|
||||||
clutter_value_transform_units_int (const GValue *src,
|
|
||||||
GValue *dest)
|
|
||||||
{
|
|
||||||
dest->data[0].v_int = clutter_units_to_pixels (src->data[0].v_pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* integer to units */
|
|
||||||
static void
|
|
||||||
clutter_value_transform_int_units (const GValue *src,
|
|
||||||
GValue *dest)
|
|
||||||
{
|
|
||||||
clutter_units_from_pixels (dest->data[0].v_pointer, src->data[0].v_int);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* units to float */
|
|
||||||
static void
|
|
||||||
clutter_value_transform_units_float (const GValue *src,
|
|
||||||
GValue *dest)
|
|
||||||
{
|
|
||||||
dest->data[0].v_float = clutter_units_to_pixels (src->data[0].v_pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* float to units */
|
|
||||||
static void
|
|
||||||
clutter_value_transform_float_units (const GValue *src,
|
|
||||||
GValue *dest)
|
|
||||||
{
|
|
||||||
clutter_units_from_pixels (dest->data[0].v_pointer, src->data[0].v_float);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* units to string */
|
|
||||||
static void
|
|
||||||
clutter_value_transform_units_string (const GValue *src,
|
|
||||||
GValue *dest)
|
|
||||||
{
|
|
||||||
gchar *string = clutter_units_to_string (src->data[0].v_pointer);
|
|
||||||
|
|
||||||
g_value_take_string (dest, string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* string to units */
|
|
||||||
static void
|
|
||||||
clutter_value_transform_string_units (const GValue *src,
|
|
||||||
GValue *dest)
|
|
||||||
{
|
|
||||||
ClutterUnits units = { CLUTTER_UNIT_PIXEL, 0.0f };
|
|
||||||
|
|
||||||
clutter_units_from_string (&units, g_value_get_string (src));
|
|
||||||
|
|
||||||
clutter_value_set_units (dest, &units);
|
|
||||||
}
|
|
||||||
|
|
||||||
G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterUnits, clutter_units,
|
|
||||||
clutter_units_copy,
|
|
||||||
clutter_units_free,
|
|
||||||
CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_INT, clutter_value_transform_units_int)
|
|
||||||
CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_FLOAT, clutter_value_transform_units_float)
|
|
||||||
CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_STRING, clutter_value_transform_units_string)
|
|
||||||
CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_INT, clutter_value_transform_int_units)
|
|
||||||
CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_FLOAT, clutter_value_transform_float_units)
|
|
||||||
CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_STRING, clutter_value_transform_string_units)
|
|
||||||
CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_units_progress));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_value_set_units:
|
|
||||||
* @value: a #GValue initialized to %CLUTTER_TYPE_UNITS
|
|
||||||
* @units: the units to set
|
|
||||||
*
|
|
||||||
* Sets @value to @units
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_value_set_units (GValue *value,
|
|
||||||
const ClutterUnits *units)
|
|
||||||
{
|
|
||||||
g_return_if_fail (CLUTTER_VALUE_HOLDS_UNITS (value));
|
|
||||||
|
|
||||||
value->data[0].v_pointer = clutter_units_copy (units);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_value_get_units:
|
|
||||||
* @value: a #GValue initialized to %CLUTTER_TYPE_UNITS
|
|
||||||
*
|
|
||||||
* Gets the #ClutterUnits contained in @value.
|
|
||||||
*
|
|
||||||
* Return value: the units inside the passed [struct@GObject.Value]
|
|
||||||
*/
|
|
||||||
const ClutterUnits *
|
|
||||||
clutter_value_get_units (const GValue *value)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (CLUTTER_VALUE_HOLDS_UNITS (value), NULL);
|
|
||||||
|
|
||||||
return value->data[0].v_pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
param_units_init (GParamSpec *pspec)
|
|
||||||
{
|
|
||||||
ClutterParamSpecUnits *uspec = CLUTTER_PARAM_SPEC_UNITS (pspec);
|
|
||||||
|
|
||||||
uspec->minimum = -G_MAXFLOAT;
|
|
||||||
uspec->maximum = G_MAXFLOAT;
|
|
||||||
uspec->default_value = 0.0f;
|
|
||||||
uspec->default_type = CLUTTER_UNIT_PIXEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
param_units_set_default (GParamSpec *pspec,
|
|
||||||
GValue *value)
|
|
||||||
{
|
|
||||||
ClutterParamSpecUnits *uspec = CLUTTER_PARAM_SPEC_UNITS (pspec);
|
|
||||||
ClutterUnits units;
|
|
||||||
|
|
||||||
units.unit_type = uspec->default_type;
|
|
||||||
units.value = uspec->default_value;
|
|
||||||
units.pixels_set = FALSE;
|
|
||||||
|
|
||||||
clutter_value_set_units (value, &units);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
param_units_validate (GParamSpec *pspec,
|
|
||||||
GValue *value)
|
|
||||||
{
|
|
||||||
ClutterParamSpecUnits *uspec = CLUTTER_PARAM_SPEC_UNITS (pspec);
|
|
||||||
ClutterUnits *units = value->data[0].v_pointer;
|
|
||||||
ClutterUnitType otype = units->unit_type;
|
|
||||||
gfloat oval = units->value;
|
|
||||||
|
|
||||||
g_assert (CLUTTER_IS_PARAM_SPEC_UNITS (pspec));
|
|
||||||
|
|
||||||
if (otype != uspec->default_type)
|
|
||||||
{
|
|
||||||
gchar *str = clutter_units_to_string (units);
|
|
||||||
|
|
||||||
g_warning ("The units value of '%s' does not have the same unit "
|
|
||||||
"type as declared by the ClutterParamSpecUnits of '%s'",
|
|
||||||
str,
|
|
||||||
clutter_unit_type_name (uspec->default_type));
|
|
||||||
|
|
||||||
g_free (str);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
units->value = CLAMP (units->value,
|
|
||||||
uspec->minimum,
|
|
||||||
uspec->maximum);
|
|
||||||
|
|
||||||
return units->value != oval;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
|
||||||
param_units_values_cmp (GParamSpec *pspec,
|
|
||||||
const GValue *value1,
|
|
||||||
const GValue *value2)
|
|
||||||
{
|
|
||||||
ClutterUnits *units1 = value1->data[0].v_pointer;
|
|
||||||
ClutterUnits *units2 = value2->data[0].v_pointer;
|
|
||||||
gfloat v1, v2;
|
|
||||||
|
|
||||||
if (units1->unit_type == units2->unit_type)
|
|
||||||
{
|
|
||||||
v1 = units1->value;
|
|
||||||
v2 = units2->value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
v1 = clutter_units_to_pixels (units1);
|
|
||||||
v2 = clutter_units_to_pixels (units2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (v1 < v2)
|
|
||||||
return - (v2 - v1 > FLOAT_EPSILON);
|
|
||||||
else
|
|
||||||
return v1 - v2 > FLOAT_EPSILON;
|
|
||||||
}
|
|
||||||
|
|
||||||
GType
|
|
||||||
clutter_param_units_get_type (void)
|
|
||||||
{
|
|
||||||
static GType pspec_type = 0;
|
|
||||||
|
|
||||||
if (G_UNLIKELY (pspec_type == 0))
|
|
||||||
{
|
|
||||||
const GParamSpecTypeInfo pspec_info = {
|
|
||||||
sizeof (ClutterParamSpecUnits),
|
|
||||||
16,
|
|
||||||
param_units_init,
|
|
||||||
CLUTTER_TYPE_UNITS,
|
|
||||||
NULL,
|
|
||||||
param_units_set_default,
|
|
||||||
param_units_validate,
|
|
||||||
param_units_values_cmp,
|
|
||||||
};
|
|
||||||
|
|
||||||
pspec_type = g_param_type_register_static (I_("ClutterParamSpecUnit"),
|
|
||||||
&pspec_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pspec_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clutter_param_spec_units: (skip)
|
|
||||||
* @name: name of the property
|
|
||||||
* @nick: short name
|
|
||||||
* @blurb: description (can be translatable)
|
|
||||||
* @default_type: the default type for the #ClutterUnits
|
|
||||||
* @minimum: lower boundary
|
|
||||||
* @maximum: higher boundary
|
|
||||||
* @default_value: default value
|
|
||||||
* @flags: flags for the param spec
|
|
||||||
*
|
|
||||||
* Creates a [class@GObject.ParamSpec] for properties using [struct@Units].
|
|
||||||
*
|
|
||||||
* Return value: the newly created [class@GObject.ParamSpec]
|
|
||||||
*/
|
|
||||||
GParamSpec *
|
|
||||||
clutter_param_spec_units (const gchar *name,
|
|
||||||
const gchar *nick,
|
|
||||||
const gchar *blurb,
|
|
||||||
ClutterUnitType default_type,
|
|
||||||
gfloat minimum,
|
|
||||||
gfloat maximum,
|
|
||||||
gfloat default_value,
|
|
||||||
GParamFlags flags)
|
|
||||||
{
|
|
||||||
ClutterParamSpecUnits *uspec;
|
|
||||||
|
|
||||||
g_return_val_if_fail (default_value >= minimum && default_value <= maximum,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
uspec = g_param_spec_internal (CLUTTER_TYPE_PARAM_UNITS,
|
|
||||||
name, nick, blurb,
|
|
||||||
flags);
|
|
||||||
|
|
||||||
uspec->default_type = default_type;
|
|
||||||
uspec->minimum = minimum;
|
|
||||||
uspec->maximum = maximum;
|
|
||||||
uspec->default_value = default_value;
|
|
||||||
|
|
||||||
return G_PARAM_SPEC (uspec);
|
|
||||||
}
|
|
@ -1,165 +0,0 @@
|
|||||||
/* -*- mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
||||||
/*
|
|
||||||
* Clutter.
|
|
||||||
*
|
|
||||||
* An OpenGL based 'interactive canvas' library.
|
|
||||||
*
|
|
||||||
* Authored By: Tomas Frydrych <tf@openedhand.com>
|
|
||||||
* Emmanuele Bassu <ebassi@linux.intel.com>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007, 2008 OpenedHand
|
|
||||||
* Copyright (C) 2009 Intel Corp.
|
|
||||||
*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
|
||||||
#error "Only <clutter/clutter.h> can be included directly."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <glib-object.h>
|
|
||||||
|
|
||||||
#include "cogl/cogl.h"
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
typedef struct _ClutterUnits ClutterUnits;
|
|
||||||
|
|
||||||
struct _ClutterUnits
|
|
||||||
{
|
|
||||||
/*< private >*/
|
|
||||||
ClutterUnitType unit_type;
|
|
||||||
|
|
||||||
gfloat value;
|
|
||||||
|
|
||||||
/* pre-filled by the provided constructors */
|
|
||||||
|
|
||||||
/* cached pixel value */
|
|
||||||
gfloat pixels;
|
|
||||||
|
|
||||||
/* whether the :pixels field is set */
|
|
||||||
guint pixels_set;
|
|
||||||
|
|
||||||
/* the serial coming from the backend, used to evict the cache */
|
|
||||||
gint32 serial;
|
|
||||||
};
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
GType clutter_units_get_type (void) G_GNUC_CONST;
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
ClutterUnitType clutter_units_get_unit_type (const ClutterUnits *units);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
gfloat clutter_units_get_unit_value (const ClutterUnits *units);
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
ClutterUnits * clutter_units_copy (const ClutterUnits *units);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
void clutter_units_free (ClutterUnits *units);
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
void clutter_units_from_pixels (ClutterUnits *units,
|
|
||||||
gint px);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
void clutter_units_from_em (ClutterUnits *units,
|
|
||||||
gfloat em);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
void clutter_units_from_em_for_font (ClutterUnits *units,
|
|
||||||
const gchar *font_name,
|
|
||||||
gfloat em);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
void clutter_units_from_mm (ClutterUnits *units,
|
|
||||||
gfloat mm);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
void clutter_units_from_cm (ClutterUnits *units,
|
|
||||||
gfloat cm);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
void clutter_units_from_pt (ClutterUnits *units,
|
|
||||||
gfloat pt);
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
gfloat clutter_units_to_pixels (ClutterUnits *units);
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
gboolean clutter_units_from_string (ClutterUnits *units,
|
|
||||||
const gchar *str);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
gchar * clutter_units_to_string (const ClutterUnits *units);
|
|
||||||
|
|
||||||
/* shorthands for the constructors */
|
|
||||||
#define clutter_units_pixels clutter_units_from_pixels
|
|
||||||
#define clutter_units_em clutter_units_from_em
|
|
||||||
#define clutter_units_em_for_font clutter_units_from_em_for_font
|
|
||||||
#define clutter_units_mm clutter_units_from_mm
|
|
||||||
#define clutter_units_cm clutter_units_from_cm
|
|
||||||
#define clutter_units_pt clutter_units_from_pt
|
|
||||||
|
|
||||||
#define CLUTTER_TYPE_UNITS (clutter_units_get_type ())
|
|
||||||
#define CLUTTER_TYPE_PARAM_UNITS (clutter_param_units_get_type ())
|
|
||||||
#define CLUTTER_PARAM_SPEC_UNITS(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), CLUTTER_TYPE_PARAM_UNITS, ClutterParamSpecUnits))
|
|
||||||
#define CLUTTER_IS_PARAM_SPEC_UNITS(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), CLUTTER_TYPE_PARAM_UNITS))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CLUTTER_VALUE_HOLDS_UNITS:
|
|
||||||
* @x: a #GValue
|
|
||||||
*
|
|
||||||
* Evaluates to %TRUE if @x holds a #ClutterUnits value
|
|
||||||
*/
|
|
||||||
#define CLUTTER_VALUE_HOLDS_UNITS(x) (G_VALUE_HOLDS ((x), CLUTTER_TYPE_UNITS))
|
|
||||||
|
|
||||||
typedef struct _ClutterParamSpecUnits ClutterParamSpecUnits;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ClutterParamSpecUnits: (skip)
|
|
||||||
* @default_type: default type
|
|
||||||
* @default_value: default value
|
|
||||||
* @minimum: lower boundary
|
|
||||||
* @maximum: higher boundary
|
|
||||||
*
|
|
||||||
* #GParamSpec subclass for unit based properties.
|
|
||||||
*/
|
|
||||||
struct _ClutterParamSpecUnits
|
|
||||||
{
|
|
||||||
/*< private >*/
|
|
||||||
GParamSpec parent_instance;
|
|
||||||
|
|
||||||
/*< public >*/
|
|
||||||
ClutterUnitType default_type;
|
|
||||||
|
|
||||||
gfloat default_value;
|
|
||||||
gfloat minimum;
|
|
||||||
gfloat maximum;
|
|
||||||
};
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
GType clutter_param_units_get_type (void) G_GNUC_CONST;
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
GParamSpec * clutter_param_spec_units (const gchar *name,
|
|
||||||
const gchar *nick,
|
|
||||||
const gchar *blurb,
|
|
||||||
ClutterUnitType default_type,
|
|
||||||
gfloat minimum,
|
|
||||||
gfloat maximum,
|
|
||||||
gfloat default_value,
|
|
||||||
GParamFlags flags);
|
|
||||||
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
void clutter_value_set_units (GValue *value,
|
|
||||||
const ClutterUnits *units);
|
|
||||||
CLUTTER_EXPORT
|
|
||||||
const ClutterUnits * clutter_value_get_units (const GValue *value);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
@ -101,7 +101,6 @@
|
|||||||
#include "clutter/clutter-timeline.h"
|
#include "clutter/clutter-timeline.h"
|
||||||
#include "clutter/clutter-transition-group.h"
|
#include "clutter/clutter-transition-group.h"
|
||||||
#include "clutter/clutter-transition.h"
|
#include "clutter/clutter-transition.h"
|
||||||
#include "clutter/clutter-units.h"
|
|
||||||
#include "clutter/clutter-virtual-input-device.h"
|
#include "clutter/clutter-virtual-input-device.h"
|
||||||
#include "clutter/clutter-zoom-action.h"
|
#include "clutter/clutter-zoom-action.h"
|
||||||
|
|
||||||
|
@ -82,7 +82,6 @@ clutter_headers = [
|
|||||||
'clutter-transition-group.h',
|
'clutter-transition-group.h',
|
||||||
'clutter-transition.h',
|
'clutter-transition.h',
|
||||||
'clutter-types.h',
|
'clutter-types.h',
|
||||||
'clutter-units.h',
|
|
||||||
'clutter-virtual-input-device.h',
|
'clutter-virtual-input-device.h',
|
||||||
'clutter-zoom-action.h',
|
'clutter-zoom-action.h',
|
||||||
]
|
]
|
||||||
@ -171,7 +170,6 @@ clutter_sources = [
|
|||||||
'clutter-transition-group.c',
|
'clutter-transition-group.c',
|
||||||
'clutter-transition.c',
|
'clutter-transition.c',
|
||||||
'clutter-timeline.c',
|
'clutter-timeline.c',
|
||||||
'clutter-units.c',
|
|
||||||
'clutter-util.c',
|
'clutter-util.c',
|
||||||
'clutter-paint-volume.c',
|
'clutter-paint-volume.c',
|
||||||
'clutter-zoom-action.c',
|
'clutter-zoom-action.c',
|
||||||
|
@ -43,7 +43,6 @@ clutter_conform_tests_general_tests = [
|
|||||||
'timeline-interpolate',
|
'timeline-interpolate',
|
||||||
'timeline-progress',
|
'timeline-progress',
|
||||||
'timeline-rewind',
|
'timeline-rewind',
|
||||||
'units',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
clutter_conform_tests = []
|
clutter_conform_tests = []
|
||||||
|
@ -1,133 +0,0 @@
|
|||||||
#include <clutter/clutter.h>
|
|
||||||
|
|
||||||
#include "tests/clutter-test-utils.h"
|
|
||||||
|
|
||||||
static void
|
|
||||||
units_cache (void)
|
|
||||||
{
|
|
||||||
ClutterUnits units;
|
|
||||||
ClutterSettings *settings;
|
|
||||||
gfloat pixels;
|
|
||||||
gint old_dpi;
|
|
||||||
|
|
||||||
settings = clutter_settings_get_default ();
|
|
||||||
g_object_get (settings, "font-dpi", &old_dpi, NULL);
|
|
||||||
|
|
||||||
g_object_set (settings, "font-dpi", 96 * 1024, NULL);
|
|
||||||
clutter_units_from_em (&units, 1.0);
|
|
||||||
pixels = clutter_units_to_pixels (&units);
|
|
||||||
|
|
||||||
g_object_set (settings, "font-dpi", ((96 * 2) * 1024), NULL);
|
|
||||||
g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, pixels);
|
|
||||||
|
|
||||||
g_object_set (settings, "font-dpi", (96 * 1024), NULL);
|
|
||||||
g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, pixels);
|
|
||||||
|
|
||||||
g_object_set (settings, "font-dpi", old_dpi, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
units_constructors (void)
|
|
||||||
{
|
|
||||||
ClutterUnits units, units_cm;
|
|
||||||
|
|
||||||
clutter_units_from_pixels (&units, 100);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 100.0);
|
|
||||||
g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, 100.0);
|
|
||||||
|
|
||||||
clutter_units_from_em (&units, 5.0);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.0);
|
|
||||||
g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, 5.0);
|
|
||||||
|
|
||||||
clutter_units_from_cm (&units_cm, 5.0);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units_cm) == CLUTTER_UNIT_CM);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units_cm), ==, 5.0);
|
|
||||||
g_assert_cmpfloat (clutter_units_to_pixels (&units_cm), !=, 5.0);
|
|
||||||
|
|
||||||
clutter_units_from_mm (&units, 50.0);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
|
|
||||||
g_assert_cmpfloat (clutter_units_to_pixels (&units),
|
|
||||||
==,
|
|
||||||
clutter_units_to_pixels (&units_cm));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
units_string (void)
|
|
||||||
{
|
|
||||||
ClutterUnits units;
|
|
||||||
gchar *string;
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "") == FALSE);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "10") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 10);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "10 px") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "10 mm") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "10 cm") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "10 ") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 10);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "5 em") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "5 emeralds") == FALSE);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, " 16 mm") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 16);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, " 24 pt ") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_POINT);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 24);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, " 32 em garbage") == FALSE);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "5.1cm") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.1f);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "5,mm") == FALSE);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, ".5pt") == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_POINT);
|
|
||||||
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 0.5f);
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, "1 omg!!pony") == FALSE);
|
|
||||||
|
|
||||||
clutter_units_from_pt (&units, 24.0);
|
|
||||||
string = clutter_units_to_string (&units);
|
|
||||||
g_assert_cmpstr (string, ==, "24.0 pt");
|
|
||||||
g_free (string);
|
|
||||||
|
|
||||||
clutter_units_from_em (&units, 3.0);
|
|
||||||
string = clutter_units_to_string (&units);
|
|
||||||
g_assert_cmpstr (string, ==, "3.00 em");
|
|
||||||
|
|
||||||
units.unit_type = CLUTTER_UNIT_PIXEL;
|
|
||||||
units.value = 0;
|
|
||||||
|
|
||||||
g_assert (clutter_units_from_string (&units, string) == TRUE);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) != CLUTTER_UNIT_PIXEL);
|
|
||||||
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
|
|
||||||
g_assert_cmpint ((int) clutter_units_get_unit_value (&units), ==, 3);
|
|
||||||
|
|
||||||
g_free (string);
|
|
||||||
}
|
|
||||||
|
|
||||||
CLUTTER_TEST_SUITE (
|
|
||||||
CLUTTER_TEST_UNIT ("/units/string", units_string)
|
|
||||||
CLUTTER_TEST_UNIT ("/units/cache", units_cache)
|
|
||||||
CLUTTER_TEST_UNIT ("/units/constructors", units_constructors)
|
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user