-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionTest.cs
More file actions
75 lines (63 loc) · 2.05 KB
/
SelectionTest.cs
File metadata and controls
75 lines (63 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using Cameras;
using System.Diagnostics;
using System.Runtime.InteropServices;
using UI;
using Windows;
using Worlds;
namespace Abacus
{
public class SelectionTest : Program
{
private readonly Window window;
public unsafe SelectionTest(Application application) : base(application)
{
window = new(world, "Selection Test", new(200, 200), new(900, 720), "vulkan", new(&OnWindowClosed));
window.IsResizable = true;
Settings settings = new(world);
Camera camera = Camera.CreateOrthographic(world, window, 1f);
Canvas canvas = new(settings, camera);
Button buttonA = new(new(&Pressed), canvas);
buttonA.Position = new(100, 60);
buttonA.Size = new(32, 32);
buttonA.Color = new(1, 0, 0, 1);
Button buttonB = new(new(&Pressed), canvas);
buttonB.Position = new(200, 60);
buttonB.Size = new(32, 32);
buttonB.Color = new(0, 1, 0, 1);
Button buttonC = new(new(&Pressed), canvas);
buttonC.Position = new(200 + 16, 60 + 16);
buttonC.Size = new(32, 32);
buttonC.Color = new(0, 0, 1, 0.5f);
[UnmanagedCallersOnly]
static void Pressed(Entity buttonEntity)
{
Trace.WriteLine($"Button {buttonEntity} pressed");
}
}
public override bool Update(double deltaTime)
{
if (!IsAnyWindowOpen(world))
{
return false;
}
SharedFunctions.UpdateUISettings(world);
return true;
}
public override void Dispose()
{
if (!window.IsDestroyed)
{
window.Dispose();
}
}
private static bool IsAnyWindowOpen(World world)
{
return world.CountEntities<Window>() > 0;
}
[UnmanagedCallersOnly]
private static void OnWindowClosed(Window window)
{
window.Dispose();
}
}
}