Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 537:d924be49e192
prev508:ccd2c10edfe6
next543:361ec0a70cf2
author nkeynes
date Tue Nov 20 10:27:58 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Move gtk UI into gtkui subdir (prep for non-gtk builds), and protect with
an automake conditional
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gtkui/gtkcb.c Tue Nov 20 10:27:58 2007 +0000
1.3 @@ -0,0 +1,260 @@
1.4 +/**
1.5 + * $Id: gtkcb.c,v 1.9 2007-11-10 04:45:29 nkeynes Exp $
1.6 + *
1.7 + * Action callbacks from the main window
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include "dream.h"
1.23 +#include "config.h"
1.24 +#include "dreamcast.h"
1.25 +#include "gdrom/gdrom.h"
1.26 +#include "gtkui/gtkui.h"
1.27 +#include "pvr2/pvr2.h"
1.28 +
1.29 +
1.30 +
1.31 +static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
1.32 +{
1.33 + if( pattern != NULL ) {
1.34 + GtkFileFilter *filter = gtk_file_filter_new();
1.35 + gtk_file_filter_add_pattern( filter, pattern );
1.36 + gtk_file_filter_set_name( filter, patname );
1.37 + gtk_file_chooser_add_filter( chooser, filter );
1.38 + filter = gtk_file_filter_new();
1.39 + gtk_file_filter_set_name( filter, _("All files") );
1.40 + gtk_file_filter_add_pattern( filter, "*" );
1.41 + gtk_file_chooser_add_filter( chooser, filter );
1.42 + }
1.43 +}
1.44 +
1.45 +void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
1.46 + gchar const *initial_dir )
1.47 +{
1.48 + GtkWidget *file;
1.49 + file = gtk_file_chooser_dialog_new( title, NULL,
1.50 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.51 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.52 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.53 + NULL );
1.54 + add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
1.55 + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
1.56 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.57 + gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
1.58 + int result = gtk_dialog_run( GTK_DIALOG(file) );
1.59 + if( result == GTK_RESPONSE_ACCEPT ) {
1.60 + gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.61 + action( filename );
1.62 + }
1.63 + gtk_widget_destroy(file);
1.64 +}
1.65 +
1.66 +void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
1.67 + gchar const *initial_dir )
1.68 +{
1.69 + GtkWidget *file;
1.70 + file = gtk_file_chooser_dialog_new( title, NULL,
1.71 + GTK_FILE_CHOOSER_ACTION_SAVE,
1.72 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.73 + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1.74 + NULL );
1.75 + add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
1.76 + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
1.77 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.78 + gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
1.79 + int result = gtk_dialog_run( GTK_DIALOG(file) );
1.80 + if( result == GTK_RESPONSE_ACCEPT ) {
1.81 + gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.82 + action( filename );
1.83 + }
1.84 + gtk_widget_destroy(file);
1.85 +}
1.86 +
1.87 +void mount_action_callback( GtkAction *action, gpointer user_data)
1.88 +{
1.89 + const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
1.90 + open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
1.91 +}
1.92 +void reset_action_callback( GtkAction *action, gpointer user_data)
1.93 +{
1.94 + dreamcast_reset();
1.95 +}
1.96 +
1.97 +void pause_action_callback( GtkAction *action, gpointer user_data)
1.98 +{
1.99 + dreamcast_stop();
1.100 +}
1.101 +
1.102 +void resume_action_callback( GtkAction *action, gpointer user_data)
1.103 +{
1.104 + dreamcast_run();
1.105 +}
1.106 +
1.107 +void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
1.108 +{
1.109 + GtkWidget *preview = GTK_WIDGET(user_data);
1.110 + gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
1.111 +
1.112 + frame_buffer_t data = dreamcast_load_preview(filename);
1.113 + if( data != NULL ) {
1.114 + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
1.115 + GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
1.116 + GDK_INTERP_BILINEAR);
1.117 + g_object_unref(pixbuf);
1.118 + gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
1.119 + g_object_unref(scaled);
1.120 + gtk_widget_show(preview);
1.121 + } else {
1.122 + gtk_widget_hide(preview);
1.123 + }
1.124 +}
1.125 +
1.126 +void load_state_action_callback( GtkAction *action, gpointer user_data)
1.127 +{
1.128 + GtkWidget *file, *preview, *frame, *align;
1.129 + GtkRequisition size;
1.130 + const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
1.131 + file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
1.132 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.133 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.134 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.135 + NULL );
1.136 + add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
1.137 + gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
1.138 +
1.139 + preview = gtk_image_new( );
1.140 +
1.141 + frame = gtk_frame_new(NULL);
1.142 + gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
1.143 + gtk_container_add( GTK_CONTAINER(frame), preview );
1.144 + gtk_widget_show(frame);
1.145 + gtk_widget_size_request(frame, &size);
1.146 + gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
1.147 + align = gtk_alignment_new(0.5, 0.5, 0, 0 );
1.148 + gtk_container_add( GTK_CONTAINER(align), frame );
1.149 + gtk_widget_show( align );
1.150 + gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
1.151 + g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
1.152 + preview );
1.153 + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), dir );
1.154 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.155 + int result = gtk_dialog_run( GTK_DIALOG(file) );
1.156 + if( result == GTK_RESPONSE_ACCEPT ) {
1.157 + gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.158 + dreamcast_load_state( filename );
1.159 + }
1.160 + gtk_widget_destroy(file);
1.161 +}
1.162 +
1.163 +void save_state_action_callback( GtkAction *action, gpointer user_data)
1.164 +{
1.165 + const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
1.166 + save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), dir );
1.167 +}
1.168 +void about_action_callback( GtkAction *action, gpointer user_data)
1.169 +{
1.170 +
1.171 + GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
1.172 + "name", APP_NAME,
1.173 + "version", APP_VERSION,
1.174 + "copyright", "(C) 2003-2007 Nathan Keynes",
1.175 + NULL);
1.176 + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
1.177 + gtk_dialog_run(GTK_DIALOG(dialog));
1.178 + gtk_widget_destroy(dialog);
1.179 +
1.180 +}
1.181 +
1.182 +void exit_action_callback( GtkAction *action, gpointer user_data)
1.183 +{
1.184 + exit(0);
1.185 +}
1.186 +
1.187 +void path_settings_callback( GtkAction *action, gpointer user_data)
1.188 +{
1.189 + path_dialog_run();
1.190 +}
1.191 +
1.192 +void audio_settings_callback( GtkAction *action, gpointer user_data)
1.193 +{
1.194 +}
1.195 +
1.196 +void maple_settings_callback( GtkAction *action, gpointer user_data)
1.197 +{
1.198 + maple_dialog_run( );
1.199 +}
1.200 +
1.201 +void network_settings_callback( GtkAction *action, gpointer user_data)
1.202 +{
1.203 +}
1.204 +
1.205 +void video_settings_callback( GtkAction *action, gpointer user_data)
1.206 +{
1.207 +}
1.208 +
1.209 +void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
1.210 +{
1.211 + main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
1.212 +}
1.213 +
1.214 +void debugger_action_callback( GtkAction *action, gpointer user_data)
1.215 +{
1.216 + gtk_gui_show_debugger();
1.217 +}
1.218 +
1.219 +void debug_memory_action_callback( GtkAction *action, gpointer user_data)
1.220 +{
1.221 + gchar *title = g_strdup_printf( APP_NAME " " APP_VERSION " :: %s", _("Memory dump") );
1.222 + dump_window_new( title );
1.223 + g_free(title);
1.224 +}
1.225 +
1.226 +void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
1.227 +{
1.228 + gtk_gui_show_mmio();
1.229 +}
1.230 +
1.231 +void save_scene_action_callback( GtkAction *action, gpointer user_data)
1.232 +{
1.233 + const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
1.234 + save_file_dialog( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), dir );
1.235 +}
1.236 +
1.237 +int debug_window_get_selected_row( debug_window_t data );
1.238 +
1.239 +void debug_step_action_callback( GtkAction *action, gpointer user_data)
1.240 +{
1.241 + debug_window_single_step(gtk_gui_get_debugger());
1.242 +}
1.243 +
1.244 +void debug_runto_action_callback( GtkAction *action, gpointer user_data)
1.245 +{
1.246 + debug_window_t debug = gtk_gui_get_debugger();
1.247 + int selected_row = debug_window_get_selected_row(debug);
1.248 + if( selected_row == -1 ) {
1.249 + WARN( _("No address selected, so can't run to it"), NULL );
1.250 + } else {
1.251 + debug_window_set_oneshot_breakpoint( debug, selected_row );
1.252 + dreamcast_run();
1.253 + }
1.254 +}
1.255 +
1.256 +void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
1.257 +{
1.258 + debug_window_t debug = gtk_gui_get_debugger();
1.259 + int selected_row = debug_window_get_selected_row(debug);
1.260 + if( selected_row != -1 ) {
1.261 + debug_window_toggle_breakpoint( debug, selected_row );
1.262 + }
1.263 +}
.