code_uisection.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // UISection application source code
  2. #include <Atomic/UI/UISection.h>
  3. #include "PeriodicApp.h"
  4. void PeriodicApp::setup_uisection( UIWidget *layout )
  5. {
  6. PODVector<UIWidget*> dest;
  7. layout->SearchWidgetClass( "TBButton", dest );
  8. for (unsigned ii = 0; ii < dest.Size(); ii++)
  9. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUisectionEvent ));
  10. UIWidget *sec1 = layout->GetWidget("UISectionDemo");
  11. if (sec1)
  12. SubscribeToEvent( sec1, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUisectionEvent ));
  13. UIWidget *sec2 = layout->GetWidget("UISection2Demo");
  14. if (sec2)
  15. SubscribeToEvent( sec2, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUisectionEvent ));
  16. }
  17. void PeriodicApp::HandleUisectionEvent(StringHash eventType, VariantMap& eventData)
  18. {
  19. using namespace WidgetEvent;
  20. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  21. if ( widget == NULL ) return;
  22. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  23. {
  24. if (widget->GetId() == "uisectioncode" )
  25. {
  26. AppLog( "UISection support : " + widget->GetId() + " was pressed " );
  27. ViewCode ( "Components/code_uisection.cpp", widget->GetParent() );
  28. }
  29. if (widget->GetId() == "uisectionlayout" )
  30. {
  31. AppLog( "UISection support : " + widget->GetId() + " was pressed ");
  32. ViewCode ( "Scenes/layout_uisection.ui.txt", widget->GetParent() );
  33. }
  34. }
  35. if (eventData[P_TYPE] == UI_EVENT_TYPE_CHANGED )
  36. {
  37. UIWidget *demo1 = widget->FindWidget("UISectionDemo"); // event comes in on child widget!
  38. if ( demo1->IsAncestorOf(widget) )
  39. AppLog( "UISection event : " + demo1->GetId() + " changed to value = " + String(demo1->GetValue()));
  40. UIWidget *demo2 = widget->FindWidget("UISection2Demo");
  41. if ( demo2->IsAncestorOf(widget) )
  42. AppLog( "UISection event : " + demo2->GetId() + " changed to value = " + String(demo2->GetValue()));
  43. }
  44. }