Custom image from clipboard (#1157)
* Update how text renders in button and key * Add a placeholder * Add actual code and language entry * Sort buttons * Alter to keep original behaviour * I HAVE OCD * Add back legacy behaviour
This commit is contained in:
@@ -15,6 +15,7 @@ local timer=love.timer.getTime
|
||||
local next=next
|
||||
local floor,ceil=math.floor,math.ceil
|
||||
local max,min=math.max,math.min
|
||||
local match=string.match
|
||||
local sub,ins,rem=string.sub,table.insert,table.remove
|
||||
local xOy=SCR.xOy
|
||||
local FONT=FONT
|
||||
@@ -142,13 +143,21 @@ local button={
|
||||
type='button',
|
||||
mustHaveText=true,
|
||||
ATV=0,-- Activating time(0~8)
|
||||
textAlreadyWrapped=false,-- Text already wrapped? (Managed by :setObject, can be override, this will be true if obj has a '\n')
|
||||
}
|
||||
function button:reset()
|
||||
self.ATV=0
|
||||
end
|
||||
function button:setObject(obj)
|
||||
if type(obj)=='string' or type(obj)=='number' then
|
||||
self.obj=gc.newText(FONT.get(self.font,self.fType),obj)
|
||||
if match(obj,"\n") then
|
||||
self.textAlreadyWrapped=true
|
||||
self.obj=gc.newText(FONT.get(self.font,self.fType))
|
||||
self.obj:addf(obj,self.w-self.edge*2,(self.align=='L' and 'left') or (self.align=='R' and 'right') or 'center')
|
||||
else
|
||||
self.textAlreadyWrapped=false
|
||||
self.obj=gc.newText(FONT.get(self.font,self.fType),obj)
|
||||
end
|
||||
elseif obj then
|
||||
self.obj=obj
|
||||
end
|
||||
@@ -194,16 +203,7 @@ function button:draw()
|
||||
local ox,oy=obj:getWidth()*.5,obj:getHeight()*.5
|
||||
local y0=y+h*.5
|
||||
gc_setColor(1,1,1,.2+ATV*.05)
|
||||
if self.align=='M' then
|
||||
local x0=x+w*.5
|
||||
local kx=obj:type()=='Text' and min(w/ox/2,1) or 1
|
||||
gc_draw(obj,x0-1,y0-1,nil,kx,1,ox,oy)
|
||||
gc_draw(obj,x0-1,y0+1,nil,kx,1,ox,oy)
|
||||
gc_draw(obj,x0+1,y0-1,nil,kx,1,ox,oy)
|
||||
gc_draw(obj,x0+1,y0+1,nil,kx,1,ox,oy)
|
||||
gc_setColor(r*.55,g*.55,b*.55)
|
||||
gc_draw(obj,x0,y0,nil,kx,1,ox,oy)
|
||||
elseif self.align=='L' then
|
||||
if self.align=='L' or self.textAlreadyWrapped then
|
||||
local edge=self.edge
|
||||
gc_draw(obj,x+edge-1,y0-1-oy)
|
||||
gc_draw(obj,x+edge-1,y0+1-oy)
|
||||
@@ -219,6 +219,15 @@ function button:draw()
|
||||
gc_draw(obj,x0+1,y0+1-oy)
|
||||
gc_setColor(r*.55,g*.55,b*.55)
|
||||
gc_draw(obj,x0,y0-oy)
|
||||
else--if self.align=='M' then
|
||||
local x0=x+w*.5
|
||||
local kx=obj:type()=='Text' and min(w/ox/2,1) or 1
|
||||
gc_draw(obj,x0-1,y0-1,nil,kx,1,ox,oy)
|
||||
gc_draw(obj,x0-1,y0+1,nil,kx,1,ox,oy)
|
||||
gc_draw(obj,x0+1,y0-1,nil,kx,1,ox,oy)
|
||||
gc_draw(obj,x0+1,y0+1,nil,kx,1,ox,oy)
|
||||
gc_setColor(r*.55,g*.55,b*.55)
|
||||
gc_draw(obj,x0,y0,nil,kx,1,ox,oy)
|
||||
end
|
||||
end
|
||||
function button:getInfo()
|
||||
@@ -290,13 +299,21 @@ local key={
|
||||
type='key',
|
||||
mustHaveText=true,
|
||||
ATV=0,-- Activating time(0~4)
|
||||
textAlreadyWrapped=false,---See button.setObject (line 146)
|
||||
}
|
||||
function key:reset()
|
||||
self.ATV=0
|
||||
end
|
||||
function key:setObject(obj)
|
||||
if type(obj)=='string' or type(obj)=='number' then
|
||||
self.obj=gc.newText(FONT.get(self.font,self.fType),obj)
|
||||
if match(obj,"\n") then
|
||||
self.textAlreadyWrapped=true
|
||||
self.obj=gc.newText(FONT.get(self.font,self.fType))
|
||||
self.obj:addf(obj,self.w-self.edge*2,(self.align=='L' and 'left') or (self.align=='R' and 'right') or 'center')
|
||||
else
|
||||
self.textAlreadyWrapped=false
|
||||
self.obj=gc.newText(FONT.get(self.font,self.fType),obj)
|
||||
end
|
||||
elseif obj then
|
||||
self.obj=obj
|
||||
end
|
||||
@@ -354,14 +371,15 @@ function key:draw()
|
||||
-- Drawable
|
||||
local obj=self.obj
|
||||
local ox,oy=obj:getWidth()*.5,obj:getHeight()*.5
|
||||
|
||||
gc_setColor(r,g,b)
|
||||
if align=='M' then
|
||||
local kx=obj:type()=='Text' and min(w/ox/2,1) or 1
|
||||
gc_draw(obj,x+w*.5,y+h*.5,nil,kx,1,ox,oy)
|
||||
elseif align=='L' then
|
||||
gc_draw(obj,x+self.edge,y-oy+h*.5)
|
||||
if align=='L' or self.textAlreadyWrapped then
|
||||
gc_draw(obj,x+self.edge,y+h*.5-oy)
|
||||
elseif align=='R' then
|
||||
gc_draw(obj,x+w-self.edge-ox*2,y-oy+h*.5)
|
||||
else--if align=='M' then
|
||||
local kx=obj:type()=='Text' and min(w/ox/2,1) or 1
|
||||
gc_draw(obj,x+w*.5,y+h*.5,nil,kx,1,ox,oy)
|
||||
end
|
||||
end
|
||||
function key:getInfo()
|
||||
@@ -1382,10 +1400,13 @@ function WIDGET.setLang(widgetText)
|
||||
t=W.name or "##"
|
||||
W.color=COLOR.dV
|
||||
end
|
||||
if type(t)=='string' and W.font then
|
||||
t=gc.newText(FONT.get(W.font),t)
|
||||
if type(W.setObject)=='function' then
|
||||
W:setObject(t)
|
||||
elseif type(t)=='string' and W.font then
|
||||
W.obj=gc.newText(FONT.get(W.font or 30),t)
|
||||
else
|
||||
W.obj=t
|
||||
end
|
||||
W.obj=t
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user