summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWildemann Stefan <stefan.wildemann@corpuls.com>2019-07-16 09:42:33 +0200
committerWildemann Stefan <stefan.wildemann@corpuls.com>2019-07-16 09:42:33 +0200
commit695749f57ba34f7db4fe212b9ece52ce1b57cd43 (patch)
tree506a43dd384b299ef1e4b04e4560d7d791506f7e
parentc6025c758e483aa40cb545625c1fef9a52235136 (diff)
downloadnavit-695749f57ba34f7db4fe212b9ece52ce1b57cd43.tar.gz
Remove 0% magic. Remove Magic number defines.
-rw-r--r--navit/attr.c3
-rw-r--r--navit/attr.h18
-rw-r--r--navit/osd.c9
-rw-r--r--navit/osd.h1
-rw-r--r--navit/osd/core/osd_core.c22
5 files changed, 19 insertions, 34 deletions
diff --git a/navit/attr.c b/navit/attr.c
index c8b2bcd1c..b42c86993 100644
--- a/navit/attr.c
+++ b/navit/attr.c
@@ -466,6 +466,9 @@ char *attr_to_text_ext(struct attr *attr, char *sep, enum attr_format fmt, enum
}
if (type >= attr_type_osd_coordinate_begin && type <= attr_type_osd_coordinate_end) {
switch(attr->u.osd_display_coordinate->type) {
+ case OSD_NOT_SET:
+ return g_strdup_printf("%s","OSD_NOT_SET");
+ break;
case OSD_PIXELS:
return g_strdup_printf("%f",attr->u.osd_display_coordinate->num);
break;
diff --git a/navit/attr.h b/navit/attr.h
index 72c398c68..85410dce0 100644
--- a/navit/attr.h
+++ b/navit/attr.h
@@ -99,24 +99,6 @@ enum attr_format {
#define AF_DG_EXPLOSIVE (1<<2)
#define AF_DG_FLAMMABLE (1<<3)
-/*
- * Values for attributes that could carry relative values.
- * Some attributes allow both absolute and relative values. The value for these
- * attributes is stored as an int. Absolute values are stored as-is, relative
- * values are stored shifted by adding ATTR_REL_RELSHIFT.
- */
-/** Minimum value for an absolute attribute value. */
-#define ATTR_REL_MINABS -0x40000000
-/** Maximum value for an absolute attribute value. */
-#define ATTR_REL_MAXABS 0x40000000
-/** Minimum value for an relative attribute value (without value shift). */
-#define ATTR_REL_MINREL -0x1FFFFFFF
-/** Maximum value for an relative attribute value (without value shift). */
-#define ATTR_REL_MAXREL 0x20000000
-/**
- * Value shift for relative values. This value is added to an attribute values to indicate
- * a relative value. */
-#define ATTR_REL_RELSHIFT 0x60000000
/** Indicates whether a position is valid **/
enum attr_position_valid {
diff --git a/navit/osd.c b/navit/osd.c
index 50453f81f..c1283e83e 100644
--- a/navit/osd.c
+++ b/navit/osd.c
@@ -151,7 +151,7 @@ void osd_std_resize(struct osd_item *item) {
*
* If the geometry of the OSD item is specified relative to screen dimensions,
* this function will set its absolute dimensions accordingly. If relative width
- * or relative height is set to 0% (int value is equal to ATTR_REL_RELSHIFT),
+ * or relative height is not set,
* object width (height) is not changed here, for button and image osds it means
* to derive values from the underlying image.
*
@@ -188,11 +188,11 @@ void osd_std_calculate_sizes(struct osd_item *item, int w, int h) {
h -= (padding->top + padding->bottom);
}
- if(!((item->rel_w.type == OSD_RELATIVE) && (item->rel_w.num == 0)))
+ if(item->rel_w.type != OSD_NOT_SET)
item->w=osd_rel2real(navit_get_graphics(item->navit), &(item->rel_w), w, 1);
if(item->w<0)
item->w=0;
- if(!((item->rel_h.type == OSD_RELATIVE) && (item->rel_h.num == 0)))
+ if(item->rel_h.type != OSD_NOT_SET)
item->h=osd_rel2real(navit_get_graphics(item->navit),&(item->rel_h), h, 1);
if(item->h<0)
item->h=0;
@@ -517,6 +517,9 @@ int osd_rel2real(struct graphics *gra, const struct osd_display_coordinate * att
result = osd_mm_to_in(attrval->num) * dpi;
} else if (attrval->type == OSD_INCHES) {
result = attrval->num * dpi;
+ } else if (attrval->type == OSD_NOT_SET) {
+ result = -1;
+ return result;
} else
result = attrval->num;
if(treat_neg_as_rel && (result <0) )
diff --git a/navit/osd.h b/navit/osd.h
index ca184ba6d..24188113e 100644
--- a/navit/osd.h
+++ b/navit/osd.h
@@ -41,6 +41,7 @@ struct osd_item_methods {
};
typedef enum {
+ OSD_NOT_SET=-1, /** marker for value invalid. Will never be pared from configuration */
OSD_PIXELS=0, /** number is in pixels. No calculation required */
OSD_MILLIMETERS, /** number is in mm. Use dpi value to calculate to pixels */
OSD_INCHES, /** number is in inches. Use dpi value to calculate to pixels */
diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c
index 0cafa3fc1..4967fdc71 100644
--- a/navit/osd/core/osd_core.c
+++ b/navit/osd/core/osd_core.c
@@ -1601,7 +1601,7 @@ struct osd_button {
/**
* @brief Adjusts width and height of an OSD item to fit the image it displays.
*
- * A width or height of 0%, stored in relative attributes as {@code ATTR_REL_RELSHIFT}, is used as a flag
+ * A OSD_NOT_SET width or height , stored in relative attributes, is used as a flag
* indicating that the respective dimension is unset, i.e. determined by the dimensions of its image.
*
* If this is the case for height and/or width, the respective dimension will be updated to fit the image.
@@ -1613,9 +1613,9 @@ struct osd_button {
* @param img The image displayed by the item
*/
static void osd_button_adjust_sizes(struct osd_priv_common *opc, struct graphics_image *img) {
- if((opc->osd_item.rel_w.type == OSD_RELATIVE) && (opc->osd_item.rel_w.num == 0))
+ if(opc->osd_item.rel_w.type == OSD_NOT_SET)
opc->osd_item.w=img->width;
- if((opc->osd_item.rel_h.type == OSD_RELATIVE) && (opc->osd_item.rel_h.num == 0))
+ if(opc->osd_item.rel_h.type == OSD_NOT_SET)
opc->osd_item.h=img->height;
}
@@ -1757,11 +1757,9 @@ static struct osd_priv *osd_button_new(struct navit *nav, struct osd_methods *me
opc->data = (void*)this;
opc->osd_item.navit = nav;
opc->osd_item.meth.draw = osd_draw_cast(osd_button_draw);
- /*Value of 0% is stored in relative attributes as ATTR_REL_RELSHIFT, we use this value as "width/height unset" flag */
- opc->osd_item.rel_w.type = OSD_RELATIVE;
- opc->osd_item.rel_w.num = 0;
- opc->osd_item.rel_h.type = OSD_RELATIVE;
- opc->osd_item.rel_h.num = 0;
+ /*Relative values of OSD_NOT_SET type are used to indicate "width/height unset" */
+ opc->osd_item.rel_w.type = OSD_NOT_SET;
+ opc->osd_item.rel_h.type = OSD_NOT_SET;
meth->set_attr = set_std_osd_attr;
opc->spec_set_attr_func = osd_button_set_attr;
@@ -1844,11 +1842,9 @@ static struct osd_priv *osd_image_new(struct navit *nav, struct osd_methods *met
opc->data = (void*)this;
opc->osd_item.navit = nav;
opc->osd_item.meth.draw = osd_draw_cast(osd_button_draw);
- /*Value of 0% is stored in relative attributes as ATTR_REL_RELSHIFT, we use this value as "width/height unset" flag */
- opc->osd_item.rel_w.type = OSD_RELATIVE;
- opc->osd_item.rel_w.num = 0;
- opc->osd_item.rel_h.type = OSD_RELATIVE;
- opc->osd_item.rel_h.num = 0;
+ /*Relative values of OSD_NOT_SET type are used to indicate "width/height unset" */
+ opc->osd_item.rel_w.type = OSD_NOT_SET;
+ opc->osd_item.rel_h.type = OSD_NOT_SET;
meth->set_attr = set_std_osd_attr;
opc->spec_set_attr_func = osd_button_set_attr;