editint.c
Go to the documentation of this file.00001
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #include <mware/editint.h>
00073 #include <dt/dwidget.h>
00074 #include <dt/dtag.h>
00075 #include <dt/dnotifier.h>
00076
00077 #include <cfg/macros.h>
00078
00079 #include <drv/lcd_text.h>
00080
00084 void editint_init(DEditInt *e, dpos_t pos, dpos_t size, dcontext_t *context, int *value, int min, int max)
00085 {
00086
00087 widget_init(&e->widget, pos, size, context);
00088
00089
00090 e->widget.notifier.update = (update_func_ptr)editint_update;
00091
00092
00093 e->value = value;
00094 e->min = min;
00095 e->max = max;
00096 e->style = EDIS_DEFAULT;
00097 e->draw = editint_draw;
00098 }
00099
00103 void editint_update(DEditInt *e, dtag_t tag, dval_t _val)
00104 {
00105 bool changed = false;
00106 int val = (int)_val;
00107
00108 switch (tag)
00109 {
00110 case TAG_SETVALUE:
00111 *e->value = MINMAX(e->min, val, e->max);
00112 changed = true;
00113 break;
00114
00115
00116 case TAG_UP:
00117 if (e->style & EDIS_WRAP)
00118 {
00119 if (*e->value + val > e->max)
00120 *e->value = (*e->value + val - e->min) % (e->max - e->min + 1) + e->min;
00121 else
00122 *e->value += val;
00123 }
00124 else
00125 *e->value = MIN(*e->value + val, e->max);
00126 changed = true;
00127 break;
00128
00129 case TAG_DOWN:
00130 if (e->style & EDIS_WRAP)
00131 {
00132 if (*e->value - val < e->min)
00133 *e->value = e->max - (e->max - (*e->value - val)) % (e->max - e->min + 1);
00134 else
00135 *e->value -= val;
00136 }
00137 else
00138 *e->value = MAX(*e->value - val, e->min);
00139 changed = true;
00140 break;
00141
00142 default:
00143 break;
00144 }
00145
00146 if (changed)
00147 {
00148 e->draw(e);
00149 dnotify_targets(&e->widget.notifier, TAG_SETVALUE, (dval_t)*e->value);
00150 }
00151 }
00152
00156 void editint_draw(DEditInt *e)
00157 {
00158 lcd_printf((Layer *)e->widget.context, (lcdpos_t)e->widget.pos, LCD_NORMAL,"%*d", (int)e->widget.size, *e->value);
00159 }