Search
lxdream.org :: lxdream/src/gui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkcb.c
changeset 455:3080881d00d4
prev450:207461e79f21
next477:9a373f2ff009
author nkeynes
date Sun Oct 21 05:21:35 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change More GUI WIP
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@455
     2
 * $Id: gtkcb.c,v 1.5 2007-10-21 05:21:35 nkeynes Exp $
nkeynes@435
     3
 *
nkeynes@435
     4
 * Action callbacks from the main window
nkeynes@435
     5
 *
nkeynes@435
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     7
 *
nkeynes@435
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    11
 * (at your option) any later version.
nkeynes@435
    12
 *
nkeynes@435
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    16
 * GNU General Public License for more details.
nkeynes@435
    17
 */
nkeynes@435
    18
nkeynes@435
    19
#include "dream.h"
nkeynes@450
    20
#include "config.h"
nkeynes@435
    21
#include "dreamcast.h"
nkeynes@435
    22
#include "gdrom/gdrom.h"
nkeynes@435
    23
#include "gui/gtkui.h"
nkeynes@455
    24
#include "pvr2/pvr2.h"
nkeynes@435
    25
nkeynes@435
    26
typedef gboolean (*file_callback_t)( const gchar *filename );
nkeynes@435
    27
nkeynes@435
    28
static gboolean dreamcast_paused = FALSE;
nkeynes@435
    29
nkeynes@435
    30
void dreamcast_pause()
nkeynes@435
    31
{
nkeynes@435
    32
    if( dreamcast_is_running() ) {
nkeynes@435
    33
	dreamcast_paused = TRUE;
nkeynes@435
    34
	dreamcast_stop();
nkeynes@435
    35
    }
nkeynes@435
    36
}
nkeynes@435
    37
nkeynes@435
    38
void dreamcast_unpause()
nkeynes@435
    39
{
nkeynes@435
    40
    if( dreamcast_paused ) {
nkeynes@435
    41
	dreamcast_paused = FALSE;
nkeynes@435
    42
	if( !dreamcast_is_running() ) {
nkeynes@435
    43
	    dreamcast_run();
nkeynes@435
    44
	}
nkeynes@435
    45
    }
nkeynes@435
    46
}
nkeynes@435
    47
nkeynes@435
    48
nkeynes@435
    49
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
nkeynes@435
    50
    GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
nkeynes@435
    51
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@435
    52
	gchar *filename =gtk_file_chooser_get_filename(
nkeynes@435
    53
						       GTK_FILE_CHOOSER(file) );
nkeynes@435
    54
	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
nkeynes@435
    55
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@435
    56
	action( filename );
nkeynes@435
    57
	g_free(filename);
nkeynes@435
    58
    } else {
nkeynes@435
    59
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@435
    60
    }
nkeynes@435
    61
    dreamcast_unpause();
nkeynes@435
    62
}
nkeynes@435
    63
nkeynes@435
    64
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@435
    65
{
nkeynes@435
    66
    if( pattern != NULL ) {
nkeynes@435
    67
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@435
    68
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@435
    69
	gtk_file_filter_set_name( filter, patname );
nkeynes@435
    70
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    71
	filter = gtk_file_filter_new();
nkeynes@435
    72
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@435
    73
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@435
    74
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    75
    }
nkeynes@435
    76
}
nkeynes@435
    77
nkeynes@435
    78
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    79
		       gchar const *initial_dir )
nkeynes@435
    80
{
nkeynes@435
    81
    GtkWidget *file;
nkeynes@435
    82
    dreamcast_pause();
nkeynes@435
    83
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
    84
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@435
    85
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
    86
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@435
    87
					NULL );
nkeynes@435
    88
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@435
    89
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@435
    90
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@435
    91
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@435
    92
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
nkeynes@435
    93
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@435
    94
    gtk_widget_show( file );
nkeynes@435
    95
}
nkeynes@435
    96
nkeynes@435
    97
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    98
		       gchar const *initial_dir )
nkeynes@435
    99
{
nkeynes@435
   100
    GtkWidget *file;
nkeynes@435
   101
    dreamcast_pause();
nkeynes@435
   102
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
   103
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@435
   104
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
   105
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@435
   106
					NULL );
nkeynes@435
   107
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@435
   108
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@435
   109
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@435
   110
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@435
   111
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
nkeynes@435
   112
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@435
   113
    gtk_widget_show( file );
nkeynes@435
   114
}
nkeynes@435
   115
nkeynes@435
   116
void mount_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   117
{
nkeynes@450
   118
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@435
   119
    open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
nkeynes@435
   120
}
nkeynes@435
   121
void reset_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   122
{
nkeynes@435
   123
    dreamcast_reset();
nkeynes@435
   124
}
nkeynes@435
   125
nkeynes@435
   126
void pause_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   127
{
nkeynes@435
   128
    dreamcast_stop();
nkeynes@435
   129
}
nkeynes@435
   130
nkeynes@435
   131
void resume_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   132
{
nkeynes@435
   133
    dreamcast_run();
nkeynes@435
   134
}
nkeynes@435
   135
nkeynes@435
   136
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   137
{
nkeynes@450
   138
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@435
   139
    open_file_dialog( "Load state...", dreamcast_load_state, "*.dst", "lxDream Save State (*.dst)", dir );
nkeynes@435
   140
}
nkeynes@435
   141
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   142
{
nkeynes@450
   143
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@435
   144
    save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", "lxDream Save State (*.dst)", dir );
nkeynes@435
   145
}
nkeynes@435
   146
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   147
{
nkeynes@435
   148
    
nkeynes@435
   149
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@435
   150
				      "name", APP_NAME, 
nkeynes@435
   151
                                     "version", APP_VERSION,
nkeynes@435
   152
			             "copyright", "(C) 2003-2007 Nathan Keynes",
nkeynes@435
   153
                                     NULL);
nkeynes@435
   154
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   155
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   156
    gtk_widget_destroy(dialog);
nkeynes@435
   157
    
nkeynes@435
   158
}
nkeynes@435
   159
nkeynes@435
   160
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   161
{
nkeynes@435
   162
    exit(0);
nkeynes@435
   163
}
nkeynes@435
   164
nkeynes@447
   165
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   166
{
nkeynes@450
   167
    path_dialog_run();
nkeynes@447
   168
}
nkeynes@447
   169
nkeynes@435
   170
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   171
{
nkeynes@435
   172
}
nkeynes@435
   173
nkeynes@455
   174
void maple_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   175
{
nkeynes@455
   176
    maple_dialog_run( );
nkeynes@435
   177
}
nkeynes@435
   178
nkeynes@435
   179
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   180
{
nkeynes@435
   181
}
nkeynes@435
   182
nkeynes@435
   183
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   184
{
nkeynes@435
   185
}
nkeynes@435
   186
nkeynes@435
   187
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   188
{
nkeynes@435
   189
}
nkeynes@455
   190
nkeynes@455
   191
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   192
{
nkeynes@455
   193
    gtk_gui_show_debugger();
nkeynes@455
   194
}
nkeynes@455
   195
nkeynes@455
   196
void debug_memory_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   197
{
nkeynes@455
   198
    dump_window_new( APP_NAME " " APP_VERSION " :: Memory dump" );
nkeynes@455
   199
}
nkeynes@455
   200
nkeynes@455
   201
void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   202
{
nkeynes@455
   203
    gtk_gui_show_mmio();
nkeynes@455
   204
}
nkeynes@455
   205
nkeynes@455
   206
void save_scene_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   207
{
nkeynes@455
   208
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@455
   209
    save_file_dialog( "Save next scene...", pvr2_save_next_scene, "*.dsc", "lxdream scene file (*.dsc)", dir );
nkeynes@455
   210
}
nkeynes@455
   211
nkeynes@455
   212
void debug_step_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   213
{
nkeynes@455
   214
    debug_window_single_step(gtk_gui_get_debugger());
nkeynes@455
   215
}
nkeynes@455
   216
nkeynes@455
   217
void debug_runto_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   218
{
nkeynes@455
   219
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   220
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   221
    if( selected_row == -1 ) {
nkeynes@455
   222
        WARN( "No address selected, so can't run to it", NULL );
nkeynes@455
   223
    } else {
nkeynes@455
   224
	debug_window_set_oneshot_breakpoint( debug, selected_row );
nkeynes@455
   225
	dreamcast_run();
nkeynes@455
   226
    }
nkeynes@455
   227
}
nkeynes@455
   228
nkeynes@455
   229
void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   230
{
nkeynes@455
   231
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   232
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   233
    if( selected_row != -1 ) {
nkeynes@455
   234
	debug_window_toggle_breakpoint( debug, selected_row );
nkeynes@455
   235
    }
nkeynes@455
   236
}
.