/*\r
- * (C) Gražvydas "notaz" Ignotas, 2006-2010\r
+ * (C) Gražvydas "notaz" Ignotas, 2006-2011\r
*\r
* This work is licensed under the terms of any of these licenses\r
* (at your option):\r
return ret;\r
}\r
\r
+static unsigned int me_read_onoff(const menu_entry *ent)\r
+{\r
+ // guess var size based on mask to avoid reading too much\r
+ if (ent->mask & 0xffff0000)\r
+ return *(unsigned int *)ent->var & ent->mask;\r
+ else if (ent->mask & 0xff00)\r
+ return *(unsigned short *)ent->var & ent->mask;\r
+ else\r
+ return *(unsigned char *)ent->var & ent->mask;\r
+}\r
+\r
+static void me_toggle_onoff(menu_entry *ent)\r
+{\r
+ // guess var size based on mask to avoid reading too much\r
+ if (ent->mask & 0xffff0000)\r
+ *(unsigned int *)ent->var ^= ent->mask;\r
+ else if (ent->mask & 0xff00)\r
+ *(unsigned short *)ent->var ^= ent->mask;\r
+ else\r
+ *(unsigned char *)ent->var ^= ent->mask;\r
+}\r
+\r
static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))\r
{\r
const menu_entry *ent, *ent_sel = entries;\r
case MB_NONE:\r
break;\r
case MB_OPT_ONOFF:\r
- text_out16(x + col2_offs, y, (*(int *)ent->var & ent->mask) ? "ON" : "OFF");\r
+ text_out16(x + col2_offs, y, me_read_onoff(ent) ? "ON" : "OFF");\r
break;\r
case MB_OPT_RANGE:\r
text_out16(x + col2_offs, y, "%i", *(int *)ent->var);\r
{\r
case MB_OPT_ONOFF:\r
case MB_OPT_CUSTONOFF:\r
- *(int *)entry->var ^= entry->mask;\r
+ me_toggle_onoff(entry);\r
return 1;\r
case MB_OPT_RANGE:\r
case MB_OPT_CUSTRANGE:\r
names = (const char **)entry->data;\r
for (c = 0; names[c] != NULL; c++)\r
;\r
- *(int *)entry->var += is_next ? 1 : -1;\r
- if (*(int *)entry->var < 0)\r
- *(int *)entry->var = 0;\r
- if (*(int *)entry->var >= c)\r
- *(int *)entry->var = c - 1;\r
+ *(signed char *)entry->var += is_next ? 1 : -1;\r
+ if (*(signed char *)entry->var < 0)\r
+ *(signed char *)entry->var = 0;\r
+ if (*(signed char *)entry->var >= c)\r
+ *(signed char *)entry->var = c - 1;\r
return 1;\r
default:\r
return 0;\r
#define mee_onoff(name, id, var, mask) \
mee_onoff_h(name, id, var, mask, NULL)
+#define mee_range_h(name, id, var, min, max, help) \
+ { name, MB_OPT_RANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, NULL, NULL, help }
+
#define mee_range(name, id, var, min, max) \
- { name, MB_OPT_RANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, NULL, NULL, NULL }
+ mee_range_h(name, id, var, min, max, NULL)
#define mee_range_hide(name, id, var, min, max) \
{ name, MB_OPT_RANGE, id, &(var), 0, min, max, 0, 1, 0, NULL, NULL, NULL, NULL }