Replaced color usage with OpenTK's implementation.
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
using System;
|
||||
namespace RecrownedAthenaeum.Types
|
||||
{
|
||||
public struct Color
|
||||
{
|
||||
public byte r, g, b, a;
|
||||
public float R {
|
||||
set {
|
||||
r = (byte)Math.Min(Math.Round(Byte.MaxValue * value), Byte.MaxValue);
|
||||
}
|
||||
get {
|
||||
return r / (float)(byte.MaxValue);
|
||||
}
|
||||
}
|
||||
public float G {
|
||||
set {
|
||||
g = (byte)Math.Min(Math.Round(Byte.MaxValue * value), Byte.MaxValue);
|
||||
}
|
||||
get {
|
||||
return g / (float)(byte.MaxValue);
|
||||
}
|
||||
}
|
||||
public float B {
|
||||
set {
|
||||
g = (byte)Math.Min(Math.Round(Byte.MaxValue * value), Byte.MaxValue);
|
||||
}
|
||||
get {
|
||||
return g / (float)(byte.MaxValue);
|
||||
}
|
||||
}
|
||||
public float A {
|
||||
set {
|
||||
a = (byte)Math.Min(Math.Round(Byte.MaxValue * value), Byte.MaxValue);
|
||||
}
|
||||
get {
|
||||
return a / (float)(byte.MaxValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
RecrownedAthenaeum/Types/Extensions.cs
Normal file
33
RecrownedAthenaeum/Types/Extensions.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK;
|
||||
namespace RecrownedAthenaeum.Types {
|
||||
public static class Color4Ext {
|
||||
public static byte GetRedAsByte(this Color4 color) {
|
||||
return (byte) (color.R * Byte.MaxValue);
|
||||
}
|
||||
public static byte GetGreenAsByte(this Color4 color) {
|
||||
return (byte) (color.G * Byte.MaxValue);
|
||||
}
|
||||
public static byte GetBlueAsByte(this Color4 color) {
|
||||
return (byte) (color.B * Byte.MaxValue);
|
||||
}
|
||||
public static byte GetAlphaAsByte(this Color4 color) {
|
||||
return (byte) (color.A * Byte.MaxValue);
|
||||
}
|
||||
public static void MultiplyByFloat(this Color4 color, float val) {
|
||||
color.A *= val;
|
||||
color.R *= val;
|
||||
color.G *= val;
|
||||
color.B *= val;
|
||||
}
|
||||
public static Color4 ReturnMultipliedByFloat(this Color4 color, float val) {
|
||||
Color4 output = new Color4(color.R * val, color.G * val, color.B * val, color.A * val);
|
||||
return output;
|
||||
}
|
||||
public static void FromNonPremultiplied(ref Vector4 vector) {
|
||||
//Premultiplied.
|
||||
vector = new Vector4(vector.W * vector.X, vector.W * vector.Y, vector.W * vector.Z, vector.W);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,7 @@
|
||||
using RecrownedAthenaeum.Graphics.Render;
|
||||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace RecrownedAthenaeum.Types
|
||||
{
|
||||
@@ -83,7 +85,7 @@ namespace RecrownedAthenaeum.Types
|
||||
/// <param name="spriteBatch">Batch to use.</param>
|
||||
/// <param name="color">The color of the patch.</param>
|
||||
/// <param name="destination">Where to the patch.</param>
|
||||
public void Draw(ConsistentSpriteBatch spriteBatch, Color color, Rectangle destination)
|
||||
public void Draw(ConsistentSpriteBatch spriteBatch, Color4 color, Rectangle destination)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -114,7 +116,7 @@ namespace RecrownedAthenaeum.Types
|
||||
/// <param name="color">The tint for each patch.</param>
|
||||
/// <param name="rotation">Not considered for 9patches.</param>
|
||||
/// <param name="origin">Not considered for 9patches.</param>
|
||||
public void Draw(ConsistentSpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
public void Draw(ConsistentSpriteBatch spriteBatch, Rectangle destination, Color4 color, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
{
|
||||
if (rotation != 0) throw new NotImplementedException("Ninepatches can't be rotated.");
|
||||
if (origin != default(Vector2))
|
||||
|
@@ -2,6 +2,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace RecrownedAthenaeum.Types
|
||||
{
|
||||
@@ -55,7 +57,7 @@ namespace RecrownedAthenaeum.Types
|
||||
/// <param name="color">Color to use.</param>
|
||||
/// <param name="rotation">Rotation of texture drawn.</param>
|
||||
/// <param name="origin">Origin used by rotation.</param>
|
||||
public void Draw(string name, ConsistentSpriteBatch batch, Rectangle destination, Color color = default(Color), float rotation = 0, Vector2 origin = new Vector2())
|
||||
public void Draw(string name, ConsistentSpriteBatch batch, Rectangle destination, Color4 color = default(Color4), float rotation = 0, Vector2 origin = new Vector2())
|
||||
{
|
||||
dictionaryOfRegions[name].Draw(batch, destination, color, rotation, origin);
|
||||
}
|
||||
@@ -166,7 +168,7 @@ namespace RecrownedAthenaeum.Types
|
||||
/// <param name="color">The color to use.</param>
|
||||
/// <param name="rotation">Rotation of the final drawing. Ignored if is a 9patch.</param>
|
||||
/// <param name="origin">The origin of the drawing. Ignored if is a 9patch.</param>
|
||||
public void Draw(ConsistentSpriteBatch batch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
public void Draw(ConsistentSpriteBatch batch, Rectangle destination, Color4 color, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
{
|
||||
if (Disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
|
||||
@@ -191,7 +193,7 @@ namespace RecrownedAthenaeum.Types
|
||||
|
||||
if (regionTexture == null)
|
||||
{
|
||||
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
|
||||
Color4[] data = new Color4[sourceRectangle.Width * sourceRectangle.Height];
|
||||
regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
|
||||
atlasTexture.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
|
||||
regionTexture.SetData(data);
|
||||
|
Reference in New Issue
Block a user