183 lines
5.9 KiB
C#
183 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using Quik;
|
|
using Quik.VertexGenerator;
|
|
using OpenTK.Mathematics;
|
|
using OpenTK.Graphics.OpenGL4;
|
|
using OpenTK.Windowing.Common;
|
|
using OpenTK.Windowing.Desktop;
|
|
using OpenTK.Windowing.GraphicsLibraryFramework;
|
|
using Quik.FreeType;
|
|
using Quik.OpenTK;
|
|
using Quik.Typography;
|
|
using Quik.Controls;
|
|
using Quik.OpenGL;
|
|
using GL = Quik.OpenGL.GL;
|
|
using static Quik.OpenGL.GLEnum;
|
|
using Quik.CommandMachine;
|
|
|
|
namespace QuikTestApplication
|
|
{
|
|
public class Program
|
|
{
|
|
public const string vertex =
|
|
@"#version 140
|
|
uniform mat4 matrix;
|
|
in vec2 position;
|
|
in vec2 texcoord;
|
|
in vec4 color;
|
|
out vec2 ftexcoord;
|
|
out vec4 fcolor;
|
|
|
|
void main()
|
|
{
|
|
fcolor = color;
|
|
ftexcoord = texcoord;
|
|
gl_Position = matrix * vec4(position.xy, 0, 1);
|
|
}
|
|
";
|
|
|
|
public const string fragment =
|
|
@"#version 140
|
|
in vec2 ftexcoord;
|
|
in vec4 fcolor;
|
|
out vec4 outcolor;
|
|
|
|
uniform sampler2D texture0;
|
|
uniform vec2 texture0offset;
|
|
|
|
void main()
|
|
{
|
|
outcolor = fcolor * texture(texture0, ftexcoord + texture0offset);
|
|
}
|
|
";
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
NativeWindowSettings windowSettings = NativeWindowSettings.Default;
|
|
windowSettings.NumberOfSamples = 4;
|
|
NativeWindow window = new NativeWindow(windowSettings);
|
|
|
|
window.Context.MakeCurrent();
|
|
GL.LoadBindings(new GLFWBindingsContext().GetProcAddress);
|
|
|
|
FreeTypeFontManager fontManager = new FreeTypeFontManager();
|
|
QuikContext context = new QuikContext(new OpenGLTextureManager(), fontManager);
|
|
|
|
VertexGeneratorEngine engine = new VertexGeneratorEngine();
|
|
CommandQueue cmdQueue = new CommandQueue();
|
|
GL30Driver gldriver;
|
|
|
|
RootControl root = new RootControl(context);
|
|
Button button = new Button()
|
|
{
|
|
Bounds = new QRectangle(120, 60, 20, 20),
|
|
Text = "button",
|
|
Padding = 8,
|
|
NormalStroke = new QuikStrokeStyle(new QColor(0xccccccff), 4f),
|
|
HoverStroke = new QuikStrokeStyle(new QColor(0x1010ccff), 4f),
|
|
ActiveStroke = new QuikStrokeStyle(new QColor(0x999999ff), 4f),
|
|
};
|
|
button.Clicked += (sender, args) => {
|
|
if (!args.Buttons.HasFlag(Quik.MouseButton.Primary))
|
|
return;
|
|
|
|
Button xbutton = (Button)sender;
|
|
|
|
if (xbutton.Text == "button")
|
|
{
|
|
xbutton.Text = "le button";
|
|
}
|
|
else
|
|
{
|
|
xbutton.Text = "button";
|
|
}
|
|
};
|
|
root.MouseEnter += (_,_) => Console.WriteLine("enter");
|
|
root.MouseLeave += (_,_) => Console.WriteLine("leave");
|
|
root.MouseMove += (_,_) => Console.WriteLine("move");
|
|
root.MouseDown += (_,_) => Console.WriteLine("down");
|
|
root.MouseUp += (_,_) => Console.WriteLine("up");
|
|
root.Add(button);
|
|
|
|
GL.Enable(GL_MULTISAMPLE);
|
|
|
|
gldriver = new GL30Driver();
|
|
|
|
window.Context.SwapInterval = 0;
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
float lastMs = stopwatch.ElapsedMilliseconds;
|
|
int frames = 0;
|
|
for (;!window.IsExiting;)
|
|
{
|
|
NativeWindow.ProcessWindowEvents(false);
|
|
window.ProcessEvents(0.0f);
|
|
window.TryGetCurrentMonitorDpi(out float dpi, out _);
|
|
|
|
if (window.IsFocused)
|
|
{
|
|
var mouseState = window.MouseState;
|
|
QVec2 postion = new QVec2(mouseState.Position.X, window.ClientSize.Y - mouseState.Position.Y) * (dpi/72f);
|
|
Quik.MouseButton buttons =
|
|
(mouseState.IsButtonDown(OpenTK.Windowing.GraphicsLibraryFramework.MouseButton.Button1) ? Quik.MouseButton.Primary : 0) |
|
|
(mouseState.IsButtonDown(OpenTK.Windowing.GraphicsLibraryFramework.MouseButton.Button2) ? Quik.MouseButton.Secondary : 0) |
|
|
(mouseState.IsButtonDown(OpenTK.Windowing.GraphicsLibraryFramework.MouseButton.Button3) ? Quik.MouseButton.Tertiary : 0);
|
|
|
|
root.NotifyMouse(new Quik.MouseState(postion, buttons));
|
|
}
|
|
|
|
root.Bounds = new QRectangle(
|
|
window.ClientSize.X,
|
|
window.ClientSize.Y,
|
|
0,
|
|
0);
|
|
root.NotifyUpdate();
|
|
|
|
cmdQueue.Clear();
|
|
root.NotifyPaint(cmdQueue);
|
|
|
|
engine.Reset();
|
|
engine.ProcessCommands(root.Bounds, cmdQueue);
|
|
|
|
DrawQueue drawQueue = engine.DrawQueue;
|
|
|
|
GL.Clear(GL_COLOR_BUFFER_BIT);
|
|
gldriver.Draw(drawQueue);
|
|
|
|
window.Context.SwapBuffers();
|
|
|
|
frames++;
|
|
float ms = stopwatch.ElapsedMilliseconds;
|
|
if (ms - lastMs > 1000)
|
|
{
|
|
Console.WriteLine("Frames: {0}", frames*(ms - lastMs)/1000);
|
|
frames = 0;
|
|
lastMs = ms;
|
|
Console.WriteLine("Vertex Usage: {0} ; Element Usage: {1} Calls: {2}", drawQueue.VertexCount, drawQueue.ElementCount, drawQueue.DrawCallCount);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class TextFontManager : IQuikFontManager
|
|
{
|
|
public QuikContext Context { get; set; }
|
|
|
|
private TestFont _font;
|
|
|
|
public void Clear()
|
|
{
|
|
}
|
|
|
|
public QuikFont GetFont(QuikFontStyle fontStyle)
|
|
{
|
|
if (_font is null)
|
|
{
|
|
_font = new TestFont(Context);
|
|
}
|
|
|
|
return _font;
|
|
}
|
|
}
|
|
}
|
|
} |