Skip to content

Commit 8e63d31

Browse files
committed
Added examples, readme, and nuget package.
1 parent 4d387ea commit 8e63d31

File tree

15 files changed

+940
-30
lines changed

15 files changed

+940
-30
lines changed

Example/Example.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\Hexa.NET.Raylib\Hexa.NET.Raylib.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

Example/Program.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Hexa.NET.Raylib;
2+
3+
Raylib.InitWindow(1280, 720, "Example");
4+
5+
Raylib.SetTargetFPS(60);
6+
7+
while (!Raylib.WindowShouldClose())
8+
{
9+
Raylib.BeginDrawing();
10+
Raylib.ClearBackground(Raylib.White);
11+
Raylib.DrawText("Hello, world!", 190, 200, 20, Raylib.LightGray);
12+
Raylib.EndDrawing();
13+
}
14+
15+
Raylib.CloseWindow();

ExampleImGui/ExampleImGui.csproj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Hexa.NET.ImGui" Version="2.1.1" />
13+
<PackageReference Include="Hexa.NET.ImGuizmo" Version="2.1.1" />
14+
<PackageReference Include="Hexa.NET.ImNodes" Version="2.1.1" />
15+
<PackageReference Include="Hexa.NET.ImPlot" Version="2.1.1" />
16+
<PackageReference Include="Hexa.NET.Utilities" Version="2.1.6" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\Hexa.NET.Raylib\Hexa.NET.Raylib.csproj" />
21+
</ItemGroup>
22+
23+
</Project>

ExampleImGui/Globals.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using static Hexa.NET.Utilities.Utils;

ExampleImGui/ImGuiManager.cs

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
namespace ExampleFramework.ImGuiDemo
2+
{
3+
using ExampleImGui;
4+
using Hexa.NET.ImGui;
5+
using Hexa.NET.ImGuizmo;
6+
using Hexa.NET.ImNodes;
7+
using Hexa.NET.ImPlot;
8+
using System.Numerics;
9+
10+
public class ImGuiManager
11+
{
12+
private ImGuiContextPtr guiContext;
13+
private ImNodesContextPtr nodesContext;
14+
private ImPlotContextPtr plotContext;
15+
16+
public unsafe ImGuiManager()
17+
{
18+
// Create ImGui context
19+
guiContext = ImGui.CreateContext(null);
20+
21+
// Set ImGui context
22+
ImGui.SetCurrentContext(guiContext);
23+
24+
// Set ImGui context for ImGuizmo
25+
ImGuizmo.SetImGuiContext(guiContext);
26+
27+
// Set ImGui context for ImPlot
28+
ImPlot.SetImGuiContext(guiContext);
29+
30+
// Set ImGui context for ImNodes
31+
ImNodes.SetImGuiContext(guiContext);
32+
33+
// Create and set ImNodes context and set style
34+
nodesContext = ImNodes.CreateContext();
35+
ImNodes.SetCurrentContext(nodesContext);
36+
ImNodes.StyleColorsDark(ImNodes.GetStyle());
37+
38+
// Create and set ImPlot context and set style
39+
plotContext = ImPlot.CreateContext();
40+
ImPlot.SetCurrentContext(plotContext);
41+
ImPlot.StyleColorsDark(ImPlot.GetStyle());
42+
43+
// Setup ImGui config.
44+
var io = ImGui.GetIO();
45+
io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard; // Enable Keyboard Controls
46+
io.ConfigFlags |= ImGuiConfigFlags.NavEnableGamepad; // Enable Gamepad Controls
47+
io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; // Enable Docking
48+
//io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; // Enable Multi-Viewport / Platform Windows
49+
io.ConfigViewportsNoAutoMerge = false;
50+
io.ConfigViewportsNoTaskBarIcon = false;
51+
52+
// setup fonts.
53+
var config = ImGui.ImFontConfig();
54+
io.Fonts.AddFontDefault(config);
55+
56+
// setup ImGui style
57+
var style = ImGui.GetStyle();
58+
var colors = style.Colors;
59+
60+
colors[(int)ImGuiCol.Text] = new Vector4(1.00f, 1.00f, 1.00f, 1.00f);
61+
colors[(int)ImGuiCol.TextDisabled] = new Vector4(0.50f, 0.50f, 0.50f, 1.00f);
62+
colors[(int)ImGuiCol.WindowBg] = new Vector4(0.10f, 0.10f, 0.10f, 1.00f);
63+
colors[(int)ImGuiCol.ChildBg] = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
64+
colors[(int)ImGuiCol.PopupBg] = new Vector4(0.19f, 0.19f, 0.19f, 0.92f);
65+
colors[(int)ImGuiCol.Border] = new Vector4(0.19f, 0.19f, 0.19f, 0.29f);
66+
colors[(int)ImGuiCol.BorderShadow] = new Vector4(0.00f, 0.00f, 0.00f, 0.24f);
67+
colors[(int)ImGuiCol.FrameBg] = new Vector4(0.05f, 0.05f, 0.05f, 0.54f);
68+
colors[(int)ImGuiCol.FrameBgHovered] = new Vector4(0.19f, 0.19f, 0.19f, 0.54f);
69+
colors[(int)ImGuiCol.FrameBgActive] = new Vector4(0.20f, 0.22f, 0.23f, 1.00f);
70+
colors[(int)ImGuiCol.TitleBg] = new Vector4(0.00f, 0.00f, 0.00f, 1.00f);
71+
colors[(int)ImGuiCol.TitleBgActive] = new Vector4(0.06f, 0.06f, 0.06f, 1.00f);
72+
colors[(int)ImGuiCol.TitleBgCollapsed] = new Vector4(0.00f, 0.00f, 0.00f, 1.00f);
73+
colors[(int)ImGuiCol.MenuBarBg] = new Vector4(0.14f, 0.14f, 0.14f, 1.00f);
74+
colors[(int)ImGuiCol.ScrollbarBg] = new Vector4(0.05f, 0.05f, 0.05f, 0.54f);
75+
colors[(int)ImGuiCol.ScrollbarGrab] = new Vector4(0.34f, 0.34f, 0.34f, 0.54f);
76+
colors[(int)ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.40f, 0.40f, 0.40f, 0.54f);
77+
colors[(int)ImGuiCol.ScrollbarGrabActive] = new Vector4(0.56f, 0.56f, 0.56f, 0.54f);
78+
colors[(int)ImGuiCol.CheckMark] = new Vector4(0.33f, 0.67f, 0.86f, 1.00f);
79+
colors[(int)ImGuiCol.SliderGrab] = new Vector4(0.34f, 0.34f, 0.34f, 0.54f);
80+
colors[(int)ImGuiCol.SliderGrabActive] = new Vector4(0.56f, 0.56f, 0.56f, 0.54f);
81+
colors[(int)ImGuiCol.Button] = new Vector4(0.05f, 0.05f, 0.05f, 0.54f);
82+
colors[(int)ImGuiCol.ButtonHovered] = new Vector4(0.19f, 0.19f, 0.19f, 0.54f);
83+
colors[(int)ImGuiCol.ButtonActive] = new Vector4(0.20f, 0.22f, 0.23f, 1.00f);
84+
colors[(int)ImGuiCol.Header] = new Vector4(0.00f, 0.00f, 0.00f, 0.52f);
85+
colors[(int)ImGuiCol.HeaderHovered] = new Vector4(0.00f, 0.00f, 0.00f, 0.36f);
86+
colors[(int)ImGuiCol.HeaderActive] = new Vector4(0.20f, 0.22f, 0.23f, 0.33f);
87+
colors[(int)ImGuiCol.Separator] = new Vector4(0.28f, 0.28f, 0.28f, 0.29f);
88+
colors[(int)ImGuiCol.SeparatorHovered] = new Vector4(0.44f, 0.44f, 0.44f, 0.29f);
89+
colors[(int)ImGuiCol.SeparatorActive] = new Vector4(0.40f, 0.44f, 0.47f, 1.00f);
90+
colors[(int)ImGuiCol.ResizeGrip] = new Vector4(0.28f, 0.28f, 0.28f, 0.29f);
91+
colors[(int)ImGuiCol.ResizeGripHovered] = new Vector4(0.44f, 0.44f, 0.44f, 0.29f);
92+
colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.40f, 0.44f, 0.47f, 1.00f);
93+
colors[(int)ImGuiCol.Tab] = new Vector4(0.00f, 0.00f, 0.00f, 0.52f);
94+
colors[(int)ImGuiCol.TabHovered] = new Vector4(0.14f, 0.14f, 0.14f, 1.00f);
95+
colors[(int)ImGuiCol.TabSelected] = new Vector4(0.20f, 0.20f, 0.20f, 0.36f);
96+
colors[(int)ImGuiCol.TabDimmed] = new Vector4(0.00f, 0.00f, 0.00f, 0.52f);
97+
colors[(int)ImGuiCol.TabDimmedSelected] = new Vector4(0.14f, 0.14f, 0.14f, 1.00f);
98+
colors[(int)ImGuiCol.DockingPreview] = new Vector4(0.33f, 0.67f, 0.86f, 1.00f);
99+
colors[(int)ImGuiCol.DockingEmptyBg] = new Vector4(1.00f, 0.00f, 0.00f, 1.00f);
100+
colors[(int)ImGuiCol.PlotLines] = new Vector4(1.00f, 0.00f, 0.00f, 1.00f);
101+
colors[(int)ImGuiCol.PlotLinesHovered] = new Vector4(1.00f, 0.00f, 0.00f, 1.00f);
102+
colors[(int)ImGuiCol.PlotHistogram] = new Vector4(1.00f, 0.00f, 0.00f, 1.00f);
103+
colors[(int)ImGuiCol.PlotHistogramHovered] = new Vector4(1.00f, 0.00f, 0.00f, 1.00f);
104+
colors[(int)ImGuiCol.TableHeaderBg] = new Vector4(0.00f, 0.00f, 0.00f, 0.52f);
105+
colors[(int)ImGuiCol.TableBorderStrong] = new Vector4(0.00f, 0.00f, 0.00f, 0.52f);
106+
colors[(int)ImGuiCol.TableBorderLight] = new Vector4(0.28f, 0.28f, 0.28f, 0.29f);
107+
colors[(int)ImGuiCol.TableRowBg] = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
108+
colors[(int)ImGuiCol.TableRowBgAlt] = new Vector4(1.00f, 1.00f, 1.00f, 0.06f);
109+
colors[(int)ImGuiCol.TextSelectedBg] = new Vector4(0.20f, 0.22f, 0.23f, 1.00f);
110+
colors[(int)ImGuiCol.DragDropTarget] = new Vector4(0.33f, 0.67f, 0.86f, 1.00f);
111+
colors[(int)ImGuiCol.NavHighlight] = new Vector4(1.00f, 0.00f, 0.00f, 1.00f);
112+
colors[(int)ImGuiCol.NavWindowingHighlight] = new Vector4(1.00f, 0.00f, 0.00f, 0.70f);
113+
colors[(int)ImGuiCol.NavWindowingDimBg] = new Vector4(1.00f, 0.00f, 0.00f, 0.20f);
114+
colors[(int)ImGuiCol.ModalWindowDimBg] = new Vector4(0.10f, 0.10f, 0.10f, 0.00f);
115+
116+
style.WindowPadding = new Vector2(8.00f, 8.00f);
117+
style.FramePadding = new Vector2(5.00f, 2.00f);
118+
style.CellPadding = new Vector2(6.00f, 6.00f);
119+
style.ItemSpacing = new Vector2(6.00f, 6.00f);
120+
style.ItemInnerSpacing = new Vector2(6.00f, 6.00f);
121+
style.TouchExtraPadding = new Vector2(0.00f, 0.00f);
122+
style.IndentSpacing = 25;
123+
style.ScrollbarSize = 15;
124+
style.GrabMinSize = 10;
125+
style.WindowBorderSize = 1;
126+
style.ChildBorderSize = 1;
127+
style.PopupBorderSize = 1;
128+
style.FrameBorderSize = 1;
129+
style.TabBorderSize = 1;
130+
style.WindowRounding = 7;
131+
style.ChildRounding = 4;
132+
style.FrameRounding = 3;
133+
style.PopupRounding = 4;
134+
style.ScrollbarRounding = 9;
135+
style.GrabRounding = 3;
136+
style.LogSliderDeadzone = 4;
137+
style.TabRounding = 4;
138+
139+
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
140+
if ((io.ConfigFlags & ImGuiConfigFlags.ViewportsEnable) != 0)
141+
{
142+
style.WindowRounding = 0.0f;
143+
style.Colors[(int)ImGuiCol.WindowBg].W = 1.0f;
144+
}
145+
146+
ImGuiRaylibPlatform.Init();
147+
}
148+
149+
public unsafe void NewFrame()
150+
{
151+
// Set ImGui context
152+
ImGui.SetCurrentContext(guiContext);
153+
// Set ImGui context for ImGuizmo
154+
ImGuizmo.SetImGuiContext(guiContext);
155+
// Set ImGui context for ImPlot
156+
ImPlot.SetImGuiContext(guiContext);
157+
// Set ImGui context for ImNodes
158+
ImNodes.SetImGuiContext(guiContext);
159+
160+
// Set ImNodes context
161+
ImNodes.SetCurrentContext(nodesContext);
162+
// Set ImPlot context
163+
ImPlot.SetCurrentContext(plotContext);
164+
165+
// Start new frame, call order matters.
166+
ImGuiRaylibPlatform.NewFrame();
167+
ImGui.NewFrame();
168+
ImGuizmo.BeginFrame(); // mandatory for ImGuizmo
169+
170+
// Example for getting the central dockspace id of a window/viewport.
171+
ImGui.PushStyleColor(ImGuiCol.WindowBg, Vector4.Zero);
172+
DockSpaceId = ImGui.DockSpaceOverViewport(null, ImGuiDockNodeFlags.PassthruCentralNode, null); // passing null as first argument will use the main viewport
173+
ImGui.PopStyleColor(1);
174+
}
175+
176+
public static uint DockSpaceId { get; private set; }
177+
178+
public event Action OnRenderDrawData;
179+
180+
public unsafe void EndFrame()
181+
{
182+
// Renders ImGui Data
183+
var io = ImGui.GetIO();
184+
ImGui.Render();
185+
ImGui.EndFrame();
186+
187+
ImGuiRaylibPlatform.RenderDrawData(ImGui.GetDrawData());
188+
189+
// Update and Render additional Platform Windows
190+
if ((io.ConfigFlags & ImGuiConfigFlags.ViewportsEnable) != 0)
191+
{
192+
ImGui.UpdatePlatformWindows();
193+
ImGui.RenderPlatformWindowsDefault();
194+
}
195+
}
196+
197+
public void Dispose()
198+
{
199+
ImGuiRaylibPlatform.Shutdown();
200+
}
201+
}
202+
}

0 commit comments

Comments
 (0)