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 486:9af294489aad
prev480:d28c2992f5ee
next497:cd6e10c2e96b
author nkeynes
date Tue Nov 06 08:35:16 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Issue #37: Add nulldc GDI format
view annotate diff log raw
     1 /**
     2  * $Id: main_win.c,v 1.9 2007-11-02 08:22:33 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"
    34 struct main_window_info {
    35     GtkWidget *window;
    36     GtkWidget *video;
    37     GtkWidget *menubar;
    38     GtkWidget *toolbar;
    39     GtkWidget *statusbar;
    40     GtkActionGroup *actions;
    41 };
    43 static gboolean on_main_window_deleted( GtkWidget *widget, GdkEvent event, gpointer user_data )
    44 {
    45     exit(0);
    46 }
    48 static void on_main_window_state_changed( GtkWidget *widget, GdkEventWindowState *state, 
    49 					  gpointer userdata )
    50 {
    51     if( state->changed_mask & GDK_WINDOW_STATE_FULLSCREEN ) {
    52 	gboolean fs = (state->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
    53     }
    54     return FALSE;
    55 }
    57 main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
    58 			       GtkAccelGroup *accel_group )
    59 {
    60     GtkWidget *vbox;
    61     GtkWidget *frame;
    62     main_window_t win = g_malloc0( sizeof(struct main_window_info) );
    64     win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    65     win->menubar = menubar;
    66     win->toolbar = toolbar;
    67     gtk_window_set_title( GTK_WINDOW(win->window), title );
    68     gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
    70     gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
    72     win->video = gtk_drawing_area_new();
    73     GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
    74     gtk_widget_set_size_request( win->video, 640, 480 ); 
    75     frame = gtk_frame_new(NULL);
    76     gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
    77     gtk_container_add( GTK_CONTAINER(frame), win->video );
    79     win->statusbar = gtk_statusbar_new();
    81     vbox = gtk_vbox_new(FALSE, 0);
    82     gtk_container_add( GTK_CONTAINER(win->window), vbox );
    83     gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
    84     gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
    85     gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
    86     gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
    87     gtk_widget_show_all( win->window );
    88     gtk_widget_grab_focus( win->video );
    90     gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
    91     g_signal_connect( win->window, "delete_event", 
    92 		      G_CALLBACK(on_main_window_deleted), win );
    93     g_signal_connect( win->window, "window-state-event",
    94 		      G_CALLBACK(on_main_window_state_changed), win );
    95     return win;
    96 }
    98 void main_window_set_running( main_window_t win, gboolean running )
    99 {
   100     gtk_gui_enable_action( "Pause", running );
   101     gtk_gui_enable_action( "Run", !running );
   102     gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
   103     gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
   104 }
   106 void main_window_set_framerate( main_window_t win, float rate )
   107 {
   110 }
   112 void main_window_set_speed( main_window_t win, double speed )
   113 {
   114     char buf[32];
   116     snprintf( buf, 32, "Running (%2.4f%%)", speed );
   117     gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
   118     gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
   121 }
   123 GtkWidget *main_window_get_renderarea( main_window_t win )
   124 {
   125     return win->video;
   126 }
   128 GtkWindow *main_window_get_frame( main_window_t win )
   129 {
   130     return GTK_WINDOW(win->window);
   131 }
   133 void main_window_set_fullscreen( main_window_t win, gboolean fullscreen )
   134 {
   135     GtkWidget *frame = gtk_widget_get_parent(win->video);
   136     if( frame->style == NULL ) {
   137 	gtk_widget_set_style( frame, gtk_style_new() );
   138     }
   139     if( fullscreen ) {
   140 	gtk_window_fullscreen( GTK_WINDOW(win->window) );
   141 	gtk_widget_hide( win->menubar );
   142 	gtk_widget_hide( win->toolbar );
   143 	gtk_widget_hide( win->statusbar );
   145 	frame->style->xthickness = 0;
   146 	frame->style->ythickness = 0;
   147     } else {
   148 	gtk_window_unfullscreen( GTK_WINDOW(win->window) );
   149 	frame->style->xthickness = 2;
   150 	frame->style->ythickness = 2;
   151 	gtk_widget_show( win->menubar );
   152 	gtk_widget_show( win->toolbar );
   153 	gtk_widget_show( win->statusbar );
   154     }
   155 }
.