Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 671:a530ea88eebd
prev669:ab344e42bca9
next736:a02d1475ccfd
author nkeynes
date Thu May 15 10:22:39 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Permanently add SH4 instruction statistics tracking (enabled with --enable-sh4stats)
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Action callbacks from the main window
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include "dream.h"
    20 #include "config.h"
    21 #include "dreamcast.h"
    22 #include "gdrom/gdrom.h"
    23 #include "gtkui/gtkui.h"
    24 #include "pvr2/pvr2.h"
    25 #include "loader.h"
    28 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
    29 {
    30     if( pattern != NULL ) {
    31 	GtkFileFilter *filter = gtk_file_filter_new();
    32 	gtk_file_filter_add_pattern( filter, pattern );
    33 	gtk_file_filter_set_name( filter, patname );
    34 	gtk_file_chooser_add_filter( chooser, filter );
    35 	filter = gtk_file_filter_new();
    36 	gtk_file_filter_set_name( filter, _("All files") );
    37 	gtk_file_filter_add_pattern( filter, "*" );
    38 	gtk_file_chooser_add_filter( chooser, filter );
    39     }
    40 }
    42 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
    43 		       gchar const *initial_dir )
    44 {
    45     GtkWidget *file;
    46     gchar *initial_path = get_absolute_path(initial_dir);
    47     file = gtk_file_chooser_dialog_new( title, NULL,
    48 					GTK_FILE_CHOOSER_ACTION_OPEN,
    49 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    50 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    51 					NULL );
    52     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    53     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
    54     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    55     gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
    56     int result = gtk_dialog_run( GTK_DIALOG(file) );
    57     if( result == GTK_RESPONSE_ACCEPT ) {
    58 	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    59 	action( filename );
    60     }
    61     gtk_widget_destroy(file);
    62     g_free(initial_path);
    63 }
    65 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
    66 		       gchar const *initial_dir )
    67 {
    68     GtkWidget *file;
    69     gchar *initial_path = get_absolute_path(initial_dir);
    70     file = gtk_file_chooser_dialog_new( title, NULL,
    71 					GTK_FILE_CHOOSER_ACTION_SAVE,
    72 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    73 					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
    74 					NULL );
    75     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    76     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
    77     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    78     gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
    79     int result = gtk_dialog_run( GTK_DIALOG(file) );
    80     if( result == GTK_RESPONSE_ACCEPT ) {
    81 	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    82 	action( filename );
    83     }
    84     gtk_widget_destroy(file);
    85     g_free(initial_path);
    86 }
    88 void mount_action_callback( GtkAction *action, gpointer user_data)
    89 {
    90     const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
    91     open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
    92 }
    93 void reset_action_callback( GtkAction *action, gpointer user_data)
    94 {
    95     dreamcast_reset();
    96 }
    98 void pause_action_callback( GtkAction *action, gpointer user_data)
    99 {
   100     dreamcast_stop();
   101 }
   103 void resume_action_callback( GtkAction *action, gpointer user_data)
   104 {
   105     dreamcast_run();
   106 }
   108 void load_binary_action_callback( GtkAction *action, gpointer user_data)
   109 {
   110     const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
   111     open_file_dialog( "Open Binary...", file_load_magic, NULL, NULL, dir );
   112 }
   114 void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
   115 {
   116     GtkWidget *preview = GTK_WIDGET(user_data);
   117     gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
   119     frame_buffer_t data = dreamcast_load_preview(filename);
   120     if( data != NULL ) {
   121 	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
   122 	GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
   123 						    GDK_INTERP_BILINEAR);
   124 	g_object_unref(pixbuf);
   125 	gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
   126 	g_object_unref(scaled);
   127 	gtk_widget_show(preview);
   128     } else {
   129 	gtk_widget_hide(preview);
   130     }
   131 }
   133 void load_state_action_callback( GtkAction *action, gpointer user_data)
   134 {
   135     GtkWidget *file, *preview, *frame, *align;
   136     GtkRequisition size;
   137     const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
   138     gchar *path = get_absolute_path(dir);
   139     file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
   140 					GTK_FILE_CHOOSER_ACTION_OPEN,
   141 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   142 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
   143 					NULL );
   144     add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
   145     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   147     preview = gtk_image_new( );
   149     frame = gtk_frame_new(NULL);
   150     gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
   151     gtk_container_add( GTK_CONTAINER(frame), preview );
   152     gtk_widget_show(frame);
   153     gtk_widget_size_request(frame, &size);
   154     gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
   155     align = gtk_alignment_new(0.5, 0.5, 0, 0 );
   156     gtk_container_add( GTK_CONTAINER(align), frame );
   157     gtk_widget_show( align );
   158     gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
   159     g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
   160 		      preview );
   161     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), path );
   162     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
   163     int result = gtk_dialog_run( GTK_DIALOG(file) );
   164     if( result == GTK_RESPONSE_ACCEPT ) {
   165 	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
   166 	dreamcast_load_state( filename );
   167     }
   168     gtk_widget_destroy(file);
   169     g_free(path);
   170 }
   172 void save_state_action_callback( GtkAction *action, gpointer user_data)
   173 {
   174     const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
   175     save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), dir );
   176 }
   177 void about_action_callback( GtkAction *action, gpointer user_data)
   178 {
   180     GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
   181 				      "name", APP_NAME, 
   182                                      "version", APP_VERSION,
   183 			             "copyright", "(C) 2003-2007 Nathan Keynes",
   184                                      NULL);
   185     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
   186     gtk_dialog_run(GTK_DIALOG(dialog));
   187     gtk_widget_destroy(dialog);
   189 }
   191 void exit_action_callback( GtkAction *action, gpointer user_data)
   192 {
   193     dreamcast_shutdown();
   194     exit(0);
   195 }
   197 void path_settings_callback( GtkAction *action, gpointer user_data)
   198 {
   199     path_dialog_run();
   200 }
   202 void audio_settings_callback( GtkAction *action, gpointer user_data)
   203 {
   204 }
   206 void maple_settings_callback( GtkAction *action, gpointer user_data)
   207 {
   208     maple_dialog_run( );
   209 }
   211 void network_settings_callback( GtkAction *action, gpointer user_data)
   212 {
   213 }
   215 void video_settings_callback( GtkAction *action, gpointer user_data)
   216 {
   217 }
   219 void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
   220 {
   221     main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
   222 }
   224 void debugger_action_callback( GtkAction *action, gpointer user_data)
   225 {
   226     gtk_gui_show_debugger();
   227 }
   229 void debug_memory_action_callback( GtkAction *action, gpointer user_data)
   230 {
   231     gchar *title = g_strdup_printf( APP_NAME " " APP_VERSION " :: %s", _("Memory dump") );
   232     dump_window_new( title );
   233     g_free(title);
   234 }
   236 void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
   237 {
   238     gtk_gui_show_mmio();
   239 }
   241 void save_scene_action_callback( GtkAction *action, gpointer user_data)
   242 {
   243     const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
   244     save_file_dialog( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), dir );
   245 }
   247 int debug_window_get_selected_row( debug_window_t data );
   249 void debug_step_action_callback( GtkAction *action, gpointer user_data)
   250 {
   251     debug_window_single_step(gtk_gui_get_debugger());
   252 }
   254 void debug_runto_action_callback( GtkAction *action, gpointer user_data)
   255 {
   256     debug_window_t debug = gtk_gui_get_debugger();
   257     int selected_row = debug_window_get_selected_row(debug);
   258     if( selected_row == -1 ) {
   259         WARN( _("No address selected, so can't run to it"), NULL );
   260     } else {
   261 	debug_window_set_oneshot_breakpoint( debug, selected_row );
   262 	dreamcast_run();
   263     }
   264 }
   266 void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
   267 {
   268     debug_window_t debug = gtk_gui_get_debugger();
   269     int selected_row = debug_window_get_selected_row(debug);
   270     if( selected_row != -1 ) {
   271 	debug_window_toggle_breakpoint( debug, selected_row );
   272     }
   273 }
.