forked from g4eml/Langstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphics.h
More file actions
225 lines (190 loc) · 4.29 KB
/
Copy pathGraphics.h
File metadata and controls
225 lines (190 loc) · 4.29 KB
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
224
225
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "Font.h"
char *fbp = 0;
int fbfd = 0;
long int screenSize = 0;
int screenXsize=0;
int screenYsize=0;
int currentX=0;
int currentY=0;
int textSize=1;
int foreColourR=0;
int foreColourG=0;
int foreColourB=0;
int backColourR=0;
int backColourG=0;
int backColourB=0;
void closeScreen(void);
int initScreen(void);
void setPixel(int x, int y, int R, int G, int B);
void clearScreen();
void displayChar(int ch);
void setLargePixel(int x, int y, int size, int R, int G, int B);
void gotoXY(int x, int y);
void setForeColour(int R,int G,int B);
void setBackColour(int R,int G,int B);
void displayStr(char*s);
void displayButton(char*s);
void drawLine(int x0, int y0, int x1, int y1,int r,int g,int b);
void displayStr(char*s)
{
int p;
p=0;
do
{
displayChar(s[p++]);
}
while(s[p]!=0);
}
void displayChar(int ch)
{
int row;
int col;
int pix;
for(row=0;row<9;row++)
{
pix=font[ch][row];
for(col=0;col<8;col++)
{
if((pix << col) & 0x80)
{
setLargePixel(currentX+col*textSize,currentY+row*textSize,textSize,foreColourR,foreColourG,foreColourB);
}
else
{
setLargePixel(currentX+col*textSize,currentY+row*textSize,textSize,backColourR,backColourG,backColourG);
}
}
}
currentX=currentX+8*textSize;
}
void displayButton(char*s)
{
int saveX=currentX;
int saveY=currentY;
for(int x=0;x<100;x++)
{
setPixel(currentX+x,currentY,foreColourR,foreColourG,foreColourB);
setPixel(currentX+x,currentY+50,foreColourR,foreColourG,foreColourB);
}
for(int y=0;y<50;y++)
{
setPixel(currentX,currentY+y,foreColourR,foreColourG,foreColourB);
setPixel(currentX+100,currentY+y,foreColourR,foreColourG,foreColourB);
}
gotoXY(currentX+1,currentY+18);
textSize=2;
displayStr(" ");
currentX=saveX;
int sx=50-((strlen(s)*16)/2);
gotoXY(currentX+sx,currentY);
textSize=2;
displayStr(s);
currentX=saveX+105;
currentY=saveY;
}
void gotoXY(int x, int y)
{
currentX=x;
currentY=y;
}
void setForeColour(int R,int G,int B)
{
foreColourR=R;
foreColourG=G;
foreColourB=B;
}
void setBackColour(int R,int G,int B)
{
backColourR=R;
backColourG=G;
backColourB=B;
}
void clearScreen()
{
for(int y=0;y<screenYsize;y++)
{
for(int x=0;x<screenXsize;x++)
{
setPixel(x,y,backColourR,backColourG,backColourB);
}
}
}
void setPixel(int x, int y, int R, int G, int B)
{
if((x<800)&(y<480))
{
int p=(x+screenXsize*y)*4;
memset(fbp+p,B,1); //Blue
memset(fbp+p+1,G,1); //Green
memset(fbp+p+2,R,1); //Red
memset(fbp+p+3,0x80,1); //A
}
}
void drawLine(int x0, int y0, int x1, int y1,int r,int g,int b) {
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
for(;;){
setPixel(x0,y0,r,g,b);
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
}
void setLargePixel(int x, int y, int size, int R, int G, int B)
{
for (int px=0;px<size;px++)
{
for(int py=0;py<size;py++)
{
setPixel(x+px,y+py,R,G,B);
}
}
}
void closeScreen(void)
{
munmap(fbp, screenSize);
close(fbfd);
}
int initScreen(void)
{
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
fbfd = open("/dev/fb0", O_RDWR);
if (!fbfd)
{
printf("Error: cannot open framebuffer device.\n");
return(0);
}
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo))
{
printf("Error reading fixed information.\n");
return(0);
}
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo))
{
printf("Error reading variable information.\n");
return(0);
}
screenXsize=vinfo.xres;
screenYsize=vinfo.yres;
screenSize = finfo.smem_len;
fbp = (char*)mmap(0, screenSize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
if ((int)fbp == -1)
{
return 0;
}
else
{
return 1;
}
}