WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
LogPanel.cpp
Go to the documentation of this file.
1#include "LogPanel.h"
2
3#include <cassert>
4
5#include "imgui.h"
6
7#include <fstream>
8#include <string>
9
10namespace
11{
12
13void reloadLogFile(std::vector<std::string>& lines, bool& needsReload)
14{
15 lines.clear();
16 std::ifstream file("userSettings/log_imgui.txt");
17 if (!file.is_open())
18 return;
19 std::string line;
20 while (std::getline(file, line))
21 lines.push_back(line);
22 needsReload = false;
23}
24
25} // anonymous namespace
26
28{
29 assert(ctx.logLines && "DrawContext::logLines must not be null");
30 assert(ctx.logAutoScroll && "DrawContext::logAutoScroll must not be null");
31 assert(ctx.logNeedsReload && "DrawContext::logNeedsReload must not be null");
32
33 if (*ctx.logNeedsReload)
34 reloadLogFile(*ctx.logLines, *ctx.logNeedsReload);
35
36 if (ImGui::Button("Reload"))
37 reloadLogFile(*ctx.logLines, *ctx.logNeedsReload);
38 ImGui::SameLine();
39 if (ImGui::Button("Clear"))
40 ctx.logLines->clear();
41 ImGui::SameLine();
42 ImGui::Checkbox("Auto-scroll", ctx.logAutoScroll);
43 ImGui::SameLine();
44 ImGui::TextDisabled("%d lines", static_cast<int>(ctx.logLines->size()));
45
46 ImGui::Separator();
47 ImGui::BeginChild("##LogScroll", ImVec2(0, 0), ImGuiChildFlags_None,
48 ImGuiWindowFlags_HorizontalScrollbar);
49 ImGuiListClipper clipper;
50 clipper.Begin(static_cast<int>(ctx.logLines->size()));
51 while (clipper.Step())
52 {
53 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
54 {
55 const auto& line = (*ctx.logLines)[i];
56 if (line.find("ERROR") != std::string::npos)
57 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.4f, 0.4f, 1.0f));
58 else if (line.find("WARNING") != std::string::npos)
59 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 0.3f, 1.0f));
60 else
61 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.7f, 0.7f, 0.7f, 1.0f));
62 ImGui::TextUnformatted(line.c_str());
63 ImGui::PopStyleColor();
64 }
65 }
66 if (*ctx.logAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY() - 20.0f)
67 ImGui::SetScrollHereY(1.0f);
68 ImGui::EndChild();
69}
void draw(DrawContext &ctx)
Definition LogPanel.cpp:27
Per-frame context for the log panel.
Definition LogPanel.h:12
std::vector< std::string > * logLines
Definition LogPanel.h:13