editint.c
Go to the documentation of this file.00001
00039 #include "editint.h"
00040
00041 #include <cfg/macros.h>
00042
00043 #include <dt/dwidget.h>
00044 #include <dt/dtag.h>
00045 #include <dt/dnotifier.h>
00046
00047 #include <drv/lcd_text.h>
00048
00052 void editint_init(DEditInt *e, dpos_t pos, dpos_t size, dcontext_t *context, int *value, int min, int max)
00053 {
00054
00055 widget_init(&e->widget, pos, size, context);
00056
00057
00058 e->widget.notifier.update = (update_func_ptr)editint_update;
00059
00060
00061 e->value = value;
00062 e->min = min;
00063 e->max = max;
00064 e->style = EDIS_DEFAULT;
00065 e->draw = editint_draw;
00066 }
00067
00071 void editint_update(DEditInt *e, dtag_t tag, dval_t _val)
00072 {
00073 bool changed = false;
00074 int val = (int)_val;
00075
00076 switch (tag)
00077 {
00078 case TAG_SETVALUE:
00079 *e->value = MINMAX(e->min, val, e->max);
00080 changed = true;
00081 break;
00082
00083
00084 case TAG_UP:
00085 if (e->style & EDIS_WRAP)
00086 {
00087 if (*e->value + val > e->max)
00088 *e->value = (*e->value + val - e->min) % (e->max - e->min + 1) + e->min;
00089 else
00090 *e->value += val;
00091 }
00092 else
00093 *e->value = MIN(*e->value + val, e->max);
00094 changed = true;
00095 break;
00096
00097 case TAG_DOWN:
00098 if (e->style & EDIS_WRAP)
00099 {
00100 if (*e->value - val < e->min)
00101 *e->value = e->max - (e->max - (*e->value - val)) % (e->max - e->min + 1);
00102 else
00103 *e->value -= val;
00104 }
00105 else
00106 *e->value = MAX(*e->value - val, e->min);
00107 changed = true;
00108 break;
00109
00110 default:
00111 break;
00112 }
00113
00114 if (changed)
00115 {
00116 e->draw(e);
00117 dnotify_targets(&e->widget.notifier, TAG_SETVALUE, (dval_t)*e->value);
00118 }
00119 }
00120
00124 void editint_draw(DEditInt *e)
00125 {
00126 lcd_printf((Layer *)e->widget.context, (lcdpos_t)e->widget.pos, LCD_NORMAL,"%*d", (int)e->widget.size, *e->value);
00127 }