-
Notifications
You must be signed in to change notification settings - Fork 2
/
Demo.cs
90 lines (86 loc) · 2.55 KB
/
Demo.cs
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
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using imgui.backend;
public class Demo : GameWindow
{
ImGuiBackEnd imguiBackEnd;
LoginWindow login;
MainWindow main;
public Demo() : base(GameWindowSettings.Default, new NativeWindowSettings() { StartVisible = true, APIVersion = new Version(4, 1) })
{
Title = "OpenIM_SDK_DEMO";
imguiBackEnd = new ImGuiBackendOpenGL();
WindowState = WindowState.Normal;
int w = 900;
int h = 700;
MinimumSize = new Vector2i(w, h);
MaximumSize = MinimumSize;
login = new LoginWindow("Login", new Rect(w / 4, h / 4, w / 2, h / 2));
main = new MainWindow("MainWindow", new Rect(0, 0, w, h));
}
protected override void OnLoad()
{
base.OnLoad();
if (User.Instance.Init())
{
IsVisible = true;
}
else
{
Debug.Log("Init Sdk Error");
Close();
}
}
protected override void OnResize(ResizeEventArgs e)
{
base.OnResize(e);
GL.Viewport(0, 0, ClientSize.X, ClientSize.Y);
imguiBackEnd.WindowResized(ClientSize.X, ClientSize.Y);
// OnRenderFrame(new FrameEventArgs(0));
}
protected override void OnMove(WindowPositionEventArgs e)
{
base.OnMove(e);
// OnRenderFrame(new FrameEventArgs(0));
}
protected override void OnUpdateFrame(FrameEventArgs args)
{
base.OnUpdateFrame(args);
User.Instance.Update();
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
GL.ClearColor(new Color4(1.0f, 1.0f, 1.0f, 1.0f));
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
imguiBackEnd.StartFrame();
if (User.Instance.ConnectStatus == ConnectStatus.ConnectSuc)
{
main.OnDraw();
}
else
{
login.OnDraw();
}
imguiBackEnd.OnEndFrame((float)e.Time);
imguiBackEnd.UpdateImGuiInput(this);
SwapBuffers();
}
protected override void OnTextInput(TextInputEventArgs e)
{
base.OnTextInput(e);
imguiBackEnd.PressChar((char)e.Unicode);
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
imguiBackEnd.MouseScroll(e.Offset);
}
protected override void OnUnload()
{
base.OnUnload();
imguiBackEnd.Dispose();
}
}