Console & DebugHUD code cleanup.
This commit is contained in:
parent
ffce296795
commit
e4bb607126
@ -43,38 +43,38 @@ Console::Console(Engine* engine) :
|
||||
{
|
||||
LOGINFO("Console created");
|
||||
|
||||
if (mEngine)
|
||||
if (!mEngine)
|
||||
EXCEPTION("Null Engine for Console");
|
||||
|
||||
UIElement* uiRoot = mEngine->getUIRoot();
|
||||
if (uiRoot)
|
||||
{
|
||||
UIElement* uiRoot = mEngine->getUIRoot();
|
||||
if (uiRoot)
|
||||
{
|
||||
Log* log = getLog();
|
||||
if (log)
|
||||
log->addListener(this);
|
||||
|
||||
mBackground = new BorderImage();
|
||||
mBackground->setWidth(uiRoot->getWidth());
|
||||
mBackground->setColor(C_TOPLEFT, Color(0.0f, 0.25f, 0.0f, 0.75f));
|
||||
mBackground->setColor(C_TOPRIGHT, Color(0.0f, 0.25f, 0.0f, 0.75f));
|
||||
mBackground->setColor(C_BOTTOMLEFT, Color(0.25f, 0.75f, 0.25f, 0.75f));
|
||||
mBackground->setColor(C_BOTTOMRIGHT, Color(0.25f, 0.75f, 0.25f, 0.75f));
|
||||
mBackground->setBringToBack(false);
|
||||
mBackground->setEnabled(true);
|
||||
mBackground->setVisible(false);
|
||||
mBackground->setPriority(200); // Show on top of the debug HUD
|
||||
|
||||
mLineEdit = new LineEdit();
|
||||
mLineEdit->setColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
mLineEdit->setDefocusable(false);
|
||||
mBackground->addChild(mLineEdit);
|
||||
|
||||
uiRoot->addChild(mBackground);
|
||||
|
||||
updateElements();
|
||||
|
||||
subscribeToEvent(EVENT_TEXTFINISHED, EVENT_HANDLER(Console, handleTextFinished));
|
||||
subscribeToEvent(EVENT_WINDOWRESIZED, EVENT_HANDLER(Console, handleWindowResized));
|
||||
}
|
||||
Log* log = getLog();
|
||||
if (log)
|
||||
log->addListener(this);
|
||||
|
||||
mBackground = new BorderImage();
|
||||
mBackground->setWidth(uiRoot->getWidth());
|
||||
mBackground->setColor(C_TOPLEFT, Color(0.0f, 0.25f, 0.0f, 0.75f));
|
||||
mBackground->setColor(C_TOPRIGHT, Color(0.0f, 0.25f, 0.0f, 0.75f));
|
||||
mBackground->setColor(C_BOTTOMLEFT, Color(0.25f, 0.75f, 0.25f, 0.75f));
|
||||
mBackground->setColor(C_BOTTOMRIGHT, Color(0.25f, 0.75f, 0.25f, 0.75f));
|
||||
mBackground->setBringToBack(false);
|
||||
mBackground->setEnabled(true);
|
||||
mBackground->setVisible(false);
|
||||
mBackground->setPriority(200); // Show on top of the debug HUD
|
||||
|
||||
mLineEdit = new LineEdit();
|
||||
mLineEdit->setColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
mLineEdit->setDefocusable(false);
|
||||
mBackground->addChild(mLineEdit);
|
||||
|
||||
uiRoot->addChild(mBackground);
|
||||
|
||||
updateElements();
|
||||
|
||||
subscribeToEvent(EVENT_TEXTFINISHED, EVENT_HANDLER(Console, handleTextFinished));
|
||||
subscribeToEvent(EVENT_WINDOWRESIZED, EVENT_HANDLER(Console, handleWindowResized));
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,12 +84,9 @@ Console::~Console()
|
||||
if (log)
|
||||
log->removeListener(this);
|
||||
|
||||
if (mEngine)
|
||||
{
|
||||
UIElement* uiRoot = mEngine->getUIRoot();
|
||||
if (uiRoot)
|
||||
uiRoot->removeChild(mBackground);
|
||||
}
|
||||
UIElement* uiRoot = mEngine->getUIRoot();
|
||||
if (uiRoot)
|
||||
uiRoot->removeChild(mBackground);
|
||||
|
||||
LOGINFO("Console shut down");
|
||||
}
|
||||
@ -113,7 +110,7 @@ void Console::write(const std::string& message)
|
||||
|
||||
void Console::setVisible(bool enable)
|
||||
{
|
||||
if ((!mEngine) || (!mBackground))
|
||||
if (!mBackground)
|
||||
return;
|
||||
|
||||
mBackground->setVisible(enable);
|
||||
@ -169,9 +166,6 @@ bool Console::isVisible() const
|
||||
|
||||
void Console::updateElements()
|
||||
{
|
||||
if (!mEngine)
|
||||
return;
|
||||
|
||||
int width = mEngine->getRenderer()->getWidth();
|
||||
|
||||
if (mFont)
|
||||
@ -191,9 +185,6 @@ void Console::updateElements()
|
||||
|
||||
void Console::handleTextFinished(StringHash eventType, VariantMap& eventData)
|
||||
{
|
||||
if (!mEngine)
|
||||
return;
|
||||
|
||||
using namespace TextFinished;
|
||||
|
||||
if (eventData[P_ELEMENT].getPtr() == (void*)mLineEdit)
|
||||
|
@ -73,7 +73,7 @@ private:
|
||||
void handleWindowResized(StringHash eventType, VariantMap& eventData);
|
||||
|
||||
//! Engine
|
||||
WeakPtr<Engine> mEngine;
|
||||
Engine* mEngine;
|
||||
//! Background
|
||||
SharedPtr<BorderImage> mBackground;
|
||||
//! Font
|
||||
|
@ -39,45 +39,42 @@ DebugHud::DebugHud(Engine* engine) :
|
||||
mProfilerInterval(1.0f),
|
||||
mProfilerTimer(0.0f)
|
||||
{
|
||||
if (!mEngine)
|
||||
EXCEPTION("Null Engine for Debug HUD");
|
||||
|
||||
LOGINFO("Debug HUD created");
|
||||
|
||||
if (mEngine)
|
||||
UIElement* uiRoot = mEngine->getUIRoot();
|
||||
if (uiRoot)
|
||||
{
|
||||
UIElement* uiRoot = mEngine->getUIRoot();
|
||||
if (uiRoot)
|
||||
{
|
||||
mStatsText = new Text();
|
||||
mStatsText->setAlignment(HA_LEFT, VA_TOP);
|
||||
mStatsText->setPriority(100);
|
||||
mStatsText->setVisible(false);
|
||||
uiRoot->addChild(mStatsText);
|
||||
|
||||
mModeText = new Text();
|
||||
mModeText->setAlignment(HA_LEFT, VA_BOTTOM);
|
||||
mModeText->setPriority(100);
|
||||
mModeText->setVisible(false);
|
||||
uiRoot->addChild(mModeText);
|
||||
|
||||
mProfilerText = new Text();
|
||||
mProfilerText->setAlignment(HA_RIGHT, VA_TOP);
|
||||
mProfilerText->setPriority(100);
|
||||
mProfilerText->setVisible(false);
|
||||
uiRoot->addChild(mProfilerText);
|
||||
}
|
||||
mStatsText = new Text();
|
||||
mStatsText->setAlignment(HA_LEFT, VA_TOP);
|
||||
mStatsText->setPriority(100);
|
||||
mStatsText->setVisible(false);
|
||||
uiRoot->addChild(mStatsText);
|
||||
|
||||
mModeText = new Text();
|
||||
mModeText->setAlignment(HA_LEFT, VA_BOTTOM);
|
||||
mModeText->setPriority(100);
|
||||
mModeText->setVisible(false);
|
||||
uiRoot->addChild(mModeText);
|
||||
|
||||
mProfilerText = new Text();
|
||||
mProfilerText->setAlignment(HA_RIGHT, VA_TOP);
|
||||
mProfilerText->setPriority(100);
|
||||
mProfilerText->setVisible(false);
|
||||
uiRoot->addChild(mProfilerText);
|
||||
}
|
||||
}
|
||||
|
||||
DebugHud::~DebugHud()
|
||||
{
|
||||
if (mEngine)
|
||||
UIElement* uiRoot = mEngine->getUIRoot();
|
||||
if (uiRoot)
|
||||
{
|
||||
UIElement* uiRoot = mEngine->getUIRoot();
|
||||
if (uiRoot)
|
||||
{
|
||||
uiRoot->removeChild(mStatsText);
|
||||
uiRoot->removeChild(mModeText);
|
||||
uiRoot->removeChild(mProfilerText);
|
||||
}
|
||||
uiRoot->removeChild(mStatsText);
|
||||
uiRoot->removeChild(mModeText);
|
||||
uiRoot->removeChild(mProfilerText);
|
||||
}
|
||||
|
||||
LOGINFO("Debug HUD shut down");
|
||||
@ -85,9 +82,6 @@ DebugHud::~DebugHud()
|
||||
|
||||
void DebugHud::update(float timeStep)
|
||||
{
|
||||
if (!mEngine)
|
||||
return;
|
||||
|
||||
Pipeline* pipeline = mEngine->getPipeline();
|
||||
Renderer* renderer = mEngine->getRenderer();
|
||||
if ((!pipeline) || (!renderer))
|
||||
|
@ -64,7 +64,7 @@ public:
|
||||
|
||||
private:
|
||||
//! Engine
|
||||
WeakPtr<Engine> mEngine;
|
||||
Engine* mEngine;
|
||||
//! Rendering stats text
|
||||
SharedPtr<Text> mStatsText;
|
||||
//! Rendering mode text
|
||||
|
Loading…
Reference in New Issue
Block a user