Skip to content
Snippets Groups Projects
Commit 85dce134 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

UIFC "list" now supports an optional left/right arrow key indicator

Passing either WIN_LEFTKEY or WIN_RIGHTKEY in the window "mode" argument enables this new indicator in the upper right of "list" windows. These indicator arrows are mouse-clickable too (translate to the left and right arrow keys).

We had defined uses for all 32 available WIN_* mode bits, so I extended the win mode type from 32 to 64 bits (should this now be called uifc64.c?) :-)

Anyway, it'll be easier to add more WIN_* mode flags as needed later, but I do wonder about JavaScript support (not so great for > 31-bit integers).
parent 662069f4
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -132,48 +132,52 @@ ...@@ -132,48 +132,52 @@
/*******************************/ /*******************************/
/* Bits in uifcapi_t.list mode */ /* Bits in uifcapi_t.list mode */
/*******************************/ /*******************************/
#define WIN_ORG (1<<0) /* Original menu - destroy valid screen area */ #define WIN_ORG (1LL<<0) /* Original menu - destroy valid screen area */
#define WIN_SAV (1<<1) /* Save existing text and replace when finished */ #define WIN_SAV (1LL<<1) /* Save existing text and replace when finished */
#define WIN_ACT (1<<2) /* Menu remains active after a selection */ #define WIN_ACT (1LL<<2) /* Menu remains active after a selection */
#define WIN_L2R (1<<3) /* Center the window based on 'width' */ #define WIN_L2R (1LL<<3) /* Center the window based on 'width' */
#define WIN_T2B (1<<4) /* Center the window based on 'height' */ #define WIN_T2B (1LL<<4) /* Center the window based on 'height' */
#define WIN_INS (1<<5) /* Allows user to use insert key */ #define WIN_INS (1LL<<5) /* Allows user to use insert key */
#define WIN_INSACT (1<<6) /* Remains active after insert key */ #define WIN_INSACT (1LL<<6) /* Remains active after insert key */
#define WIN_DEL (1<<7) /* Allows user to use delete key */ #define WIN_DEL (1LL<<7) /* Allows user to use delete key */
#define WIN_DELACT (1<<8) /* Remains active after delete key */ #define WIN_DELACT (1LL<<8) /* Remains active after delete key */
#define WIN_ESC (1<<9) /* Screen is active when escape is hit */ #define WIN_ESC (1LL<<9) /* Screen is active when escape is hit */
#define WIN_RHT (1<<10) /* Place window against right side of screen */ #define WIN_RHT (1LL<<10) /* Place window against right side of screen */
#define WIN_BOT (1<<11) /* Place window against bottom of screen */ #define WIN_BOT (1LL<<11) /* Place window against bottom of screen */
#define WIN_COPY (1<<12) /* Allows F5 to Get (copy) a menu item */ #define WIN_COPY (1LL<<12) /* Allows F5 to Get (copy) a menu item */
#define WIN_PASTE (1<<13) /* Allows F6 to Put (paste) a menu item */ #define WIN_PASTE (1LL<<13) /* Allows F6 to Put (paste) a menu item */
#define WIN_CHE (1<<14) /* Stay active after escape if changes */ #define WIN_CHE (1LL<<14) /* Stay active after escape if changes */
#define WIN_XTR (1<<15) /* Add extra line at end for inserting at end */ #define WIN_XTR (1LL<<15) /* Add extra line at end for inserting at end */
#define WIN_DYN (1<<16) /* Dynamic window - return at least every second */ #define WIN_DYN (1LL<<16) /* Dynamic window - return at least every second */
#define WIN_CUT (1<<17) /* Allow ^X (cut) a menu item */ #define WIN_CUT (1LL<<17) /* Allow ^X (cut) a menu item */
#define WIN_HLP (1<<17) /* Parse 'Help codes' - showbuf() */ #define WIN_HLP (1LL<<17) /* Parse 'Help codes' - showbuf() */
#define WIN_PACK (1<<18) /* Pack text in window (No padding) - showbuf() */ #define WIN_PACK (1LL<<18) /* Pack text in window (No padding) - showbuf() */
#define WIN_IMM (1<<19) /* Draw window and return immediately */ #define WIN_IMM (1LL<<19) /* Draw window and return immediately */
#define WIN_FAT (1<<20) /* Do not pad outside borders */ #define WIN_FAT (1LL<<20) /* Do not pad outside borders */
#define WIN_REDRAW (1<<21) /* Force redraw on dynamic window */ #define WIN_REDRAW (1LL<<21) /* Force redraw on dynamic window */
#define WIN_NODRAW (1<<22) /* Force not to redraw on dynamic window */ #define WIN_NODRAW (1LL<<22) /* Force not to redraw on dynamic window */
#define WIN_EXTKEYS (1<<23) /* Return on any keypress... if it's not handled internally #define WIN_EXTKEYS (1LL<<23) /* Return on any keypress... if it's not handled internally
* Return value is -2 - keyvalue */ * Return value is -2 - keyvalue */
#define WIN_NOBRDR (1<<24) /* Do not draw a border around the window */ #define WIN_NOBRDR (1LL<<24) /* Do not draw a border around the window */
#define WIN_FIXEDHEIGHT (1<<25) /* Use list_height from uifc struct */ #define WIN_FIXEDHEIGHT (1LL<<25) /* Use list_height from uifc struct */
#define WIN_UNGETMOUSE (1<<26) /* If the mouse is clicked outside the window, */ #define WIN_UNGETMOUSE (1LL<<26) /* If the mouse is clicked outside the window, */
/* Put the mouse event back into the event queue */ /* Put the mouse event back into the event queue */
#define WIN_EDIT (1<<27) /* Allow F2 to edit a menu item */ #define WIN_EDIT (1LL<<27) /* Allow F2 to edit a menu item */
#define WIN_PASTEXTR (1<<28) /* Allow paste into extra (blank) item */ #define WIN_PASTEXTR (1LL<<28) /* Allow paste into extra (blank) item */
#define WIN_INACT (1<<29) /* Draw window inactive... intended for use with WIN_IMM */ #define WIN_INACT (1LL<<29) /* Draw window inactive... intended for use with WIN_IMM */
#define WIN_POP (1<<30) /* Exit the list. Act as though ESC was pressed. */ #define WIN_POP (1LL<<30) /* Exit the list. Act as though ESC was pressed. */
/* Intended for use after a WIN_EXTKEYS or WIN_DYN */ /* Intended for use after a WIN_EXTKEYS or WIN_DYN */
#define WIN_SEL (1<<31) /* Exit the list. Act as though ENTER was pressed. */ #define WIN_SEL (1LL<<31) /* Exit the list. Act as though ENTER was pressed. */
/* Intended for use after a WIN_EXTKEYS or WIN_DYN */ /* Intended for use after a WIN_EXTKEYS or WIN_DYN */
#define WIN_LEFTKEY (1LL<<32) /* Display left-arrow-key support indicator */
#define WIN_RIGHTKEY (1LL<<33) /* Display right-arrow-key support indicator */
#define WIN_MID WIN_L2R|WIN_T2B /* Place window in middle of screen */ #define WIN_MID WIN_L2R|WIN_T2B /* Place window in middle of screen */
#define WIN_GET WIN_COPY #define WIN_GET WIN_COPY
#define WIN_PUT WIN_PASTE #define WIN_PUT WIN_PASTE
typedef int64_t uifc_winmode_t;
#define SCRN_TOP 3 #define SCRN_TOP 3
#define SCRN_LEFT 5 #define SCRN_LEFT 5
#define SCRN_RIGHT ((int)api->scrn_width-4) #define SCRN_RIGHT ((int)api->scrn_width-4)
...@@ -282,6 +286,8 @@ typedef struct { ...@@ -282,6 +286,8 @@ typedef struct {
char close_char; char close_char;
char up_arrow; char up_arrow;
char down_arrow; char down_arrow;
char left_arrow;
char right_arrow;
char button_left; char button_left;
char button_right; char button_right;
...@@ -452,7 +458,7 @@ typedef struct { ...@@ -452,7 +458,7 @@ typedef struct {
/* Returns the 0-based selected option number, -1 for ESC, or the selected */ /* Returns the 0-based selected option number, -1 for ESC, or the selected */
/* option number OR'd with MSK_INS, MSK_DEL, MSK_GET, MSK_PUT, or MSK_EDIT. */ /* option number OR'd with MSK_INS, MSK_DEL, MSK_GET, MSK_PUT, or MSK_EDIT. */
/****************************************************************************/ /****************************************************************************/
int (*list) (int mode, int left, int top, int width, int* dflt int (*list) (uifc_winmode_t, int left, int top, int width, int* dflt
,int* bar, const char *title, char** option); ,int* bar, const char *title, char** option);
/****************************************************************************/ /****************************************************************************/
/* Windowed string input routine. */ /* Windowed string input routine. */
...@@ -465,7 +471,7 @@ typedef struct { ...@@ -465,7 +471,7 @@ typedef struct {
/* This function sets uifcapi_t.changes to TRUE if the string is modified. */ /* This function sets uifcapi_t.changes to TRUE if the string is modified. */
/* Returns the length of the string or -1 on escape/abort. */ /* Returns the length of the string or -1 on escape/abort. */
/****************************************************************************/ /****************************************************************************/
int (*input)(int mode, int left, int top, const char* prompt, char* str int (*input)(uifc_winmode_t, int left, int top, const char* prompt, char* str
,int len, int kmode); ,int len, int kmode);
/****************************************************************************/ /****************************************************************************/
/* Sets the current help index by source code file and line number. */ /* Sets the current help index by source code file and line number. */
...@@ -480,7 +486,7 @@ typedef struct { ...@@ -480,7 +486,7 @@ typedef struct {
/****************************************************************************/ /****************************************************************************/
/* Shows a scrollable text buffer - optionally parsing "help markup codes" */ /* Shows a scrollable text buffer - optionally parsing "help markup codes" */
/****************************************************************************/ /****************************************************************************/
void (*showbuf)(int mode, int left, int top, int width, int height void (*showbuf)(uifc_winmode_t, int left, int top, int width, int height
,const char *title, const char *hbuf, int *curp, int *barp); ,const char *title, const char *hbuf, int *curp, int *barp);
/****************************************************************************/ /****************************************************************************/
...@@ -492,7 +498,7 @@ typedef struct { ...@@ -492,7 +498,7 @@ typedef struct {
/****************************************************************************/ /****************************************************************************/
/* Displays the bottom line using the WIN_* mode flags */ /* Displays the bottom line using the WIN_* mode flags */
/****************************************************************************/ /****************************************************************************/
void (*bottomline)(int mode); void (*bottomline)(uifc_winmode_t);
/****************************************************************************/ /****************************************************************************/
/* String input/exit box at a specified position */ /* String input/exit box at a specified position */
......
...@@ -68,7 +68,7 @@ static uifcapi_t* api; ...@@ -68,7 +68,7 @@ static uifcapi_t* api;
/* Prototypes */ /* Prototypes */
static int uprintf(int x, int y, unsigned attr, char *fmt,...); static int uprintf(int x, int y, unsigned attr, char *fmt,...);
static void bottomline(int line); static void bottomline(uifc_winmode_t);
static char *utimestr(time_t *intime); static char *utimestr(time_t *intime);
static void help(void); static void help(void);
static int ugetstr(int left, int top, int width, char *outstr, int max, long mode, int *lastkey); static int ugetstr(int left, int top, int width, char *outstr, int max, long mode, int *lastkey);
...@@ -77,9 +77,9 @@ static void timedisplay(BOOL force); ...@@ -77,9 +77,9 @@ static void timedisplay(BOOL force);
/* API routines */ /* API routines */
static void uifcbail(void); static void uifcbail(void);
static int uscrn(const char *str); static int uscrn(const char *str);
static int ulist(int mode, int left, int top, int width, int *dflt, int *bar static int ulist(uifc_winmode_t, int left, int top, int width, int *dflt, int *bar
,const char *title, char **option); ,const char *title, char **option);
static int uinput(int imode, int left, int top, const char *prompt, char *str static int uinput(uifc_winmode_t, int left, int top, const char *prompt, char *str
,int len ,int kmode); ,int len ,int kmode);
static int umsg(const char *str); static int umsg(const char *str);
static int umsgf(char *fmt, ...); static int umsgf(char *fmt, ...);
...@@ -87,7 +87,7 @@ static BOOL confirm(char *fmt, ...); ...@@ -87,7 +87,7 @@ static BOOL confirm(char *fmt, ...);
static BOOL deny(char *fmt, ...); static BOOL deny(char *fmt, ...);
static void upop(const char *str); static void upop(const char *str);
static void sethelp(int line, char* file); static void sethelp(int line, char* file);
static void showbuf(int mode, int left, int top, int width, int height, const char *title static void showbuf(uifc_winmode_t, int left, int top, int width, int height, const char *title
, const char *hbuf, int *curp, int *barp); , const char *hbuf, int *curp, int *barp);
/* Dynamic menu support */ /* Dynamic menu support */
...@@ -113,6 +113,8 @@ static uifc_graphics_t cp437_chars = { ...@@ -113,6 +113,8 @@ static uifc_graphics_t cp437_chars = {
.close_char=0xfe, .close_char=0xfe,
.up_arrow=30, .up_arrow=30,
.down_arrow=31, .down_arrow=31,
.left_arrow=17,
.right_arrow=16,
.button_left='[', .button_left='[',
.button_right=']', .button_right=']',
...@@ -619,7 +621,7 @@ inactive_win(struct vmem_cell *buf, int left, int top, int right, int bottom, in ...@@ -619,7 +621,7 @@ inactive_win(struct vmem_cell *buf, int left, int top, int right, int bottom, in
/****************************************************************************/ /****************************************************************************/
/* General menu function, see uifc.h for details. */ /* General menu function, see uifc.h for details. */
/****************************************************************************/ /****************************************************************************/
int ulist(int mode, int left, int top, int width, int *cur, int *bar int ulist(int64_t mode, int left, int top, int width, int *cur, int *bar
, const char *initial_title, char **option) , const char *initial_title, char **option)
{ {
struct vmem_cell *ptr, *win, shade[MAX_LINES*2], line[MAX_COLS]; struct vmem_cell *ptr, *win, shade[MAX_LINES*2], line[MAX_COLS];
...@@ -697,7 +699,7 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar ...@@ -697,7 +699,7 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar
api->help_available = (api->helpbuf!=NULL || api->helpixbfile[0]!=0); api->help_available = (api->helpbuf!=NULL || api->helpixbfile[0]!=0);
/* Create the status bar/bottom-line */ /* Create the status bar/bottom-line */
int bline = mode; int64_t bline = mode;
if (api->bottomline != NULL) { if (api->bottomline != NULL) {
if ((mode&(WIN_XTR | WIN_PASTEXTR)) == WIN_XTR && (*cur) == opts - 1) if ((mode&(WIN_XTR | WIN_PASTEXTR)) == WIN_XTR && (*cur) == opts - 1)
api->bottomline(bline & ~WIN_PASTE); api->bottomline(bline & ~WIN_PASTE);
...@@ -886,8 +888,24 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar ...@@ -886,8 +888,24 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar
else else
i=0; i=0;
if(mode & (WIN_LEFTKEY|WIN_RIGHTKEY)) {
for(;i<width-7;i++)
set_vmem(ptr++, api->chars->list_top, hclr|(bclr<<4), 0);
set_vmem(ptr++, api->chars->button_left, hclr|(bclr<<4), 0);
if(mode & WIN_LEFTKEY)
set_vmem(ptr++, api->chars->left_arrow, lclr|(bclr<<4), 0);
else
set_vmem(ptr++, ' ', lclr|(bclr<<4), 0);
set_vmem(ptr++, ' ', lclr|(bclr<<4), 0);
if(mode & WIN_RIGHTKEY)
set_vmem(ptr++, api->chars->right_arrow, lclr|(bclr<<4), 0);
else
set_vmem(ptr++, ' ', lclr|(bclr<<4), 0);
set_vmem(ptr++, api->chars->button_right, hclr|(bclr<<4), 0);
} else {
for(;i<width-2;i++) for(;i<width-2;i++)
set_vmem(ptr++, api->chars->list_top, hclr|(bclr<<4), 0); set_vmem(ptr++, api->chars->list_top, hclr|(bclr<<4), 0);
}
set_vmem(ptr++, api->chars->list_top_right, hclr|(bclr<<4), 0); set_vmem(ptr++, api->chars->list_top_right, hclr|(bclr<<4), 0);
set_vmem(ptr++, api->chars->list_left, hclr|(bclr<<4), 0); set_vmem(ptr++, api->chars->list_left, hclr|(bclr<<4), 0);
a=title_len; a=title_len;
...@@ -1155,6 +1173,20 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar ...@@ -1155,6 +1173,20 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar
&& mevnt.event==CIOLIB_BUTTON_1_CLICK) { && mevnt.event==CIOLIB_BUTTON_1_CLICK) {
gotkey=CIO_KEY_NPAGE; gotkey=CIO_KEY_NPAGE;
} }
/* Clicked Left Arrow */
else if((mode & WIN_LEFTKEY)
&& mevnt.startx==s_left+left+(width-5)
&& mevnt.starty==(s_top+top)-(bbrdrwidth-1)
&& mevnt.event==CIOLIB_BUTTON_1_CLICK) {
gotkey = CIO_KEY_LEFT;
}
/* Clicked Right Arrow */
else if((mode & WIN_RIGHTKEY)
&& mevnt.startx==s_left+left+(width-3)
&& mevnt.starty==(s_top+top)-(bbrdrwidth-1)
&& mevnt.event==CIOLIB_BUTTON_1_CLICK) {
gotkey = CIO_KEY_RIGHT;
}
/* Clicked Outside of Window */ /* Clicked Outside of Window */
else if((mevnt.startx<s_left+left else if((mevnt.startx<s_left+left
|| mevnt.startx>s_left+left+width-1 || mevnt.startx>s_left+left+width-1
...@@ -1836,7 +1868,7 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar ...@@ -1836,7 +1868,7 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar
/*************************************************************************/ /*************************************************************************/
/* This function is a windowed input string input routine. */ /* This function is a windowed input string input routine. */
/*************************************************************************/ /*************************************************************************/
int uinput(int mode, int left, int top, const char *inprompt, char *str, int uinput(uifc_winmode_t mode, int left, int top, const char *inprompt, char *str,
int max, int kmode) int max, int kmode)
{ {
struct vmem_cell shade[MAX_COLS], save_buf[MAX_COLS*4], in_win[MAX_COLS*3]; struct vmem_cell shade[MAX_COLS], save_buf[MAX_COLS*4], in_win[MAX_COLS*3];
...@@ -2483,7 +2515,7 @@ static int uprintf(int x, int y, unsigned attr, char *fmat, ...) ...@@ -2483,7 +2515,7 @@ static int uprintf(int x, int y, unsigned attr, char *fmat, ...)
/****************************************************************************/ /****************************************************************************/
/* Display bottom line of screen in inverse */ /* Display bottom line of screen in inverse */
/****************************************************************************/ /****************************************************************************/
void bottomline(int mode) void bottomline(uifc_winmode_t mode)
{ {
int i=1; int i=1;
...@@ -2690,7 +2722,7 @@ void sethelp(int line, char* file) ...@@ -2690,7 +2722,7 @@ void sethelp(int line, char* file)
/****************************************************************************/ /****************************************************************************/
/* Shows a scrollable text buffer - optionally parsing "help markup codes" */ /* Shows a scrollable text buffer - optionally parsing "help markup codes" */
/****************************************************************************/ /****************************************************************************/
void showbuf(int mode, int left, int top, int width, int height, const char *title, const char *hbuf, int *curp, int *barp) void showbuf(uifc_winmode_t mode, int left, int top, int width, int height, const char *title, const char *hbuf, int *curp, int *barp)
{ {
char inverse=0,high=0; char inverse=0,high=0;
struct vmem_cell *textbuf; struct vmem_cell *textbuf;
......
...@@ -55,9 +55,9 @@ static void help(void); ...@@ -55,9 +55,9 @@ static void help(void);
/* API routines */ /* API routines */
static void uifcbail(void); static void uifcbail(void);
static int uscrn(const char *str); static int uscrn(const char *str);
static int ulist(int mode, int left, int top, int width, int *dflt, int *bar static int ulist(uifc_winmode_t, int left, int top, int width, int *dflt, int *bar
,const char *title, char **option); ,const char *title, char **option);
static int uinput(int imode, int left, int top, const char *prompt, char *str static int uinput(uifc_winmode_t, int left, int top, const char *prompt, char *str
,int len ,int kmode); ,int len ,int kmode);
static int umsg(const char *str); static int umsg(const char *str);
static int umsgf(char *str, ...); static int umsgf(char *str, ...);
...@@ -192,7 +192,7 @@ static int which(char* prompt, int max) ...@@ -192,7 +192,7 @@ static int which(char* prompt, int max)
/****************************************************************************/ /****************************************************************************/
/* General menu function, see uifc.h for details. */ /* General menu function, see uifc.h for details. */
/****************************************************************************/ /****************************************************************************/
int ulist(int mode, int left, int top, int width, int *cur, int *bar int ulist(uifc_winmode_t mode, int left, int top, int width, int *cur, int *bar
, const char *title, char **option) , const char *title, char **option)
{ {
char str[128]; char str[128];
...@@ -336,7 +336,7 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar ...@@ -336,7 +336,7 @@ int ulist(int mode, int left, int top, int width, int *cur, int *bar
/*************************************************************************/ /*************************************************************************/
/* This function is a windowed input string input routine. */ /* This function is a windowed input string input routine. */
/*************************************************************************/ /*************************************************************************/
int uinput(int mode, int left, int top, const char *prompt, char *outstr, int uinput(uifc_winmode_t mode, int left, int top, const char *prompt, char *outstr,
int max, int kmode) int max, int kmode)
{ {
char str[256]; char str[256];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment