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; }
//doc ClutterUnits ==(otherUnit) IO_METHOD(IoClutterUnits, equals) { IoClutterUnits *other = IoMessage_locals_clutterUnitsArgAt_(m, locals, 0); int self_in_pixels = clutter_units_to_pixels(&IOCUNITS(self)), other_in_pixels = clutter_units_to_pixels(&IOCUNITS(other)); return IOBOOL(self, self_in_pixels == other_in_pixels); }
//doc ClutterUnits compare(otherUnit) Returns 0 if units are equal, -1 if <code>self</code> is smaller, 1 if <code>self</code> is bigger than <code>otherUnit</code>. IO_METHOD(IoClutterUnits, compare) { IoClutterUnits *other = IoMessage_locals_clutterUnitsArgAt_(m, locals, 0); int self_in_pixels = clutter_units_to_pixels(&IOCUNITS(self)), other_in_pixels = clutter_units_to_pixels(&IOCUNITS(other)); if(self_in_pixels < other_in_pixels) return IONUMBER(-1); else if(self_in_pixels > other_in_pixels) return IONUMBER(1); return IONUMBER(0); }
//doc ClutterUnits -(otherUnit) IO_METHOD(IoClutterUnits, subtract) { IoObject *other = IoMessage_locals_valueArgAt_(m, locals, 0); int self_in_pixels = clutter_units_to_pixels(&IOCUNITS(self)), other_in_pixels = 0; ClutterUnits units; if(ISNUMBER(other)) { other_in_pixels = CNUMBER(other); } else if(ISCLUTTERUNITS(other)) { other_in_pixels = clutter_units_to_pixels(&IOCUNITS(other)); } else { IoState_error_(IOSTATE, m, "ClutterUnits arithmetic works only for Numbers and other ClutterUnits."); return IONIL(self); } clutter_units_from_pixels(&units, self_in_pixels - other_in_pixels); return IoClutterUnits_newWithUnits(IOSTATE, units); }
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; }
IO_METHOD(IoClutterUnits, asPixels) { return IONUMBER(clutter_units_to_pixels(&IOCUNITS(self))); }
/* 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); }