naming; includes; change contrast handling logic
This commit is contained in:
parent
ed0cd5cfa5
commit
19a11f513d
3 changed files with 78 additions and 101 deletions
|
@ -11,9 +11,8 @@ int main( int argc, char** argv )
|
|||
ui_start( config_init( argc, argv ) );
|
||||
|
||||
while ( true ) {
|
||||
ui_update_LCD();
|
||||
|
||||
ui_get_event();
|
||||
ui_update_display();
|
||||
}
|
||||
|
||||
/* Never reached */
|
||||
|
|
166
src/ui.c
166
src/ui.c
|
@ -1,20 +1,9 @@
|
|||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "emulator.h"
|
||||
|
||||
#include "ui.h"
|
||||
#include "ui_inner.h"
|
||||
|
||||
|
@ -51,7 +40,6 @@ typedef struct on_off_sdl_textures_struct_t {
|
|||
/*************/
|
||||
/* variables */
|
||||
/*************/
|
||||
|
||||
letter_t small_font[ 128 ] = {
|
||||
{0, 0, 0 },
|
||||
{nl_gx_width, nl_gx_height, nl_gx_bits }, /* \x01 == \n gx */
|
||||
|
@ -2324,6 +2312,7 @@ static config_t config;
|
|||
static int display_offset_x, display_offset_y;
|
||||
static int lcd_pixels_buffer[ LCD_WIDTH * LCD_HEIGHT ];
|
||||
static int last_annunciators = -1;
|
||||
static int last_contrast = -1;
|
||||
|
||||
static color_t colors[ NB_COLORS ];
|
||||
static on_off_sdl_textures_struct_t buttons_textures[ NB_KEYS ];
|
||||
|
@ -2469,35 +2458,6 @@ static void write_with_big_font( int x, int y, const char* string, int color_fg,
|
|||
}
|
||||
}
|
||||
|
||||
static void colors_setup( void )
|
||||
{
|
||||
// Adjust the LCD color according to the contrast
|
||||
int contrast = get_contrast();
|
||||
if ( contrast < 0x3 )
|
||||
contrast = 0x3;
|
||||
if ( contrast > 0x13 )
|
||||
contrast = 0x13;
|
||||
|
||||
for ( unsigned i = FIRST_COLOR; i < LAST_COLOR; i++ ) {
|
||||
colors[ i ] = COLORS[ i ];
|
||||
if ( config.mono ) {
|
||||
colors[ i ].r = colors[ i ].mono_rgb;
|
||||
colors[ i ].g = colors[ i ].mono_rgb;
|
||||
colors[ i ].b = colors[ i ].mono_rgb;
|
||||
} else if ( config.gray ) {
|
||||
colors[ i ].r = colors[ i ].gray_rgb;
|
||||
colors[ i ].g = colors[ i ].gray_rgb;
|
||||
colors[ i ].b = colors[ i ].gray_rgb;
|
||||
}
|
||||
|
||||
if ( !config.mono && i == PIXEL ) {
|
||||
colors[ i ].r = ( 0x13 - contrast ) * ( colors[ LCD ].r / 0x10 );
|
||||
colors[ i ].g = ( 0x13 - contrast ) * ( colors[ LCD ].g / 0x10 );
|
||||
colors[ i ].b = 128 - ( ( 0x13 - contrast ) * ( ( 128 - colors[ LCD ].b ) / 0x10 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This should be called once to setup the surfaces. Calling it multiple
|
||||
// times is fine, it won't do anything on subsequent calls.
|
||||
static void create_annunciators_textures( void )
|
||||
|
@ -3177,6 +3137,70 @@ static int sdl_release_key( int hpkey )
|
|||
return hpkey;
|
||||
}
|
||||
|
||||
void ui_init_LCD( void ) { memset( lcd_pixels_buffer, 0, sizeof( lcd_pixels_buffer ) ); }
|
||||
|
||||
void sdl_update_annunciators( void )
|
||||
{
|
||||
int annunciators_bits[ NB_ANNUNCIATORS ] = { ANN_LEFT, ANN_RIGHT, ANN_ALPHA, ANN_BATTERY, ANN_BUSY, ANN_IO };
|
||||
int annunciators = get_annunciators();
|
||||
|
||||
if ( last_annunciators == annunciators )
|
||||
return;
|
||||
|
||||
last_annunciators = annunciators;
|
||||
|
||||
SDL_SetRenderTarget( renderer, main_texture );
|
||||
|
||||
for ( int i = 0; i < NB_ANNUNCIATORS; i++ )
|
||||
__draw_texture( display_offset_x + ann_tbl[ i ].x, display_offset_y + ann_tbl[ i ].y, ann_tbl[ i ].width, ann_tbl[ i ].height,
|
||||
( ( ( annunciators_bits[ i ] & annunciators ) == annunciators_bits[ i ] ) ) ? annunciators_textures[ i ].up
|
||||
: annunciators_textures[ i ].down );
|
||||
|
||||
// Always immediately update annunciators
|
||||
SDL_SetRenderTarget( renderer, NULL );
|
||||
SDL_RenderCopy( renderer, main_texture, NULL, NULL );
|
||||
SDL_RenderPresent( renderer );
|
||||
}
|
||||
|
||||
static void apply_contrast( void )
|
||||
{
|
||||
// Adjust the LCD color according to the contrast
|
||||
int contrast = get_contrast();
|
||||
|
||||
if ( last_contrast == contrast )
|
||||
return;
|
||||
|
||||
last_contrast = contrast;
|
||||
|
||||
if ( contrast < 0x3 )
|
||||
contrast = 0x3;
|
||||
if ( contrast > 0x13 )
|
||||
contrast = 0x13;
|
||||
|
||||
for ( unsigned i = FIRST_COLOR; i < LAST_COLOR; i++ ) {
|
||||
colors[ i ] = COLORS[ i ];
|
||||
if ( config.mono ) {
|
||||
colors[ i ].r = colors[ i ].mono_rgb;
|
||||
colors[ i ].g = colors[ i ].mono_rgb;
|
||||
colors[ i ].b = colors[ i ].mono_rgb;
|
||||
} else if ( config.gray ) {
|
||||
colors[ i ].r = colors[ i ].gray_rgb;
|
||||
colors[ i ].g = colors[ i ].gray_rgb;
|
||||
colors[ i ].b = colors[ i ].gray_rgb;
|
||||
}
|
||||
|
||||
if ( !config.mono && i == PIXEL ) {
|
||||
colors[ i ].r = ( 0x13 - contrast ) * ( colors[ LCD ].r / 0x10 );
|
||||
colors[ i ].g = ( 0x13 - contrast ) * ( colors[ LCD ].g / 0x10 );
|
||||
colors[ i ].b = 128 - ( ( 0x13 - contrast ) * ( ( 128 - colors[ LCD ].b ) / 0x10 ) );
|
||||
}
|
||||
}
|
||||
|
||||
// re-create annunciators textures
|
||||
last_annunciators = -1;
|
||||
create_annunciators_textures();
|
||||
}
|
||||
|
||||
/**********/
|
||||
/* public */
|
||||
/**********/
|
||||
|
@ -3225,33 +3249,10 @@ void ui_get_event( void )
|
|||
}
|
||||
}
|
||||
|
||||
void ui_init_LCD( void ) { memset( lcd_pixels_buffer, 0, sizeof( lcd_pixels_buffer ) ); }
|
||||
|
||||
void sdl_update_annunciators( void )
|
||||
void ui_update_display( void )
|
||||
{
|
||||
int annunciators_bits[ NB_ANNUNCIATORS ] = { ANN_LEFT, ANN_RIGHT, ANN_ALPHA, ANN_BATTERY, ANN_BUSY, ANN_IO };
|
||||
int annunciators = get_annunciators();
|
||||
apply_contrast();
|
||||
|
||||
if ( last_annunciators == annunciators )
|
||||
return;
|
||||
|
||||
last_annunciators = annunciators;
|
||||
|
||||
SDL_SetRenderTarget( renderer, main_texture );
|
||||
|
||||
for ( int i = 0; i < NB_ANNUNCIATORS; i++ )
|
||||
__draw_texture( display_offset_x + ann_tbl[ i ].x, display_offset_y + ann_tbl[ i ].y, ann_tbl[ i ].width, ann_tbl[ i ].height,
|
||||
( ( ( annunciators_bits[ i ] & annunciators ) == annunciators_bits[ i ] ) ) ? annunciators_textures[ i ].up
|
||||
: annunciators_textures[ i ].down );
|
||||
|
||||
// Always immediately update annunciators
|
||||
SDL_SetRenderTarget( renderer, NULL );
|
||||
SDL_RenderCopy( renderer, main_texture, NULL, NULL );
|
||||
SDL_RenderPresent( renderer );
|
||||
}
|
||||
|
||||
void ui_update_LCD( void )
|
||||
{
|
||||
if ( get_display_state() ) {
|
||||
get_lcd_buffer( lcd_pixels_buffer );
|
||||
|
||||
|
@ -3271,28 +3272,6 @@ void ui_update_LCD( void )
|
|||
ui_init_LCD();
|
||||
}
|
||||
|
||||
void ui_adjust_contrast( void )
|
||||
{
|
||||
colors_setup();
|
||||
|
||||
// redraw LCD
|
||||
ui_init_LCD();
|
||||
ui_update_LCD();
|
||||
|
||||
// redraw annunc
|
||||
last_annunciators = -1;
|
||||
|
||||
create_annunciators_textures();
|
||||
sdl_update_annunciators();
|
||||
}
|
||||
|
||||
void ui_stop( void )
|
||||
{
|
||||
SDL_DestroyTexture( main_texture );
|
||||
SDL_DestroyRenderer( renderer );
|
||||
SDL_DestroyWindow( window );
|
||||
}
|
||||
|
||||
void ui_start( config_t* conf )
|
||||
{
|
||||
config = *conf;
|
||||
|
@ -3347,9 +3326,7 @@ void ui_start( config_t* conf )
|
|||
|
||||
SDL_SetRenderTarget( renderer, main_texture );
|
||||
|
||||
colors_setup();
|
||||
|
||||
create_annunciators_textures();
|
||||
apply_contrast();
|
||||
|
||||
if ( !config.hide_chrome ) {
|
||||
int cut = BUTTONS[ HPKEY_MTH ].y + KEYBOARD_OFFSET_Y - 19;
|
||||
|
@ -3372,6 +3349,13 @@ void ui_start( config_t* conf )
|
|||
SDL_RenderPresent( renderer );
|
||||
}
|
||||
|
||||
void ui_stop( void )
|
||||
{
|
||||
SDL_DestroyTexture( main_texture );
|
||||
SDL_DestroyRenderer( renderer );
|
||||
SDL_DestroyWindow( window );
|
||||
}
|
||||
|
||||
void close_and_exit( void )
|
||||
{
|
||||
exit_emulator();
|
||||
|
|
10
src/ui.h
10
src/ui.h
|
@ -2,21 +2,15 @@
|
|||
#define _UI_H 1
|
||||
|
||||
#include "config.h"
|
||||
#include "emulator.h"
|
||||
|
||||
/*************************************************/
|
||||
/* public API: if it's there it's used elsewhere */
|
||||
/*************************************************/
|
||||
extern void ui_get_event( void );
|
||||
extern void ui_adjust_contrast( void );
|
||||
extern void ui_update_display( void );
|
||||
|
||||
extern void ui_update_LCD( void );
|
||||
|
||||
/*******************/
|
||||
/* used in: main.c */
|
||||
/*******************/
|
||||
extern void ui_stop( void );
|
||||
extern void ui_start( config_t* config );
|
||||
extern void ui_stop( void );
|
||||
|
||||
extern void close_and_exit( void );
|
||||
|
||||
|
|
Loading…
Reference in a new issue