ttyscrn.cc 5.0 KB

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