Sync usage with man page.
[netbsd-mini2440.git] / games / dab / ttyscrn.cc
blob7fce0801708623d5eebeed2b5e9380a84eeb6689
1 /* $NetBSD: ttyscrn.cc,v 1.3 2005/08/09 02:38:32 christos Exp $ */
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * ttyscrn.C: Curses screen implementation for dots
36 #include "defs.h"
37 RCSID("$NetBSD: ttyscrn.cc,v 1.3 2005/08/09 02:38:32 christos Exp $")
39 #include <stdio.h>
40 #include <curses.h>
41 #include <sys/ioctl.h>
43 #include "player.h"
44 #include "ttyscrn.h"
46 void TTYSCRN::clean(void)
48 clear();
51 void TTYSCRN::moveto(size_t y, size_t x)
53 move(y + TTYSCRN::offsy, x + TTYSCRN::offsx);
56 void TTYSCRN::addsym(const int sym)
58 addch(sym);
61 void TTYSCRN::addedge(const int sym)
63 int nsym;
64 #ifdef A_ALTCHARSET
65 if (_acs) {
66 switch (sym) {
67 case GS_HLINE:
68 nsym = ACS_HLINE;
69 break;
70 case GS_VLINE:
71 nsym = ACS_VLINE;
72 break;
73 case GS_ULCORNER:
74 nsym = ACS_ULCORNER;
75 break;
76 case GS_URCORNER:
77 nsym = ACS_URCORNER;
78 break;
79 case GS_LLCORNER:
80 nsym = ACS_LLCORNER;
81 break;
82 case GS_LRCORNER:
83 nsym = ACS_LRCORNER;
84 break;
85 case GS_LTEE:
86 nsym = ACS_LTEE;
87 break;
88 case GS_RTEE:
89 nsym = ACS_RTEE;
90 break;
91 case GS_TTEE:
92 nsym = ACS_TTEE;
93 break;
94 case GS_BTEE:
95 nsym = ACS_BTEE;
96 break;
97 case GS_PLUS:
98 nsym = ACS_PLUS;
99 break;
100 case ' ':
101 addsym(' ');
102 return;
103 default:
104 ::abort();
106 attron(A_ALTCHARSET);
107 addch(nsym);
108 attroff(A_ALTCHARSET);
109 return;
111 #endif
112 switch (sym) {
113 case GS_HLINE:
114 nsym = '-';
115 break;
116 case GS_VLINE:
117 nsym = '|';
118 break;
119 case GS_ULCORNER:
120 nsym = '.';
121 break;
122 case GS_URCORNER:
123 nsym = '.';
124 break;
125 case GS_LLCORNER:
126 nsym = '.';
127 break;
128 case GS_LRCORNER:
129 nsym = '.';
130 break;
131 case GS_LTEE:
132 nsym = '.';
133 break;
134 case GS_RTEE:
135 nsym = '.';
136 break;
137 case GS_TTEE:
138 nsym = '.';
139 break;
140 case GS_BTEE:
141 nsym = '.';
142 break;
143 case GS_PLUS:
144 nsym = '+';
145 break;
146 case ' ':
147 addsym(' ');
148 return;
149 default:
150 ::abort();
152 addsym(nsym);
155 void TTYSCRN::redraw(void)
157 refresh();
158 doupdate();
161 void TTYSCRN::bell(void)
163 putc('\007', stdout);
166 int TTYSCRN::getinput(void)
168 return getch();
171 void TTYSCRN::score(size_t s, const PLAYER& p)
173 mvwprintw(stdscr, _sy + s + TTYSCRN::offsscore, _sx, "S %c:%5zd", p.getWho(),
174 p.getScore());
177 void TTYSCRN::total(size_t s, const PLAYER& p)
179 mvwprintw(stdscr, _sy + s + TTYSCRN::offstotal, _sx, "T %c:%5zd", p.getWho(),
180 p.getTotal());
183 void TTYSCRN::games(size_t s, const PLAYER& p)
185 mvwprintw(stdscr, _sy + s + TTYSCRN::offsgames, _sx, "G %c:%5zd", p.getWho(),
186 p.getGames());
189 void TTYSCRN::ties(const PLAYER& p)
191 mvwprintw(stdscr, _sy + TTYSCRN::offsties, _sx, "G =:%5zd", p.getTies());
194 TTYSCRN* TTYSCRN::create(int acs, size_t y, size_t x)
196 int tx, ty;
198 initscr();
200 tx = getmaxx(stdscr);
201 ty = getmaxy(stdscr);
203 if (tx == ERR || ty == ERR
204 || static_cast<size_t>(tx) < x * 2 + TTYSCRN::offsx + 12
205 || static_cast<size_t>(ty) < y * 2 + TTYSCRN::offsy) {
206 endwin();
207 return NULL;
209 cbreak();
210 noecho();
213 TTYSCRN* that = new TTYSCRN;
215 that->_tx = tx;
216 that->_ty = ty;
217 that->_sx = tx - 12;
218 that->_sy = TTYSCRN::offsy;
219 that->_acs = acs;
221 return that;
224 TTYSCRN::~TTYSCRN(void)
226 nocbreak();
227 echo();
228 endwin();