Search
lxdream.org :: lxdream/src/gtkui/main_win.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/main_win.c
changeset 537:d924be49e192
prev497:cd6e10c2e96b
next543:361ec0a70cf2
author nkeynes
date Tue Nov 20 10:27:58 2007 +0000 (15 years ago)
permissions -rw-r--r--
last change Move gtk UI into gtkui subdir (prep for non-gtk builds), and protect with
an automake conditional
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gtkui/main_win.c Tue Nov 20 10:27:58 2007 +0000
1.3 @@ -0,0 +1,159 @@
1.4 +/**
1.5 + * $Id: main_win.c,v 1.10 2007-11-08 10:46:41 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 "gtkui/gtkui.h"
1.35 +
1.36 +
1.37 +struct main_window_info {
1.38 + GtkWidget *window;
1.39 + GtkWidget *video;
1.40 + GtkWidget *menubar;
1.41 + GtkWidget *toolbar;
1.42 + GtkWidget *statusbar;
1.43 + GtkActionGroup *actions;
1.44 +};
1.45 +
1.46 +static gboolean on_main_window_deleted( GtkWidget *widget, GdkEvent event, gpointer user_data )
1.47 +{
1.48 + exit(0);
1.49 +}
1.50 +
1.51 +static void on_main_window_state_changed( GtkWidget *widget, GdkEventWindowState *state,
1.52 + gpointer userdata )
1.53 +{
1.54 + main_window_t win = (main_window_t)userdata;
1.55 + if( state->changed_mask & GDK_WINDOW_STATE_FULLSCREEN ) {
1.56 + gboolean fs = (state->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
1.57 + GtkWidget *frame = gtk_widget_get_parent(win->video);
1.58 + if( frame->style == NULL ) {
1.59 + gtk_widget_set_style( frame, gtk_style_new() );
1.60 + }
1.61 + if( fs ) {
1.62 + gtk_widget_hide( win->menubar );
1.63 + gtk_widget_hide( win->toolbar );
1.64 + gtk_widget_hide( win->statusbar );
1.65 +
1.66 + frame->style->xthickness = 0;
1.67 + frame->style->ythickness = 0;
1.68 + } else {
1.69 + frame->style->xthickness = 2;
1.70 + frame->style->ythickness = 2;
1.71 + gtk_widget_show( win->menubar );
1.72 + gtk_widget_show( win->toolbar );
1.73 + gtk_widget_show( win->statusbar );
1.74 + }
1.75 + gtk_widget_queue_draw( win->window );
1.76 + }
1.77 +}
1.78 +
1.79 +main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
1.80 + GtkAccelGroup *accel_group )
1.81 +{
1.82 + GtkWidget *vbox;
1.83 + GtkWidget *frame;
1.84 + main_window_t win = g_malloc0( sizeof(struct main_window_info) );
1.85 +
1.86 + win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1.87 + win->menubar = menubar;
1.88 + win->toolbar = toolbar;
1.89 + gtk_window_set_title( GTK_WINDOW(win->window), title );
1.90 + gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
1.91 +
1.92 + gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
1.93 +
1.94 + win->video = gtk_drawing_area_new();
1.95 + GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
1.96 + gtk_widget_set_size_request( win->video, 640, 480 );
1.97 + frame = gtk_frame_new(NULL);
1.98 + gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
1.99 + gtk_container_add( GTK_CONTAINER(frame), win->video );
1.100 +
1.101 + win->statusbar = gtk_statusbar_new();
1.102 +
1.103 + vbox = gtk_vbox_new(FALSE, 0);
1.104 + gtk_container_add( GTK_CONTAINER(win->window), vbox );
1.105 + gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
1.106 + gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
1.107 + gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
1.108 + gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
1.109 + gtk_widget_show_all( win->window );
1.110 + gtk_widget_grab_focus( win->video );
1.111 +
1.112 + gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
1.113 + g_signal_connect( win->window, "delete_event",
1.114 + G_CALLBACK(on_main_window_deleted), win );
1.115 + g_signal_connect( win->window, "window-state-event",
1.116 + G_CALLBACK(on_main_window_state_changed), win );
1.117 + return win;
1.118 +}
1.119 +
1.120 +void main_window_set_running( main_window_t win, gboolean running )
1.121 +{
1.122 + gtk_gui_enable_action( "Pause", running );
1.123 + gtk_gui_enable_action( "Run", !running );
1.124 + gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
1.125 + gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
1.126 +}
1.127 +
1.128 +void main_window_set_framerate( main_window_t win, float rate )
1.129 +{
1.130 +
1.131 +
1.132 +}
1.133 +
1.134 +void main_window_set_speed( main_window_t win, double speed )
1.135 +{
1.136 + char buf[32];
1.137 +
1.138 + snprintf( buf, 32, "Running (%2.4f%%)", speed );
1.139 + gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
1.140 + gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
1.141 +
1.142 +
1.143 +}
1.144 +
1.145 +GtkWidget *main_window_get_renderarea( main_window_t win )
1.146 +{
1.147 + return win->video;
1.148 +}
1.149 +
1.150 +GtkWindow *main_window_get_frame( main_window_t win )
1.151 +{
1.152 + return GTK_WINDOW(win->window);
1.153 +}
1.154 +
1.155 +void main_window_set_fullscreen( main_window_t win, gboolean fullscreen )
1.156 +{
1.157 + if( fullscreen ) {
1.158 + gtk_window_fullscreen( GTK_WINDOW(win->window) );
1.159 + } else {
1.160 + gtk_window_unfullscreen( GTK_WINDOW(win->window) );
1.161 + }
1.162 +}
.