Rename geometry types with Q prefix instead of Quik.

This commit is contained in:
H. Utku Maden 2023-06-29 10:42:02 +03:00
parent fe71028573
commit 41b7bebba5
29 changed files with 485 additions and 2920 deletions

@ -64,15 +64,15 @@ namespace Quik.FreeType
entry.Atlas = new Atlas(_owner.Context.TextureManager, _library); entry.Atlas = new Atlas(_owner.Context.TextureManager, _library);
_textures.Add(entry.Atlas); _textures.Add(entry.Atlas);
} }
entry.Atlas.AttachGlyph(_face.Glyph, out QuikRectangle uvs); entry.Atlas.AttachGlyph(_face.Glyph, out QRectangle uvs);
entry.Metrics = new QuikGlyph( entry.Metrics = new QuikGlyph(
character, character,
uvs, uvs,
new QuikVec2(_face.Glyph.Metrics.Width / 64f, _face.Glyph.Metrics.Height / 64f), new QVec2(_face.Glyph.Metrics.Width / 64f, _face.Glyph.Metrics.Height / 64f),
new QuikVec2(_face.Glyph.Metrics.HorizontalBearingX / 64f, _face.Glyph.Metrics.HorizontalBearingY / 64f), new QVec2(_face.Glyph.Metrics.HorizontalBearingX / 64f, _face.Glyph.Metrics.HorizontalBearingY / 64f),
new QuikVec2(_face.Glyph.Metrics.VerticalBearingX / 64f , _face.Glyph.Metrics.VerticalBearingY / 64f), new QVec2(_face.Glyph.Metrics.VerticalBearingX / 64f , _face.Glyph.Metrics.VerticalBearingY / 64f),
new QuikVec2(_face.Glyph.Metrics.HorizontalAdvance / 64f, _face.Glyph.Metrics.VerticalAdvance / 64f)); new QVec2(_face.Glyph.Metrics.HorizontalAdvance / 64f, _face.Glyph.Metrics.VerticalAdvance / 64f));
_entries[character] = entry; _entries[character] = entry;
@ -104,7 +104,7 @@ namespace Quik.FreeType
{ {
public QuikTexture Texture; public QuikTexture Texture;
private QuikVec2 _pointer = new QuikVec2(); private QVec2 _pointer = new QVec2();
private float _verticalAdvance = 0; private float _verticalAdvance = 0;
private FTLibrary _ft; private FTLibrary _ft;
private FTBitmap _bitmap; private FTBitmap _bitmap;
@ -112,7 +112,7 @@ namespace Quik.FreeType
public Atlas(IQuikTextureManager textureManager, FTLibrary ft) public Atlas(IQuikTextureManager textureManager, FTLibrary ft)
{ {
Texture = textureManager.CreateTexture( Texture = textureManager.CreateTexture(
new QuikVec2(4096, 4096), new QVec2(4096, 4096),
false, false,
QuikImageFormat.RgbaU8); QuikImageFormat.RgbaU8);
@ -126,14 +126,14 @@ namespace Quik.FreeType
return true; return true;
} }
public void AttachGlyph(in FTGlyphSlot slot, out QuikRectangle UVs) public void AttachGlyph(in FTGlyphSlot slot, out QRectangle UVs)
{ {
FT.BitmapConvert(_ft, slot.Bitmap, ref _bitmap, 1); FT.BitmapConvert(_ft, slot.Bitmap, ref _bitmap, 1);
QuikRectangle position = QRectangle position =
new QuikRectangle( new QRectangle(
_pointer + new QuikVec2(_bitmap.Width + 1, _bitmap.Rows + 1), _pointer + new QVec2(_bitmap.Width + 1, _bitmap.Rows + 1),
_pointer + new QuikVec2(1, 1)); _pointer + new QVec2(1, 1));
Texture.SubImage( Texture.SubImage(
_bitmap.Buffer, _bitmap.Buffer,
@ -145,7 +145,7 @@ namespace Quik.FreeType
_pointer.X += _bitmap.Width + 2; _pointer.X += _bitmap.Width + 2;
_verticalAdvance = Math.Max(_verticalAdvance, slot.Bitmap.Rows + 2); _verticalAdvance = Math.Max(_verticalAdvance, slot.Bitmap.Rows + 2);
UVs = new QuikRectangle( UVs = new QRectangle(
position.Right / 4096, position.Right / 4096,
position.Bottom / 4096, position.Bottom / 4096,
position.Left / 4096, position.Left / 4096,

@ -2,6 +2,8 @@ using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using Quik.OpenGL; using Quik.OpenGL;
using Quik.VertexGenerator;
using Matrix4 = OpenTK.Mathematics.Matrix4;
using static Quik.OpenGL.GLEnum; using static Quik.OpenGL.GLEnum;
namespace Quik.OpenTK namespace Quik.OpenTK
@ -86,9 +88,16 @@ namespace Quik.OpenTK
{ {
location = GL.GetAttribLocation(_sp, name); location = GL.GetAttribLocation(_sp, name);
} }
_vbo = GL.GenBuffer();
_ebo = GL.GenBuffer();
_vao = GL.GenVertexArray();
} }
private readonly int _sp; private readonly int _sp;
private readonly int _vao;
private readonly int _vbo;
private readonly int _ebo;
private const string _nameM4View = "m4View"; private const string _nameM4View = "m4View";
private readonly int _locM4View; private readonly int _locM4View;
@ -122,6 +131,38 @@ namespace Quik.OpenTK
SdfAuxEnable = 1 << 3, SdfAuxEnable = 1 << 3,
} }
public void Draw(DrawQueue queue)
{
GL.UseProgram(_sp);
GL.BindVertexArray(_vao);
GL.BindBuffer(GL_ARRAY_BUFFER, _vbo);
GL.BufferData(GL_ARRAY_BUFFER, queue.VertexCount * QuikVertex.Stride, queue.VertexArray, GL_STREAM_DRAW);
GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);
GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, queue.ElementCount * sizeof(int), queue.ElementArray, GL_STREAM_DRAW);
GL.VertexAttribPointer(_locV2Position, 2, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.PositionOffset);
GL.VertexAttribPointer(_locV2Texture, 2, GL_FLOAT, false, QuikVertex.Stride, QuikVertex.TextureCoordinatesOffset);
GL.VertexAttribPointer(_locV4Color, 4, GL_UNSIGNED_BYTE, false, QuikVertex.Stride, QuikVertex.ColorOffset);
GL.EnableVertexAttribArray(_locV2Position);
GL.EnableVertexAttribArray(_locV2Texture);
GL.EnableVertexAttribArray(_locV4Color);
GL.Enable(GL_BLEND);
GL.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Matrix4 m = Matrix4.Identity;
GL.UniformMatrix4(_locM4Model, false, ref m.Row0.X);
foreach (DrawCall call in queue)
{
GL.BindTexture(GL_TEXTURE_2D, ((OpenGLTexture)call.Texture)?.TextureId ?? 0);
m = Matrix4.CreateOrthographicOffCenter(0, call.Bounds.Right, 0, call.Bounds.Top, 1.0f, -1.0f);
GL.UniformMatrix4(_locM4View, false, ref m.Row0.X);
GL.DrawElements(GL_TRIANGLES, call.Count, GL_UNSIGNED_INT, call.Start);
}
}
private bool _isDisposed = false; private bool _isDisposed = false;
private void Dispose(bool disposing) private void Dispose(bool disposing)
{ {

@ -13,7 +13,7 @@ namespace Quik.OpenTK
private int _height; private int _height;
private bool _mipmaps; private bool _mipmaps;
internal OpenGLTexture(OpenGLTextureManager manager, QuikImageFormat format, QuikVec2 size, bool mipmaps) internal OpenGLTexture(OpenGLTextureManager manager, QuikImageFormat format, QVec2 size, bool mipmaps)
{ {
Manager = manager; Manager = manager;
_mipmaps = mipmaps; _mipmaps = mipmaps;
@ -61,7 +61,7 @@ namespace Quik.OpenTK
public override bool Mipmaps => _mipmaps; public override bool Mipmaps => _mipmaps;
/// <inheritdoc /> /// <inheritdoc />
public override void Image(IntPtr data, QuikImageFormat format, QuikVec2 size, int level, int alignment = 4) public override void Image(IntPtr data, QuikImageFormat format, QVec2 size, int level, int alignment = 4)
{ {
GL.BindTexture(GL_TEXTURE_2D, TextureId); GL.BindTexture(GL_TEXTURE_2D, TextureId);
GL.PixelStore(GL_UNPACK_ALIGNMENT, alignment); GL.PixelStore(GL_UNPACK_ALIGNMENT, alignment);
@ -69,7 +69,7 @@ namespace Quik.OpenTK
} }
/// <inheritdoc /> /// <inheritdoc />
public override void SubImage(IntPtr data, QuikImageFormat format, QuikRectangle location, int level, int alignment = 4) public override void SubImage(IntPtr data, QuikImageFormat format, QRectangle location, int level, int alignment = 4)
{ {
GL.BindTexture(GL_TEXTURE_2D, TextureId); GL.BindTexture(GL_TEXTURE_2D, TextureId);
GL.PixelStore(GL_UNPACK_ALIGNMENT, alignment); GL.PixelStore(GL_UNPACK_ALIGNMENT, alignment);

@ -9,7 +9,7 @@ namespace Quik.OpenTK
private List<int> _reclaimList = new List<int>(); private List<int> _reclaimList = new List<int>();
public QuikTexture CreateTexture(QuikVec2 size, bool mipmaps, QuikImageFormat format) public QuikTexture CreateTexture(QVec2 size, bool mipmaps, QuikImageFormat format)
{ {
return new OpenGLTexture(this, format, size, mipmaps); return new OpenGLTexture(this, format, size, mipmaps);
} }

@ -9,14 +9,14 @@ namespace Quik.CommandMachine
private readonly Stack<int> _zStack = new Stack<int>(); private readonly Stack<int> _zStack = new Stack<int>();
public int ZIndex => _zIndex; public int ZIndex => _zIndex;
private QuikRectangle _viewport; private QRectangle _viewport;
private readonly Stack<QuikRectangle> _viewportStack = new Stack<QuikRectangle>(); private readonly Stack<QRectangle> _viewportStack = new Stack<QRectangle>();
private readonly Stack<object> _matrixStack = new Stack<object>(); private readonly Stack<object> _matrixStack = new Stack<object>();
private Command _customCommandBase = Command.CustomCommandBase; private Command _customCommandBase = Command.CustomCommandBase;
private readonly List<QuikCommandHandler> _customCommands = new List<QuikCommandHandler>(); private readonly List<QuikCommandHandler> _customCommands = new List<QuikCommandHandler>();
public QuikRectangle Viewport => _viewport; public QRectangle Viewport => _viewport;
// TODO: Make a real matrix class. // TODO: Make a real matrix class.
public float[] ActiveTransforms { get; } public float[] ActiveTransforms { get; }
@ -35,7 +35,7 @@ namespace Quik.CommandMachine
return id; return id;
} }
public void ProcessCommands(QuikRectangle bounds, CommandQueue queue) public void ProcessCommands(QRectangle bounds, CommandQueue queue)
{ {
if (!queue.Peek().IsCommand) if (!queue.Peek().IsCommand)
throw new ArgumentException("The first element in the queue must be a command frame."); throw new ArgumentException("The first element in the queue must be a command frame.");
@ -72,13 +72,13 @@ namespace Quik.CommandMachine
_viewportStack.Push(_viewport); _viewportStack.Push(_viewport);
break; break;
case Command.IntersectViewport: case Command.IntersectViewport:
_viewport = QuikRectangle.Intersect((QuikRectangle)queue.Dequeue(), _viewport); _viewport = QRectangle.Intersect((QRectangle)queue.Dequeue(), _viewport);
break; break;
case Command.StoreViewport: case Command.StoreViewport:
_viewport = (QuikRectangle)queue.Dequeue(); _viewport = (QRectangle)queue.Dequeue();
break; break;
case Command.PopViewport: case Command.PopViewport:
_viewport = _viewportStack.TryPop(out QuikRectangle viewport) ? viewport : bounds; _viewport = _viewportStack.TryPop(out QRectangle viewport) ? viewport : bounds;
break; break;
case Command.PushZ: case Command.PushZ:
_zStack.Push(_zIndex); _zStack.Push(_zIndex);
@ -111,7 +111,7 @@ namespace Quik.CommandMachine
_zIndex = 0; _zIndex = 0;
_zStack.Clear(); _zStack.Clear();
_viewport = new QuikRectangle(float.MaxValue, float.MaxValue, float.MinValue, float.MinValue); _viewport = new QRectangle(float.MaxValue, float.MaxValue, float.MinValue, float.MinValue);
_viewportStack.Clear(); _viewportStack.Clear();
_matrixStack.Clear(); _matrixStack.Clear();

@ -33,13 +33,13 @@ namespace Quik.CommandMachine
Enqueue(Command.PushViewport); Enqueue(Command.PushViewport);
} }
public void IntersectViewport(in QuikRectangle viewport) public void IntersectViewport(in QRectangle viewport)
{ {
Enqueue(Command.IntersectViewport); Enqueue(Command.IntersectViewport);
Enqueue(viewport); Enqueue(viewport);
} }
public void StoreViewport(in QuikRectangle viewport) public void StoreViewport(in QRectangle viewport)
{ {
Enqueue(Command.StoreViewport); Enqueue(Command.StoreViewport);
Enqueue(viewport); Enqueue(viewport);
@ -93,21 +93,21 @@ namespace Quik.CommandMachine
Enqueue(Command.PopZ); Enqueue(Command.PopZ);
} }
public void Line(in QuikLine line) public void Line(in QLine line)
{ {
Enqueue(Command.Line); Enqueue(Command.Line);
Enqueue(line); Enqueue(line);
} }
public void Line(params QuikLine[] lines) public void Line(params QLine[] lines)
{ {
Enqueue(Command.Line); Enqueue(Command.Line);
Enqueue((Frame)lines.Length); Enqueue((Frame)lines.Length);
foreach (QuikLine line in lines) foreach (QLine line in lines)
Enqueue(line); Enqueue(line);
} }
public void Bezier(in QuikBezier bezier) public void Bezier(in QBezier bezier)
{ {
Frame a, b; Frame a, b;
Frame.Create(bezier, out a, out b); Frame.Create(bezier, out a, out b);
@ -117,14 +117,14 @@ namespace Quik.CommandMachine
Enqueue(b); Enqueue(b);
} }
public void Bezier(params QuikBezier[] beziers) public void Bezier(params QBezier[] beziers)
{ {
Frame a, b; Frame a, b;
Enqueue(Command.Bezier); Enqueue(Command.Bezier);
Enqueue((Frame)beziers.Length); Enqueue((Frame)beziers.Length);
foreach (QuikBezier bezier in beziers) foreach (QBezier bezier in beziers)
{ {
Frame.Create(bezier, out a, out b); Frame.Create(bezier, out a, out b);
Enqueue(a); Enqueue(a);
@ -132,21 +132,21 @@ namespace Quik.CommandMachine
} }
} }
public void Rectangle(in QuikRectangle rectangle) public void Rectangle(in QRectangle rectangle)
{ {
Enqueue(Command.Rectangle); Enqueue(Command.Rectangle);
Enqueue(rectangle); Enqueue(rectangle);
} }
public void Rectangle(QuikRectangle[] rectangles) public void Rectangle(QRectangle[] rectangles)
{ {
Enqueue(Command.Rectangle); Enqueue(Command.Rectangle);
Enqueue((Frame)rectangles.Length); Enqueue((Frame)rectangles.Length);
foreach (QuikRectangle rectangle in rectangles) foreach (QRectangle rectangle in rectangles)
Enqueue(rectangle); Enqueue(rectangle);
} }
public void Ellipse(in QuikEllipse ellipse) public void Ellipse(in QEllipse ellipse)
{ {
Frame a, b; Frame a, b;
Frame.Create(ellipse, out a, out b); Frame.Create(ellipse, out a, out b);
@ -156,12 +156,12 @@ namespace Quik.CommandMachine
Enqueue(b); Enqueue(b);
} }
public void Ellipse(params QuikEllipse[] ellipses) public void Ellipse(params QEllipse[] ellipses)
{ {
Frame a, b; Frame a, b;
Enqueue(Command.Ellipse); Enqueue(Command.Ellipse);
Enqueue((Frame)ellipses.Length); Enqueue((Frame)ellipses.Length);
foreach (QuikEllipse ellipse in ellipses) foreach (QEllipse ellipse in ellipses)
{ {
Frame.Create(ellipse, out a, out b); Frame.Create(ellipse, out a, out b);
Enqueue(a); Enqueue(a);
@ -169,7 +169,7 @@ namespace Quik.CommandMachine
} }
} }
public void Triangle(in QuikTriangle triangle) public void Triangle(in QTriangle triangle)
{ {
Enqueue(Command.Triangle); Enqueue(Command.Triangle);
Enqueue(triangle.A); Enqueue(triangle.A);
@ -177,11 +177,11 @@ namespace Quik.CommandMachine
Enqueue(triangle.C); Enqueue(triangle.C);
} }
public void Triangle(params QuikTriangle[] triangles) public void Triangle(params QTriangle[] triangles)
{ {
Enqueue(Command.Triangle); Enqueue(Command.Triangle);
Enqueue((Frame)triangles.Length); Enqueue((Frame)triangles.Length);
foreach (QuikTriangle triangle in triangles) foreach (QTriangle triangle in triangles)
{ {
Enqueue(triangle.A); Enqueue(triangle.A);
Enqueue(triangle.B); Enqueue(triangle.B);
@ -189,17 +189,17 @@ namespace Quik.CommandMachine
} }
} }
public void Polygon(params QuikVec2[] polygon) public void Polygon(params QVec2[] polygon)
{ {
Enqueue(Command.Polygon); Enqueue(Command.Polygon);
Enqueue((Frame)polygon.Length); Enqueue((Frame)polygon.Length);
foreach (QuikVec2 vertex in polygon) foreach (QVec2 vertex in polygon)
{ {
Enqueue(vertex); Enqueue(vertex);
} }
} }
public void Image(QuikTexture texture, in QuikRectangle rectangle) public void Image(QuikTexture texture, in QRectangle rectangle)
{ {
Enqueue(Command.Image); Enqueue(Command.Image);
Enqueue((Frame)(int)ImageCommandFlags.Single); Enqueue((Frame)(int)ImageCommandFlags.Single);
@ -207,7 +207,7 @@ namespace Quik.CommandMachine
Enqueue(rectangle); Enqueue(rectangle);
} }
public void Image(QuikTexture texture, in QuikRectangle rectangle, in QuikRectangle uv) public void Image(QuikTexture texture, in QRectangle rectangle, in QRectangle uv)
{ {
Enqueue(Command.Image); Enqueue(Command.Image);
Enqueue((Frame)(int)(ImageCommandFlags.Single | ImageCommandFlags.UVs)); Enqueue((Frame)(int)(ImageCommandFlags.Single | ImageCommandFlags.UVs));
@ -216,7 +216,7 @@ namespace Quik.CommandMachine
Enqueue(uv); Enqueue(uv);
} }
public void Image(QuikTexture texture, QuikRectangle[] rectangles, bool interleavedUV = false) public void Image(QuikTexture texture, QRectangle[] rectangles, bool interleavedUV = false)
{ {
ImageCommandFlags flags = interleavedUV ? ImageCommandFlags.UVs : ImageCommandFlags.None; ImageCommandFlags flags = interleavedUV ? ImageCommandFlags.UVs : ImageCommandFlags.None;
@ -224,13 +224,13 @@ namespace Quik.CommandMachine
Enqueue(new Frame((int)flags, rectangles.Length / 2)); Enqueue(new Frame((int)flags, rectangles.Length / 2));
Enqueue(new Frame(texture)); Enqueue(new Frame(texture));
foreach (QuikRectangle rectangle in rectangles) foreach (QRectangle rectangle in rectangles)
{ {
Enqueue(rectangle); Enqueue(rectangle);
} }
} }
public void Image(QuikTexture texture, QuikRectangle[] rectangles, QuikRectangle[] uvs) public void Image(QuikTexture texture, QRectangle[] rectangles, QRectangle[] uvs)
{ {
int count = Math.Min(rectangles.Length, uvs.Length); int count = Math.Min(rectangles.Length, uvs.Length);
Enqueue(Command.Image); Enqueue(Command.Image);

@ -229,34 +229,34 @@ namespace Quik.CommandMachine
public static explicit operator int(in Frame frame) => frame._i1; public static explicit operator int(in Frame frame) => frame._i1;
public static explicit operator float(in Frame frame) => frame._f1; public static explicit operator float(in Frame frame) => frame._f1;
public static explicit operator Command(in Frame frame) => (Command)frame._i1; public static explicit operator Command(in Frame frame) => (Command)frame._i1;
public static explicit operator QuikVec2(in Frame frame) => public static explicit operator QVec2(in Frame frame) =>
frame.IsFloat ? new QuikVec2(frame._f1, frame._f2) : new QuikVec2(frame._i1, frame._i2); frame.IsFloat ? new QVec2(frame._f1, frame._f2) : new QVec2(frame._i1, frame._i2);
public static explicit operator QuikColor(in Frame frame) => public static explicit operator QColor(in Frame frame) =>
new QuikColor((byte)frame._i1, (byte)frame._i2, (byte)frame._i3, (byte)frame._i4); new QColor((byte)frame._i1, (byte)frame._i2, (byte)frame._i3, (byte)frame._i4);
public static explicit operator QuikRectangle(in Frame frame) => public static explicit operator QRectangle(in Frame frame) =>
frame.IsFloat ? frame.IsFloat ?
new QuikRectangle(frame._f1, frame._f2, frame._f3, frame._f4) : new QRectangle(frame._f1, frame._f2, frame._f3, frame._f4) :
new QuikRectangle(frame._i1, frame._i2, frame._i3, frame._i4); new QRectangle(frame._i1, frame._i2, frame._i3, frame._i4);
public static explicit operator QuikLine(in Frame frame) => public static explicit operator QLine(in Frame frame) =>
frame.IsFloat ? frame.IsFloat ?
new QuikLine(frame._f1, frame._f2, frame._f3, frame._f4) : new QLine(frame._f1, frame._f2, frame._f3, frame._f4) :
new QuikLine(frame._i1, frame._i2, frame._i3, frame._i4); new QLine(frame._i1, frame._i2, frame._i3, frame._i4);
public static explicit operator Frame(int i) => new Frame(i); public static explicit operator Frame(int i) => new Frame(i);
public static explicit operator Frame(float f) => new Frame(f); public static explicit operator Frame(float f) => new Frame(f);
public static implicit operator Frame(Command cmd) => new Frame(cmd); public static implicit operator Frame(Command cmd) => new Frame(cmd);
public static implicit operator Frame(in QuikVec2 vector) => new Frame(vector.X, vector.Y); public static implicit operator Frame(in QVec2 vector) => new Frame(vector.X, vector.Y);
public static implicit operator Frame(in QuikColor color) => new Frame(color.R, color.G, color.B, color.A); public static implicit operator Frame(in QColor color) => new Frame(color.R, color.G, color.B, color.A);
public static implicit operator Frame(in QuikRectangle rect) => new Frame(rect.Max.X, rect.Max.Y, rect.Min.X, rect.Min.Y); public static implicit operator Frame(in QRectangle rect) => new Frame(rect.Max.X, rect.Max.Y, rect.Min.X, rect.Min.Y);
public static implicit operator Frame(in QuikLine line) => new Frame(line.Start.X, line.Start.Y, line.End.X, line.Start.Y); public static implicit operator Frame(in QLine line) => new Frame(line.Start.X, line.Start.Y, line.End.X, line.Start.Y);
public static void Create(in QuikBezier bezier, out Frame a, out Frame b) public static void Create(in QBezier bezier, out Frame a, out Frame b)
{ {
a = new Frame(bezier.Start.X, bezier.Start.Y, bezier.End.X, bezier.End.Y); a = new Frame(bezier.Start.X, bezier.Start.Y, bezier.End.X, bezier.End.Y);
b = new Frame(bezier.ControlA.X, bezier.ControlA.Y, bezier.ControlB.X, bezier.ControlB.Y); b = new Frame(bezier.ControlA.X, bezier.ControlA.Y, bezier.ControlB.X, bezier.ControlB.Y);
} }
public static void Create(in QuikEllipse ellipse, out Frame a, out Frame b) public static void Create(in QEllipse ellipse, out Frame a, out Frame b)
{ {
a = new Frame(ellipse.Center.X, ellipse.Center.Y); a = new Frame(ellipse.Center.X, ellipse.Center.Y);
b = new Frame(ellipse.AxisA.X, ellipse.AxisA.Y, ellipse.AxisB.X, ellipse.AxisB.Y); b = new Frame(ellipse.AxisA.X, ellipse.AxisA.Y, ellipse.AxisB.X, ellipse.AxisB.Y);

@ -1,3 +1,4 @@
using Quik.CommandMachine;
using Quik.Typography; using Quik.Typography;
namespace Quik.Controls namespace Quik.Controls
@ -60,46 +61,47 @@ namespace Quik.Controls
} }
} }
protected override void OnPaint(QuikDraw draw) protected override void OnPaint(CommandQueue draw)
{ {
QuikRectangle bounds = AbsoluteBounds; QRectangle bounds = AbsoluteBounds;
switch (_class) switch (_class)
{ {
default: default:
case ButtonClass.Normal: case ButtonClass.Normal:
draw.Commands.Enqueue(new QuikCommandRectangle(bounds) { draw.Rectangle(bounds);
StrokeStyle = NormalStroke, // draw.Commands.Enqueue(new QuikCommandRectangle(bounds) {
FillStyle = NormalFill // StrokeStyle = NormalStroke,
}); // FillStyle = NormalFill
break; // });
case ButtonClass.Hover:
draw.Commands.Enqueue(new QuikCommandRectangle(bounds) {
StrokeStyle = HoverStroke,
FillStyle = HoverFill
});
break;
case ButtonClass.Active:
draw.Commands.Enqueue(new QuikCommandRectangle(bounds) {
StrokeStyle = ActiveStroke,
FillStyle = ActiveFill
});
break; break;
// case ButtonClass.Hover:
// draw.Commands.Enqueue(new QuikCommandRectangle(bounds) {
// StrokeStyle = HoverStroke,
// FillStyle = HoverFill
// });
// break;
// case ButtonClass.Active:
// draw.Commands.Enqueue(new QuikCommandRectangle(bounds) {
// StrokeStyle = ActiveStroke,
// FillStyle = ActiveFill
// });
// break;
} }
// Position the text so that it is centered. // Position the text so that it is centered.
float ascender = Root.Context.DefaultFont.Ascender; // float ascender = Root.Context.DefaultFont.Ascender;
float descender = -Root.Context.DefaultFont.Descender; // float descender = -Root.Context.DefaultFont.Descender;
QuikVec2 position = // QuikVec2 position =
bounds.Min + // bounds.Min +
new QuikVec2( // new QuikVec2(
Padding, // Padding,
( // (
(bounds.Size.Y - ascender - descender) / // (bounds.Size.Y - ascender - descender) /
2) // 2)
+ descender); // + descender);
draw.PutText(Text, position); // draw.PutText(Text, position);
} }
} }
} }

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Quik.CommandMachine;
namespace Quik.Controls namespace Quik.Controls
{ {
@ -86,7 +87,7 @@ namespace Quik.Controls
} }
} }
internal override void NotifyPaint(QuikDraw draw) internal override void NotifyPaint(CommandQueue draw)
{ {
base.NotifyPaint(draw); base.NotifyPaint(draw);

@ -1,4 +1,5 @@
using System; using System;
using Quik.CommandMachine;
namespace Quik.Controls namespace Quik.Controls
{ {
@ -10,18 +11,18 @@ namespace Quik.Controls
protected RootControl Root { get; set; } = null; protected RootControl Root { get; set; } = null;
public QuikRectangle Bounds { get; set; } public QRectangle Bounds { get; set; }
public bool Focused { get => Root.FocusedControl == this; } public bool Focused { get => Root.FocusedControl == this; }
public QuikRectangle AbsoluteBounds public QRectangle AbsoluteBounds
{ {
get => Parent is null get => Parent is null
? Bounds ? Bounds
: new QuikRectangle(Parent.Bounds.Min + Bounds.Max, Parent.Bounds.Min + Bounds.Min); : new QRectangle(Parent.Bounds.Min + Bounds.Max, Parent.Bounds.Min + Bounds.Min);
set => Bounds = Parent is null set => Bounds = Parent is null
? value ? value
: new QuikRectangle(value.Min - Parent.Bounds.Min, value.Max - Parent.Bounds.Min); : new QRectangle(value.Min - Parent.Bounds.Min, value.Max - Parent.Bounds.Min);
} }
private MouseButton DownButtons; private MouseButton DownButtons;
@ -29,7 +30,7 @@ namespace Quik.Controls
// Hierarchy events. // Hierarchy events.
public event EventHandler Update; public event EventHandler Update;
public event EventHandler<QuikDraw> Paint; public event EventHandler<CommandQueue> Paint;
public event EventHandler<RootChangedEventArgs> RootChanging; public event EventHandler<RootChangedEventArgs> RootChanging;
public event EventHandler<ParentChangedEventArgs> ParentChanging; public event EventHandler<ParentChangedEventArgs> ParentChanging;
public event EventHandler<FocusChangedEventArgs> FocusLost; public event EventHandler<FocusChangedEventArgs> FocusLost;
@ -46,7 +47,7 @@ namespace Quik.Controls
public event EventHandler<MouseMoveEventArgs> MouseLeave; public event EventHandler<MouseMoveEventArgs> MouseLeave;
protected virtual void OnUpdate() => Update?.Invoke(this, EventArgs.Empty); protected virtual void OnUpdate() => Update?.Invoke(this, EventArgs.Empty);
protected virtual void OnPaint(QuikDraw draw) => Paint?.Invoke(this, draw); protected virtual void OnPaint(CommandQueue draw) => Paint?.Invoke(this, draw);
protected virtual void OnParentChanging(ParentChangedEventArgs args) => ParentChanging?.Invoke(this, args); protected virtual void OnParentChanging(ParentChangedEventArgs args) => ParentChanging?.Invoke(this, args);
protected virtual void OnRootChanging(RootChangedEventArgs args) => RootChanging?.Invoke(this, args); protected virtual void OnRootChanging(RootChangedEventArgs args) => RootChanging?.Invoke(this, args);
protected virtual void OnFocusLost(FocusChangedEventArgs args) => FocusLost?.Invoke(this, args); protected virtual void OnFocusLost(FocusChangedEventArgs args) => FocusLost?.Invoke(this, args);
@ -70,7 +71,7 @@ namespace Quik.Controls
OnUpdate(); OnUpdate();
} }
internal virtual void NotifyPaint(QuikDraw draw) internal virtual void NotifyPaint(CommandQueue draw)
{ {
OnPaint(draw); OnPaint(draw);
} }
@ -101,7 +102,7 @@ namespace Quik.Controls
internal virtual void NotifyMouseMove(MouseMoveEventArgs args) internal virtual void NotifyMouseMove(MouseMoveEventArgs args)
{ {
QuikRectangle bounds = AbsoluteBounds; QRectangle bounds = AbsoluteBounds;
if (bounds.Contains(args.AbsolutePosition)) if (bounds.Contains(args.AbsolutePosition))
{ {

@ -1,3 +1,4 @@
using Quik.CommandMachine;
using Quik.Typography; using Quik.Typography;
namespace Quik.Controls namespace Quik.Controls
@ -11,26 +12,26 @@ namespace Quik.Controls
public QuikFont Font { get; set; } public QuikFont Font { get; set; }
protected override void OnPaint(QuikDraw draw) // protected override void OnPaint(CommandQueue draw)
{ // {
if (MultiLine) // if (MultiLine)
{ // {
QuikRectangle absolute = AbsoluteBounds; // QuikRectangle absolute = AbsoluteBounds;
QuikVec2 paddingVector = new QuikVec2(Padding, Padding); // QuikVec2 paddingVector = new QuikVec2(Padding, Padding);
QuikRectangle rectangle; // QuikRectangle rectangle;
rectangle.Min = absolute.Min + paddingVector; // rectangle.Min = absolute.Min + paddingVector;
rectangle.Max = absolute.Min - paddingVector; // rectangle.Max = absolute.Min - paddingVector;
// FIXME: For now use a puttext command. // // FIXME: For now use a puttext command.
draw.PutText(Text, rectangle.Min + new QuikVec2(0, rectangle.Size.Y / 3f)); // draw.PutText(Text, rectangle.Min + new QuikVec2(0, rectangle.Size.Y / 3f));
// draw.FlowText(Text, rectangle); // // draw.FlowText(Text, rectangle);
} // }
else // else
{ // {
QuikVec2 position = AbsoluteBounds.Min + new QuikVec2(Padding, Padding + AbsoluteBounds.Size.Y / 3f); // QuikVec2 position = AbsoluteBounds.Min + new QuikVec2(Padding, Padding + AbsoluteBounds.Size.Y / 3f);
draw.PutText(Text, position); // draw.PutText(Text, position);
} // }
} // }
} }
} }

@ -1,14 +1,16 @@
using Quik.CommandMachine;
namespace Quik.Controls namespace Quik.Controls
{ {
public sealed class RootControl : Container public sealed class RootControl : Container
{ {
public QuikContext Context { get; } // public QuikContext Context { get; }
public Control FocusedControl { get; private set; } public Control FocusedControl { get; private set; }
public RootControl(QuikContext context) public RootControl(object context)
{ {
Context = context; // Context = context;
} }
public void Focus(Control which) public void Focus(Control which)
@ -24,7 +26,7 @@ namespace Quik.Controls
base.NotifyUpdate(); base.NotifyUpdate();
} }
public new void NotifyPaint(QuikDraw draw) public new void NotifyPaint(CommandQueue draw)
{ {
base.NotifyPaint(draw); base.NotifyPaint(draw);
} }

@ -40,7 +40,7 @@ namespace Quik
/// <param name="size">Size of the texture data.</param> /// <param name="size">Size of the texture data.</param>
/// <param name="level">Mip level.</param> /// <param name="level">Mip level.</param>
/// <param name="alignment">Pixel alignment. Expected to be 1, 2, 4, or 8.</param> /// <param name="alignment">Pixel alignment. Expected to be 1, 2, 4, or 8.</param>
public abstract void Image(IntPtr data, QuikImageFormat format, QuikVec2 size, int level, int alignment = 4); public abstract void Image(IntPtr data, QuikImageFormat format, QVec2 size, int level, int alignment = 4);
/// <summary> /// <summary>
/// Upload texture data. /// Upload texture data.
@ -50,7 +50,7 @@ namespace Quik
/// <param name="location">Location of the data in the texture.</param> /// <param name="location">Location of the data in the texture.</param>
/// <param name="level">Mip level.</param> /// <param name="level">Mip level.</param>
/// <param name="alignment">Pixel alignment. Expected to be 1, 2, 4, or 8.</param> /// <param name="alignment">Pixel alignment. Expected to be 1, 2, 4, or 8.</param>
public abstract void SubImage(IntPtr data, QuikImageFormat format, QuikRectangle location, int level, int alignment = 4); public abstract void SubImage(IntPtr data, QuikImageFormat format, QRectangle location, int level, int alignment = 4);
/// <summary> /// <summary>
/// Generate the mip maps for the texture. /// Generate the mip maps for the texture.

@ -8,7 +8,7 @@ namespace Quik
/// <summary> /// <summary>
/// The context that owns the texture manager. /// The context that owns the texture manager.
/// </summary> /// </summary>
QuikContext Context { get; set; } // QuikContext Context { get; set; }
/// <summary> /// <summary>
/// Create a texture. /// Create a texture.
@ -21,7 +21,7 @@ namespace Quik
/// All parameters are hints. If there is a situation where the texture does not /// All parameters are hints. If there is a situation where the texture does not
/// have mip levels, or format cannot be specified, ignore these parameters. /// have mip levels, or format cannot be specified, ignore these parameters.
/// </remarks> /// </remarks>
QuikTexture CreateTexture(QuikVec2 size, bool mipmaps, QuikImageFormat format); QuikTexture CreateTexture(QVec2 size, bool mipmaps, QuikImageFormat format);
/// <summary> /// <summary>
/// A function called on context clear. (useful for discarding old textures) /// A function called on context clear. (useful for discarding old textures)

@ -16,10 +16,10 @@ namespace Quik
public struct MouseState public struct MouseState
{ {
public readonly QuikVec2 AbsolutePosition; public readonly QVec2 AbsolutePosition;
public readonly MouseButton ButtonsDown; public readonly MouseButton ButtonsDown;
public MouseState(QuikVec2 position, MouseButton down) public MouseState(QVec2 position, MouseButton down)
{ {
AbsolutePosition = position; AbsolutePosition = position;
ButtonsDown = down; ButtonsDown = down;
@ -28,21 +28,21 @@ namespace Quik
public class MouseButtonEventArgs : EventArgs public class MouseButtonEventArgs : EventArgs
{ {
public QuikVec2 AbsolutePosition { get; } public QVec2 AbsolutePosition { get; }
public MouseButton Buttons { get; } public MouseButton Buttons { get; }
public MouseButtonEventArgs(QuikVec2 position, MouseButton buttons) public MouseButtonEventArgs(QVec2 position, MouseButton buttons)
{ {
AbsolutePosition = position; AbsolutePosition = position;
Buttons = buttons; Buttons = buttons;
} }
public QuikVec2 RelativePosition(QuikVec2 origin) public QVec2 RelativePosition(QVec2 origin)
{ {
return AbsolutePosition - origin; return AbsolutePosition - origin;
} }
public QuikVec2 RelativePosition(Controls.Control control) public QVec2 RelativePosition(Controls.Control control)
{ {
return AbsolutePosition - control.AbsoluteBounds.Min; return AbsolutePosition - control.AbsoluteBounds.Min;
} }
@ -50,23 +50,23 @@ namespace Quik
public class MouseMoveEventArgs : EventArgs public class MouseMoveEventArgs : EventArgs
{ {
public QuikVec2 AbsolutePosition { get; } public QVec2 AbsolutePosition { get; }
public QuikVec2 LastPosition { get; } public QVec2 LastPosition { get; }
public QuikVec2 Motion { get; } public QVec2 Motion { get; }
public MouseMoveEventArgs(QuikVec2 position, QuikVec2 lastPosition) public MouseMoveEventArgs(QVec2 position, QVec2 lastPosition)
{ {
AbsolutePosition = position; AbsolutePosition = position;
LastPosition = lastPosition; LastPosition = lastPosition;
Motion = position - lastPosition; Motion = position - lastPosition;
} }
public QuikVec2 RelativePosition(QuikVec2 origin) public QVec2 RelativePosition(QVec2 origin)
{ {
return AbsolutePosition - origin; return AbsolutePosition - origin;
} }
public QuikVec2 RelativePosition(Controls.Control control) public QVec2 RelativePosition(Controls.Control control)
{ {
return AbsolutePosition - control.AbsoluteBounds.Min; return AbsolutePosition - control.AbsoluteBounds.Min;
} }

10
Quik/QuikApplication.cs Normal file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
namespace Quik
{
public class QuikApplication
{
}
}

@ -1,645 +0,0 @@
namespace Quik
{
/// <summary>
/// Enumeration of QUIK commands.
/// </summary>
public enum QuikCommandType
{
/// <summary>
/// Nothing.
/// </summary>
/// <seealso cref="QuikCommandNone"/>
None,
/// <summary>
/// Set a mask region.
/// </summary>
Mask,
/// <summary>
/// Draw a line.
/// </summary>
/// <seealso cref="QuikCommandLine"/>
Line,
/// <summary>
/// Draw multiple lines.
/// </summary>
Lines,
/// <summary>
/// Draw a Bezier curve.
/// </summary>
Bezier,
/// <summary>
/// Draw a rectangle.
/// </summary>
Rectangle,
/// <summary>
/// Draw multiple rectangles.
/// </summary>
Rectangles,
/// <summary>
/// Draw an ellipse.
/// </summary>
Ellipse,
/// <summary>
/// Draw multiple ellipses.
/// </summary>
Ellipses,
/// <summary>
/// Draw a triangle.
/// </summary>
Triangle,
/// <summary>
/// Draw multiple triangles.
/// </summary>
Triangles,
/// <summary>
/// Draw a polygon.
/// </summary>
Polygon,
/// <summary>
/// Put a character.
/// </summary>
PutChar,
/// <summary>
/// Put text.
/// </summary>
PutText,
/// <summary>
/// Flow text in box.
/// </summary>
FlowText,
EmitTypeset,
/// <summary>
/// Clear the image mask.
/// </summary>
StencilMaskClear,
/// <summary>
/// Create an image mask with the following commands.
/// </summary>
StencilMaskBegin,
/// <summary>
/// End the image mask commands.
/// </summary>
StencilMaskEnd,
/// <summary>
/// Draw an image.
/// </summary>
Image,
/// <summary>
/// Begin defining custom commands after this value.
/// </summary>
/// <seealso cref="QuikCommand"/>
CustomCommandRange = 1024,
}
/// <summary>
/// A single QUIK command.
/// </summary>
public abstract class QuikCommand
{
/// <summary>
/// The type ID for the QUIK command.
/// </summary>
public abstract QuikCommandType Type { get; }
}
/// <summary>
/// Does nothing.
/// </summary>
public sealed class QuikCommandNone : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.None;
}
public sealed class QuikCommandMask : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Mask;
public QuikRectangle Bounds { get; }
public QuikCommandMask(QuikRectangle bounds)
{
Bounds = bounds;
}
}
/// <summary>
/// Draws a line.
/// </summary>
public sealed class QuikCommandLine : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Line;
/// <summary>
/// The line to draw.
/// </summary>
public QuikLine Line { get; }
/// <summary>
/// Stroke style of the line.
/// </summary>
public QuikStrokeStyle Style { get; set; }
/// <summary>
/// Create a draw line command.
/// </summary>
/// <param name="line">The line to draw.</param>
public QuikCommandLine(QuikLine line)
{
Line = line;
}
}
/// <summary>
/// Draw multiple lines.
/// </summary>
public sealed class QuikCommandLines : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Lines;
/// <summary>
/// The array of lines to draw.
/// </summary>
public QuikLine[] Lines { get; }
/// <summary>
/// Stroke style of the lines.
/// </summary>
public QuikStrokeStyle Style { get; set; }
/// <summary>
/// Create a draw lines command.
/// </summary>
/// <param name="lines">The lines to draw.</param>
public QuikCommandLines(QuikLine[] lines)
{
Lines = lines;
}
}
/// <summary>
/// Draw a Bezier curve.
/// </summary>
public sealed class QuikCommandBezier : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Bezier;
/// <summary>
/// The Bezier curve segments to draw.
/// </summary>
public QuikBezier[] Segments;
/// <summary>
/// Stroke style of the curve.
/// </summary>
public QuikStrokeStyle Style { get; set; }
/// <summary>
/// Create a draw Bezier curve command.
/// </summary>
/// <param name="segments">The Bezier curve segments to draw.</param>
public QuikCommandBezier(QuikBezier[] segments)
{
Segments = segments;
}
}
/// <summary>
/// Draw a rectangle.
/// </summary>
public sealed class QuikCommandRectangle : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Rectangle;
/// <summary>
/// The rectangle to draw.
/// </summary>
public QuikRectangle Rectangle { get; }
/// <summary>
/// Stroke style of the border.
/// </summary>
public QuikStrokeStyle StrokeStyle { get; set; }
/// <summary>
/// Fill style of the contents.
/// </summary>
public QuikFillStyle FillStyle { get; set; }
/// <summary>
/// Radius for round corners.
/// </summary>
public float CornerRadius { get; set; }
/// <summary>
/// Create a draw rectangle command.
/// </summary>
/// <param name="rectangle">The rectangle to draw.</param>
public QuikCommandRectangle(QuikRectangle rectangle)
{
Rectangle = rectangle;
}
}
/// <summary>
/// Draw rectangles.
/// </summary>
public sealed class QuikCommandRectangles : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Rectangles;
/// <summary>
/// The rectangles to draw.
/// </summary>
public QuikRectangle[] Rectangles { get; }
/// <summary>
/// Stroke style of the border.
/// </summary>
public QuikStrokeStyle StrokeStyle { get; set; }
/// <summary>
/// Fill style of the contents.
/// </summary>
public QuikFillStyle FillStyle { get; set; }
/// <summary>
/// Radius for round corners.
/// </summary>
public float CornerRadius { get; set; }
/// <summary>
/// Create a draw rectangles commands.
/// </summary>
/// <param name="rectangles">The rectangles to draw.</param>
public QuikCommandRectangles(QuikRectangle[] rectangles)
{
Rectangles = rectangles;
}
}
/// <summary>
/// Draw an ellipse.
/// </summary>
public sealed class QuikCommandEllipse : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Ellipse;
/// <summary>
/// The ellipse to draw.
/// </summary>
public QuikEllipse Ellipse { get; }
/// <summary>
/// Stroke style of the border.
/// </summary>
public QuikStrokeStyle StrokeStyle { get; set; }
/// <summary>
/// Fill style of the contents.
/// </summary>
public QuikFillStyle FillStyle { get; set; }
/// <summary>
/// Create a draw ellipse command.
/// </summary>
/// <param name="ellipse">The ellipse to draw.</param>
public QuikCommandEllipse(QuikEllipse ellipse)
{
Ellipse = ellipse;
}
}
/// <summary>
/// Draw ellipses.
/// </summary>
public sealed class QuikCommandEllipses : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Ellipses;
/// <summary>
/// The ellipses to draw.
/// </summary>
public QuikEllipse[] Ellipses { get; }
/// <summary>
/// Stroke style of the border.
/// </summary>
public QuikStrokeStyle StrokeStyle { get; set; }
/// <summary>
/// Fill style of the contents.
/// </summary>
public QuikFillStyle FillStyle { get; set; }
/// <summary>
/// Create a draw ellipses command.
/// </summary>
/// <param name="ellipses">The ellipses to draw.</param>
public QuikCommandEllipses(QuikEllipse[] ellipses)
{
Ellipses = ellipses;
}
}
/// <summary>
/// Create a draw triangle command.
/// </summary>
public sealed class QuikCommandTriangle : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Triangle;
/// <summary>
/// The triangle to draw.
/// </summary>
public QuikTriangle Triangle { get; }
/// <summary>
/// Stroke style of the border.
/// </summary>
public QuikStrokeStyle StrokeStyle { get; set; }
/// <summary>
/// Fill style of the contents.
/// </summary>
public QuikFillStyle FillStyle { get; set; }
/// <summary>
/// Create a draw triangle command.
/// </summary>
/// <param name="triangle">The triangles to draw.</param>
public QuikCommandTriangle(QuikTriangle triangle)
{
Triangle = triangle;
}
}
/// <summary>
/// Draw triangles.
/// </summary>
public sealed class QuikCommandTriangles : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Triangles;
/// <summary>
/// The triangles to draw.
/// </summary>
public QuikTriangle[] Triangles { get; }
/// <summary>
/// Stroke style of the border.
/// </summary>
public QuikStrokeStyle StrokeStyle { get; set; }
/// <summary>
/// Fill style of the contents.
/// </summary>
public QuikFillStyle FillStyle { get; set; }
/// <summary>
/// Create a draw triangles command.
/// </summary>
/// <param name="triangles">The triangles to draw.</param>
public QuikCommandTriangles(QuikTriangle[] triangles)
{
Triangles = triangles;
}
}
/// <summary>
/// Draw a polygon.
/// </summary>
/// <remarks>Behavior is defined by rendering backend for concave polygons.</remarks>
public sealed class QuikCommandPolygon : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Polygon;
/// <summary>
/// The vertices that make up the polygon.
/// </summary>
public QuikVec2[] Polygon { get; }
/// <summary>
/// Stroke style of the border.
/// </summary>
public QuikStrokeStyle StrokeStyle { get; set; }
/// <summary>
/// Fill style of the contents.
/// </summary>
public QuikFillStyle FillStyle { get; set; }
/// <summary>
/// Create a draw polygon command.
/// </summary>
/// <param name="polygon">The polygon to draw.</param>
public QuikCommandPolygon(QuikVec2[] polygon)
{
Polygon = polygon;
}
}
/// <summary>
/// Put a character.
/// </summary>
public sealed class QuikCommandPutChar : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.PutChar;
/// <summary>
/// The character to put.
/// </summary>
/// <remarks>This field is integer to accomodate for surrogate pairs.</remarks>
public int Character { get; }
/// <summary>
/// The baseline start position of the character.
/// </summary>
public QuikVec2 Position { get; }
/// <summary>
/// Create a put character command.
/// </summary>
/// <param name="character">The character to put.</param>
/// <param name="position">The baseline start position of the character.</param>
public QuikCommandPutChar(int character, QuikVec2 position)
{
Character = character;
Position = position;
}
/// <summary>
/// Create a put character command.
/// </summary>
/// <param name="character">The character to put.</param>
/// <param name="position">The baseline start position of the character.</param>
public QuikCommandPutChar(char character, QuikVec2 position) : this((int) character, position)
{
}
}
/// <summary>
/// Put some text.
/// </summary>
public sealed class QuikCommandPutText : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.PutText;
/// <summary>
/// The text to put.
/// </summary>
public string Text { get; }
/// <summary>
/// The baseline start position of the text.
/// </summary>
public QuikVec2 Position { get; }
/// <summary>
/// Create a put text command.
/// </summary>
/// <param name="text">The text to put.</param>
/// <param name="position">The baseline start position of the text.</param>
public QuikCommandPutText(string text, QuikVec2 position)
{
Text = text;
Position = position;
}
}
/// <summary>
/// Flow text into a box.
/// </summary>
public sealed class QuikCommandFlowText : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.FlowText;
/// <summary>
/// The text to flow.
/// </summary>
public string Text { get; }
/// <summary>
/// The flowing box boundaries.
/// </summary>
public QuikRectangle Bounds { get; }
/// <summary>
/// Create a flow text command.
/// </summary>
/// <param name="text">The text to flow.</param>
/// <param name="bounds">The flowing box boundaries.</param>
public QuikCommandFlowText(string text, QuikRectangle bounds)
{
Text = text;
Bounds = bounds;
}
}
/// <summary>
/// Emit previously typeset text.
/// </summary>
public sealed class QuikCommandEmitText : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.EmitTypeset;
/// <summary>
/// The typeset group to emit.
/// </summary>
public Typography.TypesetGroup Group { get; }
public QuikVec2 Offset { get; }
/// <summary>
/// Create an emit typeset text command.
/// </summary>
/// <param name="group">The typeset group to emit.</param>
public QuikCommandEmitText(Typography.TypesetGroup group)
{
Group = group;
Offset = new QuikVec2(0, 0);
}
/// <summary>
/// Create an emit typeset text command.
/// </summary>
/// <param name="group">The typeset group to emit.</param>
/// <param name="offset">The offset to emit at.</param>
public QuikCommandEmitText(Typography.TypesetGroup group, QuikVec2 offset)
{
Group = group;
Offset = offset;
}
}
/// <summary>
/// Clear the stencil buffer.
/// </summary>
public sealed class QuikCommandStencilClear : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.StencilMaskClear;
}
/// <summary>
/// Begin rendering to the stencil buffer.
/// </summary>
public sealed class QuikCommandStencilBegin : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.StencilMaskBegin;
}
/// <summary>
/// End rendering to the stencil buffer.
/// </summary>
public sealed class QuikCommandStencilEnd : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.StencilMaskEnd;
}
/// <summary>
/// Draw an image.
/// </summary>
public sealed class QuikCommandImage : QuikCommand
{
/// <inheritdoc/>
public override QuikCommandType Type => QuikCommandType.Image;
}
}

@ -1,51 +0,0 @@
using Quik.Typography;
namespace Quik
{
/// <summary>
/// An object which QUIK commands may be issued to.
/// </summary>
public class QuikContext
{
/// <summary>
/// Draw queue.
/// </summary>
public QuikDraw Draw { get; } = new QuikDraw();
/// <summary>
/// The object responsible for managing textures.
/// </summary>
public IQuikTextureManager TextureManager { get; }
/// <summary>
/// The object responsible for managing fonts.
/// </summary>
public IQuikFontManager FontManager { get; }
public QuikStrokeStyle DefaultStroke { get; set; } = new QuikStrokeStyle(new QuikColor(0xaaaaaaff), 4);
public QuikFillStyle DefaultFill { get; set; } = new QuikFillStyle()
{
Color = new QuikColor(0xeeeeeeff)
};
public QuikFont DefaultFont { get; set; }
public QuikContext(IQuikTextureManager textureManager, IQuikFontManager fontManager)
{
TextureManager = textureManager;
FontManager = fontManager;
TextureManager.Context = FontManager.Context = this;
}
/// <summary>
/// Clear the context.
/// </summary>
public void Clear()
{
Draw.Clear();
TextureManager.Clear();
FontManager.Clear();
}
}
}

@ -1,43 +0,0 @@
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
namespace Quik
{
/// <summary>
/// QUIK draw command provider.
/// </summary>
public class QuikDraw
{
/// <summary>
/// The draw command queue.
/// </summary>
public Queue<QuikCommand> Commands { get; } = new Queue<QuikCommand>();
public void Clear() => Commands.Clear();
public void Mask(QuikRectangle bounds) => Commands.Enqueue(new QuikCommandMask(bounds));
public void Line(QuikLine line) => Commands.Enqueue(new QuikCommandLine(line));
public void Line(params QuikLine[] lines) => Commands.Enqueue(new QuikCommandLines(lines));
public void Line(IEnumerable<QuikLine> lines) => Commands.Enqueue(new QuikCommandLines(lines.ToArray()));
public void Bezier(params QuikBezier[] curve) => Commands.Enqueue(new QuikCommandBezier(curve));
public void Bezier(IEnumerable<QuikBezier> curve) => Commands.Enqueue(new QuikCommandBezier(curve.ToArray()));
public void Rectangle(QuikRectangle rectangle) => Commands.Enqueue(new QuikCommandRectangle(rectangle));
public void Rectangle(params QuikRectangle[] rectangles) =>
Commands.Enqueue(new QuikCommandRectangles(rectangles));
public void Rectangle(IEnumerable<QuikRectangle> rectangles) =>
Commands.Enqueue(new QuikCommandRectangles(rectangles.ToArray()));
public void Triangle(QuikTriangle triangle) => Commands.Enqueue(new QuikCommandTriangle(triangle));
public void Triangle(params QuikTriangle[] triangles) => Commands.Enqueue(new QuikCommandTriangles(triangles));
public void Triangle(IEnumerable<QuikTriangle> triangles) =>
Commands.Enqueue(new QuikCommandTriangles(triangles.ToArray()));
public void Polygon(params QuikVec2[] polygon) => Commands.Enqueue(new QuikCommandPolygon(polygon));
public void Polygon(IEnumerable<QuikVec2> polygon) => Commands.Enqueue(new QuikCommandPolygon(polygon.ToArray()));
public void StencilClear() => Commands.Enqueue(new QuikCommandStencilClear());
public void StencilBegin() => Commands.Enqueue(new QuikCommandStencilBegin());
public void StencilEnd() => Commands.Enqueue(new QuikCommandStencilEnd());
public void PutChar(char chr, QuikVec2 position) => Commands.Enqueue(new QuikCommandPutChar(chr, position));
public void PutText(string text, QuikVec2 position) => Commands.Enqueue(new QuikCommandPutText(text, position));
public void FlowText(string text, QuikRectangle bounds) => Commands.Enqueue(new QuikCommandFlowText(text, bounds));
}
}

@ -8,69 +8,69 @@ namespace Quik
/// A 2 dimensional Vector. /// A 2 dimensional Vector.
/// </summary> /// </summary>
[DebuggerDisplay("({X}, {Y})")] [DebuggerDisplay("({X}, {Y})")]
public struct QuikVec2 public struct QVec2
{ {
public float X; public float X;
public float Y; public float Y;
public float Magnitude => MathF.Sqrt(X * X + Y * Y); public float Magnitude => MathF.Sqrt(X * X + Y * Y);
public QuikVec2(float x, float y) public QVec2(float x, float y)
{ {
X = x; X = x;
Y = y; Y = y;
} }
public QuikVec2 Normalize() => this * (1.0f / Magnitude); public QVec2 Normalize() => this * (1.0f / Magnitude);
public float Atan2() => MathF.Atan2(Y, X); public float Atan2() => MathF.Atan2(Y, X);
public static QuikVec2 operator +(QuikVec2 a, QuikVec2 b) public static QVec2 operator +(QVec2 a, QVec2 b)
{ {
return new QuikVec2() return new QVec2()
{ {
X = a.X + b.X, X = a.X + b.X,
Y = a.Y + b.Y Y = a.Y + b.Y
}; };
} }
public static QuikVec2 operator -(QuikVec2 a) public static QVec2 operator -(QVec2 a)
{ {
return new QuikVec2() return new QVec2()
{ {
X = -a.X, X = -a.X,
Y = -a.Y Y = -a.Y
}; };
} }
public static QuikVec2 operator -(QuikVec2 a, QuikVec2 b) public static QVec2 operator -(QVec2 a, QVec2 b)
{ {
return new QuikVec2() return new QVec2()
{ {
X = a.X - b.X, X = a.X - b.X,
Y = a.Y - b.Y Y = a.Y - b.Y
}; };
} }
public static QuikVec2 operator *(float a, QuikVec2 b) public static QVec2 operator *(float a, QVec2 b)
{ {
return new QuikVec2() return new QVec2()
{ {
X = a * b.X, X = a * b.X,
Y = a * b.Y Y = a * b.Y
}; };
} }
public static QuikVec2 operator *(QuikVec2 a, float b) => b * a; public static QVec2 operator *(QVec2 a, float b) => b * a;
public static bool operator ==(QuikVec2 a, QuikVec2 b) => a.X == b.X && a.Y == b.Y; public static bool operator ==(QVec2 a, QVec2 b) => a.X == b.X && a.Y == b.Y;
public static bool operator !=(QuikVec2 a, QuikVec2 b) => a.X != b.X || a.Y != b.Y; public static bool operator !=(QVec2 a, QVec2 b) => a.X != b.X || a.Y != b.Y;
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is QuikVec2) if (obj is QVec2)
{ {
return (QuikVec2) obj == this; return (QVec2) obj == this;
} }
else else
{ {
@ -83,7 +83,7 @@ namespace Quik
return 63671 * X.GetHashCode() ^ 81083 * Y.GetHashCode(); return 63671 * X.GetHashCode() ^ 81083 * Y.GetHashCode();
} }
public static float Dot(QuikVec2 a, QuikVec2 b) public static float Dot(QVec2 a, QVec2 b)
{ {
return a.X * b.X + a.Y * b.Y; return a.X * b.X + a.Y * b.Y;
} }
@ -93,7 +93,7 @@ namespace Quik
/// A RGBA color value. /// A RGBA color value.
/// </summary> /// </summary>
[DebuggerDisplay("({R}, {G}, {B}, {A})")] [DebuggerDisplay("({R}, {G}, {B}, {A})")]
public struct QuikColor public struct QColor
{ {
/// <summary> /// <summary>
/// Red channel. /// Red channel.
@ -112,7 +112,7 @@ namespace Quik
/// </summary> /// </summary>
public byte A; public byte A;
public QuikColor(byte r, byte g, byte b, byte a) public QColor(byte r, byte g, byte b, byte a)
{ {
R = r; R = r;
G = g; G = g;
@ -120,52 +120,52 @@ namespace Quik
A = a; A = a;
} }
public QuikColor(byte r, byte g, byte b) : this(r, g, b, 1) { } public QColor(byte r, byte g, byte b) : this(r, g, b, 1) { }
public QuikColor(uint hexCode) public QColor(uint hexCode)
{ {
R = (byte)((hexCode >> 24) & 0xFF); R = (byte)((hexCode >> 24) & 0xFF);
G = (byte)((hexCode >> 16) & 0xFF); G = (byte)((hexCode >> 16) & 0xFF);
B = (byte)((hexCode >> 8 ) & 0xFF); B = (byte)((hexCode >> 8 ) & 0xFF);
A = (byte)((hexCode >> 0 ) & 0xFF); A = (byte)((hexCode >> 0 ) & 0xFF);
} }
public QuikColor(int hexCode) : this((uint)hexCode) { } public QColor(int hexCode) : this((uint)hexCode) { }
public static readonly QuikColor Black = new QuikColor(0, 0, 0, 255); public static readonly QColor Black = new QColor(0, 0, 0, 255);
public static readonly QuikColor Red = new QuikColor(255, 0, 0, 255); public static readonly QColor Red = new QColor(255, 0, 0, 255);
public static readonly QuikColor Green = new QuikColor(0, 255, 0, 255); public static readonly QColor Green = new QColor(0, 255, 0, 255);
public static readonly QuikColor Blue = new QuikColor(0, 0, 255, 255); public static readonly QColor Blue = new QColor(0, 0, 255, 255);
public static readonly QuikColor Yellow = new QuikColor(255, 255, 0, 255); public static readonly QColor Yellow = new QColor(255, 255, 0, 255);
public static readonly QuikColor Cyan = new QuikColor(0, 255, 255, 255); public static readonly QColor Cyan = new QColor(0, 255, 255, 255);
public static readonly QuikColor Magenta = new QuikColor(255, 0, 255, 255); public static readonly QColor Magenta = new QColor(255, 0, 255, 255);
public static readonly QuikColor White = new QuikColor(255, 255, 255, 255); public static readonly QColor White = new QColor(255, 255, 255, 255);
} }
/// <summary> /// <summary>
/// A bezier curve segment. /// A bezier curve segment.
/// </summary> /// </summary>
[DebuggerDisplay("{Start} -- {ControlA} -- {ControlB} -- {End}")] [DebuggerDisplay("{Start} -- {ControlA} -- {ControlB} -- {End}")]
public struct QuikBezier public struct QBezier
{ {
/// <summary> /// <summary>
/// Segment start point. /// Segment start point.
/// </summary> /// </summary>
public QuikVec2 Start; public QVec2 Start;
/// <summary> /// <summary>
/// Start point control point. /// Start point control point.
/// </summary> /// </summary>
public QuikVec2 ControlA; public QVec2 ControlA;
/// <summary> /// <summary>
/// End point control point. /// End point control point.
/// </summary> /// </summary>
public QuikVec2 ControlB; public QVec2 ControlB;
/// <summary> /// <summary>
/// Segment end point. /// Segment end point.
/// </summary> /// </summary>
public QuikVec2 End; public QVec2 End;
/// <summary> /// <summary>
/// An approximation of the arc length of the bezier curve, for calculating rasterization resolution. /// An approximation of the arc length of the bezier curve, for calculating rasterization resolution.
@ -174,7 +174,7 @@ namespace Quik
0.5f * (End - Start).Magnitude + 0.5f * (End - Start).Magnitude +
0.5f * ((ControlA - Start).Magnitude + (ControlB - ControlA).Magnitude + (End - ControlB).Magnitude); 0.5f * ((ControlA - Start).Magnitude + (ControlB - ControlA).Magnitude + (End - ControlB).Magnitude);
public QuikBezier(QuikVec2 start, QuikVec2 controlA, QuikVec2 controlB, QuikVec2 end) public QBezier(QVec2 start, QVec2 controlA, QVec2 controlB, QVec2 end)
{ {
Start = start; Start = start;
ControlA = controlA; ControlA = controlA;
@ -182,7 +182,7 @@ namespace Quik
End = end; End = end;
} }
public QuikBezier( public QBezier(
float startX, float startX,
float startY, float startY,
float controlAx, float controlAx,
@ -192,10 +192,10 @@ namespace Quik
float endX, float endX,
float endY) float endY)
: this( : this(
new QuikVec2(startX, startY), new QVec2(startX, startY),
new QuikVec2(controlAx, controlAy), new QVec2(controlAx, controlAy),
new QuikVec2(controlBx, controlBy), new QVec2(controlBx, controlBy),
new QuikVec2(endX, endY)) new QVec2(endX, endY))
{ {
} }
@ -204,7 +204,7 @@ namespace Quik
/// </summary> /// </summary>
/// <param name="t">Control parameter (between 0 and 1)</param> /// <param name="t">Control parameter (between 0 and 1)</param>
/// <returns>The point on the curve.</returns> /// <returns>The point on the curve.</returns>
public QuikVec2 GetBezierPoint(float t) public QVec2 GetBezierPoint(float t)
{ {
float T = 1 - t; float T = 1 - t;
return return
@ -219,7 +219,7 @@ namespace Quik
/// </summary> /// </summary>
/// <param name="t">Control parameter (between 0 and 1)</param> /// <param name="t">Control parameter (between 0 and 1)</param>
/// <returns>The tangent curve.</returns> /// <returns>The tangent curve.</returns>
public QuikVec2 GetBezierTangent(float t) public QVec2 GetBezierTangent(float t)
{ {
float T = 1 - t; float T = 1 - t;
return return
@ -230,10 +230,10 @@ namespace Quik
).Normalize(); ).Normalize();
} }
internal QuikVec2 GetBezierNormal(float t) internal QVec2 GetBezierNormal(float t)
{ {
QuikVec2 tangent = GetBezierTangent(t); QVec2 tangent = GetBezierTangent(t);
return new QuikVec2(-tangent.Y, tangent.X); return new QVec2(-tangent.Y, tangent.X);
} }
} }
@ -241,25 +241,25 @@ namespace Quik
/// A line segment. /// A line segment.
/// </summary> /// </summary>
[DebuggerDisplay("{Start} -- {End}")] [DebuggerDisplay("{Start} -- {End}")]
public struct QuikLine public struct QLine
{ {
/// <summary> /// <summary>
/// Start point. /// Start point.
/// </summary> /// </summary>
public QuikVec2 Start; public QVec2 Start;
/// <summary> /// <summary>
/// End point. /// End point.
/// </summary> /// </summary>
public QuikVec2 End; public QVec2 End;
public QuikLine(QuikVec2 start, QuikVec2 end) public QLine(QVec2 start, QVec2 end)
{ {
Start = start; Start = start;
End = end; End = end;
} }
public QuikLine(float startX, float startY, float endX, float endY) public QLine(float startX, float startY, float endX, float endY)
{ {
Start.X = startX; Start.X = startX;
Start.Y = startY; Start.Y = startY;
@ -267,12 +267,12 @@ namespace Quik
End.Y = endY; End.Y = endY;
} }
public QuikVec2 Normal() public QVec2 Normal()
{ {
QuikVec2 tangent = Tangent(); QVec2 tangent = Tangent();
return new QuikVec2(-tangent.Y, tangent.X); return new QVec2(-tangent.Y, tangent.X);
} }
public QuikVec2 Tangent() public QVec2 Tangent()
{ {
return (End - Start).Normalize(); return (End - Start).Normalize();
} }
@ -282,17 +282,17 @@ namespace Quik
/// A rectangle. /// A rectangle.
/// </summary> /// </summary>
[DebuggerDisplay("({Right}, {Top}, {Left}, {Bottom})")] [DebuggerDisplay("({Right}, {Top}, {Left}, {Bottom})")]
public struct QuikRectangle public struct QRectangle
{ {
/// <summary> /// <summary>
/// Rectangle maximum point. /// Rectangle maximum point.
/// </summary> /// </summary>
public QuikVec2 Max; public QVec2 Max;
/// <summary> /// <summary>
/// Rectangle minimum point. /// Rectangle minimum point.
/// </summary> /// </summary>
public QuikVec2 Min; public QVec2 Min;
public float Left public float Left
{ {
@ -318,39 +318,39 @@ namespace Quik
set => Min.Y = value; set => Min.Y = value;
} }
public QuikVec2 Size public QVec2 Size
{ {
get => Max - Min; get => Max - Min;
set => Max = Min + value; set => Max = Min + value;
} }
public QuikRectangle(QuikVec2 max, QuikVec2 min) public QRectangle(QVec2 max, QVec2 min)
{ {
Max = max; Max = max;
Min = min; Min = min;
} }
public QuikRectangle(float r, float t, float l, float b) public QRectangle(float r, float t, float l, float b)
{ {
Max = new QuikVec2() {X = r, Y = t}; Max = new QVec2() {X = r, Y = t};
Min = new QuikVec2() {X = l, Y = b}; Min = new QVec2() {X = l, Y = b};
} }
public bool Contains(QuikVec2 point) public bool Contains(QVec2 point)
{ {
return return
point.X > Left && point.X < Right && point.X > Left && point.X < Right &&
point.Y > Bottom && point.Y < Top; point.Y > Bottom && point.Y < Top;
} }
internal void Translate(in QuikVec2 offset) internal void Translate(in QVec2 offset)
{ {
Min += offset; Min += offset;
Max += offset; Max += offset;
} }
public static QuikRectangle Intersect(in QuikRectangle a, in QuikRectangle b) => public static QRectangle Intersect(in QRectangle a, in QRectangle b) =>
new QuikRectangle( new QRectangle(
Math.Min(a.Right, b.Right), Math.Min(a.Right, b.Right),
Math.Min(a.Top, b.Top), Math.Min(a.Top, b.Top),
Math.Max(a.Left, b.Left), Math.Max(a.Left, b.Left),
@ -363,43 +363,43 @@ namespace Quik
/// </summary> /// </summary>
/// <remarks>It is undefined to have an ellipse with non-orthogonal axes.</remarks> /// <remarks>It is undefined to have an ellipse with non-orthogonal axes.</remarks>
[DebuggerDisplay("{Center} ellipse {AxisA}; {AxisB}")] [DebuggerDisplay("{Center} ellipse {AxisA}; {AxisB}")]
public struct QuikEllipse public struct QEllipse
{ {
/// <summary> /// <summary>
/// Ellipse center point. /// Ellipse center point.
/// </summary> /// </summary>
public QuikVec2 Center; public QVec2 Center;
/// <summary> /// <summary>
/// First ellipse axis. /// First ellipse axis.
/// </summary> /// </summary>
public QuikVec2 AxisA; public QVec2 AxisA;
/// <summary> /// <summary>
/// Second ellipse axis. /// Second ellipse axis.
/// </summary> /// </summary>
public QuikVec2 AxisB; public QVec2 AxisB;
} }
/// <summary> /// <summary>
/// A triangle. /// A triangle.
/// </summary> /// </summary>
[DebuggerDisplay("{A} -- {B} -- {C}")] [DebuggerDisplay("{A} -- {B} -- {C}")]
public struct QuikTriangle public struct QTriangle
{ {
/// <summary> /// <summary>
/// First vertex. /// First vertex.
/// </summary> /// </summary>
public QuikVec2 A; public QVec2 A;
/// <summary> /// <summary>
/// Second vertex. /// Second vertex.
/// </summary> /// </summary>
public QuikVec2 B; public QVec2 B;
/// <summary> /// <summary>
/// Third vertex. /// Third vertex.
/// </summary> /// </summary>
public QuikVec2 C; public QVec2 C;
} }
} }

@ -54,9 +54,9 @@ namespace Quik
{ {
public abstract object this[string key] { get; set; } public abstract object this[string key] { get; set; }
public QuikColor? Color public QColor? Color
{ {
get => (QuikColor?)this["color"]; get => (QColor?)this["color"];
set => this["color"] = value; set => this["color"] = value;
} }
@ -120,9 +120,9 @@ namespace Quik
set => this["stroke-width"] = value; set => this["stroke-width"] = value;
} }
public QuikColor? StrokeColor public QColor? StrokeColor
{ {
get => (QuikColor?)this["stroke-color"]; get => (QColor?)this["stroke-color"];
set => this["stroke-color"] = value; set => this["stroke-color"] = value;
} }
@ -236,7 +236,7 @@ namespace Quik
/// <summary> /// <summary>
/// Stroke color. /// Stroke color.
/// </summary> /// </summary>
public QuikColor Color { get; set; } public QColor Color { get; set; }
/// <summary> /// <summary>
/// Stroke width. /// Stroke width.
@ -252,7 +252,7 @@ namespace Quik
{ {
} }
public QuikStrokeStyle(QuikColor color, float width /*, QuikStipplePattern pattern*/) public QuikStrokeStyle(QColor color, float width /*, QuikStipplePattern pattern*/)
{ {
Color = color; Color = color;
Width = width; Width = width;
@ -269,6 +269,6 @@ namespace Quik
/// </summary> /// </summary>
public class QuikFillStyle public class QuikFillStyle
{ {
public QuikColor Color { get; set; } public QColor Color { get; set; }
} }
} }

@ -13,35 +13,35 @@ namespace Quik.Typography
/// <summary> /// <summary>
/// Location of the glyph on the atlas. /// Location of the glyph on the atlas.
/// </summary> /// </summary>
public QuikRectangle Location { get; } public QRectangle Location { get; }
/// <summary> /// <summary>
/// Size of the glyph in units. /// Size of the glyph in units.
/// </summary> /// </summary>
public QuikVec2 Size { get; } public QVec2 Size { get; }
/// <summary> /// <summary>
/// Bearing vector for horizontal layout. /// Bearing vector for horizontal layout.
/// </summary> /// </summary>
public QuikVec2 HorizontalBearing { get; } public QVec2 HorizontalBearing { get; }
/// <summary> /// <summary>
/// Bearing vector for vertical layout. /// Bearing vector for vertical layout.
/// </summary> /// </summary>
public QuikVec2 VerticalBearing { get; } public QVec2 VerticalBearing { get; }
/// <summary> /// <summary>
/// Advance vector for vertical and horizontal layouts. /// Advance vector for vertical and horizontal layouts.
/// </summary> /// </summary>
public QuikVec2 Advance { get; } public QVec2 Advance { get; }
public QuikGlyph( public QuikGlyph(
int character, int character,
QuikRectangle location, QRectangle location,
QuikVec2 size, QVec2 size,
QuikVec2 horizontalBearing, QVec2 horizontalBearing,
QuikVec2 verticalBearing, QVec2 verticalBearing,
QuikVec2 advance) QVec2 advance)
{ {
Character = character; Character = character;
Location = location; Location = location;

@ -181,7 +181,7 @@ namespace Quik.Typography
int index = 0; int index = 0;
bool firstLine = true; bool firstLine = true;
QuikVec2 pen = new QuikVec2(0, -PreSpace); QVec2 pen = new QVec2(0, -PreSpace);
while (index < Blocks.Count) while (index < Blocks.Count)
{ {
@ -225,7 +225,7 @@ namespace Quik.Typography
pen.Y -= PostSpace; pen.Y -= PostSpace;
group.BoundingBox = new QuikRectangle(width, 0, 0, pen.Y); group.BoundingBox = new QRectangle(width, 0, 0, pen.Y);
group.Translate(-pen); group.Translate(-pen);
} }
@ -263,9 +263,9 @@ namespace Quik.Typography
TypesetGroup group, TypesetGroup group,
Queue<HorizontalTextBlock> line, Queue<HorizontalTextBlock> line,
float interblockWs, float interblockWs,
ref QuikVec2 pen) ref QVec2 pen)
{ {
QuikVec2 penpal = pen; QVec2 penpal = pen;
while (line.TryDequeue(out HorizontalTextBlock block)) while (line.TryDequeue(out HorizontalTextBlock block))
{ {
@ -285,7 +285,7 @@ namespace Quik.Typography
new TypesetCharacter( new TypesetCharacter(
chr, chr,
texture, texture,
new QuikRectangle( new QRectangle(
penpal.X + metrics.Advance.X, penpal.X + metrics.Advance.X,
penpal.Y + metrics.HorizontalBearing.Y, penpal.Y + metrics.HorizontalBearing.Y,
penpal.X + metrics.HorizontalBearing.X, penpal.X + metrics.HorizontalBearing.X,
@ -306,7 +306,7 @@ namespace Quik.Typography
new TypesetCharacter( new TypesetCharacter(
chr, chr,
texture, texture,
new QuikRectangle( new QRectangle(
penpal.X + metrics.Advance.X, penpal.X + metrics.Advance.X,
penpal.Y + metrics.HorizontalBearing.Y, penpal.Y + metrics.HorizontalBearing.Y,
penpal.X + metrics.HorizontalBearing.X, penpal.X + metrics.HorizontalBearing.X,
@ -353,14 +353,14 @@ namespace Quik.Typography
{ {
public int Character; public int Character;
public QuikTexture Texture; public QuikTexture Texture;
public QuikRectangle Position; public QRectangle Position;
public QuikRectangle UV; public QRectangle UV;
public TypesetCharacter( public TypesetCharacter(
int chr, int chr,
QuikTexture texture, QuikTexture texture,
in QuikRectangle position, in QRectangle position,
in QuikRectangle uv) in QRectangle uv)
{ {
Character = chr; Character = chr;
Texture = texture; Texture = texture;
@ -374,7 +374,7 @@ namespace Quik.Typography
private int _count = 0; private int _count = 0;
private TypesetCharacter[] _array = Array.Empty<TypesetCharacter>(); private TypesetCharacter[] _array = Array.Empty<TypesetCharacter>();
public QuikRectangle BoundingBox; public QRectangle BoundingBox;
public int Count => _count; public int Count => _count;
@ -395,7 +395,7 @@ namespace Quik.Typography
_count = 0; _count = 0;
} }
public void Translate(QuikVec2 offset) public void Translate(QVec2 offset)
{ {
BoundingBox.Translate(offset); BoundingBox.Translate(offset);

@ -12,7 +12,7 @@ namespace Quik.VertexGenerator
private readonly List<DrawCall> _drawCalls = new List<DrawCall>(); private readonly List<DrawCall> _drawCalls = new List<DrawCall>();
private int _start; private int _start;
private int _baseOffset; private int _baseOffset;
private QuikRectangle _bounds; private QRectangle _bounds;
private QuikTexture _texture; private QuikTexture _texture;
public int ZDepth { get; private set; } public int ZDepth { get; private set; }
@ -32,7 +32,7 @@ namespace Quik.VertexGenerator
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StartDrawCall(in QuikRectangle bounds, QuikTexture texture, int baseOffset) public void StartDrawCall(in QRectangle bounds, QuikTexture texture, int baseOffset)
{ {
_start = ElementCount; _start = ElementCount;
_texture = texture; _texture = texture;
@ -41,13 +41,13 @@ namespace Quik.VertexGenerator
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StartDrawCall(in QuikRectangle bounds) => StartDrawCall(bounds, null, _vertices.Count); public void StartDrawCall(in QRectangle bounds) => StartDrawCall(bounds, null, _vertices.Count);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StartDrawCall(in QuikRectangle bounds, int baseOffset) => StartDrawCall(bounds, null, baseOffset); public void StartDrawCall(in QRectangle bounds, int baseOffset) => StartDrawCall(bounds, null, baseOffset);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StartDrawCall(in QuikRectangle bounds, QuikTexture texture) => StartDrawCall(bounds, texture, _vertices.Count); public void StartDrawCall(in QRectangle bounds, QuikTexture texture) => StartDrawCall(bounds, texture, _vertices.Count);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddVertex(in QuikVertex vertex) public void AddVertex(in QuikVertex vertex)
@ -98,10 +98,10 @@ namespace Quik.VertexGenerator
{ {
public int Start { get; } public int Start { get; }
public int Count { get; } public int Count { get; }
public QuikRectangle Bounds { get; } public QRectangle Bounds { get; }
public QuikTexture Texture { get; } public QuikTexture Texture { get; }
public DrawCall(int start, int count, in QuikRectangle bounds, QuikTexture texture) public DrawCall(int start, int count, in QRectangle bounds, QuikTexture texture)
{ {
Start = start; Start = start;
Count = count; Count = count;

@ -11,17 +11,17 @@ namespace Quik.VertexGenerator
/// <summary> /// <summary>
/// Position value. /// Position value.
/// </summary> /// </summary>
public QuikVec2 Position; public QVec2 Position;
/// <summary> /// <summary>
/// Texture Coordinates. /// Texture Coordinates.
/// </summary> /// </summary>
public QuikVec2 TextureCoordinates; public QVec2 TextureCoordinates;
/// <summary> /// <summary>
/// Per vertex color value. /// Per vertex color value.
/// </summary> /// </summary>
public QuikColor Color; public QColor Color;
/// <summary> /// <summary>
/// Per vertex depth index value. /// Per vertex depth index value.
@ -29,9 +29,9 @@ namespace Quik.VertexGenerator
public int ZIndex; public int ZIndex;
public static int PositionOffset => 0; public static int PositionOffset => 0;
public static unsafe int TextureCoordinatesOffset => sizeof(QuikVec2); public static unsafe int TextureCoordinatesOffset => sizeof(QVec2);
public static unsafe int ColorOffset => 2 * sizeof(QuikVec2); public static unsafe int ColorOffset => 2 * sizeof(QVec2);
public static unsafe int ZIndexOffset => ColorOffset + sizeof(QuikColor); public static unsafe int ZIndexOffset => ColorOffset + sizeof(QColor);
public static unsafe int Stride => sizeof(QuikVertex); public static unsafe int Stride => sizeof(QuikVertex);
} }
} }

File diff suppressed because it is too large Load Diff

@ -16,12 +16,12 @@ namespace Quik.VertexGenerator
protected QuikVertex StrokeVertex => new QuikVertex() protected QuikVertex StrokeVertex => new QuikVertex()
{ {
ZIndex = Style.ZIndex ?? this.ZIndex, ZIndex = Style.ZIndex ?? this.ZIndex,
Color = Style.StrokeColor ?? QuikColor.Black, Color = Style.StrokeColor ?? QColor.Black,
}; };
protected QuikVertex FillVertex => new QuikVertex() protected QuikVertex FillVertex => new QuikVertex()
{ {
ZIndex = Style.ZIndex ?? this.ZIndex, ZIndex = Style.ZIndex ?? this.ZIndex,
Color = Style.Color ?? QuikColor.White, Color = Style.Color ?? QColor.White,
}; };
public override void Reset() public override void Reset()
@ -54,7 +54,7 @@ namespace Quik.VertexGenerator
return (int) Math.Ceiling(arc * radius * CurveGranularity); return (int) Math.Ceiling(arc * radius * CurveGranularity);
} }
private readonly List<QuikLine> LineList = new List<QuikLine>(); private readonly List<QLine> LineList = new List<QLine>();
private void LineProc(CommandQueue queue) private void LineProc(CommandQueue queue)
{ {
Frame frame = queue.Dequeue(); Frame frame = queue.Dequeue();
@ -67,12 +67,12 @@ namespace Quik.VertexGenerator
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
frame = queue.Dequeue(); frame = queue.Dequeue();
LineList.Add((QuikLine)frame); LineList.Add((QLine)frame);
} }
} }
else else
{ {
LineList.Add((QuikLine)frame); LineList.Add((QLine)frame);
} }
float width = Style.StrokeWidth ?? 1; float width = Style.StrokeWidth ?? 1;
@ -81,7 +81,7 @@ namespace Quik.VertexGenerator
LineInfo prevBase, nextBase = default; LineInfo prevBase, nextBase = default;
for (int i = 0; i < LineList.Count; i++) for (int i = 0; i < LineList.Count; i++)
{ {
QuikLine line = LineList[i]; QLine line = LineList[i];
// A line segment needs a start cap if it is the first segment in // A line segment needs a start cap if it is the first segment in
// the list, or the last end point is not the current start point. // the list, or the last end point is not the current start point.
bool isStart = (i == 0 || line.Start != LineList[i - 1].End); bool isStart = (i == 0 || line.Start != LineList[i - 1].End);
@ -112,11 +112,11 @@ namespace Quik.VertexGenerator
DrawQueue.EndDrawCall(); DrawQueue.EndDrawCall();
} }
private LineInfo GenerateLineSegment(in QuikLine line) private LineInfo GenerateLineSegment(in QLine line)
{ {
QuikVertex vertex = StrokeVertex; QuikVertex vertex = StrokeVertex;
QuikVertex a, b, c, d; QuikVertex a, b, c, d;
QuikVec2 normal = line.Normal(); QVec2 normal = line.Normal();
float width = Style.StrokeWidth ?? 1; float width = Style.StrokeWidth ?? 1;
a = b = c = d = vertex; a = b = c = d = vertex;
@ -136,20 +136,20 @@ namespace Quik.VertexGenerator
} }
private void GenerateJoint( private void GenerateJoint(
in QuikVec2 center, in QVec2 center,
in QuikVec2 prevNormal, in QVec2 prevNormal,
in QuikVec2 nextNormal, in QVec2 nextNormal,
in LineInfo prevInfo, in LineInfo prevInfo,
in LineInfo nextInfo) in LineInfo nextInfo)
{ {
// Figure out which side needs the joint. // Figure out which side needs the joint.
QuikVec2 meanNormal = 0.5f * (prevNormal + nextNormal); QVec2 meanNormal = 0.5f * (prevNormal + nextNormal);
QuikVec2 meanTangent = new QuikVec2(meanNormal.Y, -meanNormal.X); QVec2 meanTangent = new QVec2(meanNormal.Y, -meanNormal.X);
QuikVec2 positiveEdge = ((center + nextNormal) - (center + prevNormal)).Normalize(); QVec2 positiveEdge = ((center + nextNormal) - (center + prevNormal)).Normalize();
QuikVec2 negativeEdge = ((center - nextNormal) - (center - prevNormal)).Normalize(); QVec2 negativeEdge = ((center - nextNormal) - (center - prevNormal)).Normalize();
float positive, negative; float positive, negative;
positive = QuikVec2.Dot(meanTangent, positiveEdge); positive = QVec2.Dot(meanTangent, positiveEdge);
negative = QuikVec2.Dot(meanNormal, negativeEdge); negative = QVec2.Dot(meanNormal, negativeEdge);
if (positive == negative) if (positive == negative)
{ {
@ -161,7 +161,7 @@ namespace Quik.VertexGenerator
QuikVertex vertex = StrokeVertex; QuikVertex vertex = StrokeVertex;
float radius = Style.StrokeWidth/2 ?? 0.5f; float radius = Style.StrokeWidth/2 ?? 0.5f;
float arc = MathF.Acos(QuikVec2.Dot(prevNormal, nextNormal)); float arc = MathF.Acos(QVec2.Dot(prevNormal, nextNormal));
int resolution = GetRoundingResolution(radius, arc); int resolution = GetRoundingResolution(radius, arc);
bool isNegative = positive < negative; bool isNegative = positive < negative;
@ -187,10 +187,10 @@ namespace Quik.VertexGenerator
float cos = MathF.Cos(angle); float cos = MathF.Cos(angle);
float sin = MathF.Sin(angle); float sin = MathF.Sin(angle);
QuikVec2 displacement; QVec2 displacement;
if (isNegative) if (isNegative)
{ {
displacement = new QuikVec2() displacement = new QVec2()
{ {
X = -prevNormal.X * cos + prevNormal.Y * sin, X = -prevNormal.X * cos + prevNormal.Y * sin,
Y = -prevNormal.X * sin - prevNormal.Y * cos Y = -prevNormal.X * sin - prevNormal.Y * cos
@ -198,7 +198,7 @@ namespace Quik.VertexGenerator
} }
else else
{ {
displacement = new QuikVec2() displacement = new QVec2()
{ {
X = nextNormal.X * cos - nextNormal.Y * sin, X = nextNormal.X * cos - nextNormal.Y * sin,
Y = nextNormal.X * sin + nextNormal.Y * cos Y = nextNormal.X * sin + nextNormal.Y * cos
@ -222,8 +222,8 @@ namespace Quik.VertexGenerator
} }
private void GenerateCap( private void GenerateCap(
in QuikVec2 center, in QVec2 center,
in QuikVec2 normal, in QVec2 normal,
in LineInfo info, in LineInfo info,
bool endCap) bool endCap)
{ {
@ -250,10 +250,10 @@ namespace Quik.VertexGenerator
float cos = MathF.Cos(angle); float cos = MathF.Cos(angle);
float sin = MathF.Sin(angle); float sin = MathF.Sin(angle);
QuikVec2 displacement; QVec2 displacement;
if (endCap) if (endCap)
{ {
displacement = new QuikVec2() displacement = new QVec2()
{ {
X = normal.X * cos + normal.Y * sin, X = normal.X * cos + normal.Y * sin,
Y = -normal.X * sin + normal.Y * cos Y = -normal.X * sin + normal.Y * cos
@ -261,7 +261,7 @@ namespace Quik.VertexGenerator
} }
else else
{ {
displacement = new QuikVec2() displacement = new QVec2()
{ {
X = normal.X * cos - normal.Y * sin, X = normal.X * cos - normal.Y * sin,
Y = normal.X * sin + normal.Y * cos Y = normal.X * sin + normal.Y * cos
@ -279,7 +279,7 @@ namespace Quik.VertexGenerator
} }
} }
private readonly List<QuikBezier> BezierList = new List<QuikBezier>(); private readonly List<QBezier> BezierList = new List<QBezier>();
private void BezierProc(CommandQueue queue) private void BezierProc(CommandQueue queue)
{ {
Frame a = queue.Dequeue(); Frame a = queue.Dequeue();
@ -296,11 +296,11 @@ namespace Quik.VertexGenerator
b = queue.Dequeue(); b = queue.Dequeue();
BezierList.Add( BezierList.Add(
new QuikBezier( new QBezier(
new QuikVec2(a.GetF(0), a.GetF(1)), new QVec2(a.GetF(0), a.GetF(1)),
new QuikVec2(b.GetF(0), b.GetF(1)), new QVec2(b.GetF(0), b.GetF(1)),
new QuikVec2(b.GetF(2), b.GetF(3)), new QVec2(b.GetF(2), b.GetF(3)),
new QuikVec2(a.GetF(2), a.GetF(3)) new QVec2(a.GetF(2), a.GetF(3))
) )
); );
} }
@ -310,11 +310,11 @@ namespace Quik.VertexGenerator
b = queue.Dequeue(); b = queue.Dequeue();
BezierList.Add( BezierList.Add(
new QuikBezier( new QBezier(
new QuikVec2(a.GetF(0), a.GetF(1)), new QVec2(a.GetF(0), a.GetF(1)),
new QuikVec2(b.GetF(0), b.GetF(1)), new QVec2(b.GetF(0), b.GetF(1)),
new QuikVec2(b.GetF(2), b.GetF(3)), new QVec2(b.GetF(2), b.GetF(3)),
new QuikVec2(a.GetF(2), a.GetF(3)) new QVec2(a.GetF(2), a.GetF(3))
) )
); );
} }
@ -325,7 +325,7 @@ namespace Quik.VertexGenerator
LineInfo prevBase, nextBase = default; LineInfo prevBase, nextBase = default;
for (int i = 0; i < LineList.Count; i++) for (int i = 0; i < LineList.Count; i++)
{ {
QuikBezier bezier = BezierList[i]; QBezier bezier = BezierList[i];
// A line segment needs a start cap if it is the first segment in // A line segment needs a start cap if it is the first segment in
// the list, or the last end point is not the current start point. // the list, or the last end point is not the current start point.
bool isStart = (i == 0 || bezier.Start != BezierList[i - 1].End); bool isStart = (i == 0 || bezier.Start != BezierList[i - 1].End);
@ -356,12 +356,12 @@ namespace Quik.VertexGenerator
DrawQueue.EndDrawCall(); DrawQueue.EndDrawCall();
} }
private LineInfo GenerateBezierSegment(in QuikBezier bezier) private LineInfo GenerateBezierSegment(in QBezier bezier)
{ {
QuikVec2 startTangent = bezier.GetBezierTangent(0); QVec2 startTangent = bezier.GetBezierTangent(0);
QuikVec2 endTangent = bezier.GetBezierTangent(1); QVec2 endTangent = bezier.GetBezierTangent(1);
QuikVec2 startNormal = new QuikVec2(-startTangent.Y, startTangent.X).Normalize(); QVec2 startNormal = new QVec2(-startTangent.Y, startTangent.X).Normalize();
QuikVec2 endNormal = new QuikVec2(-endTangent.Y, endTangent.X).Normalize(); QVec2 endNormal = new QVec2(-endTangent.Y, endTangent.X).Normalize();
float width = Style.StrokeWidth ?? 1; float width = Style.StrokeWidth ?? 1;
float radius = 0.5f * width; float radius = 0.5f * width;
@ -380,9 +380,9 @@ namespace Quik.VertexGenerator
for (int i = 0; i < resolution; i++, index += 2) for (int i = 0; i < resolution; i++, index += 2)
{ {
float t = (i + 1.0f) / resolution; float t = (i + 1.0f) / resolution;
QuikVec2 at = bezier.GetBezierTangent(t).Normalize(); QVec2 at = bezier.GetBezierTangent(t).Normalize();
QuikVec2 a = bezier.GetBezierPoint(t); QVec2 a = bezier.GetBezierPoint(t);
QuikVec2 an = radius * new QuikVec2(-at.Y, at.X); QVec2 an = radius * new QVec2(-at.Y, at.X);
v.Position = a + an; v.Position = a + an;
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
@ -396,7 +396,7 @@ namespace Quik.VertexGenerator
return new LineInfo(vbase, 0, 1, index - 2, index - 1); return new LineInfo(vbase, 0, 1, index - 2, index - 1);
} }
private readonly List<QuikRectangle> RectangleList = new List<QuikRectangle>(); private readonly List<QRectangle> RectangleList = new List<QRectangle>();
private void RectangleProc(CommandQueue queue) private void RectangleProc(CommandQueue queue)
{ {
Frame frame = queue.Dequeue(); Frame frame = queue.Dequeue();
@ -407,12 +407,12 @@ namespace Quik.VertexGenerator
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
frame = queue.Dequeue(); frame = queue.Dequeue();
RectangleList.Add((QuikRectangle)frame); RectangleList.Add((QRectangle)frame);
} }
} }
else else
{ {
RectangleList.Add((QuikRectangle)frame); RectangleList.Add((QRectangle)frame);
} }
float stroke = Style.StrokeWidth ?? 1.0f; float stroke = Style.StrokeWidth ?? 1.0f;
@ -420,8 +420,8 @@ namespace Quik.VertexGenerator
DrawQueue.StartDrawCall(Viewport); DrawQueue.StartDrawCall(Viewport);
for (int i = 0; i < RectangleList.Count; i++) for (int i = 0; i < RectangleList.Count; i++)
{ {
QuikRectangle outer = RectangleList[i]; QRectangle outer = RectangleList[i];
QuikRectangle inner = new QuikRectangle( QRectangle inner = new QRectangle(
outer.Right - stroke, outer.Top - stroke, outer.Right - stroke, outer.Top - stroke,
outer.Left + stroke, outer.Bottom + stroke); outer.Left + stroke, outer.Bottom + stroke);
@ -445,7 +445,7 @@ namespace Quik.VertexGenerator
DrawQueue.EndDrawCall(); DrawQueue.EndDrawCall();
} }
private void GenerateRectangleBase(in QuikRectangle rectangle, float radius) private void GenerateRectangleBase(in QRectangle rectangle, float radius)
{ {
/* /*
+--j-------i--+ +--j-------i--+
@ -466,16 +466,16 @@ namespace Quik.VertexGenerator
// Draw center rectangle. // Draw center rectangle.
QuikVec2 aPos, bPos, cPos, dPos; QVec2 aPos, bPos, cPos, dPos;
QuikVertex v = FillVertex; QuikVertex v = FillVertex;
aPos = v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Bottom + radius); aPos = v.Position = new QVec2(rectangle.Left + radius, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
bPos = v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Bottom + radius); bPos = v.Position = new QVec2(rectangle.Right - radius, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
cPos = v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Top - radius); cPos = v.Position = new QVec2(rectangle.Right - radius, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
dPos = v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Top - radius); dPos = v.Position = new QVec2(rectangle.Left + radius, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(0); DrawQueue.AddElement(1); DrawQueue.AddElement(2); DrawQueue.AddElement(0); DrawQueue.AddElement(1); DrawQueue.AddElement(2);
@ -486,9 +486,9 @@ namespace Quik.VertexGenerator
// Draw south rectangle. // Draw south rectangle.
v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Bottom); v.Position = new QVec2(rectangle.Left + radius, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Bottom); v.Position = new QVec2(rectangle.Right - radius, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(4); DrawQueue.AddElement(5); DrawQueue.AddElement(1); DrawQueue.AddElement(4); DrawQueue.AddElement(5); DrawQueue.AddElement(1);
@ -496,9 +496,9 @@ namespace Quik.VertexGenerator
// Draw east rectangle. // Draw east rectangle.
v.Position = new QuikVec2(rectangle.Right, rectangle.Bottom + radius); v.Position = new QVec2(rectangle.Right, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right, rectangle.Top - radius); v.Position = new QVec2(rectangle.Right, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(1); DrawQueue.AddElement(6); DrawQueue.AddElement(7); DrawQueue.AddElement(1); DrawQueue.AddElement(6); DrawQueue.AddElement(7);
@ -506,9 +506,9 @@ namespace Quik.VertexGenerator
// Draw north rectangle. // Draw north rectangle.
v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Top); v.Position = new QVec2(rectangle.Right - radius, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Top); v.Position = new QVec2(rectangle.Left + radius, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(3); DrawQueue.AddElement(2); DrawQueue.AddElement(8); DrawQueue.AddElement(3); DrawQueue.AddElement(2); DrawQueue.AddElement(8);
@ -516,9 +516,9 @@ namespace Quik.VertexGenerator
// Draw west rectangle. // Draw west rectangle.
v.Position = new QuikVec2(rectangle.Left, rectangle.Top - radius); v.Position = new QVec2(rectangle.Left, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left, rectangle.Bottom + radius); v.Position = new QVec2(rectangle.Left, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(11); DrawQueue.AddElement(0); DrawQueue.AddElement(3); DrawQueue.AddElement(11); DrawQueue.AddElement(0); DrawQueue.AddElement(3);
@ -535,7 +535,7 @@ namespace Quik.VertexGenerator
float xoff = MathF.Cos(theta) * radius; float xoff = MathF.Cos(theta) * radius;
float yoff = MathF.Sin(theta) * radius; float yoff = MathF.Sin(theta) * radius;
v.Position = cPos + new QuikVec2(xoff, yoff); v.Position = cPos + new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(2); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++)); DrawQueue.AddElement(2); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++));
} }
@ -550,7 +550,7 @@ namespace Quik.VertexGenerator
float xoff = -MathF.Sin(theta) * radius; float xoff = -MathF.Sin(theta) * radius;
float yoff = MathF.Cos(theta) * radius; float yoff = MathF.Cos(theta) * radius;
v.Position = dPos + new QuikVec2(xoff, yoff); v.Position = dPos + new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(3); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++)); DrawQueue.AddElement(3); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++));
} }
@ -565,7 +565,7 @@ namespace Quik.VertexGenerator
float xoff = -MathF.Cos(theta) * radius; float xoff = -MathF.Cos(theta) * radius;
float yoff = -MathF.Sin(theta) * radius; float yoff = -MathF.Sin(theta) * radius;
v.Position = aPos + new QuikVec2(xoff, yoff); v.Position = aPos + new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(0); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++)); DrawQueue.AddElement(0); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++));
} }
@ -580,14 +580,14 @@ namespace Quik.VertexGenerator
float xoff = -MathF.Sin(theta) * radius; float xoff = -MathF.Sin(theta) * radius;
float yoff = MathF.Cos(theta) * radius; float yoff = MathF.Cos(theta) * radius;
v.Position = bPos + new QuikVec2(xoff, yoff); v.Position = bPos + new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(1); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++)); DrawQueue.AddElement(1); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++));
} }
DrawQueue.AddElement(1); DrawQueue.AddElement(previous); DrawQueue.AddElement(6); DrawQueue.AddElement(1); DrawQueue.AddElement(previous); DrawQueue.AddElement(6);
} }
private void GenerateRectangleStripStraight(in QuikRectangle rectangle) private void GenerateRectangleStripStraight(in QRectangle rectangle)
{ {
/* /*
h---------g h---------g
@ -609,22 +609,22 @@ namespace Quik.VertexGenerator
DrawQueue.RestoreOffset(); DrawQueue.RestoreOffset();
v.Position = new QuikVec2(rectangle.Left + stroke, rectangle.Bottom + stroke); v.Position = new QVec2(rectangle.Left + stroke, rectangle.Bottom + stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - stroke, rectangle.Bottom + stroke); v.Position = new QVec2(rectangle.Right - stroke, rectangle.Bottom + stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - stroke, rectangle.Top - stroke); v.Position = new QVec2(rectangle.Right - stroke, rectangle.Top - stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + stroke, rectangle.Top - stroke); v.Position = new QVec2(rectangle.Left + stroke, rectangle.Top - stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left, rectangle.Bottom); v.Position = new QVec2(rectangle.Left, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right, rectangle.Bottom); v.Position = new QVec2(rectangle.Right, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right, rectangle.Top); v.Position = new QVec2(rectangle.Right, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left, rectangle.Top); v.Position = new QVec2(rectangle.Left, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(4); DrawQueue.AddElement(5); DrawQueue.AddElement(1); // SSW DrawQueue.AddElement(4); DrawQueue.AddElement(5); DrawQueue.AddElement(1); // SSW
@ -637,7 +637,7 @@ namespace Quik.VertexGenerator
DrawQueue.AddElement(4); DrawQueue.AddElement(3); DrawQueue.AddElement(7); // SWW DrawQueue.AddElement(4); DrawQueue.AddElement(3); DrawQueue.AddElement(7); // SWW
} }
private void GenerateRectangleStripNarrow(in QuikRectangle rectangle, float radius) private void GenerateRectangleStripNarrow(in QRectangle rectangle, float radius)
{ {
/* /*
v-j---i-u v-j---i-u
@ -662,73 +662,73 @@ namespace Quik.VertexGenerator
20: 0 1 2 3 20: 0 1 2 3
*/ */
QuikVertex v = StrokeVertex; QuikVertex v = StrokeVertex;
QuikVec2 nPos, qPos, tPos, wPos; QVec2 nPos, qPos, tPos, wPos;
float stroke = Style.StrokeWidth ?? 1.0f; float stroke = Style.StrokeWidth ?? 1.0f;
DrawQueue.RestoreOffset(); DrawQueue.RestoreOffset();
// a-b-c-d // a-b-c-d
v.Position = new QuikVec2(rectangle.Left + stroke, rectangle.Bottom + stroke); v.Position = new QVec2(rectangle.Left + stroke, rectangle.Bottom + stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - stroke, rectangle.Bottom + stroke); v.Position = new QVec2(rectangle.Right - stroke, rectangle.Bottom + stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - stroke, rectangle.Top - stroke); v.Position = new QVec2(rectangle.Right - stroke, rectangle.Top - stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + stroke, rectangle.Top - stroke); v.Position = new QVec2(rectangle.Left + stroke, rectangle.Top - stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
// ef-gh-ij-kl // ef-gh-ij-kl
v.Position = new QuikVec2(rectangle.Left + stroke, rectangle.Bottom); v.Position = new QVec2(rectangle.Left + stroke, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + stroke, rectangle.Bottom); v.Position = new QVec2(rectangle.Left + stroke, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right, rectangle.Bottom + stroke); v.Position = new QVec2(rectangle.Right, rectangle.Bottom + stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right, rectangle.Top - stroke); v.Position = new QVec2(rectangle.Right, rectangle.Top - stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - stroke, rectangle.Top); v.Position = new QVec2(rectangle.Right - stroke, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - stroke, rectangle.Top); v.Position = new QVec2(rectangle.Right - stroke, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left, rectangle.Top - stroke); v.Position = new QVec2(rectangle.Left, rectangle.Top - stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left, rectangle.Bottom + stroke); v.Position = new QVec2(rectangle.Left, rectangle.Bottom + stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
// mno // mno
v.Position = new QuikVec2(rectangle.Left, rectangle.Bottom + radius); v.Position = new QVec2(rectangle.Left, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
nPos = v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Bottom + radius); nPos = v.Position = new QVec2(rectangle.Left + radius, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Bottom); v.Position = new QVec2(rectangle.Left + radius, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
// pqr // pqr
v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Bottom); v.Position = new QVec2(rectangle.Right - radius, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
qPos = v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Bottom + radius); qPos = v.Position = new QVec2(rectangle.Right - radius, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right, rectangle.Bottom + radius); v.Position = new QVec2(rectangle.Right, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
// stu // stu
v.Position = new QuikVec2(rectangle.Right, rectangle.Top - radius); v.Position = new QVec2(rectangle.Right, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
tPos = v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Top - radius); tPos = v.Position = new QVec2(rectangle.Right - radius, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Top); v.Position = new QVec2(rectangle.Right - radius, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
// vwx // vwx
v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Top); v.Position = new QVec2(rectangle.Left + radius, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
wPos = v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Top - radius); wPos = v.Position = new QVec2(rectangle.Left + radius, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left, rectangle.Top - radius); v.Position = new QVec2(rectangle.Left, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
// E // E
@ -779,7 +779,7 @@ namespace Quik.VertexGenerator
float xoff = MathF.Cos(theta) * radius; float xoff = MathF.Cos(theta) * radius;
float yoff = MathF.Sin(theta) * radius; float yoff = MathF.Sin(theta) * radius;
v.Position = tPos + new QuikVec2(xoff, yoff); v.Position = tPos + new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(19); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++)); DrawQueue.AddElement(19); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++));
} }
@ -794,7 +794,7 @@ namespace Quik.VertexGenerator
float xoff = -MathF.Sin(theta) * radius; float xoff = -MathF.Sin(theta) * radius;
float yoff = MathF.Cos(theta) * radius; float yoff = MathF.Cos(theta) * radius;
v.Position = wPos + new QuikVec2(xoff, yoff); v.Position = wPos + new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(22); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++)); DrawQueue.AddElement(22); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++));
} }
@ -809,7 +809,7 @@ namespace Quik.VertexGenerator
float xoff = -MathF.Cos(theta) * radius; float xoff = -MathF.Cos(theta) * radius;
float yoff = -MathF.Sin(theta) * radius; float yoff = -MathF.Sin(theta) * radius;
v.Position = nPos + new QuikVec2(xoff, yoff); v.Position = nPos + new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(23); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++)); DrawQueue.AddElement(23); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++));
} }
@ -824,14 +824,14 @@ namespace Quik.VertexGenerator
float xoff = -MathF.Sin(theta) * radius; float xoff = -MathF.Sin(theta) * radius;
float yoff = MathF.Cos(theta) * radius; float yoff = MathF.Cos(theta) * radius;
v.Position = qPos + new QuikVec2(xoff, yoff); v.Position = qPos + new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(16); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++)); DrawQueue.AddElement(16); DrawQueue.AddElement(previous); DrawQueue.AddElement((previous = current++));
} }
DrawQueue.AddElement(16); DrawQueue.AddElement(previous); DrawQueue.AddElement(17); DrawQueue.AddElement(16); DrawQueue.AddElement(previous); DrawQueue.AddElement(17);
} }
private void GenerateRectangleStripWide(in QuikRectangle rectangle, float radius) private void GenerateRectangleStripWide(in QRectangle rectangle, float radius)
{ {
/* /*
l---k l---k
@ -855,40 +855,40 @@ namespace Quik.VertexGenerator
float innerRadius = radius - stroke; float innerRadius = radius - stroke;
DrawQueue.RestoreOffset(); DrawQueue.RestoreOffset();
v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Bottom); v.Position = new QVec2(rectangle.Left + radius, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Bottom); v.Position = new QVec2(rectangle.Right - radius, rectangle.Bottom);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Bottom + stroke); v.Position = new QVec2(rectangle.Right - radius, rectangle.Bottom + stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Bottom + stroke); v.Position = new QVec2(rectangle.Left + radius, rectangle.Bottom + stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - stroke, rectangle.Bottom + radius); v.Position = new QVec2(rectangle.Right - stroke, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right, rectangle.Top - radius); v.Position = new QVec2(rectangle.Right, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right, rectangle.Top - radius); v.Position = new QVec2(rectangle.Right, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - stroke, rectangle.Bottom + radius); v.Position = new QVec2(rectangle.Right - stroke, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Top - stroke); v.Position = new QVec2(rectangle.Left + radius, rectangle.Top - stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Top - stroke); v.Position = new QVec2(rectangle.Right - radius, rectangle.Top - stroke);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Right - radius, rectangle.Top); v.Position = new QVec2(rectangle.Right - radius, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + radius, rectangle.Top); v.Position = new QVec2(rectangle.Left + radius, rectangle.Top);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left, rectangle.Bottom + radius); v.Position = new QVec2(rectangle.Left, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + stroke, rectangle.Top - radius); v.Position = new QVec2(rectangle.Left + stroke, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left + stroke, rectangle.Top - radius); v.Position = new QVec2(rectangle.Left + stroke, rectangle.Top - radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = new QuikVec2(rectangle.Left, rectangle.Bottom + radius); v.Position = new QVec2(rectangle.Left, rectangle.Bottom + radius);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
// S // S
@ -908,7 +908,7 @@ namespace Quik.VertexGenerator
int resolution = GetRoundingResolution(radius, 0.5f * MathF.PI); int resolution = GetRoundingResolution(radius, 0.5f * MathF.PI);
int current = 16; int current = 16;
QuikVec2 center = new QuikVec2(rectangle.Right - radius, rectangle.Top - radius); QVec2 center = new QVec2(rectangle.Right - radius, rectangle.Top - radius);
int s1 = 7, s2 = 6; int s1 = 7, s2 = 6;
for (int i = 0; i < resolution - 1; i++) for (int i = 0; i < resolution - 1; i++)
{ {
@ -916,9 +916,9 @@ namespace Quik.VertexGenerator
float xoff = MathF.Cos(theta); float xoff = MathF.Cos(theta);
float yoff = MathF.Sin(theta); float yoff = MathF.Sin(theta);
v.Position = center + radius * new QuikVec2(xoff, yoff); v.Position = center + radius * new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = center + innerRadius * new QuikVec2(xoff, yoff); v.Position = center + innerRadius * new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(current + 0); DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(current + 0);
@ -931,7 +931,7 @@ namespace Quik.VertexGenerator
DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(9); DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(9);
// Draw NW arc // Draw NW arc
center = new QuikVec2(rectangle.Left + radius, rectangle.Top - radius); center = new QVec2(rectangle.Left + radius, rectangle.Top - radius);
s1 = 8; s2 = 11; s1 = 8; s2 = 11;
for (int i = 0; i < resolution - 1; i++) for (int i = 0; i < resolution - 1; i++)
{ {
@ -939,9 +939,9 @@ namespace Quik.VertexGenerator
float xoff = -MathF.Sin(theta); float xoff = -MathF.Sin(theta);
float yoff = MathF.Cos(theta); float yoff = MathF.Cos(theta);
v.Position = center + radius * new QuikVec2(xoff, yoff); v.Position = center + radius * new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = center + innerRadius * new QuikVec2(xoff, yoff); v.Position = center + innerRadius * new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(current + 0); DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(current + 0);
@ -954,7 +954,7 @@ namespace Quik.VertexGenerator
DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(14); DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(14);
// Draw SW arc // Draw SW arc
center = new QuikVec2(rectangle.Left + radius, rectangle.Bottom + radius); center = new QVec2(rectangle.Left + radius, rectangle.Bottom + radius);
s1 = 13; s2 = 12; s1 = 13; s2 = 12;
for (int i = 0; i < resolution - 1; i++) for (int i = 0; i < resolution - 1; i++)
{ {
@ -962,9 +962,9 @@ namespace Quik.VertexGenerator
float xoff = -MathF.Cos(theta); float xoff = -MathF.Cos(theta);
float yoff = -MathF.Sin(theta); float yoff = -MathF.Sin(theta);
v.Position = center + radius * new QuikVec2(xoff, yoff); v.Position = center + radius * new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = center + innerRadius * new QuikVec2(xoff, yoff); v.Position = center + innerRadius * new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(current + 0); DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(current + 0);
@ -977,7 +977,7 @@ namespace Quik.VertexGenerator
DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(3); DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(3);
// Draw SW arc // Draw SW arc
center = new QuikVec2(rectangle.Right - radius, rectangle.Bottom + radius); center = new QVec2(rectangle.Right - radius, rectangle.Bottom + radius);
s1 = 2; s2 = 1; s1 = 2; s2 = 1;
for (int i = 0; i < resolution - 1; i++) for (int i = 0; i < resolution - 1; i++)
{ {
@ -985,9 +985,9 @@ namespace Quik.VertexGenerator
float xoff = MathF.Sin(theta); float xoff = MathF.Sin(theta);
float yoff = -MathF.Cos(theta); float yoff = -MathF.Cos(theta);
v.Position = center + radius * new QuikVec2(xoff, yoff); v.Position = center + radius * new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
v.Position = center + innerRadius * new QuikVec2(xoff, yoff); v.Position = center + innerRadius * new QVec2(xoff, yoff);
DrawQueue.AddVertex(v); DrawQueue.AddVertex(v);
DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(current + 0); DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(current + 0);

@ -15,6 +15,7 @@ using Quik.Controls;
using Quik.OpenGL; using Quik.OpenGL;
using GL = Quik.OpenGL.GL; using GL = Quik.OpenGL.GL;
using static Quik.OpenGL.GLEnum; using static Quik.OpenGL.GLEnum;
using Quik.CommandMachine;
namespace QuikTestApplication namespace QuikTestApplication
{ {
@ -62,17 +63,21 @@ void main()
GL.LoadBindings(new GLFWBindingsContext().GetProcAddress); GL.LoadBindings(new GLFWBindingsContext().GetProcAddress);
FreeTypeFontManager fontManager = new FreeTypeFontManager(); FreeTypeFontManager fontManager = new FreeTypeFontManager();
QuikContext context = new QuikContext(new OpenGLTextureManager(), fontManager); QuikContext context = new QuikContext(new OpenGLTextureManager(), fontManager);
QuikVertexGenerator gen = new QuikVertexGenerator(context);
VertexGeneratorEngine engine = new VertexGeneratorEngine();
CommandQueue cmdQueue = new CommandQueue();
GL30Driver gldriver;
RootControl root = new RootControl(context); RootControl root = new RootControl(context);
Button button = new Button() Button button = new Button()
{ {
Bounds = new QuikRectangle(120, 60, 20, 20), Bounds = new QRectangle(120, 60, 20, 20),
Text = "button", Text = "button",
Padding = 8, Padding = 8,
NormalStroke = new QuikStrokeStyle(new QuikColor(0xccccccff), 4f), NormalStroke = new QuikStrokeStyle(new QColor(0xccccccff), 4f),
HoverStroke = new QuikStrokeStyle(new QuikColor(0x1010ccff), 4f), HoverStroke = new QuikStrokeStyle(new QColor(0x1010ccff), 4f),
ActiveStroke = new QuikStrokeStyle(new QuikColor(0x999999ff), 4f), ActiveStroke = new QuikStrokeStyle(new QColor(0x999999ff), 4f),
}; };
button.Clicked += (sender, args) => { button.Clicked += (sender, args) => {
if (!args.Buttons.HasFlag(Quik.MouseButton.Primary)) if (!args.Buttons.HasFlag(Quik.MouseButton.Primary))
@ -98,109 +103,7 @@ void main()
GL.Enable(GL_MULTISAMPLE); GL.Enable(GL_MULTISAMPLE);
int sp; gldriver = new GL30Driver();
{
int vs, fs;
sp = GL.CreateProgram();
vs = GL.CreateShader(GL_VERTEX_SHADER);
fs = GL.CreateShader(GL_FRAGMENT_SHADER);
GL.ShaderSource(vs, vertex);
GL.CompileShader(vs);
GL.ShaderSource(fs, fragment);
GL.CompileShader(fs);
GL.AttachShader(sp, vs);
GL.AttachShader(sp, fs);
GL.LinkProgram(sp);
GL.UseProgram(sp);
}
new GL30Driver();
int vbo, ebo, vao;
vbo = GL.GenBuffer();
ebo = GL.GenBuffer();
vao = GL.GenVertexArray();
GL.BindVertexArray(vao);
GL.BindBuffer(GL_ARRAY_BUFFER, vbo);
GL.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
int loc;
GL.VertexAttribPointer(
loc = GL.GetAttribLocation(sp, "position"),
2,
GL_FLOAT,
false,
QuikVertex.Stride,
QuikVertex.PositionOffset);
GL.EnableVertexAttribArray(loc);
GL.VertexAttribPointer(
loc = GL.GetAttribLocation(sp, "texcoord"),
2,
GL_FLOAT,
false,
QuikVertex.Stride,
QuikVertex.TextureCoordinatesOffset);
GL.EnableVertexAttribArray(loc);
GL.VertexAttribPointer(
loc = GL.GetAttribLocation(sp, "color"),
4,
GL_UNSIGNED_BYTE,
true,
QuikVertex.Stride,
QuikVertex.ColorOffset);
GL.EnableVertexAttribArray(loc);
loc = GL.GetUniformLocation(sp, "matrix");
int offsetLoc = GL.GetUniformLocation(sp, "texture0offset");
QuikStrokeStyle strokeBorder = new QuikStrokeStyle()
{
Color = new QuikColor(0xaaaaaaff),
Width = 8
};
QuikStrokeStyle strokeNoBorder = new QuikStrokeStyle()
{
Color = new QuikColor(0xaaaaaaff),
Width = 0
};
QuikFillStyle fill = new QuikFillStyle()
{
Color = new QuikColor(0xeeeeeeff)
};
QuikFillStyle magenta = new QuikFillStyle
{
Color = new QuikColor(0xff00ffff)
};
int whiteTexture = GL.GenTexture();
uint[] whitePixel = {0xFFFFFFFF};
GL.BindTexture(GL_TEXTURE_2D, whiteTexture);
GL.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, whitePixel);
GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GL.TexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
context.DefaultFont = context.FontManager.GetFont(new QuikFontStyle("Arial", 16, QuikFontType.Normal));
const string testString =
"The quick brown fox jumps over the lazy dog. " +
"Sphinx of black quartz judge my vow. " +
"Have some japanese for fun: これが読めるかな?";
var para = new HorizontalParagraph();
para.ConsumeText(context.DefaultFont, testString);
var typeset = new TypesetGroup();
para.Typeset(typeset, 200);
window.Context.SwapInterval = 0; window.Context.SwapInterval = 0;
Stopwatch stopwatch = Stopwatch.StartNew(); Stopwatch stopwatch = Stopwatch.StartNew();
@ -215,7 +118,7 @@ void main()
if (window.IsFocused) if (window.IsFocused)
{ {
var mouseState = window.MouseState; var mouseState = window.MouseState;
QuikVec2 postion = new QuikVec2(mouseState.Position.X, window.ClientSize.Y - mouseState.Position.Y) * (dpi/72f); QVec2 postion = new QVec2(mouseState.Position.X, window.ClientSize.Y - mouseState.Position.Y) * (dpi/72f);
Quik.MouseButton buttons = Quik.MouseButton buttons =
(mouseState.IsButtonDown(OpenTK.Windowing.GraphicsLibraryFramework.MouseButton.Button1) ? Quik.MouseButton.Primary : 0) | (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.Button2) ? Quik.MouseButton.Secondary : 0) |
@ -224,107 +127,24 @@ void main()
root.NotifyMouse(new Quik.MouseState(postion, buttons)); root.NotifyMouse(new Quik.MouseState(postion, buttons));
} }
root.Bounds = new QuikRectangle( root.Bounds = new QRectangle(
window.ClientSize.X, window.ClientSize.X,
window.ClientSize.Y, window.ClientSize.Y,
0, 0,
0); 0);
root.NotifyUpdate(); root.NotifyUpdate();
GL.Viewport(0, 0, window.Size.X, window.Size.Y); cmdQueue.Clear();
root.NotifyPaint(cmdQueue);
engine.Reset();
engine.ProcessCommands(root.Bounds, cmdQueue);
DrawQueue drawQueue = engine.DrawQueue;
GL.ClearColor(1,1,1,1);
GL.Clear(GL_COLOR_BUFFER_BIT); GL.Clear(GL_COLOR_BUFFER_BIT);
GL.Enable(GL_BLEND); gldriver.Draw(drawQueue);
GL.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Matrix4 matrix = Matrix4.CreateOrthographicOffCenter(
0,
(float)window.Size.X*dpi/72f,
0,
(float)window.Size.Y*dpi/72f,
1,
-1);
GL.UniformMatrix4(loc, false, ref matrix.Row0.X);
context.Draw.Commands.Enqueue(
new QuikCommandRectangle(new QuikRectangle(120, 60, 20, 20))
{
CornerRadius = 0,
FillStyle = fill,
StrokeStyle = strokeNoBorder
});
context.Draw.Commands.Enqueue(
new QuikCommandRectangle(new QuikRectangle(240, 60, 140, 20))
{
CornerRadius = 4,
FillStyle = fill,
StrokeStyle = strokeNoBorder
});
context.Draw.Commands.Enqueue(
new QuikCommandRectangle(new QuikRectangle(360, 60, 260, 20))
{
CornerRadius = 15,
FillStyle = fill,
StrokeStyle = strokeNoBorder
});
context.Draw.Commands.Enqueue(
new QuikCommandRectangle(new QuikRectangle(120, 120, 20, 80))
{
CornerRadius = 0,
FillStyle = fill,
StrokeStyle = strokeBorder
});
context.Draw.Commands.Enqueue(
new QuikCommandRectangle(new QuikRectangle(240, 120, 140, 80))
{
CornerRadius = 4,
FillStyle = fill,
StrokeStyle = strokeBorder
});
context.Draw.Commands.Enqueue(
new QuikCommandRectangle(new QuikRectangle(360, 120, 260, 80))
{
CornerRadius = 15,
FillStyle = fill,
StrokeStyle = strokeBorder
});
// context.Draw.PutText("これが読めるかな?", new QuikVec2(25,30));
root.NotifyPaint(context.Draw);
context.Draw.Commands.Enqueue(new QuikCommandEmitText(typeset, new QuikVec2(200, 200)));
QuikCommand command;
while (context.Draw.Commands.TryDequeue(out command))
{
gen.ConsumeCommand(command);
}
GL.BufferData(GL_ARRAY_BUFFER, gen.VertexCount * QuikVertex.Stride, gen.VertexBuffer, GL_STREAM_DRAW);
GL.BufferData(GL_ELEMENT_ARRAY_BUFFER, gen.ElementCount * 2, gen.ElementBuffer, GL_STREAM_DRAW);
GL.Enable(GL_BLEND);
GL.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
foreach (QuikDrawCall call in gen.DrawCalls)
{
GL.BindTexture(
GL_TEXTURE_2D,
call.Texture == null ? whiteTexture : (call.Texture as OpenGLTexture).TextureId);
if (call.Texture != null)
GL.Uniform2(offsetLoc, 0.5f / call.Texture.Width, 0.5f / call.Texture.Height);
GL.DrawElements(GL_TRIANGLES, call.Count, GL_UNSIGNED_SHORT, call.Offset);
}
GL.Disable(GL_BLEND);
int callCount = gen.DrawCalls.Count;
gen.Clear();
System.Threading.Thread.Sleep(1);
window.Context.SwapBuffers(); window.Context.SwapBuffers();
frames++; frames++;
@ -334,7 +154,7 @@ void main()
Console.WriteLine("Frames: {0}", frames*(ms - lastMs)/1000); Console.WriteLine("Frames: {0}", frames*(ms - lastMs)/1000);
frames = 0; frames = 0;
lastMs = ms; lastMs = ms;
Console.WriteLine("Vertex Usage: {0} ; Element Usage: {1} Calls: {2}", gen.VertexUsage, gen.ElementUsage, callCount); Console.WriteLine("Vertex Usage: {0} ; Element Usage: {1} Calls: {2}", drawQueue.VertexCount, drawQueue.ElementCount, drawQueue.DrawCallCount);
} }
} }
} }

@ -18,7 +18,7 @@ namespace QuikTestApplication
private static Dictionary<int, QuikGlyph> _glyphs = new Dictionary<int, QuikGlyph>(); private static Dictionary<int, QuikGlyph> _glyphs = new Dictionary<int, QuikGlyph>();
public static byte[] TextureData { get; private set; } = Array.Empty<byte>(); public static byte[] TextureData { get; private set; } = Array.Empty<byte>();
public static QuikVec2 TextureSize { get; private set; } public static QVec2 TextureSize { get; private set; }
public QuikTexture Texture { get; } public QuikTexture Texture { get; }
@ -55,7 +55,7 @@ namespace QuikTestApplication
_style = new QuikFontStyle(family, fontSize, style); _style = new QuikFontStyle(family, fontSize, style);
QuikVec2 atlasSize = default; QVec2 atlasSize = default;
atlasSize.X = float.Parse(document.DocumentElement.Attributes["width"].Value); atlasSize.X = float.Parse(document.DocumentElement.Attributes["width"].Value);
atlasSize.Y = float.Parse(document.DocumentElement.Attributes["height"].Value); atlasSize.Y = float.Parse(document.DocumentElement.Attributes["height"].Value);
@ -63,18 +63,18 @@ namespace QuikTestApplication
foreach (XmlElement element in document.SelectNodes("/font/character")) foreach (XmlElement element in document.SelectNodes("/font/character"))
{ {
QuikRectangle UVs; QRectangle UVs;
QuikVec2 origin; QVec2 origin;
float advance; float advance;
int chr = element.Attributes["text"].Value[0]; int chr = element.Attributes["text"].Value[0];
QuikVec2 pos; QVec2 pos;
QuikVec2 size; QVec2 size;
pos.X = float.Parse(element.Attributes["x"].Value); pos.X = float.Parse(element.Attributes["x"].Value);
pos.Y = float.Parse(element.Attributes["y"].Value); pos.Y = float.Parse(element.Attributes["y"].Value);
size.X = float.Parse(element.Attributes["width"].Value); size.X = float.Parse(element.Attributes["width"].Value);
size.Y = float.Parse(element.Attributes["height"].Value); size.Y = float.Parse(element.Attributes["height"].Value);
UVs = new QuikRectangle( UVs = new QRectangle(
(pos.X + size.X)/atlasSize.X, (pos.X + size.X)/atlasSize.X,
pos.Y/atlasSize.Y, pos.Y/atlasSize.Y,
pos.X/atlasSize.X, pos.X/atlasSize.X,
@ -85,7 +85,7 @@ namespace QuikTestApplication
advance = float.Parse(element.Attributes["advance"].Value); advance = float.Parse(element.Attributes["advance"].Value);
QuikGlyph glyph = new QuikGlyph(chr, UVs, size, origin, default, new QuikVec2(advance, 0)); QuikGlyph glyph = new QuikGlyph(chr, UVs, size, origin, default, new QVec2(advance, 0));
_glyphs.Add(chr, glyph); _glyphs.Add(chr, glyph);
_characters.Add(chr); _characters.Add(chr);
} }