Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to intergrate with GTK+ interface?  (Read 14534 times)

0 Members and 2 Guests are viewing this topic.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
How to intergrate with GTK+ interface?
« on: October 31, 2010, 12:56:33 pm »
On the tutorial site I find tutorials for how to intergrate SFML with Win32, X11 or Qt interface, but why not GTK+? Is it not possible to intergrate it with? :( I really want to use GTK+, and not Qt...
Or is it possible? Can anybody tell me how to do?
Please note that my previous display name was "Shy Guy".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to intergrate with GTK+ interface?
« Reply #1 on: October 31, 2010, 01:00:17 pm »
It's probably possible, but I don't use GTK so I can't help you. However if you know the library it shouldn't be hard to find out.
Laurent Gomila - SFML developer

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
How to intergrate with GTK+ interface?
« Reply #2 on: October 31, 2010, 01:43:30 pm »
Quote from: "Laurent"
However if you know the library it shouldn't be hard to find out.

I'm quite new to GTK+, so it is a bit hard to find out ^^.
Do I need to get the window handle (for Windows HWND) from GTK+ to integrate? Or how about should I do it?
Please note that my previous display name was "Shy Guy".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to intergrate with GTK+ interface?
« Reply #3 on: October 31, 2010, 03:21:25 pm »
Quote
Do I need to get the window handle (for Windows HWND) from GTK+ to integrate?

Yes. Take a look at other sources (those for Qt, wxWidgets, ...) and try to do the same kind of stuff :lol:

The Qt example might be useful to you, there is some GTK related code in it because Qt is built on top of GTK on Linux.
Laurent Gomila - SFML developer

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
How to intergrate with GTK+ interface?
« Reply #4 on: October 31, 2010, 04:00:50 pm »
Quote from: "Laurent"
Quote
Do I need to get the window handle (for Windows HWND) from GTK+ to integrate?

Yes.

I get insane  :x Google is not on my side, I can't find out how to get the Win32 handle from a GtkWidget  :cry:
Please note that my previous display name was "Shy Guy".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to intergrate with GTK+ interface?
« Reply #5 on: October 31, 2010, 04:10:09 pm »
Sorry, I said "Qt" but I meant "wxWidgets" in my previous post.

The wxSFMLCanvas source code uses GDK_WINDOW_XWINDOW on the GtkWindow* to retrieve its system handle. Don't know if it works for all platforms, and if it is the right solution, but it might help you.

Quote
Google is not on my side, I can't find out how to get the Win32 handle from a GtkWidget

I just tried "get gtkwindow hwnd", and a lot of useful links are found. Just replace "hwnd" for other OSes.
Laurent Gomila - SFML developer

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
How to intergrate with GTK+ interface?
« Reply #6 on: October 31, 2010, 04:34:28 pm »
Quote from: "Laurent"
Quote
Google is not on my side, I can't find out how to get the Win32 handle from a GtkWidget

I just tried "get gtkwindow hwnd", and a lot of useful links are found. Just replace "hwnd" for other OSes.

I find those pages too, but for example when trying GDK_WINDOW_HWND() or something, I get "not declared" errors :(.
Please note that my previous display name was "Shy Guy".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to intergrate with GTK+ interface?
« Reply #7 on: October 31, 2010, 05:53:53 pm »
Did you include the corresponding header?
Laurent Gomila - SFML developer

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
How to intergrate with GTK+ interface?
« Reply #8 on: October 31, 2010, 05:58:18 pm »
Quote from: "Laurent"
Did you include the corresponding header?

I include, as I think only needed, <gtk/gtk.h>. More files are included by gtk.h I think. There are tons of includes so I can't simply try which include must be included by myself for that.
Please note that my previous display name was "Shy Guy".

Kknd

  • Newbie
  • *
  • Posts: 4
    • View Profile
How to intergrate with GTK+ interface?
« Reply #9 on: October 31, 2010, 06:22:00 pm »
Quote from: "Laurent"
Quote
Do I need to get the window handle (for Windows HWND) from GTK+ to integrate?

Yes. Take a look at other sources (those for Qt, wxWidgets, ...) and try to do the same kind of stuff :lol:

The Qt example might be useful to you, there is some GTK related code in it because Qt is built on top of GTK on Linux.


Qt isn't built on top of GTK on Linux, the only relation is a theme engine for Qt that uses GTK+ drawing code.

I think you can easily integrate SFML with GTK+ using the RenderWindow constructor that accepts the window handle as parameter and by properly redrawing the window at each frame.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to intergrate with GTK+ interface?
« Reply #10 on: October 31, 2010, 06:41:26 pm »
Quote
Qt isn't built on top of GTK on Linux, the only relation is a theme engine for Qt that uses GTK+ drawing code.

I corrected in my next post, I was talking about wxWidgets.

Quote
I think you can easily integrate SFML with GTK+ using the RenderWindow constructor that accepts the window handle as parameter and by properly redrawing the window at each frame.

Yah... this part is already clear, what we're trying to do is to get the window handle.
Laurent Gomila - SFML developer

Kknd

  • Newbie
  • *
  • Posts: 4
    • View Profile
How to intergrate with GTK+ interface?
« Reply #11 on: October 31, 2010, 06:59:13 pm »
Humm,

For Windows, you must call GDK_WINDOW_HWND passing the GdkWindow as parameter.

For others you must call GDK_DRAWABLE_XID passing the GdkDrawable (such as a GdkWindow) as parameter. GDK_WINDOW_XID() passing the GdkWindow should work too.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
How to intergrate with GTK+ interface?
« Reply #12 on: October 31, 2010, 08:15:59 pm »
Quote from: Kknd
Humm,

For Windows, you must call GDK_WINDOW_HWND passing the GdkWindow as parameter.

Quote from: Shy Guy
..., but for example when trying GDK_WINDOW_HWND() or something, I get "not declared" errors :(.
Even, if I include <gdk/gdk.h>.

EDIT:
Okay, I'm so far now:
#include <gtk/gtk.h>
#include <gdk/gdkwin32.h> // new
...
... GDK_WINDOW_HWND(gtk_widget_get_window(window));
...
 
Having the following libs linked:
-lgtk-win32-2.0 -lgobject-2.0 -lglib-2.0
And added this lib for GDK_WINDOW_HWND:
-lgdk-win32-2.0

The compiling and linking works. But when running the program, I get an error (translated in English):
Quote
The procedure entry "gtk_widget_get_window" couldn't be found in the DLL "libgtk-win32-2.0-0.dll".
What to do?


EDIT2:

Okay, I'm almost there.
#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;

void on_frame(void *user)
{
  App.Clear(sf::Color(0, 192, 255));
  App.Display();
}

int main(int argc, char **argv)
{
  GtkBuilder *builder;
  GtkWidget *window;
 
  gtk_init(&argc, &argv);
 
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
  //GDK_WINDOW_HWND(gtk_widget_get_window(window));
  App.Create(GDK_WINDOW_HWND(window->window));
  //gdk_win32_drawable_get_handle(window);
 
  g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
  g_signal_connect(window, "frame-event", G_CALLBACK(on_frame), NULL);
 
 
  gtk_widget_show_all(window);
 
 
  gtk_main();
 
  return 0;
}
 
But I'm not sure which signal to use, the window keeps grey.
« Last Edit: March 26, 2012, 08:14:16 pm by Shy Guy »
Please note that my previous display name was "Shy Guy".

Kknd

  • Newbie
  • *
  • Posts: 4
    • View Profile
How to intergrate with GTK+ interface?
« Reply #13 on: October 31, 2010, 10:53:45 pm »
You could put the Clear and Display code inside a "expose-event" window event and call gtk_widget_queue_draw on each frame.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
How to intergrate with GTK+ interface?
« Reply #14 on: October 31, 2010, 11:00:57 pm »
Quote from: Kknd
You could put the Clear and Display code inside a "expose-event" window event and call gtk_widget_queue_draw on each frame.
I have tried it with "expose-event" too. First without gtk_widget_queue_draw(), but tried it now, too.
#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;

void on_expose(GtkWidget *widget, GdkEventExpose *event, gpointer user)
{
  printf("Expose\n");
  App.Clear(sf::Color(0, 192, 255));
  App.Display();
  gtk_widget_queue_draw(widget);
}
void on_show(GtkWidget *widget, gpointer user)
{
  printf("Show\n");
  App.Clear(sf::Color(0, 192, 255));
  App.Display();
}

int main(int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *area;
 
  gtk_init(&argc, &argv);
 
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);
 
  area = gtk_drawing_area_new();
  //gtk_drawing_area_size(GTK_DRAWING_AREA(area), 640, 480);
  gtk_widget_set_size_request(area, 640, 480);
  //gtk_widget_realize(area);
  gtk_widget_set_double_buffered(area, false);
 
  gtk_container_add(GTK_CONTAINER(window), area);
 
  App.Create(GDK_WINDOW_HWND(area->window));
  App.SetSize(640, 480);
 
 
  g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
  //g_signal_connect(area, "frame-event", G_CALLBACK(on_frame), NULL);
  g_signal_connect(area, "expose-event", G_CALLBACK(on_expose), NULL);
  g_signal_connect(area, "show", G_CALLBACK(on_show), NULL);
 
 
  gtk_widget_show_all(window);
 
 
  gtk_main();
 
  return 0;
}
« Last Edit: March 26, 2012, 08:13:43 pm by Shy Guy »
Please note that my previous display name was "Shy Guy".