Merged SM2D.DrawColor/DrawComplex/DrawPolygon/DrawShader/DrawTexture into DrawObject2D

This commit is contained in:
Michel Fedde 2020-12-12 11:00:59 +01:00
parent beb9c19081
commit 0895c600cf
14 changed files with 320 additions and 256 deletions

View file

@ -1,20 +0,0 @@
using SM.Base.Contexts;
using SM.Base.Drawing;
using SM.Base.Scene;
using SM2D.Scene;
namespace SM2D.Drawing
{
public class DrawBackgroundShader : DrawShader, IBackgroundItem
{
public DrawBackgroundShader(MaterialShader shader) : base(shader)
{ }
protected override void DrawContext(ref DrawContext context)
{
Transform.Size.Set(context.WorldScale);
base.DrawContext(ref context);
}
}
}

View file

@ -1,38 +0,0 @@
#region usings
using OpenTK.Graphics;
using SM.Base.Contexts;
using SM.Base.Drawing;
using SM.Base.Scene;
using SM2D.Scene;
using SM2D.Types;
#endregion
namespace SM2D.Drawing
{
public class DrawColor : DrawingBasis<Transformation>, I2DShowItem
{
public DrawColor()
{
}
public DrawColor(Color4 color)
{
_material.Tint = color;
}
public Color4 Color
{
get => _material.Tint;
set => _material.Tint = value;
}
public int ZIndex { get; set; }
protected override void DrawContext(ref DrawContext context)
{
context.Shader.Draw(context);
}
}
}

View file

@ -1,37 +0,0 @@
#region usings
using SM.Base.Contexts;
using SM.Base.Drawing;
using SM.Base.Scene;
using SM.OGL.Mesh;
using SM2D.Scene;
using SM2D.Types;
#endregion
namespace SM2D.Drawing
{
public class DrawComplex : DrawingBasis<Transformation>, I2DShowItem
{
public Material Material
{
get => _material;
set => _material = value;
}
public GenericMesh Mesh
{
get => _mesh;
set => _mesh = value;
}
public int ZIndex { get; set; }
protected override void DrawContext(ref DrawContext context)
{
base.DrawContext(ref context);
context.Shader.Draw(context);
}
}
}

View file

@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using SM.Base.Contexts;
using SM.Base.Drawing;
using SM.Base.Objects;
using SM.Base.Textures;
using SM2D.Object;
using SM2D.Scene;
using SM2D.Types;
namespace SM2D.Drawing
{
public class DrawObject2D : DrawingBasis<Transformation>, I2DShowItem
{
public int ZIndex { get; set; }
public Texture Texture
{
get => (Texture) _material.Texture;
set => _material.Texture = value;
}
public Color4 Color
{
get => _material.Tint;
set => _material.Tint = value;
}
protected override void DrawContext(ref DrawContext context)
{
base.DrawContext(ref context);
context.Shader.Draw(context);
}
public Material GetMaterialReference() => _material;
public void SetMaterialReference(Material material) => _material = material;
public void SetShader(MaterialShader shader) => _material.CustomShader = shader;
public Polygon ApplyPolygon(ICollection<Vector2> vertices)
{
Polygon polygon = new Polygon(vertices);
_mesh = polygon;
return polygon;
}
public Polygon ApplyPolygon(ICollection<PolygonVertex> vertices)
{
Polygon polygon = new Polygon(vertices);
_mesh = polygon;
return polygon;
}
public void ApplyPolygon(Polygon polygon)
{
_mesh = polygon;
}
public void ApplyMesh(Mesh mesh) => _mesh = mesh;
public Polygon ApplyCircle(int segments = 32)
{
Polygon pol = Polygon.GenerateCircle(segments);
_mesh = pol;
return pol;
}
}
}

View file

@ -1,46 +0,0 @@
#region usings
using System.Drawing;
using OpenTK.Graphics;
using SM.Base.Textures;
using SM2D.Object;
#endregion
namespace SM2D.Drawing
{
public class DrawPolygon : DrawColor
{
public DrawPolygon(Polygon polygon) : this(polygon, Color4.White)
{
}
public DrawPolygon(Polygon polygon, Bitmap map) : this(polygon, map, Color4.White)
{
}
public DrawPolygon(Polygon polygon, Color4 color) : base(color)
{
_mesh = polygon;
}
public DrawPolygon(Polygon polygon, Bitmap map, Color4 tint) : base(tint)
{
_mesh = polygon;
_material.Texture = new Texture(map);
}
public Polygon Polygon
{
get => (Polygon) _mesh;
set => _mesh = value;
}
public Texture Texture
{
get => (Texture) _material.Texture;
set => _material.Texture = value;
}
}
}

View file

@ -1,24 +0,0 @@
using SM.Base.Contexts;
using SM.Base.Drawing;
using SM.Base.Scene;
using SM2D.Scene;
using SM2D.Types;
namespace SM2D.Drawing
{
public class DrawShader : DrawingBasis<Transformation>, I2DShowItem
{
public int ZIndex { get; set; }
public DrawShader(MaterialShader shader)
{
_material.CustomShader = shader;
}
protected override void DrawContext(ref DrawContext context)
{
base.DrawContext(ref context);
_material.CustomShader.Draw(context);
}
}
}

View file

@ -1,56 +0,0 @@
#region usings
using System.Drawing;
using OpenTK.Graphics;
using SM.Base.Contexts;
using SM.Base.Textures;
using SM.Base.Types;
#endregion
namespace SM2D.Drawing
{
public class DrawTexture : DrawColor
{
public static float MasterScale = .25f;
public bool ManualSize = false;
public float Scale = 1;
public DrawTexture()
{
}
protected DrawTexture(Color4 color) : base(color)
{
}
public DrawTexture(Bitmap map) : this(map, Color4.White)
{
}
public DrawTexture(Bitmap map, Color4 color) : this((Texture) map, color)
{
}
public DrawTexture(Texture texture, Color4 color)
{
_material.Texture = texture;
_material.Tint = color;
}
public Texture Texture
{
get => (Texture) _material.Texture;
set => _material.Texture = value;
}
protected override void DrawContext(ref DrawContext context)
{
if (!ManualSize)
Transform.Size = new CVector2(Texture.Map.Width * MasterScale * Scale,
Texture.Map.Height * MasterScale * Scale);
base.DrawContext(ref context);
}
}
}