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
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     file = gtk_file_chooser_dialog_new( title, NULL,
    47 					GTK_FILE_CHOOSER_ACTION_OPEN,
    48 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    49 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    50 					NULL );
    51     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    52     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
    53     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    54     gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
    55     int result = gtk_dialog_run( GTK_DIALOG(file) );
    56     if( result == GTK_RESPONSE_ACCEPT ) {
    57 	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    58 	action( filename );
    59     }
    60     gtk_widget_destroy(file);
    61 }
    63 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
    64 		       gchar const *initial_dir )
    65 {
    66     GtkWidget *file;
    67     file = gtk_file_chooser_dialog_new( title, NULL,
    68 					GTK_FILE_CHOOSER_ACTION_SAVE,
    69 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    70 					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
    71 					NULL );
    72     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    73     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
    74     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    75     gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
    76     int result = gtk_dialog_run( GTK_DIALOG(file) );
    77     if( result == GTK_RESPONSE_ACCEPT ) {
    78 	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    79 	action( filename );
    80     }
    81     gtk_widget_destroy(file);
    82 }
    84 void mount_action_callback( GtkAction *action, gpointer user_data)
    85 {
    86     const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
    87     open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
    88 }
    89 void reset_action_callback( GtkAction *action, gpointer user_data)
    90 {
    91     dreamcast_reset();
    92 }
    94 void pause_action_callback( GtkAction *action, gpointer user_data)
    95 {
    96     dreamcast_stop();
    97 }
    99 void resume_action_callback( GtkAction *action, gpointer user_data)
   100 {
   101     dreamcast_run();
   102 }
   104 void load_binary_action_callback( GtkAction *action, gpointer user_data)
   105 {
   106     const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
   107     open_file_dialog( "Open Binary...", file_load_magic, NULL, NULL, dir );
   108 }
   110 void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
   111 {
   112     GtkWidget *preview = GTK_WIDGET(user_data);
   113     gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
   115     frame_buffer_t data = dreamcast_load_preview(filename);
   116     if( data != NULL ) {
   117 	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
   118 	GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
   119 						    GDK_INTERP_BILINEAR);
   120 	g_object_unref(pixbuf);
   121 	gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
   122 	g_object_unref(scaled);
   123 	gtk_widget_show(preview);
   124     } else {
   125 	gtk_widget_hide(preview);
   126     }
   127 }
   129 void load_state_action_callback( GtkAction *action, gpointer user_data)
   130 {
   131     GtkWidget *file, *preview, *frame, *align;
   132     GtkRequisition size;
   133     const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
   134     file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
   135 					GTK_FILE_CHOOSER_ACTION_OPEN,
   136 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   137 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
   138 					NULL );
   139     add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
   140     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   142     preview = gtk_image_new( );
   144     frame = gtk_frame_new(NULL);
   145     gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
   146     gtk_container_add( GTK_CONTAINER(frame), preview );
   147     gtk_widget_show(frame);
   148     gtk_widget_size_request(frame, &size);
   149     gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
   150     align = gtk_alignment_new(0.5, 0.5, 0, 0 );
   151     gtk_container_add( GTK_CONTAINER(align), frame );
   152     gtk_widget_show( align );
   153     gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
   154     g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
   155 		      preview );
   156     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), dir );
   157     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
   158     int result = gtk_dialog_run( GTK_DIALOG(file) );
   159     if( result == GTK_RESPONSE_ACCEPT ) {
   160 	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
   161 	dreamcast_load_state( filename );
   162     }
   163     gtk_widget_destroy(file);
   164 }
   166 void save_state_action_callback( GtkAction *action, gpointer user_data)
   167 {
   168     const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
   169     save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), dir );
   170 }
   171 void about_action_callback( GtkAction *action, gpointer user_data)
   172 {
   174     GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
   175 				      "name", APP_NAME, 
   176                                      "version", APP_VERSION,
   177 			             "copyright", "(C) 2003-2007 Nathan Keynes",
   178                                      NULL);
   179     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
   180     gtk_dialog_run(GTK_DIALOG(dialog));
   181     gtk_widget_destroy(dialog);
   183 }
   185 void exit_action_callback( GtkAction *action, gpointer user_data)
   186 {
   187     exit(0);
   188 }
   190 void path_settings_callback( GtkAction *action, gpointer user_data)
   191 {
   192     path_dialog_run();
   193 }
   195 void audio_settings_callback( GtkAction *action, gpointer user_data)
   196 {
   197 }
   199 void maple_settings_callback( GtkAction *action, gpointer user_data)
   200 {
   201     maple_dialog_run( );
   202 }
   204 void network_settings_callback( GtkAction *action, gpointer user_data)
   205 {
   206 }
   208 void video_settings_callback( GtkAction *action, gpointer user_data)
   209 {
   210 }
   212 void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
   213 {
   214     main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
   215 }
   217 void debugger_action_callback( GtkAction *action, gpointer user_data)
   218 {
   219     gtk_gui_show_debugger();
   220 }
   222 void debug_memory_action_callback( GtkAction *action, gpointer user_data)
   223 {
   224     gchar *title = g_strdup_printf( APP_NAME " " APP_VERSION " :: %s", _("Memory dump") );
   225     dump_window_new( title );
   226     g_free(title);
   227 }
   229 void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
   230 {
   231     gtk_gui_show_mmio();
   232 }
   234 void save_scene_action_callback( GtkAction *action, gpointer user_data)
   235 {
   236     const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
   237     save_file_dialog( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), dir );
   238 }
   240 int debug_window_get_selected_row( debug_window_t data );
   242 void debug_step_action_callback( GtkAction *action, gpointer user_data)
   243 {
   244     debug_window_single_step(gtk_gui_get_debugger());
   245 }
   247 void debug_runto_action_callback( GtkAction *action, gpointer user_data)
   248 {
   249     debug_window_t debug = gtk_gui_get_debugger();
   250     int selected_row = debug_window_get_selected_row(debug);
   251     if( selected_row == -1 ) {
   252         WARN( _("No address selected, so can't run to it"), NULL );
   253     } else {
   254 	debug_window_set_oneshot_breakpoint( debug, selected_row );
   255 	dreamcast_run();
   256     }
   257 }
   259 void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
   260 {
   261     debug_window_t debug = gtk_gui_get_debugger();
   262     int selected_row = debug_window_get_selected_row(debug);
   263     if( selected_row != -1 ) {
   264 	debug_window_toggle_breakpoint( debug, selected_row );
   265     }
   266 }
.