Search
lxdream.org :: lxdream/src/gui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkcb.c
changeset 480:d28c2992f5ee
prev477:9a373f2ff009
next486:9af294489aad
author nkeynes
date Wed Oct 31 11:53:35 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Fix miscellaneous warnings
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@480
     2
 * $Id: gtkcb.c,v 1.7 2007-10-31 11:53: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
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@435
    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@477
   104
void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
nkeynes@477
   105
{
nkeynes@477
   106
    GtkWidget *preview = GTK_WIDGET(user_data);
nkeynes@477
   107
    gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
nkeynes@477
   108
    
nkeynes@477
   109
    frame_buffer_t data = dreamcast_load_preview(filename);
nkeynes@477
   110
    if( data != NULL ) {
nkeynes@477
   111
	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
nkeynes@477
   112
	GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
nkeynes@477
   113
						    GDK_INTERP_BILINEAR);
nkeynes@477
   114
	g_object_unref(pixbuf);
nkeynes@477
   115
	gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
nkeynes@477
   116
	g_object_unref(scaled);
nkeynes@477
   117
	gtk_widget_show(preview);
nkeynes@477
   118
    } else {
nkeynes@477
   119
	gtk_widget_hide(preview);
nkeynes@477
   120
    }
nkeynes@477
   121
}
nkeynes@477
   122
nkeynes@435
   123
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   124
{
nkeynes@477
   125
    GtkWidget *file, *preview, *frame, *align;
nkeynes@477
   126
    GtkRequisition size;
nkeynes@450
   127
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@477
   128
    file = gtk_file_chooser_dialog_new( "Load state...", NULL,
nkeynes@477
   129
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@477
   130
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@477
   131
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@477
   132
					NULL );
nkeynes@477
   133
    add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", "lxDream Save State (*.dst)" );
nkeynes@477
   134
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@477
   135
nkeynes@477
   136
    preview = gtk_image_new( );
nkeynes@477
   137
nkeynes@477
   138
    frame = gtk_frame_new(NULL);
nkeynes@477
   139
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@477
   140
    gtk_container_add( GTK_CONTAINER(frame), preview );
nkeynes@477
   141
    gtk_widget_show(frame);
nkeynes@477
   142
    gtk_widget_size_request(frame, &size);
nkeynes@477
   143
    gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
nkeynes@477
   144
    align = gtk_alignment_new(0.5, 0.5, 0, 0 );
nkeynes@477
   145
    gtk_container_add( GTK_CONTAINER(align), frame );
nkeynes@477
   146
    gtk_widget_show( align );
nkeynes@477
   147
    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
nkeynes@477
   148
    g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
nkeynes@477
   149
		      preview );
nkeynes@477
   150
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), dir );
nkeynes@477
   151
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
   152
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
   153
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
   154
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
   155
	dreamcast_load_state( filename );
nkeynes@477
   156
    }
nkeynes@477
   157
    gtk_widget_destroy(file);
nkeynes@435
   158
}
nkeynes@477
   159
nkeynes@435
   160
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   161
{
nkeynes@450
   162
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@435
   163
    save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", "lxDream Save State (*.dst)", dir );
nkeynes@435
   164
}
nkeynes@435
   165
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   166
{
nkeynes@435
   167
    
nkeynes@435
   168
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@435
   169
				      "name", APP_NAME, 
nkeynes@435
   170
                                     "version", APP_VERSION,
nkeynes@435
   171
			             "copyright", "(C) 2003-2007 Nathan Keynes",
nkeynes@435
   172
                                     NULL);
nkeynes@435
   173
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   174
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   175
    gtk_widget_destroy(dialog);
nkeynes@435
   176
    
nkeynes@435
   177
}
nkeynes@435
   178
nkeynes@435
   179
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   180
{
nkeynes@435
   181
    exit(0);
nkeynes@435
   182
}
nkeynes@435
   183
nkeynes@447
   184
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   185
{
nkeynes@450
   186
    path_dialog_run();
nkeynes@447
   187
}
nkeynes@447
   188
nkeynes@435
   189
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   190
{
nkeynes@435
   191
}
nkeynes@435
   192
nkeynes@455
   193
void maple_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   194
{
nkeynes@455
   195
    maple_dialog_run( );
nkeynes@435
   196
}
nkeynes@435
   197
nkeynes@435
   198
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   199
{
nkeynes@435
   200
}
nkeynes@435
   201
nkeynes@435
   202
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   203
{
nkeynes@435
   204
}
nkeynes@435
   205
nkeynes@435
   206
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   207
{
nkeynes@435
   208
}
nkeynes@455
   209
nkeynes@455
   210
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   211
{
nkeynes@455
   212
    gtk_gui_show_debugger();
nkeynes@455
   213
}
nkeynes@455
   214
nkeynes@455
   215
void debug_memory_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   216
{
nkeynes@455
   217
    dump_window_new( APP_NAME " " APP_VERSION " :: Memory dump" );
nkeynes@455
   218
}
nkeynes@455
   219
nkeynes@455
   220
void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   221
{
nkeynes@455
   222
    gtk_gui_show_mmio();
nkeynes@455
   223
}
nkeynes@455
   224
nkeynes@455
   225
void save_scene_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   226
{
nkeynes@455
   227
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@455
   228
    save_file_dialog( "Save next scene...", pvr2_save_next_scene, "*.dsc", "lxdream scene file (*.dsc)", dir );
nkeynes@455
   229
}
nkeynes@455
   230
nkeynes@480
   231
int debug_window_get_selected_row( debug_window_t data );
nkeynes@480
   232
nkeynes@455
   233
void debug_step_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   234
{
nkeynes@455
   235
    debug_window_single_step(gtk_gui_get_debugger());
nkeynes@455
   236
}
nkeynes@455
   237
nkeynes@455
   238
void debug_runto_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   239
{
nkeynes@455
   240
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   241
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   242
    if( selected_row == -1 ) {
nkeynes@455
   243
        WARN( "No address selected, so can't run to it", NULL );
nkeynes@455
   244
    } else {
nkeynes@455
   245
	debug_window_set_oneshot_breakpoint( debug, selected_row );
nkeynes@455
   246
	dreamcast_run();
nkeynes@455
   247
    }
nkeynes@455
   248
}
nkeynes@455
   249
nkeynes@455
   250
void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   251
{
nkeynes@455
   252
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   253
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   254
    if( selected_row != -1 ) {
nkeynes@455
   255
	debug_window_toggle_breakpoint( debug, selected_row );
nkeynes@455
   256
    }
nkeynes@455
   257
}
.