Search
lxdream.org :: lxdream/src/gtkui/main_win.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/main_win.c
changeset 543:361ec0a70cf2
prev537:d924be49e192
next545:fdcdcd8b9fd1
author nkeynes
date Thu Nov 22 11:10:15 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Re-add "Load Binary" menu item (misplaced in GUI rewrite)
Prevent running with no code loaded
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@497
     2
 * $Id: main_win.c,v 1.10 2007-11-08 10:46:41 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@537
    31
#include "gtkui/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@497
    51
    main_window_t win = (main_window_t)userdata;
nkeynes@486
    52
    if( state->changed_mask & GDK_WINDOW_STATE_FULLSCREEN ) {
nkeynes@486
    53
	gboolean fs = (state->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
nkeynes@497
    54
	GtkWidget *frame = gtk_widget_get_parent(win->video);
nkeynes@497
    55
	if( frame->style == NULL ) {
nkeynes@497
    56
	    gtk_widget_set_style( frame, gtk_style_new() );
nkeynes@497
    57
	}
nkeynes@497
    58
	if( fs ) {
nkeynes@497
    59
	    gtk_widget_hide( win->menubar );
nkeynes@497
    60
	    gtk_widget_hide( win->toolbar );
nkeynes@497
    61
	    gtk_widget_hide( win->statusbar );
nkeynes@497
    62
	    
nkeynes@497
    63
	    frame->style->xthickness = 0;
nkeynes@497
    64
	    frame->style->ythickness = 0;
nkeynes@497
    65
	} else {
nkeynes@497
    66
	    frame->style->xthickness = 2;
nkeynes@497
    67
	    frame->style->ythickness = 2;
nkeynes@497
    68
	    gtk_widget_show( win->menubar );
nkeynes@497
    69
	    gtk_widget_show( win->toolbar );
nkeynes@497
    70
	    gtk_widget_show( win->statusbar );
nkeynes@497
    71
	}
nkeynes@497
    72
	gtk_widget_queue_draw( win->window );
nkeynes@486
    73
    }
nkeynes@486
    74
}
nkeynes@486
    75
nkeynes@455
    76
main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
nkeynes@455
    77
			       GtkAccelGroup *accel_group )
nkeynes@435
    78
{
nkeynes@435
    79
    GtkWidget *vbox;
nkeynes@437
    80
    GtkWidget *frame;
nkeynes@435
    81
    main_window_t win = g_malloc0( sizeof(struct main_window_info) );
nkeynes@435
    82
nkeynes@435
    83
    win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
nkeynes@486
    84
    win->menubar = menubar;
nkeynes@486
    85
    win->toolbar = toolbar;
nkeynes@435
    86
    gtk_window_set_title( GTK_WINDOW(win->window), title );
nkeynes@435
    87
    gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
nkeynes@435
    88
nkeynes@455
    89
    gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
nkeynes@435
    90
nkeynes@435
    91
    win->video = gtk_drawing_area_new();
nkeynes@435
    92
    GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
nkeynes@435
    93
    gtk_widget_set_size_request( win->video, 640, 480 ); 
nkeynes@437
    94
    frame = gtk_frame_new(NULL);
nkeynes@437
    95
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@437
    96
    gtk_container_add( GTK_CONTAINER(frame), win->video );
nkeynes@437
    97
nkeynes@435
    98
    win->statusbar = gtk_statusbar_new();
nkeynes@435
    99
nkeynes@435
   100
    vbox = gtk_vbox_new(FALSE, 0);
nkeynes@435
   101
    gtk_container_add( GTK_CONTAINER(win->window), vbox );
nkeynes@455
   102
    gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
nkeynes@455
   103
    gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
nkeynes@437
   104
    gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
nkeynes@435
   105
    gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
nkeynes@435
   106
    gtk_widget_show_all( win->window );
nkeynes@435
   107
    gtk_widget_grab_focus( win->video );
nkeynes@435
   108
    
nkeynes@437
   109
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
nkeynes@457
   110
    g_signal_connect( win->window, "delete_event", 
nkeynes@457
   111
		      G_CALLBACK(on_main_window_deleted), win );
nkeynes@486
   112
    g_signal_connect( win->window, "window-state-event",
nkeynes@486
   113
		      G_CALLBACK(on_main_window_state_changed), win );
nkeynes@435
   114
    return win;
nkeynes@435
   115
}
nkeynes@435
   116
nkeynes@435
   117
void main_window_set_running( main_window_t win, gboolean running )
nkeynes@435
   118
{
nkeynes@455
   119
    gtk_gui_enable_action( "Pause", running );
nkeynes@543
   120
    gtk_gui_enable_action( "Run", !running && dreamcast_can_run() );
nkeynes@437
   121
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   122
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
nkeynes@435
   123
}
nkeynes@435
   124
nkeynes@435
   125
void main_window_set_framerate( main_window_t win, float rate )
nkeynes@435
   126
{
nkeynes@435
   127
nkeynes@435
   128
nkeynes@435
   129
}
nkeynes@435
   130
nkeynes@437
   131
void main_window_set_speed( main_window_t win, double speed )
nkeynes@437
   132
{
nkeynes@437
   133
    char buf[32];
nkeynes@437
   134
nkeynes@480
   135
    snprintf( buf, 32, "Running (%2.4f%%)", speed );
nkeynes@437
   136
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   137
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
nkeynes@437
   138
    
nkeynes@437
   139
nkeynes@437
   140
}
nkeynes@437
   141
nkeynes@435
   142
GtkWidget *main_window_get_renderarea( main_window_t win )
nkeynes@435
   143
{
nkeynes@435
   144
    return win->video;
nkeynes@435
   145
}
nkeynes@447
   146
nkeynes@447
   147
GtkWindow *main_window_get_frame( main_window_t win )
nkeynes@447
   148
{
nkeynes@447
   149
    return GTK_WINDOW(win->window);
nkeynes@447
   150
}
nkeynes@486
   151
nkeynes@486
   152
void main_window_set_fullscreen( main_window_t win, gboolean fullscreen )
nkeynes@486
   153
{
nkeynes@486
   154
    if( fullscreen ) {
nkeynes@486
   155
	gtk_window_fullscreen( GTK_WINDOW(win->window) );
nkeynes@486
   156
    } else {
nkeynes@486
   157
	gtk_window_unfullscreen( GTK_WINDOW(win->window) );
nkeynes@486
   158
    }
nkeynes@486
   159
}
.