-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowImplementation.cs
77 lines (69 loc) · 2.34 KB
/
WindowImplementation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Numerics;
using System.Collections.Generic;
using System;
namespace BBQLib
{
public abstract class WindowImplementation : IDrawableSurface, IDisposable
{
public abstract void Clear();
public abstract void Draw(Sprite sprite);
public abstract void Draw(string font, string text, Vector2 position);
public abstract void DrawBox(BoundingBox box, Color color);
public abstract void Present();
public abstract Sprite CreateSprite(string filename);
public abstract Sprite CreateSprite(byte[] frameBuffer, uint width, uint height, string name);
public abstract void DrawLine(Vector2 A, Vector2 B, float width, Color color);
//public abstract void UpdateSprite(byte[] frameBuffer, string name);
public abstract void LoadFonts(string filename);
public abstract void Dispose();
public abstract bool IsKeyDown(KeyboardKey key);
public abstract Vector2 GetMouse();
protected abstract void DrawSpriteInternal(Sprite sprite);
protected readonly List<int> usedLayers = new List<int>();
protected List<Sprite> sprites = new List<Sprite>();
//I couldn't think of a better function name
protected void Layer(int layer)
{
if(!usedLayers.Contains(layer))
{
usedLayers.Add(layer);
}
}
protected void DrawSprites()
{
usedLayers.Sort();
foreach(var sprite in sprites)
{
sprite.drawn = false;
}
foreach(var layer in usedLayers)
{
for(int i = 0; i < sprites.Count; i++)
{
Sprite sprite = sprites[i];
if(!sprite.drawn)
{
if(sprite.layer == layer)
{
sprite.drawn = true;
DrawSpriteInternal(sprite);
}
}
}
}
usedLayers.Clear();
}
public abstract bool IsOpen
{
get;
}
public abstract float DeltaTime
{
get;
}
public abstract Vector2 Size
{
get;
}
}
}