1
0
Fork 0
forked from Miroirs/x49gp

Merge branch 'main' of ssh://src.le-moine.org:38172/gwh/x49gpng

This commit is contained in:
Gwenhael Le Moine 2024-11-13 09:32:58 +01:00
commit 0e0e1d646c
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -26,7 +26,7 @@
#define FONT_SIZE_KEY opt.font_size #define FONT_SIZE_KEY opt.font_size
#define FONT_SIZE_SYMBOL ( 2 * opt.font_size ) #define FONT_SIZE_SYMBOL ( 2 * opt.font_size )
#define FONT_SIZE_NUMBER ( ( int )( 1.5 * opt.font_size ) ) #define FONT_SIZE_NUMBER ( ( int )( 1.75 * opt.font_size ) )
#define FONT_SIZE_TINY ( ( int )( 0.75 * opt.font_size ) ) #define FONT_SIZE_TINY ( ( int )( 0.75 * opt.font_size ) )
#define TINY_TEXT_HEIGHT ( FONT_SIZE_TINY + 2 ) #define TINY_TEXT_HEIGHT ( FONT_SIZE_TINY + 2 )
@ -39,11 +39,11 @@
#define KB_WIDTH_6_KEYS ( 3 * opt.font_size ) #define KB_WIDTH_6_KEYS ( 3 * opt.font_size )
#define KB_WIDTH_5_KEYS ( 4 * opt.font_size ) #define KB_WIDTH_5_KEYS ( 4 * opt.font_size )
#define KB_HEIGHT_MENU_KEYS ( 2 * opt.font_size ) #define KB_HEIGHT_MENU_KEYS ( ( int )( 1.75 * opt.font_size ) )
#define KB_HEIGHT_SMALL_KEYS ( ( int )( 1.5 * opt.font_size ) ) #define KB_HEIGHT_SMALL_KEYS ( ( int )( 2 * opt.font_size ) )
#define KB_HEIGHT_BIG_KEYS ( 3 * opt.font_size ) #define KB_HEIGHT_BIG_KEYS ( ( int )( 2.5 * opt.font_size ) )
#define KB_SPACING_KEYS TINY_TEXT_WIDTH #define KB_SPACING_KEYS ( ( int )( 0.5 * TINY_TEXT_WIDTH ) )
#define KB_COLUMN_WIDTH_6_KEYS ( KB_WIDTH_6_KEYS + KB_SPACING_KEYS ) #define KB_COLUMN_WIDTH_6_KEYS ( KB_WIDTH_6_KEYS + KB_SPACING_KEYS )
#define KB_COLUMN_WIDTH_5_KEYS ( KB_WIDTH_5_KEYS + KB_SPACING_KEYS ) #define KB_COLUMN_WIDTH_5_KEYS ( KB_WIDTH_5_KEYS + KB_SPACING_KEYS )
@ -55,12 +55,8 @@
#define LCD_WIDTH ( 131 * LCD_PIXEL_SCALE ) #define LCD_WIDTH ( 131 * LCD_PIXEL_SCALE )
#define LCD_HEIGHT ( 80 * LCD_PIXEL_SCALE ) #define LCD_HEIGHT ( 80 * LCD_PIXEL_SCALE )
#define KEYBOARD_PADDING ( TINY_TEXT_HEIGHT + 2 )
#define WINDOW_WIDTH ( 384 ) #define WINDOW_WIDTH ( 384 )
#define LCD_PADDING ( ( WINDOW_WIDTH - LCD_WIDTH ) / 2 )
static x49gp_ui_key_t ui_keys[ NB_KEYS ] = { static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
{.css_class = "menu", {.css_class = "menu",
.label = "F1", .label = "F1",
@ -411,7 +407,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
{.css_class = "alpha", {.css_class = "alpha",
.label = "ALPHA", .label = "ALPHA",
.letter = "", .letter = NULL,
.left = "USER", .left = "USER",
.right = "ENTRY", .right = "ENTRY",
.below = NULL, .below = NULL,
@ -422,7 +418,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 4}, .eint = 4},
{.css_class = "core-number", {.css_class = "core-number",
.label = "7", .label = "7",
.letter = "", .letter = NULL,
.left = "S.SLV", .left = "S.SLV",
.right = "NUM.SLV", .right = "NUM.SLV",
.below = NULL, .below = NULL,
@ -433,7 +429,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 4}, .eint = 4},
{.css_class = "core-number", {.css_class = "core-number",
.label = "8", .label = "8",
.letter = "", .letter = NULL,
.left = "EXP&LN", .left = "EXP&LN",
.right = "TRIG", .right = "TRIG",
.below = NULL, .below = NULL,
@ -444,7 +440,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 4}, .eint = 4},
{.css_class = "core-number", {.css_class = "core-number",
.label = "9", .label = "9",
.letter = "", .letter = NULL,
.left = "FINANCE", .left = "FINANCE",
.right = "TIME", .right = "TIME",
.below = NULL, .below = NULL,
@ -455,7 +451,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 4}, .eint = 4},
{.css_class = "core-number", {.css_class = "core-number",
.label = "×", .label = "×",
.letter = "", .letter = NULL,
.left = "[ ]", .left = "[ ]",
.right = "\" \"", .right = "\" \"",
.below = NULL, .below = NULL,
@ -467,7 +463,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
{.css_class = "shift-left", {.css_class = "shift-left",
.label = "", .label = "",
.letter = "", .letter = NULL,
.left = "", .left = "",
.right = NULL, .right = NULL,
.below = NULL, .below = NULL,
@ -478,7 +474,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 5}, .eint = 5},
{.css_class = "core-number", {.css_class = "core-number",
.label = "4", .label = "4",
.letter = "", .letter = NULL,
.left = "CALC", .left = "CALC",
.right = "ALG", .right = "ALG",
.below = NULL, .below = NULL,
@ -489,7 +485,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 5}, .eint = 5},
{.css_class = "core-number", {.css_class = "core-number",
.label = "5", .label = "5",
.letter = "", .letter = NULL,
.left = "MATRICES", .left = "MATRICES",
.right = "STAT", .right = "STAT",
.below = NULL, .below = NULL,
@ -500,7 +496,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 5}, .eint = 5},
{.css_class = "core-number", {.css_class = "core-number",
.label = "6", .label = "6",
.letter = "", .letter = NULL,
.left = "CONVERT", .left = "CONVERT",
.right = "UNITS", .right = "UNITS",
.below = NULL, .below = NULL,
@ -511,7 +507,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 5}, .eint = 5},
{.css_class = "core-number", {.css_class = "core-number",
.label = "-", .label = "-",
.letter = "", .letter = NULL,
.left = "( )", .left = "( )",
.right = "_", .right = "_",
.below = NULL, .below = NULL,
@ -523,7 +519,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
{.css_class = "shift-right", {.css_class = "shift-right",
.label = "", .label = "",
.letter = "", .letter = NULL,
.left = "", .left = "",
.right = NULL, .right = NULL,
.below = NULL, .below = NULL,
@ -534,7 +530,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 6}, .eint = 6},
{.css_class = "core-number", {.css_class = "core-number",
.label = "1", .label = "1",
.letter = "", .letter = NULL,
.left = "ARITH", .left = "ARITH",
.right = "CMPLX", .right = "CMPLX",
.below = NULL, .below = NULL,
@ -545,7 +541,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 6}, .eint = 6},
{.css_class = "core-number", {.css_class = "core-number",
.label = "2", .label = "2",
.letter = "", .letter = NULL,
.left = "DEF", .left = "DEF",
.right = "LIB", .right = "LIB",
.below = NULL, .below = NULL,
@ -556,7 +552,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 6}, .eint = 6},
{.css_class = "core-number", {.css_class = "core-number",
.label = "3", .label = "3",
.letter = "", .letter = NULL,
.left = "#", .left = "#",
.right = "BASE", .right = "BASE",
.below = NULL, .below = NULL,
@ -567,7 +563,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 6}, .eint = 6},
{.css_class = "core-number", {.css_class = "core-number",
.label = "+", .label = "+",
.letter = "", .letter = NULL,
.left = "{ }", .left = "{ }",
.right = "« »", .right = "« »",
.below = NULL, .below = NULL,
@ -579,7 +575,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
{.css_class = "core", {.css_class = "core",
.label = "ON", .label = "ON",
.letter = "", .letter = NULL,
.left = "CONT", .left = "CONT",
.right = "OFF", .right = "OFF",
.below = "CANCEL", .below = "CANCEL",
@ -590,7 +586,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 0}, .eint = 0},
{.css_class = "core-number", {.css_class = "core-number",
.label = "0", .label = "0",
.letter = "", .letter = NULL,
.left = "", .left = "",
.right = "", .right = "",
.below = NULL, .below = NULL,
@ -601,7 +597,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 7}, .eint = 7},
{.css_class = "core", {.css_class = "core",
.label = ".", .label = ".",
.letter = "", .letter = NULL,
.left = ": :", .left = ": :",
.right = "", .right = "",
.below = NULL, .below = NULL,
@ -612,7 +608,7 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
.eint = 7}, .eint = 7},
{.css_class = "core", {.css_class = "core",
.label = "SPC", .label = "SPC",
.letter = "", .letter = NULL,
.left = "𝚷", .left = "𝚷",
.right = ",", .right = ",",
.below = NULL, .below = NULL,
@ -640,18 +636,20 @@ char* css_global = "window {"
"window * {" "window * {"
" font-weight: bold;" " font-weight: bold;"
"}" "}"
/* "box { border: 1px dashed red; }" */
/* "label { border: 1px dotted yellow; }" */
".annunciator {" ".annunciator {"
" padding: 0px;" " padding: 0px;"
" color: #080808;" " color: #080808;"
"}" "}"
".lcd-container, .annunciators-container {" ".lcd-container, .annunciators-container {"
" background-color: #abd2b4;" " background-color: #a9d0b2;"
"}" "}"
"button {" "button {"
" background-image: none;" " background-image: none;"
" padding: 0px;" " padding: 0px;"
" margin-left: 5px;" " margin-left: 15px;"
" margin-right: 5px;" " margin-right: 15px;"
"}" "}"
"button.menu {" "button.menu {"
" background-color: #a9a9a9;" " background-color: #a9a9a9;"
@ -709,6 +707,22 @@ char* css_global = "window {"
/* functions */ /* functions */
/*************/ /*************/
static void x49gpng_press_key( x49gp_t* x49gp, const x49gp_ui_key_t* key )
{
if ( key->rowbit )
s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, 1 );
else
s3c2410_io_port_f_set_bit( x49gp, key->eint, 1 );
}
static void x49gpng_release_key( x49gp_t* x49gp, const x49gp_ui_key_t* key )
{
if ( key->rowbit )
s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, 0 );
else
s3c2410_io_port_f_set_bit( x49gp, key->eint, 0 );
}
static inline int _tiny_text_width( const char* text ) static inline int _tiny_text_width( const char* text )
{ {
char* stripped_text; char* stripped_text;
@ -725,10 +739,7 @@ static void ui_release_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cau
button->down = false; button->down = false;
button->hold = false; button->hold = false;
if ( key->rowbit ) x49gpng_release_key( x49gp, key );
s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, 0 );
else
s3c2410_io_port_f_set_bit( x49gp, key->eint, 0 );
} }
static void ui_release_all_buttons( x49gp_t* x49gp, x49gp_ui_button_t* cause ) static void ui_release_all_buttons( x49gp_t* x49gp, x49gp_ui_button_t* cause )
@ -763,6 +774,7 @@ static gboolean react_to_button_press( GtkWidget* widget, GdkEventButton* event,
return false; return false;
button->down = true; button->down = true;
break; break;
case 2:
case 3: case 3:
button->hold = true; button->hold = true;
if ( button->down ) if ( button->down )
@ -774,10 +786,7 @@ static gboolean react_to_button_press( GtkWidget* widget, GdkEventButton* event,
return true; return true;
} }
if ( key->rowbit ) x49gpng_press_key( x49gp, key );
s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, 1 );
else
s3c2410_io_port_f_set_bit( x49gp, key->eint, 1 );
return false; return false;
} }
@ -791,12 +800,8 @@ static gboolean react_to_button_release( GtkWidget* widget, GdkEventButton* even
if ( event->type != GDK_BUTTON_RELEASE ) if ( event->type != GDK_BUTTON_RELEASE )
return false; return false;
switch ( event->button ) { if ( event->button != 1 )
case 1: return true;
break;
default:
return true;
}
if ( ui->buttons_down > 0 ) if ( ui->buttons_down > 0 )
ui->buttons_down--; ui->buttons_down--;
@ -896,7 +901,6 @@ static gboolean react_to_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
{ {
x49gp_t* x49gp = user_data; x49gp_t* x49gp = user_data;
x49gp_ui_t* ui = x49gp->ui; x49gp_ui_t* ui = x49gp->ui;
/* gboolean save_in; */
int index; int index;
guint keyval; guint keyval;
@ -1199,11 +1203,11 @@ static gboolean react_to_window_click( GtkWidget* widget, GdkEventButton* event,
case 1: // left click case 1: // left click
gdk_window_begin_move_drag( gtk_widget_get_window( widget ), event->button, event->x_root, event->y_root, event->time ); gdk_window_begin_move_drag( gtk_widget_get_window( widget ), event->button, event->x_root, event->y_root, event->time );
break; break;
case 2: // middle click /* case 2: // middle click */
GtkClipboard* clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); /* GtkClipboard* clip = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ); */
gchar* text = gtk_clipboard_wait_for_text( clip ); /* gchar* text = gtk_clipboard_wait_for_text( clip ); */
fprintf( stderr, "clipboard: %s\n", text ); /* fprintf( stderr, "clipboard: %s\n", text ); */
break; /* break; */
case 3: // right click case 3: // right click
gtk_menu_popup_at_pointer( GTK_MENU( ui->menu ), NULL ); gtk_menu_popup_at_pointer( GTK_MENU( ui->menu ), NULL );
return true; return true;
@ -1451,10 +1455,6 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
GtkWidget* display_container = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 ); GtkWidget* display_container = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );
gtk_style_context_add_class( gtk_widget_get_style_context( annunciators_container ), "display-container" ); gtk_style_context_add_class( gtk_widget_get_style_context( annunciators_container ), "display-container" );
gtk_widget_set_margin_top( display_container, LCD_PADDING );
gtk_widget_set_margin_bottom( display_container, LCD_PADDING );
gtk_widget_set_margin_start( display_container, LCD_PADDING );
gtk_widget_set_margin_end( display_container, WINDOW_WIDTH - ( LCD_PADDING + LCD_WIDTH ) );
gtk_container_add( GTK_CONTAINER( display_container ), annunciators_container ); gtk_container_add( GTK_CONTAINER( display_container ), annunciators_container );
gtk_container_add( GTK_CONTAINER( display_container ), lcd_container ); gtk_container_add( GTK_CONTAINER( display_container ), lcd_container );
@ -1464,10 +1464,6 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
GtkWidget* keyboard_container = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 ); GtkWidget* keyboard_container = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );
gtk_style_context_add_class( gtk_widget_get_style_context( keyboard_container ), "keyboard-container" ); gtk_style_context_add_class( gtk_widget_get_style_context( keyboard_container ), "keyboard-container" );
gtk_box_set_homogeneous( GTK_BOX( keyboard_container ), true ); gtk_box_set_homogeneous( GTK_BOX( keyboard_container ), true );
gtk_widget_set_margin_top( keyboard_container, KEYBOARD_PADDING );
gtk_widget_set_margin_bottom( keyboard_container, KEYBOARD_PADDING );
gtk_widget_set_margin_start( keyboard_container, KEYBOARD_PADDING );
gtk_widget_set_margin_end( keyboard_container, KEYBOARD_PADDING );
gtk_container_add( GTK_CONTAINER( window_container ), keyboard_container ); gtk_container_add( GTK_CONTAINER( window_container ), keyboard_container );
@ -1513,18 +1509,18 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
gtk_style_context_add_class( gtk_widget_get_style_context( button->button ), button->key->css_class ); gtk_style_context_add_class( gtk_widget_get_style_context( button->button ), button->key->css_class );
gtk_widget_set_size_request( button->button, ( row == 0 ) ? KB_WIDTH_6_KEYS : KB_WIDTH_5_KEYS, gtk_widget_set_size_request( button->button, ( row == 0 ) ? KB_WIDTH_6_KEYS : KB_WIDTH_5_KEYS,
( row == 0 ) ? KB_HEIGHT_MENU_KEYS ( row == 0 ) ? KB_HEIGHT_MENU_KEYS
: ( key_index < 40 ) ? KB_HEIGHT_SMALL_KEYS : ( key_index < 30 ) ? KB_HEIGHT_SMALL_KEYS
: KB_HEIGHT_BIG_KEYS ); : KB_HEIGHT_BIG_KEYS );
gtk_widget_set_can_focus( button->button, false ); gtk_widget_set_can_focus( button->button, false );
gtk_widget_add_events( button->button, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK ); gtk_widget_add_events( button->button, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK );
g_signal_connect( G_OBJECT( button->button ), "button-press-event", G_CALLBACK( react_to_button_press ), button ); g_signal_connect( G_OBJECT( button->button ), "button-press-event", G_CALLBACK( react_to_button_press ), button );
g_signal_connect( G_OBJECT( button->button ), "button-release-event", G_CALLBACK( react_to_button_release ), button ); g_signal_connect( G_OBJECT( button->button ), "button-release-event", G_CALLBACK( react_to_button_release ), button );
g_signal_connect( G_OBJECT( button->button ), "leave-notify-event", G_CALLBACK( react_to_button_leave ), button ); g_signal_connect( G_OBJECT( button->button ), "leave-notify-event", G_CALLBACK( react_to_button_leave ), button );
gtk_container_add( GTK_CONTAINER( keys_containers[ key_index ] ), button->button );
if ( button->key->label ) if ( button->key->label )
gtk_container_add( GTK_CONTAINER( button->button ), _ui_load__create_label( "label-key", button->key->label ) ); gtk_container_add( GTK_CONTAINER( button->button ), _ui_load__create_label( "label-key", button->key->label ) );
gtk_container_add( GTK_CONTAINER( keys_containers[ key_index ] ), button->button );
if ( button->key->below ) if ( button->key->below )
gtk_container_add( GTK_CONTAINER( keys_containers[ key_index ] ), gtk_container_add( GTK_CONTAINER( keys_containers[ key_index ] ),
_ui_load__create_label( "label-below", button->key->below ) ); _ui_load__create_label( "label-below", button->key->below ) );
@ -1667,7 +1663,7 @@ int gui_init( x49gp_t* x49gp )
if ( opt.verbose ) { if ( opt.verbose ) {
fprintf( stderr, fprintf( stderr,
" FONT_SIZE_KEY = %i\n" "\n FONT_SIZE_KEY = %i\n"
" FONT_SIZE_SYMBOL = %i\n" " FONT_SIZE_SYMBOL = %i\n"
" FONT_SIZE_NUMBER = %i\n" " FONT_SIZE_NUMBER = %i\n"
" FONT_SIZE_TINY = %i\n" " FONT_SIZE_TINY = %i\n"
@ -1687,13 +1683,11 @@ int gui_init( x49gp_t* x49gp )
" LCD_PIXEL_SCALE = %i\n" " LCD_PIXEL_SCALE = %i\n"
" LCD_WIDTH = %i\n" " LCD_WIDTH = %i\n"
" LCD_HEIGHT = %i\n" " LCD_HEIGHT = %i\n"
" KEYBOARD_PADDING = %i\n" " WINDOW_WIDTH = %i\n",
" WINDOW_WIDTH = %i\n"
" LCD_PADDING = %i\n",
FONT_SIZE_KEY, FONT_SIZE_SYMBOL, FONT_SIZE_NUMBER, FONT_SIZE_TINY, TINY_TEXT_HEIGHT, TINY_TEXT_WIDTH, KB_WIDTH_6_KEYS, FONT_SIZE_KEY, FONT_SIZE_SYMBOL, FONT_SIZE_NUMBER, FONT_SIZE_TINY, TINY_TEXT_HEIGHT, TINY_TEXT_WIDTH, KB_WIDTH_6_KEYS,
KB_WIDTH_5_KEYS, KB_HEIGHT_MENU_KEYS, KB_HEIGHT_SMALL_KEYS, KB_HEIGHT_BIG_KEYS, KB_SPACING_KEYS, KB_COLUMN_WIDTH_6_KEYS, KB_WIDTH_5_KEYS, KB_HEIGHT_MENU_KEYS, KB_HEIGHT_SMALL_KEYS, KB_HEIGHT_BIG_KEYS, KB_SPACING_KEYS, KB_COLUMN_WIDTH_6_KEYS,
KB_COLUMN_WIDTH_5_KEYS, ANNUNCIATOR_WIDTH, ANNUNCIATOR_HEIGHT, ANNUNCIATORS_HEIGHT, LCD_PIXEL_SCALE, LCD_WIDTH, LCD_HEIGHT, KB_COLUMN_WIDTH_5_KEYS, ANNUNCIATOR_WIDTH, ANNUNCIATOR_HEIGHT, ANNUNCIATORS_HEIGHT, LCD_PIXEL_SCALE, LCD_WIDTH, LCD_HEIGHT,
KEYBOARD_PADDING, WINDOW_WIDTH, LCD_PADDING ); WINDOW_WIDTH );
} }
if ( x49gp_module_init( x49gp, "gui", ui_init, ui_exit, ui_reset, ui_load, ui_save, NULL, &module ) ) if ( x49gp_module_init( x49gp, "gui", ui_init, ui_exit, ui_reset, ui_load, ui_save, NULL, &module ) )