File: blue6.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 (373 lines) | stat: -rw-r--r-- 9,440 bytes parent folder | download
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/* blue6.h					-*- C++ -*-
   $Id: blue6.h,v 1.16 1998/09/07 00:49:31 elf Exp $
   
   written by Marc Singer
   22 Feb 1998

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

   Copyright (C) 1998 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.

   Simple that classs to interface to termcap.

*/

#if !defined (__BLUE6_H__)
#    define   __BLUE6_H__

/* ----- Includes */

#include "termcap.h"
#include <list>			// STL list
//using namespace stl;

inline void _memset (void* pv, unsigned char ch, int cb) \
			{ memset (pv, ch, cb); }

#if !defined (ZERO_BASED)
# define ZERO_BASED(t,cb) _memset ((char*) (t) + (cb), 0, sizeof (*(t)) - (cb))
#endif

/* ----- Types */

/* ----- Classes */

class Attribute {
public:
  static Attribute normal;	// Used to reset attributes

  enum eAttr {
    Plain		= 0x0000,
    Bold		= 0x0001,
    Underline		= 0x0002,
    Inverse		= 0x0004,
    Reverse		= 0x0004,
    Standout		= 0x0008,
    Blink		= 0x0010,
    //    Dim		= 0x0020,
    AllMode		= 0x003f,
    FgBright		= 0x0080,
    FgDefault		= 0x0000,	// Foreground colors
    FgMask		= 0x0f00,
    FgShift		= 8,
    FgFirst		= 0x0100,
    FgBlack		= 0x0100,
    FgRed		= 0x0200,
    FgGreen		= 0x0300,
    FgYellow		= 0x0400,
    FgBlue		= 0x0500,
    FgMagenta		= 0x0600,
    FgCyan		= 0x0700,
    FgWhite		= 0x0800,
    BgMask		= 0xf000, 	// Background colors
    BgShift		= 12,
    BgDefault		= 0x0000,
    BgFirst		= 0x1000,
    BgBlack		= 0x1000,
    BgRed		= 0x2000,
    BgGreen		= 0x3000,
    BgYellow		= 0x4000,
    BgBlue		= 0x5000,
    BgMagenta		= 0x6000,
    BgCyan		= 0x7000,
    BgWhite		= 0x8000,
    All			= 0xff3f,
  };

protected:
  int m_value;
  int m_mask;

public:
  Attribute () {
    zero (); init (); }
  Attribute (const Attribute& attr) {
    m_value = attr.m_value; m_mask = attr.m_mask; }
  Attribute (int value, int mask) {
    m_value = value; m_mask = mask; }
  void zero (void) {
    memset (this, 0, sizeof (*this)); }
  void init (void) {
    /* m_mask = (AllMode | BgMask | FgMask); */ }

  int reconcile (const Termcap& termcap, Attribute attr, char* sz, int cbMax);
  void set (int attr) {
    m_value = attr; m_mask = (AllMode | BgMask | FgMask); }
  void clear (void) {
    m_value = m_mask = 0; }
  int value (void) const {
    return m_value; }
  void ignore (int attr) {
    m_value &= ~attr;
    m_mask &= ~attr; }
				// I need more help here.
  void invert (int attr) {
    m_value = (m_value & ~attr) | ((m_value & attr) ? 0 : attr);
    m_mask |= attr; }

  Attribute merge (const Attribute& attr) const;

};

class Rectangle;

class Position {
public:
  int m_x;
  int m_y;

public:
  Position () { zero (); }
  Position (int x, int y) {
    init (x, y); }
  void init (int x, int y) {
    m_x = x; m_y = y; }
  void zero (void) {
    _memset (this, 0, sizeof (*this)); }

  void constrain (Rectangle& m_rc);

};

class Rectangle {
public:
  int m_x;
  int m_y;
  int m_dx;
  int m_dy;

public:
  Rectangle () { zero (); }
  Rectangle (int x, int y, int dx, int dy) {
    m_x = x; m_y = y; m_dx = dx; m_dy = dy; }
  Rectangle (const Rectangle& rc) {
    m_x = rc.m_x; m_y = rc.m_y; m_dx = rc.m_dx; m_dy = rc.m_dy; }
  void zero (void) {
    _memset (this, 0, sizeof (*this)); }

  bool is_empty (void) {
    return !(m_dx && m_dy); }
  Rectangle& intersect (const Rectangle& rc1, const Rectangle& rc2);
  Rectangle& intersect (const Rectangle& rc);

  Rectangle& offset (const Position& pos) {
    m_x += pos.m_x; m_y += pos.m_y; return *this; }
  Rectangle& offset (int dx, int dy) {
    m_x += dx; m_y += dy; return *this; }

  bool operator== (const Rectangle& rc) {
    return (   m_x  == rc.m_x
	    && m_y  == rc.m_y 
	    && m_dx == rc.m_dx
	    && m_dy == rc.m_dy); }

};

class Op {
public:
  enum eOp {
    opNul = 0,
    opErase,
    opDrawText,
    opDrawLine,
    opMoveTo,
  };

protected:
  Position m_pos;		// Position or 
  Rectangle m_rc;		//   Rectangle for operation
  Attribute m_attr;		// Attributes
  eOp m_op;			// Operation
  char* m_sz;			// String for draw_text

public:
  Op () {
    zero (); }
  Op (eOp op, const Rectangle& rc, const Attribute& attr) {
    zero (); init (op, rc, attr); }
  Op (eOp op, const Position& pos, const Attribute& attr,
      const char* sz, int cb) {
    zero (); init (op, pos, attr, sz, cb); }
  Op (eOp op, const Position& pos) {
    zero (); init (op, pos); }
  void zero (void) {
    memset (this, 0, sizeof (*this)); }
  void init (eOp op, const Rectangle& rc, const Attribute& attr);
  void init (eOp op, const Position& pos, const Attribute& attr,
	     const char* sz, int cb);
  void init (eOp op, const Position& pos);
  void init (eOp op, const Attribute& attr);
  
  eOp op (void) {
    return m_op; }
  const Rectangle& rc (void) {
    return m_rc; }
  const Position& pos (void) {
    return m_pos; }
  const Attribute& attr (void) {
    return m_attr; }
  const char* sz (void) {
    return m_sz; }
};

class Drawable {
protected:
  Position m_position;		// Current position
  Attribute m_attribute;	// Attributes, color and style
  Attribute m_attributeBg;	// Background or ambient attribute

public:
  Drawable () {
    zero (); init (); }
  void zero () {
    ZERO_BASED (this, sizeof (void*)); }
  void init (void) {
    m_attributeBg.set (0); }

  virtual Attribute& attr (void);
  virtual Attribute& attrBg (void);
  virtual Position& pos (void);
  virtual void _draw_text (const char* sz) = 0;
  virtual void _draw_text (const Position& pos, const char* sz);
  virtual void draw_text (const char* sz, ...);
  virtual void draw_text (const Position& pos, const char* sz, ...);
  virtual void draw_vertical_line (int x, int y, int dy) = 0;
  virtual void erase (const Rectangle& rc) = 0;
  virtual void erase (void) = 0;
  virtual void move_to (const Position& pos) = 0;
  virtual int prompt (Position pos, const char* szPrompt,
		      char* szReposonse, size_t cchResponse,
		      const char* szDefault) = 0;
  virtual bool scroll (int c) = 0;
};

class Frame {
protected:
  Rectangle m_rc;

public:
  Frame () {
    zero (); }
  Frame (Rectangle& rc) {
    zero (); init (rc); }
  void zero (void) {
    memset (this, 0, sizeof (*this)); }
  void init (const Rectangle& rc) {
    m_rc = rc; }

  int dx (void) const {
    return m_rc.m_dx; }
  int dy (void) const {
    return m_rc.m_dy; }
};

class Window;

class Pane : public Drawable, public Frame {
protected:
  Window* m_pWindow;		// Pointer to parent window

  Termcap& termcap (void);

public:
  Pane () {
    zero (); }
  Pane (Window& window, const Rectangle& rc) {
    zero (); init (window); Frame::init (rc); }
  void init (Window& window) {
    m_pWindow = &window; }
  void zero (void) {
    ZERO_BASED (this, sizeof (Drawable) + sizeof (Frame)); }

		// -- Implement Drawable
  void _draw_text (const char* sz);
  void erase (const Rectangle& rc);
  void draw_vertical_line (int x, int y, int dy);

  void erase (void);
  void move_to (const Position& pos);
  int prompt (Position pos, const char* szPrompt, 
	      char* szResponse, size_t cchResponse, 
	      const char* szDefault);
  bool scroll (int /* c */) { return false; }

  int getch (const Position& pos);

};

class Window : public Pane {
protected:
  Termcap* m_pTermcap;		// Termcap that we use
  //  Attribute m_attr;		// Default attribute for next character
  Position m_pos;		// Position of real cursor
  Attribute m_attrSave;		// Saved attribute for pushing

  char* m_rgb;			// Window buffer
  char m_rgbInput[10];		// Input buffer for multi-byte keystrokes
  int m_cbInput;		// Valid characters in the input buffer
  bool m_fNoGraphicCharset;	// Inhibit alt charset for line drawing

  list<Op*>* m_pListOp;		// List of pending operations

  //  list<Pane*> m_listPane;	// List of panes

public:
  Window () {
    zero (); Pane::init (*this); }
  virtual ~Window () {
    release_this (); }
  void zero (void) {
    ZERO_BASED (this, sizeof (Pane)); }
  void init (Termcap* pTermcap);
  void release_this (void);
  
  Termcap& termcap (void) {
    return *m_pTermcap; }

  void inhibit_alt_charset (bool fInhibit) {
    m_fNoGraphicCharset = fInhibit; }
  void queue (Op* pOp);
  void flush (void);		// Flush output queue
  int getch (void);
  void refresh (void) {}	// Repaint window
  void reset (void);
  void pop_attribute (void);
  void push_attribute (void);
  void activate (bool fActivate);

  void do_erase (Op* pOp);
  void do_draw_text (Op* pOp);
  void do_draw_line (Op* pOp);
  void do_move_to (Op* pOp);

		// -- Implement Drawable
  void erase (const Rectangle& rc);
  void erase (void) {
    erase (m_rc); }
};

inline Termcap& Pane::termcap (void) {
  return m_pWindow->termcap (); }


/* ----- Globals */



#endif  /* __BLUE6_H__ */