Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 738:0cbff49086b8
prev736:a02d1475ccfd
next887:8b3ee741c9d7
author nkeynes
date Tue Jul 15 06:47:49 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Record the SVN revision in the build
Rationalise the version/copyright strings a little as well.
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@435
     3
 *
nkeynes@435
     4
 * Action callbacks from the main window
nkeynes@435
     5
 *
nkeynes@435
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     7
 *
nkeynes@435
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    11
 * (at your option) any later version.
nkeynes@435
    12
 *
nkeynes@435
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    16
 * GNU General Public License for more details.
nkeynes@435
    17
 */
nkeynes@435
    18
nkeynes@435
    19
#include "dream.h"
nkeynes@450
    20
#include "config.h"
nkeynes@435
    21
#include "dreamcast.h"
nkeynes@435
    22
#include "gdrom/gdrom.h"
nkeynes@537
    23
#include "gtkui/gtkui.h"
nkeynes@455
    24
#include "pvr2/pvr2.h"
nkeynes@543
    25
#include "loader.h"
nkeynes@435
    26
nkeynes@435
    27
nkeynes@435
    28
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@435
    29
{
nkeynes@435
    30
    if( pattern != NULL ) {
nkeynes@736
    31
        GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@736
    32
        gtk_file_filter_add_pattern( filter, pattern );
nkeynes@736
    33
        gtk_file_filter_set_name( filter, patname );
nkeynes@736
    34
        gtk_file_chooser_add_filter( chooser, filter );
nkeynes@736
    35
        filter = gtk_file_filter_new();
nkeynes@736
    36
        gtk_file_filter_set_name( filter, _("All files") );
nkeynes@736
    37
        gtk_file_filter_add_pattern( filter, "*" );
nkeynes@736
    38
        gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    39
    }
nkeynes@435
    40
}
nkeynes@435
    41
nkeynes@435
    42
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@736
    43
                       gchar const *initial_dir )
nkeynes@435
    44
{
nkeynes@435
    45
    GtkWidget *file;
nkeynes@630
    46
    gchar *initial_path = get_absolute_path(initial_dir);
nkeynes@435
    47
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@736
    48
            GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@736
    49
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
    50
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@736
    51
            NULL );
nkeynes@435
    52
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@630
    53
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
nkeynes@435
    54
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    55
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    56
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    57
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@736
    58
        gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@736
    59
        action( filename );
nkeynes@477
    60
    }
nkeynes@477
    61
    gtk_widget_destroy(file);
nkeynes@630
    62
    g_free(initial_path);
nkeynes@435
    63
}
nkeynes@435
    64
nkeynes@435
    65
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@736
    66
                       gchar const *initial_dir )
nkeynes@435
    67
{
nkeynes@435
    68
    GtkWidget *file;
nkeynes@630
    69
    gchar *initial_path = get_absolute_path(initial_dir);
nkeynes@435
    70
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@736
    71
            GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@736
    72
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
    73
            GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@736
    74
            NULL );
nkeynes@435
    75
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@630
    76
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
nkeynes@435
    77
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    78
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    79
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    80
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@736
    81
        gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@736
    82
        action( filename );
nkeynes@477
    83
    }
nkeynes@477
    84
    gtk_widget_destroy(file);
nkeynes@630
    85
    g_free(initial_path);
nkeynes@435
    86
}
nkeynes@435
    87
nkeynes@435
    88
void mount_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    89
{
nkeynes@450
    90
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@435
    91
    open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
nkeynes@435
    92
}
nkeynes@435
    93
void reset_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    94
{
nkeynes@435
    95
    dreamcast_reset();
nkeynes@435
    96
}
nkeynes@435
    97
nkeynes@435
    98
void pause_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    99
{
nkeynes@435
   100
    dreamcast_stop();
nkeynes@435
   101
}
nkeynes@435
   102
nkeynes@435
   103
void resume_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   104
{
nkeynes@435
   105
    dreamcast_run();
nkeynes@435
   106
}
nkeynes@435
   107
nkeynes@543
   108
void load_binary_action_callback( GtkAction *action, gpointer user_data)
nkeynes@543
   109
{
nkeynes@543
   110
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@543
   111
    open_file_dialog( "Open Binary...", file_load_magic, NULL, NULL, dir );
nkeynes@543
   112
}
nkeynes@543
   113
nkeynes@477
   114
void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
nkeynes@477
   115
{
nkeynes@477
   116
    GtkWidget *preview = GTK_WIDGET(user_data);
nkeynes@477
   117
    gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
nkeynes@736
   118
nkeynes@477
   119
    frame_buffer_t data = dreamcast_load_preview(filename);
nkeynes@477
   120
    if( data != NULL ) {
nkeynes@736
   121
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
nkeynes@736
   122
        GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
nkeynes@736
   123
                GDK_INTERP_BILINEAR);
nkeynes@736
   124
        g_object_unref(pixbuf);
nkeynes@736
   125
        gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
nkeynes@736
   126
        g_object_unref(scaled);
nkeynes@736
   127
        gtk_widget_show(preview);
nkeynes@477
   128
    } else {
nkeynes@736
   129
        gtk_widget_hide(preview);
nkeynes@477
   130
    }
nkeynes@477
   131
}
nkeynes@477
   132
nkeynes@435
   133
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   134
{
nkeynes@477
   135
    GtkWidget *file, *preview, *frame, *align;
nkeynes@477
   136
    GtkRequisition size;
nkeynes@450
   137
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@669
   138
    gchar *path = get_absolute_path(dir);
nkeynes@508
   139
    file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
nkeynes@736
   140
            GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@736
   141
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
   142
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@736
   143
            NULL );
nkeynes@508
   144
    add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
nkeynes@477
   145
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@477
   146
nkeynes@477
   147
    preview = gtk_image_new( );
nkeynes@477
   148
nkeynes@477
   149
    frame = gtk_frame_new(NULL);
nkeynes@477
   150
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@477
   151
    gtk_container_add( GTK_CONTAINER(frame), preview );
nkeynes@477
   152
    gtk_widget_show(frame);
nkeynes@477
   153
    gtk_widget_size_request(frame, &size);
nkeynes@477
   154
    gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
nkeynes@477
   155
    align = gtk_alignment_new(0.5, 0.5, 0, 0 );
nkeynes@477
   156
    gtk_container_add( GTK_CONTAINER(align), frame );
nkeynes@477
   157
    gtk_widget_show( align );
nkeynes@477
   158
    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
nkeynes@477
   159
    g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
nkeynes@736
   160
                      preview );
nkeynes@630
   161
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), path );
nkeynes@477
   162
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
   163
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
   164
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@736
   165
        gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@736
   166
        dreamcast_load_state( filename );
nkeynes@477
   167
    }
nkeynes@477
   168
    gtk_widget_destroy(file);
nkeynes@630
   169
    g_free(path);
nkeynes@435
   170
}
nkeynes@477
   171
nkeynes@435
   172
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   173
{
nkeynes@450
   174
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@508
   175
    save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), dir );
nkeynes@435
   176
}
nkeynes@435
   177
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   178
{
nkeynes@736
   179
nkeynes@435
   180
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@736
   181
            "name", APP_NAME, 
nkeynes@738
   182
            "version", lxdream_full_version,
nkeynes@738
   183
            "copyright", lxdream_copyright,
nkeynes@736
   184
            NULL);
nkeynes@435
   185
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   186
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   187
    gtk_widget_destroy(dialog);
nkeynes@736
   188
nkeynes@435
   189
}
nkeynes@435
   190
nkeynes@435
   191
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   192
{
nkeynes@671
   193
    dreamcast_shutdown();
nkeynes@435
   194
    exit(0);
nkeynes@435
   195
}
nkeynes@435
   196
nkeynes@447
   197
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   198
{
nkeynes@450
   199
    path_dialog_run();
nkeynes@447
   200
}
nkeynes@447
   201
nkeynes@435
   202
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   203
{
nkeynes@435
   204
}
nkeynes@435
   205
nkeynes@455
   206
void maple_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   207
{
nkeynes@455
   208
    maple_dialog_run( );
nkeynes@435
   209
}
nkeynes@435
   210
nkeynes@435
   211
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   212
{
nkeynes@435
   213
}
nkeynes@435
   214
nkeynes@435
   215
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   216
{
nkeynes@435
   217
}
nkeynes@435
   218
nkeynes@435
   219
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   220
{
nkeynes@486
   221
    main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
nkeynes@435
   222
}
nkeynes@455
   223
nkeynes@455
   224
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   225
{
nkeynes@455
   226
    gtk_gui_show_debugger();
nkeynes@455
   227
}
nkeynes@455
   228
nkeynes@455
   229
void debug_memory_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   230
{
nkeynes@738
   231
    gchar *title = g_strdup_printf( "%s :: %s", lxdream_package_name, _("Memory dump") );
nkeynes@508
   232
    dump_window_new( title );
nkeynes@508
   233
    g_free(title);
nkeynes@455
   234
}
nkeynes@455
   235
nkeynes@455
   236
void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   237
{
nkeynes@455
   238
    gtk_gui_show_mmio();
nkeynes@455
   239
}
nkeynes@455
   240
nkeynes@455
   241
void save_scene_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   242
{
nkeynes@455
   243
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@508
   244
    save_file_dialog( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), dir );
nkeynes@455
   245
}
nkeynes@455
   246
nkeynes@480
   247
int debug_window_get_selected_row( debug_window_t data );
nkeynes@480
   248
nkeynes@455
   249
void debug_step_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   250
{
nkeynes@455
   251
    debug_window_single_step(gtk_gui_get_debugger());
nkeynes@455
   252
}
nkeynes@455
   253
nkeynes@455
   254
void debug_runto_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   255
{
nkeynes@455
   256
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   257
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   258
    if( selected_row == -1 ) {
nkeynes@508
   259
        WARN( _("No address selected, so can't run to it"), NULL );
nkeynes@455
   260
    } else {
nkeynes@736
   261
        debug_window_set_oneshot_breakpoint( debug, selected_row );
nkeynes@736
   262
        dreamcast_run();
nkeynes@455
   263
    }
nkeynes@455
   264
}
nkeynes@455
   265
nkeynes@455
   266
void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   267
{
nkeynes@455
   268
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   269
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   270
    if( selected_row != -1 ) {
nkeynes@736
   271
        debug_window_toggle_breakpoint( debug, selected_row );
nkeynes@455
   272
    }
nkeynes@455
   273
}
.