5#define RETROCON_DEBOUNCE_WAIT 3
7#define RETROCON_FLAG_ACTIVE 0x01
9#define RETROCON_IDC_TEXTBOX 1
11#define RETROCON_IDC_CON_BASE 10
13#define RETROCON_IDC_CLOSE 65535
15#ifndef RETROCON_TRACE_LVL
16# define RETROCON_TRACE_LVL 0
19#ifdef RETROCON_DISABLE
28# define retrocon_init( con, fn, x, y, w, h ) (MERROR_OK)
30# define retrocon_add_command( con, cmd, cb, cb_data ) (MERROR_OK)
32# define retrocon_display( con, display )
34# define retrocon_print_line( con, line )
36# define retrocon_exec_line( con, line, line_sz )
38# define retrocon_debounce( con, c )
40# define retrocon_input( con, p_c, input_evt, p_idc, win_stack )
42# define retrocon_shutdown( con )
51#ifndef RETROCON_TRACE_LVL
52# define RETROCON_TRACE_LVL 0
55#ifndef RETROCON_SBUFFER_SZ_MAX
56# define RETROCON_SBUFFER_SZ_MAX 4096
59#ifndef RETROCON_SBUFFER_LINES_MAX
60# define RETROCON_SBUFFER_LINES_MAX 30
63#ifndef RETROCON_LBUFFER_SZ_MAX
64# define RETROCON_LBUFFER_SZ_MAX 256
67#ifndef RETROCON_ACTIVE_KEY
68# define RETROCON_ACTIVE_KEY RETROFLAT_KEY_GRAVE
71#ifndef RETROCON_CB_NAME_SZ_MAX
72# define RETROCON_CB_NAME_SZ_MAX 32
75#ifndef RETROCON_CB_SZ_MAX
76# define RETROCON_CB_SZ_MAX 128
80# define RETROCON_WIN_H 110
86 struct RETROCON* con,
const char* line,
size_t line_sz,
void* data );
93 void* callback_data[RETROCON_CB_SZ_MAX];
94 char callback_names[RETROCON_CB_SZ_MAX][RETROCON_CB_NAME_SZ_MAX + 1];
95 retrocon_cb callbacks[RETROCON_CB_SZ_MAX];
100 size_t sbuffer_lines;
104 struct RETROCON* con,
const char* font_name,
105 size_t x,
size_t y,
size_t w,
size_t h );
108 struct RETROCON* con,
const char* cmd, retrocon_cb cb,
void* cb_data );
113 struct RETROCON* con,
char* line,
size_t line_sz );
115int retrocon_debounce(
struct RETROCON* con,
int c );
126 struct RETROCON* con, RETROFLAT_IN_KEY* p_c,
133void retrocon_shutdown(
struct RETROCON* con );
138 struct RETROCON* con,
const char* line,
size_t line_sz,
void* data
141 char* print_line = NULL;
143 print_line = maug_strchr( line,
' ' );
144 if( NULL == print_line ) {
152 retrocon_print_line( con, print_line );
160 struct RETROCON* con,
const char* line,
size_t line_sz,
void* data
170 struct RETROCON* con,
const char* font_name,
171 size_t x,
size_t y,
size_t w,
size_t h
175 size_t ctl_y_iter = 0;
177 debug_printf( RETROCON_TRACE_LVL,
"initializing console..." );
179 retval = retrogui_init( &(con->gui) );
180 maug_cleanup_if_not_ok();
183#ifdef RETROGXC_PRESENT
184 con->gui.font_idx = retrogxc_load_font( font_name, 0, 33, 93 );
186 retval = retrofont_load( font_name, &(con->gui.font_h), 0, 33, 93 );
188 maug_cleanup_if_not_ok();
190 con->sbuffer_color = RETROFLAT_COLOR_DARKBLUE;
191 con->lbuffer_color = RETROFLAT_COLOR_BLACK;
192 con->gui.bg_color = RETROFLAT_COLOR_WHITE;
198 retrogui_lock( &(con->gui) );
201 &ctl, RETROGUI_CTL_TYPE_TEXTBOX, RETROCON_IDC_TEXTBOX );
205 ctl.base.w = con->gui.w - 10;
207 ctl.base.fg_color = RETROFLAT_COLOR_BLACK;
209 retval = retrogui_push_ctl( &(con->gui), &ctl );
210 maug_cleanup_if_not_ok();
212 ctl_y_iter = ctl.base.y + ctl.base.h + 1;
213 while( h - 5 > ctl_y_iter + 8 + 1 ) {
215 &ctl, RETROGUI_CTL_TYPE_LABEL,
216 RETROCON_IDC_CON_BASE + con->sbuffer_lines );
219 ctl.base.y = ctl_y_iter;
220 ctl.base.w = con->gui.w - 10;
222 ctl.base.fg_color = RETROFLAT_COLOR_DARKGRAY;
223 ctl.LABEL.label =
"xxxxxx";
225 retval = retrogui_push_ctl( &(con->gui), &ctl );
226 maug_cleanup_if_not_ok();
228 ctl_y_iter += ctl.base.h + 1;
229 con->sbuffer_lines++;
232 retrogui_unlock( &(con->gui) );
234 con->gui.focus = RETROCON_IDC_TEXTBOX;
236 retval = retrocon_add_command( con,
"PRINT", retrocon_cmd_print, NULL );
237 maug_cleanup_if_not_ok();
238 retval = retrocon_add_command( con,
"QUIT", retrocon_cmd_quit, NULL );
239 maug_cleanup_if_not_ok();
247 struct RETROCON* con,
const char* cmd, retrocon_cb cb,
void* cb_data
251 debug_printf( RETROCON_TRACE_LVL,
"adding console command: %s", cmd );
253 maug_cleanup_if_ge_overflow( con->callbacks_sz + 1, RETROCON_CB_SZ_MAX );
256 con->callback_names[con->callbacks_sz], cmd, RETROCON_CB_NAME_SZ_MAX );
258 con->callbacks[con->callbacks_sz] = cb;
260 con->callback_data[con->callbacks_sz] = cb_data;
277 if( RETROCON_FLAG_ACTIVE != (RETROCON_FLAG_ACTIVE & con->flags) ) {
282 error_printf(
"colors not set!" );
287 NULL, con->bg_color, 10, 10,
291 NULL, con->lbuffer_color, con->lbuffer, -1, NULL,
295 for( i = 0 ; con->sbuffer_lines_sz > i ; i++ ) {
296 if( i + 1 < con->sbuffer_lines_sz ) {
297 line_sz = con->sbuffer_lines[i + 1] - con->sbuffer_lines[i];
303 NULL, con->sbuffer_color,
304 &(con->sbuffer[con->sbuffer_lines[i]]), line_sz, NULL,
305 15, 25 + (i * 10), 0 );
315 char sbuffer_shift[RETROCON_LBUFFER_SZ_MAX + 1] = { 0 };
322 for( i = con->sbuffer_lines - 1 ; 0 < i ; i-- ) {
323 debug_printf( RETROCON_TRACE_LVL,
324 "copying sbuffer line " SIZE_T_FMT
" to " SIZE_T_FMT
"...",
326 maug_mzero( sbuffer_shift, RETROCON_LBUFFER_SZ_MAX + 1 );
327 retrogui_lock( &(con->gui) );
328 retval = retrogui_get_ctl_text(
329 &(con->gui), RETROCON_IDC_CON_BASE + i - 1,
330 sbuffer_shift, RETROCON_LBUFFER_SZ_MAX );
331 retval = retrogui_set_ctl_text(
332 &(con->gui), RETROCON_IDC_CON_BASE + i,
333 RETROCON_LBUFFER_SZ_MAX, sbuffer_shift );
334 retrogui_unlock( &(con->gui) );
335 maug_cleanup_if_not_ok();
339 retrogui_lock( &(con->gui) );
340 retval = retrogui_set_ctl_text(
341 &(con->gui), RETROCON_IDC_CON_BASE,
342 RETROCON_LBUFFER_SZ_MAX, line );
343 retrogui_unlock( &(con->gui) );
344 maug_cleanup_if_not_ok();
352 struct RETROCON* con,
char* line,
size_t line_sz
356 char line_cap[RETROCON_LBUFFER_SZ_MAX + 1];
359 maug_mzero( line_cap, RETROCON_LBUFFER_SZ_MAX + 1 );
360 strncpy( line_cap, line, RETROCON_LBUFFER_SZ_MAX );
361 maug_str_upper( line_cap, line_sz );
364 for( i = 0 ; con->callbacks_sz > i ; i++ ) {
368 con->callback_names[i], line_cap,
369 maug_strlen( con->callback_names[i] ) )
371 retval = con->callbacks[i](
372 con, line, line_sz, con->callback_data[i] );
377 retrocon_print_line( con,
"COMMAND NOT FOUND!" );
385 struct RETROCON* con, RETROFLAT_IN_KEY* p_c,
393 char lbuffer[RETROCON_LBUFFER_SZ_MAX + 1] = { 0 };
395 *p_idc_out = RETROGUI_IDC_NONE;
397 if( *p_c == RETROCON_ACTIVE_KEY ) {
398 debug_printf( RETROCON_TRACE_LVL,
"active key pressed" );
399 if( RETROCON_FLAG_ACTIVE != (RETROCON_FLAG_ACTIVE & (con)->flags) ) {
400 debug_printf( RETROCON_TRACE_LVL,
"opening console..." );
401 (con)->flags |= RETROCON_FLAG_ACTIVE;
404# ifdef RETROFLAT_OPENGL
405 retval = retro3dw_push_win(
406 &((con)->gui), win_stack,
407 *p_idc_out, NULL, (con)->gui.x, (con)->gui.y,
408 (con)->gui.w, (con)->gui.h, 0 );
409 maug_cleanup_if_not_ok();
412 debug_printf( RETROCON_TRACE_LVL,
"console open!" );
414 debug_printf( RETROCON_TRACE_LVL,
"closing console..." );
415 con->flags &= ~RETROCON_FLAG_ACTIVE;
417# ifdef RETROFLAT_OPENGL
419 retro3dw_destroy_win( win_stack, *p_idc_out );
421 debug_printf( RETROCON_TRACE_LVL,
"console closed!" );
424 *p_idc_out = RETROCON_IDC_CLOSE;
428 }
else if( RETROCON_FLAG_ACTIVE != (RETROCON_FLAG_ACTIVE & (con)->flags) ) {
434 retrogui_lock( &(con->gui) );
438 retrogui_unlock( &(con->gui) );
442 if( RETROCON_IDC_TEXTBOX == *p_idc_out ) {
443 retrogui_lock( &(con->gui) );
444 retval = retrogui_get_ctl_text(
445 &(con->gui), RETROCON_IDC_TEXTBOX, lbuffer, RETROCON_LBUFFER_SZ_MAX );
446 retval = retrogui_set_ctl_text(
447 &(con->gui), RETROCON_IDC_TEXTBOX, 1,
"" );
448 retrogui_unlock( &(con->gui) );
449 maug_cleanup_if_not_ok();
451 if( 0 == maug_strlen( lbuffer ) ) {
457 retval = retrocon_exec_line( con, lbuffer, maug_strlen( lbuffer ) );
462 if( !retrocon_debounce( con, c ) ) {
468 case RETROCON_ACTIVE_KEY:
469 if( RETROCON_FLAG_ACTIVE == (RETROCON_FLAG_ACTIVE & con->flags) ) {
470 con->flags &= ~RETROCON_FLAG_ACTIVE;
472 con->flags |= RETROCON_FLAG_ACTIVE;
481 if( 0 < con->lbuffer_sz ) {
483 con->lbuffer[con->lbuffer_sz] =
'\0';
489 if( 0 == con->lbuffer_sz ) {
495 retval = retrocon_exec_line( con, con->lbuffer, con->lbuffer_sz );
497 con->lbuffer[con->lbuffer_sz] =
'\0';
501 c = retroflat_vk_to_ascii(
502 c, input_evt->key_flags | RETROFLAT_INPUT_FORCE_UPPER );
505 RETROCON_FLAG_ACTIVE == (RETROCON_FLAG_ACTIVE & con->flags) &&
508 con->lbuffer[con->lbuffer_sz++] = c;
509 con->lbuffer[con->lbuffer_sz] =
'\0';
525 if( RETROCON_FLAG_ACTIVE != (RETROCON_FLAG_ACTIVE & (con)->flags) ) {
529 (con)->gui.draw_bmp = (gui_bmp);
532 retrogui_lock( &((con)->gui) );
533 retrogui_redraw_ctls( &((con)->gui) );
534 retrogui_unlock( &((con)->gui) );
541void retrocon_shutdown(
struct RETROCON* con ) {
542#ifndef RETROGXC_PRESENT
543 maug_mfree( con->gui.font_h );
545 retrogui_free( &(con->gui) );
MERROR_RETVAL retrocon_input(struct RETROCON *con, RETROFLAT_IN_KEY *p_c, struct RETROFLAT_INPUT *input_evt, retrogui_idc_t *p_idc_out, struct MDATA_VECTOR *win_stack)
Process input from retroflat_poll_input() and apply it to the console, if open.
int MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:19
#define maug_mzero(ptr, sz)
Zero the block of memory pointed to by ptr.
Definition mmem.h:62
int8_t RETROFLAT_COLOR
Defines an index in the platform-specific color-table.
Definition retroflt.h:307
void retroflat_rect(struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t flags)
Draw a rectangle onto the target RETROFLAT_BITMAP.
#define RETROFLAT_FLAGS_FILL
Flag for retroflat_rect() or retroflat_ellipse(), indicating drawn shape should be filled.
Definition retroflt.h:355
void retroflat_string(struct RETROFLAT_BITMAP *target, const RETROFLAT_COLOR color, const char *str, int str_sz, const char *font_str, int16_t x_orig, int16_t y_orig, uint8_t flags)
Draw a text string at the specified location in the specified font and color on the target RETROFLAT_...
#define RETROGUI_FLAGS_DIRTY
RETROGUI::flags indicating controls should be redrawn.
Definition retrogui.h:16
retrogui_idc_t retrogui_poll_ctls(struct RETROGUI *gui, RETROFLAT_IN_KEY *p_input, struct RETROFLAT_INPUT *input_evt)
Poll for the last clicked control and maintain listboxes and menus.
size_t retrogui_idc_t
Unique identifying constant number for controls.
Definition retrogui.h:89
#define retroflat_quit(retval_in)
This should be called in order to quit a program using RetroFlat.
Definition retpltd.h:47
Platform-specific bitmap structure. retroflat_bitmap_ok() can be used on a pointer to it to determine...
Definition retpltd.h:21
Definition retrogui.h:167
Definition retrogui.h:158