|
36 | 36 | // return timestamp; |
37 | 37 | //} |
38 | 38 |
|
39 | | -// ExampleAppLog taken from "imgui_demo.cpp" |
40 | | -struct ExtensionLog |
41 | | -{ |
42 | | - ImGuiTextBuffer Buf; |
43 | | - ImGuiTextFilter Filter; |
44 | | - ImVector<int> LineOffsets; // Index to lines offset. We maintain this with AddLog() calls. |
45 | | - bool AutoScroll; // Keep scrolling if already at the bottom. |
46 | | - |
47 | | - ExtensionLog() noexcept |
48 | | - { |
49 | | - AutoScroll = true; |
50 | | - Clear(); |
51 | | - } |
52 | | - |
53 | | - void Clear() noexcept |
54 | | - { |
55 | | - Buf.clear(); |
56 | | - LineOffsets.clear(); |
57 | | - LineOffsets.push_back(0); |
58 | | - } |
59 | | - |
60 | | - inline int LogSizeBytes() const noexcept |
61 | | - { |
62 | | - return Buf.Buf.size_in_bytes() + LineOffsets.size_in_bytes(); |
63 | | - } |
64 | | - |
65 | | - inline int AllocatedSizeBytes() const noexcept |
66 | | - { |
67 | | - return Buf.Buf.Capacity + LineOffsets.Capacity*sizeof(int); |
68 | | - } |
69 | | - |
70 | | - void AddLog(const char* fmt, ...) noexcept IM_FMTARGS(2) |
71 | | - { |
72 | | - int old_size = Buf.size(); |
73 | | - va_list args; |
74 | | - va_start(args, fmt); |
75 | | - Buf.appendfv(fmt, args); |
76 | | - va_end(args); |
77 | | - for (int new_size = Buf.size(); old_size < new_size; old_size++) |
78 | | - if (Buf[old_size] == '\n') |
79 | | - LineOffsets.push_back(old_size + 1); |
80 | | - } |
81 | | - |
82 | | - void Draw(const char* title, bool* p_open = NULL) noexcept |
83 | | - { |
84 | | - if (!ImGui::Begin(title, p_open)) { |
85 | | - ImGui::End(); |
86 | | - return; |
87 | | - } |
88 | | - |
89 | | - // Options menu |
90 | | - if (ImGui::BeginPopup("Options")) { |
91 | | - ImGui::Checkbox("Auto-scroll", &AutoScroll); |
92 | | - ImGui::EndPopup(); |
93 | | - } |
94 | | - |
95 | | - // Main window |
96 | | - if (ImGui::Button("Options")) |
97 | | - ImGui::OpenPopup("Options"); |
98 | | - ImGui::SameLine(); |
99 | | - bool clear = ImGui::Button("Clear"); |
100 | | - ImGui::SameLine(); |
101 | | - bool copy = ImGui::Button("Copy"); |
102 | | - ImGui::SameLine(); |
103 | | - Filter.Draw("Filter", -100.0f); |
104 | | - |
105 | | - ImGui::Text("Used: %.2f MB", LogSizeBytes() / (1024.f * 1024.f)); |
106 | | - ImGui::SameLine(); |
107 | | - ImGui::Text("Allocated: %.2f MB", AllocatedSizeBytes() / (1024.f * 1024.f)); |
108 | | - ImGui::Separator(); |
109 | | - ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar); |
110 | | - |
111 | | - if (clear) |
112 | | - Clear(); |
113 | | - if (copy) |
114 | | - ImGui::LogToClipboard(); |
115 | | - |
116 | | - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); |
117 | | - const char* buf = Buf.begin(); |
118 | | - const char* buf_end = Buf.end(); |
119 | | - if (Filter.IsActive()) { |
120 | | - for (int line_no = 0; line_no < LineOffsets.Size; line_no++) { |
121 | | - const char* line_start = buf + LineOffsets[line_no]; |
122 | | - const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end; |
123 | | - if (Filter.PassFilter(line_start, line_end)) |
124 | | - ImGui::TextUnformatted(line_start, line_end); |
125 | | - } |
126 | | - } |
127 | | - else { |
128 | | - ImGuiListClipper clipper; |
129 | | - clipper.Begin(LineOffsets.Size); |
130 | | - while (clipper.Step()) { |
131 | | - for (int line_no = clipper.DisplayStart; line_no < clipper.DisplayEnd; line_no++) { |
132 | | - const char* line_start = buf + LineOffsets[line_no]; |
133 | | - const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end; |
134 | | - ImGui::TextUnformatted(line_start, line_end); |
135 | | - } |
136 | | - } |
137 | | - clipper.End(); |
138 | | - } |
139 | | - ImGui::PopStyleVar(); |
140 | | - |
141 | | - if (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) |
142 | | - ImGui::SetScrollHereY(1.0f); |
143 | | - |
144 | | - ImGui::EndChild(); |
145 | | - ImGui::End(); |
146 | | - } |
147 | | -}; |
148 | | - |
149 | 39 | constexpr const char* LuaDefaultFunctions = R"( |
150 | 40 | function clamp(val, min, max) |
151 | 41 | return math.min(max, math.max(val, min)) |
152 | 42 | end |
153 | 43 | )"; |
154 | 44 |
|
155 | | -static ExtensionLog ExtensionLogBuffer; |
| 45 | +static OFS::AppLog ExtensionLogBuffer; |
156 | 46 |
|
157 | 47 | SDL_threadID OFS_LuaExtensions::MainThread = SDL_ThreadID(); |
158 | 48 | bool OFS_LuaExtensions::DevMode = false; |
@@ -197,7 +87,6 @@ static int LuaPrint(lua_State* L) noexcept |
197 | 87 | } |
198 | 88 | } |
199 | 89 |
|
200 | | - LOG_INFO(logMsg.c_str()); |
201 | 90 | logMsg.append(1, '\n'); |
202 | 91 | ExtensionLogBuffer.AddLog(logMsg.c_str()); |
203 | 92 | return 0; |
|
0 commit comments