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 545:fdcdcd8b9fd1
prev543:361ec0a70cf2
next561:533f6b478071
author nkeynes
date Thu Nov 29 09:28:28 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Refactor GLX support and implement pbuffer rendering support
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@545
    29
#include <gdk/gdkx.h>
nkeynes@545
    30
#include <X11/Xutil.h>
nkeynes@435
    31
nkeynes@435
    32
#include "dream.h"
nkeynes@537
    33
#include "gtkui/gtkui.h"
nkeynes@545
    34
#include "drivers/video_glx.h"
nkeynes@435
    35
nkeynes@435
    36
nkeynes@435
    37
struct main_window_info {
nkeynes@435
    38
    GtkWidget *window;
nkeynes@435
    39
    GtkWidget *video;
nkeynes@486
    40
    GtkWidget *menubar;
nkeynes@486
    41
    GtkWidget *toolbar;
nkeynes@435
    42
    GtkWidget *statusbar;
nkeynes@435
    43
    GtkActionGroup *actions;
nkeynes@435
    44
};
nkeynes@435
    45
nkeynes@486
    46
static gboolean on_main_window_deleted( GtkWidget *widget, GdkEvent event, gpointer user_data )
nkeynes@457
    47
{
nkeynes@457
    48
    exit(0);
nkeynes@457
    49
}
nkeynes@457
    50
nkeynes@486
    51
static void on_main_window_state_changed( GtkWidget *widget, GdkEventWindowState *state, 
nkeynes@486
    52
					  gpointer userdata )
nkeynes@486
    53
{
nkeynes@497
    54
    main_window_t win = (main_window_t)userdata;
nkeynes@486
    55
    if( state->changed_mask & GDK_WINDOW_STATE_FULLSCREEN ) {
nkeynes@486
    56
	gboolean fs = (state->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
nkeynes@497
    57
	GtkWidget *frame = gtk_widget_get_parent(win->video);
nkeynes@497
    58
	if( frame->style == NULL ) {
nkeynes@497
    59
	    gtk_widget_set_style( frame, gtk_style_new() );
nkeynes@497
    60
	}
nkeynes@497
    61
	if( fs ) {
nkeynes@497
    62
	    gtk_widget_hide( win->menubar );
nkeynes@497
    63
	    gtk_widget_hide( win->toolbar );
nkeynes@497
    64
	    gtk_widget_hide( win->statusbar );
nkeynes@497
    65
	    
nkeynes@497
    66
	    frame->style->xthickness = 0;
nkeynes@497
    67
	    frame->style->ythickness = 0;
nkeynes@497
    68
	} else {
nkeynes@497
    69
	    frame->style->xthickness = 2;
nkeynes@497
    70
	    frame->style->ythickness = 2;
nkeynes@497
    71
	    gtk_widget_show( win->menubar );
nkeynes@497
    72
	    gtk_widget_show( win->toolbar );
nkeynes@497
    73
	    gtk_widget_show( win->statusbar );
nkeynes@497
    74
	}
nkeynes@497
    75
	gtk_widget_queue_draw( win->window );
nkeynes@486
    76
    }
nkeynes@486
    77
}
nkeynes@486
    78
nkeynes@455
    79
main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
nkeynes@455
    80
			       GtkAccelGroup *accel_group )
nkeynes@435
    81
{
nkeynes@435
    82
    GtkWidget *vbox;
nkeynes@437
    83
    GtkWidget *frame;
nkeynes@435
    84
    main_window_t win = g_malloc0( sizeof(struct main_window_info) );
nkeynes@435
    85
nkeynes@435
    86
    win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
nkeynes@486
    87
    win->menubar = menubar;
nkeynes@486
    88
    win->toolbar = toolbar;
nkeynes@435
    89
    gtk_window_set_title( GTK_WINDOW(win->window), title );
nkeynes@435
    90
    gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
nkeynes@435
    91
nkeynes@455
    92
    gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
nkeynes@545
    93
    
nkeynes@545
    94
    Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(win->window));
nkeynes@545
    95
    Screen *screen = gdk_x11_screen_get_xscreen( gtk_widget_get_screen(win->window));
nkeynes@545
    96
    int screen_no = XScreenNumberOfScreen(screen);
nkeynes@545
    97
    video_glx_init(display, screen_no);
nkeynes@435
    98
nkeynes@545
    99
    XVisualInfo *visual = video_glx_get_visual();
nkeynes@545
   100
    GdkVisual *gdkvis = gdk_x11_screen_lookup_visual( gtk_widget_get_screen(win->window), visual->visualid );
nkeynes@545
   101
    GdkColormap *colormap = gdk_colormap_new( gdkvis, FALSE );
nkeynes@435
   102
    win->video = gtk_drawing_area_new();
nkeynes@545
   103
    gtk_widget_set_colormap( win->video, colormap );
nkeynes@435
   104
    GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
nkeynes@435
   105
    gtk_widget_set_size_request( win->video, 640, 480 ); 
nkeynes@437
   106
    frame = gtk_frame_new(NULL);
nkeynes@437
   107
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@437
   108
    gtk_container_add( GTK_CONTAINER(frame), win->video );
nkeynes@437
   109
nkeynes@435
   110
    win->statusbar = gtk_statusbar_new();
nkeynes@435
   111
nkeynes@435
   112
    vbox = gtk_vbox_new(FALSE, 0);
nkeynes@435
   113
    gtk_container_add( GTK_CONTAINER(win->window), vbox );
nkeynes@455
   114
    gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
nkeynes@455
   115
    gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
nkeynes@437
   116
    gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
nkeynes@435
   117
    gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
nkeynes@435
   118
    gtk_widget_show_all( win->window );
nkeynes@435
   119
    gtk_widget_grab_focus( win->video );
nkeynes@435
   120
    
nkeynes@437
   121
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
nkeynes@457
   122
    g_signal_connect( win->window, "delete_event", 
nkeynes@457
   123
		      G_CALLBACK(on_main_window_deleted), win );
nkeynes@486
   124
    g_signal_connect( win->window, "window-state-event",
nkeynes@486
   125
		      G_CALLBACK(on_main_window_state_changed), win );
nkeynes@435
   126
    return win;
nkeynes@435
   127
}
nkeynes@435
   128
nkeynes@435
   129
void main_window_set_running( main_window_t win, gboolean running )
nkeynes@435
   130
{
nkeynes@455
   131
    gtk_gui_enable_action( "Pause", running );
nkeynes@543
   132
    gtk_gui_enable_action( "Run", !running && dreamcast_can_run() );
nkeynes@437
   133
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   134
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
nkeynes@435
   135
}
nkeynes@435
   136
nkeynes@435
   137
void main_window_set_framerate( main_window_t win, float rate )
nkeynes@435
   138
{
nkeynes@435
   139
nkeynes@435
   140
nkeynes@435
   141
}
nkeynes@435
   142
nkeynes@437
   143
void main_window_set_speed( main_window_t win, double speed )
nkeynes@437
   144
{
nkeynes@437
   145
    char buf[32];
nkeynes@437
   146
nkeynes@480
   147
    snprintf( buf, 32, "Running (%2.4f%%)", speed );
nkeynes@437
   148
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
   149
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
nkeynes@437
   150
    
nkeynes@437
   151
nkeynes@437
   152
}
nkeynes@437
   153
nkeynes@435
   154
GtkWidget *main_window_get_renderarea( main_window_t win )
nkeynes@435
   155
{
nkeynes@435
   156
    return win->video;
nkeynes@435
   157
}
nkeynes@447
   158
nkeynes@447
   159
GtkWindow *main_window_get_frame( main_window_t win )
nkeynes@447
   160
{
nkeynes@447
   161
    return GTK_WINDOW(win->window);
nkeynes@447
   162
}
nkeynes@486
   163
nkeynes@486
   164
void main_window_set_fullscreen( main_window_t win, gboolean fullscreen )
nkeynes@486
   165
{
nkeynes@486
   166
    if( fullscreen ) {
nkeynes@486
   167
	gtk_window_fullscreen( GTK_WINDOW(win->window) );
nkeynes@486
   168
    } else {
nkeynes@486
   169
	gtk_window_unfullscreen( GTK_WINDOW(win->window) );
nkeynes@486
   170
    }
nkeynes@486
   171
}
.