| View previous topic :: View next topic |
| Author |
Message |
cohort
Joined: 07 Feb 2006 Posts: 47
|
Posted: Wed Apr 05, 2006 10:54 pm Post subject: Scrolling/resizing a GtkImage object |
|
|
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
|
|
| Back to top |
|
 |
cohort
Joined: 07 Feb 2006 Posts: 47
|
Posted: Thu Apr 06, 2006 7:55 am Post subject: |
|
|
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
|
Posted: Thu Apr 06, 2006 8:01 am Post subject: |
|
|
| 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
|
Posted: Thu Apr 06, 2006 8:13 am Post subject: |
|
|
| 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
|
Posted: Thu Apr 06, 2006 8:18 am Post subject: |
|
|
| 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
|
Posted: Thu Apr 06, 2006 9:10 am Post subject: |
|
|
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
|
Posted: Thu Apr 06, 2006 1:05 pm Post subject: |
|
|
| Use the allocation property, it should have x and y subproperties. |
|
| Back to top |
|
 |
scott
Joined: 16 Feb 2006 Posts: 35
|
|
| Back to top |
|
 |
cohort
Joined: 07 Feb 2006 Posts: 47
|
Posted: Sun Apr 30, 2006 12:54 pm Post subject: |
|
|
| 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
|
Posted: Tue May 02, 2006 2:45 am Post subject: |
|
|
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
|
Posted: Tue May 02, 2006 3:05 pm Post subject: |
|
|
| 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
|
Posted: Wed May 03, 2006 12:31 am Post subject: |
|
|
| I manually resize the child object (a GtkImage), not the viewport. |
|
| Back to top |
|
 |
scott
Joined: 16 Feb 2006 Posts: 35
|
Posted: Wed May 03, 2006 2:38 pm Post subject: |
|
|
| 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
|
Posted: Thu May 04, 2006 3:36 am Post subject: |
|
|
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 |
|
 |
|