RE: Images in GTKmm



Harry,

I tried that originally, but I got complier errors:

‘class Gdk::Pixbuf’ has no member named ‘render_to_drawable’
‘get_style’ was not declared in this scope
‘RGB_DITHER_NONE’ is not a member of ‘Gdk’

(I'm including <gtkmm.h> and <gdkmm.h> and compiling with: g++ `pkg-config gtkmm-3.0 --cflags --libs`)

I had a look in Pixbuf reference (http://developer.gnome.org/gtkmm/unstable/classGdk_1_1Pixbuf.html) and couldn't see any reference to render_to_drawable. I also couldn't find this in the headers or any of the widgets it's derived from. The gdkmm/gdk/pixbf.h had the comment:

//Use Gdk::Drawable::draw_pixbuf() instead of gdk_pixbuf_render_to_drawable(), gdk_pixbuf_render_to_drawable_alpha().

Any ideas?

From: Harry van Haaren [harryhaaren gmail com]
Sent: 02 August 2011 21:02
To: Thomas Harty
Cc: Yann LEYDIER; gtkmm-list gnome org
Subject: Re: Images in GTKmm

Hi Thomas,

Gtk 3 uses Cairo for its drawing backend, so one option would be to subclass Gtk::DrawingArea, and then load a .png or so with Cairo, and copy that to the cairo surface (& hence the Gtk::DrawingArea), after which you can display the DrawingArea as a normal widget.

Another option is to use Gdk::Pixbuf and friends. This might be the easier option, but provides less flexibility.

This link provides up to date (ie: Gtk3) info on both:
See this link: http://developer.gnome.org/gtkmm-tutorial/3.0/sec-draw-images.html.en

Good luck! -Harry



On Tue, Aug 2, 2011 at 6:49 PM, Thomas Harty <t harty1 physics ox ac uk> wrote:
Thanks. It looks like these won't work in gtkmm3. E.g. the "Changes in gtkmm 3" notes:

9. Gdk::Pixmap and Gdk::Bitmap were removed in favour of Gdk::Pixbuf.

I had a look in the Gdk::window api (http://developer.gnome.org/gtkmm/stable/classGdk_1_1Window.html), but couldn't see a draw_drawable method.

Any idea how to do this in gtkmm3?

Tom
________________________________________
From: gtkmm-list-bounces gnome org [gtkmm-list-bounces gnome org] on behalf of Yann LEYDIER [yann leydier info]
Sent: 02 August 2011 18:19
To: gtkmm-list gnome org
Subject: Re: Images in GTKmm

I'm not using Gtkmm 3, but you might have to use cairomm to do that.

In Gtkmm 2, I render the Pixbuf to a Pixmap and then use
Gdk::Window::draw_drawable on the DrawingArea's Gdk window. Perhaps it
still works in API 3…


yann

On 02/08/11 19:05, Thomas Harty wrote:
> Thank you for the reply.
>
> I tried following the example here: http://developer.gnome.org/gtkmm-tutorial/3.0/sec-draw-images.html.en to test out using a Pixbuf in a Drawing area, but got a few compile-time errors (n.b. I'm using gtkmm 3.0):
>
> error: ‘class Gdk::Pixbuf’ has no member named ‘render_to_drawable’
> error: ‘get_style’ was not declared in this scope
> error: ‘RGB_DITHER_NONE’ is not a member of ‘Gdk’
>
> I had a look in the class reference (http://developer.gnome.org/gtkmm/3.1/classGdk_1_1Pixbuf.html) and couldn't see render_to_drawable. Has this been depreciated in gtkmm 3? If so, what's the appropriate way to do this now?
>
> Tom
>
>
>
> ________________________________________
> From: gtkmm-list-bounces gnome org [gtkmm-list-bounces gnome org] on behalf of Yann LEYDIER [yann leydier info]
> Sent: 02 August 2011 16:29
> To: gtkmm-list gnome org
> Subject: Re: Images in GTKmm
>
> I would do this with a DrawingArea. It is possible to resize a Pixbuf to
> the size of the DrawingArea and render it in a callback plugged to the
> expose_event signal.
>
> But I don't known if it is the best way! ;)
> yann
>
> On 02/08/11 12:51, Thomas Harty wrote:
>> I want to put an image into a box in such a way that the image will
>> shrink to fit into empty space in the box, whilst preserving its aspect
>> ratio. Thus, the dimensions of the image should be determined by the
>> dimensions of the objects around it. The image needs to shrink and
>> expand with the box (e.g. if the user re-sizes the main window).
>>
>> For example, I want to put a few items in a VBox and have these items
>> determine the width of the VBox. I then want to be able to add the image
>> to the VBox in such a way that it doesn't resize the box, but rather
>> fits into the space. If there is space left above/below the widget (due
>> to the constraint of preserving it's aspect ratio), this should be
>> filled with padding, rather than the image expanding to fill the space.
>>
>> What's the best way of accomplishing this in Gtkmm?
>>
>> Tom
>>
>>
>>
>> _______________________________________________
>> gtkmm-list mailing list
>> gtkmm-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]