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 <string>
14
15namespace openmsx {
16
17class ImGuiManager;
18
19class ImGuiMessages final : public ImGuiPart
20{
21public:
22 struct Message {
24 std::string text;
25 };
26public:
27 explicit ImGuiMessages(ImGuiManager& manager_);
29
30 [[nodiscard]] zstring_view iniName() const override { return "messages"; }
31 void save(ImGuiTextBuffer& buf) override;
32 void loadLine(std::string_view name, zstring_view value) override;
33 void paint(MSXMotherBoard* motherBoard) override;
34
35public:
38
39private:
40 void paintModal();
41 void paintPopup();
42 void paintProgress();
43 void paintOSD();
44 void paintLog();
45 void paintConfigure();
46 [[nodiscard]] bool paintButtons();
47
48 void log(CliComm::LogLevel level, std::string_view message, float fraction);
49
50private:
51 enum PopupAction : int { NO_POPUP, POPUP, MODAL_POPUP };
52 enum OpenLogAction : int { NO_OPEN_LOG, OPEN_LOG, OPEN_LOG_FOCUS };
53 enum OsdAction : int { NO_OSD, SHOW_OSD };
54 array_with_enum_index<CliComm::LogLevel, int /*PopupAction*/ > popupAction;
55 array_with_enum_index<CliComm::LogLevel, int /*OpenLogAction*/> openLogAction;
56 array_with_enum_index<CliComm::LogLevel, int /*OsdAction*/ > osdAction;
57
58 circular_buffer<Message> modalMessages;
59 circular_buffer<Message> popupMessages;
60 circular_buffer<Message> allMessages;
61 std::string filterLog;
62 bool doOpenModal = false;
63 size_t doOpenPopup = 0;
64
65 std::string progressMessage;
66 float progressFraction = 0.0f;;
67 float progressTime = 0.0f;
68 bool doOpenProgress = false;
69
70 struct Colors {
71 uint32_t text;
72 uint32_t background;
73 };
74 struct Step {
75 float start;
76 Colors colors;
77 };
78 using ColorSequence = std::array<Step, 4>;
80 ColorSequence{ // Info AA'BB'GG'RR
81 Step{0.0f, Colors{0xff'00'ff'ff, 0x80'ff'ff'ff}}, // start of flash
82 Step{0.5f, Colors{0xff'ff'ff'ff, 0x80'80'80'80}}, // start of stable colors
83 Step{5.0f, Colors{0xff'ff'ff'ff, 0x80'80'80'80}}, // end of stable colors
84 Step{1.5f, Colors{0x00'ff'ff'ff, 0x00'80'80'80}}, // end of fade-out
85 },
86 ColorSequence{ // warning
87 Step{0.0f, Colors{0xff'00'ff'ff, 0x80'ff'ff'ff}}, // start of flash
88 Step{0.5f, Colors{0xff'ff'ff'ff, 0x80'00'60'A0}}, // start of stable colors
89 Step{5.0f, Colors{0xff'ff'ff'ff, 0x80'00'60'A0}}, // end of stable colors
90 Step{1.5f, Colors{0x00'ff'ff'ff, 0x00'00'60'A0}}, // end of fade-out
91 },
92 ColorSequence{ // error
93 Step{0.0f, Colors{0xff'00'ff'ff, 0x80'ff'ff'ff}}, // start of flash
94 Step{0.5f, Colors{0xff'ff'ff'ff, 0x80'00'00'C0}}, // start of stable colors
95 Step{5.0f, Colors{0xff'ff'ff'ff, 0x80'00'00'C0}}, // end of stable colors
96 Step{1.5f, Colors{0x00'ff'ff'ff, 0x00'00'00'C0}}, // end of fade-out
97 },
98 ColorSequence{ /*dummy*/ } // progress
99 };
100 struct OsdMessage {
101 // clang workaround:
102 OsdMessage(const std::string& te, float ti, CliComm::LogLevel l)
103 : text(te), time(ti), level(l) {}
104
105 std::string text;
106 float time;
107 CliComm::LogLevel level;
108 };
109 std::vector<OsdMessage> osdMessages;
110
111 struct Listener : CliListener {
112 ImGuiMessages& messages;
113 explicit Listener(ImGuiMessages& m) : messages(m) {}
114
115 void log(CliComm::LogLevel level, std::string_view message, float fraction) noexcept override {
116 messages.log(level, message, fraction);
117 }
118 void update(CliComm::UpdateType /*type*/, std::string_view /*machine*/,
119 std::string_view /*name*/, std::string_view /*value*/) noexcept override {
120 // nothing
121 }
122 };
123 CliListener* listenerHandle;
124
125 static constexpr auto persistentElements = std::tuple{
128 // 'popupAction', 'openLogAction', 'osdAction' handled elsewhere
129 };
130};
131
132} // namespace openmsx
133
134#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 >