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>

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);

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
Then you can intercept events on that box and what it contains.

Hope this helps.

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 mailing list

Reply via email to