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 455:3080881d00d4
prev450:207461e79f21
next457:af605fd32c0b
author nkeynes
date Sun Oct 21 05:21:35 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change More GUI WIP
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@455
     2
 * $Id: main_win.c,v 1.6 2007-10-21 05:21:35 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@435
    37
    GtkWidget *statusbar;
nkeynes@435
    38
    GtkActionGroup *actions;
nkeynes@435
    39
};
nkeynes@435
    40
nkeynes@455
    41
main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
nkeynes@455
    42
			       GtkAccelGroup *accel_group )
nkeynes@435
    43
{
nkeynes@435
    44
    GtkWidget *vbox;
nkeynes@437
    45
    GtkWidget *frame;
nkeynes@435
    46
    main_window_t win = g_malloc0( sizeof(struct main_window_info) );
nkeynes@435
    47
nkeynes@435
    48
    win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
nkeynes@435
    49
    gtk_window_set_title( GTK_WINDOW(win->window), title );
nkeynes@435
    50
    gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
nkeynes@435
    51
nkeynes@455
    52
    gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
nkeynes@435
    53
nkeynes@435
    54
    win->video = gtk_drawing_area_new();
nkeynes@435
    55
    GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
nkeynes@435
    56
    gtk_widget_set_size_request( win->video, 640, 480 ); 
nkeynes@437
    57
    frame = gtk_frame_new(NULL);
nkeynes@437
    58
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@437
    59
    gtk_container_add( GTK_CONTAINER(frame), win->video );
nkeynes@437
    60
nkeynes@435
    61
    win->statusbar = gtk_statusbar_new();
nkeynes@435
    62
nkeynes@435
    63
    vbox = gtk_vbox_new(FALSE, 0);
nkeynes@435
    64
    gtk_container_add( GTK_CONTAINER(win->window), vbox );
nkeynes@455
    65
    gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
nkeynes@455
    66
    gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
nkeynes@437
    67
    gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
nkeynes@435
    68
    gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
nkeynes@435
    69
    gtk_widget_show_all( win->window );
nkeynes@435
    70
    gtk_widget_grab_focus( win->video );
nkeynes@435
    71
    
nkeynes@437
    72
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
nkeynes@435
    73
    return win;
nkeynes@435
    74
}
nkeynes@435
    75
nkeynes@435
    76
void main_window_set_running( main_window_t win, gboolean running )
nkeynes@435
    77
{
nkeynes@455
    78
    gtk_gui_enable_action( "Pause", running );
nkeynes@455
    79
    gtk_gui_enable_action( "Run", !running );
nkeynes@437
    80
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
    81
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
nkeynes@435
    82
}
nkeynes@435
    83
nkeynes@435
    84
void main_window_set_framerate( main_window_t win, float rate )
nkeynes@435
    85
{
nkeynes@435
    86
nkeynes@435
    87
nkeynes@435
    88
}
nkeynes@435
    89
nkeynes@437
    90
void main_window_set_speed( main_window_t win, double speed )
nkeynes@437
    91
{
nkeynes@437
    92
    char buf[32];
nkeynes@437
    93
nkeynes@437
    94
    snprintf( buf, 32, "Running (%2.4f%)", speed );
nkeynes@437
    95
    gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
nkeynes@437
    96
    gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
nkeynes@437
    97
    
nkeynes@437
    98
nkeynes@437
    99
}
nkeynes@437
   100
nkeynes@435
   101
GtkWidget *main_window_get_renderarea( main_window_t win )
nkeynes@435
   102
{
nkeynes@435
   103
    return win->video;
nkeynes@435
   104
}
nkeynes@447
   105
nkeynes@447
   106
GtkWindow *main_window_get_frame( main_window_t win )
nkeynes@447
   107
{
nkeynes@447
   108
    return GTK_WINDOW(win->window);
nkeynes@447
   109
}
.