Prepare 11.2
22
demo/conf.lua
Normal file
@ -0,0 +1,22 @@
|
||||
function love.conf(t)
|
||||
|
||||
t.title = "Love Frames Demo"
|
||||
t.author = "Kenny Shields"
|
||||
t.version = "11.2"
|
||||
t.identity = "loveframes-demo"
|
||||
|
||||
t.console = true
|
||||
t.modules.joystick = false
|
||||
t.modules.audio = true
|
||||
t.modules.keyboard = true
|
||||
t.modules.event = true
|
||||
t.modules.image = true
|
||||
t.modules.graphics = true
|
||||
t.modules.timer = true
|
||||
t.modules.mouse = true
|
||||
t.modules.sound = true
|
||||
t.modules.physics = false
|
||||
t.window.vsync = false
|
||||
t.window.resizable = false
|
||||
|
||||
end
|
27
demo/examples/button.lua
Normal file
@ -0,0 +1,27 @@
|
||||
local example = {}
|
||||
example.title = "Button"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Button")
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local button = loveframes.Create("button", frame)
|
||||
button:SetWidth(200)
|
||||
button:SetText("Button")
|
||||
button:Center()
|
||||
button.OnClick = function(object, x, y)
|
||||
object:SetText("You clicked the button!")
|
||||
end
|
||||
button.OnMouseEnter = function(object)
|
||||
object:SetText("The mouse entered the button.")
|
||||
end
|
||||
button.OnMouseExit = function(object)
|
||||
object:SetText("The mouse exited the button.")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
41
demo/examples/buttongroup.lua
Normal file
@ -0,0 +1,41 @@
|
||||
local example = {}
|
||||
example.title = "Button Group"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Button Group with image")
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local button1 = loveframes.Create("button", frame)
|
||||
button1:SetWidth(200)
|
||||
button1:SetText("Folder 1")
|
||||
button1:SetImage("resources/folder.png")
|
||||
button1:SetPos(50, 30)
|
||||
button1.groupIndex = 1
|
||||
|
||||
local button2 = loveframes.Create("button", frame)
|
||||
button2:SetWidth(200)
|
||||
button2:SetText("Folder 2")
|
||||
button2:SetImage("resources/folder.png")
|
||||
button2:SetPos(50, 60)
|
||||
button2.groupIndex = 1
|
||||
|
||||
local button3 = loveframes.Create("button", frame)
|
||||
button3:SetWidth(200)
|
||||
button3:SetText("File 1")
|
||||
button3:SetImage("resources/file.png")
|
||||
button3:SetPos(50, 90)
|
||||
button3.groupIndex = 2
|
||||
|
||||
local button4 = loveframes.Create("button", frame)
|
||||
button4:SetWidth(200)
|
||||
button4:SetText("File 2")
|
||||
button4:SetImage("resources/file.png")
|
||||
button4:SetPos(50, 120)
|
||||
button4.groupIndex = 2
|
||||
|
||||
end
|
||||
|
||||
return example
|
23
demo/examples/checkbox.lua
Normal file
@ -0,0 +1,23 @@
|
||||
local example = {}
|
||||
example.title = "Checkbox"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Checkbox")
|
||||
frame:SetHeight(85)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local checkbox1 = loveframes.Create("checkbox", frame)
|
||||
checkbox1:SetText("Checkbox 1")
|
||||
checkbox1:SetPos(5, 30)
|
||||
|
||||
local checkbox2 = loveframes.Create("checkbox", frame)
|
||||
checkbox2:SetText("Checkbox 2")
|
||||
checkbox2:SetPos(5, 60)
|
||||
|
||||
end
|
||||
|
||||
return example
|
||||
|
28
demo/examples/collapsiblecategory.lua
Normal file
@ -0,0 +1,28 @@
|
||||
local example = {}
|
||||
example.title = "Collapsible Category"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Collapsible Category")
|
||||
frame:SetSize(500, 300)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local panel = loveframes.Create("panel")
|
||||
panel:SetHeight(230)
|
||||
|
||||
local text = loveframes.Create("text", panel)
|
||||
text:SetText("Collapsible Category")
|
||||
|
||||
local collapsiblecategory = loveframes.Create("collapsiblecategory", frame)
|
||||
collapsiblecategory:SetPos(5, 30)
|
||||
collapsiblecategory:SetSize(490, 265)
|
||||
collapsiblecategory:SetText("Category 1")
|
||||
collapsiblecategory:SetObject(panel)
|
||||
|
||||
text:Center()
|
||||
|
||||
end
|
||||
|
||||
return example
|
85
demo/examples/color_changer.lua
Normal file
@ -0,0 +1,85 @@
|
||||
local example = {}
|
||||
example.title = "Color Changer"
|
||||
example.category = "Example Implementations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local color = {0, 0, 0, 1}
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Color Changer")
|
||||
frame:SetSize(500, 255)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local colorbox = loveframes.Create("panel", frame)
|
||||
colorbox:SetPos(5, 30)
|
||||
colorbox:SetSize(490, 100)
|
||||
colorbox.Draw = function(object)
|
||||
love.graphics.setColor(color)
|
||||
love.graphics.rectangle("fill", object:GetX(), object:GetY(), object:GetWidth(), object:GetHeight())
|
||||
love.graphics.setColor(.6, .6, .6, 1)
|
||||
love.graphics.setLineWidth(1)
|
||||
love.graphics.setLineStyle("smooth")
|
||||
love.graphics.rectangle("line", object:GetX(), object:GetY(), object:GetWidth(), object:GetHeight())
|
||||
end
|
||||
|
||||
local slider1 = loveframes.Create("slider", frame)
|
||||
slider1:SetPos(5, 150)
|
||||
slider1:SetWidth(490)
|
||||
slider1:SetMax(255)
|
||||
slider1:SetDecimals(0)
|
||||
slider1.OnValueChanged = function(object, value)
|
||||
color[1] = value / 255
|
||||
end
|
||||
|
||||
local slider1name = loveframes.Create("text", frame)
|
||||
slider1name:SetPos(5, 135)
|
||||
slider1name:SetText("Red")
|
||||
|
||||
local slider1value = loveframes.Create("text", frame)
|
||||
slider1value:SetPos(470, 135)
|
||||
slider1value.Update = function(object)
|
||||
object:SetText(slider1:GetValue())
|
||||
end
|
||||
|
||||
local slider2 = loveframes.Create("slider", frame)
|
||||
slider2:SetPos(5, 190)
|
||||
slider2:SetWidth(490)
|
||||
slider2:SetMax(255)
|
||||
slider2:SetDecimals(0)
|
||||
slider2.OnValueChanged = function(object, value)
|
||||
color[2] = value / 255
|
||||
end
|
||||
|
||||
local slider2name = loveframes.Create("text", frame)
|
||||
slider2name:SetPos(5, 175)
|
||||
slider2name:SetText("Green")
|
||||
|
||||
local slider2value = loveframes.Create("text", frame)
|
||||
slider2value:SetPos(470, 175)
|
||||
slider2value.Update = function(object)
|
||||
object:SetText(slider2:GetValue())
|
||||
end
|
||||
|
||||
local slider3 = loveframes.Create("slider", frame)
|
||||
slider3:SetPos(5, 230)
|
||||
slider3:SetWidth(490)
|
||||
slider3:SetMax(255)
|
||||
slider3:SetDecimals(0)
|
||||
slider3.OnValueChanged = function(object, value)
|
||||
color[3] = value / 255
|
||||
end
|
||||
|
||||
local slider3name = loveframes.Create("text", frame)
|
||||
slider3name:SetPos(5, 215)
|
||||
slider3name:SetText("Blue")
|
||||
|
||||
local slider3value = loveframes.Create("text", frame)
|
||||
slider3value:SetPos(470, 215)
|
||||
slider3value.Update = function(object)
|
||||
object:SetText(slider3:GetValue())
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
26
demo/examples/columnlist.lua
Normal file
@ -0,0 +1,26 @@
|
||||
local example = {}
|
||||
example.title = "Column List"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Column List")
|
||||
frame:SetSize(500, 300)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local list = loveframes.Create("columnlist", frame)
|
||||
list:SetPos(5, 30)
|
||||
list:SetSize(490, 265)
|
||||
list:AddColumn("Column 1")
|
||||
list:AddColumn("Column 2")
|
||||
list:AddColumn("Column 3")
|
||||
list:AddColumn("Column 4")
|
||||
|
||||
for i=1, 20 do
|
||||
list:AddRow("Row " ..i.. ", column 1", "Row " ..i.. ", column 2", "Row " ..i.. ", column 3", "Row " ..i.. ", column 4")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
35
demo/examples/custom_state.lua
Normal file
@ -0,0 +1,35 @@
|
||||
local example = {}
|
||||
example.title = "Custom State"
|
||||
example.category = "Example Implementations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Custom State")
|
||||
frame:SetWidth(500)
|
||||
frame:Center()
|
||||
frame:ShowCloseButton(false)
|
||||
|
||||
local text = loveframes.Create("text", frame)
|
||||
text:SetText("Love Frames is now in a custom state. The objects that you are currently seeing are registered with this custom state and will only be visible while the state is active. All the objects that you were able to see before the state was activated still exist, they just won't be visible until the custom state is deactivated.")
|
||||
text:SetMaxWidth(490)
|
||||
text:SetPos(5, 30)
|
||||
|
||||
local button = loveframes.Create("button", frame)
|
||||
button:SetWidth(490)
|
||||
button:SetText("Return to main state")
|
||||
button:Center()
|
||||
button.OnClick = function(object, x, y)
|
||||
loveframes.SetState("none")
|
||||
frame:Remove()
|
||||
end
|
||||
|
||||
button:SetY(text:GetHeight() + 35)
|
||||
frame:SetHeight(text:GetHeight() + 65)
|
||||
frame:SetState("newstate")
|
||||
|
||||
loveframes.SetState("newstate")
|
||||
|
||||
end
|
||||
|
||||
return example
|
26
demo/examples/form.lua
Normal file
@ -0,0 +1,26 @@
|
||||
local example = {}
|
||||
example.title = "Form"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Form")
|
||||
frame:SetSize(500, 80)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local form = loveframes.Create("form", frame)
|
||||
form:SetPos(5, 25)
|
||||
form:SetSize(490, 65)
|
||||
form:SetLayoutType("horizontal")
|
||||
|
||||
for i=1, 3 do
|
||||
local button = loveframes.Create("button")
|
||||
button:SetText(i)
|
||||
button:SetWidth((490/3) - 7)
|
||||
form:AddItem(button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
42
demo/examples/frame.lua
Normal file
@ -0,0 +1,42 @@
|
||||
local example = {}
|
||||
example.title = "Frame"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Frame")
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
frame:SetIcon("resources/food/Apple.png")
|
||||
frame:SetDockable(true)
|
||||
frame:SetScreenLocked(true)
|
||||
frame:SetResizable(true)
|
||||
frame:SetMaxWidth(800)
|
||||
frame:SetMaxHeight(600)
|
||||
frame:SetMinWidth(200)
|
||||
frame:SetMinHeight(100)
|
||||
|
||||
local button = loveframes.Create("button", frame)
|
||||
button:SetText("Modal")
|
||||
button:SetImage("resources/food/Onion.png")
|
||||
button:SetWidth(125)
|
||||
button:Center()
|
||||
button.Update = function(object, dt)
|
||||
object:Center()
|
||||
local modal = object:GetParent():GetModal()
|
||||
if modal then
|
||||
object:SetText("Remove Modal")
|
||||
object.OnClick = function()
|
||||
object:GetParent():SetModal(false)
|
||||
end
|
||||
else
|
||||
object:SetText("Set Modal")
|
||||
object.OnClick = function()
|
||||
object:GetParent():SetModal(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
25
demo/examples/globals_viewer.lua
Normal file
@ -0,0 +1,25 @@
|
||||
local example = {}
|
||||
example.title = "Globals Viewer"
|
||||
example.category = "Example Implementations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Globals Viewer")
|
||||
frame:SetSize(500, 300)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local glist = loveframes.Create("columnlist", frame)
|
||||
glist:SetPos(5, 30)
|
||||
glist:SetSize(490, 265)
|
||||
glist:AddColumn("Key")
|
||||
glist:AddColumn("Value")
|
||||
|
||||
for k, v in pairs(_G) do
|
||||
local value_str = ""
|
||||
glist:AddRow(k, tostring(v))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
39
demo/examples/grid.lua
Normal file
@ -0,0 +1,39 @@
|
||||
local example = {}
|
||||
example.title = "Grid"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Grid")
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local grid = loveframes.Create("grid", frame)
|
||||
grid:SetPos(5, 30)
|
||||
grid:SetRows(5)
|
||||
grid:SetColumns(5)
|
||||
grid:SetCellWidth(25)
|
||||
grid:SetCellHeight(25)
|
||||
grid:SetCellPadding(5)
|
||||
grid:SetItemAutoSize(true)
|
||||
|
||||
local id = 1
|
||||
|
||||
for i=1, 5 do
|
||||
for n=1, 5 do
|
||||
local button = loveframes.Create("button")
|
||||
button:SetSize(15, 15)
|
||||
button:SetText(id)
|
||||
grid:AddItem(button, i, n)
|
||||
id = id + 1
|
||||
end
|
||||
end
|
||||
|
||||
grid.OnSizeChanged = function(object)
|
||||
frame:SetSize(object:GetWidth() + 10, object:GetHeight() + 35)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
75
demo/examples/http_request.lua
Normal file
@ -0,0 +1,75 @@
|
||||
local example = {}
|
||||
example.title = "HTTP request"
|
||||
example.category = "Example Implementations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local headers = {}
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("HTTP Request")
|
||||
frame:SetSize(500, 365)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local resultpanel = loveframes.Create("panel", frame)
|
||||
resultpanel:SetPos(5, 30)
|
||||
resultpanel:SetSize(490, 25)
|
||||
|
||||
local headersbutton = loveframes.Create("button", resultpanel)
|
||||
headersbutton:SetPos(390, 0)
|
||||
headersbutton:SetSize(100, 25)
|
||||
headersbutton:SetText("View Headers")
|
||||
headersbutton:SetVisible(false)
|
||||
headersbutton.OnClick = function(object)
|
||||
local headersframe = loveframes.Create("frame")
|
||||
headersframe:SetName("Headers")
|
||||
headersframe:SetSize(400, 200)
|
||||
headersframe:CenterWithinArea(unpack(centerarea))
|
||||
local headerslist = loveframes.Create("columnlist", headersframe)
|
||||
headerslist:SetPos(5, 30)
|
||||
headerslist:SetSize(390, 165)
|
||||
headerslist:AddColumn("Name")
|
||||
headerslist:AddColumn("Value")
|
||||
for k, v in pairs(headers) do
|
||||
headerslist:AddRow(k, v)
|
||||
end
|
||||
end
|
||||
|
||||
local resulttext = loveframes.Create("text", resultpanel)
|
||||
resulttext:SetPos(5, 5)
|
||||
|
||||
local resultinput = loveframes.Create("textinput", frame)
|
||||
resultinput:SetPos(5, 60)
|
||||
resultinput:SetWidth(490)
|
||||
resultinput:SetMultiline(true)
|
||||
resultinput:SetHeight(270)
|
||||
resultinput:SetEditable(false)
|
||||
|
||||
local urlinput = loveframes.Create("textinput", frame)
|
||||
urlinput:SetSize(387, 25)
|
||||
urlinput:SetPos(5, 335)
|
||||
urlinput:SetText("http://love2d.org")
|
||||
|
||||
local httpbutton = loveframes.Create("button", frame)
|
||||
httpbutton:SetSize(100, 25)
|
||||
httpbutton:SetPos(frame:GetWidth() - 105, 335)
|
||||
httpbutton:SetText("Send Request")
|
||||
httpbutton.OnClick = function()
|
||||
local url = urlinput:GetValue()
|
||||
local http = require("socket.http")
|
||||
local b, c, h = http.request(url)
|
||||
if b then
|
||||
resulttext:SetText("Response code: " ..c)
|
||||
resulttext:CenterY()
|
||||
resultinput:SetText(b)
|
||||
resultinput:SetFocus(true)
|
||||
headersbutton:SetVisible(true)
|
||||
headers = h
|
||||
else
|
||||
resultinput:SetText("Error: HTTP request returned a nil value.")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
104
demo/examples/image.lua
Normal file
@ -0,0 +1,104 @@
|
||||
local example = {}
|
||||
example.title = "Image"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Image")
|
||||
frame:SetSize(138, 340)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local image = loveframes.Create("image", frame)
|
||||
image:SetImage("resources/magic.png")
|
||||
image:SetPos(5, 30)
|
||||
image:SetSize(128, 120)
|
||||
|
||||
local panel = loveframes.Create("panel", frame)
|
||||
panel:SetPos(5, 160)
|
||||
panel:SetSize(128, 170)
|
||||
|
||||
local text1 = loveframes.Create("text", panel)
|
||||
text1:SetPos(5, 5)
|
||||
text1:SetText("Orientation: ")
|
||||
|
||||
local slider1 = loveframes.Create("slider", panel)
|
||||
slider1:SetPos(5, 20)
|
||||
slider1:SetWidth(118)
|
||||
slider1:SetMinMax(0, loveframes.Round(math.pi * 2, 5))
|
||||
slider1:SetDecimals(5)
|
||||
slider1.OnValueChanged = function(object)
|
||||
image:SetOrientation(object:GetValue())
|
||||
end
|
||||
|
||||
text1.Update = function(object, dt)
|
||||
local value = slider1:GetValue()
|
||||
local max = slider1:GetMax()
|
||||
local progress = value/max
|
||||
local final = loveframes.Round(360 * progress)
|
||||
object:SetText("Orientation: " ..final)
|
||||
end
|
||||
|
||||
local text2 = loveframes.Create("text", panel)
|
||||
text2:SetPos(5, 40)
|
||||
text2:SetText("Scale")
|
||||
|
||||
local slider2 = loveframes.Create("slider", panel)
|
||||
slider2:SetPos(5, 55)
|
||||
slider2:SetWidth(118)
|
||||
slider2:SetMinMax(.5, 2)
|
||||
slider2:SetValue(1)
|
||||
slider2:SetDecimals(5)
|
||||
slider2.OnValueChanged = function(object)
|
||||
image:SetScale(object:GetValue(), object:GetValue())
|
||||
end
|
||||
|
||||
text2.Update = function(object, dt)
|
||||
object:SetText("Scale: " ..slider2:GetValue())
|
||||
end
|
||||
|
||||
local text3 = loveframes.Create("text", panel)
|
||||
text3:SetPos(5, 75)
|
||||
text3:SetText("Offset")
|
||||
|
||||
local slider3 = loveframes.Create("slider", panel)
|
||||
slider3:SetPos(5, 90)
|
||||
slider3:SetWidth(118)
|
||||
slider3:SetMinMax(0, 50)
|
||||
slider3:SetDecimals(5)
|
||||
slider3.OnValueChanged = function(object)
|
||||
image:SetOffset(object:GetValue(), object:GetValue())
|
||||
end
|
||||
|
||||
text3.Update = function(object, dt)
|
||||
object:SetText("Offset: " ..slider3:GetValue())
|
||||
end
|
||||
|
||||
local text4 = loveframes.Create("text", panel)
|
||||
text4:SetPos(5, 110)
|
||||
text4:SetText("Shear")
|
||||
|
||||
local slider4 = loveframes.Create("slider", panel)
|
||||
slider4:SetPos(5, 125)
|
||||
slider4:SetWidth(118)
|
||||
slider4:SetMinMax(0, 40)
|
||||
slider4:SetDecimals(5)
|
||||
slider4.OnValueChanged = function(object)
|
||||
image:SetShear(object:GetValue(), object:GetValue())
|
||||
end
|
||||
|
||||
text4.Update = function(object, dt)
|
||||
object:SetText("Shear: " ..slider4:GetValue())
|
||||
end
|
||||
|
||||
local checkbox5 = loveframes.Create("checkbox", panel)
|
||||
checkbox5:SetText("Stretched")
|
||||
checkbox5:SetPos(5, 150)
|
||||
checkbox5.OnChanged = function(object, value)
|
||||
image.stretch = value
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
||||
|
19
demo/examples/imagebutton.lua
Normal file
@ -0,0 +1,19 @@
|
||||
local example = {}
|
||||
example.title = "Image Button"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Image Button")
|
||||
frame:SetSize(138, 163)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local imagebutton = loveframes.Create("imagebutton", frame)
|
||||
imagebutton:SetImage("resources/magic.png")
|
||||
imagebutton:SetPos(5, 30)
|
||||
imagebutton:SizeToImage()
|
||||
|
||||
end
|
||||
|
||||
return example
|
129
demo/examples/list.lua
Normal file
@ -0,0 +1,129 @@
|
||||
local example = {}
|
||||
example.title = "List"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
local font = love.graphics.newFont(10)
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("List")
|
||||
frame:SetSize(500, 470)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local list = loveframes.Create("list", frame)
|
||||
list:SetPos(5, 30)
|
||||
list:SetSize(490, 300)
|
||||
list:SetPadding(5)
|
||||
list:SetSpacing(5)
|
||||
|
||||
local panel = loveframes.Create("panel")
|
||||
panel:SetSize(490, 115)
|
||||
panel.Draw = function() end
|
||||
|
||||
local text1 = loveframes.Create("text", panel)
|
||||
local text2 = loveframes.Create("text", panel)
|
||||
local slider1 = loveframes.Create("slider", panel)
|
||||
slider1:SetPos(5, 20)
|
||||
slider1:SetWidth(480)
|
||||
slider1:SetMinMax(0, 100)
|
||||
slider1:SetValue(5)
|
||||
slider1:SetText("Padding")
|
||||
slider1:SetDecimals(0)
|
||||
slider1.OnValueChanged = function(object2, value)
|
||||
list:SetPadding(value)
|
||||
text2:SetPos(slider1:GetWidth() - text2:GetWidth(), 5)
|
||||
text2:SetText(slider1:GetValue())
|
||||
end
|
||||
|
||||
text1:SetPos(5, 5)
|
||||
text1:SetFont(font)
|
||||
text1:SetText(slider1:GetText())
|
||||
|
||||
text2:SetText(slider1:GetValue())
|
||||
text2:SetFont(font)
|
||||
text2:SetPos(slider1:GetWidth() - text2:GetWidth(), 5)
|
||||
|
||||
local text3 = loveframes.Create("text", panel)
|
||||
local text4 = loveframes.Create("text", panel)
|
||||
local slider2 = loveframes.Create("slider", panel)
|
||||
slider2:SetPos(5, 60)
|
||||
slider2:SetWidth(480)
|
||||
slider2:SetMinMax(0, 100)
|
||||
slider2:SetValue(5)
|
||||
slider2:SetText("Spacing")
|
||||
slider2:SetDecimals(0)
|
||||
slider2.OnValueChanged = function(object2, value)
|
||||
list:SetSpacing(value)
|
||||
text4:SetPos(slider2:GetWidth() - text4:GetWidth(), 45)
|
||||
text4:SetText(slider2:GetValue())
|
||||
end
|
||||
|
||||
text3:SetPos(5, 45)
|
||||
text3:SetFont(font)
|
||||
text3:SetText(slider2:GetText())
|
||||
|
||||
text4:SetText(slider2:GetValue())
|
||||
text4:SetFont(font)
|
||||
text4:SetPos(slider2:GetWidth() - text4:GetWidth(), 45)
|
||||
|
||||
local button1 = loveframes.Create("button", panel)
|
||||
button1:SetPos(5, 85)
|
||||
button1:SetSize(237, 25)
|
||||
button1:SetText("Change List Type")
|
||||
button1.OnClick = function(object2, x, y)
|
||||
if list:GetDisplayType() == "vertical" then
|
||||
list:SetDisplayType("horizontal")
|
||||
else
|
||||
list:SetDisplayType("vertical")
|
||||
end
|
||||
list:Clear()
|
||||
for i=1, 100 do
|
||||
local button = loveframes.Create("button")
|
||||
button:SetText(i)
|
||||
list:AddItem(button)
|
||||
end
|
||||
end
|
||||
|
||||
local button2 = loveframes.Create("button", panel)
|
||||
button2:SetPos(247, 85)
|
||||
button2:SetSize(237, 25)
|
||||
button2:SetText("Toggle Horizontal Stacking")
|
||||
button2.OnClick = function(object2, x, y)
|
||||
local enabled = list:GetHorizontalStacking()
|
||||
list:EnableHorizontalStacking(not enabled)
|
||||
list:Clear()
|
||||
for i=1, 100 do
|
||||
local button = loveframes.Create("button")
|
||||
button:SetSize(100, 25)
|
||||
button:SetText(i)
|
||||
list:AddItem(button)
|
||||
end
|
||||
end
|
||||
button2.Update = function(object)
|
||||
local displaytype = list:GetDisplayType()
|
||||
if displaytype ~= "vertical" then
|
||||
object:SetEnabled(false)
|
||||
object:SetClickable(false)
|
||||
else
|
||||
object:SetEnabled(true)
|
||||
object:SetClickable(true)
|
||||
end
|
||||
end
|
||||
|
||||
local form = loveframes.Create("form", frame)
|
||||
form:SetPos(5, 335)
|
||||
form.padding = 0
|
||||
form.spacing = 0
|
||||
form:SetName("List Controls")
|
||||
form:AddItem(panel)
|
||||
|
||||
for i=1, 100 do
|
||||
local button = loveframes.Create("button")
|
||||
button:SetText(i)
|
||||
list:AddItem(button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
44
demo/examples/menu.lua
Normal file
@ -0,0 +1,44 @@
|
||||
local example = {}
|
||||
example.title = "Menu"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Menu")
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local text = loveframes.Create("text", frame)
|
||||
text:SetText("Right click this frame to see an \n example of the menu object")
|
||||
text:Center()
|
||||
|
||||
|
||||
local submenu3 = loveframes.Create("menu")
|
||||
submenu3:AddOption("Option 1", false, function() end)
|
||||
submenu3:AddOption("Option 2", false, function() end)
|
||||
|
||||
local submenu2 = loveframes.Create("menu")
|
||||
submenu2:AddOption("Option 1", "resources/food/FishFillet.png", function() end)
|
||||
submenu2:AddOption("Option 2", "resources/food/FishSteak.png", function() end)
|
||||
submenu2:AddOption("Option 3", "resources/food/Shrimp.png", function() end)
|
||||
submenu2:AddOption("Option 4", "resources/food/Sushi.png", function() end)
|
||||
|
||||
local submenu1 = loveframes.Create("menu")
|
||||
submenu1:AddSubMenu("Option 1", "resources/food/Cookie.png", submenu3)
|
||||
submenu1:AddSubMenu("Option 2", "resources/food/Fish.png", submenu2)
|
||||
|
||||
local menu = loveframes.Create("menu")
|
||||
menu:AddOption("Option A", "resources/food/Eggplant.png", function() end)
|
||||
menu:AddOption("Option B", "resources/food/Eggs.png", function() end)
|
||||
menu:AddDivider()
|
||||
menu:AddOption("Option C", "resources/food/Cherry.png", function() end)
|
||||
menu:AddOption("Option D", "resources/food/Honey.png", function() end)
|
||||
menu:AddDivider()
|
||||
menu:AddSubMenu("Option E", false, submenu1)
|
||||
menu:SetVisible(false)
|
||||
|
||||
frame.menu_example = menu
|
||||
|
||||
end
|
||||
|
||||
return example
|
21
demo/examples/multichoice.lua
Normal file
@ -0,0 +1,21 @@
|
||||
local example = {}
|
||||
example.title = "Multichoice"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Multichoice")
|
||||
frame:SetSize(210, 60)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local multichoice = loveframes.Create("multichoice", frame)
|
||||
multichoice:SetPos(5, 30)
|
||||
|
||||
for i=1, 10 do
|
||||
multichoice:AddChoice(i)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
18
demo/examples/numberbox.lua
Normal file
@ -0,0 +1,18 @@
|
||||
local example = {}
|
||||
example.title = "Numberbox"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Numberbox")
|
||||
frame:SetSize(210, 60)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local numberbox = loveframes.Create("numberbox", frame)
|
||||
numberbox:SetPos(5, 30)
|
||||
numberbox:SetSize(200, 25)
|
||||
|
||||
end
|
||||
|
||||
return example
|
17
demo/examples/panel.lua
Normal file
@ -0,0 +1,17 @@
|
||||
local example = {}
|
||||
example.title = "Panel"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Panel")
|
||||
frame:SetSize(210, 85)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local panel = loveframes.Create("panel", frame)
|
||||
panel:SetPos(5, 30)
|
||||
|
||||
end
|
||||
|
||||
return example
|
62
demo/examples/progressbar.lua
Normal file
@ -0,0 +1,62 @@
|
||||
local example = {}
|
||||
example.title = "Progress Bar"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Progress Bar")
|
||||
frame:SetSize(500, 160)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local progressbar = loveframes.Create("progressbar", frame)
|
||||
progressbar:SetPos(5, 30)
|
||||
progressbar:SetWidth(490)
|
||||
progressbar:SetLerpRate(10)
|
||||
|
||||
local button1 = loveframes.Create("button", frame)
|
||||
button1:SetPos(5, 60)
|
||||
button1:SetWidth(490)
|
||||
button1:SetText("Change bar value")
|
||||
button1.OnClick = function(object2, x, y)
|
||||
progressbar:SetValue(math.random(progressbar:GetMin(), progressbar:GetMax()))
|
||||
end
|
||||
|
||||
local button2 = loveframes.Create("button", frame)
|
||||
button2:SetPos(5, 90)
|
||||
button2:SetWidth(490)
|
||||
button2:SetText("Toggle bar lerp")
|
||||
button2.OnClick = function(object2, x, y)
|
||||
if progressbar:GetLerp() == true then
|
||||
progressbar:SetLerp(false)
|
||||
else
|
||||
progressbar:SetLerp(true)
|
||||
end
|
||||
end
|
||||
|
||||
local slider = loveframes.Create("slider", frame)
|
||||
slider:SetPos(5, 135)
|
||||
slider:SetWidth(490)
|
||||
slider:SetText("Progressbar lerp rate")
|
||||
slider:SetMinMax(0, 50)
|
||||
slider:SetDecimals(0)
|
||||
slider:SetValue(10)
|
||||
slider.OnValueChanged = function(object2, value)
|
||||
progressbar:SetLerpRate(value)
|
||||
end
|
||||
|
||||
local text1 = loveframes.Create("text", frame)
|
||||
text1:SetPos(5, 120)
|
||||
text1:SetText("Lerp Rate")
|
||||
text1:SetFont(love.graphics.newFont(10))
|
||||
|
||||
local text2 = loveframes.Create("text", frame)
|
||||
text2:SetFont(love.graphics.newFont(10))
|
||||
text2.Update = function(object, dt)
|
||||
object:SetPos(slider:GetWidth() - object:GetWidth(), 120)
|
||||
object:SetText(slider:GetValue())
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
38
demo/examples/radiobutton.lua
Normal file
@ -0,0 +1,38 @@
|
||||
local example = {}
|
||||
example.title = "Radiobutton"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Radiobutton")
|
||||
frame:SetHeight(150)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local group1 = {}
|
||||
|
||||
local radiobutton1 = loveframes.Create("radiobutton", frame)
|
||||
radiobutton1:SetText("Radiobutton 1 in Group 1")
|
||||
radiobutton1:SetPos(5, 30)
|
||||
radiobutton1:SetGroup(group1)
|
||||
|
||||
local radiobutton2 = loveframes.Create("radiobutton", frame)
|
||||
radiobutton2:SetText("Radiobutton 2 in Group 1")
|
||||
radiobutton2:SetPos(5, 60)
|
||||
radiobutton2:SetGroup(group1)
|
||||
|
||||
local group2 = {}
|
||||
|
||||
local radiobutton3 = loveframes.Create("radiobutton", frame)
|
||||
radiobutton3:SetText("Radiobutton 3 in Group 2")
|
||||
radiobutton3:SetPos(5, 90)
|
||||
radiobutton3:SetGroup(group2)
|
||||
|
||||
local radiobutton4 = loveframes.Create("radiobutton", frame)
|
||||
radiobutton4:SetText("Radiobutton 4 in Group 2")
|
||||
radiobutton4:SetPos(5, 120)
|
||||
radiobutton4:SetGroup(group2)
|
||||
|
||||
end
|
||||
|
||||
return example
|
50
demo/examples/resizeable_layout.lua
Normal file
@ -0,0 +1,50 @@
|
||||
local example = {}
|
||||
example.title = "Resizeable Layout"
|
||||
example.category = "Example Implementations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Resizeable Layout")
|
||||
frame:SetSize(500, 300)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
frame:SetResizable(true)
|
||||
frame:SetMaxWidth(800)
|
||||
frame:SetMaxHeight(600)
|
||||
frame:SetMinWidth(200)
|
||||
frame:SetMinHeight(200)
|
||||
|
||||
local panel1 = loveframes.Create("panel", frame)
|
||||
panel1:SetPos(5, 30)
|
||||
panel1:SetSize(frame:GetWidth()/2 - 2, frame:GetHeight() - 65)
|
||||
panel1.Update = function(object)
|
||||
object:SetSize(frame:GetWidth()/2 - 7, frame:GetHeight() - 65)
|
||||
end
|
||||
|
||||
local panel2 = loveframes.Create("panel", frame)
|
||||
panel2:SetPos(frame:GetWidth()/2 + 2, 30)
|
||||
panel2:SetSize(frame:GetWidth()/2 - 7, frame:GetHeight()/2 - 35)
|
||||
panel2.Update = function(object)
|
||||
object:SetPos(frame:GetWidth()/2 + 2, 30)
|
||||
object:SetSize(frame:GetWidth()/2 - 7, frame:GetHeight()/2 - 35)
|
||||
end
|
||||
|
||||
local panel3 = loveframes.Create("panel", frame)
|
||||
panel3:SetPos(frame:GetWidth()/2 + 2, (panel2.staticy + panel2:GetHeight()) + 5)
|
||||
panel3:SetSize(frame:GetWidth()/2 - 7, frame:GetHeight()/2 - 35)
|
||||
panel3.Update = function(object)
|
||||
object:SetPos(frame:GetWidth()/2 + 2, (panel2.staticy + panel2:GetHeight()) + 5)
|
||||
object:SetSize(frame:GetWidth()/2 - 7, frame:GetHeight()/2 - 35)
|
||||
end
|
||||
|
||||
local panel4 = loveframes.Create("panel", frame)
|
||||
panel4:SetPos(5, frame:GetHeight() - 30)
|
||||
panel4:SetSize(frame:GetWidth(), 25)
|
||||
panel4.Update = function(object)
|
||||
object:SetY(frame:GetHeight() - 30)
|
||||
object:SetWidth(frame:GetWidth() - 10)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
29
demo/examples/slider.lua
Normal file
@ -0,0 +1,29 @@
|
||||
local example = {}
|
||||
example.title = "Slider"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Slider")
|
||||
frame:SetSize(300, 275)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local slider1 = loveframes.Create("slider", frame)
|
||||
slider1:SetPos(5, 30)
|
||||
slider1:SetWidth(290)
|
||||
slider1:SetMinMax(0, 100)
|
||||
|
||||
local slider2 = loveframes.Create("slider", frame)
|
||||
slider2:SetPos(5, 60)
|
||||
slider2:SetHeight(200)
|
||||
slider2:SetMinMax(0, 100)
|
||||
slider2:SetButtonSize(20, 10)
|
||||
slider2:SetSlideType("vertical")
|
||||
slider2.Update = function(object, dt)
|
||||
object:CenterX()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
38
demo/examples/tabs.lua
Normal file
@ -0,0 +1,38 @@
|
||||
local example = {}
|
||||
example.title = "Tabs"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Tabs")
|
||||
frame:SetSize(500, 300)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local tabs = loveframes.Create("tabs", frame)
|
||||
tabs:SetPos(5, 30)
|
||||
tabs:SetSize(490, 265)
|
||||
|
||||
local imagelist = loveframes.GetDirectoryContents("resources/food/")
|
||||
local images = {}
|
||||
for i, v in ipairs(imagelist) do
|
||||
if v.extension == "png" then table.insert(images, v.fullpath) end
|
||||
end
|
||||
|
||||
for i=1, 20 do
|
||||
local image = images[math.random(1, #images)]
|
||||
local panel = loveframes.Create("panel")
|
||||
panel.Draw = function()
|
||||
end
|
||||
local text = loveframes.Create("text", panel)
|
||||
text:SetText("Tab " ..i)
|
||||
text:SetAlwaysUpdate(true)
|
||||
text.Update = function(object, dt)
|
||||
object:Center()
|
||||
end
|
||||
tabs:AddTab("Tab " ..i, panel, "Tab " ..i, image)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
79
demo/examples/text.lua
Normal file
@ -0,0 +1,79 @@
|
||||
local example = {}
|
||||
example.title = "Text"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
local loremipsum =
|
||||
[[http://nikolairesokav.com/
|
||||
---------------------------------------------------
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean laoreet massa mattis tortor faucibus non congue mauris mattis. Aliquam ultricies scelerisque mi, sit amet tempor metus pharetra vel. Etiam eu arcu a dolor porttitor condimentum in malesuada urna. Mauris vel nulla mi, quis aliquet neque. In aliquet turpis eget purus malesuada tincidunt. Donec rutrum purus vel diam suscipit vehicula. Cras sem nibh, tempus at dictum non, consequat non justo. In sed tellus nec orci scelerisque scelerisque id vitae leo. Maecenas pharetra, nibh eget commodo gravida, augue nisl blandit dui, ut malesuada augue dui nec erat. Phasellus nec mauris pharetra metus iaculis viverra sit amet ut tortor. Duis et viverra magna. Nunc orci dolor, placerat a iaculis non, mattis sed nibh.
|
||||
|
||||
Mauris ac erat sit amet ante condimentum scelerisque. Cras eleifend lorem dictum mi euismod non placerat lorem gravida. Vestibulum sodales dapibus eros, non iaculis risus commodo eu. Maecenas dapibus purus accumsan metus euismod suscipit. Etiam eleifend lorem eget quam ornare interdum sed at nulla. Suspendisse viverra sapien ut felis viverra pellentesque. Ut convallis hendrerit est, in imperdiet purus placerat ut. Curabitur sapien nibh, molestie et elementum a, sagittis et tortor. Vestibulum sed quam eu velit euismod rutrum vitae et sem. Morbi accumsan quam vitae sapien scelerisque tincidunt. Nulla ipsum leo, scelerisque at consequat sit amet, venenatis eget mauris. Aliquam at nibh vel lorem hendrerit dignissim. Cras et risus sit amet est vehicula auctor at a leo. Curabitur euismod mi sit amet nunc consequat sed fringilla justo sagittis.
|
||||
|
||||
Nulla ut arcu felis, a laoreet tellus. Vivamus ligula nibh, bibendum ut ultrices sed, ullamcorper et est. Pellentesque nisi diam, sollicitudin lacinia fermentum quis, aliquam fermentum elit. Donec egestas vestibulum mollis. Vivamus sollicitudin nisl vestibulum nisi fermentum scelerisque. Nunc enim magna, posuere ornare faucibus a, bibendum vestibulum felis. Etiam laoreet molestie elit, vitae ultrices sem faucibus in. Fusce rutrum convallis lacus, vitae scelerisque eros tincidunt sed. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
|
||||
|
||||
Quisque ornare arcu sed enim sodales dictum. Suspendisse at convallis mi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas et nibh odio, eu lacinia lacus. Mauris at pulvinar urna. Pellentesque vel justo erat, a congue nibh. Nunc tristique mattis euismod. Suspendisse potenti.
|
||||
|
||||
Sed dictum faucibus cursus. Integer nisi ipsum, dapibus vel blandit laoreet, bibendum congue massa. Vestibulum tincidunt vulputate nunc, facilisis consequat lacus posuere at. Aenean sed mollis urna. Vivamus congue neque non arcu malesuada lobortis. Curabitur suscipit pretium massa eu rutrum. Nulla vehicula imperdiet dui in blandit. Curabitur vitae felis ut massa scelerisque consequat. Nulla a magna quis risus consequat hendrerit. Maecenas quis lacus sit amet ipsum condimentum interdum. Proin condimentum erat id enim elementum ut tincidunt neque vulputate.
|
||||
]]
|
||||
|
||||
local fonts = {}
|
||||
for i=10, 30 do
|
||||
fonts[i] = love.graphics.newFont(i)
|
||||
end
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Text")
|
||||
frame:SetSize(500, 330)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local list1 = loveframes.Create("list", frame)
|
||||
list1:SetPos(5, 30)
|
||||
list1:SetSize(243, 265)
|
||||
list1:SetPadding(5)
|
||||
list1:SetSpacing(5)
|
||||
|
||||
local text1 = loveframes.Create("text")
|
||||
text1:SetLinksEnabled(true)
|
||||
text1:SetDetectLinks(true)
|
||||
text1:SetText(loremipsum)
|
||||
text1:SetShadowColor(.8, .8, .8, 1)
|
||||
list1:AddItem(text1)
|
||||
|
||||
local colortext = {}
|
||||
for i=1, 150 do
|
||||
local r = math.random(0, 255) / 255
|
||||
local g = math.random(0, 255) / 255
|
||||
local b = math.random(0, 255) / 255
|
||||
table.insert(colortext, {color = {r, g, b, 1}, font = fonts[math.random(1, 30)]})
|
||||
table.insert(colortext, math.random(1, 1000) .. " ")
|
||||
end
|
||||
|
||||
local list2 = loveframes.Create("list", frame)
|
||||
list2:SetPos(252, 30)
|
||||
list2:SetSize(243, 265)
|
||||
list2:SetPadding(5)
|
||||
list2:SetSpacing(5)
|
||||
|
||||
local text2 = loveframes.Create("text", frame)
|
||||
text2:SetPos(255, 30)
|
||||
text2:SetLinksEnabled(true)
|
||||
text2:SetText(colortext)
|
||||
text2.OnClickLink = function(object, text)
|
||||
print(text)
|
||||
end
|
||||
list2:AddItem(text2)
|
||||
|
||||
local shadowbutton = loveframes.Create("button", frame)
|
||||
shadowbutton:SetSize(490, 25)
|
||||
shadowbutton:SetPos(5, 300)
|
||||
shadowbutton:SetText("Toggle Text Shadow")
|
||||
shadowbutton.OnClick = function()
|
||||
text1:SetShadow(not text1:GetShadow())
|
||||
text2:SetShadow(not text2:GetShadow())
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
48
demo/examples/textinput.lua
Normal file
@ -0,0 +1,48 @@
|
||||
local example = {}
|
||||
example.title = "Textinput"
|
||||
example.category = "Object Demonstrations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("Text Input")
|
||||
frame:SetSize(500, 90)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local textinput = loveframes.Create("textinput", frame)
|
||||
textinput:SetPos(5, 30)
|
||||
textinput:SetWidth(490)
|
||||
textinput.OnEnter = function(object)
|
||||
if not textinput.multiline then
|
||||
object:Clear()
|
||||
end
|
||||
end
|
||||
textinput:SetFont(love.graphics.newFont(12))
|
||||
|
||||
local togglebutton = loveframes.Create("button", frame)
|
||||
togglebutton:SetPos(5, 60)
|
||||
togglebutton:SetWidth(490)
|
||||
togglebutton:SetText("Toggle Multiline")
|
||||
togglebutton.OnClick = function(object)
|
||||
if textinput.multiline then
|
||||
frame:SetHeight(90)
|
||||
frame:Center()
|
||||
togglebutton:SetPos(5, 60)
|
||||
textinput:SetMultiline(false)
|
||||
textinput:SetHeight(25)
|
||||
textinput:SetText("")
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
else
|
||||
frame:SetHeight(365)
|
||||
frame:Center()
|
||||
togglebutton:SetPos(5, 335)
|
||||
textinput:SetMultiline(true)
|
||||
textinput:SetHeight(300)
|
||||
textinput:SetText("")
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
75
demo/examples/user_input_form.lua
Normal file
@ -0,0 +1,75 @@
|
||||
local example = {}
|
||||
example.title = "User Input Form"
|
||||
example.category = "Example Implementations"
|
||||
|
||||
function example.func(loveframes, centerarea)
|
||||
|
||||
local frame = loveframes.Create("frame")
|
||||
frame:SetName("User Input Form")
|
||||
frame:SetSize(500, 180)
|
||||
frame:CenterWithinArea(unpack(centerarea))
|
||||
|
||||
local text1 = loveframes.Create("text", frame)
|
||||
text1:SetPos(5, 35)
|
||||
text1:SetText("Username")
|
||||
|
||||
local textinput1 = loveframes.Create("textinput", frame)
|
||||
textinput1:SetPos(125, 30)
|
||||
textinput1:SetWidth(370)
|
||||
|
||||
local text2 = loveframes.Create("text", frame)
|
||||
text2:SetPos(5, 65)
|
||||
text2:SetText("E-mail")
|
||||
|
||||
local textinput2 = loveframes.Create("textinput", frame)
|
||||
textinput2:SetPos(125, 60)
|
||||
textinput2:SetWidth(370)
|
||||
|
||||
local text3 = loveframes.Create("text", frame)
|
||||
text3:SetPos(5, 95)
|
||||
text3:SetText("Password")
|
||||
|
||||
local textinput3 = loveframes.Create("textinput", frame)
|
||||
textinput3:SetPos(125, 90)
|
||||
textinput3:SetWidth(370)
|
||||
|
||||
local text4 = loveframes.Create("text", frame)
|
||||
text4:SetPos(5, 125)
|
||||
text4:SetText("Confirm Password")
|
||||
|
||||
local textinput4 = loveframes.Create("textinput", frame)
|
||||
textinput4:SetPos(125, 120)
|
||||
textinput4:SetWidth(370)
|
||||
|
||||
local donebutton = loveframes.Create("button", frame)
|
||||
donebutton:SetPos(5, 150)
|
||||
donebutton:SetWidth(243)
|
||||
donebutton:SetText("Done")
|
||||
donebutton.OnClick = function()
|
||||
local restultframe = loveframes.Create("frame")
|
||||
restultframe:SetSize(300, 100)
|
||||
restultframe:Center()
|
||||
restultframe:SetName("Input Form Values")
|
||||
local text = loveframes.Create("text", restultframe)
|
||||
text:SetPos(5, 30)
|
||||
text:SetText({"Username: " ..textinput1:GetValue(), " \n E-mail: " ..textinput2:GetValue(), " \n Password: " ..textinput3:GetValue(), " \n Confirm Password: " ..textinput4:GetValue()})
|
||||
text:SetMaxWidth(290)
|
||||
restultframe:SetHeight(35 + text:GetHeight())
|
||||
restultframe:SetModal(true)
|
||||
restultframe:CenterWithinArea(unpack(centerarea))
|
||||
end
|
||||
|
||||
local clearbutton = loveframes.Create("button", frame)
|
||||
clearbutton:SetPos(252, 150)
|
||||
clearbutton:SetWidth(243)
|
||||
clearbutton:SetText("Clear Form")
|
||||
clearbutton.OnClick = function()
|
||||
textinput1:Clear()
|
||||
textinput2:Clear()
|
||||
textinput3:Clear()
|
||||
textinput4:Clear()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return example
|
1
demo/loveframes/readme
Normal file
@ -0,0 +1 @@
|
||||
Placeholder for LoveFrames library (https://github.com/linux-man/LoveFrames)
|
210
demo/main.lua
Normal file
@ -0,0 +1,210 @@
|
||||
|
||||
local loveframes
|
||||
local tween
|
||||
local demo = {}
|
||||
|
||||
function demo.CreateToolbar()
|
||||
local width = love.graphics.getWidth()
|
||||
local version = loveframes.version
|
||||
local stage = loveframes.stage
|
||||
|
||||
local toolbar = loveframes.Create("panel")
|
||||
toolbar:SetSize(width, 35)
|
||||
toolbar:SetPos(0, 0)
|
||||
|
||||
local info = loveframes.Create("text", toolbar)
|
||||
info:SetPos(5, 3)
|
||||
info:SetText({
|
||||
{color = {0, 0, 0, 1}},
|
||||
"Love Frames (",
|
||||
{color = {.5, .25, 1, 1}}, "version " ..version.. " - " ..stage,
|
||||
{color = {0, 0, 0, 1}}, ")\n",
|
||||
{color = {1, .4, 0, 1}}, "F1",
|
||||
{color = {0, 0, 0, 1}}, ": Toggle debug mode - ",
|
||||
{color = {1, .4, 0, 1}}, "F2",
|
||||
{color = {0, 0, 0, 1}}, ": Remove all objects"
|
||||
})
|
||||
|
||||
demo.examplesbutton = loveframes.Create("button", toolbar)
|
||||
demo.examplesbutton:SetPos(toolbar:GetWidth() - 105, 5)
|
||||
demo.examplesbutton:SetSize(100, 25)
|
||||
demo.examplesbutton:SetText("Hide Examples")
|
||||
demo.examplesbutton.OnClick = function()
|
||||
demo.ToggleExamplesList()
|
||||
end
|
||||
|
||||
local skinslist = loveframes.Create("multichoice", toolbar)
|
||||
skinslist:SetPos(toolbar:GetWidth() - 250, 5)
|
||||
skinslist:SetWidth(140)
|
||||
skinslist:SetChoice("Choose a skin")
|
||||
skinslist.OnChoiceSelected = function(object, choice)
|
||||
loveframes.SetActiveSkin(choice)
|
||||
end
|
||||
|
||||
local skins = loveframes.skins
|
||||
for k, v in pairs(skins) do
|
||||
skinslist:AddChoice(v.name)
|
||||
end
|
||||
skinslist:Sort()
|
||||
end
|
||||
|
||||
function demo.RegisterExample(example)
|
||||
local examples = demo.examples
|
||||
local category = example.category
|
||||
|
||||
for k, v in ipairs(examples) do
|
||||
if v.category_title == category then
|
||||
table.insert(examples[k].registered, example)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function demo.CreateExamplesList()
|
||||
local examples = demo.examples
|
||||
local width = love.graphics.getWidth()
|
||||
local height = love.graphics.getHeight()
|
||||
|
||||
demo.exampleslist = loveframes.Create("list")
|
||||
demo.exampleslist:SetPos(width - 250, 35)
|
||||
demo.exampleslist:SetSize(250, height - 35)
|
||||
demo.exampleslist:SetPadding(5)
|
||||
demo.exampleslist:SetSpacing(5)
|
||||
demo.exampleslist.toggled = true
|
||||
|
||||
demo.tween_open = tween.new(1, demo.exampleslist, {x = (width - 250)}, "outBounce")
|
||||
demo.tween_close = tween.new(1, demo.exampleslist, {x = (width - 5)}, "outBounce")
|
||||
|
||||
for k, v in ipairs(examples) do
|
||||
local panelheight = 0
|
||||
local category = loveframes.Create("collapsiblecategory")
|
||||
category:SetText(v.category_title)
|
||||
local panel = loveframes.Create("panel")
|
||||
panel.Draw = function() end
|
||||
demo.exampleslist:AddItem(category)
|
||||
for key, value in ipairs(v.registered) do
|
||||
local button = loveframes.Create("button", panel)
|
||||
button:SetWidth(210)
|
||||
button:SetPos(0, panelheight)
|
||||
button:SetText(value.title)
|
||||
button.OnClick = function()
|
||||
value.func(loveframes, demo.centerarea)
|
||||
demo.current = value
|
||||
end
|
||||
panelheight = panelheight + 30
|
||||
end
|
||||
panel:SetHeight(panelheight)
|
||||
category:SetObject(panel)
|
||||
category:SetOpen(true)
|
||||
end
|
||||
end
|
||||
|
||||
function demo.ToggleExamplesList()
|
||||
|
||||
local toggled = demo.exampleslist.toggled
|
||||
|
||||
if not toggled then
|
||||
demo.exampleslist.toggled = true
|
||||
demo.tween = demo.tween_open
|
||||
demo.examplesbutton:SetText("Hide Examples")
|
||||
else
|
||||
demo.exampleslist.toggled = false
|
||||
demo.tween = demo.tween_close
|
||||
demo.examplesbutton:SetText("Show Examples")
|
||||
end
|
||||
|
||||
demo.tween:reset()
|
||||
end
|
||||
|
||||
|
||||
function love.load()
|
||||
local font = love.graphics.newFont(12)
|
||||
love.graphics.setFont(font)
|
||||
|
||||
loveframes = require("loveframes")
|
||||
tween = require("tween")
|
||||
|
||||
-- table to store available examples
|
||||
demo.examples = {}
|
||||
demo.examples[1] = {category_title = "Object Demonstrations", registered = {}}
|
||||
demo.examples[2] = {category_title = "Example Implementations", registered = {}}
|
||||
|
||||
demo.exampleslist = nil
|
||||
demo.examplesbutton = nil
|
||||
demo.tween = nil
|
||||
demo.centerarea = {5, 40, 540, 555}
|
||||
|
||||
local files = loveframes.GetDirectoryContents("examples")
|
||||
local example
|
||||
for k, v in ipairs(files) do
|
||||
if v.extension == "lua" then
|
||||
example = require(v.requirepath)
|
||||
demo.RegisterExample(example)
|
||||
end
|
||||
end
|
||||
|
||||
local image = love.graphics.newImage("resources/background.png")
|
||||
image:setWrap("repeat", "repeat")
|
||||
local width = love.graphics.getWidth()
|
||||
local height = love.graphics.getHeight()
|
||||
demo.bgquad = love.graphics.newQuad(0, 0, width, height, image:getWidth(), image:getHeight())
|
||||
demo.bgimage = image
|
||||
|
||||
-- create demo gui
|
||||
demo.CreateToolbar()
|
||||
demo.CreateExamplesList()
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
|
||||
loveframes.update(dt)
|
||||
if demo.tween then
|
||||
if demo.tween:update(dt) then demo.tween = nil end
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.draw(demo.bgimage, demo.bgquad, 0, 0)
|
||||
loveframes.draw()
|
||||
|
||||
end
|
||||
|
||||
function love.mousepressed(x, y, button)
|
||||
loveframes.mousepressed(x, y, button)
|
||||
local menu = loveframes.hoverobject and loveframes.hoverobject.menu_example
|
||||
if menu and button == 2 then
|
||||
menu:SetPos(x, y)
|
||||
menu:SetVisible(true)
|
||||
menu:MoveToTop()
|
||||
end
|
||||
end
|
||||
|
||||
function love.mousereleased(x, y, button)
|
||||
loveframes.mousereleased(x, y, button)
|
||||
end
|
||||
|
||||
function love.wheelmoved(x, y)
|
||||
loveframes.wheelmoved(x, y)
|
||||
end
|
||||
|
||||
function love.keypressed(key, isrepeat)
|
||||
loveframes.keypressed(key, isrepeat)
|
||||
|
||||
if key == "f1" then
|
||||
local debug = loveframes.config["DEBUG"]
|
||||
loveframes.config["DEBUG"] = not debug
|
||||
elseif key == "f2" then
|
||||
loveframes.RemoveAll()
|
||||
demo.CreateToolbar()
|
||||
demo.CreateExamplesList()
|
||||
--demo.ToggleExamplesList()
|
||||
end
|
||||
end
|
||||
|
||||
function love.keyreleased(key)
|
||||
loveframes.keyreleased(key)
|
||||
end
|
||||
|
||||
function love.textinput(text)
|
||||
loveframes.textinput(text)
|
||||
end
|
BIN
demo/resources/background.png
Normal file
After Width: | Height: | Size: 386 B |
BIN
demo/resources/file.png
Normal file
After Width: | Height: | Size: 565 B |
BIN
demo/resources/folder.png
Normal file
After Width: | Height: | Size: 492 B |
BIN
demo/resources/food/Apple.png
Normal file
After Width: | Height: | Size: 450 B |
BIN
demo/resources/food/AppleWorm.png
Normal file
After Width: | Height: | Size: 458 B |
BIN
demo/resources/food/Avocado.png
Normal file
After Width: | Height: | Size: 439 B |
BIN
demo/resources/food/Bacon.png
Normal file
After Width: | Height: | Size: 468 B |
BIN
demo/resources/food/Beer.png
Normal file
After Width: | Height: | Size: 528 B |
BIN
demo/resources/food/Boar.png
Normal file
After Width: | Height: | Size: 509 B |
BIN
demo/resources/food/Bread.png
Normal file
After Width: | Height: | Size: 474 B |
BIN
demo/resources/food/Brownie.png
Normal file
After Width: | Height: | Size: 443 B |
BIN
demo/resources/food/Bug.png
Normal file
After Width: | Height: | Size: 462 B |
BIN
demo/resources/food/Cheese.png
Normal file
After Width: | Height: | Size: 449 B |
BIN
demo/resources/food/Cherry.png
Normal file
After Width: | Height: | Size: 443 B |
BIN
demo/resources/food/Chicken.png
Normal file
After Width: | Height: | Size: 490 B |
BIN
demo/resources/food/ChickenLeg.png
Normal file
After Width: | Height: | Size: 450 B |
BIN
demo/resources/food/Cookie.png
Normal file
After Width: | Height: | Size: 433 B |
BIN
demo/resources/food/DragonFruit.png
Normal file
After Width: | Height: | Size: 459 B |
BIN
demo/resources/food/Eggplant.png
Normal file
After Width: | Height: | Size: 413 B |
BIN
demo/resources/food/Eggs.png
Normal file
After Width: | Height: | Size: 455 B |
BIN
demo/resources/food/Fish.png
Normal file
After Width: | Height: | Size: 410 B |
BIN
demo/resources/food/FishFillet.png
Normal file
After Width: | Height: | Size: 466 B |
BIN
demo/resources/food/FishSteak.png
Normal file
After Width: | Height: | Size: 401 B |
BIN
demo/resources/food/Grub.png
Normal file
After Width: | Height: | Size: 425 B |
BIN
demo/resources/food/Grubs.png
Normal file
After Width: | Height: | Size: 399 B |
BIN
demo/resources/food/Honey.png
Normal file
After Width: | Height: | Size: 452 B |
BIN
demo/resources/food/Honeycomb.png
Normal file
After Width: | Height: | Size: 427 B |
BIN
demo/resources/food/Jam.png
Normal file
After Width: | Height: | Size: 456 B |
BIN
demo/resources/food/Jerky.png
Normal file
After Width: | Height: | Size: 440 B |
BIN
demo/resources/food/Lemon.png
Normal file
After Width: | Height: | Size: 450 B |
BIN
demo/resources/food/Marmalade.png
Normal file
After Width: | Height: | Size: 459 B |
BIN
demo/resources/food/MelonCantaloupe.png
Normal file
After Width: | Height: | Size: 430 B |
BIN
demo/resources/food/MelonHoneydew.png
Normal file
After Width: | Height: | Size: 430 B |
BIN
demo/resources/food/MelonWater.png
Normal file
After Width: | Height: | Size: 492 B |
BIN
demo/resources/food/Moonshine.png
Normal file
After Width: | Height: | Size: 453 B |
BIN
demo/resources/food/Olive.png
Normal file
After Width: | Height: | Size: 440 B |
BIN
demo/resources/food/Onion.png
Normal file
After Width: | Height: | Size: 477 B |
BIN
demo/resources/food/Peach.png
Normal file
After Width: | Height: | Size: 460 B |
BIN
demo/resources/food/PepperGreen.png
Normal file
After Width: | Height: | Size: 432 B |
BIN
demo/resources/food/PepperRed.png
Normal file
After Width: | Height: | Size: 422 B |
BIN
demo/resources/food/Pepperoni.png
Normal file
After Width: | Height: | Size: 507 B |
BIN
demo/resources/food/Pickle.png
Normal file
After Width: | Height: | Size: 428 B |
BIN
demo/resources/food/PickledEggs.png
Normal file
After Width: | Height: | Size: 493 B |
BIN
demo/resources/food/PieApple.png
Normal file
After Width: | Height: | Size: 414 B |
BIN
demo/resources/food/PieLemon.png
Normal file
After Width: | Height: | Size: 437 B |
BIN
demo/resources/food/PiePumpkin.png
Normal file
After Width: | Height: | Size: 441 B |
BIN
demo/resources/food/Pineapple.png
Normal file
After Width: | Height: | Size: 482 B |
BIN
demo/resources/food/Potato.png
Normal file
After Width: | Height: | Size: 409 B |
BIN
demo/resources/food/PotatoRed.png
Normal file
After Width: | Height: | Size: 411 B |
BIN
demo/resources/food/Pretzel.png
Normal file
After Width: | Height: | Size: 457 B |
BIN
demo/resources/food/Ribs.png
Normal file
After Width: | Height: | Size: 443 B |
BIN
demo/resources/food/Roll.png
Normal file
After Width: | Height: | Size: 637 B |
BIN
demo/resources/food/Saki.png
Normal file
After Width: | Height: | Size: 431 B |
BIN
demo/resources/food/Sardines.png
Normal file
After Width: | Height: | Size: 510 B |
BIN
demo/resources/food/Sashimi.png
Normal file
After Width: | Height: | Size: 430 B |
BIN
demo/resources/food/Sausages.png
Normal file
After Width: | Height: | Size: 452 B |
BIN
demo/resources/food/Shrimp.png
Normal file
After Width: | Height: | Size: 457 B |
BIN
demo/resources/food/Steak.png
Normal file
After Width: | Height: | Size: 504 B |
BIN
demo/resources/food/Stein.png
Normal file
After Width: | Height: | Size: 427 B |
BIN
demo/resources/food/Strawberry.png
Normal file
After Width: | Height: | Size: 464 B |
BIN
demo/resources/food/Sushi.png
Normal file
After Width: | Height: | Size: 438 B |
BIN
demo/resources/food/Tart.png
Normal file
After Width: | Height: | Size: 446 B |
BIN
demo/resources/food/Tomato.png
Normal file
After Width: | Height: | Size: 444 B |
BIN
demo/resources/food/Turnip.png
Normal file
After Width: | Height: | Size: 456 B |
BIN
demo/resources/food/Waffles.png
Normal file
After Width: | Height: | Size: 521 B |
BIN
demo/resources/food/Whiskey.png
Normal file
After Width: | Height: | Size: 435 B |
BIN
demo/resources/food/Wine.png
Normal file
After Width: | Height: | Size: 421 B |
BIN
demo/resources/magic.png
Normal file
After Width: | Height: | Size: 10 KiB |
14
demo/resources/readme.txt
Normal file
@ -0,0 +1,14 @@
|
||||
food/*.png
|
||||
page: https://henrysoftware.itch.io/pixel-food
|
||||
license: https://itch.io/game-assets/assets-cc0
|
||||
-----------------------------------------------
|
||||
|
||||
background.png
|
||||
page: -
|
||||
license: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-----------------------------------------------
|
||||
|
||||
magic.png
|
||||
page: https://opengameart.org/content/wizard-0
|
||||
license: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-----------------------------------------------
|
367
demo/tween.lua
Normal file
@ -0,0 +1,367 @@
|
||||
local tween = {
|
||||
_VERSION = 'tween 2.1.1',
|
||||
_DESCRIPTION = 'tweening for lua',
|
||||
_URL = 'https://github.com/kikito/tween.lua',
|
||||
_LICENSE = [[
|
||||
MIT LICENSE
|
||||
|
||||
Copyright (c) 2014 Enrique García Cota, Yuichi Tateno, Emmanuel Oga
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
]]
|
||||
}
|
||||
|
||||
-- easing
|
||||
|
||||
-- Adapted from https://github.com/EmmanuelOga/easing. See LICENSE.txt for credits.
|
||||
-- For all easing functions:
|
||||
-- t = time == how much time has to pass for the tweening to complete
|
||||
-- b = begin == starting property value
|
||||
-- c = change == ending - beginning
|
||||
-- d = duration == running time. How much time has passed *right now*
|
||||
|
||||
local pow, sin, cos, pi, sqrt, abs, asin = math.pow, math.sin, math.cos, math.pi, math.sqrt, math.abs, math.asin
|
||||
|
||||
-- linear
|
||||
local function linear(t, b, c, d) return c * t / d + b end
|
||||
|
||||
-- quad
|
||||
local function inQuad(t, b, c, d) return c * pow(t / d, 2) + b end
|
||||
local function outQuad(t, b, c, d)
|
||||
t = t / d
|
||||
return -c * t * (t - 2) + b
|
||||
end
|
||||
local function inOutQuad(t, b, c, d)
|
||||
t = t / d * 2
|
||||
if t < 1 then return c / 2 * pow(t, 2) + b end
|
||||
return -c / 2 * ((t - 1) * (t - 3) - 1) + b
|
||||
end
|
||||
local function outInQuad(t, b, c, d)
|
||||
if t < d / 2 then return outQuad(t * 2, b, c / 2, d) end
|
||||
return inQuad((t * 2) - d, b + c / 2, c / 2, d)
|
||||
end
|
||||
|
||||
-- cubic
|
||||
local function inCubic (t, b, c, d) return c * pow(t / d, 3) + b end
|
||||
local function outCubic(t, b, c, d) return c * (pow(t / d - 1, 3) + 1) + b end
|
||||
local function inOutCubic(t, b, c, d)
|
||||
t = t / d * 2
|
||||
if t < 1 then return c / 2 * t * t * t + b end
|
||||
t = t - 2
|
||||
return c / 2 * (t * t * t + 2) + b
|
||||
end
|
||||
local function outInCubic(t, b, c, d)
|
||||
if t < d / 2 then return outCubic(t * 2, b, c / 2, d) end
|
||||
return inCubic((t * 2) - d, b + c / 2, c / 2, d)
|
||||
end
|
||||
|
||||
-- quart
|
||||
local function inQuart(t, b, c, d) return c * pow(t / d, 4) + b end
|
||||
local function outQuart(t, b, c, d) return -c * (pow(t / d - 1, 4) - 1) + b end
|
||||
local function inOutQuart(t, b, c, d)
|
||||
t = t / d * 2
|
||||
if t < 1 then return c / 2 * pow(t, 4) + b end
|
||||
return -c / 2 * (pow(t - 2, 4) - 2) + b
|
||||
end
|
||||
local function outInQuart(t, b, c, d)
|
||||
if t < d / 2 then return outQuart(t * 2, b, c / 2, d) end
|
||||
return inQuart((t * 2) - d, b + c / 2, c / 2, d)
|
||||
end
|
||||
|
||||
-- quint
|
||||
local function inQuint(t, b, c, d) return c * pow(t / d, 5) + b end
|
||||
local function outQuint(t, b, c, d) return c * (pow(t / d - 1, 5) + 1) + b end
|
||||
local function inOutQuint(t, b, c, d)
|
||||
t = t / d * 2
|
||||
if t < 1 then return c / 2 * pow(t, 5) + b end
|
||||
return c / 2 * (pow(t - 2, 5) + 2) + b
|
||||
end
|
||||
local function outInQuint(t, b, c, d)
|
||||
if t < d / 2 then return outQuint(t * 2, b, c / 2, d) end
|
||||
return inQuint((t * 2) - d, b + c / 2, c / 2, d)
|
||||
end
|
||||
|
||||
-- sine
|
||||
local function inSine(t, b, c, d) return -c * cos(t / d * (pi / 2)) + c + b end
|
||||
local function outSine(t, b, c, d) return c * sin(t / d * (pi / 2)) + b end
|
||||
local function inOutSine(t, b, c, d) return -c / 2 * (cos(pi * t / d) - 1) + b end
|
||||
local function outInSine(t, b, c, d)
|
||||
if t < d / 2 then return outSine(t * 2, b, c / 2, d) end
|
||||
return inSine((t * 2) -d, b + c / 2, c / 2, d)
|
||||
end
|
||||
|
||||
-- expo
|
||||
local function inExpo(t, b, c, d)
|
||||
if t == 0 then return b end
|
||||
return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001
|
||||
end
|
||||
local function outExpo(t, b, c, d)
|
||||
if t == d then return b + c end
|
||||
return c * 1.001 * (-pow(2, -10 * t / d) + 1) + b
|
||||
end
|
||||
local function inOutExpo(t, b, c, d)
|
||||
if t == 0 then return b end
|
||||
if t == d then return b + c end
|
||||
t = t / d * 2
|
||||
if t < 1 then return c / 2 * pow(2, 10 * (t - 1)) + b - c * 0.0005 end
|
||||
return c / 2 * 1.0005 * (-pow(2, -10 * (t - 1)) + 2) + b
|
||||
end
|
||||
local function outInExpo(t, b, c, d)
|
||||
if t < d / 2 then return outExpo(t * 2, b, c / 2, d) end
|
||||
return inExpo((t * 2) - d, b + c / 2, c / 2, d)
|
||||
end
|
||||
|
||||
-- circ
|
||||
local function inCirc(t, b, c, d) return(-c * (sqrt(1 - pow(t / d, 2)) - 1) + b) end
|
||||
local function outCirc(t, b, c, d) return(c * sqrt(1 - pow(t / d - 1, 2)) + b) end
|
||||
local function inOutCirc(t, b, c, d)
|
||||
t = t / d * 2
|
||||
if t < 1 then return -c / 2 * (sqrt(1 - t * t) - 1) + b end
|
||||
t = t - 2
|
||||
return c / 2 * (sqrt(1 - t * t) + 1) + b
|
||||
end
|
||||
local function outInCirc(t, b, c, d)
|
||||
if t < d / 2 then return outCirc(t * 2, b, c / 2, d) end
|
||||
return inCirc((t * 2) - d, b + c / 2, c / 2, d)
|
||||
end
|
||||
|
||||
-- elastic
|
||||
local function calculatePAS(p,a,c,d)
|
||||
p, a = p or d * 0.3, a or 0
|
||||
if a < abs(c) then return p, c, p / 4 end -- p, a, s
|
||||
return p, a, p / (2 * pi) * asin(c/a) -- p,a,s
|
||||
end
|
||||
local function inElastic(t, b, c, d, a, p)
|
||||
local s
|
||||
if t == 0 then return b end
|
||||
t = t / d
|
||||
if t == 1 then return b + c end
|
||||
p,a,s = calculatePAS(p,a,c,d)
|
||||
t = t - 1
|
||||
return -(a * pow(2, 10 * t) * sin((t * d - s) * (2 * pi) / p)) + b
|
||||
end
|
||||
local function outElastic(t, b, c, d, a, p)
|
||||
local s
|
||||
if t == 0 then return b end
|
||||
t = t / d
|
||||
if t == 1 then return b + c end
|
||||
p,a,s = calculatePAS(p,a,c,d)
|
||||
return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b
|
||||
end
|
||||
local function inOutElastic(t, b, c, d, a, p)
|
||||
local s
|
||||
if t == 0 then return b end
|
||||
t = t / d * 2
|
||||
if t == 2 then return b + c end
|
||||
p,a,s = calculatePAS(p,a,c,d)
|
||||
t = t - 1
|
||||
if t < 0 then return -0.5 * (a * pow(2, 10 * t) * sin((t * d - s) * (2 * pi) / p)) + b end
|
||||
return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p ) * 0.5 + c + b
|
||||
end
|
||||
local function outInElastic(t, b, c, d, a, p)
|
||||
if t < d / 2 then return outElastic(t * 2, b, c / 2, d, a, p) end
|
||||
return inElastic((t * 2) - d, b + c / 2, c / 2, d, a, p)
|
||||
end
|
||||
|
||||
-- back
|
||||
local function inBack(t, b, c, d, s)
|
||||
s = s or 1.70158
|
||||
t = t / d
|
||||
return c * t * t * ((s + 1) * t - s) + b
|
||||
end
|
||||
local function outBack(t, b, c, d, s)
|
||||
s = s or 1.70158
|
||||
t = t / d - 1
|
||||
return c * (t * t * ((s + 1) * t + s) + 1) + b
|
||||
end
|
||||
local function inOutBack(t, b, c, d, s)
|
||||
s = (s or 1.70158) * 1.525
|
||||
t = t / d * 2
|
||||
if t < 1 then return c / 2 * (t * t * ((s + 1) * t - s)) + b end
|
||||
t = t - 2
|
||||
return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b
|
||||
end
|
||||
local function outInBack(t, b, c, d, s)
|
||||
if t < d / 2 then return outBack(t * 2, b, c / 2, d, s) end
|
||||
return inBack((t * 2) - d, b + c / 2, c / 2, d, s)
|
||||
end
|
||||
|
||||
-- bounce
|
||||
local function outBounce(t, b, c, d)
|
||||
t = t / d
|
||||
if t < 1 / 2.75 then return c * (7.5625 * t * t) + b end
|
||||
if t < 2 / 2.75 then
|
||||
t = t - (1.5 / 2.75)
|
||||
return c * (7.5625 * t * t + 0.75) + b
|
||||
elseif t < 2.5 / 2.75 then
|
||||
t = t - (2.25 / 2.75)
|
||||
return c * (7.5625 * t * t + 0.9375) + b
|
||||
end
|
||||
t = t - (2.625 / 2.75)
|
||||
return c * (7.5625 * t * t + 0.984375) + b
|
||||
end
|
||||
local function inBounce(t, b, c, d) return c - outBounce(d - t, 0, c, d) + b end
|
||||
local function inOutBounce(t, b, c, d)
|
||||
if t < d / 2 then return inBounce(t * 2, 0, c, d) * 0.5 + b end
|
||||
return outBounce(t * 2 - d, 0, c, d) * 0.5 + c * .5 + b
|
||||
end
|
||||
local function outInBounce(t, b, c, d)
|
||||
if t < d / 2 then return outBounce(t * 2, b, c / 2, d) end
|
||||
return inBounce((t * 2) - d, b + c / 2, c / 2, d)
|
||||
end
|
||||
|
||||
tween.easing = {
|
||||
linear = linear,
|
||||
inQuad = inQuad, outQuad = outQuad, inOutQuad = inOutQuad, outInQuad = outInQuad,
|
||||
inCubic = inCubic, outCubic = outCubic, inOutCubic = inOutCubic, outInCubic = outInCubic,
|
||||
inQuart = inQuart, outQuart = outQuart, inOutQuart = inOutQuart, outInQuart = outInQuart,
|
||||
inQuint = inQuint, outQuint = outQuint, inOutQuint = inOutQuint, outInQuint = outInQuint,
|
||||
inSine = inSine, outSine = outSine, inOutSine = inOutSine, outInSine = outInSine,
|
||||
inExpo = inExpo, outExpo = outExpo, inOutExpo = inOutExpo, outInExpo = outInExpo,
|
||||
inCirc = inCirc, outCirc = outCirc, inOutCirc = inOutCirc, outInCirc = outInCirc,
|
||||
inElastic = inElastic, outElastic = outElastic, inOutElastic = inOutElastic, outInElastic = outInElastic,
|
||||
inBack = inBack, outBack = outBack, inOutBack = inOutBack, outInBack = outInBack,
|
||||
inBounce = inBounce, outBounce = outBounce, inOutBounce = inOutBounce, outInBounce = outInBounce
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- private stuff
|
||||
|
||||
local function copyTables(destination, keysTable, valuesTable)
|
||||
valuesTable = valuesTable or keysTable
|
||||
local mt = getmetatable(keysTable)
|
||||
if mt and getmetatable(destination) == nil then
|
||||
setmetatable(destination, mt)
|
||||
end
|
||||
for k,v in pairs(keysTable) do
|
||||
if type(v) == 'table' then
|
||||
destination[k] = copyTables({}, v, valuesTable[k])
|
||||
else
|
||||
destination[k] = valuesTable[k]
|
||||
end
|
||||
end
|
||||
return destination
|
||||
end
|
||||
|
||||
local function checkSubjectAndTargetRecursively(subject, target, path)
|
||||
path = path or {}
|
||||
local targetType, newPath
|
||||
for k,targetValue in pairs(target) do
|
||||
targetType, newPath = type(targetValue), copyTables({}, path)
|
||||
table.insert(newPath, tostring(k))
|
||||
if targetType == 'number' then
|
||||
assert(type(subject[k]) == 'number', "Parameter '" .. table.concat(newPath,'/') .. "' is missing from subject or isn't a number")
|
||||
elseif targetType == 'table' then
|
||||
checkSubjectAndTargetRecursively(subject[k], targetValue, newPath)
|
||||
else
|
||||
assert(targetType == 'number', "Parameter '" .. table.concat(newPath,'/') .. "' must be a number or table of numbers")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function checkNewParams(duration, subject, target, easing)
|
||||
assert(type(duration) == 'number' and duration > 0, "duration must be a positive number. Was " .. tostring(duration))
|
||||
local tsubject = type(subject)
|
||||
assert(tsubject == 'table' or tsubject == 'userdata', "subject must be a table or userdata. Was " .. tostring(subject))
|
||||
assert(type(target)== 'table', "target must be a table. Was " .. tostring(target))
|
||||
assert(type(easing)=='function', "easing must be a function. Was " .. tostring(easing))
|
||||
checkSubjectAndTargetRecursively(subject, target)
|
||||
end
|
||||
|
||||
local function getEasingFunction(easing)
|
||||
easing = easing or "linear"
|
||||
if type(easing) == 'string' then
|
||||
local name = easing
|
||||
easing = tween.easing[name]
|
||||
if type(easing) ~= 'function' then
|
||||
error("The easing function name '" .. name .. "' is invalid")
|
||||
end
|
||||
end
|
||||
return easing
|
||||
end
|
||||
|
||||
local function performEasingOnSubject(subject, target, initial, clock, duration, easing)
|
||||
local t,b,c,d
|
||||
for k,v in pairs(target) do
|
||||
if type(v) == 'table' then
|
||||
performEasingOnSubject(subject[k], v, initial[k], clock, duration, easing)
|
||||
else
|
||||
t,b,c,d = clock, initial[k], v - initial[k], duration
|
||||
subject[k] = easing(t,b,c,d)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Tween methods
|
||||
|
||||
local Tween = {}
|
||||
local Tween_mt = {__index = Tween}
|
||||
|
||||
function Tween:set(clock)
|
||||
assert(type(clock) == 'number', "clock must be a positive number or 0")
|
||||
|
||||
self.initial = self.initial or copyTables({}, self.target, self.subject)
|
||||
self.clock = clock
|
||||
|
||||
if self.clock <= 0 then
|
||||
|
||||
self.clock = 0
|
||||
copyTables(self.subject, self.initial)
|
||||
|
||||
elseif self.clock >= self.duration then -- the tween has expired
|
||||
|
||||
self.clock = self.duration
|
||||
copyTables(self.subject, self.target)
|
||||
|
||||
else
|
||||
|
||||
performEasingOnSubject(self.subject, self.target, self.initial, self.clock, self.duration, self.easing)
|
||||
|
||||
end
|
||||
|
||||
return self.clock >= self.duration
|
||||
end
|
||||
|
||||
function Tween:reset()
|
||||
return self:set(0)
|
||||
end
|
||||
|
||||
function Tween:update(dt)
|
||||
assert(type(dt) == 'number', "dt must be a number")
|
||||
return self:set(self.clock + dt)
|
||||
end
|
||||
|
||||
|
||||
-- Public interface
|
||||
|
||||
function tween.new(duration, subject, target, easing)
|
||||
easing = getEasingFunction(easing)
|
||||
checkNewParams(duration, subject, target, easing)
|
||||
return setmetatable({
|
||||
duration = duration,
|
||||
subject = subject,
|
||||
target = target,
|
||||
easing = easing,
|
||||
clock = 0
|
||||
}, Tween_mt)
|
||||
end
|
||||
|
||||
return tween
|