Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em><code>a) SDL events are not received with this solution.</code></em><br> As the page mentions, the events are not received by SDL event loop but by Gtk event loop. So you can try capturing events through Gtk event loop.</p> <p><em><code>b) The frame buffer display is always put on the top left of the window (0,0) but I would actually like this display to show up somewhere in the middle on my window, with some buttons above and below.</code></em><br> This is possible. The hack which you are using, basically makes use of the fact that SDL (in case hardware not used directly) &amp; Gtk are dependent on the <a href="http://en.wikipedia.org/wiki/Windowing_system" rel="nofollow"><code>Windowing system</code></a> to display onto window &amp; more precisely on <a href="http://en.wikipedia.org/wiki/X11" rel="nofollow"><code>X11</code></a> on most Linux desktops. Thus window creation is done by <code>X</code> which has an XID, which SDL is using from the one created for <code>GtkWidget</code>. Currently you are using <code>GtkWindow</code>'s corresponding X window, instead if you use <a href="http://developer.gnome.org/gtk/2.24/GtkDrawingArea.html" rel="nofollow"><code>GtkDrawingArea</code></a>'s X window you can make the display as per your wish. Now to get the events, register callback. I tried to create a <a href="http://pastebin.com/16XyaJh7" rel="nofollow">mash up</a> where on clicking "Start SDL Animation", SDL animation starts &amp; clicking in the area of animation will trigger the <code>"button-release-event"</code> which prints the relative x &amp; y coordinates onto the console output but key events are not being received. Hopefully you can build up on this or use it for future reference (in case). </p> <p><em><code>Could you please tell me what kind of GtkWidget should be used to display my frame buffer inside a window?</code></em><br> You can look at <a href="http://developer.gnome.org/gtk/2.24/GtkDrawingArea.html" rel="nofollow"><code>GtkDrawingArea</code></a> which is meant for custom UI interfaces or <a href="http://developer.gnome.org/gtk/2.24/GtkImage.html" rel="nofollow"><code>GtkImage</code></a> with <a href="http://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-Image-Data-in-Memory.html" rel="nofollow"><code>GdkPixbuf</code></a> as few of the alternatives. You can see <code>gtk-demo</code> code or <a href="http://cairographics.org/threaded_animation_with_cairo/" rel="nofollow"><code>Cairo animation sample</code></a> to see how to proceed for your requirements. </p> <p><em><code>Does anyone also please know what function I could use in GTK to perform the same task as SDL_CreateRGBSurfaceFrom() (if it is even possible)?</code></em><br> For this you can have a look at <a href="http://developer.gnome.org/gdk-pixbuf/stable/" rel="nofollow"><code>GdkPixbuf</code></a>. It is possible to set raw data to <code>GdkPixbuf</code> &amp; the pixbuf can be used to create <code>GtkImage</code> and such which you can use for displaying. </p> <p><em><code>And finally, would you please link me to a way to get the x and y coordinates in the GtkWidget that gets clicked or moved in, and not the coordinates of the whole window, as well as keyboards input?</code></em><br> For mouse events you need to register callback for either <a href="http://developer.gnome.org/gtk/2.24/GtkWidget.html#GtkWidget-button-press-event" rel="nofollow"><code>"button-press-event"</code></a> or <a href="http://developer.gnome.org/gtk/2.24/GtkWidget.html#GtkWidget-button-release-event" rel="nofollow"><code>"button-release-event"</code></a>. The signal callback has a <a href="http://developer.gnome.org/gdk/stable/gdk-Event-Structures.html#GdkEvent" rel="nofollow"><code>GdkEvent</code></a> parameter. Typecast that in the callback to <a href="http://developer.gnome.org/gdk/stable/gdk-Event-Structures.html#GdkEventButton" rel="nofollow"><code>GdkEventButton</code></a> &amp; get the information which you need like relative x &amp; y coordinates etc.<br> For keyboard events you need to register callback for either <a href="http://developer.gnome.org/gtk/2.24/GtkWidget.html#GtkWidget-key-press-event" rel="nofollow"><code>"key-press-event"</code></a> or <a href="http://developer.gnome.org/gtk/2.24/GtkWidget.html#GtkWidget-key-release-event" rel="nofollow"><code>"key-release-event"</code></a>. The signal callback has a <a href="http://developer.gnome.org/gdk/stable/gdk-Event-Structures.html#GdkEvent" rel="nofollow"><code>GdkEvent</code></a> parameter. Typecast that in the callback to <a href="http://developer.gnome.org/gdk/stable/gdk-Event-Structures.html#GdkEventKey" rel="nofollow"><code>GdkEventKey</code></a> &amp; get the information which you need. Additionally for keyboard events the widget should be able to grab focus which you can enforce through the call <a href="http://developer.gnome.org/gtk/2.24/GtkWidget.html#gtk-widget-set-can-focus" rel="nofollow"><code>gtk_widget_set_can_focus</code></a><br> Hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload