Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 18:9a1b5d75703f
prev9:2784c7660165
next23:1ec3acd0594d
author nkeynes
date Thu Dec 15 13:33:14 2005 +0000 (16 years ago)
permissions -rw-r--r--
last change Implement save states
view annotate diff log raw
     1 #include <stdlib.h>
     2 #include <stdarg.h>
     3 #include <gnome.h>
     4 #include <math.h>
     5 #include "dreamcast.h"
     6 #include "gui.h"
     7 #include "mem.h"
     8 #include "sh4dasm.h"
     9 #include "sh4core.h"
    11 #define REGISTER_FONT "-*-fixed-medium-r-normal--12-*-*-*-*-*-iso8859-1"
    13 GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;
    14 PangoFontDescription *fixed_list_font;
    16 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data);
    18 void init_gui() {
    19     GdkColormap *map;
    21     clrNormal.red = clrNormal.green = clrNormal.blue = 0;
    22     clrChanged.red = clrChanged.green = 64*256;
    23     clrChanged.blue = 154*256;
    24     clrError.red = 65535;
    25     clrError.green = clrError.blue = 64*256;
    26     clrPC.red = 32*256;
    27     clrPC.green = 170*256;
    28     clrPC.blue = 52*256;
    29     clrWarn = clrChanged;
    30     clrTrace.red = 156*256;
    31     clrTrace.green = 78*256;
    32     clrTrace.blue = 201*256;
    33     clrDebug = clrPC;
    35     map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
    36     gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
    37     gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
    38     gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
    39     gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
    40     gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
    41     gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
    42     gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
    43     fixed_list_font = pango_font_description_from_string("Courier 10");
    44 }
    46 void update_gui(void) {
    47     update_registers(main_debug);
    48     update_icount(main_debug);
    49     update_mmr_win();
    50     dump_win_update_all();
    51 }
    53 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
    54     GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
    55     if( result == GTK_RESPONSE_ACCEPT ) {
    56 	gchar *filename =gtk_file_chooser_get_filename(
    57 						       GTK_FILE_CHOOSER(file) );
    58 	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
    59 	gtk_widget_destroy(GTK_WIDGET(file));
    60 	action( filename );
    61 	g_free(filename);
    62     } else {
    63 	gtk_widget_destroy(GTK_WIDGET(file));
    64     }
    65 }
    67 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
    68 {
    69     if( pattern != NULL ) {
    70 	GtkFileFilter *filter = gtk_file_filter_new();
    71 	gtk_file_filter_add_pattern( filter, pattern );
    72 	gtk_file_filter_set_name( filter, patname );
    73 	gtk_file_chooser_add_filter( chooser, filter );
    74 	filter = gtk_file_filter_new();
    75 	gtk_file_filter_set_name( filter, "All files" );
    76 	gtk_file_filter_add_pattern( filter, "*" );
    77 	gtk_file_chooser_add_filter( chooser, filter );
    78     }
    79 }
    81 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
    82 {
    83     GtkWidget *file;
    85     file = gtk_file_chooser_dialog_new( title, NULL,
    86 					GTK_FILE_CHOOSER_ACTION_OPEN,
    87 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    88 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    89 					NULL );
    90     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    91     g_signal_connect( GTK_OBJECT(file), "response", 
    92 		      GTK_SIGNAL_FUNC(open_file_callback), file );
    93     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
    94     gtk_widget_show( file );
    95 }
    97 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
    98 {
    99     GtkWidget *file;
   101     file = gtk_file_chooser_dialog_new( title, NULL,
   102 					GTK_FILE_CHOOSER_ACTION_SAVE,
   103 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   104 					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
   105 					NULL );
   106     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   107     g_signal_connect( GTK_OBJECT(file), "response", 
   108 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   109     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   110     gtk_widget_show( file );
   111 }
   113 uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
   114 {
   115     gchar *text = gtk_entry_get_text(entry);
   116     if( text == NULL )
   117         return defaultValue;
   118     gchar *endptr;
   119     uint32_t value = strtoul( text, &endptr, 16 );
   120     if( text == endptr ) { /* invalid input */
   121         value = defaultValue;
   122         gtk_entry_set_hex_value( entry, value );
   123     }
   124     return value;
   125 }
   127 void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
   128 {
   129     char buf[10];
   130     sprintf( buf, "%08X", value );
   131     gtk_entry_set_text( entry, buf );
   132 }
.