DOGC移入GC拓展模块,GC.DO添加dRPol(圆角正多边形)命令
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
local setColor=love.graphics.setColor
|
||||
local printf=love.graphics.printf
|
||||
local draw=love.graphics.draw
|
||||
local gc=love.graphics
|
||||
local setColor=gc.setColor
|
||||
local printf=gc.printf
|
||||
local draw=gc.draw
|
||||
local GC={}
|
||||
function GC.str(obj,x,y)printf(obj,x-626,y,1252,'center')end
|
||||
function GC.simpX(obj,x,y)draw(obj,x-obj:getWidth()*.5,y)end
|
||||
@@ -31,4 +32,105 @@ function GC.shadedPrint(str,x,y,mode,d,clr1,clr2)
|
||||
setColor(clr2 or COLOR.Z)
|
||||
printf(str,x,y,w,mode)
|
||||
end
|
||||
do--function GC.DO(L)
|
||||
local cmds={
|
||||
origin="origin",
|
||||
move="translate",
|
||||
scale="scale",
|
||||
rotate="rotate",
|
||||
shear="shear",
|
||||
clear="clear",
|
||||
|
||||
setCL="setColor",
|
||||
setCM="setColorMask",
|
||||
setLW="setLineWidth",
|
||||
setLS="setLineStyle",
|
||||
setLJ="setLineJoin",
|
||||
|
||||
print="print",
|
||||
setFT=setFont,
|
||||
mText=GC.str,
|
||||
mDraw=GC.draw,
|
||||
mOutDraw=GC.outDraw,
|
||||
|
||||
draw="draw",
|
||||
line="line",
|
||||
fRect=function(...)gc.rectangle('fill',...)end,
|
||||
dRect=function(...)gc.rectangle('line',...)end,
|
||||
fCirc=function(...)gc.circle('fill',...)end,
|
||||
dCirc=function(...)gc.circle('line',...)end,
|
||||
fElps=function(...)gc.ellipse('fill',...)end,
|
||||
dElps=function(...)gc.ellipse('line',...)end,
|
||||
fPoly=function(...)gc.polygon('fill',...)end,
|
||||
|
||||
dPoly=function(...)gc.polygon('line',...)end,
|
||||
dRPol=function(x,y,R,segments,r,phase)
|
||||
local X,Y={},{}
|
||||
local ang=phase or 0
|
||||
local angStep=6.283185307179586/segments
|
||||
for i=1,segments do
|
||||
X[i]=x+R*math.cos(ang)
|
||||
Y[i]=y+R*math.sin(ang)
|
||||
ang=ang+angStep
|
||||
end
|
||||
X[segments+1]=x+R*math.cos(ang)
|
||||
Y[segments+1]=y+R*math.sin(ang)
|
||||
|
||||
local halfAng=6.283185307179586/segments/2
|
||||
local erasedLen=r*math.tan(halfAng)
|
||||
for i=1,segments do
|
||||
--Line
|
||||
local x1,y1,x2,y2=X[i],Y[i],X[i+1],Y[i+1]
|
||||
local dir=math.atan2(y2-y1,x2-x1)
|
||||
gc.line(x1+erasedLen*math.cos(dir),y1+erasedLen*math.sin(dir),x2-erasedLen*math.cos(dir),y2-erasedLen*math.sin(dir))
|
||||
|
||||
--Arc
|
||||
ang=ang+angStep
|
||||
local R2=R-r/math.cos(halfAng)
|
||||
local arcCX,arcCY=x+R2*math.cos(ang),y+R2*math.sin(ang)
|
||||
gc.arc('line','open',arcCX,arcCY,r,ang-halfAng,ang+halfAng)
|
||||
end
|
||||
end,
|
||||
|
||||
dPie=function(...)gc.arc('line',...)end,
|
||||
dArc=function(...)gc.arc('line','open',...)end,
|
||||
dBow=function(...)gc.arc('line','closed',...)end,
|
||||
fPie=function(...)gc.arc('fill',...)end,
|
||||
fArc=function(...)gc.arc('fill','open',...)end,
|
||||
fBow=function(...)gc.arc('fill','closed',...)end,
|
||||
}
|
||||
local sizeLimit=gc.getSystemLimits().texturesize
|
||||
function GC.DO(L)
|
||||
gc.push()
|
||||
::REPEAT_tryAgain::
|
||||
local success,canvas=pcall(gc.newCanvas,math.min(L[1],sizeLimit),math.min(L[2],sizeLimit))
|
||||
if not success then
|
||||
sizeLimit=math.floor(sizeLimit*.8)
|
||||
goto REPEAT_tryAgain
|
||||
end
|
||||
gc.setCanvas(canvas)
|
||||
gc.origin()
|
||||
gc.setColor(1,1,1)
|
||||
gc.setLineWidth(1)
|
||||
for i=3,#L do
|
||||
local cmd=L[i][1]
|
||||
if type(cmd)=='boolean'and cmd then
|
||||
table.remove(L[i],1)
|
||||
cmd=L[i][1]
|
||||
end
|
||||
if type(cmd)=='string'then
|
||||
local func=cmds[cmd]
|
||||
if type(func)=='string'then func=gc[func]end
|
||||
if func then
|
||||
func(unpack(L[i],2))
|
||||
else
|
||||
error("No gc command: "..cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
gc.setCanvas()
|
||||
gc.pop()
|
||||
return canvas
|
||||
end
|
||||
end
|
||||
return GC
|
||||
Reference in New Issue
Block a user