Posted on 2012-05-21 16:05
点点滴滴 阅读(693)
评论(0) 编辑 收藏 引用
--当前缩放系数 scale
--平移向量 offset=(ox, oy)
--鼠标中心位置 pos=(px, py), 缩放系数 factor
--offset‘ = offset * factor + pos * (1 - factor)
--scale' = scale * factor
local area = draginfo.params.window:getArea()
local destpos = WE.UICoordConverter:windowToRelative(draginfo.params.window:getParent(), pos)
local srcpos = draginfo.params.window:getPosition()
local width = area:getWidth() .mScale * scale
local height = area:getHeight().mScale * scale
local posx = srcpos.mX.mScale * scale + destpos.mX.mScale * (1 - scale)
local posy = srcpos.mY.mScale * scale + destpos.mY.mScale * (1 - scale)
--最大
if (width > draginfo.params.maxscalex) or (height > draginfo.params.maxscaley) then --
local stdscale=draginfo.params.maxscalex / area:getWidth().mScale
width = area:getWidth() .mScale * stdscale
height = area:getHeight().mScale * stdscale
posx = srcpos.mX.mScale * stdscale + destpos.mX.mScale * (1 - stdscale)
posy = srcpos.mY.mScale * stdscale + destpos.mY.mScale * (1 - stdscale)
--最小
elseif (width < draginfo.params.minscalex) or (height < draginfo.params.minscaley) then --
local stdscale=draginfo.params.minscalex / area:getWidth().mScale
width = area:getWidth() .mScale * stdscale
height = area:getHeight().mScale * stdscale
posx = srcpos.mX.mScale * stdscale + destpos.mX.mScale * (1 - stdscale)
posy = srcpos.mY.mScale * stdscale + destpos.mY.mScale * (1 - stdscale)
end
--校正
if (posx > 0) then posx = srcpos.mX.mScale end
if (posy > 0) then posy = srcpos.mY.mScale end
if posx + width < 1 then posx = 1 - width end
if posy + height < 1 then posy = 1 - height end
local newarea = WE.UIRect(WE.UIDim(posx, 0), WE.UIDim(posy, 0 ), WE.UIDim(posx + width, 0), WE.UIDim(posy + height, 0))