mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-10-11 22:34:17 +00:00
base code for textinput masking
This commit is contained in:
parent
1d42f3f694
commit
7ed08c984e
@ -8,10 +8,14 @@ Version 0.9.6.4 - Alpha (Release Date TBD)
|
|||||||
[ADDED] a new textinput method: Paste()
|
[ADDED] a new textinput method: Paste()
|
||||||
[ADDED] a new textinput method: SelectAll()
|
[ADDED] a new textinput method: SelectAll()
|
||||||
[ADDED] a new textinput method: DeselectAll()
|
[ADDED] a new textinput method: DeselectAll()
|
||||||
|
[ADDED] a new textinput method: SetMasked(masked)
|
||||||
|
[ADDED] a new textinput method: GetMasked()
|
||||||
|
[ADDED] a new textinput method: SetMaskChar(char)
|
||||||
|
[ADDED] a new textinput method: GetMaskChar()
|
||||||
[ADDED] a new library function: TableHasValue(table, value)
|
[ADDED] a new library function: TableHasValue(table, value)
|
||||||
[ADDED] basic clipboard support for the textinput object (0.9.0 only)
|
[ADDED] basic clipboard support for the textinput object (0.9.0 only)
|
||||||
[ADDED] custom cursor support for the textinput object
|
[ADDED] custom cursor support for the textinput object
|
||||||
[ADDED] support for love.filesystem api changes to loveframes.util.GetDirectoryContents
|
[ADDED] support for love.filesystem changes to loveframes.util.GetDirectoryContents (0.9.0 only)
|
||||||
|
|
||||||
[FIXED] error when pressing a function key while a textinput was focused
|
[FIXED] error when pressing a function key while a textinput was focused
|
||||||
[FIXED] the tooltip object not setting the state of its text object
|
[FIXED] the tooltip object not setting the state of its text object
|
||||||
|
@ -15,6 +15,7 @@ function newobject:initialize()
|
|||||||
self.type = "textinput"
|
self.type = "textinput"
|
||||||
self.keydown = "none"
|
self.keydown = "none"
|
||||||
self.tabreplacement = " "
|
self.tabreplacement = " "
|
||||||
|
self.maskchar = "*"
|
||||||
self.font = loveframes.basicfont
|
self.font = loveframes.basicfont
|
||||||
self.width = 200
|
self.width = 200
|
||||||
self.height = 25
|
self.height = 25
|
||||||
@ -60,6 +61,7 @@ function newobject:initialize()
|
|||||||
self.internal = false
|
self.internal = false
|
||||||
self.autoscroll = false
|
self.autoscroll = false
|
||||||
self.cursorset = false
|
self.cursorset = false
|
||||||
|
self.masked = false
|
||||||
self.prevcursor = nil
|
self.prevcursor = nil
|
||||||
self.OnEnter = nil
|
self.OnEnter = nil
|
||||||
self.OnTextChanged = nil
|
self.OnTextChanged = nil
|
||||||
@ -175,9 +177,16 @@ function newobject:update(dt)
|
|||||||
local textoffsetx = self.textoffsetx
|
local textoffsetx = self.textoffsetx
|
||||||
local textoffsety = self.textoffsety
|
local textoffsety = self.textoffsety
|
||||||
local linenumbers = self.linenumbers
|
local linenumbers = self.linenumbers
|
||||||
|
local masked = self.masked
|
||||||
|
local maskchar = self.maskchar
|
||||||
-- get the longest line of text
|
-- get the longest line of text
|
||||||
for k, v in ipairs(lines) do
|
for k, v in ipairs(lines) do
|
||||||
local linewidth = font:getWidth(v)
|
local linewidth = 0
|
||||||
|
if masked then
|
||||||
|
linewidth = font:getWidth(v:gsub(".", maskchar))
|
||||||
|
else
|
||||||
|
linewidth = font:getWidth(v)
|
||||||
|
end
|
||||||
if linewidth > twidth then
|
if linewidth > twidth then
|
||||||
twidth = linewidth
|
twidth = linewidth
|
||||||
end
|
end
|
||||||
@ -669,7 +678,14 @@ function newobject:RunKey(key, unicode)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local cwidth = font:getWidth(text:sub(#text))
|
local masked = self.masked
|
||||||
|
local cwidth = 0
|
||||||
|
if masked then
|
||||||
|
local maskchar = self.maskchar
|
||||||
|
cwidth = font:getWidth(text:sub(#text):gsub(".", maskchar))
|
||||||
|
else
|
||||||
|
cwidth = font:getWidth(text:sub(#text))
|
||||||
|
end
|
||||||
if self.offsetx > 0 then
|
if self.offsetx > 0 then
|
||||||
self.offsetx = self.offsetx - cwidth
|
self.offsetx = self.offsetx - cwidth
|
||||||
elseif self.offsetx < 0 then
|
elseif self.offsetx < 0 then
|
||||||
@ -807,8 +823,17 @@ function newobject:RunKey(key, unicode)
|
|||||||
curline = lines[line]
|
curline = lines[line]
|
||||||
text = curline
|
text = curline
|
||||||
if not multiline then
|
if not multiline then
|
||||||
local twidth = font:getWidth(text)
|
local masked = self.masked
|
||||||
local cwidth = font:getWidth(ckey)
|
local twidth = 0
|
||||||
|
local cwidth = 0
|
||||||
|
if masked then
|
||||||
|
local maskchar = self.maskchar
|
||||||
|
twidth = font:getWidth(text:gsub(".", maskchar))
|
||||||
|
cwidth = font:getWidth(ckey:gsub(".", maskchar))
|
||||||
|
else
|
||||||
|
twidth = font:getWidth(text)
|
||||||
|
cwidth = font:getWidth(ckey)
|
||||||
|
end
|
||||||
-- swidth - 1 is for the "-" character
|
-- swidth - 1 is for the "-" character
|
||||||
if (twidth + textoffsetx) >= (swidth - 1) then
|
if (twidth + textoffsetx) >= (swidth - 1) then
|
||||||
self.offsetx = self.offsetx + cwidth
|
self.offsetx = self.offsetx + cwidth
|
||||||
@ -875,6 +900,7 @@ function newobject:UpdateIndicator()
|
|||||||
local alltextselected = self.alltextselected
|
local alltextselected = self.alltextselected
|
||||||
local textx = self.textx
|
local textx = self.textx
|
||||||
local texty = self.texty
|
local texty = self.texty
|
||||||
|
local masked = self.masked
|
||||||
|
|
||||||
if indincatortime < time then
|
if indincatortime < time then
|
||||||
if showindicator then
|
if showindicator then
|
||||||
@ -892,8 +918,13 @@ function newobject:UpdateIndicator()
|
|||||||
local width = 0
|
local width = 0
|
||||||
|
|
||||||
for i=1, indicatornum do
|
for i=1, indicatornum do
|
||||||
local char = text:sub(i, i)
|
if masked then
|
||||||
width = width + font:getWidth(char)
|
local char = self.maskchar
|
||||||
|
width = width + font:getWidth(char)
|
||||||
|
else
|
||||||
|
local char = text:sub(i, i)
|
||||||
|
width = width + font:getWidth(char)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if multiline then
|
if multiline then
|
||||||
@ -963,7 +994,8 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
local selfx = self.x
|
local selfx = self.x
|
||||||
local selfy = self.y
|
local selfy = self.y
|
||||||
local selfwidth = self.width
|
local selfwidth = self.width
|
||||||
|
local masked = self.masked
|
||||||
|
|
||||||
if multiline then
|
if multiline then
|
||||||
local theight = font:getHeight()
|
local theight = font:getHeight()
|
||||||
local liney = 0
|
local liney = 0
|
||||||
@ -991,7 +1023,13 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
local curline = lines[line]
|
local curline = lines[line]
|
||||||
for i=1, #curline do
|
for i=1, #curline do
|
||||||
local char = text:sub(i, i)
|
local char = text:sub(i, i)
|
||||||
local width = font:getWidth(char)
|
local width = 0
|
||||||
|
if masked then
|
||||||
|
local maskchar = self.maskchar
|
||||||
|
width = font:getWidth(maskchar)
|
||||||
|
else
|
||||||
|
width = font:getWidth(char)
|
||||||
|
end
|
||||||
local height = font:getHeight()
|
local height = font:getHeight()
|
||||||
local tx = self.textx + xpos
|
local tx = self.textx + xpos
|
||||||
local ty = self.texty
|
local ty = self.texty
|
||||||
@ -1022,7 +1060,13 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
else
|
else
|
||||||
for i=1, #text do
|
for i=1, #text do
|
||||||
local char = text:sub(i, i)
|
local char = text:sub(i, i)
|
||||||
local width = font:getWidth(char)
|
local width = 0
|
||||||
|
if masked then
|
||||||
|
local maskchar = self.maskchar
|
||||||
|
width = font:getWidth(maskchar)
|
||||||
|
else
|
||||||
|
width = font:getWidth(char)
|
||||||
|
end
|
||||||
local height = font:getHeight()
|
local height = font:getHeight()
|
||||||
local tx = self.textx + xpos
|
local tx = self.textx + xpos
|
||||||
local ty = self.texty
|
local ty = self.texty
|
||||||
@ -1871,4 +1915,44 @@ function newobject:DeselectAll()
|
|||||||
|
|
||||||
self.alltextselected = false
|
self.alltextselected = false
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[---------------------------------------------------------
|
||||||
|
- func: SetMasked(masked)
|
||||||
|
- desc: sets whether or not the object is masked
|
||||||
|
--]]---------------------------------------------------------
|
||||||
|
function newobject:SetMasked(masked)
|
||||||
|
|
||||||
|
self.masked = masked
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[---------------------------------------------------------
|
||||||
|
- func: GetMasked()
|
||||||
|
- desc: gets whether or not the object is masked
|
||||||
|
--]]---------------------------------------------------------
|
||||||
|
function newobject:GetMasked()
|
||||||
|
|
||||||
|
return self.masked
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[---------------------------------------------------------
|
||||||
|
- func: SetMaskChar(char)
|
||||||
|
- desc: sets the object's mask character
|
||||||
|
--]]---------------------------------------------------------
|
||||||
|
function newobject:SetMaskChar(char)
|
||||||
|
|
||||||
|
self.maskchar = char
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[---------------------------------------------------------
|
||||||
|
- func: GetMaskChar()
|
||||||
|
- desc: gets the object's mask character
|
||||||
|
--]]---------------------------------------------------------
|
||||||
|
function newobject:GetMaskChar()
|
||||||
|
|
||||||
|
return self.maskchar
|
||||||
|
|
||||||
end
|
end
|
@ -915,6 +915,7 @@ function skin.DrawTextInput(object)
|
|||||||
local hbar = object:HasHorizontalScrollBar()
|
local hbar = object:HasHorizontalScrollBar()
|
||||||
local linenumbers = object:GetLineNumbersEnabled()
|
local linenumbers = object:GetLineNumbersEnabled()
|
||||||
local itemwidth = object:GetItemWidth()
|
local itemwidth = object:GetItemWidth()
|
||||||
|
local masked = object:GetMasked()
|
||||||
local theight = font:getHeight("a")
|
local theight = font:getHeight("a")
|
||||||
local bodycolor = skin.controls.textinput_body_color
|
local bodycolor = skin.controls.textinput_body_color
|
||||||
local textnormalcolor = skin.controls.textinput_text_normal_color
|
local textnormalcolor = skin.controls.textinput_text_normal_color
|
||||||
@ -929,7 +930,11 @@ function skin.DrawTextInput(object)
|
|||||||
local bary = 0
|
local bary = 0
|
||||||
if multiline then
|
if multiline then
|
||||||
for i=1, #lines do
|
for i=1, #lines do
|
||||||
local twidth = font:getWidth(lines[i])
|
local str = lines[i]
|
||||||
|
if masked then
|
||||||
|
str = str:gsub(".", "*")
|
||||||
|
end
|
||||||
|
local twidth = font:getWidth(str)
|
||||||
if twidth == 0 then
|
if twidth == 0 then
|
||||||
twidth = 5
|
twidth = 5
|
||||||
end
|
end
|
||||||
@ -938,7 +943,13 @@ function skin.DrawTextInput(object)
|
|||||||
bary = bary + theight
|
bary = bary + theight
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local twidth = font:getWidth(text)
|
local twidth = 0
|
||||||
|
if masked then
|
||||||
|
local maskchar = object:GetMaskChar()
|
||||||
|
twidth = font:getWidth(text:gsub(".", maskchar))
|
||||||
|
else
|
||||||
|
twidth = font:getWidth(text)
|
||||||
|
end
|
||||||
love.graphics.setColor(highlightbarcolor)
|
love.graphics.setColor(highlightbarcolor)
|
||||||
love.graphics.rectangle("fill", textx, texty, twidth, theight)
|
love.graphics.rectangle("fill", textx, texty, twidth, theight)
|
||||||
end
|
end
|
||||||
@ -1007,14 +1018,25 @@ function skin.DrawTextInput(object)
|
|||||||
love.graphics.setColor(textnormalcolor)
|
love.graphics.setColor(textnormalcolor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local str = ""
|
||||||
if multiline then
|
if multiline then
|
||||||
for i=1, #lines do
|
for i=1, #lines do
|
||||||
love.graphics.print(lines[i], textx, texty + theight * i - theight)
|
str = lines[i]
|
||||||
|
if masked then
|
||||||
|
local maskchar = object:GetMaskChar()
|
||||||
|
str = str:gsub(".", maskchar)
|
||||||
|
end
|
||||||
|
love.graphics.print(str, textx, texty + theight * i - theight)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
love.graphics.print(lines[1], textx, texty)
|
str = lines[1]
|
||||||
|
if masked then
|
||||||
|
local maskchar = object:GetMaskChar()
|
||||||
|
str = str:gsub(".", maskchar)
|
||||||
|
end
|
||||||
|
love.graphics.print(str, textx, texty)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[---------------------------------------------------------
|
--[[---------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user