code_uiscrollbar.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // UIScrollBar application source code
  2. #include <Atomic/UI/UIScrollBar.h>
  3. #include "PeriodicApp.h"
  4. void PeriodicApp::setup_uiscrollbar( 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, HandleUiscrollbarEvent ));
  10. UIWidget *sbx = layout->GetWidget("scrollbardemo");
  11. if (sbx) // warning - this will route for all scrollbar instances events into this event handler.
  12. sbx->SubscribeToEvent( E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleAllScrollcontainerEvent ));
  13. }
  14. void PeriodicApp::HandleAllScrollcontainerEvent(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 *sbx = widget->FindWidget("scrollbardemo"); // find our scrollbar
  20. if ( widget != sbx ) return; // if its not ours, bail
  21. if (eventData[P_TYPE] == UI_EVENT_TYPE_CHANGED )
  22. {
  23. if (widget->GetId() == "scrollbardemo" )
  24. {
  25. AppLog( "UIScrollBar action : " + widget->GetId() + " changed value to " + String (widget->GetValue()));
  26. }
  27. }
  28. }
  29. void PeriodicApp::HandleUiscrollbarEvent(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() == "uiscrollbarcode" )
  37. {
  38. AppLog( "UIScrollBar support : " + widget->GetId() + " was pressed " );
  39. ViewCode ( "Components/code_uiscrollbar.cpp", widget->GetParent() );
  40. }
  41. if (widget->GetId() == "uiscrollbarlayout" )
  42. {
  43. AppLog( "UIScrollBar support : " + widget->GetId() + " was pressed ");
  44. ViewCode ( "Scenes/layout_uiscrollbar.ui.txt", widget->GetParent() );
  45. }
  46. }
  47. }