1 #ifndef DIALOGSINCLUDED 2 3 #ifndef WINDOWINCLUDED 4 #include "window.h" 5 #endif 6 #ifndef FONTINCLUDED 7 #include "font.h" 8 #endif 9 #define DIALOGSINCLUDED 10 11 #include<string> 12 #include<stack> 13 using std::string; 14 using std::stack; 15 16 17 18 19 typedef void (*onDialogEnd)(bool yesclicked); 20 void onDialogClickDoNothing(bool yesclicked); 21 22 struct yesnoData 23 { 24 window* target; 25 onDialogEnd func; 26 bool enterdown; 27 bool escdown; 28 }; 29 30 class inputDialogData {}; 31 32 typedef void (*onTextDialogEnd)(bool okclicked, const string resulttext, inputDialogData* data); 33 34 35 struct inputDialog 36 { 37 inputDialogData* data; 38 onTextDialogEnd func; 39 string text; 40 vector<string> textsplit; 41 int lines; 42 window* target; 43 inputDialoginputDialog44 inputDialog() {data=NULL; } 45 46 }; 47 48 class dialogs 49 { 50 private: 51 static stack<yesnoData> yesnoCurrent; 52 static stack<inputDialog> inputCurrent; 53 static void yesButtonClick(const buttondata* data); 54 static void noButtonClick(const buttondata* data); 55 static void yesnoOnKeyUp(SDLKey keysym,Uint16 unicode); 56 static void yesnoOnKeyDown(SDLKey keysym,Uint16 unicode); 57 58 59 static void makeButtonDialog(window* target, string prompt, string yescaption, bool showno, string nocaption, onDialogEnd func); 60 61 62 static void inputOnKeyDown(SDLKey keysym,Uint16 unicode); 63 static void inputOnKeyUp(SDLKey keysym,Uint16 unicode); 64 65 66 public: 67 static Font* FontResource; 68 static SDL_Color BackgroundColor; 69 static SDL_Color TextBoxColor; 70 71 72 73 static void makeYesNoDialog(window* target, string prompt, string yescaption, string nocaption, onDialogEnd func); 74 static void makeMessageDialog(window* target, string prompt, string buttoncaption, onDialogEnd func); 75 76 static void makeTextInputDialog(window* target, string prompt, string defaulttext, int lines, string okcaption, string cancelcaption, onTextDialogEnd func, inputDialogData* data); 77 78 static void textDialogClick(bool ok); textDialogClickOk(const buttondata * data)79 static void textDialogClickOk(const buttondata* data) { textDialogClick(true); } 80 static void textDialogClickClear(const buttondata* data); textDialogClickCancel(const buttondata * data)81 static void textDialogClickCancel(const buttondata* data) { textDialogClick(false); } 82 83 static string getCurrentInputText(); 84 85 }; 86 87 88 #endif 89 90