Home | History | Annotate | Line # | Download | only in dab
ttyscrn.cc revision 1.2
      1  1.2    martin /*	$NetBSD: ttyscrn.cc,v 1.2 2003/12/27 18:24:51 martin Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*-
      4  1.1  christos  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5  1.1  christos  * All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  christos  * by Christos Zoulas.
      9  1.1  christos  *
     10  1.1  christos  * Redistribution and use in source and binary forms, with or without
     11  1.1  christos  * modification, are permitted provided that the following conditions
     12  1.1  christos  * are met:
     13  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  christos  *    documentation and/or other materials provided with the distribution.
     18  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     19  1.1  christos  *    must display the following acknowledgement:
     20  1.1  christos  *        This product includes software developed by the NetBSD
     21  1.1  christos  *        Foundation, Inc. and its contributors.
     22  1.1  christos  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  christos  *    contributors may be used to endorse or promote products derived
     24  1.1  christos  *    from this software without specific prior written permission.
     25  1.1  christos  *
     26  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  christos  */
     38  1.1  christos 
     39  1.1  christos /*
     40  1.1  christos  * ttyscrn.C: Curses screen implementation for dots
     41  1.1  christos  */
     42  1.1  christos 
     43  1.1  christos #include "defs.h"
     44  1.2    martin RCSID("$NetBSD: ttyscrn.cc,v 1.2 2003/12/27 18:24:51 martin Exp $")
     45  1.1  christos 
     46  1.1  christos #include <stdio.h>
     47  1.1  christos #include <curses.h>
     48  1.1  christos #include <sys/ioctl.h>
     49  1.1  christos 
     50  1.1  christos #include "player.h"
     51  1.1  christos #include "ttyscrn.h"
     52  1.1  christos 
     53  1.1  christos void TTYSCRN::clean(void)
     54  1.1  christos {
     55  1.1  christos     clear();
     56  1.1  christos }
     57  1.1  christos 
     58  1.1  christos void TTYSCRN::moveto(size_t y, size_t x)
     59  1.1  christos {
     60  1.1  christos     move(y + TTYSCRN::offsy, x + TTYSCRN::offsx);
     61  1.1  christos }
     62  1.1  christos 
     63  1.1  christos void TTYSCRN::addsym(const int sym)
     64  1.1  christos {
     65  1.1  christos     addch(sym);
     66  1.1  christos }
     67  1.1  christos 
     68  1.1  christos void TTYSCRN::addedge(const int sym)
     69  1.1  christos {
     70  1.1  christos     int nsym;
     71  1.1  christos #ifdef A_ALTCHARSET
     72  1.1  christos     if (_acs) {
     73  1.1  christos 	switch (sym) {
     74  1.1  christos 	case GS_HLINE:
     75  1.1  christos 	    nsym = ACS_HLINE;
     76  1.1  christos 	    break;
     77  1.1  christos 	case GS_VLINE:
     78  1.1  christos 	    nsym = ACS_VLINE;
     79  1.1  christos 	    break;
     80  1.1  christos 	case GS_ULCORNER:
     81  1.1  christos 	    nsym = ACS_ULCORNER;
     82  1.1  christos 	    break;
     83  1.1  christos 	case GS_URCORNER:
     84  1.1  christos 	    nsym = ACS_URCORNER;
     85  1.1  christos 	    break;
     86  1.1  christos 	case GS_LLCORNER:
     87  1.1  christos 	    nsym = ACS_LLCORNER;
     88  1.1  christos 	    break;
     89  1.1  christos 	case GS_LRCORNER:
     90  1.1  christos 	    nsym = ACS_LRCORNER;
     91  1.1  christos 	    break;
     92  1.1  christos 	case GS_LTEE:
     93  1.1  christos 	    nsym = ACS_LTEE;
     94  1.1  christos 	    break;
     95  1.1  christos 	case GS_RTEE:
     96  1.1  christos 	    nsym = ACS_RTEE;
     97  1.1  christos 	    break;
     98  1.1  christos 	case GS_TTEE:
     99  1.1  christos 	    nsym = ACS_TTEE;
    100  1.1  christos 	    break;
    101  1.1  christos 	case GS_BTEE:
    102  1.1  christos 	    nsym = ACS_BTEE;
    103  1.1  christos 	    break;
    104  1.1  christos 	case GS_PLUS:
    105  1.1  christos 	    nsym = ACS_PLUS;
    106  1.1  christos 	    break;
    107  1.1  christos 	case ' ':
    108  1.1  christos 	    addsym(' ');
    109  1.1  christos 	    return;
    110  1.1  christos 	default:
    111  1.1  christos 	    ::abort();
    112  1.1  christos 	}
    113  1.1  christos 	attron(A_ALTCHARSET);
    114  1.1  christos 	addch(nsym);
    115  1.1  christos 	attroff(A_ALTCHARSET);
    116  1.1  christos 	return;
    117  1.1  christos     }
    118  1.1  christos #endif
    119  1.1  christos     switch (sym) {
    120  1.1  christos     case GS_HLINE:
    121  1.1  christos 	nsym = '-';
    122  1.1  christos 	break;
    123  1.1  christos     case GS_VLINE:
    124  1.1  christos 	nsym = '|';
    125  1.1  christos 	break;
    126  1.1  christos     case GS_ULCORNER:
    127  1.1  christos 	nsym = '.';
    128  1.1  christos 	break;
    129  1.1  christos     case GS_URCORNER:
    130  1.1  christos 	nsym = '.';
    131  1.1  christos 	break;
    132  1.1  christos     case GS_LLCORNER:
    133  1.1  christos 	nsym = '.';
    134  1.1  christos 	break;
    135  1.1  christos     case GS_LRCORNER:
    136  1.1  christos 	nsym = '.';
    137  1.1  christos 	break;
    138  1.1  christos     case GS_LTEE:
    139  1.1  christos 	nsym = '.';
    140  1.1  christos 	break;
    141  1.1  christos     case GS_RTEE:
    142  1.1  christos 	nsym = '.';
    143  1.1  christos 	break;
    144  1.1  christos     case GS_TTEE:
    145  1.1  christos 	nsym = '.';
    146  1.1  christos 	break;
    147  1.1  christos     case GS_BTEE:
    148  1.1  christos 	nsym = '.';
    149  1.1  christos 	break;
    150  1.1  christos     case GS_PLUS:
    151  1.1  christos 	nsym = '+';
    152  1.1  christos 	break;
    153  1.1  christos     case ' ':
    154  1.1  christos 	addsym(' ');
    155  1.1  christos 	return;
    156  1.1  christos     default:
    157  1.1  christos 	::abort();
    158  1.1  christos     }
    159  1.1  christos     addsym(nsym);
    160  1.1  christos }
    161  1.1  christos 
    162  1.1  christos void TTYSCRN::redraw(void)
    163  1.1  christos {
    164  1.1  christos     refresh();
    165  1.1  christos     doupdate();
    166  1.1  christos }
    167  1.1  christos 
    168  1.1  christos void TTYSCRN::bell(void)
    169  1.1  christos {
    170  1.1  christos     putc('\007', stdout);
    171  1.1  christos }
    172  1.1  christos 
    173  1.1  christos int TTYSCRN::getinput(void)
    174  1.1  christos {
    175  1.1  christos     return getch();
    176  1.1  christos }
    177  1.1  christos 
    178  1.1  christos void TTYSCRN::score(size_t s, const PLAYER& p)
    179  1.1  christos {
    180  1.2    martin     mvwprintw(stdscr, _sy + s + TTYSCRN::offsscore, _sx, "S %c:%5zd", p.getWho(),
    181  1.1  christos 	      p.getScore());
    182  1.1  christos }
    183  1.1  christos 
    184  1.1  christos void TTYSCRN::total(size_t s, const PLAYER& p)
    185  1.1  christos {
    186  1.2    martin     mvwprintw(stdscr, _sy + s + TTYSCRN::offstotal, _sx, "T %c:%5zd", p.getWho(),
    187  1.1  christos 	      p.getTotal());
    188  1.1  christos }
    189  1.1  christos 
    190  1.1  christos void TTYSCRN::games(size_t s, const PLAYER& p)
    191  1.1  christos {
    192  1.2    martin     mvwprintw(stdscr, _sy + s + TTYSCRN::offsgames, _sx, "G %c:%5zd", p.getWho(),
    193  1.1  christos 	      p.getGames());
    194  1.1  christos }
    195  1.1  christos 
    196  1.1  christos void TTYSCRN::ties(const PLAYER& p)
    197  1.1  christos {
    198  1.2    martin     mvwprintw(stdscr, _sy + TTYSCRN::offsties, _sx, "G =:%5zd", p.getTies());
    199  1.1  christos }
    200  1.1  christos 
    201  1.1  christos TTYSCRN* TTYSCRN::create(int acs, size_t y, size_t x)
    202  1.1  christos {
    203  1.1  christos     int tx, ty;
    204  1.1  christos 
    205  1.1  christos     initscr();
    206  1.1  christos 
    207  1.1  christos     tx = getmaxx(stdscr);
    208  1.1  christos     ty = getmaxy(stdscr);
    209  1.1  christos 
    210  1.1  christos     if (tx == ERR || ty == ERR || (size_t)tx < x * 2 + TTYSCRN::offsx + 12
    211  1.1  christos 	|| (size_t)ty < y * 2 + TTYSCRN::offsy) {
    212  1.1  christos 	endwin();
    213  1.1  christos 	return NULL;
    214  1.1  christos     }
    215  1.1  christos     cbreak();
    216  1.1  christos     noecho();
    217  1.1  christos 
    218  1.1  christos 
    219  1.1  christos     TTYSCRN* that = new TTYSCRN;
    220  1.1  christos 
    221  1.1  christos     that->_tx = tx;
    222  1.1  christos     that->_ty = ty;
    223  1.1  christos     that->_sx = tx - 12;
    224  1.1  christos     that->_sy = TTYSCRN::offsy;
    225  1.1  christos     that->_acs = acs;
    226  1.1  christos 
    227  1.1  christos     return that;
    228  1.1  christos }
    229  1.1  christos 
    230  1.1  christos TTYSCRN::~TTYSCRN(void)
    231  1.1  christos {
    232  1.1  christos     nocbreak();
    233  1.1  christos     echo();
    234  1.1  christos     endwin();
    235  1.1  christos }
    236