Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Lephenixnoir | e324f9a3a2 | |
Lephenixnoir | 0e5ccf4cc3 | |
Lephenixnoir | bea113f09e | |
Lephenixnoir | ef71bc11c0 | |
Lephenixnoir | 4c44b3e413 |
|
@ -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
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
|
@ -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
|
||||
|
|
|
@ -30,6 +30,8 @@ typedef struct {
|
|||
void *entries;
|
||||
/* Number of entries in the current folder */
|
||||
int entry_count;
|
||||
/* Error code for loaded folder */
|
||||
int folder_error;
|
||||
|
||||
/* Full path to file last selected with EXE */
|
||||
char *selected_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 */
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
#include <gint/display.h>
|
||||
|
||||
/* Keymap function for jinput. See jinput_set_keymap_function(). */
|
||||
typedef uint32_t jinput_keymap_function_t(int key, bool shift, bool alpha);
|
||||
|
||||
/* jinput: One-line input field
|
||||
|
||||
This widget is used to read input from the user. It has a single line of
|
||||
|
@ -63,6 +66,9 @@ typedef struct {
|
|||
/* Timer ID for the cursor state */
|
||||
int8_t timer;
|
||||
|
||||
/* Custom keymap function (may be NULL) */
|
||||
jinput_keymap_function_t *keymap_fun;
|
||||
|
||||
} jinput;
|
||||
|
||||
/* Type IDs */
|
||||
|
@ -81,6 +87,15 @@ void jinput_set_text_color(jinput *input, int color);
|
|||
void jinput_set_font(jinput *input, font_t const *font);
|
||||
void jinput_set_prompt(jinput *input, char const *prompt);
|
||||
|
||||
/* Set a custom keymap function. The keymap function is called when a key is
|
||||
pressed that should produce input in the field. The following parameters are
|
||||
provided:
|
||||
* key is the code for the pressed key (<gint/keycodes.h>)
|
||||
* shift and alpha indicate the state of modifiers
|
||||
The function should return a Unicode code point. Note that jinput can deal
|
||||
with any Unicode code point but the font used for the jinput might not! */
|
||||
void jinput_set_keymap_function(jinput *input, jinput_keymap_function_t *kf);
|
||||
|
||||
/* Current value visible in the widget, normally useful upon receiving the
|
||||
JINPUT_VALIDATED event, not guaranteed otherwise */
|
||||
char const *jinput_value(jinput *input);
|
||||
|
|
|
@ -33,6 +33,8 @@ typedef struct {
|
|||
uint16_t lost_events;
|
||||
/* Whether jscene_run() returns to the main menu */
|
||||
bool mainmenu;
|
||||
/* Whether jscene_run() powers off */
|
||||
bool poweroff;
|
||||
|
||||
} jscene;
|
||||
|
||||
|
@ -110,6 +112,12 @@ bool jscene_process_event(jscene *scene, jevent event);
|
|||
resources before invoking the main menu. */
|
||||
void jscene_set_mainmenu(jscene *scene, bool mainmenu);
|
||||
|
||||
/* jscene_set_poweroff(): Set whether jscene_run() will poweroff
|
||||
This type of poweroff (SHIFT+AC/ON) doesn't allow return to menu, so the
|
||||
add-in "must" resume after powering on again, however sensitive programs
|
||||
will probably want to save important data before leaving anyway. */
|
||||
void jscene_set_poweroff(jscene *scene, bool poweroff);
|
||||
|
||||
/* jscene_run(): Run a scene's main loop
|
||||
|
||||
This function implements a main control loop that sleeps when there is
|
||||
|
|
|
@ -4,15 +4,27 @@
|
|||
|
||||
#include <gint/display.h>
|
||||
#include <gint/gint.h>
|
||||
#include <gint/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* 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;
|
||||
|
@ -27,9 +39,9 @@ struct fileinfo {
|
|||
/* Entry name (owned by the structure) */
|
||||
char *name;
|
||||
/* File size in bytes if file, number of entries if folder */
|
||||
int size;
|
||||
int size :24;
|
||||
/* Type from [struct dirent], -1 for the "Save As" entry */
|
||||
int type;
|
||||
int8_t type;
|
||||
};
|
||||
|
||||
jfileselect *jfileselect_create(void *parent)
|
||||
|
@ -52,25 +64,20 @@ jfileselect *jfileselect_create(void *parent)
|
|||
fs->path = NULL;
|
||||
fs->entries = NULL;
|
||||
fs->entry_count = 0;
|
||||
fs->folder_error = 0;
|
||||
|
||||
fs->selected_file = NULL;
|
||||
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;
|
||||
|
||||
|
@ -215,19 +222,24 @@ static int compare_entries(void const *i1_0, void const *i2_0)
|
|||
static bool load_folder_switch(jfileselect *fs, char *path)
|
||||
{
|
||||
set_finfo(fs, NULL, 0);
|
||||
free(fs->path);
|
||||
fs->path = path;
|
||||
|
||||
struct dirent *ent;
|
||||
DIR *dp = opendir(path);
|
||||
if(!dp)
|
||||
if(!dp) {
|
||||
fs->folder_error = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Count entries */
|
||||
int n = count_accepted_entries(fs, dp) + fs->saveas;
|
||||
|
||||
/* Allocate memory for the fileinfo structures */
|
||||
struct fileinfo *finfo = malloc(n * sizeof *finfo);
|
||||
if(!finfo) {
|
||||
if(n && !finfo) {
|
||||
closedir(dp);
|
||||
fs->folder_error = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -246,6 +258,7 @@ static bool load_folder_switch(jfileselect *fs, char *path)
|
|||
for(int j = 0; j < i; j++) free(finfo[j].name);
|
||||
free(finfo);
|
||||
closedir(dp);
|
||||
fs->folder_error = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -257,6 +270,9 @@ static bool load_folder_switch(jfileselect *fs, char *path)
|
|||
finfo[i].size = count_accepted_entries(fs, sub);
|
||||
closedir(sub);
|
||||
}
|
||||
else {
|
||||
finfo[i].size = -errno;
|
||||
}
|
||||
}
|
||||
else {
|
||||
struct stat st;
|
||||
|
@ -278,18 +294,20 @@ static bool load_folder_switch(jfileselect *fs, char *path)
|
|||
qsort(finfo, n, sizeof *finfo, compare_entries);
|
||||
|
||||
closedir(dp);
|
||||
free(fs->path);
|
||||
fs->path = path;
|
||||
set_finfo(fs, finfo, n);
|
||||
fs->widget.update = true;
|
||||
|
||||
jwidget_emit(fs, (jevent){ .type = JFILESELECT_LOADED });
|
||||
fs->folder_error = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool load_folder(jfileselect *fs, char *path)
|
||||
{
|
||||
return gint_world_switch(GINT_CALL(load_folder_switch, (void *)fs, path));
|
||||
bool ok =
|
||||
gint_world_switch(GINT_CALL(load_folder_switch, (void *)fs, path));
|
||||
|
||||
fs->widget.update = true;
|
||||
jwidget_emit(fs, (jevent){ .type = JFILESELECT_LOADED });
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool jfileselect_browse(jfileselect *fs, char const *path)
|
||||
|
@ -298,8 +316,7 @@ bool jfileselect_browse(jfileselect *fs, char const *path)
|
|||
if(!path_copy)
|
||||
return false;
|
||||
|
||||
if(!load_folder(fs, path_copy))
|
||||
return false;
|
||||
bool ok = load_folder(fs, path_copy);
|
||||
|
||||
free(fs->selected_file);
|
||||
fs->selected_file = NULL;
|
||||
|
@ -307,7 +324,7 @@ bool jfileselect_browse(jfileselect *fs, char const *path)
|
|||
fs->cursor = 0;
|
||||
fs->scroll = 0;
|
||||
stop_input(fs);
|
||||
return true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
char const *jfileselect_selected_file(jfileselect *fs)
|
||||
|
@ -361,15 +378,19 @@ static void jfileselect_poly_layout(void *fs0)
|
|||
|
||||
static void generate_info_string(char *str, bool isfolder, int size)
|
||||
{
|
||||
#ifdef FX9860G
|
||||
if(isfolder)
|
||||
#if JFILESELECT_INFO_SHORT
|
||||
if(size < 0)
|
||||
sprintf(str, "E%d", -size);
|
||||
else if(isfolder)
|
||||
sprintf(str, "%d/", size);
|
||||
else if(size < 10000) /* 10 kB */
|
||||
sprintf(str, "%d", size);
|
||||
else
|
||||
sprintf(str, "%dk", size / 1000);
|
||||
#else
|
||||
if(isfolder)
|
||||
if(size < 0)
|
||||
sprintf(str, "E%d", -size);
|
||||
else if(isfolder)
|
||||
sprintf(str, "%d entries", size);
|
||||
else
|
||||
sprintf(str, "%d B", size);
|
||||
|
@ -379,8 +400,6 @@ static void generate_info_string(char *str, bool isfolder, int size)
|
|||
static void jfileselect_poly_render(void *fs0, int x, int y)
|
||||
{
|
||||
jfileselect *fs = fs0;
|
||||
if(!fs->path || !fs->entries)
|
||||
return;
|
||||
|
||||
font_t const *old_font = dfont(fs->font);
|
||||
int line_height = fs->font->line_height + fs->line_spacing;
|
||||
|
@ -393,6 +412,17 @@ static void jfileselect_poly_render(void *fs0, int x, int y)
|
|||
&& fs->scrollbar_width > 0;
|
||||
int entry_width = cw - (scrollbar ? 2 * fs->scrollbar_width : 0);
|
||||
|
||||
if(fs->folder_error) {
|
||||
int text_y = y + (fs->line_spacing + 0) / 2;
|
||||
dprint(x, text_y, C_BLACK, "(E%d)", fs->folder_error);
|
||||
return;
|
||||
}
|
||||
if(!fs->entries || fs->entry_count == 0) {
|
||||
int text_y = y + (fs->line_spacing + 0) / 2;
|
||||
dprint(x, text_y, C_BLACK, "(No entries)");
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < fs->visible_lines && i < fs->entry_count; i++) {
|
||||
bool selected = (fs->cursor == fs->scroll + i);
|
||||
struct fileinfo *info = &finfo[fs->scroll + i];
|
||||
|
@ -417,7 +447,7 @@ static void jfileselect_poly_render(void *fs0, int x, int y)
|
|||
}
|
||||
|
||||
dprint(x+2, text_y, fg, "%s%s", info->name, isfolder ? "/" : "");
|
||||
if(fs->show_file_size && info->size >= 0) {
|
||||
if(fs->show_file_size) {
|
||||
char str[32];
|
||||
generate_info_string(str, isfolder, info->size);
|
||||
dtext_opt(x + entry_width - 3, text_y, fg, C_NONE, DTEXT_RIGHT,
|
||||
|
@ -440,7 +470,7 @@ static void jfileselect_poly_render(void *fs0, int x, int y)
|
|||
static bool jfileselect_poly_event(void *fs0, jevent e)
|
||||
{
|
||||
jfileselect *fs = fs0;
|
||||
if(!fs->path || !fs->entries)
|
||||
if(!fs->path)
|
||||
return false;
|
||||
|
||||
if(e.type == JINPUT_CANCELED && e.source == fs->saveas_input) {
|
||||
|
@ -510,7 +540,7 @@ static bool jfileselect_poly_event(void *fs0, jevent e)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else if(key == KEY_EXE) {
|
||||
else if(key == KEY_EXE && fs->entries) {
|
||||
struct fileinfo *finfo = fs->entries;
|
||||
struct fileinfo *i = &finfo[fs->cursor];
|
||||
|
||||
|
|
91
src/jfkeys.c
91
src/jfkeys.c
|
@ -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 */
|
||||
|
|
27
src/jframe.c
27
src/jframe.c
|
@ -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;
|
||||
|
|
30
src/jinput.c
30
src/jinput.c
|
@ -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)
|
||||
|
@ -56,6 +58,7 @@ jinput *jinput_create(char const *prompt, size_t length, void *parent)
|
|||
|
||||
i->mode = JINPUT_FLAT;
|
||||
i->timer = -1;
|
||||
i->keymap_fun = NULL;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -79,6 +82,11 @@ void jinput_set_prompt(jinput *i, char const *prompt)
|
|||
i->widget.dirty = 1;
|
||||
}
|
||||
|
||||
void jinput_set_keymap_function(jinput *i, jinput_keymap_function_t *kf)
|
||||
{
|
||||
i->keymap_fun = kf;
|
||||
}
|
||||
|
||||
//---
|
||||
// Input helpers
|
||||
//---
|
||||
|
@ -212,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);
|
||||
|
@ -305,7 +310,10 @@ static bool jinput_poly_event(void *i0, jevent e)
|
|||
i->mode |= JINPUT_ALPHA;
|
||||
}
|
||||
else {
|
||||
uint32_t code_point = keymap_translate(ev.key,
|
||||
jinput_keymap_function_t *kf = i->keymap_fun;
|
||||
if(!kf)
|
||||
kf = &keymap_translate;
|
||||
uint32_t code_point = (*kf)(ev.key,
|
||||
(i->mode & JINPUT_SHIFT) || (i->mode & JINPUT_SHIFT_LOCK),
|
||||
(i->mode & JINPUT_ALPHA) || (i->mode & JINPUT_ALPHA_LOCK)
|
||||
);
|
||||
|
|
14
src/jscene.c
14
src/jscene.c
|
@ -53,6 +53,7 @@ jscene *jscene_create(int x, int y, int w, int h, void *parent)
|
|||
s->queue_next = 0;
|
||||
s->lost_events = 0;
|
||||
s->mainmenu = true;
|
||||
s->poweroff = true;
|
||||
|
||||
/* Prepare first layout/paint operation */
|
||||
s->widget.dirty = 1;
|
||||
|
@ -225,12 +226,21 @@ jevent jscene_run(jscene *s)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
#ifdef FX9860G
|
||||
if(k.type == KEYEV_DOWN && k.key == KEY_ACON && k.shift && !k.alpha) {
|
||||
if(s->poweroff) {
|
||||
gint_poweroff(true);
|
||||
jscene_queue_event(s, (jevent){ .type = JSCENE_PAINT });
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 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))
|
||||
|
|
Loading…
Reference in New Issue