Code: Select all
local x,y,w,h,r,rx,ry = v:Layout() --[x,y]=pos [w,h]=size [r]=rotation [rx,ry]=pivot point offset+pos
if r ~= 0 then
love.graphics.translate(rx,ry) --translate draw operation
love.graphics.rotate(r)
love.graphics.translate(-rx,-ry)
--M3 Debug (global mouse pos):
GAME:AddDebugID("m3","M3: "..tostring( love.mouse.getX())..", "..tostring( love.mouse.getY()),1)
local s = sin(-r) --rotated local mousepos
local c = cos(-r)
v.mx,v.my = MousePos()
--M4 Debug ("local" mouse pos):
GAME:AddDebugID("m4","M4: "..tostring(v.mx)..", "..tostring( v.my ),1)
v.mx = v.mx - rx --translate mouse(?)
v.my = v.my - ry
v.mx = v.mx * c - v.my * s --rotate mouse
v.my = v.mx * s + v.my * c
v.mx = v.mx + rx --translate back(?)
v.my = v.my + ry
--M5 Debug (local mouse pos):
GAME:AddDebugID("m5","M5: "..tostring(v.mx)..", "..tostring( v.my ),1)
else
Code: Select all
function UIObj:Layout()
local p = self.Parent
if p then
local px,py=p:Layout()
return self.x+px , self.y+py , self.w, self.h, self.r, self.rx+self.x+px, self.ry+self.y+py
end
return self.x, self.y, self.w, self.h, self.r, self.rx+self.x, self.ry+self.y
end
red point is the mouse, the white is the local mouse pos(should be on 1 place), the blue is the pivot point (panel's center)
Top left are debug prints (M3-M5 from the code above,M1 and M2 were between the love.graphics.translate to verify that it has no effect on the mouse )
I'm sitting on this problem for 2 days now but I don't get it :/
Any ideas?