filename | src/gui/gtkcb.c |
changeset | 455:3080881d00d4 |
prev | 450:207461e79f21 |
next | 477:9a373f2ff009 |
author | nkeynes |
date | Wed Oct 24 21:23:22 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Fix long standing texcache management bug (invalidate palette was not placing the invalidated entries on the free list). |
view | annotate | diff | log | raw |
1 /**
2 * $Id: gtkcb.c,v 1.5 2007-10-21 05:21: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"
26 typedef gboolean (*file_callback_t)( const gchar *filename );
28 static gboolean dreamcast_paused = FALSE;
30 void dreamcast_pause()
31 {
32 if( dreamcast_is_running() ) {
33 dreamcast_paused = TRUE;
34 dreamcast_stop();
35 }
36 }
38 void dreamcast_unpause()
39 {
40 if( dreamcast_paused ) {
41 dreamcast_paused = FALSE;
42 if( !dreamcast_is_running() ) {
43 dreamcast_run();
44 }
45 }
46 }
49 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
50 GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
51 if( result == GTK_RESPONSE_ACCEPT ) {
52 gchar *filename =gtk_file_chooser_get_filename(
53 GTK_FILE_CHOOSER(file) );
54 file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
55 gtk_widget_destroy(GTK_WIDGET(file));
56 action( filename );
57 g_free(filename);
58 } else {
59 gtk_widget_destroy(GTK_WIDGET(file));
60 }
61 dreamcast_unpause();
62 }
64 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
65 {
66 if( pattern != NULL ) {
67 GtkFileFilter *filter = gtk_file_filter_new();
68 gtk_file_filter_add_pattern( filter, pattern );
69 gtk_file_filter_set_name( filter, patname );
70 gtk_file_chooser_add_filter( chooser, filter );
71 filter = gtk_file_filter_new();
72 gtk_file_filter_set_name( filter, "All files" );
73 gtk_file_filter_add_pattern( filter, "*" );
74 gtk_file_chooser_add_filter( chooser, filter );
75 }
76 }
78 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
79 gchar const *initial_dir )
80 {
81 GtkWidget *file;
82 dreamcast_pause();
83 file = gtk_file_chooser_dialog_new( title, NULL,
84 GTK_FILE_CHOOSER_ACTION_OPEN,
85 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
86 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
87 NULL );
88 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
89 g_signal_connect( GTK_OBJECT(file), "response",
90 GTK_SIGNAL_FUNC(open_file_callback), file );
91 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
92 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
93 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
94 gtk_widget_show( file );
95 }
97 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
98 gchar const *initial_dir )
99 {
100 GtkWidget *file;
101 dreamcast_pause();
102 file = gtk_file_chooser_dialog_new( title, NULL,
103 GTK_FILE_CHOOSER_ACTION_SAVE,
104 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
105 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
106 NULL );
107 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
108 g_signal_connect( GTK_OBJECT(file), "response",
109 GTK_SIGNAL_FUNC(open_file_callback), file );
110 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
111 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
112 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
113 gtk_widget_show( file );
114 }
116 void mount_action_callback( GtkAction *action, gpointer user_data)
117 {
118 const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
119 open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
120 }
121 void reset_action_callback( GtkAction *action, gpointer user_data)
122 {
123 dreamcast_reset();
124 }
126 void pause_action_callback( GtkAction *action, gpointer user_data)
127 {
128 dreamcast_stop();
129 }
131 void resume_action_callback( GtkAction *action, gpointer user_data)
132 {
133 dreamcast_run();
134 }
136 void load_state_action_callback( GtkAction *action, gpointer user_data)
137 {
138 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
139 open_file_dialog( "Load state...", dreamcast_load_state, "*.dst", "lxDream Save State (*.dst)", dir );
140 }
141 void save_state_action_callback( GtkAction *action, gpointer user_data)
142 {
143 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
144 save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", "lxDream Save State (*.dst)", dir );
145 }
146 void about_action_callback( GtkAction *action, gpointer user_data)
147 {
149 GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
150 "name", APP_NAME,
151 "version", APP_VERSION,
152 "copyright", "(C) 2003-2007 Nathan Keynes",
153 NULL);
154 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
155 gtk_dialog_run(GTK_DIALOG(dialog));
156 gtk_widget_destroy(dialog);
158 }
160 void exit_action_callback( GtkAction *action, gpointer user_data)
161 {
162 exit(0);
163 }
165 void path_settings_callback( GtkAction *action, gpointer user_data)
166 {
167 path_dialog_run();
168 }
170 void audio_settings_callback( GtkAction *action, gpointer user_data)
171 {
172 }
174 void maple_settings_callback( GtkAction *action, gpointer user_data)
175 {
176 maple_dialog_run( );
177 }
179 void network_settings_callback( GtkAction *action, gpointer user_data)
180 {
181 }
183 void video_settings_callback( GtkAction *action, gpointer user_data)
184 {
185 }
187 void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
188 {
189 }
191 void debugger_action_callback( GtkAction *action, gpointer user_data)
192 {
193 gtk_gui_show_debugger();
194 }
196 void debug_memory_action_callback( GtkAction *action, gpointer user_data)
197 {
198 dump_window_new( APP_NAME " " APP_VERSION " :: Memory dump" );
199 }
201 void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
202 {
203 gtk_gui_show_mmio();
204 }
206 void save_scene_action_callback( GtkAction *action, gpointer user_data)
207 {
208 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
209 save_file_dialog( "Save next scene...", pvr2_save_next_scene, "*.dsc", "lxdream scene file (*.dsc)", dir );
210 }
212 void debug_step_action_callback( GtkAction *action, gpointer user_data)
213 {
214 debug_window_single_step(gtk_gui_get_debugger());
215 }
217 void debug_runto_action_callback( GtkAction *action, gpointer user_data)
218 {
219 debug_window_t debug = gtk_gui_get_debugger();
220 int selected_row = debug_window_get_selected_row(debug);
221 if( selected_row == -1 ) {
222 WARN( "No address selected, so can't run to it", NULL );
223 } else {
224 debug_window_set_oneshot_breakpoint( debug, selected_row );
225 dreamcast_run();
226 }
227 }
229 void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
230 {
231 debug_window_t debug = gtk_gui_get_debugger();
232 int selected_row = debug_window_get_selected_row(debug);
233 if( selected_row != -1 ) {
234 debug_window_toggle_breakpoint( debug, selected_row );
235 }
236 }
.