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