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 447:3e095bfcb476
prev440:d9bd9b7a283f
next450:207461e79f21
author nkeynes
date Tue Oct 16 12:36:29 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Add gui error reporting
Add initial controller settings dialog
view annotate diff log raw
     1 /**
     2  * $Id: main_win.c,v 1.4 2007-10-16 12:36:29 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     { "PathSettings", NULL, "_Paths...", NULL, "Configure files and paths", G_CALLBACK(path_settings_callback) }, 
    50     { "AudioSettings", NULL, "_Audio...", NULL, "Configure audio output", G_CALLBACK(audio_settings_callback) },
    51     { "ControllerSettings", NULL, "_Controllers...", NULL, "Configure controllers", G_CALLBACK(controller_settings_callback) },
    52     { "NetworkSettings", NULL, "_Network...", NULL, "Configure network settings", G_CALLBACK(network_settings_callback) },
    53     { "VideoSettings", NULL, "_Video...", NULL, "Configure video output", G_CALLBACK(video_settings_callback) },
    54     { "About", GTK_STOCK_ABOUT, "_About...", NULL, "About lxdream", G_CALLBACK(about_action_callback) }
    55 };
    56 static const GtkToggleActionEntry ui_toggle_actions[] = {
    57     { "FullScreen", NULL, "_Full Screen", "F9", "Toggle full screen video", G_CALLBACK(fullscreen_toggle_callback), 0 },
    58 };
    61 static const char *ui_description =
    62     "<ui>"
    63     " <menubar name='MainMenu'>"
    64     "  <menu action='FileMenu'>"
    65     "   <menuitem action='Mount'/>"
    66     "   <separator/>"
    67     "   <menuitem action='Reset'/>"
    68     "   <menuitem action='Pause'/>"
    69     "   <menuitem action='Run'/>"
    70     "   <separator/>"
    71     "   <menuitem action='LoadState'/>"
    72     "   <menuitem action='SaveState'/>"
    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, "AudioSettings");
   125     DISABLE_ACTION(win, "NetworkSettings");
   126     DISABLE_ACTION(win, "VideoSettings");
   128     ui_manager = gtk_ui_manager_new();
   129     gtk_ui_manager_set_add_tearoffs(ui_manager, TRUE);
   130     gtk_ui_manager_insert_action_group( ui_manager, win->actions, 0 );
   132     if (!gtk_ui_manager_add_ui_from_string (ui_manager, ui_description, -1, &error)) {
   133 	g_message ("building menus failed: %s", error->message);
   134 	g_error_free (error);
   135 	exit(1);
   136     }
   138     accel_group = gtk_ui_manager_get_accel_group (ui_manager);
   139     gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
   141     win->menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
   142     win->toolbar = gtk_ui_manager_get_widget(ui_manager, "/MainToolbar");
   144     gtk_toolbar_set_style( GTK_TOOLBAR(win->toolbar), GTK_TOOLBAR_ICONS );
   146     win->video = gtk_drawing_area_new();
   147     GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
   148     gtk_widget_set_size_request( win->video, 640, 480 ); 
   149     frame = gtk_frame_new(NULL);
   150     gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
   151     gtk_container_add( GTK_CONTAINER(frame), win->video );
   153     win->statusbar = gtk_statusbar_new();
   155     vbox = gtk_vbox_new(FALSE, 0);
   156     gtk_container_add( GTK_CONTAINER(win->window), vbox );
   157     gtk_box_pack_start( GTK_BOX(vbox), win->menubar, FALSE, FALSE, 0 );
   158     gtk_box_pack_start( GTK_BOX(vbox), win->toolbar, FALSE, FALSE, 0 );
   159     gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
   160     gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
   161     gtk_widget_show_all( win->window );
   162     gtk_widget_grab_focus( win->video );
   164     gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
   165     return win;
   166 }
   168 void main_window_set_running( main_window_t win, gboolean running )
   169 {
   170     SET_ACTION_ENABLED( win, "Pause", running );
   171     SET_ACTION_ENABLED( win, "Run", !running );
   172     gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
   173     gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
   174 }
   176 void main_window_set_framerate( main_window_t win, float rate )
   177 {
   180 }
   182 void main_window_set_speed( main_window_t win, double speed )
   183 {
   184     char buf[32];
   186     snprintf( buf, 32, "Running (%2.4f%)", speed );
   187     gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
   188     gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
   191 }
   193 GtkWidget *main_window_get_renderarea( main_window_t win )
   194 {
   195     return win->video;
   196 }
   198 GtkWindow *main_window_get_frame( main_window_t win )
   199 {
   200     return GTK_WINDOW(win->window);
   201 }
.