2 * $Id: main_win.c,v 1.3 2007-10-13 03:58:31 nkeynes Exp $
4 * Define the main (emu) GTK window, along with its menubars,
7 * Copyright (c) 2005 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
21 #include <sys/types.h>
31 #include "gui/gtkui.h"
33 #define SET_ACTION_ENABLED(win,name,b) gtk_action_set_sensitive( gtk_action_group_get_action( win->actions, name), b)
34 #define ENABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,TRUE)
35 #define DISABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,FALSE)
37 static const GtkActionEntry ui_actions[] = {
38 { "FileMenu", NULL, "_File" },
39 { "SettingsMenu", NULL, "_Settings" },
40 { "HelpMenu", NULL, "_Help" },
41 { "Mount", GTK_STOCK_CDROM, "_Mount...", "<control>O", "Mount a cdrom disc", G_CALLBACK(mount_action_callback) },
42 { "Reset", GTK_STOCK_REFRESH, "_Reset", "<control>R", "Reset dreamcast", G_CALLBACK(reset_action_callback) },
43 { "Pause", GTK_STOCK_MEDIA_PAUSE, "_Pause", NULL, "Pause dreamcast", G_CALLBACK(pause_action_callback) },
44 { "Run", GTK_STOCK_MEDIA_PLAY, "Resume", NULL, "Resume", G_CALLBACK(resume_action_callback) },
45 { "LoadState", GTK_STOCK_REVERT_TO_SAVED, "_Load state...", "F4", "Load an lxdream save state", G_CALLBACK(load_state_action_callback) },
46 { "SaveState", GTK_STOCK_SAVE_AS, "_Save state...", "F3", "Create an lxdream save state", G_CALLBACK(save_state_action_callback) },
47 { "Debugger", NULL, "_Debugger", NULL, "Open debugger window", G_CALLBACK(debugger_action_callback) },
48 { "Exit", GTK_STOCK_QUIT, "E_xit", NULL, "Exit lxdream", G_CALLBACK(exit_action_callback) },
49 { "AudioSettings", NULL, "_Audio...", NULL, "Configure audio output", G_CALLBACK(audio_settings_callback) },
50 { "ControllerSettings", NULL, "_Controllers...", NULL, "Configure controllers", G_CALLBACK(controller_settings_callback) },
51 { "NetworkSettings", NULL, "_Network...", NULL, "Configure network settings", G_CALLBACK(network_settings_callback) },
52 { "VideoSettings", NULL, "_Video...", NULL, "Configure video output", G_CALLBACK(video_settings_callback) },
53 { "About", GTK_STOCK_ABOUT, "_About...", NULL, "About lxdream", G_CALLBACK(about_action_callback) }
55 static const GtkToggleActionEntry ui_toggle_actions[] = {
56 { "FullScreen", NULL, "_Full Screen", "F9", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
60 static const char *ui_description =
62 " <menubar name='MainMenu'>"
63 " <menu action='FileMenu'>"
64 " <menuitem action='Mount'/>"
66 " <menuitem action='Reset'/>"
67 " <menuitem action='Pause'/>"
68 " <menuitem action='Run'/>"
70 " <menuitem action='LoadState'/>"
71 " <menuitem action='SaveState'/>"
73 " <menuitem action='Exit'/>"
75 " <menu action='SettingsMenu'>"
76 " <menuitem action='AudioSettings'/>"
77 " <menuitem action='ControllerSettings'/>"
78 " <menuitem action='NetworkSettings'/>"
79 " <menuitem action='VideoSettings'/>"
81 " <menuitem action='FullScreen'/>"
83 " <menu action='HelpMenu'>"
84 " <menuitem action='About'/>"
87 " <toolbar name='MainToolbar'>"
88 " <toolitem action='Mount'/>"
89 " <toolitem action='Reset'/>"
90 " <toolitem action='Pause'/>"
91 " <toolitem action='Run'/>"
93 " <toolitem action='LoadState'/>"
94 " <toolitem action='SaveState'/>"
99 struct main_window_info {
104 GtkWidget *statusbar;
105 GtkActionGroup *actions;
108 main_window_t main_window_new( const gchar *title )
111 GtkUIManager *ui_manager;
112 GtkAccelGroup *accel_group;
114 GError *error = NULL;
115 main_window_t win = g_malloc0( sizeof(struct main_window_info) );
117 win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
118 gtk_window_set_title( GTK_WINDOW(win->window), title );
120 win->actions = gtk_action_group_new("MenuActions");
121 gtk_action_group_add_actions( win->actions, ui_actions, G_N_ELEMENTS(ui_actions), win->window );
122 gtk_action_group_add_toggle_actions( win->actions, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), win->window );
123 DISABLE_ACTION(win, "AudioSettings");
124 DISABLE_ACTION(win, "NetworkSettings");
125 DISABLE_ACTION(win, "VideoSettings");
127 ui_manager = gtk_ui_manager_new();
128 gtk_ui_manager_set_add_tearoffs(ui_manager, TRUE);
129 gtk_ui_manager_insert_action_group( ui_manager, win->actions, 0 );
131 if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, &error)) {
132 g_message ("building menus failed: %s", error->message);
133 g_error_free (error);
137 accel_group = gtk_ui_manager_get_accel_group (ui_manager);
138 gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
140 win->menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
141 win->toolbar = gtk_ui_manager_get_widget(ui_manager, "/MainToolbar");
143 gtk_toolbar_set_style( GTK_TOOLBAR(win->toolbar), GTK_TOOLBAR_ICONS );
145 win->video = gtk_drawing_area_new();
146 GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
147 gtk_widget_set_size_request( win->video, 640, 480 );
148 frame = gtk_frame_new(NULL);
149 gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
150 gtk_container_add( GTK_CONTAINER(frame), win->video );
152 win->statusbar = gtk_statusbar_new();
154 vbox = gtk_vbox_new(FALSE, 0);
155 gtk_container_add( GTK_CONTAINER(win->window), vbox );
156 gtk_box_pack_start( GTK_BOX(vbox), win->menubar, FALSE, FALSE, 0 );
157 gtk_box_pack_start( GTK_BOX(vbox), win->toolbar, FALSE, FALSE, 0 );
158 gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
159 gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
160 gtk_widget_show_all( win->window );
161 gtk_widget_grab_focus( win->video );
163 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
167 void main_window_set_running( main_window_t win, gboolean running )
169 SET_ACTION_ENABLED( win, "Pause", running );
170 SET_ACTION_ENABLED( win, "Run", !running );
171 gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
172 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
175 void main_window_set_framerate( main_window_t win, float rate )
181 void main_window_set_speed( main_window_t win, double speed )
185 snprintf( buf, 32, "Running (%2.4f%)", speed );
186 gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
187 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
192 GtkWidget *main_window_get_renderarea( main_window_t win )
.