diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2009-10-06 17:47:34 +0100 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2009-10-07 16:06:26 +0100 |
commit | 8605073edb7a1e830696632a6de5ad694f1af98d (patch) | |
tree | 1f7d9ef6bff98fa267fc55c609954971eb911d4e /clutter/clutter-units.c | |
parent | 96859959bd24d99f51d5dea3b5ec7bc4bf7071f3 (diff) | |
download | clutter-8605073edb7a1e830696632a6de5ad694f1af98d.tar.gz |
[units] Add support for centimeters
The only tricky part of the patch is to remember that 1cm is 10mm.
Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
Diffstat (limited to 'clutter/clutter-units.c')
-rw-r--r-- | clutter/clutter-units.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/clutter/clutter-units.c b/clutter/clutter-units.c index 069bed0bc..595f0a50f 100644 --- a/clutter/clutter-units.c +++ b/clutter/clutter-units.c @@ -91,6 +91,12 @@ units_mm_to_pixels (gfloat mm) } 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; @@ -153,6 +159,27 @@ clutter_units_from_mm (ClutterUnits *units, } /** + * clutter_units_from_cm: + * @units: a #ClutterUnits + * @cm: centimeters + * + * Stores a value in centimeters inside @units + * + * Since: 1.2 + */ +void +clutter_units_from_cm (ClutterUnits *units, + gfloat cm) +{ + g_return_if_fail (units != NULL); + + units->unit_type = CLUTTER_UNIT_CM; + units->value = cm; + units->pixels = units_cm_to_pixels (cm); + units->pixels_set = TRUE; +} + +/** * clutter_units_from_pt: * @units: a #ClutterUnits * @pt: typographic points @@ -334,6 +361,10 @@ clutter_units_to_pixels (ClutterUnits *units) 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; @@ -364,7 +395,7 @@ clutter_units_to_pixels (ClutterUnits *units) * |[ * units: wsp* unit-value wsp* unit-name? wsp* * unit-value: number - * unit-name: 'px' | 'pt' | 'mm' | 'em' + * unit-name: 'px' | 'pt' | 'mm' | 'em' | 'cm' * number: digit+ * | digit* sep digit+ * sep: '.' | ',' @@ -448,6 +479,11 @@ clutter_units_from_string (ClutterUnits *units, 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; @@ -482,6 +518,9 @@ clutter_unit_type_name (ClutterUnitType unit_type) case CLUTTER_UNIT_MM: return "mm"; + case CLUTTER_UNIT_CM: + return "cm"; + case CLUTTER_UNIT_POINT: return "pt"; @@ -507,7 +546,7 @@ clutter_unit_type_name (ClutterUnitType unit_type) * examples of output * * <note>Fractional values are truncated to the second decimal - * position for em and mm, and to the first decimal position for + * position for em, mm and cm, and to the first decimal position for * typographic points. Pixels are integers.</note> * * Return value: a newly allocated string containing the encoded @@ -537,6 +576,11 @@ clutter_units_to_string (const ClutterUnits *units) fmt = "%.2f"; break; + case CLUTTER_UNIT_CM: + unit_name = "cm"; + fmt = "%.2f"; + break; + case CLUTTER_UNIT_POINT: unit_name = "pt"; fmt = "%.1f"; |