Scale to fit

Todd Geist tg.lists at geistinteractive.com
Tue Oct 11 12:25:28 EDT 2005


Thanks for this tip

On 10/10/05 11:09 PM, "Ken Ray" <kray at sonsothunder.com> wrote:

> Here you go:
> 
> function stsScaleObject pOrigW,pOrigH,pMaxW,pMaxH
>   put pMaxW/pOrigW into tPctW
>   put pMaxH/pOrigH into tPctH
>   if tPctH < tPctW then
>     put pOrigH * tPctH into tNewH
>     put pOrigW * tPctH into tNewW
>   else
>     put pOrigH * tPctW into tNewH
>     put pOrigW * tPctW into tNewW
>   end if
>   return round(tNewW),round(tNewH)
> end stsScaleObject


I added the constraint of only scaling when necessary and this is what I
came up with

FUNCTION stsScaleObject pOrigW,pOrigH,pMaxW,pMaxH
   put pMaxW/pOrigW into tPctW
   put pMaxH/pOrigH into tPctH
   IF tPctH < tPctW THEN
      IF  tPctH < 1 THEN
         put pOrigH * tPctH into tNewH
         put pOrigW * tPctH into tNewW
      ELSE
         put pOrigH into tNewH
         put pOrigW into tNewW
      END if
   ELSE
      IF tPctW < 1 THEN
         put pOrigH * tPctW into tNewH
         put pOrigW * tPctW into tNewW
      ELSE
         put pOrigH into tNewH
         put pOrigW into tNewW
      END if
   END if
    
   return round(tNewW),round(tNewH)
END stsScaleObject


It could probably be optimized but it works

Thanks again

-- 

Todd Geist
______________________________________
g e i s t   i n t e r a c t i v e 





More information about the Use-livecode mailing list