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 424:421d68e78c46
prev370:3131ba1440fc
next435:7a5d71e8560b
author nkeynes
date Sun Oct 07 05:42:25 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Fix compilation warnings
view annotate diff log raw
     1 /**
     2  * $Id: video_gtk.c,v 1.12 2007-10-07 05:42:25 nkeynes Exp $
     3  *
     4  * The PC side of the video support (responsible for actually displaying / 
     5  * rendering frames)
     6  *
     7  * Copyright (c) 2005 Nathan Keynes.
     8  *
     9  * This program is free software; you can redistribute it and/or modify
    10  * it under the terms of the GNU General Public License as published by
    11  * the Free Software Foundation; either version 2 of the License, or
    12  * (at your option) any later version.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  */
    20 #include <gnome.h>
    21 #include <gdk/gdkx.h>
    22 #include <stdint.h>
    23 #include "dream.h"
    24 #include "display.h"
    25 #include "drivers/video_x11.h"
    27 GdkImage *video_img = NULL;
    28 GtkWindow *video_win = NULL;
    29 GtkWidget *video_area = NULL;
    30 uint32_t video_width = 640;
    31 uint32_t video_height = 480;
    33 gboolean video_gtk_init();
    34 void video_gtk_shutdown();
    35 uint16_t video_gtk_resolve_keysym( const gchar *keysym );
    37 struct display_driver display_gtk_driver = { "gtk", video_gtk_init, video_gtk_shutdown,
    38 					     video_gtk_resolve_keysym,
    39 					     NULL, NULL, NULL, NULL, NULL, NULL, NULL };
    42 gboolean video_gtk_keydown_callback(GtkWidget       *widget,
    43 				     GdkEventKey     *event,
    44 				     gpointer         user_data)
    45 {
    46     input_event_keydown( event->keyval );
    47     return TRUE;
    48 }
    50 uint16_t video_gtk_resolve_keysym( const gchar *keysym )
    51 {
    52     int val = gdk_keyval_from_name( keysym );
    53     if( val == GDK_VoidSymbol )
    54 	return 0;
    55     return (uint16_t)val;
    56 }
    58 gboolean video_gtk_keyup_callback(GtkWidget       *widget,
    59 				  GdkEventKey     *event,
    60 				  gpointer         user_data)
    61 {
    62     input_event_keyup( event->keyval );
    63     return TRUE;
    64 }
    66 gboolean video_gtk_init()
    67 {
    68     video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
    69     gtk_window_set_title( video_win, APP_NAME " - Emulation Window" );
    70     gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
    72     g_signal_connect( video_win, "key_press_event", 
    73 		      G_CALLBACK(video_gtk_keydown_callback), NULL );
    74     g_signal_connect( video_win, "key_release_event", 
    75 		      G_CALLBACK(video_gtk_keyup_callback), NULL );
    76     gtk_widget_add_events( GTK_WIDGET(video_win), 
    77 			   GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
    78 			   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
    79     video_area = gtk_image_new();
    80     gtk_widget_show( GTK_WIDGET(video_area) );
    81     gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
    82     gtk_widget_show( GTK_WIDGET(video_win) );
    83     video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
    84                                video_width, video_height );
    85     gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
    87     gtk_window_set_default_size( video_win, video_width, video_height );
    89     return video_glx_init( gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win))),
    90 		    gdk_x11_screen_get_xscreen( gtk_widget_get_screen(GTK_WIDGET(video_win))),
    91 		    GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ),
    92 		    video_width, video_height, &display_gtk_driver );
    93 }
    95 void video_gtk_shutdown()
    96 {
    97     video_glx_shutdown();
    98     gtk_widget_destroy( GTK_WIDGET(video_win) );
   100 }
.