Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 561:533f6b478071
prev543:361ec0a70cf2
next630:50addb748df5
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@561
     2
 * $Id$
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@537
    23
#include "gtkui/gtkui.h"
nkeynes@455
    24
#include "pvr2/pvr2.h"
nkeynes@543
    25
#include "loader.h"
nkeynes@435
    26
nkeynes@435
    27
nkeynes@435
    28
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@435
    29
{
nkeynes@435
    30
    if( pattern != NULL ) {
nkeynes@435
    31
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@435
    32
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@435
    33
	gtk_file_filter_set_name( filter, patname );
nkeynes@435
    34
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    35
	filter = gtk_file_filter_new();
nkeynes@508
    36
	gtk_file_filter_set_name( filter, _("All files") );
nkeynes@435
    37
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@435
    38
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    39
    }
nkeynes@435
    40
}
nkeynes@435
    41
nkeynes@435
    42
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    43
		       gchar const *initial_dir )
nkeynes@435
    44
{
nkeynes@435
    45
    GtkWidget *file;
nkeynes@435
    46
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
    47
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@435
    48
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
    49
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@435
    50
					NULL );
nkeynes@435
    51
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@435
    52
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
nkeynes@435
    53
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    54
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    55
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    56
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
    57
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
    58
	action( filename );
nkeynes@477
    59
    }
nkeynes@477
    60
    gtk_widget_destroy(file);
nkeynes@435
    61
}
nkeynes@435
    62
nkeynes@435
    63
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    64
		       gchar const *initial_dir )
nkeynes@435
    65
{
nkeynes@435
    66
    GtkWidget *file;
nkeynes@435
    67
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
    68
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@435
    69
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
    70
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@435
    71
					NULL );
nkeynes@435
    72
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@435
    73
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
nkeynes@435
    74
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    75
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    76
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    77
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
    78
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
    79
	action( filename );
nkeynes@477
    80
    }
nkeynes@477
    81
    gtk_widget_destroy(file);
nkeynes@435
    82
}
nkeynes@435
    83
nkeynes@435
    84
void mount_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    85
{
nkeynes@450
    86
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@435
    87
    open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
nkeynes@435
    88
}
nkeynes@435
    89
void reset_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    90
{
nkeynes@435
    91
    dreamcast_reset();
nkeynes@435
    92
}
nkeynes@435
    93
nkeynes@435
    94
void pause_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    95
{
nkeynes@435
    96
    dreamcast_stop();
nkeynes@435
    97
}
nkeynes@435
    98
nkeynes@435
    99
void resume_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   100
{
nkeynes@435
   101
    dreamcast_run();
nkeynes@435
   102
}
nkeynes@435
   103
nkeynes@543
   104
void load_binary_action_callback( GtkAction *action, gpointer user_data)
nkeynes@543
   105
{
nkeynes@543
   106
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@543
   107
    open_file_dialog( "Open Binary...", file_load_magic, NULL, NULL, dir );
nkeynes@543
   108
}
nkeynes@543
   109
nkeynes@477
   110
void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
nkeynes@477
   111
{
nkeynes@477
   112
    GtkWidget *preview = GTK_WIDGET(user_data);
nkeynes@477
   113
    gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
nkeynes@477
   114
    
nkeynes@477
   115
    frame_buffer_t data = dreamcast_load_preview(filename);
nkeynes@477
   116
    if( data != NULL ) {
nkeynes@477
   117
	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
nkeynes@477
   118
	GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
nkeynes@477
   119
						    GDK_INTERP_BILINEAR);
nkeynes@477
   120
	g_object_unref(pixbuf);
nkeynes@477
   121
	gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
nkeynes@477
   122
	g_object_unref(scaled);
nkeynes@477
   123
	gtk_widget_show(preview);
nkeynes@477
   124
    } else {
nkeynes@477
   125
	gtk_widget_hide(preview);
nkeynes@477
   126
    }
nkeynes@477
   127
}
nkeynes@477
   128
nkeynes@435
   129
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   130
{
nkeynes@477
   131
    GtkWidget *file, *preview, *frame, *align;
nkeynes@477
   132
    GtkRequisition size;
nkeynes@450
   133
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@508
   134
    file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
nkeynes@477
   135
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@477
   136
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@477
   137
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@477
   138
					NULL );
nkeynes@508
   139
    add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
nkeynes@477
   140
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@477
   141
nkeynes@477
   142
    preview = gtk_image_new( );
nkeynes@477
   143
nkeynes@477
   144
    frame = gtk_frame_new(NULL);
nkeynes@477
   145
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@477
   146
    gtk_container_add( GTK_CONTAINER(frame), preview );
nkeynes@477
   147
    gtk_widget_show(frame);
nkeynes@477
   148
    gtk_widget_size_request(frame, &size);
nkeynes@477
   149
    gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
nkeynes@477
   150
    align = gtk_alignment_new(0.5, 0.5, 0, 0 );
nkeynes@477
   151
    gtk_container_add( GTK_CONTAINER(align), frame );
nkeynes@477
   152
    gtk_widget_show( align );
nkeynes@477
   153
    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
nkeynes@477
   154
    g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
nkeynes@477
   155
		      preview );
nkeynes@477
   156
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), dir );
nkeynes@477
   157
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
   158
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
   159
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
   160
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
   161
	dreamcast_load_state( filename );
nkeynes@477
   162
    }
nkeynes@477
   163
    gtk_widget_destroy(file);
nkeynes@435
   164
}
nkeynes@477
   165
nkeynes@435
   166
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   167
{
nkeynes@450
   168
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@508
   169
    save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), dir );
nkeynes@435
   170
}
nkeynes@435
   171
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   172
{
nkeynes@435
   173
    
nkeynes@435
   174
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@435
   175
				      "name", APP_NAME, 
nkeynes@435
   176
                                     "version", APP_VERSION,
nkeynes@435
   177
			             "copyright", "(C) 2003-2007 Nathan Keynes",
nkeynes@435
   178
                                     NULL);
nkeynes@435
   179
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   180
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   181
    gtk_widget_destroy(dialog);
nkeynes@435
   182
    
nkeynes@435
   183
}
nkeynes@435
   184
nkeynes@435
   185
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   186
{
nkeynes@435
   187
    exit(0);
nkeynes@435
   188
}
nkeynes@435
   189
nkeynes@447
   190
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   191
{
nkeynes@450
   192
    path_dialog_run();
nkeynes@447
   193
}
nkeynes@447
   194
nkeynes@435
   195
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   196
{
nkeynes@435
   197
}
nkeynes@435
   198
nkeynes@455
   199
void maple_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   200
{
nkeynes@455
   201
    maple_dialog_run( );
nkeynes@435
   202
}
nkeynes@435
   203
nkeynes@435
   204
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   205
{
nkeynes@435
   206
}
nkeynes@435
   207
nkeynes@435
   208
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   209
{
nkeynes@435
   210
}
nkeynes@435
   211
nkeynes@435
   212
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   213
{
nkeynes@486
   214
    main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
nkeynes@435
   215
}
nkeynes@455
   216
nkeynes@455
   217
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   218
{
nkeynes@455
   219
    gtk_gui_show_debugger();
nkeynes@455
   220
}
nkeynes@455
   221
nkeynes@455
   222
void debug_memory_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   223
{
nkeynes@508
   224
    gchar *title = g_strdup_printf( APP_NAME " " APP_VERSION " :: %s", _("Memory dump") );
nkeynes@508
   225
    dump_window_new( title );
nkeynes@508
   226
    g_free(title);
nkeynes@455
   227
}
nkeynes@455
   228
nkeynes@455
   229
void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   230
{
nkeynes@455
   231
    gtk_gui_show_mmio();
nkeynes@455
   232
}
nkeynes@455
   233
nkeynes@455
   234
void save_scene_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   235
{
nkeynes@455
   236
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@508
   237
    save_file_dialog( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), dir );
nkeynes@455
   238
}
nkeynes@455
   239
nkeynes@480
   240
int debug_window_get_selected_row( debug_window_t data );
nkeynes@480
   241
nkeynes@455
   242
void debug_step_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   243
{
nkeynes@455
   244
    debug_window_single_step(gtk_gui_get_debugger());
nkeynes@455
   245
}
nkeynes@455
   246
nkeynes@455
   247
void debug_runto_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   248
{
nkeynes@455
   249
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   250
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   251
    if( selected_row == -1 ) {
nkeynes@508
   252
        WARN( _("No address selected, so can't run to it"), NULL );
nkeynes@455
   253
    } else {
nkeynes@455
   254
	debug_window_set_oneshot_breakpoint( debug, selected_row );
nkeynes@455
   255
	dreamcast_run();
nkeynes@455
   256
    }
nkeynes@455
   257
}
nkeynes@455
   258
nkeynes@455
   259
void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   260
{
nkeynes@455
   261
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   262
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   263
    if( selected_row != -1 ) {
nkeynes@455
   264
	debug_window_toggle_breakpoint( debug, selected_row );
nkeynes@455
   265
    }
nkeynes@455
   266
}
.