dsekai
World engine for retrocomputers.
All Data Structures Files Functions Variables Typedefs Friends Macros Modules Pages
window.h
Go to the documentation of this file.
1
2#ifndef WINDOW_H
3#define WINDOW_H
4
24 int32_t scalar;
25 MEMORY_HANDLE string;
26 int16_t grid[4];
27};
28
35 uint16_t tr;
37 uint16_t tl;
39 uint16_t br;
41 uint16_t bl;
43 uint16_t t;
45 uint16_t b;
47 uint16_t r;
49 uint16_t l;
51 uint16_t c;
52};
53
55struct WINDOW {
57 uint16_t id;
59 uint16_t parent_id;
61 uint8_t type;
63 uint8_t flags;
68 uint8_t render_flags;
86 uint16_t coords[4];
89};
90
94#define GUI_X 0
98#define GUI_Y 1
102#define GUI_W 2
106#define GUI_H 3
107
112#define WINDOW_NUM_BUFFER_SZ 10
113
127#define WINDOW_FLAG_ACTIVE 0x01
128#define WINDOW_FLAG_DIRTY 0x04
132#define WINDOW_FLAG_MODAL 0x08
136#define WINDOW_FLAG_CHECKED 0x10
137
141#define WINDOW_FLAG_TEXT_NUM 0x10
142
143#define WINDOW_FLAG_TEXT_PTR 0x20
144
145#define WINDOW_FLAG_TEXT_MASK 0x30
146
147#define WINDOW_FLAG_SPRITE_DIR_MASK 0x30
148
149#define WINDOW_FLAG_SPRITE_SOUTH 0x00
150#define WINDOW_FLAG_SPRITE_NORTH 0x10
151#define WINDOW_FLAG_SPRITE_EAST 0x20
152#define WINDOW_FLAG_SPRITE_WEST 0x30
153
154#define WINDOW_FLAG_SPRITE_BORDER_SINGLE 0x40
155 /* unilayer_gui_windows_flags */
157
158#define WINDOW_STRING_SZ_MAX 100
159
170#define WINDOW_PLACEMENT_CENTER 0x8000
171
175#define WINDOW_PLACEMENT_RIGHT_BOTTOM 0x2000
176
181#define WINDOW_PLACEMENT_GRID_RIGHT_DOWN 0xc000
182
186#define WINDOW_PLACEMENT_GRID 0x4000
187
192#define WINDOW_PLACEMENT_AUTO_MASK 0xe000
193
199#define WINDOW_PLACEMENT_PHYS_MASK 0x1fff
200
201#define WINDOW_SIZE_AUTO 0x8000
202
207#define WINDOW_SIZE_AUTO_MASK (WINDOW_PLACEMENT_AUTO_MASK)
208
214#define WINDOW_SIZE_PHYS_MASK (WINDOW_PLACEMENT_PHYS_MASK)
215
216#define window_screen_reset_grid() memory_zero_ptr( g_window_screen_grid, 4 * sizeof( int16_t ) );
217
223#define window_update_coords( window, x_y_w_h, coord ) (window)->coords[x_y_w_h] = ((window)->coords[x_y_w_h] & WINDOW_PLACEMENT_AUTO_MASK) | (WINDOW_PLACEMENT_PHYS_MASK & (coord));
224
229#define window_get_coords( window, x_y_w_h ) (((window)->coords[x_y_w_h] & WINDOW_PLACEMENT_PHYS_MASK))
230 /* unilayer_gui_windows_placement */
232
233#ifdef WINDOW_TRACE
234# define window_trace_printf( lvl, ... ) debug_printf( lvl, __VA_ARGS__ )
235#else
242# define window_trace_printf( ... )
243#endif /* WINDOW_TRACE */
244
245#ifdef DEPTH_VGA
246# define WINDOW_PREFAB_DEFAULT_FG() GRAPHICS_COLOR_WHITE
247# define WINDOW_PREFAB_DEFAULT_BG() GRAPHICS_COLOR_MAGENTA
248# define WINDOW_PREFAB_DEFAULT_HL() GRAPHICS_COLOR_CYAN
249#elif defined( DEPTH_CGA )
250# define WINDOW_PREFAB_DEFAULT_FG() GRAPHICS_COLOR_BLACK
251# define WINDOW_PREFAB_DEFAULT_BG() GRAPHICS_COLOR_MAGENTA
252# define WINDOW_PREFAB_DEFAULT_HL() GRAPHICS_COLOR_CYAN
253#elif defined( DEPTH_MONO )
254 /* TODO: Verify this looks OK. */
255# define WINDOW_PREFAB_DEFAULT_FG() GRAPHICS_COLOR_WHITE
256# define WINDOW_PREFAB_DEFAULT_BG() GRAPHICS_COLOR_BLACK
257# define WINDOW_PREFAB_DEFAULT_HL() GRAPHICS_COLOR_WHITE
258#endif /* DEPTH */
259
267 uint16_t auto_x, uint16_t auto_y, uint16_t auto_w, uint16_t auto_h
268) SECTION_WINDOW;
269
270int16_t window_reload_frames() SECTION_WINDOW;
271
275void window_shutdown() SECTION_WINDOW;
276
277int16_t window_draw_all();
278
291 uint16_t id, uint16_t parent_id, uint8_t type, uint8_t flags,
292 uint16_t x, uint16_t y, uint16_t w, uint16_t h,
293 GRAPHICS_COLOR fg, GRAPHICS_COLOR bg, uint8_t render_flags,
294 int32_t data_scalar, const char* data_string ) SECTION_WINDOW;
295
301void window_pop( uint16_t id ) SECTION_WINDOW;
302
303void window_refresh( uint16_t w_id ) SECTION_WINDOW;
304
305#if 0
311int16_t window_modal();
312#endif
313
314#define window_modal() (g_window_modals)
315
328#define WINDOW_CB_TABLE_4( f ) f( 4, WINDOW )
329
333#define WINDOW_CB_TABLE_3( f ) f( 3, SPRITE ) WINDOW_CB_TABLE_4( f )
334
340#define WINDOW_CB_TABLE_2( f ) f( 2, CHECK ) WINDOW_CB_TABLE_3( f )
341
347#define WINDOW_CB_TABLE_1( f ) f( 1, BUTTON ) WINDOW_CB_TABLE_2( f )
348
355#define WINDOW_CB_TABLE( f ) f( 0, LABEL ) WINDOW_CB_TABLE_1( f )
356 /* unilayer_gui_windows_types */
358
359typedef int16_t (*WINDOW_CB_DRAW)( uint16_t w_id, struct WINDOW* windows );
360
364typedef uint8_t (*WINDOW_CB_SZ)(
365 uint16_t w_id, struct WINDOW* windows, uint8_t w_h, uint16_t* out );
366
367#ifdef WINDOW_C
368
369static MEMORY_HANDLE g_frames_handle = (MEMORY_HANDLE)NULL;
370static MEMORY_HANDLE g_windows_handle = (MEMORY_HANDLE)NULL;
371
372uint8_t g_window_modals = 0;
373
374static uint16_t g_window_screen_coords[4] = {
375 0, 0, SCREEN_W, SCREEN_H
376};
377
378static int16_t g_window_screen_grid[4] = {
379 0, 0, 0, 0
380};
381
382# define WINDOW_CB_DRAW_TABLE_PROTOTYPES( idx, name ) int16_t window_draw_ ## name( uint16_t w_id, struct WINDOW* windows );
383
384WINDOW_CB_TABLE( WINDOW_CB_DRAW_TABLE_PROTOTYPES );
385
386# define WINDOW_CB_SZ_TABLE_PROTOTYPES( idx, name ) uint8_t window_sz_ ## name( uint16_t w_id, struct WINDOW* windows, uint8_t w_h, uint16_t* out ) SECTION_WINDOW;
387
388WINDOW_CB_TABLE( WINDOW_CB_SZ_TABLE_PROTOTYPES );
389
390# define WINDOW_CB_DRAW_TABLE_LIST( idx, name ) window_draw_ ## name,
391
392static const WINDOW_CB_DRAW gc_window_draw_callbacks[] = {
393 WINDOW_CB_TABLE( WINDOW_CB_DRAW_TABLE_LIST )
394};
395
396# define WINDOW_CB_SZ_TABLE_LIST( idx, name ) window_sz_ ## name,
397
398static const WINDOW_CB_SZ gc_window_sz_callbacks[] = {
399 WINDOW_CB_TABLE( WINDOW_CB_SZ_TABLE_LIST )
400};
401
402# define WINDOW_CB_TABLE_CONSTS( idx, name ) RES_CONST uint16_t WINDOW_TYPE_ ## name = idx;
403
405
406#else
407
408extern uint8_t g_window_modals;
409
413# define WINDOW_CB_TABLE_CONSTS( idx, name ) extern RES_CONST uint16_t WINDOW_TYPE_ ## name;
414
416
417#endif /* WINDOW_C */
418
421#endif /* WINDOW_H */
422
int GRAPHICS_COLOR
Representation for specific colors on the current platform.
Definition: nullg.h:16
#define WINDOW_CB_TABLE(f)
WINDOW_TYPE_LABEL: A static text label.
Definition: window.h:355
#define WINDOW_CB_TABLE_CONSTS(idx, name)
Define extern constants that can be used e.g. in spawners.
Definition: window.h:413
int16_t window_push(uint16_t id, uint16_t parent_id, uint8_t type, uint8_t flags, uint16_t x, uint16_t y, uint16_t w, uint16_t h, GRAPHICS_COLOR fg, GRAPHICS_COLOR bg, uint8_t render_flags, int32_t data_scalar, const char *data_string) SECTION_WINDOW
Push a new window onto the global window stack.
void window_shutdown() SECTION_WINDOW
Global shutdown for the window subsystem. Runs at shutdown.
void window_pop(uint16_t id) SECTION_WINDOW
Destroy the top-most onscreen WINDOW with the given WINDOW::id.
uint8_t(* WINDOW_CB_SZ)(uint16_t w_id, struct WINDOW *windows, uint8_t w_h, uint16_t *out)
Definition: window.h:364
int16_t window_init(uint16_t auto_x, uint16_t auto_y, uint16_t auto_w, uint16_t auto_h) SECTION_WINDOW
Global initialization for the window subsystem. Runs at startup.
struct FAKE_MEMORY_HANDLE * MEMORY_HANDLE
A reference to a block of memory which the operating system may move around on its own to free up spa...
Definition: fakem.h:21
An emulated memory handle for modern systems. Overridden on most platforms.
Definition: memory.h:20
Defines a graphical window frame/background with a set of image assets.
Definition: window.h:33
uint16_t t
Top edge.
Definition: window.h:43
uint16_t r
Right edge.
Definition: window.h:47
uint16_t tl
Top-left corner.
Definition: window.h:37
uint16_t br
Bottom-right corner.
Definition: window.h:39
uint16_t tr
Top-right corner.
Definition: window.h:35
uint16_t b
Bottom edge.
Definition: window.h:45
uint16_t l
Left edge.
Definition: window.h:49
uint16_t c
Center fill.
Definition: window.h:51
uint16_t bl
Bottom-left corner.
Definition: window.h:41
Struct representing an on-screen graphical window.
Definition: window.h:55
GRAPHICS_COLOR bg
Background Unilayer Graphics Colors with which to draw this window.
Definition: window.h:78
uint16_t parent_id
Unique identifier of the parent window of this window.
Definition: window.h:59
union CONTROL_DATA data
Data specific to each GUI Window Types.
Definition: window.h:88
uint16_t id
Unique identifier used to find this window in the global stack.
Definition: window.h:57
GRAPHICS_COLOR fg
Foreground Unilayer Graphics Colors with which to draw this window's text.
Definition: window.h:73
uint16_t coords[4]
Pixel coordinates for this window on-screen; a tuple indexed as GUI_X, GUI_Y, GUI_W,...
Definition: window.h:86
uint8_t render_flags
Flags passed directly to rendering function, depending on GUI Window Types.
Definition: window.h:68
uint8_t flags
GUI Window Flags modifying window behavior.
Definition: window.h:63
uint8_t type
Type of window defined by a constant.
Definition: window.h:61
A piece of data attached to CONTROL::data.
Definition: window.h:23