Search
lxdream.org :: lxdream/src/gui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkcb.c
changeset 437:2c259474b474
prev435:7a5d71e8560b
next447:3e095bfcb476
author nkeynes
date Sun Oct 14 09:30:16 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Maintain aspect ratio when resizing (draw black-bars to the sides when needed)
view annotate diff log raw
     1 /**
     2  * $Id: gtkcb.c,v 1.2 2007-10-11 08:22:03 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 "dreamcast.h"
    21 #include "gdrom/gdrom.h"
    22 #include "gui/gtkui.h"
    24 typedef gboolean (*file_callback_t)( const gchar *filename );
    26 static gboolean dreamcast_paused = FALSE;
    28 void dreamcast_pause()
    29 {
    30     if( dreamcast_is_running() ) {
    31 	dreamcast_paused = TRUE;
    32 	dreamcast_stop();
    33     }
    34 }
    36 void dreamcast_unpause()
    37 {
    38     if( dreamcast_paused ) {
    39 	dreamcast_paused = FALSE;
    40 	if( !dreamcast_is_running() ) {
    41 	    dreamcast_run();
    42 	}
    43     }
    44 }
    47 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
    48     GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
    49     if( result == GTK_RESPONSE_ACCEPT ) {
    50 	gchar *filename =gtk_file_chooser_get_filename(
    51 						       GTK_FILE_CHOOSER(file) );
    52 	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
    53 	gtk_widget_destroy(GTK_WIDGET(file));
    54 	action( filename );
    55 	g_free(filename);
    56     } else {
    57 	gtk_widget_destroy(GTK_WIDGET(file));
    58     }
    59     dreamcast_unpause();
    60 }
    62 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
    63 {
    64     if( pattern != NULL ) {
    65 	GtkFileFilter *filter = gtk_file_filter_new();
    66 	gtk_file_filter_add_pattern( filter, pattern );
    67 	gtk_file_filter_set_name( filter, patname );
    68 	gtk_file_chooser_add_filter( chooser, filter );
    69 	filter = gtk_file_filter_new();
    70 	gtk_file_filter_set_name( filter, "All files" );
    71 	gtk_file_filter_add_pattern( filter, "*" );
    72 	gtk_file_chooser_add_filter( chooser, filter );
    73     }
    74 }
    76 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
    77 		       gchar const *initial_dir )
    78 {
    79     GtkWidget *file;
    80     dreamcast_pause();
    81     file = gtk_file_chooser_dialog_new( title, NULL,
    82 					GTK_FILE_CHOOSER_ACTION_OPEN,
    83 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    84 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    85 					NULL );
    86     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
    87     g_signal_connect( GTK_OBJECT(file), "response", 
    88 		      GTK_SIGNAL_FUNC(open_file_callback), file );
    89     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
    90     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
    91     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    92     gtk_widget_show( file );
    93 }
    95 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
    96 		       gchar const *initial_dir )
    97 {
    98     GtkWidget *file;
    99     dreamcast_pause();
   100     file = gtk_file_chooser_dialog_new( title, NULL,
   101 					GTK_FILE_CHOOSER_ACTION_SAVE,
   102 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   103 					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
   104 					NULL );
   105     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   106     g_signal_connect( GTK_OBJECT(file), "response", 
   107 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   108     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   109     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
   110     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
   111     gtk_widget_show( file );
   112 }
   114 void mount_action_callback( GtkAction *action, gpointer user_data)
   115 {
   116     const gchar *dir = dreamcast_get_config_value(CONFIG_DEFAULT_PATH);
   117     open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
   118 }
   119 void reset_action_callback( GtkAction *action, gpointer user_data)
   120 {
   121     dreamcast_reset();
   122 }
   124 void pause_action_callback( GtkAction *action, gpointer user_data)
   125 {
   126     dreamcast_stop();
   127 }
   129 void resume_action_callback( GtkAction *action, gpointer user_data)
   130 {
   131     dreamcast_run();
   132 }
   134 void load_state_action_callback( GtkAction *action, gpointer user_data)
   135 {
   136     const gchar *dir = dreamcast_get_config_value(CONFIG_SAVE_PATH);
   137     open_file_dialog( "Load state...", dreamcast_load_state, "*.dst", "lxDream Save State (*.dst)", dir );
   138 }
   139 void save_state_action_callback( GtkAction *action, gpointer user_data)
   140 {
   141     const gchar *dir = dreamcast_get_config_value(CONFIG_SAVE_PATH);
   142     save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", "lxDream Save State (*.dst)", dir );
   143 }
   144 void about_action_callback( GtkAction *action, gpointer user_data)
   145 {
   147     GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
   148 				      "name", APP_NAME, 
   149                                      "version", APP_VERSION,
   150 			             "copyright", "(C) 2003-2007 Nathan Keynes",
   151                                      NULL);
   152     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
   153     gtk_widget_show(dialog);
   155 }
   157 void exit_action_callback( GtkAction *action, gpointer user_data)
   158 {
   159     exit(0);
   160 }
   162 void debugger_action_callback( GtkAction *action, gpointer user_data)
   163 {
   164     gtk_gui_show_debugger();
   165 }
   167 void audio_settings_callback( GtkAction *action, gpointer user_data)
   168 {
   169 }
   171 void controller_settings_callback( GtkAction *action, gpointer user_data)
   172 {
   173 }
   175 void network_settings_callback( GtkAction *action, gpointer user_data)
   176 {
   177 }
   179 void video_settings_callback( GtkAction *action, gpointer user_data)
   180 {
   181 }
   183 void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
   184 {
   185 }
.