2013-02-11 21:15:40 +00:00
|
|
|
--[[------------------------------------------------
|
|
|
|
-- Love Frames - A GUI library for LOVE --
|
2014-01-14 11:29:11 +00:00
|
|
|
-- Copyright (c) 2012-2014 Kenny Shields --
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
|
|
|
--[[------------------------------------------------
|
|
|
|
-- note: the text wrapping of this object is
|
|
|
|
experimental and not final
|
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2019-03-06 23:19:58 +00:00
|
|
|
return function(loveframes)
|
|
|
|
---------- module start ----------
|
2014-10-23 22:36:16 +00:00
|
|
|
|
2013-11-25 13:06:41 +00:00
|
|
|
-- text object
|
2013-02-11 21:15:40 +00:00
|
|
|
local newobject = loveframes.NewObject("text", "loveframes_object_text", true)
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:initialize()
|
2013-11-04 16:23:39 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
self.type = "text"
|
|
|
|
self.text = ""
|
|
|
|
self.font = loveframes.basicfont
|
|
|
|
self.width = 5
|
|
|
|
self.height = 5
|
|
|
|
self.maxw = 0
|
|
|
|
self.shadowxoffset = 1
|
|
|
|
self.shadowyoffset = 1
|
2014-09-27 19:23:29 +00:00
|
|
|
self.lines = 0
|
2013-02-11 21:15:40 +00:00
|
|
|
self.formattedtext = {}
|
|
|
|
self.original = {}
|
2019-03-06 23:19:58 +00:00
|
|
|
self.defaultcolor = {0, 0, 0, 1}
|
|
|
|
self.shadowcolor = {0, 0, 0, 1}
|
|
|
|
self.linkcolor = {0, .4, 1, 1}
|
|
|
|
self.linkhovercolor = {0, 0, 1, 1}
|
2013-02-11 21:15:40 +00:00
|
|
|
self.ignorenewlines = false
|
|
|
|
self.shadow = false
|
2014-01-08 00:21:22 +00:00
|
|
|
self.linkcol = false
|
2013-02-11 21:15:40 +00:00
|
|
|
self.internal = false
|
2013-11-04 16:23:39 +00:00
|
|
|
self.linksenabled = false
|
2013-11-25 15:18:26 +00:00
|
|
|
self.detectlinks = false
|
2013-11-04 16:23:39 +00:00
|
|
|
self.OnClickLink = nil
|
2013-02-11 21:15:40 +00:00
|
|
|
|
2019-03-06 23:19:58 +00:00
|
|
|
local skin = loveframes.GetActiveSkin()
|
2013-11-25 13:06:41 +00:00
|
|
|
if not skin then
|
|
|
|
skin = loveframes.config["DEFAULTSKIN"]
|
|
|
|
end
|
|
|
|
|
2013-11-09 14:30:08 +00:00
|
|
|
local directives = skin.directives
|
|
|
|
if directives then
|
|
|
|
local text_default_color = directives.text_default_color
|
|
|
|
local text_default_shadowcolor = directives.text_default_shadowcolor
|
|
|
|
local text_default_font = directives.text_default_font
|
|
|
|
if text_default_color then
|
|
|
|
self.defaultcolor = text_default_color
|
|
|
|
end
|
|
|
|
if text_default_shadowcolor then
|
|
|
|
self.shadowcolor = text_default_shadowcolor
|
|
|
|
end
|
|
|
|
if text_default_font then
|
|
|
|
self.font = text_default_font
|
|
|
|
end
|
|
|
|
end
|
2019-03-06 23:19:58 +00:00
|
|
|
self:SetDrawFunc()
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:update(dt)
|
|
|
|
|
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
local alwaysupdate = self.alwaysupdate
|
|
|
|
|
|
|
|
if not visible then
|
|
|
|
if not alwaysupdate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local parent = self.parent
|
|
|
|
local base = loveframes.base
|
|
|
|
local update = self.Update
|
|
|
|
|
|
|
|
self:CheckHover()
|
|
|
|
|
2013-11-04 16:23:39 +00:00
|
|
|
local hover = self.hover
|
|
|
|
local linksenabled = self.linksenabled
|
|
|
|
local linkcol = false
|
2013-11-04 16:50:24 +00:00
|
|
|
|
2014-01-08 00:21:22 +00:00
|
|
|
if hover and linksenabled and not loveframes.resizeobject then
|
2013-11-04 16:23:39 +00:00
|
|
|
local formattedtext = self.formattedtext
|
|
|
|
local x = self.x
|
|
|
|
local y = self.y
|
|
|
|
for k, v in ipairs(formattedtext) do
|
|
|
|
local link = v.link
|
|
|
|
if link then
|
|
|
|
local mx, my = love.mouse.getPosition()
|
|
|
|
local font = v.font
|
|
|
|
local linkx = v.x
|
|
|
|
local linky = v.y
|
|
|
|
local text = v.text
|
|
|
|
local twidth = font:getWidth(text)
|
|
|
|
local theight = font:getHeight()
|
2019-03-06 23:19:58 +00:00
|
|
|
local col = loveframes.BoundingBox(x + linkx, mx, y + linky, my, twidth, 1, theight, 1)
|
2013-11-04 16:23:39 +00:00
|
|
|
v.hover = false
|
|
|
|
if col then
|
|
|
|
v.hover = true
|
|
|
|
linkcol = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-01-08 00:21:22 +00:00
|
|
|
self.linkcol = linkcol
|
2013-11-04 16:23:39 +00:00
|
|
|
end
|
2021-09-05 17:46:49 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
-- move to parent if there is a parent
|
|
|
|
if parent ~= base then
|
2021-09-05 17:46:49 +00:00
|
|
|
self.x = self.parent.x + self.staticx - (parent.offsetx or 0)
|
|
|
|
self.y = self.parent.y + self.staticy - (parent.offsety or 0)
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
2021-09-05 17:46:49 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
if update then
|
|
|
|
update(self, dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: mousepressed(x, y, button)
|
|
|
|
- desc: called when the player presses a mouse button
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:mousepressed(x, y, button)
|
|
|
|
|
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
|
|
|
if not visible then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local hover = self.hover
|
2015-10-31 13:40:19 +00:00
|
|
|
if hover and button == 1 then
|
2013-02-11 21:15:40 +00:00
|
|
|
local baseparent = self:GetBaseParent()
|
|
|
|
if baseparent and baseparent.type == "frame" then
|
|
|
|
baseparent:MakeTop()
|
|
|
|
end
|
2013-11-04 16:23:39 +00:00
|
|
|
local linksenabled = self.linksenabled
|
|
|
|
if linksenabled then
|
|
|
|
local formattedtext = self.formattedtext
|
2013-11-25 15:18:26 +00:00
|
|
|
local objx = self.x
|
|
|
|
local objy = self.y
|
2013-11-04 16:23:39 +00:00
|
|
|
for k, v in ipairs(formattedtext) do
|
|
|
|
local link = v.link
|
|
|
|
if link then
|
|
|
|
local linkx = v.x
|
|
|
|
local linky = v.y
|
|
|
|
local font = v.font
|
|
|
|
local text = v.text
|
|
|
|
local twidth = font:getWidth(text)
|
|
|
|
local theight = font:getHeight()
|
2019-03-06 23:19:58 +00:00
|
|
|
local col = loveframes.BoundingBox(objx + linkx, x, objy + linky, y, twidth, 1, theight, 1)
|
2013-11-04 16:23:39 +00:00
|
|
|
if col then
|
|
|
|
local onclicklink = self.OnClickLink
|
|
|
|
if onclicklink then
|
|
|
|
onclicklink(self, text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetText(text)
|
|
|
|
- desc: sets the object's text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetText(t)
|
|
|
|
|
|
|
|
local dtype = type(t)
|
|
|
|
local maxw = self.maxw
|
|
|
|
local font = self.font
|
2013-05-05 23:51:20 +00:00
|
|
|
local defaultcolor = self.defaultcolor
|
2013-02-11 21:15:40 +00:00
|
|
|
local inserts = {}
|
2013-11-25 15:18:26 +00:00
|
|
|
local prevcolor = defaultcolor
|
|
|
|
local prevlinkcolor = self.linkcolor
|
|
|
|
local prevlinkhovercolor = self.linkhovercolor
|
2013-05-15 18:02:55 +00:00
|
|
|
local prevfont = font
|
2013-11-25 15:18:26 +00:00
|
|
|
local link = false
|
|
|
|
local tdata
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
self.text = ""
|
|
|
|
self.formattedtext = {}
|
|
|
|
|
|
|
|
if dtype == "string" then
|
|
|
|
tdata = {t}
|
|
|
|
self.original = {t}
|
|
|
|
elseif dtype == "number" then
|
|
|
|
tdata = {tostring(t)}
|
|
|
|
self.original = {tostring(t)}
|
|
|
|
elseif dtype == "table" then
|
|
|
|
tdata = t
|
|
|
|
self.original = t
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
for k, v in ipairs(tdata) do
|
2013-09-14 15:37:01 +00:00
|
|
|
dtype = type(v)
|
2013-02-11 21:15:40 +00:00
|
|
|
if dtype == "table" then
|
2013-11-25 15:18:26 +00:00
|
|
|
if v.color then
|
|
|
|
prevcolor = v.color
|
|
|
|
end
|
|
|
|
if v.linkcolor then
|
|
|
|
prevlinkcolor = v.linkcolor
|
|
|
|
end
|
|
|
|
if v.linkhovercolor then
|
|
|
|
prevlinkhovercolor = v.linkhovercolor
|
|
|
|
end
|
|
|
|
if v.font then
|
|
|
|
prevfont = v.font
|
|
|
|
end
|
|
|
|
if v.link then
|
|
|
|
link = true
|
2014-02-14 07:22:02 +00:00
|
|
|
else
|
|
|
|
link = false
|
2013-11-25 15:18:26 +00:00
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
elseif dtype == "number" then
|
2014-02-26 12:37:20 +00:00
|
|
|
table.insert(self.formattedtext, {
|
|
|
|
font = prevfont,
|
|
|
|
color = prevcolor,
|
|
|
|
linkcolor = prevlinkcolor,
|
|
|
|
linkhovercolor = prevlinkhovercolor,
|
|
|
|
link = link,
|
|
|
|
text = tostring(v)
|
|
|
|
})
|
2013-02-11 21:15:40 +00:00
|
|
|
elseif dtype == "string" then
|
|
|
|
if self.ignorenewlines then
|
2020-04-28 16:55:30 +00:00
|
|
|
v = loveframes.utf8.gsub(v, "\n", " ")
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
2020-04-28 16:55:30 +00:00
|
|
|
v = loveframes.utf8.gsub(v, string.char(9), " ")
|
|
|
|
v = loveframes.utf8.gsub(v, "\n", " \n ")
|
2019-03-06 23:19:58 +00:00
|
|
|
local parts = loveframes.SplitString(v, " ")
|
2013-02-11 21:15:40 +00:00
|
|
|
for i, j in ipairs(parts) do
|
2014-02-26 12:37:20 +00:00
|
|
|
table.insert(self.formattedtext, {
|
|
|
|
font = prevfont,
|
|
|
|
color = prevcolor,
|
|
|
|
linkcolor = prevlinkcolor,
|
|
|
|
linkhovercolor = prevlinkhovercolor,
|
|
|
|
link = link,
|
|
|
|
text = j
|
|
|
|
})
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if maxw > 0 then
|
|
|
|
for k, v in ipairs(self.formattedtext) do
|
|
|
|
local data = v.text
|
2013-05-15 18:02:55 +00:00
|
|
|
local width = v.font:getWidth(data)
|
2013-02-11 21:15:40 +00:00
|
|
|
local curw = 0
|
|
|
|
local new = ""
|
|
|
|
local key = k
|
|
|
|
if width > maxw then
|
|
|
|
table.remove(self.formattedtext, k)
|
2020-04-28 16:55:30 +00:00
|
|
|
for n=1, loveframes.utf8.len(data) do
|
|
|
|
local item = loveframes.utf8.sub(data, n, n)
|
2013-05-15 18:02:55 +00:00
|
|
|
local itemw = v.font:getWidth(item)
|
2020-04-28 16:55:30 +00:00
|
|
|
if n ~= loveframes.utf8.len(data) then
|
2013-02-11 21:15:40 +00:00
|
|
|
if (curw + itemw) > maxw then
|
2014-02-26 12:37:20 +00:00
|
|
|
table.insert(inserts, {
|
|
|
|
key = key,
|
|
|
|
font = v.font,
|
|
|
|
color = v.color,
|
|
|
|
linkcolor = prevlinkcolor,
|
|
|
|
linkhovercolor = v.linkhovercolor,
|
|
|
|
link = v.link,
|
|
|
|
text = new
|
|
|
|
})
|
2013-02-11 21:15:40 +00:00
|
|
|
new = item
|
|
|
|
curw = 0 + itemw
|
|
|
|
key = key + 1
|
|
|
|
else
|
|
|
|
new = new .. item
|
|
|
|
curw = curw + itemw
|
|
|
|
end
|
|
|
|
else
|
|
|
|
new = new .. item
|
2014-02-26 12:37:20 +00:00
|
|
|
table.insert(inserts, {
|
|
|
|
key = key,
|
|
|
|
font = v.font,
|
|
|
|
color = v.color,
|
|
|
|
linkcolor = prevlinkcolor,
|
|
|
|
linkhovercolor = v.linkhovercolor,
|
|
|
|
link = v.link,
|
|
|
|
text = new
|
|
|
|
})
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for k, v in ipairs(inserts) do
|
2014-02-26 12:37:20 +00:00
|
|
|
table.insert(self.formattedtext, v.key, {
|
|
|
|
font = v.font,
|
|
|
|
color = v.color,
|
|
|
|
linkcolor = prevlinkcolor,
|
|
|
|
linkhovercolor = v.linkhovercolor,
|
|
|
|
link = v.link,
|
|
|
|
text = v.text
|
|
|
|
})
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local textdata = self.formattedtext
|
|
|
|
local maxw = self.maxw
|
|
|
|
local font = self.font
|
|
|
|
local twidth = 0
|
|
|
|
local drawx = 0
|
|
|
|
local drawy = 0
|
2014-09-27 19:23:29 +00:00
|
|
|
local lines = 1
|
2013-02-11 21:15:40 +00:00
|
|
|
local textwidth = 0
|
|
|
|
local lastwidth = 0
|
|
|
|
local totalwidth = 0
|
|
|
|
local x = self.x
|
|
|
|
local y = self.y
|
2013-05-15 18:02:55 +00:00
|
|
|
local prevtextwidth = 0
|
|
|
|
local prevtextheight = 0
|
|
|
|
local prevlargestheight = 0
|
2013-09-14 15:37:01 +00:00
|
|
|
local largestwidth = 0
|
2013-05-15 18:02:55 +00:00
|
|
|
local largestheight = 0
|
2013-09-14 15:37:01 +00:00
|
|
|
local initialwidth = 0
|
2013-11-25 15:18:26 +00:00
|
|
|
local detectlinks = self.detectlinks
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
for k, v in ipairs(textdata) do
|
|
|
|
local text = v.text
|
|
|
|
local color = v.color
|
2013-11-25 15:18:26 +00:00
|
|
|
if detectlinks then
|
2020-04-28 16:55:30 +00:00
|
|
|
if loveframes.utf8.len(text) > 7 and (loveframes.utf8.sub(text, 1, 7) == "http://" or loveframes.utf8.sub(text, 1, 8) == "https://") then
|
2013-11-04 16:23:39 +00:00
|
|
|
v.link = true
|
|
|
|
end
|
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
if type(text) == "string" then
|
|
|
|
self.text = self.text .. text
|
2013-05-15 18:02:55 +00:00
|
|
|
local width = v.font:getWidth(text)
|
|
|
|
local height = v.font:getHeight("a")
|
|
|
|
if height > largestheight then
|
|
|
|
largestheight = height
|
|
|
|
prevlargestheight = height
|
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
totalwidth = totalwidth + width
|
|
|
|
if maxw > 0 then
|
|
|
|
if k ~= 1 then
|
|
|
|
if string.byte(text) == 10 then
|
|
|
|
twidth = 0
|
|
|
|
drawx = 0
|
|
|
|
width = 0
|
2013-05-15 18:02:55 +00:00
|
|
|
drawy = drawy + largestheight
|
|
|
|
largestheight = 0
|
2013-02-11 21:15:40 +00:00
|
|
|
text = ""
|
2014-09-27 19:23:29 +00:00
|
|
|
lines = lines + 1
|
2013-02-11 21:15:40 +00:00
|
|
|
elseif (twidth + width) > maxw then
|
|
|
|
twidth = 0 + width
|
|
|
|
drawx = 0
|
2013-05-15 18:02:55 +00:00
|
|
|
drawy = drawy + largestheight
|
|
|
|
largestheight = 0
|
2014-09-27 19:23:29 +00:00
|
|
|
lines = lines + 1
|
2013-02-11 21:15:40 +00:00
|
|
|
else
|
|
|
|
twidth = twidth + width
|
|
|
|
drawx = drawx + prevtextwidth
|
|
|
|
end
|
|
|
|
else
|
|
|
|
twidth = twidth + width
|
|
|
|
end
|
|
|
|
prevtextwidth = width
|
2013-05-15 18:02:55 +00:00
|
|
|
prevtextheight = height
|
2013-02-11 21:15:40 +00:00
|
|
|
v.x = drawx
|
|
|
|
v.y = drawy
|
|
|
|
else
|
2014-01-27 12:41:00 +00:00
|
|
|
if string.byte(text) == 10 then
|
|
|
|
twidth = 0
|
|
|
|
drawx = 0
|
|
|
|
width = 0
|
|
|
|
drawy = drawy + largestheight
|
|
|
|
largestheight = 0
|
|
|
|
text = ""
|
2014-09-27 19:23:29 +00:00
|
|
|
lines = lines + 1
|
2014-01-27 12:41:00 +00:00
|
|
|
if lastwidth < textwidth then
|
|
|
|
lastwidth = textwidth
|
|
|
|
end
|
|
|
|
if largestwidth < textwidth then
|
|
|
|
largestwidth = textwidth
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
2014-01-27 12:41:00 +00:00
|
|
|
textwidth = 0
|
2013-09-14 15:37:01 +00:00
|
|
|
else
|
2014-01-27 12:41:00 +00:00
|
|
|
drawx = drawx + prevtextwidth
|
|
|
|
textwidth = textwidth + width
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
prevtextwidth = width
|
2013-05-15 18:02:55 +00:00
|
|
|
prevtextheight = height
|
2013-02-11 21:15:40 +00:00
|
|
|
v.x = drawx
|
|
|
|
v.y = drawy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-27 19:23:29 +00:00
|
|
|
self.lines = lines
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
if lastwidth == 0 then
|
|
|
|
textwidth = totalwidth
|
|
|
|
end
|
|
|
|
|
2013-09-14 15:37:01 +00:00
|
|
|
if textwidth < largestwidth then
|
2014-01-27 12:41:00 +00:00
|
|
|
textwidth = largestwidth
|
2013-09-14 15:37:01 +00:00
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
if maxw > 0 then
|
|
|
|
self.width = maxw
|
|
|
|
else
|
|
|
|
self.width = textwidth
|
|
|
|
end
|
|
|
|
|
2013-05-15 18:02:55 +00:00
|
|
|
self.height = drawy + prevlargestheight
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetText()
|
|
|
|
- desc: gets the object's text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetText()
|
|
|
|
|
|
|
|
return self.text
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetFormattedText()
|
|
|
|
- desc: gets the object's formatted text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetFormattedText()
|
|
|
|
|
|
|
|
return self.formattedtext
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
2013-05-15 18:02:55 +00:00
|
|
|
- func: DrawText()
|
|
|
|
- desc: draws the object's text
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:DrawText()
|
|
|
|
|
|
|
|
local textdata = self.formattedtext
|
|
|
|
local x = self.x
|
|
|
|
local y = self.y
|
|
|
|
local shadow = self.shadow
|
|
|
|
local shadowxoffset = self.shadowxoffset
|
|
|
|
local shadowyoffset = self.shadowyoffset
|
|
|
|
local shadowcolor = self.shadowcolor
|
|
|
|
local inlist, list = self:IsInList()
|
2019-03-06 23:19:58 +00:00
|
|
|
local printfunc = function(text, x, y)
|
|
|
|
love.graphics.print(text, math.floor(x + 0.5), math.floor(y + 0.5))
|
|
|
|
end
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
for k, v in ipairs(textdata) do
|
2013-11-04 16:23:39 +00:00
|
|
|
local textx = v.x
|
|
|
|
local texty = v.y
|
2013-02-11 21:15:40 +00:00
|
|
|
local text = v.text
|
|
|
|
local color = v.color
|
2013-05-15 18:02:55 +00:00
|
|
|
local font = v.font
|
2013-11-04 16:23:39 +00:00
|
|
|
local link = v.link
|
2013-05-15 18:02:55 +00:00
|
|
|
local theight = font:getHeight("a")
|
2013-02-11 21:15:40 +00:00
|
|
|
if inlist then
|
2013-11-04 16:23:39 +00:00
|
|
|
local listy = list.y
|
|
|
|
local listhieght = list.height
|
|
|
|
if (y + texty) <= (listy + listhieght) and y + ((texty + theight)) >= listy then
|
2013-02-11 21:15:40 +00:00
|
|
|
love.graphics.setFont(font)
|
|
|
|
if shadow then
|
|
|
|
love.graphics.setColor(unpack(shadowcolor))
|
2019-03-06 23:19:58 +00:00
|
|
|
printfunc(text, x + textx + shadowxoffset, y + texty + shadowyoffset)
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
2013-11-04 16:23:39 +00:00
|
|
|
if link then
|
2013-11-25 15:18:26 +00:00
|
|
|
local linkcolor = v.linkcolor
|
|
|
|
local linkhovercolor = v.linkhovercolor
|
2013-11-04 16:23:39 +00:00
|
|
|
local hover = v.hover
|
|
|
|
if hover then
|
|
|
|
love.graphics.setColor(linkhovercolor)
|
|
|
|
else
|
|
|
|
love.graphics.setColor(linkcolor)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
love.graphics.setColor(unpack(color))
|
|
|
|
end
|
2019-03-06 23:19:58 +00:00
|
|
|
printfunc(text, x + textx, y + texty)
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
love.graphics.setFont(font)
|
|
|
|
if shadow then
|
|
|
|
love.graphics.setColor(unpack(shadowcolor))
|
2019-03-06 23:19:58 +00:00
|
|
|
printfunc(text, x + textx + shadowxoffset, y + texty + shadowyoffset)
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
2013-11-25 15:18:26 +00:00
|
|
|
if link then
|
|
|
|
local linkcolor = v.linkcolor
|
|
|
|
local linkhovercolor = v.linkhovercolor
|
|
|
|
local hover = v.hover
|
|
|
|
if hover then
|
|
|
|
love.graphics.setColor(linkhovercolor)
|
|
|
|
else
|
|
|
|
love.graphics.setColor(linkcolor)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
love.graphics.setColor(unpack(color))
|
|
|
|
end
|
2019-03-06 23:19:58 +00:00
|
|
|
printfunc(text, x + textx, y + texty)
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetMaxWidth(width)
|
|
|
|
- desc: sets the object's maximum width
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetMaxWidth(width)
|
|
|
|
|
2013-05-05 23:51:20 +00:00
|
|
|
local original = self.original
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
self.maxw = width
|
2013-05-05 23:51:20 +00:00
|
|
|
self:SetText(original)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetMaxWidth()
|
|
|
|
- desc: gets the object's maximum width
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetMaxWidth()
|
|
|
|
|
|
|
|
return self.maxw
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
2014-07-12 21:33:22 +00:00
|
|
|
- func: SetWidth(width, relative)
|
2013-02-11 21:15:40 +00:00
|
|
|
- desc: sets the object's width
|
|
|
|
--]]---------------------------------------------------------
|
2014-07-12 21:33:22 +00:00
|
|
|
function newobject:SetWidth(width, relative)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
2014-07-12 21:33:22 +00:00
|
|
|
if relative then
|
|
|
|
self:SetMaxWidth(self.parent.width * width)
|
|
|
|
else
|
|
|
|
self:SetMaxWidth(width)
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetHeight()
|
|
|
|
- desc: sets the object's height
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetHeight(height)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
2014-07-12 21:33:22 +00:00
|
|
|
- func: SetSize(width, height, relative)
|
2013-02-11 21:15:40 +00:00
|
|
|
- desc: sets the object's size
|
|
|
|
--]]---------------------------------------------------------
|
2014-07-12 21:33:22 +00:00
|
|
|
function newobject:SetSize(width, height, relative)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
2014-07-12 21:33:22 +00:00
|
|
|
if relative then
|
|
|
|
self:SetMaxWidth(self.parent.width * width)
|
|
|
|
else
|
|
|
|
self:SetMaxWidth(width)
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetFont(font)
|
|
|
|
- desc: sets the object's font
|
|
|
|
- note: font argument must be a font object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetFont(font)
|
|
|
|
|
|
|
|
local original = self.original
|
|
|
|
|
|
|
|
self.font = font
|
|
|
|
|
|
|
|
if original then
|
|
|
|
self:SetText(original)
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetFont()
|
|
|
|
- desc: gets the object's font
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetFont()
|
|
|
|
|
|
|
|
return self.font
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetLines()
|
|
|
|
- desc: gets the number of lines the object's text uses
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetLines()
|
|
|
|
|
|
|
|
return self.lines
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetIgnoreNewlines(bool)
|
|
|
|
- desc: sets whether the object should ignore \n or not
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetIgnoreNewlines(bool)
|
|
|
|
|
|
|
|
self.ignorenewlines = bool
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetIgnoreNewlines()
|
|
|
|
- desc: gets whether the object should ignore \n or not
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetIgnoreNewlines()
|
|
|
|
|
|
|
|
return self.ignorenewlines
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetShadow(bool)
|
|
|
|
- desc: sets whether or not the object should draw a
|
2013-03-23 19:50:44 +00:00
|
|
|
shadow behind its text
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetShadow(bool)
|
|
|
|
|
|
|
|
self.shadow = bool
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetShadow()
|
|
|
|
- desc: gets whether or not the object should draw a
|
2013-03-23 19:50:44 +00:00
|
|
|
shadow behind its text
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetShadow()
|
|
|
|
|
|
|
|
return self.shadow
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetShadowOffsets(offsetx, offsety)
|
|
|
|
- desc: sets the object's x and y shadow offsets
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetShadowOffsets(offsetx, offsety)
|
|
|
|
|
|
|
|
self.shadowxoffset = offsetx
|
|
|
|
self.shadowyoffset = offsety
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetShadowOffsets()
|
|
|
|
- desc: gets the object's x and y shadow offsets
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetShadowOffsets()
|
|
|
|
|
|
|
|
return self.shadowxoffset, self.shadowyoffset
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetShadowColor(r, g, b, a)
|
|
|
|
- desc: sets the object's shadow color
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetShadowColor(r, g, b, a)
|
|
|
|
|
|
|
|
self.shadowcolor = {r, g, b, a}
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetShadowColor()
|
|
|
|
- desc: gets the object's shadow color
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetShadowColor()
|
|
|
|
|
|
|
|
return self.shadowcolor
|
|
|
|
|
2013-05-05 23:51:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetDefaultColor(r, g, b, a)
|
|
|
|
- desc: sets the object's default text color
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetDefaultColor(r, g, b, a)
|
|
|
|
|
|
|
|
self.defaultcolor = {r, g, b, a}
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-05-05 23:51:20 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetDefaultColor()
|
2013-11-04 16:23:39 +00:00
|
|
|
- desc: gets whether or not the object should draw a
|
|
|
|
shadow behind its text
|
2013-05-05 23:51:20 +00:00
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetDefaultColor()
|
|
|
|
|
|
|
|
return self.defaultcolor
|
|
|
|
|
2013-11-04 16:23:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetLinksEnabled(enabled)
|
|
|
|
- desc: sets whether or not the object should process
|
|
|
|
urls into clickable links
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetLinksEnabled(enabled)
|
|
|
|
|
|
|
|
self.linksenabled = enabled
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-11-04 16:23:39 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetLinksEnabled()
|
|
|
|
- desc: gets whether or not the object should process
|
|
|
|
urls into clickable links
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetLinksEnabled()
|
|
|
|
|
|
|
|
return self.linksenabled
|
|
|
|
|
2013-11-25 15:18:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetDetectLinks(detect)
|
|
|
|
- desc: sets whether or not the object should detect
|
|
|
|
links when processing new text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetDetectLinks(detect)
|
|
|
|
|
|
|
|
self.detectlinks = detect
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-11-25 15:18:26 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetDetectLinks()
|
|
|
|
- desc: gets whether or not the object should detect
|
|
|
|
links when processing new text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetDetectLinks()
|
|
|
|
|
|
|
|
return self.detectlinks
|
|
|
|
|
2014-02-22 21:48:49 +00:00
|
|
|
end
|
2019-03-06 23:19:58 +00:00
|
|
|
|
|
|
|
---------- module end ----------
|
|
|
|
end
|