don't use FX9860G/FXCG50 and slightly more unified APIs

We still have a few platform-specific occurrences that I'll want to get
rid of in the future. This should ultimately leave me with only one
version of the library (but this also precludes the use of macros like
DWIDTH/DHEIGHT which will require further changes).
This commit is contained in:
Lephenixnoir 2024-03-24 11:05:10 +01:00
parent 0e5ccf4cc3
commit e324f9a3a2
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
9 changed files with 114 additions and 130 deletions

View File

@ -11,6 +11,7 @@ configure_file(include/justui/config.h.in include/justui/config.h)
set(ASSETS_fx
assets/input-modes-fx.png
assets/font-fkeys-fx.png
)
set(ASSETS_cg
assets/input-modes-cg.png

BIN
assets/font-fkeys-fx.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -6,3 +6,13 @@ input-modes-cg.png:
name: j_img_input_modes
type: bopti-image
profile: p4
font-fkeys-fx.png:
name: j_font_fkeys_fx
type: font
charset: print
grid.size: 5x6
grid.padding: 1
grid.border: 0
proportional: true
height: 6

View File

@ -9,6 +9,7 @@
#include <justui/jwidget.h>
#include <gint/display.h>
#include <gint/config.h>
/* jfkeys: Functions keys indicating functions for the F1..F6 keys
@ -32,8 +33,8 @@
that should catch attention, or particularly unsafe actions. They are
round white keys.
On fx-CG 50, the keys are drawn dynamically using gint's default font, and
specified using 6 strings that give the type and name of the keys:
The more flexible option to draw the keys is dynamically with text. In that
case each key are specified with a strings that combines a type and name:
* "/NAME" for a menu key;
* ".NAME" for an entry key;
@ -45,20 +46,22 @@
instance, "/F1;#F2|/F1" represents a function bar where the F2
function can be hidden by switching from level 0 to level 1.
On fx-9860G, there is not enough space to generate keys on-the-fly, so the
full specification is just an image. The convention for the image is to be
128x8 pixels, with each function key (i) positioned at (x = 21*i + 2) of
width 19. Several levels can be stacked up (n levels in an image of height
9n-1) and selected independently. */
The other option is to draw the keys with an image. This is most useful at
small resolutions where hand-drawn keys often look better. On the fx-9860G
with its 128x64 resolution, the convention is that the image is 128x8, and
key #i is positioned at x = 21i+2 with width 19. The equivalent of "|"-
separated levels is allowed by stacking up rows of keys (in which case the
image is of height 9n-1 for n rows). */
typedef struct {
jwidget widget;
int8_t level;
#ifdef FX9860G
bopti_image_t const *img;
#endif
/* Image version; if specified this overrides all text parameters */
bopti_image_t const *img;
/* Text version */
#ifdef FXCG50
char const *labels;
char const *overrides[6];
@ -66,39 +69,29 @@ typedef struct {
int text_color, text_special_color;
font_t const *font;
#endif
} jfkeys;
/* jfkeys_create(): Create a set of function keysed
/* jfkeys_create2(): Create a set of function keys
The arguments are obviously different on fx-9860G and fx-CG 50. If your
application supports both, you might want to specify arguments for both
platforms in a single call with jfkeys_create2() which will filter them out
for you. Referencing an image unavailable on fx-CG 50 in jfkeys_create2() is
safe since the preprocessor will remove that text. */
Both the image and text specification are provided; one of them should
generally be NULL (if both are non-NULL, the image takes precedence). For
historical reasons the name fkeys_create() is a one-argument version with
either the text or image depending on the platform. */
jfkeys *jfkeys_create2(
bopti_image_t const *img, char const *labels, void *parent);
#ifdef FX9860G
jfkeys *jfkeys_create(bopti_image_t const *img, void *parent);
#define jfkeys_create2(img, labels, parent) jfkeys_create(img, parent)
#endif
#ifdef FXCG50
jfkeys *jfkeys_create(char const *labels, void *parent);
#define jfkeys_create2(img, labels, parent) jfkeys_create(labels, parent)
#endif
/* jfkeys_set(): Replace functions
/* jfkeys_set2(): Replace the definition of function keys
This will also reset the level to 0. */
void jfkeys_set2(jfkeys *keys, bopti_image_t const *img, char const *labels);
#ifdef FX9860G
void jfkeys_set(jfkeys *keys, bopti_image_t const *img);
#define jfkeys_set2(keys, img, labels) jfkeys_set(keys, img)
#endif
#ifdef FXCG50
void jfkeys_set(jfkeys *keys, char const *labels);
#define jfkeys_set2(keys, img, labels) jfkeys_set(keys, labels)
/* Deprecated platform-specific shortcuts */
#if GINT_RENDER_MONO
# define jfkeys_create(img, parent) jfkeys_create2(img, NULL, parent)
# define jfkeys_set(keys, img) jfkeys_set2(keys, img, NULL)
#elif GINT_RENDER_RGB
# define jfkeys_create(labels, parent) jfkeys_create2(NULL, labels, parent)
# define jfkeys_set(keys, labels) jfkeys_set2(keys, NULL, labels)
#endif
/* jfkeys_level(): Return the current function key level */

View File

@ -4,6 +4,7 @@
#include <gint/display.h>
#include <gint/gint.h>
#include <gint/config.h>
#include <stdio.h>
#include <stdlib.h>
@ -14,6 +15,16 @@
/* Type identifier for jfileselect */
static int jfileselect_type_id = -1;
#if GINT_RENDER_MONO
# define JFILESELECT_LINE_SPACING 1
# define JFILESELECT_SCROLLBAR_WIDTH 1
# define JFILESELECT_INFO_SHORT 1
#elif GINT_RENDER_RGB
# define JFILESELECT_LINE_SPACING 4
# define JFILESELECT_SCROLLBAR_WIDTH 2
# define JFILESELECT_INFO_SHORT 0
#endif
/* Events */
uint16_t JFILESELECT_LOADED;
uint16_t JFILESELECT_VALIDATED;
@ -59,20 +70,14 @@ jfileselect *jfileselect_create(void *parent)
fs->saveas_input = input;
fs->saveas = false;
fs->input_mode = false;
fs->scrollbar_width = JFILESELECT_SCROLLBAR_WIDTH;
fs->filter_function = jfileselect_default_filter;
fs->cursor = -1;
fs->scroll = 0;
fs->visible_lines = 0;
#ifdef FX9860G
fs->line_spacing = 1;
fs->scrollbar_width = 1;
#else
fs->line_spacing = 4;
fs->scrollbar_width = 2;
#endif
fs->line_spacing = JFILESELECT_LINE_SPACING;
fs->font = dfont_default();
fs->show_file_size = false;
@ -373,7 +378,7 @@ static void jfileselect_poly_layout(void *fs0)
static void generate_info_string(char *str, bool isfolder, int size)
{
#ifdef FX9860G
#if JFILESELECT_INFO_SHORT
if(size < 0)
sprintf(str, "E%d", -size);
else if(isfolder)

View File

@ -7,45 +7,39 @@
/* Type identified for jfkeys */
static int jfkeys_type_id = -1;
#ifdef FX9860G
jfkeys *jfkeys_create(bopti_image_t const *img, void *parent)
extern font_t j_font_fkeys_fx;
#if GINT_RENDER_MONO
# define JFKEYS_HEIGHT 8
#elif GINT_RENDER_RGB
# define JFKEYS_HEIGHT 17
#endif
jfkeys *jfkeys_create2(
bopti_image_t const *img, char const *labels, void *parent)
{
if(jfkeys_type_id < 0) return NULL;
jfkeys *f = malloc(sizeof *f);
jwidget_init(&f->widget, jfkeys_type_id, parent);
jfkeys_set(f, img);
return f;
}
void jfkeys_set(jfkeys *f, bopti_image_t const *img)
{
f->img = img;
f->level = 0;
f->widget.update = true;
}
#endif /* FX9860G */
#ifdef FXCG50
jfkeys *jfkeys_create(char const *labels, void *parent)
{
if(jfkeys_type_id < 0) return NULL;
jfkeys *f = malloc(sizeof *f);
jwidget_init(&f->widget, jfkeys_type_id, parent);
jfkeys_set(f, labels);
jfkeys_set2(f, img, labels);
for(int i = 0; i < 6; i++) f->overrides[i] = NULL;
f->bg_color = C_BLACK;
f->bg_special_color = C_WHITE;
f->text_color = C_WHITE;
f->text_special_color = C_BLACK;
#if GINT_RENDER_MONO
f->font = &j_font_fkeys_fx;
#else
f->font = dfont_default();
#endif
return f;
}
void jfkeys_set(jfkeys *f, char const *labels)
void jfkeys_set2(jfkeys *f, bopti_image_t const *img, char const *labels)
{
f->img = img;
f->labels = labels;
f->level = 0;
f->widget.update = true;
@ -90,7 +84,6 @@ static char const *get_label(char const *level, int key, size_t *len)
return NULL;
}
#endif /* FXCG50 */
//---
// Polymorphic widget operations
@ -99,37 +92,27 @@ static char const *get_label(char const *level, int key, size_t *len)
static void jfkeys_poly_csize(void *f0)
{
jfkeys *f = f0;
#ifdef FX9860G
f->widget.w = 128;
f->widget.h = 8;
#endif
#ifdef FXCG50
f->widget.w = 396;
f->widget.h = 17;
#endif
f->widget.w = DWIDTH;
f->widget.h = JFKEYS_HEIGHT;
}
static void jfkeys_poly_render(void *f0, int base_x, int y)
{
jfkeys *f = f0;
#ifdef FX9860G
dsubimage(base_x, y, f->img, 0, 9*f->level, f->img->width, 8, DIMAGE_NONE);
#endif
if(f->img) {
dsubimage(base_x, y, f->img, 0, (JFKEYS_HEIGHT+1) * f->level,
f->img->width, JFKEYS_HEIGHT, DIMAGE_NONE);
return;
}
#ifdef FXCG50
font_t const *old_font = dfont(f->font);
char const *level = get_level(f->labels, f->level);
if(!level) return;
for(int position = 0; position < 6; position++) {
size_t length = 0;
char const *text = NULL;
#ifdef FXCG50
text = f->overrides[position];
#endif
char const *text = f->overrides[position];
if(!text) text = get_label(level, position, &length);
if(!text || (*text != '.' && *text != '/' && *text != '@'
&& *text != '#')) continue;
@ -168,7 +151,6 @@ static void jfkeys_poly_render(void *f0, int base_x, int y)
}
dfont(old_font);
#endif /* FXCG50 */
}
int jfkeys_level(jfkeys *f)
@ -183,41 +165,30 @@ void jfkeys_set_level(jfkeys *f, int level)
f->widget.update = 1;
}
char const *jfkeys_override(GUNUSED jfkeys *keys, GUNUSED int key)
char const *jfkeys_override(jfkeys *keys, 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)
void jfkeys_set_override(jfkeys *keys, int key, char const *override)
{
#ifdef FXCG50
if(key < 1 || key > 6) return;
keys->overrides[key - 1] = override;
#endif
}
void jfkeys_set_color(GUNUSED jfkeys *keys, GUNUSED int bg,
GUNUSED int bg_special, GUNUSED int text, GUNUSED int text_special)
void jfkeys_set_color(
jfkeys *keys, int bg, int bg_special, int text, int text_special)
{
#ifdef FXCG50
keys->bg_color = bg;
keys->bg_special_color = bg_special;
keys->text_color = text;
keys->text_special_color = text_special;
#endif
}
void jfkeys_set_font(GUNUSED jfkeys *keys, GUNUSED font_t const *font)
void jfkeys_set_font(jfkeys *keys, font_t const *font)
{
#ifdef FXCG50
keys->font = font;
#endif
}
/* jfkeys type definition */

View File

@ -4,18 +4,28 @@
#include "util.h"
#include <gint/display.h>
#include <gint/config.h>
#include <stdlib.h>
/* Type identifier for jframe */
static int jframe_type_id = -1;
#if GINT_RENDER_MONO
# define JFRAME_SCROLLBAR_WIDTH 1
# define JFRAME_SCROLLBAR_SPACING 1
# define JFRAME_DEFAULT_MARGIN 4
#elif GINT_RENDER_RGB
# define JFRAME_SCROLLBAR_WIDTH 2
# define JFRAME_SCROLLBAR_SPACING 2
# define JFRAME_DEFAULT_MARGIN 8
#endif
jframe *jframe_create(void *parent)
{
if(jframe_type_id < 0)
return NULL;
jframe *f = malloc(sizeof *f);
if(!f)
return NULL;
@ -30,18 +40,11 @@ jframe *jframe_create(void *parent)
f->keyboard_control = false;
f->match_width = false;
f->match_height = false;
f->scrollbar_width = JFRAME_SCROLLBAR_WIDTH;
f->scrollbar_spacing = JFRAME_SCROLLBAR_SPACING;
#ifdef FX9860G
f->scrollbar_width = 1;
f->scrollbar_spacing = 1;
f->visibility_margin_x = 4;
f->visibility_margin_y = 4;
#else
f->scrollbar_width = 2;
f->scrollbar_spacing = 2;
f->visibility_margin_x = 8;
f->visibility_margin_y = 8;
#endif
f->visibility_margin_x = JFRAME_DEFAULT_MARGIN;
f->visibility_margin_y = JFRAME_DEFAULT_MARGIN;
f->scroll_x = 0;
f->scroll_y = 0;

View File

@ -5,7 +5,8 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/std/stdlib.h>
#include <gint/config.h>
#include <stdlib.h>
/* Type identifier for jinput */
static int jinput_type_id = -1;
@ -28,11 +29,12 @@ enum {
/* Mode indicators and their size */
extern bopti_image_t j_img_input_modes;
#ifdef FX9860G
#define JINPUT_INDICATOR 9
#endif
#ifdef FXCG50
#define JINPUT_INDICATOR 12
#if GINT_RENDER_MONO
# define JINPUT_INDICATOR 9
# define JINPUT_CURSOR_WIDTH 1
#elif GINT_RENDER_RGB
# define JINPUT_INDICATOR 12
# define JINPUT_CURSOR_WIDTH 2
#endif
jinput *jinput_create(char const *prompt, size_t length, void *parent)
@ -218,10 +220,7 @@ static void jinput_poly_render(void *i0, int x, int y)
else cursor_w = 0;
int cursor_x = x + prompt_w + cursor_w;
dline(cursor_x, y, cursor_x, y + h - 1, i->color);
#ifdef FXCG50
dline(cursor_x + 1, y, cursor_x + 1, y + h - 1, i->color);
#endif
drect(cursor_x, y, cursor_x+JINPUT_CURSOR_WIDTH-1, y + h - 1, i->color);
}
dfont(old_font);

View File

@ -233,12 +233,14 @@ jevent jscene_run(jscene *s)
continue;
}
}
#ifdef FX9860G
// TODO: Temporarily disabled to allow build-fxg3a, will put back when
// gint's generic video interface is available
/* #ifdef FX9860G
if(k.type == KEYEV_DOWN && k.key == KEY_OPTN && k.shift && !k.alpha) {
t6k11_backlight(-1);
continue;
}
#endif
#endif */
getkey_feature_t feat = getkey_feature_function();
if((k.type == KEYEV_DOWN || k.type == KEYEV_HOLD) && feat && feat(k))