升级SCR模块,整理大量坐标系变换代码
This commit is contained in:
@@ -45,12 +45,10 @@ THEME= require"Zframework.theme"
|
||||
local ms,kb=love.mouse,love.keyboard
|
||||
|
||||
local gc=love.graphics
|
||||
local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
|
||||
local gc_translate,gc_scale=gc.translate,gc.scale
|
||||
local gc_push,gc_pop,gc_clear=gc.push,gc.pop,gc.clear
|
||||
local gc_replaceTransform,gc_present=gc.replaceTransform,gc.present
|
||||
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
|
||||
local gc_draw,gc_line=gc.draw,gc.line
|
||||
local gc_print=gc.print
|
||||
local gc_draw,gc_line,gc_print=gc.draw,gc.line,gc.print
|
||||
|
||||
local setFont,mStr=setFont,mStr
|
||||
|
||||
@@ -79,7 +77,7 @@ local function updatePowerInfo()
|
||||
local state,pow=love.system.getPowerInfo()
|
||||
gc.setCanvas(infoCanvas)
|
||||
gc_push('transform')
|
||||
gc_origin()
|
||||
gc.origin()
|
||||
gc_clear(0,0,0,.25)
|
||||
if state~='unknown'then
|
||||
gc_setLineWidth(4)
|
||||
@@ -450,7 +448,7 @@ function love.errorhandler(msg)
|
||||
end
|
||||
gc_clear(.3,.5,.9)
|
||||
gc_push('transform')
|
||||
gc_replaceTransform(xOy)
|
||||
gc_replaceTransform(SCR.xOy)
|
||||
setFont(100)gc_print(":(",100,0,0,1.2)
|
||||
setFont(40)gc.printf(errorMsg,100,160,SCR.w0-100)
|
||||
setFont(20)
|
||||
@@ -572,15 +570,13 @@ function love.run()
|
||||
if FCT>=100 then
|
||||
FCT=FCT-100
|
||||
|
||||
--Draw background
|
||||
BG.draw()
|
||||
|
||||
gc.replaceTransform(xOy)
|
||||
--Draw scene contents
|
||||
gc_replaceTransform(SCR.origin)
|
||||
BG.draw()
|
||||
gc_replaceTransform(SCR.xOy)
|
||||
if SCN.draw then SCN.draw()end
|
||||
|
||||
--Draw widgets
|
||||
WIDGET.draw()
|
||||
SYSFX.draw()
|
||||
TEXT.draw()
|
||||
|
||||
--Draw cursor
|
||||
if mouseShow then
|
||||
@@ -592,52 +588,48 @@ function love.run()
|
||||
gc_setColor(1,1,1)
|
||||
gc_draw(ms.isDown(1)and cursor_holdImg or cursorImg,mx,my,nil,nil,nil,8,8)
|
||||
end
|
||||
SYSFX.draw()
|
||||
TEXT.draw()
|
||||
gc_origin()
|
||||
|
||||
--Draw power info.
|
||||
if SETTING.powerInfo then
|
||||
gc_setColor(1,1,1)
|
||||
gc_draw(infoCanvas,SCR.safeX,0,0,SCR.k)
|
||||
end
|
||||
|
||||
--Draw Logs
|
||||
LOG.draw()
|
||||
|
||||
gc_replaceTransform(SCR.origin)
|
||||
--Draw scene swapping animation
|
||||
if SCN.swapping then
|
||||
gc_setColor(1,1,1)
|
||||
_=SCN.stat
|
||||
_.draw(_.time)
|
||||
end
|
||||
|
||||
--Draw Logs
|
||||
LOG.draw()
|
||||
|
||||
gc_replaceTransform(SCR.xOy_dl)
|
||||
--Draw FPS
|
||||
setFont(15)
|
||||
_=SCR.h
|
||||
gc_setColor(1,1,1)
|
||||
gc_print(FPS(),SCR.safeX+5,_-20)
|
||||
gc_print(FPS(),SCR.safeX+5,-20)
|
||||
|
||||
--Debug info.
|
||||
if devMode then
|
||||
--Left-down infos
|
||||
gc_setColor(devColor[devMode])
|
||||
gc_print("MEM "..gcinfo(),SCR.safeX+5,_-40)
|
||||
gc_print("Lines "..FREEROW.getCount(),SCR.safeX+5,_-60)
|
||||
gc_print("Cursor "..int(mx+.5).." "..int(my+.5),SCR.safeX+5,_-80)
|
||||
gc_print("Voices "..VOC.getQueueCount(),SCR.safeX+5,_-100)
|
||||
gc_print("Tasks "..TASK.getCount(),SCR.safeX+5,_-120)
|
||||
gc_print("MEM "..gcinfo(),SCR.safeX+5,-40)
|
||||
gc_print("Lines "..FREEROW.getCount(),SCR.safeX+5,-60)
|
||||
gc_print("Cursor "..int(mx+.5).." "..int(my+.5),SCR.safeX+5,-80)
|
||||
gc_print("Voices "..VOC.getQueueCount(),SCR.safeX+5,-100)
|
||||
gc_print("Tasks "..TASK.getCount(),SCR.safeX+5,-120)
|
||||
|
||||
--Update & draw frame time
|
||||
ins(frameTimeList,1,dt)rem(frameTimeList,126)
|
||||
gc_setColor(1,1,1,.3)
|
||||
for i=1,#frameTimeList do
|
||||
gc.rectangle('fill',150+2*i,_-20,2,-frameTimeList[i]*4000)
|
||||
gc.rectangle('fill',150+2*i,-20,2,-frameTimeList[i]*4000)
|
||||
end
|
||||
|
||||
gc_replaceTransform(SCR.xOy_dr)
|
||||
--Websocket status
|
||||
gc_push('transform')
|
||||
gc_translate(SCR.w,SCR.h)
|
||||
gc_scale(SCR.k)
|
||||
for i=1,5 do
|
||||
local status=WS.status(WSnames[i])
|
||||
gc_setColor(WScolor[i])
|
||||
@@ -657,20 +649,12 @@ function love.run()
|
||||
gc_setColor(0,1,0,t2)gc.rectangle('fill',-40,20*i-100,-20,-20)
|
||||
gc_setColor(1,0,0,t3)gc.rectangle('fill',-20,20*i-100,-20,-20)
|
||||
end
|
||||
gc_pop()
|
||||
|
||||
--Slow devmode
|
||||
if devMode==3 then WAIT(.1)
|
||||
elseif devMode==4 then WAIT(.5)
|
||||
end
|
||||
end
|
||||
gc_translate(SCR.cx,SCR.h)
|
||||
gc_scale(SCR.k)
|
||||
gc_replaceTransform(SCR.xOy_dm)
|
||||
--Draw Version string
|
||||
gc_setColor(.8,.8,.8,.4)
|
||||
setFont(20)
|
||||
mStr(VERSION.string,0,-30)
|
||||
gc_origin()
|
||||
gc_present()
|
||||
|
||||
--SPEED UPUPUP!
|
||||
@@ -689,6 +673,11 @@ function love.run()
|
||||
end
|
||||
end
|
||||
|
||||
--Slow devmode
|
||||
if devMode==3 then WAIT(.1)
|
||||
elseif devMode==4 then WAIT(.5)
|
||||
end
|
||||
|
||||
--Keep 60fps
|
||||
_=TIME()-lastFrame
|
||||
if _<.016 then WAIT(.016-_)end
|
||||
|
||||
@@ -10,7 +10,19 @@ local SCR={
|
||||
rad=0, --Radius
|
||||
k=1, --Scale size
|
||||
dpi=1, --DPI from gc.getDPIScale()
|
||||
xOy=love.math.newTransform(),--Screen transformation object
|
||||
|
||||
--Screen transformation objects
|
||||
origin=love.math.newTransform(),
|
||||
xOy_m=love.math.newTransform(),
|
||||
xOy=love.math.newTransform(),
|
||||
xOy_ul=love.math.newTransform(),
|
||||
xOy_um=love.math.newTransform(),
|
||||
xOy_ur=love.math.newTransform(),
|
||||
xOy_ml=love.math.newTransform(),
|
||||
xOy_mr=love.math.newTransform(),
|
||||
xOy_dl=love.math.newTransform(),
|
||||
xOy_dm=love.math.newTransform(),
|
||||
xOy_dr=love.math.newTransform(),
|
||||
}
|
||||
function SCR.setSize(w,h)
|
||||
SCR.w0,SCR.h0=w,h
|
||||
@@ -32,7 +44,18 @@ function SCR.resize(w,h)
|
||||
SCR.cx,SCR.cy=SCR.w/2,SCR.h/2
|
||||
SCR.ex,SCR.ey=SCR.w-SCR.x,SCR.h-SCR.y
|
||||
SCR.safeX,SCR.safeY,SCR.safeW,SCR.safeH=love.window.getSafeArea()
|
||||
SCR.xOy:setTransformation(w/2,h/2,nil,SCR.k,nil,SCR.w0/2,SCR.h0/2)
|
||||
|
||||
SCR.origin:setTransformation(0,0)
|
||||
SCR.xOy:setTransformation(SCR.x,SCR.y,0,SCR.k)
|
||||
SCR.xOy_m:setTransformation(w/2,h/2,0,SCR.k)
|
||||
SCR.xOy_ul:setTransformation(0,0,0,SCR.k)
|
||||
SCR.xOy_um:setTransformation(w/2,0,0,SCR.k)
|
||||
SCR.xOy_ur:setTransformation(w,0,0,SCR.k)
|
||||
SCR.xOy_ml:setTransformation(0,h/2,0,SCR.k)
|
||||
SCR.xOy_mr:setTransformation(w,h/2,0,SCR.k)
|
||||
SCR.xOy_dl:setTransformation(0,h,0,SCR.k)
|
||||
SCR.xOy_dm:setTransformation(w/2,h,0,SCR.k)
|
||||
SCR.xOy_dr:setTransformation(w,h,0,SCR.k)
|
||||
end
|
||||
function SCR.info()
|
||||
return{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local gc=love.graphics
|
||||
local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
|
||||
local gc_clear,gc_origin=gc.clear,gc.origin
|
||||
local gc_translate,gc_replaceTransform=gc.translate,gc.replaceTransform
|
||||
local gc_setCanvas,gc_setBlendMode=gc.setCanvas,gc.setBlendMode
|
||||
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
|
||||
@@ -828,7 +828,7 @@ function inputBox:getInfo()
|
||||
end
|
||||
function inputBox:press()
|
||||
if MOBILE then
|
||||
local _,y1=SCR.xOy:transformPoint(0,self.y+self.h)
|
||||
local _,y1=xOy:transformPoint(0,self.y+self.h)
|
||||
kb.setTextInput(true,0,y1,1,1)
|
||||
end
|
||||
end
|
||||
@@ -1096,7 +1096,7 @@ function WIDGET.focus(W)
|
||||
if WIDGET.sel and WIDGET.sel.type=='inputBox'then kb.setTextInput(false)end
|
||||
WIDGET.sel=W
|
||||
if W and W.type=='inputBox'then
|
||||
local _,y1=SCR.xOy:transformPoint(0,W.y+W.h)
|
||||
local _,y1=xOy:transformPoint(0,W.y+W.h)
|
||||
kb.setTextInput(true,0,y1,1,1)
|
||||
end
|
||||
end
|
||||
@@ -1261,31 +1261,29 @@ function WIDGET.resize(w,h)
|
||||
widgetCanvas=gc.newCanvas(w,h)
|
||||
end
|
||||
function WIDGET.draw()
|
||||
gc_push('transform')
|
||||
gc_setCanvas(widgetCanvas)
|
||||
gc_clear(0,0,0,0)
|
||||
gc_replaceTransform(xOy)
|
||||
gc_translate(0,-WIDGET.scrollPos)
|
||||
for _,W in next,WIDGET.active do
|
||||
if not W.hide then W:draw()end
|
||||
gc_setCanvas(widgetCanvas)
|
||||
gc_clear(0,0,0,0)
|
||||
gc_translate(0,-WIDGET.scrollPos)
|
||||
for _,W in next,WIDGET.active do
|
||||
if not W.hide then W:draw()end
|
||||
end
|
||||
gc_origin()
|
||||
gc_setColor(1,1,1)
|
||||
if WIDGET.scrollHeight>0 then
|
||||
if WIDGET.scrollPos>0 then
|
||||
gc_draw(upArrowIcon,scr_w*.5,10,0,SCR.k,nil,upArrowIcon:getWidth()*.5,0)
|
||||
end
|
||||
gc_origin()
|
||||
gc_setColor(1,1,1)
|
||||
if WIDGET.scrollHeight>0 then
|
||||
if WIDGET.scrollPos>0 then
|
||||
gc_draw(upArrowIcon,scr_w*.5,10,0,SCR.k,nil,upArrowIcon:getWidth()*.5,0)
|
||||
end
|
||||
if WIDGET.scrollPos<WIDGET.scrollHeight then
|
||||
gc_draw(downArrowIcon,scr_w*.5,scr_h-10,0,SCR.k,nil,downArrowIcon:getWidth()*.5,downArrowIcon:getHeight())
|
||||
end
|
||||
gc_setBlendMode('multiply','premultiplied')
|
||||
gc_draw(widgetCover,nil,nil,nil,scr_w,scr_h/360)
|
||||
if WIDGET.scrollPos<WIDGET.scrollHeight then
|
||||
gc_draw(downArrowIcon,scr_w*.5,scr_h-10,0,SCR.k,nil,downArrowIcon:getWidth()*.5,downArrowIcon:getHeight())
|
||||
end
|
||||
gc_setCanvas()
|
||||
gc_setBlendMode('lighten','premultiplied')
|
||||
gc_draw(widgetCanvas)
|
||||
gc_setBlendMode('alpha')
|
||||
gc_pop()
|
||||
gc_setBlendMode('multiply','premultiplied')
|
||||
gc_draw(widgetCover,nil,nil,nil,scr_w,scr_h/360)
|
||||
end
|
||||
gc_setCanvas()
|
||||
gc_setBlendMode('lighten','premultiplied')
|
||||
gc_draw(widgetCanvas)
|
||||
gc_setBlendMode('alpha')
|
||||
gc_replaceTransform(SCR.xOy)
|
||||
end
|
||||
|
||||
return WIDGET
|
||||
Reference in New Issue
Block a user