openMSX
ImGuiMessages.hh
Go to the documentation of this file.
1#ifndef IMGUI_MESSAGES_HH
2#define IMGUI_MESSAGES_HH
3
4#include "ImGuiCpp.hh"
5#include "ImGuiPart.hh"
6
7#include "CliListener.hh"
8
9#include "circular_buffer.hh"
10#include "stl.hh"
11
12#include <array>
13#include <cstdint>
14#include <string>
15
16namespace openmsx {
17
18class ImGuiManager;
19
20class ImGuiMessages final : public ImGuiPart
21{
22public:
23 struct Message {
25 std::string text;
26 uint64_t timestamp; // us
27 };
28public:
29 explicit ImGuiMessages(ImGuiManager& manager_);
31
32 [[nodiscard]] zstring_view iniName() const override { return "messages"; }
33 void save(ImGuiTextBuffer& buf) override;
34 void loadLine(std::string_view name, zstring_view value) override;
35 void paint(MSXMotherBoard* motherBoard) override;
36
37public:
40
41private:
42 void paintModal();
43 void paintPopup();
44 void paintProgress();
45 void paintOSD();
46 void paintLog();
47 void paintConfigure();
48 [[nodiscard]] bool paintButtons();
49
50 void log(CliComm::LogLevel level, std::string_view message, float fraction);
51
52private:
53 enum PopupAction : int { NO_POPUP, POPUP, MODAL_POPUP };
54 enum OpenLogAction : int { NO_OPEN_LOG, OPEN_LOG, OPEN_LOG_FOCUS };
55 enum OsdAction : int { NO_OSD, SHOW_OSD };
56 array_with_enum_index<CliComm::LogLevel, int /*PopupAction*/ > popupAction;
57 array_with_enum_index<CliComm::LogLevel, int /*OpenLogAction*/> openLogAction;
58 array_with_enum_index<CliComm::LogLevel, int /*OsdAction*/ > osdAction;
59
60 circular_buffer<Message> modalMessages;
61 circular_buffer<Message> popupMessages;
62 circular_buffer<Message> allMessages;
63 std::string filterLog;
64 bool doOpenModal = false;
65 size_t doOpenPopup = 0;
66
67 std::string progressMessage;
68 float progressFraction = 0.0f;;
69 float progressTime = 0.0f;
70 bool doOpenProgress = false;
71
72 struct Colors {
73 uint32_t text;
74 uint32_t background;
75 };
76 struct Step {
77 float start;
78 Colors colors;
79 };
80 using ColorSequence = std::array<Step, 4>;
82 ColorSequence{ // Info AA'BB'GG'RR
83 Step{0.0f, Colors{0xff'00'ff'ff, 0x80'ff'ff'ff}}, // start of flash
84 Step{0.5f, Colors{0xff'ff'ff'ff, 0x80'80'80'80}}, // start of stable colors
85 Step{5.0f, Colors{0xff'ff'ff'ff, 0x80'80'80'80}}, // end of stable colors
86 Step{1.5f, Colors{0x00'ff'ff'ff, 0x00'80'80'80}}, // end of fade-out
87 },
88 ColorSequence{ // warning
89 Step{0.0f, Colors{0xff'00'ff'ff, 0x80'ff'ff'ff}}, // start of flash
90 Step{0.5f, Colors{0xff'ff'ff'ff, 0x80'00'60'A0}}, // start of stable colors
91 Step{5.0f, Colors{0xff'ff'ff'ff, 0x80'00'60'A0}}, // end of stable colors
92 Step{1.5f, Colors{0x00'ff'ff'ff, 0x00'00'60'A0}}, // end of fade-out
93 },
94 ColorSequence{ // error
95 Step{0.0f, Colors{0xff'00'ff'ff, 0x80'ff'ff'ff}}, // start of flash
96 Step{0.5f, Colors{0xff'ff'ff'ff, 0x80'00'00'C0}}, // start of stable colors
97 Step{5.0f, Colors{0xff'ff'ff'ff, 0x80'00'00'C0}}, // end of stable colors
98 Step{1.5f, Colors{0x00'ff'ff'ff, 0x00'00'00'C0}}, // end of fade-out
99 },
100 ColorSequence{ /*dummy*/ } // progress
101 };
102 struct OsdMessage {
103 // clang workaround:
104 OsdMessage(const std::string& te, float ti, CliComm::LogLevel l)
105 : text(te), time(ti), level(l) {}
106
107 std::string text;
108 float time;
109 CliComm::LogLevel level;
110 };
111 std::vector<OsdMessage> osdMessages;
112
113 struct Listener : CliListener {
114 ImGuiMessages& messages;
115 explicit Listener(ImGuiMessages& m) : messages(m) {}
116
117 void log(CliComm::LogLevel level, std::string_view message, float fraction) noexcept override {
118 messages.log(level, message, fraction);
119 }
120 void update(CliComm::UpdateType /*type*/, std::string_view /*machine*/,
121 std::string_view /*name*/, std::string_view /*value*/) noexcept override {
122 // nothing
123 }
124 };
125 CliListener* listenerHandle;
126
127 static constexpr auto persistentElements = std::tuple{
130 // 'popupAction', 'openLogAction', 'osdAction' handled elsewhere
131 };
132};
133
134} // namespace openmsx
135
136#endif
Circular buffer class, based on boost::circular_buffer/.
void loadLine(std::string_view name, zstring_view value) override
void save(ImGuiTextBuffer &buf) override
zstring_view iniName() const override
void paint(MSXMotherBoard *motherBoard) override
im::WindowStatus logWindow
im::WindowStatus configureWindow
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr double log(double x)
Definition cstd.hh:208
This file implemented 3 utility functions:
Definition Autofire.cc:11
PersistentElement(zstring_view, T C::*) -> PersistentElement< C, T >