Skip to content

Commit

Permalink
simplify scale
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Apr 27, 2024
1 parent 1ff8885 commit bcdd315
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion addons/imgui-godot/ImGuiGodot/ImGuiGD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void RebuildFontAtlas()
//if (_inProcessFrame)
// throw new InvalidOperationException("fonts cannot be changed during process frame");

_backend.RebuildFontAtlas(Scale);
_backend.RebuildFontAtlas();
}

public static void Connect(Callable callable)
Expand Down
4 changes: 2 additions & 2 deletions addons/imgui-godot/ImGuiGodot/Internal/BackendNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void Connect(Callable callable)
_gd.Call(MethodName.Connect, callable);
}

public void RebuildFontAtlas(float scale)
public void RebuildFontAtlas()
{
_gd.Call(MethodName.RebuildFontAtlas, scale);
_gd.Call(MethodName.RebuildFontAtlas);
}

public void ResetFonts()
Expand Down
4 changes: 2 additions & 2 deletions addons/imgui-godot/ImGuiGodot/Internal/BackendNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void Connect(Callable callable)
ImGuiLayer.Instance?.Signaler.Connect("imgui_layout", callable);
}

public void RebuildFontAtlas(float scale)
public void RebuildFontAtlas()
{
bool scaleToDpi = (bool)ProjectSettings.GetSetting("display/window/dpi/allow_hidpi");
int dpiFactor = Math.Max(1, DisplayServer.ScreenGetDpi() / 96);
State.Instance.Fonts.RebuildFontAtlas(scaleToDpi ? dpiFactor * scale : scale);
State.Instance.Fonts.RebuildFontAtlas(scaleToDpi ? dpiFactor * Scale : Scale);
}

public void ResetFonts()
Expand Down
2 changes: 1 addition & 1 deletion addons/imgui-godot/ImGuiGodot/Internal/IBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal interface IBackend
public void ResetFonts();
public void AddFont(FontFile fontData, int fontSize, bool merge, ushort[]? glyphRanges);
public void AddFontDefault();
public void RebuildFontAtlas(float scale);
public void RebuildFontAtlas();
public void Connect(Callable callable);
public bool SubViewportWidget(SubViewport svp);
}
Expand Down
1 change: 1 addition & 0 deletions addons/imgui-godot/scripts/ImGuiPlugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ func _enter_tree():

func _exit_tree():
remove_autoload_singleton("ImGuiRoot")
Engine.unregister_singleton("ImGuiPlugin")
4 changes: 2 additions & 2 deletions data/sample_config.tres
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
script = ExtResource("2_etwwr")
FontData = ExtResource("1_0g12f")
FontSize = 18
Merge = true

[sub_resource type="Resource" id="Resource_kiahq"]
script = ExtResource("2_etwwr")
FontData = ExtResource("3_qqkxo")
FontSize = 22
Merge = true

[resource]
script = ExtResource("1_n8f18")
Fonts = Array[ExtResource("2_etwwr")]([SubResource("Resource_df4vj"), SubResource("Resource_kiahq")])
MergeFonts = true
AddDefaultFont = true
Scale = 1.0
ScaleToDpi = true
IniFilename = "user://imgui.ini"
Renderer = "RenderingDevice"
Layer = 100
4 changes: 2 additions & 2 deletions gdext/include/imgui-godot.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ inline void Connect(const Callable& callable)
detail::ImGuiGD->call(sn, callable);
}

inline void RebuildFontAtlas(float scale)
inline void RebuildFontAtlas()
{
ERR_FAIL_COND(!detail::GET_IMGUIGD());
static const StringName sn("RebuildFontAtlas");
detail::ImGuiGD->call(sn, scale);
detail::ImGuiGD->call(sn);
}

inline void ResetFonts()
Expand Down
8 changes: 6 additions & 2 deletions gdext/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,28 @@ void Connect(const godot::Callable& callable)

void ResetFonts()
{
ERR_FAIL_COND(!ctx);
ctx->fonts->Reset();
}

void AddFont(const Ref<FontFile>& fontFile, int fontSize, bool merge, const ImVector<ImWchar>& glyphRanges)
{
ERR_FAIL_COND(!ctx);
ctx->fonts->Add(fontFile, fontSize, merge, glyphRanges);
}

void AddFontDefault()
{
ERR_FAIL_COND(!ctx);
ctx->fonts->Add(nullptr, 13, false);
}

void RebuildFontAtlas(float scale)
void RebuildFontAtlas()
{
ERR_FAIL_COND(!ctx);
bool scaleToDpi = ProjectSettings::get_singleton()->get_setting("display/window/dpi/allow_hidpi");
int dpiFactor = std::max(1, DisplayServer::get_singleton()->screen_get_dpi() / 96);
ctx->fonts->RebuildFontAtlas(scaleToDpi ? dpiFactor * scale : scale);
ctx->fonts->RebuildFontAtlas(scaleToDpi ? dpiFactor * ctx->scale : ctx->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 @@ -72,7 +72,7 @@ void ResetFonts();
void AddFont(const Ref<FontFile>& fontFile, int fontSize, bool merge = false,
const ImVector<ImWchar>& glyphRanges = {});
void AddFontDefault();
void RebuildFontAtlas(float scale = 1.0f);
void RebuildFontAtlas();
void SetIniFilename(const String& fn);
void SetVisible(bool visible);
bool IsVisible();
Expand Down
6 changes: 3 additions & 3 deletions gdext/src/ImGuiGD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void ImGuiGD::_bind_methods()
DEFVAL(PackedInt32Array()));
ClassDB::bind_method(D_METHOD("AddFontDefault"), &ImGuiGD::AddFontDefault);
ClassDB::bind_method(D_METHOD("Connect", "callable"), &ImGuiGD::Connect);
ClassDB::bind_method(D_METHOD("RebuildFontAtlas", "scale"), &ImGuiGD::RebuildFontAtlas, DEFVAL(1.0f));
ClassDB::bind_method(D_METHOD("RebuildFontAtlas"), &ImGuiGD::RebuildFontAtlas);
ClassDB::bind_method(D_METHOD("ResetFonts"), &ImGuiGD::ResetFonts);
ClassDB::bind_method(D_METHOD("SubViewport", "svp"), &ImGuiGD::SubViewport);
ClassDB::bind_method(D_METHOD("GetImGuiPtrs", "version", "ioSize", "vertSize", "idxSize", "charSize"),
Expand Down Expand Up @@ -91,9 +91,9 @@ void ImGuiGD::AddFontDefault()
ImGui::Godot::AddFontDefault();
}

void ImGuiGD::RebuildFontAtlas(float scale)
void ImGuiGD::RebuildFontAtlas()
{
ImGui::Godot::RebuildFontAtlas(scale);
ImGui::Godot::RebuildFontAtlas();
}

void ImGuiGD::_SetVisible(bool visible)
Expand Down
2 changes: 1 addition & 1 deletion gdext/src/ImGuiGD.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ImGuiGD : public Object
void AddFont(const Ref<FontFile>& fontFile, int fontSize, bool merge = false,
const PackedInt32Array& glyphRanges = {});
void AddFontDefault();
void RebuildFontAtlas(float scale);
void RebuildFontAtlas();

void _SetJoyAxisDeadZone(float zone);
float _GetJoyAxisDeadZone();
Expand Down
3 changes: 2 additions & 1 deletion src/ViewportArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ public override void _Ready()
public override void _InputEvent(Camera3D camera, InputEvent @event, Vector3 position,
Vector3 normal, int shapeIdx)
{
if (@event is InputEventMouseMotion)
if (@event is InputEventMouseMotion mm)
{
_piece.Position = position;
mm.Dispose(); // prevent "leaks"
}
else if (@event is InputEventMouseButton mb && mb.Pressed)
{
Expand Down

0 comments on commit bcdd315

Please sign in to comment.