Destroy signal for gtkmm, please :-)



Hello, I've been able to solve the embedding of an SDL window into gtkmm.

The problem with gtkmm is that when you call main.run(window) the window for
 the SDL application won't get embedded.

If you use main.run() instead, you can embed it, but you cannot destroy your toplevel
window anymore, at least in an easy way.

My code is attached to this mail. The window works, and embeds SDL, but I can't destroy
the window after creating it.
#include <gtkmm/main.h>
#include <gtkmm/socket.h>
#include <gtkmm/box.h>
#include <gtkmm/window.h>
#include <SDL.h>
#include <cstdlib>
#include <stdexcept>
#include <sstream>
#include <cstdio>
#include <gtk/gtksocket.h>
#include <iostream>



class VentanaSDL
{
private:
	Gtk::Main main_;
	Gtk::Window window_;
	Gtk::VBox vbox_;
	Gtk::Socket socket_;
	SDL_Surface * superficie_;

public:

	
	VentanaSDL(int argc, char ** argv) : main_(&argc, &argv), superficie_(0), window_(Gtk::WINDOW_TOPLEVEL)
	{
		window_.set_title("Ventana SDL");
		window_.set_border_width(6);
		vbox_.pack_start(socket_, true, false);
		window_.add(vbox_);
	}

	void ejecutar()
	{
		

		window_.show_all_children();		

		std::stringstream sdlhack;
		sdlhack << "SDL_WINDOWID=" << socket_.get_id();
		std::cout << sdlhack.str().c_str() << '\n';		


		SDL_putenv(const_cast<char *>(sdlhack.str().c_str()));		

		if (SDL_Init(SDL_INIT_VIDEO))
			throw std::runtime_error("Error al inicializar la SDL");
		else
			superficie_ = SDL_SetVideoMode(480, 272, 0, 0);			
		
		main_.run();			
	}

	~VentanaSDL()
	{
		if (superficie_) SDL_FreeSurface(superficie_);
	}
};


int main(int argc, char ** argv)
{
	VentanaSDL app(argc, argv);

	app.ejecutar();
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]