Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 1040:9e3e41eab2db
prev1036:af7b0c5905dd
next1041:5fcc39857c5c
author nkeynes
date Thu Jun 25 21:21:18 2009 +0000 (12 years ago)
permissions -rw-r--r--
last change Add quick state bits to the menus
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, const char *pattern, const 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 gchar *open_file_dialog( const char *title, const char *pattern, const char *patname,
    43                          int initial_dir_key )
    44 {
    45     GtkWidget *file;
    46     gchar *filename = NULL;
    48     file = gtk_file_chooser_dialog_new( title, NULL,
    49             GTK_FILE_CHOOSER_ACTION_OPEN,
    50             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    51             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    52             NULL );
    53     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    54     if( initial_dir_key != -1 ) {
    55         gchar *initial_path = get_absolute_path(gui_get_configurable_path(initial_dir_key));
    56         gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
    57         g_free(initial_path);
    58     }
    59     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    60     gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
    61     int result = gtk_dialog_run( GTK_DIALOG(file) );
    62     if( result == GTK_RESPONSE_ACCEPT ) {
    63         filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    64         if( initial_dir_key != -1 ) {
    65             gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
    66             gui_set_configurable_path(initial_dir_key,end_path);
    67             g_free(end_path);
    68         }
    69     }
    70     gtk_widget_destroy(file);
    72     return filename;
    73 }
    75 gchar *save_file_dialog( const char *title, const char *pattern, const char *patname,
    76                          int initial_dir_key )
    77 {
    78     GtkWidget *file;
    79     gchar *filename;
    81     file = gtk_file_chooser_dialog_new( title, NULL,
    82             GTK_FILE_CHOOSER_ACTION_SAVE,
    83             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    84             GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
    85             NULL );
    86     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    87     if( initial_dir_key != -1 ) {
    88         gchar *initial_path = get_absolute_path(gui_get_configurable_path(initial_dir_key));
    89         gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
    90         g_free(initial_path);
    91     }
    92     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    93     gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
    94     int result = gtk_dialog_run( GTK_DIALOG(file) );
    95     if( result == GTK_RESPONSE_ACCEPT ) {
    96         filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    97         if( initial_dir_key != -1 ) {
    98             gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
    99             gui_set_configurable_path(initial_dir_key,end_path);
   100             g_free(end_path);
   101         }
   102     }
   103     gtk_widget_destroy(file);
   104     return filename;
   105 }
   107 void open_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
   108                           int initial_dir_key )
   109 {
   110     gchar *filename = open_file_dialog( title, pattern, patname, initial_dir_key ); 
   111     if( filename != NULL ) {
   112         action( filename );
   113         g_free(filename);
   114     }
   115 }
   117 void save_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
   118                           int initial_dir_key )
   119 {
   120     gchar *filename = save_file_dialog( title, pattern, patname, initial_dir_key );
   121     if( filename != NULL ) {
   122         action(filename);
   123         g_free(filename);
   124     }
   125 }
   127 void mount_action_callback( GtkAction *action, gpointer user_data)
   128 {
   129     open_file_dialog_cb( "Open...", gdrom_mount_image, NULL, NULL, CONFIG_DEFAULT_PATH );
   130 }
   131 void reset_action_callback( GtkAction *action, gpointer user_data)
   132 {
   133     dreamcast_reset();
   134 }
   136 void pause_action_callback( GtkAction *action, gpointer user_data)
   137 {
   138     dreamcast_stop();
   139 }
   141 void resume_action_callback( GtkAction *action, gpointer user_data)
   142 {
   143     dreamcast_run();
   144 }
   146 void load_binary_action_callback( GtkAction *action, gpointer user_data)
   147 {
   148     open_file_dialog_cb( "Open Binary...", file_load_magic, NULL, NULL, CONFIG_DEFAULT_PATH );
   149 }
   151 void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
   152 {
   153     GtkWidget *preview = GTK_WIDGET(user_data);
   154     gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
   156     frame_buffer_t data = dreamcast_load_preview(filename);
   157     if( data != NULL ) {
   158         GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
   159         GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
   160                 GDK_INTERP_BILINEAR);
   161         g_object_unref(pixbuf);
   162         gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
   163         g_object_unref(scaled);
   164         gtk_widget_show(preview);
   165     } else {
   166         gtk_widget_hide(preview);
   167     }
   168 }
   170 void load_state_action_callback( GtkAction *action, gpointer user_data)
   171 {
   172     GtkWidget *file, *preview, *frame, *align;
   173     GtkRequisition size;
   174     const gchar *dir = gui_get_configurable_path(CONFIG_SAVE_PATH);
   175     gchar *path = get_absolute_path(dir);
   176     file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
   177             GTK_FILE_CHOOSER_ACTION_OPEN,
   178             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   179             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
   180             NULL );
   181     add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
   182     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   184     preview = gtk_image_new( );
   186     frame = gtk_frame_new(NULL);
   187     gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
   188     gtk_container_add( GTK_CONTAINER(frame), preview );
   189     gtk_widget_show(frame);
   190     gtk_widget_size_request(frame, &size);
   191     gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
   192     align = gtk_alignment_new(0.5, 0.5, 0, 0 );
   193     gtk_container_add( GTK_CONTAINER(align), frame );
   194     gtk_widget_show( align );
   195     gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
   196     g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
   197                       preview );
   198     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), path );
   199     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
   200     int result = gtk_dialog_run( GTK_DIALOG(file) );
   201     if( result == GTK_RESPONSE_ACCEPT ) {
   202         gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
   203         gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
   204         gui_set_configurable_path(CONFIG_SAVE_PATH,end_path);
   205         g_free(end_path);
   206         dreamcast_load_state( filename );
   207     }
   208     gtk_widget_destroy(file);
   209     g_free(path);
   210 }
   212 void save_state_action_callback( GtkAction *action, gpointer user_data)
   213 {
   214     save_file_dialog_cb( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), CONFIG_SAVE_PATH );
   215 }
   217 void quick_state_action_callback( GtkRadioAction *action, GtkRadioAction *current, gpointer user_data)
   218 {
   219     gint val = gtk_radio_action_get_current_value(action);
   220     dreamcast_set_quick_state(val);
   221 }
   223 void quick_load_action_callback( GtkAction *action, gpointer user_data)
   224 {
   225     dreamcast_quick_load();
   226 }
   228 void quick_save_action_callback( GtkAction *action, gpointer user_data)
   229 {
   230     dreamcast_quick_save();
   231 }
   234 void about_action_callback( GtkAction *action, gpointer user_data)
   235 {
   237     GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
   238             "name", APP_NAME, 
   239             "version", lxdream_full_version,
   240             "copyright", lxdream_copyright,
   241             "logo-icon-name", "lxdream",
   242             NULL);
   243     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
   244     gtk_dialog_run(GTK_DIALOG(dialog));
   245     gtk_widget_destroy(dialog);
   247 }
   249 void exit_action_callback( GtkAction *action, gpointer user_data)
   250 {
   251     dreamcast_shutdown();
   252     exit(0);
   253 }
   255 void path_settings_callback( GtkAction *action, gpointer user_data)
   256 {
   257     path_dialog_run();
   258 }
   260 void audio_settings_callback( GtkAction *action, gpointer user_data)
   261 {
   262 }
   264 void maple_settings_callback( GtkAction *action, gpointer user_data)
   265 {
   266     maple_dialog_run( );
   267 }
   269 void network_settings_callback( GtkAction *action, gpointer user_data)
   270 {
   271 }
   273 void video_settings_callback( GtkAction *action, gpointer user_data)
   274 {
   275 }
   277 void hotkey_settings_callback( GtkAction *action, gpointer user_data)
   278 {
   279     hotkeys_dialog_run();
   280 }
   282 void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
   283 {
   284     main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
   285 }
   287 void debugger_action_callback( GtkAction *action, gpointer user_data)
   288 {
   289     gtk_gui_show_debugger();
   290 }
   292 void debug_memory_action_callback( GtkAction *action, gpointer user_data)
   293 {
   294     gchar *title = g_strdup_printf( "%s :: %s", lxdream_package_name, _("Memory dump") );
   295     dump_window_new( title );
   296     g_free(title);
   297 }
   299 void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
   300 {
   301     gtk_gui_show_mmio();
   302 }
   304 void save_scene_action_callback( GtkAction *action, gpointer user_data)
   305 {
   306     save_file_dialog_cb( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), CONFIG_SAVE_PATH );
   307 }
   309 int debug_window_get_selected_row( debug_window_t data );
   311 void debug_step_action_callback( GtkAction *action, gpointer user_data)
   312 {
   313     debug_window_single_step(gtk_gui_get_debugger());
   314 }
   316 void debug_runto_action_callback( GtkAction *action, gpointer user_data)
   317 {
   318     debug_window_t debug = gtk_gui_get_debugger();
   319     int selected_row = debug_window_get_selected_row(debug);
   320     if( selected_row == -1 ) {
   321         WARN( _("No address selected, so can't run to it"), NULL );
   322     } else {
   323         debug_window_set_oneshot_breakpoint( debug, selected_row );
   324         dreamcast_run();
   325     }
   326 }
   328 void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
   329 {
   330     debug_window_t debug = gtk_gui_get_debugger();
   331     int selected_row = debug_window_get_selected_row(debug);
   332     if( selected_row != -1 ) {
   333         debug_window_toggle_breakpoint( debug, selected_row );
   334     }
   335 }
.