文本控件可以淡入淡出

This commit is contained in:
MrZ626
2020-11-21 20:19:23 +08:00
parent 59fbb8106c
commit c38ef7c487

View File

@@ -19,6 +19,7 @@ local widgetMetatable={
local text={ local text={
type="text", type="text",
alpha=0,
} }
function text:reset() function text:reset()
if type(self.text)=="string"then if type(self.text)=="string"then
@@ -29,14 +30,26 @@ function text:reset()
self.font=self.font-10 self.font=self.font-10
end end
end end
function text:update()
if self.hideCon and self.hideCon()then
if self.alpha>0 then
self.alpha=self.alpha-.125
end
elseif self.alpha<1 then
self.alpha=self.alpha+.125
end
end
function text:draw() function text:draw()
gc.setColor(self.color) if self.alpha>0 then
if self.align=="M"then local c=self.color
gc.draw(self.text,self.x-self.text:getWidth()*.5,self.y) gc.setColor(c[1],c[2],c[3],self.alpha)
elseif self.align=="L"then if self.align=="M"then
gc.draw(self.text,self.x,self.y) gc.draw(self.text,self.x-self.text:getWidth()*.5,self.y)
elseif self.align=="R"then elseif self.align=="L"then
gc.draw(self.text,self.x-self.text:getWidth(),self.y) gc.draw(self.text,self.x,self.y)
elseif self.align=="R"then
gc.draw(self.text,self.x-self.text:getWidth(),self.y)
end
end end
end end
function WIDGET.newText(D)--name,x,y[,color][,font=30][,align="M"][,hide] function WIDGET.newText(D)--name,x,y[,color][,font=30][,align="M"][,hide]
@@ -47,9 +60,10 @@ function WIDGET.newText(D)--name,x,y[,color][,font=30][,align="M"][,hide]
color= D.color and(COLOR[D.color]or D.color)or COLOR.white, color= D.color and(COLOR[D.color]or D.color)or COLOR.white,
font= D.font or 30, font= D.font or 30,
align= D.align or"M", align= D.align or"M",
hide= D.hide, hideCon=D.hide,
} }
for k,v in next,text do _[k]=v end for k,v in next,text do _[k]=v end
if not _.hideCon then _.alpha=1 end
setmetatable(_,widgetMetatable) setmetatable(_,widgetMetatable)
return _ return _
end end