mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
Version 0.9.3 - Alpha (see changelog.txt)
This commit is contained in:
parent
92869bcd22
commit
138e335f82
299
changelog.txt
299
changelog.txt
@ -1,128 +1,173 @@
|
||||
================================================
|
||||
Version 0.9.2.5 - Alpha (June 1 - 2012)
|
||||
================================================
|
||||
[FIXED] the text object not drawing numbers in certain situations
|
||||
[FIXED] a typo in the changelog
|
||||
|
||||
================================================
|
||||
Version 0.9.2.4 - Alpha (May 29 - 2012)
|
||||
================================================
|
||||
[FIXED] the SetSkin(skin) method causing a stack overflow
|
||||
|
||||
================================================
|
||||
Version 0.9.2.3 - Alpha (May 27 - 2012)
|
||||
================================================
|
||||
[FIXED] imagebutton.OnClick not working
|
||||
[FIXED] text being added into the text input object at incorrect positions when the value of textinput.blinknum was 0
|
||||
[FIXED] a bug that would cause an error when running SetVisible on a frame object when the value of frame.showclose was true
|
||||
|
||||
================================================
|
||||
Version 0.9.2.2 - Alpha (May 23 - 2012)
|
||||
================================================
|
||||
[FIXED] vertical slider value direction (top is now max value and bottom is 0)
|
||||
[FIXED] text flashing in the text input object when moving the text blinker to the right
|
||||
[FIXED] text blinker in the text input object not appearing in certain situations
|
||||
|
||||
================================================
|
||||
Version 0.9.2 - Alpha (May 22 - 2012)
|
||||
================================================
|
||||
[ADDED] a new slider method: SetButtonSize(width, height)
|
||||
[ADDED] a new slider method: GetButtonSize()
|
||||
[ADDED] a new slider method: SetSlideType(slidetype)
|
||||
[ADDED] a new slider button method: MoveToY(y)
|
||||
|
||||
[REMOVED] slider method: SetButtonYCenter(y)
|
||||
[REMOVED] slider method: GetButtonYCenter()
|
||||
|
||||
[FIXED] the column list row object not setting it's text's font to it's font
|
||||
[FIXED] a small graient error in the default skins
|
||||
[FIXED] an error that caused tab buttons to be overscrolled with the middle mouse button
|
||||
[FIXED] the scroll area object not moving it's base parent to the top when clicked (only in situatuions where it'sbase parent was a frame)
|
||||
|
||||
[CHANGED] sliders no longer use ycenter for button positioning
|
||||
[CHANGED] slider functionality, sliders can now be horizontal or vertical (use slider:SetSlideType("horizontal" or "vertical"))
|
||||
[CHANGED] lots of code for optimization and general cleanliness
|
||||
[CHANGED] a few minor things in the default skins
|
||||
[CHANGED] scrollbar hover behavior when being moved via it's scroll area being clicked (will no longer auto hover when it reaches the mouse position)
|
||||
|
||||
================================================
|
||||
Version 0.9.1.6 - Alpha (May 17 - 2012)
|
||||
================================================
|
||||
[ADDED] a new column list method: Clear()
|
||||
[ADDED] a new column list method: SetAutoScroll(bool)
|
||||
[ADDED] "autoscroll" property for the column list object
|
||||
[ADDED] a new column list area method: Clear()
|
||||
[ADDED] a new skin function: DrawOverTextInput()
|
||||
|
||||
[FIXED] not being able to move the column list object's scrollbar by clicking on it's scroll area
|
||||
[FIXED] column list rows color indexs becoming disorderd when the list was sorted via a column list header
|
||||
|
||||
[CHANGED] a few minor things in the default skins
|
||||
|
||||
================================================
|
||||
Version 0.9.1.5 - Alpha (May 16 - 2012)
|
||||
================================================
|
||||
[FIXED] a bug that caused scrollbars to always autoscroll
|
||||
|
||||
================================================
|
||||
Version 0.9.1.4 - Alpha (May 16 - 2012)
|
||||
================================================
|
||||
[FIXED] list:SetAutoScroll() not working
|
||||
|
||||
================================================
|
||||
Version 0.9.1.3 - Alpha (May 14 - 2012)
|
||||
================================================
|
||||
[ADDED] modal system for frames
|
||||
[ADDED] a new frame method: SetModal(bool)
|
||||
[ADDED] a new frame method: GetModal()
|
||||
[ADDED] a new frame method: SetVisible(bool) - this override is part of a frame bug fix
|
||||
[ADDED] "showclose" property for the frame object
|
||||
[ADDED] a new internal object: modal background
|
||||
[ADDED] a new base method: IsActive()
|
||||
[ADDED] a new base method: CenterX()
|
||||
[ADDED] a new base method: CenterY()
|
||||
[ADDED] a new skin function: DrawOverColumList()
|
||||
|
||||
[FIXED] a bug that made the frame's close button become visisble when the frame was made visible and show close button was set to false
|
||||
|
||||
================================================
|
||||
Version 0.9.1.2 - Alpha (May 12 - 2012)
|
||||
================================================
|
||||
[ADDED] a system for preventing objects from being hovered over when another object is being pressed or is "down"
|
||||
[ADDED] "down" property for the checkbox object
|
||||
[ADDED] "down" property for the collapsible category object
|
||||
[ADDED] a new method for the tabs object: SetToolTipFont(font)
|
||||
|
||||
[FIXED] list:GetScrollBar() crashing when the list had no scroll bar
|
||||
[FIXED] not being able to move the text input blinker to the front or end of the it's text by clicking on it's whitespace
|
||||
[FIXED] the multichoice row object being "down" when mouse buttons other than the left mouse button were pressed
|
||||
|
||||
[CHANGED] collapsible category opening and closing system (will now only open or close when "down")
|
||||
|
||||
================================================
|
||||
Version 0.9.1 - Alpha (May 8 - 2012)
|
||||
================================================
|
||||
[ADDED] a new object: image button
|
||||
[ADDED] a new skin: Orange
|
||||
[ADDED] a new column list row method: SetTextPos(x, y)
|
||||
[ADDED] a new column list row method: SetFont(font)
|
||||
[ADDED] a new column list row method: GetFont()
|
||||
[ADDED] a new column list row method: GetColorIndex()
|
||||
[ADDED] a new column list row method: SetTextColor(color)
|
||||
[ADDED] a new debug function: SkinSelector()
|
||||
[ADDED] license.txt
|
||||
[ADDED] changelog.txt
|
||||
|
||||
[CHANGED] the name of the default skin to Blue
|
||||
[CHANGED] the drawing system of the image object, the image object will now draw it's image from it's skin function instead of it's internal drawing function
|
||||
[CHANGED] argument type for adding an image to a tab in tabs:AddTab(), the image argument can now be either an image object or a string containg the path to an image
|
||||
[CHANGED] the look of the debug overlay
|
||||
[CHANGED] some of the code within the default skins to improve performance (as suggested by kikito)
|
||||
|
||||
[REMOVED] license.html
|
||||
[REMOVED] loveframes.graphics and graphics.lua
|
||||
|
||||
================================================
|
||||
Version 0.9 - Alpha (May 5 - 2012)
|
||||
================================================
|
||||
================================================
|
||||
Version 0.9.3 - Alpha (Spetember 1 - 2012)
|
||||
================================================
|
||||
|
||||
[ADDED] a new base method: GetParents()
|
||||
[ADDED] a new base method: IsTopInternal()
|
||||
[ADDED] a new base method: IsInternal()
|
||||
[ADDED] a new base method: GetType()
|
||||
[ADDED] a new checkbox method: GetFont()
|
||||
[ADDED] a new checkbox method: GetBoxSize()
|
||||
[ADDED] a new checkbox method: GetBoxWidth()
|
||||
[ADDED] a new checkbox method: GetBoxHeight()
|
||||
[ADDED] a new image method: GetImage()
|
||||
[ADDED] a new image method: GetColor()
|
||||
[ADDED] a new progressbar method: GetCompleted()
|
||||
[ADDED] a new tabs method: GetTabNumber()
|
||||
[ADDED] a new text method: GetLines()
|
||||
[ADDED] a new text input method: SetLimit(limit)
|
||||
[ADDED] a new text input method: SetUsable(usable)
|
||||
[ADDED] a new text input method: SetUnusable(unusable)
|
||||
[ADDED] a new text input method: Clear()
|
||||
[ADDED] a new text input method: GetText()
|
||||
[ADDED] support for line breaks in the text object (please refer to the wiki on how to format your text with line breaks)
|
||||
[ADDED] more information to the debug overlay
|
||||
|
||||
[FIXED] tooltips and multichoice lists not functioning properly when a frame was modaled
|
||||
[FIXED] the text object not moving it's base parent to the top when clicked if it's base parent was a frame
|
||||
[FIXED] the list object not scrolling via the mouse wheel due to certain collision detection issues
|
||||
[FIXED] tooltips flickering when in a hover state
|
||||
[FIXED] slider calculation errors
|
||||
[FIXED] skin.DrawRepeatingImage creating a new image every frame
|
||||
[FIXED] checkbox text not scrolling properly when in a list
|
||||
[FIXED] the collapsible category's object not scrolling properly when in a list
|
||||
[FIXED] skins not assuming the drawing functions of the default skins if drawing functions in the active skin were missing
|
||||
[FIXED] some objects not being removed
|
||||
[FIXED] sliders not scrolling properly when in a list
|
||||
|
||||
[CHANGED] various code for a small cleanup
|
||||
[CHANGED] tooltips from being children of the base object to internals of the base object
|
||||
[CHANGED] tooltips from never being removed to being removed when their assigned object is removed
|
||||
[CHANGED] tooltips are now not able to be assigned to the base object (this would cause an error due to the way the tooltip currently functions)
|
||||
[CHANGED] the text object now positions it's text when SetText is called instead of positioning it's text every frame
|
||||
[CHANGED] slider:SetMax(max), slider:SetMin(min) and slider:SetMinMax(min, max) now adjust the slider's value if the slider's value is out of the range specified
|
||||
[CHANGED] loveframes.Create(data, parent) now activates an error screen if the object specified is invalid
|
||||
|
||||
================================================
|
||||
Version 0.9.2.5 - Alpha (June 1 - 2012)
|
||||
================================================
|
||||
[FIXED] the text object not drawing numbers in certain situations
|
||||
[FIXED] a typo in the changelog
|
||||
|
||||
================================================
|
||||
Version 0.9.2.4 - Alpha (May 29 - 2012)
|
||||
================================================
|
||||
[FIXED] the SetSkin(skin) method causing a stack overflow
|
||||
|
||||
================================================
|
||||
Version 0.9.2.3 - Alpha (May 27 - 2012)
|
||||
================================================
|
||||
[FIXED] imagebutton.OnClick not working
|
||||
[FIXED] text being added into the text input object at incorrect positions when the value of textinput.blinknum was 0
|
||||
[FIXED] a bug that would cause an error when running SetVisible on a frame object when the value of frame.showclose was true
|
||||
|
||||
================================================
|
||||
Version 0.9.2.2 - Alpha (May 23 - 2012)
|
||||
================================================
|
||||
[FIXED] vertical slider value direction (top is now max value and bottom is 0)
|
||||
[FIXED] text flashing in the text input object when moving the text blinker to the right
|
||||
[FIXED] text blinker in the text input object not appearing in certain situations
|
||||
|
||||
================================================
|
||||
Version 0.9.2 - Alpha (May 22 - 2012)
|
||||
================================================
|
||||
[ADDED] a new slider method: SetButtonSize(width, height)
|
||||
[ADDED] a new slider method: GetButtonSize()
|
||||
[ADDED] a new slider method: SetSlideType(slidetype)
|
||||
[ADDED] a new slider button method: MoveToY(y)
|
||||
|
||||
[REMOVED] slider method: SetButtonYCenter(y)
|
||||
[REMOVED] slider method: GetButtonYCenter()
|
||||
|
||||
[FIXED] the column list row object not setting it's text's font to it's font
|
||||
[FIXED] a small graient error in the default skins
|
||||
[FIXED] an error that caused tab buttons to be overscrolled with the middle mouse button
|
||||
[FIXED] the scroll area object not moving it's base parent to the top when clicked (only in situatuions where it'sbase parent was a frame)
|
||||
|
||||
[CHANGED] sliders no longer use ycenter for button positioning
|
||||
[CHANGED] slider functionality, sliders can now be horizontal or vertical (use slider:SetSlideType("horizontal" or "vertical"))
|
||||
[CHANGED] lots of code for optimization and general cleanliness
|
||||
[CHANGED] a few minor things in the default skins
|
||||
[CHANGED] scrollbar hover behavior when being moved via it's scroll area being clicked (will no longer auto hover when it reaches the mouse position)
|
||||
|
||||
================================================
|
||||
Version 0.9.1.6 - Alpha (May 17 - 2012)
|
||||
================================================
|
||||
[ADDED] a new column list method: Clear()
|
||||
[ADDED] a new column list method: SetAutoScroll(bool)
|
||||
[ADDED] "autoscroll" property for the column list object
|
||||
[ADDED] a new column list area method: Clear()
|
||||
[ADDED] a new skin function: DrawOverTextInput()
|
||||
|
||||
[FIXED] not being able to move the column list object's scrollbar by clicking on it's scroll area
|
||||
[FIXED] column list rows color indexs becoming disorderd when the list was sorted via a column list header
|
||||
|
||||
[CHANGED] a few minor things in the default skins
|
||||
|
||||
================================================
|
||||
Version 0.9.1.5 - Alpha (May 16 - 2012)
|
||||
================================================
|
||||
[FIXED] a bug that caused scrollbars to always autoscroll
|
||||
|
||||
================================================
|
||||
Version 0.9.1.4 - Alpha (May 16 - 2012)
|
||||
================================================
|
||||
[FIXED] list:SetAutoScroll() not working
|
||||
|
||||
================================================
|
||||
Version 0.9.1.3 - Alpha (May 14 - 2012)
|
||||
================================================
|
||||
[ADDED] modal system for frames
|
||||
[ADDED] a new frame method: SetModal(bool)
|
||||
[ADDED] a new frame method: GetModal()
|
||||
[ADDED] a new frame method: SetVisible(bool) - this override is part of a frame bug fix
|
||||
[ADDED] "showclose" property for the frame object
|
||||
[ADDED] a new internal object: modal background
|
||||
[ADDED] a new base method: IsActive()
|
||||
[ADDED] a new base method: CenterX()
|
||||
[ADDED] a new base method: CenterY()
|
||||
[ADDED] a new skin function: DrawOverColumList()
|
||||
|
||||
[FIXED] a bug that made the frame's close button become visisble when the frame was made visible and show close button was set to false
|
||||
|
||||
================================================
|
||||
Version 0.9.1.2 - Alpha (May 12 - 2012)
|
||||
================================================
|
||||
[ADDED] a system for preventing objects from being hovered over when another object is being pressed or is "down"
|
||||
[ADDED] "down" property for the checkbox object
|
||||
[ADDED] "down" property for the collapsible category object
|
||||
[ADDED] a new method for the tabs object: SetToolTipFont(font)
|
||||
|
||||
[FIXED] list:GetScrollBar() crashing when the list had no scroll bar
|
||||
[FIXED] not being able to move the text input blinker to the front or end of the it's text by clicking on it's whitespace
|
||||
[FIXED] the multichoice row object being "down" when mouse buttons other than the left mouse button were pressed
|
||||
|
||||
[CHANGED] collapsible category opening and closing system (will now only open or close when "down")
|
||||
|
||||
================================================
|
||||
Version 0.9.1 - Alpha (May 8 - 2012)
|
||||
================================================
|
||||
[ADDED] a new object: image button
|
||||
[ADDED] a new skin: Orange
|
||||
[ADDED] a new column list row method: SetTextPos(x, y)
|
||||
[ADDED] a new column list row method: SetFont(font)
|
||||
[ADDED] a new column list row method: GetFont()
|
||||
[ADDED] a new column list row method: GetColorIndex()
|
||||
[ADDED] a new column list row method: SetTextColor(color)
|
||||
[ADDED] a new debug function: SkinSelector()
|
||||
[ADDED] license.txt
|
||||
[ADDED] changelog.txt
|
||||
|
||||
[CHANGED] the name of the default skin to Blue
|
||||
[CHANGED] the drawing system of the image object, the image object will now draw it's image from it's skin function instead of it's internal drawing function
|
||||
[CHANGED] argument type for adding an image to a tab in tabs:AddTab(), the image argument can now be either an image object or a string containg the path to an image
|
||||
[CHANGED] the look of the debug overlay
|
||||
[CHANGED] some of the code within the default skins to improve performance (as suggested by kikito)
|
||||
|
||||
[REMOVED] license.html
|
||||
[REMOVED] loveframes.graphics and graphics.lua
|
||||
|
||||
================================================
|
||||
Version 0.9 - Alpha (May 5 - 2012)
|
||||
================================================
|
||||
Initial commit
|
506
init.lua
506
init.lua
@ -1,249 +1,259 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- central library table
|
||||
loveframes = {}
|
||||
|
||||
-- library info
|
||||
loveframes.info = {}
|
||||
loveframes.info.author = "Nikolai Resokav"
|
||||
loveframes.info.version = "0.9.2.5"
|
||||
loveframes.info.stage = "Alpha"
|
||||
|
||||
-- library configurations
|
||||
loveframes.config = {}
|
||||
loveframes.config["DIRECTORY"] = "libraries/loveframes"
|
||||
loveframes.config["DEFAULTSKIN"] = "Blue"
|
||||
loveframes.config["ACTIVESKIN"] = "Blue"
|
||||
loveframes.config["INDEXSKINIMAGES"] = true
|
||||
loveframes.config["DEBUG"] = true
|
||||
|
||||
loveframes.drawcount = 0
|
||||
loveframes.hoverobject = false
|
||||
loveframes.modalobject = false
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: load()
|
||||
- desc: loads the library
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.load()
|
||||
|
||||
-- install directory of the library
|
||||
local dir = loveframes.config["DIRECTORY"]
|
||||
|
||||
-- require the internal base libraries
|
||||
require(dir .. "/third-party/middleclass/middleclass")
|
||||
require(dir .. "/util")
|
||||
require(dir .. "/skins")
|
||||
require(dir .. "/templates")
|
||||
require(dir .. "/debug")
|
||||
|
||||
-- create a list of gui objects and skins
|
||||
local objects = loveframes.util.GetDirContents(dir .. "/objects")
|
||||
local skins = loveframes.util.GetDirContents(dir .. "/skins")
|
||||
|
||||
-- loop through a list of all gui objects and require them
|
||||
for k, v in ipairs(objects) do
|
||||
if v.extension == "lua" then
|
||||
require(v.path .. "/" ..v.name)
|
||||
end
|
||||
end
|
||||
|
||||
-- loop through a list of all gui skins and require them
|
||||
for k, v in ipairs(skins) do
|
||||
if v.extension == "lua" then
|
||||
require(v.path .. "/" ..v.name)
|
||||
end
|
||||
end
|
||||
|
||||
-- create the base gui object
|
||||
loveframes.base = base:new()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates all library objects
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.update(dt)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:update(dt)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws all library objects
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.draw()
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
-- set the drawcount to zero
|
||||
loveframes.drawcount = 0
|
||||
|
||||
-- draw the base object
|
||||
object:draw()
|
||||
|
||||
-- draw the debug library
|
||||
loveframes.debug.draw()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.mousepressed(x, y, button)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:mousepressed(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.mousereleased(x, y, button)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:mousereleased(x, y, button)
|
||||
|
||||
if button == "l" then
|
||||
loveframes.hoverobject = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: keypressed(key)
|
||||
- desc: called when the player presses a key
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.keypressed(key, unicode)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:keypressed(key, unicode)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: keyreleased(key)
|
||||
- desc: called when the player releases a key
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.keyreleased(key)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:keyreleased(key)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: New(type, parent)
|
||||
- desc: creates a new object or multiple new objects
|
||||
(based on the method used) and returns said
|
||||
object or objects for further manipulation
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.Create(data, parent)
|
||||
|
||||
if type(data) == "string" then
|
||||
|
||||
-- create the new object
|
||||
local object = _G[data]:new()
|
||||
|
||||
if object.internal == true then
|
||||
if object.type == "tooltip" then
|
||||
object = tooltip:new()
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- parent the new object by default to the base gui object
|
||||
object.parent = loveframes.base
|
||||
table.insert(loveframes.base.children, object)
|
||||
|
||||
-- if the parent argument is not nil, make that argument the object's new parent
|
||||
if parent ~= nil then
|
||||
object:SetParent(parent)
|
||||
end
|
||||
|
||||
-- return the object for further manipulation
|
||||
return object
|
||||
|
||||
elseif type(data) == "table" then
|
||||
|
||||
-- table for creation of multiple objects
|
||||
local objects = {}
|
||||
|
||||
-- this function reads a table that contains a layout of object properties and then
|
||||
-- creates objects based on those properties
|
||||
local function CreateObjects(t, o, c)
|
||||
|
||||
local child = c or false
|
||||
|
||||
for k, v in pairs(t) do
|
||||
|
||||
-- current default object
|
||||
local object = _G[v.type]:new()
|
||||
|
||||
-- indert the object into the table of objects being created
|
||||
table.insert(objects, object)
|
||||
|
||||
-- parent the new object by default to the base gui object
|
||||
object.parent = loveframes.base
|
||||
table.insert(loveframes.base.children, object)
|
||||
|
||||
if o then
|
||||
object:SetParent(o)
|
||||
end
|
||||
|
||||
-- loop through the current layout table and assign the properties found
|
||||
-- to the current object
|
||||
for i, j in pairs(v) do
|
||||
|
||||
if i ~= "children" and i ~= "func" then
|
||||
if child == true then
|
||||
if i == "x" then
|
||||
object["staticx"] = j
|
||||
elseif i == "y" then
|
||||
object["staticy"] = j
|
||||
else
|
||||
object[i] = j
|
||||
end
|
||||
else
|
||||
object[i] = j
|
||||
end
|
||||
elseif i == "children" then
|
||||
CreateObjects(j, object, true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if v.func then
|
||||
v.func(object)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- create the objects
|
||||
CreateObjects(data)
|
||||
|
||||
return objects
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- load the library
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- central library table
|
||||
loveframes = {}
|
||||
|
||||
-- library info
|
||||
loveframes.info = {}
|
||||
loveframes.info.author = "Nikolai Resokav"
|
||||
loveframes.info.version = "0.9.3"
|
||||
loveframes.info.stage = "Alpha"
|
||||
|
||||
-- library configurations
|
||||
loveframes.config = {}
|
||||
loveframes.config["DIRECTORY"] = "libraries/loveframes"
|
||||
loveframes.config["DEFAULTSKIN"] = "Blue"
|
||||
loveframes.config["ACTIVESKIN"] = "Blue"
|
||||
loveframes.config["INDEXSKINIMAGES"] = true
|
||||
loveframes.config["DEBUG"] = true
|
||||
|
||||
loveframes.drawcount = 0
|
||||
loveframes.hoverobject = false
|
||||
loveframes.modalobject = false
|
||||
loveframes.basicfont = love.graphics.newFont(12)
|
||||
loveframes.basicfontsmall = love.graphics.newFont(10)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: load()
|
||||
- desc: loads the library
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.load()
|
||||
|
||||
-- install directory of the library
|
||||
local dir = loveframes.config["DIRECTORY"]
|
||||
|
||||
-- require the internal base libraries
|
||||
require(dir .. "/third-party/middleclass/middleclass")
|
||||
require(dir .. "/util")
|
||||
require(dir .. "/skins")
|
||||
require(dir .. "/templates")
|
||||
require(dir .. "/debug")
|
||||
|
||||
-- create a list of gui objects and skins
|
||||
local objects = loveframes.util.GetDirContents(dir .. "/objects")
|
||||
local skins = loveframes.util.GetDirContents(dir .. "/skins")
|
||||
|
||||
-- loop through a list of all gui objects and require them
|
||||
for k, v in ipairs(objects) do
|
||||
if v.extension == "lua" then
|
||||
require(v.path .. "/" ..v.name)
|
||||
end
|
||||
end
|
||||
|
||||
-- loop through a list of all gui skins and require them
|
||||
for k, v in ipairs(skins) do
|
||||
if v.extension == "lua" then
|
||||
require(v.path .. "/" ..v.name)
|
||||
end
|
||||
end
|
||||
|
||||
-- create the base gui object
|
||||
loveframes.base = base:new()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates all library objects
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.update(dt)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:update(dt)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws all library objects
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.draw()
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
-- set the drawcount to zero
|
||||
loveframes.drawcount = 0
|
||||
|
||||
-- draw the base object
|
||||
object:draw()
|
||||
|
||||
-- draw the debug library
|
||||
loveframes.debug.draw()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.mousepressed(x, y, button)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:mousepressed(x, y, button)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.mousereleased(x, y, button)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:mousereleased(x, y, button)
|
||||
|
||||
if button == "l" then
|
||||
loveframes.hoverobject = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: keypressed(key)
|
||||
- desc: called when the player presses a key
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.keypressed(key, unicode)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:keypressed(key, unicode)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: keyreleased(key)
|
||||
- desc: called when the player releases a key
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.keyreleased(key)
|
||||
|
||||
local object = loveframes.base
|
||||
|
||||
object:keyreleased(key)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: New(type, parent)
|
||||
- desc: creates a new object or multiple new objects
|
||||
(based on the method used) and returns said
|
||||
object or objects for further manipulation
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.Create(data, parent)
|
||||
|
||||
if type(data) == "string" then
|
||||
|
||||
-- make sure the object specified is valid
|
||||
if not _G[data] then
|
||||
error("Error creating object: Invalid object '" ..data.. "'.")
|
||||
end
|
||||
|
||||
-- create the object
|
||||
local object = _G[data]:new()
|
||||
|
||||
-- if the object is a tooltip, return it and go no further
|
||||
if data == "tooltip" then
|
||||
return object
|
||||
end
|
||||
|
||||
-- remove the object if it is an internal
|
||||
if object.internal == true then
|
||||
object:Remove()
|
||||
return
|
||||
end
|
||||
|
||||
-- parent the new object by default to the base gui object
|
||||
object.parent = loveframes.base
|
||||
table.insert(loveframes.base.children, object)
|
||||
|
||||
-- if the parent argument is not nil, make that argument the object's new parent
|
||||
if parent ~= nil then
|
||||
object:SetParent(parent)
|
||||
end
|
||||
|
||||
-- return the object for further manipulation
|
||||
return object
|
||||
|
||||
elseif type(data) == "table" then
|
||||
|
||||
-- table for creation of multiple objects
|
||||
local objects = {}
|
||||
|
||||
-- this function reads a table that contains a layout of object properties and then
|
||||
-- creates objects based on those properties
|
||||
local function CreateObjects(t, o, c)
|
||||
|
||||
local child = c or false
|
||||
|
||||
for k, v in pairs(t) do
|
||||
|
||||
-- current default object
|
||||
local object = _G[v.type]:new()
|
||||
|
||||
-- indert the object into the table of objects being created
|
||||
table.insert(objects, object)
|
||||
|
||||
-- parent the new object by default to the base gui object
|
||||
object.parent = loveframes.base
|
||||
table.insert(loveframes.base.children, object)
|
||||
|
||||
if o then
|
||||
object:SetParent(o)
|
||||
end
|
||||
|
||||
-- loop through the current layout table and assign the properties found
|
||||
-- to the current object
|
||||
for i, j in pairs(v) do
|
||||
|
||||
if i ~= "children" and i ~= "func" then
|
||||
if child == true then
|
||||
if i == "x" then
|
||||
object["staticx"] = j
|
||||
elseif i == "y" then
|
||||
object["staticy"] = j
|
||||
else
|
||||
object[i] = j
|
||||
end
|
||||
else
|
||||
object[i] = j
|
||||
end
|
||||
elseif i == "children" then
|
||||
CreateObjects(j, object, true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if v.func then
|
||||
v.func(object)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- create the objects
|
||||
CreateObjects(data)
|
||||
|
||||
return objects
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- load the library
|
||||
loveframes.load()
|
1949
objects/base.lua
1949
objects/base.lua
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- button clas
|
||||
@ -81,20 +81,21 @@ function button:draw()
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawButton or skins[defaultskin].DrawButton
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawButton(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,313 +1,354 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- button clas
|
||||
checkbox = class("checkbox", base)
|
||||
checkbox:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:initialize()
|
||||
|
||||
self.type = "checkbox"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.boxwidth = 20
|
||||
self.boxheight = 20
|
||||
self.font = love.graphics.newFont(12)
|
||||
self.checked = false
|
||||
self.lastvalue = false
|
||||
self.internal = false
|
||||
self.down = true
|
||||
self.internals = {}
|
||||
self.OnChanged = nil
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if self.hover == false then
|
||||
self.down = false
|
||||
elseif self.hover == true then
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.down == false and loveframes.hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.internals[1] then
|
||||
|
||||
self.width = self.boxwidth + 5 + self.internals[1].width
|
||||
|
||||
if self.internals[1].height == self.boxheight then
|
||||
self.height = self.boxheight
|
||||
else
|
||||
if self.internals[1].height > self.boxheight then
|
||||
self.height = self.internals[1].height
|
||||
else
|
||||
self.height = self.boxheight
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
self.width = self.boxwidth
|
||||
self.height = self.boxheight
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawCheckBox(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local checked = self.checked
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
if checked == true then
|
||||
self.checked = false
|
||||
else
|
||||
self.checked = true
|
||||
end
|
||||
|
||||
if self.OnChanged then
|
||||
self.OnChanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetText(text)
|
||||
|
||||
if text ~= "" then
|
||||
|
||||
self.internals = {}
|
||||
|
||||
local textobject = loveframes.Create("text")
|
||||
textobject:Remove()
|
||||
textobject.parent = self
|
||||
textobject.collide = false
|
||||
textobject:SetFont(self.font)
|
||||
textobject:SetText(text)
|
||||
textobject.Update = function(object, dt)
|
||||
if object.height > self.boxheight then
|
||||
object:SetPos(self.boxwidth + 5, 0)
|
||||
else
|
||||
object:SetPos(self.boxwidth + 5, self.boxheight/2 - object.height/2)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(self.internals, textobject)
|
||||
|
||||
else
|
||||
|
||||
self.width = self.boxwidth
|
||||
self.height = self.boxheight
|
||||
self.internals = {}
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:GetText()
|
||||
|
||||
local internals = self.internals
|
||||
local text = internals[1]
|
||||
|
||||
if text then
|
||||
return text.text
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSize(width, height)
|
||||
- desc: sets the object's size
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetSize(width, height)
|
||||
|
||||
self.boxwidth = width
|
||||
self.boxheight = height
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetWidth(width)
|
||||
- desc: sets the object's width
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetWidth(width)
|
||||
|
||||
self.boxwidth = width
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetHeight(height)
|
||||
- desc: sets the object's height
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetHeight(height)
|
||||
|
||||
self.boxheight = height
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetChecked(bool)
|
||||
- desc: sets whether the object is checked or not
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetChecked(bool)
|
||||
|
||||
self.checked = bool
|
||||
|
||||
if self.OnChanged then
|
||||
self.OnChanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetChecked()
|
||||
- desc: gets whether the object is checked or not
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:GetChecked()
|
||||
|
||||
return self.checked
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFont(font)
|
||||
- desc: sets the font of the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetFont(font)
|
||||
|
||||
local internals = self.internals
|
||||
local text = internals[1]
|
||||
|
||||
self.font = font
|
||||
|
||||
if text then
|
||||
text:SetFont(font)
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- checkbox class
|
||||
checkbox = class("checkbox", base)
|
||||
checkbox:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:initialize()
|
||||
|
||||
self.type = "checkbox"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.boxwidth = 20
|
||||
self.boxheight = 20
|
||||
self.font = loveframes.basicfont
|
||||
self.checked = false
|
||||
self.lastvalue = false
|
||||
self.internal = false
|
||||
self.down = true
|
||||
self.internals = {}
|
||||
self.OnChanged = nil
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if self.hover == false then
|
||||
self.down = false
|
||||
elseif self.hover == true then
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.down == false and loveframes.hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base and self.parent.type ~= "list" then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.internals[1] then
|
||||
|
||||
self.width = self.boxwidth + 5 + self.internals[1].width
|
||||
|
||||
if self.internals[1].height == self.boxheight then
|
||||
self.height = self.boxheight
|
||||
else
|
||||
if self.internals[1].height > self.boxheight then
|
||||
self.height = self.internals[1].height
|
||||
else
|
||||
self.height = self.boxheight
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
self.width = self.boxwidth
|
||||
self.height = self.boxheight
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawCheckBox or skins[defaultskin].DrawCheckBox
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local checked = self.checked
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
if checked == true then
|
||||
self.checked = false
|
||||
else
|
||||
self.checked = true
|
||||
end
|
||||
|
||||
if self.OnChanged then
|
||||
self.OnChanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetText(text)
|
||||
|
||||
if text ~= "" then
|
||||
|
||||
self.internals = {}
|
||||
|
||||
local textobject = loveframes.Create("text")
|
||||
textobject:Remove()
|
||||
textobject.parent = self
|
||||
textobject.collide = false
|
||||
textobject:SetFont(self.font)
|
||||
textobject:SetText(text)
|
||||
textobject.Update = function(object, dt)
|
||||
if object.height > self.boxheight then
|
||||
object:SetPos(self.boxwidth + 5, 0)
|
||||
else
|
||||
object:SetPos(self.boxwidth + 5, self.boxheight/2 - object.height/2)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(self.internals, textobject)
|
||||
|
||||
else
|
||||
|
||||
self.width = self.boxwidth
|
||||
self.height = self.boxheight
|
||||
self.internals = {}
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:GetText()
|
||||
|
||||
local internals = self.internals
|
||||
local text = internals[1]
|
||||
|
||||
if text then
|
||||
return text.text
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSize(width, height)
|
||||
- desc: sets the object's size
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetSize(width, height)
|
||||
|
||||
self.boxwidth = width
|
||||
self.boxheight = height
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetWidth(width)
|
||||
- desc: sets the object's width
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetWidth(width)
|
||||
|
||||
self.boxwidth = width
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetHeight(height)
|
||||
- desc: sets the object's height
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetHeight(height)
|
||||
|
||||
self.boxheight = height
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetChecked(bool)
|
||||
- desc: sets whether the object is checked or not
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetChecked(bool)
|
||||
|
||||
self.checked = bool
|
||||
|
||||
if self.OnChanged then
|
||||
self.OnChanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetChecked()
|
||||
- desc: gets whether the object is checked or not
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:GetChecked()
|
||||
|
||||
return self.checked
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFont(font)
|
||||
- desc: sets the font of the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:SetFont(font)
|
||||
|
||||
local internals = self.internals
|
||||
local text = internals[1]
|
||||
|
||||
self.font = font
|
||||
|
||||
if text then
|
||||
text:SetFont(font)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: checkbox:GetFont()
|
||||
- desc: gets the font of the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:GetFont()
|
||||
|
||||
return self.font
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: checkbox:GetBoxHeight()
|
||||
- desc: gets the object's box size
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:GetBoxSize()
|
||||
|
||||
return self.boxwidth, self.boxheight
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: checkbox:GetBoxWidth()
|
||||
- desc: gets the object's box width
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:GetBoxWidth()
|
||||
|
||||
return self.boxwidth
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: checkbox:GetBoxHeight()
|
||||
- desc: gets the object's box height
|
||||
--]]---------------------------------------------------------
|
||||
function checkbox:GetBoxHeight()
|
||||
|
||||
return self.boxheight
|
||||
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- button clas
|
||||
@ -49,16 +49,14 @@ function collapsiblecategory:update(dt)
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
if self.parent ~= loveframes.base and self.parent.type ~= "list" then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if open == true then
|
||||
curobject:update(dt)
|
||||
curobject:SetWidth(self.width - self.padding*2)
|
||||
curobject.y = (curobject.parent.y + curobject.staticy)
|
||||
curobject.x = (curobject.parent.x + curobject.staticx)
|
||||
curobject:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
@ -79,23 +77,23 @@ function collapsiblecategory:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local open = self.open
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
local open = self.open
|
||||
local children = self.children
|
||||
local curobject = children[1]
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawCollapsibleCategory or skins[defaultskin].DrawCollapsibleCategory
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawCollapsibleCategory(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
if open == true then
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- columnlist object
|
||||
@ -83,19 +83,22 @@ function columnlist:draw()
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawColumnList or skins[defaultskin].DrawColumnList
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawColumnList(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- frame class
|
||||
@ -62,20 +62,20 @@ function frame:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local showclose = self.showclose
|
||||
local close = self.internals[1]
|
||||
local dragging = self.dragging
|
||||
local screenlocked = self.screenlocked
|
||||
local modal = self.modal
|
||||
local base = loveframes.base
|
||||
local basechildren = base.children
|
||||
local numbasechildren = #basechildren
|
||||
local draworder = self.draworder
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local x, y = love.mouse.getPosition()
|
||||
local showclose = self.showclose
|
||||
local close = self.internals[1]
|
||||
local dragging = self.dragging
|
||||
local screenlocked = self.screenlocked
|
||||
local modal = self.modal
|
||||
local base = loveframes.base
|
||||
local basechildren = base.children
|
||||
local numbasechildren = #basechildren
|
||||
local draworder = self.draworder
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
close:SetPos(self.width - 22, 4)
|
||||
close:SetPos(self.width - 20, 4)
|
||||
self:CheckHover()
|
||||
|
||||
-- dragging check
|
||||
@ -107,17 +107,25 @@ function frame:update(dt)
|
||||
|
||||
if modal == true then
|
||||
|
||||
local numtooltips = 0
|
||||
local tip = false
|
||||
local key = 0
|
||||
|
||||
for k, v in ipairs(basechildren) do
|
||||
if v.type == "tooltip" then
|
||||
numtooltips = numtooltips + 1
|
||||
if v.type == "tooltip" and v.show == true then
|
||||
tip = v
|
||||
key = k
|
||||
end
|
||||
end
|
||||
|
||||
if draworder ~= numbasechildren - numtooltips then
|
||||
self.modalbackground:MoveToTop()
|
||||
self:MoveToTop()
|
||||
if tip ~= false then
|
||||
self:Remove()
|
||||
self.modalbackground:Remove()
|
||||
table.insert(basechildren, key - 2, self.modalbackground)
|
||||
table.insert(basechildren, key - 1, self)
|
||||
end
|
||||
|
||||
if self.modalbackground.draworder > self.draworder then
|
||||
self:MakeTop()
|
||||
end
|
||||
|
||||
end
|
||||
@ -148,14 +156,14 @@ function frame:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawFrame or skins[defaultskin].DrawFrame
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
@ -163,7 +171,7 @@ function frame:draw()
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawFrame(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
|
@ -1,106 +1,127 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- progress bar class
|
||||
image = class("image", base)
|
||||
image:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function image:initialize()
|
||||
|
||||
self.type = "image"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.internal = false
|
||||
self.image = nil
|
||||
self.imagecolor = nil
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function image:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= nil then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function image:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawImage(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetImage(image)
|
||||
- desc: sets the object's image
|
||||
--]]---------------------------------------------------------
|
||||
function image:SetImage(image)
|
||||
|
||||
if type(image) == "string" then
|
||||
self.image = love.graphics.newImage(image)
|
||||
else
|
||||
self.image = image
|
||||
end
|
||||
|
||||
self.width = self.image:getWidth()
|
||||
self.height = self.image:getHeight()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetColor(table)
|
||||
- desc: sets the object's color
|
||||
--]]---------------------------------------------------------
|
||||
function image:SetColor(data)
|
||||
|
||||
self.imagecolor = data
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- progress bar class
|
||||
image = class("image", base)
|
||||
image:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function image:initialize()
|
||||
|
||||
self.type = "image"
|
||||
self.width = 0
|
||||
self.height = 0
|
||||
self.internal = false
|
||||
self.image = nil
|
||||
self.imagecolor = nil
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function image:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= nil then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function image:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawImage or skins[defaultskin].DrawImage
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetImage(image)
|
||||
- desc: sets the object's image
|
||||
--]]---------------------------------------------------------
|
||||
function image:SetImage(image)
|
||||
|
||||
if type(image) == "string" then
|
||||
self.image = love.graphics.newImage(image)
|
||||
else
|
||||
self.image = image
|
||||
end
|
||||
|
||||
self.width = self.image:getWidth()
|
||||
self.height = self.image:getHeight()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetImage()
|
||||
- desc: gets the object's image
|
||||
--]]---------------------------------------------------------
|
||||
function image:GetImage()
|
||||
|
||||
return self.image
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetColor(table)
|
||||
- desc: sets the object's color
|
||||
--]]---------------------------------------------------------
|
||||
function image:SetColor(data)
|
||||
|
||||
self.imagecolor = data
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetColor()
|
||||
- desc: gets the object's color
|
||||
--]]---------------------------------------------------------
|
||||
function image:GetColor()
|
||||
|
||||
return self.imagecolor
|
||||
|
||||
end
|
@ -1,258 +1,259 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- imagebutton clas
|
||||
imagebutton = class("imagebutton", base)
|
||||
imagebutton:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:initialize()
|
||||
|
||||
self.type = "imagebutton"
|
||||
self.text = "Image Button"
|
||||
self.width = 50
|
||||
self.height = 50
|
||||
self.internal = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.image = nil
|
||||
self.OnClick = nil
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local hoverobject = loveframes.hoverobject
|
||||
local down = self.down
|
||||
|
||||
if hover == false then
|
||||
self.down = false
|
||||
elseif hover == true then
|
||||
if hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if down == false and hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawImageButton(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local clickable = self.clickable
|
||||
local enabled = self.enabled
|
||||
|
||||
if hover == true and down == true and button == "l" and clickable == true then
|
||||
if enabled == true then
|
||||
if self.OnClick then
|
||||
self.OnClick(self, x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetClickable(bool)
|
||||
- desc: sets whether the object can be clicked or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SetClickable(bool)
|
||||
|
||||
self.clickable = bool
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetClickable(bool)
|
||||
- desc: gets whether the object can be clicked or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:GetClickable()
|
||||
|
||||
return self.clickable
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetClickable(bool)
|
||||
- desc: sets whether the object is enabled or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SetEnabled(bool)
|
||||
|
||||
self.enabled = bool
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetEnabled()
|
||||
- desc: gets whether the object is enabled or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:GetEnabled()
|
||||
|
||||
return self.enabled
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetImage(image)
|
||||
- desc: sets the object's image
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SetImage(image)
|
||||
|
||||
if type(image) == "string" then
|
||||
self.image = love.graphics.newImage(image)
|
||||
else
|
||||
self.image = image
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetImage()
|
||||
- desc: gets whether the object is enabled or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:GetImage()
|
||||
|
||||
return self.image
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SizeToImage()
|
||||
- desc: makes the object the same size as it's image
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SizeToImage()
|
||||
|
||||
local image = self.image
|
||||
|
||||
if image then
|
||||
self.width = image:getWidth()
|
||||
self.height = image:getHeight()
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- imagebutton clas
|
||||
imagebutton = class("imagebutton", base)
|
||||
imagebutton:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:initialize()
|
||||
|
||||
self.type = "imagebutton"
|
||||
self.text = "Image Button"
|
||||
self.width = 50
|
||||
self.height = 50
|
||||
self.internal = false
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.image = nil
|
||||
self.OnClick = nil
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local hover = self.hover
|
||||
local hoverobject = loveframes.hoverobject
|
||||
local down = self.down
|
||||
|
||||
if hover == false then
|
||||
self.down = false
|
||||
elseif hover == true then
|
||||
if hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if down == false and hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawImageButton or skins[defaultskin].DrawImageButton
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local clickable = self.clickable
|
||||
local enabled = self.enabled
|
||||
|
||||
if hover == true and down == true and button == "l" and clickable == true then
|
||||
if enabled == true then
|
||||
if self.OnClick then
|
||||
self.OnClick(self, x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetClickable(bool)
|
||||
- desc: sets whether the object can be clicked or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SetClickable(bool)
|
||||
|
||||
self.clickable = bool
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetClickable(bool)
|
||||
- desc: gets whether the object can be clicked or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:GetClickable()
|
||||
|
||||
return self.clickable
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetClickable(bool)
|
||||
- desc: sets whether the object is enabled or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SetEnabled(bool)
|
||||
|
||||
self.enabled = bool
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetEnabled()
|
||||
- desc: gets whether the object is enabled or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:GetEnabled()
|
||||
|
||||
return self.enabled
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetImage(image)
|
||||
- desc: sets the object's image
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SetImage(image)
|
||||
|
||||
if type(image) == "string" then
|
||||
self.image = love.graphics.newImage(image)
|
||||
else
|
||||
self.image = image
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetImage()
|
||||
- desc: gets whether the object is enabled or not
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:GetImage()
|
||||
|
||||
return self.image
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SizeToImage()
|
||||
- desc: makes the object the same size as it's image
|
||||
--]]---------------------------------------------------------
|
||||
function imagebutton:SizeToImage()
|
||||
|
||||
local image = self.image
|
||||
|
||||
if image then
|
||||
self.width = image:getWidth()
|
||||
self.height = image:getHeight()
|
||||
end
|
||||
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- closebutton clas
|
||||
@ -80,19 +80,20 @@ function closebutton:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawCloseButton or skins[defaultskin].DrawCloseButton
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawCloseButton(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- columnlistarea object
|
||||
@ -88,27 +88,23 @@ function columnlistarea:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawColumnListArea or skins[defaultskin].DrawColumnListArea
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawColumnListArea(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
|
||||
love.graphics.setStencil(stencil)
|
||||
|
||||
@ -121,6 +117,10 @@ function columnlistarea:draw()
|
||||
|
||||
love.graphics.setStencil()
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
if self.Draw == nil then
|
||||
skin.DrawOverColumnListArea(self)
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- columnlistrow object
|
||||
@ -16,7 +16,7 @@ function columnlistrow:initialize(parent, data)
|
||||
self.type = "columnlistrow"
|
||||
self.parent = parent
|
||||
self.colorindex = self.parent.rowcolorindex
|
||||
self.font = love.graphics.newFont(10)
|
||||
self.font = loveframes.basicfontsmall
|
||||
self.textcolor = {0, 0, 0, 255}
|
||||
self.width = 80
|
||||
self.height = 25
|
||||
@ -68,24 +68,24 @@ function columnlistrow:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local cwidth, cheight = self:GetParent():GetParent():GetColumnSize()
|
||||
local x = self.textx
|
||||
local textcolor = self.textcolor
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawColumnListRow or skins[defaultskin].DrawColumnListRow
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawColumnListRow(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
local cwidth, cheight = self:GetParent():GetParent():GetColumnSize()
|
||||
local x = self.textx
|
||||
local textcolor = self.textcolor
|
||||
|
||||
for k, v in ipairs(self.columndata) do
|
||||
love.graphics.setFont(self.font)
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- columnlistheader object
|
||||
@ -99,19 +99,20 @@ function columnlistheader:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawColumnListHeader or skins[defaultskin].DrawColumnListHeader
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawColumnListHeader(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,86 +1,87 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- modalbackground class
|
||||
modalbackground = class("modalbackground", base)
|
||||
modalbackground:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:initialize(object)
|
||||
|
||||
self.type = "modalbackground"
|
||||
self.width = love.graphics.getWidth()
|
||||
self.height = love.graphics.getHeight()
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.internal = true
|
||||
self.parent = loveframes.base
|
||||
self.object = object
|
||||
|
||||
table.insert(loveframes.base.children, self)
|
||||
|
||||
if self.object.type ~= "frame" then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the element
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local object = self.object
|
||||
|
||||
if object:IsActive() == false then
|
||||
self:Remove()
|
||||
loveframes.modalobject = false
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawModalBackground(self)
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- modalbackground class
|
||||
modalbackground = class("modalbackground", base)
|
||||
modalbackground:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:initialize(object)
|
||||
|
||||
self.type = "modalbackground"
|
||||
self.width = love.graphics.getWidth()
|
||||
self.height = love.graphics.getHeight()
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.internal = true
|
||||
self.parent = loveframes.base
|
||||
self.object = object
|
||||
|
||||
table.insert(loveframes.base.children, self)
|
||||
|
||||
if self.object.type ~= "frame" then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the element
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local object = self.object
|
||||
|
||||
if object:IsActive() == false then
|
||||
self:Remove()
|
||||
loveframes.modalobject = false
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function modalbackground:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawModalBackground or skins[defaultskin].DrawModalBackground
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- multichoicelist class
|
||||
@ -111,23 +111,29 @@ function multichoicelist:draw()
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawMultiChoiceList or skins[defaultskin].DrawMultiChoiceList
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawMultiChoiceList(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
love.graphics.setScissor(self.x, self.y, self.width, self.height)
|
||||
love.graphics.setStencil(stencil)
|
||||
|
||||
for k, v in ipairs(self.children) do
|
||||
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
|
||||
@ -136,9 +142,11 @@ function multichoicelist:draw()
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.setScissor()
|
||||
love.graphics.setStencil()
|
||||
|
||||
skin.DrawOverMultiChoiceList(self)
|
||||
if self.Draw == nil and skin.DrawOverMultiChoiceList then
|
||||
skin.DrawOverMultiChoiceList(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- multichoicerow class
|
||||
@ -77,19 +77,20 @@ function multichoicerow:draw()
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawMultiChoiceRow or skins[defaultskin].DrawMultiChoiceRow
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawMultiChoiceRow(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,225 +1,225 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
scrollarea = class("scrollarea", base)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:initialize(parent, bartype)
|
||||
|
||||
self.type = "scroll-area"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.scrolldelay = 0
|
||||
self.delayamount = 0.05
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
|
||||
table.insert(self.internals, scrollbar:new(self, bartype))
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local parent = self.parent
|
||||
local pinternals = parent.internals
|
||||
local button = pinternals[2]
|
||||
local bartype = self.bartype
|
||||
local time = love.timer.getTime()
|
||||
local x, y = love.mouse.getPosition()
|
||||
local listo = parent.parent
|
||||
local down = self.down
|
||||
local scrolldelay = self.scrolldelay
|
||||
local delayamount = self.delayamount
|
||||
local internals = self.internals
|
||||
local bar = internals[1]
|
||||
local hover = self.hover
|
||||
|
||||
if button then
|
||||
|
||||
if bartype == "vertical" then
|
||||
self.staticx = 0
|
||||
self.staticy = button.height - 1
|
||||
self.width = parent.width
|
||||
self.height = parent.height - button.height*2 + 2
|
||||
elseif bartype == "horizontal" then
|
||||
self.staticx = button.width - 1
|
||||
self.staticy = 0
|
||||
self.width = parent.width - button.width*2 + 2
|
||||
self.height = parent.height
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if down == true then
|
||||
if scrolldelay < time then
|
||||
self.scrolldelay = time + delayamount
|
||||
if listo.display == "vertical" then
|
||||
if y > bar.y then
|
||||
bar:Scroll(bar.height)
|
||||
else
|
||||
bar:Scroll(-bar.height)
|
||||
end
|
||||
elseif listo.display == "horizontal" then
|
||||
if x > bar.x then
|
||||
bar:Scroll(bar.width)
|
||||
else
|
||||
bar:Scroll(-bar.width)
|
||||
end
|
||||
end
|
||||
end
|
||||
if hover == false then
|
||||
self.down = false
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawScrollArea(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local listo = self.parent.parent
|
||||
local time = love.timer.getTime()
|
||||
local internals = self.internals
|
||||
local bar = internals[1]
|
||||
local hover = self.hover
|
||||
local delayamount = self.delayamount
|
||||
|
||||
if hover == true and button == "l" then
|
||||
self.down = true
|
||||
self.scrolldelay = time + delayamount + 0.5
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
if listo.display == "vertical" then
|
||||
if y > self.internals[1].y then
|
||||
bar:Scroll(bar.height)
|
||||
else
|
||||
bar:Scroll(-bar.height)
|
||||
end
|
||||
elseif listo.display == "horizontal" then
|
||||
if x > bar.x then
|
||||
bar:Scroll(bar.width)
|
||||
else
|
||||
bar:Scroll(-bar.width)
|
||||
end
|
||||
end
|
||||
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
if button == "l" then
|
||||
self.down = false
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
scrollarea = class("scrollarea", base)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:initialize(parent, bartype)
|
||||
|
||||
self.type = "scroll-area"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.scrolldelay = 0
|
||||
self.delayamount = 0.05
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
|
||||
table.insert(self.internals, scrollbar:new(self, bartype))
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local parent = self.parent
|
||||
local pinternals = parent.internals
|
||||
local button = pinternals[2]
|
||||
local bartype = self.bartype
|
||||
local time = love.timer.getTime()
|
||||
local x, y = love.mouse.getPosition()
|
||||
local listo = parent.parent
|
||||
local down = self.down
|
||||
local scrolldelay = self.scrolldelay
|
||||
local delayamount = self.delayamount
|
||||
local internals = self.internals
|
||||
local bar = internals[1]
|
||||
local hover = self.hover
|
||||
|
||||
if button then
|
||||
|
||||
if bartype == "vertical" then
|
||||
self.staticx = 0
|
||||
self.staticy = button.height - 1
|
||||
self.width = parent.width
|
||||
self.height = parent.height - button.height*2 + 2
|
||||
elseif bartype == "horizontal" then
|
||||
self.staticx = button.width - 1
|
||||
self.staticy = 0
|
||||
self.width = parent.width - button.width*2 + 2
|
||||
self.height = parent.height
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if down == true then
|
||||
if scrolldelay < time then
|
||||
self.scrolldelay = time + delayamount
|
||||
if listo.display == "vertical" then
|
||||
if y > bar.y then
|
||||
bar:Scroll(bar.height)
|
||||
else
|
||||
bar:Scroll(-bar.height)
|
||||
end
|
||||
elseif listo.display == "horizontal" then
|
||||
if x > bar.x then
|
||||
bar:Scroll(bar.width)
|
||||
else
|
||||
bar:Scroll(-bar.width)
|
||||
end
|
||||
end
|
||||
end
|
||||
if hover == false then
|
||||
self.down = false
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawScrollArea or skins[defaultskin].DrawScrollArea
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local listo = self.parent.parent
|
||||
local time = love.timer.getTime()
|
||||
local internals = self.internals
|
||||
local bar = internals[1]
|
||||
local hover = self.hover
|
||||
local delayamount = self.delayamount
|
||||
|
||||
if hover == true and button == "l" then
|
||||
self.down = true
|
||||
self.scrolldelay = time + delayamount + 0.5
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
if listo.display == "vertical" then
|
||||
if y > self.internals[1].y then
|
||||
bar:Scroll(bar.height)
|
||||
else
|
||||
bar:Scroll(-bar.height)
|
||||
end
|
||||
elseif listo.display == "horizontal" then
|
||||
if x > bar.x then
|
||||
bar:Scroll(bar.width)
|
||||
else
|
||||
bar:Scroll(-bar.width)
|
||||
end
|
||||
end
|
||||
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollarea:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
if button == "l" then
|
||||
self.down = false
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
@ -1,334 +1,335 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
scrollbar = class("scrollbar", base)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:initialize(parent, bartype)
|
||||
|
||||
self.type = "scrollbar"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.maxx = 0
|
||||
self.maxy = 0
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.starty = 0
|
||||
self.lastwidth = 0
|
||||
self.lastheight = 0
|
||||
self.lastx = 0
|
||||
self.lasty = 0
|
||||
self.internal = true
|
||||
self.hover = false
|
||||
self.dragging = false
|
||||
self.autoscroll = false
|
||||
self.internal = true
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
self.width = self.parent.width
|
||||
self.height = 5
|
||||
elseif self.bartype == "horizontal" then
|
||||
self.width = 5
|
||||
self.height = self.parent.height
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local bartype = self.bartype
|
||||
local cols = {}
|
||||
local basecols = {}
|
||||
local dragging = self.dragging
|
||||
|
||||
if bartype == "vertical" then
|
||||
self.width = self.parent.width
|
||||
elseif bartype == "horizontal" then
|
||||
self.height = self.parent.height
|
||||
end
|
||||
|
||||
if bartype == "vertical" then
|
||||
|
||||
local parent = self.parent
|
||||
local listo = parent.parent.parent
|
||||
local height = parent.height * (listo.height/listo.itemheight)
|
||||
|
||||
if height < 20 then
|
||||
self.height = 20
|
||||
else
|
||||
self.height = height
|
||||
end
|
||||
|
||||
self.maxy = parent.y + (parent.height - self.height)
|
||||
self.x = parent.x + parent.width - self.width
|
||||
self.y = parent.y + self.staticy
|
||||
|
||||
if dragging == true then
|
||||
if self.staticy ~= self.lasty then
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
end
|
||||
self.lasty = self.staticy
|
||||
end
|
||||
self.staticy = self.starty + (y - self.clicky)
|
||||
end
|
||||
|
||||
local space = (self.maxy - parent.y)
|
||||
local remaining = (0 + self.staticy)
|
||||
local percent = remaining/space
|
||||
local extra = listo.extra * percent
|
||||
local autoscroll = self.autoscroll
|
||||
local lastheight = self.lastheight
|
||||
|
||||
listo.offsety = 0 + extra
|
||||
|
||||
if self.staticy > space then
|
||||
self.staticy = space
|
||||
listo.offsety = listo.extra
|
||||
end
|
||||
|
||||
if self.staticy < 0 then
|
||||
self.staticy = 0
|
||||
listo.offsety = 0
|
||||
end
|
||||
|
||||
if autoscroll == true then
|
||||
if listo.itemheight ~= lastheight then
|
||||
self.lastheight = listo.itemheight
|
||||
self:Scroll(self.maxy)
|
||||
end
|
||||
end
|
||||
|
||||
elseif bartype == "horizontal" then
|
||||
|
||||
self.lastwidth = self.width
|
||||
|
||||
local parent = self.parent
|
||||
local listo = self.parent.parent.parent
|
||||
local width = self.parent.width * (listo.width/listo.itemwidth)
|
||||
|
||||
if width < 20 then
|
||||
self.width = 20
|
||||
else
|
||||
self.width = width
|
||||
end
|
||||
|
||||
self.maxx = parent.x + (parent.width) - self.width
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
|
||||
if dragging == true then
|
||||
if self.staticx ~= self.lastx then
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
end
|
||||
self.lastx = self.staticx
|
||||
end
|
||||
self.staticx = self.startx + (x - self.clickx)
|
||||
end
|
||||
|
||||
local space = (self.maxx - parent.x)
|
||||
local remaining = (0 + self.staticx)
|
||||
local percent = remaining/space
|
||||
local extra = listo.extra * percent
|
||||
local autoscroll = self.autoscroll
|
||||
local lastwidth = self.lastwidth
|
||||
|
||||
listo.offsetx = 0 + extra
|
||||
|
||||
if self.staticx > space then
|
||||
self.staticx = space
|
||||
listo.offsetx = listo.extra
|
||||
end
|
||||
|
||||
if self.staticx < 0 then
|
||||
self.staticx = 0
|
||||
listo.offsetx = 0
|
||||
end
|
||||
|
||||
if autoscroll == true then
|
||||
if self.width ~= lastwidth then
|
||||
self.width = self.width
|
||||
self:Scroll(self.maxx)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawScrollBar(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local hover = self.hover
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if hover == false then
|
||||
return
|
||||
end
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
local dragging = self.dragging
|
||||
|
||||
if dragging == false then
|
||||
|
||||
if button == "l" then
|
||||
|
||||
self.starty = self.staticy
|
||||
self.startx = self.staticx
|
||||
self.clickx = x
|
||||
self.clicky = y
|
||||
self.dragging = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.dragging == true then
|
||||
self.dragging = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMaxX(x)
|
||||
- desc: sets the object's max x position
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:SetMaxX(x)
|
||||
|
||||
self.maxx = x
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMaxY(y)
|
||||
- desc: sets the object's max y position
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:SetMaxY(y)
|
||||
|
||||
self.maxy = y
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Scroll(amount)
|
||||
- desc: scrolls the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:Scroll(amount)
|
||||
|
||||
local bartype = self.bartype
|
||||
local listo = self.parent.parent.parent
|
||||
|
||||
if bartype == "vertical" then
|
||||
local newy = (self.y + amount)
|
||||
|
||||
if newy > self.maxy then
|
||||
self.staticy = self.maxy - self.parent.y
|
||||
elseif newy < self.parent.y then
|
||||
self.staticy = 0
|
||||
else
|
||||
self.staticy = self.staticy + amount
|
||||
end
|
||||
elseif bartype == "horizontal" then
|
||||
local newx = (self.x + amount)
|
||||
|
||||
if newx > self.maxx then
|
||||
self.staticx = self.maxx - self.parent.x
|
||||
elseif newx < self.parent.x then
|
||||
self.staticx = 0
|
||||
else
|
||||
self.staticx = self.staticx + amount
|
||||
end
|
||||
end
|
||||
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
scrollbar = class("scrollbar", base)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:initialize(parent, bartype)
|
||||
|
||||
self.type = "scrollbar"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.maxx = 0
|
||||
self.maxy = 0
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.starty = 0
|
||||
self.lastwidth = 0
|
||||
self.lastheight = 0
|
||||
self.lastx = 0
|
||||
self.lasty = 0
|
||||
self.internal = true
|
||||
self.hover = false
|
||||
self.dragging = false
|
||||
self.autoscroll = false
|
||||
self.internal = true
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
self.width = self.parent.width
|
||||
self.height = 5
|
||||
elseif self.bartype == "horizontal" then
|
||||
self.width = 5
|
||||
self.height = self.parent.height
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local bartype = self.bartype
|
||||
local cols = {}
|
||||
local basecols = {}
|
||||
local dragging = self.dragging
|
||||
|
||||
if bartype == "vertical" then
|
||||
self.width = self.parent.width
|
||||
elseif bartype == "horizontal" then
|
||||
self.height = self.parent.height
|
||||
end
|
||||
|
||||
if bartype == "vertical" then
|
||||
|
||||
local parent = self.parent
|
||||
local listo = parent.parent.parent
|
||||
local height = parent.height * (listo.height/listo.itemheight)
|
||||
|
||||
if height < 20 then
|
||||
self.height = 20
|
||||
else
|
||||
self.height = height
|
||||
end
|
||||
|
||||
self.maxy = parent.y + (parent.height - self.height)
|
||||
self.x = parent.x + parent.width - self.width
|
||||
self.y = parent.y + self.staticy
|
||||
|
||||
if dragging == true then
|
||||
if self.staticy ~= self.lasty then
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
end
|
||||
self.lasty = self.staticy
|
||||
end
|
||||
self.staticy = self.starty + (y - self.clicky)
|
||||
end
|
||||
|
||||
local space = (self.maxy - parent.y)
|
||||
local remaining = (0 + self.staticy)
|
||||
local percent = remaining/space
|
||||
local extra = listo.extra * percent
|
||||
local autoscroll = self.autoscroll
|
||||
local lastheight = self.lastheight
|
||||
|
||||
listo.offsety = 0 + extra
|
||||
|
||||
if self.staticy > space then
|
||||
self.staticy = space
|
||||
listo.offsety = listo.extra
|
||||
end
|
||||
|
||||
if self.staticy < 0 then
|
||||
self.staticy = 0
|
||||
listo.offsety = 0
|
||||
end
|
||||
|
||||
if autoscroll == true then
|
||||
if listo.itemheight ~= lastheight then
|
||||
self.lastheight = listo.itemheight
|
||||
self:Scroll(self.maxy)
|
||||
end
|
||||
end
|
||||
|
||||
elseif bartype == "horizontal" then
|
||||
|
||||
self.lastwidth = self.width
|
||||
|
||||
local parent = self.parent
|
||||
local listo = self.parent.parent.parent
|
||||
local width = self.parent.width * (listo.width/listo.itemwidth)
|
||||
|
||||
if width < 20 then
|
||||
self.width = 20
|
||||
else
|
||||
self.width = width
|
||||
end
|
||||
|
||||
self.maxx = parent.x + (parent.width) - self.width
|
||||
self.x = parent.x + self.staticx
|
||||
self.y = parent.y + self.staticy
|
||||
|
||||
if dragging == true then
|
||||
if self.staticx ~= self.lastx then
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
end
|
||||
self.lastx = self.staticx
|
||||
end
|
||||
self.staticx = self.startx + (x - self.clickx)
|
||||
end
|
||||
|
||||
local space = (self.maxx - parent.x)
|
||||
local remaining = (0 + self.staticx)
|
||||
local percent = remaining/space
|
||||
local extra = listo.extra * percent
|
||||
local autoscroll = self.autoscroll
|
||||
local lastwidth = self.lastwidth
|
||||
|
||||
listo.offsetx = 0 + extra
|
||||
|
||||
if self.staticx > space then
|
||||
self.staticx = space
|
||||
listo.offsetx = listo.extra
|
||||
end
|
||||
|
||||
if self.staticx < 0 then
|
||||
self.staticx = 0
|
||||
listo.offsetx = 0
|
||||
end
|
||||
|
||||
if autoscroll == true then
|
||||
if self.width ~= lastwidth then
|
||||
self.width = self.width
|
||||
self:Scroll(self.maxx)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawScrollBar or skins[defaultskin].DrawScrollBar
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local hover = self.hover
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if hover == false then
|
||||
return
|
||||
end
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
local dragging = self.dragging
|
||||
|
||||
if dragging == false then
|
||||
|
||||
if button == "l" then
|
||||
|
||||
self.starty = self.staticy
|
||||
self.startx = self.staticx
|
||||
self.clickx = x
|
||||
self.clicky = y
|
||||
self.dragging = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.dragging == true then
|
||||
self.dragging = false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMaxX(x)
|
||||
- desc: sets the object's max x position
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:SetMaxX(x)
|
||||
|
||||
self.maxx = x
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMaxY(y)
|
||||
- desc: sets the object's max y position
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:SetMaxY(y)
|
||||
|
||||
self.maxy = y
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Scroll(amount)
|
||||
- desc: scrolls the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbar:Scroll(amount)
|
||||
|
||||
local bartype = self.bartype
|
||||
local listo = self.parent.parent.parent
|
||||
|
||||
if bartype == "vertical" then
|
||||
local newy = (self.y + amount)
|
||||
|
||||
if newy > self.maxy then
|
||||
self.staticy = self.maxy - self.parent.y
|
||||
elseif newy < self.parent.y then
|
||||
self.staticy = 0
|
||||
else
|
||||
self.staticy = self.staticy + amount
|
||||
end
|
||||
elseif bartype == "horizontal" then
|
||||
local newx = (self.x + amount)
|
||||
|
||||
if newx > self.maxx then
|
||||
self.staticx = self.maxx - self.parent.x
|
||||
elseif newx < self.parent.x then
|
||||
self.staticx = 0
|
||||
else
|
||||
self.staticx = self.staticx + amount
|
||||
end
|
||||
end
|
||||
|
||||
if listo.OnScroll then
|
||||
listo.OnScroll(listo)
|
||||
end
|
||||
|
||||
end
|
@ -1,152 +1,153 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
scrollbody = class("scrollbody", base)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:initialize(parent, bartype)
|
||||
|
||||
self.type = "scroll-body"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
self.width = 16
|
||||
self.height = self.parent.height
|
||||
self.staticx = self.parent.width - self.width
|
||||
self.staticy = 0
|
||||
elseif self.bartype == "horizontal" then
|
||||
self.width = self.parent.width
|
||||
self.height = 16
|
||||
self.staticx = 0
|
||||
self.staticy = self.parent.height - self.height
|
||||
end
|
||||
|
||||
table.insert(self.internals, scrollarea:new(self, bartype))
|
||||
|
||||
local bar = self.internals[1].internals[1]
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
|
||||
local upbutton = scrollbutton:new("up")
|
||||
upbutton.parent = self
|
||||
upbutton.Update = function(object, dt)
|
||||
upbutton.staticx = 0 + self.width - upbutton.width
|
||||
upbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
bar:Scroll(-0.10)
|
||||
end
|
||||
end
|
||||
|
||||
local downbutton = scrollbutton:new("down")
|
||||
downbutton.parent = self
|
||||
downbutton.Update = function(object, dt)
|
||||
downbutton.staticx = 0 + self.width - downbutton.width
|
||||
downbutton.staticy = 0 + self.height - downbutton.height
|
||||
if object.down == true and object.hover == true then
|
||||
bar:Scroll(0.10)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(self.internals, upbutton)
|
||||
table.insert(self.internals, downbutton)
|
||||
|
||||
elseif self.bartype == "horizontal" then
|
||||
|
||||
local leftbutton = scrollbutton:new("left")
|
||||
leftbutton.parent = self
|
||||
leftbutton.Update = function(object, dt)
|
||||
leftbutton.staticx = 0
|
||||
leftbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
bar:Scroll(-0.10)
|
||||
end
|
||||
end
|
||||
|
||||
local rightbutton = scrollbutton:new("right")
|
||||
rightbutton.parent = self
|
||||
rightbutton.Update = function(object, dt)
|
||||
rightbutton.staticx = 0 + self.width - rightbutton.width
|
||||
rightbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
bar:Scroll(0.10)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(self.internals, leftbutton)
|
||||
table.insert(self.internals, rightbutton)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawScrollBody(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbar class
|
||||
scrollbody = class("scrollbody", base)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:initialize(parent, bartype)
|
||||
|
||||
self.type = "scroll-body"
|
||||
self.bartype = bartype
|
||||
self.parent = parent
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.internal = true
|
||||
self.internals = {}
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
self.width = 16
|
||||
self.height = self.parent.height
|
||||
self.staticx = self.parent.width - self.width
|
||||
self.staticy = 0
|
||||
elseif self.bartype == "horizontal" then
|
||||
self.width = self.parent.width
|
||||
self.height = 16
|
||||
self.staticx = 0
|
||||
self.staticy = self.parent.height - self.height
|
||||
end
|
||||
|
||||
table.insert(self.internals, scrollarea:new(self, bartype))
|
||||
|
||||
local bar = self.internals[1].internals[1]
|
||||
|
||||
if self.bartype == "vertical" then
|
||||
|
||||
local upbutton = scrollbutton:new("up")
|
||||
upbutton.parent = self
|
||||
upbutton.Update = function(object, dt)
|
||||
upbutton.staticx = 0 + self.width - upbutton.width
|
||||
upbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
bar:Scroll(-0.10)
|
||||
end
|
||||
end
|
||||
|
||||
local downbutton = scrollbutton:new("down")
|
||||
downbutton.parent = self
|
||||
downbutton.Update = function(object, dt)
|
||||
downbutton.staticx = 0 + self.width - downbutton.width
|
||||
downbutton.staticy = 0 + self.height - downbutton.height
|
||||
if object.down == true and object.hover == true then
|
||||
bar:Scroll(0.10)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(self.internals, upbutton)
|
||||
table.insert(self.internals, downbutton)
|
||||
|
||||
elseif self.bartype == "horizontal" then
|
||||
|
||||
local leftbutton = scrollbutton:new("left")
|
||||
leftbutton.parent = self
|
||||
leftbutton.Update = function(object, dt)
|
||||
leftbutton.staticx = 0
|
||||
leftbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
bar:Scroll(-0.10)
|
||||
end
|
||||
end
|
||||
|
||||
local rightbutton = scrollbutton:new("right")
|
||||
rightbutton.parent = self
|
||||
rightbutton.Update = function(object, dt)
|
||||
rightbutton.staticx = 0 + self.width - rightbutton.width
|
||||
rightbutton.staticy = 0
|
||||
if object.down == true and object.hover == true then
|
||||
bar:Scroll(0.10)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(self.internals, leftbutton)
|
||||
table.insert(self.internals, rightbutton)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbody:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawScrollBody or skins[defaultskin].DrawScrollBody
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
@ -1,147 +1,148 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbutton clas
|
||||
scrollbutton = class("scrollbutton", base)
|
||||
scrollbutton:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:initialize(scrolltype)
|
||||
|
||||
self.type = "scrollbutton"
|
||||
self.scrolltype = scrolltype
|
||||
self.width = 16
|
||||
self.height = 16
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.OnClick = function() end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if self.hover == false then
|
||||
self.down = false
|
||||
elseif self.hover == true then
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.down == false and loveframes.hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawScrollButton(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, scrollbutton)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:mousepressed(x, y, scrollbutton)
|
||||
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, scrollbutton)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:mousereleased(x, y, scrollbutton)
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true and self.down == true then
|
||||
|
||||
if scrollbutton == "l" then
|
||||
self.OnClick(x, y, self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:SetText(text)
|
||||
|
||||
return
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- scrollbutton clas
|
||||
scrollbutton = class("scrollbutton", base)
|
||||
scrollbutton:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:initialize(scrolltype)
|
||||
|
||||
self.type = "scrollbutton"
|
||||
self.scrolltype = scrolltype
|
||||
self.width = 16
|
||||
self.height = 16
|
||||
self.down = false
|
||||
self.internal = true
|
||||
self.OnClick = function() end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if self.hover == false then
|
||||
self.down = false
|
||||
elseif self.hover == true then
|
||||
if loveframes.hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if self.down == false and loveframes.hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawScrollButton or skins[defaultskin].DrawScrollButton
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, scrollbutton)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:mousepressed(x, y, scrollbutton)
|
||||
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, scrollbutton)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:mousereleased(x, y, scrollbutton)
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true and self.down == true then
|
||||
|
||||
if scrollbutton == "l" then
|
||||
self.OnClick(x, y, self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function scrollbutton:SetText(text)
|
||||
|
||||
return
|
||||
|
||||
end
|
@ -1,236 +1,250 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- closebutton clas
|
||||
sliderbutton = class("sliderbutton", base)
|
||||
sliderbutton:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:initialize(parent)
|
||||
|
||||
self.type = "sliderbutton"
|
||||
self.width = 10
|
||||
self.height = 20
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.startx = 0
|
||||
self.clickx = 0
|
||||
self.starty = 0
|
||||
self.clicky = 0
|
||||
self.intervals = true
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.dragging = false
|
||||
self.parent = parent
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local intervals = self.intervals
|
||||
local progress = 0
|
||||
local nvalue = 0
|
||||
local pvalue = 0
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hoverobject = loveframes.hoverobject
|
||||
local parent = self.parent
|
||||
local slidetype = parent.slidetype
|
||||
local dragging = self.dragging
|
||||
|
||||
if hover == false then
|
||||
self.down = false
|
||||
elseif hover == true then
|
||||
if hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if down == false and hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if slidetype == "horizontal" then
|
||||
|
||||
if dragging == true then
|
||||
self.staticx = self.startx + (x - self.clickx)
|
||||
end
|
||||
|
||||
if (self.staticx + self.width) > self.parent.width then
|
||||
self.staticx = self.parent.width - self.width
|
||||
end
|
||||
|
||||
if self.staticx < 0 then
|
||||
self.staticx = 0
|
||||
end
|
||||
|
||||
progress = loveframes.util.Round(self.staticx/(self.parent.width - self.width), 5)
|
||||
nvalue = self.parent.min + (self.parent.max - self.parent.min) * progress
|
||||
pvalue = self.parent.value
|
||||
|
||||
elseif slidetype == "vertical" then
|
||||
|
||||
if dragging == true then
|
||||
self.staticy = self.starty + (y - self.clicky)
|
||||
end
|
||||
|
||||
if (self.staticy + self.height) > self.parent.height then
|
||||
self.staticy = self.parent.height - self.height
|
||||
end
|
||||
|
||||
if self.staticy < 0 then
|
||||
self.staticy = 0
|
||||
end
|
||||
|
||||
local space = self.parent.height - self.height
|
||||
local remaining = (self.parent.height - self.height) - self.staticy
|
||||
local percent = loveframes.util.Round(remaining/space, 5)
|
||||
|
||||
nvalue = self.parent.min + (self.parent.max - self.parent.min) * percent
|
||||
pvalue = self.parent.value
|
||||
|
||||
end
|
||||
|
||||
if nvalue ~= pvalue then
|
||||
self.parent.value = loveframes.util.Round(nvalue, self.parent.decimals)
|
||||
if self.parent.OnValueChanged then
|
||||
self.parent.OnValueChanged(self.parent, self.parent.value)
|
||||
end
|
||||
end
|
||||
|
||||
if dragging == true then
|
||||
loveframes.hoverobject = self
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawSliderButton(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
self.dragging = true
|
||||
self.startx = self.staticx
|
||||
self.clickx = x
|
||||
self.starty = self.staticy
|
||||
self.clicky = y
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
self.down = false
|
||||
self.dragging = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: MoveToX(x)
|
||||
- desc: moves the object to the specified x position
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:MoveToX(x)
|
||||
|
||||
self.staticx = x
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: MoveToY(y)
|
||||
- desc: moves the object to the specified y position
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:MoveToY(y)
|
||||
|
||||
self.staticy = y
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- closebutton clas
|
||||
sliderbutton = class("sliderbutton", base)
|
||||
sliderbutton:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:initialize(parent)
|
||||
|
||||
self.type = "sliderbutton"
|
||||
self.width = 10
|
||||
self.height = 20
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.startx = 0
|
||||
self.clickx = 0
|
||||
self.starty = 0
|
||||
self.clicky = 0
|
||||
self.intervals = true
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.dragging = false
|
||||
self.parent = parent
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local intervals = self.intervals
|
||||
local progress = 0
|
||||
local nvalue = 0
|
||||
local pvalue = self.parent.value
|
||||
local hover = self.hover
|
||||
local down = self.down
|
||||
local hoverobject = loveframes.hoverobject
|
||||
local parent = self.parent
|
||||
local slidetype = parent.slidetype
|
||||
local dragging = self.dragging
|
||||
|
||||
if hover == false then
|
||||
self.down = false
|
||||
elseif hover == true then
|
||||
if hoverobject == self then
|
||||
self.down = true
|
||||
end
|
||||
end
|
||||
|
||||
if down == false and hoverobject == self then
|
||||
self.hover = true
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
-- start calculations if the button is being dragged
|
||||
if dragging == true then
|
||||
|
||||
-- calculations for horizontal sliders
|
||||
if slidetype == "horizontal" then
|
||||
|
||||
self.staticx = self.startx + (x - self.clickx)
|
||||
|
||||
progress = self.staticx/(self.parent.width - self.width)
|
||||
nvalue = self.parent.min + (self.parent.max - self.parent.min) * progress
|
||||
nvalue = loveframes.util.Round(nvalue, self.parent.decimals)
|
||||
|
||||
-- calculations for vertical sliders
|
||||
elseif slidetype == "vertical" then
|
||||
|
||||
self.staticy = self.starty + (y - self.clicky)
|
||||
|
||||
local space = self.parent.height - self.height
|
||||
local remaining = (self.parent.height - self.height) - self.staticy
|
||||
local percent = remaining/space
|
||||
|
||||
nvalue = self.parent.min + (self.parent.max - self.parent.min) * percent
|
||||
nvalue = loveframes.util.Round(nvalue, self.parent.decimals)
|
||||
|
||||
end
|
||||
|
||||
--
|
||||
if nvalue > self.parent.max then
|
||||
nvalue = self.parent.max
|
||||
end
|
||||
|
||||
if nvalue < self.parent.min then
|
||||
nvalue = self.parent.min
|
||||
end
|
||||
|
||||
self.parent.value = nvalue
|
||||
|
||||
if nvalue ~= pvalue and nvalue >= self.parent.min and nvalue <= self.parent.max then
|
||||
if self.parent.OnValueChanged then
|
||||
self.parent.OnValueChanged(self.parent, self.parent.value)
|
||||
end
|
||||
end
|
||||
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
if slidetype == "horizontal" then
|
||||
if (self.staticx + self.width) > self.parent.width then
|
||||
self.staticx = self.parent.width - self.width
|
||||
end
|
||||
if self.staticx < 0 then
|
||||
self.staticx = 0
|
||||
end
|
||||
end
|
||||
|
||||
if slidetype == "vertical" then
|
||||
if (self.staticy + self.height) > self.parent.height then
|
||||
self.staticy = self.parent.height - self.height
|
||||
end
|
||||
if self.staticy < 0 then
|
||||
self.staticy = 0
|
||||
end
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawSliderButton or skins[defaultskin].DrawSliderButton
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
self.dragging = true
|
||||
self.startx = self.staticx
|
||||
self.clickx = x
|
||||
self.starty = self.staticy
|
||||
self.clicky = y
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
self.down = false
|
||||
self.dragging = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: MoveToX(x)
|
||||
- desc: moves the object to the specified x position
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:MoveToX(x)
|
||||
|
||||
self.staticx = x
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: MoveToY(y)
|
||||
- desc: moves the object to the specified y position
|
||||
--]]---------------------------------------------------------
|
||||
function sliderbutton:MoveToY(y)
|
||||
|
||||
self.staticy = y
|
||||
|
||||
end
|
@ -1,187 +1,187 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tabbutton clas
|
||||
tabbutton = class("tabbutton", base)
|
||||
tabbutton:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:initialize(parent, text, tabnumber, tip, image)
|
||||
|
||||
self.type = "tabbutton"
|
||||
self.text = text
|
||||
self.tabnumber = tabnumber
|
||||
self.parent = parent
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.width = 50
|
||||
self.height = 25
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.image = nil
|
||||
|
||||
if tip then
|
||||
self.tooltip = tooltip:new(self, tip)
|
||||
self.tooltip:SetFollowCursor(false)
|
||||
self.tooltip:SetOffsets(0, -5)
|
||||
end
|
||||
|
||||
if image then
|
||||
self:SetImage(image)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
self:SetClickBounds(self.parent.x, self.parent.y, self.parent.width, self.parent.height)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawTabButton(self)
|
||||
end
|
||||
|
||||
local font = love.graphics.getFont()
|
||||
local width = font:getWidth(self.text)
|
||||
local image = self.image
|
||||
|
||||
if image then
|
||||
local imagewidth = image:getWidth()
|
||||
self.width = imagewidth + 15 + width
|
||||
else
|
||||
self.width = 10 + width
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local parent = self.parent
|
||||
local tabnumber = self.tabnumber
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
if button == "l" then
|
||||
parent:SwitchToTab(tabnumber)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetImage(image)
|
||||
- desc: adds an image to the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:SetImage(image)
|
||||
|
||||
if type(image) == "string" then
|
||||
self.image = love.graphics.newImage(image)
|
||||
else
|
||||
self.image = image
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tabbutton clas
|
||||
tabbutton = class("tabbutton", base)
|
||||
tabbutton:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:initialize(parent, text, tabnumber, tip, image)
|
||||
|
||||
self.type = "tabbutton"
|
||||
self.text = text
|
||||
self.tabnumber = tabnumber
|
||||
self.parent = parent
|
||||
self.staticx = 0
|
||||
self.staticy = 0
|
||||
self.width = 50
|
||||
self.height = 25
|
||||
self.internal = true
|
||||
self.down = false
|
||||
self.image = nil
|
||||
|
||||
if tip then
|
||||
self.tooltip = tooltip:new(self, tip)
|
||||
self.tooltip:SetFollowCursor(false)
|
||||
self.tooltip:SetOffsets(0, -5)
|
||||
end
|
||||
|
||||
if image then
|
||||
self:SetImage(image)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
self:SetClickBounds(self.parent.x, self.parent.y, self.parent.width, self.parent.height)
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local font = love.graphics.getFont()
|
||||
local width = font:getWidth(self.text)
|
||||
local image = self.image
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawTabButton or skins[defaultskin].DrawTabButton
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
if image then
|
||||
local imagewidth = image:getWidth()
|
||||
self.width = imagewidth + 15 + width
|
||||
else
|
||||
self.width = 10 + width
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.down = true
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local parent = self.parent
|
||||
local tabnumber = self.tabnumber
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
if button == "l" then
|
||||
parent:SwitchToTab(tabnumber)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self.down = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetImage(image)
|
||||
- desc: adds an image to the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabbutton:SetImage(image)
|
||||
|
||||
if type(image) == "string" then
|
||||
self.image = love.graphics.newImage(image)
|
||||
else
|
||||
self.image = image
|
||||
end
|
||||
|
||||
end
|
@ -1,217 +1,228 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tooltip clas
|
||||
tooltip = class("tooltip", base)
|
||||
tooltip:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:initialize(object, text, width)
|
||||
|
||||
local width = width or 0
|
||||
|
||||
self.type = "tooltip"
|
||||
self.parent = loveframes.base
|
||||
self.object = object or nil
|
||||
self.width = width or 0
|
||||
self.height = 0
|
||||
self.padding = 5
|
||||
self.xoffset = 0
|
||||
self.yoffset = 0
|
||||
self.internal = true
|
||||
self.show = false
|
||||
self.followcursor = true
|
||||
self.alwaysupdate = true
|
||||
|
||||
self.text = loveframes.Create("text")
|
||||
self.text:Remove()
|
||||
self.text.parent = self
|
||||
self.text:SetText(text or "")
|
||||
self.text:SetWidth(width or 0)
|
||||
self.text:SetPos(0, 0)
|
||||
|
||||
table.insert(loveframes.base.children, self)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local text = self.text
|
||||
|
||||
self.width = text.width + self.padding*2
|
||||
self.height = text.height + self.padding*2
|
||||
|
||||
local object = self.object
|
||||
local draworder = self.draworder
|
||||
|
||||
if object then
|
||||
|
||||
local hover = object.hover
|
||||
local odraworder = object.draworder
|
||||
|
||||
self.show = object.hover
|
||||
self.visible = self.show
|
||||
|
||||
local show = self.show
|
||||
|
||||
if show == true then
|
||||
if self.followcursor == true then
|
||||
local x, y = love.mouse.getPosition()
|
||||
local top = self:IsTopChild()
|
||||
self.x = x + self.xoffset
|
||||
self.y = y - self.height + self.yoffset
|
||||
else
|
||||
self.x = object.x + self.xoffset
|
||||
self.y = object.y - self.height + self.yoffset
|
||||
end
|
||||
|
||||
if top == false then
|
||||
self:MoveToTop()
|
||||
end
|
||||
|
||||
text:SetPos(self.padding, self.padding)
|
||||
|
||||
end
|
||||
|
||||
if odraworder > draworder then
|
||||
self:Remove()
|
||||
table.insert(loveframes.base.children, self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
text:update(dt)
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
local show = self.show
|
||||
local text = self.text
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if show == true then
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawToolTip(self)
|
||||
end
|
||||
|
||||
text:draw()
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFollowCursor(bool)
|
||||
- desc: sets whether or not the tooltip should follow the
|
||||
cursor
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetFollowCursor(bool)
|
||||
|
||||
self.followcursor = bool
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetObject(object)
|
||||
- desc: sets the tooltip's object
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetObject(object)
|
||||
|
||||
self.object = object
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the tooltip's text
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetText(text)
|
||||
|
||||
self.text:SetText(text)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetTextMaxWidth(text)
|
||||
- desc: sets the tooltip's text max width
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetTextMaxWidth(width)
|
||||
|
||||
self.text:SetMaxWidth(width)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetOffsets(xoffset, yoffset)
|
||||
- desc: sets the tooltip's x and y offset
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetOffsets(xoffset, yoffset)
|
||||
|
||||
self.xoffset = xoffset
|
||||
self.yoffset = yoffset
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(padding)
|
||||
- desc: sets the tooltip's padding
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetPadding(padding)
|
||||
|
||||
self.padding = padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFont(font)
|
||||
- desc: sets the tooltip's font
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetFont(font)
|
||||
|
||||
self.text:SetFont(font)
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tooltip clas
|
||||
tooltip = class("tooltip", base)
|
||||
tooltip:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:initialize(object, text, width)
|
||||
|
||||
local width = width or 0
|
||||
|
||||
self.type = "tooltip"
|
||||
self.parent = loveframes.base
|
||||
self.object = object or nil
|
||||
self.width = width or 0
|
||||
self.height = 0
|
||||
self.padding = 5
|
||||
self.xoffset = 10
|
||||
self.yoffset = -10
|
||||
self.internal = true
|
||||
self.show = false
|
||||
self.followcursor = true
|
||||
self.alwaysupdate = true
|
||||
|
||||
self.text = loveframes.Create("text")
|
||||
self.text:Remove()
|
||||
self.text.parent = self
|
||||
self.text:SetText(text or "")
|
||||
self.text:SetWidth(width or 0)
|
||||
self.text:SetPos(0, 0)
|
||||
|
||||
table.insert(loveframes.base.internals, self)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local text = self.text
|
||||
|
||||
self.width = text.width + self.padding*2
|
||||
self.height = text.height + self.padding*2
|
||||
|
||||
local object = self.object
|
||||
local draworder = self.draworder
|
||||
|
||||
if object then
|
||||
|
||||
if object == loveframes.base then
|
||||
self:Remove()
|
||||
return
|
||||
end
|
||||
|
||||
local hover = object.hover
|
||||
local odraworder = object.draworder
|
||||
|
||||
self.show = object.hover
|
||||
self.visible = self.show
|
||||
|
||||
local show = self.show
|
||||
|
||||
if show == true then
|
||||
local top = self:IsTopInternal()
|
||||
if self.followcursor == true then
|
||||
local x, y = love.mouse.getPosition()
|
||||
self.x = x + self.xoffset
|
||||
self.y = y - self.height + self.yoffset
|
||||
else
|
||||
self.x = object.x + self.xoffset
|
||||
self.y = object.y - self.height + self.yoffset
|
||||
end
|
||||
|
||||
if top == false then
|
||||
self:MoveToTop()
|
||||
end
|
||||
|
||||
text:SetPos(self.padding, self.padding)
|
||||
|
||||
end
|
||||
|
||||
local baseparent = object:GetBaseParent()
|
||||
|
||||
if baseparent then
|
||||
if baseparent.removed and baseparent.removed == true then
|
||||
self:Remove()
|
||||
end
|
||||
elseif object.removed then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
text:update(dt)
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local show = self.show
|
||||
local text = self.text
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawToolTip or skins[defaultskin].DrawToolTip
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if show == true then
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
text:draw()
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFollowCursor(bool)
|
||||
- desc: sets whether or not the tooltip should follow the
|
||||
cursor
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetFollowCursor(bool)
|
||||
|
||||
self.followcursor = bool
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetObject(object)
|
||||
- desc: sets the tooltip's object
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetObject(object)
|
||||
|
||||
self.object = object
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the tooltip's text
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetText(text)
|
||||
|
||||
self.text:SetText(text)
|
||||
self.text2 = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetTextMaxWidth(text)
|
||||
- desc: sets the tooltip's text max width
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetTextMaxWidth(width)
|
||||
|
||||
self.text:SetMaxWidth(width)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetOffsets(xoffset, yoffset)
|
||||
- desc: sets the tooltip's x and y offset
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetOffsets(xoffset, yoffset)
|
||||
|
||||
self.xoffset = xoffset
|
||||
self.yoffset = yoffset
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(padding)
|
||||
- desc: sets the tooltip's padding
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetPadding(padding)
|
||||
|
||||
self.padding = padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFont(font)
|
||||
- desc: sets the tooltip's font
|
||||
--]]---------------------------------------------------------
|
||||
function tooltip:SetFont(font)
|
||||
|
||||
self.text:SetFont(font)
|
||||
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- list class
|
||||
@ -40,8 +40,8 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function list:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
@ -49,9 +49,9 @@ function list:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local display = self.display
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local display = self.display
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
@ -97,28 +97,27 @@ function list:draw()
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawList or skins[defaultskin].DrawList
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawList(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
|
||||
love.graphics.setStencil(stencil)
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
@ -152,11 +151,11 @@ function list:mousepressed(x, y, button)
|
||||
return
|
||||
end
|
||||
|
||||
local toplist = self:IsTopList()
|
||||
local hover = self.hover
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local children = self.children
|
||||
local toplist = self:IsTopList()
|
||||
local hover = self.hover
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
if hover == true and button == "l" then
|
||||
@ -235,18 +234,18 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function list:CalculateSize()
|
||||
|
||||
local numitems = #self.children
|
||||
local height = self.height
|
||||
local width = self.width
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
local itemheight = self.padding
|
||||
local itemwidth = self.padding
|
||||
local display = self.display
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
local numitems = #self.children
|
||||
local height = self.height
|
||||
local width = self.width
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
local itemheight = self.padding
|
||||
local itemwidth = self.padding
|
||||
local display = self.display
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local internals = self.internals
|
||||
local children = self.children
|
||||
|
||||
if display == "vertical" then
|
||||
|
||||
@ -322,14 +321,14 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function list:RedoLayout()
|
||||
|
||||
local children = self.children
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
local starty = padding
|
||||
local startx = padding
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local display = self.display
|
||||
local children = self.children
|
||||
local padding = self.padding
|
||||
local spacing = self.spacing
|
||||
local starty = padding
|
||||
local startx = padding
|
||||
local vbar = self.vbar
|
||||
local hbar = self.hbar
|
||||
local display = self.display
|
||||
|
||||
if #children > 0 then
|
||||
|
||||
@ -398,8 +397,8 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function list:SetDisplayType(type)
|
||||
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
|
||||
self.display = type
|
||||
|
||||
@ -432,8 +431,8 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function list:SetPadding(amount)
|
||||
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
|
||||
self.padding = amount
|
||||
|
||||
@ -450,8 +449,8 @@ end
|
||||
--]]---------------------------------------------------------
|
||||
function list:SetSpacing(amount)
|
||||
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
|
||||
self.spacing = amount
|
||||
|
||||
|
@ -1,217 +1,218 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- progress bar class
|
||||
multichoice = class("multichoice", base)
|
||||
multichoice:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:initialize()
|
||||
|
||||
self.type = "multichoice"
|
||||
self.choice = ""
|
||||
self.text = "Select an option"
|
||||
self.width = 200
|
||||
self.height = 25
|
||||
self.listpadding = 0
|
||||
self.listspacing = 0
|
||||
self.listheight = nil
|
||||
self.haslist = false
|
||||
self.internal = false
|
||||
self.choices = {}
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= nil then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawMultiChoice(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local haslist = self.haslist
|
||||
|
||||
if hover == true and haslist == false and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.haslist = true
|
||||
self.list = multichoicelist:new(self)
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddChoice(choice)
|
||||
- desc: adds a choice to the current list of choices
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:AddChoice(choice)
|
||||
|
||||
local choices = self.choices
|
||||
table.insert(choices, choice)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetChoice(choice)
|
||||
- desc: sets the current choice
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SetChoice(choice)
|
||||
|
||||
self.choice = choice
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SelectChoice(choice)
|
||||
- desc: selects a choice
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SelectChoice(choice)
|
||||
|
||||
self.choice = choice
|
||||
self.list:Close()
|
||||
|
||||
if self.OnChoiceSelected then
|
||||
self.OnChoiceSelected(self, choice)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetListHeight(height)
|
||||
- desc: sets the height of the list of choices
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SetListHeight(height)
|
||||
|
||||
self.listheight = height
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(padding)
|
||||
- desc: sets the padding of the list of choices
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SetPadding(padding)
|
||||
|
||||
self.listpadding = padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSpacing(spacing)
|
||||
- desc: sets the spacing of the list of choices
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SetSpacing(spacing)
|
||||
|
||||
self.listspacing = spacing
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetValue()
|
||||
- desc: gets the value (choice) of the object
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:GetValue()
|
||||
|
||||
return self.choice
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetChoice()
|
||||
- desc: gets the current choice (same as get value)
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:GetChoice()
|
||||
|
||||
return self.choice
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- progress bar class
|
||||
multichoice = class("multichoice", base)
|
||||
multichoice:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:initialize()
|
||||
|
||||
self.type = "multichoice"
|
||||
self.choice = ""
|
||||
self.text = "Select an option"
|
||||
self.width = 200
|
||||
self.height = 25
|
||||
self.listpadding = 0
|
||||
self.listspacing = 0
|
||||
self.listheight = nil
|
||||
self.haslist = false
|
||||
self.internal = false
|
||||
self.choices = {}
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= nil then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawMultiChoice or skins[defaultskin].DrawMultiChoice
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
local haslist = self.haslist
|
||||
|
||||
if hover == true and haslist == false and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
self.haslist = true
|
||||
self.list = multichoicelist:new(self)
|
||||
loveframes.hoverobject = self
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddChoice(choice)
|
||||
- desc: adds a choice to the current list of choices
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:AddChoice(choice)
|
||||
|
||||
local choices = self.choices
|
||||
table.insert(choices, choice)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetChoice(choice)
|
||||
- desc: sets the current choice
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SetChoice(choice)
|
||||
|
||||
self.choice = choice
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SelectChoice(choice)
|
||||
- desc: selects a choice
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SelectChoice(choice)
|
||||
|
||||
self.choice = choice
|
||||
self.list:Close()
|
||||
|
||||
if self.OnChoiceSelected then
|
||||
self.OnChoiceSelected(self, choice)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetListHeight(height)
|
||||
- desc: sets the height of the list of choices
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SetListHeight(height)
|
||||
|
||||
self.listheight = height
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(padding)
|
||||
- desc: sets the padding of the list of choices
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SetPadding(padding)
|
||||
|
||||
self.listpadding = padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSpacing(spacing)
|
||||
- desc: sets the spacing of the list of choices
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:SetSpacing(spacing)
|
||||
|
||||
self.listspacing = spacing
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetValue()
|
||||
- desc: gets the value (choice) of the object
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:GetValue()
|
||||
|
||||
return self.choice
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetChoice()
|
||||
- desc: gets the current choice (same as get value)
|
||||
--]]---------------------------------------------------------
|
||||
function multichoice:GetChoice()
|
||||
|
||||
return self.choice
|
||||
|
||||
end
|
@ -1,143 +1,143 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- panel class
|
||||
panel = class("panel", base)
|
||||
panel:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function panel:initialize()
|
||||
|
||||
self.type = "panel"
|
||||
self.width = 200
|
||||
self.height = 50
|
||||
self.internal = false
|
||||
self.children = {}
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the element
|
||||
--]]---------------------------------------------------------
|
||||
function panel:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base and self.parent.type ~= "list" then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function panel:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawPanel(self)
|
||||
end
|
||||
|
||||
-- loop through the object's children and draw them
|
||||
for k, v in ipairs(children) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function panel:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function panel:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local children = self.children
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- panel class
|
||||
panel = class("panel", base)
|
||||
panel:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function panel:initialize()
|
||||
|
||||
self.type = "panel"
|
||||
self.width = 200
|
||||
self.height = 50
|
||||
self.internal = false
|
||||
self.children = {}
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the element
|
||||
--]]---------------------------------------------------------
|
||||
function panel:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base and self.parent.type ~= "list" then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function panel:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawPanel or skins[defaultskin].DrawPanel
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
-- loop through the object's children and draw them
|
||||
for k, v in ipairs(children) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function panel:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function panel:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local children = self.children
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
@ -1,6 +1,6 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- progress bar class
|
||||
@ -46,12 +46,12 @@ function progressbar:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
local lerp = self.lerp
|
||||
local lerprate = self.lerprate
|
||||
local lerp = self.lerp
|
||||
local lerprate = self.lerprate
|
||||
local lerpvalue = self.lerpvalue
|
||||
local lerpto = self.lerpto
|
||||
local lerpfrom = self.lerpfrom
|
||||
local value = self.value
|
||||
local lerpto = self.lerpto
|
||||
local lerpfrom = self.lerpfrom
|
||||
local value = self.value
|
||||
local completed = self.completed
|
||||
|
||||
self:CheckHover()
|
||||
@ -133,11 +133,12 @@ function progressbar:draw()
|
||||
return
|
||||
end
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawProgressBar or skins[defaultskin].DrawProgressBar
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
@ -145,7 +146,7 @@ function progressbar:draw()
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawProgressBar(self)
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
end
|
||||
@ -282,4 +283,14 @@ function progressbar:GetLerpRate()
|
||||
|
||||
return self.lerprate
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetCompleted()
|
||||
- desc: gets the value of object.completed
|
||||
--]]---------------------------------------------------------
|
||||
function progressbar:GetLerpRate()
|
||||
|
||||
return self.completed
|
||||
|
||||
end
|
@ -1,361 +1,377 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- text clas
|
||||
slider = class("slider", base)
|
||||
slider:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function slider:initialize()
|
||||
|
||||
self.type = "slider"
|
||||
self.text = "Slider"
|
||||
self.slidetype = "horizontal"
|
||||
self.width = 5
|
||||
self.height = 5
|
||||
self.max = 10
|
||||
self.min = 0
|
||||
self.value = 0
|
||||
self.decimals = 5
|
||||
self.internal = false
|
||||
self.internals = {}
|
||||
self.OnValueChanged = nil
|
||||
|
||||
-- create the slider button
|
||||
table.insert(self.internals, sliderbutton:new(self))
|
||||
|
||||
-- set initial value to minimum
|
||||
self:SetValue(self.min)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function slider:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = internals[1]
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if sliderbutton then
|
||||
if self.slidetype == "horizontal" then
|
||||
self.height = sliderbutton.height
|
||||
elseif self.slidetype == "vertical" then
|
||||
self.width = sliderbutton.width
|
||||
end
|
||||
end
|
||||
|
||||
-- update internals
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function slider:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawSlider(self)
|
||||
end
|
||||
|
||||
-- draw internals
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function slider:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true and button == "l" then
|
||||
|
||||
if self.slidetype == "horizontal" then
|
||||
|
||||
local xpos = x - self.x
|
||||
local button = self.internals[1]
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
button:MoveToX(xpos)
|
||||
button.down = true
|
||||
button.dragging = true
|
||||
button.startx = button.staticx
|
||||
button.clickx = x
|
||||
|
||||
elseif self.slidetype == "vertical" then
|
||||
|
||||
local ypos = y - self.y
|
||||
local button = self.internals[1]
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
button:MoveToY(ypos)
|
||||
button.down = true
|
||||
button.dragging = true
|
||||
button.starty = button.staticy
|
||||
button.clicky = y
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetValue(value)
|
||||
- desc: sets the object's value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetValue(value)
|
||||
|
||||
if value > self.max then
|
||||
return
|
||||
end
|
||||
|
||||
if value < self.min then
|
||||
return
|
||||
end
|
||||
|
||||
local decimals = self.decimals
|
||||
local newval = loveframes.util.Round(value, decimals)
|
||||
local internals = self.internals
|
||||
|
||||
-- set the new value
|
||||
self.value = newval
|
||||
|
||||
-- slider button object
|
||||
local sliderbutton = internals[1]
|
||||
|
||||
-- move the slider button to the new position
|
||||
if self.slidetype == "horizontal" then
|
||||
local xpos = self.width * (( newval - self.min ) / (self.max - self.min))
|
||||
sliderbutton:MoveToX(xpos)
|
||||
elseif self.slidetype == "vertical" then
|
||||
local ypos = self.height - self.height * (( newval - self.min ) / (self.max - self.min))
|
||||
sliderbutton:MoveToY(ypos)
|
||||
end
|
||||
|
||||
-- call OnValueChanged
|
||||
if self.OnValueChanged then
|
||||
self.OnValueChanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetValue()
|
||||
- desc: gets the object's value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetValue()
|
||||
|
||||
return self.value
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMax(max)
|
||||
- desc: sets the object's maximum value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetMax(max)
|
||||
|
||||
self.max = max
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMax()
|
||||
- desc: gets the object's maximum value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetMax()
|
||||
|
||||
return self.max
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMin(min)
|
||||
- desc: sets the object's minimum value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetMin(min)
|
||||
|
||||
self.min = min
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMin()
|
||||
- desc: gets the object's minimum value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetMin()
|
||||
|
||||
return self.min
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMinMax()
|
||||
- desc: sets the object's minimum and maximum values
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetMinMax(min, max)
|
||||
|
||||
self.min = min
|
||||
self.max = max
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMinMax()
|
||||
- desc: gets the object's minimum and maximum values
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetMinMax()
|
||||
|
||||
return self.min, self.max
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(name)
|
||||
- desc: sets the objects's text
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the objects's text
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetDecimals(decimals)
|
||||
- desc: sets the objects's decimals
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetDecimals(decimals)
|
||||
|
||||
self.decimals = decimals
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetButtonSize(width, height)
|
||||
- desc: sets the objects's button size
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetButtonSize(width, height)
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = self.internals[1]
|
||||
|
||||
if sliderbutton then
|
||||
sliderbutton.width = width
|
||||
sliderbutton.height = height
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetButtonSize()
|
||||
- desc: gets the objects's button size
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetButtonSize()
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = self.internals[1]
|
||||
|
||||
if sliderbutton then
|
||||
return sliderbutton.width, sliderbutton.height
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSlideType(slidetype)
|
||||
- desc: sets the objects's slide type
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetSlideType(slidetype)
|
||||
|
||||
self.slidetype = slidetype
|
||||
|
||||
if slidetype == "vertical" then
|
||||
self:SetValue(self.min)
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- text clas
|
||||
slider = class("slider", base)
|
||||
slider:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function slider:initialize()
|
||||
|
||||
self.type = "slider"
|
||||
self.text = "Slider"
|
||||
self.slidetype = "horizontal"
|
||||
self.width = 5
|
||||
self.height = 5
|
||||
self.max = 10
|
||||
self.min = 0
|
||||
self.value = 0
|
||||
self.decimals = 5
|
||||
self.internal = false
|
||||
self.internals = {}
|
||||
self.OnValueChanged = nil
|
||||
|
||||
-- create the slider button
|
||||
table.insert(self.internals, sliderbutton:new(self))
|
||||
|
||||
-- set initial value to minimum
|
||||
self:SetValue(self.min)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function slider:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = internals[1]
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base and self.parent.type ~= "list" then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if sliderbutton then
|
||||
if self.slidetype == "horizontal" then
|
||||
self.height = sliderbutton.height
|
||||
elseif self.slidetype == "vertical" then
|
||||
self.width = sliderbutton.width
|
||||
end
|
||||
end
|
||||
|
||||
-- update internals
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:update(dt)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function slider:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawSlider or skins[defaultskin].DrawSlider
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
-- draw internals
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function slider:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.hover == true and button == "l" then
|
||||
|
||||
if self.slidetype == "horizontal" then
|
||||
|
||||
local xpos = x - self.x
|
||||
local button = self.internals[1]
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
button:MoveToX(xpos)
|
||||
button.down = true
|
||||
button.dragging = true
|
||||
button.startx = button.staticx
|
||||
button.clickx = x
|
||||
|
||||
elseif self.slidetype == "vertical" then
|
||||
|
||||
local ypos = y - self.y
|
||||
local button = self.internals[1]
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
button:MoveToY(ypos)
|
||||
button.down = true
|
||||
button.dragging = true
|
||||
button.starty = button.staticy
|
||||
button.clicky = y
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
for k, v in ipairs(self.internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetValue(value)
|
||||
- desc: sets the object's value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetValue(value)
|
||||
|
||||
if value > self.max then
|
||||
return
|
||||
end
|
||||
|
||||
if value < self.min then
|
||||
return
|
||||
end
|
||||
|
||||
local decimals = self.decimals
|
||||
local newval = loveframes.util.Round(value, decimals)
|
||||
local internals = self.internals
|
||||
|
||||
-- set the new value
|
||||
self.value = newval
|
||||
|
||||
-- slider button object
|
||||
local sliderbutton = internals[1]
|
||||
|
||||
-- move the slider button to the new position
|
||||
if self.slidetype == "horizontal" then
|
||||
local xpos = self.width * (( newval - self.min ) / (self.max - self.min))
|
||||
sliderbutton:MoveToX(xpos)
|
||||
elseif self.slidetype == "vertical" then
|
||||
local ypos = self.height - self.height * (( newval - self.min ) / (self.max - self.min))
|
||||
sliderbutton:MoveToY(ypos)
|
||||
end
|
||||
|
||||
-- call OnValueChanged
|
||||
if self.OnValueChanged then
|
||||
self.OnValueChanged(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetValue()
|
||||
- desc: gets the object's value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetValue()
|
||||
|
||||
return self.value
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMax(max)
|
||||
- desc: sets the object's maximum value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetMax(max)
|
||||
|
||||
self.max = max
|
||||
|
||||
if self.value > self.max then
|
||||
self.value = self.max
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMax()
|
||||
- desc: gets the object's maximum value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetMax()
|
||||
|
||||
return self.max
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMin(min)
|
||||
- desc: sets the object's minimum value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetMin(min)
|
||||
|
||||
self.min = min
|
||||
|
||||
if self.value < self.min then
|
||||
self.value = self.min
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMin()
|
||||
- desc: gets the object's minimum value
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetMin()
|
||||
|
||||
return self.min
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMinMax()
|
||||
- desc: sets the object's minimum and maximum values
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetMinMax(min, max)
|
||||
|
||||
self.min = min
|
||||
self.max = max
|
||||
|
||||
if self.value > self.max then
|
||||
self.value = self.max
|
||||
end
|
||||
|
||||
if self.value < self.min then
|
||||
self.value = self.min
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMinMax()
|
||||
- desc: gets the object's minimum and maximum values
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetMinMax()
|
||||
|
||||
return self.min, self.max
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(name)
|
||||
- desc: sets the objects's text
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetText(text)
|
||||
|
||||
self.text = text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the objects's text
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetDecimals(decimals)
|
||||
- desc: sets the objects's decimals
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetDecimals(decimals)
|
||||
|
||||
self.decimals = decimals
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetButtonSize(width, height)
|
||||
- desc: sets the objects's button size
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetButtonSize(width, height)
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = self.internals[1]
|
||||
|
||||
if sliderbutton then
|
||||
sliderbutton.width = width
|
||||
sliderbutton.height = height
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetButtonSize()
|
||||
- desc: gets the objects's button size
|
||||
--]]---------------------------------------------------------
|
||||
function slider:GetButtonSize()
|
||||
|
||||
local internals = self.internals
|
||||
local sliderbutton = self.internals[1]
|
||||
|
||||
if sliderbutton then
|
||||
return sliderbutton.width, sliderbutton.height
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSlideType(slidetype)
|
||||
- desc: sets the objects's slide type
|
||||
--]]---------------------------------------------------------
|
||||
function slider:SetSlideType(slidetype)
|
||||
|
||||
self.slidetype = slidetype
|
||||
|
||||
if slidetype == "vertical" then
|
||||
self:SetValue(self.min)
|
||||
end
|
||||
|
||||
end
|
926
objects/tabs.lua
926
objects/tabs.lua
@ -1,459 +1,469 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tabs class
|
||||
tabs = class("tabpanel", base)
|
||||
tabs:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:initialize()
|
||||
|
||||
self.type = "tabs"
|
||||
self.width = 100
|
||||
self.height = 50
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.offsetx = 0
|
||||
self.tab = 1
|
||||
self.tabnumber = 1
|
||||
self.padding = 5
|
||||
self.tabheight = 25
|
||||
self.autosize = true
|
||||
self.internal = false
|
||||
self.tooltipfont = love.graphics.newFont(10)
|
||||
self.tabs = {}
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the element
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local internals = self.internals
|
||||
local tab = self.tab
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if numchildren > 0 and tab == 0 then
|
||||
self.tab = 1
|
||||
end
|
||||
|
||||
local pos = 0
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
if v.type == "tabbutton" then
|
||||
v.y = (v.parent.y + v.staticy)
|
||||
v.x = (v.parent.x + v.staticx) + pos + self.offsetx
|
||||
pos = pos + v.width - 1
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:update(dt)
|
||||
v:SetPos(padding, tabheight + padding)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawTabPanel(self)
|
||||
end
|
||||
|
||||
local tabheight = self:GetHeightOfButtons()
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
|
||||
love.graphics.setStencil(stencil)
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
love.graphics.setStencil()
|
||||
|
||||
if #self.children > 0 then
|
||||
self.children[self.tab]:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local tab = self.tab
|
||||
local internals = self.internals
|
||||
local numinternals = #internals
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true then
|
||||
|
||||
if button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if button == "wu" then
|
||||
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals - 1]:GetVisible()
|
||||
|
||||
if col == true and visible == true then
|
||||
self.offsetx = self.offsetx + 5
|
||||
if self.offsetx > 0 then
|
||||
self.offsetx = 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if button == "wd" then
|
||||
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals]:GetVisible()
|
||||
|
||||
if col == true and visible == true then
|
||||
local bwidth = self:GetWidthOfButtons()
|
||||
if (self.offsetx + bwidth) < self.width then
|
||||
self.offsetx = bwidth - self.width
|
||||
else
|
||||
self.offsetx = self.offsetx - 5
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
if numchildren > 0 then
|
||||
children[tab]:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local tab = self.tab
|
||||
local internals = self.internals
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
if numchildren > 0 then
|
||||
children[tab]:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddTab(name, object, tip, image)
|
||||
- desc: adds a new tab to the tab panel
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:AddTab(name, object, tip, image)
|
||||
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local retainsize = object.retainsize
|
||||
local tabnumber = self.tabnumber
|
||||
local internals = self.internals
|
||||
|
||||
object:Remove()
|
||||
object.parent = self
|
||||
object.staticx = 0
|
||||
object.staticy = 0
|
||||
object:SetWidth(self.width - 10)
|
||||
object:SetHeight(self.height - 35)
|
||||
|
||||
table.insert(self.children, object)
|
||||
internals[tabnumber] = tabbutton:new(self, name, tabnumber, tip, image)
|
||||
internals[tabnumber].height = self.tabheight
|
||||
self.tabnumber = tabnumber + 1
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
self:SwitchToTab(k)
|
||||
break
|
||||
end
|
||||
|
||||
self:AddScrollButtons()
|
||||
|
||||
if autosize == true and retainsize == false then
|
||||
object:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddScrollButtons()
|
||||
- desc: creates scroll buttons fot the tab panel
|
||||
- note: for internal use only
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:AddScrollButtons()
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "scrollbutton" then
|
||||
table.remove(internals, k)
|
||||
end
|
||||
end
|
||||
|
||||
local leftbutton = scrollbutton:new("left")
|
||||
leftbutton.parent = self
|
||||
leftbutton:SetPos(0, 0)
|
||||
leftbutton:SetSize(15, 25)
|
||||
leftbutton:SetAlwaysUpdate(true)
|
||||
leftbutton.Update = function(object, dt)
|
||||
if self.offsetx ~= 0 then
|
||||
object.visible = true
|
||||
else
|
||||
object.visible = false
|
||||
object.down = false
|
||||
object.hover = false
|
||||
end
|
||||
|
||||
if object.down == true then
|
||||
if self.offsetx ~= 0 then
|
||||
self.offsetx = self.offsetx + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local rightbutton = scrollbutton:new("right")
|
||||
rightbutton.parent = self
|
||||
rightbutton:SetPos(self.width - 15, 0)
|
||||
rightbutton:SetSize(15, 25)
|
||||
rightbutton:SetAlwaysUpdate(true)
|
||||
rightbutton.Update = function(object, dt)
|
||||
local bwidth = self:GetWidthOfButtons()
|
||||
if (self.offsetx + bwidth) > self.width then
|
||||
object.visible = true
|
||||
else
|
||||
object.visible = false
|
||||
object.down = false
|
||||
object.hover = false
|
||||
end
|
||||
|
||||
if object.down == true then
|
||||
if ((self.x + self.offsetx) + bwidth) ~= (self.x + self.width) then
|
||||
self.offsetx = self.offsetx - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(internals, leftbutton)
|
||||
table.insert(internals, rightbutton)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetWidthOfButtons()
|
||||
- desc: gets the total width of all of the tab buttons
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetWidthOfButtons()
|
||||
|
||||
local width = 0
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "tabbutton" then
|
||||
width = width + v.width
|
||||
end
|
||||
end
|
||||
|
||||
return width
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetHeightOfButtons()
|
||||
- desc: gets the height of one tab button
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetHeightOfButtons()
|
||||
|
||||
return self.tabheight
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SwitchToTab(tabnumber)
|
||||
- desc: makes the specified tab the active tab
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SwitchToTab(tabnumber)
|
||||
|
||||
local children = self.children
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v.visible = false
|
||||
end
|
||||
|
||||
self.tab = tabnumber
|
||||
self.children[tabnumber].visible = true
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetScrollButtonSize(width, height)
|
||||
- desc: sets the size of the scroll buttons
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SetScrollButtonSize(width, height)
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "scrollbutton" then
|
||||
v:SetSize(width, height)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(paddint)
|
||||
- desc: sets the padding for the tab panel
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SetPadding(padding)
|
||||
|
||||
self.padding = padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(paddint)
|
||||
- desc: gets the padding of the tab panel
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetPadding()
|
||||
|
||||
return self.padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetTabHeight(height)
|
||||
- desc: sets the height of the tab buttons
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SetTabHeight(height)
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
self.tabheight = height
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "tabbutton" then
|
||||
v:SetHeight(self.tabheight)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetToolTipFont(font)
|
||||
- desc: sets the height of the tab buttons
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SetToolTipFont(font)
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "tabbutton" and v.tooltip then
|
||||
v.tooltip:SetFont(font)
|
||||
end
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- tabs class
|
||||
tabs = class("tabpanel", base)
|
||||
tabs:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:initialize()
|
||||
|
||||
self.type = "tabs"
|
||||
self.width = 100
|
||||
self.height = 50
|
||||
self.clickx = 0
|
||||
self.clicky = 0
|
||||
self.offsetx = 0
|
||||
self.tab = 1
|
||||
self.tabnumber = 1
|
||||
self.padding = 5
|
||||
self.tabheight = 25
|
||||
self.autosize = true
|
||||
self.internal = false
|
||||
self.tooltipfont = loveframes.basicfontsmall
|
||||
self.tabs = {}
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the element
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:update(dt)
|
||||
|
||||
local visible = self.visible
|
||||
local alwaysupdate = self.alwaysupdate
|
||||
|
||||
if visible == false then
|
||||
if alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local internals = self.internals
|
||||
local tab = self.tab
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
if numchildren > 0 and tab == 0 then
|
||||
self.tab = 1
|
||||
end
|
||||
|
||||
local pos = 0
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:update(dt)
|
||||
if v.type == "tabbutton" then
|
||||
v.y = (v.parent.y + v.staticy)
|
||||
v.x = (v.parent.x + v.staticx) + pos + self.offsetx
|
||||
pos = pos + v.width - 1
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v:update(dt)
|
||||
v:SetPos(padding, tabheight + padding)
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:draw()
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local internals = self.internals
|
||||
local tabheight = self:GetHeightOfButtons()
|
||||
local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end
|
||||
local stencil = love.graphics.newStencil(stencilfunc)
|
||||
local internals = self.internals
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawTabPanel or skins[defaultskin].DrawTabPanel
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
love.graphics.setStencil(stencil)
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
love.graphics.setStencil()
|
||||
|
||||
if #self.children > 0 then
|
||||
self.children[self.tab]:draw()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local tab = self.tab
|
||||
local internals = self.internals
|
||||
local numinternals = #internals
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true then
|
||||
|
||||
if button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if button == "wu" then
|
||||
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals - 1]:GetVisible()
|
||||
|
||||
if col == true and visible == true then
|
||||
self.offsetx = self.offsetx + 5
|
||||
if self.offsetx > 0 then
|
||||
self.offsetx = 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if button == "wd" then
|
||||
|
||||
local buttonheight = self:GetHeightOfButtons()
|
||||
local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1)
|
||||
local visible = internals[numinternals]:GetVisible()
|
||||
|
||||
if col == true and visible == true then
|
||||
local bwidth = self:GetWidthOfButtons()
|
||||
if (self.offsetx + bwidth) < self.width then
|
||||
self.offsetx = bwidth - self.width
|
||||
else
|
||||
self.offsetx = self.offsetx - 5
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
if numchildren > 0 then
|
||||
children[tab]:mousepressed(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousereleased(x, y, button)
|
||||
- desc: called when the player releases a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:mousereleased(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
local children = self.children
|
||||
local numchildren = #children
|
||||
local tab = self.tab
|
||||
local internals = self.internals
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
v:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
if numchildren > 0 then
|
||||
children[tab]:mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddTab(name, object, tip, image)
|
||||
- desc: adds a new tab to the tab panel
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:AddTab(name, object, tip, image)
|
||||
|
||||
local tabheight = self.tabheight
|
||||
local padding = self.padding
|
||||
local autosize = self.autosize
|
||||
local retainsize = object.retainsize
|
||||
local tabnumber = self.tabnumber
|
||||
local internals = self.internals
|
||||
|
||||
object:Remove()
|
||||
object.parent = self
|
||||
object.staticx = 0
|
||||
object.staticy = 0
|
||||
object:SetWidth(self.width - 10)
|
||||
object:SetHeight(self.height - 35)
|
||||
|
||||
table.insert(self.children, object)
|
||||
internals[tabnumber] = tabbutton:new(self, name, tabnumber, tip, image)
|
||||
internals[tabnumber].height = self.tabheight
|
||||
self.tabnumber = tabnumber + 1
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
self:SwitchToTab(k)
|
||||
break
|
||||
end
|
||||
|
||||
self:AddScrollButtons()
|
||||
|
||||
if autosize == true and retainsize == false then
|
||||
object:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: AddScrollButtons()
|
||||
- desc: creates scroll buttons fot the tab panel
|
||||
- note: for internal use only
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:AddScrollButtons()
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "scrollbutton" then
|
||||
table.remove(internals, k)
|
||||
end
|
||||
end
|
||||
|
||||
local leftbutton = scrollbutton:new("left")
|
||||
leftbutton.parent = self
|
||||
leftbutton:SetPos(0, 0)
|
||||
leftbutton:SetSize(15, 25)
|
||||
leftbutton:SetAlwaysUpdate(true)
|
||||
leftbutton.Update = function(object, dt)
|
||||
if self.offsetx ~= 0 then
|
||||
object.visible = true
|
||||
else
|
||||
object.visible = false
|
||||
object.down = false
|
||||
object.hover = false
|
||||
end
|
||||
|
||||
if object.down == true then
|
||||
if self.offsetx ~= 0 then
|
||||
self.offsetx = self.offsetx + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local rightbutton = scrollbutton:new("right")
|
||||
rightbutton.parent = self
|
||||
rightbutton:SetPos(self.width - 15, 0)
|
||||
rightbutton:SetSize(15, 25)
|
||||
rightbutton:SetAlwaysUpdate(true)
|
||||
rightbutton.Update = function(object, dt)
|
||||
local bwidth = self:GetWidthOfButtons()
|
||||
if (self.offsetx + bwidth) > self.width then
|
||||
object.visible = true
|
||||
else
|
||||
object.visible = false
|
||||
object.down = false
|
||||
object.hover = false
|
||||
end
|
||||
|
||||
if object.down == true then
|
||||
if ((self.x + self.offsetx) + bwidth) ~= (self.x + self.width) then
|
||||
self.offsetx = self.offsetx - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(internals, leftbutton)
|
||||
table.insert(internals, rightbutton)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetWidthOfButtons()
|
||||
- desc: gets the total width of all of the tab buttons
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetWidthOfButtons()
|
||||
|
||||
local width = 0
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "tabbutton" then
|
||||
width = width + v.width
|
||||
end
|
||||
end
|
||||
|
||||
return width
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetHeightOfButtons()
|
||||
- desc: gets the height of one tab button
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetHeightOfButtons()
|
||||
|
||||
return self.tabheight
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SwitchToTab(tabnumber)
|
||||
- desc: makes the specified tab the active tab
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SwitchToTab(tabnumber)
|
||||
|
||||
local children = self.children
|
||||
|
||||
for k, v in ipairs(children) do
|
||||
v.visible = false
|
||||
end
|
||||
|
||||
self.tab = tabnumber
|
||||
self.children[tabnumber].visible = true
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetScrollButtonSize(width, height)
|
||||
- desc: sets the size of the scroll buttons
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SetScrollButtonSize(width, height)
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "scrollbutton" then
|
||||
v:SetSize(width, height)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(paddint)
|
||||
- desc: sets the padding for the tab panel
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SetPadding(padding)
|
||||
|
||||
self.padding = padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetPadding(paddint)
|
||||
- desc: gets the padding of the tab panel
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetPadding()
|
||||
|
||||
return self.padding
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetTabHeight(height)
|
||||
- desc: sets the height of the tab buttons
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SetTabHeight(height)
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
self.tabheight = height
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "tabbutton" then
|
||||
v:SetHeight(self.tabheight)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetToolTipFont(font)
|
||||
- desc: sets the height of the tab buttons
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:SetToolTipFont(font)
|
||||
|
||||
local internals = self.internals
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
if v.type == "tabbutton" and v.tooltip then
|
||||
v.tooltip:SetFont(font)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetTabNumber()
|
||||
- desc: gets the object's tab number
|
||||
--]]---------------------------------------------------------
|
||||
function tabs:GetTabNumber()
|
||||
|
||||
return self.tabnumber
|
||||
|
||||
end
|
775
objects/text.lua
775
objects/text.lua
@ -1,360 +1,417 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- note: the text wrapping of this object is
|
||||
experimental and not final
|
||||
--]]------------------------------------------------
|
||||
-- text class
|
||||
text = class("text", base)
|
||||
text:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function text:initialize()
|
||||
|
||||
self.type = "text"
|
||||
self.text = ""
|
||||
self.font = love.graphics.newFont(12)
|
||||
self.width = 5
|
||||
self.height = 5
|
||||
self.maxw = 0
|
||||
self.lines = 1
|
||||
self.text = {}
|
||||
self.original = {}
|
||||
self.internal = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function text:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function text:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
-- skin variables
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin]
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
skin.DrawText(self)
|
||||
end
|
||||
|
||||
self:DrawText()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetText(t)
|
||||
|
||||
local dtype = type(t)
|
||||
local maxw = self.maxw
|
||||
local font = self.font
|
||||
local inserts = {}
|
||||
local tdata, prevcolor
|
||||
|
||||
self.text = {}
|
||||
|
||||
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
|
||||
|
||||
local dtype = type(v)
|
||||
|
||||
if k == 1 and dtype ~= "table" then
|
||||
prevcolor = {0, 0, 0, 255}
|
||||
end
|
||||
|
||||
if dtype == "table" then
|
||||
prevcolor = v
|
||||
elseif dtype == "number" then
|
||||
|
||||
table.insert(self.text, {color = prevcolor, text = tostring(v)})
|
||||
|
||||
elseif dtype == "string" then
|
||||
|
||||
v = v:gsub(string.char(9), " ")
|
||||
v = v:gsub("\n", "")
|
||||
|
||||
local parts = loveframes.util.SplitSring(v, " ")
|
||||
|
||||
for i, j in ipairs(parts) do
|
||||
table.insert(self.text, {color = prevcolor, text = j})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if maxw > 0 then
|
||||
|
||||
for k, v in ipairs(self.text) do
|
||||
|
||||
local data = v.text
|
||||
local width = font:getWidth(data)
|
||||
local curw = 0
|
||||
local new = ""
|
||||
local key = k
|
||||
|
||||
if width > maxw then
|
||||
|
||||
table.remove(self.text, k)
|
||||
|
||||
for n=1, #data do
|
||||
|
||||
local item = data:sub(n, n)
|
||||
local itemw = font:getWidth(item)
|
||||
|
||||
if n ~= #data then
|
||||
|
||||
if (curw + itemw) > maxw then
|
||||
table.insert(inserts, {key = key, color = v.color, text = new})
|
||||
new = item
|
||||
curw = 0 + itemw
|
||||
key = key + 1
|
||||
else
|
||||
new = new .. item
|
||||
curw = curw + itemw
|
||||
end
|
||||
|
||||
else
|
||||
new = new .. item
|
||||
table.insert(inserts, {key = key, color = v.color, text = new})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(inserts) do
|
||||
table.insert(self.text, v.key, {color = v.color, text = v.text})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function text:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Format()
|
||||
- desc: formats the text
|
||||
--]]---------------------------------------------------------
|
||||
function text:DrawText()
|
||||
|
||||
local textdata = self.text
|
||||
local maxw = self.maxw
|
||||
local font = self.font
|
||||
local height = font:getHeight("a")
|
||||
local twidth = 0
|
||||
local drawx = 0
|
||||
local drawy = 0
|
||||
local lines = 0
|
||||
local totalwidth = 0
|
||||
local prevtextwidth
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
|
||||
for k, v in ipairs(textdata) do
|
||||
|
||||
local text = v.text
|
||||
local color = v.color
|
||||
|
||||
if type(text) == "string" then
|
||||
|
||||
local width = font:getWidth(text)
|
||||
totalwidth = totalwidth + width
|
||||
|
||||
if maxw > 0 then
|
||||
|
||||
if k ~= 1 then
|
||||
|
||||
if (twidth + width) > maxw then
|
||||
twidth = 0 + width
|
||||
drawx = 0
|
||||
drawy = drawy + height
|
||||
else
|
||||
twidth = twidth + width
|
||||
drawx = drawx + prevtextwidth
|
||||
end
|
||||
|
||||
else
|
||||
twidth = twidth + width
|
||||
end
|
||||
|
||||
prevtextwidth = width
|
||||
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(unpack(color))
|
||||
love.graphics.print(text, x + drawx, y + drawy)
|
||||
|
||||
else
|
||||
|
||||
if k ~= 1 then
|
||||
drawx = drawx + prevtextwidth
|
||||
end
|
||||
|
||||
prevtextwidth = width
|
||||
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(unpack(color))
|
||||
love.graphics.print(text, x + drawx, y)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if maxw > 0 then
|
||||
self.width = maxw
|
||||
else
|
||||
self.width = totalwidth
|
||||
end
|
||||
|
||||
self.height = drawy + height
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMaxWidth(width)
|
||||
- desc: sets the object's maximum width
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetMaxWidth(width)
|
||||
|
||||
self.maxw = width
|
||||
self:SetText(self.original)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMaxWidth()
|
||||
- desc: gets the object's maximum width
|
||||
--]]---------------------------------------------------------
|
||||
function text:GetMaxWidth()
|
||||
|
||||
return self.maxw
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetWidth(width)
|
||||
- desc: sets the object's width
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetWidth(width)
|
||||
|
||||
self:SetMaxWidth(width)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetHeight()
|
||||
- desc: sets the object's height
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetHeight(height)
|
||||
|
||||
return
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSize()
|
||||
- desc: sets the object's size
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetSize(width, height)
|
||||
|
||||
self:SetMaxWidth(width)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFont(font)
|
||||
- desc: sets the object's font
|
||||
- note: font argument must be a font object
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetFont(font)
|
||||
|
||||
local original = self.original
|
||||
|
||||
self.font = font
|
||||
|
||||
if original then
|
||||
self:SetText(original)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetFont()
|
||||
- desc: gets the object's font
|
||||
--]]---------------------------------------------------------
|
||||
function text:GetFont()
|
||||
|
||||
return self.font
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- note: the text wrapping of this object is
|
||||
experimental and not final
|
||||
--]]------------------------------------------------
|
||||
-- text class
|
||||
text = class("text", base)
|
||||
text:include(loveframes.templates.default)
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: initialize()
|
||||
- desc: initializes the object
|
||||
--]]---------------------------------------------------------
|
||||
function text:initialize()
|
||||
|
||||
self.type = "text"
|
||||
self.text = ""
|
||||
self.font = loveframes.basicfont
|
||||
self.width = 5
|
||||
self.height = 5
|
||||
self.maxw = 0
|
||||
self.lines = 1
|
||||
self.text = {}
|
||||
self.original = {}
|
||||
self.internal = false
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: update(deltatime)
|
||||
- desc: updates the object
|
||||
--]]---------------------------------------------------------
|
||||
function text:update(dt)
|
||||
|
||||
if self.visible == false then
|
||||
if self.alwaysupdate == false then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self:CheckHover()
|
||||
|
||||
-- move to parent if there is a parent
|
||||
if self.parent ~= loveframes.base then
|
||||
self.x = self.parent.x + self.staticx
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
if self.Update then
|
||||
self.Update(self, dt)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: draw()
|
||||
- desc: draws the object
|
||||
--]]---------------------------------------------------------
|
||||
function text:draw()
|
||||
|
||||
if self.visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local skins = loveframes.skins.available
|
||||
local skinindex = loveframes.config["ACTIVESKIN"]
|
||||
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
||||
local selfskin = self.skin
|
||||
local skin = skins[selfskin] or skins[skinindex]
|
||||
local drawfunc = skin.DrawText or skins[defaultskin].DrawText
|
||||
|
||||
loveframes.drawcount = loveframes.drawcount + 1
|
||||
self.draworder = loveframes.drawcount
|
||||
|
||||
if self.Draw ~= nil then
|
||||
self.Draw(self)
|
||||
else
|
||||
drawfunc(self)
|
||||
end
|
||||
|
||||
self:DrawText()
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: mousepressed(x, y, button)
|
||||
- desc: called when the player presses a mouse button
|
||||
--]]---------------------------------------------------------
|
||||
function text:mousepressed(x, y, button)
|
||||
|
||||
local visible = self.visible
|
||||
|
||||
if visible == false then
|
||||
return
|
||||
end
|
||||
|
||||
local hover = self.hover
|
||||
|
||||
if hover == true and button == "l" then
|
||||
|
||||
local baseparent = self:GetBaseParent()
|
||||
|
||||
if baseparent and baseparent.type == "frame" then
|
||||
baseparent:MakeTop()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetText(text)
|
||||
- desc: sets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetText(t)
|
||||
|
||||
local dtype = type(t)
|
||||
local maxw = self.maxw
|
||||
local font = self.font
|
||||
local inserts = {}
|
||||
local tdata, prevcolor
|
||||
|
||||
self.text = {}
|
||||
|
||||
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
|
||||
|
||||
local dtype = type(v)
|
||||
|
||||
if k == 1 and dtype ~= "table" then
|
||||
prevcolor = {0, 0, 0, 255}
|
||||
end
|
||||
|
||||
if dtype == "table" then
|
||||
prevcolor = v
|
||||
elseif dtype == "number" then
|
||||
|
||||
table.insert(self.text, {color = prevcolor, text = tostring(v)})
|
||||
|
||||
elseif dtype == "string" then
|
||||
|
||||
v = v:gsub(string.char(9), " ")
|
||||
v = v:gsub(string.char(92) .. string.char(110), string.char(10))
|
||||
|
||||
local parts = loveframes.util.SplitSring(v, " ")
|
||||
|
||||
for i, j in ipairs(parts) do
|
||||
table.insert(self.text, {color = prevcolor, text = j})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if maxw > 0 then
|
||||
|
||||
for k, v in ipairs(self.text) do
|
||||
|
||||
local data = v.text
|
||||
local width = font:getWidth(data)
|
||||
local curw = 0
|
||||
local new = ""
|
||||
local key = k
|
||||
|
||||
if width > maxw then
|
||||
|
||||
table.remove(self.text, k)
|
||||
|
||||
for n=1, #data do
|
||||
|
||||
local item = data:sub(n, n)
|
||||
local itemw = font:getWidth(item)
|
||||
|
||||
if n ~= #data then
|
||||
|
||||
if (curw + itemw) > maxw then
|
||||
table.insert(inserts, {key = key, color = v.color, text = new})
|
||||
new = item
|
||||
curw = 0 + itemw
|
||||
key = key + 1
|
||||
else
|
||||
new = new .. item
|
||||
curw = curw + itemw
|
||||
end
|
||||
|
||||
else
|
||||
new = new .. item
|
||||
table.insert(inserts, {key = key, color = v.color, text = new})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(inserts) do
|
||||
table.insert(self.text, v.key, {color = v.color, text = v.text})
|
||||
end
|
||||
|
||||
local textdata = self.text
|
||||
local maxw = self.maxw
|
||||
local font = self.font
|
||||
local height = font:getHeight("a")
|
||||
local twidth = 0
|
||||
local drawx = 0
|
||||
local drawy = 0
|
||||
local lines = 0
|
||||
local totalwidth = 0
|
||||
local prevtextwidth
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
|
||||
for k, v in ipairs(textdata) do
|
||||
|
||||
local text = v.text
|
||||
local color = v.color
|
||||
|
||||
if type(text) == "string" then
|
||||
|
||||
local width = font:getWidth(text)
|
||||
totalwidth = totalwidth + width
|
||||
|
||||
if maxw > 0 then
|
||||
|
||||
if k ~= 1 then
|
||||
|
||||
if string.byte(text) == 10 then
|
||||
twidth = 0
|
||||
drawx = 0
|
||||
width = 0
|
||||
drawy = drawy + height
|
||||
text = ""
|
||||
elseif (twidth + width) > maxw then
|
||||
twidth = 0 + width
|
||||
drawx = 0
|
||||
drawy = drawy + height
|
||||
else
|
||||
twidth = twidth + width
|
||||
drawx = drawx + prevtextwidth
|
||||
end
|
||||
|
||||
else
|
||||
twidth = twidth + width
|
||||
end
|
||||
|
||||
prevtextwidth = width
|
||||
|
||||
v.x = drawx
|
||||
v.y = drawy
|
||||
|
||||
else
|
||||
|
||||
if k ~= 1 then
|
||||
drawx = drawx + prevtextwidth
|
||||
end
|
||||
|
||||
prevtextwidth = width
|
||||
|
||||
v.x = drawx
|
||||
v.y = drawy
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if maxw > 0 then
|
||||
self.width = maxw
|
||||
else
|
||||
self.width = totalwidth
|
||||
end
|
||||
|
||||
self.height = drawy + height
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetText()
|
||||
- desc: gets the object's text
|
||||
--]]---------------------------------------------------------
|
||||
function text:GetText()
|
||||
|
||||
return self.text
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Format()
|
||||
- desc: formats the text
|
||||
--]]---------------------------------------------------------
|
||||
function text:DrawText()
|
||||
|
||||
local textdata = self.text
|
||||
local font = self.font
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
|
||||
for k, v in ipairs(textdata) do
|
||||
|
||||
local text = v.text
|
||||
local color = v.color
|
||||
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(unpack(color))
|
||||
love.graphics.printf(text, x + v.x, y + v.y, 0, "left")
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetMaxWidth(width)
|
||||
- desc: sets the object's maximum width
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetMaxWidth(width)
|
||||
|
||||
self.maxw = width
|
||||
self:SetText(self.original)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetMaxWidth()
|
||||
- desc: gets the object's maximum width
|
||||
--]]---------------------------------------------------------
|
||||
function text:GetMaxWidth()
|
||||
|
||||
return self.maxw
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetWidth(width)
|
||||
- desc: sets the object's width
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetWidth(width)
|
||||
|
||||
self:SetMaxWidth(width)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetHeight()
|
||||
- desc: sets the object's height
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetHeight(height)
|
||||
|
||||
return
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetSize()
|
||||
- desc: sets the object's size
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetSize(width, height)
|
||||
|
||||
self:SetMaxWidth(width)
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetFont(font)
|
||||
- desc: sets the object's font
|
||||
- note: font argument must be a font object
|
||||
--]]---------------------------------------------------------
|
||||
function text:SetFont(font)
|
||||
|
||||
local original = self.original
|
||||
|
||||
self.font = font
|
||||
|
||||
if original then
|
||||
self:SetText(original)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetFont()
|
||||
- desc: gets the object's font
|
||||
--]]---------------------------------------------------------
|
||||
function text:GetFont()
|
||||
|
||||
return self.font
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetLines()
|
||||
- desc: gets the number of lines the object's text uses
|
||||
--]]---------------------------------------------------------
|
||||
function text:GetLines()
|
||||
|
||||
return self.lines
|
||||
|
||||
end
|
File diff suppressed because it is too large
Load Diff
102
skins.lua
102
skins.lua
@ -1,52 +1,52 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
loveframes.skins = {}
|
||||
loveframes.skins.available = {}
|
||||
|
||||
function loveframes.skins.Register(skin)
|
||||
|
||||
local name = skin.name
|
||||
local author = skin.author
|
||||
local version = skin.version
|
||||
local namecheck = loveframes.skins.available[name]
|
||||
local dir = loveframes.config["DIRECTORY"] .. "/skins/" ..name
|
||||
local dircheck = love.filesystem.isDirectory(dir)
|
||||
local images = loveframes.util.GetDirContents(dir .. "/images")
|
||||
local indeximages = loveframes.config["INDEXSKINIMAGES"]
|
||||
|
||||
if name == "" or name == nil then
|
||||
error("Could not register skin: Invalid or missing name data.")
|
||||
end
|
||||
|
||||
if author == "" or author == nil then
|
||||
error("Could not register skin: Invalid or missing author data.")
|
||||
end
|
||||
|
||||
if version == "" or version == nil then
|
||||
error("Could not register skin: Invalid or missing version data.")
|
||||
end
|
||||
|
||||
if namecheck ~= nil then
|
||||
error("Could not register skin: A skin with the name '" ..name.. "' already exists.")
|
||||
end
|
||||
|
||||
if dircheck == false then
|
||||
error("Could not register skin: Could not find a directory for skin '" ..name.. "'.")
|
||||
end
|
||||
|
||||
loveframes.skins.available[name] = skin
|
||||
loveframes.skins.available[name].dir = dir
|
||||
loveframes.skins.available[name].images = {}
|
||||
|
||||
if #images > 0 and indeximages == true then
|
||||
|
||||
for k, v in ipairs(images) do
|
||||
loveframes.skins.available[name].images[v.name .. "." .. v.extension] = love.graphics.newImage(v.fullpath)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
loveframes.skins = {}
|
||||
loveframes.skins.available = {}
|
||||
|
||||
function loveframes.skins.Register(skin)
|
||||
|
||||
local name = skin.name
|
||||
local author = skin.author
|
||||
local version = skin.version
|
||||
local namecheck = loveframes.skins.available[name]
|
||||
local dir = loveframes.config["DIRECTORY"] .. "/skins/" ..name
|
||||
local dircheck = love.filesystem.isDirectory(dir)
|
||||
local images = loveframes.util.GetDirContents(dir .. "/images")
|
||||
local indeximages = loveframes.config["INDEXSKINIMAGES"]
|
||||
|
||||
if name == "" or name == nil then
|
||||
error("Could not register skin: Invalid or missing name data.")
|
||||
end
|
||||
|
||||
if author == "" or author == nil then
|
||||
error("Could not register skin: Invalid or missing author data.")
|
||||
end
|
||||
|
||||
if version == "" or version == nil then
|
||||
error("Could not register skin: Invalid or missing version data.")
|
||||
end
|
||||
|
||||
if namecheck ~= nil then
|
||||
error("Could not register skin: A skin with the name '" ..name.. "' already exists.")
|
||||
end
|
||||
|
||||
if dircheck == false then
|
||||
error("Could not register skin: Could not find a directory for skin '" ..name.. "'.")
|
||||
end
|
||||
|
||||
loveframes.skins.available[name] = skin
|
||||
loveframes.skins.available[name].dir = dir
|
||||
loveframes.skins.available[name].images = {}
|
||||
|
||||
if #images > 0 and indeximages == true then
|
||||
|
||||
for k, v in ipairs(images) do
|
||||
loveframes.skins.available[name].images[v.name .. "." .. v.extension] = love.graphics.newImage(v.fullpath)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
2460
skins/Blue/skin.lua
2460
skins/Blue/skin.lua
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,31 +1,31 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- templates
|
||||
loveframes.templates = {}
|
||||
|
||||
-- default template
|
||||
loveframes.templates.default =
|
||||
{
|
||||
x = 0,
|
||||
y = 0,
|
||||
width = 5,
|
||||
height = 5,
|
||||
staticx = 5,
|
||||
staticy = 5,
|
||||
draworder = 0,
|
||||
internal = false,
|
||||
visible = true,
|
||||
hover = false,
|
||||
alwaysupdate = false,
|
||||
retainsize = false,
|
||||
calledmousefunc = false,
|
||||
skin = nil,
|
||||
clickbounds = nil,
|
||||
Draw = nil,
|
||||
Update = nil,
|
||||
OnMouseEnter = nil,
|
||||
OnMouseExit = nil,
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- templates
|
||||
loveframes.templates = {}
|
||||
|
||||
-- default template
|
||||
loveframes.templates.default =
|
||||
{
|
||||
x = 0,
|
||||
y = 0,
|
||||
width = 5,
|
||||
height = 5,
|
||||
staticx = 5,
|
||||
staticy = 5,
|
||||
draworder = 0,
|
||||
internal = false,
|
||||
visible = true,
|
||||
hover = false,
|
||||
alwaysupdate = false,
|
||||
retainsize = false,
|
||||
calledmousefunc = false,
|
||||
skin = nil,
|
||||
clickbounds = nil,
|
||||
Draw = nil,
|
||||
Update = nil,
|
||||
OnMouseEnter = nil,
|
||||
OnMouseExit = nil,
|
||||
}
|
539
util.lua
539
util.lua
@ -1,271 +1,270 @@
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Nikolai Resokav --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- util library
|
||||
loveframes.util = {}
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetActiveSkin(name)
|
||||
- desc: sets the active skin
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.SetActiveSkin(name)
|
||||
|
||||
loveframes.config["ACTIVESKIN"] = name
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetActiveSkin()
|
||||
- desc: gets the active skin
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.GetActiveSkin()
|
||||
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local skin = loveframes.skins.available[index]
|
||||
|
||||
return skin
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2)
|
||||
- desc: checks for a collision between two boxes
|
||||
- note: i take no credit for this function
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2)
|
||||
|
||||
if x1 > x2 + w2 - 1 or y1 > y2 + h2 - 1 or x2 > x1 + w1 - 1 or y2 > y1 + h1 - 1 then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: loveframes.util.GetCollisions(object, table)
|
||||
- desc: gets all objects colliding with the mouse
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.GetCollisions(object, t)
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local object = object or loveframes.base
|
||||
local t = t or {}
|
||||
|
||||
-- add the current object if colliding
|
||||
if object.visible == true then
|
||||
|
||||
local col = loveframes.util.BoundingBox(x, object.x, y, object.y, 1, object.width, 1, object.height)
|
||||
|
||||
if col == true and object.collide ~= false then
|
||||
if object.clickbounds then
|
||||
local clickcol = loveframes.util.BoundingBox(x, object.clickbounds.x, y, object.clickbounds.y, 1, object.clickbounds.width, 1, object.clickbounds.height)
|
||||
if clickcol == true then
|
||||
table.insert(t, object)
|
||||
end
|
||||
else
|
||||
table.insert(t, object)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- check for internals
|
||||
if object.internals then
|
||||
|
||||
for k, v in ipairs(object.internals) do
|
||||
if v.visible == true then
|
||||
loveframes.util.GetCollisions(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- check for children
|
||||
if object.children then
|
||||
|
||||
for k, v in ipairs(object.children) do
|
||||
if v.visible == true then
|
||||
loveframes.util.GetCollisions(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: loveframes.util.GetAllObjects(object, table)
|
||||
- desc: gets all active objects
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.GetAllObjects(object, t)
|
||||
|
||||
local object = object or loveframes.base
|
||||
local t = t or {}
|
||||
|
||||
table.insert(t, object)
|
||||
|
||||
if object.internals then
|
||||
for k, v in ipairs(object.internals) do
|
||||
loveframes.util.GetAllObjects(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
if object.children then
|
||||
for k, v in ipairs(object.children) do
|
||||
loveframes.util.GetAllObjects(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetDirContents(directory, table)
|
||||
- desc: gets the contents of a directory and all of
|
||||
it's subdirectories
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.GetDirContents(dir, t)
|
||||
|
||||
local dir = dir
|
||||
local t = t or {}
|
||||
local files = love.filesystem.enumerate(dir)
|
||||
local dirs = {}
|
||||
|
||||
-- local function to restore a string to it's original state after being split
|
||||
local function restore(t)
|
||||
|
||||
local s = ""
|
||||
|
||||
t[#t] = nil
|
||||
|
||||
for k, v in ipairs(t) do
|
||||
if k ~= #t then
|
||||
s = s .. v .. "."
|
||||
else
|
||||
s = s .. v
|
||||
end
|
||||
end
|
||||
|
||||
return s
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(files) do
|
||||
|
||||
local isdir = love.filesystem.isDirectory(dir.. "/" ..v)
|
||||
|
||||
if isdir == true then
|
||||
table.insert(dirs, dir.. "/" ..v)
|
||||
else
|
||||
local parts = loveframes.util.SplitSring(v, "([.])")
|
||||
local extension = parts[#parts]
|
||||
local name = restore(parts)
|
||||
table.insert(t, {path = dir, fullpath = dir.. "/" ..v, name = name, extension = extension})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if #dirs > 0 then
|
||||
for k, v in ipairs(dirs) do
|
||||
t = loveframes.util.GetDirContents(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Round(val, decimal)
|
||||
- desc: rounds a number based on the decimal limit
|
||||
- note: i take no credit for this function
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.Round(val, decimal)
|
||||
|
||||
if (decimal) then
|
||||
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
|
||||
else
|
||||
return math.floor(val+0.5)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Split(string, pattern)
|
||||
- desc: splits a string into a table based on a given pattern
|
||||
- note: i take no credit for this function
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.SplitSring(str, pat)
|
||||
|
||||
local t = {} -- NOTE: use {n = 0} in Lua-5.0
|
||||
|
||||
if pat == " " then
|
||||
|
||||
local fpat = "(.-)" .. pat
|
||||
local last_end = 1
|
||||
local s, e, cap = str:find(fpat, 1)
|
||||
while s do
|
||||
if s ~= #str then
|
||||
cap = cap .. " "
|
||||
end
|
||||
if s ~= 1 or cap ~= "" then
|
||||
table.insert(t,cap)
|
||||
end
|
||||
last_end = e+1
|
||||
s, e, cap = str:find(fpat, last_end)
|
||||
end
|
||||
if last_end <= #str then
|
||||
cap = str:sub(last_end)
|
||||
table.insert(t, cap)
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
local fpat = "(.-)" .. pat
|
||||
local last_end = 1
|
||||
local s, e, cap = str:find(fpat, 1)
|
||||
while s do
|
||||
if s ~= 1 or cap ~= "" then
|
||||
table.insert(t,cap)
|
||||
end
|
||||
last_end = e+1
|
||||
s, e, cap = str:find(fpat, last_end)
|
||||
end
|
||||
if last_end <= #str then
|
||||
cap = str:sub(last_end)
|
||||
table.insert(t, cap)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Trim(string)
|
||||
- desc: trims spaces off of the beginning and end of
|
||||
a string
|
||||
- note: i take no credit for this function
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.TrimString(s)
|
||||
|
||||
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: RemoveAll()
|
||||
- desc: removes all gui elements
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.RemoveAll()
|
||||
|
||||
loveframes.base.children = {}
|
||||
|
||||
--[[------------------------------------------------
|
||||
-- LÖVE Frames --
|
||||
-- By Kenny Shields --
|
||||
--]]------------------------------------------------
|
||||
|
||||
-- util library
|
||||
loveframes.util = {}
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetActiveSkin(name)
|
||||
- desc: sets the active skin
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.SetActiveSkin(name)
|
||||
|
||||
loveframes.config["ACTIVESKIN"] = name
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetActiveSkin()
|
||||
- desc: gets the active skin
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.GetActiveSkin()
|
||||
|
||||
local index = loveframes.config["ACTIVESKIN"]
|
||||
local skin = loveframes.skins.available[index]
|
||||
|
||||
return skin
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2)
|
||||
- desc: checks for a collision between two boxes
|
||||
- note: i take no credit for this function
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2)
|
||||
|
||||
if x1 > x2 + w2 - 1 or y1 > y2 + h2 - 1 or x2 > x1 + w1 - 1 or y2 > y1 + h1 - 1 then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: loveframes.util.GetCollisions(object, table)
|
||||
- desc: gets all objects colliding with the mouse
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.GetCollisions(object, t)
|
||||
|
||||
local x, y = love.mouse.getPosition()
|
||||
local object = object or loveframes.base
|
||||
local t = t or {}
|
||||
|
||||
-- add the current object if colliding
|
||||
if object.visible == true then
|
||||
|
||||
local col = loveframes.util.BoundingBox(x, object.x, y, object.y, 1, object.width, 1, object.height)
|
||||
|
||||
if col == true and object.collide ~= false then
|
||||
if object.clickbounds then
|
||||
local clickcol = loveframes.util.BoundingBox(x, object.clickbounds.x, y, object.clickbounds.y, 1, object.clickbounds.width, 1, object.clickbounds.height)
|
||||
if clickcol == true then
|
||||
table.insert(t, object)
|
||||
end
|
||||
else
|
||||
table.insert(t, object)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- check for internals
|
||||
if object.internals then
|
||||
|
||||
for k, v in ipairs(object.internals) do
|
||||
if v.visible == true and v.type ~= "tooltip" then
|
||||
loveframes.util.GetCollisions(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- check for children
|
||||
if object.children then
|
||||
|
||||
for k, v in ipairs(object.children) do
|
||||
if v.visible == true then
|
||||
loveframes.util.GetCollisions(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: loveframes.util.GetAllObjects(object, table)
|
||||
- desc: gets all active objects
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.GetAllObjects(object, t)
|
||||
|
||||
local object = object or loveframes.base
|
||||
local t = t or {}
|
||||
|
||||
table.insert(t, object)
|
||||
|
||||
if object.internals then
|
||||
for k, v in ipairs(object.internals) do
|
||||
loveframes.util.GetAllObjects(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
if object.children then
|
||||
for k, v in ipairs(object.children) do
|
||||
loveframes.util.GetAllObjects(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetDirContents(directory, table)
|
||||
- desc: gets the contents of a directory and all of
|
||||
it's subdirectories
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.GetDirContents(dir, t)
|
||||
|
||||
local dir = dir
|
||||
local t = t or {}
|
||||
local files = love.filesystem.enumerate(dir)
|
||||
local dirs = {}
|
||||
|
||||
-- local function to restore a string to it's original state after being split
|
||||
local function restore(t)
|
||||
|
||||
local s = ""
|
||||
|
||||
t[#t] = nil
|
||||
|
||||
for k, v in ipairs(t) do
|
||||
if k ~= #t then
|
||||
s = s .. v .. "."
|
||||
else
|
||||
s = s .. v
|
||||
end
|
||||
end
|
||||
|
||||
return s
|
||||
|
||||
end
|
||||
|
||||
for k, v in ipairs(files) do
|
||||
|
||||
local isdir = love.filesystem.isDirectory(dir.. "/" ..v)
|
||||
|
||||
if isdir == true then
|
||||
table.insert(dirs, dir.. "/" ..v)
|
||||
else
|
||||
local parts = loveframes.util.SplitSring(v, "([.])")
|
||||
local extension = parts[#parts]
|
||||
local name = restore(parts)
|
||||
table.insert(t, {path = dir, fullpath = dir.. "/" ..v, name = name, extension = extension})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if #dirs > 0 then
|
||||
for k, v in ipairs(dirs) do
|
||||
t = loveframes.util.GetDirContents(v, t)
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: Round(num, idp)
|
||||
- desc: rounds a number based on the decimal limit
|
||||
- note: i take no credit for this function
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.Round(num, idp)
|
||||
|
||||
local mult = 10^(idp or 0)
|
||||
if num >= 0 then return math.floor(num * mult + 0.5) / mult
|
||||
else return math.ceil(num * mult - 0.5) / mult end
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SplitSring(string, pattern)
|
||||
- desc: splits a string into a table based on a given pattern
|
||||
- note: i take no credit for this function
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.SplitSring(str, pat)
|
||||
|
||||
local t = {} -- NOTE: use {n = 0} in Lua-5.0
|
||||
|
||||
if pat == " " then
|
||||
|
||||
local fpat = "(.-)" .. pat
|
||||
local last_end = 1
|
||||
local s, e, cap = str:find(fpat, 1)
|
||||
while s do
|
||||
if s ~= #str then
|
||||
cap = cap .. " "
|
||||
end
|
||||
if s ~= 1 or cap ~= "" then
|
||||
table.insert(t,cap)
|
||||
end
|
||||
last_end = e+1
|
||||
s, e, cap = str:find(fpat, last_end)
|
||||
end
|
||||
if last_end <= #str then
|
||||
cap = str:sub(last_end)
|
||||
table.insert(t, cap)
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
local fpat = "(.-)" .. pat
|
||||
local last_end = 1
|
||||
local s, e, cap = str:find(fpat, 1)
|
||||
while s do
|
||||
if s ~= 1 or cap ~= "" then
|
||||
table.insert(t,cap)
|
||||
end
|
||||
last_end = e+1
|
||||
s, e, cap = str:find(fpat, last_end)
|
||||
end
|
||||
if last_end <= #str then
|
||||
cap = str:sub(last_end)
|
||||
table.insert(t, cap)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: TrimString(string)
|
||||
- desc: trims spaces off of the beginning and end of
|
||||
a string
|
||||
- note: i take no credit for this function
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.TrimString(s)
|
||||
|
||||
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: RemoveAll()
|
||||
- desc: removes all gui elements
|
||||
--]]---------------------------------------------------------
|
||||
function loveframes.util.RemoveAll()
|
||||
|
||||
loveframes.base.children = {}
|
||||
loveframes.base.internals = {}
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user