- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraphics.c
More file actions
Latest commit
116 lines (99 loc) · 3.35 KB
/
Copy pathgraphics.c
File metadata and controls
116 lines (99 loc) · 3.35 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
#include"draw.h"
// Back Buffer in RAM memory to prevent screen tearing/flicker
uint32_tback_buffer[SCREEN_WIDTH*SCREEN_HEIGHT];
// Hardware VESA Framebuffer address pointing to physical GPU VRAM
uint32_t*gpu_framebuffer= (uint32_t*) 0xFD000000;
// Embedded $8 \times 8$ Font Bitmap Data for basic ASCII rendering
externconstuint8_tfont8x8_basic[128][8];
/**
* @brief Draws a single color pixel to the back buffer
*/
voiddraw_pixel(intx, inty, uint32_tcolor) {
if (x >= 0&&x<SCREEN_WIDTH&&y >= 0&&y<SCREEN_HEIGHT) {
back_buffer[y*SCREEN_WIDTH+x] =color;
}
}
/**
* @brief Draws a filled solid rectangle
*/
voiddraw_rect(intx, inty, intwidth, intheight, uint32_tcolor) {
for (inti=0; i<height; i++) {
for (intj=0; j<width; j++) {
draw_pixel(x+j, y+i, color);
}
}
}
/**
* @brief Draws a hollow rectangular border outline
*/
voiddraw_rect_outline(intx, inty, intwidth, intheight, uint32_tcolor) {
for (intj=0; j<width; j++) {
draw_pixel(x+j, y, color); // Top border
draw_pixel(x+j, y+height-1, color); // Bottom border
}
for (inti=0; i<height; i++) {
draw_pixel(x, y+i, color); // Left border
draw_pixel(x+width-1, y+i, color); // Right border
}
}
/**
* @brief Draws a single character using an 8x8 bitmap font
*/
voiddraw_char(intx, inty, charc, uint32_tcolor) {
uint8_tascii_index= (uint8_t)c;
if (ascii_index>127) return;
for (introw=0; row<8; row++) {
uint8_tbyte=font8x8_basic[ascii_index][row];
for (intcol=0; col<8; col++) {
if (byte& (1 << col)) {
draw_pixel(x+col, y+row, color);
}
}
}
}
/**
* @brief Renders a full text string
*/
voiddraw_string(intx, inty, constchar*str, uint32_tcolor) {
intcur_x=x;
intcur_y=y;
for (size_ti=0; str[i] !='\0'; i++) {
if (str[i] =='\n') {
cur_x=x;
cur_y+=10; // Move to next line (8 pixels height + 2 padding)
} else {
draw_char(cur_x, cur_y, str[i], color);
cur_x+=8; // Move character cursor 8 pixels right
}
}
}
/**
* @brief Renders a complete Windows XP style application window frame
*/
voiddraw_window(intx, inty, intwidth, intheight, constchar*title) {
// 1. Draw Main Window Background
draw_rect(x, y, width, height, COLOR_LIGHT_GRAY);
// 2. Draw 3D Window Outer Border Outline
draw_rect_outline(x, y, width, height, COLOR_DARK_GRAY);
// 3. Draw Top Title Bar Header
draw_rect(x+2, y+2, width-4, 20, COLOR_XP_BLUE);
// 4. Render Window Title Text
draw_string(x+8, y+6, title, COLOR_WHITE);
// 5. Draw Top-Right Close Button ('X')
draw_rect(x+width-20, y+4, 16, 16, COLOR_RED);
draw_char(x+width-15, y+8, 'X', COLOR_WHITE);
}
/**
* @brief Fills the entire screen back buffer with a solid background color
*/
voidclear_screen(uint32_tcolor) {
draw_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color);
}
/**
* @brief Copies the completed back buffer frame to physical GPU memory
*/
voidswap_buffers(void) {
for (uint32_ti=0; i<SCREEN_WIDTH*SCREEN_HEIGHT; i++) {
gpu_framebuffer[i] =back_buffer[i];
}
}