code_uislider.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // UISlider application source code
  2. #include <Atomic/UI/UISlider.h>
  3. #include "PeriodicApp.h"
  4. void PeriodicApp::setup_uislider( 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, HandleUisliderEvent ));
  10. UISlider *slider = static_cast<UISlider*>(layout->GetWidget("sliderdemo"));
  11. if (slider) // warning - this will route for all UISlider instances events into this event handler.
  12. slider->SubscribeToEvent( E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleAllSliderEvent ));
  13. }
  14. void PeriodicApp::HandleAllSliderEvent(StringHash eventType, VariantMap& eventData)
  15. {
  16. using namespace WidgetEvent;
  17. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  18. if ( widget == NULL ) return;
  19. UIWidget *demo = widget->FindWidget("sliderdemo"); // find our specific widget
  20. if ( widget != demo ) return; // if its not ours, bail
  21. if (eventData[P_TYPE] == UI_EVENT_TYPE_CHANGED )
  22. {
  23. if (widget->GetId() == "sliderdemo" )
  24. {
  25. AppLog( "UISlider event : " + widget->GetId() + " changed value to " + String (widget->GetValue()));
  26. }
  27. }
  28. }
  29. void PeriodicApp::HandleUisliderEvent(StringHash eventType, VariantMap& eventData)
  30. {
  31. using namespace WidgetEvent;
  32. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  33. if ( widget == NULL ) return;
  34. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  35. {
  36. if (widget->GetId() == "uislidercode" )
  37. {
  38. AppLog( "UISlider support : " + widget->GetId() + " was pressed " );
  39. ViewCode ( "Components/code_uislider.cpp", widget->GetParent() );
  40. }
  41. if (widget->GetId() == "uisliderlayout" )
  42. {
  43. AppLog( "UISlider support : " + widget->GetId() + " was pressed ");
  44. ViewCode ( "Scenes/layout_uislider.ui.txt", widget->GetParent() );
  45. }
  46. }
  47. }