1 // Emacs style mode select   -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // Copyright(C) 2005,2006 Simon Howard
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 // 02111-1307, USA.
20 //
21 //-----------------------------------------------------------------------------
22 //
23 // Base interface that abstracts the text mode screen.
24 //
25 //-----------------------------------------------------------------------------
26 
27 #ifndef TXT_MAIN_H
28 #define TXT_MAIN_H
29 
30 // For the moment, txt_sdl.c is the only implementation of the base
31 // text mode screen API:
32 
33 #include "txt_sdl.h"
34 
35 // textscreen key values:
36 // Key values are difficult because we have to support multiple conflicting
37 // address spaces.
38 // First, Doom's key constants use 0-127 as ASCII and extra values from
39 // 128-255 to represent special keys. Second, mouse buttons are represented
40 // as buttons. Finally, we want to be able to support Unicode.
41 //
42 // So we define different ranges:
43 // 0-255:    Doom key constants, including ASCII.
44 // 256-511:  Mouse buttons and other reserved.
45 // >=512:    Unicode values greater than 127 are offset up into this range.
46 
47 // Special keypress values that correspond to mouse button clicks
48 
49 #define TXT_MOUSE_BASE         256
50 #define TXT_MOUSE_LEFT         (TXT_MOUSE_BASE + 0)
51 #define TXT_MOUSE_RIGHT        (TXT_MOUSE_BASE + 1)
52 #define TXT_MOUSE_MIDDLE       (TXT_MOUSE_BASE + 2)
53 #define TXT_MOUSE_SCROLLUP     (TXT_MOUSE_BASE + 3)
54 #define TXT_MOUSE_SCROLLDOWN   (TXT_MOUSE_BASE + 4)
55 #define TXT_MAX_MOUSE_BUTTONS  16
56 
57 #define TXT_KEY_TO_MOUSE_BUTTON(x)                                        \
58         ( (x) >= TXT_MOUSE_BASE                                           \
59        && (x) < TXT_MOUSE_BASE + TXT_MAX_MOUSE_BUTTONS ?                  \
60           (x) - TXT_MOUSE_BASE : -1 )
61 
62 // Unicode offset. Unicode values from 128 onwards are offset up into
63 // this range, so TXT_UNICODE_BASE = Unicode character #128, and so on.
64 
65 #define TXT_UNICODE_BASE       512
66 
67 // Convert a key value to a Unicode character:
68 
69 #define TXT_KEY_TO_UNICODE(x)                                             \
70         ( (x) < 128 ? (x) :                                               \
71           (x) >= TXT_UNICODE_BASE ? ((x) - TXT_UNICODE_BASE + 128) : 0 )
72 
73 // Screen size
74 
75 #define TXT_SCREEN_W 80
76 #define TXT_SCREEN_H 25
77 
78 #define TXT_COLOR_BLINKING (1 << 3)
79 
80 typedef enum
81 {
82     TXT_COLOR_BLACK,
83     TXT_COLOR_BLUE,
84     TXT_COLOR_GREEN,
85     TXT_COLOR_CYAN,
86     TXT_COLOR_RED,
87     TXT_COLOR_MAGENTA,
88     TXT_COLOR_BROWN,
89     TXT_COLOR_GREY,
90     TXT_COLOR_DARK_GREY,
91     TXT_COLOR_BRIGHT_BLUE,
92     TXT_COLOR_BRIGHT_GREEN,
93     TXT_COLOR_BRIGHT_CYAN,
94     TXT_COLOR_BRIGHT_RED,
95     TXT_COLOR_BRIGHT_MAGENTA,
96     TXT_COLOR_YELLOW,
97     TXT_COLOR_BRIGHT_WHITE,
98 } txt_color_t;
99 
100 // Modifier keys.
101 
102 typedef enum
103 {
104     TXT_MOD_SHIFT,
105     TXT_MOD_CTRL,
106     TXT_MOD_ALT,
107     TXT_NUM_MODIFIERS
108 } txt_modifier_t;
109 
110 // Initialize the screen
111 // Returns 1 if successful, 0 if failed.
112 
113 int TXT_Init(void);
114 
115 // Shut down text mode emulation
116 
117 void TXT_Shutdown(void);
118 
119 // Get a pointer to the buffer containing the raw screen data.
120 
121 unsigned char *TXT_GetScreenData(void);
122 
123 // Update an area of the screen
124 
125 void TXT_UpdateScreenArea(int x, int y, int w, int h);
126 
127 // Update the whole screen
128 
129 void TXT_UpdateScreen(void);
130 
131 // Read a character from the keyboard
132 
133 int TXT_GetChar(void);
134 
135 // Read the current state of modifier keys that are held down.
136 
137 int TXT_GetModifierState(txt_modifier_t mod);
138 
139 // Provides a short description of a key code, placing into the
140 // provided buffer.
141 
142 void TXT_GetKeyDescription(int key, char *buf);
143 
144 // Retrieve the current position of the mouse
145 
146 void TXT_GetMousePosition(int *x, int *y);
147 
148 // Sleep until an event is received or the screen needs updating
149 // Optional timeout in ms (timeout == 0 : sleep forever)
150 
151 void TXT_Sleep(int timeout);
152 
153 // Controls whether keys are returned from TXT_GetChar based on keyboard
154 // mapping, or raw key code.
155 
156 void TXT_EnableKeyMapping(int enable);
157 
158 // Set the window title of the window containing the text mode screen
159 
160 void TXT_SetWindowTitle(char *title);
161 
162 #endif /* #ifndef TXT_MAIN_H */
163 
164