bugfix
- some offset bugfixes - reworked dynamic values - % got removed for now, now you are able to use parent.w*0.8 instead of 80% - but you are also able to use objectid.x/y/w/h
This commit is contained in:
147
Basalt/Frame.lua
147
Basalt/Frame.lua
@@ -19,6 +19,8 @@ return function(name, parent, pTerm, basalt)
|
|||||||
local object = {}
|
local object = {}
|
||||||
local variables = {}
|
local variables = {}
|
||||||
local theme = {}
|
local theme = {}
|
||||||
|
local dynamicValues = {}
|
||||||
|
local dynValueId = 0
|
||||||
local termObject = pTerm or term.current()
|
local termObject = pTerm or term.current()
|
||||||
|
|
||||||
local monSide = ""
|
local monSide = ""
|
||||||
@@ -65,37 +67,11 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function duplicateTerm(term1, term2)
|
|
||||||
local both = {}
|
|
||||||
setmetatable(both, {
|
|
||||||
__index = function(_, k)
|
|
||||||
if (type(term1[k]) == "function") then
|
|
||||||
return function(...)
|
|
||||||
pcall(term1[k], ...)
|
|
||||||
return term2[k](...)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return term1[k]
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__call = function(_, f, ...)
|
|
||||||
pcall(term2[f], ...)
|
|
||||||
return term1[f](...)
|
|
||||||
end,
|
|
||||||
__newindex = function(_, k, v)
|
|
||||||
term1[k] = v
|
|
||||||
term2[k] = v
|
|
||||||
end
|
|
||||||
})
|
|
||||||
return both
|
|
||||||
end
|
|
||||||
|
|
||||||
if (parent ~= nil) then
|
if (parent ~= nil) then
|
||||||
base.parent = parent
|
base.parent = parent
|
||||||
base.width, base.height = parent:getSize()
|
base.width, base.height = parent:getSize()
|
||||||
base.bgColor = parent:getTheme("FrameBG")
|
base.bgColor = parent:getTheme("FrameBG")
|
||||||
base.fgColor = parent:getTheme("FrameText")
|
base.fgColor = parent:getTheme("FrameText")
|
||||||
print(parent:getTheme("FrameBG"))
|
|
||||||
else
|
else
|
||||||
base.width, base.height = termObject.getSize()
|
base.width, base.height = termObject.getSize()
|
||||||
base.bgColor = basalt.getTheme("BasaltBG")
|
base.bgColor = basalt.getTheme("BasaltBG")
|
||||||
@@ -168,6 +144,89 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function stringToNumber(str)
|
||||||
|
local ok, err = pcall(load("return " .. str))
|
||||||
|
if not(ok)then error(str.." is not a valid dynamic code") end
|
||||||
|
return load("return " .. str)()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function newDynamicValue(_, obj, str)
|
||||||
|
dynValueId = dynValueId + 1
|
||||||
|
dynamicValues[dynValueId] = {0, str, {}, obj, dynValueId}
|
||||||
|
return dynamicValues[dynValueId]
|
||||||
|
end
|
||||||
|
|
||||||
|
local function dynValueGetObjects(obj, str)
|
||||||
|
local names = {}
|
||||||
|
local t = {}
|
||||||
|
for v in str:gmatch("%a+%.x") do
|
||||||
|
local name = v:gsub("%.x", "")
|
||||||
|
if(name~="self")and(name~="parent")then
|
||||||
|
table.insert(names, name) end
|
||||||
|
end
|
||||||
|
for v in str:gmatch("%w+%.y") do
|
||||||
|
local name = v:gsub("%.y", "")
|
||||||
|
if(name~="self")and(name~="parent")then table.insert(names, name) end
|
||||||
|
end
|
||||||
|
for v in str:gmatch("%a+%.w") do
|
||||||
|
local name = v:gsub("%.w", "")
|
||||||
|
if(name~="self")and(name~="parent")then
|
||||||
|
table.insert(names, name)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for v in str:gmatch("%a+%.h") do
|
||||||
|
local name = v:gsub("%.h", "")
|
||||||
|
if(name~="self")and(name~="parent")then
|
||||||
|
table.insert(names, name) end
|
||||||
|
end
|
||||||
|
for k,v in pairs(names)do
|
||||||
|
t[v] = getObject(v)
|
||||||
|
if(t[v]==nil)then
|
||||||
|
error("Dynamic Values - unable to find object "..v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
t["self"] = obj
|
||||||
|
t["parent"] = obj:getParent()
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
local function dynValueObjectToNumber(str, objList)
|
||||||
|
local newStr = str
|
||||||
|
for v in str:gmatch("%w+%.x") do
|
||||||
|
newStr = newStr:gsub(v, objList[v:gsub("%.x", "")]:getX())
|
||||||
|
end
|
||||||
|
for v in str:gmatch("%w+%.y") do
|
||||||
|
newStr = newStr:gsub(v, objList[v:gsub("%.y", "")]:getY())
|
||||||
|
end
|
||||||
|
for v in str:gmatch("%w+%.w") do
|
||||||
|
newStr = newStr:gsub(v, objList[v:gsub("%.w", "")]:getWidth())
|
||||||
|
end
|
||||||
|
for v in str:gmatch("%w+%.h") do
|
||||||
|
newStr = newStr:gsub(v, objList[v:gsub("%.h", "")]:getHeight())
|
||||||
|
end
|
||||||
|
return newStr
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function recalculateDynamicValues()
|
||||||
|
if(#dynamicValues>0)then
|
||||||
|
for n=1,dynValueId do
|
||||||
|
if(dynamicValues[n]~=nil)then
|
||||||
|
local numberStr
|
||||||
|
if(#dynamicValues[n][3]<=0)then dynamicValues[n][3] = dynValueGetObjects(dynamicValues[n][4], dynamicValues[n][2]) end
|
||||||
|
numberStr = dynValueObjectToNumber(dynamicValues[n][2], dynamicValues[n][3])
|
||||||
|
dynamicValues[n][1] = stringToNumber(numberStr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getDynamicValue(id)
|
||||||
|
return dynamicValues[id][1]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
object = {
|
object = {
|
||||||
barActive = false,
|
barActive = false,
|
||||||
barBackground = colors.gray,
|
barBackground = colors.gray,
|
||||||
@@ -176,6 +235,10 @@ return function(name, parent, pTerm, basalt)
|
|||||||
barTextAlign = "left",
|
barTextAlign = "left",
|
||||||
isMoveable = false,
|
isMoveable = false,
|
||||||
|
|
||||||
|
newDynamicValue = newDynamicValue,
|
||||||
|
recalculateDynamicValues = recalculateDynamicValues,
|
||||||
|
getDynamicValue = getDynamicValue,
|
||||||
|
|
||||||
getType = function(self)
|
getType = function(self)
|
||||||
return objectType
|
return objectType
|
||||||
end;
|
end;
|
||||||
@@ -243,10 +306,14 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getOffset = function(self) -- internal
|
getOffset = function(self)
|
||||||
return xOffset, yOffset
|
return xOffset, yOffset
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
getOffsetInternal = function(self) -- internal
|
||||||
|
return xOffset < 0 and math.abs(xOffset) or -xOffset, yOffset < 0 and math.abs(yOffset) or -yOffset
|
||||||
|
end;
|
||||||
|
|
||||||
removeFocusedObject = function(self)
|
removeFocusedObject = function(self)
|
||||||
if (basalt.getFocusedObject() ~= nil) then
|
if (basalt.getFocusedObject() ~= nil) then
|
||||||
basalt.getFocusedObject():loseFocusHandler()
|
basalt.getFocusedObject():loseFocusHandler()
|
||||||
@@ -264,7 +331,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
local obx, oby = self:getAnchorPosition()
|
local obx, oby = self:getAnchorPosition()
|
||||||
self.parent:setCursor(_blink or false, (_xCursor or 0)+obx-1, (_yCursor or 0)+oby-1, color or cursorColor)
|
self.parent:setCursor(_blink or false, (_xCursor or 0)+obx-1, (_yCursor or 0)+oby-1, color or cursorColor)
|
||||||
else
|
else
|
||||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition(self:getX(), self:getY(), true))
|
||||||
cursorBlink = _blink or false
|
cursorBlink = _blink or false
|
||||||
if (_xCursor ~= nil) then
|
if (_xCursor ~= nil) then
|
||||||
xCursor = obx + _xCursor - 1
|
xCursor = obx + _xCursor - 1
|
||||||
@@ -361,7 +428,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
setValuesByXMLData = function(self, data)
|
setValuesByXMLData = function(self, data)
|
||||||
base.setValuesByXMLData(self, data)
|
base.setValuesByXMLData(self, data)
|
||||||
|
|
||||||
if(xmlValue("moveable", data)~=nil)then if(xmlValue("moveable", data))then self:setMoveable(true) end end
|
if(xmlValue("moveable", data)~=nil)then if(xmlValue("moveable", data))then self:setMoveable(true) end end
|
||||||
if(xmlValue("scrollable", data)~=nil)then if(xmlValue("scrollable", data))then self:setScrollable(true) end end
|
if(xmlValue("scrollable", data)~=nil)then if(xmlValue("scrollable", data))then self:setScrollable(true) end end
|
||||||
if(xmlValue("monitor", data)~=nil)then self:setMonitor(xmlValue("monitor", data)):show() end
|
if(xmlValue("monitor", data)~=nil)then self:setMonitor(xmlValue("monitor", data)):show() end
|
||||||
@@ -378,14 +444,19 @@ return function(name, parent, pTerm, basalt)
|
|||||||
if(xmlValue("minScroll", data)~=nil)then self:setMaxScroll(xmlValue("minScroll", data)) end
|
if(xmlValue("minScroll", data)~=nil)then self:setMaxScroll(xmlValue("minScroll", data)) end
|
||||||
if(xmlValue("importantScroll", data)~=nil)then self:setImportantScroll(xmlValue("importantScroll", data)) end
|
if(xmlValue("importantScroll", data)~=nil)then self:setImportantScroll(xmlValue("importantScroll", data)) end
|
||||||
|
|
||||||
|
local objectList = data:children()
|
||||||
for k,v in pairs(_OBJECTS)do
|
|
||||||
if(k~="Animation")then
|
for k,v in pairs(objectList)do
|
||||||
addXMLObjectType(data[string.lower(k)], self["add"..k], self)
|
if(v.___name~="animation")then
|
||||||
|
local name = v.___name:gsub("^%l", string.upper)
|
||||||
|
if(_OBJECTS[name]~=nil)then
|
||||||
|
addXMLObjectType(v, self["add"..name], self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
addXMLObjectType(data["animation"], self.addAnimation, self)
|
|
||||||
addXMLObjectType(data["frame"], self.addFrame, self)
|
addXMLObjectType(data["frame"], self.addFrame, self)
|
||||||
|
addXMLObjectType(data["animation"], self.addAnimation, self)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -545,12 +616,12 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
local xO, yO = self:getOffset()
|
|
||||||
xO = xO < 0 and math.abs(xO) or -xO
|
|
||||||
yO = yO < 0 and math.abs(yO) or -yO
|
|
||||||
if (self.drag) then
|
if (self.drag) then
|
||||||
|
local xO, yO = self.parent:getOffset()
|
||||||
|
xO = xO < 0 and math.abs(xO) or -xO
|
||||||
|
yO = yO < 0 and math.abs(yO) or -yO
|
||||||
if (event == "mouse_drag") then
|
if (event == "mouse_drag") then
|
||||||
local parentX = 1;
|
local parentX = 1
|
||||||
local parentY = 1
|
local parentY = 1
|
||||||
if (self.parent ~= nil) then
|
if (self.parent ~= nil) then
|
||||||
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
|
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
local basaltEvent = require("basaltEvent")
|
local basaltEvent = require("basaltEvent")
|
||||||
local dynValue = require("dynamicValues")
|
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
local split = utils.splitString
|
local split = utils.splitString
|
||||||
local numberFromString = utils.numberFromString
|
local numberFromString = utils.numberFromString
|
||||||
@@ -23,6 +22,9 @@ return function(name)
|
|||||||
|
|
||||||
local shadowColor = colors.black
|
local shadowColor = colors.black
|
||||||
local borderColor = colors.black
|
local borderColor = colors.black
|
||||||
|
local isEnabled = true
|
||||||
|
local isDragging = false
|
||||||
|
local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0
|
||||||
|
|
||||||
local visualsChanged = true
|
local visualsChanged = true
|
||||||
|
|
||||||
@@ -50,16 +52,48 @@ return function(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
enable = function(self)
|
||||||
|
isEnabled = true
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
disable = function(self)
|
||||||
|
isEnabled = false
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
generateXMLEventFunction = function(self, func, val)
|
||||||
|
local createF = function(str)
|
||||||
|
if(str:sub(1,1)=="#")then
|
||||||
|
local o = self:getBaseFrame():getDeepObject(str:sub(2,str:len()))
|
||||||
|
if(o~=nil)and(o.internalObjetCall~=nil)then
|
||||||
|
func(self,function()o:internalObjetCall()end)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
func(self,self:getBaseFrame():getVariable(str))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(type(val)=="string")then
|
||||||
|
createF(val)
|
||||||
|
elseif(type(val)=="table")then
|
||||||
|
for k,v in pairs(val)do
|
||||||
|
createF(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
setValuesByXMLData = function(self, data)
|
setValuesByXMLData = function(self, data)
|
||||||
local baseFrame = self:getBaseFrame()
|
local baseFrame = self:getBaseFrame()
|
||||||
if(xmlValue("x", data)~=nil)then self:setPosition(xmlValue("x", data), self:getY()) end
|
if(xmlValue("x", data)~=nil)then self:setPosition(xmlValue("x", data), self.y) end
|
||||||
if(xmlValue("y", data)~=nil)then self:setPosition(self:getX(), xmlValue("y", data)) end
|
if(xmlValue("y", data)~=nil)then self:setPosition(self.x, xmlValue("y", data)) end
|
||||||
if(xmlValue("width", data)~=nil)then self:setSize(xmlValue("width", data), self:getHeight()) end
|
if(xmlValue("width", data)~=nil)then self:setSize(xmlValue("width", data), self.height) end
|
||||||
if(xmlValue("height", data)~=nil)then self:setSize(self:getWidth(), xmlValue("height", data)) end
|
if(xmlValue("height", data)~=nil)then self:setSize(self.width, xmlValue("height", data)) end
|
||||||
if(xmlValue("bg", data)~=nil)then self:setBackground(colors[xmlValue("bg", data)]) end
|
if(xmlValue("bg", data)~=nil)then self:setBackground(colors[xmlValue("bg", data)]) end
|
||||||
if(xmlValue("fg", data)~=nil)then self:setForeground(colors[xmlValue("fg", data)]) end
|
if(xmlValue("fg", data)~=nil)then self:setForeground(colors[xmlValue("fg", data)]) end
|
||||||
if(xmlValue("value", data)~=nil)then self:setValue(colors[xmlValue("value", data)]) end
|
if(xmlValue("value", data)~=nil)then self:setValue(colors[xmlValue("value", data)]) end
|
||||||
if(xmlValue("visible", data)~=nil)then if(xmlValue("visible", data))then self:show() else self:hide() end end
|
if(xmlValue("visible", data)~=nil)then if(xmlValue("visible", data))then self:show() else self:hide() end end
|
||||||
|
if(xmlValue("enabled", data)~=nil)then if(xmlValue("enabled", data))then self:enable() else self:disable() end end
|
||||||
if(xmlValue("zIndex", data)~=nil)then self:setZIndex(xmlValue("zIndex", data)) end
|
if(xmlValue("zIndex", data)~=nil)then self:setZIndex(xmlValue("zIndex", data)) end
|
||||||
if(xmlValue("anchor", data)~=nil)then self:setAnchor(xmlValue("anchor", data)) end
|
if(xmlValue("anchor", data)~=nil)then self:setAnchor(xmlValue("anchor", data)) end
|
||||||
if(xmlValue("shadow", data)~=nil)then if(xmlValue("shadow", data))then self:showShadow(true) end end
|
if(xmlValue("shadow", data)~=nil)then if(xmlValue("shadow", data))then self:showShadow(true) end end
|
||||||
@@ -71,20 +105,20 @@ return function(name)
|
|||||||
if(xmlValue("borderBottom", data)~=nil)then if(xmlValue("borderBottom", data))then borderBottom = true else borderBottom = false end end
|
if(xmlValue("borderBottom", data)~=nil)then if(xmlValue("borderBottom", data))then borderBottom = true else borderBottom = false end end
|
||||||
if(xmlValue("borderColor", data)~=nil)then self:setBorder(colors[xmlValue("borderColor", data)]) end
|
if(xmlValue("borderColor", data)~=nil)then self:setBorder(colors[xmlValue("borderColor", data)]) end
|
||||||
if(xmlValue("ignoreOffset", data)~=nil)then if(xmlValue("ignoreOffset", data))then self:ignoreOffset(true) end end
|
if(xmlValue("ignoreOffset", data)~=nil)then if(xmlValue("ignoreOffset", data))then self:ignoreOffset(true) end end
|
||||||
if(xmlValue("onClick", data)~=nil)then self:onClick(baseFrame:getVariable(xmlValue("onClick", data))) end
|
if(xmlValue("onClick", data)~=nil)then self:generateXMLEventFunction(self.onClick, xmlValue("onClick", data)) end
|
||||||
if(xmlValue("onClickUp", data)~=nil)then self:onClickUp(baseFrame:getVariable(xmlValue("onClickUp", data))) end
|
if(xmlValue("onClickUp", data)~=nil)then self:generateXMLEventFunction(self.onClickUp, xmlValue("onClickUp", data)) end
|
||||||
if(xmlValue("onScroll", data)~=nil)then self:onScroll(baseFrame:getVariable(xmlValue("onScroll", data))) end
|
if(xmlValue("onScroll", data)~=nil)then self:generateXMLEventFunction(self.onScroll, xmlValue("onScroll", data)) end
|
||||||
if(xmlValue("onDrag", data)~=nil)then self:onDrag(baseFrame:getVariable(xmlValue("onDrag", data))) end
|
if(xmlValue("onDrag", data)~=nil)then self:generateXMLEventFunction(self.onDrag, xmlValue("onDrag", data)) end
|
||||||
if(xmlValue("onKey", data)~=nil)then self:onKey(baseFrame:getVariable(xmlValue("onKey", data))) end
|
if(xmlValue("onKey", data)~=nil)then self:generateXMLEventFunction(self.onKey, xmlValue("onKey", data)) end
|
||||||
if(xmlValue("onKeyUp", data)~=nil)then self:onKeyUp(baseFrame:getVariable(xmlValue("onKeyUp", data))) end
|
if(xmlValue("onKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onKeyUp, xmlValue("onKeyUp", data)) end
|
||||||
if(xmlValue("onChange", data)~=nil)then self:onChange(baseFrame:getVariable(xmlValue("onChange", data))) end
|
if(xmlValue("onChange", data)~=nil)then self:generateXMLEventFunction(self.onChange, xmlValue("onChange", data)) end
|
||||||
if(xmlValue("onResize", data)~=nil)then self:onResize(baseFrame:getVariable(xmlValue("onResize", data))) end
|
if(xmlValue("onResize", data)~=nil)then self:generateXMLEventFunction(self.onResize, xmlValue("onResize", data)) end
|
||||||
if(xmlValue("onReposition", data)~=nil)then self:onReposition(baseFrame:getVariable(xmlValue("onReposition", data))) end
|
if(xmlValue("onReposition", data)~=nil)then self:generateXMLEventFunction(self.onReposition, xmlValue("onReposition", data)) end
|
||||||
if(xmlValue("onEvent", data)~=nil)then self:onEvent(baseFrame:getVariable(xmlValue("onEvent", data))) end
|
if(xmlValue("onEvent", data)~=nil)then self:generateXMLEventFunction(self.onEvent, xmlValue("onEvent", data)) end
|
||||||
if(xmlValue("onGetFocus", data)~=nil)then self:onGetFocus(baseFrame:getVariable(xmlValue("onGetFocus", data))) end
|
if(xmlValue("onGetFocus", data)~=nil)then self:generateXMLEventFunction(self.onGetFocus, xmlValue("onGetFocus", data)) end
|
||||||
if(xmlValue("onLoseFocus", data)~=nil)then self:onLoseFocus(baseFrame:getVariable(xmlValue("onLoseFocus", data))) end
|
if(xmlValue("onLoseFocus", data)~=nil)then self:generateXMLEventFunction(self.onLoseFocus, xmlValue("onLoseFocus", data)) end
|
||||||
if(xmlValue("onBackgroundKey", data)~=nil)then self:onBackgroundKey(baseFrame:getVariable(xmlValue("onBackgroundKey", data))) end
|
if(xmlValue("onBackgroundKey", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKey, xmlValue("onBackgroundKey", data)) end
|
||||||
if(xmlValue("onBackgroundKeyUp", data)~=nil)then self:onBackgroundKeyUp(baseFrame:getVariable(xmlValue("onBackgroundKeyUp", data))) end
|
if(xmlValue("onBackgroundKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKeyUp, xmlValue("onBackgroundKeyUp", data)) end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
@@ -172,6 +206,10 @@ return function(name)
|
|||||||
return self.parent
|
return self.parent
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
getObjectReferencesForDynVal = function(self, str)
|
||||||
|
|
||||||
|
end,
|
||||||
|
|
||||||
setPosition = function(self, xPos, yPos, rel)
|
setPosition = function(self, xPos, yPos, rel)
|
||||||
if(type(xPos)=="number")then
|
if(type(xPos)=="number")then
|
||||||
self.x = rel and self:getX()+xPos or xPos
|
self.x = rel and self:getX()+xPos or xPos
|
||||||
@@ -179,36 +217,26 @@ return function(name)
|
|||||||
if(type(yPos)=="number")then
|
if(type(yPos)=="number")then
|
||||||
self.y = rel and self:getY()+yPos or yPos
|
self.y = rel and self:getY()+yPos or yPos
|
||||||
end
|
end
|
||||||
if(type(xPos)=="string")then
|
if(self.parent~=nil)then
|
||||||
self.x = dynValue(xPos, function() return self:getParent():getWidth() end)
|
if(type(xPos)=="string")then
|
||||||
|
self.x = self.parent:newDynamicValue(self, xPos)
|
||||||
|
end
|
||||||
|
if(type(yPos)=="string")then
|
||||||
|
self.y = self.parent:newDynamicValue(self, yPos)
|
||||||
|
end
|
||||||
|
self.parent:recalculateDynamicValues()
|
||||||
end
|
end
|
||||||
if(type(xPos)=="table")then
|
|
||||||
local str = xPos[1]
|
|
||||||
table.remove(xPos, 1)
|
|
||||||
local fList = xPos
|
|
||||||
self.x = dynValue(str, function() return self:getParent():getWidth() end, fList)
|
|
||||||
end
|
|
||||||
if(type(yPos)=="string")then
|
|
||||||
self.y = dynValue(yPos, function() return self:getParent():getHeight() end)
|
|
||||||
end
|
|
||||||
if(type(yPos)=="table")then
|
|
||||||
local str = yPos[1]
|
|
||||||
table.remove(yPos, 1)
|
|
||||||
local fList = yPos
|
|
||||||
self.y = dynValue(str, function() return self:getParent():getHeight() end, fList)
|
|
||||||
end
|
|
||||||
self:calculateDynamicValues()
|
|
||||||
eventSystem:sendEvent("basalt_reposition", self)
|
eventSystem:sendEvent("basalt_reposition", self)
|
||||||
visualsChanged = true
|
visualsChanged = true
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getX = function(self)
|
getX = function(self)
|
||||||
return type(self.x)=="number" and self.x or self.x:get()
|
return type(self.x) == "number" and self.x or self.x[1]
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getY = function(self)
|
getY = function(self)
|
||||||
return type(self.y)=="number" and self.y or self.y:get()
|
return type(self.y) == "number" and self.y or self.y[1]
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getPosition = function(self)
|
getPosition = function(self)
|
||||||
@@ -232,36 +260,26 @@ return function(name)
|
|||||||
if(type(height)=="number")then
|
if(type(height)=="number")then
|
||||||
self.height = rel and self.height+height or height
|
self.height = rel and self.height+height or height
|
||||||
end
|
end
|
||||||
if(type(width)=="string")then
|
if(self.parent~=nil)then
|
||||||
self.width = dynValue(width, function() return self:getParent():getWidth() end)
|
if(type(width)=="string")then
|
||||||
|
self.width = self.parent:newDynamicValue(self, width)
|
||||||
|
end
|
||||||
|
if(type(height)=="string")then
|
||||||
|
self.height = self.parent:newDynamicValue(self, height)
|
||||||
|
end
|
||||||
|
self.parent:recalculateDynamicValues()
|
||||||
end
|
end
|
||||||
if(type(width)=="table")then
|
|
||||||
local str = width[1]
|
|
||||||
table.remove(width, 1)
|
|
||||||
local fList = width
|
|
||||||
self.width = dynValue(str, function() return self:getParent():getWidth() end, fList)
|
|
||||||
end
|
|
||||||
if(type(height)=="string")then
|
|
||||||
self.height = dynValue(height, function() return self:getParent():getHeight() end)
|
|
||||||
end
|
|
||||||
if(type(height)=="table")then
|
|
||||||
local str = height[1]
|
|
||||||
table.remove(height, 1)
|
|
||||||
local fList = height
|
|
||||||
self.height = dynValue(str, function() return self:getParent():getHeight() end, fList)
|
|
||||||
end
|
|
||||||
self:calculateDynamicValues()
|
|
||||||
eventSystem:sendEvent("basalt_resize", self)
|
eventSystem:sendEvent("basalt_resize", self)
|
||||||
visualsChanged = true
|
visualsChanged = true
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getHeight = function(self)
|
getHeight = function(self)
|
||||||
return type(self.height)=="number" and self.height or self.height:get()
|
return type(self.height) == "number" and self.height or self.height[1]
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getWidth = function(self)
|
getWidth = function(self)
|
||||||
return type(self.width)=="number" and self.width or self.width:get()
|
return type(self.width) == "number" and self.width or self.width[1]
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getSize = function(self)
|
getSize = function(self)
|
||||||
@@ -277,7 +295,7 @@ return function(name)
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
setBackground = function(self, color)
|
setBackground = function(self, color)
|
||||||
self.bgColor = color
|
self.bgColor = color or false
|
||||||
visualsChanged = true
|
visualsChanged = true
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -287,7 +305,7 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
setForeground = function(self, color)
|
setForeground = function(self, color)
|
||||||
self.fgColor = color
|
self.fgColor = color or false
|
||||||
visualsChanged = true
|
visualsChanged = true
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -516,9 +534,11 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
onDrag = function(self, ...)
|
onDrag = function(self, ...)
|
||||||
for _,v in pairs(table.pack(...))do
|
if(isEnabled)then
|
||||||
if(type(v)=="function")then
|
for _,v in pairs(table.pack(...))do
|
||||||
self:registerEvent("mouse_drag", v)
|
if(type(v)=="function")then
|
||||||
|
self:registerEvent("mouse_drag", v)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
@@ -627,38 +647,67 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
if(isEnabled)and(isVisible)then
|
||||||
local w, h = self:getSize()
|
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
local yOff = false
|
local w, h = self:getSize()
|
||||||
|
local yOff = false
|
||||||
if(objY-1 == y)and(self:getBorder("top"))then
|
|
||||||
y = y+1
|
if(objY-1 == y)and(self:getBorder("top"))then
|
||||||
yOff = true
|
y = y+1
|
||||||
end
|
yOff = true
|
||||||
|
end
|
||||||
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) and (isVisible) then
|
if(event=="mouse_up")then
|
||||||
if (self.parent ~= nil) then
|
isDragging = false
|
||||||
self.parent:setFocusedObject(self)
|
end
|
||||||
|
|
||||||
|
if(isDragging)and(event=="mouse_drag")then
|
||||||
|
local xO, yO, parentX, parentY = 0, 0, 1, 1
|
||||||
|
if (self.parent ~= nil) then
|
||||||
|
xO, yO = self.parent:getOffset()
|
||||||
|
xO = xO < 0 and math.abs(xO) or -xO
|
||||||
|
yO = yO < 0 and math.abs(yO) or -yO
|
||||||
|
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
|
||||||
|
end
|
||||||
|
local dX, dY = x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO
|
||||||
|
local val = eventSystem:sendEvent(event, self, event, button, dX, dY, dragStartX, dragStartY, x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) then
|
||||||
|
if(event=="mouse_click")then
|
||||||
|
isDragging = true
|
||||||
|
dragStartX, dragStartY = x, y
|
||||||
|
dragXOffset, dragYOffset = objX - x, objY - y
|
||||||
|
end
|
||||||
|
if(event~="mouse_drag")then
|
||||||
|
if (self.parent ~= nil) then
|
||||||
|
self.parent:setFocusedObject(self)
|
||||||
|
end
|
||||||
|
local val = eventSystem:sendEvent(event, self, event, button, x, y)
|
||||||
|
if(val~=nil)then return val end
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
local val = eventSystem:sendEvent(event, self, event, button, x, y)
|
|
||||||
if(val~=nil)then return val end
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end;
|
end;
|
||||||
|
|
||||||
keyHandler = function(self, event, key)
|
keyHandler = function(self, event, key)
|
||||||
if (self:isFocused()) then
|
if(isEnabled)then
|
||||||
local val = eventSystem:sendEvent(event, self, event, key)
|
if (self:isFocused()) then
|
||||||
if(val~=nil)then return val end
|
local val = eventSystem:sendEvent(event, self, event, key)
|
||||||
return true
|
if(val~=nil)then return val end
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end;
|
end;
|
||||||
|
|
||||||
backgroundKeyHandler = function(self, event, key)
|
backgroundKeyHandler = function(self, event, key)
|
||||||
local val = eventSystem:sendEvent("background_"..event, self, event, key)
|
if(isEnabled)then
|
||||||
if(val~=nil)then return val end
|
local val = eventSystem:sendEvent("background_"..event, self, event, key)
|
||||||
|
if(val~=nil)then return val end
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
return function(value, parentF, ...)
|
|
||||||
local cache
|
|
||||||
local fList = ...
|
|
||||||
if(...~=nil)then
|
|
||||||
if(type(...)~="table")then
|
|
||||||
fList = table.pack(...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function numberFromString(str)
|
|
||||||
return load("return " .. str)()
|
|
||||||
end
|
|
||||||
|
|
||||||
local function replacePercentage(str, parentValue)
|
|
||||||
local _fullStr = str
|
|
||||||
for v in _fullStr:gmatch("%d+%%") do
|
|
||||||
local pValue = v:gsub("%%", "")
|
|
||||||
str = str:gsub(v.."%", parentValue / 100 * math.max(math.min(tonumber(pValue),100),0))
|
|
||||||
end
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
local function fToNumber(str)
|
|
||||||
for k,v in pairs(fList)do
|
|
||||||
if(type(v)=="function")then
|
|
||||||
for _ in str:gmatch("f"..k)do
|
|
||||||
str = string.gsub(str, "f"..k, v())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
local function calculateValue()
|
|
||||||
if(value~=nil)then
|
|
||||||
if(type(value)=="string")then
|
|
||||||
if(fList~=nil and #fList>0)then
|
|
||||||
cache = math.floor(numberFromString(replacePercentage(fToNumber(value), parentF() or 1))+0.5)
|
|
||||||
else
|
|
||||||
cache = math.floor(numberFromString(replacePercentage(value, parentF() or 1)))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return cache
|
|
||||||
end
|
|
||||||
|
|
||||||
local public = {
|
|
||||||
getType = function(self)
|
|
||||||
return "DynamicValue"
|
|
||||||
end,
|
|
||||||
|
|
||||||
get = function(self)
|
|
||||||
return cache or calculateValue()
|
|
||||||
end,
|
|
||||||
|
|
||||||
calculate = function(self)
|
|
||||||
calculateValue()
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
|
|
||||||
setParent = function(self, p)
|
|
||||||
parentF = p
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
}
|
|
||||||
return public
|
|
||||||
end
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
local function PPMToBasalt()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function loadPPM(path)
|
|
||||||
local image = {}
|
|
||||||
|
|
||||||
|
|
||||||
return image
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
|
||||||
loadPPM = loadPPM
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
local logDir = ""
|
|
||||||
local logFileName = "log.txt"
|
|
||||||
|
|
||||||
return {
|
|
||||||
setLogDir = function(dir)
|
|
||||||
logDir = dir
|
|
||||||
end,
|
|
||||||
|
|
||||||
setLogFileName = function(name)
|
|
||||||
logFileName = name
|
|
||||||
end,
|
|
||||||
|
|
||||||
__call = function()
|
|
||||||
--somelogs
|
|
||||||
end
|
|
||||||
}
|
|
||||||
@@ -164,6 +164,41 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
|||||||
drawFrames()
|
drawFrames()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local basaltError = function(errMsg)
|
||||||
|
baseTerm.clear()
|
||||||
|
baseTerm.setBackgroundColor(colors.black)
|
||||||
|
baseTerm.setTextColor(colors.red)
|
||||||
|
local w,h = baseTerm.getSize()
|
||||||
|
|
||||||
|
local splitString = function(str, sep)
|
||||||
|
if sep == nil then
|
||||||
|
sep = "%s"
|
||||||
|
end
|
||||||
|
local t={}
|
||||||
|
for v in string.gmatch(str, "([^"..sep.."]+)") do
|
||||||
|
table.insert(t, v)
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
local words = splitString(errMsg, " ")
|
||||||
|
local line = "Basalt error: "
|
||||||
|
local yPos = 1
|
||||||
|
for n=1,#words do
|
||||||
|
baseTerm.setCursorPos(1,yPos)
|
||||||
|
if(#line+#words[n]<w)then
|
||||||
|
line = line.." "..words[n]
|
||||||
|
else
|
||||||
|
baseTerm.write(line)
|
||||||
|
line = words[n]
|
||||||
|
yPos = yPos + 1
|
||||||
|
end
|
||||||
|
if(n==#words)then
|
||||||
|
baseTerm.write(line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
baseTerm.setCursorPos(1,yPos+1)
|
||||||
|
end
|
||||||
|
|
||||||
local basalt = {}
|
local basalt = {}
|
||||||
basalt = {
|
basalt = {
|
||||||
setTheme = setTheme,
|
setTheme = setTheme,
|
||||||
@@ -180,12 +215,17 @@ basalt = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
autoUpdate = function(isActive)
|
autoUpdate = function(isActive)
|
||||||
|
local pCall = pcall
|
||||||
updaterActive = isActive
|
updaterActive = isActive
|
||||||
if(isActive==nil)then updaterActive = true end
|
if(isActive==nil)then updaterActive = true end
|
||||||
drawFrames()
|
drawFrames()
|
||||||
while updaterActive do
|
while updaterActive do
|
||||||
local event, p1, p2, p3, p4 = os.pullEventRaw()
|
local event, p1, p2, p3, p4 = os.pullEventRaw()
|
||||||
basaltUpdateEvent(event, p1, p2, p3, p4)
|
local ok, err = pCall(basaltUpdateEvent, event, p1, p2, p3, p4)
|
||||||
|
if not(ok)then
|
||||||
|
basaltError(err)
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -232,12 +272,13 @@ basalt = {
|
|||||||
|
|
||||||
shedule = function(f)
|
shedule = function(f)
|
||||||
assert(f~="function", "Shedule needs a function in order to work!")
|
assert(f~="function", "Shedule needs a function in order to work!")
|
||||||
local co = coroutine.create(f)
|
return function(...)
|
||||||
local ok, result = coroutine.resume(co)
|
local co = coroutine.create(f)
|
||||||
if(ok)then
|
local ok, result = coroutine.resume(co, ...)
|
||||||
table.insert(shedules, co)
|
if(ok)then
|
||||||
|
table.insert(shedules, co)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return co
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
createFrame = function(name)
|
createFrame = function(name)
|
||||||
@@ -281,7 +322,7 @@ basalt = {
|
|||||||
end
|
end
|
||||||
basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount()))
|
basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount()))
|
||||||
if(basalt.debugList.getItemCount() > basalt.debugList:getHeight())then
|
if(basalt.debugList.getItemCount() > basalt.debugList:getHeight())then
|
||||||
basalt.debugList:setIndexOffset(basalt.debugList:getItemCount() - basalt.debugList:getHeight())
|
basalt.debugList:setOffset(basalt.debugList:getItemCount() - basalt.debugList:getHeight())
|
||||||
end
|
end
|
||||||
basalt.debugLabel:show()
|
basalt.debugLabel:show()
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ local lerp = function(s, e, pct)
|
|||||||
return s + (e - s) * pct
|
return s + (e - s) * pct
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local linear = function (t)
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
local flip = function (x)
|
local flip = function (x)
|
||||||
return 1 - x
|
return 1 - x
|
||||||
end
|
end
|
||||||
@@ -25,6 +29,7 @@ local easeInOut = function(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local lerp = {
|
local lerp = {
|
||||||
|
linear = linear,
|
||||||
lerp = lerp,
|
lerp = lerp,
|
||||||
flip=flip,
|
flip=flip,
|
||||||
easeIn=easeIn,
|
easeIn=easeIn,
|
||||||
@@ -48,6 +53,8 @@ return function(name)
|
|||||||
local nextWaitTimer = 0
|
local nextWaitTimer = 0
|
||||||
local lastFunc
|
local lastFunc
|
||||||
local loop=false
|
local loop=false
|
||||||
|
local autoDestroy = false
|
||||||
|
local mode = "easeOut"
|
||||||
|
|
||||||
local _OBJ
|
local _OBJ
|
||||||
|
|
||||||
@@ -58,6 +65,7 @@ return function(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function onPlay(self)
|
local function onPlay(self)
|
||||||
|
if(index==1)then self:animationStartHandler() end
|
||||||
if (animations[index] ~= nil) then
|
if (animations[index] ~= nil) then
|
||||||
call(animations[index].f)
|
call(animations[index].f)
|
||||||
animationTime = animations[index].t
|
animationTime = animations[index].t
|
||||||
@@ -106,9 +114,9 @@ return function(name)
|
|||||||
table.insert(animations, {t=time, f={f}})
|
table.insert(animations, {t=time, f={f}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function predefinedLerp(v1,v2,d,t,get,set,mode)
|
local function predefinedLerp(v1,v2,d,t,get,set)
|
||||||
mode = mode or "easeOut"
|
|
||||||
local x,y
|
local x,y
|
||||||
addAnimationPart(t+0.05, function()
|
addAnimationPart(t+0.05, function()
|
||||||
x,y = get(_OBJ)
|
x,y = get(_OBJ)
|
||||||
@@ -135,6 +143,32 @@ return function(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
setMode = function(self, newMode)
|
||||||
|
mode = newMode
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
generateXMLEventFunction = function(self, func, val)
|
||||||
|
local createF = function(str)
|
||||||
|
if(str:sub(1,1)=="#")then
|
||||||
|
local o = self:getBaseFrame():getDeepObject(str:sub(2,str:len()))
|
||||||
|
if(o~=nil)and(o.internalObjetCall~=nil)then
|
||||||
|
func(self,function()o:internalObjetCall()end)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
func(self,self:getBaseFrame():getVariable(str))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(type(val)=="string")then
|
||||||
|
createF(val)
|
||||||
|
elseif(type(val)=="table")then
|
||||||
|
for k,v in pairs(val)do
|
||||||
|
createF(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
setValuesByXMLData = function(self, data)
|
setValuesByXMLData = function(self, data)
|
||||||
loop = xmlValue("loop", data)==true and true or false
|
loop = xmlValue("loop", data)==true and true or false
|
||||||
if(xmlValue("object", data)~=nil)then
|
if(xmlValue("object", data)~=nil)then
|
||||||
@@ -151,24 +185,21 @@ return function(name)
|
|||||||
local y = xmlValue("y", data["move"])
|
local y = xmlValue("y", data["move"])
|
||||||
local duration = xmlValue("duration", data["move"])
|
local duration = xmlValue("duration", data["move"])
|
||||||
local time = xmlValue("time", data["move"])
|
local time = xmlValue("time", data["move"])
|
||||||
local mode = xmlValue("mode", data["move"])
|
self:move(x, y, duration, time)
|
||||||
self:move(x, y, duration, time, mode)
|
|
||||||
end
|
end
|
||||||
if(data["size"]~=nil)then
|
if(data["size"]~=nil)then
|
||||||
local w = xmlValue("width", data["size"])
|
local w = xmlValue("width", data["size"])
|
||||||
local h = xmlValue("height", data["size"])
|
local h = xmlValue("height", data["size"])
|
||||||
local duration = xmlValue("duration", data["size"])
|
local duration = xmlValue("duration", data["size"])
|
||||||
local time = xmlValue("time", data["size"])
|
local time = xmlValue("time", data["size"])
|
||||||
local mode = xmlValue("mode", data["size"])
|
self:size(w, h, duration, time)
|
||||||
self:size(w, h, duration, time, mode)
|
|
||||||
end
|
end
|
||||||
if(data["offset"]~=nil)then
|
if(data["offset"]~=nil)then
|
||||||
local x = xmlValue("x", data["offset"])
|
local x = xmlValue("x", data["offset"])
|
||||||
local y = xmlValue("y", data["offset"])
|
local y = xmlValue("y", data["offset"])
|
||||||
local duration = xmlValue("duration", data["offset"])
|
local duration = xmlValue("duration", data["offset"])
|
||||||
local time = xmlValue("time", data["offset"])
|
local time = xmlValue("time", data["offset"])
|
||||||
local mode = xmlValue("mode", data["offset"])
|
self:offset(x, y, duration, time)
|
||||||
self:offset(x, y, duration, time, mode)
|
|
||||||
end
|
end
|
||||||
if(data["textColor"]~=nil)then
|
if(data["textColor"]~=nil)then
|
||||||
local duration = xmlValue("duration", data["textColor"])
|
local duration = xmlValue("duration", data["textColor"])
|
||||||
@@ -215,29 +246,14 @@ return function(name)
|
|||||||
self:changeText(duration, timer or 0, table.unpack(t))
|
self:changeText(duration, timer or 0, table.unpack(t))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(xmlValue("onDone", data)~=nil)then
|
if(xmlValue("onDone", data)~=nil)then self:generateXMLEventFunction(self.onDone, xmlValue("onDone", data)) end
|
||||||
local value = xmlValue("onDone", data)
|
if(xmlValue("onStart", data)~=nil)then self:generateXMLEventFunction(self.onDone, xmlValue("onStart", data)) end
|
||||||
if(value:sub(1,1)=="#")then
|
if(xmlValue("autoDestroy", data)~=nil)then
|
||||||
value = xmlValue("onDone", data):sub(2,value:len())
|
if(xmlValue("autoDestroy", data))then
|
||||||
local o = self:getBaseFrame():getDeepObject(value)
|
autoDestroy = true
|
||||||
if(o~=nil)then
|
|
||||||
self:onAnimationDone(function()o:internalObjetCall()end)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local f = self:getBaseFrame():getVariable(value)
|
|
||||||
if(f~=nil)then
|
|
||||||
self:onAnimationDone(f)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(xmlValue("autoRemove", data)~=nil)then
|
mode = xmlValue("mode", data) or mode
|
||||||
if(xmlValue("autoRemove", data)~=false)then
|
|
||||||
self:onAnimationDone(function() self.parent:removeObject(self) end)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self:onAnimationDone(function() self.parent:removeObject(self) end)
|
|
||||||
end
|
|
||||||
|
|
||||||
if(xmlValue("play", data)~=nil)then if(xmlValue("play", data))then self:play(loop) end end
|
if(xmlValue("play", data)~=nil)then if(xmlValue("play", data))then self:play(loop) end end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
@@ -263,7 +279,7 @@ return function(name)
|
|||||||
|
|
||||||
offset = function(self, x, y, duration, timer, obj)
|
offset = function(self, x, y, duration, timer, obj)
|
||||||
_OBJ = obj or _OBJ
|
_OBJ = obj or _OBJ
|
||||||
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset)
|
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffsetInternal,_OBJ.setOffset)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -329,13 +345,31 @@ return function(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
onAnimationDone = function(self, f)
|
onDone = function(self, f)
|
||||||
eventSystem:registerEvent("animation_done", f)
|
eventSystem:registerEvent("animation_done", f)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
onStart = function(self, f)
|
||||||
|
eventSystem:registerEvent("animation_start", f)
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
setAutoDestroy = function(self, destroy)
|
||||||
|
autoDestroy = destroy~=nil and destroy or true
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
animationDoneHandler = function(self)
|
animationDoneHandler = function(self)
|
||||||
eventSystem:sendEvent("animation_done", self)
|
eventSystem:sendEvent("animation_done", self)
|
||||||
|
if(autoDestroy)then
|
||||||
|
self.parent:removeObject(self)
|
||||||
|
self = nil
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
animationStartHandler = function(self)
|
||||||
|
eventSystem:sendEvent("animation_start", self)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
clear = function(self)
|
clear = function(self)
|
||||||
|
|||||||
@@ -559,7 +559,7 @@ return function(name, parent)
|
|||||||
if not (curProcess:isDead()) then
|
if not (curProcess:isDead()) then
|
||||||
if not (paused) then
|
if not (paused) then
|
||||||
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
|
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
|
||||||
curProcess:resume(event, button, x - (absX - 1), y - (absY - 1))
|
curProcess:resume(event, button, x-absX+1, y-absY+1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ return function(name)
|
|||||||
if(xmlValue("progressSymbol", data)~=nil)then activeBarSymbol = xmlValue("progressSymbol", data) end
|
if(xmlValue("progressSymbol", data)~=nil)then activeBarSymbol = xmlValue("progressSymbol", data) end
|
||||||
if(xmlValue("backgroundSymbol", data)~=nil)then bgBarSymbol = xmlValue("backgroundSymbol", data) end
|
if(xmlValue("backgroundSymbol", data)~=nil)then bgBarSymbol = xmlValue("backgroundSymbol", data) end
|
||||||
if(xmlValue("progressSymbolColor", data)~=nil)then activeBarSymbolCol = colors[xmlValue("progressSymbolColor", data)] end
|
if(xmlValue("progressSymbolColor", data)~=nil)then activeBarSymbolCol = colors[xmlValue("progressSymbolColor", data)] end
|
||||||
if(xmlValue("onDone", data)~=nil)then self:onProgressDone(baseFrame:getVariable(xmlValue("onDone", data))) end
|
if(xmlValue("onDone", data)~=nil)then self:generateXMLEventFunction(self.onProgressDone, xmlValue("onDone", data)) end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local Object = require("Object")
|
local Object = require("Object")
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
local xmlValue = utils.getValueFromXML
|
||||||
|
|
||||||
return function(name)
|
return function(name)
|
||||||
local base = Object(name)
|
local base = Object(name)
|
||||||
@@ -12,6 +13,8 @@ return function(name)
|
|||||||
local itemSelectedFG
|
local itemSelectedFG
|
||||||
local boxSelectedBG
|
local boxSelectedBG
|
||||||
local boxSelectedFG
|
local boxSelectedFG
|
||||||
|
local boxNotSelectedBG
|
||||||
|
local boxNotSelectedFG
|
||||||
local selectionColorActive = true
|
local selectionColorActive = true
|
||||||
local symbol = "\7"
|
local symbol = "\7"
|
||||||
local align = "left"
|
local align = "left"
|
||||||
@@ -35,8 +38,10 @@ return function(name)
|
|||||||
base.setValuesByXMLData(self, data)
|
base.setValuesByXMLData(self, data)
|
||||||
if(xmlValue("selectionBG", data)~=nil)then itemSelectedBG = colors[xmlValue("selectionBG", data)] end
|
if(xmlValue("selectionBG", data)~=nil)then itemSelectedBG = colors[xmlValue("selectionBG", data)] end
|
||||||
if(xmlValue("selectionFG", data)~=nil)then itemSelectedFG = colors[xmlValue("selectionFG", data)] end
|
if(xmlValue("selectionFG", data)~=nil)then itemSelectedFG = colors[xmlValue("selectionFG", data)] end
|
||||||
if(xmlValue("boxBG", data)~=nil)then itemSelectedBG = colors[xmlValue("boxBG", data)] end
|
if(xmlValue("boxBG", data)~=nil)then boxSelectedBG = colors[xmlValue("boxBG", data)] end
|
||||||
if(xmlValue("boxFG", data)~=nil)then itemSelectedFG = colors[xmlValue("boxFG", data)] end
|
if(xmlValue("inactiveBoxBG", data)~=nil)then boxNotSelectedBG = colors[xmlValue("inactiveBoxBG", data)] end
|
||||||
|
if(xmlValue("inactiveBoxFG", data)~=nil)then boxNotSelectedFG = colors[xmlValue("inactiveBoxFG", data)] end
|
||||||
|
if(xmlValue("boxFG", data)~=nil)then boxSelectedFG = colors[xmlValue("boxFG", data)] end
|
||||||
if(xmlValue("symbol", data)~=nil)then symbol = xmlValue("symbol", data) end
|
if(xmlValue("symbol", data)~=nil)then symbol = xmlValue("symbol", data) end
|
||||||
if(data["item"]~=nil)then
|
if(data["item"]~=nil)then
|
||||||
local tab = data["item"]
|
local tab = data["item"]
|
||||||
@@ -139,7 +144,7 @@ return function(name)
|
|||||||
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG)
|
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.parent:drawBackgroundBox(value.x + obx - 1, value.y + oby - 1, 1, 1, self.bgColor)
|
self.parent:drawBackgroundBox(value.x + obx - 1, value.y + oby - 1, 1, 1, boxNotSelectedBG or self.bgColor)
|
||||||
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, value.bgCol, value.fgCol)
|
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, value.bgCol, value.fgCol)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,11 +34,12 @@ return function(name)
|
|||||||
return pos
|
return pos
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateColors(self)
|
local function updateColors(self, l)
|
||||||
local fgLine = tHex[self.fgColor]:rep(fgLines[textY]:len())
|
l = l or textY
|
||||||
local bgLine = tHex[self.bgColor]:rep(bgLines[textY]:len())
|
local fgLine = tHex[self.fgColor]:rep(fgLines[l]:len())
|
||||||
|
local bgLine = tHex[self.bgColor]:rep(bgLines[l]:len())
|
||||||
for k,v in pairs(rules)do
|
for k,v in pairs(rules)do
|
||||||
local pos = stringGetPositions(lines[textY], v[1])
|
local pos = stringGetPositions(lines[l], v[1])
|
||||||
if(#pos>0)then
|
if(#pos>0)then
|
||||||
for x=1,#pos/2 do
|
for x=1,#pos/2 do
|
||||||
local xP = x*2 - 1
|
local xP = x*2 - 1
|
||||||
@@ -53,7 +54,7 @@ return function(name)
|
|||||||
end
|
end
|
||||||
for k,v in pairs(keyWords)do
|
for k,v in pairs(keyWords)do
|
||||||
for _,b in pairs(v)do
|
for _,b in pairs(v)do
|
||||||
local pos = stringGetPositions(lines[textY], b)
|
local pos = stringGetPositions(lines[l], b)
|
||||||
if(#pos>0)then
|
if(#pos>0)then
|
||||||
for x=1,#pos/2 do
|
for x=1,#pos/2 do
|
||||||
local xP = x*2 - 1
|
local xP = x*2 - 1
|
||||||
@@ -62,8 +63,14 @@ return function(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
fgLines[textY] = fgLine
|
fgLines[l] = fgLine
|
||||||
bgLines[textY] = bgLine
|
bgLines[l] = bgLine
|
||||||
|
end
|
||||||
|
|
||||||
|
local function updateAllColors(self)
|
||||||
|
for n=1,#lines do
|
||||||
|
updateColors(self, n)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local object = {
|
local object = {
|
||||||
@@ -75,10 +82,24 @@ return function(name)
|
|||||||
return objectType
|
return objectType
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
setBackground = function(self, bg)
|
||||||
|
base.setBackground(self, bg)
|
||||||
|
updateAllColors(self)
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
setForeground = function(self, fg)
|
||||||
|
base.setForeground(self, fg)
|
||||||
|
updateAllColors(self)
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
setValuesByXMLData = function(self, data)
|
setValuesByXMLData = function(self, data)
|
||||||
base.setValuesByXMLData(self, data)
|
base.setValuesByXMLData(self, data)
|
||||||
if(data["lines"]~=nil)then
|
if(data["lines"]~=nil)then
|
||||||
for k,v in pairs(data["lines"]["line"])do
|
local l = data["lines"]["line"]
|
||||||
|
if(l.properties~=nil)then l = {l} end
|
||||||
|
for k,v in pairs(l)do
|
||||||
self:addLine(v:value())
|
self:addLine(v:value())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,18 @@ return function(name)
|
|||||||
local cRoutine
|
local cRoutine
|
||||||
local isActive = false
|
local isActive = false
|
||||||
|
|
||||||
|
local generateXMLEventFunction = function(self, str)
|
||||||
|
if(str:sub(1,1)=="#")then
|
||||||
|
local o = self:getBaseFrame():getDeepObject(str:sub(2,str:len()))
|
||||||
|
if(o~=nil)and(o.internalObjetCall~=nil)then
|
||||||
|
return (function()o:internalObjetCall()end)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return self:getBaseFrame():getVariable(str)
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
object = {
|
object = {
|
||||||
name = name,
|
name = name,
|
||||||
getType = function(self)
|
getType = function(self)
|
||||||
@@ -29,7 +41,7 @@ return function(name)
|
|||||||
|
|
||||||
setValuesByXMLData = function(self, data)
|
setValuesByXMLData = function(self, data)
|
||||||
local f
|
local f
|
||||||
if(xmlValue("thread", data)~=nil)then f = self:getBaseFrame():getVariable(xmlValue("thread", data)) end
|
if(xmlValue("thread", data)~=nil)then f = generateXMLEventFunction(self, xmlValue("thread", data)) end
|
||||||
if(xmlValue("start", data)~=nil)then if(xmlValue("start", data))and(f~=nil)then self:start(f) end end
|
if(xmlValue("start", data)~=nil)then if(xmlValue("start", data))and(f~=nil)then self:start(f) end end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -11,6 +11,27 @@ return function(name)
|
|||||||
local eventSystem = basaltEvent()
|
local eventSystem = basaltEvent()
|
||||||
local timerIsActive = false
|
local timerIsActive = false
|
||||||
|
|
||||||
|
local generateXMLEventFunction = function(self, func, val)
|
||||||
|
local createF = function(str)
|
||||||
|
if(str:sub(1,1)=="#")then
|
||||||
|
local o = self:getBaseFrame():getDeepObject(str:sub(2,str:len()))
|
||||||
|
if(o~=nil)and(o.internalObjetCall~=nil)then
|
||||||
|
func(self,function()o:internalObjetCall()end)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
func(self,self:getBaseFrame():getVariable(str))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(type(val)=="string")then
|
||||||
|
createF(val)
|
||||||
|
elseif(type(val)=="table")then
|
||||||
|
for k,v in pairs(val)do
|
||||||
|
createF(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
local object = {
|
local object = {
|
||||||
name = name,
|
name = name,
|
||||||
getType = function(self)
|
getType = function(self)
|
||||||
@@ -21,7 +42,7 @@ return function(name)
|
|||||||
if(xmlValue("time", data)~=nil)then timer = xmlValue("time", data) end
|
if(xmlValue("time", data)~=nil)then timer = xmlValue("time", data) end
|
||||||
if(xmlValue("repeat", data)~=nil)then savedRepeats = xmlValue("repeat", data) end
|
if(xmlValue("repeat", data)~=nil)then savedRepeats = xmlValue("repeat", data) end
|
||||||
if(xmlValue("start", data)~=nil)then if(xmlValue("start", data))then self:start() end end
|
if(xmlValue("start", data)~=nil)then if(xmlValue("start", data))then self:start() end end
|
||||||
if(xmlValue("onCall", data)~=nil)then self:onCall(getBaseFrame():getVariable(xmlValue("onCall", data))) end
|
if(xmlValue("onCall", data)~=nil)then generateXMLEventFunction(self, self.onCall, xmlValue("onCall", data)) end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|||||||
@@ -178,26 +178,24 @@ Shedules a function which gets called in a coroutine. After the coroutine is fin
|
|||||||
1. `function` a function which should get executed
|
1. `function` a function which should get executed
|
||||||
|
|
||||||
#### Returns:
|
#### Returns:
|
||||||
1. `coroutine` it returns the coroutine which got created to execute the function
|
1. `function` it returns the function which you have to execute in order to start the coroutine
|
||||||
|
|
||||||
#### Usage:
|
#### Usage:
|
||||||
* Creates a shedule which switches the color between red and gray
|
* Creates a shedule which switches the color between red and gray
|
||||||
```lua
|
```lua
|
||||||
local mainFrame = basalt.createFrame()
|
local mainFrame = basalt.createFrame()
|
||||||
local aButton = mainFrame:addButton():setText("Click me")
|
local aButton = mainFrame:addButton():setText("Click me")
|
||||||
aButton:onClick(function()
|
aButton:onClick(basalt.shedule(function(self)
|
||||||
basalt.shedule(function()
|
self:setBackground(colors.red)
|
||||||
aButton:setBackground(colors.red)
|
os.sleep(0.1)
|
||||||
os.sleep(0.1)
|
self:setBackground(colors.gray)
|
||||||
aButton:setBackground(colors.gray)
|
os.sleep(0.1)
|
||||||
os.sleep(0.1)
|
self:setBackground(colors.red)
|
||||||
aButton:setBackground(colors.red)
|
os.sleep(0.1)
|
||||||
os.sleep(0.1)
|
self:setBackground(colors.gray)
|
||||||
aButton:setBackground(colors.gray)
|
os.sleep(0.1)
|
||||||
os.sleep(0.1)
|
self:setBackground(colors.red)
|
||||||
aButton:setBackground(colors.red)
|
os.sleep(0.1)
|
||||||
os.sleep(0.1)
|
self:setBackground(colors.gray)
|
||||||
aButton:setBackground(colors.gray)
|
end))
|
||||||
end)
|
|
||||||
end)
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user