整理代码,微调debug模式输出点击位置的格式和widget模块的一个方法名

This commit is contained in:
MrZ626
2021-03-17 13:51:49 +08:00
parent 210e602057
commit 7ec1688825
4 changed files with 107 additions and 111 deletions

View File

@@ -106,14 +106,14 @@ function love.mousepressed(x,y,k,touch)
mouseShow=true
mx,my=xOy:inverseTransformPoint(x,y)
if devMode==1 then
DBP(("(%d,%d), D=(%d,%d)~~(%d,%d)(%d,%d)"):format(
DBP(("(%d,%d)<-%d,%d ~~(%d,%d)<-%d,%d"):format(
mx,my,
mx-lastX,my-lastY,
int(mx/10)*10,int(my/10)*10,
int((mx-lastX)/10)*10,int((my-lastY)/10)*10
))
end
if not SCN.swapping then
if SCN.swapping then return end
if SCN.mouseDown then
SCN.mouseDown(mx,my,k)
elseif k==2 then
@@ -125,9 +125,8 @@ function love.mousepressed(x,y,k,touch)
lastX,lastY=mx,my
SYSFX.newTap(3,mx,my,30)
end
end
function love.mousemoved(x,y,dx,dy,t)
if t then return end
function love.mousemoved(x,y,dx,dy,touch)
if touch then return end
mouseShow=true
mx,my=xOy:inverseTransformPoint(x,y)
if SCN.swapping then return end
@@ -136,16 +135,15 @@ function love.mousemoved(x,y,dx,dy,t)
if ms.isDown(1) then
WIDGET.drag(mx,my,dx,dy)
else
WIDGET.moveCursor(mx,my)
WIDGET.cursorMove(mx,my)
end
end
function love.mousereleased(x,y,k,touch)
if touch or SCN.swapping then return end
mx,my=xOy:inverseTransformPoint(x,y)
WIDGET.release(mx,my)
WIDGET.moveCursor(mx,my)
if SCN.mouseUp then SCN.mouseUp(mx,my,k)end
if lastX and SCN.mouseClick and(mx-lastX)^2+(my-lastY)^2<42 then
if lastX and SCN.mouseClick and(mx-lastX)^2+(my-lastY)^2<62 then
SCN.mouseClick(mx,my,k)
end
end
@@ -175,7 +173,7 @@ function love.touchmoved(id,x,y,dx,dy)
WIDGET.drag(x,y,dx,dy)
end
else
WIDGET.moveCursor(x,y)
WIDGET.cursorMove(x,y)
if not WIDGET.sel then
touching=false
end

View File

@@ -11,7 +11,7 @@ local _internal = {}-- list of internal profiler functions
local getInfo=debug.getinfo
function profile.hooker(event,line,info)
info = info or getInfo(2, 'fnS')
info=info or getInfo(2,"fnS")
local f=info.func
if _internal[f]then return end-- ignore the profiler itself
if info.name then _labeled[f]=info.name end-- get the function name if available
@@ -27,10 +27,10 @@ function profile.hooker(event, line, info)
_tcalled[f]=nil
end
if event=="tail call"then
local prev = getInfo(3, 'fnS')
local prev=getInfo(3,"fnS")
profile.hooker("return",line,prev)
profile.hooker("call",line,info)
elseif event == 'call' then
elseif event=="call"then
_tcalled[f]=clock()
else
_ncalls[f]=_ncalls[f]+1
@@ -39,7 +39,7 @@ end
--- Starts collecting data.
function profile.start()
if rawget(_G, 'jit') then
if jit then
jit.off()
jit.flush()
end
@@ -57,7 +57,7 @@ function profile.stop()
-- merge closures
local lookup={}
for f,d in next,_defined do
local id = (_labeled[f] or '?') .. d
local id=(_labeled[f]or"?")..d
local f2=lookup[id]
if f2 then
_ncalls[f2]=_ncalls[f2]+(_ncalls[f]or 0)
@@ -68,7 +68,7 @@ function profile.stop()
lookup[id]=f
end
end
collectgarbage('collect')
collectgarbage("collect")
end
--- Resets all collected data.
@@ -78,10 +78,10 @@ function profile.reset()
_telapsed[f]=0
_tcalled[f]=nil
end
collectgarbage('collect')
collectgarbage("collect")
end
function profile.comp(a, b)
local function _comp(a,b)
local dt=_telapsed[b]-_telapsed[a]
return dt==0 and _ncalls[b]<_ncalls[a]or dt<0
end
@@ -94,18 +94,16 @@ function profile.query(limit)
t[#t+1]=f
end
end
table.sort(t, profile.comp)
if limit then
while #t > limit do
table.remove(t)
end
end
table.sort(t,_comp)
if limit then while #t>limit do table.remove(t)end end
for i,f in ipairs(t)do
local dt=0
if _tcalled[f]then
dt=clock()-_tcalled[f]
end
t[i] = {i, _labeled[f] or '?', math.floor((_telapsed[f] + dt) * 1e6) / 1e6, _ncalls[f], _defined[f]}
t[i]={i,_labeled[f]or"?",math.floor((_telapsed[f]+dt)*1e6)/1e6,_ncalls[f],_defined[f]}
end
return t
end
@@ -119,22 +117,22 @@ function profile.report(n)
local s=tostring(row[j])
local l1,l2=#s,cols[j]
if l1<l2 then
s = s .. (' '):rep(l2 - l1)
s=s..(" "):rep(l2-l1)
elseif l1>l2 then
s=s:sub(l1-l2+1,l1)
end
row[j]=s
end
out[i] = table.concat(row, ' | ')
out[i]=table.concat(row," | ")
end
local row=" +-----+----------------------+----------+--------+----------------------------------+ \n"
local col=" | # | Function | Time | Calls | Code | \n"
local sz=row..col..row
if #out>0 then
sz = sz .. ' | ' .. table.concat(out, ' | \n | ') .. ' | \n'
sz=sz.." | "..table.concat(out," | \n | ").." | \n"
end
return '\n' .. sz .. row
return"\n"..sz..row
end
local switch=false

View File

@@ -1002,7 +1002,7 @@ function WIDGET.setLang(widgetText)
end
end
function WIDGET.moveCursor(x,y)
function WIDGET.cursorMove(x,y)
for _,W in next,WIDGET.active do
if not(W.hide==true or W.hide and W.hide())and W.resCtr and W:isAbove(x,y)then
WIDGET.sel=W