I've written a quick and dirty demonstration, a la the win32 demo in the language reference, on painting the ScreenPtr to a GtkDrawingArea widget. Now it sort of works, but currently the byte ordering of the ScreenPtr is not what the GdkPixbuf wrapper is expecting, so while you can see the letters on the screen that where PRINTed there, drawing lines and stuff is funky. And there's no real provision for redrawing the screen other than on an expose. But here's the code. It has no real purpose, but others may enjoy it. The window starts off with a DrawingArea that's 0 pixels, so you'll have to resize the window.
Here's the glade file:
Code: Select all
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="window">
<property name="visible">True</property>
<property name="title" translatable="yes">FreeBASIC and GTK and GfxLib</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="on_window_delete_event" last_modification_time="Mon, 26 Feb 2007 06:16:11 GMT"/>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="border_width">11</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">5</property>
<child>
<widget class="GtkDrawingArea" id="drawingarea1">
<property name="visible">True</property>
<signal name="configure_event" handler="on_drawingarea_configure_event" last_modification_time="Mon, 26 Feb 2007 05:55:48 GMT"/>
<signal name="expose_event" handler="on_drawingarea_expose_event" last_modification_time="Mon, 26 Feb 2007 05:55:56 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="border_width">10</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkButton" id="quit_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-quit</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_quit_button_clicked" last_modification_time="Mon, 26 Feb 2007 05:58:55 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">button2</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button2_clicked" last_modification_time="Mon, 26 Feb 2007 05:58:42 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">button3</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button3_clicked" last_modification_time="Mon, 26 Feb 2007 05:58:48 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
Code: Select all
option explicit 'no idea what this does
defint a-z
#include "gtk/gtk.bi"
#include "gtk/libglade/glade-xml.bi"
#include "fbgfx.bi"
#define NULL 0
dim shared w,h
dim shared xml as GladeXML Ptr
declare sub on_window_delete_event cdecl alias _
"on_window_delete_event" ( byval object as GtkObject Ptr, _
byval user_data as gpointer )
declare sub on_drawingarea_configure_event cdecl alias _
"on_drawingarea_configure_event" ( byval object as GtkObject Ptr, _
byval event as GdkEventConfigure Ptr, _
byval user_data as gpointer )
declare sub on_drawingarea_expose_event cdecl alias _
"on_drawingarea_expose_event" ( byval object as GtkObject Ptr, _
byval expose as GdkEventExpose Ptr, _
byval user_data as gpointer )
declare sub on_quit_button_clicked cdecl alias _
"on_quit_button_clicked" ( byval object as GtkObject Ptr, _
byval user_data as gpointer )
declare sub on_button2_clicked cdecl alias _
"on_button2_clicked" ( byval object as GtkObject Ptr, _
byval user_data as gpointer )
declare sub on_button3_clicked cdecl alias _
"on_button3_clicked" ( byval object as GtkObject Ptr, _
byval user_data as gpointer )
sub redraw ()
dim widget as GtkWidget Ptr
widget=glade_xml_get_widget(xml,"drawingarea")
gtk_widget_queue_draw_area(widget,0,0,w,h)
end sub
sub on_window_delete_event cdecl ( byval object as GtkObject Ptr, _
byval user_data as gpointer )
on_quit_button_clicked(object,user_data)
end sub
sub on_quit_button_clicked cdecl ( byval object as GtkObject Ptr, _
byval user_data as gpointer ) export
print "Quit Button clicked."
gtk_main_quit()
end sub
sub on_button3_clicked cdecl ( byval object as GtkObject Ptr, _
byval user_data as gpointer )
print "Button 3 clicked"
line (40,40)-(139,499),55
redraw
end sub
sub on_drawingarea_configure_event cdecl ( byval object as GtkObject Ptr, _
byval event as GdkEventConfigure Ptr, _
byval user_data as gpointer )
w=event->width
h=event->height
print "New dimensions are ";w;",";h
if h < 16 or w < 16 then print "too small" : return
ScreenRes w,h,24,1,GFX_NULL
width ,25
color ,0
cls
print "Drawing area (re)configured."
print "New dimensions are ";w;",";h
'here we resize the screen buffer
end sub
sub on_drawingarea_expose_event cdecl ( byval object as GtkObject Ptr, _
byval expose as GdkEventExpose Ptr, _
byval user_data as gpointer )
dim pixbuf as GdkPixbuf Ptr
dim gc as GdkGC Ptr
if h < 16 or w < 16 then print "too small; no drawing" : return 'no valid graphics mode yet
pixbuf=gdk_pixbuf_new_from_data(ScreenPtr, _
GDK_COLORSPACE_RGB, _
0, _
8, _
w, _
h, _
w*4, _
NULL, _
NULL)
gc = gdk_gc_new (expose->window)
gdk_pixbuf_render_to_drawable (pixbuf, _
expose->window, _
gc, _
0,0,0,0, _
w,h, _
GDK_RGB_DITHER_NORMAL, _
0,0)
gdk_pixbuf_unref(pixbuf)
gdk_gc_unref(gc)
end sub
dim window_widget as GtkWidget Ptr
gtk_init( NULL, NULL)
xml = glade_xml_new("gtkgfxlib.glade",NULL,NULL)
window_widget=glade_xml_get_widget( xml, "window")
gtk_widget_show_all( window_widget)
gtk_widget_set_size_request (glade_xml_get_widget(xml,"drawingarea"), 640, 480)
glade_xml_signal_autoconnect(xml)
gtk_main()
end 0