00001 00025 #ifndef CGUICONFIRMLIST_H_ 00026 #define CGUICONFIRMLIST_H_ 00027 00028 #include "GUIPrompt.h" 00029 #include "GUIList.h" 00030 00031 template<class T> 00032 class CGUIPromptList: public CGUIPrompt<T> { 00033 public: 00034 CGUIPromptList(); 00035 virtual ~CGUIPromptList(); 00036 virtual void initChilds(); 00037 00038 int getValue(); 00039 00040 void addOption(int value, string label); 00041 void centered(); 00042 }; 00043 00044 template<class T> 00045 CGUIPromptList<T>::CGUIPromptList() { 00046 // TODO Auto-generated constructor stub 00047 00048 } 00049 00050 template<class T> 00051 CGUIPromptList<T>::~CGUIPromptList() { 00052 // TODO Auto-generated destructor stub 00053 } 00054 00055 template<class T> 00056 void CGUIPromptList<T>::initChilds() { 00057 00058 CGUILabel* text = new CGUILabel(); 00059 CGUIList<int>* list = new CGUIList<int> (); 00060 list->addOption(-1, "-- NEW --"); 00061 list->centered(); 00062 00063 CGUIButton<CGUIPromptList> *buttonOK = 00064 new CGUIButton<CGUIPromptList> (this); 00065 buttonOK->setMouseDownCallback(&CGUIPromptList::onConfirm); 00066 buttonOK->setString("OK"); 00067 buttonOK->setDimension(25, 14); 00068 00069 CGUIButton<CGUIPromptList> *buttonCancel = new CGUIButton<CGUIPromptList> ( 00070 this); 00071 buttonCancel->setMouseDownCallback(&CGUIPromptList::onCancel); 00072 buttonCancel->setString("CANCEL"); 00073 buttonCancel->setDimension(50, 14); 00074 00075 this->addChild(text); 00076 this->addChild(list); 00077 this->addChild(buttonOK); 00078 this->addChild(buttonCancel); 00079 00080 } 00081 00082 template<class T> 00083 void CGUIPromptList<T>::addOption(int value, string label) { 00084 CGUIElement* list = this->getChild(1); 00085 if (list != NULL) { 00086 dynamic_cast<CGUIList<int>*> (list)->addOption(value, label); 00087 } 00088 } 00089 00090 template<class T> 00091 int CGUIPromptList<T>::getValue() { 00092 CGUIElement* list = NULL; 00093 00094 if ((list = this->getChild(1)) != NULL) { 00095 return dynamic_cast<CGUIList<int>*> (list)->getActiveValue(); 00096 } 00097 00098 return -2; 00099 } 00100 00101 template<class T> 00102 void CGUIPromptList<T>::centered() { 00103 CGUIConfirm<T>::centered(); 00104 00105 CGUIElement* list = this->getChild(1); 00106 CGUIElement* buttonOK = this->getChild(2); 00107 CGUIElement* buttonCancel = this->getChild(3); 00108 00109 float positionY = this->getPositionY(); 00110 float visible = 0; 00111 00112 if (list != NULL) { 00113 positionY = list->getPositionY(); 00114 visible = dynamic_cast<CGUIList<int>*> (list)->getCountVisible(); 00115 } 00116 00117 if (buttonOK != NULL) { 00118 buttonOK->setPositionY(positionY + visible * this->getLineHeight()); 00119 } 00120 00121 if (buttonCancel != NULL) { 00122 buttonCancel->setPositionY( 00123 positionY + (visible + 1) * this->getLineHeight()); 00124 } 00125 00126 } 00127 00128 #endif /* CGUICONFIRMLIST_H_ */