Drag<float/vector> imports, sample window improvements

Added helper wrappers for DragFloat/DragVector2-3-4

Modified the sample window a bit, should support window scaling a bit better now.
internals
Eric Mellino 9 years ago
parent 1fada561bd
commit e7851d08e6
  1. 29
      src/ImGui.NET.SampleProgram/SampleWindow.cs
  2. 16
      src/ImGui.NET.sln
  3. 18
      src/ImGui.NET/IO.cs
  4. 20
      src/ImGui.NET/ImGui.cs
  5. 8
      src/ImGui.NET/ImGuiNative.cs

@ -26,10 +26,15 @@ namespace ImGuiNET
private bool _mainWindowOpened;
private static double s_desiredFrameLength = 1f / 60.0f;
private DateTime _previousFrameStartTime;
private float _scaleFactor;
private System.Numerics.Vector3 _positionValue = new System.Numerics.Vector3(500);
public unsafe SampleWindow()
{
_nativeWindow = new NativeWindow(960, 540, "ImGui.NET", GameWindowFlags.Default, OpenTK.Graphics.GraphicsMode.Default, DisplayDevice.Default);
int desiredWidth = 960, desiredHeight = 540;
_nativeWindow = new NativeWindow(desiredWidth, desiredHeight, "ImGui.NET", GameWindowFlags.Default, OpenTK.Graphics.GraphicsMode.Default, DisplayDevice.Default);
_scaleFactor = _nativeWindow.Width / desiredWidth;
GraphicsContextFlags flags = GraphicsContextFlags.Default;
_graphicsContext = new GraphicsContext(GraphicsMode.Default, _nativeWindow.WindowInfo, 3, 0, flags);
_graphicsContext.MakeCurrent(_nativeWindow.WindowInfo);
@ -110,7 +115,7 @@ namespace ImGuiNET
IO io = ImGui.GetIO();
// Build texture atlas
Alpha8TexData texData = io.FontAtlas.GetTexDataAsAlpha8();
FontTextureData texData = io.FontAtlas.GetTexDataAsAlpha8();
// Create OpenGL texture
s_fontTexture = GL.GenTexture();
@ -166,7 +171,7 @@ namespace ImGuiNET
{
IO io = ImGui.GetIO();
io.DisplaySize = new System.Numerics.Vector2(_nativeWindow.Width, _nativeWindow.Height);
io.DisplayFramebufferScale = new System.Numerics.Vector2(1, 1);
io.DisplayFramebufferScale = new System.Numerics.Vector2(_scaleFactor);
io.DeltaTime = (1f / 60f);
UpdateImGuiInput(io);
@ -214,13 +219,14 @@ namespace ImGuiNET
ImGui.TextColored(new System.Numerics.Vector4(0, 1, 1, 1), $"Button pressed {_pressCount} times.");
ImGui.InputTextMultiline("Input some numbers:",
ImGui.InputTextMultiline("Input some text:",
_textInputBuffer, (uint)_textInputBufferLength,
new System.Numerics.Vector2(360, 240),
InputTextFlags.CharsDecimal,
InputTextFlags.Default,
OnTextEdited);
ImGui.SliderFloat("SlidableValue", ref _sliderVal, -50f, 100f, $"{_sliderVal.ToString("##0.00")}", 1.0f);
ImGui.DragVector3("Vector3", ref _positionValue, -100, 100);
if (ImGui.TreeNode("First Item"))
{
@ -302,7 +308,7 @@ namespace ImGuiNET
if (_nativeWindow.Bounds.Contains(cursorState.X, cursorState.Y))
{
Point windowPoint = _nativeWindow.PointToClient(new Point(cursorState.X, cursorState.Y));
io.MousePosition = new System.Numerics.Vector2(windowPoint.X, windowPoint.Y);
io.MousePosition = new System.Numerics.Vector2(windowPoint.X / io.DisplayFramebufferScale.X, windowPoint.Y / io.DisplayFramebufferScale.Y);
}
else
{
@ -350,14 +356,19 @@ namespace ImGuiNET
// Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
IO io = ImGui.GetIO();
float fb_height = io.DisplaySize.Y * io.DisplayFramebufferScale.Y;
ImGui.ScaleClipRects(draw_data, io.DisplayFramebufferScale);
// Setup orthographic projection matrix
GL.MatrixMode(MatrixMode.Projection);
GL.PushMatrix();
GL.LoadIdentity();
GL.Ortho(0.0f, io.DisplaySize.X, io.DisplaySize.Y, 0.0f, -1.0f, 1.0f);
GL.Ortho(
0.0f,
io.DisplaySize.X / io.DisplayFramebufferScale.X,
io.DisplaySize.Y / io.DisplayFramebufferScale.Y,
0.0f,
-1.0f,
1.0f);
GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();
@ -390,7 +401,7 @@ namespace ImGuiNET
GL.BindTexture(TextureTarget.Texture2D, pcmd->TextureId.ToInt32());
GL.Scissor(
(int)pcmd->ClipRect.X,
(int)(fb_height - pcmd->ClipRect.W),
(int)(io.DisplaySize.Y - pcmd->ClipRect.W),
(int)(pcmd->ClipRect.Z - pcmd->ClipRect.X),
(int)(pcmd->ClipRect.W - pcmd->ClipRect.Y));
ushort[] indices = new ushort[pcmd->ElemCount];

@ -67,14 +67,14 @@ Global
{2665014F-0FEC-4268-8F77-7B029921AB09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.Debug|x64.ActiveCfg = Debug|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.Debug|x64.Build.0 = Debug|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Debug|Any CPU.ActiveCfg = OSX_Debug|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Debug|Any CPU.Build.0 = OSX_Debug|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Debug|x64.ActiveCfg = OSX_Debug|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Debug|x64.Build.0 = OSX_Debug|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Release|Any CPU.ActiveCfg = OSX_Release|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Release|Any CPU.Build.0 = OSX_Release|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Release|x64.ActiveCfg = OSX_Release|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Release|x64.Build.0 = OSX_Release|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Debug|Any CPU.Build.0 = Debug|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Debug|x64.ActiveCfg = Debug|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Debug|x64.Build.0 = Debug|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Release|Any CPU.ActiveCfg = Release|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Release|Any CPU.Build.0 = Release|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Release|x64.ActiveCfg = Release|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.OSX_Release|x64.Build.0 = Release|x64
{2665014F-0FEC-4268-8F77-7B029921AB09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.Release|Any CPU.Build.0 = Release|Any CPU
{2665014F-0FEC-4268-8F77-7B029921AB09}.Release|x64.ActiveCfg = Release|x64

@ -173,14 +173,24 @@ namespace ImGuiNET
_atlasPtr = atlasPtr;
}
public Alpha8TexData GetTexDataAsAlpha8()
public FontTextureData GetTexDataAsAlpha8()
{
byte* pixels;
int width, height;
int bytesPerPixel;
ImGuiNative.ImFontAtlas_GetTexDataAsAlpha8(_atlasPtr, &pixels, &width, &height, &bytesPerPixel);
return new Alpha8TexData(pixels, width, height, bytesPerPixel);
return new FontTextureData(pixels, width, height, bytesPerPixel);
}
public FontTextureData GetTexDataAsRGBA32()
{
byte* pixels;
int width, height;
int bytesPerPixel;
ImGuiNative.ImFontAtlas_GetTexDataAsRGBA32(_atlasPtr, &pixels, &width, &height, &bytesPerPixel);
return new FontTextureData(pixels, width, height, bytesPerPixel);
}
public void SetTexID(int textureID)
@ -199,14 +209,14 @@ namespace ImGuiNET
}
}
public unsafe struct Alpha8TexData
public unsafe struct FontTextureData
{
public readonly byte* Pixels;
public readonly int Width;
public readonly int Height;
public readonly int BytesPerPixel;
public Alpha8TexData(byte* pixels, int width, int height, int bytesPerPixel)
public FontTextureData(byte* pixels, int width, int height, int bytesPerPixel)
{
Pixels = pixels;
Width = width;

@ -360,6 +360,26 @@ namespace ImGuiNET
ImGuiNative.igSliderFloat(sliderLabel, ref value, min, max, displayText, power);
}
public static void DragFloat(string label, ref float value, float min, float max, float dragSpeed = 1f, string displayFormat = "%f", float dragPower = 1f)
{
ImGuiNative.igDragFloat(label, ref value, dragSpeed, min, max, displayFormat, dragPower);
}
public static void DragVector2(string label, ref Vector2 value, float min, float max, float dragSpeed = 1f, string displayFormat = "%f", float dragPower = 1f)
{
ImGuiNative.igDragFloat2(label, ref value, dragSpeed, min, max, displayFormat, dragPower);
}
public static void DragVector3(string label, ref Vector3 value, float min, float max, float dragSpeed = 1f, string displayFormat = "%f", float dragPower = 1f)
{
ImGuiNative.igDragFloat3(label, ref value, dragSpeed, min, max, displayFormat, dragPower);
}
public static void DragVector4(string label, ref Vector4 value, float min, float max, float dragSpeed = 1f, string displayFormat = "%f", float dragPower = 1f)
{
ImGuiNative.igDragFloat4(label, ref value, dragSpeed, min, max, displayFormat, dragPower);
}
public static void TextColored(Vector4 colorRGBA, string text)
{
ImGuiNative.igTextColored(colorRGBA, text);

@ -386,16 +386,16 @@ namespace ImGuiNET
// Widgets: Drags (tip: ctrl+click on a drag box to input text)
[DllImport(cimguiLib)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool igDragFloat(string label, float* v, float v_speed, float v_min, float v_max, string display_format, float power); // If v_max >= v_max we have no bound
public static extern bool igDragFloat(string label, ref float v, float v_speed, float v_min, float v_max, string display_format, float power); // If v_max >= v_max we have no bound
[DllImport(cimguiLib)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool igDragFloat2(string label, Vector2 v, float v_speed, float v_min, float v_max, string display_format, float power);
public static extern bool igDragFloat2(string label, ref Vector2 v, float v_speed, float v_min, float v_max, string display_format, float power);
[DllImport(cimguiLib)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool igDragFloat3(string label, Vector3 v, float v_speed, float v_min, float v_max, string display_format, float power);
public static extern bool igDragFloat3(string label, ref Vector3 v, float v_speed, float v_min, float v_max, string display_format, float power);
[DllImport(cimguiLib)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool igDragFloat4(string label, Vector4 v, float v_speed, float v_min, float v_max, string display_format, float power);
public static extern bool igDragFloat4(string label, ref Vector4 v, float v_speed, float v_min, float v_max, string display_format, float power);
[DllImport(cimguiLib)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool igDragFloatRange2(string label, float* v_current_min, float* v_current_max, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, string display_format = "%.3f", string display_format_max = null, float power = 1.0f);

Loading…
Cancel
Save