Sdk/Console: Turn console into a widget (WIP)

This commit is contained in:
Lynix
2017-01-15 13:25:12 +01:00
parent c9458eeb17
commit dc439d69a5
7 changed files with 58 additions and 286 deletions

View File

@@ -17,6 +17,7 @@
#include <vector>
#ifndef NDK_SERVER
#include <NDK/Canvas.hpp>
#include <NDK/Console.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Lua/LuaInstance.hpp>
@@ -83,7 +84,7 @@ namespace Ndk
#ifndef NDK_SERVER
struct ConsoleOverlay
{
std::unique_ptr<Console> console;
Console* console;
Nz::LuaInstance lua;
NazaraSlot(Nz::EventHandler, OnEvent, eventSlot);
@@ -116,10 +117,11 @@ namespace Ndk
Nz::RenderTarget* renderTarget;
std::unique_ptr<Nz::Window> window;
std::unique_ptr<ConsoleOverlay> console;
std::unique_ptr<Canvas> canvas;
std::unique_ptr<FPSCounterOverlay> fpsCounter;
std::unique_ptr<World> overlayWorld;
};
void SetupConsole(WindowInfo& info);
void SetupFPSCounter(WindowInfo& info);
void SetupOverlay(WindowInfo& info);

View File

@@ -114,7 +114,6 @@ namespace Ndk
}
m_overlayFlags |= OverlayFlags_Console;
}
else
{

View File

@@ -15,6 +15,7 @@
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/Node.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <NDK/BaseWidget.hpp>
#include <NDK/EntityOwner.hpp>
namespace Nz
@@ -26,13 +27,14 @@ namespace Ndk
{
class Console;
class Entity;
class TextAreaWidget;
using ConsoleHandle = Nz::ObjectHandle<Console>;
class NDK_API Console : public Nz::Node, public Nz::HandledObject<Console>
class NDK_API Console : public BaseWidget, public Nz::HandledObject<Console>
{
public:
Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance);
Console(BaseWidget* parent, Nz::LuaInstance& instance);
Console(const Console& console) = delete;
Console(Console&& console) = default;
~Console() = default;
@@ -42,31 +44,22 @@ namespace Ndk
void Clear();
inline unsigned int GetCharacterSize() const;
inline const EntityHandle& GetHistory() const;
inline const EntityHandle& GetHistoryBackground() const;
inline const EntityHandle& GetInput() const;
inline const EntityHandle& GetInputBackground() const;
inline const Nz::Vector2f& GetSize() const;
inline const TextAreaWidget* GetHistory() const;
inline const TextAreaWidget* GetInput() const;
inline const Nz::FontRef& GetTextFont() const;
inline bool IsVisible() const;
void SendCharacter(char32_t character);
void SendEvent(const Nz::WindowEvent& event);
void ResizeToContent() override;
void SetCharacterSize(unsigned int size);
void SetSize(const Nz::Vector2f& size);
void SetTextFont(Nz::FontRef font);
void Show(bool show = true);
Console& operator=(const Console& console) = delete;
Console& operator=(Console&& console) = default;
private:
void AddLineInternal(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
void ExecuteInput();
void Layout();
void Layout() override;
void RefreshHistory();
struct Line
@@ -78,20 +71,10 @@ namespace Ndk
std::size_t m_historyPosition;
std::vector<Nz::String> m_commandHistory;
std::vector<Line> m_historyLines;
EntityOwner m_historyBackground;
EntityOwner m_history;
EntityOwner m_input;
EntityOwner m_inputBackground;
TextAreaWidget* m_history;
TextAreaWidget* m_input;
Nz::FontRef m_defaultFont;
Nz::LuaInstance& m_instance;
Nz::SpriteRef m_historyBackgroundSprite;
Nz::SpriteRef m_inputBackgroundSprite;
Nz::SimpleTextDrawer m_historyDrawer;
Nz::SimpleTextDrawer m_inputDrawer;
Nz::TextSpriteRef m_historyTextSprite;
Nz::TextSpriteRef m_inputTextSprite;
Nz::Vector2f m_size;
bool m_opened;
unsigned int m_characterSize;
unsigned int m_maxHistoryLines;
};

View File

@@ -22,51 +22,21 @@ namespace Ndk
* \return History of the console
*/
inline const EntityHandle& Console::GetHistory() const
inline const TextAreaWidget* Console::GetHistory() const
{
return m_history;
}
/*!
* \brief Gets the entity representing the background of the console's history
* \return Background history of the console
*/
inline const EntityHandle& Console::GetHistoryBackground() const
{
return m_historyBackground;
}
/*!
* \brief Gets the entity representing the input of the console
* \return Input of the console
*/
inline const EntityHandle& Console::GetInput() const
inline const TextAreaWidget* Console::GetInput() const
{
return m_input;
}
/*!
* \brief Gets the entity representing the background of the console's input
* \return Background input of the console
*/
inline const EntityHandle& Console::GetInputBackground() const
{
return m_inputBackground;
}
/*!
* \brief Gets the size of the console
* \return Size (Width, Height) of the console
*/
inline const Nz::Vector2f& Console::GetSize() const
{
return m_size;
}
/*!
* \brief Gets the font used by the console
* \return A reference to the font currenty used
@@ -76,14 +46,4 @@ namespace Ndk
{
return m_defaultFont;
}
/*!
* \brief Checks whether the console is visible
* \return true If it is the case
*/
inline bool Console::IsVisible() const
{
return m_opened;
}
}