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