UIModalOps.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicEditor
  4. #include "AtomicEditor.h"
  5. #include <TurboBadger/tb_widgets_common.h>
  6. #include <TurboBadger/tb_window.h>
  7. #include <TurboBadger/tb_message_window.h>
  8. #include <TurboBadger/tb_editfield.h>
  9. #include <Atomic/Core/Context.h>
  10. #include <Atomic/Graphics/Graphics.h>
  11. #include <Atomic/UI/TBUI.h>
  12. #include "AEEvents.h"
  13. #include "Resources/AEResourceOps.h"
  14. #include "UI/UIMainFrame.h"
  15. #include "UI/UIProjectFrame.h"
  16. #include "UIModalOps.h"
  17. #include "UIResourceOps.h"
  18. #include "UIBuild.h"
  19. #include "UIBuildSettings.h"
  20. #include "UIProgramOutput.h"
  21. #include "UINewProject.h"
  22. #include "UIAbout.h"
  23. #include "UIPlatformsInfo.h"
  24. #include "License/UIActivation.h"
  25. #include "License/UIActivationSuccess.h"
  26. #include "License/UIManageLicense.h"
  27. #include "License/AELicenseSystem.h"
  28. namespace AtomicEditor
  29. {
  30. // UIModalOpWindow------------------------------------------------
  31. UIModalOpWindow::UIModalOpWindow(Context* context):
  32. AEWidget(context)
  33. {
  34. window_ = new TBWindow();
  35. TBUI* tbui = GetSubsystem<TBUI>();
  36. TBWidget* root = tbui->GetRootWidget();
  37. root->AddChild(delegate_);
  38. // start with full screen as size
  39. delegate_->SetRect(TBRect(0, 0, root->GetRect().w, root->GetRect().h));
  40. delegate_->AddChild(window_);
  41. }
  42. UIModalOpWindow::~UIModalOpWindow()
  43. {
  44. }
  45. bool UIModalOpWindow::OnEvent(const TBWidgetEvent &ev)
  46. {
  47. return false;
  48. }
  49. void UIModalOpWindow::Center()
  50. {
  51. TBUI* tbui = GetSubsystem<TBUI>();
  52. TBRect rect = window_->GetRect();
  53. TBWidget* root = tbui->GetRootWidget();
  54. TBRect bounds(0, 0, root->GetRect().w, root->GetRect().h);
  55. window_->SetRect(rect.CenterIn(bounds).MoveIn(bounds).Clip(bounds));
  56. delegate_->SetRect(bounds);
  57. }
  58. // UIModalOps------------------------------------------------
  59. UIModalOps::UIModalOps(Context* context) :
  60. AEWidget(context),
  61. dimmer_(0),
  62. isHiding_(false)
  63. {
  64. TBWidgetListener::AddGlobalListener(this);
  65. context->RegisterSubsystem(this);
  66. dimmer_ = new TBDimmer();
  67. }
  68. void UIModalOps::Show()
  69. {
  70. assert(!dimmer_->GetParent());
  71. TBUI* tbui = GetSubsystem<TBUI>();
  72. TBWidget* root = tbui->GetRootWidget();
  73. root->AddChild(dimmer_);
  74. }
  75. void UIModalOps::Hide()
  76. {
  77. isHiding_ = true;
  78. if (dimmer_->GetParent())
  79. dimmer_->GetParent()->RemoveChild(dimmer_);
  80. opWindow_ = NULL;
  81. isHiding_ = false;
  82. }
  83. void UIModalOps::ShowCreateComponent(const String& resourcePath)
  84. {
  85. assert(opWindow_.Null());
  86. resourcePath_ = resourcePath;
  87. Show();
  88. opWindow_ = new UICreateComponent(context_);
  89. }
  90. void UIModalOps::ShowCreateScript(const String& resourcePath)
  91. {
  92. assert(opWindow_.Null());
  93. resourcePath_ = resourcePath;
  94. Show();
  95. opWindow_ = new UICreateScript(context_);
  96. }
  97. void UIModalOps::ShowResourceDelete(const String& resourcePath)
  98. {
  99. assert(opWindow_.Null());
  100. resourcePath_ = resourcePath;
  101. Show();
  102. opWindow_ = new UIResourceDelete(context_);
  103. }
  104. void UIModalOps::ShowNewFolder(const String& resourcePath)
  105. {
  106. assert(opWindow_.Null());
  107. resourcePath_ = resourcePath;
  108. Show();
  109. opWindow_ = new UINewFolder(context_);
  110. }
  111. void UIModalOps::ShowBuildSettings()
  112. {
  113. assert(opWindow_.Null());
  114. Show();
  115. opWindow_ = new UIBuildSettings(context_);
  116. }
  117. void UIModalOps::ShowBuild()
  118. {
  119. assert(opWindow_.Null());
  120. Show();
  121. // BEGIN LICENSE MANAGEMENT
  122. LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>();
  123. if (licenseSystem->HasPlatformLicense())
  124. opWindow_ = new UIBuild(context_);
  125. else
  126. opWindow_ = new PlatformsInfo(context_);
  127. // END LICENSE MANAGEMENT
  128. }
  129. void UIModalOps::ShowNewProject()
  130. {
  131. assert(opWindow_.Null());
  132. Show();
  133. opWindow_ = new UINewProject(context_);
  134. }
  135. void UIModalOps::SetProgramOutputSubprocess(Object* subprocess)
  136. {
  137. if (opWindow_.Null())
  138. return;
  139. if (opWindow_->GetType() != UIProgramOutput::GetTypeStatic())
  140. return;
  141. UIProgramOutput* output = (UIProgramOutput*)(opWindow_.Get());
  142. output->SetSubprocess(subprocess);
  143. }
  144. void UIModalOps::ShowProgramOutput(Object *subprocess)
  145. {
  146. assert(opWindow_.Null());
  147. Show();
  148. UIProgramOutput* output = new UIProgramOutput(context_);
  149. output->SetSubprocess(subprocess);
  150. opWindow_ = output;
  151. }
  152. void UIModalOps::ShowActivation()
  153. {
  154. assert(opWindow_.Null());
  155. Show();
  156. opWindow_ = new UIActivation(context_);
  157. }
  158. void UIModalOps::ShowActivationSuccess()
  159. {
  160. assert(opWindow_.Null());
  161. Show();
  162. opWindow_ = new UIActivationSuccess(context_);
  163. }
  164. void UIModalOps::ShowAbout()
  165. {
  166. assert(opWindow_.Null());
  167. Show();
  168. opWindow_ = new UIAbout(context_);
  169. }
  170. void UIModalOps::ShowManageLicense()
  171. {
  172. assert(opWindow_.Null());
  173. Show();
  174. opWindow_ = new UIManageLicense(context_);
  175. }
  176. void UIModalOps::ShowPlatformsInfo()
  177. {
  178. assert(opWindow_.Null());
  179. Show();
  180. opWindow_ = new PlatformsInfo(context_);
  181. }
  182. void UIModalOps::OnWidgetDelete(TBWidget *widget)
  183. {
  184. if (isHiding_)
  185. return;
  186. if (opWindow_)
  187. {
  188. if (widget == opWindow_->GetWindow())
  189. Hide();
  190. }
  191. }
  192. bool UIModalOps::OnWidgetDying(TBWidget *widget)
  193. {
  194. return false;
  195. }
  196. UIModalOps::~UIModalOps()
  197. {
  198. }
  199. bool UIModalOps::OnEvent(const TBWidgetEvent &ev)
  200. {
  201. return false;
  202. }
  203. }