Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 1124:aacaae9812ea
prev1109:700c5ab26a63
author nkeynes
date Tue Feb 28 18:22:52 2012 +1000 (10 years ago)
permissions -rw-r--r--
last change Add a GL-only video driver for android usage (since the Java code is
responsible for creating the context)
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@1041
    19
#include <stdlib.h>
nkeynes@1041
    20
nkeynes@1041
    21
#include "lxdream.h"
nkeynes@450
    22
#include "config.h"
nkeynes@1041
    23
#include "lxpaths.h"
nkeynes@435
    24
#include "dreamcast.h"
nkeynes@435
    25
#include "gdrom/gdrom.h"
nkeynes@537
    26
#include "gtkui/gtkui.h"
nkeynes@455
    27
#include "pvr2/pvr2.h"
nkeynes@543
    28
#include "loader.h"
nkeynes@435
    29
nkeynes@435
    30
nkeynes@887
    31
static void add_file_pattern( GtkFileChooser *chooser, const char *pattern, const char *patname )
nkeynes@435
    32
{
nkeynes@435
    33
    if( pattern != NULL ) {
nkeynes@736
    34
        GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@736
    35
        gtk_file_filter_add_pattern( filter, pattern );
nkeynes@736
    36
        gtk_file_filter_set_name( filter, patname );
nkeynes@736
    37
        gtk_file_chooser_add_filter( chooser, filter );
nkeynes@736
    38
        filter = gtk_file_filter_new();
nkeynes@736
    39
        gtk_file_filter_set_name( filter, _("All files") );
nkeynes@736
    40
        gtk_file_filter_add_pattern( filter, "*" );
nkeynes@736
    41
        gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    42
    }
nkeynes@435
    43
}
nkeynes@435
    44
nkeynes@1034
    45
gchar *open_file_dialog( const char *title, const char *pattern, const char *patname,
nkeynes@1036
    46
                         int initial_dir_key )
nkeynes@435
    47
{
nkeynes@435
    48
    GtkWidget *file;
nkeynes@1034
    49
    gchar *filename = NULL;
nkeynes@1036
    50
nkeynes@435
    51
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@736
    52
            GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@736
    53
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
    54
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@736
    55
            NULL );
nkeynes@435
    56
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@1036
    57
    if( initial_dir_key != -1 ) {
nkeynes@1041
    58
        gchar *initial_path = get_absolute_path(get_gui_path(initial_dir_key));
nkeynes@1036
    59
        gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
nkeynes@1036
    60
        g_free(initial_path);
nkeynes@1036
    61
    }
nkeynes@435
    62
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    63
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    64
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    65
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@1034
    66
        filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@1036
    67
        if( initial_dir_key != -1 ) {
nkeynes@1036
    68
            gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
nkeynes@1041
    69
            set_gui_path(initial_dir_key,end_path);
nkeynes@1036
    70
            g_free(end_path);
nkeynes@1036
    71
        }
nkeynes@477
    72
    }
nkeynes@477
    73
    gtk_widget_destroy(file);
nkeynes@1034
    74
nkeynes@1034
    75
    return filename;
nkeynes@435
    76
}
nkeynes@435
    77
nkeynes@1034
    78
gchar *save_file_dialog( const char *title, const char *pattern, const char *patname,
nkeynes@1124
    79
                         const char *mandatory_ext, int initial_dir_key )
nkeynes@435
    80
{
nkeynes@435
    81
    GtkWidget *file;
nkeynes@1072
    82
    gchar *filename = NULL;
nkeynes@1036
    83
    
nkeynes@435
    84
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@736
    85
            GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@736
    86
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
    87
            GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@736
    88
            NULL );
nkeynes@435
    89
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@1036
    90
    if( initial_dir_key != -1 ) {
nkeynes@1041
    91
        gchar *initial_path = get_absolute_path(get_gui_path(initial_dir_key));
nkeynes@1036
    92
        gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
nkeynes@1036
    93
        g_free(initial_path);
nkeynes@1036
    94
    }
nkeynes@435
    95
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    96
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    97
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    98
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@1034
    99
        filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@1124
   100
        if( mandatory_ext ) {
nkeynes@1124
   101
            int extlen = strlen(mandatory_ext);
nkeynes@1124
   102
            int fnlen = strlen(filename);
nkeynes@1124
   103
            if( fnlen < extlen || strcmp(filename + (fnlen - extlen), mandatory_ext) != 0 ) {
nkeynes@1124
   104
                gchar *f2 = g_strdup_printf("%s%s",filename, mandatory_ext);
nkeynes@1124
   105
                g_free(filename);
nkeynes@1124
   106
                filename = f2;
nkeynes@1124
   107
            }
nkeynes@1124
   108
        }
nkeynes@1036
   109
        if( initial_dir_key != -1 ) {
nkeynes@1036
   110
            gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
nkeynes@1041
   111
            set_gui_path(initial_dir_key,end_path);
nkeynes@1036
   112
            g_free(end_path);
nkeynes@1036
   113
        }
nkeynes@477
   114
    }
nkeynes@477
   115
    gtk_widget_destroy(file);
nkeynes@1034
   116
    return filename;
nkeynes@1034
   117
}
nkeynes@1034
   118
nkeynes@1034
   119
void open_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
nkeynes@1036
   120
                          int initial_dir_key )
nkeynes@1034
   121
{
nkeynes@1036
   122
    gchar *filename = open_file_dialog( title, pattern, patname, initial_dir_key ); 
nkeynes@1034
   123
    if( filename != NULL ) {
nkeynes@1034
   124
        action( filename );
nkeynes@1034
   125
        g_free(filename);
nkeynes@1034
   126
    }
nkeynes@1034
   127
}
nkeynes@1034
   128
nkeynes@1034
   129
void save_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
nkeynes@1124
   130
                          const char *mandatory_ext, int initial_dir_key )
nkeynes@1034
   131
{
nkeynes@1124
   132
    gchar *filename = save_file_dialog( title, pattern, patname, mandatory_ext, initial_dir_key );
nkeynes@1034
   133
    if( filename != NULL ) {
nkeynes@1034
   134
        action(filename);
nkeynes@1034
   135
        g_free(filename);
nkeynes@1034
   136
    }
nkeynes@435
   137
}
nkeynes@435
   138
nkeynes@435
   139
void mount_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   140
{
nkeynes@1109
   141
    open_file_dialog_cb( "Open...", gtk_gui_gdrom_mount_image, NULL, NULL, CONFIG_DEFAULT_PATH );
nkeynes@435
   142
}
nkeynes@435
   143
void reset_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   144
{
nkeynes@435
   145
    dreamcast_reset();
nkeynes@435
   146
}
nkeynes@435
   147
nkeynes@435
   148
void pause_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   149
{
nkeynes@435
   150
    dreamcast_stop();
nkeynes@435
   151
}
nkeynes@435
   152
nkeynes@435
   153
void resume_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   154
{
nkeynes@435
   155
    dreamcast_run();
nkeynes@435
   156
}
nkeynes@435
   157
nkeynes@1109
   158
gboolean gtk_gui_load_exec( const gchar *filename )
nkeynes@1109
   159
{
nkeynes@1109
   160
    ERROR err;
nkeynes@1109
   161
    gboolean ok = file_load_exec(filename, &err);
nkeynes@1109
   162
    if( !ok ) {
nkeynes@1109
   163
        ERROR(err.msg);
nkeynes@1109
   164
    }
nkeynes@1109
   165
    return ok;
nkeynes@1109
   166
}
nkeynes@1109
   167
nkeynes@543
   168
void load_binary_action_callback( GtkAction *action, gpointer user_data)
nkeynes@543
   169
{
nkeynes@1109
   170
    open_file_dialog_cb( "Open Binary...", gtk_gui_load_exec, NULL, NULL, CONFIG_DEFAULT_PATH );
nkeynes@543
   171
}
nkeynes@543
   172
nkeynes@477
   173
void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
nkeynes@477
   174
{
nkeynes@477
   175
    GtkWidget *preview = GTK_WIDGET(user_data);
nkeynes@477
   176
    gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
nkeynes@736
   177
nkeynes@477
   178
    frame_buffer_t data = dreamcast_load_preview(filename);
nkeynes@477
   179
    if( data != NULL ) {
nkeynes@736
   180
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
nkeynes@736
   181
        GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
nkeynes@736
   182
                GDK_INTERP_BILINEAR);
nkeynes@736
   183
        g_object_unref(pixbuf);
nkeynes@736
   184
        gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
nkeynes@736
   185
        g_object_unref(scaled);
nkeynes@736
   186
        gtk_widget_show(preview);
nkeynes@477
   187
    } else {
nkeynes@736
   188
        gtk_widget_hide(preview);
nkeynes@477
   189
    }
nkeynes@477
   190
}
nkeynes@477
   191
nkeynes@435
   192
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   193
{
nkeynes@477
   194
    GtkWidget *file, *preview, *frame, *align;
nkeynes@477
   195
    GtkRequisition size;
nkeynes@1041
   196
    const gchar *dir = get_gui_path(CONFIG_SAVE_PATH);
nkeynes@669
   197
    gchar *path = get_absolute_path(dir);
nkeynes@508
   198
    file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
nkeynes@736
   199
            GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@736
   200
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
   201
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@736
   202
            NULL );
nkeynes@508
   203
    add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
nkeynes@477
   204
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@477
   205
nkeynes@477
   206
    preview = gtk_image_new( );
nkeynes@477
   207
nkeynes@477
   208
    frame = gtk_frame_new(NULL);
nkeynes@477
   209
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@477
   210
    gtk_container_add( GTK_CONTAINER(frame), preview );
nkeynes@477
   211
    gtk_widget_show(frame);
nkeynes@477
   212
    gtk_widget_size_request(frame, &size);
nkeynes@477
   213
    gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
nkeynes@477
   214
    align = gtk_alignment_new(0.5, 0.5, 0, 0 );
nkeynes@477
   215
    gtk_container_add( GTK_CONTAINER(align), frame );
nkeynes@477
   216
    gtk_widget_show( align );
nkeynes@477
   217
    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
nkeynes@477
   218
    g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
nkeynes@736
   219
                      preview );
nkeynes@630
   220
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), path );
nkeynes@477
   221
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
   222
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
   223
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@736
   224
        gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@1036
   225
        gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
nkeynes@1041
   226
        set_gui_path(CONFIG_SAVE_PATH,end_path);
nkeynes@1036
   227
        g_free(end_path);
nkeynes@736
   228
        dreamcast_load_state( filename );
nkeynes@477
   229
    }
nkeynes@477
   230
    gtk_widget_destroy(file);
nkeynes@630
   231
    g_free(path);
nkeynes@435
   232
}
nkeynes@477
   233
nkeynes@435
   234
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   235
{
nkeynes@1124
   236
    save_file_dialog_cb( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), ".dst", CONFIG_SAVE_PATH );
nkeynes@435
   237
}
nkeynes@1040
   238
nkeynes@1040
   239
void quick_state_action_callback( GtkRadioAction *action, GtkRadioAction *current, gpointer user_data)
nkeynes@1040
   240
{
nkeynes@1040
   241
    gint val = gtk_radio_action_get_current_value(action);
nkeynes@1040
   242
    dreamcast_set_quick_state(val);
nkeynes@1040
   243
}
nkeynes@1040
   244
nkeynes@1040
   245
void quick_load_action_callback( GtkAction *action, gpointer user_data)
nkeynes@1040
   246
{
nkeynes@1040
   247
    dreamcast_quick_load();
nkeynes@1040
   248
}
nkeynes@1040
   249
nkeynes@1040
   250
void quick_save_action_callback( GtkAction *action, gpointer user_data)
nkeynes@1040
   251
{
nkeynes@1040
   252
    dreamcast_quick_save();
nkeynes@1040
   253
}
nkeynes@1040
   254
nkeynes@1040
   255
nkeynes@435
   256
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   257
{
nkeynes@736
   258
nkeynes@435
   259
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@736
   260
            "name", APP_NAME, 
nkeynes@738
   261
            "version", lxdream_full_version,
nkeynes@738
   262
            "copyright", lxdream_copyright,
nkeynes@1017
   263
            "logo-icon-name", "lxdream",
nkeynes@736
   264
            NULL);
nkeynes@435
   265
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   266
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   267
    gtk_widget_destroy(dialog);
nkeynes@736
   268
nkeynes@435
   269
}
nkeynes@435
   270
nkeynes@435
   271
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   272
{
nkeynes@671
   273
    dreamcast_shutdown();
nkeynes@435
   274
    exit(0);
nkeynes@435
   275
}
nkeynes@435
   276
nkeynes@447
   277
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   278
{
nkeynes@1072
   279
    gtk_configuration_panel_run( _("Path Settings"), lxdream_get_config_group(CONFIG_GROUP_GLOBAL) );
nkeynes@447
   280
}
nkeynes@447
   281
nkeynes@435
   282
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   283
{
nkeynes@435
   284
}
nkeynes@435
   285
nkeynes@455
   286
void maple_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   287
{
nkeynes@455
   288
    maple_dialog_run( );
nkeynes@435
   289
}
nkeynes@435
   290
nkeynes@435
   291
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   292
{
nkeynes@435
   293
}
nkeynes@435
   294
nkeynes@435
   295
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   296
{
nkeynes@435
   297
}
nkeynes@435
   298
nkeynes@1015
   299
void hotkey_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@1015
   300
{
nkeynes@1072
   301
    gtk_configuration_panel_run( _("Hotkey Settings"), lxdream_get_config_group(CONFIG_GROUP_HOTKEYS) );
nkeynes@1015
   302
}
nkeynes@1015
   303
nkeynes@435
   304
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   305
{
nkeynes@486
   306
    main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
nkeynes@435
   307
}
nkeynes@455
   308
nkeynes@455
   309
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   310
{
nkeynes@455
   311
    gtk_gui_show_debugger();
nkeynes@455
   312
}
nkeynes@455
   313
nkeynes@455
   314
void debug_memory_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   315
{
nkeynes@738
   316
    gchar *title = g_strdup_printf( "%s :: %s", lxdream_package_name, _("Memory dump") );
nkeynes@508
   317
    dump_window_new( title );
nkeynes@508
   318
    g_free(title);
nkeynes@455
   319
}
nkeynes@455
   320
nkeynes@455
   321
void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   322
{
nkeynes@455
   323
    gtk_gui_show_mmio();
nkeynes@455
   324
}
nkeynes@455
   325
nkeynes@455
   326
void save_scene_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   327
{
nkeynes@1124
   328
    save_file_dialog_cb( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), ".dsc", CONFIG_SAVE_PATH );
nkeynes@455
   329
}
nkeynes@455
   330
nkeynes@480
   331
int debug_window_get_selected_row( debug_window_t data );
nkeynes@480
   332
nkeynes@455
   333
void debug_step_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   334
{
nkeynes@455
   335
    debug_window_single_step(gtk_gui_get_debugger());
nkeynes@455
   336
}
nkeynes@455
   337
nkeynes@455
   338
void debug_runto_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   339
{
nkeynes@455
   340
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   341
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   342
    if( selected_row == -1 ) {
nkeynes@508
   343
        WARN( _("No address selected, so can't run to it"), NULL );
nkeynes@455
   344
    } else {
nkeynes@736
   345
        debug_window_set_oneshot_breakpoint( debug, selected_row );
nkeynes@736
   346
        dreamcast_run();
nkeynes@455
   347
    }
nkeynes@455
   348
}
nkeynes@455
   349
nkeynes@455
   350
void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   351
{
nkeynes@455
   352
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   353
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   354
    if( selected_row != -1 ) {
nkeynes@736
   355
        debug_window_toggle_breakpoint( debug, selected_row );
nkeynes@455
   356
    }
nkeynes@455
   357
}
.