code_uiwindow.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // UIWindow application source code
  2. #include <Atomic/UI/UIWindow.h>
  3. #include <Atomic/UI/UIView.h>
  4. #include "PeriodicApp.h"
  5. void PeriodicApp::setup_uiwindow( UIWidget *layout, UIView *uiview )
  6. {
  7. PODVector<UIWidget*> dest;
  8. layout->SearchWidgetClass( "TBButton", dest );
  9. for (unsigned ii = 0; ii < dest.Size(); ii++)
  10. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUiwindowEvent ));
  11. }
  12. void PeriodicApp::HandleUiwindowEvent(StringHash eventType, VariantMap& eventData)
  13. {
  14. using namespace WidgetEvent;
  15. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  16. if ( widget == NULL ) return;
  17. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  18. {
  19. if (widget->GetId() == "uiwindowcode" )
  20. {
  21. AppLog( "UIWindow support : " + widget->GetId() + " was pressed " );
  22. ViewCode ( "Components/code_uiwindow.cpp", widget->GetParent() );
  23. }
  24. if (widget->GetId() == "uiwindowlayout" )
  25. {
  26. AppLog( "UIWindow support : " + widget->GetId() + " was pressed ");
  27. ViewCode ( "Scenes/layout_uiwindow.ui.txt", widget->GetParent() );
  28. }
  29. if (widget->GetId() == "windowdemo" )
  30. {
  31. AppLog( "UIWindow action : " + widget->GetId() + " was pressed " );
  32. UIView *someview = widget->GetView();
  33. UIWindow *window = new UIWindow(context_);
  34. window->SetSettings ( UI_WINDOW_SETTINGS_DEFAULT );
  35. window->SetText("UIWindow demo (a login dialog)");
  36. window->Load("Scenes/login_dialog.ui.txt");
  37. window->ResizeToFitContent();
  38. someview->AddChild(window);
  39. window->Center();
  40. UIWidget *login = window->GetWidget("login");
  41. SubscribeToEvent(login, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUiwindowEvent ));
  42. UIWidget *cancel = window->GetWidget("cancel");
  43. SubscribeToEvent(cancel, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUiwindowEvent ));
  44. }
  45. if (widget->GetId() == "login" )
  46. {
  47. AppLog( "UIWindow action : " + widget->GetId() + " was pressed " );
  48. UIWindow *mywindow = static_cast<UIWindow *>(FindTheWindowParent(widget));
  49. if (mywindow)
  50. mywindow->Close();
  51. }
  52. if (widget->GetId() == "cancel" )
  53. {
  54. AppLog( "UIWindow action : " + widget->GetId() + " was pressed " );
  55. UIWindow *mywindow = static_cast<UIWindow *>(FindTheWindowParent(widget));
  56. if (mywindow)
  57. mywindow->Close();
  58. }
  59. if (widget->GetId() == "windowdemo1" )
  60. {
  61. AppLog( "UIWindow action : " + widget->GetId() + " was pressed " );
  62. UIView *someview = widget->GetView();
  63. UIWindow *window = new UIWindow(context_);
  64. window->SetSettings ( UI_WINDOW_SETTINGS_DEFAULT );
  65. window->SetText("UIWindow demo (a table)" );
  66. window->Load("Scenes/sheet.ui.txt");
  67. window->ResizeToFitContent();
  68. someview->AddChild(window);
  69. window->Center();
  70. }
  71. }
  72. }