|
@@ -1,568 +0,0 @@
|
1
|
|
-/*
|
2
|
|
-* BearLibTerminal
|
3
|
|
-* Copyright (C) 2013-2014 Cfyz
|
4
|
|
-*
|
5
|
|
-* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
|
-* of this software and associated documentation files (the "Software"), to deal
|
7
|
|
-* in the Software without restriction, including without limitation the rights
|
8
|
|
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
9
|
|
-* of the Software, and to permit persons to whom the Software is furnished to do
|
10
|
|
-* so, subject to the following conditions:
|
11
|
|
-*
|
12
|
|
-* The above copyright notice and this permission notice shall be included in all
|
13
|
|
-* copies or substantial portions of the Software.
|
14
|
|
-*
|
15
|
|
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
|
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
|
-* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
|
-* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
|
-* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
|
-* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
|
-*/
|
22
|
|
-
|
23
|
|
-#ifndef BEARLIBTERMINAL_H
|
24
|
|
-#define BEARLIBTERMINAL_H
|
25
|
|
-
|
26
|
|
-#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
27
|
|
-#define _CRT_SECURE_NO_WARNINGS
|
28
|
|
-#endif
|
29
|
|
-
|
30
|
|
-#include <stdio.h>
|
31
|
|
-#include <stddef.h>
|
32
|
|
-#include <stdint.h>
|
33
|
|
-#include <stdarg.h>
|
34
|
|
-#include <wchar.h>
|
35
|
|
-#if defined(__cplusplus)
|
36
|
|
-#include <sstream>
|
37
|
|
-#endif
|
38
|
|
-
|
39
|
|
-/*
|
40
|
|
- * Keyboard scancodes for events/states
|
41
|
|
- */
|
42
|
|
-#define TK_A 0x04
|
43
|
|
-#define TK_B 0x05
|
44
|
|
-#define TK_C 0x06
|
45
|
|
-#define TK_D 0x07
|
46
|
|
-#define TK_E 0x08
|
47
|
|
-#define TK_F 0x09
|
48
|
|
-#define TK_G 0x0A
|
49
|
|
-#define TK_H 0x0B
|
50
|
|
-#define TK_I 0x0C
|
51
|
|
-#define TK_J 0x0D
|
52
|
|
-#define TK_K 0x0E
|
53
|
|
-#define TK_L 0x0F
|
54
|
|
-#define TK_M 0x10
|
55
|
|
-#define TK_N 0x11
|
56
|
|
-#define TK_O 0x12
|
57
|
|
-#define TK_P 0x13
|
58
|
|
-#define TK_Q 0x14
|
59
|
|
-#define TK_R 0x15
|
60
|
|
-#define TK_S 0x16
|
61
|
|
-#define TK_T 0x17
|
62
|
|
-#define TK_U 0x18
|
63
|
|
-#define TK_V 0x19
|
64
|
|
-#define TK_W 0x1A
|
65
|
|
-#define TK_X 0x1B
|
66
|
|
-#define TK_Y 0x1C
|
67
|
|
-#define TK_Z 0x1D
|
68
|
|
-#define TK_1 0x1E
|
69
|
|
-#define TK_2 0x1F
|
70
|
|
-#define TK_3 0x20
|
71
|
|
-#define TK_4 0x21
|
72
|
|
-#define TK_5 0x22
|
73
|
|
-#define TK_6 0x23
|
74
|
|
-#define TK_7 0x24
|
75
|
|
-#define TK_8 0x25
|
76
|
|
-#define TK_9 0x26
|
77
|
|
-#define TK_0 0x27
|
78
|
|
-#define TK_RETURN 0x28
|
79
|
|
-#define TK_ENTER 0x28
|
80
|
|
-#define TK_ESCAPE 0x29
|
81
|
|
-#define TK_BACKSPACE 0x2A
|
82
|
|
-#define TK_TAB 0x2B
|
83
|
|
-#define TK_SPACE 0x2C
|
84
|
|
-#define TK_MINUS 0x2D /* - */
|
85
|
|
-#define TK_EQUALS 0x2E /* = */
|
86
|
|
-#define TK_LBRACKET 0x2F /* [ */
|
87
|
|
-#define TK_RBRACKET 0x30 /* ] */
|
88
|
|
-#define TK_BACKSLASH 0x31 /* \ */
|
89
|
|
-#define TK_SEMICOLON 0x33 /* ; */
|
90
|
|
-#define TK_APOSTROPHE 0x34 /* ' */
|
91
|
|
-#define TK_GRAVE 0x35 /* ` */
|
92
|
|
-#define TK_COMMA 0x36 /* , */
|
93
|
|
-#define TK_PERIOD 0x37 /* . */
|
94
|
|
-#define TK_SLASH 0x38 /* / */
|
95
|
|
-#define TK_F1 0x3A
|
96
|
|
-#define TK_F2 0x3B
|
97
|
|
-#define TK_F3 0x3C
|
98
|
|
-#define TK_F4 0x3D
|
99
|
|
-#define TK_F5 0x3E
|
100
|
|
-#define TK_F6 0x3F
|
101
|
|
-#define TK_F7 0x40
|
102
|
|
-#define TK_F8 0x41
|
103
|
|
-#define TK_F9 0x42
|
104
|
|
-#define TK_F10 0x43
|
105
|
|
-#define TK_F11 0x44
|
106
|
|
-#define TK_F12 0x45
|
107
|
|
-#define TK_PAUSE 0x48 /* Pause/Break */
|
108
|
|
-#define TK_INSERT 0x49
|
109
|
|
-#define TK_HOME 0x4A
|
110
|
|
-#define TK_PAGEUP 0x4B
|
111
|
|
-#define TK_DELETE 0x4C
|
112
|
|
-#define TK_END 0x4D
|
113
|
|
-#define TK_PAGEDOWN 0x4E
|
114
|
|
-#define TK_RIGHT 0x4F /* Right arrow */
|
115
|
|
-#define TK_LEFT 0x50 /* Left arrow */
|
116
|
|
-#define TK_DOWN 0x51 /* Down arrow */
|
117
|
|
-#define TK_UP 0x52 /* Up arrow */
|
118
|
|
-#define TK_KP_DIVIDE 0x54 /* '/' on numpad */
|
119
|
|
-#define TK_KP_MULTIPLY 0x55 /* '*' on numpad */
|
120
|
|
-#define TK_KP_MINUS 0x56 /* '-' on numpad */
|
121
|
|
-#define TK_KP_PLUS 0x57 /* '+' on numpad */
|
122
|
|
-#define TK_KP_ENTER 0x58
|
123
|
|
-#define TK_KP_1 0x59
|
124
|
|
-#define TK_KP_2 0x5A
|
125
|
|
-#define TK_KP_3 0x5B
|
126
|
|
-#define TK_KP_4 0x5C
|
127
|
|
-#define TK_KP_5 0x5D
|
128
|
|
-#define TK_KP_6 0x5E
|
129
|
|
-#define TK_KP_7 0x5F
|
130
|
|
-#define TK_KP_8 0x60
|
131
|
|
-#define TK_KP_9 0x61
|
132
|
|
-#define TK_KP_0 0x62
|
133
|
|
-#define TK_KP_PERIOD 0x63 /* '.' on numpad */
|
134
|
|
-#define TK_SHIFT 0x70
|
135
|
|
-#define TK_CONTROL 0x71
|
136
|
|
-
|
137
|
|
-/*
|
138
|
|
- * Mouse events/states
|
139
|
|
- */
|
140
|
|
-#define TK_MOUSE_LEFT 0x80 /* Buttons */
|
141
|
|
-#define TK_MOUSE_RIGHT 0x81
|
142
|
|
-#define TK_MOUSE_MIDDLE 0x82
|
143
|
|
-#define TK_MOUSE_X1 0x83
|
144
|
|
-#define TK_MOUSE_X2 0x84
|
145
|
|
-#define TK_MOUSE_MOVE 0x85 /* Movement event */
|
146
|
|
-#define TK_MOUSE_SCROLL 0x86 /* Mouse scroll event */
|
147
|
|
-#define TK_MOUSE_X 0x87 /* Cusor position in cells */
|
148
|
|
-#define TK_MOUSE_Y 0x88
|
149
|
|
-#define TK_MOUSE_PIXEL_X 0x89 /* Cursor position in pixels */
|
150
|
|
-#define TK_MOUSE_PIXEL_Y 0x8A
|
151
|
|
-#define TK_MOUSE_WHEEL 0x8B /* Scroll direction and amount */
|
152
|
|
-#define TK_MOUSE_CLICKS 0x8C /* Number of consecutive clicks */
|
153
|
|
-
|
154
|
|
-/*
|
155
|
|
- * If key was released instead of pressed, it's code will be OR'ed with TK_KEY_RELEASED:
|
156
|
|
- * a) pressed 'A': 0x04
|
157
|
|
- * b) released 'A': 0x04|VK_KEY_RELEASED = 0x104
|
158
|
|
- */
|
159
|
|
-#define TK_KEY_RELEASED 0x100
|
160
|
|
-
|
161
|
|
-/*
|
162
|
|
- * Virtual key-codes for internal terminal states/variables.
|
163
|
|
- * These can be accessed via terminal_state function.
|
164
|
|
- */
|
165
|
|
-#define TK_WIDTH 0xC0 /* Terminal window size in cells */
|
166
|
|
-#define TK_HEIGHT 0xC1
|
167
|
|
-#define TK_CELL_WIDTH 0xC2 /* Character cell size in pixels */
|
168
|
|
-#define TK_CELL_HEIGHT 0xC3
|
169
|
|
-#define TK_COLOR 0xC4 /* Current foregroung color */
|
170
|
|
-#define TK_BKCOLOR 0xC5 /* Current background color */
|
171
|
|
-#define TK_LAYER 0xC6 /* Current layer */
|
172
|
|
-#define TK_COMPOSITION 0xC7 /* Current composition state */
|
173
|
|
-#define TK_CHAR 0xC8 /* Translated ANSI code of last produced character */
|
174
|
|
-#define TK_WCHAR 0xC9 /* Unicode codepoint of last produced character */
|
175
|
|
-#define TK_EVENT 0xCA /* Last dequeued event */
|
176
|
|
-#define TK_FULLSCREEN 0xCB /* Fullscreen state */
|
177
|
|
-
|
178
|
|
-/*
|
179
|
|
- * Other events
|
180
|
|
- */
|
181
|
|
-#define TK_CLOSE 0xE0
|
182
|
|
-#define TK_RESIZED 0xE1
|
183
|
|
-
|
184
|
|
-/*
|
185
|
|
- * Generic mode enum.
|
186
|
|
- * Right now it is used for composition option only.
|
187
|
|
- */
|
188
|
|
-#define TK_OFF 0
|
189
|
|
-#define TK_ON 1
|
190
|
|
-
|
191
|
|
-/*
|
192
|
|
- * Input result codes for terminal_read function.
|
193
|
|
- */
|
194
|
|
-#define TK_INPUT_NONE 0
|
195
|
|
-#define TK_INPUT_CANCELLED -1
|
196
|
|
-
|
197
|
|
-/*
|
198
|
|
- * Terminal uses unsigned 32-bit value for color representation in ARGB order (0xAARRGGBB), e. g.
|
199
|
|
- * a) solid red is 0xFFFF0000
|
200
|
|
- * b) half-transparent green is 0x8000FF00
|
201
|
|
- */
|
202
|
|
-typedef uint32_t color_t;
|
203
|
|
-
|
204
|
|
-#if defined(BEARLIBTERMINAL_STATIC_BUILD)
|
205
|
|
-# define TERMINAL_API
|
206
|
|
-#elif defined(_WIN32)
|
207
|
|
-# if defined(BEARLIBTERMINAL_BUILDING_LIBRARY)
|
208
|
|
-# define TERMINAL_API __declspec(dllexport)
|
209
|
|
-# else
|
210
|
|
-# define TERMINAL_API __declspec(dllimport)
|
211
|
|
-# endif
|
212
|
|
-#else
|
213
|
|
-# if defined(BEARLIBTERMINAL_BUILDING_LIBRARY) && __GNUC__ >= 4
|
214
|
|
-# define TERMINAL_API __attribute__ ((visibility ("default")))
|
215
|
|
-# else
|
216
|
|
-# define TERMINAL_API
|
217
|
|
-# endif
|
218
|
|
-#endif
|
219
|
|
-
|
220
|
|
-#ifdef __cplusplus
|
221
|
|
-extern "C" {
|
222
|
|
-#endif
|
223
|
|
-
|
224
|
|
-TERMINAL_API int terminal_open();
|
225
|
|
-TERMINAL_API void terminal_close();
|
226
|
|
-TERMINAL_API int terminal_set8(const int8_t* value);
|
227
|
|
-TERMINAL_API int terminal_set16(const int16_t* value);
|
228
|
|
-TERMINAL_API int terminal_set32(const int32_t* value);
|
229
|
|
-TERMINAL_API void terminal_refresh();
|
230
|
|
-TERMINAL_API void terminal_clear();
|
231
|
|
-TERMINAL_API void terminal_clear_area(int x, int y, int w, int h);
|
232
|
|
-TERMINAL_API void terminal_crop(int x, int y, int w, int h);
|
233
|
|
-TERMINAL_API void terminal_layer(int index);
|
234
|
|
-TERMINAL_API void terminal_color(color_t color);
|
235
|
|
-TERMINAL_API void terminal_bkcolor(color_t color);
|
236
|
|
-TERMINAL_API void terminal_composition(int mode);
|
237
|
|
-TERMINAL_API void terminal_put(int x, int y, int code);
|
238
|
|
-TERMINAL_API void terminal_put_ext(int x, int y, int dx, int dy, int code, color_t* corners);
|
239
|
|
-TERMINAL_API int terminal_pick(int x, int y, int index);
|
240
|
|
-TERMINAL_API color_t terminal_pick_color(int x, int y, int index);
|
241
|
|
-TERMINAL_API color_t terminal_pick_bkcolor(int x, int y);
|
242
|
|
-TERMINAL_API int terminal_print8(int x, int y, const int8_t* s);
|
243
|
|
-TERMINAL_API int terminal_print16(int x, int y, const int16_t* s);
|
244
|
|
-TERMINAL_API int terminal_print32(int x, int y, const int32_t* s);
|
245
|
|
-TERMINAL_API int terminal_measure8(const int8_t* s);
|
246
|
|
-TERMINAL_API int terminal_measure16(const int16_t* s);
|
247
|
|
-TERMINAL_API int terminal_measure32(const int32_t* s);
|
248
|
|
-TERMINAL_API int terminal_has_input();
|
249
|
|
-TERMINAL_API int terminal_state(int code);
|
250
|
|
-TERMINAL_API int terminal_read();
|
251
|
|
-TERMINAL_API int terminal_read_str8(int x, int y, int8_t* buffer, int max);
|
252
|
|
-TERMINAL_API int terminal_read_str16(int x, int y, int16_t* buffer, int max);
|
253
|
|
-TERMINAL_API int terminal_read_str32(int x, int y, int32_t* buffer, int max);
|
254
|
|
-TERMINAL_API int terminal_peek();
|
255
|
|
-TERMINAL_API void terminal_delay(int period);
|
256
|
|
-TERMINAL_API const int8_t* terminal_get8(const int8_t* key, const int8_t* default_);
|
257
|
|
-TERMINAL_API const int16_t* terminal_get16(const int16_t* key, const int16_t* default_);
|
258
|
|
-TERMINAL_API const int32_t* terminal_get32(const int32_t* key, const int32_t* default_);
|
259
|
|
-TERMINAL_API color_t color_from_name8(const int8_t* name);
|
260
|
|
-TERMINAL_API color_t color_from_name16(const int16_t* name);
|
261
|
|
-TERMINAL_API color_t color_from_name32(const int32_t* name);
|
262
|
|
-
|
263
|
|
-#ifdef __cplusplus
|
264
|
|
-} /* End of extern "C" */
|
265
|
|
-#endif
|
266
|
|
-
|
267
|
|
-/*
|
268
|
|
- * Utility macro trick which allows macro-in-macro expansion
|
269
|
|
- */
|
270
|
|
-#define TERMINAL_CAT(a, b) TERMINAL_PRIMITIVE_CAT(a, b)
|
271
|
|
-#define TERMINAL_PRIMITIVE_CAT(a, b) a ## b
|
272
|
|
-
|
273
|
|
-/*
|
274
|
|
- * wchar_t has different sized depending on platform. Furthermore, it's size
|
275
|
|
- * can be changed for GCC compiler.
|
276
|
|
- */
|
277
|
|
-#if !defined(__SIZEOF_WCHAR_T__)
|
278
|
|
-# if defined(_WIN32)
|
279
|
|
-# define __SIZEOF_WCHAR_T__ 2
|
280
|
|
-# else
|
281
|
|
-# define __SIZEOF_WCHAR_T__ 4
|
282
|
|
-# endif
|
283
|
|
-#endif
|
284
|
|
-
|
285
|
|
-#if __SIZEOF_WCHAR_T__ == 2
|
286
|
|
-#define TERMINAL_WCHAR_SUFFIX 16
|
287
|
|
-#define TERMINAL_WCHAR_TYPE int16_t
|
288
|
|
-#else // 4
|
289
|
|
-#define TERMINAL_WCHAR_SUFFIX 32
|
290
|
|
-#define TERMINAL_WCHAR_TYPE int32_t
|
291
|
|
-#endif
|
292
|
|
-
|
293
|
|
-/*
|
294
|
|
- * This set of inline functions define basic name substitution + type cast:
|
295
|
|
- * terminal_[w]xxxx -> terminal_xxxx{8|16|32}
|
296
|
|
- */
|
297
|
|
-
|
298
|
|
-#if defined(__cplusplus)
|
299
|
|
-#define TERMINAL_INLINE inline
|
300
|
|
-#define TERMINAL_DEFAULT(value) = value
|
301
|
|
-#else
|
302
|
|
-#define TERMINAL_INLINE static inline
|
303
|
|
-#define TERMINAL_DEFAULT(value)
|
304
|
|
-#endif
|
305
|
|
-
|
306
|
|
-TERMINAL_INLINE int terminal_set(const char* value)
|
307
|
|
-{
|
308
|
|
- return terminal_set8((const int8_t*)value);
|
309
|
|
-}
|
310
|
|
-
|
311
|
|
-TERMINAL_INLINE int terminal_wset(const wchar_t* value)
|
312
|
|
-{
|
313
|
|
- return TERMINAL_CAT(terminal_set, TERMINAL_WCHAR_SUFFIX)((const TERMINAL_WCHAR_TYPE*)value);
|
314
|
|
-}
|
315
|
|
-
|
316
|
|
-TERMINAL_INLINE int terminal_print(int x, int y, const char* s)
|
317
|
|
-{
|
318
|
|
- return terminal_print8(x, y, (const int8_t*)s);
|
319
|
|
-}
|
320
|
|
-
|
321
|
|
-TERMINAL_INLINE int terminal_wprint(int x, int y, const wchar_t* s)
|
322
|
|
-{
|
323
|
|
- return TERMINAL_CAT(terminal_print, TERMINAL_WCHAR_SUFFIX)(x, y, (const TERMINAL_WCHAR_TYPE*)s);
|
324
|
|
-}
|
325
|
|
-
|
326
|
|
-TERMINAL_INLINE int terminal_measure(const char* s)
|
327
|
|
-{
|
328
|
|
- return terminal_measure8((const int8_t*)s);
|
329
|
|
-}
|
330
|
|
-
|
331
|
|
-TERMINAL_INLINE int terminal_wmeasure(const wchar_t* s)
|
332
|
|
-{
|
333
|
|
- return TERMINAL_CAT(terminal_measure, TERMINAL_WCHAR_SUFFIX)((const TERMINAL_WCHAR_TYPE*)s);
|
334
|
|
-}
|
335
|
|
-
|
336
|
|
-TERMINAL_INLINE int terminal_read_str(int x, int y, char* buffer, int max)
|
337
|
|
-{
|
338
|
|
- return terminal_read_str8(x, y, (int8_t*)buffer, max);
|
339
|
|
-}
|
340
|
|
-
|
341
|
|
-TERMINAL_INLINE int terminal_read_wstr(int x, int y, wchar_t* buffer, int max)
|
342
|
|
-{
|
343
|
|
- return TERMINAL_CAT(terminal_read_str, TERMINAL_WCHAR_SUFFIX)(x, y, (TERMINAL_WCHAR_TYPE*)buffer, max);
|
344
|
|
-}
|
345
|
|
-
|
346
|
|
-TERMINAL_INLINE const char* terminal_get(const char* key, const char* default_ TERMINAL_DEFAULT((const char*)0))
|
347
|
|
-{
|
348
|
|
- return (const char*)terminal_get8((const int8_t*)key, (const int8_t*)default_);
|
349
|
|
-}
|
350
|
|
-
|
351
|
|
-TERMINAL_INLINE const wchar_t* terminal_wget(const wchar_t* key, const wchar_t* default_ TERMINAL_DEFAULT((const wchar_t*)0))
|
352
|
|
-{
|
353
|
|
- return (const wchar_t*)TERMINAL_CAT(terminal_get, TERMINAL_WCHAR_SUFFIX)((const TERMINAL_WCHAR_TYPE*)key, (const TERMINAL_WCHAR_TYPE*)default_);
|
354
|
|
-}
|
355
|
|
-
|
356
|
|
-TERMINAL_INLINE color_t color_from_name(const char* name)
|
357
|
|
-{
|
358
|
|
- return color_from_name8((const int8_t*)name);
|
359
|
|
-}
|
360
|
|
-
|
361
|
|
-TERMINAL_INLINE color_t color_from_wname(const wchar_t* name)
|
362
|
|
-{
|
363
|
|
- return TERMINAL_CAT(color_from_name, TERMINAL_WCHAR_SUFFIX)((const TERMINAL_WCHAR_TYPE*)name);
|
364
|
|
-}
|
365
|
|
-
|
366
|
|
-/*
|
367
|
|
- * These inline functions provide formatted versions for textual API:
|
368
|
|
- * terminal_[w]setf and terminal_[w]printf
|
369
|
|
- *
|
370
|
|
- * Using static termporary buffer is okay because terminal API is not
|
371
|
|
- * required to be multiple-thread safe by design.
|
372
|
|
- */
|
373
|
|
-
|
374
|
|
-#if !defined(TERMINAL_FORMAT_BUFFER_SIZE)
|
375
|
|
-#define TERMINAL_FORMAT_BUFFER_SIZE 1024
|
376
|
|
-#endif
|
377
|
|
-
|
378
|
|
-#define TERMINAL_FORMATTED_VA(type, name, sign, func, call_sign)\
|
379
|
|
- TERMINAL_INLINE int terminal_v##name##f sign\
|
380
|
|
- {\
|
381
|
|
- static type buffer[TERMINAL_FORMAT_BUFFER_SIZE] = {0};\
|
382
|
|
- int rc = 0;\
|
383
|
|
- if (s == NULL) return 0;\
|
384
|
|
- rc = func(buffer, TERMINAL_FORMAT_BUFFER_SIZE-1, s, args);\
|
385
|
|
- if (rc > 0) rc = terminal_##name call_sign;\
|
386
|
|
- return rc;\
|
387
|
|
- }
|
388
|
|
-
|
389
|
|
-#if defined(_WIN32)
|
390
|
|
-#define TERMINAL_VSNWPRINTF _vsnwprintf
|
391
|
|
-#else
|
392
|
|
-#define TERMINAL_VSNWPRINTF vswprintf
|
393
|
|
-#endif
|
394
|
|
-
|
395
|
|
-TERMINAL_FORMATTED_VA(char, set, (const char* s, va_list args), vsnprintf, (buffer))
|
396
|
|
-TERMINAL_FORMATTED_VA(wchar_t, wset, (const wchar_t* s, va_list args), TERMINAL_VSNWPRINTF, (buffer))
|
397
|
|
-TERMINAL_FORMATTED_VA(char, print, (int x, int y, const char* s, va_list args), vsnprintf, (x, y, buffer))
|
398
|
|
-TERMINAL_FORMATTED_VA(wchar_t, wprint, (int x, int y, const wchar_t* s, va_list args), TERMINAL_VSNWPRINTF, (x, y, buffer))
|
399
|
|
-TERMINAL_FORMATTED_VA(char, measure, (const char* s, va_list args), vsnprintf, (buffer))
|
400
|
|
-TERMINAL_FORMATTED_VA(wchar_t, wmeasure, (const wchar_t* s, va_list args), TERMINAL_VSNWPRINTF, (buffer))
|
401
|
|
-
|
402
|
|
-#define TERMINAL_FORMATTED(outer, inner)\
|
403
|
|
- TERMINAL_INLINE int terminal_##outer\
|
404
|
|
- {\
|
405
|
|
- va_list args;\
|
406
|
|
- int rc = 0;\
|
407
|
|
- va_start(args, s);\
|
408
|
|
- rc = terminal_v##inner;\
|
409
|
|
- va_end(args);\
|
410
|
|
- return rc;\
|
411
|
|
- }
|
412
|
|
-
|
413
|
|
-TERMINAL_FORMATTED(setf(const char* s, ...), setf(s, args))
|
414
|
|
-TERMINAL_FORMATTED(wsetf(const wchar_t* s, ...), wsetf(s, args))
|
415
|
|
-TERMINAL_FORMATTED(printf(int x, int y, const char* s, ...), printf(x, y, s, args))
|
416
|
|
-TERMINAL_FORMATTED(wprintf(int x, int y, const wchar_t* s, ...), wprintf(x, y, s, args))
|
417
|
|
-TERMINAL_FORMATTED(measuref(const char* s, ...), measuref(s, args))
|
418
|
|
-TERMINAL_FORMATTED(wmeasuref(const wchar_t* s, ...), wmeasuref(s, args))
|
419
|
|
-
|
420
|
|
-#ifdef __cplusplus
|
421
|
|
-/*
|
422
|
|
- * C++ supports function overloading, should take advantage of it.
|
423
|
|
- */
|
424
|
|
-
|
425
|
|
-TERMINAL_INLINE int terminal_set(const wchar_t* s)
|
426
|
|
-{
|
427
|
|
- return terminal_wset(s);
|
428
|
|
-}
|
429
|
|
-
|
430
|
|
-TERMINAL_FORMATTED(setf(const wchar_t* s, ...), wsetf(s, args))
|
431
|
|
-
|
432
|
|
-TERMINAL_INLINE void terminal_color(const char* name)
|
433
|
|
-{
|
434
|
|
- terminal_color(color_from_name(name));
|
435
|
|
-}
|
436
|
|
-
|
437
|
|
-TERMINAL_INLINE void terminal_color(const wchar_t* name)
|
438
|
|
-{
|
439
|
|
- terminal_color(color_from_wname(name));
|
440
|
|
-}
|
441
|
|
-
|
442
|
|
-TERMINAL_INLINE void terminal_bkcolor(const char* name)
|
443
|
|
-{
|
444
|
|
- terminal_bkcolor(color_from_name(name));
|
445
|
|
-}
|
446
|
|
-
|
447
|
|
-TERMINAL_INLINE void terminal_bkcolor(const wchar_t* name)
|
448
|
|
-{
|
449
|
|
- terminal_bkcolor(color_from_wname(name));
|
450
|
|
-}
|
451
|
|
-
|
452
|
|
-TERMINAL_INLINE void terminal_put_ext(int x, int y, int dx, int dy, int code)
|
453
|
|
-{
|
454
|
|
- terminal_put_ext(x, y, dx, dy, code, 0);
|
455
|
|
-}
|
456
|
|
-
|
457
|
|
-TERMINAL_INLINE int terminal_print(int x, int y, const wchar_t* s)
|
458
|
|
-{
|
459
|
|
- return terminal_wprint(x, y, s);
|
460
|
|
-}
|
461
|
|
-
|
462
|
|
-TERMINAL_FORMATTED(printf(int x, int y, const wchar_t* s, ...), wprintf(x, y, s, args))
|
463
|
|
-
|
464
|
|
-TERMINAL_INLINE int terminal_measure(const wchar_t* s)
|
465
|
|
-{
|
466
|
|
- return terminal_wmeasure(s);
|
467
|
|
-}
|
468
|
|
-
|
469
|
|
-TERMINAL_FORMATTED(measuref(const wchar_t* s, ...), wmeasuref(s, args))
|
470
|
|
-
|
471
|
|
-TERMINAL_INLINE int terminal_read_str(int x, int y, wchar_t* buffer, int max)
|
472
|
|
-{
|
473
|
|
- return terminal_read_wstr(x, y, buffer, max);
|
474
|
|
-}
|
475
|
|
-
|
476
|
|
-TERMINAL_INLINE color_t color_from_name(const wchar_t* name)
|
477
|
|
-{
|
478
|
|
- return color_from_wname(name);
|
479
|
|
-}
|
480
|
|
-
|
481
|
|
-TERMINAL_INLINE int terminal_pick(int x, int y)
|
482
|
|
-{
|
483
|
|
- return terminal_pick(x, y, 0);
|
484
|
|
-}
|
485
|
|
-
|
486
|
|
-TERMINAL_INLINE color_t terminal_pick_color(int x, int y)
|
487
|
|
-{
|
488
|
|
- return terminal_pick_color(x, y, 0);
|
489
|
|
-}
|
490
|
|
-
|
491
|
|
-TERMINAL_INLINE const wchar_t* terminal_get(const wchar_t* key, const wchar_t* default_ = (const wchar_t*)0)
|
492
|
|
-{
|
493
|
|
- return terminal_wget(key, default_);
|
494
|
|
-}
|
495
|
|
-
|
496
|
|
-template<typename T, typename C> T terminal_get(const C* key, const T& default_ = T())
|
497
|
|
-{
|
498
|
|
- const C* result_str = terminal_get(key, (const C*)0);
|
499
|
|
- if (result_str[0] == C(0))
|
500
|
|
- return default_;
|
501
|
|
- T result;
|
502
|
|
- return (bool)(std::basic_istringstream<C>(result_str) >> result)? result: default_;
|
503
|
|
-}
|
504
|
|
-
|
505
|
|
-#endif /* __cplusplus */
|
506
|
|
-
|
507
|
|
-/*
|
508
|
|
- * Color routines
|
509
|
|
- */
|
510
|
|
-TERMINAL_INLINE color_t color_from_argb(uint8_t a, uint8_t r, uint8_t g, uint8_t b)
|
511
|
|
-{
|
512
|
|
- return ((color_t)a << 24) | (r << 16) | (g << 8) | b;
|
513
|
|
-}
|
514
|
|
-
|
515
|
|
-/*
|
516
|
|
- * Other functional sugar
|
517
|
|
- */
|
518
|
|
-TERMINAL_INLINE int terminal_check(int code)
|
519
|
|
-{
|
520
|
|
- return terminal_state(code) > 0;
|
521
|
|
-}
|
522
|
|
-
|
523
|
|
-/*
|
524
|
|
- * WinMain entry point handling macro. This allows easier entry point definition.
|
525
|
|
- * The macro will expand to proper WinMain stub regardless of header include order.
|
526
|
|
- */
|
527
|
|
-#if defined(_WIN32)
|
528
|
|
-
|
529
|
|
-/*
|
530
|
|
- * WinMain probe macro. It will expand to either X or X_WINDOWS_ depending on
|
531
|
|
- * Windows.h header inclusion.
|
532
|
|
- */
|
533
|
|
-#define TERMINAL_TAKE_CARE_OF_WINMAIN TERMINAL_WINMAIN_PROBE_IMPL(_WINDOWS_)
|
534
|
|
-#define TERMINAL_WINMAIN_PROBE_IMPL(DEF) TERMINAL_PRIMITIVE_CAT(TERMINAL_WINMAIN_IMPL, DEF)
|
535
|
|
-
|
536
|
|
-/*
|
537
|
|
- * Trivial no-arguments WinMain implementation. It just calls main.
|
538
|
|
- */
|
539
|
|
-#define TERMINAL_WINMAIN_IMPL_BASE(INSTANCE_T, STRING_T)\
|
540
|
|
- extern "C" int main();\
|
541
|
|
- extern "C" int __stdcall WinMain(INSTANCE_T hInstance, INSTANCE_T hPrevInstance, STRING_T lpCmdLine, int nCmdShow)\
|
542
|
|
- {\
|
543
|
|
- return main();\
|
544
|
|
- }
|
545
|
|
-
|
546
|
|
-/*
|
547
|
|
- * Macro expands to empty string. Windows.h is included thus code MUST use
|
548
|
|
- * predefined types or else MSVC will complain.
|
549
|
|
- */
|
550
|
|
-#define TERMINAL_WINMAIN_IMPL TERMINAL_WINMAIN_IMPL_BASE(HINSTANCE, LPSTR)
|
551
|
|
-
|
552
|
|
-/*
|
553
|
|
- * Macro expands to macro name. Windows.h wasn't included, so WinMain will be
|
554
|
|
- * defined with fundamental types (enough for linker to find it).
|
555
|
|
- */
|
556
|
|
-#define TERMINAL_WINMAIN_IMPL_WINDOWS_ TERMINAL_WINMAIN_IMPL_BASE(void*, char*)
|
557
|
|
-
|
558
|
|
-#else
|
559
|
|
-
|
560
|
|
-/*
|
561
|
|
- * Only Windows has WinMain but macro still must be defined for cross-platform
|
562
|
|
- * applications.
|
563
|
|
- */
|
564
|
|
-#define TERMINAL_TAKE_CARE_OF_WINMAIN
|
565
|
|
-
|
566
|
|
-#endif
|
567
|
|
-
|
568
|
|
-#endif // BEARLIBTERMINAL_H
|