diff options
author | Sebastian Geerken <devnull@localhost> | 2013-11-17 16:01:17 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2013-11-17 16:01:17 +0100 |
commit | 0ff5581158180cde9d49c507aacd5d1a4e1a5b53 (patch) | |
tree | 5c4b494fc101481d1667adb6a8bd4b83e9dee1b1 /dw/style.hh | |
parent | 4045b3d64203bc758a14926cd6c6ac48c200c10c (diff) |
Some refactoring: floats may be removed related do Length, so usage is reduced.
Diffstat (limited to 'dw/style.hh')
-rw-r--r-- | dw/style.hh | 36 |
1 files changed, 34 insertions, 2 deletions
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 |