diff --git a/Dashboard/Geometry.cs b/Dashboard/Geometry.cs index 9595df9..821fb74 100644 --- a/Dashboard/Geometry.cs +++ b/Dashboard/Geometry.cs @@ -4,112 +4,6 @@ using System.Diagnostics; namespace Dashboard { - /// - /// A RGBA color value. - /// - [DebuggerDisplay("({R}, {G}, {B}, {A})")] - public struct QColor - { - /// - /// Red channel. - /// - public byte R; - /// - /// Green channel. - /// - public byte G; - /// - /// Blue channel. - /// - public byte B; - /// - /// Alpha channel. - /// - public byte A; - - public QColor(byte r, byte g, byte b, byte a) - { - R = r; - G = g; - B = b; - A = a; - } - - public QColor(byte r, byte g, byte b) : this(r, g, b, 1) { } - - public QColor(uint hexCode) - { - R = (byte)((hexCode >> 24) & 0xFF); - G = (byte)((hexCode >> 16) & 0xFF); - B = (byte)((hexCode >> 8 ) & 0xFF); - A = (byte)((hexCode >> 0 ) & 0xFF); - } - public QColor(int hexCode) : this((uint)hexCode) { } - - public static readonly QColor Black = new QColor(0, 0, 0, 255); - public static readonly QColor Red = new QColor(255, 0, 0, 255); - public static readonly QColor Green = new QColor(0, 255, 0, 255); - public static readonly QColor Blue = new QColor(0, 0, 255, 255); - public static readonly QColor Yellow = new QColor(255, 255, 0, 255); - public static readonly QColor Cyan = new QColor(0, 255, 255, 255); - public static readonly QColor Magenta = new QColor(255, 0, 255, 255); - public static readonly QColor White = new QColor(255, 255, 255, 255); - - public static explicit operator QColorF(QColor a) - { - return new QColorF(a.R/255.0f, a.G/255.0f, a.B/255.0f, a.A/255.0f); - } - } - - public struct QColorF - { - /// - /// Red channel. - /// - public float R; - /// - /// Green channel. - /// - public float G; - /// - /// Blue channel. - /// - public float B; - /// - /// Alpha channel. - /// - public float A; - - public QColorF(float r, float g, float b, float a) - { - R = r; G = g; B = b; A = a; - } - public QColorF(float r, float g, float b) : this(r, g, b, 1.0f) { } - public QColorF(uint hexCode) - { - R = ((hexCode >> 24) & 0xFF)/255.0f; - G = ((hexCode >> 16) & 0xFF)/255.0f; - B = ((hexCode >> 8 ) & 0xFF)/255.0f; - A = ((hexCode >> 0 ) & 0xFF)/255.0f; - } - public QColorF(int hexCode) : this((uint)hexCode) { } - - public static readonly QColorF Black = new QColorF(0, 0, 0, 1.0f); - public static readonly QColorF Red = new QColorF(1.0f, 0, 0, 1.0f); - public static readonly QColorF Green = new QColorF(0, 1, 0, 1); - public static readonly QColorF Blue = new QColorF(0, 0, 1, 1); - public static readonly QColorF Yellow = new QColorF(1, 1, 0, 1); - public static readonly QColorF Cyan = new QColorF(0, 1, 1, 1); - public static readonly QColorF Magenta = new QColorF(1, 0, 1, 1); - public static readonly QColorF White = new QColorF(1, 1, 1, 1); - - public static explicit operator QColor(QColorF a) - { - return new QColor((byte)(a.R * 255), (byte)(a.G * 255), (byte)(a.B * 255), (byte)(a.A * 255)); - } - } - - /// /// A bezier curve segment. /// diff --git a/Dashboard/ImmediateDraw/Frame.cs b/Dashboard/ImmediateDraw/Frame.cs index 800075f..ce736d0 100644 --- a/Dashboard/ImmediateDraw/Frame.cs +++ b/Dashboard/ImmediateDraw/Frame.cs @@ -299,12 +299,17 @@ namespace Dashboard.ImmediateDraw } } - public static explicit operator QColor(in Frame frame) + public static explicit operator Color4(in Frame frame) { - if (frame.Type != FrameType.IVec4) + switch (frame.Type) + { + case FrameType.IVec4: + return new Color4((byte)frame._i1, (byte)frame._i2, (byte)frame._i3, (byte)frame._i4); + case FrameType.Vec4: + return new Color4(frame._f1, frame._f2, frame._f3, frame._f4); + default: throw new InvalidCastException(); - - return new QColor((byte)frame._i1, (byte)frame._i2, (byte)frame._i3, (byte)frame._i4); + } } public static explicit operator QRectangle(in Frame frame) @@ -338,7 +343,7 @@ namespace Dashboard.ImmediateDraw 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(in Vector2 vector) => new Frame(vector.X, vector.Y); - public static implicit operator Frame(in QColor color) => new Frame(color.R, color.G, color.B, color.A); + public static implicit operator Frame(in Color4 color) => new Frame(color.R, color.G, color.B, color.A); 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 QLine line) => new Frame(line.Start.X, line.Start.Y, line.End.X, line.Start.Y); diff --git a/Dashboard/Media/Color/FormatConvert.cs b/Dashboard/Media/Color/FormatConvert.cs index 11a9ed2..f9c57cf 100644 --- a/Dashboard/Media/Color/FormatConvert.cs +++ b/Dashboard/Media/Color/FormatConvert.cs @@ -1,4 +1,5 @@ using System; +using OpenTK.Mathematics; namespace Dashboard.Media.Color { @@ -27,7 +28,7 @@ namespace Dashboard.Media.Color for (int i = 0; i < count; i++) { - QColorF color = io[i]; + Color4 color = io[i]; color.R *= color.A; color.G *= color.A; @@ -42,8 +43,8 @@ namespace Dashboard.Media.Color for (int i = 0; i < count; i++) { - QColor color = io[i]; - float a = color.A/255.0f; + Color4 color = io[i]; + float a = color.A; color.R = (byte)(color.R * a); color.G = (byte)(color.G * a); @@ -75,7 +76,7 @@ namespace Dashboard.Media.Color int count = dst.Width * dst.Height * dst.Depth; for (int i = 0; i < count; i++) { - dstIO[i] = (QColor)srcIO[i]; + dstIO[i] = srcIO[i]; } } else if (dst.Format.IsFloat() && src.Format.IsU8()) @@ -86,7 +87,7 @@ namespace Dashboard.Media.Color int count = dst.Width * dst.Height * dst.Depth; for (int i = 0; i < count; i++) { - dstIO[i] = (QColorF)srcIO[i]; + dstIO[i] = srcIO[i]; } } else if (dst.Format.IsFloat() && src.Format.IsFloat()) diff --git a/Dashboard/Media/Color/LockIO.cs b/Dashboard/Media/Color/LockIO.cs index 004b6a9..4c6fc9b 100644 --- a/Dashboard/Media/Color/LockIO.cs +++ b/Dashboard/Media/Color/LockIO.cs @@ -1,4 +1,5 @@ using System; +using OpenTK.Mathematics; namespace Dashboard.Media.Color { @@ -18,7 +19,7 @@ namespace Dashboard.Media.Color Lock = imageLock; } - public QColor this[int index] + public Color4 this[int index] { get { @@ -28,11 +29,11 @@ namespace Dashboard.Media.Color switch (Format) { default: - case QImageFormat.RedU8: return new QColor(ptr[0], 0, 0, 255); - case QImageFormat.AlphaU8: return new QColor(0, 0, 0, ptr[0]); - case QImageFormat.RaU8: return new QColor(ptr[0], 0, 0, ptr[1]); - case QImageFormat.RgbU8: return new QColor(ptr[0], ptr[1], ptr[2], 255); - case QImageFormat.RgbaU8: return new QColor(ptr[0], ptr[1], ptr[2], ptr[3]); + case QImageFormat.RedU8: return new Color4(ptr[0], 0, 0, 255); + case QImageFormat.AlphaU8: return new Color4(0, 0, 0, ptr[0]); + case QImageFormat.RaU8: return new Color4(ptr[0], 0, 0, ptr[1]); + case QImageFormat.RgbU8: return new Color4(ptr[0], ptr[1], ptr[2], 255); + case QImageFormat.RgbaU8: return new Color4(ptr[0], ptr[1], ptr[2], ptr[3]); } } @@ -45,30 +46,30 @@ namespace Dashboard.Media.Color { default: case QImageFormat.RedU8: - ptr[0] = value.R; + ptr[0] = (byte)(value.R * 255); break; case QImageFormat.AlphaU8: - ptr[0] = value.A; + ptr[0] = (byte)(value.A * 255); break; case QImageFormat.RaU8: - ptr[0] = value.R; - ptr[1] = value.A; + ptr[0] = (byte)(value.R * 255); + ptr[1] = (byte)(value.A * 255); break; case QImageFormat.RgbU8: - ptr[0] = value.R; - ptr[1] = value.G; - ptr[2] = value.B; + ptr[0] = (byte)(value.R * 255); + ptr[1] = (byte)(value.G * 255); + ptr[2] = (byte)(value.B * 255); break; case QImageFormat.RgbaU8: - ptr[0] = value.R; - ptr[1] = value.G; - ptr[2] = value.B; - ptr[3] = value.A; + ptr[0] = (byte)(value.R * 255); + ptr[1] = (byte)(value.G * 255); + ptr[2] = (byte)(value.B * 255); + ptr[3] = (byte)(value.A * 255); break; } } } - public QColor this[int x, int y, int z = 0] + public Color4 this[int x, int y, int z = 0] { get => this[x + y * Width + z * Width * Height]; set => this[x + y * Width + z * Width * Height] = value; @@ -91,7 +92,7 @@ namespace Dashboard.Media.Color Lock = imageLock; } - public QColorF this[int index] + public Color4 this[int index] { get { @@ -101,11 +102,11 @@ namespace Dashboard.Media.Color switch (Format) { default: - case QImageFormat.RedU8: return new QColorF(ptr[0], 0, 0, 255); - case QImageFormat.AlphaU8: return new QColorF(0, 0, 0, ptr[0]); - case QImageFormat.RaU8: return new QColorF(ptr[0], 0, 0, ptr[1]); - case QImageFormat.RgbU8: return new QColorF(ptr[0], ptr[1], ptr[2], 255); - case QImageFormat.RgbaU8: return new QColorF(ptr[0], ptr[1], ptr[2], ptr[3]); + case QImageFormat.RedU8: return new Color4(ptr[0], 0, 0, 1); + case QImageFormat.AlphaU8: return new Color4(0, 0, 0, ptr[0]); + case QImageFormat.RaU8: return new Color4(ptr[0], 0, 0, ptr[1]); + case QImageFormat.RgbU8: return new Color4(ptr[0], ptr[1], ptr[2], 1); + case QImageFormat.RgbaU8: return new Color4(ptr[0], ptr[1], ptr[2], ptr[3]); } } @@ -141,7 +142,7 @@ namespace Dashboard.Media.Color } } } - public QColorF this[int x, int y, int z = 0] + public Color4 this[int x, int y, int z = 0] { get => this[x + y * Width + z * Width * Height]; set => this[x + y * Width + z * Width * Height] = value; diff --git a/Dashboard/OpenGL/GL21Driver.cs b/Dashboard/OpenGL/GL21Driver.cs index 241e349..c264b85 100644 --- a/Dashboard/OpenGL/GL21Driver.cs +++ b/Dashboard/OpenGL/GL21Driver.cs @@ -296,7 +296,7 @@ namespace Dashboard.OpenGL GL.VertexAttribPointer(driver.fZIndex, 1, VertexAttribPointerType.UnsignedInt, false, DbVertex.Stride, DbVertex.ZIndexOffset); GL.VertexAttribPointer(driver.v2TexPos, 2, VertexAttribPointerType.Float, false, DbVertex.Stride, DbVertex.TextureCoordinatesOffset); GL.VertexAttribPointer(driver.fTexLayer, 1, VertexAttribPointerType.Float, false, DbVertex.Stride, DbVertex.TextureLayerOffset); - GL.VertexAttribPointer(driver.v4Color, 4, VertexAttribPointerType.UnsignedByte, true, DbVertex.Stride, DbVertex.ColorOffset); + GL.VertexAttribPointer(driver.v4Color, 4, VertexAttribPointerType.Float, true, DbVertex.Stride, DbVertex.ColorOffset); GL.EnableVertexAttribArray(driver.v2Position); GL.EnableVertexAttribArray(driver.fZIndex); GL.EnableVertexAttribArray(driver.v2TexPos); diff --git a/Dashboard/Style.cs b/Dashboard/Style.cs index bec86cc..a88fbc0 100644 --- a/Dashboard/Style.cs +++ b/Dashboard/Style.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Dashboard.Media; using Dashboard.Media.Font; +using OpenTK.Mathematics; namespace Dashboard { @@ -55,9 +56,9 @@ namespace Dashboard { public abstract object? this[string key] { get; set; } - public QColor? Color + public Color4? Color { - get => (QColor?)this["color"]; + get => (Color4?)this["color"]; set => this["color"] = value; } @@ -121,9 +122,9 @@ namespace Dashboard set => this["stroke-width"] = value; } - public QColor? StrokeColor + public OpenTK.Mathematics.Color4? StrokeColor { - get => (QColor?)this["stroke-color"]; + get => (Color4?)this["stroke-color"]; set => this["stroke-color"] = value; } @@ -237,7 +238,7 @@ namespace Dashboard /// /// Stroke color. /// - public QColor Color { get; set; } + public Color4 Color { get; set; } /// /// Stroke width. @@ -253,7 +254,7 @@ namespace Dashboard { } - public QuikStrokeStyle(QColor color, float width /*, QuikStipplePattern pattern*/) + public QuikStrokeStyle(Color4 color, float width /*, QuikStipplePattern pattern*/) { Color = color; Width = width; @@ -270,6 +271,6 @@ namespace Dashboard /// public class QuikFillStyle { - public QColor Color { get; set; } + public Color4 Color { get; set; } } } \ No newline at end of file diff --git a/Dashboard/VertexGenerator/DbVertex.cs b/Dashboard/VertexGenerator/DbVertex.cs index 727bf49..e646eda 100644 --- a/Dashboard/VertexGenerator/DbVertex.cs +++ b/Dashboard/VertexGenerator/DbVertex.cs @@ -22,7 +22,7 @@ namespace Dashboard.VertexGenerator /// /// Per vertex color value. /// - public QColor Color; + public Color4 Color; /// /// Per vertex depth index value. @@ -37,7 +37,7 @@ namespace Dashboard.VertexGenerator public static int PositionOffset => 0; public static unsafe int TextureCoordinatesOffset => sizeof(Vector2); public static unsafe int ColorOffset => 2 * sizeof(Vector2); - public static unsafe int ZIndexOffset => ColorOffset + sizeof(QColor); + public static unsafe int ZIndexOffset => ColorOffset + sizeof(Color4); public static unsafe int TextureLayerOffset => ZIndexOffset + sizeof(int); public static unsafe int Stride => sizeof(DbVertex); } diff --git a/Dashboard/VertexGenerator/VertexDrawingEngine.cs b/Dashboard/VertexGenerator/VertexDrawingEngine.cs index a0661fb..46eaa4a 100644 --- a/Dashboard/VertexGenerator/VertexDrawingEngine.cs +++ b/Dashboard/VertexGenerator/VertexDrawingEngine.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using Dashboard.ImmediateDraw; using Dashboard.Media; -using Dashboard.Typography; using OpenTK.Mathematics; namespace Dashboard.VertexGenerator @@ -22,18 +21,18 @@ namespace Dashboard.VertexGenerator protected DbVertex StrokeVertex => new DbVertex() { ZIndex = Style.ZIndex ?? this.ZIndex, - Color = Style.StrokeColor ?? QColor.Black, + Color = Style.StrokeColor ?? Color4.Black, }; protected DbVertex FillVertex => new DbVertex() { ZIndex = Style.ZIndex ?? this.ZIndex, - Color = Style.Color ?? QColor.White, + Color = Style.Color ?? Color4.White, }; protected DbVertex ImageVertex => new DbVertex() { ZIndex = Style.ZIndex ?? this.ZIndex, - Color = BlendTextures ? (Style.Color ?? QColor.White) : QColor.White, + Color = BlendTextures ? (Style.Color ?? Color4.White) : Color4.White, }; public override void Reset() @@ -42,7 +41,7 @@ namespace Dashboard.VertexGenerator DrawQueue.Clear(); } - protected override void ChildProcessCommand(Command name, ImmediateDraw.DrawQueue queue) + protected override void ChildProcessCommand(Command name, DrawQueue queue) { base.ChildProcessCommand(name, queue); @@ -68,7 +67,7 @@ namespace Dashboard.VertexGenerator } private readonly List LineList = new List(); - private void LineProc(ImmediateDraw.DrawQueue queue) + private void LineProc(DrawQueue queue) { Frame frame = queue.Dequeue(); @@ -410,7 +409,7 @@ namespace Dashboard.VertexGenerator } private readonly List RectangleList = new List(); - private void RectangleProc(ImmediateDraw.DrawQueue queue) + private void RectangleProc(DrawQueue queue) { Frame frame = queue.Dequeue(); RectangleList.Clear(); @@ -1013,7 +1012,7 @@ namespace Dashboard.VertexGenerator DrawQueue.AddElement(s1); DrawQueue.AddElement(s2); DrawQueue.AddElement(4); } - private void ImageProc(ImmediateDraw.DrawQueue queue) + private void ImageProc(DrawQueue queue) { Frame frame = queue.Dequeue(); ImageCommandFlags flags = (ImageCommandFlags)frame.I1; @@ -1030,7 +1029,7 @@ namespace Dashboard.VertexGenerator } } - private void Image2d(ImmediateDraw.DrawQueue queue, QImage image, int count, bool uv) + private void Image2d(DrawQueue queue, QImage image, int count, bool uv) { DrawQueue.StartDrawCall(Viewport, image);