diff --git a/src/display.c b/src/display.c index d6b3633..5249941 100644 --- a/src/display.c +++ b/src/display.c @@ -184,7 +184,7 @@ void display_show() // Show rendered to texture SDL_Rect r1 = { 0, 0, LCD_WIDTH, LCD_HEIGHT }; - SDL_Rect r2 = { LCD_X, LCD_Y, LCD_WIDTH * LCD_SCALE, LCD_HEIGHT * LCD_SCALE }; + SDL_Rect r2 = { LCD_X * UI_SCALE, LCD_Y * UI_SCALE, LCD_WIDTH * UI_SCALE, LCD_HEIGHT * UI_SCALE }; SDL_RenderCopyEx( renderer, texTarget, &r1, &r2, 0, NULL, SDL_FLIP_NONE ); button_draw_all( calc_buttons ); diff --git a/src/gui.c b/src/gui.c index 6430383..dfaae48 100644 --- a/src/gui.c +++ b/src/gui.c @@ -161,12 +161,12 @@ void gui_initKeyboard( Button* calcbuttons ) static inline void button_draw( Button* b ) { - SDL_Rect rectToDraw = { b->x * KB_UI_SCALE, b->y * KB_UI_SCALE, b->w * KB_UI_SCALE, b->h * KB_UI_SCALE }; + SDL_Rect rectToDraw = { b->x * UI_SCALE, b->y * UI_SCALE, b->w * UI_SCALE, b->h * UI_SCALE }; SDL_SetRenderDrawColor( renderer, 0x00, 0x00, 0x00, 0x33 ); SDL_RenderFillRect( renderer, &rectToDraw ); - drawText( b->index, b->x * KB_UI_SCALE, 10 + b->y * KB_UI_SCALE, b->w * KB_UI_SCALE, b->h * KB_UI_SCALE ); + 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, 0xFF, 0x00, 0x00, 0xFF ); @@ -189,8 +189,8 @@ void button_draw_all( Button* buttons ) static inline Button* find_button( Button* b, int x, int y ) { while ( b->label ) { - if ( x >= b->x * KB_UI_SCALE && x < b->x * KB_UI_SCALE + b->w * KB_UI_SCALE && y >= b->y * KB_UI_SCALE && - y < b->y * KB_UI_SCALE + b->h * KB_UI_SCALE ) + if ( x >= b->x * UI_SCALE && x < b->x * UI_SCALE + b->w * UI_SCALE && y >= b->y * UI_SCALE && + y < b->y * UI_SCALE + b->h * UI_SCALE ) return b; b++; diff --git a/src/gui.h b/src/gui.h index 73625ae..c9e6f05 100644 --- a/src/gui.h +++ b/src/gui.h @@ -1,45 +1,41 @@ #ifndef __GUI_H #define __GUI_H -#define FONT_FILENAME "/usr/share/fonts/TTF/unifont.ttf" - #include "types.h" -#define UI_PADDING 16 +#define FONT_FILENAME "/usr/share/fonts/TTF/unifont.ttf" + +#define UI_SCALE 4 + +#define UI_PADDING 4 + #define ANNUNC_X UI_PADDING #define ANNUNC_Y UI_PADDING #define ANNUNC_HEIGHT 32 #define LCD_X UI_PADDING -#define LCD_Y UI_PADDING + ANNUNC_HEIGHT +#define LCD_Y ( UI_PADDING + ANNUNC_HEIGHT ) #define LCD_WIDTH 131 #define LCD_HEIGHT 64 -#define LCD_SCALE 4 -#define KB_UI_SCALE 2 +#define UI_K_WIDTH_1 ( LCD_WIDTH / 8 ) +#define UI_KB_GAP_X ( UI_K_WIDTH_1 / 2.66 ) +#define UI_K_HEIGHT_1 10 -#define UI_K_WIDTH_1 ( ( LCD_WIDTH * KB_UI_SCALE ) / 8 ) -#define UI_K_HEIGHT_1 18 +#define UI_K_WIDTH_2 ( UI_K_WIDTH_1 * 1.275 ) +#define UI_KB_GAP_X2 UI_KB_GAP_X +#define UI_K_HEIGHT_2 12 -#define UI_K_WIDTH_2 ( ( ( LCD_WIDTH * KB_UI_SCALE ) - UI_KB_GAP_X ) / 6 ) -#define UI_K_HEIGHT_2 22 - -#define UI_KB_OFFSET_X 10 -#define UI_KB_GAP_X ( UI_K_WIDTH_1 / 3 ) -#define UI_KB_GAP_X2 ( UI_K_WIDTH_2 / 4 ) - -#define UI_KB_OFFSET_Y ( LCD_Y + ( LCD_HEIGHT * KB_UI_SCALE ) ) -#define UI_KB_GAP_Y 14 +#define UI_KB_OFFSET_Y ( LCD_Y + LCD_HEIGHT ) +#define UI_KB_GAP_Y 6 #define UI_K_WIDTH_enter ( ( UI_K_WIDTH_1 * 2 ) + UI_KB_GAP_X ) #define Y_LINE( i ) ( UI_KB_OFFSET_Y + ( i * ( UI_KB_GAP_Y + 10 ) ) ) -#define X_COL( i ) ( UI_KB_OFFSET_X + ( UI_K_WIDTH_1 * i ) + ( UI_KB_GAP_X * i ) ) -#define XE_COL( i ) ( UI_K_WIDTH_enter - UI_K_WIDTH_1 + X_COL( i ) ) -#define X2_COL( i ) ( UI_KB_OFFSET_X + ( UI_K_WIDTH_2 * i ) + ( UI_KB_GAP_X2 * ( i - 1 ) ) ) +#define X_COL( i ) ( UI_PADDING + ( ( UI_K_WIDTH_1 + UI_KB_GAP_X ) * i ) ) +#define X2_COL( i ) ( UI_PADDING + ( ( UI_K_WIDTH_2 + UI_KB_GAP_X2 ) * i ) ) -#define UI_KB_HEIGHT ( KB_UI_SCALE * ( Y_LINE( 9 ) + UI_K_HEIGHT_2 + UI_KB_GAP_Y ) ) -#define UI_KB_WIDTH ( KB_UI_SCALE * ( ( X_COL( 5 ) + UI_K_WIDTH_1 + UI_KB_OFFSET_X ) ) ) +#define UI_KB_HEIGHT ( UI_SCALE * ( Y_LINE( 9 ) + UI_K_HEIGHT_2 + UI_KB_GAP_Y ) ) typedef struct { int index; diff --git a/src/gui_buttons.c b/src/gui_buttons.c index 12950a4..017c61c 100644 --- a/src/gui_buttons.c +++ b/src/gui_buttons.c @@ -40,10 +40,10 @@ Button calc_buttons[] = { {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, XE_COL( 1 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "±", "EDIT", "CMD", "Y", press_NEG, release_NEG }, - {26, XE_COL( 2 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "EEX", "PURG", "ARG", "Z", press_EEX, release_EEX }, - {27, XE_COL( 3 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "DEL", "CLEAR", "", "", press_DEL, release_DEL }, - {28, XE_COL( 4 ), Y_LINE( 4 ), UI_K_WIDTH_1, UI_K_HEIGHT_2, std_flags, "←", "DROP", "", "", press_BKSP, release_BKSP }, + {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 }, @@ -69,7 +69,7 @@ Button calc_buttons[] = { {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 }, - {49, X_COL( 0 ), Y_LINE( 9 ), 130, 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/main.c b/src/main.c index 5299df0..1e15eff 100644 --- a/src/main.c +++ b/src/main.c @@ -68,10 +68,10 @@ static void program_init( void ) exit( EXIT_FAILURE ); } - ttffont = TTF_OpenFont( FONT_FILENAME, 16 ); - ttffont2 = TTF_OpenFont( FONT_FILENAME, 12 ); + ttffont = TTF_OpenFont( FONT_FILENAME, 6 * UI_SCALE ); + ttffont2 = TTF_OpenFont( FONT_FILENAME, 4 * UI_SCALE ); - int window_width = LCD_WIDTH * LCD_SCALE + 2 * UI_PADDING; + int window_width = LCD_WIDTH * UI_SCALE + ( 2 * UI_PADDING ); int window_height = ( UI_KB_OFFSET_Y + UI_KB_HEIGHT ) + 2 * UI_PADDING; window = SDL_CreateWindow( "hpemu", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, SDL_WINDOW_SHOWN );