code_uitabcontainer.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // UITabContainer application source code
  2. #include <Atomic/Resource/ResourceCache.h>
  3. #include <Atomic/IO/FileSystem.h>
  4. #include <Atomic/UI/UITabContainer.h>
  5. #include <Atomic/UI/UIWindow.h>
  6. #include <Atomic/UI/UILayout.h>
  7. #include <Atomic/UI/UIEditField.h>
  8. #include <Atomic/UI/UIButton.h>
  9. #include <Atomic/UI/UIFontDescription.h>
  10. #include "PeriodicApp.h"
  11. void PeriodicApp::setup_uitabcontainer( UIWidget *layout )
  12. {
  13. PODVector<UIWidget*> dest;
  14. layout->SearchWidgetClass( "TBButton", dest );
  15. for (unsigned ii = 0; ii < dest.Size(); ii++)
  16. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUitabcontainerEvent ));
  17. UITabContainer *tcx = static_cast<UITabContainer*>(layout->GetWidget("UITabContainerDemo"));
  18. if ( tcx)
  19. {
  20. tcx->SetCurrentPage(0); // fix or it looks like crap
  21. tcx->SubscribeToEvent( E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleAllTabcontainerEvent ));
  22. // warning - this will route for all UITabContainer instances events into this event handler.
  23. }
  24. }
  25. void PeriodicApp::HandleAllTabcontainerEvent(StringHash eventType, VariantMap& eventData)
  26. {
  27. using namespace WidgetEvent;
  28. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  29. String refid = eventData[P_REFID].GetString();
  30. if ( widget == NULL ) return;
  31. UIWidget *demo = widget->FindWidget("UITabContainerDemo"); // find our specific widget
  32. if ( widget != demo ) return; // if its not ours, bail
  33. if (eventData[P_TYPE] == UI_EVENT_TYPE_TAB_CHANGED )
  34. {
  35. if ( widget->GetId() == "UITabContainerDemo" )
  36. {
  37. UITabContainer *tcx = static_cast<UITabContainer*>(widget); // check the focus & stuff, or it gets a little spammy
  38. if ( tcx && ( tcx->GetState(UI_WIDGET_STATE_FOCUSED) == true ) )
  39. AppLog( "UITabContainer event : " + widget->GetId() + " UI_EVENT_TYPE_TAB_CHANGED to " + String( tcx->GetCurrentPage() )
  40. + " id: " + tcx->GetCurrentPageWidget()->GetId() );
  41. }
  42. }
  43. }
  44. void PeriodicApp::HandleUitabcontainerEvent(StringHash eventType, VariantMap& eventData)
  45. {
  46. using namespace WidgetEvent;
  47. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  48. String refid = eventData[P_REFID].GetString();
  49. if ( widget == NULL ) return;
  50. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  51. {
  52. if (widget->GetId() == "uitabcontainercode" )
  53. {
  54. AppLog( "UITabContainer support : " + widget->GetId() + " was pressed " );
  55. ViewCode ( "Components/code_uitabcontainer.cpp", widget->GetParent() );
  56. }
  57. if (widget->GetId() == "uitabcontainerlayout" )
  58. {
  59. AppLog( "UITabContainer support : " + widget->GetId() + " was pressed ");
  60. ViewCode ( "Scenes/layout_uitabcontainer.ui.txt", widget->GetParent() );
  61. }
  62. if (widget->GetId() == "uitabcontainerremove" )
  63. {
  64. AppLog( "UITabContainer action : " + widget->GetId() + " was pressed ");
  65. UITabContainer *tcx = static_cast<UITabContainer*>(widget->FindWidget("UITabContainerDemo"));
  66. int current = tcx->GetCurrentPage();
  67. tcx->DeletePage(current);
  68. }
  69. if (widget->GetId() == "uitabcontaineradd" )
  70. {
  71. AppLog( "UITabContainer action : " + widget->GetId() + " was pressed ");
  72. UITabContainer *tcx = static_cast<UITabContainer*>(widget->FindWidget("UITabContainerDemo"));
  73. tcx->AddTabPageFile("New File", "Scenes/sheet.ui.txt" );
  74. }
  75. if (widget->GetId() == "uitabcontainermake" )
  76. {
  77. AppLog( "UITabContainer action : " + widget->GetId() + " was pressed ");
  78. ResourceCache* cache = GetSubsystem<ResourceCache>();
  79. UITabContainer *tcx = static_cast<UITabContainer*>(widget->FindWidget("UITabContainerDemo"));
  80. UILayout *lo = new UILayout(context_);
  81. lo->SetLayoutConfig ( "YAGAC" ); // YACAC!
  82. UIEditField *myeditfield = new UIEditField(context_);
  83. myeditfield->SetGravity( UI_GRAVITY_ALL);
  84. myeditfield->SetMultiline(true);
  85. SharedPtr<File> filex = cache->GetFile("Components/code_uitabcontainer.cpp");
  86. String textx = filex->ReadText();
  87. filex->Close();
  88. myeditfield->SetText(textx);
  89. UIFontDescription *myfont = new UIFontDescription(context_); // put in a coder font
  90. myfont->SetSize(16);
  91. myfont->SetId("Vera");
  92. myeditfield->SetFontDescription (myfont);
  93. lo->AddChild (myeditfield);
  94. tcx->AddTabPageWidget("New Code", lo);
  95. }
  96. if (widget->GetId() == "uitabcontainerundock" )
  97. {
  98. AppLog( "UITabContainer action : " + widget->GetId() + " was pressed ");
  99. UITabContainer *tcx = static_cast<UITabContainer*>(widget->FindWidget("UITabContainerDemo"));
  100. int current = tcx->GetCurrentPage();
  101. tcx->UndockPage(current);
  102. }
  103. if (widget->GetId() == "uitabcontainerredock" )
  104. {
  105. AppLog( "UITabContainer action : " + widget->GetId() + " was pressed ");
  106. UITabContainer *tcx = static_cast<UITabContainer*>(widget->FindWidget("UITabContainerDemo"));
  107. if ( !tcx->DockWindow ( "tab1" ) )
  108. if ( !tcx->DockWindow ( "tab2" ) )
  109. if ( !tcx->DockWindow ( "tab3" ) )
  110. if ( !tcx->DockWindow ( "New File" ) )
  111. if ( !tcx->DockWindow ( "New Code" ) )
  112. AppLog( "UITabContainer action : no more windows to dock.");
  113. }
  114. }
  115. }