editbool.c

Go to the documentation of this file.
00001 
00043 /*#*
00044  *#* $Log$
00045  *#* Revision 1.2  2006/07/19 12:56:26  bernie
00046  *#* Convert to new Doxygen style.
00047  *#*
00048  *#* Revision 1.1  2005/11/04 18:26:38  bernie
00049  *#* Import into DevLib.
00050  *#*
00051  *#* Revision 1.3  2005/06/08 17:32:33  batt
00052  *#* Switch to new messaging system.
00053  *#*
00054  *#* Revision 1.2  2005/06/06 11:04:12  batt
00055  *#* Add some comments.
00056  *#*
00057  *#* Revision 1.1  2005/05/31 11:11:37  batt
00058  *#* Edit bool: first release.
00059  *#*
00060  *#*/
00061 
00062 #include <mware/editbool.h>
00063 #include <dt/dtag.h>
00064 
00065 #include <drv/lcd_text.h>
00066 
00070 void editbool_init(DEditBool *e, dpos_t pos, dpos_t size, dcontext_t *context, bool *value, const char *true_string, const char *false_string)
00071 {
00072     // Initialize superclass
00073     widget_init(&e->widget, pos, size, context);
00074 
00075     // Override superclass methods
00076     e->widget.notifier.update = (update_func_ptr)editbool_update;
00077 
00078     // Init instance
00079     e->value = value;
00080     e->true_string = true_string;
00081     e->false_string = false_string;
00082     e->draw = editbool_draw;
00083 }
00084 
00088 void editbool_update(DEditBool *e, dtag_t tag, dval_t _val)
00089 {
00090     bool changed = false;
00091 
00092     switch (tag)
00093     {
00094     case TAG_SETVALUE:
00095         *e->value = (bool)_val;
00096         changed = true;
00097         break;
00098 
00099     case TAG_TOGGLE:
00100         *e->value = !*e->value;
00101         changed = true;
00102         break;
00103     default:
00104         break;
00105     }
00106 
00107     if (changed)
00108     {
00109         e->draw(e);
00110         dnotify_targets(&e->widget.notifier, TAG_SETVALUE, (dval_t)*e->value);
00111     }
00112 }
00113 
00117 void editbool_draw(DEditBool *e)
00118 {
00119     lcd_printf((Layer *)e->widget.context, (lcdpos_t)e->widget.pos, LCD_NORMAL, "%*s", (int)e->widget.size , *e->value? e->true_string: e->false_string);
00120 }