-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_gl.c
224 lines (178 loc) · 5.5 KB
/
draw_gl.c
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <linux/fb.h>
#include "tiger_gl.h"
extern TglScreen *_ts;
extern ClipRegion _clip;
extern TglInfo *_tglInfo;
extern DirtyArea *dirtyArea;
extern int dirtyAreaQue;
extern int dirtyAreaPoolQue;
extern struct fb_var_screeninfo _vinfo;
extern struct fb_fix_screeninfo _finfo;
void _addArea(WidgetType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
DirtyArea *da = NULL;
ItemType it;
int r = cqRemove(dirtyAreaPoolQue, &it, CQ_BLOCK);
if (r != 0) {
printf("No more dirty area blocks.\n");
return;
}
da = &dirtyArea[it.i];
da->type = type;
da->x = x;
da->y = y;
da->width = width;
da->height = height;
cqAdd(dirtyAreaQue, &it);
}
void _addAreaW(TglWidget *tw) {
_addArea(tw->widgetType, tw->x, tw->y, tw->width, tw->height);
}
void tglDrawSetClipRegion(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
_clip.isActive = true;
_clip.x = x;
_clip.y = y;
_clip.width = width;
_clip.height = height;
}
void tglDrawUnsetClipRegion() {
_clip.isActive = false;
}
void tglDrawFillScreen(uint32_t c) {
UG_FillScreen(c);
_addArea(WIDGET_MAIN_SCREEN, _ts->x, _ts->y, _ts->width, _ts->height);
}
void tglDrawLine(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint32_t c) {
UG_DrawLine(xs, ys, xe, ye, c);
if(_tglInfo->autoUpdate)
_addArea(TGL_LINE, xs, ys, xe, ye);
}
void tglDrawRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t c) {
if (_ts == NULL)
return;
if (_ts->screen == NULL)
return;
UG_DrawFrame(x, y, (x + width), (y + height), c);
if(_tglInfo->autoUpdate)
_addArea(TGL_RECT, x, y, width, height);
}
void tglDrawRoundRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t radius, uint32_t c) {
if (_ts == NULL)
return;
if (_ts->screen == NULL)
return;
UG_DrawRoundFrame(x, y, (x + width), (y + height), radius, c);
if(_tglInfo->autoUpdate)
_addArea(TGL_RECT, x, y, width, height);
}
void tglDrawFillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t c) {
if (_ts == NULL)
return;
if (_ts->screen == NULL)
return;
UG_FillFrame(x, y, (x + width), (y + height), c);
if(_tglInfo->autoUpdate)
_addArea(TGL_RECT, x, y, width, height);
}
void tglDrawFillRoundRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t radius, uint32_t c) {
if (_ts == NULL)
return;
if (_ts->screen == NULL)
return;
UG_FillRoundFrame(x, y, (x + width), (y + height), radius, c);
if(_tglInfo->autoUpdate)
_addArea(TGL_RECT, x, y, width, height);
}
void tglDrawCircle(uint16_t x, uint16_t y, uint16_t radius, uint32_t c) {
if (_ts == NULL)
return;
if (_ts->screen == NULL)
return;
UG_DrawCircle(x, y, radius, c);
if(_tglInfo->autoUpdate)
_addArea(TGL_CIRCLE, x, y, radius, 0);
}
void tglDrawFillCircle(uint16_t x, uint16_t y, uint16_t radius, uint32_t c) {
if (_ts == NULL)
return;
if (_ts->screen == NULL)
return;
UG_FillCircle(x, y, radius, c);
if(_tglInfo->autoUpdate)
_addArea(TGL_CIRCLE, x, y, radius, 0);
}
void tglSetBgColor(uint32_t bg) {
UG_SetBackcolor(bg);
}
void tglSetFgColor(uint32_t fg) {
UG_SetForecolor(fg);
}
void tglDrawPutChar(char c, uint16_t x, uint16_t y, uint32_t fc, uint32_t bc, bool transparency) {
UG_PutChar(c, x, y, fc, bc, transparency);
}
void tglDrawPutString(uint16_t x, uint16_t y, char *text, uint32_t fc, uint32_t bc, bool transparency) {
UG_PutString(x, y, text, fc, bc, transparency);
}
void tglDrawMeshRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t c) {
UG_DrawMesh(x, y, (x + width), (y + height), c);
if(_tglInfo->autoUpdate)
_addArea(TGL_RECT, x, y, width, height);
}
void tglDrawArc( uint16_t x, uint16_t y, uint16_t radius, int sec, uint32_t c) {
UG_DrawArc(x, y, radius, sec, c);
if(_tglInfo->autoUpdate)
_addArea(TGL_ARC, x, y, radius, 0);
}
void tglDrawImage(uint16_t x, uint16_t y, TGLBITMAP *img, bool transparency) {
if (img == NULL)
return;
int width = tglImageGetWidth(img);
int height = tglImageGetHeight(img);
int bpp = tglImageGetLine(img) / tglImageGetWidth(img); // Bytes per pixel
int length = width * bpp; // number of bytes to copy
for (int y2 = 0; y2 < height; y2++, y++) {
if (transparency == false) {
unsigned char *p = tglScreenGetScanLine(y) + (x * bpp);
unsigned char *b = tglImageGetScanLine(img, y2);
memcpy(p, b, length);
} else {
unsigned int *p = (unsigned int *)(tglScreenGetScanLine(y) + (x * bpp));
unsigned int *b = (unsigned int *)tglImageGetScanLine(img, y2);
for (int i = 0; i < width; i++, p++, b++) {
if (*b)
*p = *b;
}
}
}
if(_tglInfo->autoUpdate)
_addArea(TGL_IMAGE, x, y, width, height);
}
// xs and ys are the starting position, width and height are the images width and height
void tglDrawVideoImage(TglWidget *tw, TGLBITMAP *img) {
if (_ts == NULL)
return;
if (_ts->screen == NULL)
return;
if (tw == NULL)
return;
int screenWidth = tglScreenGetWidth();
int bytespp = tglScreenGetLine() / screenWidth;
unsigned char *p = FreeImage_GetBits((FIBITMAP *)img);
int bpp = tglImageGetLine(img) / tglImageGetWidth(img);
for (int y = tw->y; y < (tw->y + tw->height); y++) {
BYTE *bits = tglScreenGetScanLine(y);
if (tw->x > 0)
bits += (bytespp * tw->x);
for (int x = tw->x; x < (tw->x + tw->width); x++) {
bits[FI_RGBA_RED] = p[FI_RGBA_RED];
bits[FI_RGBA_GREEN] = p[FI_RGBA_GREEN];
bits[FI_RGBA_BLUE] = p[FI_RGBA_BLUE];
if (bpp > 3)
bits[FI_RGBA_ALPHA] = p[FI_RGBA_ALPHA];
p += bpp;
bits += bytespp;
}
}
if(_tglInfo->autoUpdate) {
_addArea(TGL_IMAGE, tw->x, tw->y, tw->width, tw->height);
}
}