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