1
0
Fork 0
forked from Miroirs/x49gp

Compare commits

...

3 commits

Author SHA1 Message Date
Gwenhael Le Moine
5246fcb0fd
move actual LCD rendering into ui.c 2024-11-05 13:29:03 +01:00
Gwenhael Le Moine
3609e8df9a
slowly moving things out of ui-> 2024-11-05 13:00:16 +01:00
Gwenhael Le Moine
f14aa9bf14
typo 2024-11-05 12:35:38 +01:00
8 changed files with 130 additions and 160 deletions

View file

@ -443,8 +443,9 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key )
memset( phys_ram_base + flash->offset, 0xff, flash->size - st.st_size ); memset( phys_ram_base + flash->offset, 0xff, flash->size - st.st_size );
bootfd = x49gp_module_open_rodata( module, bootfd = x49gp_module_open_rodata( module,
ui->calculator == UI_CALCULATOR_HP49GP || calc == UI_CALCULATOR_HP49GP_NEWRPL ? "firmware/boot-49g+.bin" ui->calculator == UI_CALCULATOR_HP49GP || ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL
: "firmware/boot-50g.bin", ? "firmware/boot-49g+.bin"
: "firmware/boot-50g.bin",
&bootfile ); &bootfile );
if ( bootfd < 0 ) { if ( bootfd < 0 ) {

View file

@ -204,7 +204,7 @@ void x49gp_lcd_timer( void* data )
x49gp_t* x49gp = data; x49gp_t* x49gp = data;
int64_t now, expires; int64_t now, expires;
x49gp_lcd_update( x49gp ); gui_update_lcd( x49gp );
gdk_flush(); gdk_flush();
now = x49gp_get_clock(); now = x49gp_get_clock();

View file

@ -11,6 +11,32 @@ typedef struct {
uint32_t *datap; uint32_t *datap;
} s3c2410_offset_t; } s3c2410_offset_t;
typedef struct {
uint32_t lcdcon1;
uint32_t lcdcon2;
uint32_t lcdcon3;
uint32_t lcdcon4;
uint32_t lcdcon5;
uint32_t lcdsaddr1;
uint32_t lcdsaddr2;
uint32_t lcdsaddr3;
uint32_t redlut;
uint32_t greenlut;
uint32_t bluelut;
uint32_t dithmode;
uint32_t tpal;
uint32_t lcdintpnd;
uint32_t lcdsrcpnd;
uint32_t lcdintmsk;
uint32_t lpcsel;
uint32_t __unknown_68;
unsigned int nr_regs;
s3c2410_offset_t* regs;
x49gp_t* x49gp;
} s3c2410_lcd_t;
#define S3C2410_OFFSET(module, name, reset, data) \ #define S3C2410_OFFSET(module, name, reset, data) \
[S3C2410_ ## module ## _ ## name >> 2] = { #name, reset, &(data) } [S3C2410_ ## module ## _ ## name >> 2] = { #name, reset, &(data) }
@ -338,8 +364,9 @@ extern int x49gp_s3c2410_sdi_init(x49gp_t *x49gp);
extern void s3c2410_io_port_g_update(x49gp_t *x49gp, int column, int row, unsigned char columnbit, unsigned char rowbit, uint32_t new_state); extern void s3c2410_io_port_g_update(x49gp_t *x49gp, int column, int row, unsigned char columnbit, unsigned char rowbit, uint32_t new_state);
extern void s3c2410_io_port_f_set_bit(x49gp_t *x49gp, int n, uint32_t set); extern void s3c2410_io_port_f_set_bit(x49gp_t *x49gp, int n, uint32_t set);
extern void x49gp_schedule_lcd_update(x49gp_t *x49gp); extern void s3c2410_schedule_lcd_update(x49gp_t *x49gp);
extern void x49gp_lcd_update(x49gp_t *x49gp);
extern int x49gp_get_pixel_color( s3c2410_lcd_t* lcd, int x, int y );
extern unsigned long s3c2410_timer_next_interrupt(x49gp_t *x49gp); extern unsigned long s3c2410_timer_next_interrupt(x49gp_t *x49gp);
extern unsigned long s3c2410_watchdog_next_interrupt(x49gp_t *x49gp); extern unsigned long s3c2410_watchdog_next_interrupt(x49gp_t *x49gp);

View file

@ -7,38 +7,10 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <errno.h> #include <errno.h>
#include <gtk/gtk.h>
#include "x49gp.h" #include "x49gp.h"
#include "ui.h" #include "ui.h"
#include "s3c2410.h" #include "s3c2410.h"
typedef struct {
uint32_t lcdcon1;
uint32_t lcdcon2;
uint32_t lcdcon3;
uint32_t lcdcon4;
uint32_t lcdcon5;
uint32_t lcdsaddr1;
uint32_t lcdsaddr2;
uint32_t lcdsaddr3;
uint32_t redlut;
uint32_t greenlut;
uint32_t bluelut;
uint32_t dithmode;
uint32_t tpal;
uint32_t lcdintpnd;
uint32_t lcdsrcpnd;
uint32_t lcdintmsk;
uint32_t lpcsel;
uint32_t __unknown_68;
unsigned int nr_regs;
s3c2410_offset_t* regs;
x49gp_t* x49gp;
} s3c2410_lcd_t;
static int s3c2410_lcd_data_init( s3c2410_lcd_t* lcd ) static int s3c2410_lcd_data_init( s3c2410_lcd_t* lcd )
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = {
@ -115,7 +87,7 @@ static void s3c2410_lcd_write( void* opaque, target_phys_addr_t offset, uint32_t
switch ( offset ) { switch ( offset ) {
case S3C2410_LCD_LCDCON1: case S3C2410_LCD_LCDCON1:
if ( ( lcd->lcdcon1 ^ data ) & 1 ) if ( ( lcd->lcdcon1 ^ data ) & 1 )
x49gp_schedule_lcd_update( x49gp ); s3c2410_schedule_lcd_update( x49gp );
lcd->lcdcon1 = ( lcd->lcdcon1 & ( 0x3ff << 18 ) ) | ( data & ~( 0x3ff << 18 ) ); lcd->lcdcon1 = ( lcd->lcdcon1 & ( 0x3ff << 18 ) ) | ( data & ~( 0x3ff << 18 ) );
break; break;
@ -247,13 +219,13 @@ static int s3c2410_lcd_exit( x49gp_module_t* module )
return 0; return 0;
} }
void x49gp_schedule_lcd_update( x49gp_t* x49gp ) void s3c2410_schedule_lcd_update( x49gp_t* x49gp )
{ {
if ( !x49gp_timer_pending( x49gp->lcd_timer ) ) if ( !x49gp_timer_pending( x49gp->lcd_timer ) )
x49gp_mod_timer( x49gp->lcd_timer, x49gp_get_clock() + X49GP_LCD_REFRESH_INTERVAL ); x49gp_mod_timer( x49gp->lcd_timer, x49gp_get_clock() + X49GP_LCD_REFRESH_INTERVAL );
} }
static int x49gp_get_pixel_color( s3c2410_lcd_t* lcd, int x, int y ) int x49gp_get_pixel_color( s3c2410_lcd_t* lcd, int x, int y )
{ {
uint32_t bank, addr, data, offset, pixel_offset; uint32_t bank, addr, data, offset, pixel_offset;
int bits_per_pixel = lcd->lcdcon5 > 2 ? 1 : 4 >> lcd->lcdcon5; int bits_per_pixel = lcd->lcdcon5 > 2 ? 1 : 4 >> lcd->lcdcon5;
@ -278,68 +250,6 @@ static int x49gp_get_pixel_color( s3c2410_lcd_t* lcd, int x, int y )
} }
} }
static void _draw_pixel( GdkPixmap* target, int x, int y, int w, int h, GdkColor* color )
{
cairo_t* cr = gdk_cairo_create( target );
cairo_set_source_rgb( cr, color->red / 65535.0, color->green / 65535.0, color->blue / 65535.0 );
cairo_rectangle( cr, x, y, w, h );
cairo_fill( cr );
cairo_destroy( cr );
}
static inline void _draw_annunciator( GdkPixmap* target, cairo_surface_t* surface, int x, int y, int w, int h, GdkColor* color )
{
cairo_t* cr = gdk_cairo_create( target );
cairo_set_source_rgb( cr, color->red / 65535.0, color->green / 65535.0, color->blue / 65535.0 );
cairo_mask_surface( cr, surface, x, y );
cairo_destroy( cr );
}
void x49gp_lcd_update( x49gp_t* x49gp )
{
x49gp_ui_t* ui = x49gp->ui;
s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd;
if ( lcd->lcdcon1 & 1 ) {
GdkColor color;
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 1 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_left_surface, 11, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 2 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_right_surface, 56, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 3 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_alpha_surface, 101, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 4 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_battery_surface, 146, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 5 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_busy_surface, 191, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 0 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_io_surface, 236, 0, 15, 12, &color );
for ( int y = 0; y < ( ( ui->lcd_height - ui->lcd_annunciators_height ) / LCD_PIXEL_SCALE ); y++ )
for ( int x = 0; x < ( ui->lcd_width / LCD_PIXEL_SCALE ); x++ )
_draw_pixel( ui->lcd_pixmap, LCD_PIXEL_SCALE * x, LCD_PIXEL_SCALE * y + ui->lcd_annunciators_height, LCD_PIXEL_SCALE,
LCD_PIXEL_SCALE, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, x, y ) ] ) );
}
GdkRectangle rect;
rect.x = 0;
rect.y = 0;
rect.width = ui->lcd_width;
rect.height = ui->lcd_height;
gdk_window_invalidate_rect( gtk_widget_get_window( ui->lcd_canvas ), &rect, false );
}
int x49gp_s3c2410_lcd_init( x49gp_t* x49gp ) int x49gp_s3c2410_lcd_init( x49gp_t* x49gp )
{ {
x49gp_module_t* module; x49gp_module_t* module;

View file

@ -59,7 +59,7 @@ static int s3c2410_sram_load( x49gp_module_t* module, GKeyFile* key )
g_free( filename ); g_free( filename );
x49gp_schedule_lcd_update( module->x49gp ); s3c2410_schedule_lcd_update( module->x49gp );
return error; return error;
} }

View file

@ -10,11 +10,9 @@
#include <signal.h> #include <signal.h>
#include <poll.h> #include <poll.h>
#include <glib.h>
#include "x49gp.h" #include "x49gp.h"
#include "x49gp_timer.h" #include "x49gp_timer.h"
#include "s3c2410.h" #include "ui.h"
#include "gdbstub.h" #include "gdbstub.h"
@ -229,7 +227,7 @@ int x49gp_main_loop( x49gp_t* x49gp )
if ( x49gp->arm_idle != prev_idle ) { if ( x49gp->arm_idle != prev_idle ) {
if ( x49gp->arm_idle == X49GP_ARM_OFF ) { if ( x49gp->arm_idle == X49GP_ARM_OFF ) {
x49gp_lcd_update( x49gp ); gui_update_lcd( x49gp );
cpu_reset( x49gp->env ); cpu_reset( x49gp->env );
} }
} }

View file

@ -1602,7 +1602,7 @@ static void react_to_button_realize( GtkWidget* widget, gpointer user_data )
w = widget_allocation.width; w = widget_allocation.width;
h = widget_allocation.height; h = widget_allocation.height;
button->pixmap = gdk_pixmap_new( gtk_widget_get_style( widget )->bg_pixmap[ 0 ], w, h, -1 ); button->pixmap = gdk_pixmap_new( gtk_widget_get_window( ui->window ), w, h, -1 );
xoffset += 2; xoffset += 2;
yoffset += 2; yoffset += 2;
@ -1711,8 +1711,7 @@ static int draw_faceplate( GtkWidget* ui_background, GdkEventConfigure* event, g
int dl = 0, dr = 0; int dl = 0, dr = 0;
int faceplate_color; int faceplate_color;
if ( NULL != ui->bg_pixmap ) GdkPixmap* bg_pixmap; /* FIXME */
return false;
if ( ui->calculator == UI_CALCULATOR_HP49GP || ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL ) if ( ui->calculator == UI_CALCULATOR_HP49GP || ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL )
faceplate_color = UI_COLOR_FACEPLATE_49GP; faceplate_color = UI_COLOR_FACEPLATE_49GP;
@ -1722,24 +1721,9 @@ static int draw_faceplate( GtkWidget* ui_background, GdkEventConfigure* event, g
GdkPixbuf* bg_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, FALSE, 8, ui->width, ui->height ); GdkPixbuf* bg_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, FALSE, 8, ui->width, ui->height );
gdk_pixbuf_fill( bg_pixbuf, color2rgb( ui, faceplate_color ) ); gdk_pixbuf_fill( bg_pixbuf, color2rgb( ui, faceplate_color ) );
/* cairo_surface_t* surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, ui->width, ui->height); */ bg_pixmap = gdk_pixmap_new( gtk_widget_get_window( ui_background ), ui->width, ui->height, -1 );
/* cr = cairo_create( surface ); */
/* /\* Draw the pixbuf *\/ */
/* gdk_cairo_set_source_pixbuf (cr, ui->bg_pixbuf, 0, 0); */
/* cairo_paint (cr); */
/* /\* Draw a red rectangle *\/ */
/* GdkColor color = ui->colors[ UI_COLOR_GRAYSCALE_0 ]; */ cr = gdk_cairo_create( bg_pixmap );
/* cairo_set_source_rgb( cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0 ); */
/* cairo_rectangle (cr, ui->lcd_x_offset - 2, ui->lcd_y_offset - 2, ui->lcd_width + 4, ui->lcd_height + 4 ); */
/* cairo_fill (cr); */
/* cairo_surface_destroy( surface ); */
/* cairo_destroy( cr ); */
ui->bg_pixmap = gdk_pixmap_new( gtk_widget_get_window( ui_background ), ui->width, ui->height, -1 );
cr = gdk_cairo_create( ui->bg_pixmap );
gdk_cairo_set_source_pixbuf( cr, bg_pixbuf, 0, 0 ); gdk_cairo_set_source_pixbuf( cr, bg_pixbuf, 0, 0 );
cairo_paint( cr ); cairo_paint( cr );
@ -1772,7 +1756,7 @@ static int draw_faceplate( GtkWidget* ui_background, GdkEventConfigure* event, g
tiny_font_measure_text( key->left, &wl, &hl, &a, &dl ); tiny_font_measure_text( key->left, &wl, &hl, &a, &dl );
if ( !key->right ) { if ( !key->right ) {
xl = key->x + ( key->width - wl ) / 2; xl = key->x + ( key->width - wl ) / 2;
tiny_font_draw_text( ui->bg_pixmap, &ui->colors[ left_color ], ui->kb_x_offset + xl, ui->kb_y_offset + key->y - hl + dl + 1, tiny_font_draw_text( bg_pixmap, &ui->colors[ left_color ], ui->kb_x_offset + xl, ui->kb_y_offset + key->y - hl + dl + 1,
key->left ); key->left );
} }
} }
@ -1781,7 +1765,7 @@ static int draw_faceplate( GtkWidget* ui_background, GdkEventConfigure* event, g
tiny_font_measure_text( key->right, &wr, &hr, &a, &dr ); tiny_font_measure_text( key->right, &wr, &hr, &a, &dr );
if ( !key->left ) { if ( !key->left ) {
xr = key->x + ( key->width - wr ) / 2; xr = key->x + ( key->width - wr ) / 2;
tiny_font_draw_text( ui->bg_pixmap, &ui->colors[ right_color ], ui->kb_x_offset + xr, tiny_font_draw_text( bg_pixmap, &ui->colors[ right_color ], ui->kb_x_offset + xr,
ui->kb_y_offset + key->y - hr + dr + 1, key->right ); ui->kb_y_offset + key->y - hr + dr + 1, key->right );
} }
} }
@ -1795,15 +1779,15 @@ static int draw_faceplate( GtkWidget* ui_background, GdkEventConfigure* event, g
xr -= ( key->width - 4 - ( wl + wr ) ) / 2; xr -= ( key->width - 4 - ( wl + wr ) ) / 2;
} }
tiny_font_draw_text( ui->bg_pixmap, &ui->colors[ left_color ], ui->kb_x_offset + xl, ui->kb_y_offset + key->y - hl + dl + 1, tiny_font_draw_text( bg_pixmap, &ui->colors[ left_color ], ui->kb_x_offset + xl, ui->kb_y_offset + key->y - hl + dl + 1,
key->left ); key->left );
tiny_font_draw_text( ui->bg_pixmap, &ui->colors[ right_color ], ui->kb_x_offset + xr, ui->kb_y_offset + key->y - hr + dr + 1, tiny_font_draw_text( bg_pixmap, &ui->colors[ right_color ], ui->kb_x_offset + xr, ui->kb_y_offset + key->y - hr + dr + 1,
key->right ); key->right );
} }
if ( key->letter ) { if ( key->letter ) {
cr = gdk_cairo_create( ui->bg_pixmap ); cr = gdk_cairo_create( bg_pixmap );
regular_font_draw_text( cr, &ui->colors[ UI_COLOR_YELLOW ], key->letter_size, 0.0, ui->kb_x_offset + key->x + key->width, regular_font_draw_text( cr, &ui->colors[ UI_COLOR_YELLOW ], key->letter_size, 0.0, ui->kb_x_offset + key->x + key->width,
ui->kb_y_offset + key->y + key->height, CAIRO_FONT_SLANT_NORMAL, key->font_weight, key->letter ); ui->kb_y_offset + key->y + key->height, CAIRO_FONT_SLANT_NORMAL, key->font_weight, key->letter );
@ -1815,17 +1799,17 @@ static int draw_faceplate( GtkWidget* ui_background, GdkEventConfigure* event, g
tiny_font_measure_text( key->below, &wl, &hl, &a, &dl ); tiny_font_measure_text( key->below, &wl, &hl, &a, &dl );
xl = key->x + ( key->width - wl ) / 2; xl = key->x + ( key->width - wl ) / 2;
tiny_font_draw_text( ui->bg_pixmap, &ui->colors[ below_color ], ui->kb_x_offset + xl, tiny_font_draw_text( bg_pixmap, &ui->colors[ below_color ], ui->kb_x_offset + xl,
ui->kb_y_offset + key->y + key->height + 2, key->below ); ui->kb_y_offset + key->y + key->height + 2, key->below );
} }
#if DEBUG_LAYOUT /* Debug Button Layout */ #if DEBUG_LAYOUT /* Debug Button Layout */
gdk_draw_rectangle( ui->bg_pixmap, gtk_widget_get_style( ui->window )->white_gc, false, ui->kb_x_offset + key->x, gdk_draw_rectangle( bg_pixmap, gtk_widget_get_style( ui->window )->white_gc, false, ui->kb_x_offset + key->x,
ui->kb_y_offset + key->y, key->width, key->height ); ui->kb_y_offset + key->y, key->width, key->height );
#endif #endif
} }
gdk_window_set_back_pixmap( gtk_widget_get_window( ui_background ), ui->bg_pixmap, false ); gdk_window_set_back_pixmap( gtk_widget_get_window( ui_background ), bg_pixmap, false );
return false; return false;
} }
@ -1990,12 +1974,6 @@ static inline void _ui_load__newrplify_ui_keys()
ui_keys[ 50 ].left = NULL; ui_keys[ 50 ].left = NULL;
} }
static void _ui_load__place_ui_element_at( x49gp_t* x49gp, GtkFixed* fixed, GtkWidget* widget, gint x, gint y, gint width, gint height )
{
gtk_widget_set_size_request( widget, width, height );
gtk_fixed_put( fixed, widget, x, y );
}
static int ui_load( x49gp_module_t* module, GKeyFile* keyfile ) static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
{ {
x49gp_t* x49gp = module->x49gp; x49gp_t* x49gp = module->x49gp;
@ -2074,38 +2052,33 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
} }
// create window and widgets/stuff // create window and widgets/stuff
GtkWidget* lcd_canvas_container; GtkWidget* lcd_canvas_container = gtk_event_box_new();
GtkWidget* fixed_widgets_container = gtk_fixed_new();
GtkWidget* faceplate = gtk_drawing_area_new();
{ {
//ui->bg_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, FALSE, 8, ui->width, ui->height );
ui->window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); ui->window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_default_size( GTK_WINDOW( ui->window ), ui->width, ui->height ); gtk_window_set_default_size( GTK_WINDOW( ui->window ), ui->width, ui->height );
gtk_window_set_accept_focus( GTK_WINDOW( ui->window ), true ); gtk_window_set_accept_focus( GTK_WINDOW( ui->window ), true );
gtk_window_set_focus_on_map( GTK_WINDOW( ui->window ), true ); gtk_window_set_focus_on_map( GTK_WINDOW( ui->window ), true );
gtk_window_set_decorated( GTK_WINDOW( ui->window ), true ); gtk_window_set_decorated( GTK_WINDOW( ui->window ), true );
gtk_window_set_resizable( GTK_WINDOW( ui->window ), true ); gtk_window_set_resizable( GTK_WINDOW( ui->window ), true );
gtk_widget_set_name( ui->window, ui->name );
gtk_window_set_title( GTK_WINDOW( ui->window ), ui->name ); gtk_window_set_title( GTK_WINDOW( ui->window ), ui->name );
gtk_widget_set_name( ui->window, ui->name );
gtk_widget_realize( ui->window ); gtk_widget_realize( ui->window );
ui->fixed = gtk_fixed_new(); gtk_container_add( GTK_CONTAINER( ui->window ), fixed_widgets_container );
gtk_container_add( GTK_CONTAINER( ui->window ), ui->fixed );
ui->background = gtk_drawing_area_new(); gtk_widget_set_size_request( faceplate, ui->width, ui->height );
gtk_widget_set_size_request (ui->background, ui->width, ui->height); gtk_fixed_put( GTK_FIXED( fixed_widgets_container ), faceplate, 0, 0 );
_ui_load__place_ui_element_at( x49gp, GTK_FIXED( ui->fixed ), ui->background, 0, 0, ui->width, ui->height );
ui->lcd_canvas = gtk_drawing_area_new(); ui->lcd_canvas = gtk_drawing_area_new();
gtk_drawing_area_size( GTK_DRAWING_AREA( ui->lcd_canvas ), ui->lcd_width, ui->lcd_height ); gtk_drawing_area_size( GTK_DRAWING_AREA( ui->lcd_canvas ), ui->lcd_width, ui->lcd_height );
lcd_canvas_container = gtk_event_box_new();
gtk_event_box_set_visible_window( GTK_EVENT_BOX( lcd_canvas_container ), true ); gtk_event_box_set_visible_window( GTK_EVENT_BOX( lcd_canvas_container ), true );
gtk_event_box_set_above_child( GTK_EVENT_BOX( lcd_canvas_container ), false ); gtk_event_box_set_above_child( GTK_EVENT_BOX( lcd_canvas_container ), false );
gtk_container_add( GTK_CONTAINER( lcd_canvas_container ), ui->lcd_canvas ); gtk_container_add( GTK_CONTAINER( lcd_canvas_container ), ui->lcd_canvas );
_ui_load__place_ui_element_at( x49gp, GTK_FIXED( ui->fixed ), lcd_canvas_container, ui->lcd_x_offset, ui->lcd_y_offset, ui->lcd_width, gtk_widget_set_size_request( lcd_canvas_container, ui->lcd_width, ui->lcd_height );
ui->lcd_height ); gtk_fixed_put( GTK_FIXED( fixed_widgets_container ), lcd_canvas_container, ui->lcd_x_offset, ui->lcd_y_offset );
} }
// keyboard // keyboard
@ -2144,8 +2117,9 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
gtk_event_box_set_above_child( GTK_EVENT_BOX( button->box ), false ); gtk_event_box_set_above_child( GTK_EVENT_BOX( button->box ), false );
gtk_container_add( GTK_CONTAINER( button->box ), button->button ); gtk_container_add( GTK_CONTAINER( button->box ), button->button );
_ui_load__place_ui_element_at( x49gp, GTK_FIXED( ui->fixed ), button->box, ui->kb_x_offset + ui_keys[ i ].x, gtk_widget_set_size_request( button->box, ui_keys[ i ].width, ui_keys[ i ].height );
ui->kb_y_offset + ui_keys[ i ].y, ui_keys[ i ].width, ui_keys[ i ].height ); gtk_fixed_put( GTK_FIXED( fixed_widgets_container ), button->box, ui->kb_x_offset + ui_keys[ i ].x,
ui->kb_y_offset + ui_keys[ i ].y );
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 );
@ -2197,7 +2171,7 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
// setup signals and events // setup signals and events
{ {
g_signal_connect( G_OBJECT( ui->background ), "configure-event", G_CALLBACK( draw_faceplate ), x49gp ); g_signal_connect( G_OBJECT( faceplate ), "configure-event", G_CALLBACK( draw_faceplate ), x49gp );
g_signal_connect( G_OBJECT( ui->lcd_canvas ), "expose-event", G_CALLBACK( redraw_lcd ), x49gp ); g_signal_connect( G_OBJECT( ui->lcd_canvas ), "expose-event", G_CALLBACK( redraw_lcd ), x49gp );
g_signal_connect( G_OBJECT( ui->lcd_canvas ), "configure-event", G_CALLBACK( draw_lcd ), x49gp ); g_signal_connect( G_OBJECT( ui->lcd_canvas ), "configure-event", G_CALLBACK( draw_lcd ), x49gp );
@ -2222,10 +2196,72 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
static int ui_save( x49gp_module_t* module, GKeyFile* keyfile ) { return 0; } static int ui_save( x49gp_module_t* module, GKeyFile* keyfile ) { return 0; }
static void _draw_pixel( GdkPixmap* target, int x, int y, int w, int h, GdkColor* color )
{
cairo_t* cr = gdk_cairo_create( target );
cairo_set_source_rgb( cr, color->red / 65535.0, color->green / 65535.0, color->blue / 65535.0 );
cairo_rectangle( cr, x, y, w, h );
cairo_fill( cr );
cairo_destroy( cr );
}
static inline void _draw_annunciator( GdkPixmap* target, cairo_surface_t* surface, int x, int y, int w, int h, GdkColor* color )
{
cairo_t* cr = gdk_cairo_create( target );
cairo_set_source_rgb( cr, color->red / 65535.0, color->green / 65535.0, color->blue / 65535.0 );
cairo_mask_surface( cr, surface, x, y );
cairo_destroy( cr );
}
/********************/ /********************/
/* Public functions */ /* Public functions */
/********************/ /********************/
void gui_update_lcd( x49gp_t* x49gp )
{
x49gp_ui_t* ui = x49gp->ui;
s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd;
if ( lcd->lcdcon1 & 1 ) {
GdkColor color;
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 1 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_left_surface, 11, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 2 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_right_surface, 56, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 3 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_alpha_surface, 101, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 4 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_battery_surface, 146, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 5 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_busy_surface, 191, 0, 15, 12, &color );
color = ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, 131, 0 ) ];
_draw_annunciator( ui->lcd_pixmap, ui->ann_io_surface, 236, 0, 15, 12, &color );
for ( int y = 0; y < ( ( ui->lcd_height - ui->lcd_annunciators_height ) / LCD_PIXEL_SCALE ); y++ )
for ( int x = 0; x < ( ui->lcd_width / LCD_PIXEL_SCALE ); x++ )
_draw_pixel( ui->lcd_pixmap, LCD_PIXEL_SCALE * x, LCD_PIXEL_SCALE * y + ui->lcd_annunciators_height, LCD_PIXEL_SCALE,
LCD_PIXEL_SCALE, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, x, y ) ] ) );
}
GdkRectangle rect;
rect.x = 0;
rect.y = 0;
rect.width = ui->lcd_width;
rect.height = ui->lcd_height;
gdk_window_invalidate_rect( gtk_widget_get_window( ui->lcd_canvas ), &rect, false );
}
void gui_show_error( x49gp_t* x49gp, const char* text ) void gui_show_error( x49gp_t* x49gp, const char* text )
{ {
GtkWidget* dialog; GtkWidget* dialog;

View file

@ -74,21 +74,17 @@ typedef struct {
GtkWidget* button; GtkWidget* button;
GtkWidget* label; GtkWidget* label;
GtkWidget* box; GtkWidget* box;
GdkPixmap* pixmap; /* FIXME */ GdkPixmap* pixmap; /* FIXME */
gboolean down; gboolean down;
gboolean hold; gboolean hold;
} x49gp_ui_button_t; } x49gp_ui_button_t;
struct __x49gp_ui_s__ { struct __x49gp_ui_s__ {
GtkWidget* window; GtkWidget* window;
GtkWidget* fixed;
GtkWidget* menu; GtkWidget* menu;
GtkWidget* menu_unmount; GtkWidget* menu_unmount;
GtkWidget* menu_debug; GtkWidget* menu_debug;
GdkPixmap* bg_pixmap; /* FIXME */
GtkWidget* background;
GdkColor colors[ UI_COLOR_MAX ]; GdkColor colors[ UI_COLOR_MAX ];
x49gp_ui_calculator_t calculator; x49gp_ui_calculator_t calculator;
@ -99,7 +95,7 @@ struct __x49gp_ui_s__ {
char* name; char* name;
GtkWidget* lcd_canvas; GtkWidget* lcd_canvas;
GdkPixmap* lcd_pixmap; /* FIXME */ GdkPixmap* lcd_pixmap; /* FIXME */
cairo_surface_t* ann_left_surface; cairo_surface_t* ann_left_surface;
cairo_surface_t* ann_right_surface; cairo_surface_t* ann_right_surface;
@ -121,6 +117,8 @@ struct __x49gp_ui_s__ {
gint lcd_annunciators_height; gint lcd_annunciators_height;
}; };
void gui_update_lcd(x49gp_t *x49gp);
int gui_init( x49gp_t* x49gp ); int gui_init( x49gp_t* x49gp );
void gui_show_error( x49gp_t* x49gp, const char* text ); void gui_show_error( x49gp_t* x49gp, const char* text );
void gui_open_firmware( x49gp_t* x49gp, char** filename ); void gui_open_firmware( x49gp_t* x49gp, char** filename );