💾 Archived View for gmi.noulin.net › gitRepositories › heartbeat › file › shpPackages › termbox › mi… captured on 2024-06-20 at 11:55:56. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
mika.c (9470B)
1 #! /usr/bin/env sheepy 2 /* or direct path to sheepy: #! /usr/local/bin/sheepy */ 3 4 /* Libsheepy documentation: https://spartatek.se/libsheepy/ */ 5 #include "libsheepyObject.h" 6 #include "termbox.h" 7 #include <stdarg.h> 8 9 int argc; char **argv; 10 11 /* enable/disable logging */ 12 /* #undef pLog */ 13 /* #define pLog(...) */ 14 15 typ struct { 16 bool quit; 17 u32 onCount; 18 } contextt; 19 20 typ struct { 21 u32 x; 22 u32 y; 23 u32 width; 24 u32 height; 25 u32 color; 26 char line[2048]; 27 } bubblet; 28 29 bubblet bub[300] = init0Var; 30 31 void print_tb(const char *str, int x, int y, uint16_t fg, uint16_t bg) 32 { 33 while (*str) { 34 uint32_t uni; 35 str += tb_utf8_char_to_unicode(&uni, str); 36 tb_change_cell(x, y, uni, fg, bg); 37 x++; 38 } 39 } 40 41 void printf_tb(int x, int y, uint16_t fg, uint16_t bg, const char *fmt, ...) 42 { 43 char buf[4096]; 44 va_list vl; 45 va_start(vl, fmt); 46 vsnprintf(buf, sizeof(buf), fmt, vl); 47 va_end(vl); 48 print_tb(buf, x, y, fg, bg); 49 } 50 51 // tb_width(void); 52 // tb_height(void); 53 void showStuff(void *ct) { 54 cast(contextt*,ctx,ct); 55 56 u32 idx = 0; 57 // one bubble 58 bub[idx].x = 0; 59 bub[idx].y = tb_height()-1; 60 bub[idx].width = 20; 61 bub[idx].height = 10; 62 bub[idx].color = 0xFFFFFF; 63 range(i, bub[idx].width) { 64 bub[idx].line[i] = 'd'; 65 } 66 bub[idx].line[bub[idx].width] = 0; 67 // end bubble 68 // one bubble 69 inc idx; 70 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 71 bub[idx].y = tb_height()-1; 72 bub[idx].width = 30; 73 bub[idx].height = 10; 74 bub[idx].color = 0xFFAAAA; 75 range(i, bub[idx].width) { 76 bub[idx].line[i] = 'd'; 77 } 78 bub[idx].line[bub[idx].width] = 0; 79 // end bubble 80 // one bubble 81 inc idx; 82 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 83 bub[idx].y = tb_height()-1; 84 bub[idx].width = 10; 85 bub[idx].height = 10; 86 bub[idx].color = 0xAAFFAA; 87 range(i, bub[idx].width) { 88 bub[idx].line[i] = 'd'; 89 } 90 bub[idx].line[bub[idx].width] = 0; 91 // end bubble 92 // one bubble 93 inc idx; 94 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 95 bub[idx].y = tb_height()-1; 96 bub[idx].width = 5; 97 bub[idx].height = 10; 98 bub[idx].color = 0xAAAAFF; 99 range(i, bub[idx].width) { 100 bub[idx].line[i] = 'd'; 101 } 102 bub[idx].line[bub[idx].width] = 0; 103 // end bubble 104 // one bubble 105 inc idx; 106 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 107 bub[idx].y = tb_height()-1; 108 bub[idx].width = 15; 109 bub[idx].height = 10; 110 bub[idx].color = 0x8888FF; 111 range(i, bub[idx].width) { 112 bub[idx].line[i] = 'd'; 113 } 114 bub[idx].line[bub[idx].width] = 0; 115 // end bubble 116 // one bubble 117 inc idx; 118 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 119 bub[idx].y = tb_height()-1; 120 bub[idx].width = 15; 121 bub[idx].height = 10; 122 bub[idx].color = 0xFFFFFF; 123 range(i, bub[idx].width) { 124 bub[idx].line[i] = 'd'; 125 } 126 bub[idx].line[bub[idx].width] = 0; 127 // end bubble 128 // one bubble 129 inc idx; 130 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 131 bub[idx].y = tb_height()-1; 132 bub[idx].width = 15; 133 bub[idx].height = 10; 134 bub[idx].color = 0xFF8888; 135 range(i, bub[idx].width) { 136 bub[idx].line[i] = 'd'; 137 } 138 bub[idx].line[bub[idx].width] = 0; 139 // end bubble 140 // one bubble 141 inc idx; 142 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 143 bub[idx].y = tb_height()-1; 144 bub[idx].width = 15; 145 bub[idx].height = 10; 146 bub[idx].color = 0x8888FF; 147 range(i, bub[idx].width) { 148 bub[idx].line[i] = 'd'; 149 } 150 bub[idx].line[bub[idx].width] = 0; 151 // end bubble 152 // one bubble 153 inc idx; 154 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 155 bub[idx].y = tb_height()-1; 156 bub[idx].width = 10; 157 bub[idx].height = 10; 158 bub[idx].color = 0xFFFF88; 159 range(i, bub[idx].width) { 160 bub[idx].line[i] = 'd'; 161 } 162 bub[idx].line[bub[idx].width] = 0; 163 // end bubble 164 // one bubble 165 inc idx; 166 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 167 bub[idx].y = tb_height()-1; 168 bub[idx].width = 10; 169 bub[idx].height = 10; 170 bub[idx].color = 0xFF88FF; 171 range(i, bub[idx].width) { 172 bub[idx].line[i] = 'd'; 173 } 174 bub[idx].line[bub[idx].width] = 0; 175 // end bubble 176 // one bubble 177 inc idx; 178 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 179 bub[idx].y = tb_height()-1; 180 bub[idx].width = 10; 181 bub[idx].height = 10; 182 bub[idx].color = 0x88FFFF; 183 range(i, bub[idx].width) { 184 bub[idx].line[i] = 'd'; 185 } 186 bub[idx].line[bub[idx].width] = 0; 187 // end bubble 188 // one bubble 189 inc idx; 190 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 191 bub[idx].y = tb_height()-1; 192 bub[idx].width = 10; 193 bub[idx].height = 10; 194 bub[idx].color = 0xFFAA55; 195 range(i, bub[idx].width) { 196 bub[idx].line[i] = 'd'; 197 } 198 bub[idx].line[bub[idx].width] = 0; 199 // end bubble 200 // one bubble 201 inc idx; 202 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 203 bub[idx].y = tb_height()-1; 204 bub[idx].width = 10; 205 bub[idx].height = 10; 206 bub[idx].color = 0x55AAFF; 207 range(i, bub[idx].width) { 208 bub[idx].line[i] = 'd'; 209 } 210 bub[idx].line[bub[idx].width] = 0; 211 // end bubble 212 // one bubble 213 inc idx; 214 bub[idx].x = 4; 215 bub[idx].y = tb_height()-1; 216 bub[idx].width = 10; 217 bub[idx].height = 20; 218 bub[idx].color = 0x55FFAA; 219 range(i, bub[idx].width) { 220 bub[idx].line[i] = 'd'; 221 } 222 bub[idx].line[bub[idx].width] = 0; 223 // end bubble 224 // one bubble 225 inc idx; 226 bub[idx].x = bub[idx-1].width + bub[idx-1].x + 10; 227 bub[idx].y = tb_height()-1; 228 bub[idx].width = 10; 229 bub[idx].height = 20; 230 bub[idx].color = 0xFFCCAA; 231 range(i, bub[idx].width) { 232 bub[idx].line[i] = 'd'; 233 } 234 bub[idx].line[bub[idx].width] = 0; 235 // end bubble 236 // one bubble 237 inc idx; 238 bub[idx].x = bub[idx-1].width + bub[idx-1].x + 15; 239 bub[idx].y = tb_height()-1; 240 bub[idx].width = 10; 241 bub[idx].height = 20; 242 bub[idx].color = 0xFF99AA; 243 range(i, bub[idx].width) { 244 bub[idx].line[i] = 'd'; 245 } 246 bub[idx].line[bub[idx].width] = 0; 247 // end bubble 248 // one bubble 249 inc idx; 250 bub[idx].x = bub[idx-1].width + bub[idx-1].x + 5; 251 bub[idx].y = tb_height()-1; 252 bub[idx].width = 10; 253 bub[idx].height = 20; 254 bub[idx].color = 0x44EEAA; 255 range(i, bub[idx].width) { 256 bub[idx].line[i] = 'd'; 257 } 258 bub[idx].line[bub[idx].width] = 0; 259 // end bubble 260 // one bubble 261 inc idx; 262 bub[idx].x = bub[idx-1].width + bub[idx-1].x + 5; 263 bub[idx].y = tb_height()-1; 264 bub[idx].width = 40; 265 bub[idx].height = 20; 266 bub[idx].color = 0x661100; 267 range(i, bub[idx].width) { 268 bub[idx].line[i] = 'd'; 269 } 270 bub[idx].line[bub[idx].width] = 0; 271 // end bubble 272 // one bubble 273 inc idx; 274 bub[idx].x = bub[idx-1].width + bub[idx-1].x + 5; 275 bub[idx].y = tb_height()-1; 276 bub[idx].width = 40; 277 bub[idx].height = 20; 278 bub[idx].color = 0x002211; 279 range(i, bub[idx].width) { 280 bub[idx].line[i] = 'd'; 281 } 282 bub[idx].line[bub[idx].width] = 0; 283 // end bubble 284 // one bubble 285 inc idx; 286 bub[idx].x = 0; 287 bub[idx].y = tb_height()-1; 288 bub[idx].width = 80; 289 bub[idx].height = 40; 290 bub[idx].color = 0x000000; 291 range(i, bub[idx].width) { 292 bub[idx].line[i] = 'd'; 293 } 294 bub[idx].line[bub[idx].width] = 0; 295 // end bubble 296 // one bubble 297 inc idx; 298 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 299 bub[idx].y = tb_height()-1; 300 bub[idx].width = 80; 301 bub[idx].height = 40; 302 bub[idx].color = 0x000011; 303 range(i, bub[idx].width) { 304 bub[idx].line[i] = 'd'; 305 } 306 bub[idx].line[bub[idx].width] = 0; 307 // end bubble 308 // one bubble 309 inc idx; 310 bub[idx].x = bub[idx-1].width + bub[idx-1].x; 311 bub[idx].y = tb_height()-1; 312 bub[idx].width = 20; 313 bub[idx].height = 40; 314 bub[idx].color = 0x000000; 315 range(i, bub[idx].width) { 316 bub[idx].line[i] = 'd'; 317 } 318 bub[idx].line[bub[idx].width] = 0; 319 // end bubble 320 321 forever { 322 if (ctx->onCount > idx+1) { 323 tb_clear(); 324 //tb_present(); 325 ctx->onCount = 0; 326 } 327 range(i, ctx->onCount) { 328 u32 delta = bub[i].color / (bub[i].height-1); 329 range(h, bub[i].height) { 330 if (bub[i].y+h >= tb_height()) break; 331 //tb_stringf(bub[i].x, bub[i].y+h, bub[i].color, bub[i].color, bub[i].line); 332 tb_stringf(bub[i].x, bub[i].y+h, bub[i].color/(h+1), bub[i].color/(h+1), bub[i].line); 333 //tb_stringf(bub[i].x, bub[i].y+h, bub[i].color + delta*h, bub[i].color + delta*h, bub[i].line); 334 } 335 tb_present(); 336 dec bub[i].y; 337 if (bub[i].y == 0) { 338 bub[i].y = tb_height()-1; 339 } 340 } 341 msSleep(500); 342 if (ctx->quit) break; 343 } 344 } 345 346 int main(int ARGC, char** ARGV) { 347 348 argc = ARGC; argv = ARGV; 349 350 initLibsheepy(ARGV[0]); 351 setLogMode(LOG_FUNC); 352 //openProgLogFile(); 353 //setLogSymbols(LOG_UTF8); 354 //disableLibsheepyErrorLogs; 355 356 int r = tb_init(); 357 if (r) { 358 logE("tb_init() failed with error code %d\n", r); 359 XFailure; 360 } 361 362 tb_select_output_mode(TB_OUTPUT_TRUECOLOR); 363 364 //tb_set_cursor(0,0); 365 366 void draw_all(void) { 367 tb_clear(); 368 //tb_change_cell(/*x*/ 2, /*y*/ 2, '@', TB_GREEN, TB_WHITE | TB_BOLD); 369 tb_present(); 370 } 371 372 draw_all(); 373 374 contextt ctx = init0Var; 375 376 tpoolAdd(showStuff, &ctx); 377 struct tb_event ev; 378 while (tb_poll_event(&ev)) { 379 switch (ev.type) { 380 case TB_EVENT_KEY: 381 switch (ev.key) { 382 /* case TB_KEY_ESC: */ 383 /* ctx.quit = yes; */ 384 /* goto done; */ 385 /* break; */ 386 case TB_KEY_SPACE: 387 ctx.onCount++; 388 break; 389 } 390 if (ev.ch == 'q') { 391 ctx.quit = yes; 392 goto done; 393 } 394 395 //tb_stringf(2, 30, TB_WHITE, TB_DEFAULT, "key code: %5d, char: %5d, mod: %5d", ev.key, ev.ch, ev.mod); 396 break; 397 case TB_EVENT_RESIZE: 398 draw_all(); 399 break; 400 } 401 tb_present(); 402 } 403 404 done: 405 tpoolWait; 406 tb_shutdown(); 407 XSuccess; 408 } 409 // vim: set expandtab ts=2 sw=2: