Search
lxdream.org :: lxdream/src/gui/gtkui.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkui.c
changeset 455:3080881d00d4
prev450:207461e79f21
next457:af605fd32c0b
author nkeynes
date Sun Oct 21 05:21:35 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change More GUI WIP
file annotate diff log raw
1.1 --- a/src/gui/gtkui.c Wed Oct 17 11:26:45 2007 +0000
1.2 +++ b/src/gui/gtkui.c Sun Oct 21 05:21:35 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gtkui.c,v 1.4 2007-10-17 11:26:45 nkeynes Exp $
1.6 + * $Id: gtkui.c,v 1.5 2007-10-21 05:21:35 nkeynes Exp $
1.7 *
1.8 * Core GTK-based user interface
1.9 *
1.10 @@ -44,11 +44,144 @@
1.11 static mmio_window_t mmio_win = NULL;
1.12
1.13 /**
1.14 + * UIManager and action helpers
1.15 + */
1.16 +static GtkUIManager *global_ui_manager;
1.17 +static GtkAccelGroup *global_accel_group;
1.18 +static GtkActionGroup *global_action_group;
1.19 +
1.20 +/**
1.21 * Count of running nanoseconds - used to cut back on the GUI runtime
1.22 */
1.23 static uint32_t gtk_gui_nanos = 0;
1.24 static struct timeval gtk_gui_lasttv;
1.25
1.26 +
1.27 +#define ENABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,TRUE)
1.28 +#define DISABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,FALSE)
1.29 +
1.30 +// UI Actions
1.31 +static const GtkActionEntry ui_actions[] = {
1.32 + { "FileMenu", NULL, "_File" },
1.33 + { "SettingsMenu", NULL, "_Settings" },
1.34 + { "HelpMenu", NULL, "_Help" },
1.35 + { "Mount", GTK_STOCK_CDROM, "_Mount...", "<control>O", "Mount a cdrom disc", G_CALLBACK(mount_action_callback) },
1.36 + { "Reset", GTK_STOCK_REFRESH, "_Reset", "<control>R", "Reset dreamcast", G_CALLBACK(reset_action_callback) },
1.37 + { "Pause", GTK_STOCK_MEDIA_PAUSE, "_Pause", NULL, "Pause dreamcast", G_CALLBACK(pause_action_callback) },
1.38 + { "Run", GTK_STOCK_MEDIA_PLAY, "Resume", NULL, "Resume", G_CALLBACK(resume_action_callback) },
1.39 + { "LoadState", GTK_STOCK_REVERT_TO_SAVED, "_Load state...", "F4", "Load an lxdream save state", G_CALLBACK(load_state_action_callback) },
1.40 + { "SaveState", GTK_STOCK_SAVE_AS, "_Save state...", "F3", "Create an lxdream save state", G_CALLBACK(save_state_action_callback) },
1.41 + { "Exit", GTK_STOCK_QUIT, "E_xit", NULL, "Exit lxdream", G_CALLBACK(exit_action_callback) },
1.42 + { "PathSettings", NULL, "_Paths...", NULL, "Configure files and paths", G_CALLBACK(path_settings_callback) },
1.43 + { "AudioSettings", NULL, "_Audio...", NULL, "Configure audio output", G_CALLBACK(audio_settings_callback) },
1.44 + { "ControllerSettings", NULL, "_Controllers...", NULL, "Configure controllers", G_CALLBACK(maple_settings_callback) },
1.45 + { "NetworkSettings", NULL, "_Network...", NULL, "Configure network settings", G_CALLBACK(network_settings_callback) },
1.46 + { "VideoSettings", NULL, "_Video...", NULL, "Configure video output", G_CALLBACK(video_settings_callback) },
1.47 + { "About", GTK_STOCK_ABOUT, "_About...", NULL, "About lxdream", G_CALLBACK(about_action_callback) },
1.48 + { "DebugMenu", NULL, "_Debug" },
1.49 + { "Debugger", NULL, "_Debugger", NULL, "Open debugger window", G_CALLBACK(debugger_action_callback) },
1.50 + { "DebugMem", NULL, "View _Memory", NULL, "View memory dump", G_CALLBACK(debug_memory_action_callback) },
1.51 + { "DebugMmio", NULL, "View IO _Registers", NULL, "View MMIO Registers", G_CALLBACK(debug_mmio_action_callback) },
1.52 + { "SaveScene", NULL, "_Save Scene", NULL, "Save next rendered scene", G_CALLBACK(save_scene_action_callback) },
1.53 + { "SingleStep", GTK_STOCK_REDO, "_Single Step", NULL, "Single step", G_CALLBACK(debug_step_action_callback) },
1.54 + { "RunTo", GTK_STOCK_GOTO_LAST, "Run _To", NULL, "Run to", G_CALLBACK( debug_runto_action_callback) },
1.55 + { "SetBreakpoint", GTK_STOCK_CLOSE, "_Breakpoint", NULL, "Toggle breakpoint", G_CALLBACK( debug_breakpoint_action_callback) }
1.56 +};
1.57 +static const GtkToggleActionEntry ui_toggle_actions[] = {
1.58 + { "FullScreen", NULL, "_Full Screen", "<alt>Return", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
1.59 +};
1.60 +
1.61 +// Menus and toolbars
1.62 +static const char *ui_description =
1.63 + "<ui>"
1.64 + " <menubar name='MainMenu'>"
1.65 + " <menu action='FileMenu'>"
1.66 + " <menuitem action='Mount'/>"
1.67 + " <separator/>"
1.68 + " <menuitem action='Reset'/>"
1.69 + " <menuitem action='Pause'/>"
1.70 + " <menuitem action='Run'/>"
1.71 + " <menuitem action='Debugger'/>"
1.72 + " <separator/>"
1.73 + " <menuitem action='LoadState'/>"
1.74 + " <menuitem action='SaveState'/>"
1.75 + " <separator/>"
1.76 + " <menuitem action='Exit'/>"
1.77 + " </menu>"
1.78 + " <menu action='SettingsMenu'>"
1.79 + " <menuitem action='PathSettings'/>"
1.80 + " <menuitem action='AudioSettings'/>"
1.81 + " <menuitem action='ControllerSettings'/>"
1.82 + " <menuitem action='NetworkSettings'/>"
1.83 + " <menuitem action='VideoSettings'/>"
1.84 + " <separator/>"
1.85 + " <menuitem action='FullScreen'/>"
1.86 + " </menu>"
1.87 + " <menu action='HelpMenu'>"
1.88 + " <menuitem action='About'/>"
1.89 + " </menu>"
1.90 + " </menubar>"
1.91 + " <toolbar name='MainToolbar'>"
1.92 + " <toolitem action='Mount'/>"
1.93 + " <toolitem action='Reset'/>"
1.94 + " <toolitem action='Pause'/>"
1.95 + " <toolitem action='Run'/>"
1.96 + " <separator/>"
1.97 + " <toolitem action='LoadState'/>"
1.98 + " <toolitem action='SaveState'/>"
1.99 + " </toolbar>"
1.100 + " <menubar name='DebugMenu'>"
1.101 + " <menu action='FileMenu'>"
1.102 + " <menuitem action='Mount'/>"
1.103 + " <separator/>"
1.104 + " <menuitem action='Reset'/>"
1.105 + " <separator/>"
1.106 + " <menuitem action='LoadState'/>"
1.107 + " <menuitem action='SaveState'/>"
1.108 + " <separator/>"
1.109 + " <menuitem action='Exit'/>"
1.110 + " </menu>"
1.111 + " <menu action='DebugMenu'>"
1.112 + " <menuitem action='DebugMem'/>"
1.113 + " <menuitem action='DebugMmio'/>"
1.114 + " <menuitem action='SaveScene'/>"
1.115 + " <separator/>"
1.116 + " <menuitem action='SetBreakpoint'/>"
1.117 + " <menuitem action='Pause'/>"
1.118 + " <menuitem action='SingleStep'/>"
1.119 + " <menuitem action='RunTo'/>"
1.120 + " <menuitem action='Run'/>"
1.121 + " </menu>"
1.122 + " <menu action='SettingsMenu'>"
1.123 + " <menuitem action='PathSettings'/>"
1.124 + " <menuitem action='AudioSettings'/>"
1.125 + " <menuitem action='ControllerSettings'/>"
1.126 + " <menuitem action='NetworkSettings'/>"
1.127 + " <menuitem action='VideoSettings'/>"
1.128 + " <separator/>"
1.129 + " <menuitem action='FullScreen'/>"
1.130 + " </menu>"
1.131 + " <menu action='HelpMenu'>"
1.132 + " <menuitem action='About'/>"
1.133 + " </menu>"
1.134 + " </menubar>"
1.135 + " <toolbar name='DebugToolbar'>"
1.136 + " <toolitem action='Mount'/>"
1.137 + " <toolitem action='Reset'/>"
1.138 + " <toolitem action='Pause'/>"
1.139 + " <separator/>"
1.140 + " <toolitem action='SingleStep'/>"
1.141 + " <toolitem action='RunTo'/>"
1.142 + " <toolitem action='Run'/>"
1.143 + " <toolitem action='SetBreakpoint'/>"
1.144 + " <separator/>"
1.145 + " <toolitem action='LoadState'/>"
1.146 + " <toolitem action='SaveState'/>"
1.147 + " </toolbar>"
1.148 + "</ui>";
1.149 +
1.150 +
1.151 +
1.152 gboolean gui_parse_cmdline( int *argc, char **argv[] )
1.153 {
1.154 return gtk_init_check( argc, argv );
1.155 @@ -56,12 +189,34 @@
1.156
1.157 gboolean gui_init( gboolean withDebug )
1.158 {
1.159 + GError *error = NULL;
1.160 dreamcast_register_module( &gtk_gui_module );
1.161 gtk_gui_alloc_resources();
1.162 +
1.163 + global_action_group = gtk_action_group_new("MenuActions");
1.164 + gtk_action_group_add_actions( global_action_group, ui_actions, G_N_ELEMENTS(ui_actions), NULL );
1.165 + gtk_action_group_add_toggle_actions( global_action_group, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), NULL );
1.166 + gtk_gui_enable_action("AudioSettings", FALSE);
1.167 + gtk_gui_enable_action("NetworkSettings", FALSE);
1.168 + gtk_gui_enable_action("VideoSettings", FALSE);
1.169 + global_ui_manager = gtk_ui_manager_new();
1.170 + gtk_ui_manager_set_add_tearoffs(global_ui_manager, TRUE);
1.171 + gtk_ui_manager_insert_action_group( global_ui_manager, global_action_group, 0 );
1.172 +
1.173 + if (!gtk_ui_manager_add_ui_from_string (global_ui_manager, ui_description, -1, &error)) {
1.174 + g_message ("building menus failed: %s", error->message);
1.175 + g_error_free (error);
1.176 + exit(1);
1.177 + }
1.178 + GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (global_ui_manager);
1.179 + GtkWidget *menubar = gtk_ui_manager_get_widget(global_ui_manager, "/MainMenu");
1.180 + GtkWidget *toolbar = gtk_ui_manager_get_widget(global_ui_manager, "/MainToolbar");
1.181 + main_win = main_window_new( APP_NAME " " APP_VERSION, menubar, toolbar, accel_group );
1.182 +
1.183 if( withDebug ) {
1.184 - debug_win = debug_window_new();
1.185 + gtk_gui_show_debugger();
1.186 }
1.187 - main_win = main_window_new( APP_NAME " " APP_VERSION );
1.188 +
1.189 return TRUE;
1.190 }
1.191
1.192 @@ -99,9 +254,37 @@
1.193 if( debug_win ) {
1.194 debug_window_show(debug_win, TRUE);
1.195 } else {
1.196 - debug_win = debug_window_new();
1.197 + GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group (global_ui_manager);
1.198 + GtkWidget *menubar = gtk_ui_manager_get_widget(global_ui_manager, "/DebugMenu");
1.199 + GtkWidget *toolbar = gtk_ui_manager_get_widget(global_ui_manager, "/DebugToolbar");
1.200 + debug_win = debug_window_new( APP_NAME " " APP_VERSION " :: Debugger", menubar, toolbar, accel_group );
1.201 }
1.202 -}
1.203 +}
1.204 +
1.205 +void gtk_gui_show_mmio()
1.206 +{
1.207 + if( mmio_win ) {
1.208 + mmio_window_show(mmio_win, TRUE);
1.209 + } else {
1.210 + mmio_win = mmio_window_new( APP_NAME " " APP_VERSION " :: MMIO Registers" );
1.211 + }
1.212 +}
1.213 +
1.214 +
1.215 +main_window_t gtk_gui_get_main()
1.216 +{
1.217 + return main_win;
1.218 +}
1.219 +
1.220 +debug_window_t gtk_gui_get_debugger()
1.221 +{
1.222 + return debug_win;
1.223 +}
1.224 +
1.225 +mmio_window_t gtk_gui_get_mmio()
1.226 +{
1.227 + return mmio_win;
1.228 +}
1.229
1.230 GtkWidget *gtk_gui_get_renderarea()
1.231 {
1.232 @@ -141,7 +324,7 @@
1.233 if( mmio_win ) {
1.234 mmio_win_update(mmio_win);
1.235 }
1.236 - dump_win_update_all();
1.237 + dump_window_update_all();
1.238 }
1.239
1.240 /**
1.241 @@ -211,7 +394,7 @@
1.242 gui_fixed_font = pango_font_description_from_string("Courier 10");
1.243 }
1.244
1.245 -gint gtk_gui_run_property_dialog( const gchar *title, GtkWidget *panel )
1.246 +gint gtk_gui_run_property_dialog( const gchar *title, GtkWidget *panel, gtk_dialog_done_fn fn )
1.247 {
1.248 GtkWidget *dialog =
1.249 gtk_dialog_new_with_buttons(title, main_window_get_frame(main_win),
1.250 @@ -223,6 +406,14 @@
1.251 gtk_widget_show_all(panel);
1.252 gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel );
1.253 result = gtk_dialog_run( GTK_DIALOG(dialog) );
1.254 + if( fn != NULL ) {
1.255 + fn(panel, result == GTK_RESPONSE_ACCEPT);
1.256 + }
1.257 gtk_widget_destroy( dialog );
1.258 return result;
1.259 }
1.260 +
1.261 +void gtk_gui_enable_action( const gchar *action, gboolean enable )
1.262 +{
1.263 + gtk_action_set_sensitive( gtk_action_group_get_action( global_action_group, action), enable);
1.264 +}
.