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

Re: TODO item: proportional scaling



On Wed, 1 May 2002, Titus J. Anderson wrote:
> I was looking through the TODO file for dia and ran across the following:
> 
> * If you hold down shift while moving the handle of an 'Element',
>   scale while keeping same proportions.
> 
> So, I thought I'd try my hand at it. 

Excellent!  Somebody is actually *reading* that list:)

> It only works for boxes right now, but shouldn't be too difficult to make
> it work for the other basic objects.  Here's the patch for v0.88.1 (I'm
> not working with the CVS version at this point.)

Thank you!  We may hold off on applying it until the shortly upcoming new
release, as we're trying to stabilize Dia.
[...]

> I don't know that this is the best way to do this, but it does work.  The
> basic idea is in addition to the width and height, keep a copy of the
> aspect ratio of an element in the element object.  Then, when resizing,
> if the shift key is pressed, call the element_move_handle_aspect function
> rather than element_move_handle.  The element_move_handle function
> updates the aspect ratio when it's finished while
> element_move_handle_aspect does not, since it should be the same.  That's
> about it.  Just have to make sure that the aspect ratio is calculated
> anytime the height or width changes. 

Putting the aspect ratio calculation into foo_update_data is probably the
safest way.

> The only real trouble comes when
> the height or width is 0.  This is a little tricky and I used some ugly
> hacks to make it work.  Oh, I have to keep track of the ratio in the
> element (I guess you could keep it in the box, but then it can't be used
> in other objects) because if an object ever gets a width or height of
> zero, you don't want to recalculate the ratio.  Also, if you calculate
> the ratio everytime the move_handle method gets called, if the width goes
> to zero, the aspect ratio does as well, and then weird things start
> happening (I had what looked like 5 unconnected handles stuck to the side
> of the window.)

Here's a slightly alternative approach: Only keep the aspect ratio around
while resizing with ratio fixed.  Initialize the aspect ratio to -1, then
if we move with Shift, calculate the aspect ratio.  When changing the
coordinates, use the aspect ratio if != -1.  When moving stops, reset the
ratio to -1.  That should make sure that the aspect ratio is current
without needing changes all over.

-Lars

-- 
Lars Clausen (http://shasta.cs.uiuc.edu/~lrclause)| Hårdgrim of Numenor
"I do not agree with a word that you say, but I   |----------------------------
will defend to the death your right to say it."   | Where are we going, and
    --Evelyn Beatrice Hall paraphrasing Voltaire  | what's with the handbasket?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK