jfkeys: add key overrides on fx-CG 50

This commit is contained in:
Lephenixnoir 2021-05-23 11:56:11 +02:00
parent d36d374524
commit 846a96db4b
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
2 changed files with 40 additions and 1 deletions

View file

@ -60,6 +60,7 @@ typedef struct {
#ifdef FXCG50
char const *labels;
char const *overrides[6];
#endif
} jfkeys;
@ -101,4 +102,16 @@ int jfkeys_level(jfkeys *keys);
/* jfkeys_set_level(): Set the function key 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 */

View file

@ -1,5 +1,6 @@
#include <justui/jfkeys.h>
#include <justui/jwidget-api.h>
#include <gint/defs/attributes.h>
#include <gint/std/stdlib.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);
jwidget_init(&f->widget, jfkeys_type_id, parent);
jfkeys_set(f, img);
return f;
}
@ -32,6 +34,7 @@ jfkeys *jfkeys_create(char const *labels, void *parent)
jfkeys *f = malloc(sizeof *f);
jwidget_init(&f->widget, jfkeys_type_id, parent);
jfkeys_set(f, labels);
for(int i = 0; i < 6; i++) f->overrides[i] = NULL;
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++) {
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 != '@'
&& *text != '#')) continue;
@ -161,6 +168,25 @@ void jfkeys_set_level(jfkeys *f, int level)
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 */
static jwidget_poly type_jfkeys = {
.name = "jfkeys",