File: window.h

package info (click to toggle)
curves 0.8.7
  • links: PTS
  • area: main
  • in suites: slink
  • size: 704 kB
  • ctags: 1,001
  • sloc: cpp: 6,197; ansic: 519; makefile: 270; sh: 192; fortran: 149
file content (210 lines) | stat: -rw-r--r-- 5,075 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* window.h							-*- C++ -*-
     $Id: window.h,v 1.10 1997/07/26 11:20:02 elf Exp $

   written by Marc Singer
   19 September 1996

   This file is part of the project CurVeS.  See the file README for
   more information.

   Copyright (C) 1996 Marc Singer

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   in a file called COPYING along with this program; if not, write to
   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
   02139, USA.

   -----------
   DESCRIPTION
   -----------

   Header for screen/window class.


*/

#if !defined (_WINDOW_H_)
#    define   _WINDOW_H_

#if defined (HAVE_NCURSES_CURSES_H)
# include <ncurses/curses.h>
#else
# if defined (HAVE_NCURSES_H)
#  include <ncurses.h>
# else
#  if defined (HAVE_CURSES_H)
#   include <curses.h>
#  else
#  endif
			// This is fatal, but what are we to do?
# endif
#endif

#include "mouse.h"

				// Eliminate foolish macros
#undef refresh
#undef border
#undef vline
#undef getch
#undef getstr
#undef scroll
#undef erase
#undef clear

typedef enum {
  colorNul = 0,
  colorBlack,
  colorRed,
  colorGreen,
  colorYellow,
  colorBlue,
  colorMagenta,
  colorCyan,
  colorWhite,
  colorDefault,
} eColor;

class LWindow {
protected:
  WINDOW* m_pWindow;
  LWindow* m_pWindowParent;

  bool is (void) {
    return m_pWindow != NULL; }

public:
  LWindow (WINDOW* pWindow) {
    zero (); init (pWindow); }
  ~LWindow () {
    release_this (); }
  void zero (void) {
    memset (this, 0, sizeof (*this)); }
  void init (WINDOW* pWindow);
  void release_this (void);

  int dx (void) {
    int x, y;
    return is () ? (getmaxyx (m_pWindow, y, x), x) : -1; }
  int dy (void) {
    int x, y;
    return is () ? (getmaxyx (m_pWindow, y, x), y) : -1; }

  void attribute (int attr, bool fEnable) {
    if (fEnable)
      wattron (m_pWindow, attr); 
    else
      wattroff (m_pWindow, attr); }
  void border (void) {
    box (m_pWindow, 0, 0);
    touch (); }
  void clear (void) {
    wclear (m_pWindow); }
  LWindow* create_child (int x, int y, int dx, int dy);
  void defrefresh (void) {
    wnoutrefresh (m_pWindow); }
  void erase (void) {
    //    wclear (m_pWindow);
    werase (m_pWindow);
  }
  int getch (int x, int y) {
#if defined (USE_GPM_MOUSE)
    wmove (m_pWindow, y, x);
    wrefresh (m_pWindow);	// Force the cursor to appear in the window
    return Gpm_Wgetch (m_pWindow);
#else
    return mvwgetch (m_pWindow, y, x); 
#endif
  }
  int getch (void) {
#if defined (USE_GPM_MOUSE)
    wrefresh (m_pWindow);	// Force the cursor to appear in the window
    return Gpm_Wgetch (m_pWindow);
#else
    return wgetch (m_pWindow);
#endif
  }
  int getstr (int x, int y, char* sz, int cch);
  int getstr (int x, int y, char* szPrompt, 
	      char* szResponse, int cchResponseMax, const char* szDefault);
  void moveto (int x, int y) {
    wmove (m_pWindow, y, x); wsyncup (m_pWindow); }
  void on (int attribute) {
    wattron (m_pWindow, attribute); }
  void off (int attribute) {
    wattroff (m_pWindow, attribute); }
  void printfxy (int x, int y, const char* szFormat, ...);
  void redraw (void) {
    redrawwin (m_pWindow); }
  void refresh (void) {
    wrefresh (m_pWindow); }
  void scroll (int dy) {
    wscrl (m_pWindow, dy); }
  void touch (int y);
  void touch (void) {
    if (m_pWindowParent)
      m_pWindowParent->touch ();
    else
      touchwin (m_pWindow); }
  void vline (int x, int yTop, int yBottom) {
    moveto (x, yTop);
    wvline (m_pWindow, 0, yBottom - yTop + 1); 
    touch (); }
};


class LScreen {
protected:
  LWindow* m_pWindowRoot;

  bool is (void) {
    return m_pWindowRoot != NULL; }
  
  int _color_of (int color);

public:
  LScreen () {
    zero (); init (); }
  ~LScreen () {
    release_this (); }
  void zero (void) {
    memset (this, 0, sizeof (*this)); }
  void init (void);
  void release_this (void);
  
  int dx (void) {
    return is () ? m_pWindowRoot->dx (): -1; }
  int dy (void) {
    return is () ? m_pWindowRoot->dy (): -1; }
  LWindow* root (void) {
    return m_pWindowRoot; }

  static int string_dx (const char* sz, int cb = -1) {
    int cch = strlen (sz);
    if (cb == -1)
      return cch;
    return (cch < cb) ? cch : cb; }
  static int string_dy (const char* sz, int cb = -1) {
    int cch = strlen (sz);
    if (cb == -1)
      return cch ? 1 : 0;
    return (cch || cb) ? 1 : 0; }

  void define_color (int iColor, int colorFore, int colorBack) {
    init_pair (iColor, _color_of (colorFore), _color_of (colorBack)); }
  void update (void) {
    doupdate (); }

};

#endif /* _WINDOW_H_ */