|
|
@@ -35,49 +35,55 @@
|
|
|
#include "UI.h"
|
|
|
#include "UIEvents.h"
|
|
|
|
|
|
+#include "DebugNew.h"
|
|
|
+
|
|
|
Console::Console(Engine* engine) :
|
|
|
mEngine(engine),
|
|
|
mFontSize(1)
|
|
|
{
|
|
|
LOGINFO("Console created");
|
|
|
|
|
|
- if (!mEngine)
|
|
|
- return;
|
|
|
-
|
|
|
- Log* log = getLog();
|
|
|
- if (log)
|
|
|
- log->addListener(this);
|
|
|
-
|
|
|
- UIElement* uiRoot = mEngine->getUIRoot();
|
|
|
- if (!uiRoot)
|
|
|
- return;
|
|
|
-
|
|
|
- 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));
|
|
|
+ if (mEngine)
|
|
|
+ {
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Console::~Console()
|
|
|
{
|
|
|
+ Log* log = getLog();
|
|
|
+ if (log)
|
|
|
+ log->removeListener(this);
|
|
|
+
|
|
|
if (mEngine)
|
|
|
{
|
|
|
UIElement* uiRoot = mEngine->getUIRoot();
|
|
|
@@ -85,10 +91,6 @@ Console::~Console()
|
|
|
uiRoot->removeChild(mBackground);
|
|
|
}
|
|
|
|
|
|
- Log* log = getLog();
|
|
|
- if (log)
|
|
|
- log->removeListener(this);
|
|
|
-
|
|
|
LOGINFO("Console shut down");
|
|
|
}
|
|
|
|
|
|
@@ -111,7 +113,7 @@ void Console::write(const std::string& message)
|
|
|
|
|
|
void Console::setVisible(bool enable)
|
|
|
{
|
|
|
- if (!mBackground)
|
|
|
+ if ((!mEngine) || (!mBackground))
|
|
|
return;
|
|
|
|
|
|
mBackground->setVisible(enable);
|
|
|
@@ -167,6 +169,9 @@ bool Console::isVisible() const
|
|
|
|
|
|
void Console::updateElements()
|
|
|
{
|
|
|
+ if (!mEngine)
|
|
|
+ return;
|
|
|
+
|
|
|
int width = mEngine->getRenderer()->getWidth();
|
|
|
|
|
|
if (mFont)
|
|
|
@@ -186,6 +191,9 @@ void Console::updateElements()
|
|
|
|
|
|
void Console::handleTextFinished(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
|
+ if (!mEngine)
|
|
|
+ return;
|
|
|
+
|
|
|
using namespace TextFinished;
|
|
|
|
|
|
if (eventData[P_ELEMENT].getPtr() == (void*)mLineEdit)
|