Re: Unable to capture mouse events of GtkGLArea
- From: Jim Charlton <charltn gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Re: Unable to capture mouse events of GtkGLArea
- Date: Mon, 2 Jul 2018 14:27:43 -0700
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
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]