mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-26 05:14:21 +00:00
base code for text object clickable links
This commit is contained in:
parent
c9f3d785cb
commit
4734d92376
@ -13,12 +13,16 @@ Version 0.9.6.4 - Alpha (Release Date TBD)
|
|||||||
[ADDED] a new textinput method: GetMasked()
|
[ADDED] a new textinput method: GetMasked()
|
||||||
[ADDED] a new textinput method: SetMaskChar(char)
|
[ADDED] a new textinput method: SetMaskChar(char)
|
||||||
[ADDED] a new textinput method: GetMaskChar()
|
[ADDED] a new textinput method: GetMaskChar()
|
||||||
|
[ADDED] a new text method: SetLinksEnabled(enabled)
|
||||||
|
[ADDED] a new text method: GetLinksEnabled()
|
||||||
|
[ADDED] a new text event callback: OnClickLink(object, text)
|
||||||
[ADDED] a new util library function: TableHasValue(table, value)
|
[ADDED] a new util library function: TableHasValue(table, value)
|
||||||
[ADDED] a new util library function: GetHoverObject()
|
[ADDED] a new util library function: GetHoverObject()
|
||||||
[ADDED] a new callback: textinput(text)
|
[ADDED] a new callback: textinput(text)
|
||||||
[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 changes to loveframes.util.GetDirectoryContents (0.9.0 only)
|
[ADDED] support for love.filesystem changes to loveframes.util.GetDirectoryContents (0.9.0 only)
|
||||||
|
[ADDED] support for text object link processing
|
||||||
[ADDED] loveframes.downobject
|
[ADDED] loveframes.downobject
|
||||||
|
|
||||||
[FIXED] error when pressing a function key while a textinput was focused
|
[FIXED] error when pressing a function key while a textinput was focused
|
||||||
|
127
objects/text.lua
127
objects/text.lua
@ -29,9 +29,14 @@ function newobject:initialize()
|
|||||||
self.original = {}
|
self.original = {}
|
||||||
self.defaultcolor = {0, 0, 0, 255}
|
self.defaultcolor = {0, 0, 0, 255}
|
||||||
self.shadowcolor = {0, 0, 0, 255}
|
self.shadowcolor = {0, 0, 0, 255}
|
||||||
|
self.linkcolor = {0, 102, 255, 255}
|
||||||
|
self.linkhovercolor = {0, 0, 255, 255}
|
||||||
self.ignorenewlines = false
|
self.ignorenewlines = false
|
||||||
|
self.linkcursorset = false
|
||||||
self.shadow = false
|
self.shadow = false
|
||||||
self.internal = false
|
self.internal = false
|
||||||
|
self.linksenabled = false
|
||||||
|
self.OnClickLink = nil
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -63,12 +68,52 @@ function newobject:update(dt)
|
|||||||
|
|
||||||
self:CheckHover()
|
self:CheckHover()
|
||||||
|
|
||||||
|
local hover = self.hover
|
||||||
|
local linksenabled = self.linksenabled
|
||||||
|
local linkcol = false
|
||||||
|
if hover and linksenabled then
|
||||||
|
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()
|
||||||
|
local col = loveframes.util.BoundingBox(x + linkx, mx, y + linky, my, twidth, 1, theight, 1)
|
||||||
|
v.hover = false
|
||||||
|
if col then
|
||||||
|
local linkcursorset = self.linkcursorset
|
||||||
|
v.hover = true
|
||||||
|
if not linkcursorset then
|
||||||
|
local newcursor = love.mouse.getSystemCursor("hand")
|
||||||
|
love.mouse.setCursor(newcursor)
|
||||||
|
self.linkcursorset = true
|
||||||
|
end
|
||||||
|
linkcol = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- move to parent if there is a parent
|
-- move to parent if there is a parent
|
||||||
if parent ~= base then
|
if parent ~= base then
|
||||||
self.x = self.parent.x + self.staticx
|
self.x = self.parent.x + self.staticx
|
||||||
self.y = self.parent.y + self.staticy
|
self.y = self.parent.y + self.staticy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local linkcursorset = self.linkcursorset
|
||||||
|
if not linkcol and linkcursorset then
|
||||||
|
self.linkcursorset = false
|
||||||
|
love.mouse.setCursor()
|
||||||
|
end
|
||||||
|
|
||||||
if update then
|
if update then
|
||||||
update(self, dt)
|
update(self, dt)
|
||||||
end
|
end
|
||||||
@ -134,12 +179,35 @@ function newobject:mousepressed(x, y, button)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local hover = self.hover
|
local hover = self.hover
|
||||||
|
|
||||||
if hover and button == "l" then
|
if hover and button == "l" then
|
||||||
local baseparent = self:GetBaseParent()
|
local baseparent = self:GetBaseParent()
|
||||||
if baseparent and baseparent.type == "frame" then
|
if baseparent and baseparent.type == "frame" then
|
||||||
baseparent:MakeTop()
|
baseparent:MakeTop()
|
||||||
end
|
end
|
||||||
|
local linksenabled = self.linksenabled
|
||||||
|
if linksenabled then
|
||||||
|
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 linkx = v.x
|
||||||
|
local linky = v.y
|
||||||
|
local font = v.font
|
||||||
|
local text = v.text
|
||||||
|
local twidth = font:getWidth(text)
|
||||||
|
local theight = font:getHeight()
|
||||||
|
local col = loveframes.util.BoundingBox(x + linkx, x, y + linky, y, twidth, 1, theight, 1)
|
||||||
|
if col then
|
||||||
|
local onclicklink = self.OnClickLink
|
||||||
|
if onclicklink then
|
||||||
|
onclicklink(self, text)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -251,10 +319,16 @@ function newobject:SetText(t)
|
|||||||
local largestwidth = 0
|
local largestwidth = 0
|
||||||
local largestheight = 0
|
local largestheight = 0
|
||||||
local initialwidth = 0
|
local initialwidth = 0
|
||||||
|
local linksenabled = self.linksenabled
|
||||||
|
|
||||||
for k, v in ipairs(textdata) do
|
for k, v in ipairs(textdata) do
|
||||||
local text = v.text
|
local text = v.text
|
||||||
local color = v.color
|
local color = v.color
|
||||||
|
if linksenabled then
|
||||||
|
if #text > 7 and text:sub(1, 7) == "http://" then
|
||||||
|
v.link = true
|
||||||
|
end
|
||||||
|
end
|
||||||
if type(text) == "string" then
|
if type(text) == "string" then
|
||||||
self.text = self.text .. text
|
self.text = self.text .. text
|
||||||
local width = v.font:getWidth(text)
|
local width = v.font:getWidth(text)
|
||||||
@ -374,28 +448,44 @@ function newobject:DrawText()
|
|||||||
local inlist, list = self:IsInList()
|
local inlist, list = self:IsInList()
|
||||||
|
|
||||||
for k, v in ipairs(textdata) do
|
for k, v in ipairs(textdata) do
|
||||||
|
local textx = v.x
|
||||||
|
local texty = v.y
|
||||||
local text = v.text
|
local text = v.text
|
||||||
local color = v.color
|
local color = v.color
|
||||||
local font = v.font
|
local font = v.font
|
||||||
|
local link = v.link
|
||||||
local theight = font:getHeight("a")
|
local theight = font:getHeight("a")
|
||||||
if inlist then
|
if inlist then
|
||||||
if (y + v.y) <= (list.y + list.height) and self.y + ((v.y + theight)) >= list.y then
|
local listy = list.y
|
||||||
|
local listhieght = list.height
|
||||||
|
if (y + texty) <= (listy + listhieght) and y + ((texty + theight)) >= listy then
|
||||||
love.graphics.setFont(font)
|
love.graphics.setFont(font)
|
||||||
if shadow then
|
if shadow then
|
||||||
love.graphics.setColor(unpack(shadowcolor))
|
love.graphics.setColor(unpack(shadowcolor))
|
||||||
love.graphics.print(text, x + v.x + shadowxoffset, y + v.y + shadowyoffset)
|
love.graphics.print(text, x + textx + shadowxoffset, y + texty + shadowyoffset)
|
||||||
end
|
end
|
||||||
|
if link then
|
||||||
|
local linkcolor = self.linkcolor
|
||||||
|
local linkhovercolor = self.linkhovercolor
|
||||||
|
local hover = v.hover
|
||||||
|
if hover then
|
||||||
|
love.graphics.setColor(linkhovercolor)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(linkcolor)
|
||||||
|
end
|
||||||
|
else
|
||||||
love.graphics.setColor(unpack(color))
|
love.graphics.setColor(unpack(color))
|
||||||
love.graphics.print(text, x + v.x, y + v.y)
|
end
|
||||||
|
love.graphics.print(text, x + textx, y + texty)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
love.graphics.setFont(font)
|
love.graphics.setFont(font)
|
||||||
if shadow then
|
if shadow then
|
||||||
love.graphics.setColor(unpack(shadowcolor))
|
love.graphics.setColor(unpack(shadowcolor))
|
||||||
love.graphics.print(text, x + v.x + shadowxoffset, y + v.y + shadowyoffset)
|
love.graphics.print(text, x + textx + shadowxoffset, y + texty + shadowyoffset)
|
||||||
end
|
end
|
||||||
love.graphics.setColor(unpack(color))
|
love.graphics.setColor(unpack(color))
|
||||||
love.graphics.print(text, x + v.x, y + v.y)
|
love.graphics.print(text, x + textx, y + texty)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -586,10 +676,33 @@ end
|
|||||||
|
|
||||||
--[[---------------------------------------------------------
|
--[[---------------------------------------------------------
|
||||||
- func: GetDefaultColor()
|
- func: GetDefaultColor()
|
||||||
- desc: gets the object's default text color
|
- desc: gets whether or not the object should draw a
|
||||||
|
shadow behind its text
|
||||||
--]]---------------------------------------------------------
|
--]]---------------------------------------------------------
|
||||||
function newobject:GetDefaultColor()
|
function newobject:GetDefaultColor()
|
||||||
|
|
||||||
return self.defaultcolor
|
return self.defaultcolor
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[---------------------------------------------------------
|
||||||
|
- func: SetLinksEnabled(enabled)
|
||||||
|
- desc: sets whether or not the object should process
|
||||||
|
urls into clickable links
|
||||||
|
--]]---------------------------------------------------------
|
||||||
|
function newobject:SetLinksEnabled(enabled)
|
||||||
|
|
||||||
|
self.linksenabled = enabled
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[---------------------------------------------------------
|
||||||
|
- func: GetLinksEnabled()
|
||||||
|
- desc: gets whether or not the object should process
|
||||||
|
urls into clickable links
|
||||||
|
--]]---------------------------------------------------------
|
||||||
|
function newobject:GetLinksEnabled()
|
||||||
|
|
||||||
|
return self.linksenabled
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user