Search
lxdream.org :: lxdream/src/gui/main_win.c :: diff
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
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gui/main_win.c Wed Oct 10 11:02:04 2007 +0000
1.3 @@ -0,0 +1,173 @@
1.4 +/**
1.5 + * $Id: main_win.c,v 1.1 2007-10-10 11:02:04 nkeynes Exp $
1.6 + *
1.7 + * Define the main (emu) GTK window, along with its menubars,
1.8 + * toolbars, etc.
1.9 + *
1.10 + * Copyright (c) 2005 Nathan Keynes.
1.11 + *
1.12 + * This program is free software; you can redistribute it and/or modify
1.13 + * it under the terms of the GNU General Public License as published by
1.14 + * the Free Software Foundation; either version 2 of the License, or
1.15 + * (at your option) any later version.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful,
1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 + * GNU General Public License for more details.
1.21 + */
1.22 +
1.23 +#include <assert.h>
1.24 +#include <sys/types.h>
1.25 +#include <sys/stat.h>
1.26 +#include <unistd.h>
1.27 +#include <string.h>
1.28 +#include <stdio.h>
1.29 +#include <stdlib.h>
1.30 +
1.31 +#include <gtk/gtk.h>
1.32 +
1.33 +#include "dream.h"
1.34 +#include "gui/gtkui.h"
1.35 +
1.36 +#define SET_ACTION_ENABLED(win,name,b) gtk_action_set_sensitive( gtk_action_group_get_action( win->actions, name), b)
1.37 +#define ENABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,TRUE)
1.38 +#define DISABLE_ACTION(win,name) SET_ACTION_ENABLED(win,name,FALSE)
1.39 +
1.40 +static const GtkActionEntry ui_actions[] = {
1.41 + { "FileMenu", NULL, "_File" },
1.42 + { "SettingsMenu", NULL, "_Settings" },
1.43 + { "HelpMenu", NULL, "_Help" },
1.44 + { "Mount", GTK_STOCK_CDROM, "_Mount...", "<control>O", "Mount a cdrom disc", G_CALLBACK(mount_action_callback) },
1.45 + { "Reset", GTK_STOCK_REFRESH, "_Reset", "<control>R", "Reset dreamcast", G_CALLBACK(reset_action_callback) },
1.46 + { "Pause", GTK_STOCK_MEDIA_PAUSE, "_Pause", NULL, "Pause dreamcast", G_CALLBACK(pause_action_callback) },
1.47 + { "Run", GTK_STOCK_MEDIA_PLAY, "Resume", NULL, "Resume", G_CALLBACK(resume_action_callback) },
1.48 + { "LoadState", GTK_STOCK_REVERT_TO_SAVED, "_Load state...", "F4", "Load an lxdream save state", G_CALLBACK(load_state_action_callback) },
1.49 + { "SaveState", GTK_STOCK_SAVE_AS, "_Save state...", "F3", "Create an lxdream save state", G_CALLBACK(save_state_action_callback) },
1.50 + { "Exit", GTK_STOCK_QUIT, "E_xit", NULL, "Exit lxdream", G_CALLBACK(exit_action_callback) },
1.51 + { "AudioSettings", NULL, "_Audio...", NULL, "Configure audio output", G_CALLBACK(audio_settings_callback) },
1.52 + { "ControllerSettings", NULL, "_Controllers...", NULL, "Configure controllers", G_CALLBACK(controller_settings_callback) },
1.53 + { "NetworkSettings", NULL, "_Network...", NULL, "Configure network settings", G_CALLBACK(network_settings_callback) },
1.54 + { "VideoSettings", NULL, "_Video...", NULL, "Configure video output", G_CALLBACK(video_settings_callback) },
1.55 + { "About", GTK_STOCK_ABOUT, "_About...", NULL, "About lxdream", G_CALLBACK(about_action_callback) }
1.56 +};
1.57 +static const GtkToggleActionEntry ui_toggle_actions[] = {
1.58 + { "FullScreen", NULL, "_Full Screen", "F9", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
1.59 +};
1.60 +
1.61 +
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 + " <separator/>"
1.72 + " <menuitem action='LoadState'/>"
1.73 + " <menuitem action='SaveState'/>"
1.74 + " <separator/>"
1.75 + " <menuitem action='Exit'/>"
1.76 + " </menu>"
1.77 + " <menu action='SettingsMenu'>"
1.78 + " <menuitem action='AudioSettings'/>"
1.79 + " <menuitem action='ControllerSettings'/>"
1.80 + " <menuitem action='NetworkSettings'/>"
1.81 + " <menuitem action='VideoSettings'/>"
1.82 + " <separator/>"
1.83 + " <menuitem action='FullScreen'/>"
1.84 + " </menu>"
1.85 + " <menu action='HelpMenu'>"
1.86 + " <menuitem action='About'/>"
1.87 + " </menu>"
1.88 + " </menubar>"
1.89 + " <toolbar name='MainToolbar'>"
1.90 + " <toolitem action='Mount'/>"
1.91 + " <toolitem action='Reset'/>"
1.92 + " <toolitem action='Pause'/>"
1.93 + " <toolitem action='Run'/>"
1.94 + " <separator/>"
1.95 + " <toolitem action='LoadState'/>"
1.96 + " <toolitem action='SaveState'/>"
1.97 + " </toolbar>"
1.98 + "</ui>";
1.99 +
1.100 +
1.101 +struct main_window_info {
1.102 + GtkWidget *window;
1.103 + GtkWidget *menubar;
1.104 + GtkWidget *toolbar;
1.105 + GtkWidget *video;
1.106 + GtkWidget *statusbar;
1.107 + GtkActionGroup *actions;
1.108 +};
1.109 +
1.110 +main_window_t main_window_new( const gchar *title )
1.111 +{
1.112 + GtkWidget *vbox;
1.113 + GtkUIManager *ui_manager;
1.114 + GtkAccelGroup *accel_group;
1.115 + GError *error = NULL;
1.116 + main_window_t win = g_malloc0( sizeof(struct main_window_info) );
1.117 +
1.118 + win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1.119 + gtk_window_set_title( GTK_WINDOW(win->window), title );
1.120 +
1.121 + win->actions = gtk_action_group_new("MenuActions");
1.122 + gtk_action_group_add_actions( win->actions, ui_actions, G_N_ELEMENTS(ui_actions), win->window );
1.123 + gtk_action_group_add_toggle_actions( win->actions, ui_toggle_actions, G_N_ELEMENTS(ui_toggle_actions), win->window );
1.124 + DISABLE_ACTION(win, "NetworkSettings");
1.125 +
1.126 + ui_manager = gtk_ui_manager_new();
1.127 + gtk_ui_manager_set_add_tearoffs(ui_manager, TRUE);
1.128 + gtk_ui_manager_insert_action_group( ui_manager, win->actions, 0 );
1.129 +
1.130 + if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, &error)) {
1.131 + g_message ("building menus failed: %s", error->message);
1.132 + g_error_free (error);
1.133 + exit(1);
1.134 + }
1.135 +
1.136 + accel_group = gtk_ui_manager_get_accel_group (ui_manager);
1.137 + gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
1.138 +
1.139 + win->menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
1.140 + win->toolbar = gtk_ui_manager_get_widget(ui_manager, "/MainToolbar");
1.141 +
1.142 + gtk_toolbar_set_style( GTK_TOOLBAR(win->toolbar), GTK_TOOLBAR_ICONS );
1.143 +
1.144 + win->video = gtk_drawing_area_new();
1.145 + GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
1.146 + gtk_widget_set_size_request( win->video, 640, 480 );
1.147 + win->statusbar = gtk_statusbar_new();
1.148 +
1.149 + vbox = gtk_vbox_new(FALSE, 0);
1.150 + gtk_container_add( GTK_CONTAINER(win->window), vbox );
1.151 + gtk_box_pack_start( GTK_BOX(vbox), win->menubar, FALSE, FALSE, 0 );
1.152 + gtk_box_pack_start( GTK_BOX(vbox), win->toolbar, FALSE, FALSE, 0 );
1.153 + gtk_box_pack_start( GTK_BOX(vbox), win->video, TRUE, TRUE, 1 );
1.154 + gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
1.155 + gtk_widget_show_all( win->window );
1.156 + gtk_widget_grab_focus( win->video );
1.157 +
1.158 + return win;
1.159 +}
1.160 +
1.161 +void main_window_set_running( main_window_t win, gboolean running )
1.162 +{
1.163 + SET_ACTION_ENABLED( win, "Pause", running );
1.164 + SET_ACTION_ENABLED( win, "Run", !running );
1.165 +}
1.166 +
1.167 +void main_window_set_framerate( main_window_t win, float rate )
1.168 +{
1.169 +
1.170 +
1.171 +}
1.172 +
1.173 +GtkWidget *main_window_get_renderarea( main_window_t win )
1.174 +{
1.175 + return win->video;
1.176 +}
.