-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfgui.c
118 lines (99 loc) · 2.44 KB
/
fgui.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
/*
FemtoGUI
fgui.c:
Main code
copyright:
Copyright (c) 2006-2008 Bastiaan van Kesteren <[email protected]>
This program comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
remarks:
*/
#include "fgui.h"
#define FGUI_CODE
#include "fgui_helper.h"
fgui_t fgui;
char fgui_init(unsigned char *framebuffer)
/*
Set console parameters and initialise the screen by calling screen_init().
Returncode is the result of screen_init(), which should be '1' on success
*/
{
fgui.fb = framebuffer;
fgui.fgcolor = FGUI_BLACK;
return screen_init();
}
void fgui_clear()
/*
Clear framebuffer.
*/
{
unsigned int i;
/* clear the buffer */
for(i=0;i<FGUI_FBSIZE;i++) {
fgui.fb[i]=~fgui.fgcolor;
}
}
char fgui_refresh()
/*
Update screen (as in, write contents of buffer to the screen).
Returncode is the result of screen_update(), which should be '1' on success
*/
{
return screen_update(fgui.fb);
}
void fgui_setcolor(const unsigned char newcolor)
/*
Set the foregroundcolor to use
*/
{
if(newcolor == FGUI_BLACK || newcolor == FGUI_WHITE) {
fgui.fgcolor = newcolor;
}
}
unsigned char fgui_getcolor()
/*
Return the current foregroundcolor
*/
{
return fgui.fgcolor;
}
void fgui_invertcolor()
/*
Invert colors
*/
{
fgui.fgcolor = ~fgui.fgcolor;
}
/*
Pixel functions
*/
void fgui_pixelon(const unsigned int x, const unsigned int y)
/*
Turn pixel at location x,y on (foreground color)
*/
{
fgui_pixel(x,y,fgui.fgcolor);
}
void fgui_pixeloff(const unsigned int x, const unsigned int y)
/*
Turn pixel at location x,y off (background color)
*/
{
fgui_pixel(x,y,~fgui.fgcolor);
}
void fgui_pixel(const unsigned int x, const unsigned int y, const unsigned char value)
/*
Set pixel at location x,y on (value == FGUI_BLACK) or off (value == FGUI_WHITE)
*/
{
if(x < FGUI_SCR_W && y < FGUI_SCR_H) {
if(value == FGUI_BLACK) {
fgui.fb[y*FGUI_SCR_BYTEW + bitstobytesdown(x)] |= 1<<(7-(x%8));
}
else if(value == FGUI_WHITE) {
fgui.fb[y*FGUI_SCR_BYTEW + bitstobytesdown(x)] &= ~(1<<(7-(x%8)));
}
}
}