summaryrefslogtreecommitdiff
path: root/navit/attr.c
diff options
context:
space:
mode:
authormdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220>2015-01-03 11:48:22 +0000
committermdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220>2015-01-03 11:48:22 +0000
commit0fce2bcb63af42744f95c6b89db6bf34fcf20967 (patch)
treecd00cb2abb56106a9b6f43886b946d8de5b405f6 /navit/attr.c
parentebe1c46ebca57b3f5f6ccddd045ec6ab2bdec8f3 (diff)
downloadnavit-0fce2bcb63af42744f95c6b89db6bf34fcf20967.tar.gz
Add:osd_core:Support negative widhts and heights for osd items as it's done for negative coordinates (meaning "full size minus smth"), see #1255.
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5989 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/attr.c')
-rw-r--r--navit/attr.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/navit/attr.c b/navit/attr.c
index cc0b026b5..e884155ce 100644
--- a/navit/attr.c
+++ b/navit/attr.c
@@ -974,3 +974,22 @@ attr_types_contains_default(enum attr_type *types, enum attr_type type, int defl
}
return attr_types_contains(types, type);
}
+
+/**
+ * @brief Derive absolute value from relative attribute, given value of the whole range.
+ *
+ * @param attrval Value of u.num member of attribute capable of holding relative values.
+ * @param whole Range counted as 100%.
+ * @param treat_neg_as_rel Replace negative absolute values with whole+attr.u.num.
+ *
+ * @return True if the attribute type was found, false if it was not found, {@code deflt} if types is empty.
+ */
+int attr_rel2real(int attrval, int whole, int treat_neg_as_rel)
+{
+ if (attrval > ATTR_REL_MAXABS)
+ return whole * (attrval - ATTR_REL_RELSHIFT)/100;
+ if(treat_neg_as_rel && attrval<0 )
+ return whole+attrval;
+ return attrval;
+}
+