code_uimenuwindow.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // UIMenuWindow application source code
  2. #include <ThirdParty/TurboBadger/tb_widgets.h>
  3. #include <Atomic/UI/UIMenuWindow.h>
  4. #include <Atomic/UI/UIMenubar.h>
  5. #include "PeriodicApp.h"
  6. void PeriodicApp::setup_uimenuwindow( UIWidget *layout )
  7. {
  8. PODVector<UIWidget*> dest;
  9. layout->SearchWidgetClass( "TBButton", dest );
  10. for (unsigned ii = 0; ii < dest.Size(); ii++)
  11. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUimenuwindowEvent ));
  12. }
  13. void PeriodicApp::HandleUimenuwindowEvent(StringHash eventType, VariantMap& eventData)
  14. {
  15. using namespace WidgetEvent;
  16. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  17. String refid = eventData[P_REFID].GetString();
  18. if ( widget == NULL) return;
  19. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  20. {
  21. if (widget->GetId() == "uimenuwindowcode" )
  22. {
  23. AppLog( "UIMenuWindow support : " + widget->GetId() + " was pressed " );
  24. ViewCode ( "Components/code_uimenuwindow.cpp", widget->GetParent() );
  25. }
  26. if (widget->GetId() == "uimenuwindowlayout" )
  27. {
  28. AppLog( "UIMenuWindow support : " + widget->GetId() + " was pressed ");
  29. ViewCode ( "Scenes/layout_.uimenuwindowui.txt", widget->GetParent() );
  30. }
  31. if (widget->GetId() == "uimenuwindowpush" )
  32. {
  33. AppLog( "UIMenuWindow action : " + widget->GetId() + " was pressed " );
  34. UIMenuWindow* mymenuwindow = new UIMenuWindow( context_, widget, "MenuWindowDemo");
  35. UIMenuItemSource *mis = new UIMenuItemSource(context_);
  36. mis->AddItem( new UIMenuItem( context_,"UISelectItem1", "item1" ) );
  37. mis->AddItem( new UIMenuItem( context_,"UISelectItem2", "item2", "Ctrl+C" ) );
  38. mis->AddItem( new UIMenuItem( context_,"UISelectItem3", "item3", "Ctrl+A", "DuckButton" ) );
  39. mis->AddItem( new UIMenuItem( context_,"UISelectItem4", "item4", "Ctrl+O", "LogoAtomic" ) );
  40. int xx = widget->GetX() + (widget->GetWidth()/2);
  41. int yy = widget->GetY() + (widget->GetHeight()/2);
  42. SubscribeToEvent(mymenuwindow, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUimenuwindowEvent ));
  43. mymenuwindow->Show(mis, xx, yy);
  44. }
  45. if (widget->GetId() == "MenuWindowDemo" )
  46. {
  47. AppLog( "UIMenuWindow event : " + widget->GetId() + " and " + refid + " was selected ");
  48. }
  49. }
  50. else
  51. {
  52. if (widget->GetId() == "MenuWindowDemo" )
  53. {
  54. AppLog( "UIMenuWindow event : " + widget->GetId() + " refid=" + refid + " event type=" + EventReport(eventData[P_TYPE].GetInt()));
  55. }
  56. }
  57. }