mirror of
https://git.planet-casio.com/Lephenixnoir/JustUI.git
synced 2024-12-28 04:23:40 +01:00
jfkeys: add key overrides on fx-CG 50
This commit is contained in:
parent
d36d374524
commit
846a96db4b
2 changed files with 40 additions and 1 deletions
|
@ -60,6 +60,7 @@ typedef struct {
|
||||||
|
|
||||||
#ifdef FXCG50
|
#ifdef FXCG50
|
||||||
char const *labels;
|
char const *labels;
|
||||||
|
char const *overrides[6];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} jfkeys;
|
} jfkeys;
|
||||||
|
@ -101,4 +102,16 @@ int jfkeys_level(jfkeys *keys);
|
||||||
/* jfkeys_set_level(): Set the function key level */
|
/* jfkeys_set_level(): Set the function key level */
|
||||||
void jfkeys_set_level(jfkeys *keys, int level);
|
void jfkeys_set_level(jfkeys *keys, int level);
|
||||||
|
|
||||||
|
/* The following functions are available only on fx-CG 50 and are no-ops on
|
||||||
|
fx-9860 (you can't generate a good image for a tiny key). */
|
||||||
|
|
||||||
|
/* fkeys_override(): Get the override for a key */
|
||||||
|
char const *jfkeys_override(jfkeys *keys, int key);
|
||||||
|
|
||||||
|
/* fkeys_set_override(): Override the value of a single key on all levels
|
||||||
|
This functions sets the override on the specified key, which replaces the
|
||||||
|
label for that key on all levels. This is useful to conditionally show
|
||||||
|
functions. */
|
||||||
|
void jfkeys_set_override(jfkeys *keys, int key, char const *override);
|
||||||
|
|
||||||
#endif /* _J_JFKEYS */
|
#endif /* _J_JFKEYS */
|
||||||
|
|
28
src/jfkeys.c
28
src/jfkeys.c
|
@ -1,5 +1,6 @@
|
||||||
#include <justui/jfkeys.h>
|
#include <justui/jfkeys.h>
|
||||||
#include <justui/jwidget-api.h>
|
#include <justui/jwidget-api.h>
|
||||||
|
#include <gint/defs/attributes.h>
|
||||||
#include <gint/std/stdlib.h>
|
#include <gint/std/stdlib.h>
|
||||||
#include <gint/std/string.h>
|
#include <gint/std/string.h>
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ jfkeys *jfkeys_create(bopti_image_t const *img, void *parent)
|
||||||
jfkeys *f = malloc(sizeof *f);
|
jfkeys *f = malloc(sizeof *f);
|
||||||
jwidget_init(&f->widget, jfkeys_type_id, parent);
|
jwidget_init(&f->widget, jfkeys_type_id, parent);
|
||||||
jfkeys_set(f, img);
|
jfkeys_set(f, img);
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +34,7 @@ jfkeys *jfkeys_create(char const *labels, void *parent)
|
||||||
jfkeys *f = malloc(sizeof *f);
|
jfkeys *f = malloc(sizeof *f);
|
||||||
jwidget_init(&f->widget, jfkeys_type_id, parent);
|
jwidget_init(&f->widget, jfkeys_type_id, parent);
|
||||||
jfkeys_set(f, labels);
|
jfkeys_set(f, labels);
|
||||||
|
for(int i = 0; i < 6; i++) f->overrides[i] = NULL;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +115,11 @@ static void jfkeys_poly_render(void *f0, int base_x, int y)
|
||||||
|
|
||||||
for(int position = 0; position < 6; position++) {
|
for(int position = 0; position < 6; position++) {
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
char const *text = get_label(level, position, &length);
|
char const *text = NULL;
|
||||||
|
#ifdef FXCG50
|
||||||
|
text = f->overrides[position];
|
||||||
|
#endif
|
||||||
|
if(!text) text = get_label(level, position, &length);
|
||||||
if(!text || (*text != '.' && *text != '/' && *text != '@'
|
if(!text || (*text != '.' && *text != '/' && *text != '@'
|
||||||
&& *text != '#')) continue;
|
&& *text != '#')) continue;
|
||||||
|
|
||||||
|
@ -161,6 +168,25 @@ void jfkeys_set_level(jfkeys *f, int level)
|
||||||
f->widget.update = 1;
|
f->widget.update = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const *jfkeys_override(GUNUSED jfkeys *keys, GUNUSED int key)
|
||||||
|
{
|
||||||
|
#ifdef FXCG50
|
||||||
|
if(key < 1 || key > 6) return NULL;
|
||||||
|
return keys->overrides[key - 1];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jfkeys_set_override(GUNUSED jfkeys *keys, GUNUSED int key,
|
||||||
|
GUNUSED char const *override)
|
||||||
|
{
|
||||||
|
#ifdef FXCG50
|
||||||
|
if(key < 1 || key > 6) return;
|
||||||
|
keys->overrides[key - 1] = override;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* jfkeys type definition */
|
/* jfkeys type definition */
|
||||||
static jwidget_poly type_jfkeys = {
|
static jwidget_poly type_jfkeys = {
|
||||||
.name = "jfkeys",
|
.name = "jfkeys",
|
||||||
|
|
Loading…
Reference in a new issue