From 0ff5581158180cde9d49c507aacd5d1a4e1a5b53 Mon Sep 17 00:00:00 2001 From: Sebastian Geerken Date: Sun, 17 Nov 2013 16:01:17 +0100 Subject: Some refactoring: floats may be removed related do Length, so usage is reduced. --- dw/style.hh | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'dw/style.hh') diff --git a/dw/style.hh b/dw/style.hh index 7c00ac1f..c86446a3 100644 --- a/dw/style.hh +++ b/dw/style.hh @@ -396,12 +396,44 @@ inline bool isRelLength(Length l) { return (l & 3) == 3; } /** \brief Returns the value of a length in pixels, as an integer. */ inline int absLengthVal(Length l) { return l >> 2; } -/** \brief Returns the value of a percentage, relative to 1, as a double. */ +/** \brief Returns the value of a percentage, relative to 1, as a double. + * + * When possible, do not use this function directly; it may be removed + * soon. Instead, use multiplyWithPerLength or multiplyWithPerLengthRounded. + */ inline double perLengthVal(Length l) { return (double)(l & ~3) / (1 << 18); } -/** \brief Returns the value of a relative length, as a float. */ +/** \brief Returns the value of a relative length, as a float. + * + * When possible, do not use this function directly; it may be removed + * soon. + */ inline double relLengthVal(Length l) { return (double)(l & ~3) / (1 << 18); } +/** + * \brief Multiply an int with a percentage length, returning int. + * + * Use this instead of perLengthVal, when possible. + */ +inline int multiplyWithPerLength(int x, Length l) { + return x * perLengthVal(l); +} + +/** + * \brief Like multiplyWithPerLength, but rounds to nearest integer + * instead of down. + * + * (This function exists for backward compatibility.) + */ +inline int multiplyWithPerLengthRounded (int x, Length l) { + return lout::misc::roundInt (x * perLengthVal(l)); +} + +inline int multiplyWithRelLength(int x, Length l) { + return x * relLengthVal(l); +} + + enum { /** \brief Represents "auto" lengths. */ LENGTH_AUTO = 0 -- cgit v1.2.3