From: terencehill Date: Mon, 6 Feb 2012 22:03:53 +0000 (+0100) Subject: zoomSnapToTheBox make the zoomed in image snap to the box borders when zooming/draggi... X-Git-Tag: xonotic-v0.8.0~139^2~1^2~155^2~10 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=744f5e941e50c40589a62f0fe8a937ef429559eb;p=xonotic%2Fxonotic-data.pk3dir.git zoomSnapToTheBox make the zoomed in image snap to the box borders when zooming/dragging it --- diff --git a/qcsrc/menu/item/image.c b/qcsrc/menu/item/image.c index 4f13f997c..d7c0c90f5 100644 --- a/qcsrc/menu/item/image.c +++ b/qcsrc/menu/item/image.c @@ -15,6 +15,7 @@ CLASS(Image) EXTENDS(Item) ATTRIB(Image, zoomBox, float, 0) // used by forcedAspect -2 when the image is larger than the containing box ATTRIB(Image, zoomFactor, float, 1) ATTRIB(Image, zoomOffset, vector, '0.5 0.5 0') + ATTRIB(Image, zoomSnapToTheBox, float, 1) // snap the zoomed in image to the box borders when zooming/dragging it ATTRIB(Image, zoomTime, float, 0) ATTRIB(Image, zoomLimitedByTheBox, float, 0) // forbids zoom if image would be larger than the containing box ATTRIB(Image, zoomMax, float, 0) @@ -123,8 +124,23 @@ void Image_updateAspect(entity me) if(me.imgSize_x > 1 || me.imgSize_y > 1) { - me.zoomOffset_x = bound(0, me.zoomOffset_x, 1); - me.zoomOffset_y = bound(0, me.zoomOffset_y, 1); + if(me.zoomSnapToTheBox) + { + if(me.imgSize_x > 1) + me.zoomOffset_x = bound(0.5/me.imgSize_x, me.zoomOffset_x, 1 - 0.5/me.imgSize_x); + else + me.zoomOffset_x = bound(1 - 0.5/me.imgSize_x, me.zoomOffset_x, 0.5/me.imgSize_x); + + if(me.imgSize_y > 1) + me.zoomOffset_y = bound(0.5/me.imgSize_y, me.zoomOffset_y, 1 - 0.5/me.imgSize_y); + else + me.zoomOffset_y = bound(1 - 0.5/me.imgSize_y, me.zoomOffset_y, 0.5/me.imgSize_y); + } + else + { + me.zoomOffset_x = bound(0, me.zoomOffset_x, 1); + me.zoomOffset_y = bound(0, me.zoomOffset_y, 1); + } } else me.zoomOffset = '0.5 0.5 0';