Search
lxdream.org :: lxdream :: r659:6b1dff1575b3
lxdream 0.9.1
released Jun 29
Download Now
changeset659:6b1dff1575b3
parent658:f5926310bfbe
child660:d1b2695347c6
authornkeynes
dateWed Apr 16 22:54:40 2008 +0000 (11 years ago)
Move drawable creation to video_gtk.c - removes the last platform dependency from gtkui
src/drivers/video_gtk.c
src/gtkui/main_win.c
1.1 --- a/src/drivers/video_gtk.c Wed Apr 16 12:43:52 2008 +0000
1.2 +++ b/src/drivers/video_gtk.c Wed Apr 16 22:54:40 2008 +0000
1.3 @@ -98,7 +98,8 @@
1.4 #endif
1.5
1.6 #endif
1.7 -GtkWidget *gtk_video_win = NULL;
1.8 +
1.9 +static GtkWidget *gtk_video_drawable = NULL;
1.10 int video_width = 640;
1.11 int video_height = 480;
1.12
1.13 @@ -221,26 +222,51 @@
1.14 return DCKB_NONE;
1.15 }
1.16
1.17 +GtkWidget *video_gtk_create_drawable()
1.18 +{
1.19 + GtkWidget *drawable = gtk_drawing_area_new();
1.20 + GTK_WIDGET_SET_FLAGS(drawable, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
1.21 +
1.22 + g_signal_connect( drawable, "expose_event",
1.23 + G_CALLBACK(video_gtk_expose_callback), NULL );
1.24 + g_signal_connect( drawable, "configure_event",
1.25 + G_CALLBACK(video_gtk_resize_callback), NULL );
1.26 +
1.27 +#ifdef HAVE_GLX
1.28 + Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(drawable));
1.29 + Screen *screen = gdk_x11_screen_get_xscreen( gtk_widget_get_screen(drawable));
1.30 + int screen_no = XScreenNumberOfScreen(screen);
1.31 + if( !video_glx_init(display, screen_no) ) {
1.32 + ERROR( "Unable to initialize GLX, aborting" );
1.33 + exit(3);
1.34 + }
1.35 +
1.36 + XVisualInfo *visual = video_glx_get_visual();
1.37 + if( visual != NULL ) {
1.38 + GdkVisual *gdkvis = gdk_x11_screen_lookup_visual( gtk_widget_get_screen(drawable), visual->visualid );
1.39 + GdkColormap *colormap = gdk_colormap_new( gdkvis, FALSE );
1.40 + gtk_widget_set_colormap( drawable, colormap );
1.41 + }
1.42 +#endif
1.43 + gtk_video_drawable = drawable;
1.44 + return drawable;
1.45 +}
1.46 +
1.47 gboolean video_gtk_init()
1.48 {
1.49
1.50 - gtk_video_win = gtk_gui_get_renderarea();
1.51 - if( gtk_video_win == NULL ) {
1.52 + if( gtk_video_drawable == NULL ) {
1.53 return FALSE;
1.54 }
1.55
1.56 - g_signal_connect( gtk_video_win, "expose_event",
1.57 - G_CALLBACK(video_gtk_expose_callback), NULL );
1.58 - g_signal_connect( gtk_video_win, "configure_event",
1.59 - G_CALLBACK(video_gtk_resize_callback), NULL );
1.60 - video_width = gtk_video_win->allocation.width;
1.61 - video_height = gtk_video_win->allocation.height;
1.62 + video_width = gtk_video_drawable->allocation.width;
1.63 + video_height = gtk_video_drawable->allocation.height;
1.64 #ifdef HAVE_OSMESA
1.65 video_gdk_init_driver( &display_gtk_driver );
1.66 #else
1.67 #ifdef HAVE_GLX
1.68 - Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(gtk_video_win)));
1.69 - Window window = GDK_WINDOW_XWINDOW( GTK_WIDGET(gtk_video_win)->window );
1.70 + Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(gtk_video_drawable)));
1.71 + Window window = GDK_WINDOW_XWINDOW( GTK_WIDGET(gtk_video_drawable)->window );
1.72 if( ! video_glx_init_context( display, window ) ||
1.73 ! video_glx_init_driver( &display_gtk_driver ) ) {
1.74 return FALSE;
1.75 @@ -256,36 +282,27 @@
1.76
1.77 gboolean video_gtk_display_blank( uint32_t colour )
1.78 {
1.79 - GdkGC *gc = gdk_gc_new(gtk_video_win->window);
1.80 + GdkGC *gc = gdk_gc_new(gtk_video_drawable->window);
1.81 GdkColor color = {0, ((colour>>16)&0xFF)*257, ((colour>>8)&0xFF)*257, ((colour)&0xFF)*257 };
1.82 GdkColormap *cmap = gdk_colormap_get_system();
1.83 gdk_colormap_alloc_color( cmap, &color, TRUE, TRUE );
1.84 gdk_gc_set_foreground( gc, &color );
1.85 gdk_gc_set_background( gc, &color );
1.86 - gdk_draw_rectangle( gtk_video_win->window, gc, TRUE, 0, 0, video_width, video_height );
1.87 + gdk_draw_rectangle( gtk_video_drawable->window, gc, TRUE, 0, 0, video_width, video_height );
1.88 gdk_gc_destroy(gc);
1.89 gdk_colormap_free_colors( cmap, &color, 1 );
1.90 }
1.91
1.92 -#ifdef HAVE_GTK_X11
1.93 -XVisualInfo *video_gtk_get_visual()
1.94 -{
1.95 -#ifdef HAVE_OSMESA
1.96 - return NULL;
1.97 -#else
1.98 - return video_glx_get_visual();
1.99 -#endif
1.100 -}
1.101 -#endif
1.102 -
1.103 void video_gtk_shutdown()
1.104 {
1.105 - if( gtk_video_win != NULL ) {
1.106 + if( gtk_video_drawable != NULL ) {
1.107 #ifdef HAVE_OSMESA
1.108 video_gdk_shutdown();
1.109 #else
1.110 +#ifdef HAVE_GLX
1.111 video_glx_shutdown();
1.112 #endif
1.113 +#endif
1.114 }
1.115 #ifdef HAVE_LINUX_JOYSTICK
1.116 linux_joystick_shutdown();
2.1 --- a/src/gtkui/main_win.c Wed Apr 16 12:43:52 2008 +0000
2.2 +++ b/src/gtkui/main_win.c Wed Apr 16 22:54:40 2008 +0000
2.3 @@ -33,11 +33,6 @@
2.4 #include "lxdream.h"
2.5 #include "gtkui/gtkui.h"
2.6
2.7 -#ifdef HAVE_GLX
2.8 -#include <gdk/gdkx.h>
2.9 -#include "drivers/video_glx.h"
2.10 -#endif
2.11 -
2.12
2.13 struct main_window_info {
2.14 GtkWidget *window;
2.15 @@ -250,26 +245,7 @@
2.16
2.17 gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
2.18
2.19 - win->video = gtk_drawing_area_new();
2.20 -
2.21 -#ifdef HAVE_GLX
2.22 - Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(win->window));
2.23 - Screen *screen = gdk_x11_screen_get_xscreen( gtk_widget_get_screen(win->window));
2.24 - int screen_no = XScreenNumberOfScreen(screen);
2.25 - if( !video_glx_init(display, screen_no) ) {
2.26 - ERROR( "Unable to initialize GLX, aborting" );
2.27 - exit(3);
2.28 - }
2.29 -
2.30 - XVisualInfo *visual = video_gtk_get_visual();
2.31 - if( visual != NULL ) {
2.32 - GdkVisual *gdkvis = gdk_x11_screen_lookup_visual( gtk_widget_get_screen(win->window), visual->visualid );
2.33 - GdkColormap *colormap = gdk_colormap_new( gdkvis, FALSE );
2.34 - gtk_widget_set_colormap( win->video, colormap );
2.35 - }
2.36 -#endif
2.37 -
2.38 - GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
2.39 + win->video = video_gtk_create_drawable();
2.40 gtk_widget_set_size_request( win->video, 640, 480 );
2.41 gtk_widget_set_double_buffered( win->video, FALSE );
2.42 frame = gtk_frame_new(NULL);
.