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 Fri Nov 02 08:22:33 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Implement (fairly naive) fullscreen mode
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@486
     2
 * $Id: main_win.c,v 1.9 2007-11-02 08:22:33 nkeynes Exp $
nkeynes@435
     3
 *
nkeynes@435
     4
 * Define the main (emu) GTK window, along with its menubars,
nkeynes@435
     5
 * toolbars, etc.
nkeynes@435
     6
 *
nkeynes@435
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     8
 *
nkeynes@435
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    12
 * (at your option) any later version.
nkeynes@435
    13
 *
nkeynes@435
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    17
 * GNU General Public License for more details.
nkeynes@435
    18
 */
nkeynes@435
    19
nkeynes@435
    20
#include <assert.h>
nkeynes@435
    21
#include <sys/types.h>
nkeynes@435
    22
#include <sys/stat.h>
nkeynes@435
    23
#include <unistd.h>
nkeynes@435
    24
#include <string.h>
nkeynes@435
    25
#include <stdio.h>
nkeynes@435
    26
#include <stdlib.h>
nkeynes@435
    27
nkeynes@435
    28
#include <gtk/gtk.h>
nkeynes@435
    29
nkeynes@435
    30
#include "dream.h"
nkeynes@435
    31
#include "gui/gtkui.h"
nkeynes@435
    32
nkeynes@435
    33
nkeynes@435
    34
struct main_window_info {
nkeynes@435
    35
    GtkWidget *window;
nkeynes@435
    36
    GtkWidget *video;
nkeynes@486
    37
    GtkWidget *menubar;
nkeynes@486
    38
    GtkWidget *toolbar;
nkeynes@435
    39
    GtkWidget *statusbar;
nkeynes@435
    40
    GtkActionGroup *actions;
nkeynes@435
    41
};
nkeynes@435
    42
nkeynes@486
    43
static gboolean on_main_window_deleted( GtkWidget *widget, GdkEvent event, gpointer user_data )
nkeynes@457
    44
{
nkeynes@457
    45
    exit(0);
nkeynes@457
    46
}
nkeynes@457
    47
nkeynes@486
    48
static void on_main_window_state_changed( GtkWidget *widget, GdkEventWindowState *state, 
nkeynes@486
    49
					  gpointer userdata )
nkeynes@486
    50
{
nkeynes@486
    51
    if( state->changed_mask & GDK_WINDOW_STATE_FULLSCREEN ) {
nkeynes@486
    52
	gboolean fs = (state->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
nkeynes@486
    53
    }
nkeynes@486
    54
    return FALSE;
nkeynes@486
    55
}
nkeynes@486
    56
nkeynes@455
    57
main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
nkeynes@455
    58
			       GtkAccelGroup *accel_group )
nkeynes@435
    59
{
nkeynes@435
    60
    GtkWidget *vbox;
nkeynes@437
    61
    GtkWidget *frame;
nkeynes@435
    62
    main_window_t win = g_malloc0( sizeof(struct main_window_info) );
nkeynes@435
    63
nkeynes@435
    64
    win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
nkeynes@486
    65
    win->menubar = menubar;
nkeynes@486
    66
    win->toolbar = toolbar;
nkeynes@435
    67
    gtk_window_set_title( GTK_WINDOW(win->window), title );
nkeynes@435
    68
    gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
nkeynes@435
    69
nkeynes@455
    70
    gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
nkeynes@435
    71
nkeynes@435
    72
    win->video = gtk_drawing_area_new();
nkeynes@435
    73
    GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
nkeynes@435
    74
    gtk_widget_set_size_request( win->video, 640, 480 ); 
nkeynes@437
    75
    frame = gtk_frame_new(NULL);
nkeynes@437
    76
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@437
    77
    gtk_container_add( GTK_CONTAINER(frame), win->video );
nkeynes@437
    78
nkeynes@435
    79
    win->statusbar = gtk_statusbar_new();
nkeynes@435
    80
nkeynes@435
    81
    vbox = gtk_vbox_new(FALSE, 0);
nkeynes@435
    82
    gtk_container_add( GTK_CONTAINER(win->window), vbox );
nkeynes@455
    83
    gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
nkeynes@455
    84
    gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
nkeynes@437
    85
    gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
nkeynes@435
    86
    gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
nkeynes@435
    87
    gtk_widget_show_all( win->window );
nkeynes@435
    88
    gtk_widget_grab_focus( win->video );
nkeynes@435
    89
    
nkeynes@437
    90
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
nkeynes@457
    91
    g_signal_connect( win->window, "delete_event", 
nkeynes@457
    92
		      G_CALLBACK(on_main_window_deleted), win );
nkeynes@486
    93
    g_signal_connect( win->window, "window-state-event",
nkeynes@486
    94
		      G_CALLBACK(on_main_window_state_changed), win );
nkeynes@435
    95
    return win;
nkeynes@435
    96
}
nkeynes@435
    97
nkeynes@435
    98
void main_window_set_running( main_window_t win, gboolean running )
nkeynes@435
    99
{
nkeynes@455
   100
    gtk_gui_enable_action( "Pause", running );
nkeynes@455
   101
    gtk_gui_enable_action( "Run", !running );
nkeynes@437
   102
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   103
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
nkeynes@435
   104
}
nkeynes@435
   105
nkeynes@435
   106
void main_window_set_framerate( main_window_t win, float rate )
nkeynes@435
   107
{
nkeynes@435
   108
nkeynes@435
   109
nkeynes@435
   110
}
nkeynes@435
   111
nkeynes@437
   112
void main_window_set_speed( main_window_t win, double speed )
nkeynes@437
   113
{
nkeynes@437
   114
    char buf[32];
nkeynes@437
   115
nkeynes@480
   116
    snprintf( buf, 32, "Running (%2.4f%%)", speed );
nkeynes@437
   117
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   118
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
nkeynes@437
   119
    
nkeynes@437
   120
nkeynes@437
   121
}
nkeynes@437
   122
nkeynes@435
   123
GtkWidget *main_window_get_renderarea( main_window_t win )
nkeynes@435
   124
{
nkeynes@435
   125
    return win->video;
nkeynes@435
   126
}
nkeynes@447
   127
nkeynes@447
   128
GtkWindow *main_window_get_frame( main_window_t win )
nkeynes@447
   129
{
nkeynes@447
   130
    return GTK_WINDOW(win->window);
nkeynes@447
   131
}
nkeynes@486
   132
nkeynes@486
   133
void main_window_set_fullscreen( main_window_t win, gboolean fullscreen )
nkeynes@486
   134
{
nkeynes@486
   135
    GtkWidget *frame = gtk_widget_get_parent(win->video);
nkeynes@486
   136
    if( frame->style == NULL ) {
nkeynes@486
   137
	gtk_widget_set_style( frame, gtk_style_new() );
nkeynes@486
   138
    }
nkeynes@486
   139
    if( fullscreen ) {
nkeynes@486
   140
	gtk_window_fullscreen( GTK_WINDOW(win->window) );
nkeynes@486
   141
	gtk_widget_hide( win->menubar );
nkeynes@486
   142
	gtk_widget_hide( win->toolbar );
nkeynes@486
   143
	gtk_widget_hide( win->statusbar );
nkeynes@486
   144
	
nkeynes@486
   145
	frame->style->xthickness = 0;
nkeynes@486
   146
	frame->style->ythickness = 0;
nkeynes@486
   147
    } else {
nkeynes@486
   148
	gtk_window_unfullscreen( GTK_WINDOW(win->window) );
nkeynes@486
   149
	frame->style->xthickness = 2;
nkeynes@486
   150
	frame->style->ythickness = 2;
nkeynes@486
   151
	gtk_widget_show( win->menubar );
nkeynes@486
   152
	gtk_widget_show( win->toolbar );
nkeynes@486
   153
	gtk_widget_show( win->statusbar );
nkeynes@486
   154
    }
nkeynes@486
   155
}
.