filename | src/gui/main_win.c |
changeset | 437:2c259474b474 |
prev | 435:7a5d71e8560b |
next | 440:d9bd9b7a283f |
author | nkeynes |
date | Thu Oct 11 08:22:03 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Add speed meter to main window Add sunken border around video area Add debugger menu item Move logging out to util.c |
view | annotate | diff | log | raw |
1 /**
2 * $Id: main_win.c,v 1.2 2007-10-11 08:22:03 nkeynes Exp $
3 *
4 * Define the main (emu) GTK window, along with its menubars,
5 * toolbars, etc.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
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.
13 *
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.
18 */
20 #include <assert.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include <stdlib.h>
28 #include <gtk/gtk.h>
30 #include "dream.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) }
54 };
55 static const GtkToggleActionEntry ui_toggle_actions[] = {
56 { "FullScreen", NULL, "_Full Screen", "F9", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
57 };
60 static const char *ui_description =
61 "<ui>"
62 " <menubar name='MainMenu'>"
63 " <menu action='FileMenu'>"
64 " <menuitem action='Mount'/>"
65 " <separator/>"
66 " <menuitem action='Reset'/>"
67 " <menuitem action='Pause'/>"
68 " <menuitem action='Run'/>"
69 " <separator/>"
70 " <menuitem action='LoadState'/>"
71 " <menuitem action='SaveState'/>"
72 " <menuitem action='Debugger'/>"
73 " <separator/>"
74 " <menuitem action='Exit'/>"
75 " </menu>"
76 " <menu action='SettingsMenu'>"
77 " <menuitem action='AudioSettings'/>"
78 " <menuitem action='ControllerSettings'/>"
79 " <menuitem action='NetworkSettings'/>"
80 " <menuitem action='VideoSettings'/>"
81 " <separator/>"
82 " <menuitem action='FullScreen'/>"
83 " </menu>"
84 " <menu action='HelpMenu'>"
85 " <menuitem action='About'/>"
86 " </menu>"
87 " </menubar>"
88 " <toolbar name='MainToolbar'>"
89 " <toolitem action='Mount'/>"
90 " <toolitem action='Reset'/>"
91 " <toolitem action='Pause'/>"
92 " <toolitem action='Run'/>"
93 " <separator/>"
94 " <toolitem action='LoadState'/>"
95 " <toolitem action='SaveState'/>"
96 " </toolbar>"
97 "</ui>";
100 struct main_window_info {
101 GtkWidget *window;
102 GtkWidget *menubar;
103 GtkWidget *toolbar;
104 GtkWidget *video;
105 GtkWidget *statusbar;
106 GtkActionGroup *actions;
107 };
109 main_window_t main_window_new( const gchar *title )
110 {
111 GtkWidget *vbox;
112 GtkUIManager *ui_manager;
113 GtkAccelGroup *accel_group;
114 GtkWidget *frame;
115 GError *error = NULL;
116 main_window_t win = g_malloc0( sizeof(struct main_window_info) );
118 win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
119 gtk_window_set_title( GTK_WINDOW(win->window), title );
121 win->actions = gtk_action_group_new("MenuActions");
122 gtk_action_group_add_actions( win->actions, ui_actions, G_N_ELEMENTS(ui_actions), win->window );
123 gtk_action_group_add_toggle_actions( win->actions, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), win->window );
124 DISABLE_ACTION(win, "NetworkSettings");
126 ui_manager = gtk_ui_manager_new();
127 gtk_ui_manager_set_add_tearoffs(ui_manager, TRUE);
128 gtk_ui_manager_insert_action_group( ui_manager, win->actions, 0 );
130 if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, &error)) {
131 g_message ("building menus failed: %s", error->message);
132 g_error_free (error);
133 exit(1);
134 }
136 accel_group = gtk_ui_manager_get_accel_group (ui_manager);
137 gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
139 win->menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
140 win->toolbar = gtk_ui_manager_get_widget(ui_manager, "/MainToolbar");
142 gtk_toolbar_set_style( GTK_TOOLBAR(win->toolbar), GTK_TOOLBAR_ICONS );
144 win->video = gtk_drawing_area_new();
145 GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
146 gtk_widget_set_size_request( win->video, 640, 480 );
147 frame = gtk_frame_new(NULL);
148 gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
149 gtk_container_add( GTK_CONTAINER(frame), win->video );
151 win->statusbar = gtk_statusbar_new();
153 vbox = gtk_vbox_new(FALSE, 0);
154 gtk_container_add( GTK_CONTAINER(win->window), vbox );
155 gtk_box_pack_start( GTK_BOX(vbox), win->menubar, FALSE, FALSE, 0 );
156 gtk_box_pack_start( GTK_BOX(vbox), win->toolbar, FALSE, FALSE, 0 );
157 gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
158 gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
159 gtk_widget_show_all( win->window );
160 gtk_widget_grab_focus( win->video );
162 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
163 return win;
164 }
166 void main_window_set_running( main_window_t win, gboolean running )
167 {
168 SET_ACTION_ENABLED( win, "Pause", running );
169 SET_ACTION_ENABLED( win, "Run", !running );
170 gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
171 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
172 }
174 void main_window_set_framerate( main_window_t win, float rate )
175 {
178 }
180 void main_window_set_speed( main_window_t win, double speed )
181 {
182 char buf[32];
184 snprintf( buf, 32, "Running (%2.4f%)", speed );
185 gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
186 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
189 }
191 GtkWidget *main_window_get_renderarea( main_window_t win )
192 {
193 return win->video;
194 }
.