1 /* Tetrinet for Linux, by Andrew Church <achurch@achurch.org>
2 * This program is public domain.
4 * Text terminal I/O routines.
7 #define _GNU_SOURCE /* strsignal() - FIXME!!! --pasky */
22 /*************************************************************************/
24 #define MY_HLINE (fancy ? ACS_HLINE : '-')
25 #define MY_VLINE (fancy ? ACS_VLINE : '|')
26 #define MY_ULCORNER (fancy ? ACS_ULCORNER : '+')
27 #define MY_URCORNER (fancy ? ACS_URCORNER : '+')
28 #define MY_LLCORNER (fancy ? ACS_LLCORNER : '+')
29 #define MY_LRCORNER (fancy ? ACS_LRCORNER : '+')
31 #define MY_HLINE2 (fancy ? (ACS_HLINE | A_BOLD) : '=')
32 #define MY_BOLD (fancy ? A_BOLD : 0)
34 /*************************************************************************/
35 /******************************* Input stuff *****************************/
36 /*************************************************************************/
38 /* Return either an ASCII code 0-255, a K_* value, or -1 if server input is
39 * waiting. Return -2 if we run out of time with no input.
42 static int wait_for_input(int msec
)
50 FD_SET(server_sock
, &fds
);
51 tv
.tv_sec
= msec
/1000;
52 tv
.tv_usec
= (msec
*1000) % 1000000;
53 while (select(server_sock
+1, &fds
, NULL
, NULL
, msec
<0 ? NULL
: &tv
) < 0) {
55 perror("Warning: select() failed");
57 if (FD_ISSET(0, &fds
)) {
61 else if (c
== KEY_DOWN
)
63 else if (c
== KEY_LEFT
)
65 else if (c
== KEY_RIGHT
)
67 else if (c
== KEY_F(1))
69 else if (c
== KEY_F(2))
71 else if (c
== KEY_F(3))
73 else if (c
== KEY_F(4))
75 else if (c
== KEY_F(5))
77 else if (c
== KEY_F(6))
79 else if (c
== KEY_F(7))
81 else if (c
== KEY_F(8))
83 else if (c
== KEY_F(9))
85 else if (c
== KEY_F(10))
87 else if (c
== KEY_F(11))
89 else if (c
== KEY_F(12))
91 else if (c
== KEY_BACKSPACE
)
95 else if (c
== 7) /* ^G */
96 return 27; /* Escape */
99 } /* if (FD_ISSET(0, &fds)) */
100 else if (FD_ISSET(server_sock
, &fds
))
103 return -2; /* out of time */
106 /*************************************************************************/
107 /****************************** Output stuff *****************************/
108 /*************************************************************************/
110 /* Size of the screen */
111 static int scrwidth
, scrheight
;
113 /* Is color available? */
114 static int has_color
;
116 /*************************************************************************/
121 int x
, y
, width
, height
;
123 WINDOW
*win
; /* NULL if not currently displayed */
127 static TextBuffer plinebuf
, gmsgbuf
, attdefbuf
;
129 /*************************************************************************/
131 /* Window for typing in-game text, and its coordinates: */
133 static WINDOW
*gmsg_inputwin
;
134 static int gmsg_inputpos
, gmsg_inputheight
;
136 /*************************************************************************/
137 /*************************************************************************/
139 /* Clean up the screen on exit. */
141 static void screen_cleanup()
143 wmove(stdscr
, scrheight
-1, 0);
149 /*************************************************************************/
151 /* Little signal handler that just does an exit(1) (thereby getting our
152 * cleanup routine called), except for TSTP, which does a clean suspend.
155 static void (*old_tstp
)(int sig
);
157 static void sighandler(int sig
)
159 if (sig
!= SIGTSTP
) {
162 fprintf(stderr
, "%s\n", strsignal(sig
));
166 signal(SIGTSTP
, old_tstp
);
169 signal(SIGTSTP
, sighandler
);
172 /*************************************************************************/
173 /*************************************************************************/
175 #define MAXCOLORS 256
177 static int colors
[MAXCOLORS
][2] = { {-1,-1} };
179 /* Return a color attribute value. */
181 static long getcolor(int fg
, int bg
)
185 if (colors
[0][0] < 0) {
187 memset(colors
, -1, sizeof(colors
));
188 colors
[0][0] = COLOR_WHITE
;
189 colors
[0][1] = COLOR_BLACK
;
191 if (fg
== COLOR_WHITE
&& bg
== COLOR_BLACK
)
192 return COLOR_PAIR(0);
193 for (i
= 1; i
< MAXCOLORS
; i
++) {
194 if (colors
[i
][0] == fg
&& colors
[i
][1] == bg
)
195 return COLOR_PAIR(i
);
197 for (i
= 1; i
< MAXCOLORS
; i
++) {
198 if (colors
[i
][0] < 0) {
199 if (init_pair(i
, fg
, bg
) == ERR
)
203 return COLOR_PAIR(i
);
209 /*************************************************************************/
210 /*************************************************************************/
212 /* Set up the screen stuff. */
214 static void screen_setup(void)
216 /* Avoid messy keyfield signals while we're setting up */
217 signal(SIGINT
, SIG_IGN
);
218 signal(SIGQUIT
, SIG_IGN
);
219 signal(SIGTSTP
, SIG_IGN
);
224 nodelay(stdscr
, TRUE
);
225 keypad(stdscr
, TRUE
);
226 leaveok(stdscr
, TRUE
);
227 if ((has_color
= has_colors()))
229 getmaxyx(stdscr
, scrheight
, scrwidth
);
230 scrwidth
--; /* Don't draw in last column--this can cause scroll */
232 /* Cancel all this when we exit. */
233 atexit(screen_cleanup
);
235 /* Catch signals so we can exit cleanly. */
236 signal(SIGINT
, sighandler
);
237 signal(SIGQUIT
, sighandler
);
238 signal(SIGTERM
, sighandler
);
239 signal(SIGHUP
, sighandler
);
240 /* signal(SIGSEGV, sighandler); */
241 signal(SIGABRT
, sighandler
);
242 signal(SIGIOT
, sighandler
);
243 signal(SIGTRAP
, sighandler
);
244 signal(SIGBUS
, sighandler
);
245 signal(SIGFPE
, sighandler
);
246 signal(SIGUSR1
, sighandler
);
247 signal(SIGUSR2
, sighandler
);
248 signal(SIGALRM
, sighandler
);
250 signal(SIGSTKFLT
, sighandler
);
252 signal(SIGTSTP
, sighandler
);
253 signal(SIGXCPU
, sighandler
);
254 signal(SIGXFSZ
, sighandler
);
255 signal(SIGVTALRM
, sighandler
);
257 /* Broken pipes don't want to bother us at all. */
258 signal(SIGPIPE
, SIG_IGN
);
261 /*************************************************************************/
263 /* Redraw everything on the screen. */
265 static void screen_refresh(void)
268 touchline(stdscr
, gmsg_inputpos
, gmsg_inputheight
);
270 touchline(stdscr
, plinebuf
.y
, plinebuf
.height
);
272 touchline(stdscr
, gmsgbuf
.y
, gmsgbuf
.height
);
274 touchline(stdscr
, attdefbuf
.y
, attdefbuf
.height
);
275 wnoutrefresh(stdscr
);
279 /*************************************************************************/
281 /* Like screen_refresh(), but clear the screen first. */
283 static void screen_redraw(void)
285 clearok(stdscr
, TRUE
);
289 /*************************************************************************/
290 /************************* Text buffer routines **************************/
291 /*************************************************************************/
293 /* Put a line of text in a text buffer. */
295 static void outline(TextBuffer
*buf
, const char *s
)
297 if (buf
->line
== buf
->height
) {
300 memmove(buf
->text
, buf
->text
+1, (buf
->height
-1) * sizeof(char *));
304 mvwaddstr(buf
->win
, buf
->line
, 0, s
);
305 if (s
!= buf
->text
[buf
->line
]) /* check for restoring display */
306 buf
->text
[buf
->line
] = strdup(s
);
310 static void draw_text(int bufnum
, const char *s
)
312 char str
[1024]; /* hopefully scrwidth < 1024 */
319 case BUFFER_PLINE
: buf
= &plinebuf
; break;
320 case BUFFER_GMSG
: buf
= &gmsgbuf
; break;
321 case BUFFER_ATTDEF
: buf
= &attdefbuf
; break;
328 attrset(getcolor(COLOR_WHITE
, COLOR_BLACK
));
330 while (*s
&& isspace(*s
))
332 while (strlen(s
) > buf
->width
- indent
) {
333 t
= s
+ buf
->width
- indent
;
334 while (t
>= s
&& !isspace(*t
))
336 while (t
>= s
&& isspace(*t
))
340 t
= s
+ buf
->width
- indent
;
342 sprintf(str
, "%*s", indent
, "");
343 strncpy(str
+indent
, s
, t
-s
);
352 sprintf(str
, "%*s", indent
, "");
353 strcpy(str
+indent
, s
);
361 /*************************************************************************/
363 /* Clear the contents of a text buffer. */
365 static void clear_text(int bufnum
)
371 case BUFFER_PLINE
: buf
= &plinebuf
; break;
372 case BUFFER_GMSG
: buf
= &gmsgbuf
; break;
373 case BUFFER_ATTDEF
: buf
= &attdefbuf
; break;
377 for (i
= 0; i
< buf
->height
; i
++) {
391 /*************************************************************************/
393 /* Restore the contents of the given text buffer. */
395 static void restore_text(TextBuffer
*buf
)
398 while (buf
->line
< buf
->height
&& buf
->text
[buf
->line
])
399 outline(buf
, buf
->text
[buf
->line
]);
402 /*************************************************************************/
404 /* Open a window for the given text buffer. */
406 static void open_textwin(TextBuffer
*buf
)
408 if (buf
->height
<= 0 || buf
->width
<= 0) {
410 move(scrheight
-1, 0);
411 snprintf(str
, sizeof(str
), "ERROR: bad textwin size (%d,%d)",
412 buf
->width
, buf
->height
);
417 buf
->win
= subwin(stdscr
, buf
->height
, buf
->width
, buf
->y
, buf
->x
);
418 scrollok(buf
->win
, TRUE
);
421 buf
->text
= calloc(buf
->height
, sizeof(char *));
426 /*************************************************************************/
428 /* Close the window for the given text buffer, if it's open. */
430 static void close_textwin(TextBuffer
*buf
)
438 /*************************************************************************/
439 /************************ Field drawing routines *************************/
440 /*************************************************************************/
442 /* Are we on a wide screen (>=92 columns)? */
443 static int wide_screen
= 0;
445 /* Field display X/Y coordinates. */
446 static const int own_coord
[2] = {0,0};
447 static int other_coord
[5][2] = /* Recomputed based on screen width */
448 { {30,0}, {47,0}, {64,0}, {47,24}, {64,24} };
450 /* Position of the status window. */
451 static const int status_coord
[2] = {28,25};
452 static const int next_coord
[2] = {40,24};
453 static const int alt_status_coord
[2] = {28,2};
454 static const int alt_next_coord
[2] = {29,8};
456 /* Position of the attacks/defenses window. */
457 static const int attdef_coord
[2] = {28,28};
458 static const int alt_attdef_coord
[2] = {28,24};
460 /* Position of the text window. X coordinate is ignored. */
461 static const int field_text_coord
[2] = {0,47};
463 /* Information for drawing blocks. Color attributes are added to blocks in
464 * the setup_fields() routine. */
465 static int tile_chars
[15] =
466 { ' ','#','#','#','#','#','a','c','n','r','s','b','g','q','o' };
468 /* Are we redrawing the entire display? */
469 static int field_redraw
= 0;
471 /*************************************************************************/
472 /*************************************************************************/
474 /* Set up the field display. */
476 static void draw_own_field(void);
477 static void draw_other_field(int player
);
478 static void draw_status(void);
479 static void draw_specials(void);
480 static void draw_gmsg_input(const char *s
, int pos
);
482 static void setup_fields(void)
484 int i
, j
, x
, y
, base
, delta
, attdefbot
;
487 if (!(tile_chars
[0] & A_ATTRIBUTES
)) {
488 for (i
= 1; i
< 15; i
++)
489 tile_chars
[i
] |= A_BOLD
;
490 tile_chars
[1] |= getcolor(COLOR_BLUE
, COLOR_BLACK
);
491 tile_chars
[2] |= getcolor(COLOR_YELLOW
, COLOR_BLACK
);
492 tile_chars
[3] |= getcolor(COLOR_GREEN
, COLOR_BLACK
);
493 tile_chars
[4] |= getcolor(COLOR_MAGENTA
, COLOR_BLACK
);
494 tile_chars
[5] |= getcolor(COLOR_RED
, COLOR_BLACK
);
498 leaveok(stdscr
, TRUE
);
499 close_textwin(&plinebuf
);
501 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
503 if (scrwidth
>= 92) {
509 delta
= (scrwidth
- base
) / 3;
510 base
+= 2 + (delta
- (FIELD_WIDTH
+5)) / 2;
511 other_coord
[0][0] = base
;
512 other_coord
[1][0] = base
+ delta
;
513 other_coord
[2][0] = base
+ delta
*2;
514 other_coord
[3][0] = base
+ delta
;
515 other_coord
[4][0] = base
+ delta
*2;
517 attdefbot
= field_text_coord
[1] - 1;
518 if (scrheight
- field_text_coord
[1] > 3) {
519 move(field_text_coord
[1], 0);
520 hline(MY_HLINE2
, scrwidth
);
522 if (scrheight
- field_text_coord
[1] > 5) {
523 move(scrheight
-2, 0);
524 hline(MY_HLINE2
, scrwidth
);
526 move(scrheight
-1, 0);
527 addstr("F1=Show Fields F2=Partyline F3=Winlist");
528 move(scrheight
-1, scrwidth
-8);
531 gmsgbuf
.y
= field_text_coord
[1]+1;
532 gmsgbuf
.height
= scrheight
- field_text_coord
[1] - 3;
534 gmsgbuf
.y
= field_text_coord
[1]+1;
535 gmsgbuf
.height
= scrheight
- field_text_coord
[1] - 1;
538 gmsgbuf
.y
= field_text_coord
[1];
539 gmsgbuf
.height
= scrheight
- field_text_coord
[1];
541 gmsgbuf
.x
= field_text_coord
[0];
542 gmsgbuf
.width
= scrwidth
;
543 open_textwin(&gmsgbuf
);
547 sprintf(buf
, "%d", my_playernum
);
548 mvaddstr(y
, x
+FIELD_WIDTH
*2+2, buf
);
549 for (i
= 2; i
< FIELD_HEIGHT
*2 && players
[my_playernum
-1][i
-2]; i
++)
550 mvaddch(y
+i
, x
+FIELD_WIDTH
*2+2, players
[my_playernum
-1][i
-2]);
552 vline(MY_VLINE
, FIELD_HEIGHT
*2);
553 move(y
, x
+FIELD_WIDTH
*2+1);
554 vline(MY_VLINE
, FIELD_HEIGHT
*2);
555 move(y
+FIELD_HEIGHT
*2, x
);
557 hline(MY_HLINE
, FIELD_WIDTH
*2);
558 move(y
+FIELD_HEIGHT
*2, x
+FIELD_WIDTH
*2+1);
560 mvaddstr(y
+FIELD_HEIGHT
*2+2, x
, "Specials:");
564 for (j
= 0; j
< 5; j
++) {
565 x
= other_coord
[j
][0];
566 y
= other_coord
[j
][1];
568 vline(MY_VLINE
, FIELD_HEIGHT
);
569 move(y
, x
+FIELD_WIDTH
+1);
570 vline(MY_VLINE
, FIELD_HEIGHT
);
571 move(y
+FIELD_HEIGHT
, x
);
573 hline(MY_HLINE
, FIELD_WIDTH
);
574 move(y
+FIELD_HEIGHT
, x
+FIELD_WIDTH
+1);
576 if (j
+1 >= my_playernum
) {
577 sprintf(buf
, "%d", j
+2);
578 mvaddstr(y
, x
+FIELD_WIDTH
+2, buf
);
580 for (i
= 0; i
< FIELD_HEIGHT
-2 && players
[j
+1][i
]; i
++)
581 mvaddch(y
+i
+2, x
+FIELD_WIDTH
+2, players
[j
+1][i
]);
583 draw_other_field(j
+2);
585 sprintf(buf
, "%d", j
+1);
586 mvaddstr(y
, x
+FIELD_WIDTH
+2, buf
);
588 for (i
= 0; i
< FIELD_HEIGHT
-2 && players
[j
][i
]; i
++)
589 mvaddch(y
+i
+2, x
+FIELD_WIDTH
+2, players
[j
][i
]);
591 draw_other_field(j
+1);
596 x
= alt_status_coord
[0];
597 y
= alt_status_coord
[1];
598 mvaddstr(y
, x
, "Lines:");
599 mvaddstr(y
+1, x
, "Level:");
600 x
= alt_next_coord
[0];
601 y
= alt_next_coord
[1];
602 mvaddstr(y
-2, x
-1, "Next piece:");
606 mvaddch(y
-1, x
+8, MY_URCORNER
);
614 mvaddch(y
+8, x
+8, MY_LRCORNER
);
618 mvaddstr(y
-1, x
, "Next piece:");
619 mvaddstr(y
, x
, "Lines:");
620 mvaddstr(y
+1, x
, "Level:");
625 attdefbuf
.x
= wide_screen
? alt_attdef_coord
[0] : attdef_coord
[0];
626 attdefbuf
.y
= wide_screen
? alt_attdef_coord
[1] : attdef_coord
[1];
627 attdefbuf
.width
= (other_coord
[3][0]-1) - attdefbuf
.x
;
628 attdefbuf
.height
= (attdefbot
+1) - attdefbuf
.y
;
629 open_textwin(&attdefbuf
);
632 delwin(gmsg_inputwin
);
633 gmsg_inputwin
= NULL
;
634 draw_gmsg_input(NULL
, -1);
641 /*************************************************************************/
643 /* Display the player's own field. */
645 static void draw_own_field(void)
648 Field
*f
= &fields
[my_playernum
-1];
650 if (dispmode
!= MODE_FIELDS
)
654 for (y
= 0; y
< 22; y
++) {
655 for (x
= 0; x
< 12; x
++) {
656 int c
= tile_chars
[(int) (*f
)[y
][x
]];
657 mvaddch(y0
+y
*2, x0
+x
*2, c
);
659 mvaddch(y0
+y
*2+1, x0
+x
*2, c
);
664 delwin(gmsg_inputwin
);
665 gmsg_inputwin
= NULL
;
666 draw_gmsg_input(NULL
, -1);
672 /*************************************************************************/
674 /* Display another player's field. */
676 static void draw_other_field(int player
)
681 if (dispmode
!= MODE_FIELDS
)
683 f
= &fields
[player
-1];
684 if (player
> my_playernum
)
687 x0
= other_coord
[player
][0]+1;
688 y0
= other_coord
[player
][1];
689 for (y
= 0; y
< 22; y
++) {
691 for (x
= 0; x
< 12; x
++)
692 addch(tile_chars
[(int) (*f
)[y
][x
]]);
695 delwin(gmsg_inputwin
);
696 gmsg_inputwin
= NULL
;
697 draw_gmsg_input(NULL
, -1);
703 /*************************************************************************/
705 /* Display the current game status (level, lines, next piece). */
707 static void draw_status(void)
710 char buf
[32], shape
[4][4];
712 x
= wide_screen
? alt_status_coord
[0] : status_coord
[0];
713 y
= wide_screen
? alt_status_coord
[1] : status_coord
[1];
714 sprintf(buf
, "%d", lines
>99999 ? 99999 : lines
);
715 mvaddstr(y
+1, x
+7, buf
);
716 sprintf(buf
, "%d", levels
[my_playernum
]);
717 mvaddstr(y
+2, x
+7, buf
);
718 x
= wide_screen
? alt_next_coord
[0] : next_coord
[0];
719 y
= wide_screen
? alt_next_coord
[1] : next_coord
[1];
720 if (get_shape(next_piece
, 0, shape
) == 0) {
721 for (j
= 0; j
< 4; j
++) {
724 for (i
= 0; i
< 4; i
++) {
727 addch(tile_chars
[(int) shape
[j
][i
]]);
728 addch(tile_chars
[(int) shape
[j
][i
]]);
729 move(y
+j
*2+1, x
+i
*2);
730 addch(tile_chars
[(int) shape
[j
][i
]]);
731 addch(tile_chars
[(int) shape
[j
][i
]]);
733 addch(tile_chars
[(int) shape
[j
][i
]]);
739 /*************************************************************************/
741 /* Display the special inventory and description of the current special. */
743 static const char *descs
[] = {
748 "Clear Random Blocks ",
750 "Clear Special Blocks",
756 static void draw_specials(void)
760 if (dispmode
!= MODE_FIELDS
)
764 mvaddstr(y
, x
, descs
[specials
[0]+1]);
767 while (i
< special_capacity
&& specials
[i
] >= 0 && x
< attdef_coord
[0]-1) {
768 addch(tile_chars
[specials
[i
]+6]);
772 while (x
< attdef_coord
[0]-1) {
773 addch(tile_chars
[0]);
780 /*************************************************************************/
782 /* Display an attack/defense message. */
784 static const char *msgs
[][2] = {
785 { "cs1", "1 Line Added to All" },
786 { "cs2", "2 Lines Added to All" },
787 { "cs4", "4 Lines Added to All" },
789 { "c", "Clear Line" },
790 { "n", "Nuke Field" },
791 { "r", "Clear Random Blocks" },
792 { "s", "Switch Fields" },
793 { "b", "Clear Special Blocks" },
794 { "g", "Block Gravity" },
795 { "q", "Blockquake" },
796 { "o", "Block Bomb" },
800 static void draw_attdef(const char *type
, int from
, int to
)
805 width
= other_coord
[4][0] - attdef_coord
[0] - 1;
806 for (i
= 0; msgs
[i
][0]; i
++) {
807 if (strcmp(type
, msgs
[i
][0]) == 0)
812 strcpy(buf
, msgs
[i
][1]);
814 sprintf(buf
+strlen(buf
), " on %s", players
[to
-1]);
816 sprintf(buf
+strlen(buf
), " by Server");
818 sprintf(buf
+strlen(buf
), " by %s", players
[from
-1]);
819 draw_text(BUFFER_ATTDEF
, buf
);
822 /*************************************************************************/
824 /* Display the in-game text window. */
826 static void draw_gmsg_input(const char *s
, int pos
)
828 static int start
= 0; /* Start of displayed part of input line */
829 static const char *last_s
;
841 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
843 if (!gmsg_inputwin
) {
844 gmsg_inputpos
= scrheight
/2 - 1;
845 gmsg_inputheight
= 3;
847 subwin(stdscr
, gmsg_inputheight
, scrwidth
, gmsg_inputpos
, 0);
848 werase(gmsg_inputwin
);
849 leaveok(gmsg_inputwin
, FALSE
);
850 leaveok(stdscr
, FALSE
);
851 mvwaddstr(gmsg_inputwin
, 1, 0, "Text>");
854 if (strlen(s
) < scrwidth
-7) {
856 mvwaddstr(gmsg_inputwin
, 1, 6, s
);
857 wmove(gmsg_inputwin
, 1, 6+strlen(s
));
858 move(gmsg_inputpos
+1, 6+strlen(s
));
859 wclrtoeol(gmsg_inputwin
);
860 wmove(gmsg_inputwin
, 1, 6+pos
);
861 move(gmsg_inputpos
+1, 6+pos
);
867 } else if (pos
> start
+ scrwidth
-15) {
868 start
= pos
- (scrwidth
-15);
869 if (start
> strlen(s
) - (scrwidth
-7))
870 start
= strlen(s
) - (scrwidth
-7);
872 mvwaddnstr(gmsg_inputwin
, 1, 6, s
+start
, scrwidth
-6);
873 wmove(gmsg_inputwin
, 1, 6 + (pos
-start
));
874 move(gmsg_inputpos
+1, 6 + (pos
-start
));
879 /*************************************************************************/
881 /* Clear the in-game text window. */
883 static void clear_gmsg_input(void)
886 delwin(gmsg_inputwin
);
887 gmsg_inputwin
= NULL
;
888 leaveok(stdscr
, TRUE
);
889 touchline(stdscr
, gmsg_inputpos
, gmsg_inputheight
);
895 /*************************************************************************/
896 /*************************** Partyline display ***************************/
897 /*************************************************************************/
899 static void setup_partyline(void)
901 close_textwin(&gmsgbuf
);
902 close_textwin(&attdefbuf
);
905 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
907 plinebuf
.x
= plinebuf
.y
= 0;
908 plinebuf
.width
= scrwidth
;
909 plinebuf
.height
= scrheight
-4;
910 open_textwin(&plinebuf
);
912 move(scrheight
-4, 0);
913 hline(MY_HLINE
, scrwidth
);
914 move(scrheight
-3, 0);
917 move(scrheight
-2, 0);
918 hline(MY_HLINE2
, scrwidth
);
920 move(scrheight
-1, 0);
921 addstr("F1=Show Fields F2=Partyline F3=Winlist");
922 move(scrheight
-1, scrwidth
-8);
926 move(scrheight
-3, 2);
927 leaveok(stdscr
, FALSE
);
931 /*************************************************************************/
933 static void draw_partyline_input(const char *s
, int pos
)
935 static int start
= 0; /* Start of displayed part of input line */
937 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
938 if (strlen(s
) < scrwidth
-3) {
940 mvaddstr(scrheight
-3, 2, s
);
941 move(scrheight
-3, 2+strlen(s
));
943 move(scrheight
-3, 2+pos
);
949 } else if (pos
> start
+ scrwidth
-11) {
950 start
= pos
- (scrwidth
-11);
951 if (start
> strlen(s
) - (scrwidth
-3))
952 start
= strlen(s
) - (scrwidth
-3);
954 mvaddnstr(scrheight
-3, 2, s
+start
, scrwidth
-2);
955 move(scrheight
-3, 2 + (pos
-start
));
960 /*************************************************************************/
961 /**************************** Winlist display ****************************/
962 /*************************************************************************/
964 static void setup_winlist(void)
969 leaveok(stdscr
, TRUE
);
970 close_textwin(&plinebuf
);
972 attrset(getcolor(COLOR_WHITE
,COLOR_BLACK
));
974 for (i
= 0; i
< MAXWINLIST
&& *winlist
[i
].name
; i
++) {
975 x
= scrwidth
/2 - strlen(winlist
[i
].name
);
978 if (winlist
[i
].team
) {
981 mvaddstr(i
*2, x
-4, "<T>");
983 mvaddstr(i
*2, x
, winlist
[i
].name
);
984 snprintf(buf
, sizeof(buf
), "%4d", winlist
[i
].points
);
985 if (winlist
[i
].games
) {
986 int avg100
= winlist
[i
].points
*100 / winlist
[i
].games
;
987 snprintf(buf
+strlen(buf
), sizeof(buf
)-strlen(buf
),
988 " %d.%02d",avg100
/100, avg100
%100);
990 x
+= strlen(winlist
[i
].name
) + 2;
991 if (x
> scrwidth
- strlen(buf
))
992 x
= scrwidth
- strlen(buf
);
993 mvaddstr(i
*2, x
, buf
);
996 move(scrheight
-2, 0);
997 hline(MY_HLINE2
, scrwidth
);
999 move(scrheight
-1, 0);
1000 addstr("F1=Show Fields F2=Partyline F3=Winlist");
1001 move(scrheight
-1, scrwidth
-8);
1008 /*************************************************************************/
1009 /************************** Interface declaration ************************/
1010 /*************************************************************************/
1012 Interface xwin_interface
= {
1033 draw_partyline_input
,
1038 /*************************************************************************/