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

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

0 Members and 1 Guest are viewing this topic.

Canadadry

  • Hero Member
  • *****
  • Posts: 1081
    • View Profile
How to intergrate with GTK+ interface?
« Reply #15 on: October 31, 2010, 11:53:33 pm »
When the code will be working, it would be great to add it on the wiki.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
It works... !
« Reply #16 on: November 01, 2010, 01:30:10 pm »
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;
}

Quote from: mooglwy
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!
« Last Edit: March 26, 2012, 08:13:18 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 #17 on: November 01, 2010, 01:40:48 pm »
Ah yes, if you wanna draw directly on a window you must set the "app-paintable" property to true (or you can use a DrawingArea too, as exemplified by Shy Guy).

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
How to intergrate with GTK+ interface?
« Reply #18 on: November 01, 2010, 01:58:08 pm »
Quote from: "Kknd"
Ah yes, if you wanna draw directly on a window you must set the "app-paintable" property to true (or you can use a DrawingArea too, as exemplified by Shy Guy).

Yeah, I also was around the "app-paintable", but I didn't reached the aim anyhow.

EDIT:
By the way, does anybody know how to set the property of a widget? I didn't find out.
--------- End of edit ---------

Anyway, if you get working the code above feel free to use any part of it for a tutorial for SFML ;)

When I have the time before, I might write it myself, but currently I'm busy ^^
Please note that my previous display name was "Shy Guy".