1 /*
2     GUILIB:  An example GUI framework library for use with SDL
3 */
4 
5 /* A simple dumb terminal scrollable widget */
6 
7 #ifndef _GUI_termwin_h
8 #define _GUI_termwin_h
9 
10 #include "GUI_widget.h"
11 #include "GUI_scroll.h"
12 
13 
14 class GUI_TermWin : public GUI_Scrollable {
15 
16 public:
17 	/* The font surface should be a 16x16 character pixmap */
18 	GUI_TermWin(int x, int y, int w, int h, SDL_Surface *font = NULL,
19 			void (*KeyProc)(SDLKey key, Uint16 unicode) = NULL, int scrollback = 0);
20 	~GUI_TermWin();
21 
22 	/* Show the text window */
23 	virtual void Display(void);
24 
25 	/* Function to scroll forward and backward */
26 	virtual int Scroll(int amount);
27 
28 	/* Function to get the scrollable range */
29 	virtual void Range(int &first, int &last);
30 
31 	/* Handle keyboard input */
32 	virtual GUI_status KeyDown(SDL_keysym key);
33 	virtual GUI_status KeyUp(SDL_keysym key);
34 
35 	/* Function to add text to the visible buffer */
36 	virtual void AddText(const char *text, int len);
37 	virtual void AddText(const char *fmt, ...);
38 
39 	/* Function to clear the visible buffer */
40 	virtual void Clear(void);
41 
42 	/* Function returns true if the window has changed */
43 	virtual int Changed(void);
44 
45 	/* GUI idle function -- run when no events pending */
46 	virtual GUI_status Idle(void);
47 
48 	/* change FG/BG colors and transparency */
49 	virtual void SetColoring(Uint8 fr, Uint8 fg, Uint8 fb, int bg_opaque = 0,
50 					 Uint8 br = 0, Uint8 bg = 0, Uint8 bb = 0);
51 
52 protected:
53 	/* The actual characters representing the screen */
54 	Uint8 *vscreen;
55 
56 	/* Information about the size and position of the buffer */
57 	int total_rows;
58 	int rows, cols;
59 	int first_row;
60 	int cur_row;
61 	int cur_col;
62 	int scroll_min, scroll_row, scroll_max;
63 
64 	/* Font information used to display characters */
65 	SDL_Surface *font;
66 	int charw, charh;
67 	int translated;	/* Whether or not UNICODE translation was enabled */
68 
69 	/* The keyboard handling function */
70 	void (*keyproc)(SDLKey key, Uint16 unicode);
71 
72 	/* The last key that was pressed, along with key repeat time */
73 	SDLKey repeat_key;
74 	Uint16 repeat_unicode;
75 	Uint32 repeat_next;
76 
77 	/* Flag -- whether or not we need to redisplay ourselves */
78 	int changed;
79 
80 	/* Terminal manipulation routines */
81 	void NewLine(void);			/* <CR>+<LF> */
82 };
83 
84 #endif /* _GUI_termwin_h */
85