00001 00002 #include "DemoEventHandler.h" 00003 00004 DemoEventHandler::DemoEventHandler() : GUIEventListener(), red(0), green(0), blue(0) { } 00005 00006 void DemoEventHandler::actionPerformed(GUIEvent &evt) 00007 { 00008 00009 00010 static int num = 0; 00011 char charBuffer[50]; 00012 const std::string &callbackString = evt.getCallbackString(); 00013 GUIRectangle *sourceRectangle = evt.getEventSource(), 00014 *parent = sourceRectangle ? sourceRectangle->getParent() : NULL; 00015 int widgetType = sourceRectangle->getWidgetType(); 00016 00017 if(widgetType == WT_SLIDER) 00018 { 00019 GUISlider *slider = (GUISlider*)sourceRectangle; 00020 00021 if (slider->isClicked() || slider->isPressed()) { 00022 if(callbackString == "s1" || callbackString == "s2") 00023 { 00024 sprintf(charBuffer, "%s: %.2f", (callbackString == "s1") ? "Slider 1" : "Slider 2", slider->getProgress()); 00025 slider->setLabelString(charBuffer); 00026 } 00027 00028 if(callbackString == "red") this->red = slider->getProgress(); 00029 if(callbackString == "blue") this->blue = slider->getProgress(); 00030 if(callbackString == "green") this->green = slider->getProgress(); 00031 } 00032 } 00033 00034 if(widgetType == WT_CHECK_BOX) 00035 { 00036 GUICheckBox *checkBox = (GUICheckBox*)sourceRectangle; 00037 if (checkBox->isClicked()) { 00038 if(callbackString == "cb_red") { 00039 00040 if (checkBox->isChecked()) red = 1.0; 00041 else red = 0.0; 00042 00043 } 00044 else if(callbackString == "cb_green") { 00045 00046 if (checkBox->isChecked()) green = 1.0; 00047 else green = 0.0; 00048 00049 } 00050 else if(callbackString == "cb_blue") { 00051 00052 if (checkBox->isChecked()) blue = 1.0; 00053 else blue = 0.0; 00054 } 00055 } 00056 } 00057 00058 if(widgetType == WT_RADIO_BUTTON) 00059 { 00060 GUIRadioButton *radioButton = (GUIRadioButton*)sourceRectangle; 00061 if (radioButton->isClicked()) { 00062 if(callbackString == "rb_red") { 00063 red = 1.0; 00064 green = 0.0; 00065 blue = 0.0; 00066 } 00067 else if(callbackString == "rb_green") { 00068 red = 0; 00069 green = 1.0; 00070 blue = 0; 00071 } 00072 else if(callbackString == "rb_blue") { 00073 red = 0; 00074 green = 0; 00075 blue = 1.0; 00076 } 00077 } 00078 } 00079 00080 00081 if(widgetType == WT_BUTTON) 00082 { 00083 GUIButton *button = (GUIButton*)sourceRectangle; 00084 if(callbackString == "exit" && button->isClicked()) 00085 exit(0); 00086 00087 if(callbackString == "continue" && button->isClicked()) { 00088 00089 while (parent != NULL) { 00090 sourceRectangle = parent; 00091 parent = sourceRectangle->getParent(); 00092 } 00093 00094 GUIFrame * frame = (GUIFrame *)((GUIFrame *)sourceRectangle)->getWidgetByCallbackString("splash"); 00095 if (frame) frame->setVisible(false); 00096 00097 frame = (GUIFrame *)((GUIFrame *)sourceRectangle)->getWidgetByCallbackString("fpsPanel"); 00098 if (frame) frame->setVisible(true); 00099 frame = (GUIFrame *)((GUIFrame *)sourceRectangle)->getWidgetByCallbackString("colorSliders"); 00100 if (frame) frame->setVisible(true); 00101 frame = (GUIFrame *)((GUIFrame *)sourceRectangle)->getWidgetByCallbackString("tabs"); 00102 if (frame) frame->setVisible(true); 00103 00104 } 00105 } 00106 00107 if(widgetType == WT_COMBO_BOX) 00108 { 00109 GUIComboBox *comboBox = (GUIComboBox*)sourceRectangle; 00110 if(callbackString == "cb1") 00111 if(comboBox->getSelectedItem() == std::string("Select this item to exit")) 00112 exit(0); 00113 } 00114 00115 00116 } 00117 00118