Additional cleanup and commenting

internals
Eric Mellino 9 years ago
parent 206770ccd1
commit c05147d5aa
  1. 40
      src/ImGui.NET.SampleProgram/SampleWindow.cs
  2. 3
      src/ImGui.NET.SampleProgram/project.json
  3. 7
      src/ImGui.NET/DrawData.cs
  4. 151
      src/ImGui.NET/DrawList.cs
  5. 6
      src/ImGui.NET/DrawVert.cs
  6. 91
      src/ImGui.NET/Font.cs
  7. 75
      src/ImGui.NET/FontAtlas.cs
  8. 8
      src/ImGui.NET/GuiKey.cs
  9. 1
      src/ImGui.NET/IO.cs
  10. 24
      src/ImGui.NET/ImGui.cs
  11. 5
      src/ImGui.NET/ImVector.cs
  12. 8
      src/ImGui.NET/MouseCursorKind.cs
  13. 8
      src/ImGui.NET/SelectableFlags.cs
  14. 115
      src/ImGui.NET/Style.cs
  15. 8
      src/ImGui.NET/StyleVar.cs

@ -6,6 +6,7 @@ using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using ImDrawIdx = System.UInt16;
namespace ImGui
@ -22,6 +23,8 @@ namespace ImGui
private float _sliderVal;
private System.Numerics.Vector4 _buttonColor = new System.Numerics.Vector4(55f / 255f, 155f / 255f, 1f, 1f);
private bool _mainWindowOpened;
private static double s_desiredFrameLength = 1f / 60.0f;
private DateTime _previousFrameStartTime;
public unsafe SampleWindow()
{
@ -30,7 +33,7 @@ namespace ImGui
GraphicsContextFlags flags = GraphicsContextFlags.Default;
_graphicsContext = new GraphicsContext(GraphicsMode.Default, _nativeWindow.WindowInfo, 3, 0, flags);
_graphicsContext.MakeCurrent(_nativeWindow.WindowInfo);
((IGraphicsContextInternal)_graphicsContext).LoadAll(); // wtf is this?
_graphicsContext.LoadAll(); // wtf is this?
GL.ClearColor(Color.Black);
_nativeWindow.Visible = true;
@ -132,8 +135,23 @@ namespace ImGui
{
while (_nativeWindow.Visible)
{
_previousFrameStartTime = DateTime.UtcNow;
RenderFrame();
_nativeWindow.ProcessEvents();
DateTime afterFrameTime = DateTime.UtcNow;
double elapsed = (afterFrameTime - _previousFrameStartTime).TotalSeconds;
double sleepTime = s_desiredFrameLength - elapsed;
if (sleepTime > 0.0)
{
DateTime finishTime = afterFrameTime + TimeSpan.FromSeconds(sleepTime);
while (DateTime.UtcNow < finishTime)
{
Thread.Sleep(0);
}
Thread.Sleep((int)(sleepTime * 1000));
}
}
}
@ -179,8 +197,8 @@ namespace ImGui
ImGuiNative.igText("World!");
ImGuiNative.igText("From ImGui.NET. ...Did that work?");
var pos = ImGuiNative.igGetIO()->MousePos;
//bool leftPressed = ImGuiNative.igGetIO()->MouseDown[0];
//ImGuiNative.igText("Current mouse position: " + pos + ". Pressed=" + leftPressed);
bool leftPressed = ImGuiNative.igGetIO()->MouseDown[0] == 1;
ImGuiNative.igText("Current mouse position: " + pos + ". Pressed=" + leftPressed);
if (ImGuiNative.igButton("Press me!", new System.Numerics.Vector2(120, 30)))
{
@ -229,7 +247,7 @@ namespace ImGui
private unsafe void UpdateImGuiInput(IO* io)
{
MouseState cursorState = OpenTK.Input.Mouse.GetCursorState();
MouseState cursorState = Mouse.GetCursorState();
MouseState mouseState = Mouse.GetState();
if (_nativeWindow.Bounds.Contains(cursorState.X, cursorState.Y))
@ -279,15 +297,12 @@ namespace ImGui
GL.EnableClientState(ArrayCap.ColorArray);
GL.Enable(EnableCap.Texture2D);
//glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context
GL.UseProgram(0);
// Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
IO* io = ImGuiNative.igGetIO();
float fb_height = io->DisplaySize.Y * io->DisplayFramebufferScale.Y;
// Can implement the below in C#.
//draw_data->ScaleClipRects(io.DisplayFramebufferScale);
ImGui.ScaleClipRects(draw_data, io->DisplayFramebufferScale);
// Setup orthographic projection matrix
GL.MatrixMode(MatrixMode.Projection);
@ -299,7 +314,6 @@ namespace ImGui
GL.LoadIdentity();
// Render command lists
// #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
@ -311,11 +325,8 @@ namespace ImGui
DrawVert vert1 = *(((DrawVert*)vtx_buffer) + 1);
DrawVert vert2 = *(((DrawVert*)vtx_buffer) + 2);
//glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF("pos")));
GL.VertexPointer(2, VertexPointerType.Float, sizeof(DrawVert), new IntPtr(vtx_buffer + DrawVert.PosOffset));
//glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF("uv")));
GL.TexCoordPointer(2, TexCoordPointerType.Float, sizeof(DrawVert), new IntPtr(vtx_buffer + DrawVert.UVOffset));
//glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + OFFSETOF("col")));
GL.ColorPointer(4, ColorPointerType.UnsignedByte, sizeof(DrawVert), new IntPtr(vtx_buffer + DrawVert.ColOffset));
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
@ -324,19 +335,15 @@ namespace ImGui
if (pcmd->UserCallback != IntPtr.Zero)
{
throw new NotImplementedException();
//pcmd->UserCallback(cmd_list, pcmd);
}
else
{
//glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
GL.BindTexture(TextureTarget.Texture2D, pcmd->TextureId.ToInt32());
//glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));
GL.Scissor(
(int)pcmd->ClipRect.X,
(int)(fb_height - pcmd->ClipRect.W),
(int)(pcmd->ClipRect.Z - pcmd->ClipRect.X),
(int)(pcmd->ClipRect.W - pcmd->ClipRect.Y));
//glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer);
ushort[] indices = new ushort[pcmd->ElemCount];
for (int i = 0; i < indices.Length; i++) { indices[i] = idx_buffer[i]; }
GL.DrawElements(PrimitiveType.Triangles, (int)pcmd->ElemCount, DrawElementsType.UnsignedShort, new IntPtr(idx_buffer));
@ -344,7 +351,6 @@ namespace ImGui
idx_buffer += pcmd->ElemCount;
}
}
// #undef OFFSETOF
// Restore modified state
GL.DisableClientState(ArrayCap.ColorArray);

@ -1,7 +1,8 @@
{
"dependencies": {
"Microsoft.NETCore.Console": "1.0.0-beta-23430",
"System.Console": "4.0.0-beta-23430"
"System.Console": "4.0.0-beta-23430",
"System.Threading.Thread": "4.0.0-beta-23430"
},
"runtimes": {
"win10-x64": { },

@ -11,12 +11,5 @@ namespace ImGui
public int CmdListsCount;
public int TotalVtxCount; // For convenience, sum of all cmd_lists vtx_buffer.Size
public int TotalIdxCount; // For convenience, sum of all cmd_lists idx_buffer.Size
// Functions
/*
ImDrawData() { Valid = false; CmdLists = NULL; CmdListsCount = TotalVtxCount = TotalIdxCount = 0; }
IMGUI_API void DeIndexAllBuffers(); // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
IMGUI_API void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
*/
};
}

@ -3,117 +3,78 @@ using System.Runtime.InteropServices;
namespace ImGui
{
// Draw command list
// This is the low-level list of polygons that ImGui functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
// At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged in the future.
// If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives.
// You can interleave normal ImGui:: calls and adding primitives to the current draw list.
// All positions are in screen coordinates (0,0=top-left, 1 pixel per unit). Primitives are always added to the list and not culled (culling is done at render time and at a higher-level by ImGui:: functions).
// Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl
/// <summary>
/// Draw command list
/// This is the low-level list of polygons that ImGui functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
/// At the moment, each ImGui window contains its own ImDrawList but they could potentially be merged in the future.
/// If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives.
/// You can interleave normal ImGui:: calls and adding primitives to the current draw list.
/// All positions are in screen coordinates (0,0=top-left, 1 pixel per unit). Primitives are always added to the list and not culled (culling is done at render time and at a higher-level by ImGui:: functions).
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe struct DrawList
{
// This is what you have to render
// ImVector<ImDrawCmd> CmdBuffer; // Commands. Typically 1 command = 1 gpu draw call.
// ImVector<ImDrawIdx> IdxBuffer; // Index buffer. Each command consume ImDrawCmd::ElemCount of those
// ImVector<ImDrawVert> VtxBuffer; // Vertex buffer.
/// <summary>
/// ImVector(ImDrawCmd)
/// ImVector(ImDrawCmd).
/// Commands. Typically 1 command = 1 gpu draw call.
/// </summary>
public ImVector CmdBuffer; // Commands. Typically 1 command = 1 gpu draw call.
public ImVector CmdBuffer;
/// <summary>
/// ImVector(ImDrawIdx)
/// ImVector(ImDrawIdx).
/// Index buffer. Each command consume ImDrawCmd::ElemCount of those
/// </summary>
public ImVector IdxBuffer; // Index buffer. Each command consume ImDrawCmd::ElemCount of those
public ImVector IdxBuffer;
/// <summary>
/// ImVector(ImDrawVert)
/// </summary>
public ImVector VtxBuffer; // Vertex buffer.
public ImVector VtxBuffer;
// [Internal, used while building lists]
public IntPtr _OwnerName; // Pointer to owner window's name (if any) for debugging
public uint _VtxCurrentIdx; // [Internal] == VtxBuffer.Size
//ImDrawVert* _VtxWritePtr; // [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
//ImDrawIdx* _IdxWritePtr; // [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
public IntPtr _VtxWritePtr; // [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
public IntPtr _IdxWritePtr; // [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
//ImVector<ImVec4> _ClipRectStack; // [Internal]
//ImVector<ImTextureID> _TextureIdStack; // [Internal]
//ImVector<ImVec2> _Path; // [Internal] current path building
public ImVector _ClipRectStack; // [Internal]
public ImVector _TextureIdStack; // [Internal]
public ImVector _Path; // [Internal] current path building
public int _ChannelsCurrent; // [Internal] current channel number (0)
public int _ChannelsCount; // [Internal] number of active channels (1+)
//ImVector<ImDrawChannel> _Channels; // [Internal] draw channels for columns API (not resized down so _ChannelsCount may be smaller than _Channels.Size)
public ImVector _Channels; // [Internal] draw channels for columns API (not resized down so _ChannelsCount may be smaller than _Channels.Size)
/*
ImDrawList() { _OwnerName = NULL; Clear(); }
~ImDrawList() { ClearFreeMemory(); }
IMGUI_API void Clear();
IMGUI_API void ClearFreeMemory();
IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2.
IMGUI_API void PushClipRectFullScreen();
IMGUI_API void PopClipRect();
IMGUI_API void PushTextureID(const ImTextureID& texture_id);
IMGUI_API void PopTextureID();
// Primitives
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F);
IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F);
IMGUI_API void AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left);
IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL);
IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL);
IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), ImU32 col = 0xFFFFFFFF);
IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, bool closed, float thickness, bool anti_aliased);
IMGUI_API void AddConvexPolyFilled(const ImVec2* points, const int num_points, ImU32 col, bool anti_aliased);
IMGUI_API void AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments = 0);
/// <summary>
/// Pointer to owner window's name (if any) for debugging
/// </summary>
public IntPtr _OwnerName;
/// <summary>
/// [Internal] == VtxBuffer.Size
/// </summary>
public uint _VtxCurrentIdx;
// Stateful path API, add points then finish with PathFill() or PathStroke()
inline void PathClear() { _Path.resize(0); }
inline void PathLineTo(const ImVec2& pos) { _Path.push_back(pos); }
inline void PathLineToMergeDuplicate(const ImVec2& pos) { if (_Path.Size == 0 || _Path[_Path.Size - 1].x != pos.x || _Path[_Path.Size - 1].y != pos.y) _Path.push_back(pos); }
inline void PathFill(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col, true); PathClear(); }
inline void PathStroke(ImU32 col, bool closed, float thickness = 1.0f) { AddPolyline(_Path.Data, _Path.Size, col, closed, thickness, true); PathClear(); }
IMGUI_API void PathArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments = 10);
IMGUI_API void PathArcToFast(const ImVec2& centre, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle
IMGUI_API void PathBezierCurveTo(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, int num_segments = 0);
IMGUI_API void PathRect(const ImVec2& rect_min, const ImVec2& rect_max, float rounding = 0.0f, int rounding_corners = 0x0F);
/// <summary>
/// [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
/// </summary>
public IntPtr _VtxWritePtr;
/// <summary>
/// [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
/// </summary>
public IntPtr _IdxWritePtr;
// Channels
// - Use to simulate layers. By switching channels to can render out-of-order (e.g. submit foreground primitives before background primitives)
// - Use to minimize draw calls (e.g. if going back-and-forth between multiple non-overlapping clipping rectangles, prefer to append into separate channels then merge at the end)
IMGUI_API void ChannelsSplit(int channels_count);
IMGUI_API void ChannelsMerge();
IMGUI_API void ChannelsSetCurrent(int channel_index);
/// <summary>
/// [Internal]
/// </summary>
public ImVector _ClipRectStack;
/// <summary>
/// [Internal]
/// </summary>
public ImVector _TextureIdStack;
/// <summary>
/// [Internal] current path building
/// </summary>
public ImVector _Path;
// Advanced
IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'UserCallback' in ImDrawCmd and call the function instead of rendering triangles.
IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible
/// <summary>
/// [Internal] current channel number (0)
/// </summary>
public int _ChannelsCurrent;
/// <summary>
/// [Internal] number of active channels (1+)
/// </summary>
public int _ChannelsCount;
// Internal helpers
// NB: all primitives needs to be reserved via PrimReserve() beforehand!
IMGUI_API void PrimReserve(int idx_count, int vtx_count);
IMGUI_API void PrimRect(const ImVec2& a, const ImVec2& b, ImU32 col);
IMGUI_API void PrimRectUV(const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col);
inline void PrimVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { PrimWriteIdx((ImDrawIdx)_VtxCurrentIdx); PrimWriteVtx(pos, uv, col); }
inline void PrimWriteVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { _VtxWritePtr->pos = pos; _VtxWritePtr->uv = uv; _VtxWritePtr->col = col; _VtxWritePtr++; _VtxCurrentIdx++; }
inline void PrimWriteIdx(ImDrawIdx idx) { *_IdxWritePtr = idx; _IdxWritePtr++; }
IMGUI_API void UpdateClipRect();
IMGUI_API void UpdateTextureID();
*/
};
/// <summary>
/// [Internal] draw channels for columns API (not resized down so _ChannelsCount may be smaller than _Channels.Size)
/// </summary>
public ImVector _Channels;
}
}

@ -1,4 +1,4 @@
using ImVec2 = System.Numerics.Vector2;
using System.Numerics;
using System.Runtime.InteropServices;
namespace ImGui
@ -6,8 +6,8 @@ namespace ImGui
[StructLayout(LayoutKind.Sequential)]
public unsafe struct DrawVert
{
public ImVec2 pos;
public ImVec2 uv;
public Vector2 pos;
public Vector2 uv;
public uint col;
public const int PosOffset = 0;

@ -4,34 +4,56 @@ using System.Numerics;
namespace ImGui
{
// Font runtime data and rendering
// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
/// <summary>
/// Font runtime data and rendering.
/// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Font
{
// Members: Settings
public float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
public float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
public Vector2 DisplayOffset; // = (0.0f,1.0f) // Offset font rendering by xx pixels
public ushort FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
/// <summary>
/// ImFontConfig*
/// Height of characters, set during loading (don't change after loading).
/// Default value: [user-set]
/// </summary>
public float FontSize;
/// <summary>
/// Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
/// Default value: 1.0f.
/// </summary>
public float Scale;
/// <summary>
/// Offset font rendering by xx pixels.
/// Default value: (0.0f, 1.0f)
/// </summary>
public Vector2 DisplayOffset;
/// <summary>
/// Replacement glyph if one isn't found. Only set via SetFallbackChar()
/// Default value: '?'
/// </summary>
public ushort FallbackChar;
/// <summary>
/// ImFontConfig*. Pointer within ImFontAtlas->ConfigData
/// </summary>
public IntPtr ConfigData; // // Pointer within ImFontAtlas->ConfigData
public int ConfigDataCount; //
public IntPtr ConfigData;
public int ConfigDataCount;
// Members: Runtime data
[StructLayout(LayoutKind.Sequential)]
public struct Glyph
{
ushort Codepoint;
float XAdvance;
float X0, Y0, X1, Y1;
float U0, V0, U1, V1; // Texture coordinates
public ushort Codepoint;
public float XAdvance;
public float X0, Y0, X1, Y1;
public float U0, V0, U1, V1; // Texture coordinates
};
public float Ascent, Descent; // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
/// <summary>
/// Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
/// </summary>
public float Ascent, Descent;
/// <summary>
/// ImFontAtlas*
@ -42,33 +64,20 @@ namespace ImGui
/// ImVector(Glyph)
/// </summary>
public ImVector Glyphs;
/// <summary>
/// Equivalent to FindGlyph(FontFallbackChar)
/// </summary>
public Glyph* FallbackGlyph;
public float FallbackXAdvance;
public Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
public float FallbackXAdvance; //
//ImVector<float> IndexXAdvance; // Sparse. Glyphs->XAdvance directly indexable (more cache-friendly that reading from Glyphs, for CalcTextSize functions which are often bottleneck in large UI)
//ImVector<int> IndexLookup; // Sparse. Index glyphs by Unicode code-point.
public ImVector IndexXAdvance; // Sparse. Glyphs->XAdvance directly indexable (more cache-friendly that reading from Glyphs, for CalcTextSize functions which are often bottleneck in large UI)
public ImVector IndexLookup; // Sparse. Index glyphs by Unicode code-point.
// Methods
/*
IMGUI_API ImFont();
IMGUI_API ~ImFont();
IMGUI_API void Clear();
IMGUI_API void BuildLookupTable();
IMGUI_API const Glyph* FindGlyph(unsigned short c) const;
IMGUI_API void SetFallbackChar(ImWchar c);
float GetCharAdvance(unsigned short c) const { return ((int)c<IndexXAdvance.Size) ? IndexXAdvance[(int)c] : FallbackXAdvance; }
bool IsLoaded() const { return ContainerAtlas != NULL; }
// 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
// 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8
IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const;
IMGUI_API void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawList* draw_list, float wrap_width = 0.0f, bool cpu_fine_clip = false) const;
*/
/// <summary>
/// Sparse. Glyphs->XAdvance directly indexable (more cache-friendly that reading from Glyphs,
/// for CalcTextSize functions which are often bottleneck in large UI).
/// </summary>
public ImVector IndexXAdvance;
/// <summary>
/// Sparse. Index glyphs by Unicode code-point.
/// </summary>
public ImVector IndexLookup;
};
}

@ -15,45 +15,39 @@ namespace ImGui
[StructLayout(LayoutKind.Sequential)]
public unsafe struct FontAtlas
{
/*
public ImFont* AddFont(ImFontConfig* font_cfg) { }
public ImFont* AddFontDefault(ImFontConfig* font_cfg = null) { }
public ImFont* AddFontFromFileTTF(char* filename, float size_pixels, ImFontConfig* font_cfg = null, ImWchar* glyph_ranges = null) { }
public ImFont* AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float size_pixels, ImFontConfig* font_cfg = null, ImWchar* glyph_ranges = null); // Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
public ImFont* AddFontFromMemoryCompressedTTF(void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, ImFontConfig* font_cfg = null, ImWchar* glyph_ranges = null); // 'compressed_ttf_data' still owned by caller. Compress with binary_to_compressed_c.cpp
public ImFont* AddFontFromMemoryCompressedBase85TTF(char* compressed_ttf_data_base85, float size_pixels, ImFontConfig* font_cfg = null, ImWchar* glyph_ranges = null); // 'compressed_ttf_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 paramaeter
public void ClearTexData(); // Clear the CPU-side texture data. Saves RAM once the texture has been copied to graphics memory.
public void ClearInputData(); // Clear the input TTF data (inc sizes, glyph ranges)
public void ClearFonts(); // Clear the ImGui-side font data (glyphs storage, UV coordinates)
public void Clear() { } // Clear all
// Retrieve texture data
// User is in charge of copying the pixels into graphics memory, then call SetTextureUserID()
// After loading the texture into your graphic system, store your texture handle in 'TexID' (ignore if you aren't using multiple fonts nor images)
// RGBA32 format is provided for convenience and high compatibility, but note that all RGB pixels are white, so 75% of the memory is wasted.
// Pitch = Width * BytesPerPixels
public void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = null); // 1 byte per-pixel
public void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = null); // 4 bytes-per-pixel
void SetTexID(void* id) { TexID = id; }
// Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
// (Those functions could be static but aren't so most users don't have to refer to the ImFontAtlas:: name ever if in their code; just using io.Fonts->)
public ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
public ImWchar* GetGlyphRangesKorean(); // Default + Korean characters
public ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
public ImWchar* GetGlyphRangesChinese(); // Japanese + full set of about 21000 CJK Unified Ideographs
public ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters
*/
// Members
// (Access texture data via GetTexData*() calls which will setup a default font for you.)
public void* TexID; // User data to refer to the texture once it has been uploaded to user's graphic systems. It ia passed back to you during rendering.
public byte* TexPixelsAlpha8; // 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
public UIntPtr TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
public IntPtr TexWidth; // Texture width calculated during Build().
public IntPtr TexHeight; // Texture height calculated during Build().
public IntPtr TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height.
public Vector2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block)
/// <summary>
/// User data to refer to the texture once it has been uploaded to user's graphic systems.
/// It ia passed back to you during rendering.
/// </summary>
public void* TexID;
/// <summary>
/// 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
/// </summary>
public byte* TexPixelsAlpha8;
/// <summary>
/// 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
/// </summary>
public UIntPtr TexPixelsRGBA32;
/// <summary>
/// Texture width calculated during Build().
/// </summary>
public IntPtr TexWidth;
/// <summary>
/// Texture height calculated during Build().
/// </summary>
public IntPtr TexHeight;
/// <summary>
/// Texture width desired by user before Build(). Must be a power-of-two.
/// If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height.
/// </summary>
public IntPtr TexDesiredWidth;
/// <summary>
/// Texture coordinates to a white pixel (part of the TexExtraData block)
/// </summary>
public Vector2 TexUvWhitePixel;
/// <summary>
/// (ImVector(ImFont*)
@ -62,11 +56,8 @@ namespace ImGui
// Private
/// <summary>
/// ImVector(ImFontConfig)
/// ImVector(ImFontConfig). Internal data
/// </summary>
public ImVector ConfigData; // Internal data
/*
public bool Build(); // Build pixels data. This is automatically for you by the GetTexData*** functions.
*/
public ImVector ConfigData;
}
}

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImGui
namespace ImGui
{
/// <summary>
/// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array

@ -160,7 +160,6 @@ namespace ImGui
/// ImGui itself mostly only uses left button (BeginPopupContext** are using right button).
/// Others buttons allows us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API.
/// </summary>
[MarshalAs(UnmanagedType.I1)]
public fixed byte MouseDown[5];
/// <summary>
/// Mouse wheel: 1 unit scrolls about 5 lines text.

@ -1,5 +1,4 @@
using System;
using System.Numerics;
using System.Numerics;
namespace ImGui
{
@ -36,6 +35,25 @@ namespace ImGui
return ImGuiNative.igButton(message, size);
}
/// <summary>
/// Helper to scale the ClipRect field of each ImDrawCmd.
/// Use if your final output buffer is at a different scale than ImGui expects,
/// or if there is a difference between your window resolution and framebuffer resolution.
/// </summary>
/// <param name="drawData">Pointer to the DrawData to scale.</param>
/// <param name="scale">The scale to apply.</param>
public static unsafe void ScaleClipRects(DrawData* drawData, Vector2 scale)
{
for (int i = 0; i < drawData->CmdListsCount; i++)
{
DrawList* cmd_list = drawData->CmdLists[i];
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
DrawCmd* drawCmdList = (DrawCmd*)cmd_list->CmdBuffer.Data;
DrawCmd* cmd = &drawCmdList[cmd_i];
cmd->ClipRect = new Vector4(cmd->ClipRect.X * scale.X, cmd->ClipRect.Y * scale.Y, cmd->ClipRect.Z * scale.X, cmd->ClipRect.W * scale.Y);
}
}
}
}
}

@ -1,14 +1,11 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
namespace ImGui
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct ImVector
{
//[MarshalAs(UnmanagedType.SysInt)]
public int Size;
//[MarshalAs(UnmanagedType.SysInt)]
public int Capacity;
///<summary>T* Data</summary>
public void* Data;

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImGui
namespace ImGui
{
/// <summary>
/// Enumeration for GetMouseCursor()

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImGui
namespace ImGui
{
/// <summary>
/// Flags for ImGui::Selectable()

@ -6,29 +6,98 @@ namespace ImGui
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Style
{
public float Alpha; // Global alpha applies to everything in ImGui
public Vector2 WindowPadding; // Padding within a window
public Vector2 WindowMinSize; // Minimum window size
public float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
public Align WindowTitleAlign; // Alignment for title bar text
public float ChildWindowRounding; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows
public Vector2 FramePadding; // Padding within a framed rectangle (used by most widgets)
public float FrameRounding; // Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets).
public Vector2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines
public Vector2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
public Vector2 TouchExtraPadding; // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
public float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin()
public float IndentSpacing; // Horizontal indentation when e.g. entering a tree node
public float ColumnsMinSpacing; // Minimum horizontal spacing between two columns
public float ScrollbarSize; // Width of the vertical scrollbar, Height of the horizontal scrollbar
public float ScrollbarRounding; // Radius of grab corners for scrollbar
public float GrabMinSize; // Minimum width/height of a grab box for slider/scrollbar
public float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
public Vector2 DisplayWindowPadding; // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows.
public Vector2 DisplaySafeAreaPadding; // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
public byte AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU.
public byte AntiAliasedShapes; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
public float CurveTessellationTol; // Tessellation tolerance. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
/// <summary>
/// Global alpha applies to everything in ImGui.
/// </summary>
public float Alpha;
/// <summary>
/// Padding within a window.
/// </summary>
public Vector2 WindowPadding;
/// <summary>
/// Minimum window size.
/// </summary>
public Vector2 WindowMinSize;
/// <summary>
/// Radius of window corners rounding. Set to 0.0f to have rectangular windows.
/// </summary>
public float WindowRounding;
/// <summary>
/// Alignment for title bar text.
/// </summary>
public Align WindowTitleAlign;
/// <summary>
/// Radius of child window corners rounding. Set to 0.0f to have rectangular windows.
/// </summary>
public float ChildWindowRounding;
/// <summary>
/// Padding within a framed rectangle (used by most widgets).
/// </summary>
public Vector2 FramePadding;
/// <summary>
/// Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets).
/// </summary>
public float FrameRounding;
/// <summary>
/// Horizontal and vertical spacing between widgets/lines.
/// </summary>
public Vector2 ItemSpacing;
/// <summary>
/// Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label).
/// </summary>
public Vector2 ItemInnerSpacing;
/// <summary>
/// Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
/// </summary>
public Vector2 TouchExtraPadding;
/// <summary>
/// Default alpha of window background, if not specified in ImGui::Begin().
/// </summary>
public float WindowFillAlphaDefault;
/// <summary>
/// Horizontal indentation when e.g. entering a tree node
/// </summary>
public float IndentSpacing;
/// <summary>
/// Minimum horizontal spacing between two columns
/// </summary>
public float ColumnsMinSpacing;
/// <summary>
/// Width of the vertical scrollbar, Height of the horizontal scrollbar
/// </summary>
public float ScrollbarSize;
/// <summary>
/// Radius of grab corners for scrollbar
/// </summary>
public float ScrollbarRounding;
/// <summary>
/// Minimum width/height of a grab box for slider/scrollbar
/// </summary>
public float GrabMinSize;
/// <summary>
/// Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
/// </summary>
public float GrabRounding;
/// <summary>
/// Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows.
/// </summary>
public Vector2 DisplayWindowPadding;
/// <summary>
/// If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
/// </summary>
public Vector2 DisplaySafeAreaPadding;
/// <summary>
/// Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU.
/// </summary>
public byte AntiAliasedLines;
/// <summary>
/// Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
/// </summary>
public byte AntiAliasedShapes;
/// <summary>
/// Tessellation tolerance. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
/// </summary>
public float CurveTessellationTol;
public fixed float Colors[(int)ColorTarget.Count * 4];
};
}

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImGui
namespace ImGui
{
/// <summary>
/// Enumeration for PushStyleVar() / PopStyleVar()

Loading…
Cancel
Save