滑条和复选框控件支持lim属性限制文本宽度

This commit is contained in:
MrZ626
2021-09-16 02:29:58 +08:00
parent e1a820d1f9
commit 3714fea994

View File

@@ -177,7 +177,7 @@ function button:draw()
gc_rectangle('line',x-ATV+2,y-ATV+2,w+2*ATV-4,h+2*ATV-4,3)
end
--Object
--Drawable
local obj=self.obj
local y0=y+h*.5-ATV*.5
gc_setColor(1,1,1,.2+ATV*.05)
@@ -319,7 +319,7 @@ function key:draw()
gc_rectangle('fill',x,y,w,h,3)
end
--Object
--Drawable
gc_setColor(r,g,b)
if align=='M'then
mDraw(self.obj,x+w*.5,y+h*.5)
@@ -404,28 +404,29 @@ function switch:update()
end
end
function switch:draw()
local x,y=self.x,self.y-25
local x,y=self.x,self.y
local ATV=self.ATV
--Frame
gc_setLineWidth(2)
gc_setColor(1,1,1,.6+ATV*.1)
gc_rectangle('line',x,y,50,50,3)
gc_rectangle('line',x,y-25,50,50,3)
--Checked
if ATV>0 then
gc_setColor(1,1,1,ATV*.06)
gc_rectangle('fill',x,y,50,50,3)
gc_rectangle('fill',x,y-25,50,50,3)
end
if self.CHK>0 then
gc_setColor(.9,1,.9,self.CHK/6)
gc_setLineWidth(5)
gc_line(x+5,y+25,x+18,y+38,x+45,y+11)
gc_line(x+5,y,x+18,y+13,x+45,y-14)
end
--Drawable
local obj=self.obj
gc_setColor(self.color)
mDraw_Y(self.obj,x-12-ATV-self.obj:getWidth(),y+25)
gc_draw(obj,x-12-ATV,y,nil,min(self.lim/obj:getWidth(),1),1,obj:getWidth(),obj:getHeight()*.5)
end
function switch:getInfo()
return("x=%d,y=%d,font=%d"):format(self.x,self.y,self.font)
@@ -436,12 +437,13 @@ function switch:press()
SFX.play('move')
end
end
function WIDGET.newSwitch(D)--name,x,y[,fText][,color][,font=30][,sound=true][,disp],code[,hideF][,hide]
function WIDGET.newSwitch(D)--name,x,y[,lim][,fText][,color][,font=30][,sound=true][,disp],code[,hideF][,hide]
local _={
name= D.name or"_",
x= D.x,
y= D.y,
lim= D.lim or 1e99,
resCtr={
D.x+25,D.y,
@@ -552,9 +554,10 @@ function slider:draw()
end
--Drawable
if self.obj then
local obj=self.obj
if obj then
gc_setColor(self.color)
mDraw_Y(self.obj,x-12-ATV-self.obj:getWidth(),y)
gc_draw(obj,x-12-ATV,y,nil,min(self.lim/obj:getWidth(),1),1,obj:getWidth(),obj:getHeight()*.5)
end
end
function slider:getInfo()
@@ -597,13 +600,14 @@ end
function slider:arrowKey(k)
self:scroll((k=="left"or k=="up")and -1 or 1)
end
function WIDGET.newSlider(D)--name,x,y,w[,fText][,color][,unit][,smooth][,font=30][,change],disp[,show],code,hide
function WIDGET.newSlider(D)--name,x,y,w[,lim][,fText][,color][,unit][,smooth][,font=30][,change],disp[,show],code,hide
local _={
name= D.name or"_",
x= D.x,
y= D.y,
w= D.w,
lim= D.lim or 1e99,
resCtr={
D.x,D.y,
@@ -721,10 +725,10 @@ function selector:draw()
--Drawable
gc_setColor(self.color)
GC.simpX(self.obj,x+w*.5,y+17-21)
gc_draw(self.obj,x+w*.5,y-4,nil,min((w-20)/self.obj:getWidth(),1),1,self.obj:getWidth()*.5,0)
gc_setColor(1,1,1)
FONT.set(30)
mStr(self.selText,x+w*.5,y+43-21)
mStr(self.selText,x+w*.5,y+22)
end
function selector:getInfo()
return("x=%d,y=%d,w=%d"):format(self.x+self.w*.5,self.y+30,self.w)