Unable to capture mouse events of GtkGLArea

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to capture mouse events of GtkGLArea

foobar31415
Hey list,

I'm writing a small toy application that uses OpenGL. Actually
converting it from GLUT to GTK/GL. I'm using a glade 3.22.1 generated UI
with Gtk 3.22.30 from Python3.

I'm having two issues: The more pressing one is that I cannot seem to
figure out how to capute mouse events on my GtkGLArea. I've tried a
bunch of different settings, enabled all events, played with can
focus/can default/receives default and hooked button-press-event,
drag-begin, enter-notify-event, event, key-press-event,
motion-notify-event, etc -- none of which fire. They seem to be caught
by the main window (I testwise hooked those for the main window). But I
want to receive coordinates relative to the GL drawing area (obviously),
but don't know what I'm doing wrong. The hierarchy is GtkWindow ->
GtkBox -> GTKGLArea (if that matters). Any advice on how to set this up?

Another question related to the GtkGLArea is that I would like to create
a pixmap copy of a rendered image (to be able to save it as PNG, for
example) -- is that at all possible?

And thirdly (and completely independent), is it possible to have the
rendered text of a GtkScale use markup? I want to show
"10<sup>%.1f</sup>", but it only shows up as literal text, not
interpreting the markup.

Thanks for helping out!
All the best,
Joe
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Unable to capture mouse events of GtkGLArea

foobar31415
On 02.07.2018 22:11, Johannes Bauer wrote:

> I'm writing a small toy application that uses OpenGL. Actually
> converting it from GLUT to GTK/GL. I'm using a glade 3.22.1 generated UI
> with Gtk 3.22.30 from Python3.

So that you can see what I'm doing (wrong), here's the full source code
of my stuff:

https://github.com/johndoe31415/pygpufractal

In particular, this is my UI definition:

https://github.com/johndoe31415/pygpufractal/blob/master/gpufractal.glade

And this the very simple UI code:

https://github.com/johndoe31415/pygpufractal/blob/master/gtkfractal.py

Any help is greatly appreciated.

Thank you so much,
Cheers,
Joe

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Unable to capture mouse events of GtkGLArea

Chris Moller-3
Some years ago, I used GtkGlArea in C with:

--------------------------------------------

GtkWidget *gl_area = gtk_gl_area_new ();

gtk_widget_add_events (gl_area, GDK_BUTTON_PRESS_MASK);
g_signal_connect (gl_area, "button-press-event",
                     G_CALLBACK (button_press), molecule);

static gboolean
button_press (GtkWidget *widget,
               GdkEvent  *event,
               gpointer   user_data)
{
   g_print ("button press\n");
}

-------------------------------------------

I'm not all that familiar with Python, but it looks like your code does
the same thing except possibly that you seem to be setting the event
mask rather than adding to it.


On 02/07/18 16:34, Johannes Bauer wrote:

> On 02.07.2018 22:11, Johannes Bauer wrote:
>
>> I'm writing a small toy application that uses OpenGL. Actually
>> converting it from GLUT to GTK/GL. I'm using a glade 3.22.1 generated UI
>> with Gtk 3.22.30 from Python3.
> So that you can see what I'm doing (wrong), here's the full source code
> of my stuff:
>
> https://github.com/johndoe31415/pygpufractal
>
> In particular, this is my UI definition:
>
> https://github.com/johndoe31415/pygpufractal/blob/master/gpufractal.glade
>
> And this the very simple UI code:
>
> https://github.com/johndoe31415/pygpufractal/blob/master/gtkfractal.py
>
> Any help is greatly appreciated.
>
> Thank you so much,
> Cheers,
> Joe
>
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
>

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Unable to capture mouse events of GtkGLArea

Gtk+ - Apps Dev mailing list
In reply to this post by foobar31415
Joe:

I program in Gtkmm so my advice may not be applicable but...

What I do to get a png file of an image is to

1. Get a pointer to the cairo context (cr) from what is passed to the
on_draw() callback from your image widget.

2. in the callback, execute cr->pop_group_to_source();

3. create a pointer to a Cairo pattern Cairo::RefPtr<Cairo::Pattern>
pattern_;

4 execute pattern_ = get_source();

5. Execute the following code.

    Cairo::Format format = Cairo::FORMAT_RGB24;
    Cairo::RefPtr<Cairo::ImageSurface> image_surf_ptr =
Cairo::ImageSurface::create(format, width, height);
    Cairo::RefPtr< Cairo::Context > image_context_ptr_ =
Cairo::Context::create (image_surf_ptr);
    image_context_ptr_->set_source_rgb(0.9, 0.9, 0.9);
    image_context_ptr_->paint();
    image_context_ptr_->set_source(pattern_);
    image_context_ptr_->paint();
    image_surf_ptr->write_to_png("test.png");

I am not sure that the center two lines are necessary.  And you have to
get the height and width of your image to use in line 2.
But maybe this will give you some ideas.

For capturing events, I enclose my image area in a Gtk::EventBox and set
events on the eventbox
add_events(Gdk::EXPOSURE_MASK|
         Gdk::BUTTON_PRESS_MASK|
         Gdk::BUTTON_RELEASE_MASK|
         Gdk::POINTER_MOTION_MASK|
         Gdk::POINTER_MOTION_HINT_MASK|
         Gdk::ENTER_NOTIFY_MASK|
         Gdk::LEAVE_NOTIFY_MASK);
Then you can intercept events on that box and what it contains.

Hope this helps.
jim...


On 07/02/2018 01:11 PM, Johannes Bauer wrote:

> Hey list,
>
> I'm writing a small toy application that uses OpenGL. Actually
> converting it from GLUT to GTK/GL. I'm using a glade 3.22.1 generated UI
> with Gtk 3.22.30 from Python3.
>
> I'm having two issues: The more pressing one is that I cannot seem to
> figure out how to capute mouse events on my GtkGLArea. I've tried a
> bunch of different settings, enabled all events, played with can
> focus/can default/receives default and hooked button-press-event,
> drag-begin, enter-notify-event, event, key-press-event,
> motion-notify-event, etc -- none of which fire. They seem to be caught
> by the main window (I testwise hooked those for the main window). But I
> want to receive coordinates relative to the GL drawing area (obviously),
> but don't know what I'm doing wrong. The hierarchy is GtkWindow ->
> GtkBox -> GTKGLArea (if that matters). Any advice on how to set this up?
>
> Another question related to the GtkGLArea is that I would like to create
> a pixmap copy of a rendered image (to be able to save it as PNG, for
> example) -- is that at all possible?
>
> And thirdly (and completely independent), is it possible to have the
> rendered text of a GtkScale use markup? I want to show
> "10<sup>%.1f</sup>", but it only shows up as literal text, not
> interpreting the markup.
>
> Thanks for helping out!
> All the best,
> Joe
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list