This repository has been archived by the owner on Nov 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
TestWindows.cs
138 lines (113 loc) · 3.87 KB
/
TestWindows.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
namespace Glfw3.Tests
{
using CommandLine;
using CommandLine.Text;
using OpenGL;
using System;
/// <summary>
/// This test creates four windows and clears each in a different color.
/// </summary>
/// <remarks>
/// Ported from <c>windows.c</c>.
/// </remarks>
class TestWindows : TestBase
{
struct Color
{
internal float r, g, b;
internal Color(float r, float g, float b)
{
this.r = r;
this.g = g;
this.b = b;
}
}
readonly static string[] m_Titles =
{
"Red",
"Green",
"Blue",
"Yellow"
};
readonly static Color[] m_Colors =
{
new Color(0.95f, 0.32f, 0.11f),
new Color(0.50f, 0.80f, 0.16f),
new Color(0.00f, 0.68f, 0.94f),
new Color(0.98f, 0.74f, 0.04f)
};
class Options
{
[Option('b', HelpText = "Create decorated windows")]
public bool Decorated { get; set; }
[HelpOption(HelpText = "Display this help screen.")]
public string GetUsage()
{
return HelpText.AutoBuild(this,
(HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
}
}
static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
{
if (state != Glfw.InputState.Press)
return;
switch (key)
{
case Glfw.KeyCode.Space:
int xpos, ypos;
Glfw.GetWindowPos(window, out xpos, out ypos);
Glfw.SetWindowPos(window, xpos, ypos);
break;
case Glfw.KeyCode.Escape:
Glfw.SetWindowShouldClose(window, true);
break;
}
}
static void Main(string[] args)
{
Init();
bool decorated = false;
bool running = true;
Glfw.Window[] windows = new Glfw.Window[4];
var options = new Options();
if (Parser.Default.ParseArguments(args, options))
decorated = options.Decorated;
if (!Glfw.Init())
Environment.Exit(1);
Glfw.WindowHint(Glfw.Hint.Decorated, decorated);
Glfw.WindowHint(Glfw.Hint.Visible, false);
for (int i = 0; i < 4; i++)
{
int left, top, right, bottom;
windows[i] = Glfw.CreateWindow(200, 200, m_Titles[i]);
if (!windows[i])
{
Glfw.Terminate();
Environment.Exit(1);
}
Glfw.SetKeyCallback(windows[i], KeyCallback);
Glfw.MakeContextCurrent(windows[i]);
Gl.ClearColor(m_Colors[i].r, m_Colors[i].g, m_Colors[i].b, 1f);
Glfw.GetWindowFrameSize(windows[i], out left, out top, out right, out bottom);
Glfw.SetWindowPos(windows[i],
100 + (i & 1) * (200 + left + right),
100 + (i >> 1) * (200 + top + bottom));
}
for (int i = 0; i < 4; i++)
Glfw.ShowWindow(windows[i]);
while (running)
{
for (int i = 0; i < 4; i++)
{
Glfw.MakeContextCurrent(windows[i]);
Gl.Clear(ClearBufferMask.ColorBufferBit);
Glfw.SwapBuffers(windows[i]);
if (Glfw.WindowShouldClose(windows[i]))
running = false;
}
Glfw.WaitEvents();
}
Glfw.Terminate();
}
}
}