结合SDL的窗口和GTK +窗口在同一程序 [英] Combining SDL windows and GTK+ windows in the same program
问题描述
我创建和SDL方案,其中一些功能打开GTK +的窗口。主窗口是SDL的窗口和GTK +窗口大多对话框。在的main()
功能正常打开SDL窗口,并与SDL的事件,如一般在SDL一个,而
循环。有些SDL事件调用打开GTK +的窗户像GTK +的窗口通常被打开,并且具有相同的结构,功能的main()
在GTK +程序。
所有的窗户,因为他们应该打开,这个问题是关于关闭GTK +窗口。当我关闭GTK +的窗口,它保持打开,直到我关闭主窗口SDL。当我关闭GTK +窗口,它没有做任何事情,更它关闭后,所以例如,如果我将其最小化,然后再最大化这种情况发生的唯一的事情,它变空。当我关闭它,SDL的窗口也反应事件,因为它应该一样,如果不存在的GTK +窗口。所以一切都只是好像被关闭的GTK +窗口,但它仍然是可见的。我有一个 g_signal_connect(G_OBJECT(窗口),删除事件,G_CALLBACK(gtk_main_quit),NULL);在打开一个GTK +窗口中的每个功能
行,所以这不是问题
我怎么能这样做的GTK +窗口关闭而不是当我点击的GTK +窗口的关闭按钮的SDL窗口?
这是code的结构(GTK窗口是关于对话框这里):
的#include<&stdlib.h中GT;
#包括LT&;&stdio.h中GT;
#包括LT&; SDL / SDL.h>
#包括LT&; SDL / SDL_opengl.h>
#包括LT&; GL / gl.h>
#包括LT&; GL / glu.h>
#包括LT&; GTK / gtk.h>
#包括LT&;&math.h中GT;
#包括LT&;&time.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&文件ctype.h GT;
#包括LT&; SDL / SDL_image.h>
#包括LT&; SDL / SDL_ttf.h>
#包括LT&;&dirent.h GT;
#包括LT&;&unistd.h中GT;
#IFDEF WINDOWS
#包括LT&;&WINDOWS.H GT;
#万一无效openGtkWindow(){
GtkWidget的* aboutWindow = gtk_about_dialog_new();
//写的东西在关于窗口
g_signal_connect(G_OBJECT(aboutWindow),删除事件,G_CALLBACK(gtk_main_quit),NULL);
gtk_widget_show(aboutWindow);
进入主循环();
}INT主(INT ARGC,CHAR *的argv []){
gtk_init(安培; ARGC,&安培; argv的);
SDL_Surface *屏;
SDL_Event事件;
SDL_Init(SDL_INIT_VIDEO);
传给putenv(SDL_VIDEO_CENTERED =中心);
SDL_WM_SetCaption(SDL窗,NULL);
SDL_WM_SetIcon(IMG_Load(的icon.png),NULL);
屏幕= SDL_SetVideoMode(600,400,32,SDL_HWSURFACE | SDL_DOUBLEBUF);
//画出的东西在SDL窗口
SDL_Flip(屏);
INT continuer = 1;
而(continuer){
SDL_WaitEvent(安培;事件);
开关(event.type){
案例SDL_QUIT:
continuer = 0;
打破;
案例SDL_MOUSEBUTTONUP:
如果(event.button.button == SDL_BUTTON_LEFT){
如果(/ *测试鼠标是否关于按钮里面* /){
openGtkWindow();
}
}
打破;
}
}
SDL_QUIT();
返回0;
}
我认为你需要处理的GTK事件while循环(我asume你不叫进入主循环
你留在你的自定义,而
循环)。
您可以通过使用类似的东西这个做到这一点:
而(运行)
{
而(gtk_events_pending())//是否有GTK事件处理
gtk_main_iteration(); // - 如果是这样,处理它们 //你的SDL code
}
I'm creating and SDL program in which some functions open GTK+ windows. The main window is an SDL window and the GTK+ windows are mostly dialog boxes. The main()
function opens the SDL window normally and has a while
loop with SDL events like usually in SDL. Some SDL events call functions that open GTK+ windows like GTK+ windows usually are opened and that have the same structure as the main()
has in a GTK+ program.
All windows open as they should, the problem is about closing the GTK+ windows. When I close a GTK+ window, it stays opened until I close the main SDL window. The only thing that happens when I close the GTK+ window is that it doesn't do anything more after it's closed, so for example if I minimize it and then maximize it again, it becomes empty. When I close it, the SDL window also reacts to events as it should, like if the GTK+ window didn't exist. So everything is just as if the GTK+ window was closed except that it's still visible. I have a g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(gtk_main_quit),NULL);
line in each function that opens a GTK+ window, so that's not the problem.
How can I do so that the GTK+ window closes but not the SDL window when I click on the close button in the GTK+ window?
This is the structure of the code (the GTK window is an About dialog box here):
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <gtk/gtk.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <dirent.h>
#include <unistd.h>
#ifdef WINDOWS
#include <windows.h>
#endif
void openGtkWindow(){
GtkWidget *aboutWindow = gtk_about_dialog_new();
//Write things in the About window
g_signal_connect(G_OBJECT(aboutWindow),"delete-event",G_CALLBACK(gtk_main_quit),NULL);
gtk_widget_show(aboutWindow);
gtk_main();
}
int main(int argc,char *argv[]){
gtk_init(&argc,&argv);
SDL_Surface *screen;
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO);
putenv("SDL_VIDEO_CENTERED=center");
SDL_WM_SetCaption("SDL window",NULL);
SDL_WM_SetIcon(IMG_Load("icon.png"),NULL);
screen = SDL_SetVideoMode(600,400,32,SDL_HWSURFACE | SDL_DOUBLEBUF);
//Draw things in the SDL window
SDL_Flip(screen);
int continuer = 1;
while(continuer){
SDL_WaitEvent(&event);
switch(event.type){
case SDL_QUIT:
continuer = 0;
break;
case SDL_MOUSEBUTTONUP:
if(event.button.button == SDL_BUTTON_LEFT){
if(/*Test if the mouse is inside the About button*/){
openGtkWindow();
}
}
break;
}
}
SDL_Quit();
return 0;
}
I think you need to handle the GTK events in your while loop (I asume you do not call gtk_main
and you stay in your custom while
loop).
You can do this by using something similar to this:
while (running)
{
while (gtk_events_pending()) // are there GTK events to handle
gtk_main_iteration(); // - If so, handle them
// Your SDL Code
}
这篇关于结合SDL的窗口和GTK +窗口在同一程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!