From e8f53dd5e67efaa5114bcb11c22b329e194f520b Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Sun, 14 Apr 2024 19:06:09 +0200 Subject: [PATCH] Remove dead code; tweak GUI --- Makefile | 1 - src/config.c | 1 + src/config.h | 1 + src/gui.c | 261 ++++++++++++++++++++++++++-------------------- src/gui.h | 58 +++++++---- src/gui_buttons.c | 103 +++++++++--------- src/gui_color.c | 57 ---------- src/gui_color.h | 22 ---- src/gui_display.c | 37 +++---- 9 files changed, 252 insertions(+), 289 deletions(-) delete mode 100644 src/gui_color.c delete mode 100644 src/gui_color.h diff --git a/Makefile b/Makefile index 01d1c2e..e20a632 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,6 @@ CFLAGS = -Wall -Werror -O3 -Wno-error=unused-function -Wno-error=unused-variable all: dist/hpemu dist/hpemu: src/bus.o \ - src/gui_color.o \ src/cpu.o \ src/display.o \ src/emulator.o \ diff --git a/src/config.c b/src/config.c index e33224d..3d57be7 100644 --- a/src/config.c +++ b/src/config.c @@ -2,6 +2,7 @@ Config config = { .progname = "hpemu", + .ui_font = "/usr/share/fonts/TTF/unifont.ttf", .real_speed = true, .verbose = true, }; diff --git a/src/config.h b/src/config.h index f879360..e417ba0 100644 --- a/src/config.h +++ b/src/config.h @@ -5,6 +5,7 @@ typedef struct { char* progname; + char* ui_font; bool real_speed; bool verbose; } Config; diff --git a/src/gui.c b/src/gui.c index 9e50843..11431b5 100644 --- a/src/gui.c +++ b/src/gui.c @@ -5,7 +5,7 @@ #include #include -#include "gui_color.h" +#include "config.h" #include "gui_buttons.h" #include "files.h" #include "gui.h" @@ -15,78 +15,56 @@ #define PANEL_FLAG_VISIBLE 0x01 extern SDL_Renderer* renderer; -extern SDL_Texture* faceplateTexture; -extern TTF_Font* ttffont; -extern TTF_Font* ttffont2; -SDL_Surface* surfA[ 49 ]; -SDL_Texture* textA[ 49 ]; +TTF_Font* ttffont = NULL; +TTF_Font* ttffont2 = NULL; -SDL_Surface* surfB[ 49 ]; -SDL_Texture* label_Lshift[ 49 ]; +bool SDL_ready = false; -SDL_Surface* surfC[ 49 ]; -SDL_Texture* label_Rshift[ 49 ]; +SDL_Window* window = NULL; +SDL_Renderer* renderer = NULL; +SDL_Texture* texTarget = NULL; +SDL_Texture* tex2Target = NULL; -SDL_Surface* surfD[ 49 ]; -SDL_Texture* label_below[ 49 ]; +SDL_Surface* surfaces_labels[ 49 ]; +SDL_Texture* textures_labels[ 49 ]; -static inline void drawText( int index, int x, int y, int btn_w, int btn_h ) -{ - SDL_Surface* letterSurface = surfA[ index ]; - SDL_Texture* letterTexture = textA[ index ]; - if ( letterSurface != NULL && letterTexture != NULL ) { - int texW = letterSurface->w; - int texH = letterSurface->h; - SDL_Rect destRect = { x + ( btn_w - texW ) / 2, y, texW, texH }; - SDL_RenderCopy( renderer, letterTexture, NULL, &destRect ); - } +SDL_Surface* surfaces_labels_Lshift[ 49 ]; +SDL_Texture* textures_labels_Lshift[ 49 ]; - SDL_Surface* letterSurface2 = surfB[ index ]; - SDL_Texture* letterTexture2 = label_Lshift[ index ]; - if ( letterSurface2 != NULL && letterTexture2 != NULL ) { - int texW = letterSurface2->w; - int texH = letterSurface2->h; - SDL_Rect destRect = { x + ( btn_w - texW ) / 2, y, texW, texH }; - destRect.y -= 10; - destRect.x -= 16; - SDL_RenderCopy( renderer, letterTexture2, NULL, &destRect ); - } +SDL_Surface* surfaces_labels_Rshift[ 49 ]; +SDL_Texture* textures_labels_Rshift[ 49 ]; - SDL_Surface* letterSurface3 = surfC[ index ]; - SDL_Texture* letterTexture3 = label_Rshift[ index ]; - if ( letterSurface3 != NULL && letterTexture3 != NULL ) { - int texW = letterSurface3->w; - int texH = letterSurface3->h; - SDL_Rect destRect = { x + ( btn_w - texW ) / 2, y, texW, texH }; - destRect.y -= 10; - destRect.x += 16; - SDL_RenderCopy( renderer, letterTexture3, NULL, &destRect ); - } +SDL_Surface* surfaces_labels_below[ 49 ]; +SDL_Texture* textures_labels_below[ 49 ]; - SDL_Surface* letterSurface4 = surfD[ index ]; - SDL_Texture* letterTexture4 = label_below[ index ]; - if ( letterSurface4 != NULL && letterTexture4 != NULL ) { - int texW = letterSurface4->w; - int texH = letterSurface4->h; - SDL_Rect destRect = { x + ( btn_w - texW ) / 2, y, texW, texH }; - destRect.y += 12; - destRect.x += 22; - SDL_RenderCopy( renderer, letterTexture4, NULL, &destRect ); - } -} +SDL_Surface* surfaces_labels_letter[ 49 ]; +SDL_Texture* textures_labels_letter[ 49 ]; -void SDL__gui_initKeyboard( Button* calcbuttons ) +colors_t colors = { + .faceplate = {.r = 48, .g = 68, .b = 90, .a = 255}, + + .lcd_pixoff = {.r = 119, .g = 153, .b = 136, .a = 255}, + .lcd_pixgray1 = {.r = 71, .g = 134, .b = 145, .a = 255}, + .lcd_pixgray2 = {.r = 13, .g = 108, .b = 111, .a = 255}, + .lcd_pixon = {.r = 37, .g = 61, .b = 84, .a = 255}, + + .button = {.r = 16, .g = 26, .b = 39, .a = 33 }, + .button_active = {255, 255, 39, 33 }, + .label = {255, 255, 255, 255 }, + .Lshift = {191, 192, 236, 255 }, + .Rshift = {125, 215, 235, 255 }, + .letter = {255, 255, 255, 255 }, + .below = {128, 108, 29, 255 }, +}; + +static inline void _init_keyboard_textures( Button* calcbuttons ) { printf( "init texts\n" ); if ( ttffont == NULL ) { printf( "init texts error Font NULL\n" ); return; } - SDL_Color couleurBlanche = { 255, 255, 255, 255 }; - SDL_Color couleurGreen = { 125, 215, 235, 255 }; - SDL_Color couleurPurple = { 191, 192, 236, 255 }; - SDL_Color couleurYellow = { 128, 108, 29, 255 }; SDL_Surface* s = NULL; SDL_Texture* t = NULL; @@ -96,14 +74,14 @@ void SDL__gui_initKeyboard( Button* calcbuttons ) s = NULL; t = NULL; if ( buttons->label && strcmp( buttons->label, "" ) != 0 ) { - s = TTF_RenderUTF8_Blended( ttffont, buttons->label, couleurBlanche ); + s = TTF_RenderUTF8_Blended( ttffont, buttons->label, colors.label ); if ( s ) { t = SDL_CreateTextureFromSurface( renderer, s ); } } - surfA[ i ] = s; - textA[ i ] = t; + surfaces_labels[ i ] = s; + textures_labels[ i ] = t; i++; buttons++; @@ -115,13 +93,13 @@ void SDL__gui_initKeyboard( Button* calcbuttons ) s = NULL; t = NULL; if ( buttons->label_Lshift && strcmp( buttons->label_Lshift, "" ) != 0 ) { - s = TTF_RenderUTF8_Blended( ttffont2, buttons->label_Lshift, couleurPurple ); + s = TTF_RenderUTF8_Blended( ttffont2, buttons->label_Lshift, colors.Lshift ); if ( s ) { t = SDL_CreateTextureFromSurface( renderer, s ); } } - surfB[ i ] = s; - label_Lshift[ i ] = t; + surfaces_labels_Lshift[ i ] = s; + textures_labels_Lshift[ i ] = t; i++; buttons++; } @@ -132,63 +110,125 @@ void SDL__gui_initKeyboard( Button* calcbuttons ) s = NULL; t = NULL; if ( buttons->label_Rshift && strcmp( buttons->label_Rshift, "" ) != 0 ) { - s = TTF_RenderUTF8_Blended( ttffont2, buttons->label_Rshift, couleurGreen ); + s = TTF_RenderUTF8_Blended( ttffont2, buttons->label_Rshift, colors.Rshift ); if ( s ) { t = SDL_CreateTextureFromSurface( renderer, s ); } } - surfC[ i ] = s; - label_Rshift[ i ] = t; + surfaces_labels_Rshift[ i ] = s; + textures_labels_Rshift[ i ] = t; i++; buttons++; } i = 0; buttons = calcbuttons; - while ( buttons->label_Rshift ) { + while ( buttons->label_below ) { s = NULL; t = NULL; if ( buttons->label_below && strcmp( buttons->label_below, "" ) != 0 ) { - s = TTF_RenderUTF8_Blended( ttffont2, buttons->label_below, couleurYellow ); + s = TTF_RenderUTF8_Blended( ttffont2, buttons->label_below, colors.letter ); if ( s ) { t = SDL_CreateTextureFromSurface( renderer, s ); } } - surfD[ i ] = s; - label_below[ i ] = t; + surfaces_labels_below[ i ] = s; + textures_labels_below[ i ] = t; + i++; + buttons++; + } + + i = 0; + buttons = calcbuttons; + while ( buttons->label_letter ) { + s = NULL; + t = NULL; + if ( buttons->label_letter && strcmp( buttons->label_letter, "" ) != 0 ) { + s = TTF_RenderUTF8_Blended( ttffont2, buttons->label_letter, colors.below ); + if ( s ) { + t = SDL_CreateTextureFromSurface( renderer, s ); + } + } + surfaces_labels_letter[ i ] = s; + textures_labels_letter[ i ] = t; i++; buttons++; } } -static inline void SDL__button_draw( Button* b ) +static inline void _draw_button_labels( int index, int x, int y, int btn_w, int btn_h ) { - SDL_Rect rectToDraw = { b->x * UI_SCALE, b->y * UI_SCALE, b->w * UI_SCALE, b->h * UI_SCALE }; + int texW; + int texH; + int h_padding = 3; - SDL_SetRenderDrawColor( renderer, 0x00, 0x00, 0x00, 0x33 ); + SDL_Surface* surface_label = surfaces_labels[ index ]; + SDL_Texture* texture_label = textures_labels[ index ]; + if ( surface_label != NULL && texture_label != NULL ) { + texW = surface_label->w; + texH = surface_label->h; + SDL_Rect destRect = { x + ( btn_w - texW ) / 2, y + ( btn_h / 3 ), texW, texH }; + SDL_RenderCopy( renderer, texture_label, NULL, &destRect ); + } + + SDL_Surface* surface_label_Lshift = surfaces_labels_Lshift[ index ]; + SDL_Texture* texture_label_Lshift = textures_labels_Lshift[ index ]; + if ( surface_label_Lshift != NULL && texture_label_Lshift != NULL ) { + texW = surface_label_Lshift->w; + texH = surface_label_Lshift->h; + SDL_Rect destRect = { x + h_padding, y, texW, texH }; + SDL_RenderCopy( renderer, texture_label_Lshift, NULL, &destRect ); + } + + SDL_Surface* surface_label_Rshift = surfaces_labels_Rshift[ index ]; + SDL_Texture* texture_label_Rshift = textures_labels_Rshift[ index ]; + if ( surface_label_Rshift != NULL && texture_label_Rshift != NULL ) { + texW = surface_label_Rshift->w; + texH = surface_label_Rshift->h; + SDL_Rect destRect = { ( x + btn_w ) - ( texW + h_padding ), y, texW, texH }; + if ( surface_label_Lshift == NULL ) + destRect.x = x + ( btn_w - texW ) / 2; + SDL_RenderCopy( renderer, texture_label_Rshift, NULL, &destRect ); + } + + SDL_Surface* surface_label_letter = surfaces_labels_letter[ index ]; + SDL_Texture* texture_label_letter = textures_labels_letter[ index ]; + if ( surface_label_letter != NULL && texture_label_letter != NULL ) { + texW = surface_label_letter->w; + texH = surface_label_letter->h; + SDL_Rect destRect = { ( x + btn_w ) - ( texW / 2 ), y + ( btn_h - ( 5 * UI_SCALE ) ), texW, texH }; + SDL_RenderCopy( renderer, texture_label_letter, NULL, &destRect ); + } + + SDL_Surface* surface_label_below = surfaces_labels_below[ index ]; + SDL_Texture* texture_label_below = textures_labels_below[ index ]; + if ( surface_label_below != NULL && texture_label_below != NULL ) { + texW = surface_label_below->w; + texH = surface_label_below->h; + SDL_Rect destRect = { x + ( btn_w - texW ) / 2, y + ( btn_h - ( 3 * UI_SCALE ) ), texW, texH }; + SDL_RenderCopy( renderer, texture_label_below, NULL, &destRect ); + } +} + +static inline void _button_draw( Button* b ) +{ + SDL_Rect rectToDraw = { ( b->x + ( UI_KEY_PADDING / 2 ) ) * UI_SCALE, ( b->y + ( UI_KEY_PADDING * 1.25 ) ) * UI_SCALE, + ( b->w - UI_KEY_PADDING ) * UI_SCALE, ( b->h - ( UI_KEY_PADDING * 2 ) ) * UI_SCALE }; + + SDL_SetRenderDrawColor( renderer, colors.button.r, colors.button.g, colors.button.g, colors.button.a ); SDL_RenderFillRect( renderer, &rectToDraw ); - drawText( b->index, b->x * UI_SCALE, 10 + b->y * UI_SCALE, b->w * UI_SCALE, b->h * UI_SCALE ); + if ( b->flags & BUTTON_PUSHED ) + SDL_SetRenderDrawColor( renderer, colors.button_active.r, colors.button_active.g, colors.button_active.b, colors.button_active.a ); + else + SDL_SetRenderDrawColor( renderer, colors.button.r, colors.button.g, colors.button.b, colors.button.a ); - if ( b->flags & BUTTON_PUSHED ) { - SDL_SetRenderDrawColor( renderer, 0xFF, 0x00, 0x00, 0xFF ); - SDL_RenderDrawRect( renderer, &rectToDraw ); - } else { - // debug only - SDL_SetRenderDrawColor( renderer, 0xFF, 0xFF, 0xFF, 0xFF ); - SDL_RenderDrawRect( renderer, &rectToDraw ); - } + SDL_RenderDrawRect( renderer, &rectToDraw ); + + _draw_button_labels( b->index, b->x * UI_SCALE, b->y * UI_SCALE, b->w * UI_SCALE, b->h * UI_SCALE ); } -void button_draw_all( Button* buttons ) -{ - while ( buttons->label ) { - SDL__button_draw( buttons ); - buttons++; - } -} - -static inline Button* find_button( Button* b, int x, int y ) +static inline Button* _find_button( Button* b, int x, int y ) { while ( b->label ) { if ( x >= b->x * UI_SCALE && x < b->x * UI_SCALE + b->w * UI_SCALE && y >= b->y * UI_SCALE && @@ -201,9 +241,9 @@ static inline Button* find_button( Button* b, int x, int y ) return NULL; } -int button_mouse_down( Button* buttons, int mx, int my, int mb ) +static inline int _button_mouse_down( Button* buttons, int mx, int my, int mb ) { - Button* b = find_button( buttons, mx, my ); + Button* b = _find_button( buttons, mx, my ); if ( !b ) return 0; @@ -232,9 +272,9 @@ int button_mouse_down( Button* buttons, int mx, int my, int mb ) return 1; } -int button_mouse_up( Button* buttons, int mx, int my, int mb ) +static inline int _button_mouse_up( Button* buttons, int mx, int my, int mb ) { - Button* b = find_button( buttons, mx, my ); + Button* b = _find_button( buttons, mx, my ); int ret = ( b != NULL ); if ( b && !( b->flags & BUTTON_DISABLED ) ) { @@ -260,16 +300,13 @@ int button_mouse_up( Button* buttons, int mx, int my, int mb ) return ret; } -SDL_Window* window = NULL; -SDL_Renderer* renderer = NULL; -SDL_Texture* texTarget = NULL; -SDL_Texture* tex2Target = NULL; -SDL_Texture* faceplateTexture = NULL; - -TTF_Font* ttffont = NULL; -TTF_Font* ttffont2 = NULL; - -bool SDL_ready = false; +void button_draw_all( Button* buttons ) +{ + while ( buttons->label ) { + _button_draw( buttons ); + buttons++; + } +} bool gui_refresh() { @@ -278,11 +315,11 @@ bool gui_refresh() while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case SDL_MOUSEBUTTONUP: - button_mouse_up( calc_buttons, event.button.x, event.button.y, 1 ); + _button_mouse_up( calc_buttons, event.button.x, event.button.y, 1 ); break; case SDL_MOUSEBUTTONDOWN: - button_mouse_down( calc_buttons, event.button.x, event.button.y, 1 ); + _button_mouse_down( calc_buttons, event.button.x, event.button.y, 1 ); break; case SDL_KEYDOWN: @@ -645,8 +682,8 @@ void gui_init( void ) exit( EXIT_FAILURE ); } - ttffont = TTF_OpenFont( FONT_FILENAME, 6 * UI_SCALE ); - ttffont2 = TTF_OpenFont( FONT_FILENAME, 4 * UI_SCALE ); + ttffont = TTF_OpenFont( config.ui_font, 7 * UI_SCALE ); + ttffont2 = TTF_OpenFont( config.ui_font, 5 * UI_SCALE ); int window_width = ( LCD_WIDTH + ( 2 * UI_PADDING ) ) * UI_SCALE; int window_height = ( UI_KB_OFFSET_Y + UI_KB_HEIGHT ) + 2 * UI_PADDING; @@ -668,12 +705,10 @@ void gui_init( void ) SDL_UpdateWindowSurface( window ); - SDL__gui_initKeyboard( calc_buttons ); + _init_keyboard_textures( calc_buttons ); printf( "init done\n" ); - color_init(); - SDL_ready = true; } diff --git a/src/gui.h b/src/gui.h index c3fd61c..c798551 100644 --- a/src/gui.h +++ b/src/gui.h @@ -1,38 +1,36 @@ #ifndef __GUI_H #define __GUI_H -#include "types.h" +#include -#define FONT_FILENAME "/usr/share/fonts/TTF/unifont.ttf" +#include "types.h" #define UI_SCALE 4 #define UI_PADDING 4 +#define UI_KEY_PADDING 4 #define ANNUNC_X UI_PADDING #define ANNUNC_Y UI_PADDING #define ANNUNC_HEIGHT 8 #define LCD_X UI_PADDING -#define LCD_Y ( UI_PADDING + ANNUNC_HEIGHT ) +#define LCD_Y ( UI_PADDING + ANNUNC_HEIGHT + UI_PADDING ) -#define UI_K_WIDTH_1 19 -#define UI_K_HEIGHT_1 10 -#define UI_K_WIDTH_2 23 -#define UI_K_HEIGHT_2 12 -#define UI_KB_GAP_X 3 +#define UI_K_WIDTH_1 22 +#define UI_K_HEIGHT_1 ( UI_K_WIDTH_1 * 0.65 ) +#define UI_K_WIDTH_2 26 +#define UI_K_HEIGHT_2 ( UI_K_WIDTH_2 * 0.65 ) -#define UI_KB_OFFSET_X 1 -#define UI_KB_OFFSET_Y ( UI_PADDING + ANNUNC_HEIGHT + LCD_HEIGHT + UI_PADDING + UI_K_HEIGHT_2 ) -#define UI_KB_GAP_Y 10 +#define UI_KB_OFFSET_Y ( UI_PADDING + ANNUNC_HEIGHT + LCD_HEIGHT + UI_PADDING ) -#define UI_K_WIDTH_enter ( ( UI_K_WIDTH_1 * 2 ) + UI_KB_GAP_X ) +#define UI_K_WIDTH_enter ( UI_K_WIDTH_1 * 2 ) -#define Y_LINE( i ) ( UI_KB_OFFSET_Y + ( i * ( UI_KB_GAP_Y + 10 ) ) ) -#define X_COL( i ) ( UI_PADDING + UI_KB_OFFSET_X + ( ( UI_K_WIDTH_1 + UI_KB_GAP_X ) * i ) ) -#define X2_COL( i ) ( UI_PADDING + UI_KB_OFFSET_X + ( ( UI_K_WIDTH_2 + UI_KB_GAP_X ) * i ) ) +#define Y_LINE( i ) ( UI_KB_OFFSET_Y + ( i * UI_K_HEIGHT_2 ) ) +#define X_COL( i ) ( UI_PADDING + ( UI_K_WIDTH_1 * i ) ) +#define X2_COL( i ) ( UI_PADDING + ( UI_K_WIDTH_2 * i ) ) -#define UI_KB_HEIGHT ( UI_SCALE * ( Y_LINE( 9 ) + UI_K_HEIGHT_2 + UI_KB_GAP_Y ) ) +#define UI_KB_HEIGHT ( UI_SCALE * Y_LINE( 9 ) ) typedef struct { int index; @@ -42,11 +40,35 @@ typedef struct { char* label; char* label_Lshift; char* label_Rshift; + char* label_letter; char* label_below; void ( *down )( void ); void ( *up )( void ); } Button; +typedef struct { + SDL_Color faceplate; + + SDL_Color lcd_pixoff; + SDL_Color lcd_pixgray1; + SDL_Color lcd_pixgray2; + SDL_Color lcd_pixon; + + SDL_Color button; + SDL_Color button_active; + SDL_Color label; + SDL_Color Lshift; + SDL_Color Rshift; + SDL_Color letter; + SDL_Color below; +} colors_t; +extern colors_t colors; + +extern SDL_Renderer* renderer; +extern SDL_Window* window; +extern SDL_Texture* texTarget; +extern SDL_Texture* tex2Target; + extern bool SDL_ready; /* Button flags: @@ -65,11 +87,7 @@ extern bool SDL_ready; // Releaseing mouse button 1 anywhere unpushes the button #define BUTTON_B1RELEASE 0x10 -extern void SDL__gui_initKeyboard( Button* calcbuttons ); - extern void button_draw_all( /*BITMAP *bmp,*/ Button* buttons ); -extern int button_mouse_down( /*BITMAP *bmp,*/ Button* butons, int mx, int my, int mb ); -extern int button_mouse_up( /*BITMAP *bmp,*/ Button* buttons, int mx, int my, int mb ); extern bool gui_refresh(); extern void gui_init( void ); diff --git a/src/gui_buttons.c b/src/gui_buttons.c index 4e1831b..9265c15 100644 --- a/src/gui_buttons.c +++ b/src/gui_buttons.c @@ -1,6 +1,5 @@ #include -#include "gui_color.h" #include "display.h" #include "keyboard.h" #include "gui.h" @@ -10,66 +9,66 @@ const int std_flags = BUTTON_B1RELEASE | BUTTON_B2TOGGLE; Button calc_buttons[] = { - {0, X_COL( 0 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "A", press_A, release_A }, - {1, X_COL( 1 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "B", press_B, release_B }, - {2, X_COL( 2 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "C", press_C, release_C }, - {3, X_COL( 3 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "D", press_D, release_D }, - {4, X_COL( 4 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "E", press_E, release_E }, - {5, X_COL( 5 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "F", press_F, release_F }, + {0, X_COL( 0 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "A", "", press_A, release_A }, + {1, X_COL( 1 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "B", "", press_B, release_B }, + {2, X_COL( 2 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "C", "", press_C, release_C }, + {3, X_COL( 3 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "D", "", press_D, release_D }, + {4, X_COL( 4 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "E", "", press_E, release_E }, + {5, X_COL( 5 ), Y_LINE( 0 ), UI_K_WIDTH_1, UI_K_HEIGHT_1, std_flags, "█", "", "", "F", "", press_F, release_F }, - {6, X_COL( 0 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "MTH", "RAD", "POLAR", "G", press_MTH, release_MTH }, - {7, X_COL( 1 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "PRG", "", "CHARS", "H", press_PRG, release_PRG }, - {8, X_COL( 2 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "CST", "", "MODES", "I", press_CST, release_CST }, - {9, X_COL( 3 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "VAR", "", "MEMORY", "J", press_VAR, release_VAR }, - {10, X_COL( 4 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "▲", "", "STACK", "K", press_UP, release_UP }, - {11, X_COL( 5 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "NXT", "PREV", "MENU", "L", press_NXT, release_NXT }, + {6, X_COL( 0 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "MTH", "RAD", "POLAR", "G", "", press_MTH, release_MTH }, + {7, X_COL( 1 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "PRG", "", "CHARS", "H", "", press_PRG, release_PRG }, + {8, X_COL( 2 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "CST", "", "MODES", "I", "", press_CST, release_CST }, + {9, X_COL( 3 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "VAR", "", "MEMORY", "J", "", press_VAR, release_VAR }, + {10, X_COL( 4 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "▲", "", "STACK", "K", "", press_UP, release_UP }, + {11, X_COL( 5 ), Y_LINE( 1 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "NXT", "PREV", "MENU", "L", "", press_NXT, release_NXT }, - {12, X_COL( 0 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "'", "UP", "HOME", "M", press_QUOTE, release_QUOTE }, - {13, X_COL( 1 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "STO", "REF", "RCL", "N", press_STO, release_STO }, - {14, X_COL( 2 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "EVAL", "->NUM", "UNDO", "O", press_EVAL, release_EVAL }, - {15, X_COL( 3 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "◀", "PICTURE", "", "P", press_LEFT, release_LEFT }, - {16, X_COL( 4 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "▼", "VIEW", "", "Q", press_DOWN, release_DOWN }, - {17, X_COL( 5 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "▶", "SWAP", "", "R", press_RIGHT, release_RIGHT }, + {12, X_COL( 0 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "'", "UP", "HOME", "M", "", press_QUOTE, release_QUOTE }, + {13, X_COL( 1 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "STO", "REF", "RCL", "N", "", press_STO, release_STO }, + {14, X_COL( 2 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "EVAL", "→NUM", "UNDO", "O", "", press_EVAL, release_EVAL }, + {15, X_COL( 3 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "◀", "", "PICTURE", "P", "", press_LEFT, release_LEFT }, + {16, X_COL( 4 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "▼", "", "VIEW", "Q", "", press_DOWN, release_DOWN }, + {17, X_COL( 5 ), Y_LINE( 2 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "▶", "", "SWAP", "R", "", press_RIGHT, release_RIGHT }, - {18, X_COL( 0 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "SIN", "ASIN", "tet", "S", press_SIN, release_SIN }, - {19, X_COL( 1 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "COS", "ACOS", "", "T", press_COS, release_COS }, - {20, X_COL( 2 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "TAN", "ATAN", "Sig", "U", press_TAN, release_TAN }, - {21, X_COL( 3 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "√x", "xx", "x√y", "V", press_SQRT, release_SQRT }, - {22, X_COL( 4 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "y^x", "⏨x", "LOG", "W", press_POW, release_POW }, - {23, X_COL( 5 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "1/x", "ex", "LN", "X", press_INV, release_INV }, + {18, X_COL( 0 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "SIN", "ASIN", "𝛛", "S", "", press_SIN, release_SIN }, + {19, X_COL( 1 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "COS", "ACOS", "∫", "T", "", press_COS, release_COS }, + {20, X_COL( 2 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "TAN", "ATAN", "𝚺", "U", "", press_TAN, release_TAN }, + {21, X_COL( 3 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "√x", "x²", "x√y", "V", "", press_SQRT, release_SQRT }, + {22, X_COL( 4 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "y^x", "⏨^x", "LOG", "W", "", press_POW, release_POW }, + {23, X_COL( 5 ), Y_LINE( 3 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "1/x", "e^x", "LN", "X", "", press_INV, release_INV }, - {24, X_COL( 0 ), Y_LINE( 4 ), UI_K_WIDTH_enter, UI_K_HEIGHT_2, std_flags, "ENTER", "EQUATION", "MATRIX", "", press_ENTER, - release_ENTER }, - {25, X_COL( 2 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "±", "EDIT", "CMD", "Y", press_NEG, release_NEG }, - {26, X_COL( 3 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "EEX", "PURG", "ARG", "Z", press_EEX, release_EEX }, - {27, X_COL( 4 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "DEL", "CLEAR", "", "", press_DEL, release_DEL }, - {28, X_COL( 5 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "←", "DROP", "", "", press_BKSP, release_BKSP }, + {24, X_COL( 0 ), Y_LINE( 4 ), UI_K_WIDTH_enter, UI_K_HEIGHT_2, std_flags, "ENTER", "EQUATION", "MATRIX", "", "", press_ENTER, + release_ENTER }, + {25, X_COL( 2 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "±", "EDIT", "CMD", "Y", "", press_NEG, release_NEG }, + {26, X_COL( 3 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "EEX", "PURG", "ARG", "Z", "", press_EEX, release_EEX }, + {27, X_COL( 4 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "DEL", "", "CLEAR", "", "", press_DEL, release_DEL }, + {28, X_COL( 5 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "←", "", "DROP", "", "", press_BKSP, release_BKSP }, - {29, X_COL( 0 ), Y_LINE( 5 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "α", "USER", "ENTRY", "", press_ALPHA, release_ALPHA }, - {30, X2_COL( 1 ), Y_LINE( 5 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "7", "", "SOLVE", "", press_7, release_7 }, - {31, X2_COL( 2 ), Y_LINE( 5 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "8", "", "PLOT", "", press_8, release_8 }, - {32, X2_COL( 3 ), Y_LINE( 5 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "9", "", "SYMBOLIC", "", press_9, release_9 }, - {33, X2_COL( 4 ) + 2, Y_LINE( 5 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "÷", "( )", "#", "", press_DIV, release_DIV }, + {29, X_COL( 0 ), Y_LINE( 5 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "α", "USER", "ENTRY", "", "", press_ALPHA, release_ALPHA }, + {30, X2_COL( 1 ), Y_LINE( 5 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "7", "", "SOLVE", "", "", press_7, release_7 }, + {31, X2_COL( 2 ), Y_LINE( 5 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "8", "", "PLOT", "", "", press_8, release_8 }, + {32, X2_COL( 3 ), Y_LINE( 5 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "9", "", "SYMBOLIC", "", "", press_9, release_9 }, + {33, X2_COL( 4 ) + 2, Y_LINE( 5 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "÷", "( )", "#", "", "", press_DIV, release_DIV }, - {34, X_COL( 0 ), Y_LINE( 6 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "⮢", "red", "", "", press_LSHIFT, release_LSHIFT }, - {35, X2_COL( 1 ), Y_LINE( 6 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "4", "", "TIME", "", press_4, release_4 }, - {36, X2_COL( 2 ), Y_LINE( 6 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "5", "", "STAT", "", press_5, release_5 }, - {37, X2_COL( 3 ), Y_LINE( 6 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "6", "", "UNITS", "", press_6, release_6 }, - {38, X2_COL( 4 ) + 2, Y_LINE( 6 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "×", "[ ]", "_", "", press_MULT, release_MULT }, + {34, X_COL( 0 ), Y_LINE( 6 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "⮢", "", "", "", "", press_LSHIFT, release_LSHIFT }, + {35, X2_COL( 1 ), Y_LINE( 6 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "4", "", "TIME", "", "", press_4, release_4 }, + {36, X2_COL( 2 ), Y_LINE( 6 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "5", "", "STAT", "", "", press_5, release_5 }, + {37, X2_COL( 3 ), Y_LINE( 6 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "6", "", "UNITS", "", "", press_6, release_6 }, + {38, X2_COL( 4 ) + 2, Y_LINE( 6 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "×", "[ ]", "_", "", "", press_MULT, release_MULT }, - {39, X_COL( 0 ), Y_LINE( 7 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "⮣", "", "green", "", press_RSHIFT, release_RSHIFT }, - {40, X2_COL( 1 ), Y_LINE( 7 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "1", "", "I/O", "", press_1, release_1 }, - {41, X2_COL( 2 ), Y_LINE( 7 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "2", "", "LIBRARY", "", press_2, release_2 }, - {42, X2_COL( 3 ), Y_LINE( 7 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "3", "", "EQ LIB", "", press_3, release_3 }, - {43, X2_COL( 4 ) + 2, Y_LINE( 7 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "-", "« »", "\" \"", "", press_MINUS, release_MINUS }, + {39, X_COL( 0 ), Y_LINE( 7 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "⮣", "", "", "", "", press_RSHIFT, release_RSHIFT }, + {40, X2_COL( 1 ), Y_LINE( 7 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "1", "", "I/O", "", "", press_1, release_1 }, + {41, X2_COL( 2 ), Y_LINE( 7 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "2", "", "LIBRARY", "", "", press_2, release_2 }, + {42, X2_COL( 3 ), Y_LINE( 7 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "3", "", "EQ LIB", "", "", press_3, release_3 }, + {43, X2_COL( 4 ) + 2, Y_LINE( 7 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "-", "« »", "\" \"", "", "", press_MINUS, release_MINUS }, - {44, X_COL( 0 ), Y_LINE( 8 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "ON", "CONT", "OFF", "CANCEL", press_ON, release_ON }, - {45, X2_COL( 1 ), Y_LINE( 8 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "0", "=", "->", "", press_0, release_0 }, - {46, X2_COL( 2 ), Y_LINE( 8 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, ".", ",", "back", "", press_PERIOD, release_PERIOD }, - {47, X2_COL( 3 ), Y_LINE( 8 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "SPC", "pi", "rad", "", press_SPC, release_SPC }, - {48, X2_COL( 4 ) + 2, Y_LINE( 8 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "+", "{}", ": :", "", press_PLUS, release_PLUS }, + {44, X_COL( 0 ), Y_LINE( 8 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "ON", "CONT", "OFF", "", "CANCEL", press_ON, release_ON }, + {45, X2_COL( 1 ), Y_LINE( 8 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "0", "=", "→", "", "", press_0, release_0 }, + {46, X2_COL( 2 ), Y_LINE( 8 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, ".", ",", "⮐", "", "", press_PERIOD, release_PERIOD }, + {47, X2_COL( 3 ), Y_LINE( 8 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "SPC", "𝛑", "⦨", "", "", press_SPC, release_SPC }, + {48, X2_COL( 4 ) + 2, Y_LINE( 8 ), UI_K_WIDTH_2, UI_K_HEIGHT_2, std_flags, "+", "{ }", ": :", "", "", press_PLUS, release_PLUS }, - {49, X_COL( 0 ), Y_LINE( 9 ), 40, UI_K_HEIGHT_2, std_flags, "load file", "", "", "", press_LoadFile, release_LoadFile}, + {49, X_COL( 0 ), Y_LINE( 9 ), 40, UI_K_HEIGHT_2, std_flags, "load file", "", "", "", "", press_LoadFile, release_LoadFile}, }; void press_PLUS( void ) { kbd_key_pressed( 0, 0 ); } diff --git a/src/gui_color.c b/src/gui_color.c deleted file mode 100644 index f1ef3e2..0000000 --- a/src/gui_color.c +++ /dev/null @@ -1,57 +0,0 @@ -#include - -#include "gui_color.h" - -#define RESERVED_LCD 128 - -enum LCD_Modes { LCD_MODE_SIMPLE, LCD_MODE_GRAY4, LCD_MODE_GRAY8, LCD_MODE_EXP }; - -int color[ C_COUNT ]; - -static int lcd_0_r, lcd_0_g, lcd_0_b; -static int lcd_1_r, lcd_1_g, lcd_1_b; -static int lcd_mode; - -static int bit_count( unsigned int i ) -{ - int n = 0; - - while ( i ) { - n += i & 1; - i >>= 1; - } - return n; -} - -static int simple_color( int i ) { return ( i & 0x40 ) ? 255 : 0; } - -static int gray4_color( int i ) { return bit_count( i & 0x70 ) * 85; } - -static int gray8_color( int i ) { return bit_count( i ) * 255 / 7; } - -static int exp_color( int i ) { return i * 255 / 127; } - -typedef int ( *lcd_color_func )( int i ); - -lcd_color_func lcd_color_functions[] = { simple_color, gray4_color, gray8_color, exp_color }; - -static inline void color_lcd( int r0, int g0, int b0, int r1, int g1, int b1 ) -{ - lcd_0_r = r0 >> 2; - lcd_0_g = g0 >> 2; - lcd_0_b = b0 >> 2; - lcd_1_r = r1 >> 2; - lcd_1_g = g1 >> 2; - lcd_1_b = b1 >> 2; -} - -static inline void color_lcd_mode( int mode ) { lcd_mode = mode; } - -void color_init( void ) -{ - for ( int i = 0; i < C_COUNT; i++ ) - color[ i ] = RESERVED_LCD + i; - - color_lcd( 128, 192, 128, 0, 0, 64 ); - color_lcd_mode( LCD_MODE_GRAY4 ); -} diff --git a/src/gui_color.h b/src/gui_color.h deleted file mode 100644 index 96c6f6a..0000000 --- a/src/gui_color.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __COLOR_H -#define __COLOR_H - -enum Colors { - C_BACKGROUND, - C_PANEL_BACK, - C_PANEL_BORDER, - C_PANEL_TEXT, - C_PANEL_DISABLED, - C_BUTTON_BACK, - C_BUTTON_BORDER, - C_BUTTON_PUSHED, - C_BUTTON_TEXT, - C_BUTTON_DISABLED, - C_COUNT -}; - -extern int color[ C_COUNT ]; - -extern void color_init( void ); - -#endif diff --git a/src/gui_display.c b/src/gui_display.c index c56e4ca..ce1a59a 100644 --- a/src/gui_display.c +++ b/src/gui_display.c @@ -7,22 +7,11 @@ #include "gui.h" #include "gui_buttons.h" -extern SDL_Renderer* renderer; -extern SDL_Window* window; -extern SDL_Texture* texTarget; -extern SDL_Texture* tex2Target; -extern SDL_Texture* faceplateTexture; - void SDL__display_show() { - SDL_SetRenderDrawColor( renderer, 48, 68, 90, 0xFF ); // bleu foncé + SDL_SetRenderDrawColor( renderer, colors.faceplate.r, colors.faceplate.g, colors.faceplate.b, colors.faceplate.a ); SDL_RenderClear( renderer ); - if ( faceplateTexture ) { - SDL_Rect r3 = { 8, 0, 504, 1124 }; - SDL_RenderCopy( renderer, faceplateTexture, NULL, &r3 ); - } - if ( shouldRender == true ) { shouldRender = false; @@ -49,21 +38,21 @@ void SDL__display_show() byte hp48pixel = lcdScreenGS[ x + y * LCD_WIDTH ]; if ( hp48pixel == '\0' ) { - R = 119; - G = 153; - B = 136; + R = colors.lcd_pixoff.r; + G = colors.lcd_pixoff.g; + B = colors.lcd_pixoff.b; } else if ( hp48pixel == '\1' ) { - R = 71; // 200; - G = 134; // 20; - B = 145; // 20; + R = colors.lcd_pixgray1.r; + G = colors.lcd_pixgray1.g; + B = colors.lcd_pixgray1.b; } else if ( hp48pixel == '\2' ) { - R = 13; // 20; - G = 108; // 200; - B = 111; // 20; + R = colors.lcd_pixgray2.r; + G = colors.lcd_pixgray2.g; + B = colors.lcd_pixgray2.b; } else if ( hp48pixel == '\3' ) { - R = 37; - G = 61; - B = 84; + R = colors.lcd_pixon.r; + G = colors.lcd_pixon.g; + B = colors.lcd_pixon.b; } // Now you want to format the color to a correct format that SDL