cfad47cfa3/src/frobtadsappcurses.h

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
/* This is the curses-specific implementation of FrobTadsApplication.
2
 */
3
#ifndef FROBTADSAPPCURSES_H
4
#define FROBTADSAPPCURSES_H
5
6
#include "common.h"
7
8
#include "frobtadsapp.h"
9
#include "tadswindow.h"
10
11
12
class FrobTadsApplicationCurses: public FrobTadsApplication {
13
  private:
14
	// The window we use for I/O.
15
	FrobTadsWindow *fGameWindow;
16
17
	// Tads never tries to display a string that is longer than the
18
	// window's width.  We use this knowledge to optimize output
19
	// somewhat.  Instead of allocating and deallocating memory each
20
	// time we print a string (memory allocation is slow), we use
21
	// this small buffer instead and allocate memory only once when
22
	// a game window is created.
23
	chtype* fDispBuf;
24
25
  public:
26
	FrobTadsApplicationCurses( const FrobOptions& opts );
27
	~FrobTadsApplicationCurses();
28
29
30
	/* ============================================================
31
	 * Interface implementation.
32
	 * ============================================================
33
	 */
34
  protected:
35
	virtual void
36
	init();
37
38
	// We simply handle everything in init().
39
	virtual void
40
	resizeEvent()
41
	{ this->init(); }
42
43
  public:
44
	virtual void
45
	moveCursor( int line, int column )
46
	{ this->fGameWindow->moveCursor(line, column); }
47
48
	virtual void
49
	print( int line, int column, int attrs, const char* str )
50
	{
51
		int i;
52
		for (i = 0; str[i] != '\0'; ++i) this->fDispBuf[i] = str[i] | attrs;
53
		this->fDispBuf[i] = '\0';
54
		this->fGameWindow->printStr(line, column, this->fDispBuf);
55
	}
56
57
	virtual void
58
	flush()
59
	{ this->fGameWindow->flush(); }
60
61
	virtual void
62
	clear( int top, int left, int bottom, int right, int attrs );
63
64
	virtual void
65
	scrollRegionUp( int top, int left, int bottom, int right, int attrs );
66
67
	virtual void
68
	scrollRegionDown( int top, int left, int bottom, int right, int attrs );
69
70
	virtual int
71
	getRawChar( bool cursorVisible, int timeout );
72
73
	virtual void
74
	sleep( int ms )
75
	{ this->fGameWindow->flush(); napms(ms); }
76
77
	virtual int
78
	height() const
79
	{ return this->fGameWindow->height(); }
80
81
	virtual int
82
	width() const
83
	{ return this->fGameWindow->width(); }
84
};
85
86
#endif // FROBTADSAPPCURSES_H