Compare commits
No commits in common. "4dff6eba91464f60f1e574bddb6c707609df4cc0" and "51e9018a22f8003dd921e30d500d018558d95430" have entirely different histories.
4dff6eba91
...
51e9018a22
@ -65,7 +65,7 @@ namespace Quik.OpenTK
|
|||||||
_window.Focus();
|
_window.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Paint(CommandList queue)
|
public void Paint(CommandQueue queue)
|
||||||
{
|
{
|
||||||
QRectangle view = new QRectangle(Size, new QVec2(0, 0));
|
QRectangle view = new QRectangle(Size, new QVec2(0, 0));
|
||||||
|
|
||||||
|
@ -34,12 +34,10 @@ namespace Quik.CommandMachine
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessCommands(QRectangle bounds, CommandList queue)
|
public void ProcessCommands(QRectangle bounds, CommandQueue queue)
|
||||||
{
|
{
|
||||||
CommandEnumerator iterator = queue.GetEnumerator();
|
if (!queue.Peek().IsCommand)
|
||||||
|
throw new ArgumentException("The first element in the queue must be a command frame.");
|
||||||
if (!iterator.Peek().IsCommand)
|
|
||||||
throw new ArgumentException("The first element in the iterator must be a command frame.");
|
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
@ -47,7 +45,7 @@ namespace Quik.CommandMachine
|
|||||||
_viewportStack.Push(_viewport);
|
_viewportStack.Push(_viewport);
|
||||||
|
|
||||||
Frame frame;
|
Frame frame;
|
||||||
while (iterator.TryDequeue(out frame))
|
while (queue.TryDequeue(out frame))
|
||||||
{
|
{
|
||||||
Command cmd = (Command)frame;
|
Command cmd = (Command)frame;
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
@ -55,28 +53,28 @@ namespace Quik.CommandMachine
|
|||||||
default:
|
default:
|
||||||
if (cmd > Command.CustomCommandBase)
|
if (cmd > Command.CustomCommandBase)
|
||||||
{
|
{
|
||||||
_customCommands[cmd - Command.CustomCommandBase].Invoke(this, iterator);
|
_customCommands[cmd - Command.CustomCommandBase].Invoke(this, queue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ChildProcessCommand(cmd, iterator);
|
ChildProcessCommand(cmd, queue);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Command.ConditionalBegin: ConditionalHandler(iterator); break;
|
case Command.ConditionalBegin: ConditionalHandler(queue); break;
|
||||||
case Command.ConditionalEnd: /* nop */ break;
|
case Command.ConditionalEnd: /* nop */ break;
|
||||||
|
|
||||||
case Command.Invoke:
|
case Command.Invoke:
|
||||||
iterator.Dequeue().As<QuikCommandHandler>().Invoke(this, iterator);
|
queue.Dequeue().As<QuikCommandHandler>().Invoke(this, queue);
|
||||||
break;
|
break;
|
||||||
case Command.PushViewport:
|
case Command.PushViewport:
|
||||||
_viewportStack.Push(_viewport);
|
_viewportStack.Push(_viewport);
|
||||||
break;
|
break;
|
||||||
case Command.IntersectViewport:
|
case Command.IntersectViewport:
|
||||||
_viewport = QRectangle.Intersect((QRectangle)iterator.Dequeue(), _viewport);
|
_viewport = QRectangle.Intersect((QRectangle)queue.Dequeue(), _viewport);
|
||||||
break;
|
break;
|
||||||
case Command.StoreViewport:
|
case Command.StoreViewport:
|
||||||
_viewport = (QRectangle)iterator.Dequeue();
|
_viewport = (QRectangle)queue.Dequeue();
|
||||||
break;
|
break;
|
||||||
case Command.PopViewport:
|
case Command.PopViewport:
|
||||||
_viewport = _viewportStack.TryPop(out QRectangle viewport) ? viewport : bounds;
|
_viewport = _viewportStack.TryPop(out QRectangle viewport) ? viewport : bounds;
|
||||||
@ -88,10 +86,10 @@ namespace Quik.CommandMachine
|
|||||||
_zIndex++;
|
_zIndex++;
|
||||||
break;
|
break;
|
||||||
case Command.AddZ:
|
case Command.AddZ:
|
||||||
_zIndex += (int)iterator.Dequeue();
|
_zIndex += (int)queue.Dequeue();
|
||||||
break;
|
break;
|
||||||
case Command.StoreZ:
|
case Command.StoreZ:
|
||||||
_zIndex = (int)iterator.Dequeue();
|
_zIndex = (int)queue.Dequeue();
|
||||||
break;
|
break;
|
||||||
case Command.DecrementZ:
|
case Command.DecrementZ:
|
||||||
_zIndex--;
|
_zIndex--;
|
||||||
@ -103,7 +101,7 @@ namespace Quik.CommandMachine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ChildProcessCommand(Command name, CommandEnumerator queue)
|
protected virtual void ChildProcessCommand(Command name, CommandQueue queue)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,16 +110,16 @@ namespace Quik.CommandMachine
|
|||||||
_zIndex = 0;
|
_zIndex = 0;
|
||||||
_zStack.Clear();
|
_zStack.Clear();
|
||||||
|
|
||||||
_viewport = new QRectangle(float.MaxValue, float.MinValue, float.MinValue, float.MaxValue);
|
_viewport = new QRectangle(float.MaxValue, float.MaxValue, float.MinValue, float.MinValue);
|
||||||
_viewportStack.Clear();
|
_viewportStack.Clear();
|
||||||
|
|
||||||
_matrixStack.Clear();
|
_matrixStack.Clear();
|
||||||
_matrixStack.Push(QMat4.Identity);
|
_matrixStack.Push(QMat4.Identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConditionalHandler(CommandEnumerator iterator)
|
private void ConditionalHandler(CommandQueue queue)
|
||||||
{
|
{
|
||||||
Frame frame = iterator.Dequeue();
|
Frame frame = queue.Dequeue();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
frame.IsInteger && (int)frame != 0 ||
|
frame.IsInteger && (int)frame != 0 ||
|
||||||
@ -133,11 +131,11 @@ namespace Quik.CommandMachine
|
|||||||
|
|
||||||
// Skip this branch.
|
// Skip this branch.
|
||||||
int depth = 1;
|
int depth = 1;
|
||||||
while (iterator.TryPeek(out frame))
|
while (queue.TryPeek(out frame))
|
||||||
{
|
{
|
||||||
if (!frame.IsCommand)
|
if (!frame.IsCommand)
|
||||||
{
|
{
|
||||||
iterator.Dequeue();
|
queue.Dequeue();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,13 +149,13 @@ namespace Quik.CommandMachine
|
|||||||
// Decrement condional depth, exit if zero.
|
// Decrement condional depth, exit if zero.
|
||||||
if (--depth == 0)
|
if (--depth == 0)
|
||||||
{
|
{
|
||||||
iterator.Dequeue();
|
queue.Dequeue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator.Dequeue();
|
queue.Dequeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,5 @@ namespace Quik.CommandMachine
|
|||||||
/// A delegate for a QUIK command.
|
/// A delegate for a QUIK command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stack">The current stack.</param>
|
/// <param name="stack">The current stack.</param>
|
||||||
public delegate void QuikCommandHandler(CommandEngine state, CommandEnumerator queue);
|
public delegate void QuikCommandHandler(CommandEngine state, CommandQueue queue);
|
||||||
}
|
}
|
@ -1,25 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Reflection.Emit;
|
|
||||||
|
|
||||||
namespace Quik.CommandMachine
|
namespace Quik.CommandMachine
|
||||||
{
|
{
|
||||||
public class CommandList : IEnumerable<Frame>
|
public class CommandQueue : Queue<Frame>
|
||||||
{
|
{
|
||||||
private readonly List<Frame> _frames = new List<Frame>();
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
_frames.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Enqueue(in Frame frame)
|
|
||||||
{
|
|
||||||
_frames.Add(frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Invoke(QuikCommandHandler handler)
|
public void Invoke(QuikCommandHandler handler)
|
||||||
{
|
{
|
||||||
Enqueue(Command.Invoke);
|
Enqueue(Command.Invoke);
|
||||||
@ -258,84 +243,5 @@ namespace Quik.CommandMachine
|
|||||||
Enqueue(uvs[i]);
|
Enqueue(uvs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Splice(CommandList queue)
|
|
||||||
{
|
|
||||||
foreach (Frame frame in queue)
|
|
||||||
{
|
|
||||||
Enqueue(frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandEnumerator GetEnumerator() => new CommandEnumerator(_frames);
|
|
||||||
IEnumerator<Frame> IEnumerable<Frame>.GetEnumerator() => GetEnumerator();
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CommandEnumerator : IEnumerator<Frame>
|
|
||||||
{
|
|
||||||
private readonly IReadOnlyList<Frame> _frames;
|
|
||||||
private int _current;
|
|
||||||
|
|
||||||
public Frame Current => _frames[_current];
|
|
||||||
|
|
||||||
object IEnumerator.Current => Current;
|
|
||||||
|
|
||||||
public CommandEnumerator(IReadOnlyList<Frame> frames)
|
|
||||||
{
|
|
||||||
_current = -1;
|
|
||||||
_frames = frames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryDequeue([NotNullWhen(true)] out Frame frame)
|
|
||||||
{
|
|
||||||
if (MoveNext())
|
|
||||||
{
|
|
||||||
frame = Current;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
frame = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Frame Dequeue() => TryDequeue(out Frame frame) ? frame : throw new Exception("No more frames left.");
|
|
||||||
|
|
||||||
public bool TryPeek([NotNullWhen(true)] out Frame frame)
|
|
||||||
{
|
|
||||||
if (_current + 1 < _frames.Count)
|
|
||||||
{
|
|
||||||
frame = _frames[_current + 1];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
frame = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Frame Peek() => TryPeek(out Frame frame) ? frame : throw new Exception("No more frames left.");
|
|
||||||
|
|
||||||
public bool MoveNext()
|
|
||||||
{
|
|
||||||
if (_current + 1 < _frames.Count)
|
|
||||||
{
|
|
||||||
_current++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
_current = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -44,20 +44,20 @@ namespace Quik.Controls
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void PaintBegin(CommandList cmd)
|
protected virtual void PaintBegin(CommandQueue cmd)
|
||||||
{
|
{
|
||||||
cmd.PushViewport();
|
cmd.PushViewport();
|
||||||
cmd.StoreViewport(AbsoluteBounds);
|
cmd.StoreViewport(AbsoluteBounds);
|
||||||
cmd.PushZ();
|
cmd.PushZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void PaintEnd(CommandList cmd)
|
protected virtual void PaintEnd(CommandQueue cmd)
|
||||||
{
|
{
|
||||||
cmd.PopZ();
|
cmd.PopZ();
|
||||||
cmd.PopViewport();
|
cmd.PopViewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Paint(CommandList cmd)
|
public void Paint(CommandQueue cmd)
|
||||||
{
|
{
|
||||||
PaintBegin(cmd);
|
PaintBegin(cmd);
|
||||||
PaintEnd(cmd);
|
PaintEnd(cmd);
|
||||||
|
@ -44,6 +44,6 @@ namespace Quik.PAL
|
|||||||
/// Paint the given command queue onto the port.
|
/// Paint the given command queue onto the port.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="queue">The command queue to paint.</param>
|
/// <param name="queue">The command queue to paint.</param>
|
||||||
void Paint(CommandList queue);
|
void Paint(CommandQueue queue);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,7 +50,7 @@ namespace Quik
|
|||||||
public void Run(View mainView)
|
public void Run(View mainView)
|
||||||
{
|
{
|
||||||
IQuikPort port = Platform.CreatePort();
|
IQuikPort port = Platform.CreatePort();
|
||||||
CommandList cmd = new CommandList();
|
CommandQueue cmd = new CommandQueue();
|
||||||
|
|
||||||
MainView = mainView;
|
MainView = mainView;
|
||||||
|
|
||||||
@ -61,7 +61,6 @@ namespace Quik
|
|||||||
Platform.ProcessEvents(false);
|
Platform.ProcessEvents(false);
|
||||||
if (port.IsValid)
|
if (port.IsValid)
|
||||||
{
|
{
|
||||||
cmd.Clear();
|
|
||||||
MainView.Paint(cmd);
|
MainView.Paint(cmd);
|
||||||
port.Paint(cmd);
|
port.Paint(cmd);
|
||||||
}
|
}
|
||||||
|
@ -87,11 +87,6 @@ namespace Quik
|
|||||||
{
|
{
|
||||||
return a.X * b.X + a.Y * b.Y;
|
return a.X * b.X + a.Y * b.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return $"({X}; {Y})";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -340,16 +335,16 @@ namespace Quik
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A rectangle.
|
/// A rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DebuggerDisplay("({Left}, {Top}, {Right}, {Bottom})")]
|
[DebuggerDisplay("({Right}, {Top}, {Left}, {Bottom})")]
|
||||||
public struct QRectangle
|
public struct QRectangle
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Position maximum point.
|
/// Rectangle maximum point.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public QVec2 Max;
|
public QVec2 Max;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Position minimum point.
|
/// Rectangle minimum point.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public QVec2 Min;
|
public QVec2 Min;
|
||||||
|
|
||||||
@ -367,14 +362,14 @@ namespace Quik
|
|||||||
|
|
||||||
public float Top
|
public float Top
|
||||||
{
|
{
|
||||||
get => Min.Y;
|
get => Max.Y;
|
||||||
set => Min.Y = value;
|
set => Max.Y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Bottom
|
public float Bottom
|
||||||
{
|
{
|
||||||
get => Max.Y;
|
get => Min.Y;
|
||||||
set => Max.Y = value;
|
set => Min.Y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QVec2 Size
|
public QVec2 Size
|
||||||
@ -389,10 +384,10 @@ namespace Quik
|
|||||||
Min = min;
|
Min = min;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QRectangle(float r, float b, float l, float t)
|
public QRectangle(float r, float t, float l, float b)
|
||||||
{
|
{
|
||||||
Max = new QVec2() {X = r, Y = b};
|
Max = new QVec2() {X = r, Y = t};
|
||||||
Min = new QVec2() {X = l, Y = t};
|
Min = new QVec2() {X = l, Y = b};
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains(QVec2 point)
|
public bool Contains(QVec2 point)
|
||||||
@ -410,11 +405,11 @@ namespace Quik
|
|||||||
|
|
||||||
public static QRectangle Intersect(in QRectangle a, in QRectangle b) =>
|
public static QRectangle Intersect(in QRectangle a, in QRectangle b) =>
|
||||||
new QRectangle(
|
new QRectangle(
|
||||||
Math.Max(a.Right, b.Right),
|
Math.Min(a.Right, b.Right),
|
||||||
|
Math.Min(a.Top, b.Top),
|
||||||
|
Math.Max(a.Left, b.Left),
|
||||||
Math.Max(a.Bottom, b.Bottom)
|
Math.Max(a.Bottom, b.Bottom)
|
||||||
,
|
);
|
||||||
Math.Min(a.Left, b.Left),
|
|
||||||
Math.Min(a.Top, b.Top));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -498,19 +493,19 @@ namespace Quik
|
|||||||
public static void Orthographic(out QMat4 mat, QRectangle bounds, float near = 1, float far = -1)
|
public static void Orthographic(out QMat4 mat, QRectangle bounds, float near = 1, float far = -1)
|
||||||
{
|
{
|
||||||
float a, b, c;
|
float a, b, c;
|
||||||
mat = Identity;
|
mat = default;
|
||||||
|
|
||||||
a = 1.0f/(bounds.Right - bounds.Left);
|
a = 1.0f/(bounds.Right - bounds.Left);
|
||||||
b = 1.0f/(bounds.Top - bounds.Bottom);
|
b = 1.0f/(bounds.Top - bounds.Bottom);
|
||||||
c = 1.0f/(far - near);
|
c = 1.0f/(near - far);
|
||||||
|
|
||||||
mat.M11 = 2 * a;
|
mat.M11 = 2 * a;
|
||||||
mat.M22 = 2 * b;
|
mat.M22 = 2 * b;
|
||||||
mat.M33 = -2 * c;
|
mat.M33 = 2 * c;
|
||||||
|
|
||||||
mat.M14 = -a * (bounds.Left + bounds.Right);
|
mat.M41 = -a * (bounds.Left + bounds.Right);
|
||||||
mat.M24 = -b * (bounds.Top + bounds.Bottom);
|
mat.M42 = -b * (bounds.Top + bounds.Bottom);
|
||||||
mat.M34 = -c * (far + near);
|
mat.M43 = -c * (near + far);
|
||||||
mat.M44 = 1.0f;
|
mat.M44 = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ namespace Quik.VertexGenerator
|
|||||||
DrawQueue.Clear();
|
DrawQueue.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ChildProcessCommand(Command name, CommandEnumerator queue)
|
protected override void ChildProcessCommand(Command name, CommandQueue queue)
|
||||||
{
|
{
|
||||||
base.ChildProcessCommand(name, queue);
|
base.ChildProcessCommand(name, queue);
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ namespace Quik.VertexGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly List<QLine> LineList = new List<QLine>();
|
private readonly List<QLine> LineList = new List<QLine>();
|
||||||
private void LineProc(CommandEnumerator queue)
|
private void LineProc(CommandQueue queue)
|
||||||
{
|
{
|
||||||
Frame frame = queue.Dequeue();
|
Frame frame = queue.Dequeue();
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ namespace Quik.VertexGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly List<QBezier> BezierList = new List<QBezier>();
|
private readonly List<QBezier> BezierList = new List<QBezier>();
|
||||||
private void BezierProc(CommandEnumerator queue)
|
private void BezierProc(CommandQueue queue)
|
||||||
{
|
{
|
||||||
Frame a = queue.Dequeue();
|
Frame a = queue.Dequeue();
|
||||||
Frame b;
|
Frame b;
|
||||||
@ -397,7 +397,7 @@ namespace Quik.VertexGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly List<QRectangle> RectangleList = new List<QRectangle>();
|
private readonly List<QRectangle> RectangleList = new List<QRectangle>();
|
||||||
private void RectangleProc(CommandEnumerator queue)
|
private void RectangleProc(CommandQueue queue)
|
||||||
{
|
{
|
||||||
Frame frame = queue.Dequeue();
|
Frame frame = queue.Dequeue();
|
||||||
RectangleList.Clear();
|
RectangleList.Clear();
|
||||||
@ -422,8 +422,8 @@ namespace Quik.VertexGenerator
|
|||||||
{
|
{
|
||||||
QRectangle outer = RectangleList[i];
|
QRectangle outer = RectangleList[i];
|
||||||
QRectangle inner = new QRectangle(
|
QRectangle inner = new QRectangle(
|
||||||
outer.Right - stroke, outer.Bottom + stroke,
|
outer.Right - stroke, outer.Top - stroke,
|
||||||
outer.Left + stroke, outer.Top - stroke);
|
outer.Left + stroke, outer.Bottom + stroke);
|
||||||
|
|
||||||
GenerateRectangleBase(inner, Math.Max(radius - stroke, 0.0f));
|
GenerateRectangleBase(inner, Math.Max(radius - stroke, 0.0f));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user