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
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@2
    46
void update_gui(void) {
nkeynes@9
    47
    update_registers(main_debug);
nkeynes@9
    48
    update_icount(main_debug);
nkeynes@1
    49
    update_mmr_win();
nkeynes@2
    50
    dump_win_update_all();
nkeynes@1
    51
}
nkeynes@1
    52
nkeynes@18
    53
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
nkeynes@18
    54
    GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
nkeynes@18
    55
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@18
    56
	gchar *filename =gtk_file_chooser_get_filename(
nkeynes@18
    57
						       GTK_FILE_CHOOSER(file) );
nkeynes@18
    58
	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
nkeynes@18
    59
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
    60
	action( filename );
nkeynes@18
    61
	g_free(filename);
nkeynes@18
    62
    } else {
nkeynes@18
    63
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
    64
    }
nkeynes@1
    65
}
nkeynes@1
    66
nkeynes@18
    67
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@18
    68
{
nkeynes@18
    69
    if( pattern != NULL ) {
nkeynes@18
    70
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@18
    71
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@18
    72
	gtk_file_filter_set_name( filter, patname );
nkeynes@18
    73
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
    74
	filter = gtk_file_filter_new();
nkeynes@18
    75
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@18
    76
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@18
    77
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
    78
    }
nkeynes@1
    79
}
nkeynes@1
    80
nkeynes@18
    81
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@1
    82
{
nkeynes@1
    83
    GtkWidget *file;
nkeynes@1
    84
nkeynes@18
    85
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
    86
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@18
    87
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
    88
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@18
    89
					NULL );
nkeynes@18
    90
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
    91
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
    92
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
    93
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@18
    94
    gtk_widget_show( file );
nkeynes@18
    95
}
nkeynes@18
    96
nkeynes@18
    97
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@18
    98
{
nkeynes@18
    99
    GtkWidget *file;
nkeynes@18
   100
nkeynes@18
   101
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   102
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@18
   103
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   104
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@18
   105
					NULL );
nkeynes@18
   106
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   107
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   108
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   109
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@1
   110
    gtk_widget_show( file );
nkeynes@1
   111
}
nkeynes@1
   112
nkeynes@2
   113
uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
nkeynes@1
   114
{
nkeynes@2
   115
    gchar *text = gtk_entry_get_text(entry);
nkeynes@2
   116
    if( text == NULL )
nkeynes@2
   117
        return defaultValue;
nkeynes@2
   118
    gchar *endptr;
nkeynes@2
   119
    uint32_t value = strtoul( text, &endptr, 16 );
nkeynes@2
   120
    if( text == endptr ) { /* invalid input */
nkeynes@2
   121
        value = defaultValue;
nkeynes@2
   122
        gtk_entry_set_hex_value( entry, value );
nkeynes@2
   123
    }
nkeynes@2
   124
    return value;
nkeynes@1
   125
}
nkeynes@1
   126
nkeynes@2
   127
void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
nkeynes@1
   128
{
nkeynes@2
   129
    char buf[10];
nkeynes@2
   130
    sprintf( buf, "%08X", value );
nkeynes@2
   131
    gtk_entry_set_text( entry, buf );
nkeynes@1
   132
}
.