Skip to content

Commit

Permalink
Move extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Jan 18, 2024
1 parent ce9e612 commit fd5d0e2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 58 deletions.
65 changes: 65 additions & 0 deletions addons/imgui-godot/ImGuiGodot/ImGuiExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Godot;
using ImGuiNET;
using Vector3 = System.Numerics.Vector3;
using Vector4 = System.Numerics.Vector4;

namespace ImGuiGodot;

public static class ImGuiExtensions
{
/// <summary>
/// Extension method to translate between <see cref="Key"/> and <see cref="ImGuiKey"/>
/// </summary>
public static ImGuiKey ToImGuiKey(this Key key)
{
return Internal.Input.ConvertKey(key);
}

/// <summary>
/// Extension method to translate between <see cref="JoyButton"/> and <see cref="ImGuiKey"/>
/// </summary>
public static ImGuiKey ToImGuiKey(this JoyButton button)
{
return Internal.Input.ConvertJoyButton(button);
}

/// <summary>
/// Convert <see cref="Color"/> to ImGui color RGBA
/// </summary>
public static Vector4 ToVector4(this Color color)
{
return new Vector4(color.R, color.G, color.B, color.A);
}

/// <summary>
/// Convert <see cref="Color"/> to ImGui color RGB
/// </summary>
public static Vector3 ToVector3(this Color color)
{
return new Vector3(color.R, color.G, color.B);
}

/// <summary>
/// Convert RGB <see cref="Vector3"/> to <see cref="Color"/>
/// </summary>
public static Color ToColor(this Vector3 vec)
{
return new Color(vec.X, vec.Y, vec.Z);
}

/// <summary>
/// Convert RGBA <see cref="Vector4"/> to <see cref="Color"/>
/// </summary>
public static Color ToColor(this Vector4 vec)
{
return new Color(vec.X, vec.Y, vec.Z, vec.W);
}

/// <summary>
/// Set IniFilename, converting Godot path to native
/// </summary>
public static void SetIniFilename(this ImGuiIOPtr io, string fileName)
{
Internal.State.Instance.SetIniFilename(io, fileName);
}
}
58 changes: 0 additions & 58 deletions addons/imgui-godot/ImGuiGodot/ImGuiGD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Godot;
using ImGuiNET;
using System;
using Vector3 = System.Numerics.Vector3;
using Vector4 = System.Numerics.Vector4;

namespace ImGuiGodot;

Expand Down Expand Up @@ -176,62 +174,6 @@ public static bool ProcessInput(InputEvent evt, Window window)
{
return Internal.State.Instance.Input.ProcessInput(evt, window);
}

/// <summary>
/// Extension method to translate between <see cref="Key"/> and <see cref="ImGuiKey"/>
/// </summary>
public static ImGuiKey ToImGuiKey(this Key key)
{
return Internal.Input.ConvertKey(key);
}

/// <summary>
/// Extension method to translate between <see cref="JoyButton"/> and <see cref="ImGuiKey"/>
/// </summary>
public static ImGuiKey ToImGuiKey(this JoyButton button)
{
return Internal.Input.ConvertJoyButton(button);
}

/// <summary>
/// Convert <see cref="Color"/> to ImGui color RGBA
/// </summary>
public static Vector4 ToVector4(this Color color)
{
return new Vector4(color.R, color.G, color.B, color.A);
}

/// <summary>
/// Convert <see cref="Color"/> to ImGui color RGB
/// </summary>
public static Vector3 ToVector3(this Color color)
{
return new Vector3(color.R, color.G, color.B);
}

/// <summary>
/// Convert RGB <see cref="Vector3"/> to <see cref="Color"/>
/// </summary>
public static Color ToColor(this Vector3 vec)
{
return new Color(vec.X, vec.Y, vec.Z);
}

/// <summary>
/// Convert RGBA <see cref="Vector4"/> to <see cref="Color"/>
/// </summary>
public static Color ToColor(this Vector4 vec)
{
return new Color(vec.X, vec.Y, vec.Z, vec.W);
}

/// <summary>
/// Set IniFilename, converting Godot path to native
/// </summary>
public static void SetIniFilename(this ImGuiIOPtr io, string fileName)
{
Internal.State.Instance.SetIniFilename(io, fileName);
}
}

public enum RendererType
Expand Down

0 comments on commit fd5d0e2

Please sign in to comment.