BsGUIStatusBar.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "BsGUIStatusBar.h"
  2. #include "BsGUILayoutX.h"
  3. #include "BsGUILayoutY.h"
  4. #include "BsGUILabel.h"
  5. #include "BsGUIButton.h"
  6. #include "BsGUITexture.h"
  7. #include "BsGUIPanel.h"
  8. #include "BsGUISpace.h"
  9. #include "BsDebug.h"
  10. #include "BsBuiltinEditorResources.h"
  11. using namespace std::placeholders;
  12. namespace BansheeEngine
  13. {
  14. GUIStatusBar::GUIStatusBar(const PrivatelyConstruct& dummy,
  15. const String& style, const GUIDimensions& dimensions)
  16. :GUIElementContainer(dimensions, style)
  17. {
  18. mPanel = GUIPanel::create();
  19. mBgPanel = GUIPanel::create(1);
  20. _registerChildElement(mPanel);
  21. _registerChildElement(mBgPanel);
  22. mBackground = GUITexture::create(GUIOptions(GUIOption::flexibleWidth()), getSubStyleName(getGUIBackgroundTypeName()));
  23. mMessage = GUIButton::create(HString(L""), GUIOptions(GUIOption::flexibleWidth()), getSubStyleName(getGUIMessageTypeName()));
  24. GUILayoutX* horzLayout = mPanel->addNewElement<GUILayoutX>();
  25. horzLayout->addNewElement<GUIFixedSpace>(10);
  26. horzLayout->addElement(mMessage);
  27. horzLayout->addNewElement<GUIFixedSpace>(20);
  28. mBgPanel->addElement(mBackground);
  29. mLogEntryAddedConn = gDebug().getLog().onEntryAdded.connect(std::bind(&GUIStatusBar::logEntryAdded, this, _1));
  30. mMessageBtnPressedConn = mMessage->onClick.connect(std::bind(&GUIStatusBar::messageBtnClicked, this));
  31. }
  32. GUIStatusBar::~GUIStatusBar()
  33. {
  34. mLogEntryAddedConn.disconnect();
  35. mMessageBtnPressedConn.disconnect();
  36. }
  37. GUIStatusBar* GUIStatusBar::create(const GUIOptions& options, const String& style)
  38. {
  39. const String* curStyle = &style;
  40. if (*curStyle == StringUtil::BLANK)
  41. curStyle = &getGUITypeName();
  42. return bs_new<GUIStatusBar>(PrivatelyConstruct(), *curStyle, GUIDimensions::create(options));
  43. }
  44. GUIStatusBar* GUIStatusBar::create(const String& style)
  45. {
  46. const String* curStyle = &style;
  47. if (*curStyle == StringUtil::BLANK)
  48. curStyle = &getGUITypeName();
  49. return bs_new<GUIStatusBar>(PrivatelyConstruct(), *curStyle, GUIDimensions::create());
  50. }
  51. void GUIStatusBar::setTint(const Color& color)
  52. {
  53. mBackground->setTint(color);
  54. mMessage->setTint(color);
  55. }
  56. void GUIStatusBar::_updateLayoutInternal(const GUILayoutData& data)
  57. {
  58. mPanel->_setLayoutData(data);
  59. mPanel->_updateLayoutInternal(data);
  60. mBgPanel->_setLayoutData(data);
  61. mBgPanel->_updateLayoutInternal(data);
  62. }
  63. Vector2I GUIStatusBar::_getOptimalSize() const
  64. {
  65. return mBgPanel->_getOptimalSize();
  66. }
  67. void GUIStatusBar::styleUpdated()
  68. {
  69. mBackground->setStyle(getSubStyleName(getGUIBackgroundTypeName()));
  70. mMessage->setStyle(getSubStyleName(getGUIMessageTypeName()));
  71. }
  72. void GUIStatusBar::logEntryAdded(const LogEntry& entry)
  73. {
  74. HSpriteTexture iconTexture;
  75. UINT32 logChannel = entry.getChannel();
  76. switch (logChannel)
  77. {
  78. case (UINT32)DebugChannel::Info:
  79. case (UINT32)DebugChannel::Debug:
  80. iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Info);
  81. break;
  82. case (UINT32)DebugChannel::Warning:
  83. iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Warning);
  84. break;
  85. case (UINT32)DebugChannel::Error:
  86. iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Error);
  87. break;
  88. }
  89. GUIContent messageContent(HString(toWString(entry.getMessage())), iconTexture);
  90. mMessage->setContent(messageContent);
  91. }
  92. void GUIStatusBar::messageBtnClicked()
  93. {
  94. onMessageClicked();
  95. }
  96. const String& GUIStatusBar::getGUITypeName()
  97. {
  98. static String TypeName = "GUIStatusBar";
  99. return TypeName;
  100. }
  101. const String& GUIStatusBar::getGUIBackgroundTypeName()
  102. {
  103. static String TypeName = "GUIStatusBarBg";
  104. return TypeName;
  105. }
  106. const String& GUIStatusBar::getGUIMessageTypeName()
  107. {
  108. static String TypeName = "GUIStatusBarMessage";
  109. return TypeName;
  110. }
  111. }