Scale Gtk::Image

View: New views
9 Messages — Rating Filter:   Alert me  

Scale Gtk::Image

by Dimitri Holz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm doing a small program how show photos or make presentation of many
photos and it should scale Gtk::Image to the size of window. For showing
photos I use Gtk::Image, but I can't find a way to scaling it.


Thanks in advance!
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Scale Gtk::Image

by Daniel Elstner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am Freitag, den 26.06.2009, 09:47 +0200 schrieb Dimitri Holz:
> I'm doing a small program how show photos or make presentation of many
> photos and it should scale Gtk::Image to the size of window. For showing
> photos I use Gtk::Image, but I can't find a way to scaling it.

I think it will normally be just as large as the image it shows.  If you
want to display a scaled image, then load it into a Gdk::Pixbuf and
scale that.  I think there is even a method to load and scale an image
file at the same time.

Then just tell the Gtk::Image to display your scaled Gdk::Pixbuf.

--Daniel


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

Re: Scale Gtk::Image

by Murray Cumming :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 2009-06-26 at 17:44 +0200, Daniel Elstner wrote:

> Am Freitag, den 26.06.2009, 09:47 +0200 schrieb Dimitri Holz:
> > I'm doing a small program how show photos or make presentation of many
> > photos and it should scale Gtk::Image to the size of window. For showing
> > photos I use Gtk::Image, but I can't find a way to scaling it.
>
> I think it will normally be just as large as the image it shows.  If you
> want to display a scaled image, then load it into a Gdk::Pixbuf and
> scale that.  I think there is even a method to load and scale an image
> file at the same time.
>
> Then just tell the Gtk::Image to display your scaled Gdk::Pixbuf.

This is what I do in Glom:
http://git.gnome.org/cgit/glom/tree/glom/utility_widgets/imageglom.cc#n292

I call that scale() method in my expose_event handler.

--
murrayc@...
www.murrayc.com
www.openismus.com

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

Re: Scale Gtk::Image

by Daniel Elstner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am Freitag, den 26.06.2009, 18:07 +0200 schrieb Murray Cumming:

> On Fri, 2009-06-26 at 17:44 +0200, Daniel Elstner wrote:
> > Am Freitag, den 26.06.2009, 09:47 +0200 schrieb Dimitri Holz:
> > > I'm doing a small program how show photos or make presentation of many
> > > photos and it should scale Gtk::Image to the size of window. For showing
> > > photos I use Gtk::Image, but I can't find a way to scaling it.
> >
> > I think it will normally be just as large as the image it shows.  If you
> > want to display a scaled image, then load it into a Gdk::Pixbuf and
> > scale that.  I think there is even a method to load and scale an image
> > file at the same time.
> >
> > Then just tell the Gtk::Image to display your scaled Gdk::Pixbuf.
>
> This is what I do in Glom:
> http://git.gnome.org/cgit/glom/tree/glom/utility_widgets/imageglom.cc#n292
>
> I call that scale() method in my expose_event handler.

You override the expose_event handler of the Gtk::Image and set a new
pixbuf from in there?

That's bold. :-)

I'd try hooking into size_allocate() instead.

--Daniel


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

Re: Scale Gtk::Image

by José Alburquerque-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 2009-06-26 at 18:11 +0200, Daniel Elstner wrote:

> Am Freitag, den 26.06.2009, 18:07 +0200 schrieb Murray Cumming:
> > On Fri, 2009-06-26 at 17:44 +0200, Daniel Elstner wrote:
> > > Am Freitag, den 26.06.2009, 09:47 +0200 schrieb Dimitri Holz:
> > > > I'm doing a small program how show photos or make presentation of many
> > > > photos and it should scale Gtk::Image to the size of window. For showing
> > > > photos I use Gtk::Image, but I can't find a way to scaling it.
> > >
> > > I think it will normally be just as large as the image it shows.  If you
> > > want to display a scaled image, then load it into a Gdk::Pixbuf and
> > > scale that.  I think there is even a method to load and scale an image
> > > file at the same time.
> > >
> > > Then just tell the Gtk::Image to display your scaled Gdk::Pixbuf.
> >
> > This is what I do in Glom:
> > http://git.gnome.org/cgit/glom/tree/glom/utility_widgets/imageglom.cc#n292
> >
> > I call that scale() method in my expose_event handler.
>
> You override the expose_event handler of the Gtk::Image and set a new
> pixbuf from in there?
>
> That's bold. :-)
>
> I'd try hooking into size_allocate() instead.

For learning purposes, am I wrong in thinking that by the time the
Gtk::Image is exposed, its size has been allocated?  Is it the case that
in the allocation phase the widget is informed what its size must be
while in the expose phase the size has already been determined?  Sorry
if it's a dumb question.

--
José Alburquerque




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

Re: Scale Gtk::Image

by Daniel Elstner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am Freitag, den 26.06.2009, 14:46 -0400 schrieb José Alburquerque:
> On Fri, 2009-06-26 at 18:11 +0200, Daniel Elstner wrote:

> > You override the expose_event handler of the Gtk::Image and set a new
> > pixbuf from in there?
> >
> > That's bold. :-)
> >
> > I'd try hooking into size_allocate() instead.
>
> For learning purposes, am I wrong in thinking that by the time the
> Gtk::Image is exposed, its size has been allocated?  Is it the case that
> in the allocation phase the widget is informed what its size must be
> while in the expose phase the size has already been determined?

Yep, that's absolutely correct.  For the expose event to occur, the size
must have been allocated already.  Also, the Gdk::Window must exist. (Or
the Gdk::Window of the parent in case of a NO_WINDOW widget.)

So, yes, Murray's approach is fine in that regard. The code also avoids
rescaling the image if the widget size hasn't changed, so there is no
performance difference either.

I called it "bold" purely on my gut feeling that changing the logical
state of a widget while it is being drawn is asking for trouble.  The
expose event handler is supposed to draw a representation of the current
logical widget content, and not change the content.

Changing the logical content invalidates the widget area.  It doesn't
enter infinite recursion because invalidating a window only queues the
expose event for that area, instead of starting to draw right away.  But
my gut tells me it's not a good idea to do that sort of thing if you
don't have to. :-)

--Daniel


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

Re: Scale Gtk::Image

by Murray Cumming :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 2009-06-26 at 21:50 +0200, Daniel Elstner wrote:

> So, yes, Murray's approach is fine in that regard. The code also
> avoids
> rescaling the image if the widget size hasn't changed, so there is no
> performance difference either.
>
> I called it "bold" purely on my gut feeling that changing the logical
> state of a widget while it is being drawn is asking for trouble.  The
> expose event handler is supposed to draw a representation of the
> current
> logical widget content, and not change the content.

Maybe that optimization was to prevent an infinite loop. I forget. But
I'll fix it to work as you suggest.

--
murrayc@...
www.murrayc.com
www.openismus.com

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

Re: Scale Gtk::Image

by José Alburquerque-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 2009-06-26 at 21:50 +0200, Daniel Elstner wrote:

> Am Freitag, den 26.06.2009, 14:46 -0400 schrieb José Alburquerque:
> > For learning purposes, am I wrong in thinking that by the time the
> > Gtk::Image is exposed, its size has been allocated?  Is it the case that
> > in the allocation phase the widget is informed what its size must be
> > while in the expose phase the size has already been determined?
>
> Yep, that's absolutely correct.  For the expose event to occur, the size
> must have been allocated already.  Also, the Gdk::Window must exist. (Or
> the Gdk::Window of the parent in case of a NO_WINDOW widget.)
>
> So, yes, Murray's approach is fine in that regard. The code also avoids
> rescaling the image if the widget size hasn't changed, so there is no
> performance difference either.
>
> I called it "bold" purely on my gut feeling that changing the logical
> state of a widget while it is being drawn is asking for trouble.  The
> expose event handler is supposed to draw a representation of the current
> logical widget content, and not change the content.
>
> Changing the logical content invalidates the widget area.  It doesn't
> enter infinite recursion because invalidating a window only queues the
> expose event for that area, instead of starting to draw right away.  But
> my gut tells me it's not a good idea to do that sort of thing if you
> don't have to. :-)

Many thanks for the explanation.


--
José Alburquerque

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

Re: Scale Gtk::Image

by José Alburquerque-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 2009-06-26 at 17:03 -0400, José Alburquerque wrote:
> Many thanks for the explanation.

I wanted to add:  It really made it clear to me.

--
José Alburquerque


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