Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Console.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Development Kit"
3 // For conditions of distribution and use, see copyright notice in Prerequesites.hpp
4 
5 #pragma once
6 
7 #ifndef NDK_SERVER
8 #ifndef NDK_CONSOLE_HPP
9 #define NDK_CONSOLE_HPP
10 
11 #include <Nazara/Core/HandledObject.hpp>
12 #include <Nazara/Core/ObjectHandle.hpp>
13 #include <Nazara/Graphics/Sprite.hpp>
14 #include <Nazara/Graphics/TextSprite.hpp>
15 #include <Nazara/Utility/Node.hpp>
16 #include <Nazara/Utility/SimpleTextDrawer.hpp>
17 #include <NDK/EntityOwner.hpp>
18 
19 namespace Nz
20 {
21  class LuaState;
22  struct WindowEvent;
23 }
24 
25 namespace Ndk
26 {
27  class Console;
28 
29  using ConsoleHandle = Nz::ObjectHandle<Console>;
30 
31  class NDK_API Console : public Nz::Node, public Nz::HandledObject<Console>
32  {
33  public:
34  Console(World& world, const Nz::Vector2f& size, Nz::LuaState& state);
35  Console(const Console& console) = delete;
36  Console(Console&& console) = default;
37  ~Console() = default;
38 
39  void AddLine(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
40 
41  void Clear();
42 
43  inline unsigned int GetCharacterSize() const;
44  inline const EntityHandle& GetHistory() const;
45  inline const EntityHandle& GetHistoryBackground() const;
46  inline const EntityHandle& GetInput() const;
47  inline const EntityHandle& GetInputBackground() const;
48  inline const Nz::Vector2f& GetSize() const;
49  inline const Nz::FontRef& GetTextFont() const;
50 
51  inline bool IsVisible() const;
52 
53  void SendCharacter(char32_t character);
54  void SendEvent(const Nz::WindowEvent& event);
55 
56  void SetCharacterSize(unsigned int size);
57  void SetSize(const Nz::Vector2f& size);
58  void SetTextFont(Nz::FontRef font);
59 
60  void Show(bool show = true);
61 
62  Console& operator=(const Console& console) = delete;
63  Console& operator=(Console&& console) = default;
64 
65  private:
66  void AddLineInternal(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
67  void ExecuteInput();
68  void Layout();
69  void RefreshHistory();
70 
71  struct Line
72  {
73  Nz::Color color;
74  Nz::String text;
75  };
76 
77  std::size_t m_historyPosition;
78  std::vector<Nz::String> m_commandHistory;
79  std::vector<Line> m_historyLines;
80  EntityOwner m_historyBackground;
81  EntityOwner m_history;
82  EntityOwner m_input;
83  EntityOwner m_inputBackground;
84  Nz::FontRef m_defaultFont;
85  Nz::LuaState& m_state;
86  Nz::SpriteRef m_historyBackgroundSprite;
87  Nz::SpriteRef m_inputBackgroundSprite;
88  Nz::SimpleTextDrawer m_historyDrawer;
89  Nz::SimpleTextDrawer m_inputDrawer;
90  Nz::TextSpriteRef m_historyTextSprite;
91  Nz::TextSpriteRef m_inputTextSprite;
92  Nz::Vector2f m_size;
93  bool m_opened;
94  unsigned int m_characterSize;
95  unsigned int m_maxHistoryLines;
96  };
97 }
98 
99 #include <NDK/Console.inl>
100 
101 #endif // NDK_CONSOLE_HPP
102 #endif // NDK_SERVER
TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so...
Definition: Algorithm.hpp:12
Core class that represents a color.
Definition: Color.hpp:18
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
NDK class that represents the owner of the entity and so its lifetime.
Definition: EntityOwner.hpp:14
Core class that represents a string.
Definition: String.hpp:22
NDK class that represents a console to help development with Lua scripting.
Definition: Console.hpp:31
NDK class that represents a world.
Definition: World.hpp:25