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