Skip to content

Commit 60316fb

Browse files
committed
Nuklear.Net
1 parent d4c45b6 commit 60316fb

53 files changed

Lines changed: 36892 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
workflow_dispatch:
9+
10+
env:
11+
DOTNET_VERSION: "10.0.x"
12+
13+
jobs:
14+
build-native:
15+
name: native (${{ matrix.rid }})
16+
runs-on: ${{ matrix.runner }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- rid: linux-x64
22+
runner: ubuntu-latest
23+
- rid: linux-arm64
24+
runner: ubuntu-24.04-arm
25+
- rid: osx-x64
26+
runner: macos-latest
27+
- rid: osx-arm64
28+
runner: macos-latest
29+
- rid: win-x64
30+
runner: windows-latest
31+
- rid: win-arm64
32+
runner: windows-latest
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
with:
37+
submodules: recursive
38+
39+
- name: Build native library (Unix)
40+
if: runner.os != 'Windows'
41+
shell: bash
42+
run: ./scripts/build-native.sh "${{ matrix.rid }}"
43+
44+
- name: Build native library (Windows)
45+
if: runner.os == 'Windows'
46+
shell: pwsh
47+
run: ./scripts/build-native.ps1 -Rid "${{ matrix.rid }}"
48+
49+
- name: Upload runtime artifact
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: runtime-${{ matrix.rid }}
53+
path: Nuklear.Net.Native/runtimes/${{ matrix.rid }}/
54+
if-no-files-found: error
55+
56+
build-dotnet:
57+
name: dotnet
58+
needs: build-native
59+
runs-on: ubuntu-latest
60+
61+
steps:
62+
- uses: actions/checkout@v4
63+
with:
64+
submodules: recursive
65+
66+
- uses: actions/setup-dotnet@v4
67+
with:
68+
dotnet-version: ${{ env.DOTNET_VERSION }}
69+
70+
- name: Download all native runtimes
71+
uses: actions/download-artifact@v4
72+
with:
73+
pattern: runtime-*
74+
path: artifact-runtimes
75+
76+
- name: Layout native runtimes
77+
shell: bash
78+
run: |
79+
shopt -s nullglob
80+
for artifact_dir in artifact-runtimes/runtime-*; do
81+
rid="${artifact_dir##*/runtime-}"
82+
mkdir -p "Nuklear.Net.Native/runtimes/${rid}"
83+
cp -R "${artifact_dir}/." "Nuklear.Net.Native/runtimes/${rid}/"
84+
done
85+
find Nuklear.Net.Native/runtimes -type f
86+
87+
- name: Build Nuklear.Net.Native
88+
run: dotnet build Nuklear.Net.Native/Nuklear.Net.Native.csproj --configuration Release
89+
90+
- name: Build Nuklear.Net
91+
run: dotnet build Nuklear.Net/Nuklear.Net.csproj --configuration Release
92+
93+
- name: Pack Nuklear.Net.Native
94+
run: dotnet pack Nuklear.Net.Native/Nuklear.Net.Native.csproj --configuration Release --output artifacts
95+
96+
- name: Pack Nuklear.Net
97+
run: dotnet pack Nuklear.Net/Nuklear.Net.csproj --configuration Release --output artifacts
98+
99+
- name: Upload NuGet package
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: nuget-packages
103+
path: artifacts/*.nupkg

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**/bin/
2+
**/obj/
3+
native/build/
4+
Nuklear.Net.Native/runtimes/
5+
*.user
6+
*.suo
7+
.vs/

Examples/Directory.Build.targets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
3+
<Import Project="$(MSBuildThisFileDirectory)../Nuklear.Net.Native/buildTransitive/net10.0/Nuklear.Net.Native.targets" />
4+
5+
</Project>

Examples/MonoGame/Game1.cs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using Microsoft.Xna.Framework;
2+
using Microsoft.Xna.Framework.Graphics;
3+
using Microsoft.Xna.Framework.Input;
4+
using Nuklear.Net.Examples.Common;
5+
using Nuklear.Net.Rendering;
6+
using NkKey = Nuklear.Net.Key;
7+
using NkMouseButton = Nuklear.Net.MouseButton;
8+
using XnaColor = Microsoft.Xna.Framework.Color;
9+
10+
namespace Nuklear.Net.Examples.MonoGame;
11+
12+
public class Game1 : Game
13+
{
14+
readonly GraphicsDeviceManager _graphics;
15+
Context? _context;
16+
MonoGameNuklearDevice? _device;
17+
float _sliderValue = 0.5f;
18+
int _clickCount;
19+
int _previousScrollWheelValue;
20+
21+
public Game1()
22+
{
23+
_graphics = new GraphicsDeviceManager(this)
24+
{
25+
PreferredBackBufferWidth = 960,
26+
PreferredBackBufferHeight = 540,
27+
};
28+
Content.RootDirectory = "Content";
29+
IsMouseVisible = true;
30+
Window.Title = "Nuklear.Net - MonoGame";
31+
IsFixedTimeStep = false;
32+
}
33+
34+
protected override void Initialize()
35+
{
36+
base.Initialize();
37+
}
38+
39+
protected override void LoadContent()
40+
{
41+
_context = new Context();
42+
_device = new MonoGameNuklearDevice(GraphicsDevice);
43+
var metrics = DisplayMetrics.From(
44+
Window.ClientBounds.Width,
45+
Window.ClientBounds.Height,
46+
GraphicsDevice.PresentationParameters.BackBufferWidth,
47+
GraphicsDevice.PresentationParameters.BackBufferHeight);
48+
_context.Initialize(_device, NuklearRenderingOptions.CreatePixelPerfect(), metrics);
49+
ApplyDisplayMetrics();
50+
}
51+
52+
void ApplyDisplayMetrics()
53+
{
54+
if (_context is null)
55+
return;
56+
57+
_context.SetDisplayMetrics(DisplayMetrics.From(
58+
Window.ClientBounds.Width,
59+
Window.ClientBounds.Height,
60+
GraphicsDevice.PresentationParameters.BackBufferWidth,
61+
GraphicsDevice.PresentationParameters.BackBufferHeight));
62+
}
63+
64+
protected override void Update(GameTime gameTime)
65+
{
66+
if (_context is null)
67+
return;
68+
69+
_context.DeltaTimeSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
70+
71+
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
72+
Exit();
73+
74+
base.Update(gameTime);
75+
}
76+
77+
protected override void Draw(GameTime gameTime)
78+
{
79+
if (_context is null || _device is null)
80+
return;
81+
82+
GraphicsDevice.Clear(new XnaColor(31, 36, 46));
83+
ApplyDisplayMetrics();
84+
_context.RunFrame(_device, MapInput, () => DemoUi.Build(_context, ref _sliderValue, ref _clickCount));
85+
86+
base.Draw(gameTime);
87+
}
88+
89+
protected override void Dispose(bool disposing)
90+
{
91+
if (disposing)
92+
{
93+
_device?.Dispose();
94+
_context?.Dispose();
95+
}
96+
97+
base.Dispose(disposing);
98+
}
99+
100+
void MapInput(InputFrame frame)
101+
{
102+
var mouse = Mouse.GetState();
103+
frame.MousePosition = new Vec2(mouse.X, mouse.Y);
104+
frame.SetMouseButton(NkMouseButton.Left, mouse.LeftButton == ButtonState.Pressed);
105+
frame.SetMouseButton(NkMouseButton.Right, mouse.RightButton == ButtonState.Pressed);
106+
frame.SetMouseButton(NkMouseButton.Middle, mouse.MiddleButton == ButtonState.Pressed);
107+
var scrollDelta = mouse.ScrollWheelValue - _previousScrollWheelValue;
108+
_previousScrollWheelValue = mouse.ScrollWheelValue;
109+
frame.ScrollDelta = new Vec2(0, scrollDelta / 120f);
110+
111+
var keyboard = Keyboard.GetState();
112+
frame.SetKey(NkKey.Shift, keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift));
113+
frame.SetKey(NkKey.Ctrl, keyboard.IsKeyDown(Keys.LeftControl) || keyboard.IsKeyDown(Keys.RightControl));
114+
frame.SetKey(NkKey.Alt, keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt));
115+
frame.SetKey(NkKey.Enter, keyboard.IsKeyDown(Keys.Enter));
116+
frame.SetKey(NkKey.Backspace, keyboard.IsKeyDown(Keys.Back));
117+
frame.SetKey(NkKey.Tab, keyboard.IsKeyDown(Keys.Tab));
118+
frame.SetKey(NkKey.Up, keyboard.IsKeyDown(Keys.Up));
119+
frame.SetKey(NkKey.Down, keyboard.IsKeyDown(Keys.Down));
120+
frame.SetKey(NkKey.Left, keyboard.IsKeyDown(Keys.Left));
121+
frame.SetKey(NkKey.Right, keyboard.IsKeyDown(Keys.Right));
122+
}
123+
}

0 commit comments

Comments
 (0)