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 440:d9bd9b7a283f
prev437:2c259474b474
next447:3e095bfcb476
author nkeynes
date Sat Oct 13 03:58:31 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Disable audio/video settings for the moment
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@440
     2
 * $Id: main_win.c,v 1.3 2007-10-13 03:58:31 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@435
    49
    { "AudioSettings", NULL, "_Audio...", NULL, "Configure audio output", G_CALLBACK(audio_settings_callback) },
nkeynes@435
    50
    { "ControllerSettings", NULL, "_Controllers...", NULL, "Configure controllers", G_CALLBACK(controller_settings_callback) },
nkeynes@435
    51
    { "NetworkSettings", NULL, "_Network...", NULL, "Configure network settings", G_CALLBACK(network_settings_callback) },
nkeynes@435
    52
    { "VideoSettings", NULL, "_Video...", NULL, "Configure video output", G_CALLBACK(video_settings_callback) },
nkeynes@435
    53
    { "About", GTK_STOCK_ABOUT, "_About...", NULL, "About lxdream", G_CALLBACK(about_action_callback) }
nkeynes@435
    54
};
nkeynes@435
    55
static const GtkToggleActionEntry ui_toggle_actions[] = {
nkeynes@435
    56
    { "FullScreen", NULL, "_Full Screen", "F9", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
nkeynes@435
    57
};
nkeynes@435
    58
    
nkeynes@435
    59
nkeynes@435
    60
static const char *ui_description =
nkeynes@435
    61
    "<ui>"
nkeynes@435
    62
    " <menubar name='MainMenu'>"
nkeynes@435
    63
    "  <menu action='FileMenu'>"
nkeynes@435
    64
    "   <menuitem action='Mount'/>"
nkeynes@435
    65
    "   <separator/>"
nkeynes@435
    66
    "   <menuitem action='Reset'/>"
nkeynes@435
    67
    "   <menuitem action='Pause'/>"
nkeynes@435
    68
    "   <menuitem action='Run'/>"
nkeynes@435
    69
    "   <separator/>"
nkeynes@435
    70
    "   <menuitem action='LoadState'/>"
nkeynes@435
    71
    "   <menuitem action='SaveState'/>"
nkeynes@435
    72
    "   <separator/>"
nkeynes@435
    73
    "   <menuitem action='Exit'/>"
nkeynes@435
    74
    "  </menu>"
nkeynes@435
    75
    "  <menu action='SettingsMenu'>"
nkeynes@435
    76
    "   <menuitem action='AudioSettings'/>"
nkeynes@435
    77
    "   <menuitem action='ControllerSettings'/>"
nkeynes@435
    78
    "   <menuitem action='NetworkSettings'/>"
nkeynes@435
    79
    "   <menuitem action='VideoSettings'/>"
nkeynes@435
    80
    "   <separator/>"
nkeynes@435
    81
    "   <menuitem action='FullScreen'/>"
nkeynes@435
    82
    "  </menu>"
nkeynes@435
    83
    "  <menu action='HelpMenu'>"
nkeynes@435
    84
    "   <menuitem action='About'/>"
nkeynes@435
    85
    "  </menu>"
nkeynes@435
    86
    " </menubar>"
nkeynes@435
    87
    " <toolbar name='MainToolbar'>"
nkeynes@435
    88
    "  <toolitem action='Mount'/>"
nkeynes@435
    89
    "  <toolitem action='Reset'/>"
nkeynes@435
    90
    "  <toolitem action='Pause'/>"
nkeynes@435
    91
    "  <toolitem action='Run'/>"
nkeynes@435
    92
    "  <separator/>"
nkeynes@435
    93
    "  <toolitem action='LoadState'/>"
nkeynes@435
    94
    "  <toolitem action='SaveState'/>"
nkeynes@435
    95
    " </toolbar>"
nkeynes@435
    96
    "</ui>";
nkeynes@435
    97
nkeynes@435
    98
nkeynes@435
    99
struct main_window_info {
nkeynes@435
   100
    GtkWidget *window;
nkeynes@435
   101
    GtkWidget *menubar;
nkeynes@435
   102
    GtkWidget *toolbar;
nkeynes@435
   103
    GtkWidget *video;
nkeynes@435
   104
    GtkWidget *statusbar;
nkeynes@435
   105
    GtkActionGroup *actions;
nkeynes@435
   106
};
nkeynes@435
   107
nkeynes@435
   108
main_window_t main_window_new( const gchar *title )
nkeynes@435
   109
{
nkeynes@435
   110
    GtkWidget *vbox;
nkeynes@435
   111
    GtkUIManager *ui_manager;
nkeynes@435
   112
    GtkAccelGroup *accel_group;
nkeynes@437
   113
    GtkWidget *frame;
nkeynes@435
   114
    GError *error = NULL;
nkeynes@435
   115
    main_window_t win = g_malloc0( sizeof(struct main_window_info) );
nkeynes@435
   116
nkeynes@435
   117
    win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
nkeynes@435
   118
    gtk_window_set_title( GTK_WINDOW(win->window), title );
nkeynes@435
   119
nkeynes@435
   120
    win->actions = gtk_action_group_new("MenuActions");
nkeynes@435
   121
    gtk_action_group_add_actions( win->actions, ui_actions, G_N_ELEMENTS(ui_actions), win->window );
nkeynes@435
   122
    gtk_action_group_add_toggle_actions( win->actions, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), win->window );
nkeynes@440
   123
    DISABLE_ACTION(win, "AudioSettings");
nkeynes@435
   124
    DISABLE_ACTION(win, "NetworkSettings");
nkeynes@440
   125
    DISABLE_ACTION(win, "VideoSettings");
nkeynes@435
   126
    
nkeynes@435
   127
    ui_manager = gtk_ui_manager_new();
nkeynes@435
   128
    gtk_ui_manager_set_add_tearoffs(ui_manager, TRUE);
nkeynes@435
   129
    gtk_ui_manager_insert_action_group( ui_manager, win->actions, 0 );
nkeynes@435
   130
nkeynes@435
   131
    if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, &error)) {
nkeynes@435
   132
	g_message ("building menus failed: %s", error->message);
nkeynes@435
   133
	g_error_free (error);
nkeynes@435
   134
	exit(1);
nkeynes@435
   135
    }
nkeynes@435
   136
    
nkeynes@435
   137
    accel_group = gtk_ui_manager_get_accel_group (ui_manager);
nkeynes@435
   138
    gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
nkeynes@435
   139
nkeynes@435
   140
    win->menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
nkeynes@435
   141
    win->toolbar = gtk_ui_manager_get_widget(ui_manager, "/MainToolbar");
nkeynes@435
   142
nkeynes@435
   143
    gtk_toolbar_set_style( GTK_TOOLBAR(win->toolbar), GTK_TOOLBAR_ICONS );
nkeynes@435
   144
nkeynes@435
   145
    win->video = gtk_drawing_area_new();
nkeynes@435
   146
    GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
nkeynes@435
   147
    gtk_widget_set_size_request( win->video, 640, 480 ); 
nkeynes@437
   148
    frame = gtk_frame_new(NULL);
nkeynes@437
   149
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@437
   150
    gtk_container_add( GTK_CONTAINER(frame), win->video );
nkeynes@437
   151
nkeynes@435
   152
    win->statusbar = gtk_statusbar_new();
nkeynes@435
   153
nkeynes@435
   154
    vbox = gtk_vbox_new(FALSE, 0);
nkeynes@435
   155
    gtk_container_add( GTK_CONTAINER(win->window), vbox );
nkeynes@435
   156
    gtk_box_pack_start( GTK_BOX(vbox), win->menubar, FALSE, FALSE, 0 );
nkeynes@435
   157
    gtk_box_pack_start( GTK_BOX(vbox), win->toolbar, FALSE, FALSE, 0 );
nkeynes@437
   158
    gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
nkeynes@435
   159
    gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
nkeynes@435
   160
    gtk_widget_show_all( win->window );
nkeynes@435
   161
    gtk_widget_grab_focus( win->video );
nkeynes@435
   162
    
nkeynes@437
   163
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
nkeynes@435
   164
    return win;
nkeynes@435
   165
}
nkeynes@435
   166
nkeynes@435
   167
void main_window_set_running( main_window_t win, gboolean running )
nkeynes@435
   168
{
nkeynes@435
   169
    SET_ACTION_ENABLED( win, "Pause", running );
nkeynes@435
   170
    SET_ACTION_ENABLED( win, "Run", !running );
nkeynes@437
   171
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   172
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
nkeynes@435
   173
}
nkeynes@435
   174
nkeynes@435
   175
void main_window_set_framerate( main_window_t win, float rate )
nkeynes@435
   176
{
nkeynes@435
   177
nkeynes@435
   178
nkeynes@435
   179
}
nkeynes@435
   180
nkeynes@437
   181
void main_window_set_speed( main_window_t win, double speed )
nkeynes@437
   182
{
nkeynes@437
   183
    char buf[32];
nkeynes@437
   184
nkeynes@437
   185
    snprintf( buf, 32, "Running (%2.4f%)", speed );
nkeynes@437
   186
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   187
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
nkeynes@437
   188
    
nkeynes@437
   189
nkeynes@437
   190
}
nkeynes@437
   191
nkeynes@435
   192
GtkWidget *main_window_get_renderarea( main_window_t win )
nkeynes@435
   193
{
nkeynes@435
   194
    return win->video;
nkeynes@435
   195
}
.