[colors] factorize colors among all 3 UIs

This commit is contained in:
Gwenhael Le Moine 2024-06-12 10:53:03 +02:00
parent 3825c5e563
commit 37eca78404
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
6 changed files with 446 additions and 594 deletions

326
src/ui.c
View file

@ -141,6 +141,332 @@ letter_t small_font[ 128 ] = {
{0, 0, 0 } {0, 0, 0 }
}; };
color_t colors_sx[ NB_COLORS ] = {
{
.name = "white",
.r = 255,
.g = 255,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 255,
},
{
.name = "left",
.r = 255,
.g = 166,
.b = 0,
.mono_rgb = 255,
.gray_rgb = 230,
},
{
.name = "right",
.r = 0,
.g = 210,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 169,
},
{
.name = "but_top",
.r = 109,
.g = 93,
.b = 93,
.mono_rgb = 0,
.gray_rgb = 91,
},
{
.name = "button",
.r = 90,
.g = 77,
.b = 77,
.mono_rgb = 0,
.gray_rgb = 81,
},
{
.name = "but_bot",
.r = 76,
.g = 65,
.b = 65,
.mono_rgb = 0,
.gray_rgb = 69,
},
{
.name = "lcd_col",
.r = 202,
.g = 221,
.b = 92,
.mono_rgb = 255,
.gray_rgb = 205,
},
{
.name = "pix_col",
.r = 0,
.g = 0,
.b = 128,
.mono_rgb = 0,
.gray_rgb = 20,
},
{
.name = "pad_top",
.r = 109,
.g = 78,
.b = 78,
.mono_rgb = 0,
.gray_rgb = 88,
},
{
.name = "pad",
.r = 90,
.g = 64,
.b = 64,
.mono_rgb = 0,
.gray_rgb = 73,
},
{
.name = "pad_bot",
.r = 76,
.g = 54,
.b = 54,
.mono_rgb = 0,
.gray_rgb = 60,
},
{
.name = "disp_pad_top",
.r = 155,
.g = 118,
.b = 84,
.mono_rgb = 0,
.gray_rgb = 124,
},
{
.name = "disp_pad",
.r = 124,
.g = 94,
.b = 67,
.mono_rgb = 0,
.gray_rgb = 99,
},
{
.name = "disp_pad_bot",
.r = 100,
.g = 75,
.b = 53,
.mono_rgb = 0,
.gray_rgb = 79,
},
{
.name = "logo",
.r = 204,
.g = 169,
.b = 107,
.mono_rgb = 255,
.gray_rgb = 172,
},
{
.name = "logo_back",
.r = 64,
.g = 64,
.b = 64,
.mono_rgb = 0,
.gray_rgb = 65,
},
{
.name = "label",
.r = 202,
.g = 184,
.b = 144,
.mono_rgb = 255,
.gray_rgb = 185,
},
{
.name = "frame",
.r = 0,
.g = 0,
.b = 0,
.mono_rgb = 255,
.gray_rgb = 0,
},
{
.name = "underlay",
.r = 60,
.g = 42,
.b = 42,
.mono_rgb = 0,
.gray_rgb = 48,
},
{
.name = "black",
.r = 0,
.g = 0,
.b = 0,
.mono_rgb = 0,
.gray_rgb = 0,
},
};
color_t colors_gx[ NB_COLORS ] = {
{
.name = "white",
.r = 255,
.g = 255,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 255,
},
{
.name = "left",
.r = 255,
.g = 186,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 220,
},
{
.name = "right",
.r = 0,
.g = 255,
.b = 204,
.mono_rgb = 255,
.gray_rgb = 169,
},
{
.name = "but_top",
.r = 104,
.g = 104,
.b = 104,
.mono_rgb = 0,
.gray_rgb = 104,
},
{
.name = "button",
.r = 88,
.g = 88,
.b = 88,
.mono_rgb = 0,
.gray_rgb = 88,
},
{
.name = "but_bot",
.r = 74,
.g = 74,
.b = 74,
.mono_rgb = 0,
.gray_rgb = 74,
},
{
.name = "lcd_col",
.r = 202,
.g = 221,
.b = 92,
.mono_rgb = 255,
.gray_rgb = 205,
},
{
.name = "pix_col",
.r = 0,
.g = 0,
.b = 128,
.mono_rgb = 0,
.gray_rgb = 20,
},
{
.name = "pad_top",
.r = 88,
.g = 88,
.b = 88,
.mono_rgb = 0,
.gray_rgb = 88,
},
{
.name = "pad",
.r = 74,
.g = 74,
.b = 74,
.mono_rgb = 0,
.gray_rgb = 74,
},
{
.name = "pad_bot",
.r = 64,
.g = 64,
.b = 64,
.mono_rgb = 0,
.gray_rgb = 64,
},
{
.name = "disp_pad_top",
.r = 128,
.g = 128,
.b = 138,
.mono_rgb = 0,
.gray_rgb = 128,
},
{
.name = "disp_pad",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
},
{
.name = "disp_pad_bot",
.r = 84,
.g = 84,
.b = 90,
.mono_rgb = 0,
.gray_rgb = 84,
},
{
.name = "logo",
.r = 176,
.g = 176,
.b = 184,
.mono_rgb = 255,
.gray_rgb = 176,
},
{
.name = "logo_back",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
},
{
.name = "label",
.r = 240,
.g = 240,
.b = 240,
.mono_rgb = 255,
.gray_rgb = 240,
},
{
.name = "frame",
.r = 0,
.g = 0,
.b = 0,
.mono_rgb = 255,
.gray_rgb = 0,
},
{
.name = "underlay",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
},
{
.name = "black",
.r = 0,
.g = 0,
.b = 0,
.mono_rgb = 0,
.gray_rgb = 0,
},
};
void ( *ui_disp_draw_nibble )( word_20 addr, word_4 val ); void ( *ui_disp_draw_nibble )( word_20 addr, word_4 val );
void ( *ui_menu_draw_nibble )( word_20 addr, word_4 val ); void ( *ui_menu_draw_nibble )( word_20 addr, word_4 val );
void ( *ui_get_event )( void ); void ( *ui_get_event )( void );

View file

@ -6,14 +6,6 @@
#define DISP_ROWS 64 #define DISP_ROWS 64
#define NIBS_PER_BUFFER_ROW ( NIBBLES_PER_ROW + 2 ) #define NIBS_PER_BUFFER_ROW ( NIBBLES_PER_ROW + 2 )
/***********/
/* typedef */
/***********/
typedef struct letter_t {
unsigned int w, h;
unsigned char* bits;
} letter_t;
/*************/ /*************/
/* variables */ /* variables */
/*************/ /*************/
@ -21,8 +13,6 @@ extern int last_annunc_state;
extern unsigned char lcd_nibbles_buffer[ DISP_ROWS ][ NIBS_PER_BUFFER_ROW ]; extern unsigned char lcd_nibbles_buffer[ DISP_ROWS ][ NIBS_PER_BUFFER_ROW ];
extern letter_t small_font[ 128 ];
/*************/ /*************/
/* functions */ /* functions */
/*************/ /*************/

View file

@ -25,6 +25,32 @@
#define UNDERLAY 18 #define UNDERLAY 18
#define BLACK 19 #define BLACK 19
#define FIRST_COLOR WHITE
#define LAST_COLOR BLACK
#define NB_COLORS ( LAST_COLOR + 1 )
/***********/
/* typedef */
/***********/
typedef struct letter_t {
unsigned int w, h;
unsigned char* bits;
} letter_t;
typedef struct color_t {
const char* name;
int r, g, b;
int mono_rgb;
int gray_rgb;
} color_t;
/*************/
/* variables */
/*************/
extern letter_t small_font[ 128 ];
extern color_t colors_sx[ NB_COLORS ];
extern color_t colors_gx[ NB_COLORS ];
/***********/ /***********/
/* bitmaps */ /* bitmaps */
/***********/ /***********/

View file

@ -40,13 +40,6 @@
/* typedef */ /* typedef */
/***********/ /***********/
typedef struct sdl_color_t {
const char* name;
int r, g, b;
int mono_rgb;
int gray_rgb;
} sdl_color_t;
typedef struct sdl_keypad_t { typedef struct sdl_keypad_t {
unsigned int width; unsigned int width;
unsigned int height; unsigned int height;
@ -93,332 +86,6 @@ typedef struct sdl_ann_struct_t {
/*************/ /*************/
static sdl_keypad_t keypad; static sdl_keypad_t keypad;
static sdl_color_t sdl_colors_sx[] = {
{
.name = "white",
.r = 255,
.g = 255,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 255,
},
{
.name = "left",
.r = 255,
.g = 166,
.b = 0,
.mono_rgb = 255,
.gray_rgb = 230,
},
{
.name = "right",
.r = 0,
.g = 210,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 169,
},
{
.name = "but_top",
.r = 109,
.g = 93,
.b = 93,
.mono_rgb = 0,
.gray_rgb = 91,
},
{
.name = "button",
.r = 90,
.g = 77,
.b = 77,
.mono_rgb = 0,
.gray_rgb = 81,
},
{
.name = "but_bot",
.r = 76,
.g = 65,
.b = 65,
.mono_rgb = 0,
.gray_rgb = 69,
},
{
.name = "lcd_col",
.r = 202,
.g = 221,
.b = 92,
.mono_rgb = 255,
.gray_rgb = 205,
},
{
.name = "pix_col",
.r = 0,
.g = 0,
.b = 128,
.mono_rgb = 0,
.gray_rgb = 20,
},
{
.name = "pad_top",
.r = 109,
.g = 78,
.b = 78,
.mono_rgb = 0,
.gray_rgb = 88,
},
{
.name = "pad",
.r = 90,
.g = 64,
.b = 64,
.mono_rgb = 0,
.gray_rgb = 73,
},
{
.name = "pad_bot",
.r = 76,
.g = 54,
.b = 54,
.mono_rgb = 0,
.gray_rgb = 60,
},
{
.name = "disp_pad_top",
.r = 155,
.g = 118,
.b = 84,
.mono_rgb = 0,
.gray_rgb = 124,
},
{
.name = "disp_pad",
.r = 124,
.g = 94,
.b = 67,
.mono_rgb = 0,
.gray_rgb = 99,
},
{
.name = "disp_pad_bot",
.r = 100,
.g = 75,
.b = 53,
.mono_rgb = 0,
.gray_rgb = 79,
},
{
.name = "logo",
.r = 204,
.g = 169,
.b = 107,
.mono_rgb = 255,
.gray_rgb = 172,
},
{
.name = "logo_back",
.r = 64,
.g = 64,
.b = 64,
.mono_rgb = 0,
.gray_rgb = 65,
},
{
.name = "label",
.r = 202,
.g = 184,
.b = 144,
.mono_rgb = 255,
.gray_rgb = 185,
},
{
.name = "frame",
.r = 0,
.g = 0,
.b = 0,
.mono_rgb = 255,
.gray_rgb = 0,
},
{
.name = "underlay",
.r = 60,
.g = 42,
.b = 42,
.mono_rgb = 0,
.gray_rgb = 48,
},
{
.name = "black",
.r = 0,
.g = 0,
.b = 0,
.mono_rgb = 0,
.gray_rgb = 0,
},
};
static sdl_color_t sdl_colors_gx[] = {
{
.name = "white",
.r = 255,
.g = 255,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 255,
},
{
.name = "left",
.r = 255,
.g = 186,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 220,
},
{
.name = "right",
.r = 0,
.g = 255,
.b = 204,
.mono_rgb = 255,
.gray_rgb = 169,
},
{
.name = "but_top",
.r = 104,
.g = 104,
.b = 104,
.mono_rgb = 0,
.gray_rgb = 104,
},
{
.name = "button",
.r = 88,
.g = 88,
.b = 88,
.mono_rgb = 0,
.gray_rgb = 88,
},
{
.name = "but_bot",
.r = 74,
.g = 74,
.b = 74,
.mono_rgb = 0,
.gray_rgb = 74,
},
{
.name = "lcd_col",
.r = 202,
.g = 221,
.b = 92,
.mono_rgb = 255,
.gray_rgb = 205,
},
{
.name = "pix_col",
.r = 0,
.g = 0,
.b = 128,
.mono_rgb = 0,
.gray_rgb = 20,
},
{
.name = "pad_top",
.r = 88,
.g = 88,
.b = 88,
.mono_rgb = 0,
.gray_rgb = 88,
},
{
.name = "pad",
.r = 74,
.g = 74,
.b = 74,
.mono_rgb = 0,
.gray_rgb = 74,
},
{
.name = "pad_bot",
.r = 64,
.g = 64,
.b = 64,
.mono_rgb = 0,
.gray_rgb = 64,
},
{
.name = "disp_pad_top",
.r = 128,
.g = 128,
.b = 138,
.mono_rgb = 0,
.gray_rgb = 128,
},
{
.name = "disp_pad",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
},
{
.name = "disp_pad_bot",
.r = 84,
.g = 84,
.b = 90,
.mono_rgb = 0,
.gray_rgb = 84,
},
{
.name = "logo",
.r = 176,
.g = 176,
.b = 184,
.mono_rgb = 255,
.gray_rgb = 176,
},
{
.name = "logo_back",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
},
{
.name = "label",
.r = 240,
.g = 240,
.b = 240,
.mono_rgb = 255,
.gray_rgb = 240,
},
{
.name = "frame",
.r = 0,
.g = 0,
.b = 0,
.mono_rgb = 255,
.gray_rgb = 0,
},
{
.name = "underlay",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
},
{
.name = "black",
.r = 0,
.g = 0,
.b = 0,
.mono_rgb = 0,
.gray_rgb = 0,
},
};
// This will take the value of the defines, but can be run-time modified // This will take the value of the defines, but can be run-time modified
static unsigned KEYBOARD_HEIGHT, KEYBOARD_WIDTH, TOP_SKIP, SIDE_SKIP, BOTTOM_SKIP, DISP_KBD_SKIP, DISPLAY_WIDTH, DISPLAY_HEIGHT, static unsigned KEYBOARD_HEIGHT, KEYBOARD_WIDTH, TOP_SKIP, SIDE_SKIP, BOTTOM_SKIP, DISP_KBD_SKIP, DISPLAY_WIDTH, DISPLAY_HEIGHT,
DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISP_FRAME, KEYBOARD_OFFSET_X, KEYBOARD_OFFSET_Y, KBD_UPLINE; DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISP_FRAME, KEYBOARD_OFFSET_X, KEYBOARD_OFFSET_Y, KBD_UPLINE;
@ -2310,7 +1977,7 @@ static void write_text( int x, int y, const char* string, unsigned int length, u
} }
} }
static void colors_setup( sdl_color_t* sdl_colors ) static void colors_setup( color_t* colors )
{ {
int r, g, b; int r, g, b;
// Adjust the LCD color according to the contrast // Adjust the LCD color according to the contrast
@ -2320,27 +1987,27 @@ static void colors_setup( sdl_color_t* sdl_colors )
if ( contrast > 0x13 ) if ( contrast > 0x13 )
contrast = 0x13; contrast = 0x13;
for ( unsigned i = WHITE; i < BLACK; i++ ) { for ( unsigned i = FIRST_COLOR; i < LAST_COLOR; i++ ) {
if ( config.mono ) { if ( config.mono ) {
r = sdl_colors[ i ].mono_rgb; r = colors[ i ].mono_rgb;
g = sdl_colors[ i ].mono_rgb; g = colors[ i ].mono_rgb;
b = sdl_colors[ i ].mono_rgb; b = colors[ i ].mono_rgb;
} else if ( config.gray ) { } else if ( config.gray ) {
r = sdl_colors[ i ].gray_rgb; r = colors[ i ].gray_rgb;
g = sdl_colors[ i ].gray_rgb; g = colors[ i ].gray_rgb;
b = sdl_colors[ i ].gray_rgb; b = colors[ i ].gray_rgb;
} else { } else {
r = sdl_colors[ i ].r; r = colors[ i ].r;
g = sdl_colors[ i ].g; g = colors[ i ].g;
b = sdl_colors[ i ].b; b = colors[ i ].b;
} }
ARGBColors[ i ] = 0xff000000 | ( r << 16 ) | ( g << 8 ) | b; ARGBColors[ i ] = 0xff000000 | ( r << 16 ) | ( g << 8 ) | b;
} }
r = ( 0x13 - contrast ) * ( sdl_colors[ LCD ].r / 0x10 ); r = ( 0x13 - contrast ) * ( colors[ LCD ].r / 0x10 );
g = ( 0x13 - contrast ) * ( sdl_colors[ LCD ].g / 0x10 ); g = ( 0x13 - contrast ) * ( colors[ LCD ].g / 0x10 );
b = 128 - ( ( 0x13 - contrast ) * ( ( 128 - sdl_colors[ LCD ].b ) / 0x10 ) ); b = 128 - ( ( 0x13 - contrast ) * ( ( 128 - colors[ LCD ].b ) / 0x10 ) );
ARGBColors[ PIXEL ] = 0xff000000 | ( r << 16 ) | ( g << 8 ) | b; ARGBColors[ PIXEL ] = 0xff000000 | ( r << 16 ) | ( g << 8 ) | b;
} }
@ -3711,7 +3378,7 @@ void sdl_draw_annunc( void )
void sdl_adjust_contrast( void ) void sdl_adjust_contrast( void )
{ {
colors_setup( opt_gx ? sdl_colors_gx : sdl_colors_sx ); colors_setup( opt_gx ? colors_gx : colors_sx );
create_annunc(); create_annunc();
// redraw LCD // redraw LCD
@ -3806,7 +3473,7 @@ void init_sdl_ui( int argc, char** argv )
else else
memcpy( buttons, buttons_sx, sizeof( buttons_sx ) ); memcpy( buttons, buttons_sx, sizeof( buttons_sx ) );
colors_setup( opt_gx ? sdl_colors_gx : sdl_colors_sx ); colors_setup( opt_gx ? colors_gx : colors_sx );
if ( !config.hide_chrome ) { if ( !config.hide_chrome ) {
int cut = buttons[ HPKEY_MTH ].y + KEYBOARD_OFFSET_Y - 19; int cut = buttons[ HPKEY_MTH ].y + KEYBOARD_OFFSET_Y - 19;

View file

@ -14,6 +14,7 @@
#include <curses.h> #include <curses.h>
#include "romio.h" /* opt_gx */
#include "config.h" /* mono, gray, small, tiny, progname */ #include "config.h" /* mono, gray, small, tiny, progname */
#include "ui.h" /* last_annunc_state, lcd_nibbles_buffer, DISP_ROWS */ #include "ui.h" /* last_annunc_state, lcd_nibbles_buffer, DISP_ROWS */
#include "ui_inner.h" #include "ui_inner.h"
@ -585,15 +586,16 @@ void init_text_ui( int argc, char** argv )
noecho(); noecho();
nonl(); /* tell curses not to do NL->CR/NL on output */ nonl(); /* tell curses not to do NL->CR/NL on output */
color_t* colors = opt_gx ? colors_gx : colors_sx;
if ( !config.mono && has_colors() ) { if ( !config.mono && has_colors() ) {
start_color(); start_color();
if ( config.gray ) { if ( config.gray ) {
init_color( LCD_COLOR_BG, 205, 205, 205 ); init_color( LCD_COLOR_BG, colors[ LCD ].gray_rgb, colors[ LCD ].gray_rgb, colors[ LCD ].gray_rgb );
init_color( LCD_COLOR_FG, 20, 20, 20 ); init_color( LCD_COLOR_FG, colors[ PIXEL ].gray_rgb, colors[ PIXEL ].gray_rgb, colors[ PIXEL ].gray_rgb );
} else { } else {
init_color( LCD_COLOR_BG, 202, 221, 92 ); init_color( LCD_COLOR_BG, colors[ LCD ].r, colors[ LCD ].g, colors[ LCD ].b );
init_color( LCD_COLOR_FG, 0, 0, 128 ); init_color( LCD_COLOR_FG, colors[ PIXEL ].r, colors[ PIXEL ].g, colors[ PIXEL ].b );
} }
init_pair( LCD_PIXEL_OFF, LCD_COLOR_BG, LCD_COLOR_BG ); init_pair( LCD_PIXEL_OFF, LCD_COLOR_BG, LCD_COLOR_BG );

View file

@ -48,7 +48,7 @@
#define COLOR_MODE_GRAY 2 #define COLOR_MODE_GRAY 2
#define COLOR_MODE_COLOR 3 #define COLOR_MODE_COLOR 3
#define COLOR( c ) ( colors[ ( c ) ].xcolor.pixel ) #define COLOR( c ) ( x11_colors[ ( c ) ].pixel )
/***********/ /***********/
/* bitmaps */ /* bitmaps */
@ -185,15 +185,6 @@ static unsigned char hp48_green_gx_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00 }; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00 };
typedef struct x11_color_t {
const char* name;
int r, g, b;
int mono_rgb;
int gray_rgb;
XColor xcolor;
} x11_color_t;
typedef struct x11_keypad_t { typedef struct x11_keypad_t {
unsigned int width; unsigned int width;
unsigned int height; unsigned int height;
@ -255,7 +246,29 @@ typedef struct icon_map_t {
static bool mapped; static bool mapped;
static x11_keypad_t keypad; static x11_keypad_t keypad;
static x11_color_t* colors; static XColor x11_colors[ NB_COLORS ] = {
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
{0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0},
};
static color_t* colors;
static int CompletionType = -1; static int CompletionType = -1;
@ -290,178 +303,6 @@ static int icon_color_mode;
static char* res_name; static char* res_name;
static char* res_class; static char* res_class;
static x11_color_t colors_sx[] = {
{.name = "white",
.r = 255,
.g = 255,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 255,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "left", .r = 255, .g = 166, .b = 0, .mono_rgb = 255, .gray_rgb = 230, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "right",
.r = 0,
.g = 210,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 169,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "but_top", .r = 109, .g = 93, .b = 93, .mono_rgb = 0, .gray_rgb = 91, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "button", .r = 90, .g = 77, .b = 77, .mono_rgb = 0, .gray_rgb = 81, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "but_bot", .r = 76, .g = 65, .b = 65, .mono_rgb = 0, .gray_rgb = 69, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "lcd_col",
.r = 202,
.g = 221,
.b = 92,
.mono_rgb = 255,
.gray_rgb = 205,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "pix_col", .r = 0, .g = 0, .b = 128, .mono_rgb = 0, .gray_rgb = 20, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "pad_top", .r = 109, .g = 78, .b = 78, .mono_rgb = 0, .gray_rgb = 88, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "pad", .r = 90, .g = 64, .b = 64, .mono_rgb = 0, .gray_rgb = 73, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "pad_bot", .r = 76, .g = 54, .b = 54, .mono_rgb = 0, .gray_rgb = 60, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "disp_pad_top",
.r = 155,
.g = 118,
.b = 84,
.mono_rgb = 0,
.gray_rgb = 124,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "disp_pad",
.r = 124,
.g = 94,
.b = 67,
.mono_rgb = 0,
.gray_rgb = 99,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "disp_pad_bot",
.r = 100,
.g = 75,
.b = 53,
.mono_rgb = 0,
.gray_rgb = 79,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "logo",
.r = 204,
.g = 169,
.b = 107,
.mono_rgb = 255,
.gray_rgb = 172,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "logo_back",
.r = 64,
.g = 64,
.b = 64,
.mono_rgb = 0,
.gray_rgb = 65,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "label",
.r = 202,
.g = 184,
.b = 144,
.mono_rgb = 255,
.gray_rgb = 185,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "frame", .r = 0, .g = 0, .b = 0, .mono_rgb = 255, .gray_rgb = 0, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "underlay", .r = 60, .g = 42, .b = 42, .mono_rgb = 0, .gray_rgb = 48, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "black", .r = 0, .g = 0, .b = 0, .mono_rgb = 0, .gray_rgb = 0, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
};
static x11_color_t colors_gx[] = {
{.name = "white",
.r = 255,
.g = 255,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 255,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "left",
.r = 255,
.g = 186,
.b = 255,
.mono_rgb = 255,
.gray_rgb = 220,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "right",
.r = 0,
.g = 255,
.b = 204,
.mono_rgb = 255,
.gray_rgb = 169,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "but_top",
.r = 104,
.g = 104,
.b = 104,
.mono_rgb = 0,
.gray_rgb = 104,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "button", .r = 88, .g = 88, .b = 88, .mono_rgb = 0, .gray_rgb = 88, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "but_bot", .r = 74, .g = 74, .b = 74, .mono_rgb = 0, .gray_rgb = 74, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "lcd_col",
.r = 202,
.g = 221,
.b = 92,
.mono_rgb = 255,
.gray_rgb = 205,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "pix_col", .r = 0, .g = 0, .b = 128, .mono_rgb = 0, .gray_rgb = 20, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "pad_top", .r = 88, .g = 88, .b = 88, .mono_rgb = 0, .gray_rgb = 88, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "pad", .r = 74, .g = 74, .b = 74, .mono_rgb = 0, .gray_rgb = 74, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "pad_bot", .r = 64, .g = 64, .b = 64, .mono_rgb = 0, .gray_rgb = 64, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "disp_pad_top",
.r = 128,
.g = 128,
.b = 138,
.mono_rgb = 0,
.gray_rgb = 128,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "disp_pad",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "disp_pad_bot",
.r = 84,
.g = 84,
.b = 90,
.mono_rgb = 0,
.gray_rgb = 84,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "logo",
.r = 176,
.g = 176,
.b = 184,
.mono_rgb = 255,
.gray_rgb = 176,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "logo_back",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "label",
.r = 240,
.g = 240,
.b = 240,
.mono_rgb = 255,
.gray_rgb = 240,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "frame", .r = 0, .g = 0, .b = 0, .mono_rgb = 255, .gray_rgb = 0, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
{.name = "underlay",
.r = 104,
.g = 104,
.b = 110,
.mono_rgb = 0,
.gray_rgb = 104,
.xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 } },
{.name = "black", .r = 0, .g = 0, .b = 0, .mono_rgb = 0, .gray_rgb = 0, .xcolor = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue, 0 }},
};
static x11_button_t* buttons = 0; static x11_button_t* buttons = 0;
static x11_button_t buttons_sx[] = { static x11_button_t buttons_sx[] = {
@ -2547,52 +2388,52 @@ static inline void colors_setup( void )
b_shift = 16 - b_shift; b_shift = 16 - b_shift;
} }
for ( c = WHITE; c <= BLACK; c++ ) { for ( c = FIRST_COLOR; c <= LAST_COLOR; c++ ) {
switch ( color_mode ) { switch ( color_mode ) {
case COLOR_MODE_MONO: case COLOR_MODE_MONO:
colors[ c ].xcolor.red = colors[ c ].mono_rgb << 8; x11_colors[ c ].red = colors[ c ].mono_rgb << 8;
colors[ c ].xcolor.green = colors[ c ].mono_rgb << 8; x11_colors[ c ].green = colors[ c ].mono_rgb << 8;
colors[ c ].xcolor.blue = colors[ c ].mono_rgb << 8; x11_colors[ c ].blue = colors[ c ].mono_rgb << 8;
break; break;
case COLOR_MODE_GRAY: case COLOR_MODE_GRAY:
colors[ c ].xcolor.red = colors[ c ].gray_rgb << 8; x11_colors[ c ].red = colors[ c ].gray_rgb << 8;
colors[ c ].xcolor.green = colors[ c ].gray_rgb << 8; x11_colors[ c ].green = colors[ c ].gray_rgb << 8;
colors[ c ].xcolor.blue = colors[ c ].gray_rgb << 8; x11_colors[ c ].blue = colors[ c ].gray_rgb << 8;
break; break;
default: default:
colors[ c ].xcolor.red = colors[ c ].r << 8; x11_colors[ c ].red = colors[ c ].r << 8;
colors[ c ].xcolor.green = colors[ c ].g << 8; x11_colors[ c ].green = colors[ c ].g << 8;
colors[ c ].xcolor.blue = colors[ c ].b << 8; x11_colors[ c ].blue = colors[ c ].b << 8;
break; break;
} }
if ( direct_color ) { if ( direct_color ) {
colors[ c ].xcolor.pixel = ( ( colors[ c ].xcolor.red >> r_shift ) & visual->red_mask ) | x11_colors[ c ].pixel = ( ( x11_colors[ c ].red >> r_shift ) & visual->red_mask ) |
( ( colors[ c ].xcolor.green >> g_shift ) & visual->green_mask ) | ( ( x11_colors[ c ].green >> g_shift ) & visual->green_mask ) |
( ( colors[ c ].xcolor.blue >> b_shift ) & visual->blue_mask ); ( ( x11_colors[ c ].blue >> b_shift ) & visual->blue_mask );
XStoreColor( dpy, cmap, &colors[ c ].xcolor ); XStoreColor( dpy, cmap, &x11_colors[ c ] );
} else { } else {
if ( dynamic_color && c == PIXEL ) { if ( dynamic_color && c == PIXEL ) {
if ( XAllocColorCells( dpy, cmap, True, ( unsigned long* )0, 0, &colors[ c ].xcolor.pixel, 1 ) == 0 ) { if ( XAllocColorCells( dpy, cmap, True, ( unsigned long* )0, 0, &x11_colors[ c ].pixel, 1 ) == 0 ) {
dyn = 0; dyn = 0;
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) { if ( XAllocColor( dpy, cmap, &x11_colors[ c ] ) == 0 ) {
if ( config.verbose ) if ( config.verbose )
fprintf( stderr, "XAllocColor failed.\n" ); fprintf( stderr, "XAllocColor failed.\n" );
error = c; error = c;
break; break;
} }
} else if ( colors[ c ].xcolor.pixel >= ( unsigned long )( visual->map_entries ) ) { } else if ( x11_colors[ c ].pixel >= ( unsigned long )( visual->map_entries ) ) {
dyn = 0; dyn = 0;
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) { if ( XAllocColor( dpy, cmap, &x11_colors[ c ] ) == 0 ) {
if ( config.verbose ) if ( config.verbose )
fprintf( stderr, "XAllocColor failed.\n" ); fprintf( stderr, "XAllocColor failed.\n" );
error = c; error = c;
break; break;
} }
} else { } else {
XStoreColor( dpy, cmap, &colors[ c ].xcolor ); XStoreColor( dpy, cmap, &x11_colors[ c ] );
} }
} else { } else {
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) { if ( XAllocColor( dpy, cmap, &x11_colors[ c ] ) == 0 ) {
if ( config.verbose ) if ( config.verbose )
fprintf( stderr, "XAllocColor failed.\n" ); fprintf( stderr, "XAllocColor failed.\n" );
error = c; error = c;
@ -2611,8 +2452,8 @@ static inline void colors_setup( void )
/* /*
* free colors so far allocated * free colors so far allocated
*/ */
for ( c = WHITE; c < error; c++ ) for ( c = FIRST_COLOR; c < error; c++ )
XFreeColors( dpy, cmap, &colors[ c ].xcolor.pixel, 1, 0 ); XFreeColors( dpy, cmap, &x11_colors[ c ].pixel, 1, 0 );
/* /*
* Create my own Colormap * Create my own Colormap
@ -2630,40 +2471,40 @@ static inline void colors_setup( void )
* Try to allocate colors again * Try to allocate colors again
*/ */
dyn = dynamic_color; dyn = dynamic_color;
for ( c = WHITE; c <= BLACK; c++ ) { for ( c = FIRST_COLOR; c <= LAST_COLOR; c++ ) {
switch ( color_mode ) { switch ( color_mode ) {
case COLOR_MODE_MONO: case COLOR_MODE_MONO:
colors[ c ].xcolor.red = colors[ c ].mono_rgb << 8; x11_colors[ c ].red = colors[ c ].mono_rgb << 8;
colors[ c ].xcolor.green = colors[ c ].mono_rgb << 8; x11_colors[ c ].green = colors[ c ].mono_rgb << 8;
colors[ c ].xcolor.blue = colors[ c ].mono_rgb << 8; x11_colors[ c ].blue = colors[ c ].mono_rgb << 8;
break; break;
case COLOR_MODE_GRAY: case COLOR_MODE_GRAY:
colors[ c ].xcolor.red = colors[ c ].gray_rgb << 8; x11_colors[ c ].red = colors[ c ].gray_rgb << 8;
colors[ c ].xcolor.green = colors[ c ].gray_rgb << 8; x11_colors[ c ].green = colors[ c ].gray_rgb << 8;
colors[ c ].xcolor.blue = colors[ c ].gray_rgb << 8; x11_colors[ c ].blue = colors[ c ].gray_rgb << 8;
break; break;
default: default:
colors[ c ].xcolor.red = colors[ c ].r << 8; x11_colors[ c ].red = colors[ c ].r << 8;
colors[ c ].xcolor.green = colors[ c ].g << 8; x11_colors[ c ].green = colors[ c ].g << 8;
colors[ c ].xcolor.blue = colors[ c ].b << 8; x11_colors[ c ].blue = colors[ c ].b << 8;
break; break;
} }
if ( dynamic_color && c == PIXEL ) { if ( dynamic_color && c == PIXEL ) {
if ( XAllocColorCells( dpy, cmap, True, ( unsigned long* )0, 0, &colors[ c ].xcolor.pixel, 1 ) == 0 ) { if ( XAllocColorCells( dpy, cmap, True, ( unsigned long* )0, 0, &x11_colors[ c ].pixel, 1 ) == 0 ) {
dyn = 0; dyn = 0;
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) if ( XAllocColor( dpy, cmap, &x11_colors[ c ] ) == 0 )
fatal_exit( "can\'t alloc Color.\n", "" ); fatal_exit( "can\'t alloc Color.\n", "" );
} else if ( colors[ c ].xcolor.pixel >= ( unsigned long )( visual->map_entries ) ) { } else if ( x11_colors[ c ].pixel >= ( unsigned long )( visual->map_entries ) ) {
dyn = 0; dyn = 0;
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) if ( XAllocColor( dpy, cmap, &x11_colors[ c ] ) == 0 )
fatal_exit( "can\'t alloc Color.\n", "" ); fatal_exit( "can\'t alloc Color.\n", "" );
} else { } else {
XStoreColor( dpy, cmap, &colors[ c ].xcolor ); XStoreColor( dpy, cmap, &x11_colors[ c ] );
} }
} else { } else {
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) if ( XAllocColor( dpy, cmap, &x11_colors[ c ] ) == 0 )
fatal_exit( "can\'t alloc Color.\n", "" ); fatal_exit( "can\'t alloc Color.\n", "" );
} }
} }
@ -5015,23 +4856,23 @@ void x11_adjust_contrast( void )
if ( contrast > 0x13 ) if ( contrast > 0x13 )
contrast = 0x13; contrast = 0x13;
old = colors[ PIXEL ].xcolor.pixel; old = x11_colors[ PIXEL ].pixel;
switch ( color_mode ) { switch ( color_mode ) {
case COLOR_MODE_MONO: case COLOR_MODE_MONO:
return; return;
case COLOR_MODE_GRAY: case COLOR_MODE_GRAY:
gray = ( 0x13 - contrast ) * ( colors[ LCD ].gray_rgb / 0x10 ); gray = ( 0x13 - contrast ) * ( colors[ LCD ].gray_rgb / 0x10 );
colors[ PIXEL ].xcolor.red = gray << 8; x11_colors[ PIXEL ].red = gray << 8;
colors[ PIXEL ].xcolor.green = gray << 8; x11_colors[ PIXEL ].green = gray << 8;
colors[ PIXEL ].xcolor.blue = gray << 8; x11_colors[ PIXEL ].blue = gray << 8;
break; break;
default: default:
r = ( 0x13 - contrast ) * ( colors[ LCD ].r / 0x10 ); r = ( 0x13 - contrast ) * ( colors[ LCD ].r / 0x10 );
g = ( 0x13 - contrast ) * ( colors[ LCD ].g / 0x10 ); g = ( 0x13 - contrast ) * ( colors[ LCD ].g / 0x10 );
b = 128 - ( ( 0x13 - contrast ) * ( ( 128 - colors[ LCD ].b ) / 0x10 ) ); b = 128 - ( ( 0x13 - contrast ) * ( ( 128 - colors[ LCD ].b ) / 0x10 ) );
colors[ PIXEL ].xcolor.red = r << 8; x11_colors[ PIXEL ].red = r << 8;
colors[ PIXEL ].xcolor.green = g << 8; x11_colors[ PIXEL ].green = g << 8;
colors[ PIXEL ].xcolor.blue = b << 8; x11_colors[ PIXEL ].blue = b << 8;
break; break;
} }
@ -5055,10 +4896,10 @@ void x11_adjust_contrast( void )
last_icon_state = -1; last_icon_state = -1;
refresh_icon(); refresh_icon();
} else if ( dynamic_color ) { } else if ( dynamic_color ) {
XStoreColor( dpy, cmap, &colors[ PIXEL ].xcolor ); XStoreColor( dpy, cmap, &x11_colors[ PIXEL ] );
} else { } else {
if ( XAllocColor( dpy, cmap, &colors[ PIXEL ].xcolor ) == 0 ) { if ( XAllocColor( dpy, cmap, &x11_colors[ PIXEL ] ) == 0 ) {
colors[ PIXEL ].xcolor.pixel = old; x11_colors[ PIXEL ].pixel = old;
if ( config.verbose ) if ( config.verbose )
fprintf( stderr, "warning: can\'t alloc new pixel color.\n" ); fprintf( stderr, "warning: can\'t alloc new pixel color.\n" );
} else { } else {