UIMainToolbar.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <Atomic/UI/TBUI.h>
  6. #include <Atomic/IO/Log.h>
  7. #include "UIMainToolbar.h"
  8. #include "../AEEvents.h"
  9. #include "../AETypes.h"
  10. #include "../AEEditor.h"
  11. #include "UIMainFrame.h"
  12. #include "UIResourceFrame.h"
  13. using namespace tb;
  14. namespace AtomicEditor
  15. {
  16. MainToolbar::MainToolbar(Context* context) :
  17. AEWidget(context)
  18. {
  19. TBUI* tbui = GetSubsystem<TBUI>();
  20. tbui->LoadResourceFile(delegate_, "AtomicEditor/editor/ui/maintoolbar.tb.txt");
  21. Show3DWidgets(false);
  22. }
  23. MainToolbar::~MainToolbar()
  24. {
  25. }
  26. void MainToolbar::Show3DWidgets(bool value)
  27. {
  28. TBButton* button = delegate_->GetWidgetByIDAndType<TBButton>(TBIDC("3d_translate"));
  29. if (button)
  30. button->SetVisibilility( value ? WIDGET_VISIBILITY_VISIBLE : WIDGET_VISIBILITY_GONE);
  31. button = delegate_->GetWidgetByIDAndType<TBButton>(TBIDC("3d_rotate"));
  32. if (button)
  33. button->SetVisibilility( value ? WIDGET_VISIBILITY_VISIBLE : WIDGET_VISIBILITY_GONE);
  34. button = delegate_->GetWidgetByIDAndType<TBButton>(TBIDC("3d_scale"));
  35. if (button)
  36. button->SetVisibilility( value ? WIDGET_VISIBILITY_VISIBLE : WIDGET_VISIBILITY_GONE);
  37. }
  38. bool MainToolbar::OnEvent(const TBWidgetEvent &ev)
  39. {
  40. if (ev.type == EVENT_TYPE_CLICK)
  41. {
  42. if (ev.target->GetID() == TBIDC("3d_translate") ||
  43. ev.target->GetID() == TBIDC("3d_rotate") ||
  44. ev.target->GetID() == TBIDC("3d_scale") )
  45. {
  46. ResourceFrame* rframe = GetSubsystem<MainFrame>()->GetResourceFrame();
  47. rframe->SendCurrentEditorEvent(ev);
  48. }
  49. if (ev.target && ev.target->GetID() == TBIDC("maintoolbar_play"))
  50. {
  51. if (GetSubsystem<Editor>()->IsPlayingProject())
  52. {
  53. SendEvent(E_EDITORPLAYSTOP);
  54. return true;
  55. }
  56. else
  57. {
  58. VariantMap eventData;
  59. eventData[EditorPlayRequest::P_MODE] = (unsigned) AE_PLAYERMODE_WIDGET;
  60. SendEvent(E_EDITORPLAYREQUEST, eventData);
  61. return true;
  62. }
  63. }
  64. }
  65. return false;
  66. }
  67. }