mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
textinput - Unicode support.
This commit is contained in:
parent
d22546bcb2
commit
1bee7fa8d9
@ -3,6 +3,8 @@
|
|||||||
-- Copyright (c) 2012-2014 Kenny Shields --
|
-- Copyright (c) 2012-2014 Kenny Shields --
|
||||||
--]]------------------------------------------------
|
--]]------------------------------------------------
|
||||||
|
|
||||||
|
local utf8 = require("utf8")
|
||||||
|
|
||||||
-- get the current require path
|
-- get the current require path
|
||||||
local path = string.sub(..., 1, string.len(...) - string.len(".objects.textinput"))
|
local path = string.sub(..., 1, string.len(...) - string.len(".objects.textinput"))
|
||||||
local loveframes = require(path .. ".libraries.common")
|
local loveframes = require(path .. ".libraries.common")
|
||||||
@ -884,8 +886,8 @@ function newobject:MoveIndicator(num, exact)
|
|||||||
self.indicatornum = num
|
self.indicatornum = num
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.indicatornum > string.len(text) then
|
if self.indicatornum > utf8.len(text) then
|
||||||
self.indicatornum = string.len(text)
|
self.indicatornum = utf8.len(text)
|
||||||
elseif self.indicatornum < 0 then
|
elseif self.indicatornum < 0 then
|
||||||
self.indicatornum = 0
|
self.indicatornum = 0
|
||||||
end
|
end
|
||||||
@ -939,14 +941,15 @@ function newobject:UpdateIndicator()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local width = 0
|
local width = 0
|
||||||
|
if masked then
|
||||||
for i=1, indicatornum do
|
width = font:getWidth(string.rep(self.maskchar,indicatornum))
|
||||||
if masked then
|
else
|
||||||
local char = self.maskchar
|
if indicatornum == 0 then
|
||||||
width = width + font:getWidth(char)
|
width = 0
|
||||||
|
elseif indicatornum >= utf8.len(text) then
|
||||||
|
width = font:getWidth(text)
|
||||||
else
|
else
|
||||||
local char = text:sub(i, i)
|
width = font:getWidth(text:sub(1, utf8.offset (text, indicatornum + 1) - 1))
|
||||||
width = width + font:getWidth(char)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1022,8 +1025,8 @@ function newobject:AddIntoText(t, p)
|
|||||||
local line = self.line
|
local line = self.line
|
||||||
local curline = lines[line]
|
local curline = lines[line]
|
||||||
local text = curline
|
local text = curline
|
||||||
local part1 = text:sub(1, p)
|
local part1 = text:sub(1, utf8.offset(text, p + 1) - 1)
|
||||||
local part2 = text:sub(p + 1)
|
local part2 = text:sub(utf8.offset(text, p + 1))
|
||||||
local new = part1 .. t .. part2
|
local new = part1 .. t .. part2
|
||||||
|
|
||||||
return new
|
return new
|
||||||
@ -1041,8 +1044,8 @@ function newobject:RemoveFromText(p)
|
|||||||
local line = self.line
|
local line = self.line
|
||||||
local curline = lines[line]
|
local curline = lines[line]
|
||||||
local text = curline
|
local text = curline
|
||||||
local part1 = text:sub(1, p - 1)
|
local part1 = text:sub(1, utf8.offset(text, p) - 1)
|
||||||
local part2 = text:sub(p + 1)
|
local part2 = text:sub(utf8.offset(text, p + 1))
|
||||||
local new = part1 .. part2
|
local new = part1 .. part2
|
||||||
return new
|
return new
|
||||||
|
|
||||||
@ -1132,8 +1135,10 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for i=1, string.len(text) do
|
local i = 0
|
||||||
local char = text:sub(i, i)
|
for p, c in utf8.codes(text) do
|
||||||
|
i = i + 1
|
||||||
|
local char = utf8.char(c)
|
||||||
local width = 0
|
local width = 0
|
||||||
if masked then
|
if masked then
|
||||||
local maskchar = self.maskchar
|
local maskchar = self.maskchar
|
||||||
@ -1154,7 +1159,7 @@ function newobject:GetTextCollisions(x, y)
|
|||||||
self:MoveIndicator(0, true)
|
self:MoveIndicator(0, true)
|
||||||
end
|
end
|
||||||
if x > (tx + width) then
|
if x > (tx + width) then
|
||||||
self:MoveIndicator(string.len(text), true)
|
self:MoveIndicator(utf8.len(text), true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user