Changeset f9263dd in thomson for elec/CrO2/software/gui.cpp
- Timestamp:
- Jan 29, 2012, 9:06:29 PM (12 years ago)
- Branches:
- main
- Children:
- 192e299
- Parents:
- c7b4218
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
elec/CrO2/software/gui.cpp
rc7b4218 rf9263dd 11 11 12 12 #include <stdint.h> 13 #include <iup.h>14 13 #include <iupcontrols.h> 15 16 ///////////////////////////////////////////////////////////////////////////////17 // Super awesome extended powerful ultimate deluxe C++ IUP callback system ;)18 19 typedef int (Gui::*Callee)();20 21 class Callback22 {23 public:24 static int call(Ihandle* that);25 static int destroy(Ihandle* that);26 static void create(Ihandle* handle, const char* name, Gui* self, Callee what);27 28 private:29 Callback(Gui* self, Callee what);30 Callback(); // do not use31 32 Gui* self;33 Callee what;34 };35 36 void Callback::create(Ihandle* handle,const char* name, Gui* self, Callee what)37 {38 Callback* cb = new Callback(self, what);39 IupSetAttribute(handle, "LCALLBACK", (char*)cb);40 IupSetCallback(handle, name, Callback::call);41 IupSetCallback(handle, "LDESTROY_CB", Callback::destroy);42 }43 44 Callback::Callback(Gui* self, Callee what)45 {46 this->self = self;47 this->what = what;48 }49 50 int Callback::call(Ihandle* that)51 {52 Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");53 return ((call->self)->*(call->what))();54 }55 56 int Callback::destroy(Ihandle* that)57 {58 Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");59 delete call;60 return IUP_DEFAULT;61 }62 63 ///////////////////////////////////////////////////////////////////////////////64 14 65 15 // Start status poller "thread" … … 88 38 /* UI */ 89 39 90 int menu_exit(Ihandle* that)40 int Gui::menu_exit() 91 41 { 92 42 return IUP_CLOSE; 93 43 } 94 95 96 44 97 45 Gui::Gui(int* argc, char*** argv) … … 102 50 // IupControlsOpen(); 103 51 104 IupSetFunction("EXIT", menu_exit);105 106 52 Ihandle* menu_open = IupItem("Open", NULL); 107 Callback::create(menu_open, "ACTION", this, &Gui::menu_open); 53 Ihandle* menu_exit = IupItem("Exit", NULL); 54 Callback<Gui>::create(menu_open, "ACTION", this, &Gui::menu_open); 55 Callback<Gui>::create(menu_exit, "ACTION", this, &Gui::menu_exit); 108 56 109 57 Ihandle* menu = IupMenu( … … 111 59 IupMenu( 112 60 menu_open, 113 IupItem("Exit", "EXIT"),61 menu_exit, 114 62 NULL 115 63 )
Note:
See TracChangeset
for help on using the changeset viewer.