stuff
This commit is contained in:
122
LIB/types/generic.lua
Normal file
122
LIB/types/generic.lua
Normal file
@@ -0,0 +1,122 @@
|
||||
local path = (...):sub(1, -(("generic"):len() + 2))
|
||||
local floor
|
||||
floor = math.floor
|
||||
local generic
|
||||
do
|
||||
local _class_0
|
||||
local _base_0 = {
|
||||
draw = function(self)
|
||||
graphics.setColor(self.color)
|
||||
if self.background then
|
||||
return graphics.draw(self.background, self.x, self.y, 0, self.w / self.backgroundWidth, self.h / self.backgroundHeight)
|
||||
else
|
||||
return graphics.rectangle("fill", self.x, self.y, self.w, self.h)
|
||||
end
|
||||
end,
|
||||
_align = function(self)
|
||||
local _exp_0 = self.align
|
||||
if "top-left" == _exp_0 or "left" == _exp_0 or "bottom-left" == _exp_0 then
|
||||
self.x = self.parent.x
|
||||
elseif "top" == _exp_0 or "center" == _exp_0 or "bottom" == _exp_0 then
|
||||
self.x = self.parent.x + self.parent.w / 2 - self.w / 2
|
||||
elseif "top-right" == _exp_0 or "right" == _exp_0 or "bottom-right" == _exp_0 then
|
||||
self.x = self.parent.x + self.parent.w - self.w
|
||||
end
|
||||
local _exp_1 = self.align
|
||||
if "top-left" == _exp_1 or "top" == _exp_1 or "top-right" == _exp_1 then
|
||||
self.y = self.parent.y
|
||||
elseif "left" == _exp_1 or "center" == _exp_1 or "right" == _exp_1 then
|
||||
self.y = self.parent.y + self.parent.h / 2 - self.h / 2
|
||||
elseif "bottom-left" == _exp_1 or "bottom" == _exp_1 or "bottom-right" == _exp_1 then
|
||||
self.y = self.parent.y + self.parent.h - self.h
|
||||
end
|
||||
for _index_0 = 1, #self do
|
||||
local child = self[_index_0]
|
||||
child:_align()
|
||||
end
|
||||
end
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, element, parent)
|
||||
if element == nil then
|
||||
element = { }
|
||||
end
|
||||
if not (parent) then
|
||||
error("No parent element!")
|
||||
end
|
||||
self.parent = parent
|
||||
for k, v in pairs(element) do
|
||||
self[k] = v
|
||||
end
|
||||
if self.visible == nil then
|
||||
self.visible = true
|
||||
end
|
||||
if self.hovered then
|
||||
self.hoverable = true
|
||||
end
|
||||
if self.hoverable == nil then
|
||||
self.hoverable = false
|
||||
end
|
||||
if self.width then
|
||||
if self.width <= 1 then
|
||||
self.w = floor(parent.w * self.width)
|
||||
else
|
||||
self.w = floor(self.width)
|
||||
end
|
||||
else
|
||||
self.width = 0
|
||||
self.w = 0
|
||||
end
|
||||
if self.height then
|
||||
if self.height <= 1 then
|
||||
self.h = floor(parent.h * self.height)
|
||||
else
|
||||
self.h = floor(self.height)
|
||||
end
|
||||
else
|
||||
self.height = 0
|
||||
self.h = 0
|
||||
end
|
||||
if "table" == type(self.background) then
|
||||
if not (self.color) then
|
||||
self.color = self.background
|
||||
end
|
||||
self.background = nil
|
||||
else
|
||||
if not (self.color) then
|
||||
self.color = {
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
}
|
||||
end
|
||||
end
|
||||
if self.background then
|
||||
self.backgroundWidth = self.background:getWidth()
|
||||
self.backgroundHeight = self.background:getHeight()
|
||||
self.aspectRatio = self.backgroundWidth / self.backgroundHeight
|
||||
end
|
||||
if #self > 0 then
|
||||
local slab = require(tostring(path:sub(1, -7)) .. "/slab")
|
||||
for i = 1, #self do
|
||||
self[i] = slab.make(self[i], self)
|
||||
end
|
||||
end
|
||||
return self:_align()
|
||||
end,
|
||||
__base = _base_0,
|
||||
__name = "generic"
|
||||
}, {
|
||||
__index = _base_0,
|
||||
__call = function(cls, ...)
|
||||
local _self_0 = setmetatable({}, _base_0)
|
||||
cls.__init(_self_0, ...)
|
||||
return _self_0
|
||||
end
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
generic = _class_0
|
||||
return _class_0
|
||||
end
|
88
LIB/types/generic.moon
Normal file
88
LIB/types/generic.moon
Normal file
@@ -0,0 +1,88 @@
|
||||
path = (...)\sub 1, -("generic"\len! + 2)
|
||||
|
||||
import floor from math
|
||||
|
||||
-- local slab
|
||||
class generic
|
||||
-- @load: (lib) =>
|
||||
-- print "LOAD", self, lib
|
||||
-- slab = lib
|
||||
|
||||
new: (element={}, parent) =>
|
||||
error "No parent element!" unless parent
|
||||
@parent = parent
|
||||
for k,v in pairs element
|
||||
@[k] = v
|
||||
|
||||
@visible = true if @visible == nil
|
||||
@hoverable = true if @hovered
|
||||
@hoverable = false if @hoverable == nil
|
||||
|
||||
if @width
|
||||
if @width <= 1
|
||||
@w = floor parent.w * @width
|
||||
else
|
||||
@w = floor(@width)
|
||||
else
|
||||
@width = 0
|
||||
@w = 0
|
||||
|
||||
if @height
|
||||
if @height <= 1
|
||||
@h = floor parent.h * @height
|
||||
else
|
||||
@h = floor(@height)
|
||||
else
|
||||
@height = 0
|
||||
@h = 0
|
||||
|
||||
if "table" == type @background
|
||||
@color = @background unless @color
|
||||
@background = nil
|
||||
else
|
||||
@color = {255, 255, 255, 255} unless @color
|
||||
|
||||
if @background
|
||||
@backgroundWidth = @background\getWidth!
|
||||
@backgroundHeight = @background\getHeight!
|
||||
@aspectRatio = @backgroundWidth / @backgroundHeight
|
||||
|
||||
if #@ > 0
|
||||
slab = require "#{path\sub 1, -7}/slab"
|
||||
for i = 1, #@
|
||||
@[i] = slab.make(@[i], @)
|
||||
|
||||
@_align!
|
||||
|
||||
draw: =>
|
||||
graphics.setColor @color
|
||||
if @background
|
||||
graphics.draw @background, @x, @y, 0, @w / @backgroundWidth, @h / @backgroundHeight
|
||||
else
|
||||
graphics.rectangle "fill", @x, @y, @w, @h
|
||||
|
||||
_align: =>
|
||||
switch @align
|
||||
when "top-left", "left", "bottom-left"
|
||||
-- align left
|
||||
@x = @parent.x
|
||||
when "top", "center", "bottom"
|
||||
-- align center
|
||||
@x = @parent.x + @parent.w / 2 - @w / 2
|
||||
when "top-right", "right", "bottom-right"
|
||||
-- align right
|
||||
@x = @parent.x + @parent.w - @w
|
||||
|
||||
switch @align
|
||||
when "top-left", "top", "top-right"
|
||||
-- align top
|
||||
@y = @parent.y
|
||||
when "left", "center", "right"
|
||||
-- align center
|
||||
@y = @parent.y + @parent.h / 2 - @h / 2
|
||||
when "bottom-left", "bottom", "bottom-right"
|
||||
-- align bottom
|
||||
@y = @parent.y + @parent.h - @h
|
||||
|
||||
for child in *@
|
||||
child\_align!
|
72
LIB/types/menu.lua
Normal file
72
LIB/types/menu.lua
Normal file
@@ -0,0 +1,72 @@
|
||||
local path = (...):sub(1, -(("menu"):len() + 2))
|
||||
local generic = require(tostring(path) .. "/generic")
|
||||
local insert
|
||||
insert = table.insert
|
||||
local menu
|
||||
do
|
||||
local _class_0
|
||||
local _parent_0 = generic
|
||||
local _base_0 = { }
|
||||
_base_0.__index = _base_0
|
||||
setmetatable(_base_0, _parent_0.__base)
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, element, parent)
|
||||
if element == nil then
|
||||
element = { }
|
||||
end
|
||||
_class_0.__parent.__init(self, element, parent)
|
||||
for _index_0 = 1, #self do
|
||||
local child = self[_index_0]
|
||||
if self.menu.width then
|
||||
if not (child.width) then
|
||||
child.width = self.menu.width
|
||||
end
|
||||
end
|
||||
if self.menu.height then
|
||||
if not (child.height) then
|
||||
child.height = self.menu.height
|
||||
end
|
||||
end
|
||||
if self.menu.align then
|
||||
if not (child.align) then
|
||||
child.align = self.menu.align
|
||||
end
|
||||
end
|
||||
end
|
||||
if #self.menu > 0 then
|
||||
local slab = require(tostring(path:sub(1, -7)) .. "/slab")
|
||||
local _list_0 = self.menu
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local child = _list_0[_index_0]
|
||||
insert(self, slab.make(child, self))
|
||||
end
|
||||
end
|
||||
end,
|
||||
__base = _base_0,
|
||||
__name = "menu",
|
||||
__parent = _parent_0
|
||||
}, {
|
||||
__index = function(cls, name)
|
||||
local val = rawget(_base_0, name)
|
||||
if val == nil then
|
||||
local parent = rawget(cls, "__parent")
|
||||
if parent then
|
||||
return parent[name]
|
||||
end
|
||||
else
|
||||
return val
|
||||
end
|
||||
end,
|
||||
__call = function(cls, ...)
|
||||
local _self_0 = setmetatable({}, _base_0)
|
||||
cls.__init(_self_0, ...)
|
||||
return _self_0
|
||||
end
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
if _parent_0.__inherited then
|
||||
_parent_0.__inherited(_parent_0, _class_0)
|
||||
end
|
||||
menu = _class_0
|
||||
return _class_0
|
||||
end
|
21
LIB/types/menu.moon
Normal file
21
LIB/types/menu.moon
Normal file
@@ -0,0 +1,21 @@
|
||||
path = (...)\sub 1, -("menu"\len! + 2)
|
||||
generic = require "#{path}/generic"
|
||||
|
||||
import insert from table
|
||||
|
||||
class menu extends generic
|
||||
new: (element={}, parent) =>
|
||||
super element, parent
|
||||
|
||||
for child in *@
|
||||
if @menu.width
|
||||
child.width = @menu.width unless child.width
|
||||
if @menu.height
|
||||
child.height = @menu.height unless child.height
|
||||
if @menu.align
|
||||
child.align = @menu.align unless child.align
|
||||
|
||||
if #@menu > 0
|
||||
slab = require "#{path\sub 1, -7}/slab"
|
||||
for child in *@menu
|
||||
insert(@, slab.make child, @)
|
61
LIB/types/spinner.lua
Normal file
61
LIB/types/spinner.lua
Normal file
@@ -0,0 +1,61 @@
|
||||
local path = (...):sub(1, -(("spinner"):len() + 2))
|
||||
local generic = require(tostring(path) .. "/generic")
|
||||
local graphics
|
||||
graphics = love.graphics
|
||||
local pi, min
|
||||
do
|
||||
local _obj_0 = math
|
||||
pi, min = _obj_0.pi, _obj_0.min
|
||||
end
|
||||
local tau = pi * 2
|
||||
local half_pi = pi / 2
|
||||
local spinner
|
||||
do
|
||||
local _class_0
|
||||
local _parent_0 = generic
|
||||
local _base_0 = {
|
||||
draw = function(self)
|
||||
return graphics.arc("line", self.x + self.w / 2, self.y + self.h / 2, min(self.w, self.h), self.offset, self.offset + self.value * tau)
|
||||
end
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
setmetatable(_base_0, _parent_0.__base)
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, element, parent)
|
||||
if element == nil then
|
||||
element = { }
|
||||
end
|
||||
_class_0.__parent.__init(self, element, parent)
|
||||
if not (self.offset) then
|
||||
self.offset = 0
|
||||
end
|
||||
self.value = 0.1
|
||||
end,
|
||||
__base = _base_0,
|
||||
__name = "spinner",
|
||||
__parent = _parent_0
|
||||
}, {
|
||||
__index = function(cls, name)
|
||||
local val = rawget(_base_0, name)
|
||||
if val == nil then
|
||||
local parent = rawget(cls, "__parent")
|
||||
if parent then
|
||||
return parent[name]
|
||||
end
|
||||
else
|
||||
return val
|
||||
end
|
||||
end,
|
||||
__call = function(cls, ...)
|
||||
local _self_0 = setmetatable({}, _base_0)
|
||||
cls.__init(_self_0, ...)
|
||||
return _self_0
|
||||
end
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
if _parent_0.__inherited then
|
||||
_parent_0.__inherited(_parent_0, _class_0)
|
||||
end
|
||||
spinner = _class_0
|
||||
return _class_0
|
||||
end
|
21
LIB/types/spinner.moon
Normal file
21
LIB/types/spinner.moon
Normal file
@@ -0,0 +1,21 @@
|
||||
path = (...)\sub 1, -("spinner"\len! + 2)
|
||||
generic = require "#{path}/generic"
|
||||
|
||||
import graphics from love
|
||||
import pi, min from math
|
||||
tau = pi * 2
|
||||
half_pi = pi / 2
|
||||
|
||||
class spinner extends generic
|
||||
new: (element={}, parent) =>
|
||||
super element, parent
|
||||
|
||||
-- @offset = -half_pi
|
||||
@offset = 0 unless @offset
|
||||
@value = 0.1 -- temporary
|
||||
|
||||
-- slab = require "#{path\sub 1, -7}/slab"
|
||||
|
||||
draw: =>
|
||||
-- TODO should be setting color!
|
||||
graphics.arc "line", @x + @w / 2, @y + @h / 2, min(@w, @h), @offset, @offset + @value * tau
|
48
LIB/types/text.lua
Normal file
48
LIB/types/text.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
local path = (...):sub(1, -(("text"):len() + 2))
|
||||
local generic = require(tostring(path) .. "/generic")
|
||||
local graphics
|
||||
graphics = love.graphics
|
||||
local text
|
||||
do
|
||||
local _class_0
|
||||
local _parent_0 = generic
|
||||
local _base_0 = {
|
||||
draw = function(self) end
|
||||
}
|
||||
_base_0.__index = _base_0
|
||||
setmetatable(_base_0, _parent_0.__base)
|
||||
_class_0 = setmetatable({
|
||||
__init = function(self, element, parent)
|
||||
if element == nil then
|
||||
element = { }
|
||||
end
|
||||
return _class_0.__parent.__init(self, element, parent)
|
||||
end,
|
||||
__base = _base_0,
|
||||
__name = "text",
|
||||
__parent = _parent_0
|
||||
}, {
|
||||
__index = function(cls, name)
|
||||
local val = rawget(_base_0, name)
|
||||
if val == nil then
|
||||
local parent = rawget(cls, "__parent")
|
||||
if parent then
|
||||
return parent[name]
|
||||
end
|
||||
else
|
||||
return val
|
||||
end
|
||||
end,
|
||||
__call = function(cls, ...)
|
||||
local _self_0 = setmetatable({}, _base_0)
|
||||
cls.__init(_self_0, ...)
|
||||
return _self_0
|
||||
end
|
||||
})
|
||||
_base_0.__class = _class_0
|
||||
if _parent_0.__inherited then
|
||||
_parent_0.__inherited(_parent_0, _class_0)
|
||||
end
|
||||
text = _class_0
|
||||
return _class_0
|
||||
end
|
15
LIB/types/text.moon
Normal file
15
LIB/types/text.moon
Normal file
@@ -0,0 +1,15 @@
|
||||
path = (...)\sub 1, -("text"\len! + 2)
|
||||
generic = require "#{path}/generic"
|
||||
|
||||
import graphics from love
|
||||
|
||||
class text extends generic
|
||||
new: (element={}, parent) =>
|
||||
super element, parent
|
||||
|
||||
-- @font = graphics.newFont 14
|
||||
|
||||
-- slab = require "#{path\sub 1, -7}/slab"
|
||||
|
||||
draw: =>
|
||||
-- TODO
|
Reference in New Issue
Block a user