code_uiselectdropdown.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // UISelectDropdown application source code
  2. #include "PeriodicApp.h"
  3. void PeriodicApp::setup_uiselectdropdown( UIWidget *layout )
  4. {
  5. PODVector<UIWidget*> dest;
  6. layout->SearchWidgetClass( "TBButton", dest );
  7. for (unsigned ii = 0; ii < dest.Size(); ii++)
  8. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUiselectdropdownEvent ));
  9. UIWidget *demo = layout->GetWidget("selectdropdowndemo");
  10. if ( demo) // warning - this will route for all UISelectDropdown instances events into this event handler.
  11. demo->SubscribeToEvent(E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleAllSelectdropdownEvent ));
  12. }
  13. void PeriodicApp::HandleAllSelectdropdownEvent(StringHash eventType, VariantMap& eventData)
  14. {
  15. using namespace WidgetEvent;
  16. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  17. if ( widget == NULL ) return;
  18. UIWidget *demo = widget->FindWidget("selectdropdowndemo"); // find our specific widget
  19. if ( widget != demo ) return; // if its not ours, bail
  20. if (eventData[P_TYPE] == UI_EVENT_TYPE_CHANGED )
  21. {
  22. if (widget->GetId() == "selectdropdowndemo" )
  23. {
  24. AppLog( "UISelectDropdown event : " + widget->GetId() + " changed value to " + widget->GetText());
  25. }
  26. }
  27. }
  28. void PeriodicApp::HandleUiselectdropdownEvent(StringHash eventType, VariantMap& eventData)
  29. {
  30. using namespace WidgetEvent;
  31. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  32. if ( widget == NULL ) return;
  33. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  34. {
  35. if (widget->GetId() == "uiselectdropdowncode" )
  36. {
  37. AppLog( "UISelectDropdown support : " + widget->GetId() + " was pressed " );
  38. ViewCode ( "Components/code_uiselectdropdown.cpp", widget->GetParent() );
  39. }
  40. if (widget->GetId() == "uiselectdropdownlayout" )
  41. {
  42. AppLog( "UISelectDropdown support : " + widget->GetId() + " was pressed ");
  43. ViewCode ( "Scenes/layout_uiselectdropdown.ui.txt", widget->GetParent() );
  44. }
  45. }
  46. }