From 7d5c5f822bc33e32cedabc17074a6424f6e8aa59 Mon Sep 17 00:00:00 2001 From: dnesov Date: Fri, 16 Jun 2023 00:03:45 +0200 Subject: [PATCH] Add Color record struct, small refactor, create a DaggerFramework.SceneGraph namespace. --- Source/Color.cs | 110 ++++++++++++++++++ Source/Entities/Drawable2d.cs | 15 --- Source/Entities/Entity2d.cs | 10 -- Source/Entities/IDrawable.cs | 9 -- Source/Rendering/GlRenderer.cs | 2 +- Source/Rendering/RaylibRenderer.cs | 26 ++--- Source/Rendering/Renderer.cs | 1 - .../Entities/CircleShape2d.cs | 8 +- Source/SceneGraph/Entities/Drawable2d.cs | 15 +++ Source/{ => SceneGraph}/Entities/Entity.cs | 2 +- Source/SceneGraph/Entities/Entity2d.cs | 9 ++ Source/SceneGraph/Entities/IDrawable.cs | 9 ++ .../{ => SceneGraph}/Entities/Particles2d.cs | 4 +- Source/{ => SceneGraph}/Entities/Sprite2d.cs | 4 +- Source/{ => SceneGraph}/Entities/Text2d.cs | 6 +- Source/{ => SceneGraph}/EntityLayer.cs | 6 +- Source/{ => SceneGraph}/IMainLoop.cs | 2 +- Source/{ => SceneGraph}/Layer.cs | 7 +- Source/{ => SceneGraph}/Scene.cs | 4 +- Source/UiLayer.cs | 24 ---- Source/{ => Utils}/ImGuiRenderLayer.cs | 20 ++-- Source/{ => Utils}/MathUtils.cs | 4 +- TestGame/Circle2d.cs | 5 +- TestGame/TestGame.cs | 4 +- TestGame/UiLayer.cs | 22 ++++ 25 files changed, 217 insertions(+), 111 deletions(-) create mode 100644 Source/Color.cs delete mode 100755 Source/Entities/Drawable2d.cs delete mode 100755 Source/Entities/Entity2d.cs delete mode 100755 Source/Entities/IDrawable.cs rename Source/{ => SceneGraph}/Entities/CircleShape2d.cs (68%) create mode 100755 Source/SceneGraph/Entities/Drawable2d.cs rename Source/{ => SceneGraph}/Entities/Entity.cs (95%) create mode 100755 Source/SceneGraph/Entities/Entity2d.cs create mode 100755 Source/SceneGraph/Entities/IDrawable.cs rename Source/{ => SceneGraph}/Entities/Particles2d.cs (98%) rename Source/{ => SceneGraph}/Entities/Sprite2d.cs (84%) rename Source/{ => SceneGraph}/Entities/Text2d.cs (76%) rename Source/{ => SceneGraph}/EntityLayer.cs (89%) rename Source/{ => SceneGraph}/IMainLoop.cs (84%) rename Source/{ => SceneGraph}/Layer.cs (73%) rename Source/{ => SceneGraph}/Scene.cs (96%) delete mode 100755 Source/UiLayer.cs rename Source/{ => Utils}/ImGuiRenderLayer.cs (94%) rename Source/{ => Utils}/MathUtils.cs (92%) create mode 100755 TestGame/UiLayer.cs diff --git a/Source/Color.cs b/Source/Color.cs new file mode 100644 index 0000000..5d8478d --- /dev/null +++ b/Source/Color.cs @@ -0,0 +1,110 @@ +namespace DaggerFramework +{ + // Based on https://github.com/ppr-game/PPR/blob/engine/PER.Util/src/Color.cs + /// + /// A record struct representing a color. + /// + public record struct Color + { + // TODO: add more HTML colors. + public static Color AliceBlue = new(0xF0F8FF); + public static Color AntiqueWhite = new(0xFAEBD7); + public static Color Aqua = new(0x00FFFF); + public static Color Aquamarine = new(0x7FFFD4); + public static Color Azure = new(0xF0FFFF); + public static Color Beige = new(0xF5F5DC); + public static Color Bisque = new(0xFFE4C4); + public static Color Black = new(0x000000); + public static Color BlanchedAlmond = new(0xFFEBCD); + public static Color Blue = new(0x0000FF); + public static Color BlueViolet = new(0x8A2BE2); + public static Color Brown = new(0xA52A2A); + public static Color BurlyWood = new(0xDEB887); + public static Color CadetBlue = new(0x5F9EA0); + public static Color Chartreuse = new(0x7FFF00); + public static Color Chocolate = new(0xD2691E); + public static Color Coral = new(0xFF7F50); + public static Color CornflowerBlue = new(0x6495ED); + public static Color Cornsilk = new(0xFFF8DC); + public static Color Crimson = new(0xDC143C); + public static Color Cyan = new(0x00FFFF); + public static Color DarkBlue = new(0x00008B); + public static Color DarkCyan = new(0x008B8B); + public static Color White = new(0xFFFFFF); + public static Color Green = new(0x00FF00); + public static Color Red = new(0xFF0000); + + public float R { get; set; } + public float G { get; set; } + public float B { get; set; } + public float A { get; set; } + + public int Argb + { + get + { + int c = (ushort)Math.Round(A * 255f); + c <<= 8; + c |= (ushort)Math.Round(R * 255f); + c <<= 8; + c |= (ushort)Math.Round(G * 255f); + c <<= 8; + c |= (ushort)Math.Round(B * 255f); + + return c; + } + } + + public Color(float r, float g, float b, float a) + { + R = r; + G = g; + B = b; + A = a; + } + + public Color(byte r, byte g, byte b, byte a) + { + R = r / 255f; + G = g / 255f; + B = b / 255f; + A = a / 255f; + } + + public Color(int hex) + { + A = 1.0f; + B = (hex & 0xFF) / 255.0f; + hex >>= 8; + G = (hex & 0xFF) / 255.0f; + hex >>= 8; + R = (hex & 0xFF) / 255.0f; + } + + public Color Lightened(float amount) + { + var result = this; + result.R = result.R + (1.0f - result.R) * amount; + result.G = result.G + (1.0f - result.G) * amount; + result.B = result.B + (1.0f - result.B) * amount; + + return result; + } + + public Color Darkened(float amount) + { + var result = this; + result.R = result.R * (1.0f - amount); + result.G = result.G * (1.0f - amount); + result.B = result.B * (1.0f - amount); + + return result; + } + + public System.Drawing.Color ToSystemColor() + { + var result = System.Drawing.Color.FromArgb(Argb); + return result; + } + } +} \ No newline at end of file diff --git a/Source/Entities/Drawable2d.cs b/Source/Entities/Drawable2d.cs deleted file mode 100755 index bc65f7a..0000000 --- a/Source/Entities/Drawable2d.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DaggerFramework.Rendering; - -namespace DaggerFramework -{ - public abstract class Drawable2d : Entity2d, IDrawable - { - public void Draw(in Renderer renderer) - { - renderer.SetTransform(position); - OnDraw(in renderer); - } - - public abstract void OnDraw(in Renderer renderer); - } -} \ No newline at end of file diff --git a/Source/Entities/Entity2d.cs b/Source/Entities/Entity2d.cs deleted file mode 100755 index b18d3af..0000000 --- a/Source/Entities/Entity2d.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Numerics; - -namespace DaggerFramework -{ - public class Entity2d : Entity - { - public Vector2 Position { get => position; set => position = value; } - protected Vector2 position; - } -} \ No newline at end of file diff --git a/Source/Entities/IDrawable.cs b/Source/Entities/IDrawable.cs deleted file mode 100755 index dba0d1b..0000000 --- a/Source/Entities/IDrawable.cs +++ /dev/null @@ -1,9 +0,0 @@ -using DaggerFramework.Rendering; - -namespace DaggerFramework -{ - public interface IDrawable - { - public void Draw(in Renderer renderer); - } -} \ No newline at end of file diff --git a/Source/Rendering/GlRenderer.cs b/Source/Rendering/GlRenderer.cs index 0635a8f..e60a65a 100644 --- a/Source/Rendering/GlRenderer.cs +++ b/Source/Rendering/GlRenderer.cs @@ -36,7 +36,7 @@ namespace DaggerFramework.Rendering public override void ClearBackground(Color color) { - _gl.ClearColor(color); + _gl.ClearColor(color.ToSystemColor()); _gl.Clear((uint)ClearBufferMask.ColorBufferBit); } diff --git a/Source/Rendering/RaylibRenderer.cs b/Source/Rendering/RaylibRenderer.cs index e4b6696..1763af3 100755 --- a/Source/Rendering/RaylibRenderer.cs +++ b/Source/Rendering/RaylibRenderer.cs @@ -51,9 +51,9 @@ namespace DaggerFramework.Rendering Raylib.EndDrawing(); } - public override void ClearBackground(System.Drawing.Color color) + public override void ClearBackground(Color color) { - Raylib.ClearBackground(SystemColorToRaylibColor(color)); + Raylib.ClearBackground(DaggerColorToRaylibColor(color)); } public override double GetFrameTime() @@ -61,9 +61,9 @@ namespace DaggerFramework.Rendering return (double)Raylib.GetFrameTime(); } - public override void DrawCircle(float radius, System.Drawing.Color color) + public override void DrawCircle(float radius, Color color) { - Raylib.DrawCircle((int)_position.X, (int)_position.Y, radius, SystemColorToRaylibColor(color)); + Raylib.DrawCircle((int)_position.X, (int)_position.Y, radius, DaggerColorToRaylibColor(color)); } public override void SetTransform(Vector2 position, float rotation) @@ -98,12 +98,12 @@ namespace DaggerFramework.Rendering return _texturePool.Count - 1; } - public override void DrawTexture(int id, System.Drawing.Color tint) + public override void DrawTexture(int id, Color tint) { - Raylib.DrawTextureV(_texturePool[id], _position, SystemColorToRaylibColor(tint)); + Raylib.DrawTextureV(_texturePool[id], _position, DaggerColorToRaylibColor(tint)); } - public override void DrawRectangle(Vector2 size, System.Drawing.Color color) + public override void DrawRectangle(Vector2 size, Color color) { // Raylib.DrawRectangleV(_position, size, SystemColorToRaylibColor(color)); Raylib.DrawRectanglePro(new Rectangle() @@ -112,15 +112,15 @@ namespace DaggerFramework.Rendering y = _position.Y, width = size.X, height = size.Y - }, Vector2.Zero, _rotation, SystemColorToRaylibColor(color)); + }, Vector2.Zero, _rotation, DaggerColorToRaylibColor(color)); } - public override void DrawDebugText(Vector2 position, string text, int fontSize, System.Drawing.Color color) + public override void DrawDebugText(Vector2 position, string text, int fontSize, Color color) { - Raylib.DrawText(text, (int)position.X, (int)position.Y, fontSize, SystemColorToRaylibColor(color)); + Raylib.DrawText(text, (int)position.X, (int)position.Y, fontSize, DaggerColorToRaylibColor(color)); } - public override void DrawSdfText(Vector2 position, string text, int fontSize, System.Drawing.Color color) + public override void DrawSdfText(Vector2 position, string text, int fontSize, Color color) { throw new NotImplementedException(); } @@ -149,9 +149,9 @@ namespace DaggerFramework.Rendering Initialize(renderSettings); } - private Raylib_cs.Color SystemColorToRaylibColor(System.Drawing.Color color) + private Raylib_cs.Color DaggerColorToRaylibColor(Color color) { - return new Color { r = color.R, g = color.G, b = color.B, a = color.A }; + return new Raylib_cs.Color { r = (byte)Math.Round(color.R * 255f), g = (byte)Math.Round(color.G * 255f), b = (byte)Math.Round(color.B * 255f), a = (byte)Math.Round(color.A * 255f) }; } private List _texturePool = new List(); diff --git a/Source/Rendering/Renderer.cs b/Source/Rendering/Renderer.cs index d39bc68..a8712ed 100755 --- a/Source/Rendering/Renderer.cs +++ b/Source/Rendering/Renderer.cs @@ -1,4 +1,3 @@ -using System.Drawing; using System.Numerics; namespace DaggerFramework.Rendering diff --git a/Source/Entities/CircleShape2d.cs b/Source/SceneGraph/Entities/CircleShape2d.cs similarity index 68% rename from Source/Entities/CircleShape2d.cs rename to Source/SceneGraph/Entities/CircleShape2d.cs index c1b4513..4f071c4 100755 --- a/Source/Entities/CircleShape2d.cs +++ b/Source/SceneGraph/Entities/CircleShape2d.cs @@ -1,20 +1,18 @@ -using System.Drawing; - using DaggerFramework.Rendering; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public class CircleShape2d : Drawable2d { public float Radius { get => _radius; set => _radius = value; } public Color Color { get => _color; set => _color = value; } - public override void OnDraw(in Renderer renderer) + public override void OnDraw(Renderer renderer) { renderer.DrawCircle(_radius, _color); } private float _radius; - private System.Drawing.Color _color; + private Color _color; } } \ No newline at end of file diff --git a/Source/SceneGraph/Entities/Drawable2d.cs b/Source/SceneGraph/Entities/Drawable2d.cs new file mode 100755 index 0000000..591bf39 --- /dev/null +++ b/Source/SceneGraph/Entities/Drawable2d.cs @@ -0,0 +1,15 @@ +using DaggerFramework.Rendering; + +namespace DaggerFramework.SceneGraph +{ + public abstract class Drawable2d : Entity2d, IDrawable + { + public void Draw(Renderer renderer) + { + renderer.SetTransform(Position); + OnDraw(renderer); + } + + public abstract void OnDraw(Renderer renderer); + } +} \ No newline at end of file diff --git a/Source/Entities/Entity.cs b/Source/SceneGraph/Entities/Entity.cs similarity index 95% rename from Source/Entities/Entity.cs rename to Source/SceneGraph/Entities/Entity.cs index 66d22f2..75c81dd 100755 --- a/Source/Entities/Entity.cs +++ b/Source/SceneGraph/Entities/Entity.cs @@ -1,6 +1,6 @@ using DaggerFramework.Audio; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public class Entity { diff --git a/Source/SceneGraph/Entities/Entity2d.cs b/Source/SceneGraph/Entities/Entity2d.cs new file mode 100755 index 0000000..1262420 --- /dev/null +++ b/Source/SceneGraph/Entities/Entity2d.cs @@ -0,0 +1,9 @@ +using System.Numerics; + +namespace DaggerFramework.SceneGraph +{ + public class Entity2d : Entity + { + public Vector2 Position { get; set; } + } +} \ No newline at end of file diff --git a/Source/SceneGraph/Entities/IDrawable.cs b/Source/SceneGraph/Entities/IDrawable.cs new file mode 100755 index 0000000..5d0c111 --- /dev/null +++ b/Source/SceneGraph/Entities/IDrawable.cs @@ -0,0 +1,9 @@ +using DaggerFramework.Rendering; + +namespace DaggerFramework.SceneGraph +{ + public interface IDrawable + { + public void Draw(Renderer renderer); + } +} \ No newline at end of file diff --git a/Source/Entities/Particles2d.cs b/Source/SceneGraph/Entities/Particles2d.cs similarity index 98% rename from Source/Entities/Particles2d.cs rename to Source/SceneGraph/Entities/Particles2d.cs index 863a309..81512fc 100644 --- a/Source/Entities/Particles2d.cs +++ b/Source/SceneGraph/Entities/Particles2d.cs @@ -2,7 +2,7 @@ using System.Drawing; using System.Numerics; using DaggerFramework.Rendering; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { // TODO: add oneshot parameter. public class Particles2d : Drawable2d @@ -21,7 +21,7 @@ namespace DaggerFramework CleanupParticles(); InitializeParticles(); } - public override void OnDraw(in Renderer renderer) + public override void OnDraw(Renderer renderer) { foreach (var particle in _particles) { diff --git a/Source/Entities/Sprite2d.cs b/Source/SceneGraph/Entities/Sprite2d.cs similarity index 84% rename from Source/Entities/Sprite2d.cs rename to Source/SceneGraph/Entities/Sprite2d.cs index 069b0ea..6d4a308 100755 --- a/Source/Entities/Sprite2d.cs +++ b/Source/SceneGraph/Entities/Sprite2d.cs @@ -2,7 +2,7 @@ using System.Drawing; using DaggerFramework.Rendering; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public class Sprite2d : Drawable2d { @@ -14,7 +14,7 @@ namespace DaggerFramework _texId = renderer.LoadTexture(_texture); } - public override void OnDraw(in Renderer renderer) + public override void OnDraw(Renderer renderer) { renderer.DrawTexture(_texId, Color.White); } diff --git a/Source/Entities/Text2d.cs b/Source/SceneGraph/Entities/Text2d.cs similarity index 76% rename from Source/Entities/Text2d.cs rename to Source/SceneGraph/Entities/Text2d.cs index d9175e9..21a9750 100644 --- a/Source/Entities/Text2d.cs +++ b/Source/SceneGraph/Entities/Text2d.cs @@ -1,7 +1,7 @@ using DaggerFramework.Rendering; using System.Drawing; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public class Text2d : Drawable2d { @@ -9,9 +9,9 @@ namespace DaggerFramework public int FontSize { get => _fontSize; set => _fontSize = value; } public Color FontColor { get => _fontColor; set => _fontColor = value; } - public override void OnDraw(in Renderer renderer) + public override void OnDraw(Renderer renderer) { - renderer.DrawDebugText(position, _contents, _fontSize, _fontColor); + renderer.DrawDebugText(Position, _contents, _fontSize, _fontColor); } private string _contents = string.Empty; diff --git a/Source/EntityLayer.cs b/Source/SceneGraph/EntityLayer.cs similarity index 89% rename from Source/EntityLayer.cs rename to Source/SceneGraph/EntityLayer.cs index aa24c08..05cda32 100755 --- a/Source/EntityLayer.cs +++ b/Source/SceneGraph/EntityLayer.cs @@ -1,6 +1,6 @@ using DaggerFramework.Rendering; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public class EntityLayer : Layer { @@ -45,11 +45,11 @@ namespace DaggerFramework } } - protected override void OnDraw(in Renderer renderer) + protected override void OnDraw(Renderer renderer) { foreach (IDrawable drawable in _entities) { - drawable.Draw(in renderer); + drawable.Draw(renderer); } } diff --git a/Source/IMainLoop.cs b/Source/SceneGraph/IMainLoop.cs similarity index 84% rename from Source/IMainLoop.cs rename to Source/SceneGraph/IMainLoop.cs index 105cf9e..89efa6d 100644 --- a/Source/IMainLoop.cs +++ b/Source/SceneGraph/IMainLoop.cs @@ -1,4 +1,4 @@ -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public interface IMainLoop { diff --git a/Source/Layer.cs b/Source/SceneGraph/Layer.cs similarity index 73% rename from Source/Layer.cs rename to Source/SceneGraph/Layer.cs index 8545352..5ef5870 100755 --- a/Source/Layer.cs +++ b/Source/SceneGraph/Layer.cs @@ -1,14 +1,13 @@ -using DaggerFramework.Audio; using DaggerFramework.Rendering; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public abstract class Layer : IDrawable { public Scene Scene { get; set; } public InputHandler Input { get; set; } - public void Draw(in Renderer renderer) => OnDraw(in renderer); + public void Draw(Renderer renderer) => OnDraw(renderer); public void Start() => OnStart(); public void Update(double dt) => OnUpdate(dt); @@ -17,6 +16,6 @@ namespace DaggerFramework protected virtual void OnStart() { } protected virtual void OnUpdate(double dt) { } protected virtual void OnInput(InputHandler input) { } - protected abstract void OnDraw(in Renderer renderer); + protected abstract void OnDraw(Renderer renderer); } } \ No newline at end of file diff --git a/Source/Scene.cs b/Source/SceneGraph/Scene.cs similarity index 96% rename from Source/Scene.cs rename to Source/SceneGraph/Scene.cs index b3eae82..c14b240 100755 --- a/Source/Scene.cs +++ b/Source/SceneGraph/Scene.cs @@ -4,7 +4,7 @@ using DaggerFramework.Audio; using DaggerFramework.Rendering; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public class Scene : IMainLoop { @@ -60,7 +60,7 @@ namespace DaggerFramework Renderer.ClearBackground(Color.Black); foreach (var layer in _layers.Values) { - layer.Draw(in _renderer); + layer.Draw(_renderer); } Renderer.EndFrame(); diff --git a/Source/UiLayer.cs b/Source/UiLayer.cs deleted file mode 100755 index 25719e6..0000000 --- a/Source/UiLayer.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Drawing; -using System.Numerics; - -using DaggerFramework.Rendering; - -namespace DaggerFramework -{ - public class UiLayer : Layer - { - protected override void OnUpdate(double dt) - { - base.OnUpdate(dt); - _time += dt; - } - protected override void OnDraw(in Renderer renderer) - { - renderer.SetTransform(Vector2.Zero); - renderer.DrawRectangle(new Vector2(720 / 2, 1280), Color.Green); - renderer.DrawDebugText(new Vector2(720 / 4 - 24, 64), "UI :)", 24, Color.White); - } - - private double _time; - } -} \ No newline at end of file diff --git a/Source/ImGuiRenderLayer.cs b/Source/Utils/ImGuiRenderLayer.cs similarity index 94% rename from Source/ImGuiRenderLayer.cs rename to Source/Utils/ImGuiRenderLayer.cs index 75ec0ef..c35af98 100755 --- a/Source/ImGuiRenderLayer.cs +++ b/Source/Utils/ImGuiRenderLayer.cs @@ -4,14 +4,14 @@ using Raylib_cs; using DaggerFramework.Rendering; -namespace DaggerFramework +namespace DaggerFramework.SceneGraph { public class ImGuiRenderLayer : Layer { - protected override void OnDraw(in Renderer renderer) + protected override void OnDraw(Renderer renderer) { Layout(); - _controller.Draw(in renderer); + _controller.Draw(renderer); } protected virtual void Layout() { } @@ -258,12 +258,12 @@ namespace DaggerFramework private Color GetColor(uint hexValue) { - Color color; + Color color = new Color(); - color.r = (byte)(hexValue & 0xFF); - color.g = (byte)((hexValue >> 8) & 0xFF); - color.b = (byte)((hexValue >> 16) & 0xFF); - color.a = (byte)((hexValue >> 24) & 0xFF); + color.R = (byte)(hexValue & 0xFF) / 255f; + color.G = (byte)((hexValue >> 8) & 0xFF) / 255f; + color.B = (byte)((hexValue >> 16) & 0xFF) / 255f; + color.A = (byte)((hexValue >> 24) & 0xFF) / 255f; return color; } @@ -271,7 +271,7 @@ namespace DaggerFramework void DrawTriangleVertex(ImDrawVertPtr idxVert) { Color c = GetColor(idxVert.col); - Rlgl.rlColor4ub(c.r, c.g, c.b, c.a); + Rlgl.rlColor4ub((byte)Math.Round(c.R * 255f), (byte)Math.Round(c.G * 255f), (byte)Math.Round(c.B * 255f), (byte)Math.Round(c.A * 255f)); Rlgl.rlTexCoord2f(idxVert.uv.X, idxVert.uv.Y); Rlgl.rlVertex2f(idxVert.pos.X, idxVert.pos.Y); } @@ -307,7 +307,7 @@ namespace DaggerFramework Rlgl.rlEnd(); } - public void Draw(in Renderer renderer) + public void Draw(Renderer renderer) { ImGui.Render(); RenderCommandLists(ImGui.GetDrawData()); diff --git a/Source/MathUtils.cs b/Source/Utils/MathUtils.cs similarity index 92% rename from Source/MathUtils.cs rename to Source/Utils/MathUtils.cs index 724b8b4..002cb8a 100755 --- a/Source/MathUtils.cs +++ b/Source/Utils/MathUtils.cs @@ -12,7 +12,9 @@ namespace DaggerFramework var r = (byte)Lerp(colorA.R, colorB.R, t); var g = (byte)Lerp(colorA.G, colorB.G, t); var b = (byte)Lerp(colorA.B, colorB.B, t); - return Color.FromArgb(r, g, b); + var a = (byte)Lerp(colorA.A, colorB.A, t); + + return new Color(r, g, b, a); } public static Vector2 LerpVector2(Vector2 v1, Vector2 v2, double t) diff --git a/TestGame/Circle2d.cs b/TestGame/Circle2d.cs index 60785a5..9681bbe 100644 --- a/TestGame/Circle2d.cs +++ b/TestGame/Circle2d.cs @@ -1,12 +1,11 @@ using DaggerFramework.Rendering; -using System.Drawing; - +using DaggerFramework.SceneGraph; namespace DaggerFramework; public class Circle2d : Drawable2d { - public override void OnDraw(in Renderer renderer) + public override void OnDraw(Renderer renderer) { renderer.DrawCircle(32f, Color.AliceBlue); } diff --git a/TestGame/TestGame.cs b/TestGame/TestGame.cs index edc0bfe..f98c7a7 100644 --- a/TestGame/TestGame.cs +++ b/TestGame/TestGame.cs @@ -27,7 +27,9 @@ public class TestGame : Game while (_renderer.ShouldRun) { _renderer.BeginFrame(); - _renderer.ClearBackground(System.Drawing.Color.Black); + _renderer.ClearBackground(Color.Black); + _renderer.SetTransform(new Vector2(640, 480)); + _renderer.DrawCircle(16f, Color.Chocolate); _renderer.EndFrame(); } } diff --git a/TestGame/UiLayer.cs b/TestGame/UiLayer.cs new file mode 100755 index 0000000..d3abd9a --- /dev/null +++ b/TestGame/UiLayer.cs @@ -0,0 +1,22 @@ +using System.Numerics; + +using DaggerFramework; +using DaggerFramework.Rendering; +using DaggerFramework.SceneGraph; + +public class UiLayer : Layer +{ + protected override void OnUpdate(double dt) + { + base.OnUpdate(dt); + _time += dt; + } + protected override void OnDraw(Renderer renderer) + { + renderer.SetTransform(Vector2.Zero); + renderer.DrawRectangle(new Vector2(720 / 2, 1280), Color.Green); + renderer.DrawDebugText(new Vector2(720 / 4 - 24, 64), "UI :)", 24, Color.White); + } + + private double _time; +} \ No newline at end of file