19
|
1 /*********************************************
|
|
2 * Description - Based Term Grx
|
|
3 * Modified for use with Harelet.
|
|
4 * Author - William King
|
|
5 * Date - Sep 13 2023
|
|
6 * *******************************************/
|
|
7
|
|
8 #include <string.h>
|
|
9
|
|
10 //Always have a 2:1 ratio if you want a square picture
|
|
11 //Terminals are vertically stretched
|
|
12 #define RESX 98
|
|
13 #define RESY 48
|
|
14
|
|
15 //Center X & Y
|
|
16 #define CX 49
|
|
17 #define CY 24
|
|
18
|
|
19 //Colours
|
|
20 #define BLACK "\x1b[30m"
|
|
21 #define RED "\x1b[31m"
|
|
22 #define GREEN "\x1b[32m"
|
|
23 #define YELLOW "\x1b[33m"
|
|
24 #define BLUE "\x1b[34m"
|
|
25 #define MAGENTA "\x1b[35m"
|
|
26 #define CYAN "\x1b[36m"
|
|
27 #define WHITE "\x1b[37m"
|
|
28
|
|
29 #define IBLACK "\x1b[30;1m"
|
|
30 #define IRED "\x1b[31;1m"
|
|
31 #define IGREEN "\x1b[32;1m"
|
|
32 #define IYELLOW "\x1b[33;1m"
|
|
33 #define IBLUE "\x1b[34;1m"
|
|
34 #define IMAGENTA "\x1b[35;1m"
|
|
35 #define ICYAN "\x1b[36;1m"
|
|
36 #define IWHITE "\x1b[37;1m"
|
|
37
|
|
38 #define BGC_BLACK "\x1b[40m"
|
|
39 #define BGC_RED "\x1b[41m"
|
|
40 #define BGC_GREEN "\x1b[42m"
|
|
41 #define BGC_YELLOW "\x1b[43m"
|
|
42 #define BGC_BLUE "\x1b[44m"
|
|
43 #define BGC_MAGENTA "\x1b[45m"
|
|
44 #define BGC_CYAN "\x1b[46m"
|
|
45 #define BGC_WHITE "\x1b[47m"
|
|
46
|
|
47 #define BGC_IBLACK "\x1b[40;1m"
|
|
48 #define BGC_IRED "\x1b[41;1m"
|
|
49 #define BGC_IGREEN "\x1b[42;1m"
|
|
50 #define BGC_IYELLOW "\x1b[43;1m"
|
|
51 #define BGC_IBLUE "\x1b[44;1m"
|
|
52 #define BGC_IMAGENTA "\x1b[45;1m"
|
|
53 #define BGC_ICYAN "\x1b[46;1m"
|
|
54 #define BGC_IWHITE "\x1b[47;1m"
|
|
55
|
|
56 char screen[RESY][RESX];
|
|
57
|
|
58
|
|
59 /*********************************************
|
|
60 * Description - Clear the screen
|
|
61 * Author - William King
|
|
62 * Date - Sep 13 2023
|
|
63 * *******************************************/
|
|
64 void ClrScr(){
|
|
65 //printf("\x1b[2J");
|
|
66 for(int i = 0; i != 32;i++)
|
|
67 puts("");
|
|
68
|
|
69 for(int i = 0; i != RESY; i++){
|
|
70
|
|
71 for(int j = 0; j != RESX; j++){
|
|
72
|
|
73 screen[i][j] = ' ';
|
|
74
|
|
75 }
|
|
76
|
|
77
|
|
78 }
|
|
79
|
|
80
|
|
81 }
|
|
82
|
|
83 /*********************************************
|
|
84 * Description - Render all the cells to the screen, splashing
|
|
85 * Author - William King
|
|
86 * Date - Sep 13 2023
|
|
87 * *******************************************/
|
|
88 void Splash(){
|
|
89 puts("");
|
|
90 for(int i = 0; i != RESY; i++){
|
|
91
|
|
92 for(int j = 0; j != RESX; j++){
|
|
93
|
|
94 printf("%c",screen[j][i]);
|
|
95
|
|
96 }
|
|
97
|
|
98 puts("");
|
|
99
|
|
100 }
|
|
101
|
|
102
|
|
103 }
|
|
104
|
|
105 /*********************************************
|
|
106 * Description - Put a character onto the screen
|
|
107 * Author - William King
|
|
108 * Date - Sep 13 2023
|
|
109 * *******************************************/
|
|
110 void DrawChar(int x, int y, char content){
|
|
111 //Make sure it's in the screen
|
|
112 assert(x <= RESX && y <= RESY);
|
|
113
|
|
114 screen[x][y] = content;
|
|
115 }
|
|
116
|
|
117 /*********************************************
|
|
118 * Description - Put a string onto the screen
|
|
119 * Author - William King
|
|
120 * Date - Sep 13 2023
|
|
121 * *******************************************/
|
|
122 void DrawString(int x, int y, char str[128]){
|
|
123
|
|
124 //Make sure origin is in the screen
|
|
125 assert(x <= RESX || y <= RESY);
|
|
126
|
|
127 //Make sure the string wont run off the screen
|
|
128 assert(x + strlen(str) <= RESX);
|
|
129
|
|
130 for(int i; i != strlen(str);i++){
|
|
131
|
|
132 DrawChar(x+i,y,str[i]);
|
|
133
|
|
134 }
|
|
135
|
|
136
|
|
137 }
|
|
138
|
|
139
|
|
140 /*********************************************
|
|
141 * Description - Draw a square
|
|
142 * Author - William King
|
|
143 * Date - Sep 13 2023
|
|
144 * *******************************************/
|
|
145 void DrawSquare(int x, int y, int length, char fill){
|
|
146
|
|
147 //Make sure shape is not ridiculous
|
|
148 assert(x <= RESX && y <= RESY);
|
|
149 assert(x+length <= RESX && y+length <= RESY);
|
|
150
|
|
151 for(int i = 0; i != length;i++){
|
|
152
|
|
153 int j = 0;
|
|
154 while (j != 0){
|
|
155 DrawChar(x+j,y+i,fill);
|
|
156 j++;
|
|
157 }
|
|
158
|
|
159 }
|
|
160
|
|
161
|
|
162 }
|
|
163
|
|
164
|
|
165 /*********************************************
|
|
166 * Description - Fill the entire screen with a character
|
|
167 * Author - William King
|
|
168 * Date - Sep 15 2023
|
|
169 * *******************************************/
|
|
170 void DrawFill(char fill){
|
|
171 for(int i = 0; i != RESY; i++){
|
|
172 for(int j = 0; j != RESX; j++){
|
|
173 screen[i][j] = fill;
|
|
174
|
|
175 }
|
|
176 }
|
|
177
|
|
178 }
|
|
179
|
|
180
|
|
181
|
|
182 /*********************************************
|
|
183 * Description - Set the colour
|
|
184 * Author - William King
|
|
185 * Date - Sep 13 2023
|
|
186 * *******************************************/
|
|
187 void SetColour(char * colour){
|
|
188 printf("%s",colour);
|
|
189 }
|
|
190
|
|
191
|
|
192 /*********************************************
|
|
193 * Description - Reset the colour
|
|
194 * Author - William King
|
|
195 * Date - Sep 13 2023
|
|
196 * *******************************************/
|
|
197 void ResetColour(char * colour){
|
|
198 printf("\x1b[0m");
|
|
199 }
|