Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 23:1ec3acd0594d
prev18:9a1b5d75703f
next27:1ef09a52cd1e
author nkeynes
date Fri Dec 23 11:44:55 2005 +0000 (16 years ago)
permissions -rw-r--r--
last change Start of "real" time slices, general structure in place now
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 gui_run_slice( int millisecs ) 
    47 {
    48     while( gtk_events_pending() )
    49 	gtk_main_iteration();
    50     update_icount(main_debug);
    51 }
    53 void update_gui(void) {
    54     update_registers(main_debug);
    55     update_icount(main_debug);
    56     update_mmr_win();
    57     dump_win_update_all();
    58 }
    60 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
    61     GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
    62     if( result == GTK_RESPONSE_ACCEPT ) {
    63 	gchar *filename =gtk_file_chooser_get_filename(
    64 						       GTK_FILE_CHOOSER(file) );
    65 	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
    66 	gtk_widget_destroy(GTK_WIDGET(file));
    67 	action( filename );
    68 	g_free(filename);
    69     } else {
    70 	gtk_widget_destroy(GTK_WIDGET(file));
    71     }
    72 }
    74 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
    75 {
    76     if( pattern != NULL ) {
    77 	GtkFileFilter *filter = gtk_file_filter_new();
    78 	gtk_file_filter_add_pattern( filter, pattern );
    79 	gtk_file_filter_set_name( filter, patname );
    80 	gtk_file_chooser_add_filter( chooser, filter );
    81 	filter = gtk_file_filter_new();
    82 	gtk_file_filter_set_name( filter, "All files" );
    83 	gtk_file_filter_add_pattern( filter, "*" );
    84 	gtk_file_chooser_add_filter( chooser, filter );
    85     }
    86 }
    88 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
    89 {
    90     GtkWidget *file;
    92     file = gtk_file_chooser_dialog_new( title, NULL,
    93 					GTK_FILE_CHOOSER_ACTION_OPEN,
    94 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    95 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    96 					NULL );
    97     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    98     g_signal_connect( GTK_OBJECT(file), "response", 
    99 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   100     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   101     gtk_widget_show( file );
   102 }
   104 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
   105 {
   106     GtkWidget *file;
   108     file = gtk_file_chooser_dialog_new( title, NULL,
   109 					GTK_FILE_CHOOSER_ACTION_SAVE,
   110 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   111 					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
   112 					NULL );
   113     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   114     g_signal_connect( GTK_OBJECT(file), "response", 
   115 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   116     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   117     gtk_widget_show( file );
   118 }
   120 uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
   121 {
   122     gchar *text = gtk_entry_get_text(entry);
   123     if( text == NULL )
   124         return defaultValue;
   125     gchar *endptr;
   126     uint32_t value = strtoul( text, &endptr, 16 );
   127     if( text == endptr ) { /* invalid input */
   128         value = defaultValue;
   129         gtk_entry_set_hex_value( entry, value );
   130     }
   131     return value;
   132 }
   134 void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
   135 {
   136     char buf[10];
   137     sprintf( buf, "%08X", value );
   138     gtk_entry_set_text( entry, buf );
   139 }
.