| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/OSGEN.C,v 1.3 1999/07/11 00:46:30 MJRoberts Exp $"; |
| 4 |
#endif |
| 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 |
#define OSGEN_INIT |
| 83 |
# include "os.h" |
| 84 |
#undef OSGEN_INIT |
| 85 |
|
| 86 |
#include "osgen.h" |
| 87 |
|
| 88 |
#include <stdio.h> |
| 89 |
#include <stdlib.h> |
| 90 |
#include <string.h> |
| 91 |
#include <stdarg.h> |
| 92 |
#include <ctype.h> |
| 93 |
#include <assert.h> |
| 94 |
|
| 95 |
#include "run.h" |
| 96 |
|
| 97 |
#if defined(TURBO) || defined(DJGPP) |
| 98 |
#include "io.h" |
| 99 |
#endif |
| 100 |
|
| 101 |
#include "lib.h" |
| 102 |
#include "tio.h" |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
int os_f_plain = 0; |
| 109 |
|
| 110 |
#ifdef RUNTIME |
| 111 |
# ifdef USE_SCROLLBACK |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
int G_oss_screen_width = 80; |
| 119 |
int G_oss_screen_height = 24; |
| 120 |
|
| 121 |
|
| 122 |
# endif |
| 123 |
#endif |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
#define OSGEN_ATTR 1 |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
#define OSGEN_COLOR 2 |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
#ifdef USE_OVWCHK |
| 155 |
int os_chkovw(char *filename) |
| 156 |
{ |
| 157 |
FILE *fp; |
| 158 |
|
| 159 |
if ((fp = fopen( filename, "r" )) != 0) |
| 160 |
{ |
| 161 |
char buf[128]; |
| 162 |
|
| 163 |
fclose(fp); |
| 164 |
os_printz("That file already exists. Overwrite it? (y/n) >"); |
| 165 |
os_gets((uchar *)buf, sizeof(buf)); |
| 166 |
if (buf[0] != 'y' && buf[0] != 'Y') |
| 167 |
return 1; |
| 168 |
} |
| 169 |
return 0; |
| 170 |
} |
| 171 |
#endif |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
void os_nonstop_mode(int flag) |
| 178 |
{ |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
#ifdef USE_STDIO |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
void os_printz(const char *str) |
| 196 |
{ |
| 197 |
fputs(str, stdout); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
void os_print(const char *str, size_t len) |
| 205 |
{ |
| 206 |
printf("%.*s", (int)len, str); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
void os_flush(void) |
| 215 |
{ |
| 216 |
fflush(stdout); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
void os_update_display(void) |
| 224 |
{ |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
uchar *os_gets(uchar *s, size_t bufl) |
| 235 |
{ |
| 236 |
|
| 237 |
fflush(stdout); |
| 238 |
|
| 239 |
|
| 240 |
return((uchar *)fgets((char *)s, bufl, stdin)); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
int os_gets_timeout(unsigned char *buf, size_t bufl, |
| 248 |
unsigned long timeout, int resume_editing) |
| 249 |
{ |
| 250 |
|
| 251 |
return OS_EVT_NOTIMEOUT; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
void os_gets_cancel(int reset) |
| 259 |
{ |
| 260 |
|
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
int os_get_event(unsigned long timeout, int use_timeout, |
| 268 |
os_event_info_t *info) |
| 269 |
{ |
| 270 |
|
| 271 |
if (use_timeout) |
| 272 |
return OS_EVT_NOTIMEOUT; |
| 273 |
|
| 274 |
|
| 275 |
info->key[0] = os_getc(); |
| 276 |
|
| 277 |
|
| 278 |
if (info->key[0] == 0) |
| 279 |
{ |
| 280 |
|
| 281 |
info->key[1] = os_getc(); |
| 282 |
|
| 283 |
|
| 284 |
if (info->key[1] == CMD_EOF) |
| 285 |
return OS_EVT_EOF; |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
return OS_EVT_KEY; |
| 290 |
} |
| 291 |
|
| 292 |
#endif |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
#ifdef USE_NULLINIT |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
int os_init(int *argc, char *argv[], const char *prompt, |
| 319 |
char *buf, int bufsiz) |
| 320 |
{ |
| 321 |
return 0; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
void os_uninit(void) |
| 328 |
{ |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
void os_term(int rc) |
| 337 |
{ |
| 338 |
exit(rc); |
| 339 |
} |
| 340 |
#endif |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
#ifdef USE_NULLPAUSE |
| 351 |
void os_expause(void) |
| 352 |
{ |
| 353 |
|
| 354 |
} |
| 355 |
#endif |
| 356 |
|
| 357 |
#ifdef USE_EXPAUSE |
| 358 |
void os_expause(void) |
| 359 |
{ |
| 360 |
os_printz("(Strike any key to exit...)"); |
| 361 |
os_flush(); |
| 362 |
os_waitc(); |
| 363 |
} |
| 364 |
#endif |
| 365 |
|
| 366 |
|
| 367 |
#ifdef USE_NULLSTAT |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
void os_status(int stat) |
| 372 |
{ |
| 373 |
|
| 374 |
} |
| 375 |
|
| 376 |
int os_get_status() |
| 377 |
{ |
| 378 |
return 0; |
| 379 |
} |
| 380 |
#endif |
| 381 |
|
| 382 |
#ifdef USE_NULLSCORE |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
void os_score(int cur, int turncount) |
| 387 |
{ |
| 388 |
|
| 389 |
} |
| 390 |
|
| 391 |
void os_strsc(const char *p) |
| 392 |
{ |
| 393 |
|
| 394 |
} |
| 395 |
#endif |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
typedef struct osgen_win_t osgen_win_t; |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
# ifdef USE_SCROLLBACK |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
typedef struct osgen_charcolor_t osgen_charcolor_t; |
| 417 |
struct osgen_charcolor_t |
| 418 |
{ |
| 419 |
|
| 420 |
char fg; |
| 421 |
|
| 422 |
|
| 423 |
char bg; |
| 424 |
}; |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
struct osgen_win_t |
| 431 |
{ |
| 432 |
|
| 433 |
int win_type; |
| 434 |
|
| 435 |
|
| 436 |
unsigned int flags; |
| 437 |
|
| 438 |
|
| 439 |
osgen_win_t *nxt; |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
osgen_win_t *parent; |
| 446 |
|
| 447 |
|
| 448 |
osgen_win_t *first_child; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
int alignment; |
| 456 |
|
| 457 |
|
| 458 |
int size_type; |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
int size; |
| 467 |
|
| 468 |
|
| 469 |
int winx; |
| 470 |
int winy; |
| 471 |
|
| 472 |
|
| 473 |
size_t wid; |
| 474 |
size_t ht; |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
int x; |
| 490 |
int y; |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
int xmax; |
| 498 |
int ymax; |
| 499 |
|
| 500 |
|
| 501 |
int scrollx; |
| 502 |
int scrolly; |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
char txtfg; |
| 509 |
char txtbg; |
| 510 |
|
| 511 |
|
| 512 |
int txtattr; |
| 513 |
|
| 514 |
|
| 515 |
char fillcolor; |
| 516 |
int oss_fillcolor; |
| 517 |
}; |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
typedef struct osgen_txtwin_t osgen_txtwin_t; |
| 533 |
struct osgen_txtwin_t |
| 534 |
{ |
| 535 |
|
| 536 |
osgen_win_t base; |
| 537 |
|
| 538 |
|
| 539 |
int solfg; |
| 540 |
int solbg; |
| 541 |
int solattr; |
| 542 |
|
| 543 |
|
| 544 |
char *txtbuf; |
| 545 |
size_t txtbufsiz; |
| 546 |
|
| 547 |
|
| 548 |
char *txtfree; |
| 549 |
|
| 550 |
|
| 551 |
char **line_ptr; |
| 552 |
size_t line_ptr_cnt; |
| 553 |
|
| 554 |
|
| 555 |
size_t first_line; |
| 556 |
|
| 557 |
|
| 558 |
size_t line_count; |
| 559 |
}; |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
typedef struct osgen_gridwin_t osgen_gridwin_t; |
| 574 |
struct osgen_gridwin_t |
| 575 |
{ |
| 576 |
|
| 577 |
osgen_win_t base; |
| 578 |
|
| 579 |
|
| 580 |
size_t grid_wid; |
| 581 |
size_t grid_ht; |
| 582 |
|
| 583 |
|
| 584 |
char *grid_txt; |
| 585 |
|
| 586 |
|
| 587 |
osgen_charcolor_t *grid_color; |
| 588 |
}; |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
#define OSGEN_AUTO_VSCROLL 0x0001 |
| 596 |
|
| 597 |
|
| 598 |
#define OSGEN_FULL 0x0002 |
| 599 |
|
| 600 |
|
| 601 |
#define OSGEN_DEFER_REDRAW 0x0004 |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
#define OSGEN_MOREMODE 0x0008 |
| 609 |
|
| 610 |
|
| 611 |
#define OSGEN_VSTRUT 0x0010 |
| 612 |
#define OSGEN_HSTRUT 0x0020 |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
static osfar_t osgen_txtwin_t *S_main_win = 0; |
| 619 |
|
| 620 |
|
| 621 |
static osfar_t osgen_txtwin_t *S_status_win = 0; |
| 622 |
|
| 623 |
|
| 624 |
static osfar_t osgen_txtwin_t *S_default_win = 0; |
| 625 |
|
| 626 |
|
| 627 |
static osfar_t osgen_txtwin_t *S_sbmode_win = 0; |
| 628 |
|
| 629 |
|
| 630 |
static osfar_t int S_sbmode_orig_scrolly; |
| 631 |
static osfar_t int S_sbmode_orig_x; |
| 632 |
static osfar_t char **S_sbmode_orig_last_line; |
| 633 |
static osfar_t char *S_sbmode_orig_txtfree; |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
static osfar_t int S_special_cursor_pos = FALSE; |
| 640 |
static osfar_t int S_special_cursor_x = 0; |
| 641 |
static osfar_t int S_special_cursor_y = 0; |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
static osfar_t int S_deferred_redraw = FALSE; |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
static osfar_t char S_gets_internal_buf[256]; |
| 657 |
static osfar_t char *S_gets_buf = S_gets_internal_buf; |
| 658 |
static osfar_t char *S_gets_buf_end = 0; |
| 659 |
static osfar_t size_t S_gets_buf_siz = sizeof(S_gets_internal_buf); |
| 660 |
static osfar_t int S_gets_ofs; |
| 661 |
static osfar_t char *S_gets_curhist; |
| 662 |
static osfar_t int S_gets_x, S_gets_y; |
| 663 |
|
| 664 |
# ifdef USE_HISTORY |
| 665 |
|
| 666 |
static osfar_t char S_hist_sav_internal[256]; |
| 667 |
static osfar_t char *S_hist_sav = S_hist_sav_internal; |
| 668 |
static osfar_t size_t S_hist_sav_siz = sizeof(S_hist_sav_internal); |
| 669 |
# endif |
| 670 |
|
| 671 |
|
| 672 |
extern void safe_strcpy(char *dst, size_t dstlen, const char *src); |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
static osfar_t int S_gets_in_progress = FALSE; |
| 686 |
|
| 687 |
|
| 688 |
static void osssb_add_color_code(osgen_txtwin_t *win); |
| 689 |
static void osgen_gridwin_clear(osgen_gridwin_t *win, size_t ofs, size_t len); |
| 690 |
static void osgen_redraw_win(osgen_win_t *win); |
| 691 |
static void osgen_scrdisp(osgen_win_t *win, int x, int y, int len); |
| 692 |
static void osgen_gets_redraw_cmdline(void); |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
static void osgen_delete_win(osgen_win_t *win) |
| 698 |
{ |
| 699 |
osgen_win_t *prv; |
| 700 |
osgen_win_t *cur; |
| 701 |
osgen_txtwin_t *twin; |
| 702 |
osgen_gridwin_t *gwin; |
| 703 |
|
| 704 |
|
| 705 |
if (win->parent != 0) |
| 706 |
{ |
| 707 |
|
| 708 |
for (prv = 0, cur = win->parent->first_child ; |
| 709 |
cur != 0 && cur != win ; |
| 710 |
prv = cur, cur = cur->nxt) ; |
| 711 |
|
| 712 |
|
| 713 |
if (cur != 0) |
| 714 |
{ |
| 715 |
|
| 716 |
if (prv == 0) |
| 717 |
win->parent->first_child = win->nxt; |
| 718 |
else |
| 719 |
prv->nxt = win->nxt; |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
for (cur = win->first_child ; cur != 0 ; cur = cur->nxt) |
| 729 |
cur->parent = 0; |
| 730 |
|
| 731 |
|
| 732 |
switch(win->win_type) |
| 733 |
{ |
| 734 |
case OS_BANNER_TYPE_TEXT: |
| 735 |
|
| 736 |
twin = (osgen_txtwin_t *)win; |
| 737 |
|
| 738 |
|
| 739 |
if (twin->txtbuf != 0) |
| 740 |
osfree(twin->txtbuf); |
| 741 |
|
| 742 |
|
| 743 |
if (twin->line_ptr != 0) |
| 744 |
osfree(twin->line_ptr); |
| 745 |
break; |
| 746 |
|
| 747 |
case OS_BANNER_TYPE_TEXTGRID: |
| 748 |
|
| 749 |
gwin = (osgen_gridwin_t *)win; |
| 750 |
|
| 751 |
|
| 752 |
if (gwin->grid_txt != 0) |
| 753 |
osfree(gwin->grid_txt); |
| 754 |
if (gwin->grid_color != 0) |
| 755 |
osfree(gwin->grid_color); |
| 756 |
break; |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
osfree(win); |
| 761 |
} |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
static void osgen_delete_win_tree(osgen_win_t *win) |
| 767 |
{ |
| 768 |
osgen_win_t *chi; |
| 769 |
osgen_win_t *nxt; |
| 770 |
|
| 771 |
|
| 772 |
for (chi = win->first_child ; chi != 0 ; chi = nxt) |
| 773 |
{ |
| 774 |
|
| 775 |
nxt = chi->nxt; |
| 776 |
|
| 777 |
|
| 778 |
osgen_delete_win_tree(chi); |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
osgen_delete_win(win); |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
static osgen_win_t *osgen_create_win(int win_type, int where, void *other, |
| 791 |
osgen_win_t *parent) |
| 792 |
{ |
| 793 |
osgen_win_t *win; |
| 794 |
osgen_win_t *prv; |
| 795 |
osgen_win_t *cur; |
| 796 |
size_t struct_siz; |
| 797 |
|
| 798 |
|
| 799 |
switch(win_type) |
| 800 |
{ |
| 801 |
case OS_BANNER_TYPE_TEXT: |
| 802 |
struct_siz = sizeof(osgen_txtwin_t); |
| 803 |
break; |
| 804 |
|
| 805 |
case OS_BANNER_TYPE_TEXTGRID: |
| 806 |
struct_siz = sizeof(osgen_gridwin_t); |
| 807 |
break; |
| 808 |
|
| 809 |
default: |
| 810 |
|
| 811 |
return 0; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
win = (osgen_win_t *)osmalloc(struct_siz); |
| 816 |
if (win == 0) |
| 817 |
return 0; |
| 818 |
|
| 819 |
|
| 820 |
win->win_type = win_type; |
| 821 |
|
| 822 |
|
| 823 |
win->nxt = 0; |
| 824 |
|
| 825 |
|
| 826 |
win->txtfg = OSGEN_COLOR_TEXT; |
| 827 |
win->txtbg = OSGEN_COLOR_TRANSPARENT; |
| 828 |
win->txtattr = 0; |
| 829 |
win->fillcolor = OSGEN_COLOR_TEXTBG; |
| 830 |
|
| 831 |
|
| 832 |
win->oss_fillcolor = ossgetcolor(OSGEN_COLOR_TEXT, OSGEN_COLOR_TEXTBG, |
| 833 |
0, 0); |
| 834 |
|
| 835 |
|
| 836 |
win->x = 0; |
| 837 |
win->y = 0; |
| 838 |
win->scrollx = 0; |
| 839 |
win->scrolly = 0; |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
win->winx = 0; |
| 847 |
win->winy = 0; |
| 848 |
|
| 849 |
|
| 850 |
win->xmax = 0; |
| 851 |
win->ymax = 0; |
| 852 |
|
| 853 |
|
| 854 |
win->flags = 0; |
| 855 |
|
| 856 |
|
| 857 |
win->parent = parent; |
| 858 |
|
| 859 |
|
| 860 |
win->first_child = 0; |
| 861 |
|
| 862 |
|
| 863 |
if (parent != 0) |
| 864 |
{ |
| 865 |
|
| 866 |
switch(where) |
| 867 |
{ |
| 868 |
case OS_BANNER_FIRST: |
| 869 |
|
| 870 |
win->nxt = parent->first_child; |
| 871 |
parent->first_child = win; |
| 872 |
break; |
| 873 |
|
| 874 |
case OS_BANNER_LAST: |
| 875 |
default: |
| 876 |
|
| 877 |
for (cur = parent->first_child ; cur != 0 && cur->nxt != 0 ; |
| 878 |
cur = cur->nxt) ; |
| 879 |
|
| 880 |
|
| 881 |
win->nxt = 0; |
| 882 |
if (cur != 0) |
| 883 |
cur->nxt = win; |
| 884 |
else |
| 885 |
parent->first_child = win; |
| 886 |
|
| 887 |
|
| 888 |
break; |
| 889 |
|
| 890 |
case OS_BANNER_BEFORE: |
| 891 |
case OS_BANNER_AFTER: |
| 892 |
|
| 893 |
for (prv = 0, cur = parent->first_child ; |
| 894 |
cur != 0 && cur != other ; |
| 895 |
prv = cur, cur = cur->nxt) ; |
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
if (cur == 0) |
| 905 |
where = OS_BANNER_BEFORE; |
| 906 |
|
| 907 |
|
| 908 |
if (where == OS_BANNER_AFTER) |
| 909 |
{ |
| 910 |
prv = cur; |
| 911 |
cur = cur->nxt; |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
win->nxt = cur; |
| 916 |
if (prv != 0) |
| 917 |
prv->nxt = win; |
| 918 |
else |
| 919 |
parent->first_child = win; |
| 920 |
|
| 921 |
|
| 922 |
break; |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
return win; |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
static osgen_txtwin_t *osgen_create_txtwin(int where, void *other, |
| 934 |
void *parent, |
| 935 |
unsigned int buf_size, |
| 936 |
unsigned int buf_lines) |
| 937 |
{ |
| 938 |
osgen_txtwin_t *win; |
| 939 |
|
| 940 |
|
| 941 |
win = (osgen_txtwin_t *)osgen_create_win(OS_BANNER_TYPE_TEXT, |
| 942 |
where, other, parent); |
| 943 |
|
| 944 |
|
| 945 |
if (win == 0) |
| 946 |
return 0; |
| 947 |
|
| 948 |
|
| 949 |
win->txtbufsiz = buf_size; |
| 950 |
win->txtbuf = (char *)osmalloc(buf_size); |
| 951 |
|
| 952 |
|
| 953 |
win->line_ptr_cnt = buf_lines; |
| 954 |
win->line_ptr = (char **)osmalloc(buf_lines * sizeof(char *)); |
| 955 |
|
| 956 |
|
| 957 |
if (win->txtbuf == 0 || win->line_ptr == 0) |
| 958 |
{ |
| 959 |
|
| 960 |
osgen_delete_win(&win->base); |
| 961 |
|
| 962 |
|
| 963 |
return 0; |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
win->txtfree = win->txtbuf; |
| 968 |
|
| 969 |
|
| 970 |
win->line_count = 1; |
| 971 |
|
| 972 |
|
| 973 |
win->first_line = 0; |
| 974 |
win->line_ptr[0] = win->txtbuf; |
| 975 |
|
| 976 |
|
| 977 |
win->solfg = win->base.txtfg; |
| 978 |
win->solbg = win->base.txtbg; |
| 979 |
win->solattr = win->base.txtattr; |
| 980 |
|
| 981 |
|
| 982 |
osssb_add_color_code(win); |
| 983 |
|
| 984 |
|
| 985 |
return win; |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
static osgen_gridwin_t *osgen_create_gridwin(int where, void *other, |
| 992 |
void *parent, |
| 993 |
int grid_wid, int grid_ht) |
| 994 |
{ |
| 995 |
osgen_gridwin_t *win; |
| 996 |
|
| 997 |
|
| 998 |
win = (osgen_gridwin_t *)osgen_create_win(OS_BANNER_TYPE_TEXTGRID, |
| 999 |
where, other, parent); |
| 1000 |
|
| 1001 |
|
| 1002 |
if (win == 0) |
| 1003 |
return 0; |
| 1004 |
|
| 1005 |
|
| 1006 |
win->grid_wid = grid_wid; |
| 1007 |
win->grid_ht = grid_ht; |
| 1008 |
win->grid_txt = (char *)osmalloc(grid_wid * grid_ht); |
| 1009 |
win->grid_color = (osgen_charcolor_t *)osmalloc( |
| 1010 |
grid_wid * grid_ht * sizeof(osgen_charcolor_t)); |
| 1011 |
|
| 1012 |
|
| 1013 |
if (win->grid_txt == 0 || win->grid_color == 0) |
| 1014 |
{ |
| 1015 |
|
| 1016 |
osgen_delete_win(&win->base); |
| 1017 |
|
| 1018 |
|
| 1019 |
return 0; |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
osgen_gridwin_clear(win, 0, win->grid_wid * win->grid_ht); |
| 1024 |
|
| 1025 |
|
| 1026 |
return win; |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
static void osgen_clear_win(osgen_win_t *win) |
| 1033 |
{ |
| 1034 |
osgen_txtwin_t *twin; |
| 1035 |
osgen_gridwin_t *gwin; |
| 1036 |
|
| 1037 |
|
| 1038 |
switch(win->win_type) |
| 1039 |
{ |
| 1040 |
case OS_BANNER_TYPE_TEXT: |
| 1041 |
|
| 1042 |
twin = (osgen_txtwin_t *)win; |
| 1043 |
|
| 1044 |
|
| 1045 |
twin->txtfree = twin->txtbuf; |
| 1046 |
twin->line_count = 1; |
| 1047 |
twin->first_line = 0; |
| 1048 |
twin->line_ptr[0] = twin->txtbuf; |
| 1049 |
|
| 1050 |
|
| 1051 |
osssb_add_color_code(twin); |
| 1052 |
|
| 1053 |
|
| 1054 |
break; |
| 1055 |
|
| 1056 |
case OS_BANNER_TYPE_TEXTGRID: |
| 1057 |
|
| 1058 |
gwin = (osgen_gridwin_t *)win; |
| 1059 |
|
| 1060 |
|
| 1061 |
osgen_gridwin_clear(gwin, 0, gwin->grid_wid * gwin->grid_ht); |
| 1062 |
|
| 1063 |
|
| 1064 |
break; |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
win->x = 0; |
| 1069 |
win->y = 0; |
| 1070 |
|
| 1071 |
|
| 1072 |
win->scrollx = 0; |
| 1073 |
win->scrolly = 0; |
| 1074 |
|
| 1075 |
|
| 1076 |
win->xmax = 0; |
| 1077 |
win->ymax = 0; |
| 1078 |
|
| 1079 |
|
| 1080 |
win->flags &= ~OSGEN_FULL; |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
if (!(win->flags & OSGEN_AUTO_VSCROLL)) |
| 1101 |
{ |
| 1102 |
|
| 1103 |
win->flags |= OSGEN_DEFER_REDRAW; |
| 1104 |
} |
| 1105 |
else |
| 1106 |
{ |
| 1107 |
|
| 1108 |
ossclr(win->winy, win->winx, |
| 1109 |
win->winy + win->ht - 1, win->winx + win->wid - 1, |
| 1110 |
win->oss_fillcolor); |
| 1111 |
} |
| 1112 |
} |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
static void osgen_disp_trunc(osgen_win_t *win, int y, int x, int oss_color, |
| 1121 |
const char *p) |
| 1122 |
{ |
| 1123 |
char buf[64]; |
| 1124 |
size_t chars_rem; |
| 1125 |
size_t wid_rem; |
| 1126 |
|
| 1127 |
|
| 1128 |
if (S_deferred_redraw || (win->flags & OSGEN_DEFER_REDRAW) != 0) |
| 1129 |
return; |
| 1130 |
|
| 1131 |
|
| 1132 |
chars_rem = strlen(p); |
| 1133 |
|
| 1134 |
|
| 1135 |
wid_rem = win->wid - (x >= 0 ? x : 0); |
| 1136 |
|
| 1137 |
|
| 1138 |
if (y < 0 || y >= (int)win->ht |
| 1139 |
|| x + (int)chars_rem <= 0 || x >= (int)win->wid) |
| 1140 |
return; |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
if (x < 0) |
| 1147 |
{ |
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
x = -x; |
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
if (chars_rem <= (size_t)x) |
| 1160 |
return; |
| 1161 |
|
| 1162 |
|
| 1163 |
chars_rem -= x; |
| 1164 |
p += x; |
| 1165 |
|
| 1166 |
|
| 1167 |
x = 0; |
| 1168 |
} |
| 1169 |
|
| 1170 |
|
| 1171 |
if (chars_rem < wid_rem) |
| 1172 |
{ |
| 1173 |
|
| 1174 |
ossdsp(win->winy + y, win->winx + x, oss_color, p); |
| 1175 |
|
| 1176 |
|
| 1177 |
return; |
| 1178 |
} |
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
while (wid_rem != 0) |
| 1187 |
{ |
| 1188 |
size_t cur; |
| 1189 |
|
| 1190 |
|
| 1191 |
cur = wid_rem; |
| 1192 |
if (cur > sizeof(buf) - 1) |
| 1193 |
cur = sizeof(buf) - 1; |
| 1194 |
|
| 1195 |
|
| 1196 |
memcpy(buf, p, cur); |
| 1197 |
buf[cur] = '\0'; |
| 1198 |
|
| 1199 |
|
| 1200 |
ossdsp(win->winy + y, win->winx + x, oss_color, buf); |
| 1201 |
|
| 1202 |
|
| 1203 |
x += cur; |
| 1204 |
|
| 1205 |
|
| 1206 |
p += cur; |
| 1207 |
|
| 1208 |
|
| 1209 |
wid_rem -= cur; |
| 1210 |
} |
| 1211 |
} |
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
void osssbini(unsigned int size) |
| 1224 |
{ |
| 1225 |
osgen_txtwin_t *win; |
| 1226 |
|
| 1227 |
|
| 1228 |
if (!os_f_plain) |
| 1229 |
{ |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
S_main_win = win = osgen_create_txtwin( |
| 1235 |
OS_BANNER_FIRST, 0, 0, size, size/40); |
| 1236 |
if (win == 0) |
| 1237 |
{ |
| 1238 |
|
| 1239 |
printf("There is not enough memory to run this program.\n"); |
| 1240 |
exit(1); |
| 1241 |
} |
| 1242 |
|
| 1243 |
|
| 1244 |
S_default_win = win; |
| 1245 |
|
| 1246 |
|
| 1247 |
win->base.flags |= OSGEN_AUTO_VSCROLL; |
| 1248 |
|
| 1249 |
|
| 1250 |
win->base.winy = 0; |
| 1251 |
win->base.winx = 0; |
| 1252 |
win->base.wid = G_oss_screen_width; |
| 1253 |
win->base.ht = G_oss_screen_height; |
| 1254 |
|
| 1255 |
|
| 1256 |
G_os_linewidth = win->base.wid; |
| 1257 |
G_os_pagelength = (win->base.ht > 2 |
| 1258 |
? win->base.ht - 2 |
| 1259 |
: win->base.ht > 1 |
| 1260 |
? win->base.ht - 1 : win->base.ht); |
| 1261 |
|
| 1262 |
|
| 1263 |
os_set_text_color(OS_COLOR_P_TEXT, OS_COLOR_P_TRANSPARENT); |
| 1264 |
os_set_screen_color(OS_COLOR_P_TEXTBG); |
| 1265 |
|
| 1266 |
|
| 1267 |
osgen_clear_win(&win->base); |
| 1268 |
} |
| 1269 |
else |
| 1270 |
{ |
| 1271 |
|
| 1272 |
G_os_linewidth = G_oss_screen_width; |
| 1273 |
G_os_pagelength = G_oss_screen_height - 2; |
| 1274 |
} |
| 1275 |
} |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
void osssbdel(void) |
| 1282 |
{ |
| 1283 |
|
| 1284 |
if (S_main_win != 0) |
| 1285 |
osgen_delete_win_tree(&S_main_win->base); |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
static char *ossadvsp(osgen_txtwin_t *win, char *p) |
| 1298 |
{ |
| 1299 |
|
| 1300 |
++p; |
| 1301 |
|
| 1302 |
|
| 1303 |
if (p >= win->txtbuf + win->txtbufsiz) |
| 1304 |
p = win->txtbuf; |
| 1305 |
|
| 1306 |
|
| 1307 |
return p; |
| 1308 |
} |
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
static char *ossdecsp(osgen_txtwin_t *win, char *p) |
| 1314 |
{ |
| 1315 |
|
| 1316 |
if (p == win->txtbuf) |
| 1317 |
p = win->txtbuf + win->txtbufsiz; |
| 1318 |
|
| 1319 |
|
| 1320 |
--p; |
| 1321 |
|
| 1322 |
|
| 1323 |
return p; |
| 1324 |
} |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
static char **osgen_get_line_ptr(osgen_txtwin_t *win, int y) |
| 1330 |
{ |
| 1331 |
size_t idx; |
| 1332 |
|
| 1333 |
|
| 1334 |
if (y < 0 || (size_t)y >= win->line_count) |
| 1335 |
return 0; |
| 1336 |
|
| 1337 |
|
| 1338 |
idx = y + win->first_line; |
| 1339 |
|
| 1340 |
|
| 1341 |
if (idx >= win->line_ptr_cnt) |
| 1342 |
idx -= win->line_ptr_cnt; |
| 1343 |
|
| 1344 |
|
| 1345 |
return &win->line_ptr[idx]; |
| 1346 |
} |
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
static char *osgen_get_line(osgen_txtwin_t *win, int y) |
| 1353 |
{ |
| 1354 |
char **line_ptr; |
| 1355 |
|
| 1356 |
|
| 1357 |
line_ptr = osgen_get_line_ptr(win, y); |
| 1358 |
|
| 1359 |
|
| 1360 |
return (line_ptr != 0 ? *line_ptr : 0); |
| 1361 |
} |
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
static int osssb_add_byte(osgen_txtwin_t *win, char c) |
| 1368 |
{ |
| 1369 |
char *nxtfree; |
| 1370 |
|
| 1371 |
|
| 1372 |
if ((win->base.flags & OSGEN_FULL) != 0) |
| 1373 |
return FALSE; |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
nxtfree = ossadvsp(win, win->txtfree); |
| 1382 |
if (nxtfree == win->line_ptr[win->first_line] |
| 1383 |
&& !(win->base.flags & OSGEN_AUTO_VSCROLL)) |
| 1384 |
{ |
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
*win->txtfree = '\0'; |
| 1391 |
|
| 1392 |
|
| 1393 |
win->base.flags |= OSGEN_FULL; |
| 1394 |
|
| 1395 |
|
| 1396 |
return FALSE; |
| 1397 |
} |
| 1398 |
|
| 1399 |
|
| 1400 |
*win->txtfree = c; |
| 1401 |
|
| 1402 |
|
| 1403 |
win->txtfree = nxtfree; |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
if (win->txtfree == win->line_ptr[win->first_line]) |
| 1410 |
{ |
| 1411 |
|
| 1412 |
win->first_line++; |
| 1413 |
if (win->first_line >= win->line_ptr_cnt) |
| 1414 |
win->first_line = 0; |
| 1415 |
|
| 1416 |
|
| 1417 |
win->line_count--; |
| 1418 |
|
| 1419 |
|
| 1420 |
win->base.y--; |
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
if (win->base.scrolly == 0) |
| 1430 |
win->base.flags |= OSGEN_DEFER_REDRAW; |
| 1431 |
else |
| 1432 |
win->base.scrolly--; |
| 1433 |
} |
| 1434 |
|
| 1435 |
|
| 1436 |
return TRUE; |
| 1437 |
} |
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
static int osssb_add_bytes(osgen_txtwin_t *win, const char *p, size_t len) |
| 1444 |
{ |
| 1445 |
char *orig_free; |
| 1446 |
|
| 1447 |
|
| 1448 |
orig_free = win->txtfree; |
| 1449 |
|
| 1450 |
|
| 1451 |
for ( ; len != 0 ; --len) |
| 1452 |
{ |
| 1453 |
|
| 1454 |
if (!osssb_add_byte(win, *p++)) |
| 1455 |
{ |
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
win->txtfree = orig_free; |
| 1461 |
|
| 1462 |
|
| 1463 |
return FALSE; |
| 1464 |
} |
| 1465 |
} |
| 1466 |
|
| 1467 |
|
| 1468 |
return TRUE; |
| 1469 |
} |
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
static void osssb_add_safety_null(osgen_txtwin_t *win) |
| 1477 |
{ |
| 1478 |
|
| 1479 |
if (osssb_add_byte(win, '\0')) |
| 1480 |
{ |
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
win->txtfree = ossdecsp(win, win->txtfree); |
| 1486 |
} |
| 1487 |
} |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
static void osssb_add_color_code(osgen_txtwin_t *win) |
| 1494 |
{ |
| 1495 |
char buf[10]; |
| 1496 |
|
| 1497 |
|
| 1498 |
if (win->base.txtattr != 0) |
| 1499 |
{ |
| 1500 |
|
| 1501 |
buf[0] = OSGEN_ATTR; |
| 1502 |
buf[1] = (char)win->base.txtattr; |
| 1503 |
osssb_add_bytes(win, buf, 2); |
| 1504 |
} |
| 1505 |
|
| 1506 |
|
| 1507 |
if (win->base.txtfg != OSGEN_COLOR_TEXT |
| 1508 |
|| win->base.txtbg != OSGEN_COLOR_TRANSPARENT) |
| 1509 |
{ |
| 1510 |
|
| 1511 |
buf[0] = OSGEN_COLOR; |
| 1512 |
buf[1] = win->base.txtfg; |
| 1513 |
buf[2] = win->base.txtbg; |
| 1514 |
osssb_add_bytes(win, buf, 3); |
| 1515 |
} |
| 1516 |
|
| 1517 |
|
| 1518 |
osssb_add_safety_null(win); |
| 1519 |
} |
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
static int osssb_new_line(osgen_txtwin_t *win) |
| 1526 |
{ |
| 1527 |
char **line_ptr; |
| 1528 |
|
| 1529 |
|
| 1530 |
if (!osssb_add_byte(win, '\0')) |
| 1531 |
return FALSE; |
| 1532 |
|
| 1533 |
|
| 1534 |
if ((win->base.flags & OSGEN_FULL) != 0) |
| 1535 |
return FALSE; |
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
if (win->line_count + 1 > win->line_ptr_cnt |
| 1544 |
&& !(win->base.flags & OSGEN_AUTO_VSCROLL)) |
| 1545 |
{ |
| 1546 |
|
| 1547 |
win->base.flags |= OSGEN_FULL; |
| 1548 |
|
| 1549 |
|
| 1550 |
return FALSE; |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
win->base.x = 0; |
| 1555 |
|
| 1556 |
|
| 1557 |
if (win->line_count >= win->line_ptr_cnt) |
| 1558 |
{ |
| 1559 |
|
| 1560 |
win->first_line++; |
| 1561 |
if (win->first_line == win->line_ptr_cnt) |
| 1562 |
win->first_line = 0; |
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
if (win->base.scrolly == 0) |
| 1582 |
win->base.flags |= OSGEN_DEFER_REDRAW; |
| 1583 |
else |
| 1584 |
win->base.scrolly--; |
| 1585 |
} |
| 1586 |
else |
| 1587 |
{ |
| 1588 |
|
| 1589 |
win->line_count++; |
| 1590 |
|
| 1591 |
|
| 1592 |
if (win->base.y > win->base.ymax) |
| 1593 |
win->base.ymax = win->base.y; |
| 1594 |
|
| 1595 |
|
| 1596 |
win->base.y++; |
| 1597 |
} |
| 1598 |
|
| 1599 |
|
| 1600 |
line_ptr = osgen_get_line_ptr(win, win->base.y); |
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
*line_ptr = win->txtfree; |
| 1607 |
|
| 1608 |
|
| 1609 |
osssb_add_color_code(win); |
| 1610 |
|
| 1611 |
|
| 1612 |
win->solfg = win->base.txtfg; |
| 1613 |
win->solbg = win->base.txtbg; |
| 1614 |
win->solattr = win->base.txtattr; |
| 1615 |
|
| 1616 |
|
| 1617 |
osssb_add_safety_null(win); |
| 1618 |
|
| 1619 |
|
| 1620 |
return TRUE; |
| 1621 |
} |
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
static void osgen_scroll_win_fwd(osgen_txtwin_t *win, size_t lines) |
| 1627 |
{ |
| 1628 |
|
| 1629 |
if (lines > win->line_count - win->base.scrolly - win->base.ht) |
| 1630 |
lines = win->line_count - win->base.scrolly - win->base.ht; |
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
if (lines > 3 || (int)lines >= win->base.ht) |
| 1639 |
{ |
| 1640 |
|
| 1641 |
win->base.scrolly += lines; |
| 1642 |
|
| 1643 |
|
| 1644 |
osgen_redraw_win(&win->base); |
| 1645 |
} |
| 1646 |
else |
| 1647 |
{ |
| 1648 |
|
| 1649 |
for ( ; lines != 0 ; --lines) |
| 1650 |
{ |
| 1651 |
|
| 1652 |
ossscr(win->base.winy, win->base.winx, |
| 1653 |
win->base.winy + win->base.ht - 1, |
| 1654 |
win->base.winx + win->base.wid - 1, |
| 1655 |
win->base.oss_fillcolor); |
| 1656 |
|
| 1657 |
|
| 1658 |
win->base.scrolly++; |
| 1659 |
|
| 1660 |
|
| 1661 |
osgen_scrdisp(&win->base, 0, win->base.ht - 1, win->base.wid); |
| 1662 |
} |
| 1663 |
} |
| 1664 |
} |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
static void osgen_scroll_win_back(osgen_txtwin_t *win, int lines) |
| 1670 |
{ |
| 1671 |
|
| 1672 |
if (lines > win->base.scrolly) |
| 1673 |
lines = win->base.scrolly; |
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
if (lines > 3) |
| 1681 |
{ |
| 1682 |
|
| 1683 |
win->base.scrolly -= lines; |
| 1684 |
|
| 1685 |
|
| 1686 |
osgen_redraw_win(&win->base); |
| 1687 |
} |
| 1688 |
else |
| 1689 |
{ |
| 1690 |
|
| 1691 |
for ( ; lines != 0 ; --lines) |
| 1692 |
{ |
| 1693 |
|
| 1694 |
ossscu(win->base.winy, win->base.winx, |
| 1695 |
win->base.winy + win->base.ht - 1, |
| 1696 |
win->base.winx + win->base.wid - 1, |
| 1697 |
win->base.oss_fillcolor); |
| 1698 |
|
| 1699 |
|
| 1700 |
win->base.scrolly--; |
| 1701 |
|
| 1702 |
|
| 1703 |
osgen_scrdisp(&win->base, 0, 0, win->base.wid); |
| 1704 |
} |
| 1705 |
} |
| 1706 |
} |
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
static void osgen_auto_vscroll(osgen_txtwin_t *win) |
| 1713 |
{ |
| 1714 |
|
| 1715 |
if (!(win->base.flags & OSGEN_AUTO_VSCROLL)) |
| 1716 |
return; |
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
if (win->base.y >= win->base.scrolly + (int)win->base.ht) |
| 1723 |
osgen_scroll_win_fwd(win, win->base.y |
| 1724 |
- (win->base.scrolly + win->base.ht) + 1); |
| 1725 |
} |
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
static void ossaddsb(osgen_txtwin_t *win, const char *p, size_t len, int draw) |
| 1731 |
{ |
| 1732 |
int startx; |
| 1733 |
int starty; |
| 1734 |
int line_len; |
| 1735 |
|
| 1736 |
|
| 1737 |
if (win->txtbuf == 0) |
| 1738 |
return; |
| 1739 |
|
| 1740 |
|
| 1741 |
startx = win->base.x - win->base.scrollx; |
| 1742 |
starty = win->base.y - win->base.scrolly; |
| 1743 |
|
| 1744 |
|
| 1745 |
line_len = 0; |
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
while (len != 0) |
| 1754 |
{ |
| 1755 |
|
| 1756 |
switch(*p) |
| 1757 |
{ |
| 1758 |
case OSGEN_ATTR: |
| 1759 |
|
| 1760 |
win->base.txtattr = (unsigned char)*(p+1); |
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
if (win->base.x == 0) |
| 1768 |
win->solattr = win->base.txtattr; |
| 1769 |
|
| 1770 |
|
| 1771 |
osssb_add_bytes(win, p, 2); |
| 1772 |
p += 2; |
| 1773 |
len -= 2; |
| 1774 |
break; |
| 1775 |
|
| 1776 |
case OSGEN_COLOR: |
| 1777 |
|
| 1778 |
win->base.txtfg = (unsigned char)*(p+1); |
| 1779 |
win->base.txtbg = (unsigned char)*(p+2); |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
if (win->base.x == 0) |
| 1786 |
{ |
| 1787 |
win->solfg = win->base.txtfg; |
| 1788 |
win->solbg = win->base.txtbg; |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
osssb_add_bytes(win, p, 3); |
| 1793 |
p += 3; |
| 1794 |
len -= 3; |
| 1795 |
break; |
| 1796 |
|
| 1797 |
case '\n': |
| 1798 |
|
| 1799 |
osssb_new_line(win); |
| 1800 |
|
| 1801 |
|
| 1802 |
if (draw) |
| 1803 |
osgen_scrdisp(&win->base, startx, starty, line_len); |
| 1804 |
|
| 1805 |
|
| 1806 |
++p; |
| 1807 |
--len; |
| 1808 |
|
| 1809 |
|
| 1810 |
startx = win->base.x - win->base.scrollx; |
| 1811 |
++starty; |
| 1812 |
line_len = 0; |
| 1813 |
|
| 1814 |
|
| 1815 |
if (draw) |
| 1816 |
osgen_auto_vscroll(win); |
| 1817 |
|
| 1818 |
|
| 1819 |
break; |
| 1820 |
|
| 1821 |
case '\r': |
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
win->txtfree = osgen_get_line(win, win->base.y); |
| 1831 |
|
| 1832 |
|
| 1833 |
win->base.txtfg = win->solfg; |
| 1834 |
win->base.txtbg = win->solbg; |
| 1835 |
win->base.txtattr = win->solattr; |
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
osssb_add_color_code(win); |
| 1842 |
|
| 1843 |
|
| 1844 |
if (draw && starty >= 0 && starty < (int)win->base.ht) |
| 1845 |
ossclr(win->base.winy + starty, win->base.winx, |
| 1846 |
win->base.winy + starty, |
| 1847 |
win->base.winx + win->base.wid - 1, |
| 1848 |
win->base.oss_fillcolor); |
| 1849 |
|
| 1850 |
|
| 1851 |
line_len = 0; |
| 1852 |
startx = 0; |
| 1853 |
|
| 1854 |
|
| 1855 |
win->base.x = 0; |
| 1856 |
|
| 1857 |
|
| 1858 |
++p; |
| 1859 |
--len; |
| 1860 |
|
| 1861 |
|
| 1862 |
break; |
| 1863 |
|
| 1864 |
default: |
| 1865 |
|
| 1866 |
if (osssb_add_byte(win, *p)) |
| 1867 |
{ |
| 1868 |
|
| 1869 |
if (win->base.x > win->base.xmax) |
| 1870 |
win->base.xmax = win->base.x; |
| 1871 |
|
| 1872 |
|
| 1873 |
win->base.x++; |
| 1874 |
|
| 1875 |
|
| 1876 |
++line_len; |
| 1877 |
} |
| 1878 |
|
| 1879 |
|
| 1880 |
++p; |
| 1881 |
--len; |
| 1882 |
|
| 1883 |
|
| 1884 |
break; |
| 1885 |
} |
| 1886 |
} |
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
osssb_add_safety_null(win); |
| 1893 |
|
| 1894 |
|
| 1895 |
if (draw) |
| 1896 |
{ |
| 1897 |
|
| 1898 |
osgen_scrdisp(&win->base, startx, starty, line_len); |
| 1899 |
|
| 1900 |
|
| 1901 |
osgen_auto_vscroll(win); |
| 1902 |
} |
| 1903 |
} |
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
void ossaddsb_input(osgen_txtwin_t *win, char *p, int add_nl) |
| 1909 |
{ |
| 1910 |
size_t chars_rem; |
| 1911 |
|
| 1912 |
|
| 1913 |
chars_rem = strlen(p); |
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
while (chars_rem != 0) |
| 1920 |
{ |
| 1921 |
size_t wid_rem; |
| 1922 |
size_t cur; |
| 1923 |
|
| 1924 |
|
| 1925 |
if (win->base.x >= (int)win->base.wid) |
| 1926 |
osssb_new_line(win); |
| 1927 |
|
| 1928 |
|
| 1929 |
wid_rem = win->base.wid - win->base.x; |
| 1930 |
|
| 1931 |
|
| 1932 |
cur = chars_rem; |
| 1933 |
if (cur > wid_rem) |
| 1934 |
cur = wid_rem; |
| 1935 |
|
| 1936 |
|
| 1937 |
ossaddsb(win, p, cur, FALSE); |
| 1938 |
|
| 1939 |
|
| 1940 |
p += cur; |
| 1941 |
chars_rem -= cur; |
| 1942 |
} |
| 1943 |
|
| 1944 |
|
| 1945 |
if (add_nl) |
| 1946 |
osssb_new_line(win); |
| 1947 |
else |
| 1948 |
osssb_add_safety_null(win); |
| 1949 |
} |
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
static void osgen_sb_mode_end() |
| 1956 |
{ |
| 1957 |
osgen_txtwin_t *win = S_sbmode_win; |
| 1958 |
|
| 1959 |
|
| 1960 |
if (win->base.scrolly > S_sbmode_orig_scrolly) |
| 1961 |
osgen_scroll_win_back(win, win->base.scrolly - S_sbmode_orig_scrolly); |
| 1962 |
else if (win->base.scrolly < S_sbmode_orig_scrolly) |
| 1963 |
osgen_scroll_win_fwd(win, S_sbmode_orig_scrolly - win->base.scrolly); |
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
S_gets_y += S_sbmode_orig_scrolly - win->base.scrolly; |
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
win->base.winy -= 1; |
| 1976 |
win->base.ht += 1; |
| 1977 |
win->base.scrolly -= 1; |
| 1978 |
|
| 1979 |
|
| 1980 |
ossclr(win->base.winy, win->base.winx, |
| 1981 |
win->base.winy, win->base.winx + win->base.wid - 1, |
| 1982 |
win->base.oss_fillcolor); |
| 1983 |
osgen_scrdisp(&win->base, 0, 0, win->base.wid); |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
win->base.x = S_sbmode_orig_x; |
| 1992 |
win->txtfree = S_sbmode_orig_txtfree; |
| 1993 |
while (win->line_count > 1 |
| 1994 |
&& osgen_get_line_ptr(win, win->base.y) != S_sbmode_orig_last_line) |
| 1995 |
{ |
| 1996 |
|
| 1997 |
win->line_count--; |
| 1998 |
win->base.y--; |
| 1999 |
} |
| 2000 |
|
| 2001 |
|
| 2002 |
S_sbmode_win = 0; |
| 2003 |
} |
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
static void osgen_draw_sb_mode_line(void) |
| 2013 |
{ |
| 2014 |
osgen_txtwin_t *win; |
| 2015 |
int oss_color; |
| 2016 |
|
| 2017 |
|
| 2018 |
win = S_sbmode_win; |
| 2019 |
|
| 2020 |
|
| 2021 |
if (win == 0) |
| 2022 |
return; |
| 2023 |
|
| 2024 |
|
| 2025 |
oss_color = ossgetcolor(win->base.fillcolor, win->base.txtfg, 0, |
| 2026 |
OSGEN_COLOR_TRANSPARENT); |
| 2027 |
|
| 2028 |
|
| 2029 |
ossclr(win->base.winy - 1, win->base.winx, |
| 2030 |
win->base.winy - 1, win->base.winx + win->base.wid - 1, oss_color); |
| 2031 |
|
| 2032 |
|
| 2033 |
win->base.winy -= 1; |
| 2034 |
win->base.ht += 1; |
| 2035 |
|
| 2036 |
|
| 2037 |
osgen_disp_trunc(&win->base, 0, 0, oss_color, OS_SBSTAT); |
| 2038 |
|
| 2039 |
|
| 2040 |
win->base.winy += 1; |
| 2041 |
win->base.ht -= 1; |
| 2042 |
} |
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
static int osgen_sb_mode(osgen_txtwin_t *win, int event_type, |
| 2054 |
os_event_info_t *event_info) |
| 2055 |
{ |
| 2056 |
int ret; |
| 2057 |
char c; |
| 2058 |
int just_started; |
| 2059 |
|
| 2060 |
|
| 2061 |
if (S_sbmode_win != 0 && S_sbmode_win != win) |
| 2062 |
osgen_sb_mode_end(); |
| 2063 |
|
| 2064 |
|
| 2065 |
just_started = (S_sbmode_win == 0); |
| 2066 |
|
| 2067 |
|
| 2068 |
if (just_started) |
| 2069 |
{ |
| 2070 |
|
| 2071 |
if (win->txtbuf == 0) |
| 2072 |
return FALSE; |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
if (win->line_count <= win->base.ht || win->base.ht < 2) |
| 2082 |
return FALSE; |
| 2083 |
|
| 2084 |
|
| 2085 |
S_sbmode_win = win; |
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
win->base.winy += 1; |
| 2094 |
win->base.ht -= 1; |
| 2095 |
win->base.scrolly += 1; |
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
S_sbmode_orig_x = win->base.x; |
| 2104 |
S_sbmode_orig_txtfree = win->txtfree; |
| 2105 |
S_sbmode_orig_last_line = osgen_get_line_ptr(win, win->base.y); |
| 2106 |
ossaddsb_input(win, S_gets_buf, FALSE); |
| 2107 |
|
| 2108 |
|
| 2109 |
S_sbmode_orig_scrolly = win->base.scrolly; |
| 2110 |
|
| 2111 |
|
| 2112 |
osgen_draw_sb_mode_line(); |
| 2113 |
} |
| 2114 |
|
| 2115 |
|
| 2116 |
ret = TRUE; |
| 2117 |
|
| 2118 |
|
| 2119 |
switch(event_type) |
| 2120 |
{ |
| 2121 |
case OS_EVT_KEY: |
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
c = event_info->key[0]; |
| 2130 |
if ((unsigned char)c >= 32 || c == '\n' || c == '\r' || c == 8) |
| 2131 |
{ |
| 2132 |
|
| 2133 |
osgen_sb_mode_end(); |
| 2134 |
|
| 2135 |
|
| 2136 |
ret = FALSE; |
| 2137 |
} |
| 2138 |
|
| 2139 |
|
| 2140 |
if (c == 27) |
| 2141 |
{ |
| 2142 |
osgen_sb_mode_end(); |
| 2143 |
break; |
| 2144 |
} |
| 2145 |
|
| 2146 |
|
| 2147 |
if (c != '\0') |
| 2148 |
break; |
| 2149 |
|
| 2150 |
|
| 2151 |
switch(event_info->key[1]) |
| 2152 |
{ |
| 2153 |
case CMD_SCR: |
| 2154 |
|
| 2155 |
if (!just_started) |
| 2156 |
osgen_sb_mode_end(); |
| 2157 |
break; |
| 2158 |
|
| 2159 |
case CMD_KILL: |
| 2160 |
case CMD_EOF: |
| 2161 |
|
| 2162 |
osgen_sb_mode_end(); |
| 2163 |
break; |
| 2164 |
|
| 2165 |
case CMD_UP: |
| 2166 |
|
| 2167 |
osgen_scroll_win_back(win, 1); |
| 2168 |
break; |
| 2169 |
|
| 2170 |
case CMD_DOWN: |
| 2171 |
|
| 2172 |
osgen_scroll_win_fwd(win, 1); |
| 2173 |
break; |
| 2174 |
|
| 2175 |
case CMD_PGUP: |
| 2176 |
|
| 2177 |
osgen_scroll_win_back(win, win->base.ht > 1 |
| 2178 |
? win->base.ht - 1 : 1); |
| 2179 |
break; |
| 2180 |
|
| 2181 |
case CMD_PGDN: |
| 2182 |
|
| 2183 |
osgen_scroll_win_fwd(win, win->base.ht > 1 |
| 2184 |
? win->base.ht - 1 : 1); |
| 2185 |
break; |
| 2186 |
} |
| 2187 |
|
| 2188 |
|
| 2189 |
break; |
| 2190 |
|
| 2191 |
default: |
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
break; |
| 2198 |
} |
| 2199 |
|
| 2200 |
|
| 2201 |
return ret; |
| 2202 |
} |
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
static void osgen_scrdisp_txt(osgen_txtwin_t *win, int x, int y, int len) |
| 2208 |
{ |
| 2209 |
int fg; |
| 2210 |
int bg; |
| 2211 |
int attr; |
| 2212 |
int oss_color; |
| 2213 |
char buf[64]; |
| 2214 |
char *bufp; |
| 2215 |
char *p; |
| 2216 |
int scanx; |
| 2217 |
|
| 2218 |
|
| 2219 |
fg = OSGEN_COLOR_TEXT; |
| 2220 |
bg = OSGEN_COLOR_TRANSPARENT; |
| 2221 |
attr = 0; |
| 2222 |
oss_color = ossgetcolor(fg, bg, attr, win->base.fillcolor); |
| 2223 |
|
| 2224 |
|
| 2225 |
p = osgen_get_line(win, y + win->base.scrolly); |
| 2226 |
if (p == 0) |
| 2227 |
return; |
| 2228 |
|
| 2229 |
|
| 2230 |
scanx = -win->base.scrollx; |
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
for (bufp = buf ; *p != '\0' && len != 0 ; p = ossadvsp(win, p)) |
| 2239 |
{ |
| 2240 |
|
| 2241 |
switch(*p) |
| 2242 |
{ |
| 2243 |
case OSGEN_ATTR: |
| 2244 |
|
| 2245 |
p = ossadvsp(win, p); |
| 2246 |
|
| 2247 |
|
| 2248 |
attr = *p; |
| 2249 |
|
| 2250 |
|
| 2251 |
goto change_color; |
| 2252 |
|
| 2253 |
case OSGEN_COLOR: |
| 2254 |
|
| 2255 |
p = ossadvsp(win, p); |
| 2256 |
|
| 2257 |
|
| 2258 |
fg = *p; |
| 2259 |
p = ossadvsp(win, p); |
| 2260 |
|
| 2261 |
|
| 2262 |
bg = *p; |
| 2263 |
goto change_color; |
| 2264 |
|
| 2265 |
change_color: |
| 2266 |
|
| 2267 |
if (bufp != buf) |
| 2268 |
{ |
| 2269 |
|
| 2270 |
*bufp = '\0'; |
| 2271 |
osgen_disp_trunc(&win->base, y, x, oss_color, buf); |
| 2272 |
|
| 2273 |
|
| 2274 |
x += bufp - buf; |
| 2275 |
|
| 2276 |
|
| 2277 |
bufp = buf; |
| 2278 |
} |
| 2279 |
|
| 2280 |
|
| 2281 |
oss_color = ossgetcolor(fg, bg, attr, win->base.fillcolor); |
| 2282 |
break; |
| 2283 |
|
| 2284 |
default: |
| 2285 |
|
| 2286 |
if (bufp == buf + sizeof(buf) - 1) |
| 2287 |
{ |
| 2288 |
|
| 2289 |
*bufp = '\0'; |
| 2290 |
osgen_disp_trunc(&win->base, y, x, oss_color, buf); |
| 2291 |
|
| 2292 |
|
| 2293 |
x += bufp - buf; |
| 2294 |
|
| 2295 |
|
| 2296 |
bufp = buf; |
| 2297 |
} |
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
if (scanx >= x) |
| 2306 |
{ |
| 2307 |
|
| 2308 |
*bufp++ = *p; |
| 2309 |
|
| 2310 |
|
| 2311 |
--len; |
| 2312 |
} |
| 2313 |
|
| 2314 |
|
| 2315 |
++scanx; |
| 2316 |
|
| 2317 |
|
| 2318 |
break; |
| 2319 |
} |
| 2320 |
} |
| 2321 |
|
| 2322 |
|
| 2323 |
if (bufp != buf) |
| 2324 |
{ |
| 2325 |
|
| 2326 |
*bufp = '\0'; |
| 2327 |
|
| 2328 |
|
| 2329 |
osgen_disp_trunc(&win->base, y, x, oss_color, buf); |
| 2330 |
} |
| 2331 |
} |
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
static void osgen_gridwin_clear_ptr(char *txtp, osgen_charcolor_t *colorp, |
| 2345 |
size_t len) |
| 2346 |
{ |
| 2347 |
|
| 2348 |
for ( ; len != 0 ; --len, ++txtp, ++colorp) |
| 2349 |
{ |
| 2350 |
|
| 2351 |
*txtp = ' '; |
| 2352 |
|
| 2353 |
|
| 2354 |
colorp->fg = OSGEN_COLOR_TEXT; |
| 2355 |
colorp->bg = OSGEN_COLOR_TRANSPARENT; |
| 2356 |
} |
| 2357 |
} |
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
static void osgen_gridwin_clear(osgen_gridwin_t *win, size_t ofs, size_t len) |
| 2366 |
{ |
| 2367 |
|
| 2368 |
osgen_gridwin_clear_ptr(win->grid_txt + ofs, win->grid_color + ofs, len); |
| 2369 |
} |
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
static void osgen_gridwin_resize(osgen_gridwin_t *win, |
| 2379 |
size_t new_wid, size_t new_ht) |
| 2380 |
{ |
| 2381 |
|
| 2382 |
if (new_wid > win->grid_wid || new_ht > win->grid_ht) |
| 2383 |
{ |
| 2384 |
char *new_txt; |
| 2385 |
osgen_charcolor_t *new_color; |
| 2386 |
char *tsrc, *tdst; |
| 2387 |
osgen_charcolor_t *csrc, *cdst; |
| 2388 |
size_t y; |
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
if (win->grid_wid > new_wid) |
| 2396 |
new_wid = win->grid_wid; |
| 2397 |
if (win->grid_ht > new_ht) |
| 2398 |
new_ht = win->grid_ht; |
| 2399 |
|
| 2400 |
|
| 2401 |
new_txt = (char *)osmalloc(new_wid * new_ht); |
| 2402 |
new_color = (osgen_charcolor_t *)osmalloc( |
| 2403 |
new_wid * new_ht * sizeof(new_color[0])); |
| 2404 |
|
| 2405 |
|
| 2406 |
tsrc = win->grid_txt; |
| 2407 |
csrc = win->grid_color; |
| 2408 |
tdst = new_txt; |
| 2409 |
cdst = new_color; |
| 2410 |
for (y = 0 ; y < win->grid_ht ; ++y) |
| 2411 |
{ |
| 2412 |
|
| 2413 |
memcpy(tdst, tsrc, win->grid_wid); |
| 2414 |
memcpy(cdst, csrc, win->grid_wid * sizeof(cdst[0])); |
| 2415 |
|
| 2416 |
|
| 2417 |
osgen_gridwin_clear_ptr(tdst + win->grid_wid, |
| 2418 |
cdst + win->grid_wid, |
| 2419 |
new_wid - win->grid_wid); |
| 2420 |
|
| 2421 |
|
| 2422 |
tsrc += win->grid_wid; |
| 2423 |
csrc += win->grid_wid; |
| 2424 |
tdst += new_wid; |
| 2425 |
cdst += new_wid; |
| 2426 |
} |
| 2427 |
|
| 2428 |
|
| 2429 |
for ( ; y < new_ht ; ++y, tdst += new_wid, cdst += new_wid) |
| 2430 |
osgen_gridwin_clear_ptr(tdst, cdst, new_wid); |
| 2431 |
|
| 2432 |
|
| 2433 |
osfree(win->grid_txt); |
| 2434 |
osfree(win->grid_color); |
| 2435 |
|
| 2436 |
|
| 2437 |
win->grid_txt = new_txt; |
| 2438 |
win->grid_color = new_color; |
| 2439 |
win->grid_wid = new_wid; |
| 2440 |
win->grid_ht = new_ht; |
| 2441 |
} |
| 2442 |
} |
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
static void osgen_scrdisp_grid(osgen_gridwin_t *win, int x, int y, int len) |
| 2448 |
{ |
| 2449 |
char *txtp; |
| 2450 |
osgen_charcolor_t *colorp; |
| 2451 |
size_t ofs; |
| 2452 |
char buf[64]; |
| 2453 |
char *dst; |
| 2454 |
char fg, bg; |
| 2455 |
int oss_color; |
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
ofs = ((y - win->base.scrolly) * win->grid_wid) + (x - win->base.scrollx); |
| 2463 |
|
| 2464 |
|
| 2465 |
txtp = win->grid_txt + ofs; |
| 2466 |
colorp = win->grid_color + ofs; |
| 2467 |
|
| 2468 |
|
| 2469 |
fg = colorp->fg; |
| 2470 |
bg = colorp->bg; |
| 2471 |
|
| 2472 |
|
| 2473 |
oss_color = ossgetcolor(fg, bg, 0, win->base.fillcolor); |
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
for (dst = buf ; ; --len, ++txtp, ++colorp) |
| 2480 |
{ |
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
if (len == 0 |
| 2487 |
|| dst == buf + sizeof(buf) - 1 |
| 2488 |
|| colorp->fg != fg || colorp->bg != bg) |
| 2489 |
{ |
| 2490 |
|
| 2491 |
*dst = '\0'; |
| 2492 |
osgen_disp_trunc(&win->base, y, x, oss_color, buf); |
| 2493 |
|
| 2494 |
|
| 2495 |
x += dst - buf; |
| 2496 |
|
| 2497 |
|
| 2498 |
dst = buf; |
| 2499 |
|
| 2500 |
|
| 2501 |
if (colorp->fg != fg || colorp->bg != bg) |
| 2502 |
{ |
| 2503 |
|
| 2504 |
fg = colorp->fg; |
| 2505 |
bg = colorp->bg; |
| 2506 |
|
| 2507 |
|
| 2508 |
oss_color = ossgetcolor(fg, bg, 0, win->base.fillcolor); |
| 2509 |
} |
| 2510 |
} |
| 2511 |
|
| 2512 |
|
| 2513 |
if (len == 0) |
| 2514 |
break; |
| 2515 |
|
| 2516 |
|
| 2517 |
*dst++ = *txtp; |
| 2518 |
} |
| 2519 |
} |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
static void osgen_gridwin_write(osgen_gridwin_t *win, |
| 2525 |
const char *txt, size_t len) |
| 2526 |
{ |
| 2527 |
const char *p; |
| 2528 |
size_t rem; |
| 2529 |
int xmax, ymax; |
| 2530 |
int x, y; |
| 2531 |
int startx; |
| 2532 |
int winx; |
| 2533 |
size_t ofs; |
| 2534 |
char *tdst; |
| 2535 |
osgen_charcolor_t *cdst; |
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
xmax = x = win->base.x; |
| 2543 |
ymax = y = win->base.y; |
| 2544 |
for (p = txt, rem = len ; rem != 0 ; ++p, --rem) |
| 2545 |
{ |
| 2546 |
|
| 2547 |
switch(*p) |
| 2548 |
{ |
| 2549 |
case '\n': |
| 2550 |
|
| 2551 |
x = 0; |
| 2552 |
++y; |
| 2553 |
break; |
| 2554 |
|
| 2555 |
case '\r': |
| 2556 |
|
| 2557 |
x = 0; |
| 2558 |
break; |
| 2559 |
|
| 2560 |
default: |
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
if (y > ymax) |
| 2566 |
ymax = y; |
| 2567 |
if (x > xmax) |
| 2568 |
xmax = x; |
| 2569 |
|
| 2570 |
|
| 2571 |
++x; |
| 2572 |
break; |
| 2573 |
} |
| 2574 |
} |
| 2575 |
|
| 2576 |
|
| 2577 |
if (xmax >= (int)win->grid_wid || ymax >= (int)win->grid_ht) |
| 2578 |
osgen_gridwin_resize(win, xmax + 1, ymax + 1); |
| 2579 |
|
| 2580 |
|
| 2581 |
x = win->base.x; |
| 2582 |
y = win->base.y; |
| 2583 |
|
| 2584 |
|
| 2585 |
ofs = y * win->grid_wid + x; |
| 2586 |
tdst = win->grid_txt + ofs; |
| 2587 |
cdst = win->grid_color + ofs; |
| 2588 |
|
| 2589 |
|
| 2590 |
if (xmax > win->base.xmax) |
| 2591 |
win->base.xmax = xmax; |
| 2592 |
if (ymax > win->base.ymax) |
| 2593 |
win->base.ymax = ymax; |
| 2594 |
|
| 2595 |
|
| 2596 |
startx = x; |
| 2597 |
winx = x - win->base.scrollx; |
| 2598 |
|
| 2599 |
|
| 2600 |
for (p = txt, rem = len ; ; ++p, --rem) |
| 2601 |
{ |
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
if (rem == 0 || *p == '\n' || *p == '\r') |
| 2607 |
{ |
| 2608 |
|
| 2609 |
if (!S_deferred_redraw |
| 2610 |
&& !(win->base.flags & OSGEN_DEFER_REDRAW) |
| 2611 |
&& x != startx) |
| 2612 |
osgen_scrdisp(&win->base, winx, y, x - startx); |
| 2613 |
|
| 2614 |
|
| 2615 |
if (rem == 0) |
| 2616 |
break; |
| 2617 |
|
| 2618 |
|
| 2619 |
if (*p == '\n') |
| 2620 |
{ |
| 2621 |
|
| 2622 |
x = 0; |
| 2623 |
++y; |
| 2624 |
} |
| 2625 |
else if (*p == '\r') |
| 2626 |
{ |
| 2627 |
|
| 2628 |
x = 0; |
| 2629 |
} |
| 2630 |
|
| 2631 |
|
| 2632 |
startx = x; |
| 2633 |
winx = x - win->base.scrollx; |
| 2634 |
|
| 2635 |
|
| 2636 |
ofs = y * win->grid_wid + x; |
| 2637 |
tdst = win->grid_txt + ofs; |
| 2638 |
cdst = win->grid_color + ofs; |
| 2639 |
} |
| 2640 |
else |
| 2641 |
{ |
| 2642 |
|
| 2643 |
*tdst = *p; |
| 2644 |
cdst->fg = win->base.txtfg; |
| 2645 |
cdst->bg = win->base.txtbg; |
| 2646 |
|
| 2647 |
|
| 2648 |
++tdst; |
| 2649 |
++cdst; |
| 2650 |
|
| 2651 |
|
| 2652 |
++x; |
| 2653 |
} |
| 2654 |
} |
| 2655 |
|
| 2656 |
|
| 2657 |
win->base.x = x; |
| 2658 |
win->base.y = y; |
| 2659 |
} |
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
static void osgen_scrdisp(osgen_win_t *win, int x, int y, int len) |
| 2674 |
{ |
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
if (y < 0 || (size_t)y >= win->ht |
| 2680 |
|| x + len <= 0 || (size_t)x >= win->wid) |
| 2681 |
return; |
| 2682 |
|
| 2683 |
|
| 2684 |
switch(win->win_type) |
| 2685 |
{ |
| 2686 |
case OS_BANNER_TYPE_TEXT: |
| 2687 |
osgen_scrdisp_txt((osgen_txtwin_t *)win, x, y, len); |
| 2688 |
break; |
| 2689 |
|
| 2690 |
case OS_BANNER_TYPE_TEXTGRID: |
| 2691 |
osgen_scrdisp_grid((osgen_gridwin_t *)win, x, y, len); |
| 2692 |
break; |
| 2693 |
} |
| 2694 |
} |
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
static void osgen_redraw_win(osgen_win_t *win) |
| 2701 |
{ |
| 2702 |
size_t y; |
| 2703 |
|
| 2704 |
|
| 2705 |
ossclr(win->winy, win->winx, |
| 2706 |
win->winy + win->ht - 1, win->winx + win->wid - 1, |
| 2707 |
win->oss_fillcolor); |
| 2708 |
|
| 2709 |
|
| 2710 |
for (y = 0 ; y < win->ht ; ++y) |
| 2711 |
osgen_scrdisp(win, 0, y, win->wid); |
| 2712 |
} |
| 2713 |
|
| 2714 |
|
| 2715 |
void os_redraw(void) |
| 2716 |
{ |
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
S_deferred_redraw = TRUE; |
| 2722 |
|
| 2723 |
|
| 2724 |
osssb_redraw_if_needed(); |
| 2725 |
|
| 2726 |
} |
| 2727 |
|
| 2728 |
|
| 2729 |
static void osgen_redraw_win_if_needed(int global_deferred, osgen_win_t *win) |
| 2730 |
{ |
| 2731 |
osgen_win_t *chi; |
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
if (global_deferred || (win->flags & OSGEN_DEFER_REDRAW) != 0) |
| 2738 |
{ |
| 2739 |
|
| 2740 |
win->flags &= ~OSGEN_DEFER_REDRAW; |
| 2741 |
|
| 2742 |
|
| 2743 |
osgen_redraw_win(win); |
| 2744 |
} |
| 2745 |
|
| 2746 |
|
| 2747 |
for (chi = win->first_child ; chi != 0 ; chi = chi->nxt) |
| 2748 |
osgen_redraw_win_if_needed(global_deferred, chi); |
| 2749 |
} |
| 2750 |
|
| 2751 |
|
| 2752 |
void osssb_redraw_if_needed() |
| 2753 |
{ |
| 2754 |
int global_deferred = S_deferred_redraw; |
| 2755 |
|
| 2756 |
|
| 2757 |
S_deferred_redraw = FALSE; |
| 2758 |
|
| 2759 |
|
| 2760 |
if (S_main_win != 0) |
| 2761 |
osgen_redraw_win_if_needed(global_deferred, &S_main_win->base); |
| 2762 |
|
| 2763 |
|
| 2764 |
if (global_deferred) |
| 2765 |
{ |
| 2766 |
|
| 2767 |
osgen_draw_sb_mode_line(); |
| 2768 |
|
| 2769 |
|
| 2770 |
osgen_gets_redraw_cmdline(); |
| 2771 |
} |
| 2772 |
} |
| 2773 |
|
| 2774 |
|
| 2775 |
void osssb_cursor_to_default_pos(void) |
| 2776 |
{ |
| 2777 |
osgen_win_t *win; |
| 2778 |
|
| 2779 |
|
| 2780 |
if (os_f_plain) |
| 2781 |
return; |
| 2782 |
|
| 2783 |
|
| 2784 |
if (S_sbmode_win != 0) |
| 2785 |
{ |
| 2786 |
|
| 2787 |
ossloc(S_sbmode_win->base.winy - 1, S_sbmode_win->base.winx); |
| 2788 |
} |
| 2789 |
else if (S_special_cursor_pos) |
| 2790 |
{ |
| 2791 |
|
| 2792 |
ossloc(S_special_cursor_y, S_special_cursor_x); |
| 2793 |
} |
| 2794 |
else |
| 2795 |
{ |
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
if ((win = &S_default_win->base) != 0) |
| 2801 |
ossloc(win->winy + win->y - win->scrolly, |
| 2802 |
win->winx + win->x - win->scrollx); |
| 2803 |
} |
| 2804 |
} |
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
static void oss_lay_out_window(osgen_win_t *win) |
| 2810 |
{ |
| 2811 |
osgen_win_t *chi; |
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
if (win->parent != 0) |
| 2819 |
{ |
| 2820 |
int siz; |
| 2821 |
int base_size; |
| 2822 |
int x, y, wid, ht; |
| 2823 |
|
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
x = win->parent->winx; |
| 2829 |
y = win->parent->winy; |
| 2830 |
wid = win->parent->wid; |
| 2831 |
ht = win->parent->ht; |
| 2832 |
|
| 2833 |
|
| 2834 |
switch(win->size_type) |
| 2835 |
{ |
| 2836 |
case OS_BANNER_SIZE_ABS: |
| 2837 |
|
| 2838 |
siz = win->size; |
| 2839 |
break; |
| 2840 |
|
| 2841 |
case OS_BANNER_SIZE_PCT: |
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
base_size = (win->alignment == OS_BANNER_ALIGN_LEFT |
| 2847 |
|| win->alignment == OS_BANNER_ALIGN_RIGHT |
| 2848 |
? wid : ht); |
| 2849 |
|
| 2850 |
|
| 2851 |
siz = (win->size * base_size) / 100; |
| 2852 |
break; |
| 2853 |
} |
| 2854 |
|
| 2855 |
|
| 2856 |
switch(win->alignment) |
| 2857 |
{ |
| 2858 |
case OS_BANNER_ALIGN_TOP: |
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
win->wid = wid; |
| 2864 |
win->winx = x; |
| 2865 |
win->ht = (siz <= ht ? siz : ht); |
| 2866 |
win->winy = y; |
| 2867 |
|
| 2868 |
|
| 2869 |
ht -= win->ht; |
| 2870 |
y += win->ht; |
| 2871 |
break; |
| 2872 |
|
| 2873 |
case OS_BANNER_ALIGN_BOTTOM: |
| 2874 |
|
| 2875 |
win->wid = wid; |
| 2876 |
win->winx = x; |
| 2877 |
win->ht = (siz <= ht ? siz : ht); |
| 2878 |
win->winy = y + ht - win->ht; |
| 2879 |
|
| 2880 |
|
| 2881 |
ht -= win->ht; |
| 2882 |
break; |
| 2883 |
|
| 2884 |
case OS_BANNER_ALIGN_LEFT: |
| 2885 |
|
| 2886 |
win->wid = (siz <= wid ? siz : wid); |
| 2887 |
win->winx = x; |
| 2888 |
win->ht = ht; |
| 2889 |
win->winy = y; |
| 2890 |
|
| 2891 |
|
| 2892 |
wid -= win->wid; |
| 2893 |
x += win->wid; |
| 2894 |
break; |
| 2895 |
|
| 2896 |
case OS_BANNER_ALIGN_RIGHT: |
| 2897 |
|
| 2898 |
win->wid = (siz <= wid ? siz : wid); |
| 2899 |
win->winx = x + wid - win->wid; |
| 2900 |
win->ht = ht; |
| 2901 |
win->winy = y; |
| 2902 |
|
| 2903 |
|
| 2904 |
wid -= win->wid; |
| 2905 |
break; |
| 2906 |
} |
| 2907 |
|
| 2908 |
|
| 2909 |
win->parent->winx = x; |
| 2910 |
win->parent->winy = y; |
| 2911 |
win->parent->wid = wid; |
| 2912 |
win->parent->ht = ht; |
| 2913 |
} |
| 2914 |
|
| 2915 |
|
| 2916 |
for (chi = win->first_child ; chi != 0 ; chi = chi->nxt) |
| 2917 |
oss_lay_out_window(chi); |
| 2918 |
|
| 2919 |
|
| 2920 |
switch(win->win_type) |
| 2921 |
{ |
| 2922 |
case OS_BANNER_TYPE_TEXT: |
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
if (win == &S_sbmode_win->base) |
| 2930 |
{ |
| 2931 |
|
| 2932 |
win->winy += 1; |
| 2933 |
win->ht -= 1; |
| 2934 |
} |
| 2935 |
break; |
| 2936 |
|
| 2937 |
case OS_BANNER_TYPE_TEXTGRID: |
| 2938 |
|
| 2939 |
osgen_gridwin_resize((osgen_gridwin_t *)win, win->wid, win->ht); |
| 2940 |
break; |
| 2941 |
} |
| 2942 |
} |
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
static void osgen_recalc_layout() |
| 2948 |
{ |
| 2949 |
|
| 2950 |
if (S_main_win != 0) |
| 2951 |
{ |
| 2952 |
int ht; |
| 2953 |
|
| 2954 |
|
| 2955 |
S_main_win->base.winx = 0; |
| 2956 |
S_main_win->base.winy = 0; |
| 2957 |
S_main_win->base.wid = G_oss_screen_width; |
| 2958 |
S_main_win->base.ht = G_oss_screen_height; |
| 2959 |
|
| 2960 |
|
| 2961 |
oss_lay_out_window(&S_main_win->base); |
| 2962 |
|
| 2963 |
|
| 2964 |
G_os_linewidth = S_main_win->base.wid; |
| 2965 |
ht = S_main_win->base.ht; |
| 2966 |
G_os_pagelength = (ht > 2 ? ht - 2 : ht > 1 ? ht - 1 : ht); |
| 2967 |
} |
| 2968 |
|
| 2969 |
|
| 2970 |
S_deferred_redraw = TRUE; |
| 2971 |
} |
| 2972 |
|
| 2973 |
|
| 2974 |
|
| 2975 |
|
| 2976 |
|
| 2977 |
void osssb_on_resize_screen() |
| 2978 |
{ |
| 2979 |
|
| 2980 |
osgen_recalc_layout(); |
| 2981 |
|
| 2982 |
|
| 2983 |
osssb_redraw_if_needed(); |
| 2984 |
|
| 2985 |
|
| 2986 |
osssb_cursor_to_default_pos(); |
| 2987 |
} |
| 2988 |
|
| 2989 |
# else |
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
void osssb_on_resize_screen() |
| 2996 |
{ |
| 2997 |
|
| 2998 |
} |
| 2999 |
|
| 3000 |
# endif |
| 3001 |
|
| 3002 |
|
| 3003 |
|
| 3004 |
#ifdef USE_STATLINE |
| 3005 |
|
| 3006 |
|
| 3007 |
static osfar_t char S_scorebuf[135]; |
| 3008 |
|
| 3009 |
|
| 3010 |
static osfar_t char *S_stat_reset_free; |
| 3011 |
static osfar_t int S_stat_reset_x; |
| 3012 |
|
| 3013 |
|
| 3014 |
static void osgen_update_stat_right() |
| 3015 |
{ |
| 3016 |
osgen_txtwin_t *win; |
| 3017 |
int wid_rem; |
| 3018 |
size_t char_len; |
| 3019 |
|
| 3020 |
|
| 3021 |
|
| 3022 |
|
| 3023 |
|
| 3024 |
if ((win = S_status_win) == 0 || S_stat_reset_free == 0) |
| 3025 |
return; |
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
win->txtfree = S_stat_reset_free; |
| 3032 |
win->base.x = S_stat_reset_x; |
| 3033 |
|
| 3034 |
|
| 3035 |
if (win->base.x > (int)win->base.wid) |
| 3036 |
return; |
| 3037 |
|
| 3038 |
|
| 3039 |
wid_rem = win->base.wid - win->base.x; |
| 3040 |
|
| 3041 |
|
| 3042 |
char_len = strlen(S_scorebuf); |
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
|
| 3048 |
if ((int)char_len + 1 >= wid_rem) |
| 3049 |
{ |
| 3050 |
|
| 3051 |
ossaddsb(win, " ", 1, TRUE); |
| 3052 |
|
| 3053 |
|
| 3054 |
ossaddsb(win, S_scorebuf, strlen(S_scorebuf), TRUE); |
| 3055 |
} |
| 3056 |
else |
| 3057 |
{ |
| 3058 |
|
| 3059 |
while (wid_rem > (int)char_len + 1) |
| 3060 |
{ |
| 3061 |
char buf[64]; |
| 3062 |
size_t cur; |
| 3063 |
|
| 3064 |
|
| 3065 |
cur = wid_rem - char_len - 1; |
| 3066 |
if (cur > sizeof(buf) - 1) |
| 3067 |
cur = sizeof(buf) - 1; |
| 3068 |
|
| 3069 |
|
| 3070 |
memset(buf, ' ', cur); |
| 3071 |
|
| 3072 |
|
| 3073 |
ossaddsb(win, buf, cur, TRUE); |
| 3074 |
|
| 3075 |
|
| 3076 |
wid_rem -= cur; |
| 3077 |
} |
| 3078 |
|
| 3079 |
|
| 3080 |
ossaddsb(win, S_scorebuf, strlen(S_scorebuf), TRUE); |
| 3081 |
} |
| 3082 |
} |
| 3083 |
|
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
|
| 3089 |
|
| 3090 |
void os_status(int stat) |
| 3091 |
{ |
| 3092 |
|
| 3093 |
if (os_f_plain) |
| 3094 |
{ |
| 3095 |
|
| 3096 |
switch(stat) |
| 3097 |
{ |
| 3098 |
case 0: |
| 3099 |
|
| 3100 |
status_mode = 0; |
| 3101 |
break; |
| 3102 |
|
| 3103 |
case 1: |
| 3104 |
|
| 3105 |
status_mode = 2; |
| 3106 |
break; |
| 3107 |
|
| 3108 |
case 2: |
| 3109 |
|
| 3110 |
status_mode = 2; |
| 3111 |
break; |
| 3112 |
} |
| 3113 |
|
| 3114 |
|
| 3115 |
return; |
| 3116 |
} |
| 3117 |
|
| 3118 |
|
| 3119 |
if (S_status_win == 0) |
| 3120 |
{ |
| 3121 |
|
| 3122 |
S_status_win = osgen_create_txtwin(OS_BANNER_FIRST, 0, S_main_win, |
| 3123 |
512, 1); |
| 3124 |
|
| 3125 |
|
| 3126 |
if (S_status_win != 0) |
| 3127 |
{ |
| 3128 |
|
| 3129 |
S_status_win->base.alignment = OS_BANNER_ALIGN_TOP; |
| 3130 |
S_status_win->base.size = 1; |
| 3131 |
S_status_win->base.size_type = OS_BANNER_SIZE_ABS; |
| 3132 |
|
| 3133 |
|
| 3134 |
S_status_win->base.txtfg = OSGEN_COLOR_STATUSLINE; |
| 3135 |
S_status_win->base.txtbg = OSGEN_COLOR_TRANSPARENT; |
| 3136 |
S_status_win->base.fillcolor = OSGEN_COLOR_STATUSBG; |
| 3137 |
|
| 3138 |
|
| 3139 |
S_status_win->base.oss_fillcolor = |
| 3140 |
ossgetcolor(OSGEN_COLOR_STATUSLINE, OSGEN_COLOR_STATUSBG, |
| 3141 |
0, 0); |
| 3142 |
|
| 3143 |
|
| 3144 |
osgen_recalc_layout(); |
| 3145 |
} |
| 3146 |
} |
| 3147 |
|
| 3148 |
|
| 3149 |
if (stat == 1 && status_mode != 1 && S_status_win != 0) |
| 3150 |
{ |
| 3151 |
|
| 3152 |
S_default_win = S_status_win; |
| 3153 |
|
| 3154 |
|
| 3155 |
osgen_clear_win(&S_status_win->base); |
| 3156 |
|
| 3157 |
|
| 3158 |
S_stat_reset_free = 0; |
| 3159 |
} |
| 3160 |
|
| 3161 |
|
| 3162 |
if (status_mode == 1 && stat != 1 && S_status_win != 0) |
| 3163 |
{ |
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
S_stat_reset_free = S_status_win->txtfree; |
| 3170 |
S_stat_reset_x = S_status_win->base.x; |
| 3171 |
|
| 3172 |
|
| 3173 |
osgen_update_stat_right(); |
| 3174 |
} |
| 3175 |
|
| 3176 |
|
| 3177 |
status_mode = stat; |
| 3178 |
|
| 3179 |
|
| 3180 |
if (status_mode == 0) |
| 3181 |
{ |
| 3182 |
|
| 3183 |
S_default_win = S_main_win; |
| 3184 |
} |
| 3185 |
else if (status_mode == 2) |
| 3186 |
{ |
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
S_default_win = 0; |
| 3192 |
} |
| 3193 |
} |
| 3194 |
|
| 3195 |
int os_get_status() |
| 3196 |
{ |
| 3197 |
return status_mode; |
| 3198 |
} |
| 3199 |
|
| 3200 |
|
| 3201 |
void os_strsc(const char *p) |
| 3202 |
{ |
| 3203 |
size_t copy_len; |
| 3204 |
|
| 3205 |
|
| 3206 |
if (p != 0) |
| 3207 |
{ |
| 3208 |
|
| 3209 |
copy_len = strlen(p); |
| 3210 |
if (copy_len > sizeof(S_scorebuf) - 1) |
| 3211 |
copy_len = sizeof(S_scorebuf) - 1; |
| 3212 |
|
| 3213 |
|
| 3214 |
memcpy(S_scorebuf, p, copy_len); |
| 3215 |
S_scorebuf[copy_len] = '\0'; |
| 3216 |
} |
| 3217 |
|
| 3218 |
|
| 3219 |
osgen_update_stat_right(); |
| 3220 |
} |
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
void os_score(int cur, int turncount) |
| 3230 |
{ |
| 3231 |
char buf[20]; |
| 3232 |
|
| 3233 |
|
| 3234 |
if (turncount == -1) |
| 3235 |
{ |
| 3236 |
|
| 3237 |
os_strsc((char *)0); |
| 3238 |
} |
| 3239 |
else |
| 3240 |
{ |
| 3241 |
|
| 3242 |
sprintf(buf, "%d/%d", cur, turncount); |
| 3243 |
|
| 3244 |
|
| 3245 |
os_strsc(buf); |
| 3246 |
} |
| 3247 |
} |
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
void os_plain(void) |
| 3256 |
{ |
| 3257 |
|
| 3258 |
os_f_plain = 1; |
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
|
| 3264 |
|
| 3265 |
if (oss_eof_on_stdin()) |
| 3266 |
G_os_moremode = FALSE; |
| 3267 |
} |
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
void os_printz(const char *str) |
| 3273 |
{ |
| 3274 |
|
| 3275 |
os_print(str, strlen(str)); |
| 3276 |
} |
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
void os_print(const char *str, size_t len) |
| 3282 |
{ |
| 3283 |
osgen_txtwin_t *win; |
| 3284 |
const char *p; |
| 3285 |
const char *startp; |
| 3286 |
size_t rem; |
| 3287 |
|
| 3288 |
|
| 3289 |
switch(status_mode) |
| 3290 |
{ |
| 3291 |
case 2: |
| 3292 |
|
| 3293 |
break; |
| 3294 |
|
| 3295 |
case 0: |
| 3296 |
|
| 3297 |
if (os_f_plain) |
| 3298 |
{ |
| 3299 |
|
| 3300 |
printf("%.*s", (int)len, str); |
| 3301 |
} |
| 3302 |
else |
| 3303 |
{ |
| 3304 |
|
| 3305 |
win = S_default_win; |
| 3306 |
if (win != 0) |
| 3307 |
{ |
| 3308 |
|
| 3309 |
ossaddsb(win, str, len, TRUE); |
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
if (!S_deferred_redraw |
| 3316 |
&& !(win->base.flags & OSGEN_DEFER_REDRAW)) |
| 3317 |
ossloc(win->base.winy + win->base.y - win->base.scrolly, |
| 3318 |
win->base.winx + win->base.x - win->base.scrollx); |
| 3319 |
} |
| 3320 |
} |
| 3321 |
|
| 3322 |
|
| 3323 |
break; |
| 3324 |
|
| 3325 |
case 1: |
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
if (os_f_plain || (win = S_status_win) == 0) |
| 3331 |
break; |
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
p = str; |
| 3340 |
rem = len; |
| 3341 |
if (win->base.winy == 0 || win->base.winx == 0) |
| 3342 |
{ |
| 3343 |
|
| 3344 |
for ( ; rem != 0 && *p == '\n' ; ++p, --rem) ; |
| 3345 |
|
| 3346 |
|
| 3347 |
if (rem == 0) |
| 3348 |
break; |
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
ossaddsb(win, " ", 1, TRUE); |
| 3355 |
} |
| 3356 |
|
| 3357 |
|
| 3358 |
for (startp = p ; rem != 0 && *p != '\n' ; ++p, --rem) |
| 3359 |
{ |
| 3360 |
|
| 3361 |
switch (*p) |
| 3362 |
{ |
| 3363 |
case OSGEN_ATTR: |
| 3364 |
|
| 3365 |
p += 1; |
| 3366 |
rem -= 1; |
| 3367 |
break; |
| 3368 |
|
| 3369 |
case OSGEN_COLOR: |
| 3370 |
|
| 3371 |
p += 2; |
| 3372 |
rem -= 2; |
| 3373 |
break; |
| 3374 |
|
| 3375 |
default: |
| 3376 |
|
| 3377 |
break; |
| 3378 |
} |
| 3379 |
} |
| 3380 |
|
| 3381 |
|
| 3382 |
ossaddsb(win, startp, p - startp, TRUE); |
| 3383 |
|
| 3384 |
|
| 3385 |
if (*p == '\n') |
| 3386 |
{ |
| 3387 |
|
| 3388 |
os_status(2); |
| 3389 |
} |
| 3390 |
|
| 3391 |
|
| 3392 |
break; |
| 3393 |
} |
| 3394 |
} |
| 3395 |
|
| 3396 |
#ifndef FROBTADS |
| 3397 |
void os_flush(void) |
| 3398 |
{ |
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
if (os_f_plain) |
| 3405 |
fflush(stdout); |
| 3406 |
} |
| 3407 |
#endif |
| 3408 |
|
| 3409 |
void os_update_display(void) |
| 3410 |
{ |
| 3411 |
|
| 3412 |
} |
| 3413 |
|
| 3414 |
# ifdef USE_HISTORY |
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
static osfar_t char *histbuf = 0; |
| 3424 |
static osfar_t char *histhead = 0; |
| 3425 |
static osfar_t char *histtail = 0; |
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
char *ossadvhp(char *p) |
| 3433 |
{ |
| 3434 |
if (++p >= histbuf + HISTBUFSIZE) |
| 3435 |
p = histbuf; |
| 3436 |
return p; |
| 3437 |
} |
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
char *ossdechp(char *p) |
| 3444 |
{ |
| 3445 |
if (p == histbuf) |
| 3446 |
p = histbuf + HISTBUFSIZE; |
| 3447 |
return p - 1; |
| 3448 |
} |
| 3449 |
|
| 3450 |
|
| 3451 |
|
| 3452 |
|
| 3453 |
|
| 3454 |
|
| 3455 |
void osshstcpy(char *dst, char *hst) |
| 3456 |
{ |
| 3457 |
while (*hst != '\0') |
| 3458 |
{ |
| 3459 |
*dst++ = *hst; |
| 3460 |
hst = ossadvhp(hst); |
| 3461 |
} |
| 3462 |
*dst = '\0'; |
| 3463 |
} |
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
|
| 3469 |
|
| 3470 |
char *ossprvcmd(char *hst) |
| 3471 |
{ |
| 3472 |
|
| 3473 |
if (hst == histtail) |
| 3474 |
return 0; |
| 3475 |
|
| 3476 |
|
| 3477 |
hst = ossdechp(hst); |
| 3478 |
|
| 3479 |
|
| 3480 |
do |
| 3481 |
{ |
| 3482 |
hst = ossdechp(hst); |
| 3483 |
} while (*hst && hst != histtail); |
| 3484 |
|
| 3485 |
|
| 3486 |
if (*hst == 0) |
| 3487 |
hst = ossadvhp(hst); |
| 3488 |
|
| 3489 |
|
| 3490 |
return hst; |
| 3491 |
} |
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
|
| 3496 |
|
| 3497 |
|
| 3498 |
char *ossnxtcmd(char *hst) |
| 3499 |
{ |
| 3500 |
|
| 3501 |
if (hst == histhead) |
| 3502 |
return 0; |
| 3503 |
|
| 3504 |
|
| 3505 |
while(*hst != '\0') |
| 3506 |
hst = ossadvhp(hst); |
| 3507 |
|
| 3508 |
|
| 3509 |
hst = ossadvhp(hst); |
| 3510 |
|
| 3511 |
|
| 3512 |
return hst; |
| 3513 |
} |
| 3514 |
# endif |
| 3515 |
|
| 3516 |
|
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
static void ossdsp_str(osgen_win_t *win, int y, int x, int color, |
| 3524 |
char *str, size_t len, int *delta_yscroll) |
| 3525 |
{ |
| 3526 |
|
| 3527 |
if (delta_yscroll != 0) |
| 3528 |
*delta_yscroll = 0; |
| 3529 |
|
| 3530 |
|
| 3531 |
while (len != 0) |
| 3532 |
{ |
| 3533 |
size_t cur; |
| 3534 |
unsigned char oldc; |
| 3535 |
|
| 3536 |
|
| 3537 |
cur = win->winx + win->wid - x; |
| 3538 |
if (cur > len) |
| 3539 |
cur = len; |
| 3540 |
|
| 3541 |
|
| 3542 |
oldc = str[cur]; |
| 3543 |
str[cur] = '\0'; |
| 3544 |
|
| 3545 |
|
| 3546 |
ossdsp(y, x, color, (char *)str); |
| 3547 |
|
| 3548 |
|
| 3549 |
str[cur] = oldc; |
| 3550 |
|
| 3551 |
|
| 3552 |
str += cur; |
| 3553 |
len -= cur; |
| 3554 |
|
| 3555 |
|
| 3556 |
x += cur; |
| 3557 |
|
| 3558 |
|
| 3559 |
if (x >= win->winx + (int)win->wid) |
| 3560 |
{ |
| 3561 |
|
| 3562 |
x = win->winx; |
| 3563 |
|
| 3564 |
|
| 3565 |
++y; |
| 3566 |
|
| 3567 |
|
| 3568 |
|
| 3569 |
|
| 3570 |
|
| 3571 |
if (y >= win->winy + (int)win->ht && delta_yscroll != 0) |
| 3572 |
{ |
| 3573 |
|
| 3574 |
ossscr(win->winy, win->winx, |
| 3575 |
win->winy + win->ht - 1, win->winx + win->wid - 1, |
| 3576 |
win->oss_fillcolor); |
| 3577 |
|
| 3578 |
|
| 3579 |
win->scrolly++; |
| 3580 |
|
| 3581 |
|
| 3582 |
++(*delta_yscroll); |
| 3583 |
|
| 3584 |
|
| 3585 |
--y; |
| 3586 |
} |
| 3587 |
} |
| 3588 |
} |
| 3589 |
} |
| 3590 |
|
| 3591 |
|
| 3592 |
|
| 3593 |
|
| 3594 |
static void oss_gets_csrleft(osgen_txtwin_t *win, int *y, int *x, size_t len) |
| 3595 |
{ |
| 3596 |
for ( ; len != 0 ; --len) |
| 3597 |
{ |
| 3598 |
|
| 3599 |
if (--*x < win->base.winx) |
| 3600 |
{ |
| 3601 |
|
| 3602 |
--*y; |
| 3603 |
|
| 3604 |
|
| 3605 |
*x = win->base.winx + win->base.wid - 1; |
| 3606 |
} |
| 3607 |
} |
| 3608 |
} |
| 3609 |
|
| 3610 |
|
| 3611 |
|
| 3612 |
|
| 3613 |
static void oss_gets_csrright(osgen_txtwin_t *win, int *y, int *x, size_t len) |
| 3614 |
{ |
| 3615 |
for ( ; len != 0 ; --len) |
| 3616 |
{ |
| 3617 |
|
| 3618 |
if (++*x >= win->base.winx + (int)win->base.wid) |
| 3619 |
{ |
| 3620 |
|
| 3621 |
++*y; |
| 3622 |
|
| 3623 |
|
| 3624 |
*x = win->base.winx; |
| 3625 |
} |
| 3626 |
} |
| 3627 |
} |
| 3628 |
|
| 3629 |
|
| 3630 |
|
| 3631 |
|
| 3632 |
static void oss_gets_clear(osgen_txtwin_t *win, int y, int x, size_t len) |
| 3633 |
{ |
| 3634 |
|
| 3635 |
if (x + (int)len <= win->base.winx) |
| 3636 |
return; |
| 3637 |
|
| 3638 |
|
| 3639 |
if (x < win->base.winx) |
| 3640 |
{ |
| 3641 |
|
| 3642 |
len -= (win->base.winx - x); |
| 3643 |
|
| 3644 |
|
| 3645 |
x = win->base.winx; |
| 3646 |
} |
| 3647 |
|
| 3648 |
|
| 3649 |
while (len != 0) |
| 3650 |
{ |
| 3651 |
size_t cur; |
| 3652 |
|
| 3653 |
|
| 3654 |
cur = win->base.winx + win->base.wid - x; |
| 3655 |
|
| 3656 |
|
| 3657 |
if (cur > len) |
| 3658 |
cur = len; |
| 3659 |
|
| 3660 |
|
| 3661 |
ossclr(y, x, y, x + cur - 1, win->base.oss_fillcolor); |
| 3662 |
|
| 3663 |
|
| 3664 |
len -= cur; |
| 3665 |
|
| 3666 |
|
| 3667 |
x = win->base.winx; |
| 3668 |
++y; |
| 3669 |
|
| 3670 |
|
| 3671 |
if (y >= win->base.winy + (int)win->base.ht) |
| 3672 |
break; |
| 3673 |
} |
| 3674 |
} |
| 3675 |
|
| 3676 |
|
| 3677 |
|
| 3678 |
|
| 3679 |
static void oss_gets_delchar(osgen_txtwin_t *win, |
| 3680 |
char *buf, char *p, char **eol, int x, int y) |
| 3681 |
{ |
| 3682 |
int color; |
| 3683 |
|
| 3684 |
|
| 3685 |
color = ossgetcolor(win->base.txtfg, win->base.txtbg, |
| 3686 |
win->base.txtattr, win->base.fillcolor); |
| 3687 |
|
| 3688 |
|
| 3689 |
if (p < *eol) |
| 3690 |
{ |
| 3691 |
|
| 3692 |
--*eol; |
| 3693 |
if (p != *eol) |
| 3694 |
memmove(p, p + 1, *eol - p); |
| 3695 |
|
| 3696 |
|
| 3697 |
**eol = '\0'; |
| 3698 |
|
| 3699 |
|
| 3700 |
ossdsp_str(&win->base, y, x, color, p, *eol - p, 0); |
| 3701 |
|
| 3702 |
|
| 3703 |
oss_gets_csrright(win, &y, &x, *eol - p); |
| 3704 |
|
| 3705 |
|
| 3706 |
ossclr(y, x, y, x, win->base.oss_fillcolor); |
| 3707 |
} |
| 3708 |
} |
| 3709 |
|
| 3710 |
|
| 3711 |
|
| 3712 |
|
| 3713 |
|
| 3714 |
static void oss_gets_backsp(osgen_txtwin_t *win, |
| 3715 |
char *buf, char **p, |
| 3716 |
char **eol, int *x, int *y) |
| 3717 |
{ |
| 3718 |
int color; |
| 3719 |
|
| 3720 |
|
| 3721 |
color = ossgetcolor(win->base.txtfg, win->base.txtbg, |
| 3722 |
win->base.txtattr, win->base.fillcolor); |
| 3723 |
|
| 3724 |
|
| 3725 |
if (*p > buf) |
| 3726 |
{ |
| 3727 |
int tmpy; |
| 3728 |
int tmpx; |
| 3729 |
|
| 3730 |
|
| 3731 |
--*p; |
| 3732 |
|
| 3733 |
|
| 3734 |
--*eol; |
| 3735 |
|
| 3736 |
|
| 3737 |
if (*p != *eol) |
| 3738 |
memmove(*p, *p + 1, *eol - *p); |
| 3739 |
|
| 3740 |
|
| 3741 |
if (--*x < win->base.winx) |
| 3742 |
{ |
| 3743 |
*x = win->base.winx + win->base.wid - 1; |
| 3744 |
--*y; |
| 3745 |
} |
| 3746 |
|
| 3747 |
|
| 3748 |
**eol = '\0'; |
| 3749 |
|
| 3750 |
|
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
tmpy = *y; |
| 3755 |
tmpx = *x; |
| 3756 |
ossdsp_str(&win->base, tmpy, tmpx, color, *p, *eol - *p, 0); |
| 3757 |
|
| 3758 |
|
| 3759 |
oss_gets_csrright(win, &tmpy, &tmpx, *eol - *p); |
| 3760 |
ossclr(tmpy, tmpx, tmpy, tmpx, win->base.oss_fillcolor); |
| 3761 |
} |
| 3762 |
} |
| 3763 |
|
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
static void osgen_gets_redraw_cmdline(void) |
| 3768 |
{ |
| 3769 |
osgen_txtwin_t *win; |
| 3770 |
int x, y; |
| 3771 |
int color; |
| 3772 |
|
| 3773 |
|
| 3774 |
|
| 3775 |
|
| 3776 |
|
| 3777 |
if ((win = S_default_win) == 0 || !S_gets_in_progress) |
| 3778 |
return; |
| 3779 |
|
| 3780 |
|
| 3781 |
x = S_gets_x; |
| 3782 |
y = S_gets_y; |
| 3783 |
|
| 3784 |
|
| 3785 |
oss_gets_csrleft(win, &y, &x, S_gets_ofs); |
| 3786 |
|
| 3787 |
|
| 3788 |
color = ossgetcolor(win->base.txtfg, win->base.txtbg, |
| 3789 |
win->base.txtattr, win->base.fillcolor); |
| 3790 |
|
| 3791 |
|
| 3792 |
ossdsp_str(&win->base, y, x, color, S_gets_buf, strlen(S_gets_buf), 0); |
| 3793 |
} |
| 3794 |
|
| 3795 |
|
| 3796 |
|
| 3797 |
|
| 3798 |
|
| 3799 |
void os_gets_cancel(int reset) |
| 3800 |
{ |
| 3801 |
int x, y; |
| 3802 |
|
| 3803 |
|
| 3804 |
if (S_sbmode_win != 0) |
| 3805 |
osgen_sb_mode_end(); |
| 3806 |
|
| 3807 |
|
| 3808 |
osssb_redraw_if_needed(); |
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
if (S_gets_in_progress) |
| 3815 |
{ |
| 3816 |
osgen_txtwin_t *win; |
| 3817 |
|
| 3818 |
|
| 3819 |
win = S_main_win; |
| 3820 |
|
| 3821 |
|
| 3822 |
x = S_gets_x; |
| 3823 |
y = S_gets_y; |
| 3824 |
oss_gets_csrright(win, &y, &x, strlen(S_gets_buf + S_gets_ofs)); |
| 3825 |
|
| 3826 |
|
| 3827 |
ossloc(y, x); |
| 3828 |
|
| 3829 |
|
| 3830 |
ossaddsb_input(win, (char *)S_gets_buf, TRUE); |
| 3831 |
|
| 3832 |
|
| 3833 |
S_gets_in_progress = FALSE; |
| 3834 |
} |
| 3835 |
|
| 3836 |
|
| 3837 |
if (reset) |
| 3838 |
S_gets_buf[0] = '\0'; |
| 3839 |
} |
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
int os_gets_begin(size_t max_line_len) |
| 3847 |
{ |
| 3848 |
osgen_txtwin_t *win; |
| 3849 |
|
| 3850 |
|
| 3851 |
if ((win = S_default_win) == 0) |
| 3852 |
return FALSE; |
| 3853 |
|
| 3854 |
|
| 3855 |
osssb_redraw_if_needed(); |
| 3856 |
|
| 3857 |
|
| 3858 |
if (win->base.y >= win->base.scrolly + (int)win->base.ht) |
| 3859 |
osgen_scroll_win_fwd(win, win->base.y |
| 3860 |
- (win->base.scrolly + win->base.ht) + 1); |
| 3861 |
|
| 3862 |
|
| 3863 |
if (win->base.scrollx != 0) |
| 3864 |
{ |
| 3865 |
|
| 3866 |
win->base.scrollx = 0; |
| 3867 |
|
| 3868 |
|
| 3869 |
osgen_redraw_win(&win->base); |
| 3870 |
} |
| 3871 |
|
| 3872 |
# ifdef USE_HISTORY |
| 3873 |
|
| 3874 |
if (histbuf == 0) |
| 3875 |
{ |
| 3876 |
histbuf = (char *)osmalloc(HISTBUFSIZE); |
| 3877 |
histhead = histtail = histbuf; |
| 3878 |
S_gets_curhist = histhead; |
| 3879 |
} |
| 3880 |
# endif |
| 3881 |
|
| 3882 |
|
| 3883 |
|
| 3884 |
|
| 3885 |
|
| 3886 |
if (S_gets_buf[0] != '\0' || S_gets_in_progress) |
| 3887 |
{ |
| 3888 |
|
| 3889 |
|
| 3890 |
|
| 3891 |
|
| 3892 |
|
| 3893 |
if (!S_gets_in_progress) |
| 3894 |
{ |
| 3895 |
int x; |
| 3896 |
int y; |
| 3897 |
int deltay; |
| 3898 |
int color; |
| 3899 |
|
| 3900 |
|
| 3901 |
x = win->base.winx + win->base.x - win->base.scrollx; |
| 3902 |
y = win->base.winy + win->base.y - win->base.scrolly; |
| 3903 |
|
| 3904 |
|
| 3905 |
color = ossgetcolor(win->base.txtfg, win->base.txtbg, |
| 3906 |
win->base.txtattr, win->base.fillcolor); |
| 3907 |
|
| 3908 |
|
| 3909 |
ossdsp_str(&win->base, y, x, color, |
| 3910 |
S_gets_buf, strlen(S_gets_buf), &deltay); |
| 3911 |
|
| 3912 |
|
| 3913 |
y -= deltay; |
| 3914 |
|
| 3915 |
|
| 3916 |
if (S_gets_ofs > (int)max_line_len) |
| 3917 |
S_gets_ofs = max_line_len; |
| 3918 |
|
| 3919 |
|
| 3920 |
oss_gets_csrright(win, &y, &x, S_gets_ofs); |
| 3921 |
|
| 3922 |
|
| 3923 |
S_gets_x = x; |
| 3924 |
S_gets_y = y; |
| 3925 |
} |
| 3926 |
} |
| 3927 |
else |
| 3928 |
{ |
| 3929 |
|
| 3930 |
S_gets_curhist = histhead; |
| 3931 |
|
| 3932 |
|
| 3933 |
S_gets_x = win->base.winx + win->base.x - win->base.scrollx; |
| 3934 |
S_gets_y = win->base.winy + win->base.y - win->base.scrolly; |
| 3935 |
|
| 3936 |
|
| 3937 |
S_gets_ofs = 0; |
| 3938 |
} |
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
if (max_line_len > S_gets_buf_siz) |
| 3946 |
S_gets_buf_end = S_gets_buf + S_gets_buf_siz - 1; |
| 3947 |
else |
| 3948 |
S_gets_buf_end = S_gets_buf + max_line_len - 1; |
| 3949 |
|
| 3950 |
|
| 3951 |
S_special_cursor_pos = TRUE; |
| 3952 |
S_special_cursor_x = S_gets_x; |
| 3953 |
S_special_cursor_y = S_gets_y; |
| 3954 |
|
| 3955 |
|
| 3956 |
S_gets_in_progress = TRUE; |
| 3957 |
|
| 3958 |
|
| 3959 |
return TRUE; |
| 3960 |
} |
| 3961 |
|
| 3962 |
|
| 3963 |
|
| 3964 |
|
| 3965 |
|
| 3966 |
|
| 3967 |
|
| 3968 |
|
| 3969 |
int os_gets_process(int event_type, os_event_info_t *event_info) |
| 3970 |
{ |
| 3971 |
unsigned char c; |
| 3972 |
char *p; |
| 3973 |
char *eol; |
| 3974 |
char *buf; |
| 3975 |
size_t bufsiz; |
| 3976 |
int x; |
| 3977 |
int y; |
| 3978 |
osgen_txtwin_t *win; |
| 3979 |
int color; |
| 3980 |
|
| 3981 |
|
| 3982 |
if ((win = S_default_win) == 0) |
| 3983 |
return TRUE; |
| 3984 |
|
| 3985 |
|
| 3986 |
if (event_type == OS_EVT_KEY) |
| 3987 |
oss_raw_key_to_cmd(event_info); |
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
if (S_sbmode_win != 0) |
| 3994 |
{ |
| 3995 |
|
| 3996 |
if (osgen_sb_mode(win, event_type, event_info)) |
| 3997 |
{ |
| 3998 |
|
| 3999 |
|
| 4000 |
|
| 4001 |
|
| 4002 |
return FALSE; |
| 4003 |
} |
| 4004 |
} |
| 4005 |
|
| 4006 |
|
| 4007 |
if (event_type != OS_EVT_KEY) |
| 4008 |
return FALSE; |
| 4009 |
|
| 4010 |
|
| 4011 |
c = (unsigned char)event_info->key[0]; |
| 4012 |
|
| 4013 |
|
| 4014 |
x = S_gets_x; |
| 4015 |
y = S_gets_y; |
| 4016 |
|
| 4017 |
|
| 4018 |
p = S_gets_buf + S_gets_ofs; |
| 4019 |
buf = S_gets_buf; |
| 4020 |
bufsiz = S_gets_buf_siz; |
| 4021 |
eol = p + strlen(p); |
| 4022 |
|
| 4023 |
|
| 4024 |
color = ossgetcolor(win->base.txtfg, win->base.txtbg, |
| 4025 |
win->base.txtattr, win->base.fillcolor); |
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
|
| 4030 |
|
| 4031 |
|
| 4032 |
switch(c) |
| 4033 |
{ |
| 4034 |
case 8: |
| 4035 |
|
| 4036 |
oss_gets_backsp(win, buf, &p, &eol, &x, &y); |
| 4037 |
break; |
| 4038 |
|
| 4039 |
case 13: |
| 4040 |
|
| 4041 |
*eol = '\0'; |
| 4042 |
|
| 4043 |
|
| 4044 |
oss_gets_csrright(win, &y, &x, eol - p); |
| 4045 |
p = eol; |
| 4046 |
|
| 4047 |
# ifdef USE_HISTORY |
| 4048 |
|
| 4049 |
|
| 4050 |
|
| 4051 |
|
| 4052 |
|
| 4053 |
|
| 4054 |
if (strlen(buf) != 0) |
| 4055 |
{ |
| 4056 |
char *q; |
| 4057 |
int advtail; |
| 4058 |
int saveflag = 1; |
| 4059 |
|
| 4060 |
if ((q = ossprvcmd(histhead)) != 0) |
| 4061 |
{ |
| 4062 |
char *p = buf; |
| 4063 |
|
| 4064 |
while (*p == *q && *p != '\0' && *q != '\0') |
| 4065 |
{ |
| 4066 |
++p; |
| 4067 |
q = ossadvhp(q); |
| 4068 |
} |
| 4069 |
if (*p == *q) |
| 4070 |
saveflag = 0; |
| 4071 |
} |
| 4072 |
|
| 4073 |
if (saveflag) |
| 4074 |
{ |
| 4075 |
for (q = buf, advtail = 0 ; q <= eol ; ++q) |
| 4076 |
{ |
| 4077 |
*histhead = *q; |
| 4078 |
histhead = ossadvhp(histhead); |
| 4079 |
if (histhead == histtail) |
| 4080 |
{ |
| 4081 |
histtail = ossadvhp(histtail); |
| 4082 |
advtail = 1; |
| 4083 |
} |
| 4084 |
} |
| 4085 |
|
| 4086 |
|
| 4087 |
|
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
if (advtail) |
| 4093 |
{ |
| 4094 |
while(*histtail) |
| 4095 |
histtail = ossadvhp(histtail); |
| 4096 |
histtail = ossadvhp(histtail); |
| 4097 |
} |
| 4098 |
} |
| 4099 |
} |
| 4100 |
# endif |
| 4101 |
|
| 4102 |
|
| 4103 |
ossaddsb_input(win, buf, TRUE); |
| 4104 |
|
| 4105 |
|
| 4106 |
S_special_cursor_pos = FALSE; |
| 4107 |
|
| 4108 |
|
| 4109 |
|
| 4110 |
|
| 4111 |
|
| 4112 |
osgen_auto_vscroll(win); |
| 4113 |
osssb_cursor_to_default_pos(); |
| 4114 |
|
| 4115 |
|
| 4116 |
S_gets_in_progress = FALSE; |
| 4117 |
|
| 4118 |
|
| 4119 |
return TRUE; |
| 4120 |
|
| 4121 |
case 0: |
| 4122 |
|
| 4123 |
c = (unsigned char)event_info->key[1]; |
| 4124 |
|
| 4125 |
|
| 4126 |
switch(c) |
| 4127 |
{ |
| 4128 |
# ifdef USE_SCROLLBACK |
| 4129 |
case CMD_SCR: |
| 4130 |
case CMD_PGUP: |
| 4131 |
case CMD_PGDN: |
| 4132 |
|
| 4133 |
osgen_sb_mode(win, event_type, event_info); |
| 4134 |
|
| 4135 |
|
| 4136 |
break; |
| 4137 |
# endif |
| 4138 |
|
| 4139 |
case CMD_LEFT: |
| 4140 |
|
| 4141 |
if (p > buf) |
| 4142 |
{ |
| 4143 |
--p; |
| 4144 |
oss_gets_csrleft(win, &y, &x, 1); |
| 4145 |
} |
| 4146 |
break; |
| 4147 |
|
| 4148 |
case CMD_WORD_LEFT: |
| 4149 |
|
| 4150 |
|
| 4151 |
|
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
if (p > buf) |
| 4156 |
{ |
| 4157 |
|
| 4158 |
--p; |
| 4159 |
oss_gets_csrleft(win, &y, &x, 1); |
| 4160 |
|
| 4161 |
|
| 4162 |
while (p > buf && t_isspace(*p) && !t_isspace(*(p-1))) |
| 4163 |
{ |
| 4164 |
--p; |
| 4165 |
oss_gets_csrleft(win, &y, &x, 1); |
| 4166 |
} |
| 4167 |
|
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
|
| 4172 |
while (p > buf && !t_isspace(*(p-1))) |
| 4173 |
{ |
| 4174 |
--p; |
| 4175 |
oss_gets_csrleft(win, &y, &x, 1); |
| 4176 |
} |
| 4177 |
} |
| 4178 |
break; |
| 4179 |
|
| 4180 |
case CMD_RIGHT: |
| 4181 |
|
| 4182 |
if (p < eol) |
| 4183 |
{ |
| 4184 |
++p; |
| 4185 |
oss_gets_csrright(win, &y, &x, 1); |
| 4186 |
} |
| 4187 |
break; |
| 4188 |
|
| 4189 |
case CMD_WORD_RIGHT: |
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
|
| 4195 |
|
| 4196 |
|
| 4197 |
while (p < eol && !t_isspace(*p)) |
| 4198 |
{ |
| 4199 |
++p; |
| 4200 |
oss_gets_csrright(win, &y, &x, 1); |
| 4201 |
} |
| 4202 |
|
| 4203 |
|
| 4204 |
while (p < eol && t_isspace(*p)) |
| 4205 |
{ |
| 4206 |
++p; |
| 4207 |
oss_gets_csrright(win, &y, &x, 1); |
| 4208 |
} |
| 4209 |
break; |
| 4210 |
|
| 4211 |
case CMD_DEL: |
| 4212 |
|
| 4213 |
oss_gets_delchar(win, buf, p, &eol, x, y); |
| 4214 |
break; |
| 4215 |
|
| 4216 |
#ifdef UNIX |
| 4217 |
case CMD_WORDKILL: |
| 4218 |
{ |
| 4219 |
|
| 4220 |
while (p >= buf && *p <= ' ') |
| 4221 |
oss_gets_backsp(win, buf, &p, &eol, &x, &y); |
| 4222 |
|
| 4223 |
|
| 4224 |
while (p >= buf && *p > ' ') |
| 4225 |
oss_gets_backsp(win, buf, &p, &eol, &x, &y); |
| 4226 |
|
| 4227 |
|
| 4228 |
break; |
| 4229 |
} |
| 4230 |
#endif |
| 4231 |
|
| 4232 |
case CMD_KILL: |
| 4233 |
case CMD_HOME: |
| 4234 |
# ifdef USE_HISTORY |
| 4235 |
case CMD_UP: |
| 4236 |
case CMD_DOWN: |
| 4237 |
|
| 4238 |
|
| 4239 |
|
| 4240 |
|
| 4241 |
|
| 4242 |
|
| 4243 |
|
| 4244 |
if (c == CMD_UP && !ossprvcmd(S_gets_curhist)) |
| 4245 |
break; |
| 4246 |
|
| 4247 |
|
| 4248 |
if (c == CMD_DOWN && !ossnxtcmd(S_gets_curhist)) |
| 4249 |
break; |
| 4250 |
|
| 4251 |
|
| 4252 |
|
| 4253 |
|
| 4254 |
|
| 4255 |
|
| 4256 |
|
| 4257 |
|
| 4258 |
if (c == CMD_UP && !ossnxtcmd(S_gets_curhist)) |
| 4259 |
safe_strcpy(S_hist_sav, S_hist_sav_siz, buf); |
| 4260 |
|
| 4261 |
# endif |
| 4262 |
|
| 4263 |
|
| 4264 |
if (p != buf) |
| 4265 |
{ |
| 4266 |
|
| 4267 |
oss_gets_csrleft(win, &y, &x, p - buf); |
| 4268 |
|
| 4269 |
|
| 4270 |
p = buf; |
| 4271 |
} |
| 4272 |
|
| 4273 |
|
| 4274 |
if (c == CMD_HOME) |
| 4275 |
break; |
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
|
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
case CMD_DEOL: |
| 4284 |
|
| 4285 |
oss_gets_clear(win, y, x, eol - p); |
| 4286 |
|
| 4287 |
|
| 4288 |
eol = p; |
| 4289 |
*p = '\0'; |
| 4290 |
|
| 4291 |
# ifdef USE_HISTORY |
| 4292 |
if (c == CMD_UP) |
| 4293 |
{ |
| 4294 |
S_gets_curhist = ossprvcmd(S_gets_curhist); |
| 4295 |
osshstcpy(buf, S_gets_curhist); |
| 4296 |
} |
| 4297 |
else if (c == CMD_DOWN) |
| 4298 |
{ |
| 4299 |
if (!ossnxtcmd(S_gets_curhist)) |
| 4300 |
break; |
| 4301 |
S_gets_curhist = ossnxtcmd(S_gets_curhist); |
| 4302 |
if (ossnxtcmd(S_gets_curhist)) |
| 4303 |
osshstcpy(buf, S_gets_curhist); |
| 4304 |
else |
| 4305 |
{ |
| 4306 |
|
| 4307 |
safe_strcpy(buf, bufsiz, S_hist_sav); |
| 4308 |
} |
| 4309 |
} |
| 4310 |
if ((c == CMD_UP || c == CMD_DOWN) |
| 4311 |
&& strlen(buf) != 0) |
| 4312 |
{ |
| 4313 |
int deltay; |
| 4314 |
|
| 4315 |
|
| 4316 |
eol = buf + strlen(buf); |
| 4317 |
|
| 4318 |
|
| 4319 |
ossdsp_str(&win->base, y, x, color, p, eol - p, &deltay); |
| 4320 |
y -= deltay; |
| 4321 |
|
| 4322 |
|
| 4323 |
oss_gets_csrright(win, &y, &x, eol - p); |
| 4324 |
p = eol; |
| 4325 |
} |
| 4326 |
# endif |
| 4327 |
break; |
| 4328 |
case CMD_END: |
| 4329 |
while (p < eol) |
| 4330 |
{ |
| 4331 |
++p; |
| 4332 |
if (++x >= win->base.winx + (int)win->base.wid) |
| 4333 |
{ |
| 4334 |
x = win->base.winx; |
| 4335 |
++y; |
| 4336 |
} |
| 4337 |
} |
| 4338 |
break; |
| 4339 |
} |
| 4340 |
break; |
| 4341 |
|
| 4342 |
default: |
| 4343 |
if (c >= ' ' && eol < S_gets_buf_end) |
| 4344 |
{ |
| 4345 |
int deltay; |
| 4346 |
|
| 4347 |
|
| 4348 |
if (p != eol) |
| 4349 |
memmove(p + 1, p, eol - p); |
| 4350 |
++eol; |
| 4351 |
*p = (char)c; |
| 4352 |
*eol = '\0'; |
| 4353 |
|
| 4354 |
|
| 4355 |
ossdsp_str(&win->base, y, x, color, p, eol - p, &deltay); |
| 4356 |
y -= deltay; |
| 4357 |
|
| 4358 |
|
| 4359 |
oss_gets_csrright(win, &y, &x, 1); |
| 4360 |
|
| 4361 |
|
| 4362 |
++p; |
| 4363 |
} |
| 4364 |
break; |
| 4365 |
} |
| 4366 |
|
| 4367 |
|
| 4368 |
S_special_cursor_x = S_gets_x = x; |
| 4369 |
S_special_cursor_y = S_gets_y = y; |
| 4370 |
S_gets_ofs = p - S_gets_buf; |
| 4371 |
|
| 4372 |
|
| 4373 |
return FALSE; |
| 4374 |
} |
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
|
| 4381 |
|
| 4382 |
int os_gets_timeout(unsigned char *buf, size_t bufl, |
| 4383 |
unsigned long timeout, int use_timeout) |
| 4384 |
{ |
| 4385 |
long end_time; |
| 4386 |
osgen_txtwin_t *win; |
| 4387 |
|
| 4388 |
|
| 4389 |
if (os_f_plain) |
| 4390 |
{ |
| 4391 |
size_t len; |
| 4392 |
|
| 4393 |
|
| 4394 |
fflush(stdout); |
| 4395 |
|
| 4396 |
|
| 4397 |
if (use_timeout) |
| 4398 |
return OS_EVT_NOTIMEOUT; |
| 4399 |
|
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
|
| 4405 |
if (fgets((char *)buf, bufl, stdin) == 0) |
| 4406 |
return OS_EVT_EOF; |
| 4407 |
|
| 4408 |
|
| 4409 |
if ((len = strlen((char *)buf)) != 0 && buf[len-1] == '\n') |
| 4410 |
buf[len-1] = '\0'; |
| 4411 |
|
| 4412 |
|
| 4413 |
return OS_EVT_LINE; |
| 4414 |
} |
| 4415 |
|
| 4416 |
|
| 4417 |
os_gets_begin(bufl); |
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
end_time = os_get_sys_clock_ms() + timeout; |
| 4427 |
|
| 4428 |
|
| 4429 |
if ((win = S_default_win) == 0) |
| 4430 |
return OS_EVT_EOF; |
| 4431 |
|
| 4432 |
|
| 4433 |
for ( ;; ) |
| 4434 |
{ |
| 4435 |
int event_type; |
| 4436 |
os_event_info_t event_info; |
| 4437 |
|
| 4438 |
|
| 4439 |
if (use_timeout) |
| 4440 |
{ |
| 4441 |
long cur_clock; |
| 4442 |
|
| 4443 |
|
| 4444 |
cur_clock = os_get_sys_clock_ms(); |
| 4445 |
|
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
if (cur_clock >= end_time) |
| 4451 |
goto timeout_expired; |
| 4452 |
|
| 4453 |
|
| 4454 |
timeout = end_time - cur_clock; |
| 4455 |
} |
| 4456 |
|
| 4457 |
|
| 4458 |
if (S_sbmode_win != 0) |
| 4459 |
ossloc(S_sbmode_win->base.winy, S_sbmode_win->base.winx); |
| 4460 |
else |
| 4461 |
ossloc(S_gets_y, S_gets_x); |
| 4462 |
|
| 4463 |
|
| 4464 |
event_type = os_get_event(timeout, use_timeout, &event_info); |
| 4465 |
|
| 4466 |
|
| 4467 |
switch(event_type) |
| 4468 |
{ |
| 4469 |
case OS_EVT_TIMEOUT: |
| 4470 |
timeout_expired: |
| 4471 |
|
| 4472 |
S_special_cursor_pos = FALSE; |
| 4473 |
|
| 4474 |
|
| 4475 |
return OS_EVT_TIMEOUT; |
| 4476 |
|
| 4477 |
case OS_EVT_NOTIMEOUT: |
| 4478 |
|
| 4479 |
|
| 4480 |
|
| 4481 |
|
| 4482 |
S_special_cursor_pos = FALSE; |
| 4483 |
return OS_EVT_NOTIMEOUT; |
| 4484 |
|
| 4485 |
case OS_EVT_EOF: |
| 4486 |
|
| 4487 |
S_special_cursor_pos = FALSE; |
| 4488 |
S_gets_in_progress = FALSE; |
| 4489 |
return OS_EVT_EOF; |
| 4490 |
|
| 4491 |
default: |
| 4492 |
|
| 4493 |
if (os_gets_process(event_type, &event_info)) |
| 4494 |
{ |
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
strcpy((char *)buf, S_gets_buf); |
| 4501 |
|
| 4502 |
|
| 4503 |
S_gets_buf[0] = '\0'; |
| 4504 |
|
| 4505 |
|
| 4506 |
S_gets_in_progress = FALSE; |
| 4507 |
|
| 4508 |
|
| 4509 |
return OS_EVT_LINE; |
| 4510 |
} |
| 4511 |
break; |
| 4512 |
} |
| 4513 |
} |
| 4514 |
} |
| 4515 |
|
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
|
| 4520 |
uchar *os_gets(unsigned char *buf, size_t bufl) |
| 4521 |
{ |
| 4522 |
int evt; |
| 4523 |
|
| 4524 |
|
| 4525 |
os_gets_cancel(TRUE); |
| 4526 |
|
| 4527 |
|
| 4528 |
evt = os_gets_timeout(buf, bufl, 0, FALSE); |
| 4529 |
|
| 4530 |
|
| 4531 |
switch(evt) |
| 4532 |
{ |
| 4533 |
case OS_EVT_LINE: |
| 4534 |
|
| 4535 |
return buf; |
| 4536 |
|
| 4537 |
case OS_EVT_EOF: |
| 4538 |
|
| 4539 |
return 0; |
| 4540 |
|
| 4541 |
default: |
| 4542 |
|
| 4543 |
assert(FALSE); |
| 4544 |
return 0; |
| 4545 |
} |
| 4546 |
} |
| 4547 |
|
| 4548 |
#else |
| 4549 |
|
| 4550 |
#endif |
| 4551 |
|
| 4552 |
|
| 4553 |
|
| 4554 |
|
| 4555 |
|
| 4556 |
|
| 4557 |
#ifdef STD_OS_HILITE |
| 4558 |
|
| 4559 |
#ifdef RUNTIME |
| 4560 |
|
| 4561 |
|
| 4562 |
|
| 4563 |
void os_set_text_attr(int attr) |
| 4564 |
{ |
| 4565 |
osgen_txtwin_t *win; |
| 4566 |
|
| 4567 |
|
| 4568 |
if ((win = S_default_win) == 0) |
| 4569 |
return; |
| 4570 |
|
| 4571 |
|
| 4572 |
|
| 4573 |
|
| 4574 |
|
| 4575 |
if (attr != win->base.txtattr) |
| 4576 |
{ |
| 4577 |
char buf[3]; |
| 4578 |
|
| 4579 |
|
| 4580 |
buf[0] = OSGEN_ATTR; |
| 4581 |
buf[1] = (char)attr; |
| 4582 |
ossaddsb(win, buf, 2, TRUE); |
| 4583 |
} |
| 4584 |
} |
| 4585 |
|
| 4586 |
|
| 4587 |
|
| 4588 |
|
| 4589 |
static char osgen_xlat_color_t(os_color_t color) |
| 4590 |
{ |
| 4591 |
size_t i; |
| 4592 |
struct color_map_t |
| 4593 |
{ |
| 4594 |
|
| 4595 |
char id; |
| 4596 |
|
| 4597 |
|
| 4598 |
unsigned char rgb[3]; |
| 4599 |
}; |
| 4600 |
struct color_map_t *p; |
| 4601 |
struct color_map_t *bestp; |
| 4602 |
static struct color_map_t color_map[] = |
| 4603 |
{ |
| 4604 |
{ OSGEN_COLOR_BLACK, { 0x00, 0x00, 0x00 } }, |
| 4605 |
{ OSGEN_COLOR_WHITE, { 0xFF, 0xFF, 0xFF } }, |
| 4606 |
{ OSGEN_COLOR_RED, { 0xFF, 0x00, 0x00 } }, |
| 4607 |
{ OSGEN_COLOR_BLUE, { 0x00, 0x00, 0xFF } }, |
| 4608 |
{ OSGEN_COLOR_GREEN, { 0x00, 0x80, 0x00 } }, |
| 4609 |
{ OSGEN_COLOR_YELLOW, { 0xFF, 0xFF, 0x00 } }, |
| 4610 |
{ OSGEN_COLOR_CYAN, { 0x00, 0xFF, 0xFF } }, |
| 4611 |
{ OSGEN_COLOR_SILVER, { 0xC0, 0xC0, 0xC0 } }, |
| 4612 |
{ OSGEN_COLOR_GRAY, { 0x80, 0x80, 0x80 } }, |
| 4613 |
{ OSGEN_COLOR_MAROON, { 0x80, 0x00, 0x00 } }, |
| 4614 |
{ OSGEN_COLOR_PURPLE, { 0x80, 0x00, 0x80 } }, |
| 4615 |
{ OSGEN_COLOR_MAGENTA, { 0xFF, 0x00, 0xFF } }, |
| 4616 |
{ OSGEN_COLOR_LIME, { 0x00, 0xFF, 0x00 } }, |
| 4617 |
{ OSGEN_COLOR_OLIVE, { 0x80, 0x80, 0x00 } }, |
| 4618 |
{ OSGEN_COLOR_NAVY, { 0x00, 0x00, 0x80 } }, |
| 4619 |
{ OSGEN_COLOR_TEAL, { 0x00, 0x80, 0x80 } } |
| 4620 |
}; |
| 4621 |
unsigned char r, g, b; |
| 4622 |
unsigned long best_dist; |
| 4623 |
|
| 4624 |
|
| 4625 |
|
| 4626 |
|
| 4627 |
|
| 4628 |
|
| 4629 |
|
| 4630 |
if (os_color_is_param(color)) |
| 4631 |
return (char)((color >> 24) & 0xFF); |
| 4632 |
|
| 4633 |
|
| 4634 |
r = os_color_get_r(color); |
| 4635 |
g = os_color_get_g(color); |
| 4636 |
b = os_color_get_b(color); |
| 4637 |
|
| 4638 |
|
| 4639 |
for (i = 0, p = color_map, bestp = 0, best_dist = 0xFFFFFFFF ; |
| 4640 |
i < sizeof(color_map)/sizeof(color_map[0]) ; ++i, ++p) |
| 4641 |
{ |
| 4642 |
unsigned long dist; |
| 4643 |
int rd, gd, bd; |
| 4644 |
|
| 4645 |
|
| 4646 |
rd = r - p->rgb[0]; |
| 4647 |
gd = g - p->rgb[1]; |
| 4648 |
bd = b - p->rgb[2]; |
| 4649 |
|
| 4650 |
|
| 4651 |
dist = rd*rd + gd*gd + bd*bd; |
| 4652 |
|
| 4653 |
|
| 4654 |
if (dist == 0) |
| 4655 |
return p->id; |
| 4656 |
|
| 4657 |
|
| 4658 |
if (dist < best_dist) |
| 4659 |
{ |
| 4660 |
best_dist = dist; |
| 4661 |
bestp = p; |
| 4662 |
} |
| 4663 |
} |
| 4664 |
|
| 4665 |
|
| 4666 |
return bestp->id; |
| 4667 |
} |
| 4668 |
|
| 4669 |
|
| 4670 |
|
| 4671 |
|
| 4672 |
|
| 4673 |
|
| 4674 |
|
| 4675 |
|
| 4676 |
|
| 4677 |
void os_set_text_color(os_color_t fg, os_color_t bg) |
| 4678 |
{ |
| 4679 |
char buf[4]; |
| 4680 |
|
| 4681 |
|
| 4682 |
if (os_f_plain || S_default_win == 0) |
| 4683 |
return; |
| 4684 |
|
| 4685 |
|
| 4686 |
buf[0] = OSGEN_COLOR; |
| 4687 |
buf[1] = osgen_xlat_color_t(fg); |
| 4688 |
buf[2] = osgen_xlat_color_t(bg); |
| 4689 |
ossaddsb(S_default_win, buf, 3, TRUE); |
| 4690 |
} |
| 4691 |
|
| 4692 |
|
| 4693 |
|
| 4694 |
|
| 4695 |
void os_set_screen_color(os_color_t color) |
| 4696 |
{ |
| 4697 |
|
| 4698 |
if (os_f_plain || S_default_win == 0) |
| 4699 |
return; |
| 4700 |
|
| 4701 |
|
| 4702 |
S_default_win->base.fillcolor = osgen_xlat_color_t(color); |
| 4703 |
S_default_win->base.oss_fillcolor = |
| 4704 |
ossgetcolor(OSGEN_COLOR_TEXT, osgen_xlat_color_t(color), 0, 0); |
| 4705 |
|
| 4706 |
|
| 4707 |
if (!S_deferred_redraw |
| 4708 |
&& !(S_default_win->base.flags & OSGEN_DEFER_REDRAW)) |
| 4709 |
osgen_redraw_win(&S_default_win->base); |
| 4710 |
} |
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
|
| 4717 |
|
| 4718 |
|
| 4719 |
|
| 4720 |
void *os_banner_create(void *parent, int where, void *other, int wintype, |
| 4721 |
int align, int siz, int siz_units, unsigned long style) |
| 4722 |
{ |
| 4723 |
osgen_win_t *win; |
| 4724 |
|
| 4725 |
|
| 4726 |
if (os_f_plain) |
| 4727 |
return 0; |
| 4728 |
|
| 4729 |
|
| 4730 |
if (parent == 0) |
| 4731 |
parent = &S_main_win->base; |
| 4732 |
|
| 4733 |
|
| 4734 |
switch(wintype) |
| 4735 |
{ |
| 4736 |
case OS_BANNER_TYPE_TEXT: |
| 4737 |
|
| 4738 |
|
| 4739 |
|
| 4740 |
|
| 4741 |
|
| 4742 |
|
| 4743 |
win = (osgen_win_t *)osgen_create_txtwin(where, other, parent, |
| 4744 |
G_oss_screen_height * G_oss_screen_width * 2, |
| 4745 |
G_oss_screen_height * 2); |
| 4746 |
break; |
| 4747 |
|
| 4748 |
case OS_BANNER_TYPE_TEXTGRID: |
| 4749 |
|
| 4750 |
|
| 4751 |
|
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
|
| 4756 |
win = (osgen_win_t *)osgen_create_gridwin(where, other, parent, |
| 4757 |
G_oss_screen_width, 10); |
| 4758 |
break; |
| 4759 |
|
| 4760 |
default: |
| 4761 |
|
| 4762 |
return 0; |
| 4763 |
} |
| 4764 |
|
| 4765 |
|
| 4766 |
if (win == 0) |
| 4767 |
return 0; |
| 4768 |
|
| 4769 |
|
| 4770 |
win->alignment = align; |
| 4771 |
|
| 4772 |
|
| 4773 |
|
| 4774 |
|
| 4775 |
|
| 4776 |
if (align == OS_BANNER_ALIGN_LEFT || align == OS_BANNER_ALIGN_RIGHT) |
| 4777 |
{ |
| 4778 |
|
| 4779 |
win->wid = 0; |
| 4780 |
win->ht = (S_main_win != 0 |
| 4781 |
? S_main_win->base.ht : G_oss_screen_height); |
| 4782 |
} |
| 4783 |
else |
| 4784 |
{ |
| 4785 |
|
| 4786 |
win->wid = (S_main_win != 0 |
| 4787 |
? S_main_win->base.wid : G_oss_screen_width); |
| 4788 |
win->ht = 0; |
| 4789 |
} |
| 4790 |
|
| 4791 |
|
| 4792 |
if ((style & OS_BANNER_STYLE_AUTO_VSCROLL) != 0) |
| 4793 |
win->flags |= OSGEN_AUTO_VSCROLL; |
| 4794 |
|
| 4795 |
|
| 4796 |
|
| 4797 |
|
| 4798 |
|
| 4799 |
if ((style & OS_BANNER_STYLE_MOREMODE) != 0) |
| 4800 |
win->flags |= OSGEN_AUTO_VSCROLL | OSGEN_MOREMODE; |
| 4801 |
|
| 4802 |
|
| 4803 |
if ((style & OS_BANNER_STYLE_VSTRUT) != 0) |
| 4804 |
win->flags |= OSGEN_VSTRUT; |
| 4805 |
if ((style & OS_BANNER_STYLE_HSTRUT) != 0) |
| 4806 |
win->flags |= OSGEN_HSTRUT; |
| 4807 |
|
| 4808 |
|
| 4809 |
win->size = siz; |
| 4810 |
win->size_type = siz_units; |
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
|
| 4815 |
|
| 4816 |
|
| 4817 |
if (siz != 0) |
| 4818 |
osgen_recalc_layout(); |
| 4819 |
|
| 4820 |
|
| 4821 |
return win; |
| 4822 |
} |
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
|
| 4827 |
void os_banner_delete(void *banner_handle) |
| 4828 |
{ |
| 4829 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 4830 |
|
| 4831 |
|
| 4832 |
osgen_delete_win(win); |
| 4833 |
|
| 4834 |
|
| 4835 |
osgen_recalc_layout(); |
| 4836 |
} |
| 4837 |
|
| 4838 |
|
| 4839 |
|
| 4840 |
|
| 4841 |
void os_banner_orphan(void *banner_handle) |
| 4842 |
{ |
| 4843 |
os_banner_delete(banner_handle); |
| 4844 |
} |
| 4845 |
|
| 4846 |
|
| 4847 |
|
| 4848 |
|
| 4849 |
int os_banner_getinfo(void *banner_handle, os_banner_info_t *info) |
| 4850 |
{ |
| 4851 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 4852 |
|
| 4853 |
|
| 4854 |
info->align = win->alignment; |
| 4855 |
|
| 4856 |
|
| 4857 |
info->style = 0; |
| 4858 |
if ((win->flags & OSGEN_AUTO_VSCROLL) != 0) |
| 4859 |
info->style |= OS_BANNER_STYLE_AUTO_VSCROLL; |
| 4860 |
if ((win->flags & OSGEN_MOREMODE) != 0) |
| 4861 |
info->style |= OS_BANNER_STYLE_MOREMODE; |
| 4862 |
if ((win->flags & OSGEN_HSTRUT) != 0) |
| 4863 |
info->style |= OS_BANNER_STYLE_HSTRUT; |
| 4864 |
if ((win->flags & OSGEN_VSTRUT) != 0) |
| 4865 |
info->style |= OS_BANNER_STYLE_VSTRUT; |
| 4866 |
|
| 4867 |
|
| 4868 |
info->rows = win->ht; |
| 4869 |
info->columns = win->wid; |
| 4870 |
|
| 4871 |
|
| 4872 |
info->pix_width = 0; |
| 4873 |
info->pix_height = 0; |
| 4874 |
|
| 4875 |
|
| 4876 |
|
| 4877 |
|
| 4878 |
|
| 4879 |
info->style |= OS_BANNER_STYLE_TAB_ALIGN; |
| 4880 |
|
| 4881 |
|
| 4882 |
info->os_line_wrap = FALSE; |
| 4883 |
|
| 4884 |
|
| 4885 |
return TRUE; |
| 4886 |
} |
| 4887 |
|
| 4888 |
|
| 4889 |
|
| 4890 |
|
| 4891 |
void os_banner_clear(void *banner_handle) |
| 4892 |
{ |
| 4893 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 4894 |
|
| 4895 |
|
| 4896 |
osgen_clear_win(win); |
| 4897 |
} |
| 4898 |
|
| 4899 |
|
| 4900 |
|
| 4901 |
|
| 4902 |
void os_banner_disp(void *banner_handle, const char *txt, size_t len) |
| 4903 |
{ |
| 4904 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 4905 |
|
| 4906 |
|
| 4907 |
switch(win->win_type) |
| 4908 |
{ |
| 4909 |
case OS_BANNER_TYPE_TEXT: |
| 4910 |
|
| 4911 |
ossaddsb((osgen_txtwin_t *)win, txt, len, TRUE); |
| 4912 |
break; |
| 4913 |
|
| 4914 |
case OS_BANNER_TYPE_TEXTGRID: |
| 4915 |
|
| 4916 |
osgen_gridwin_write((osgen_gridwin_t *)win, txt, len); |
| 4917 |
break; |
| 4918 |
} |
| 4919 |
} |
| 4920 |
|
| 4921 |
|
| 4922 |
|
| 4923 |
|
| 4924 |
void os_banner_set_attr(void *banner_handle, int attr) |
| 4925 |
{ |
| 4926 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 4927 |
char buf[3]; |
| 4928 |
|
| 4929 |
|
| 4930 |
if (attr == win->txtattr) |
| 4931 |
return; |
| 4932 |
|
| 4933 |
|
| 4934 |
switch(win->win_type) |
| 4935 |
{ |
| 4936 |
case OS_BANNER_TYPE_TEXT: |
| 4937 |
|
| 4938 |
buf[0] = OSGEN_ATTR; |
| 4939 |
buf[1] = (char)attr; |
| 4940 |
ossaddsb((osgen_txtwin_t *)win, buf, 2, TRUE); |
| 4941 |
break; |
| 4942 |
|
| 4943 |
case OS_BANNER_TYPE_TEXTGRID: |
| 4944 |
|
| 4945 |
break; |
| 4946 |
} |
| 4947 |
} |
| 4948 |
|
| 4949 |
|
| 4950 |
|
| 4951 |
|
| 4952 |
void os_banner_set_color(void *banner_handle, os_color_t fg, os_color_t bg) |
| 4953 |
{ |
| 4954 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 4955 |
char buf[4]; |
| 4956 |
|
| 4957 |
|
| 4958 |
switch(win->win_type) |
| 4959 |
{ |
| 4960 |
case OS_BANNER_TYPE_TEXT: |
| 4961 |
|
| 4962 |
buf[0] = OSGEN_COLOR; |
| 4963 |
buf[1] = osgen_xlat_color_t(fg); |
| 4964 |
buf[2] = osgen_xlat_color_t(bg); |
| 4965 |
ossaddsb((osgen_txtwin_t *)win, buf, 3, TRUE); |
| 4966 |
break; |
| 4967 |
|
| 4968 |
case OS_BANNER_TYPE_TEXTGRID: |
| 4969 |
|
| 4970 |
win->txtfg = osgen_xlat_color_t(fg); |
| 4971 |
win->txtbg = osgen_xlat_color_t(bg); |
| 4972 |
break; |
| 4973 |
} |
| 4974 |
} |
| 4975 |
|
| 4976 |
|
| 4977 |
|
| 4978 |
|
| 4979 |
void os_banner_set_screen_color(void *banner_handle, os_color_t color) |
| 4980 |
{ |
| 4981 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 4982 |
|
| 4983 |
|
| 4984 |
win->fillcolor = osgen_xlat_color_t(color); |
| 4985 |
win->oss_fillcolor = ossgetcolor(OSGEN_COLOR_TEXT, win->fillcolor, 0, 0); |
| 4986 |
|
| 4987 |
|
| 4988 |
if (!S_deferred_redraw && !(win->flags & OSGEN_DEFER_REDRAW)) |
| 4989 |
osgen_redraw_win(win); |
| 4990 |
} |
| 4991 |
|
| 4992 |
|
| 4993 |
|
| 4994 |
|
| 4995 |
void os_banner_flush(void *banner_handle) |
| 4996 |
{ |
| 4997 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 4998 |
|
| 4999 |
|
| 5000 |
osgen_redraw_win_if_needed(FALSE, win); |
| 5001 |
} |
| 5002 |
|
| 5003 |
|
| 5004 |
|
| 5005 |
|
| 5006 |
void os_banner_set_size(void *banner_handle, int siz, int siz_units, |
| 5007 |
int is_advisory) |
| 5008 |
{ |
| 5009 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 5010 |
|
| 5011 |
|
| 5012 |
if (win->size == siz && win->size_type == siz_units) |
| 5013 |
return; |
| 5014 |
|
| 5015 |
|
| 5016 |
|
| 5017 |
|
| 5018 |
|
| 5019 |
if (is_advisory) |
| 5020 |
return; |
| 5021 |
|
| 5022 |
|
| 5023 |
win->size = siz; |
| 5024 |
win->size_type = siz_units; |
| 5025 |
|
| 5026 |
|
| 5027 |
osgen_recalc_layout(); |
| 5028 |
} |
| 5029 |
|
| 5030 |
|
| 5031 |
|
| 5032 |
|
| 5033 |
static size_t oss_get_content_height(osgen_win_t *win) |
| 5034 |
{ |
| 5035 |
size_t y; |
| 5036 |
osgen_win_t *chi; |
| 5037 |
|
| 5038 |
|
| 5039 |
y = win->ymax + 1; |
| 5040 |
|
| 5041 |
|
| 5042 |
for (chi = win->first_child ; chi != 0 ; chi = chi->nxt) |
| 5043 |
{ |
| 5044 |
|
| 5045 |
if ((chi->flags & OSGEN_VSTRUT) != 0) |
| 5046 |
{ |
| 5047 |
|
| 5048 |
size_t chi_y = oss_get_content_height(chi); |
| 5049 |
|
| 5050 |
|
| 5051 |
|
| 5052 |
|
| 5053 |
|
| 5054 |
|
| 5055 |
if (chi->alignment == OS_BANNER_ALIGN_TOP |
| 5056 |
|| chi->alignment == OS_BANNER_ALIGN_BOTTOM) |
| 5057 |
{ |
| 5058 |
|
| 5059 |
y += chi_y; |
| 5060 |
} |
| 5061 |
else |
| 5062 |
{ |
| 5063 |
|
| 5064 |
if (y < chi_y) |
| 5065 |
y = chi_y; |
| 5066 |
} |
| 5067 |
} |
| 5068 |
} |
| 5069 |
|
| 5070 |
|
| 5071 |
return y; |
| 5072 |
} |
| 5073 |
|
| 5074 |
|
| 5075 |
|
| 5076 |
|
| 5077 |
static size_t oss_get_content_width(osgen_win_t *win) |
| 5078 |
{ |
| 5079 |
size_t x; |
| 5080 |
osgen_win_t *chi; |
| 5081 |
|
| 5082 |
|
| 5083 |
x = win->xmax + 1; |
| 5084 |
|
| 5085 |
|
| 5086 |
for (chi = win->first_child ; chi != 0 ; chi = chi->nxt) |
| 5087 |
{ |
| 5088 |
|
| 5089 |
if ((chi->flags & OSGEN_HSTRUT) != 0) |
| 5090 |
{ |
| 5091 |
|
| 5092 |
size_t chi_x = oss_get_content_width(chi); |
| 5093 |
|
| 5094 |
|
| 5095 |
|
| 5096 |
|
| 5097 |
|
| 5098 |
|
| 5099 |
if (chi->alignment == OS_BANNER_ALIGN_LEFT |
| 5100 |
|| chi->alignment == OS_BANNER_ALIGN_RIGHT) |
| 5101 |
{ |
| 5102 |
|
| 5103 |
x += chi_x; |
| 5104 |
} |
| 5105 |
else |
| 5106 |
{ |
| 5107 |
|
| 5108 |
if (x < chi_x) |
| 5109 |
x = chi_x; |
| 5110 |
} |
| 5111 |
} |
| 5112 |
} |
| 5113 |
|
| 5114 |
|
| 5115 |
return x; |
| 5116 |
} |
| 5117 |
|
| 5118 |
|
| 5119 |
|
| 5120 |
|
| 5121 |
void os_banner_size_to_contents(void *banner_handle) |
| 5122 |
{ |
| 5123 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 5124 |
|
| 5125 |
|
| 5126 |
if (win->alignment == OS_BANNER_ALIGN_TOP |
| 5127 |
|| win->alignment == OS_BANNER_ALIGN_BOTTOM) |
| 5128 |
{ |
| 5129 |
size_t newy; |
| 5130 |
|
| 5131 |
|
| 5132 |
newy = oss_get_content_height(win); |
| 5133 |
|
| 5134 |
|
| 5135 |
|
| 5136 |
|
| 5137 |
|
| 5138 |
if (win->ht == newy) |
| 5139 |
return; |
| 5140 |
|
| 5141 |
|
| 5142 |
win->size = newy; |
| 5143 |
win->size_type = OS_BANNER_SIZE_ABS; |
| 5144 |
} |
| 5145 |
else |
| 5146 |
{ |
| 5147 |
size_t newx; |
| 5148 |
|
| 5149 |
|
| 5150 |
newx = oss_get_content_width(win); |
| 5151 |
|
| 5152 |
|
| 5153 |
if (win->wid == newx) |
| 5154 |
return; |
| 5155 |
|
| 5156 |
|
| 5157 |
win->size = newx; |
| 5158 |
win->size_type = OS_BANNER_SIZE_ABS; |
| 5159 |
} |
| 5160 |
|
| 5161 |
|
| 5162 |
osgen_recalc_layout(); |
| 5163 |
} |
| 5164 |
|
| 5165 |
|
| 5166 |
|
| 5167 |
|
| 5168 |
int os_banner_get_charwidth(void *banner_handle) |
| 5169 |
{ |
| 5170 |
|
| 5171 |
return ((osgen_win_t *)banner_handle)->wid; |
| 5172 |
} |
| 5173 |
|
| 5174 |
|
| 5175 |
|
| 5176 |
|
| 5177 |
int os_banner_get_charheight(void *banner_handle) |
| 5178 |
{ |
| 5179 |
|
| 5180 |
return ((osgen_win_t *)banner_handle)->ht; |
| 5181 |
} |
| 5182 |
|
| 5183 |
|
| 5184 |
|
| 5185 |
|
| 5186 |
void os_banner_start_html(void *banner_handle) |
| 5187 |
{ |
| 5188 |
|
| 5189 |
} |
| 5190 |
|
| 5191 |
|
| 5192 |
|
| 5193 |
|
| 5194 |
void os_banner_end_html(void *banner_handle) |
| 5195 |
{ |
| 5196 |
|
| 5197 |
} |
| 5198 |
|
| 5199 |
|
| 5200 |
|
| 5201 |
|
| 5202 |
void os_banner_goto(void *banner_handle, int row, int col) |
| 5203 |
{ |
| 5204 |
osgen_win_t *win = (osgen_win_t *)banner_handle; |
| 5205 |
|
| 5206 |
|
| 5207 |
switch(win->win_type) |
| 5208 |
{ |
| 5209 |
case OS_BANNER_TYPE_TEXTGRID: |
| 5210 |
|
| 5211 |
win->y = row; |
| 5212 |
win->x = col; |
| 5213 |
break; |
| 5214 |
|
| 5215 |
default: |
| 5216 |
|
| 5217 |
|
| 5218 |
|
| 5219 |
|
| 5220 |
break; |
| 5221 |
} |
| 5222 |
} |
| 5223 |
|
| 5224 |
|
| 5225 |
|
| 5226 |
|
| 5227 |
|
| 5228 |
#else |
| 5229 |
|
| 5230 |
void os_set_text_attr(int attr) |
| 5231 |
{ |
| 5232 |
|
| 5233 |
} |
| 5234 |
|
| 5235 |
void os_set_text_color(os_color_t fg, os_color_t bg) |
| 5236 |
{ |
| 5237 |
|
| 5238 |
} |
| 5239 |
|
| 5240 |
void os_set_screen_color(os_color_t color) |
| 5241 |
{ |
| 5242 |
|
| 5243 |
} |
| 5244 |
|
| 5245 |
|
| 5246 |
|
| 5247 |
|
| 5248 |
|
| 5249 |
void *os_banner_create(void *parent, int where, void *other, int wintype, |
| 5250 |
int align, int siz, int siz_units, unsigned long style) |
| 5251 |
{ |
| 5252 |
return 0; |
| 5253 |
} |
| 5254 |
|
| 5255 |
void os_banner_delete(void *banner_handle) |
| 5256 |
{ |
| 5257 |
} |
| 5258 |
|
| 5259 |
void os_banner_orphan(void *banner_handle) |
| 5260 |
{ |
| 5261 |
} |
| 5262 |
|
| 5263 |
int os_banner_getinfo(void *banner_handle, os_banner_info_t *info) |
| 5264 |
{ |
| 5265 |
return FALSE; |
| 5266 |
} |
| 5267 |
|
| 5268 |
void os_banner_clear(void *banner_handle) |
| 5269 |
{ |
| 5270 |
} |
| 5271 |
|
| 5272 |
int os_banner_get_charwidth(void *banner_handle) |
| 5273 |
{ |
| 5274 |
return 0; |
| 5275 |
} |
| 5276 |
|
| 5277 |
int os_banner_get_charheight(void *banner_handle) |
| 5278 |
{ |
| 5279 |
return 0; |
| 5280 |
} |
| 5281 |
|
| 5282 |
void os_banner_disp(void *banner_handle, const char *txt, size_t len) |
| 5283 |
{ |
| 5284 |
} |
| 5285 |
|
| 5286 |
void os_banner_set_color(void *banner_handle, os_color_t fg, os_color_t bg) |
| 5287 |
{ |
| 5288 |
} |
| 5289 |
|
| 5290 |
void os_banner_set_screen_color(void *banner_handle, os_color_t color) |
| 5291 |
{ |
| 5292 |
} |
| 5293 |
|
| 5294 |
void os_banner_flush(void *banner_handle) |
| 5295 |
{ |
| 5296 |
} |
| 5297 |
|
| 5298 |
void os_banner_set_size(void *banner_handle, int siz, int siz_units, |
| 5299 |
int is_advisory) |
| 5300 |
{ |
| 5301 |
} |
| 5302 |
|
| 5303 |
void os_banner_size_to_contents(void *banner_handle) |
| 5304 |
{ |
| 5305 |
} |
| 5306 |
|
| 5307 |
void os_banner_start_html(void *banner_handle) |
| 5308 |
{ |
| 5309 |
} |
| 5310 |
|
| 5311 |
void os_banner_end_html(void *banner_handle) |
| 5312 |
{ |
| 5313 |
} |
| 5314 |
|
| 5315 |
void os_banner_goto(void *banner_handle, int row, int col) |
| 5316 |
{ |
| 5317 |
} |
| 5318 |
|
| 5319 |
#endif |
| 5320 |
|
| 5321 |
#endif |
| 5322 |
|
| 5323 |
|
| 5324 |
|
| 5325 |
|
| 5326 |
|
| 5327 |
#ifdef STD_OSCLS |
| 5328 |
|
| 5329 |
void oscls(void) |
| 5330 |
{ |
| 5331 |
#ifdef RUNTIME |
| 5332 |
|
| 5333 |
if (os_f_plain || S_default_win == 0) |
| 5334 |
return; |
| 5335 |
|
| 5336 |
|
| 5337 |
osgen_clear_win(&S_default_win->base); |
| 5338 |
#endif |
| 5339 |
} |
| 5340 |
|
| 5341 |
#endif |
| 5342 |
|
| 5343 |
|
| 5344 |
|
| 5345 |
|
| 5346 |
|
| 5347 |
|
| 5348 |
|
| 5349 |
|
| 5350 |
|
| 5351 |
|
| 5352 |
int os_get_sysinfo(int code, void *param, long *result) |
| 5353 |
{ |
| 5354 |
#ifdef RUNTIME |
| 5355 |
|
| 5356 |
if (oss_get_sysinfo(code, param, result)) |
| 5357 |
return TRUE; |
| 5358 |
#endif |
| 5359 |
|
| 5360 |
|
| 5361 |
switch(code) |
| 5362 |
{ |
| 5363 |
case SYSINFO_HTML: |
| 5364 |
case SYSINFO_JPEG: |
| 5365 |
case SYSINFO_PNG: |
| 5366 |
case SYSINFO_WAV: |
| 5367 |
case SYSINFO_MIDI: |
| 5368 |
case SYSINFO_WAV_MIDI_OVL: |
| 5369 |
case SYSINFO_WAV_OVL: |
| 5370 |
case SYSINFO_MPEG: |
| 5371 |
case SYSINFO_MPEG1: |
| 5372 |
case SYSINFO_MPEG2: |
| 5373 |
case SYSINFO_MPEG3: |
| 5374 |
case SYSINFO_PREF_IMAGES: |
| 5375 |
case SYSINFO_PREF_SOUNDS: |
| 5376 |
case SYSINFO_PREF_MUSIC: |
| 5377 |
case SYSINFO_PREF_LINKS: |
| 5378 |
case SYSINFO_LINKS_HTTP: |
| 5379 |
case SYSINFO_LINKS_FTP: |
| 5380 |
case SYSINFO_LINKS_NEWS: |
| 5381 |
case SYSINFO_LINKS_MAILTO: |
| 5382 |
case SYSINFO_LINKS_TELNET: |
| 5383 |
case SYSINFO_PNG_TRANS: |
| 5384 |
case SYSINFO_PNG_ALPHA: |
| 5385 |
case SYSINFO_OGG: |
| 5386 |
case SYSINFO_MNG: |
| 5387 |
case SYSINFO_MNG_TRANS: |
| 5388 |
case SYSINFO_MNG_ALPHA: |
| 5389 |
|
| 5390 |
|
| 5391 |
|
| 5392 |
|
| 5393 |
*result = 0; |
| 5394 |
|
| 5395 |
|
| 5396 |
return TRUE; |
| 5397 |
|
| 5398 |
case SYSINFO_INTERP_CLASS: |
| 5399 |
|
| 5400 |
*result = SYSINFO_ICLASS_TEXT; |
| 5401 |
return TRUE; |
| 5402 |
|
| 5403 |
#ifdef RUNTIME |
| 5404 |
|
| 5405 |
case SYSINFO_BANNERS: |
| 5406 |
|
| 5407 |
|
| 5408 |
|
| 5409 |
|
| 5410 |
*result = !os_f_plain; |
| 5411 |
return TRUE; |
| 5412 |
|
| 5413 |
#endif |
| 5414 |
|
| 5415 |
default: |
| 5416 |
|
| 5417 |
return FALSE; |
| 5418 |
} |
| 5419 |
} |
| 5420 |
|
| 5421 |
|
| 5422 |
|
| 5423 |
|
| 5424 |
|
| 5425 |
|
| 5426 |
|
| 5427 |
|
| 5428 |
|
| 5429 |
|
| 5430 |
|
| 5431 |
|
| 5432 |
|
| 5433 |
|
| 5434 |
|
| 5435 |
void os_set_save_ext(const char *ext) |
| 5436 |
{ |
| 5437 |
|
| 5438 |
} |
| 5439 |
|
| 5440 |
const char *os_get_save_ext() |
| 5441 |
{ |
| 5442 |
|
| 5443 |
return 0; |
| 5444 |
} |
| 5445 |
|
| 5446 |
|
| 5447 |
|
| 5448 |
|
| 5449 |
|
| 5450 |
|
| 5451 |
|
| 5452 |
#ifdef USE_NULL_SET_TITLE |
| 5453 |
|
| 5454 |
void os_set_title(const char *title) |
| 5455 |
{ |
| 5456 |
|
| 5457 |
} |
| 5458 |
|
| 5459 |
#endif |
| 5460 |
|