forked from OpenApoc/OpenApoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.h
73 lines (62 loc) · 1.9 KB
/
renderer.h
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
#pragma once
#include "library/colour.h"
#include "library/sp.h"
#include "library/strings.h"
#include "library/vec.h"
#include <memory>
namespace OpenApoc
{
class Image;
class Palette;
class Surface;
class RendererImageData
{
public:
virtual sp<Image> readBack();
virtual ~RendererImageData();
};
class Renderer
{
private:
friend class RendererSurfaceBinding;
virtual void setSurface(sp<Surface> s) = 0;
virtual sp<Surface> getSurface() = 0;
public:
enum class Scaler
{
Nearest,
Linear,
};
virtual ~Renderer();
virtual void clear(Colour c = Colour{0, 0, 0, 0}) = 0;
virtual void setPalette(sp<Palette> p) = 0;
virtual sp<Palette> getPalette() = 0;
virtual void draw(sp<Image> i, Vec2<float> position) = 0;
virtual void drawRotated(sp<Image> i, Vec2<float> center, Vec2<float> position,
float angle) = 0;
virtual void drawScaled(sp<Image> i, Vec2<float> position, Vec2<float> size,
Scaler scaler = Scaler::Linear) = 0;
virtual void drawTinted(sp<Image> i, Vec2<float> position, Colour tint) = 0;
virtual void drawFilledRect(Vec2<float> position, Vec2<float> size, Colour c) = 0;
// drawRect() is expected to grow inwards, so {position, position + size} specifies the bounds
// of the rect no matter the thickness
virtual void drawRect(Vec2<float> position, Vec2<float> size, Colour c,
float thickness = 1.0) = 0;
virtual void drawLine(Vec2<float> p1, Vec2<float> p2, Colour c, float thickness = 1.0) = 0;
virtual void flush() = 0;
virtual UString getName() = 0;
virtual void newFrame(){};
virtual sp<Surface> getDefaultSurface() = 0;
};
class RendererSurfaceBinding
{
private:
// Disallow copy
RendererSurfaceBinding(const RendererSurfaceBinding &) = delete;
sp<Surface> prevBinding;
Renderer &r;
public:
RendererSurfaceBinding(Renderer &r, sp<Surface> surface);
~RendererSurfaceBinding();
};
}; // namespace OpenApoc