| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "GUI/BsGUIStatusBar.h"
- #include "GUI/BsGUILayoutX.h"
- #include "GUI/BsGUILayoutY.h"
- #include "GUI/BsGUILabel.h"
- #include "GUI/BsGUIButton.h"
- #include "GUI/BsGUITexture.h"
- #include "GUI/BsGUIPanel.h"
- #include "GUI/BsGUISpace.h"
- #include "Debug/BsDebug.h"
- #include "Utility/BsBuiltinEditorResources.h"
- using namespace std::placeholders;
- namespace bs
- {
- const Color GUIStatusBar::COLOR_INFO = Color(0.7f, 0.7f, 0.7f);
- const Color GUIStatusBar::COLOR_WARNING = Color(192 / 255.0f, 176 / 255.0f, 0.0f);
- const Color GUIStatusBar::COLOR_ERROR = Color(192 / 255.0f, 36 / 255.0f, 0.0f);
- GUIStatusBar::GUIStatusBar(const PrivatelyConstruct& dummy, const String& style, const GUIDimensions& dimensions)
- :GUIElementContainer(dimensions, style)
- {
- mPanel = GUIPanel::create();
- mBgPanel = GUIPanel::create(1);
- _registerChildElement(mPanel);
- _registerChildElement(mBgPanel);
- mBackground = GUITexture::create(GUIOptions(GUIOption::flexibleWidth()), getSubStyleName(getGUIBackgroundTypeName()));
- mMessage = GUIButton::create(HString(""), GUIOptions(GUIOption::flexibleWidth()), getSubStyleName(getGUIMessageTypeName()));
- mScene = GUILabel::create(HString("Scene: Unnamed"), GUIOptions(GUIOption::fixedWidth(150)));
- mProject = GUILabel::create(HString("Project: None"), GUIOptions(GUIOption::fixedWidth(200)));
- mCompiling = GUILabel::create(HString("Compiling..."), GUIOptions(GUIOption::fixedWidth(100)));
- GUILayoutY* vertLayout = mPanel->addNewElement<GUILayoutY>();
- vertLayout->addNewElement<GUIFixedSpace>(3);
- GUILayoutX* horzLayout = vertLayout->addNewElement<GUILayoutX>();
- horzLayout->addNewElement<GUIFixedSpace>(10);
- horzLayout->addElement(mMessage);
- horzLayout->addNewElement<GUIFlexibleSpace>();
- horzLayout->addElement(mScene);
- horzLayout->addNewElement<GUIFixedSpace>(10);
- horzLayout->addElement(mProject);
- horzLayout->addNewElement<GUIFixedSpace>(10);
- horzLayout->addElement(mCompiling);
- horzLayout->addNewElement<GUIFixedSpace>(10);
- mBgPanel->addElement(mBackground);
- mCompiling->setActive(false);
- mLogEntryAddedConn = gDebug().onLogModified.connect(std::bind(&GUIStatusBar::logModified, this));
- mMessageBtnPressedConn = mMessage->onClick.connect(std::bind(&GUIStatusBar::messageBtnClicked, this));
- }
- GUIStatusBar::~GUIStatusBar()
- {
- mLogEntryAddedConn.disconnect();
- mMessageBtnPressedConn.disconnect();
- }
- GUIStatusBar* GUIStatusBar::create(const GUIOptions& options, const String& style)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &getGUITypeName();
- return bs_new<GUIStatusBar>(PrivatelyConstruct(), *curStyle, GUIDimensions::create(options));
- }
- GUIStatusBar* GUIStatusBar::create(const String& style)
- {
- const String* curStyle = &style;
- if (*curStyle == StringUtil::BLANK)
- curStyle = &getGUITypeName();
- return bs_new<GUIStatusBar>(PrivatelyConstruct(), *curStyle, GUIDimensions::create());
- }
- void GUIStatusBar::setProject(const String& name, bool modified)
- {
- StringStream content;
- content << "Project: ";
- if (name.size() > 20)
- content << name.substr(0, 20) << "...";
- else
- content << name;
- if (modified)
- content << "*";
- mProject->setContent(HString(content.str()));
- }
- void GUIStatusBar::setScene(const String& name, bool modified)
- {
- StringStream content;
- content << "Scene: ";
- if (name.size() > 15)
- content << name.substr(0, 15) << "...";
- else
- content << name;
- if (modified)
- content << L"*";
- mScene->setContent(HString(content.str()));
- }
- void GUIStatusBar::setIsCompiling(bool compiling)
- {
- mCompiling->setActive(compiling);
- }
-
- void GUIStatusBar::setTint(const Color& color)
- {
- mBackground->setTint(color);
- mMessage->setTint(color);
- }
- void GUIStatusBar::_updateLayoutInternal(const GUILayoutData& data)
- {
- mPanel->_setLayoutData(data);
- mPanel->_updateLayoutInternal(data);
- mBgPanel->_setLayoutData(data);
- mBgPanel->_updateLayoutInternal(data);
- }
- Vector2I GUIStatusBar::_getOptimalSize() const
- {
- return mBgPanel->_getOptimalSize();
- }
-
- void GUIStatusBar::styleUpdated()
- {
- mBackground->setStyle(getSubStyleName(getGUIBackgroundTypeName()));
- mMessage->setStyle(getSubStyleName(getGUIMessageTypeName()));
- }
- void GUIStatusBar::logModified()
- {
- LogEntry entry;
- if(!gDebug().getLog().getLastEntry(entry))
- {
- GUIContent messageContent(HString(""));
- mMessage->setContent(messageContent);
- return;
- }
- HSpriteTexture iconTexture;
- Color textColor = COLOR_INFO;
- UINT32 logChannel = entry.getChannel();
- switch (logChannel)
- {
- case (UINT32)DebugChannel::Debug:
- iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Info, 16, false);
- break;
- case (UINT32)DebugChannel::Warning:
- case (UINT32)DebugChannel::CompilerWarning:
- iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Warning, 16, false);
- textColor = COLOR_WARNING;
- break;
- case (UINT32)DebugChannel::Error:
- case (UINT32)DebugChannel::CompilerError:
- iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Error, 16, false);
- textColor = COLOR_ERROR;
- break;
- }
- String message = entry.getMessage();
- size_t lfPos = message.find_first_of('\n');
- size_t crPos = message.find_first_of('\r');
- size_t newlinePos;
- if (lfPos != String::npos)
- {
- if (crPos != String::npos)
- newlinePos = std::min(lfPos, crPos);
- else
- newlinePos = lfPos;
- }
- else if (crPos != String::npos)
- newlinePos = crPos;
- else
- newlinePos = -1;
- if (newlinePos == (UINT32)-1)
- {
- GUIContent messageContent(HString(message), iconTexture);
- mMessage->setContent(messageContent);
- mMessage->setTint(textColor);
- }
- else
- {
- String firstLine = message.substr(0, newlinePos);
- GUIContent messageContent(HString(firstLine), iconTexture);
- mMessage->setContent(messageContent);
- mMessage->setTint(textColor);
- }
- }
- void GUIStatusBar::messageBtnClicked()
- {
- onMessageClicked();
- }
- const String& GUIStatusBar::getGUITypeName()
- {
- static String TypeName = "GUIStatusBar";
- return TypeName;
- }
- const String& GUIStatusBar::getGUIBackgroundTypeName()
- {
- static String TypeName = "GUIStatusBarBg";
- return TypeName;
- }
- const String& GUIStatusBar::getGUIMessageTypeName()
- {
- static String TypeName = "GUIStatusBarMessage";
- return TypeName;
- }
- }
|