Repository navigation
Expand file tree
/
Copy pathNuklearForm.cs
More file actions
117 lines (90 loc) · 3.69 KB
/
Copy pathNuklearForm.cs
File metadata and controls
117 lines (90 loc) · 3.69 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Drawing;
using System.Windows.Forms;
using NuklearDotNet;
using ExampleShared;
using System.Threading;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
namespace Example_WindowsForms {
// TODO: Implement properly
class FormDevice : NuklearDeviceTex<TextureBrush> {
Graphics Gfx;
NkVertex[] Verts;
ushort[] Inds;
public FormDevice(Graphics Gfx) {
this.Gfx = Gfx;
}
public override TextureBrush CreateTexture(int W, int H, IntPtr Data) {
Bitmap Bmp = new Bitmap(W, H);
BitmapData Dta = Bmp.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
for (int i = 0; i < W * H; i++)
Marshal.WriteInt32(Dta.Scan0, i * sizeof(int), Marshal.ReadInt32(Data, i * sizeof(int)));
Bmp.UnlockBits(Dta);
return new TextureBrush(Bmp);
}
public override void SetBuffer(NkVertex[] VertexBuffer, ushort[] IndexBuffer) {
Verts = VertexBuffer;
Inds = IndexBuffer;
}
public override void Render(NkHandle Userdata, TextureBrush Texture, NkRect ClipRect, uint Offset, uint Count) {
GraphicsPath Pth = new GraphicsPath();
Gfx.SetClip(new RectangleF(ClipRect.X, ClipRect.Y, ClipRect.W, ClipRect.H));
for (int i = 0; i < Count; i += 3) {
/*NkVertex Vtx1 = Verts[Inds[Offset + i - 1]];
NkVertex Vtx2 = Verts[Inds[Offset + i]];
Pth.AddLine(Vtx1.Position.X, Vtx1.Position.Y, Vtx2.Position.X, Vtx2.Position.Y);
if ((i + 1) % 3 == 0)
Pth.CloseFigure();*/
NkVertex Vtx1 = Verts[Inds[Offset + i]];
NkVertex Vtx2 = Verts[Inds[Offset + i + 1]];
NkVertex Vtx3 = Verts[Inds[Offset + i + 2]];
Pth.AddPolygon(new[] {
new Point((int)Vtx1.Position.X,(int)Vtx1.Position.Y),
new Point((int)Vtx2.Position.X,(int)Vtx2.Position.Y),
new Point((int)Vtx3.Position.X,(int)Vtx3.Position.Y),
});
Pth.CloseFigure();
}
Gfx.DrawPath(Pens.White, Pth);
// Gfx.FillPath(Texture, Pth);
Gfx.ResetClip();
}
}
public partial class NuklearForm : Form {
public NuklearForm() {
InitializeComponent();
}
Bitmap BBufferBitmap;
Graphics BBuffer;
Graphics FBuffer;
FormDevice Dev;
private void NuklearForm_Load(object sender, EventArgs e) {
FBuffer = CreateGraphics();
BBufferBitmap = new Bitmap(ClientSize.Width, ClientSize.Height);
BBuffer = Graphics.FromImage(BBufferBitmap);
Dev = new FormDevice(BBuffer);
Shared.Init(Dev);
MouseMove += (S, E) => Dev.OnMouseMove(E.X, E.Y);
MouseDown += (S, E) => Dev.OnMouseButton(NuklearEvent.MouseButton.Left, E.X, E.Y, true);
MouseUp += (S, E) => Dev.OnMouseButton(NuklearEvent.MouseButton.Left, E.X, E.Y, false);
Thread RenderThread = new Thread(Render);
RenderThread.IsBackground = true;
RenderThread.Start();
}
void Render() {
Thread.Sleep(1000);
while (true) {
BBuffer.Clear(Color.CornflowerBlue);
Shared.DrawLoop();
try {
FBuffer.DrawImage(BBufferBitmap, Point.Empty);
} catch (Exception) {
return;
}
Thread.Sleep(0);
}
}
}
}