annotate based/basedtermgrx.h @ 21:44e906aeea91 default tip

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