Search
lxdream.org :: lxdream/src/gui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkcb.c
changeset 477:9a373f2ff009
prev455:3080881d00d4
next480:d28c2992f5ee
author nkeynes
date Wed Oct 31 09:10:23 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Add save/restore of render buffers in save states
Gzip memory blocks in save states
Move front-buffer management back to pvr2
Add screenshot preview when loading save states
Various minor fixes and cleanups
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@477
     2
 * $Id: gtkcb.c,v 1.6 2007-10-31 09:10:23 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
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@435
    50
{
nkeynes@435
    51
    if( pattern != NULL ) {
nkeynes@435
    52
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@435
    53
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@435
    54
	gtk_file_filter_set_name( filter, patname );
nkeynes@435
    55
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    56
	filter = gtk_file_filter_new();
nkeynes@435
    57
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@435
    58
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@435
    59
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    60
    }
nkeynes@435
    61
}
nkeynes@435
    62
nkeynes@435
    63
void open_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_OPEN,
nkeynes@435
    69
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
    70
					GTK_STOCK_OPEN, 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 save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    85
		       gchar const *initial_dir )
nkeynes@435
    86
{
nkeynes@435
    87
    GtkWidget *file;
nkeynes@435
    88
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
    89
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@435
    90
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
    91
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@435
    92
					NULL );
nkeynes@435
    93
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@435
    94
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
nkeynes@435
    95
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    96
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    97
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    98
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
    99
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
   100
	action( filename );
nkeynes@477
   101
    }
nkeynes@477
   102
    gtk_widget_destroy(file);
nkeynes@435
   103
}
nkeynes@435
   104
nkeynes@435
   105
void mount_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   106
{
nkeynes@450
   107
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@435
   108
    open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
nkeynes@435
   109
}
nkeynes@435
   110
void reset_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   111
{
nkeynes@435
   112
    dreamcast_reset();
nkeynes@435
   113
}
nkeynes@435
   114
nkeynes@435
   115
void pause_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   116
{
nkeynes@435
   117
    dreamcast_stop();
nkeynes@435
   118
}
nkeynes@435
   119
nkeynes@435
   120
void resume_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   121
{
nkeynes@435
   122
    dreamcast_run();
nkeynes@435
   123
}
nkeynes@435
   124
nkeynes@477
   125
void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
nkeynes@477
   126
{
nkeynes@477
   127
    GtkWidget *preview = GTK_WIDGET(user_data);
nkeynes@477
   128
    gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
nkeynes@477
   129
    
nkeynes@477
   130
    frame_buffer_t data = dreamcast_load_preview(filename);
nkeynes@477
   131
    if( data != NULL ) {
nkeynes@477
   132
	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
nkeynes@477
   133
	GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
nkeynes@477
   134
						    GDK_INTERP_BILINEAR);
nkeynes@477
   135
	g_object_unref(pixbuf);
nkeynes@477
   136
	gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
nkeynes@477
   137
	g_object_unref(scaled);
nkeynes@477
   138
	gtk_widget_show(preview);
nkeynes@477
   139
    } else {
nkeynes@477
   140
	gtk_widget_hide(preview);
nkeynes@477
   141
    }
nkeynes@477
   142
}
nkeynes@477
   143
nkeynes@435
   144
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   145
{
nkeynes@477
   146
    GtkWidget *file, *preview, *frame, *align;
nkeynes@477
   147
    GtkRequisition size;
nkeynes@450
   148
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@477
   149
    file = gtk_file_chooser_dialog_new( "Load state...", NULL,
nkeynes@477
   150
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@477
   151
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@477
   152
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@477
   153
					NULL );
nkeynes@477
   154
    add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", "lxDream Save State (*.dst)" );
nkeynes@477
   155
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@477
   156
nkeynes@477
   157
    preview = gtk_image_new( );
nkeynes@477
   158
nkeynes@477
   159
    frame = gtk_frame_new(NULL);
nkeynes@477
   160
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@477
   161
    gtk_container_add( GTK_CONTAINER(frame), preview );
nkeynes@477
   162
    gtk_widget_show(frame);
nkeynes@477
   163
    gtk_widget_size_request(frame, &size);
nkeynes@477
   164
    gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
nkeynes@477
   165
    align = gtk_alignment_new(0.5, 0.5, 0, 0 );
nkeynes@477
   166
    gtk_container_add( GTK_CONTAINER(align), frame );
nkeynes@477
   167
    gtk_widget_show( align );
nkeynes@477
   168
    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
nkeynes@477
   169
    g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
nkeynes@477
   170
		      preview );
nkeynes@477
   171
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), dir );
nkeynes@477
   172
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
   173
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
   174
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
   175
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
   176
	dreamcast_load_state( filename );
nkeynes@477
   177
    }
nkeynes@477
   178
    gtk_widget_destroy(file);
nkeynes@435
   179
}
nkeynes@477
   180
nkeynes@435
   181
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   182
{
nkeynes@450
   183
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@435
   184
    save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", "lxDream Save State (*.dst)", dir );
nkeynes@435
   185
}
nkeynes@435
   186
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   187
{
nkeynes@435
   188
    
nkeynes@435
   189
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@435
   190
				      "name", APP_NAME, 
nkeynes@435
   191
                                     "version", APP_VERSION,
nkeynes@435
   192
			             "copyright", "(C) 2003-2007 Nathan Keynes",
nkeynes@435
   193
                                     NULL);
nkeynes@435
   194
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   195
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   196
    gtk_widget_destroy(dialog);
nkeynes@435
   197
    
nkeynes@435
   198
}
nkeynes@435
   199
nkeynes@435
   200
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   201
{
nkeynes@435
   202
    exit(0);
nkeynes@435
   203
}
nkeynes@435
   204
nkeynes@447
   205
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   206
{
nkeynes@450
   207
    path_dialog_run();
nkeynes@447
   208
}
nkeynes@447
   209
nkeynes@435
   210
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   211
{
nkeynes@435
   212
}
nkeynes@435
   213
nkeynes@455
   214
void maple_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   215
{
nkeynes@455
   216
    maple_dialog_run( );
nkeynes@435
   217
}
nkeynes@435
   218
nkeynes@435
   219
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   220
{
nkeynes@435
   221
}
nkeynes@435
   222
nkeynes@435
   223
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   224
{
nkeynes@435
   225
}
nkeynes@435
   226
nkeynes@435
   227
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   228
{
nkeynes@435
   229
}
nkeynes@455
   230
nkeynes@455
   231
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   232
{
nkeynes@455
   233
    gtk_gui_show_debugger();
nkeynes@455
   234
}
nkeynes@455
   235
nkeynes@455
   236
void debug_memory_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   237
{
nkeynes@455
   238
    dump_window_new( APP_NAME " " APP_VERSION " :: Memory dump" );
nkeynes@455
   239
}
nkeynes@455
   240
nkeynes@455
   241
void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   242
{
nkeynes@455
   243
    gtk_gui_show_mmio();
nkeynes@455
   244
}
nkeynes@455
   245
nkeynes@455
   246
void save_scene_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   247
{
nkeynes@455
   248
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@455
   249
    save_file_dialog( "Save next scene...", pvr2_save_next_scene, "*.dsc", "lxdream scene file (*.dsc)", dir );
nkeynes@455
   250
}
nkeynes@455
   251
nkeynes@455
   252
void debug_step_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   253
{
nkeynes@455
   254
    debug_window_single_step(gtk_gui_get_debugger());
nkeynes@455
   255
}
nkeynes@455
   256
nkeynes@455
   257
void debug_runto_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   258
{
nkeynes@455
   259
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   260
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   261
    if( selected_row == -1 ) {
nkeynes@455
   262
        WARN( "No address selected, so can't run to it", NULL );
nkeynes@455
   263
    } else {
nkeynes@455
   264
	debug_window_set_oneshot_breakpoint( debug, selected_row );
nkeynes@455
   265
	dreamcast_run();
nkeynes@455
   266
    }
nkeynes@455
   267
}
nkeynes@455
   268
nkeynes@455
   269
void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   270
{
nkeynes@455
   271
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   272
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   273
    if( selected_row != -1 ) {
nkeynes@455
   274
	debug_window_toggle_breakpoint( debug, selected_row );
nkeynes@455
   275
    }
nkeynes@455
   276
}
.