Skip to content

Commit

Permalink
fix scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Apr 20, 2024
1 parent 50fa981 commit 1dc82a9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Dear ImGui for Godot Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.90.1.1" />
<PackageReference Include="Roslynator.Analyzers" Version="4.10.0">
<PackageReference Include="Roslynator.Analyzers" Version="4.12.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.10.0">
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.CodeFixes" Version="4.10.0">
<PackageReference Include="Roslynator.CodeFixes" Version="4.12.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.10.0">
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.12.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 5 additions & 1 deletion addons/imgui-godot/ImGuiGodot/Internal/BackendNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public float JoyAxisDeadZone
set => _gd.Set(PropertyName.JoyAxisDeadZone, value);
}

public float Scale { get; set; } = 1.0f; // TODO: make property
public float Scale
{
get => (float)_gd.Get(PropertyName.Scale);
set => _gd.Set(PropertyName.Scale, value);
}

public bool Visible
{
Expand Down
4 changes: 2 additions & 2 deletions gdext/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ void AddFontDefault()
ctx->fonts->Add(nullptr, 13, false);
}

void RebuildFontAtlas()
void RebuildFontAtlas(float scale)
{
ctx->fonts->RebuildFontAtlas(ctx->scale);
ctx->fonts->RebuildFontAtlas(scale);
}

void SetIniFilename(const String& fn)
Expand Down
2 changes: 1 addition & 1 deletion gdext/src/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void Connect(const Callable& callable);
void ResetFonts();
void AddFont(const Ref<FontFile>& fontFile, int fontSize, bool merge = false);
void AddFontDefault();
void RebuildFontAtlas();
void RebuildFontAtlas(float scale = 1.0f);
void SetIniFilename(const String& fn);
void SetVisible(bool visible);
bool IsVisible();
Expand Down
18 changes: 13 additions & 5 deletions gdext/src/ImGuiGD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ void ImGuiGD::AddFontDefault()

void ImGuiGD::RebuildFontAtlas(float scale)
{
ImGui::Godot::RebuildFontAtlas();
bool scaleToDpi = ProjectSettings::get_singleton()->get_setting("display/window/dpi/allow_hidpi");
int dpiFactor = std::max(1, DisplayServer::get_singleton()->screen_get_dpi() / 96);
ImGui::Godot::RebuildFontAtlas(scaleToDpi ? dpiFactor * scale : scale);
}

void ImGuiGD::_SetVisible(bool visible)
Expand All @@ -108,8 +110,9 @@ void ImGuiGD::_SetVisible(bool visible)
bool ImGuiGD::_GetVisible()
{
CanvasLayer* igl = Object::cast_to<CanvasLayer>(Engine::get_singleton()->get_singleton("ImGuiLayer"));
ERR_FAIL_COND_V(!igl, false);
return igl->is_visible();
if (igl)
return igl->is_visible();
return false;
}

void ImGuiGD::_SetJoyAxisDeadZone(float zone)
Expand All @@ -122,16 +125,21 @@ float ImGuiGD::_GetJoyAxisDeadZone()
Context* ctx = ImGui::Godot::GetContext();
if (ctx)
return ctx->input->GetJoyAxisDeadZone();
else
return 0.15f;
return 0.15f;
}

void ImGuiGD::_SetScale(float scale)
{
Context* ctx = ImGui::Godot::GetContext();
ERR_FAIL_COND(!ctx);
ctx->scale = scale;
}

float ImGuiGD::_GetScale()
{
Context* ctx = ImGui::Godot::GetContext();
if (ctx)
return ctx->scale;
return 1.0f;
}

Expand Down

0 comments on commit 1dc82a9

Please sign in to comment.