| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "gui.h" |
| 21 |
#include "../ta-log.h" |
| 22 |
#include <imgui.h> |
| 23 |
|
| 24 |
const char* logLevels[5]={ |
| 25 |
_N("ERROR"), |
| 26 |
_N("warning"), |
| 27 |
_N("info"), |
| 28 |
_N("debug"), |
| 29 |
_N("trace") |
| 30 |
}; |
| 31 |
|
| 32 |
FurnaceGUIColors logColors[5]={ |
| 33 |
GUI_COLOR_LOGLEVEL_ERROR, |
| 34 |
GUI_COLOR_LOGLEVEL_WARNING, |
| 35 |
GUI_COLOR_LOGLEVEL_INFO, |
| 36 |
GUI_COLOR_LOGLEVEL_DEBUG, |
| 37 |
GUI_COLOR_LOGLEVEL_TRACE |
| 38 |
}; |
| 39 |
|
| 40 |
void FurnaceGUI::drawLog() { |
| 41 |
if (nextWindow==GUI_WINDOW_LOG) { |
| 42 |
logOpen=true; |
| 43 |
ImGui::SetNextWindowFocus(); |
| 44 |
nextWindow=GUI_WINDOW_NOTHING; |
| 45 |
} |
| 46 |
if (!logOpen) return; |
| 47 |
if (ImGui::Begin("Log Viewer",&logOpen,globalWinFlags,_("Log Viewer"))) { |
| 48 |
ImGui::Checkbox(_("Follow"),&followLog); |
| 49 |
ImGui::SameLine(); |
| 50 |
ImGui::Text(_("Level")); |
| 51 |
ImGui::SameLine(); |
| 52 |
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); |
| 53 |
ImGui::Combo("##LogLevel",&logLevel,LocalizedComboGetter,logLevels,5); |
| 54 |
if (ImGui::BeginTable("LogView",3,ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersInnerV)) { |
| 55 |
ImGui::PushFont(patFont); |
| 56 |
|
| 57 |
float timeChars=ImGui::CalcTextSize("00:00:00").x; |
| 58 |
float levelChars=ImGui::CalcTextSize("warning").x; |
| 59 |
|
| 60 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,timeChars); |
| 61 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed,levelChars); |
| 62 |
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch); |
| 63 |
|
| 64 |
ImGui::TableSetupScrollFreeze(0,1); |
| 65 |
|
| 66 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 67 |
ImGui::TableNextColumn(); |
| 68 |
ImGui::TextUnformatted(_("time")); |
| 69 |
ImGui::TableNextColumn(); |
| 70 |
ImGui::TextUnformatted(_("level")); |
| 71 |
ImGui::TableNextColumn(); |
| 72 |
ImGui::TextUnformatted(_("message")); |
| 73 |
|
| 74 |
int pos=logPosition; |
| 75 |
for (int i=0; i<TA_LOG_SIZE; i++) { |
| 76 |
const LogEntry& logEntry=logEntries[(pos+i)&(TA_LOG_SIZE-1)]; |
| 77 |
if (!logEntry.ready) continue; |
| 78 |
if (logLevel<logEntry.loglevel) continue; |
| 79 |
ImGui::TableNextRow(); |
| 80 |
ImGui::TableNextColumn(); |
| 81 |
ImGui::Text("%02d:%02d:%02d",logEntry.time.tm_hour,logEntry.time.tm_min,logEntry.time.tm_sec); |
| 82 |
ImGui::TableNextColumn(); |
| 83 |
ImGui::TextColored(uiColors[logColors[logEntry.loglevel]],"%s",_(logLevels[logEntry.loglevel])); |
| 84 |
ImGui::TableNextColumn(); |
| 85 |
ImGui::TextWrapped("%s",logEntry.text.c_str()); |
| 86 |
} |
| 87 |
ImGui::PopFont(); |
| 88 |
|
| 89 |
if (followLog) { |
| 90 |
ImGui::SetScrollY(ImGui::GetScrollMaxY()); |
| 91 |
} |
| 92 |
ImGui::EndTable(); |
| 93 |
} |
| 94 |
} |
| 95 |
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_LOG; |
| 96 |
ImGui::End(); |
| 97 |
} |