Search
lxdream.org :: lxdream/src/drivers/video_gtk.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_gtk.c
changeset 435:7a5d71e8560b
prev424:421d68e78c46
next436:e8c461d2545e
author nkeynes
date Wed Oct 10 11:02:04 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change First cut of new GUI
file annotate diff log raw
nkeynes@94
     1
/**
nkeynes@435
     2
 * $Id: video_gtk.c,v 1.13 2007-10-10 11:02:04 nkeynes Exp $
nkeynes@94
     3
 *
nkeynes@94
     4
 * The PC side of the video support (responsible for actually displaying / 
nkeynes@94
     5
 * rendering frames)
nkeynes@94
     6
 *
nkeynes@94
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@94
     8
 *
nkeynes@94
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@94
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@94
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@94
    12
 * (at your option) any later version.
nkeynes@94
    13
 *
nkeynes@94
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@94
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@94
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@94
    17
 * GNU General Public License for more details.
nkeynes@94
    18
 */
nkeynes@94
    19
nkeynes@94
    20
#include <gnome.h>
nkeynes@94
    21
#include <gdk/gdkx.h>
nkeynes@94
    22
#include <stdint.h>
nkeynes@180
    23
#include "dream.h"
nkeynes@144
    24
#include "display.h"
nkeynes@94
    25
#include "drivers/video_x11.h"
nkeynes@435
    26
#include "gui/gtkui.h"
nkeynes@94
    27
nkeynes@94
    28
GdkImage *video_img = NULL;
nkeynes@435
    29
GtkWidget *video_win = NULL;
nkeynes@94
    30
GtkWidget *video_area = NULL;
nkeynes@94
    31
uint32_t video_width = 640;
nkeynes@94
    32
uint32_t video_height = 480;
nkeynes@94
    33
nkeynes@352
    34
gboolean video_gtk_init();
nkeynes@352
    35
void video_gtk_shutdown();
nkeynes@144
    36
uint16_t video_gtk_resolve_keysym( const gchar *keysym );
nkeynes@94
    37
nkeynes@370
    38
struct display_driver display_gtk_driver = { "gtk", video_gtk_init, video_gtk_shutdown,
nkeynes@352
    39
					     video_gtk_resolve_keysym,
nkeynes@352
    40
					     NULL, NULL, NULL, NULL, NULL, NULL, NULL };
nkeynes@352
    41
					     
nkeynes@144
    42
nkeynes@144
    43
gboolean video_gtk_keydown_callback(GtkWidget       *widget,
nkeynes@144
    44
				     GdkEventKey     *event,
nkeynes@144
    45
				     gpointer         user_data)
nkeynes@144
    46
{
nkeynes@144
    47
    input_event_keydown( event->keyval );
nkeynes@424
    48
    return TRUE;
nkeynes@144
    49
}
nkeynes@144
    50
nkeynes@144
    51
uint16_t video_gtk_resolve_keysym( const gchar *keysym )
nkeynes@144
    52
{
nkeynes@144
    53
    int val = gdk_keyval_from_name( keysym );
nkeynes@144
    54
    if( val == GDK_VoidSymbol )
nkeynes@144
    55
	return 0;
nkeynes@144
    56
    return (uint16_t)val;
nkeynes@144
    57
}
nkeynes@144
    58
nkeynes@144
    59
gboolean video_gtk_keyup_callback(GtkWidget       *widget,
nkeynes@144
    60
				  GdkEventKey     *event,
nkeynes@144
    61
				  gpointer         user_data)
nkeynes@144
    62
{
nkeynes@144
    63
    input_event_keyup( event->keyval );
nkeynes@424
    64
    return TRUE;
nkeynes@144
    65
}
nkeynes@94
    66
nkeynes@435
    67
gboolean video_gtk_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data )
nkeynes@435
    68
{
nkeynes@435
    69
    /* redisplay last frame */
nkeynes@435
    70
}
nkeynes@435
    71
nkeynes@352
    72
gboolean video_gtk_init()
nkeynes@94
    73
{
nkeynes@435
    74
    /*
nkeynes@352
    75
    video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
nkeynes@352
    76
    gtk_window_set_title( video_win, APP_NAME " - Emulation Window" );
nkeynes@352
    77
    gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
nkeynes@435
    78
    gtk_window_set_default_size( video_win, video_width, video_height );
nkeynes@435
    79
    */
nkeynes@94
    80
    
nkeynes@435
    81
    video_win = gtk_gui_get_renderarea();
nkeynes@435
    82
nkeynes@352
    83
    g_signal_connect( video_win, "key_press_event", 
nkeynes@352
    84
		      G_CALLBACK(video_gtk_keydown_callback), NULL );
nkeynes@352
    85
    g_signal_connect( video_win, "key_release_event", 
nkeynes@352
    86
		      G_CALLBACK(video_gtk_keyup_callback), NULL );
nkeynes@435
    87
    g_signal_connect( video_win, "expose_event",
nkeynes@435
    88
		      G_CALLBACK(video_gtk_expose_callback), NULL );
nkeynes@435
    89
    gtk_widget_add_events( video_win, 
nkeynes@352
    90
			   GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
nkeynes@352
    91
			   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
nkeynes@352
    92
    video_area = gtk_image_new();
nkeynes@352
    93
    gtk_widget_show( GTK_WIDGET(video_area) );
nkeynes@352
    94
    gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
nkeynes@352
    95
    gtk_widget_show( GTK_WIDGET(video_win) );
nkeynes@352
    96
    video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
nkeynes@352
    97
                               video_width, video_height );
nkeynes@352
    98
    gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
nkeynes@352
    99
nkeynes@352
   100
nkeynes@370
   101
    return video_glx_init( gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win))),
nkeynes@352
   102
		    gdk_x11_screen_get_xscreen( gtk_widget_get_screen(GTK_WIDGET(video_win))),
nkeynes@352
   103
		    GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ),
nkeynes@352
   104
		    video_width, video_height, &display_gtk_driver );
nkeynes@94
   105
}
nkeynes@94
   106
nkeynes@352
   107
void video_gtk_shutdown()
nkeynes@352
   108
{
nkeynes@370
   109
    video_glx_shutdown();
nkeynes@370
   110
    gtk_widget_destroy( GTK_WIDGET(video_win) );
nkeynes@352
   111
nkeynes@94
   112
}
nkeynes@94
   113
.