4 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
9 * \brief Integer edit widget (implementation).
12 * \author Bernardo Innocenti <bernie@develer.com>
13 * \author Francesco Sacchi <batt@develer.com>
18 *#* Revision 1.1 2005/11/04 18:26:38 bernie
19 *#* Import into DevLib.
21 *#* Revision 1.7 2005/06/10 15:46:09 batt
22 *#* Add EDIS_WRAP style that wrap around min and max.
24 *#* Revision 1.6 2005/06/08 17:32:33 batt
25 *#* Switch to new messaging system.
27 *#* Revision 1.5 2005/06/06 11:04:12 batt
28 *#* Add some comments.
30 *#* Revision 1.4 2005/05/31 11:09:34 batt
31 *#* Fix sending pointer instead of value bug.
33 *#* Revision 1.3 2005/05/26 14:46:20 batt
34 *#* Use correct tag; remove warning.
36 *#* Revision 1.2 2005/05/26 14:44:10 batt
37 *#* Abstract widget from layer: use context.
39 *#* Revision 1.1 2005/05/26 08:32:53 batt
40 *#* Add new Develer widget system :)
44 #include <mware/editint.h>
45 #include <dt/dwidget.h>
47 #include <dt/dnotifier.h>
49 #include <cfg/macros.h>
51 #include <drv/lcd_text.h>
56 void editint_init(DEditInt *e, dpos_t pos, dpos_t size, dcontext_t *context, int *value, int min, int max)
58 // Initialize superclass
59 widget_init(&e->widget, pos, size, context);
61 // Override superclass methods
62 e->widget.notifier.update = (update_func_ptr)editint_update;
68 e->style = EDIS_DEFAULT;
69 e->draw = editint_draw;
73 * Handle the messages (edit the int).
75 void editint_update(DEditInt *e, dtag_t tag, dval_t _val)
83 *e->value = MINMAX(e->min, val, e->max);
87 /* Increments the integer by val */
89 if (e->style & EDIS_WRAP)
91 if (*e->value + val > e->max)
92 *e->value = (*e->value + val - e->min) % (e->max - e->min + 1) + e->min;
97 *e->value = MIN(*e->value + val, e->max);
100 /* Decrements the integer by val */
102 if (e->style & EDIS_WRAP)
104 if (*e->value - val < e->min)
105 *e->value = e->max - (e->max - (*e->value - val)) % (e->max - e->min + 1);
110 *e->value = MAX(*e->value - val, e->min);
121 dnotify_targets(&e->widget.notifier, TAG_SETVALUE, (dval_t)*e->value);
126 * Draw the integer on the context.
128 void editint_draw(DEditInt *e)
130 lcd_printf((Layer *)e->widget.context, (lcdpos_t)e->widget.pos, LCD_NORMAL,"%*d", (int)e->widget.size, *e->value);