Shkyera Engine
Easy to use, game engine for Python
ConsoleWidget.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <memory>
10 #include <mutex>
11 #include <vector>
12 
13 #include "ui/Widget.hpp"
14 
15 namespace shkyera {
16 
20 class Log {
21  public:
27  Log(std::string content);
28 
32  virtual void draw() const;
33 
39  virtual uint64_t getIconId() const = 0;
40 
41  std::string _content;
42 };
43 
47 class LogVerbose : public Log {
48  public:
49  using Log::Log;
50 
56  virtual uint64_t getIconId() const override;
57 };
58 
62 class LogInfo : public Log {
63  public:
64  using Log::Log;
65 
71  virtual uint64_t getIconId() const override;
72 };
73 
77 class LogSuccess : public Log {
78  public:
79  using Log::Log;
80 
86  virtual uint64_t getIconId() const override;
87 };
88 
92 class LogError : public Log {
93  public:
94  using Log::Log;
95 
101  virtual uint64_t getIconId() const override;
102 };
103 
107 class ConsoleWidget : public Widget {
108  public:
109  using Widget::Widget;
110 
114  virtual void draw() override;
115 
119  static void clear();
120 
124  static void enableVerbose();
125 
129  static void disableVerbose();
130 
136  static void logVerbose(std::string text);
137 
143  static void logInfo(std::string text);
144 
150  static void logSuccess(std::string text);
151 
157  static void logError(std::string text);
158 
162  static constexpr size_t MAX_LOGS = 50;
163 
164  private:
168  void drawInfoBar() const;
169 
170  static size_t _totalVerbose;
171  static size_t _totalInfo;
172  static size_t _totalSuccess;
173  static size_t _totalError;
174 
175  static std::vector<std::shared_ptr<Log>> _logs;
176  static bool _verbose;
177 };
178 
179 } // namespace shkyera
Contains the declaration of the Widget class, an abstract base class for GUI widgets.
A user interface widget for the console, used for logging and displaying messages.
Definition: ConsoleWidget.hpp:107
static size_t _totalVerbose
The total number of verbose logs.
Definition: ConsoleWidget.hpp:170
static size_t _totalInfo
The total number of informational logs.
Definition: ConsoleWidget.hpp:171
static void logInfo(std::string text)
Log an informational message to the console.
Definition: ConsoleWidget.cpp:95
static size_t _totalSuccess
The total number of success logs.
Definition: ConsoleWidget.hpp:172
static void enableVerbose()
Enable verbose logging mode.
Definition: ConsoleWidget.cpp:84
static size_t _totalError
The total number of error logs.
Definition: ConsoleWidget.hpp:173
virtual void draw() override
Implementation of the abstract draw method to render the console widget.
Definition: ConsoleWidget.cpp:25
static void disableVerbose()
Disable verbose logging mode.
Definition: ConsoleWidget.cpp:85
static std::vector< std::shared_ptr< Log > > _logs
A collection of logs in the console.
Definition: ConsoleWidget.hpp:175
void drawInfoBar() const
Draw the information bar of the console widget.
Definition: ConsoleWidget.cpp:41
static constexpr size_t MAX_LOGS
The maximum number of logs to keep in the console.
Definition: ConsoleWidget.hpp:162
static bool _verbose
A flag indicating verbose logging mode.
Definition: ConsoleWidget.hpp:176
static void logVerbose(std::string text)
Log a verbose message to the console.
Definition: ConsoleWidget.cpp:87
static void clear()
Clear all logs from the console widget.
Definition: ConsoleWidget.cpp:75
static void logError(std::string text)
Log an error message to the console.
Definition: ConsoleWidget.cpp:111
static void logSuccess(std::string text)
Log a success message to the console.
Definition: ConsoleWidget.cpp:103
A log representing error messages.
Definition: ConsoleWidget.hpp:92
virtual uint64_t getIconId() const override
Get the icon identifier for error logs.
Definition: ConsoleWidget.cpp:23
A base class for logs that contain textual content.
Definition: ConsoleWidget.hpp:20
virtual uint64_t getIconId() const =0
Virtual method to retrieve an icon identifier associated with the log.
Log(std::string content)
Constructor to create a log with the specified content.
Definition: ConsoleWidget.cpp:11
virtual void draw() const
Virtual method to draw the log in the user interface.
Definition: ConsoleWidget.cpp:13
std::string _content
The text content of the log.
Definition: ConsoleWidget.hpp:41
A log representing informational messages.
Definition: ConsoleWidget.hpp:62
virtual uint64_t getIconId() const override
Get the icon identifier for informational logs.
Definition: ConsoleWidget.cpp:21
A log representing success messages.
Definition: ConsoleWidget.hpp:77
virtual uint64_t getIconId() const override
Get the icon identifier for success logs.
Definition: ConsoleWidget.cpp:22
A log representing verbose messages.
Definition: ConsoleWidget.hpp:47
virtual uint64_t getIconId() const override
Get the icon identifier for verbose logs.
Definition: ConsoleWidget.cpp:20
An abstract base class representing a GUI widget.
Definition: Widget.hpp:21
Widget(std::string name)
Constructor to create a widget with a specified name.
Definition: Widget.cpp:5
Definition: Entity.cpp:3