Skip to content

Commit

Permalink
Merge pull request #34 from RaidcoreGG/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DeltaGW2 authored Apr 9, 2024
2 parents faac836 + bb41d54 commit 19877d1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 51 deletions.
63 changes: 38 additions & 25 deletions src/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "Consts.h"
#include "Branch.h"

#include "Mumble/Mumble.h"

#include "Events/EventHandler.h"
#include "Keybinds/KeybindHandler.h"
#include "Loader/Loader.h"
Expand Down Expand Up @@ -61,7 +63,7 @@ namespace GUI
bool IsRightClickHeld = false;
bool IsLeftClickHeld = false;
bool IsSetup = false;
float LastScaling;
float LastScaling = 1.0f;

bool HasAcceptedEULA = false;
bool NotifyChangelog = false;
Expand Down Expand Up @@ -259,11 +261,12 @@ namespace GUI
/* draw overlay */
if (IsUIVisible)
{
/* draw menu & qa */
Menu::Render();
QuickAccess::Render();
Alerts::Render();
/* draw menu & qa end*/
/* draw addons*/
for (GUI_RENDER callback : RegistryRender)
{
if (callback) { callback(); }
}
/* draw addons end*/

/* draw nexus windows */
for (IWindow* wnd : Windows)
Expand All @@ -272,12 +275,11 @@ namespace GUI
}
/* draw nexus windows end */

/* draw addons*/
for (GUI_RENDER callback : RegistryRender)
{
if (callback) { callback(); }
}
/* draw addons end*/
/* draw menu & qa */
Menu::Render();
QuickAccess::Render();
Alerts::Render();
/* draw menu & qa end*/
}
/* draw overlay end */

Expand Down Expand Up @@ -400,20 +402,30 @@ namespace GUI
((CDebugWindow*)(*it))->MumbleWindow->Visible = !((CDebugWindow*)(*it))->MumbleWindow->Visible;
}
}
void OnMumbleIdentityChanged(void* aEventArgs)

void Rescale()
{
if (Renderer::Scaling != LastScaling && IsGameplay)
{
LastScaling = Renderer::Scaling;
Settings::Settings[OPT_LASTUISCALE] = Renderer::Scaling;
Settings::Save();
}
float currScaling = MumbleIdentity
? Mumble::GetScalingFactor(MumbleIdentity->UISize)
: 1.0f;

ImGuiIO& io = ImGui::GetIO();

Renderer::Scaling = currScaling * io.FontGlobalScale;
}

void OnMumbleIdentityChanged(void* aEventArgs)
{
if (MumbleIdentity)
{
float currScaling = Mumble::GetScalingFactor(MumbleIdentity->UISize);
if (currScaling != LastScaling && IsGameplay)
{
Rescale();
LastScaling = currScaling;
Settings::Settings[OPT_LASTUISCALE] = currScaling;
Settings::Save();
}

switch (MumbleIdentity->UISize)
{
case 0:
Expand Down Expand Up @@ -474,15 +486,13 @@ namespace GUI
FontSize = 16.0f;
}

if (!Settings::Settings[OPT_LASTUISCALE].is_null() && Renderer::Scaling == 0)
if (!Settings::Settings[OPT_LASTUISCALE].is_null())
{
Settings::Settings[OPT_LASTUISCALE].get_to(LastScaling);
Settings::Settings[OPT_LASTUISCALE].get_to(Renderer::Scaling);
}
else
{
LastScaling = SC_NORMAL;
Renderer::Scaling = SC_NORMAL;
Settings::Settings[OPT_LASTUISCALE] = SC_NORMAL;
}

Expand Down Expand Up @@ -581,9 +591,10 @@ namespace GUI
Settings::Settings[OPT_ALWAYSSHOWQUICKACCESS] = false;
}

ImGuiIO& io = ImGui::GetIO();

if (!Settings::Settings[OPT_GLOBALSCALE].is_null())
{
ImGuiIO& io = ImGui::GetIO();
Settings::Settings[OPT_GLOBALSCALE].get_to(io.FontGlobalScale);

if (io.FontGlobalScale < 0.75f)
Expand All @@ -595,6 +606,8 @@ namespace GUI
{
Settings::Settings[OPT_GLOBALSCALE] = 1.0f;
}

Renderer::Scaling = LastScaling * io.FontGlobalScale;
}

ImportArcDPSStyle();
Expand Down
2 changes: 2 additions & 0 deletions src/GUI/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace GUI

void ImportArcDPSStyle();

void Rescale();

/* Registers the provided RenderCallback. */
void Register(ERenderType aRenderType, GUI_RENDER aRenderCallback);
/* Deregisters the provided RenderCallback. */
Expand Down
8 changes: 8 additions & 0 deletions src/GUI/Widgets/Debug/CDebugWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace GUI
void* memPtr = nullptr;
size_t memSz = 0;

bool showMetricsDebugger = false;

/* proto tabs */
void DbgEventsTab();
void DbgKeybindsTab();
Expand All @@ -46,11 +48,17 @@ namespace GUI

if (!Visible) { return; }

if (showMetricsDebugger)
{
ImGui::ShowMetricsWindow();
}

ImGui::SetNextWindowSize(ImVec2(dwWidth * ImGui::GetFontSize(), dwHeight * ImGui::GetFontSize()), ImGuiCond_FirstUseEver);
if (ImGui::Begin(Name.c_str(), &Visible, ImGuiWindowFlags_NoCollapse))
{
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 0.f, 0.f });
ImGui::Checkbox("Show Mumble overlay", &MumbleWindow->Visible);
ImGui::Checkbox("Show Metrics / Debugger", &showMetricsDebugger);
ImGui::PopStyleVar();

if (ImGui::BeginTabBar("DebugTabBar", ImGuiTabBarFlags_None))
Expand Down
4 changes: 3 additions & 1 deletion src/GUI/Widgets/Options/COptionsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ namespace GUI

ImGuiIO& io = ImGui::GetIO();
ImGui::TextDisabled(Language.Translate("((000072))"));
if (ImGui::DragFloat("##globalscale", &io.FontGlobalScale, 0.005f, 0.3f, 3.0f, "%.2f", ImGuiSliderFlags_AlwaysClamp))
if (ImGui::DragFloat("##globalscale", &io.FontGlobalScale, 0.005f, 0.75f, 3.0f, "%.2f", ImGuiSliderFlags_AlwaysClamp))
{
Settings::Settings[OPT_GLOBALSCALE] = io.FontGlobalScale;
Settings::Save();

GUI::Rescale();
}

ImGui::Separator();
Expand Down
30 changes: 5 additions & 25 deletions src/Mumble/Mumble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ namespace Mumble
Log(CH_CORE, "MumbleLink could not be parsed. Unknown Error.");
}

/* update ui scaling factor */
Renderer::Scaling = GetScalingFactor(MumbleIdentity->UISize);

/* notify */
/* notify (also notifies the GUI to update its scaling factor) */
if (*MumbleIdentity != prevIdentity)
{
Events::Raise(EV_MUMBLE_IDENTITY_UPDATED, MumbleIdentity);
Expand Down Expand Up @@ -138,30 +135,13 @@ namespace Mumble

float GetScalingFactor(unsigned aSize)
{
const float MIN_SCALE = 0.3f;
const float MAX_SCALE = 2.0f;

if (Renderer::GuiContext)
{
ImGuiIO& io = ImGui::GetIO();

switch (aSize)
{
case 0: return Renderer::Scaling = SC_SMALL * io.FontGlobalScale; // Small
default:
case 1: return Renderer::Scaling = SC_NORMAL * io.FontGlobalScale; // Normal
case 2: return Renderer::Scaling = SC_LARGE * io.FontGlobalScale; // Large
case 3: return Renderer::Scaling = SC_LARGER * io.FontGlobalScale; // Larger
}
}

switch (aSize)
{
case 0: return Renderer::Scaling = SC_SMALL; // Small
case 0: return SC_SMALL; // Small
default:
case 1: return Renderer::Scaling = SC_NORMAL; // Normal
case 2: return Renderer::Scaling = SC_LARGE; // Large
case 3: return Renderer::Scaling = SC_LARGER; // Larger
case 1: return SC_NORMAL; // Normal
case 2: return SC_LARGE; // Large
case 3: return SC_LARGER; // Larger
}
}
}

0 comments on commit 19877d1

Please sign in to comment.