-
Notifications
You must be signed in to change notification settings - Fork 1
/
gfx-framework.h
154 lines (117 loc) · 4.47 KB
/
gfx-framework.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Copyright (C) 2020 Marcel Smit
https://www.facebook.com/marcel.smit981
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "jsusfx_gfx.h"
#include "Mat4x4.h"
//
class ImageData;
class Surface;
class JsusFx;
struct JsusFx_Image;
struct JsusFx_ImageCache;
struct JsusFxGfx_Framework; // implements JsusFxGfx
//
struct JsusFx_Image
{
bool isValid = false;
ImageData * imageData = nullptr;
Surface * surface = nullptr;
~JsusFx_Image();
void free();
void resize(const int sx, const int sy);
};
struct JsusFx_ImageCache
{
static const int kMaxImages = 1024;
JsusFx_Image images[kMaxImages];
JsusFx_Image dummyImage;
JsusFx_ImageCache();
void free();
int alloc(const int sx, const int sy);
JsusFx_Image & get(const int index);
};
//
struct JsusFxGfx_Framework : JsusFxGfx
{
enum PrimType
{
kPrimType_Other,
kPrimType_Rect,
kPrimType_RectLine,
kPrimType_HqLine,
kPrimType_HqFillCircle,
kPrimType_HqStrokeCircle
};
float m_fontSize = 10.f;
JsusFx_ImageCache imageCache;
int mouseFlags = 0;
int currentImageIndex = -1;
int currentBlendMode = -1;
JsusFx & jsusFx;
PrimType primType = kPrimType_Other;
Surface * surface = nullptr;
int mouseX = 0;
int mouseY = 0;
int lastKey = 0;
bool inputEnabled = true;
Mat4x4 drawTransform;
bool needsClear = false;
int clearColor = 0;
JsusFxGfx_Framework(JsusFx & _jsusFx);
void setup(Surface * surface, const int w, const int h, const int mouseX, const int mouseY, const bool inputEnabled);
virtual void setup(const int w, const int h) override;
virtual void beginDraw() override;
virtual void endDraw() override;
void updatePrimType(PrimType _primType);
void updateBlendMode();
void updateColor();
void updateSurface();
virtual void gfx_line(int np, EEL_F ** params) override;
virtual void gfx_rect(int np, EEL_F ** params) override;
virtual void gfx_circle(EEL_F x, EEL_F y, EEL_F radius, bool fill, bool aa) override;
virtual void gfx_triangle(EEL_F ** parms, int np) override;
virtual void gfx_lineto(EEL_F xpos, EEL_F ypos, EEL_F useaa) override;
virtual void gfx_rectto(EEL_F xpos, EEL_F ypos) override;
virtual void gfx_arc(int np, EEL_F ** parms) override;
virtual void gfx_set(int np, EEL_F ** params) override;
virtual void gfx_roundrect(int np, EEL_F ** parms) override;
virtual void gfx_grad_or_muladd_rect(int mode, int np, EEL_F ** parms) override;
virtual void gfx_drawnumber(EEL_F n, int nd) override;
virtual void gfx_drawchar(EEL_F n) override;
virtual void gfx_drawstr(void * opaque, EEL_F ** parms, int nparms, int formatmode) override;
virtual void gfx_setpixel(EEL_F r, EEL_F g, EEL_F b) override;
virtual void gfx_getpixel(EEL_F * r, EEL_F * g, EEL_F * b) override;
virtual EEL_F gfx_loadimg(JsusFx & jsusFx, int index, EEL_F loadFrom) override;
virtual void gfx_getimgdim(EEL_F _img, EEL_F * w, EEL_F * h) override;
virtual EEL_F gfx_setimgdim(int img, EEL_F * w, EEL_F * h) override;
virtual EEL_F gfx_setfont(int np, EEL_F ** parms) override;
virtual EEL_F gfx_getfont(int np, EEL_F ** parms) override;
virtual EEL_F gfx_showmenu(EEL_F ** parms, int nparms) override;
virtual EEL_F gfx_setcursor(EEL_F ** parms, int nparms) override;
virtual void gfx_blurto(EEL_F x, EEL_F y) override;
virtual void gfx_blit(EEL_F _img, EEL_F scale, EEL_F rotate) override;
virtual void gfx_blitext(EEL_F img, EEL_F * coords, EEL_F angle) override;
virtual void gfx_blitext2(int np, EEL_F ** parms, int blitmode) override;
virtual int gfx_getchar(int p) override;
};