I got it loading a Glade-Interface file, containing a DrawingArea, and the drawing in it works for me now
It can also react on mouse and resize events, though not on keyboard events. But that can be solved using GTK+ and global variables.
And you should set a frame limit if you want your app drawing certain times per second.
This is my code so far, hope it helps somebody:
#include <gtk/gtk.h>
#include <gdk/gdkwin32.h>
#include <stdio.h>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
sf::RenderWindow App;
unsigned char bvalue = 0x00;
void on_expose(GtkWidget *widget, GdkEventExpose *event, gpointer user)
{
//printf("Expose\n");
sf::Event Event;
while(App.GetEvent(Event))
{
if(Event.Type==sf::Event::Closed) printf("Closed.\n");
if(Event.Type==sf::Event::Resized) printf("Resized.\n");
if(Event.Type==sf::Event::MouseEntered) printf("Mouse Entered.\n");
if(Event.Type==sf::Event::MouseButtonPressed) printf("Mouse Button.\n");
if(Event.Type==sf::Event::KeyPressed) printf("Key Pressed.\n");
}
App.Clear(sf::Color(0, 192, bvalue++));
//App.Clear(sf::Color(0, 192, 255));
App.Display();
gtk_widget_queue_draw(widget);
}
int main(int argc, char **argv)
{
GtkBuilder *builder;
GtkWidget *window;
GError *error = NULL;
printf("Start\n");
gtk_init(&argc, &argv);
builder = gtk_builder_new();
printf("Read file\n");
if(!gtk_builder_add_from_file(builder, "interface.glade", &error))
{
printf("Error: %s\n", error->message);
//g_warning("%s", error->message);
//g_free(error);
return 1;
}
GtkWidget *area;
printf("Get window\n");
window = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
gtk_builder_connect_signals(builder, NULL);
area= GTK_WIDGET(gtk_builder_get_object(builder, "drawingarea1"));
gtk_widget_set_size_request(area, 32, 32);
gtk_widget_realize(area);
gtk_widget_set_double_buffered(area, false);
g_object_unref(G_OBJECT(builder));
App.Create(GDK_WINDOW_HWND(area->window));
App.SetFramerateLimit(60);
//App.SetSize(32, 32);
printf("Connect signal\n");
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
//g_signal_connect(area, "show", G_CALLBACK(on_show), NULL);
g_signal_connect(area, "expose-event", G_CALLBACK(on_expose), NULL);
printf("Show all\n");
gtk_widget_show_all(window);
printf("Main\n");
gtk_main();
printf("Exit\n");
return 0;
}
When the code will be working, it would be great to add it on the wiki.
Before anybody wants to add this code to the wiki or the tutorial page, please ensure that it really works for you!