Search
lxdream.org :: lxdream/src/gui/main_win.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/main_win.c
changeset 447:3e095bfcb476
prev440:d9bd9b7a283f
next450:207461e79f21
author nkeynes
date Tue Oct 16 12:36:29 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Add gui error reporting
Add initial controller settings dialog
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@447
     2
 * $Id: main_win.c,v 1.4 2007-10-16 12:36:29 nkeynes Exp $
nkeynes@435
     3
 *
nkeynes@435
     4
 * Define the main (emu) GTK window, along with its menubars,
nkeynes@435
     5
 * toolbars, etc.
nkeynes@435
     6
 *
nkeynes@435
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     8
 *
nkeynes@435
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    12
 * (at your option) any later version.
nkeynes@435
    13
 *
nkeynes@435
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    17
 * GNU General Public License for more details.
nkeynes@435
    18
 */
nkeynes@435
    19
nkeynes@435
    20
#include <assert.h>
nkeynes@435
    21
#include <sys/types.h>
nkeynes@435
    22
#include <sys/stat.h>
nkeynes@435
    23
#include <unistd.h>
nkeynes@435
    24
#include <string.h>
nkeynes@435
    25
#include <stdio.h>
nkeynes@435
    26
#include <stdlib.h>
nkeynes@435
    27
nkeynes@435
    28
#include <gtk/gtk.h>
nkeynes@435
    29
nkeynes@435
    30
#include "dream.h"
nkeynes@435
    31
#include "gui/gtkui.h"
nkeynes@435
    32
nkeynes@435
    33
#define SET_ACTION_ENABLED(win,name,b) gtk_action_set_sensitive( gtk_action_group_get_action( win->actions, name), b)
nkeynes@435
    34
#define ENABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,TRUE)
nkeynes@435
    35
#define DISABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,FALSE)
nkeynes@435
    36
nkeynes@435
    37
static const GtkActionEntry ui_actions[] = {
nkeynes@435
    38
    { "FileMenu", NULL, "_File" },
nkeynes@435
    39
    { "SettingsMenu", NULL, "_Settings" },
nkeynes@435
    40
    { "HelpMenu", NULL, "_Help" },
nkeynes@435
    41
    { "Mount", GTK_STOCK_CDROM, "_Mount...", "<control>O", "Mount a cdrom disc", G_CALLBACK(mount_action_callback) },
nkeynes@435
    42
    { "Reset", GTK_STOCK_REFRESH, "_Reset", "<control>R", "Reset dreamcast", G_CALLBACK(reset_action_callback) },
nkeynes@435
    43
    { "Pause", GTK_STOCK_MEDIA_PAUSE, "_Pause", NULL, "Pause dreamcast", G_CALLBACK(pause_action_callback) },
nkeynes@435
    44
    { "Run", GTK_STOCK_MEDIA_PLAY, "Resume", NULL, "Resume", G_CALLBACK(resume_action_callback) },
nkeynes@435
    45
    { "LoadState", GTK_STOCK_REVERT_TO_SAVED, "_Load state...", "F4", "Load an lxdream save state", G_CALLBACK(load_state_action_callback) },
nkeynes@435
    46
    { "SaveState", GTK_STOCK_SAVE_AS, "_Save state...", "F3", "Create an lxdream save state", G_CALLBACK(save_state_action_callback) },
nkeynes@437
    47
    { "Debugger", NULL, "_Debugger", NULL, "Open debugger window", G_CALLBACK(debugger_action_callback) },
nkeynes@435
    48
    { "Exit", GTK_STOCK_QUIT, "E_xit", NULL, "Exit lxdream", G_CALLBACK(exit_action_callback) },
nkeynes@447
    49
    { "PathSettings", NULL, "_Paths...", NULL, "Configure files and paths", G_CALLBACK(path_settings_callback) }, 
nkeynes@435
    50
    { "AudioSettings", NULL, "_Audio...", NULL, "Configure audio output", G_CALLBACK(audio_settings_callback) },
nkeynes@435
    51
    { "ControllerSettings", NULL, "_Controllers...", NULL, "Configure controllers", G_CALLBACK(controller_settings_callback) },
nkeynes@435
    52
    { "NetworkSettings", NULL, "_Network...", NULL, "Configure network settings", G_CALLBACK(network_settings_callback) },
nkeynes@435
    53
    { "VideoSettings", NULL, "_Video...", NULL, "Configure video output", G_CALLBACK(video_settings_callback) },
nkeynes@435
    54
    { "About", GTK_STOCK_ABOUT, "_About...", NULL, "About lxdream", G_CALLBACK(about_action_callback) }
nkeynes@435
    55
};
nkeynes@435
    56
static const GtkToggleActionEntry ui_toggle_actions[] = {
nkeynes@435
    57
    { "FullScreen", NULL, "_Full Screen", "F9", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
nkeynes@435
    58
};
nkeynes@435
    59
    
nkeynes@435
    60
nkeynes@435
    61
static const char *ui_description =
nkeynes@435
    62
    "<ui>"
nkeynes@435
    63
    " <menubar name='MainMenu'>"
nkeynes@435
    64
    "  <menu action='FileMenu'>"
nkeynes@435
    65
    "   <menuitem action='Mount'/>"
nkeynes@435
    66
    "   <separator/>"
nkeynes@435
    67
    "   <menuitem action='Reset'/>"
nkeynes@435
    68
    "   <menuitem action='Pause'/>"
nkeynes@435
    69
    "   <menuitem action='Run'/>"
nkeynes@435
    70
    "   <separator/>"
nkeynes@435
    71
    "   <menuitem action='LoadState'/>"
nkeynes@435
    72
    "   <menuitem action='SaveState'/>"
nkeynes@435
    73
    "   <separator/>"
nkeynes@435
    74
    "   <menuitem action='Exit'/>"
nkeynes@435
    75
    "  </menu>"
nkeynes@435
    76
    "  <menu action='SettingsMenu'>"
nkeynes@435
    77
    "   <menuitem action='AudioSettings'/>"
nkeynes@435
    78
    "   <menuitem action='ControllerSettings'/>"
nkeynes@435
    79
    "   <menuitem action='NetworkSettings'/>"
nkeynes@435
    80
    "   <menuitem action='VideoSettings'/>"
nkeynes@435
    81
    "   <separator/>"
nkeynes@435
    82
    "   <menuitem action='FullScreen'/>"
nkeynes@435
    83
    "  </menu>"
nkeynes@435
    84
    "  <menu action='HelpMenu'>"
nkeynes@435
    85
    "   <menuitem action='About'/>"
nkeynes@435
    86
    "  </menu>"
nkeynes@435
    87
    " </menubar>"
nkeynes@435
    88
    " <toolbar name='MainToolbar'>"
nkeynes@435
    89
    "  <toolitem action='Mount'/>"
nkeynes@435
    90
    "  <toolitem action='Reset'/>"
nkeynes@435
    91
    "  <toolitem action='Pause'/>"
nkeynes@435
    92
    "  <toolitem action='Run'/>"
nkeynes@435
    93
    "  <separator/>"
nkeynes@435
    94
    "  <toolitem action='LoadState'/>"
nkeynes@435
    95
    "  <toolitem action='SaveState'/>"
nkeynes@435
    96
    " </toolbar>"
nkeynes@435
    97
    "</ui>";
nkeynes@435
    98
nkeynes@435
    99
nkeynes@435
   100
struct main_window_info {
nkeynes@435
   101
    GtkWidget *window;
nkeynes@435
   102
    GtkWidget *menubar;
nkeynes@435
   103
    GtkWidget *toolbar;
nkeynes@435
   104
    GtkWidget *video;
nkeynes@435
   105
    GtkWidget *statusbar;
nkeynes@435
   106
    GtkActionGroup *actions;
nkeynes@435
   107
};
nkeynes@435
   108
nkeynes@435
   109
main_window_t main_window_new( const gchar *title )
nkeynes@435
   110
{
nkeynes@435
   111
    GtkWidget *vbox;
nkeynes@435
   112
    GtkUIManager *ui_manager;
nkeynes@435
   113
    GtkAccelGroup *accel_group;
nkeynes@437
   114
    GtkWidget *frame;
nkeynes@435
   115
    GError *error = NULL;
nkeynes@435
   116
    main_window_t win = g_malloc0( sizeof(struct main_window_info) );
nkeynes@435
   117
nkeynes@435
   118
    win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
nkeynes@435
   119
    gtk_window_set_title( GTK_WINDOW(win->window), title );
nkeynes@435
   120
nkeynes@435
   121
    win->actions = gtk_action_group_new("MenuActions");
nkeynes@435
   122
    gtk_action_group_add_actions( win->actions, ui_actions, G_N_ELEMENTS(ui_actions), win->window );
nkeynes@435
   123
    gtk_action_group_add_toggle_actions( win->actions, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), win->window );
nkeynes@440
   124
    DISABLE_ACTION(win, "AudioSettings");
nkeynes@435
   125
    DISABLE_ACTION(win, "NetworkSettings");
nkeynes@440
   126
    DISABLE_ACTION(win, "VideoSettings");
nkeynes@435
   127
    
nkeynes@435
   128
    ui_manager = gtk_ui_manager_new();
nkeynes@435
   129
    gtk_ui_manager_set_add_tearoffs(ui_manager, TRUE);
nkeynes@435
   130
    gtk_ui_manager_insert_action_group( ui_manager, win->actions, 0 );
nkeynes@435
   131
nkeynes@435
   132
    if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, &error)) {
nkeynes@435
   133
	g_message ("building menus failed: %s", error->message);
nkeynes@435
   134
	g_error_free (error);
nkeynes@435
   135
	exit(1);
nkeynes@435
   136
    }
nkeynes@435
   137
    
nkeynes@435
   138
    accel_group = gtk_ui_manager_get_accel_group (ui_manager);
nkeynes@435
   139
    gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
nkeynes@435
   140
nkeynes@435
   141
    win->menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
nkeynes@435
   142
    win->toolbar = gtk_ui_manager_get_widget(ui_manager, "/MainToolbar");
nkeynes@435
   143
nkeynes@435
   144
    gtk_toolbar_set_style( GTK_TOOLBAR(win->toolbar), GTK_TOOLBAR_ICONS );
nkeynes@435
   145
nkeynes@435
   146
    win->video = gtk_drawing_area_new();
nkeynes@435
   147
    GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
nkeynes@435
   148
    gtk_widget_set_size_request( win->video, 640, 480 ); 
nkeynes@437
   149
    frame = gtk_frame_new(NULL);
nkeynes@437
   150
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@437
   151
    gtk_container_add( GTK_CONTAINER(frame), win->video );
nkeynes@437
   152
nkeynes@435
   153
    win->statusbar = gtk_statusbar_new();
nkeynes@435
   154
nkeynes@435
   155
    vbox = gtk_vbox_new(FALSE, 0);
nkeynes@435
   156
    gtk_container_add( GTK_CONTAINER(win->window), vbox );
nkeynes@435
   157
    gtk_box_pack_start( GTK_BOX(vbox), win->menubar, FALSE, FALSE, 0 );
nkeynes@435
   158
    gtk_box_pack_start( GTK_BOX(vbox), win->toolbar, FALSE, FALSE, 0 );
nkeynes@437
   159
    gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
nkeynes@435
   160
    gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
nkeynes@435
   161
    gtk_widget_show_all( win->window );
nkeynes@435
   162
    gtk_widget_grab_focus( win->video );
nkeynes@435
   163
    
nkeynes@437
   164
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
nkeynes@435
   165
    return win;
nkeynes@435
   166
}
nkeynes@435
   167
nkeynes@435
   168
void main_window_set_running( main_window_t win, gboolean running )
nkeynes@435
   169
{
nkeynes@435
   170
    SET_ACTION_ENABLED( win, "Pause", running );
nkeynes@435
   171
    SET_ACTION_ENABLED( win, "Run", !running );
nkeynes@437
   172
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   173
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
nkeynes@435
   174
}
nkeynes@435
   175
nkeynes@435
   176
void main_window_set_framerate( main_window_t win, float rate )
nkeynes@435
   177
{
nkeynes@435
   178
nkeynes@435
   179
nkeynes@435
   180
}
nkeynes@435
   181
nkeynes@437
   182
void main_window_set_speed( main_window_t win, double speed )
nkeynes@437
   183
{
nkeynes@437
   184
    char buf[32];
nkeynes@437
   185
nkeynes@437
   186
    snprintf( buf, 32, "Running (%2.4f%)", speed );
nkeynes@437
   187
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   188
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
nkeynes@437
   189
    
nkeynes@437
   190
nkeynes@437
   191
}
nkeynes@437
   192
nkeynes@435
   193
GtkWidget *main_window_get_renderarea( main_window_t win )
nkeynes@435
   194
{
nkeynes@435
   195
    return win->video;
nkeynes@435
   196
}
nkeynes@447
   197
nkeynes@447
   198
GtkWindow *main_window_get_frame( main_window_t win )
nkeynes@447
   199
{
nkeynes@447
   200
    return GTK_WINDOW(win->window);
nkeynes@447
   201
}
.