Skip to content

Commit

Permalink
Fix log window autoscroll and line cutting
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Nov 15, 2024
1 parent fccd09d commit 7eb363c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
47 changes: 22 additions & 25 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8587,7 +8587,8 @@ void Gui::loadFonts()

void Gui::drawLog()
{
static bool AutoScroll = true; // Keep scrolling if already at the bottom
static bool AutoScroll = true;
static bool scroll_to_bottom = false;

ImGui::SetNextWindowSize(ImVec2(750.f, 300.f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints(ImVec2(200.f, 100.f), ImVec2(FLT_MAX, app->windowHeight - 40.f));
Expand All @@ -8605,13 +8606,13 @@ void Gui::drawLog()
{
log_buffer_copy = g_log_buffer;
color_buffer_copy = g_color_buffer;
scroll_to_bottom = true;
}
g_mutex_list[0].unlock();

ImGui::BeginChild(get_localized_string(LANG_0706).c_str(), ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);

bool copy = false;
bool toggledAutoScroll = false;
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem(get_localized_string(LANG_1165).c_str()))
Expand All @@ -8627,15 +8628,14 @@ void Gui::drawLog()
}
if (ImGui::MenuItem(get_localized_string(LANG_0708).c_str(), NULL, &AutoScroll))
{
toggledAutoScroll = true;

}
ImGui::EndPopup();
}

ImGui::PushFont(consoleFont);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));


if (copy)
{
std::string logStr;
Expand All @@ -8646,32 +8646,24 @@ void Gui::drawLog()
ImGui::SetClipboardText(logStr.c_str());
}

ImGuiListClipper clipper;
clipper.Begin((int)log_buffer_copy.size(), ImGui::GetTextLineHeightWithSpacing());
while (clipper.Step())
for (size_t i = 0; i < log_buffer_copy.size(); i++)
{
int line_start = clipper.DisplayStart;
int line_count = clipper.DisplayEnd - clipper.DisplayStart;
for (int i = 0; i < line_count; i++)
{
if (line_start + i < (int)log_buffer_copy.size())
{
ImGui::PushStyleColor(ImGuiCol_Text, imguiColorFromConsole(color_buffer_copy[line_start + i]));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0, 0));
ImGui::TextWrapped(log_buffer_copy[line_start + i].c_str());
ImGui::PopStyleVar();
ImGui::PopStyleColor();
}
}
ImGui::PushStyleColor(ImGuiCol_Text, imguiColorFromConsole(color_buffer_copy[i]));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0, 0));
ImGui::TextWrapped(log_buffer_copy[i].c_str());
ImGui::PopStyleVar();
ImGui::PopStyleColor();
}

if (AutoScroll && scroll_to_bottom)
{
ImGui::SetScrollHereY(1.0f);
scroll_to_bottom = false;
}
clipper.End();

ImGui::PopFont();
ImGui::PopStyleVar();

if (AutoScroll && (ImGui::GetScrollY() >= ImGui::GetScrollMaxY() || toggledAutoScroll))
ImGui::SetScrollHereY(1.0f);

ImGui::EndChild();
ImGui::End();
}
Expand Down Expand Up @@ -9348,6 +9340,7 @@ void Gui::drawSettings()
bool renderModels = g_render_flags & RENDER_MODELS;
bool renderAnimatedModels = g_render_flags & RENDER_MODELS_ANIMATED;
bool renderSelectedAtTop = g_render_flags & RENDER_SELECTED_AT_TOP;
bool renderMapBoundary = g_render_flags & RENDER_MAP_BOUNDARY;

ImGui::Text(get_localized_string(LANG_0779).c_str());

Expand Down Expand Up @@ -9440,7 +9433,11 @@ void Gui::drawSettings()
mapRenderers[i]->updateClipnodeOpacity(transparentNodes ? 128 : 255);
}
}

if (ImGui::Checkbox("Map boundary", &renderMapBoundary))
{
g_render_flags ^= RENDER_MAP_BOUNDARY;
}

ImGui::Columns(1);

ImGui::Separator();
Expand Down
4 changes: 2 additions & 2 deletions src/editor/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ void AppSettings::loadDefault()

settings_tab = 0;

render_flags = g_render_flags = RENDER_TEXTURES | RENDER_LIGHTMAPS | RENDER_SPECIAL
render_flags = g_render_flags = (RENDER_TEXTURES | RENDER_LIGHTMAPS | RENDER_SPECIAL
| RENDER_ENTS | RENDER_SPECIAL_ENTS | RENDER_POINT_ENTS | RENDER_WIREFRAME | RENDER_ENT_CONNECTIONS
| RENDER_ENT_CLIPNODES | RENDER_MODELS | RENDER_MODELS_ANIMATED;
| RENDER_ENT_CLIPNODES | RENDER_MODELS | RENDER_MODELS_ANIMATED | RENDER_WORLD_CLIPNODES | RENDER_ORIGIN);

vsync = true;
merge_verts = false;
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// Solve:
// Create empty hull 0 box ?

std::string g_version_string = "NewBSPGuy v4.27";
std::string g_version_string = "NewBSPGuy v4.28";

bool g_verbose = false;

Expand Down

0 comments on commit 7eb363c

Please sign in to comment.