1 // generated by Fast Light User Interface Designer (fluid) version 1.0300 2 3 #ifndef ffffltk_input_h 4 #define ffffltk_input_h 5 #include <FL/Fl.H> 6 #include <FL/Fl_Double_Window.H> 7 #include <FL/Fl_Button.H> 8 #include <FL/Fl_Input.H> 9 #include <cairo.h> 10 11 /** 12 a non-modal input dialog for ffffltk 13 */ 14 15 namespace ffffltk 16 { 17 class nonmodal_input 18 { 19 public: 20 21 Fl_Double_Window *winder; 22 Fl_Input *inpoot; 23 void* caller; 24 void (*setcallback)(void*,float);//function pointer to set calling widget's value 25 26 // void cb_OK_i(Fl_Button*, void*); 27 // static void cb_OK(Fl_Button*, void*); 28 // void cb_Cancel_i(Fl_Button*, void*); 29 // static void cb_Cancel(Fl_Button*, void*); cb_OK_i(Fl_Button *,void * v)30 void cb_OK_i(Fl_Button*, void* v) 31 { 32 float val; 33 if(sscanf(inpoot->value(),"%f",&val)) 34 { 35 setcallback(caller,val); 36 }; 37 winder->hide(); 38 delete winder; 39 winder = NULL; 40 } cb_OK(Fl_Button * o,void * v)41 static void cb_OK(Fl_Button* o, void* v) 42 { 43 ((nonmodal_input*)(o->parent()->user_data()))->cb_OK_i(o,v); 44 } 45 cb_Cancel_i(Fl_Button *,void *)46 void cb_Cancel_i(Fl_Button*, void*) 47 { 48 winder->hide(); 49 delete winder; 50 winder = NULL; 51 } cb_Cancel(Fl_Button * o,void * v)52 static void cb_Cancel(Fl_Button* o, void* v) 53 { 54 ((nonmodal_input*)(o->parent()->user_data()))->cb_Cancel_i(o,v); 55 } 56 57 /** 58 function for other widgets to call this dialog 59 */ show(float cur_val,char * param,char * units,void * obj,void (* set_val_callback)(void *,float))60 Fl_Double_Window* show(float cur_val, char* param, char* units, void* obj, void(*set_val_callback)(void*,float)) 61 { 62 char s[80]; 63 if(!winder) 64 { 65 sprintf(s,"Set %s",param); 66 winder = new Fl_Double_Window(400, 99, s); 67 winder->user_data((void*)(this)); 68 { 69 Fl_Button* o = new Fl_Button(199, 60, 75, 25, "OK"); 70 o->callback((Fl_Callback*)cb_OK); 71 } // Fl_Button* o 72 { 73 Fl_Button* o = new Fl_Button(286, 60, 75, 25, "Cancel"); 74 o->callback((Fl_Callback*)cb_Cancel); 75 } // Fl_Button* o 76 { 77 inpoot = new Fl_Input(130, 20, 250, 30, "Enter Value:"); 78 } // Fl_Input* inpoot 79 winder->end(); 80 } // Fl_Double_Window* winder 81 winder->show(); 82 sprintf(s,"%f",cur_val); 83 inpoot->value(s); 84 if(units[0] != 0) 85 { 86 sprintf(s,"Enter Value (%s):",units); 87 inpoot->label(s); 88 } 89 setcallback = set_val_callback; 90 caller = obj; 91 return winder; 92 } 93 94 }; 95 class nonmodal_2input 96 { 97 public: 98 99 Fl_Double_Window *winder; 100 Fl_Input *inpootx; 101 Fl_Input *inpooty; 102 char unitsx[6], unitsy[6]; 103 char paramx[26], paramy[26]; 104 void* caller; 105 void (*setcallbackx)(void*,float);//function pointer to set calling widget's value 106 void (*setcallbacky)(void*,float);//function pointer to set calling widget's value 107 setparams(const char * px,const char * ux,const char * py,const char * uy)108 void setparams(const char* px, const char* ux, const char* py, const char* uy) 109 { 110 if(px && strlen(px) < 26) 111 strcpy(paramx,px); 112 if(ux && strlen(px) < 6) 113 strcpy(unitsx,ux); 114 if(px && strlen(px) < 26) 115 strcpy(paramy,py); 116 if(ux && strlen(px) < 6) 117 strcpy(unitsy,uy); 118 } 119 120 // void cb_OK_i(Fl_Button*, void*); 121 // static void cb_OK(Fl_Button*, void*); 122 // void cb_Cancel_i(Fl_Button*, void*); 123 // static void cb_Cancel(Fl_Button*, void*); cb_OK_i(Fl_Button *,void * v)124 void cb_OK_i(Fl_Button*, void* v) 125 { 126 float val; 127 if(sscanf(inpootx->value(),"%f",&val)) 128 { 129 setcallbackx(caller,val); 130 }; 131 if(sscanf(inpooty->value(),"%f",&val)) 132 { 133 setcallbacky(caller,val); 134 }; 135 winder->hide(); 136 delete winder; 137 winder = NULL; 138 } cb_OK(Fl_Button * o,void * v)139 static void cb_OK(Fl_Button* o, void* v) 140 { 141 ((nonmodal_2input*)(o->parent()->user_data()))->cb_OK_i(o,v); 142 } 143 cb_Cancel_i(Fl_Button *,void *)144 void cb_Cancel_i(Fl_Button*, void*) 145 { 146 winder->hide(); 147 delete winder; 148 winder = NULL; 149 } cb_Cancel(Fl_Button * o,void * v)150 static void cb_Cancel(Fl_Button* o, void* v) 151 { 152 ((nonmodal_input*)(o->parent()->user_data()))->cb_Cancel_i(o,v); 153 } 154 155 /** 156 function for other widgets to call this dialog 157 */ show(void * obj,float cur_valx,void (* set_val_callbackx)(void *,float),float cur_valy,void (* set_val_callbacky)(void *,float))158 Fl_Double_Window* show(void* obj, float cur_valx, void(*set_val_callbackx)(void*,float), 159 float cur_valy, void(*set_val_callbacky)(void*,float)) 160 { 161 char s[80]; 162 if(!winder) 163 { 164 sprintf(s,"Set %s and %s",paramx,paramy); 165 winder = new Fl_Double_Window(400, 140, s); 166 winder->user_data((void*)(this)); 167 { 168 Fl_Button* o = new Fl_Button(199, 100, 75, 25, "OK"); 169 o->callback((Fl_Callback*)cb_OK); 170 } // Fl_Button* o 171 { 172 Fl_Button* o = new Fl_Button(286, 100, 75, 25, "Cancel"); 173 o->callback((Fl_Callback*)cb_Cancel); 174 } // Fl_Button* o 175 { 176 inpootx = new Fl_Input(130, 20, 250, 30, "Enter X Value:"); 177 inpooty = new Fl_Input(130, 60, 250, 30, "Enter Y Value:"); 178 } // Fl_Input* inpoot 179 winder->end(); 180 } // Fl_Double_Window* winder 181 winder->show(); 182 if(unitsx[0] != 0) 183 sprintf(s,"%f (%s)",cur_valx,unitsx); 184 else 185 sprintf(s,"%f",cur_valx); 186 inpootx->value(s); 187 if(unitsy[0] != 0) 188 sprintf(s,"%f (%s)",cur_valy,unitsy); 189 else 190 sprintf(s,"%f",cur_valy); 191 inpooty->value(s); 192 if(paramx[0] != 0) 193 { 194 sprintf(s,"Enter %s:",paramx); 195 inpootx->copy_label(s); 196 } 197 if(paramy[0] != 0) 198 { 199 sprintf(s,"Enter %s:",paramy); 200 inpooty->copy_label(s); 201 } 202 setcallbackx = set_val_callbackx; 203 setcallbacky = set_val_callbacky; 204 caller = obj; 205 return winder; 206 } 207 208 }; 209 }//ffffltk 210 #endif 211