gnope php gtk gui gnope.org  

Scrolling/resizing a GtkImage object

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Wed Apr 05, 2006 10:54 pm    Post subject: Scrolling/resizing a GtkImage object Reply with quote

I'm trying to build an app that requires having a viewport with a large image to be held within, resized to fit by default, scrolled if "zoomed in".

Is there any easy way to do it?

(I got the viewport scrolling worked out, I just need zooming)
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Apr 06, 2006 6:19 am    Post subject: Reply with quote

http://developer.gnome.org/doc/API/2.0/gdk-pixbuf/gdk-pixbuf-scaling.html
Back to top
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Thu Apr 06, 2006 7:55 am    Post subject: Reply with quote

In other words, "no."

So, how do I get the size of my viewport?

And yes, I did look through the docs.
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Apr 06, 2006 8:01 am    Post subject: Reply with quote

You can zoom it. The viewport will adjust itself if you add the image to it. You just need to scale the image correctly, and that's possible with the methods.
Back to top
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Thu Apr 06, 2006 8:13 am    Post subject: Reply with quote

cweiske wrote:
You just need to scale the image correctly

Which is why I need to know the size of my viewport (which can change if the user resizes the app)..
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Apr 06, 2006 8:18 am    Post subject: Reply with quote

get_size_request() doesn't help? Maybe there are width and height properties you can read.
Back to top
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Thu Apr 06, 2006 9:10 am    Post subject: Reply with quote

From the GTK docs: "the size request is not necessarily the size a widget will actually be allocated."

I can't find any "actual size" properties anywhere. Only found "requested size" properties, which are "not to be trusted"...
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Apr 06, 2006 1:05 pm    Post subject: Reply with quote

Use the allocation property, it should have x and y subproperties.
Back to top
scott



Joined: 16 Feb 2006
Posts: 35

PostPosted: Thu Apr 06, 2006 3:39 pm    Post subject: Reply with quote

Try the php-gtk-general mailing list. But check the archives first http://marc.theaimsgroup.com/?l=php-gtk-general&m=113964636202242&w=2
Back to top
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Sun Apr 30, 2006 12:54 pm    Post subject: Reply with quote

cweiske wrote:
Use the allocation property, it should have x and y subproperties.

That was it.

I created a little function to determine the scale while keeping the aspect ratio, and uploaded it to the gnope channel -- perhaps it may help out someone else, too.

I'll make a usage example later, I'm in a bit of a crunch now.
Back to top
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Tue May 02, 2006 2:45 am    Post subject: Reply with quote

Now the question is, how do I capture the resize event?

I tried:
Code:

$this->manip_viewport->connect("size-allocate", array($this, 'resize_imagewin'));

but get an infinite loop...

Shouldn't it only fire once?
Back to top
scott



Joined: 16 Feb 2006
Posts: 35

PostPosted: Tue May 02, 2006 3:05 pm    Post subject: Reply with quote

The signal should be fired once for each time the size is allocated. What is happening in your callback? Are you resizing the image again? Also, have you tried the 'size-request' signal? I think that is probably the better signal to use in this case.
Back to top
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Wed May 03, 2006 12:31 am    Post subject: Reply with quote

I manually resize the child object (a GtkImage), not the viewport.
Back to top
scott



Joined: 16 Feb 2006
Posts: 35

PostPosted: Wed May 03, 2006 2:38 pm    Post subject: Reply with quote

Yes but when you resize the child, doesn't the view port get resized? A container's size is determined by the size of its children. And when you resize a container, the resizing is propogated to its children. I think you are inadvertenly creating an infinite loop by setting a size while setting a size.
Back to top
cohort



Joined: 07 Feb 2006
Posts: 47

PostPosted: Thu May 04, 2006 3:36 am    Post subject: Reply with quote

It does the same thing using both signals ('size-allocation' and 'size-request').

However, you pointed me in the right direction -- I put a test in the resize-imagewin() function that checks to see if the size of the viewport has changed -- if no, it "returns" having done nothing. (basically, checks to see if either height OR width matches -- if it does, it doesn't need to be resized.)

Problem fixed.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.