image: fix the image ratio calculation. Closes #71

This commit is contained in:
Mathieu Virbel 2011-02-26 13:29:21 +01:00
parent aaac31c6b3
commit b5f9d9592d
1 changed files with 9 additions and 14 deletions

View File

@ -100,22 +100,17 @@ class Image(Widget):
ratio = self.image_ratio ratio = self.image_ratio
w, h = self.size w, h = self.size
tw, th = self.texture.size tw, th = self.texture.size
iw, ih = 0, 0
# cases if the image is lower than the widget # ensure that the width is always maximized to the containter width
if iw < w and ih < h: iw = w if tw < w else w
if iw < w: # calculate the appropriate height
iw = w
ih = iw / ratio ih = iw / ratio
elif ih < h: # if the height is too higher, take the height of the container
ih = h # and calculate appropriate width. no need to test further. :)
iw = ih * ratio
# cases if the image is bigger than the widget
if iw > w:
iw = w
ih = iw * ratio
if ih > h: if ih > h:
ih = h ih = h
iw = ih / ratio iw = ih * ratio
return iw, ih return iw, ih