code_uicheckbox.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // UICheckBox application source code
  2. #include "PeriodicApp.h"
  3. void PeriodicApp::setup_uicheckbox( 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, HandleUicheckboxEvent ));
  9. UIWidget *demochk = layout->GetWidget ("democheck");
  10. if (demochk)
  11. SubscribeToEvent(demochk, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUicheckboxEvent ));
  12. }
  13. void PeriodicApp::HandleUicheckboxEvent(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. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  19. {
  20. if (widget->GetId() == "uicheckboxcode" )
  21. {
  22. AppLog( "UICheckBox support : " + widget->GetId() + " was pressed " );
  23. ViewCode ( "Components/code_uicheckbox.cpp", widget->GetParent() );
  24. }
  25. if (widget->GetId() == "uicheckboxlayout" )
  26. {
  27. AppLog( "UICheckBox support : " + widget->GetId() + " was pressed ");
  28. ViewCode ( "Scenes/layout_uicheckbox.ui.txt", widget->GetParent() );
  29. }
  30. if (widget->GetId() == "democheck" )
  31. {
  32. AppLog( "UICheckBox event : " + widget->GetId() + " was pressed, state = " + String ( widget->GetValue() ) );
  33. }
  34. if (widget->GetId() == "checkset" )
  35. {
  36. UIWidget *demochk = widget->FindWidget ("democheck");
  37. if (demochk)
  38. {
  39. demochk->SetValue (1);
  40. AppLog( "UICheckBox action : " + widget->GetId() + " was pressed, set state to 1" );
  41. }
  42. }
  43. if (widget->GetId() == "checkunset" )
  44. {
  45. UIWidget *demochk = widget->FindWidget ("democheck");
  46. if (demochk)
  47. {
  48. demochk->SetValue (0);
  49. AppLog( "UICheckBox action : " + widget->GetId() + " was pressed, set state to 0" );
  50. }
  51. }
  52. }
  53. }