本文介绍了SDL_Surface进入GTK窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在我的IT学校做一个项目,并与SDL一起工作(该项目是图像处理和类似的东西),目前我只用SDL显示图像而没有界面(按钮等)。我知道一些关于GTK的知识,所以我想知道是否可以在GTK窗口中显示一个图像(这里是一个SDL_Surface)
我做了一些研究,但没有什么是非常清楚的...
谢谢! 使用SDL绘图窗口小部件

使用SDL绘图功能绘制小部件(菜单,按钮等),并通过在事件发生期间(在执行事件时光标所在的项目)跟踪光标位置来处理操作。
这变得非常复杂,用一些简单的黑客来使用现有的GUI库会更好。你可以找到代码示例来绘制一个按钮找到类似的问题。



GTK插件



插件和插槽允许从一个进程嵌入小部件到另一个。 GTK将创建一个套接字并将套接字标识传递给SDL,SDL将从该套接字标识创建窗口。

事件循环处理
在将SDL与GTK合并后,您可能会发现gtk和sdl有自己的事件循环,不像预期的那样。为了解决这个问题,您可以在GTK中处理
事件,并在使用用户定义的事件时使用 SDL_PushEvent 函数将事件传播到SDL,反之亦然。

 

static SDL_Event SDLevent;
switch(event-> keyval)
{
case GDK_KEY_m:
SDLevent.type = SDL_KEYUP;
SDLevent.key.keysym.sym = SDLK_m;
SDL_PushEvent(& SDLevent);
休息;



对上述方法有很好的解释。


I'm currently making a project in my IT School and I work with SDL (The project is image processing and stuff like that), and currently I just display the image with SDL without interface (buttons etc...). I know a little bit about GTK so I want to know if I can display an image (here a SDL_Surface) into a GTK windowI made some research but nothing was very clear...Thank you !

解决方案

Drawing widgets using SDL

Drawing widgets(menu, buttons etc) using SDL drawing functions and handling actions by tracking the cursor position during the occurrence of event(on which item the cursor was while the event was performed).This becomes very complicated and would be better to use an existing GUI library with some simple hacks. You can find code example for drawing a button here.

Copying SDL surface into target GUI widget

This involves copying pixel by pixel(predefined functions might be available to do the same, gdk_draw_rgb_image in case of gtk) of the sdl surface into target gui widget(can be a drawingArea in case of GTK).

Merging SDL window into a GUI widget

In X11 and win32 systems each windows are given with a window id and by default sdl and gtk would have separate window id resulting two different windows, we can exploit SDL_CreateWindowFrom function to use single window for sdl and gtk in which we will force both the libraries to use a single window id.You can find similar question here.

GTK Plug and Socket

Plug and Socket enables embeeding widget from one process to another. GTK will create a socket and pass the socket id to SDL and SDL would create window from that socket ID.

Event loop handling:After merging SDL with GTK you might find gtk and sdl have their own event loops hence handling events might not be as expected. To solve that issue you can handleevents in GTK and propagate the event to SDL using SDL_PushEvent function and vice versa in case you are using user defined events.

.
.
static SDL_Event SDLevent;
switch(event->keyval)
{
    case GDK_KEY_m:
       SDLevent.type = SDL_KEYUP;
       SDLevent.key.keysym.sym = SDLK_m;
       SDL_PushEvent(&SDLevent);
       break;
       .
       .
       .

This link has a nice explanation for above methods.

这篇关于SDL_Surface进入GTK窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 11:24