mirror of
				https://github.com/MaddyThorson/StrawberryBF.git
				synced 2025-11-04 01:41:33 +08:00 
			
		
		
		
	Color struct. Reorg.
This commit is contained in:
		@ -399,7 +399,7 @@ namespace Strawberry
 | 
			
		||||
 | 
			
		||||
		// ===== Misc =====
 | 
			
		||||
 | 
			
		||||
		public void DrawHitbox(SDL2.SDL.Color color)
 | 
			
		||||
		public void DrawHitbox(Color color)
 | 
			
		||||
		{
 | 
			
		||||
			Draw.Rect(SceneHitbox, color);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -26,6 +26,7 @@ namespace Strawberry
 | 
			
		||||
		private bool updating;
 | 
			
		||||
 | 
			
		||||
		public SDL.Renderer* Renderer { get; private set; }
 | 
			
		||||
		public Color ClearColor = Color.Black;
 | 
			
		||||
 | 
			
		||||
		private SDL.Rect screenRect;
 | 
			
		||||
		private SDL.Window* window;
 | 
			
		||||
@ -175,7 +176,7 @@ namespace Strawberry
 | 
			
		||||
 | 
			
		||||
		public void Render()
 | 
			
		||||
		{
 | 
			
		||||
			SDL.SetRenderDrawColor(Renderer, 0, 0, 0, 255);
 | 
			
		||||
			SDL.SetRenderDrawColor(Renderer, ClearColor.R, ClearColor.G, ClearColor.B, ClearColor.A);
 | 
			
		||||
			SDL.RenderClear(Renderer);
 | 
			
		||||
			SDL.RenderSetScale(Renderer, WindowScale, WindowScale);
 | 
			
		||||
			Draw();
 | 
			
		||||
 | 
			
		||||
@ -1,16 +0,0 @@
 | 
			
		||||
namespace Strawberry
 | 
			
		||||
{
 | 
			
		||||
	static public class Draw
 | 
			
		||||
	{
 | 
			
		||||
		static public void Rect(int x, int y, int w, int h, SDL2.SDL.Color color)
 | 
			
		||||
		{
 | 
			
		||||
			SDL2.SDL.SetRenderDrawColor(Game.Renderer, color.r, color.g, color.b, color.a);
 | 
			
		||||
			SDL2.SDL.RenderFillRect(Game.Renderer, &SDL2.SDL.Rect((int32)x, (int32)y, (int32)w, (int32)h));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public void Rect(Rect rect, SDL2.SDL.Color color)
 | 
			
		||||
		{
 | 
			
		||||
			Rect(rect.X, rect.Y, rect.Width, rect.Height, color);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										132
									
								
								src/Util/Color.bf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								src/Util/Color.bf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,132 @@
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace Strawberry
 | 
			
		||||
{
 | 
			
		||||
	public struct Color
 | 
			
		||||
	{
 | 
			
		||||
		static public readonly Color White = Color(255, 255, 255);
 | 
			
		||||
		static public readonly Color Black = Color(0, 0, 0);
 | 
			
		||||
		static public readonly Color Transparent = Color(0, 0, 0, 0);
 | 
			
		||||
		static public readonly Color Red = Color(255, 0, 0);
 | 
			
		||||
		static public readonly Color Green = Color(0, 255, 0);
 | 
			
		||||
		static public readonly Color Blue = Color(0, 0, 255);
 | 
			
		||||
 | 
			
		||||
		public uint8 R;
 | 
			
		||||
		public uint8 G;
 | 
			
		||||
		public uint8 B;
 | 
			
		||||
		public uint8 A;
 | 
			
		||||
 | 
			
		||||
		public this(uint8 red, uint8 green, uint8 blue, uint8 alpha)
 | 
			
		||||
		{
 | 
			
		||||
			R = red;
 | 
			
		||||
			G = green;
 | 
			
		||||
			B = blue;
 | 
			
		||||
			A = alpha;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public this(uint8 red, uint8 green, uint8 blue)
 | 
			
		||||
			: this(red, green, blue, 255)
 | 
			
		||||
		{
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public this(float red, float green, float blue, float alpha)
 | 
			
		||||
		{
 | 
			
		||||
			R = (uint8)(red * 255);
 | 
			
		||||
			G = (uint8)(green * 255);
 | 
			
		||||
			B = (uint8)(blue * 255);
 | 
			
		||||
			A = (uint8)(alpha * 255);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public this(float red, float green, float blue)
 | 
			
		||||
			: this(red, green, blue, 1f)
 | 
			
		||||
		{
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public float Rf
 | 
			
		||||
		{
 | 
			
		||||
			[Inline]
 | 
			
		||||
			get
 | 
			
		||||
			{
 | 
			
		||||
				return R / 255f;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			[Inline]
 | 
			
		||||
			set	mut
 | 
			
		||||
			{
 | 
			
		||||
				R = (uint8)(value * 255);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public float Gf
 | 
			
		||||
		{
 | 
			
		||||
			[Inline]
 | 
			
		||||
			get
 | 
			
		||||
			{
 | 
			
		||||
				return G / 255f;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			[Inline]
 | 
			
		||||
			set	mut
 | 
			
		||||
			{
 | 
			
		||||
				G = (uint8)(value * 255);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public float Bf
 | 
			
		||||
		{
 | 
			
		||||
			[Inline]
 | 
			
		||||
			get
 | 
			
		||||
			{
 | 
			
		||||
				return B / 255f;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			[Inline]
 | 
			
		||||
			set	mut
 | 
			
		||||
			{
 | 
			
		||||
				B = (uint8)(value * 255);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public float Af
 | 
			
		||||
		{
 | 
			
		||||
			[Inline]
 | 
			
		||||
			get
 | 
			
		||||
			{
 | 
			
		||||
				return A / 255f;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			[Inline]
 | 
			
		||||
			set	mut
 | 
			
		||||
			{
 | 
			
		||||
				A = (uint8)(value * 255);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public Color Lerp(Color a, Color b, float t)
 | 
			
		||||
		{
 | 
			
		||||
			return Color(
 | 
			
		||||
				Math.Lerp(a.Rf, b.Rf, t),
 | 
			
		||||
				Math.Lerp(a.Gf, b.Gf, t),
 | 
			
		||||
				Math.Lerp(a.Bf, b.Bf, t),
 | 
			
		||||
				Math.Lerp(a.Af, b.Af, t)
 | 
			
		||||
			);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public Color operator/(Color a, Color b)
 | 
			
		||||
		{
 | 
			
		||||
			return Lerp(a, b, 0.5f);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public Color operator*(Color color, float b)
 | 
			
		||||
		{
 | 
			
		||||
			return Color(color.R, color.G, color.B, (uint8)(color.A * b));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public implicit operator SDL2.SDL.Color(Color color)
 | 
			
		||||
		{
 | 
			
		||||
			return SDL2.SDL.Color(color.R, color.G, color.B, color.A);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								src/Util/Draw.bf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/Util/Draw.bf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
			
		||||
using SDL2;
 | 
			
		||||
 | 
			
		||||
namespace Strawberry
 | 
			
		||||
{
 | 
			
		||||
	static public class Draw
 | 
			
		||||
	{
 | 
			
		||||
		static public void Rect(int x, int y, int w, int h, Color color)
 | 
			
		||||
		{
 | 
			
		||||
			SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
 | 
			
		||||
			SDL.RenderFillRect(Game.Renderer, &SDL.Rect((int32)x, (int32)y, (int32)w, (int32)h));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public void Rect(Rect rect, Color color)
 | 
			
		||||
		{
 | 
			
		||||
			Rect(rect.X, rect.Y, rect.Width, rect.Height, color);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public void HollowRect(int x, int y, int w, int h, Color color)
 | 
			
		||||
		{
 | 
			
		||||
			SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
 | 
			
		||||
			SDL.RenderDrawRect(Game.Renderer, &SDL.Rect((int32)x, (int32)y, (int32)w, (int32)h));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public void HollowRect(Rect rect, Color color)
 | 
			
		||||
		{
 | 
			
		||||
			HollowRect(rect.X, rect.Y, rect.Width, rect.Height, color);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		static public void Line(Point from, Point to, Color color)
 | 
			
		||||
		{
 | 
			
		||||
			SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
 | 
			
		||||
			SDL.RenderDrawLine(Game.Renderer, (int32)from.X, (int32)from.Y, (int32)to.X, (int32)to.Y);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user