Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacing SDL with GTK+ for mouse and keyboard and displaying a frame buffer
    primarykey
    data
    text
    <p>I started building my program with SDL. I am using SDL to render a frame buffer live on the screen and also looking for user input from the keyboard and the mouse.</p> <p>I have been using the following code to display a 5-6-5 RGB frame buffer on the screen.</p> <pre><code>SDL_Surface* screen = SDL_SetVideoMode(width, height, bitsPerPixel, SDL_SWSURFACE); SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(frameBuffer, width, height, depth, lineWidth, Rmask, Gmask, Bmask, Amask); SDL_BlitSurface(surface, NULL, screen, NULL); SDL_Flip(screen); </code></pre> <p>Note that Rmask, Gmask and Bmask and Amask are all 0. I am using SDL's default masking.</p> <p>For the keyboard and mouse, I have been using the following code:</p> <pre><code>while (run) { SDL_WaitEvent(&amp;event); switch (event.type) { // Key is pressed case SDL_KEYDOWN: map&lt;int, int&gt;::iterator it = SDLToAndroid.find(event.key.keysym.sym); if (it != SDLToAndroid.end()) { /* ... */ } break; case SDL_MOUSEBUTTONDOWN: // Left click if (event.button.button == SDL_BUTTON_LEFT) { /* ... */ } break; </code></pre> <p>Where for keypresses I look them up in map to convert them to some other keys.</p> <p>This works great, but I would like to use the capabilities of GTK (in terms of UI). I started including SDL into my GTK+ window using putenv environment (<a href="http://sdl.beuc.net/sdl.wiki/FAQ_GUI" rel="nofollow">The SDL_WINDOWID hack</a>) but I have two problems:</p> <p>a) SDL events are not received with this solution. 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.</p> <p>I am thinking of getting rid of SDL and just use GTK+ itself. There are a few things that I would please like to ask you, as I am very new with GTK+.</p> <p>Could you please tell me what kind of GtkWidget should be used to display my frame buffer inside a window? 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)? 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?</p> <p>(I have found some solution for the mouse and keyboard. I've seen the "configure-event" used to get the x and y values, but I am not sure if this event works on any GtkWidget. Also for keyboard, what I have found is to use "activate", but I'd like to be confirmed this is the right approach.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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