Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
859303e7a1 | ||
|
|
51f6ebe7ce | ||
|
|
4d227af9d9 | ||
|
|
cf4f15e659 | ||
|
|
a3291544ac | ||
|
|
0503aa1274 | ||
|
|
299b23a6c2 | ||
|
|
8b3b6f3490 | ||
|
|
d1792ac537 | ||
|
|
709cf66ce8 | ||
|
|
ae14d85a6b | ||
|
|
896e8179a6 | ||
|
|
2dd3bf648b | ||
|
|
c977410a41 | ||
|
|
23b94d076b | ||
|
|
b10ec1770c | ||
|
|
001e8c4ef6 | ||
|
|
18601d54f7 | ||
|
|
4d614372a1 | ||
|
|
53d7b9f70c | ||
|
|
92e91b7d6b | ||
|
|
b6c5531290 | ||
|
|
b637e65983 | ||
|
|
5d12e0db74 | ||
|
|
41bbe19de1 | ||
|
|
537d37c21b | ||
|
|
de84dbf406 | ||
|
|
8ab06dbc17 | ||
|
|
14643193b9 | ||
|
|
9d7c7d8a85 | ||
|
|
6809f9991b | ||
|
|
b64f3ef87c | ||
|
|
fb227445df | ||
|
|
10c25e7615 | ||
|
|
dfed9a5512 | ||
|
|
fac7e221b3 | ||
|
|
c775958254 | ||
|
|
1c76130086 | ||
|
|
57b303f538 | ||
|
|
74071cb4bd | ||
|
|
0cbded634a | ||
|
|
6ae0242b00 | ||
|
|
ad6bf96124 | ||
|
|
039782ec0e | ||
|
|
878e45bf8c | ||
|
|
cf387cab5a | ||
|
|
bcbca630f8 | ||
|
|
cfa2f561e4 | ||
|
|
1bc6cb80d2 | ||
|
|
323b521ddc | ||
|
|
80e2ed1c33 | ||
|
|
46bb1c53f2 | ||
|
|
e6717c8648 | ||
|
|
5b422905fe | ||
|
|
00e70c8b4e | ||
|
|
ca38c7d560 | ||
|
|
a3c2e7a043 | ||
|
|
c36690da00 |
785
Basalt/Frame.lua
785
Basalt/Frame.lua
File diff suppressed because it is too large
Load Diff
@@ -13,20 +13,23 @@ return function(name)
|
||||
local anchor = "topLeft"
|
||||
local ignOffset = false
|
||||
local isVisible = true
|
||||
local initialized = false
|
||||
|
||||
local shadow = false
|
||||
local borderLeft = false
|
||||
local borderTop = false
|
||||
local borderRight = false
|
||||
local borderBottom = false
|
||||
local borderColors = {
|
||||
left = false,
|
||||
right = false,
|
||||
top = false,
|
||||
bottom = false
|
||||
}
|
||||
|
||||
local shadowColor = 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 draw = true
|
||||
local activeEvents = {}
|
||||
|
||||
local eventSystem = basaltEvent()
|
||||
|
||||
@@ -36,31 +39,38 @@ return function(name)
|
||||
width = 1,
|
||||
height = 1,
|
||||
bgColor = colors.black,
|
||||
bgSymbol = " ",
|
||||
bgSymbolColor = colors.black,
|
||||
fgColor = colors.white,
|
||||
transparentColor = false,
|
||||
name = name or "Object",
|
||||
parent = nil,
|
||||
|
||||
show = function(self)
|
||||
isVisible = true
|
||||
visualsChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
hide = function(self)
|
||||
isVisible = false
|
||||
visualsChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
end,
|
||||
|
||||
enable = function(self)
|
||||
isEnabled = true
|
||||
return self
|
||||
end;
|
||||
end,
|
||||
|
||||
disable = function(self)
|
||||
isEnabled = false
|
||||
return self
|
||||
end;
|
||||
end,
|
||||
|
||||
isEnabled = function(self)
|
||||
return isEnabled
|
||||
end,
|
||||
|
||||
generateXMLEventFunction = function(self, func, val)
|
||||
local createF = function(str)
|
||||
@@ -96,13 +106,12 @@ return function(name)
|
||||
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("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("shadowColor", data)~=nil)then self:setShadow(colors[xmlValue("shadowColor", data)]) end
|
||||
if(xmlValue("border", data)~=nil)then if(xmlValue("border", data))then borderLeft,borderTop,borderRight,borderBottom = true,true,true,true end end
|
||||
if(xmlValue("borderLeft", data)~=nil)then if(xmlValue("borderLeft", data))then borderLeft = true else borderLeft = false end end
|
||||
if(xmlValue("borderTop", data)~=nil)then if(xmlValue("borderTop", data))then borderTop = true else borderTop = false end end
|
||||
if(xmlValue("borderRight", data)~=nil)then if(xmlValue("borderRight", data))then borderRight = true else borderRight = false end end
|
||||
if(xmlValue("borderBottom", data)~=nil)then if(xmlValue("borderBottom", data))then borderBottom = true else borderBottom = false end end
|
||||
if(xmlValue("border", data)~=nil)then self:setBorder(colors[xmlValue("border", data)]) end
|
||||
if(xmlValue("borderLeft", data)~=nil)then borderColors["left"] = xmlValue("borderLeft", data) end
|
||||
if(xmlValue("borderTop", data)~=nil)then borderColors["top"] = xmlValue("borderTop", data) end
|
||||
if(xmlValue("borderRight", data)~=nil)then borderColors["right"] = xmlValue("borderRight", data) end
|
||||
if(xmlValue("borderBottom", data)~=nil)then borderColors["bottom"] = xmlValue("borderBottom", 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("onClick", data)~=nil)then self:generateXMLEventFunction(self.onClick, xmlValue("onClick", data)) end
|
||||
@@ -117,9 +126,7 @@ return function(name)
|
||||
if(xmlValue("onEvent", data)~=nil)then self:generateXMLEventFunction(self.onEvent, xmlValue("onEvent", data)) end
|
||||
if(xmlValue("onGetFocus", data)~=nil)then self:generateXMLEventFunction(self.onGetFocus, xmlValue("onGetFocus", data)) end
|
||||
if(xmlValue("onLoseFocus", data)~=nil)then self:generateXMLEventFunction(self.onLoseFocus, xmlValue("onLoseFocus", data)) end
|
||||
if(xmlValue("onBackgroundKey", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKey, xmlValue("onBackgroundKey", data)) end
|
||||
if(xmlValue("onBackgroundKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKeyUp, xmlValue("onBackgroundKeyUp", data)) end
|
||||
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
@@ -139,9 +146,19 @@ return function(name)
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:removeObject(self)
|
||||
self.parent:addObject(self)
|
||||
self:updateEventHandlers()
|
||||
end
|
||||
|
||||
return self
|
||||
end;
|
||||
end,
|
||||
|
||||
updateEventHandlers = function(self)
|
||||
for k,v in pairs(activeEvents)do
|
||||
if(v)then
|
||||
self.parent:addEvent(k, self)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
getZIndex = function(self)
|
||||
return zIndex;
|
||||
@@ -159,6 +176,7 @@ return function(name)
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:removeObject(self)
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -176,7 +194,7 @@ return function(name)
|
||||
setValue = function(self, _value)
|
||||
if (value ~= _value) then
|
||||
value = _value
|
||||
visualsChanged = true
|
||||
self:updateDraw()
|
||||
self:valueChangedHandler()
|
||||
end
|
||||
return self
|
||||
@@ -186,13 +204,14 @@ return function(name)
|
||||
return value
|
||||
end;
|
||||
|
||||
getVisualChanged = function(self)
|
||||
return visualsChanged
|
||||
getDraw = function(self)
|
||||
return draw
|
||||
end;
|
||||
|
||||
setVisualChanged = function(self, change)
|
||||
visualsChanged = change or true
|
||||
if(change == nil)then visualsChanged = true end
|
||||
updateDraw = function(self, change)
|
||||
draw = change
|
||||
if(change == nil)then draw = true end
|
||||
if(draw)then if(self.parent~=nil)then self.parent:updateDraw() end end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -206,10 +225,6 @@ return function(name)
|
||||
return self.parent
|
||||
end;
|
||||
|
||||
getObjectReferencesForDynVal = function(self, str)
|
||||
|
||||
end,
|
||||
|
||||
setPosition = function(self, xPos, yPos, rel)
|
||||
if(type(xPos)=="number")then
|
||||
self.x = rel and self:getX()+xPos or xPos
|
||||
@@ -227,7 +242,7 @@ return function(name)
|
||||
self.parent:recalculateDynamicValues()
|
||||
end
|
||||
eventSystem:sendEvent("basalt_reposition", self)
|
||||
visualsChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -249,7 +264,7 @@ return function(name)
|
||||
|
||||
setVisibility = function(self, _isVisible)
|
||||
isVisible = _isVisible or not isVisible
|
||||
visualsChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -270,7 +285,7 @@ return function(name)
|
||||
self.parent:recalculateDynamicValues()
|
||||
end
|
||||
eventSystem:sendEvent("basalt_resize", self)
|
||||
visualsChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -291,12 +306,23 @@ return function(name)
|
||||
if(type(self.height)=="table")then self.height:calculate() end
|
||||
if(type(self.x)=="table")then self.x:calculate() end
|
||||
if(type(self.y)=="table")then self.y:calculate() end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
setBackground = function(self, color)
|
||||
setBackground = function(self, color, symbol, symbolCol)
|
||||
self.bgColor = color or false
|
||||
visualsChanged = true
|
||||
self.bgSymbol = symbol or (self.bgColor~=false and self.bgSymbol or false)
|
||||
self.bgSymbolColor = symbolCol or self.bgSymbolColor
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setTransparent = function(self, color)
|
||||
self.transparentColor = color or false
|
||||
self.bgSymbol = false
|
||||
self.bgSymbolColor = false
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -306,7 +332,7 @@ return function(name)
|
||||
|
||||
setForeground = function(self, color)
|
||||
self.fgColor = color or false
|
||||
visualsChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -314,13 +340,14 @@ return function(name)
|
||||
return self.fgColor
|
||||
end;
|
||||
|
||||
showShadow = function(self, show)
|
||||
shadow = show or (not shadow)
|
||||
return self
|
||||
end;
|
||||
|
||||
setShadow = function(self, color)
|
||||
shadowColor = color
|
||||
if(color==false)then
|
||||
shadow = false
|
||||
else
|
||||
shadowColor = color
|
||||
shadow = true
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -328,26 +355,25 @@ return function(name)
|
||||
return shadow;
|
||||
end;
|
||||
|
||||
showBorder = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(v=="left")then
|
||||
borderLeft = true
|
||||
end
|
||||
if(v=="top")then
|
||||
borderTop = true
|
||||
end
|
||||
if(v=="right")then
|
||||
borderRight = true
|
||||
end
|
||||
if(v=="bottom")then
|
||||
borderBottom = true
|
||||
setBorder = function(self, ...)
|
||||
if(...~=nil)then
|
||||
local t = {...}
|
||||
for k,v in pairs(t)do
|
||||
if(v=="left")or(#t==1)then
|
||||
borderColors["left"] = t[1]
|
||||
end
|
||||
if(v=="top")or(#t==1)then
|
||||
borderColors["top"] = t[1]
|
||||
end
|
||||
if(v=="right")or(#t==1)then
|
||||
borderColors["right"] = t[1]
|
||||
end
|
||||
if(v=="bottom")or(#t==1)then
|
||||
borderColors["bottom"] = t[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
setBorder = function(self, color)
|
||||
borderColor = color
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -367,52 +393,73 @@ return function(name)
|
||||
end;
|
||||
|
||||
draw = function(self)
|
||||
if (isVisible) then
|
||||
if (isVisible)then
|
||||
if(self.parent~=nil)then
|
||||
local x, y = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
local wP,hP = self.parent:getSize()
|
||||
if(x+w<1)or(x>wP)or(y+h<1)or(y>hP)then return false end
|
||||
if(self.transparentColor~=false)then
|
||||
self.parent:drawForegroundBox(x, y, w, h, self.transparentColor)
|
||||
end
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(x, y, w, h, self.bgColor)
|
||||
end
|
||||
if(self.bgSymbol~=false)then
|
||||
self.parent:drawTextBox(x, y, w, h, self.bgSymbol)
|
||||
if(self.bgSymbol~=" ")then
|
||||
self.parent:drawForegroundBox(x, y, w, h, self.bgSymbolColor)
|
||||
end
|
||||
end
|
||||
if(shadow)then
|
||||
self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor)
|
||||
self.parent:drawBackgroundBox(x+w, y+1, 1, h, shadowColor)
|
||||
self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor)
|
||||
self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor)
|
||||
end
|
||||
if(borderLeft)then
|
||||
if(borderColors["left"]~=false)then
|
||||
self.parent:drawTextBox(x-1, y, 1, h, "\149")
|
||||
self.parent:drawForegroundBox(x-1, y, 1, h, borderColor)
|
||||
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y, 1, h, self.bgColor) end
|
||||
self.parent:drawBackgroundBox(x-1, y, 1, h, self.bgColor)
|
||||
self.parent:drawForegroundBox(x-1, y, 1, h, borderColors["left"])
|
||||
end
|
||||
if(borderLeft)and(borderTop)then
|
||||
if(borderColors["left"]~=false)and(borderColors["top"]~=false)then
|
||||
self.parent:drawTextBox(x-1, y-1, 1, 1, "\151")
|
||||
self.parent:drawForegroundBox(x-1, y-1, 1, 1, borderColor)
|
||||
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor) end
|
||||
self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor)
|
||||
self.parent:drawForegroundBox(x-1, y-1, 1, 1, borderColors["left"])
|
||||
end
|
||||
if(borderTop)then
|
||||
if(borderColors["top"]~=false)then
|
||||
|
||||
self.parent:drawTextBox(x, y-1, w, 1, "\131")
|
||||
self.parent:drawForegroundBox(x, y-1, w, 1, borderColor)
|
||||
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x, y-1, w, 1, self.bgColor) end
|
||||
self.parent:drawBackgroundBox(x, y-1, w, 1, self.bgColor)
|
||||
self.parent:drawForegroundBox(x, y-1, w, 1, borderColors["top"])
|
||||
end
|
||||
if(borderTop)and(borderRight)then
|
||||
self.parent:drawTextBox(x+w, y-1, 1, 1, "\149")
|
||||
self.parent:drawForegroundBox(x+w, y-1, 1, 1, borderColor)
|
||||
if(borderColors["top"]~=false)and(borderColors["right"]~=false)then
|
||||
self.parent:drawTextBox(x+w, y-1, 1, 1, "\148")
|
||||
self.parent:drawForegroundBox(x+w, y-1, 1, 1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x+w, y-1, 1, 1, borderColors["right"])
|
||||
end
|
||||
if(borderRight)then
|
||||
if(borderColors["right"]~=false)then
|
||||
self.parent:drawTextBox(x+w, y, 1, h, "\149")
|
||||
self.parent:drawForegroundBox(x+w, y, 1, h, borderColor)
|
||||
self.parent:drawForegroundBox(x+w, y, 1, h, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x+w, y, 1, h, borderColors["right"])
|
||||
end
|
||||
if(borderRight)and(borderBottom)then
|
||||
self.parent:drawTextBox(x+w, y+h, 1, 1, "\129")
|
||||
self.parent:drawForegroundBox(x+w, y+h, 1, 1, borderColor)
|
||||
if(borderColors["right"]~=false)and(borderColors["bottom"]~=false)then
|
||||
self.parent:drawTextBox(x+w, y+h, 1, 1, "\133")
|
||||
self.parent:drawForegroundBox(x+w, y+h, 1, 1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x+w, y+h, 1, 1, borderColors["right"])
|
||||
end
|
||||
if(borderBottom)then
|
||||
self.parent:drawTextBox(x, y+h, w, 1, "\131")
|
||||
self.parent:drawForegroundBox(x, y+h, w, 1, borderColor)
|
||||
if(borderColors["bottom"]~=false)then
|
||||
self.parent:drawTextBox(x, y+h, w, 1, "\143")
|
||||
self.parent:drawForegroundBox(x, y+h, w, 1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x, y+h, w, 1, borderColors["bottom"])
|
||||
end
|
||||
if(borderBottom)and(borderLeft)then
|
||||
self.parent:drawTextBox(x-1, y+h, 1, 1, "\131")
|
||||
self.parent:drawForegroundBox(x-1, y+h, 1, 1, borderColor)
|
||||
if(borderColors["bottom"]~=false)and(borderColors["left"]~=false)then
|
||||
self.parent:drawTextBox(x-1, y+h, 1, 1, "\138")
|
||||
self.parent:drawForegroundBox(x-1, y+h, 1, 1, self.bgColor)
|
||||
self.parent:drawBackgroundBox(x-1, y+h, 1, 1, borderColors["left"])
|
||||
end
|
||||
end
|
||||
draw = false
|
||||
return true
|
||||
end
|
||||
return false
|
||||
@@ -487,7 +534,7 @@ return function(name)
|
||||
|
||||
setAnchor = function(self, newAnchor)
|
||||
anchor = newAnchor
|
||||
visualsChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -505,59 +552,88 @@ return function(name)
|
||||
end;
|
||||
|
||||
onClick = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_click", v)
|
||||
self:registerEvent("monitor_touch", v)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_click", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onClickUp = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_up", v)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_up", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
activeEvents["mouse_up"] = true
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
|
||||
onScroll = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_scroll", v)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_scroll", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
activeEvents["mouse_scroll"] = true
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onDrag = function(self, ...)
|
||||
if(isEnabled)then
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_drag", v)
|
||||
end
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_drag", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
activeEvents["mouse_drag"] = true
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
activeEvents["mouse_up"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onEvent = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("custom_event_handler", v)
|
||||
self:registerEvent("other_event", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("other_event", self)
|
||||
activeEvents["other_event"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onKey = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("key", v)
|
||||
self:registerEvent("char", v)
|
||||
if(isEnabled)then
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("key", v)
|
||||
self:registerEvent("char", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("key", self)
|
||||
self.parent:addEvent("char", self)
|
||||
activeEvents["key"] = true
|
||||
activeEvents["char"] = true
|
||||
end
|
||||
end
|
||||
return self
|
||||
@@ -582,30 +658,15 @@ return function(name)
|
||||
end;
|
||||
|
||||
onKeyUp = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("key_up", v)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("key_up", v)
|
||||
end
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onBackgroundKey = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("background_key", v)
|
||||
self:registerEvent("background_char", v)
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("key_up", self)
|
||||
activeEvents["key_up"] = true
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
onBackgroundKeyUp = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("background_key_up", v)
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -622,6 +683,10 @@ return function(name)
|
||||
self:registerEvent("get_focus", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -631,6 +696,10 @@ return function(name)
|
||||
self:registerEvent("lose_focus", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -646,79 +715,122 @@ return function(name)
|
||||
return eventSystem:sendEvent(event, self, ...)
|
||||
end;
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if(isEnabled)and(isVisible)then
|
||||
isCoordsInObject = function(self, x, y)
|
||||
if(isVisible)and(isEnabled)then
|
||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local w, h = self:getSize()
|
||||
local yOff = false
|
||||
|
||||
if(objY-1 == y)and(self:getBorder("top"))then
|
||||
y = y+1
|
||||
yOff = true
|
||||
end
|
||||
if(event=="mouse_up")then
|
||||
isDragging = false
|
||||
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:getOffsetInternal()
|
||||
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
|
||||
|
||||
|
||||
local w, h = self:getSize()
|
||||
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(event~="mouse_up")then
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
end
|
||||
local val = eventSystem:sendEvent(event, self, event, button, x, y)
|
||||
if(val~=nil)then return val end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end;
|
||||
end,
|
||||
|
||||
keyHandler = function(self, event, key)
|
||||
if(isEnabled)then
|
||||
if (self:isFocused()) then
|
||||
local val = eventSystem:sendEvent(event, self, event, key)
|
||||
if(val~=nil)then return val end
|
||||
return true
|
||||
mouseHandler = function(self, button, x, y, isMon)
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x, y, isMon)
|
||||
if(val==false)then return false end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
isDragging = true
|
||||
dragStartX, dragStartY = x, y
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end;
|
||||
end,
|
||||
|
||||
backgroundKeyHandler = function(self, event, key)
|
||||
if(isEnabled)then
|
||||
local val = eventSystem:sendEvent("background_"..event, self, event, key)
|
||||
mouseUpHandler = function(self, button, x, y)
|
||||
isDragging = false
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x, y)
|
||||
if(val==false)then return false end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
dragHandler = function(self, button, x, y)
|
||||
if(isDragging)then
|
||||
local xO, yO, parentX, parentY = 0, 0, 1, 1
|
||||
if (self.parent ~= nil) then
|
||||
xO, yO = self.parent:getOffsetInternal()
|
||||
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("mouse_drag", self, button, dX, dY, dragStartX-x, dragStartY-y, x, y)
|
||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
dragStartX, dragStartY = x, y
|
||||
if(val~=nil)then return val end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return true
|
||||
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
dragStartX, dragStartY = x, y
|
||||
dragXOffset, dragYOffset = objX - x, objY - y
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y)
|
||||
if(val==false)then return false end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
keyHandler = function(self, key, isHolding)
|
||||
if(isEnabled)and(isVisible)then
|
||||
if (self:isFocused()) then
|
||||
local val = eventSystem:sendEvent("key", self, "key", key, isHolding)
|
||||
if(val==false)then return false end
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end;
|
||||
|
||||
keyUpHandler = function(self, key)
|
||||
if(isEnabled)and(isVisible)then
|
||||
if (self:isFocused()) then
|
||||
local val = eventSystem:sendEvent("key_up", self, "key_up", key)
|
||||
if(val==false)then return false end
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end;
|
||||
|
||||
charHandler = function(self, char)
|
||||
if(isEnabled)and(isVisible)then
|
||||
if (self:isFocused()) then
|
||||
local val = eventSystem:sendEvent("char", self, "char", char)
|
||||
if(val==false)then return false end
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
valueChangedHandler = function(self)
|
||||
eventSystem:sendEvent("value_changed", self)
|
||||
eventSystem:sendEvent("value_changed", self, value)
|
||||
end;
|
||||
|
||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
||||
eventSystem:sendEvent("custom_event_handler", self, event, p1, p2, p3, p4)
|
||||
local val = eventSystem:sendEvent("other_event", self, event, p1, p2, p3, p4)
|
||||
if(val~=nil)then return val end
|
||||
return true
|
||||
end;
|
||||
|
||||
getFocusHandler = function(self)
|
||||
@@ -728,11 +840,25 @@ return function(name)
|
||||
end;
|
||||
|
||||
loseFocusHandler = function(self)
|
||||
isDragging = false
|
||||
local val = eventSystem:sendEvent("lose_focus", self)
|
||||
if(val~=nil)then return val end
|
||||
return true
|
||||
end;
|
||||
|
||||
init = function(self)
|
||||
if(self.parent~=nil)then
|
||||
for k,v in pairs(activeEvents)do
|
||||
if(v)then
|
||||
self.parent:addEvent(k, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
if not(initialized)then
|
||||
initialized = true
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ return function(drawTerm)
|
||||
createEmptyLines()
|
||||
|
||||
local function recreateWindowArray()
|
||||
createEmptyLines()
|
||||
local emptyText = emptySpaceLine
|
||||
local emptyFG = emptyColorLines[colors.white]
|
||||
local emptyBG = emptyColorLines[colors.black]
|
||||
@@ -126,6 +127,11 @@ return function(drawTerm)
|
||||
end
|
||||
|
||||
local drawHelper = {
|
||||
setSize = function(w, h)
|
||||
width, height = w, h
|
||||
recreateWindowArray()
|
||||
end,
|
||||
|
||||
setMirror = function(mirror)
|
||||
mirrorTerm = mirror
|
||||
end,
|
||||
@@ -157,11 +163,15 @@ return function(drawTerm)
|
||||
end
|
||||
end;
|
||||
writeText = function(x, y, text, bgCol, fgCol)
|
||||
bgCol = bgCol or terminal.getBackgroundColor()
|
||||
fgCol = fgCol or terminal.getTextColor()
|
||||
setText(x, y, text)
|
||||
setBG(x, y, rep(tHex[bgCol], text:len()))
|
||||
setFG(x, y, rep(tHex[fgCol], text:len()))
|
||||
if(text~=nil)then
|
||||
setText(x, y, text)
|
||||
if(bgCol~=nil)and(bgCol~=false)then
|
||||
setBG(x, y, rep(tHex[bgCol], text:len()))
|
||||
end
|
||||
if(fgCol~=nil)and(fgCol~=false)then
|
||||
setFG(x, y, rep(tHex[fgCol], text:len()))
|
||||
end
|
||||
end
|
||||
end;
|
||||
|
||||
update = function()
|
||||
@@ -171,7 +181,7 @@ return function(drawTerm)
|
||||
isBlinking = terminal.getCursorBlink()
|
||||
end
|
||||
terminal.setCursorBlink(false)
|
||||
if(mirrorTerm~=nil)then terminal.setCursorBlink(false) end
|
||||
if(mirrorTerm~=nil)then mirrorTerm.setCursorBlink(false) end
|
||||
for n = 1, height do
|
||||
terminal.setCursorPos(1, n)
|
||||
terminal.blit(cacheT[n], cacheFG[n], cacheBG[n])
|
||||
|
||||
20
Basalt/libraries/basaltLogs.lua
Normal file
20
Basalt/libraries/basaltLogs.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
local logDir = ""
|
||||
local logFileName = "basaltLog.txt"
|
||||
|
||||
local defaultLogType = "Debug"
|
||||
|
||||
fs.delete(logDir~="" and logDir.."/"..logFileName or logFileName)
|
||||
|
||||
local mt = {
|
||||
__call = function(_,text, typ)
|
||||
if(text==nil)then return end
|
||||
local dirStr = logDir~="" and logDir.."/"..logFileName or logFileName
|
||||
local handle = fs.open(dirStr, fs.exists(dirStr) and "a" or "w")
|
||||
handle.writeLine("[Basalt]["..(typ and typ or defaultLogType).."]: "..tostring(text))
|
||||
handle.close()
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable({}, mt)
|
||||
|
||||
--Work in progress
|
||||
199
Basalt/libraries/basaltMon.lua
Normal file
199
Basalt/libraries/basaltMon.lua
Normal file
@@ -0,0 +1,199 @@
|
||||
-- Right now this doesn't support scroll(n)
|
||||
-- Because this lbirary is mainly made for basalt - it doesn't need scroll support, maybe i will add it in the future
|
||||
|
||||
local tHex = {
|
||||
[colors.white] = "0",
|
||||
[colors.orange] = "1",
|
||||
[colors.magenta] = "2",
|
||||
[colors.lightBlue] = "3",
|
||||
[colors.yellow] = "4",
|
||||
[colors.lime] = "5",
|
||||
[colors.pink] = "6",
|
||||
[colors.gray] = "7",
|
||||
[colors.lightGray] = "8",
|
||||
[colors.cyan] = "9",
|
||||
[colors.purple] = "a",
|
||||
[colors.blue] = "b",
|
||||
[colors.brown] = "c",
|
||||
[colors.green] = "d",
|
||||
[colors.red] = "e",
|
||||
[colors.black] = "f",
|
||||
}
|
||||
|
||||
local type,len,rep,sub = type,string.len,string.rep,string.sub
|
||||
|
||||
|
||||
return function (monitorNames)
|
||||
local monitors = {}
|
||||
for k,v in pairs(monitorNames)do
|
||||
monitors[k] = {}
|
||||
for a,b in pairs(v)do
|
||||
local mon = peripheral.wrap(b)
|
||||
if(mon==nil)then
|
||||
error("Unable to find monitor "..b)
|
||||
end
|
||||
monitors[k][a] = mon
|
||||
monitors[k][a].name = b
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local x,y,monX,monY,monW,monH,w,h = 1,1,1,1,0,0,0,0
|
||||
local blink,scale = false,1
|
||||
local fg,bg = colors.white,colors.black
|
||||
|
||||
|
||||
local function calcSize()
|
||||
local maxW,maxH = 0,0
|
||||
for k,v in pairs(monitors)do
|
||||
local _maxW,_maxH = 0,0
|
||||
for a,b in pairs(v)do
|
||||
local nw,nh = b.getSize()
|
||||
_maxW = _maxW + nw
|
||||
_maxH = nh > _maxH and nh or _maxH
|
||||
end
|
||||
maxW = maxW > _maxW and maxW or _maxW
|
||||
maxH = maxH + _maxH
|
||||
end
|
||||
w,h = maxW,maxH
|
||||
end
|
||||
calcSize()
|
||||
|
||||
local function calcPosition()
|
||||
local relY = 0
|
||||
local mX,mY = 0,0
|
||||
for k,v in pairs(monitors)do
|
||||
local relX = 0
|
||||
local _mh = 0
|
||||
for a,b in pairs(v)do
|
||||
local mw,mh = b.getSize()
|
||||
if(x-relX>=1)and(x-relX<=mw)then
|
||||
mX = a
|
||||
end
|
||||
b.setCursorPos(x-relX, y-relY)
|
||||
relX = relX + mw
|
||||
if(_mh<mh)then _mh = mh end
|
||||
end
|
||||
if(y-relY>=1)and(y-relY<=_mh)then
|
||||
mY = k
|
||||
end
|
||||
relY = relY + _mh
|
||||
end
|
||||
monX,monY = mX,mY
|
||||
end
|
||||
calcPosition()
|
||||
|
||||
local function call(f, ...)
|
||||
local t = {...}
|
||||
return function()
|
||||
for k,v in pairs(monitors)do
|
||||
for a,b in pairs(v)do
|
||||
b[f](table.unpack(t))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function cursorBlink()
|
||||
call("setCursorBlink", false)()
|
||||
if not(blink)then return end
|
||||
if(monitors[monY]==nil)then return end
|
||||
local mon = monitors[monY][monX]
|
||||
if(mon==nil)then return end
|
||||
mon.setCursorBlink(blink)
|
||||
end
|
||||
|
||||
local function blit(text, tCol, bCol)
|
||||
if(monitors[monY]==nil)then return end
|
||||
local mon = monitors[monY][monX]
|
||||
if(mon==nil)then return end
|
||||
mon.blit(text, tCol, bCol)
|
||||
local mW, mH = mon.getSize()
|
||||
if(len(text)+x>mW)then
|
||||
local monRight = monitors[monY][monX+1]
|
||||
if(monRight~=nil)then
|
||||
monRight.blit(text, tCol, bCol)
|
||||
monX = monX + 1
|
||||
x = x + len(text)
|
||||
end
|
||||
end
|
||||
calcPosition()
|
||||
end
|
||||
|
||||
return {
|
||||
clear = call("clear"),
|
||||
|
||||
setCursorBlink = function(_blink)
|
||||
blink = _blink
|
||||
cursorBlink()
|
||||
end,
|
||||
|
||||
getCursorBlink = function()
|
||||
return blink
|
||||
end,
|
||||
|
||||
getCursorPos = function()
|
||||
return x, y
|
||||
end,
|
||||
|
||||
setCursorPos = function(newX,newY)
|
||||
x, y = newX, newY
|
||||
calcPosition()
|
||||
cursorBlink()
|
||||
end,
|
||||
|
||||
setTextScale = function(_scale)
|
||||
call("setTextScale", _scale)()
|
||||
calcSize()
|
||||
calcPosition()
|
||||
scale = _scale
|
||||
end,
|
||||
|
||||
getTextScale = function()
|
||||
return scale
|
||||
end,
|
||||
|
||||
blit = function(text,fgCol,bgCol)
|
||||
blit(text,fgCol,bgCol)
|
||||
end,
|
||||
|
||||
write = function(text)
|
||||
text = tostring(text)
|
||||
local l = len(text)
|
||||
blit(text, rep(tHex[fg], l), rep(tHex[bg], l))
|
||||
end,
|
||||
|
||||
getSize = function()
|
||||
return w,h
|
||||
end,
|
||||
|
||||
setBackgroundColor = function(col)
|
||||
call("setBackgroundColor", col)()
|
||||
bg = col
|
||||
end,
|
||||
|
||||
setTextColor = function(col)
|
||||
call("setTextColor", col)()
|
||||
fg = col
|
||||
end,
|
||||
|
||||
calculateClick = function(name, xClick, yClick)
|
||||
local relY = 0
|
||||
for k,v in pairs(monitors)do
|
||||
local relX = 0
|
||||
local maxY = 0
|
||||
for a,b in pairs(v)do
|
||||
local wM,hM = b.getSize()
|
||||
if(b.name==name)then
|
||||
return xClick + relX, yClick + relY
|
||||
end
|
||||
relX = relX + wM
|
||||
if(hM > maxY)then maxY = hM end
|
||||
end
|
||||
relY = relY + maxY
|
||||
end
|
||||
return xClick, yClick
|
||||
end,
|
||||
|
||||
}
|
||||
end
|
||||
@@ -3,13 +3,21 @@ local process = {}
|
||||
local processId = 0
|
||||
|
||||
function process:new(path, window, ...)
|
||||
local args = table.pack(...)
|
||||
local args = {...}
|
||||
local newP = setmetatable({ path = path }, { __index = self })
|
||||
newP.window = window
|
||||
newP.processId = processId
|
||||
if(type(path)=="string")then
|
||||
newP.coroutine = coroutine.create(function()
|
||||
os.run({ }, path, table.unpack(args))
|
||||
shell.execute(path, table.unpack(args))
|
||||
end)
|
||||
elseif(type(path)=="function")then
|
||||
newP.coroutine = coroutine.create(function()
|
||||
path(table.unpack(args))
|
||||
end)
|
||||
else
|
||||
return
|
||||
end
|
||||
processes[processId] = newP
|
||||
processId = processId + 1
|
||||
return newP
|
||||
@@ -17,12 +25,15 @@ end
|
||||
|
||||
function process:resume(event, ...)
|
||||
term.redirect(self.window)
|
||||
if(self.filter~=nil)then
|
||||
if(event~=self.filter)then return end
|
||||
self.filter=nil
|
||||
end
|
||||
local ok, result = coroutine.resume(self.coroutine, event, ...)
|
||||
self.window = term.current()
|
||||
if ok then
|
||||
self.filter = result
|
||||
else
|
||||
basalt.debug(result)
|
||||
error(result)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -48,6 +48,16 @@ rpairs = function(t)
|
||||
end, t, #t + 1
|
||||
end,
|
||||
|
||||
tableCount = function(t)
|
||||
local n = 0
|
||||
if(t~=nil)then
|
||||
for k,v in pairs(t)do
|
||||
n = n + 1
|
||||
end
|
||||
end
|
||||
return n
|
||||
end,
|
||||
|
||||
splitString = splitString,
|
||||
|
||||
createText = function(str, width)
|
||||
|
||||
180
Basalt/main.lua
180
Basalt/main.lua
@@ -2,24 +2,31 @@ local basaltEvent = require("basaltEvent")()
|
||||
local Frame = require("Frame")
|
||||
local theme = require("theme")
|
||||
local utils = require("utils")
|
||||
local log = require("basaltLogs")
|
||||
local uuid = utils.uuid
|
||||
local createText = utils.createText
|
||||
local count = utils.tableCount
|
||||
|
||||
|
||||
local baseTerm = term.current()
|
||||
local version = 5
|
||||
local version = "1.6.2"
|
||||
local debugger = true
|
||||
|
||||
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
|
||||
|
||||
local activeKey, frames, monFrames, variables, schedules = {}, {}, {}, {}, {}
|
||||
local activeKey, frames, monFrames, monGroups, variables, schedules = {}, {}, {}, {}, {}, {}
|
||||
local mainFrame, activeFrame, focusedObject, updaterActive
|
||||
|
||||
local basalt = {}
|
||||
|
||||
if not term.isColor or not term.isColor() then
|
||||
error('Basalt requires an advanced (golden) computer to run.', 0)
|
||||
end
|
||||
|
||||
local function stop()
|
||||
updaterActive = false
|
||||
updaterActive = false
|
||||
baseTerm.clear()
|
||||
baseTerm.setCursorPos(1, 1)
|
||||
end
|
||||
|
||||
local setVariable = function(name, var)
|
||||
@@ -68,11 +75,19 @@ local bInstance = {
|
||||
end,
|
||||
|
||||
getMonitorFrame = function(name)
|
||||
return monFrames[name]
|
||||
return monFrames[name] or monGroups[name][1]
|
||||
end,
|
||||
|
||||
setMonitorFrame = function(name, frame)
|
||||
monFrames[name] = frame
|
||||
setMonitorFrame = function(name, frame, isGroupedMon)
|
||||
if(mainFrame == frame)then mainFrame = nil end
|
||||
if(isGroupedMon)then
|
||||
monGroups[name] = {frame, sides}
|
||||
else
|
||||
monFrames[name] = frame
|
||||
end
|
||||
if(frame==nil)then
|
||||
monGroups[name] = nil
|
||||
end
|
||||
end,
|
||||
|
||||
getBaseTerm = function()
|
||||
@@ -92,34 +107,19 @@ local basaltError = function(errMsg)
|
||||
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
|
||||
if(basalt.logging)then
|
||||
log(errMsg, "Error")
|
||||
end
|
||||
|
||||
local text = createText("Basalt error: "..errMsg, w)
|
||||
local yPos = 1
|
||||
for k,v in pairs(text)do
|
||||
baseTerm.setCursorPos(1,yPos)
|
||||
baseTerm.write(v)
|
||||
yPos = yPos + 1
|
||||
end
|
||||
baseTerm.setCursorPos(1,yPos+1)
|
||||
updaterActive = false
|
||||
end
|
||||
|
||||
local function handleSchedules(event, p1, p2, p3, p4)
|
||||
@@ -144,15 +144,18 @@ local function handleSchedules(event, p1, p2, p3, p4)
|
||||
end
|
||||
|
||||
local function drawFrames()
|
||||
if(updaterActive)then
|
||||
if(mainFrame~=nil)then
|
||||
mainFrame:draw()
|
||||
mainFrame:drawUpdate()
|
||||
end
|
||||
for _,v in pairs(monFrames)do
|
||||
v:draw()
|
||||
v:drawUpdate()
|
||||
end
|
||||
if(updaterActive==false)then return end
|
||||
if(mainFrame~=nil)then
|
||||
mainFrame:draw()
|
||||
mainFrame:updateTerm()
|
||||
end
|
||||
for _,v in pairs(monFrames)do
|
||||
v:draw()
|
||||
v:updateTerm()
|
||||
end
|
||||
for _,v in pairs(monGroups)do
|
||||
v[1]:draw()
|
||||
v[1]:updateTerm()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -160,51 +163,70 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
||||
if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end
|
||||
if(mainFrame~=nil)then
|
||||
if (event == "mouse_click") then
|
||||
mainFrame:mouseHandler(event, p1, p2, p3, p4)
|
||||
mainFrame:mouseHandler(p1, p2, p3, false)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "mouse_drag") then
|
||||
mainFrame:mouseHandler(event, p1, p2, p3, p4)
|
||||
mainFrame:dragHandler(p1, p2, p3, p4)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "mouse_up") then
|
||||
mainFrame:mouseHandler(event, p1, p2, p3, p4)
|
||||
mainFrame:mouseUpHandler(p1, p2, p3, p4)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "mouse_scroll") then
|
||||
mainFrame:mouseHandler(event, p1, p2, p3, p4)
|
||||
mainFrame:scrollHandler(p1, p2, p3, p4)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "monitor_touch") then
|
||||
if(monFrames[p1]~=nil)then
|
||||
monFrames[p1]:mouseHandler(event, p1, p2, p3, p4)
|
||||
activeFrame = monFrames[p1]
|
||||
end
|
||||
end
|
||||
if(event == "monitor_touch") then
|
||||
if(monFrames[p1]~=nil)then
|
||||
monFrames[p1]:mouseHandler(1, p2, p3, true)
|
||||
activeFrame = monFrames[p1]
|
||||
end
|
||||
if(count(monGroups)>0)then
|
||||
for k,v in pairs(monGroups)do
|
||||
v[1]:mouseHandler(1, p2, p3, true, p1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if(event == "key") or (event == "char") then
|
||||
|
||||
|
||||
if(event == "char")then
|
||||
if(activeFrame~=nil)then
|
||||
activeFrame:keyHandler(event, p1)
|
||||
activeFrame:backgroundKeyHandler(event, p1)
|
||||
activeFrame:charHandler(p1)
|
||||
end
|
||||
end
|
||||
|
||||
if(event == "key")then
|
||||
activeKey[p1] = true
|
||||
end
|
||||
|
||||
if(event == "key_up")then
|
||||
if(activeFrame~=nil)then
|
||||
activeFrame:keyUpHandler(p1)
|
||||
end
|
||||
activeKey[p1] = false
|
||||
end
|
||||
|
||||
for _, v in pairs(frames) do
|
||||
v:eventHandler(event, p1, p2, p3, p4)
|
||||
if(event == "key")then
|
||||
if(activeFrame~=nil)then
|
||||
activeFrame:keyHandler(p1, p2)
|
||||
end
|
||||
activeKey[p1] = true
|
||||
end
|
||||
if(event == "terminate")then
|
||||
if(activeFrame~=nil)then
|
||||
activeFrame:eventHandler(event)
|
||||
if(updaterActive==false)then return end
|
||||
end
|
||||
end
|
||||
if(event~="mouse_click")and(event~="mouse_up")and(event~="mouse_scroll")and(event~="mouse_drag")and(event~="key")and(event~="key_up")and(event~="char")and(event~="terminate")then
|
||||
for k, v in pairs(frames) do
|
||||
v:eventHandler(event, p1, p2, p3, p4)
|
||||
end
|
||||
end
|
||||
handleSchedules(event, p1, p2, p3, p4)
|
||||
drawFrames()
|
||||
end
|
||||
|
||||
local basalt = {}
|
||||
basalt = {
|
||||
logging = false,
|
||||
setTheme = setTheme,
|
||||
getTheme = getTheme,
|
||||
drawFrames = drawFrames,
|
||||
getVersion = function()
|
||||
return version
|
||||
end,
|
||||
@@ -216,14 +238,29 @@ basalt = {
|
||||
baseTerm = _baseTerm
|
||||
end,
|
||||
|
||||
log = function(...)
|
||||
log(...)
|
||||
end,
|
||||
|
||||
autoUpdate = function(isActive)
|
||||
local pCall = pcall
|
||||
updaterActive = isActive
|
||||
if(isActive==nil)then updaterActive = true end
|
||||
drawFrames()
|
||||
while updaterActive do
|
||||
local event, p1, p2, p3, p4 = os.pullEventRaw()
|
||||
local ok, err = pCall(basaltUpdateEvent, event, p1, p2, p3, p4)
|
||||
local function f()
|
||||
drawFrames()
|
||||
while updaterActive do
|
||||
basaltUpdateEvent(os.pullEventRaw())
|
||||
end
|
||||
end
|
||||
local ok, err = xpcall(f, debug.traceback)
|
||||
if not(ok)then
|
||||
basaltError(err)
|
||||
return
|
||||
end
|
||||
end,
|
||||
|
||||
update = function(event, p1, p2, p3, p4)
|
||||
if (event ~= nil) then
|
||||
local ok, err = xpcall(basaltUpdateEvent, debug.traceback, event, p1, p2, p3, p4)
|
||||
if not(ok)then
|
||||
basaltError(err)
|
||||
return
|
||||
@@ -231,13 +268,8 @@ basalt = {
|
||||
end
|
||||
end,
|
||||
|
||||
update = function(event, p1, p2, p3, p4)
|
||||
if (event ~= nil) then
|
||||
basaltUpdateEvent(event, p1, p2, p3, p4)
|
||||
end
|
||||
end,
|
||||
|
||||
stop = stop,
|
||||
stopUpdate = stop,
|
||||
|
||||
isKeyDown = function(key)
|
||||
if(activeKey[key]==nil)then return false end
|
||||
@@ -293,6 +325,7 @@ basalt = {
|
||||
end
|
||||
end
|
||||
local newFrame = Frame(name,nil,nil,bInstance)
|
||||
newFrame:init()
|
||||
table.insert(frames, newFrame)
|
||||
if(mainFrame==nil)and(newFrame:getName()~="basaltDebuggingFrame")then
|
||||
newFrame:show()
|
||||
@@ -310,6 +343,7 @@ basalt = {
|
||||
|
||||
debug = function(...)
|
||||
local args = { ... }
|
||||
if(mainFrame==nil)then print(...) return end
|
||||
if (mainFrame.name ~= "basaltDebuggingFrame") then
|
||||
if (mainFrame ~= basalt.debugFrame) then
|
||||
basalt.debugLabel:setParent(mainFrame)
|
||||
@@ -336,7 +370,7 @@ basalt = {
|
||||
|
||||
basalt.debugFrame = basalt.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug", colors.black, colors.gray)
|
||||
basalt.debugFrame:addButton("back"):setAnchor("topRight"):setSize(1, 1):setText("\22"):onClick(function() if(basalt.oldFrame~=nil)then basalt.oldFrame:show() end end):setBackground(colors.red):show()
|
||||
basalt.debugList = basalt.debugFrame:addList("debugList"):setSize(basalt.debugFrame.width - 2, basalt.debugFrame.height - 3):setPosition(2, 3):setScrollable(true):show()
|
||||
basalt.debugList = basalt.debugFrame:addList("debugList"):setSize("parent.w - 2", "parent.h - 3"):setPosition(2, 3):setScrollable(true):show()
|
||||
basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() basalt.oldFrame = mainFrame basalt.debugFrame:show() end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottomLeft"):ignoreOffset():setZIndex(20):show()
|
||||
|
||||
return basalt
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
local basaltEvent = require("basaltEvent")
|
||||
|
||||
local floor = math.floor
|
||||
local floor,sin,cos,pi = math.floor,math.sin,math.cos,math.pi
|
||||
|
||||
local lerp = function(s, e, pct)
|
||||
return s + (e - s) * pct
|
||||
@@ -12,8 +11,8 @@ local linear = function (t)
|
||||
return t
|
||||
end
|
||||
|
||||
local flip = function (x)
|
||||
return 1 - x
|
||||
local flip = function (t)
|
||||
return 1 - t
|
||||
end
|
||||
|
||||
local easeIn = function (t)
|
||||
@@ -28,6 +27,18 @@ local easeInOut = function(t)
|
||||
return lerp(easeIn(t), easeOut(t), t)
|
||||
end
|
||||
|
||||
local easeOutSine = function(t)
|
||||
return sin((t * pi) / 2);
|
||||
end
|
||||
|
||||
local easeInSine = function(t)
|
||||
return flip(cos((t * pi) / 2))
|
||||
end
|
||||
|
||||
local easeInOutSine = function(t)
|
||||
return -(cos(pi * x) - 1) / 2
|
||||
end
|
||||
|
||||
local lerp = {
|
||||
linear = linear,
|
||||
lerp = lerp,
|
||||
@@ -35,8 +46,13 @@ local lerp = {
|
||||
easeIn=easeIn,
|
||||
easeOut=easeOut,
|
||||
easeInOut=easeInOut,
|
||||
easeOutSine = easeOutSine,
|
||||
easeInSine = easeInSine,
|
||||
easeInOutSine = easeInOutSine,
|
||||
}
|
||||
|
||||
local activeAnimations = {}
|
||||
|
||||
return function(name)
|
||||
local object = {}
|
||||
local objectType = "Animation"
|
||||
@@ -117,16 +133,36 @@ return function(name)
|
||||
end
|
||||
|
||||
|
||||
local function predefinedLerp(v1,v2,d,t,get,set)
|
||||
local function predefinedLerp(v1,v2,d,t,get,set,typ,self)
|
||||
local obj = _OBJ
|
||||
local x,y
|
||||
local name = ""
|
||||
if(obj.parent~=nil)then name = obj.parent:getName() end
|
||||
name = name..obj:getName()
|
||||
addAnimationPart(t+0.05, function()
|
||||
x,y = get(_OBJ)
|
||||
if(typ~=nil)then
|
||||
if(activeAnimations[typ]==nil)then activeAnimations[typ] = {} end
|
||||
if(activeAnimations[typ][name]~=nil)then
|
||||
if(activeAnimations[typ][name]~=self)then
|
||||
activeAnimations[typ][name]:cancel()
|
||||
end
|
||||
end
|
||||
activeAnimations[typ][name] = self
|
||||
end
|
||||
x,y = get(obj)
|
||||
end)
|
||||
for n=0.05,d,0.05 do
|
||||
for n=0.05,d+0.01,0.05 do
|
||||
addAnimationPart(t+n, function()
|
||||
local _x = math.floor(lerp.lerp(x, v1, lerp[mode](n / d))+0.5)
|
||||
local _y = math.floor(lerp.lerp(y, v2, lerp[mode](n / d))+0.5)
|
||||
set(_OBJ, _x,_y)
|
||||
set(obj, _x,_y)
|
||||
if(typ~=nil)then
|
||||
if(n>=d-0.01)then
|
||||
if(activeAnimations[typ][name]==self)then
|
||||
activeAnimations[typ][name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end;
|
||||
@@ -274,19 +310,19 @@ return function(name)
|
||||
|
||||
move = function(self, x, y, duration, timer, obj)
|
||||
_OBJ = obj or _OBJ
|
||||
predefinedLerp(x,y,duration,timer or 0,_OBJ.getPosition,_OBJ.setPosition)
|
||||
predefinedLerp(x,y,duration,timer or 0,_OBJ.getPosition,_OBJ.setPosition, "position", self)
|
||||
return self
|
||||
end,
|
||||
|
||||
offset = function(self, x, y, duration, timer, obj)
|
||||
_OBJ = obj or _OBJ
|
||||
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset)
|
||||
predefinedLerp(x,y,duration,timer or 0,_OBJ.getOffset,_OBJ.setOffset, "offset", self)
|
||||
return self
|
||||
end,
|
||||
|
||||
size = function(self, w, h, duration, timer, obj)
|
||||
_OBJ = obj or _OBJ
|
||||
predefinedLerp(w,h,duration,timer or 0,_OBJ.getSize,_OBJ.setSize)
|
||||
predefinedLerp(w,h,duration,timer or 0,_OBJ.getSize,_OBJ.setSize, "size", self)
|
||||
return self
|
||||
end,
|
||||
|
||||
@@ -363,6 +399,7 @@ return function(name)
|
||||
|
||||
animationDoneHandler = function(self)
|
||||
eventSystem:sendEvent("animation_done", self)
|
||||
self.parent:removeEvent("other_event", self)
|
||||
if(autoDestroy)then
|
||||
self.parent:removeObject(self)
|
||||
self = nil
|
||||
@@ -393,11 +430,12 @@ return function(name)
|
||||
if (animations[index].t > 0) then
|
||||
timerObj = os.startTimer(animations[index].t)
|
||||
else
|
||||
onPlay()
|
||||
onPlay(self)
|
||||
end
|
||||
else
|
||||
self:animationDoneHandler()
|
||||
end
|
||||
self.parent:addEvent("other_event", self)
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -407,6 +445,7 @@ return function(name)
|
||||
infinitePlay = false
|
||||
end
|
||||
animationActive = false
|
||||
self.parent:removeEvent("other_event", self)
|
||||
return self
|
||||
end;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local Object = require("Object")
|
||||
local utils = require("utils")
|
||||
local xmlValue = utils.getValueFromXML
|
||||
local tHex = require("tHex")
|
||||
|
||||
return function(name)
|
||||
-- Button
|
||||
@@ -24,14 +25,19 @@ return function(name)
|
||||
end;
|
||||
setHorizontalAlign = function(self, pos)
|
||||
textHorizontalAlign = pos
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setVerticalAlign = function(self, pos)
|
||||
textVerticalAlign = pos
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setText = function(self, text)
|
||||
base:setValue(text)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -50,20 +56,15 @@ return function(name)
|
||||
local w,h = self:getSize()
|
||||
local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign)
|
||||
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
|
||||
self.parent:drawTextBox(obx, oby, w, h, " ")
|
||||
end
|
||||
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end
|
||||
for n = 1, h do
|
||||
if (n == verticalAlign) then
|
||||
self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign))
|
||||
self.parent:setFG(obx, oby + (n - 1), utils.getTextHorizontalAlign(tHex[self.fgColor]:rep(self:getValue():len()), w, textHorizontalAlign))
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
}
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -12,31 +12,38 @@ return function(name)
|
||||
base.width = 1
|
||||
base.height = 1
|
||||
|
||||
local object = {
|
||||
symbol = "\42",
|
||||
local symbol = "\42"
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("CheckboxBG")
|
||||
self.fgColor = self.parent:getTheme("CheckboxText")
|
||||
end,
|
||||
local object = {
|
||||
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
|
||||
setSymbol = function(self, sym)
|
||||
symbol = sym
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
if(button == 1)then
|
||||
if (self:getValue() ~= true) and (self:getValue() ~= false) then
|
||||
self:setValue(false)
|
||||
else
|
||||
self:setValue(not self:getValue())
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end;
|
||||
end,
|
||||
|
||||
touchHandler = function(self, x, y)
|
||||
return self:mouseHandler(1, x, y)
|
||||
end,
|
||||
|
||||
setValuesByXMLData = function(self, data)
|
||||
base.setValuesByXMLData(self, data)
|
||||
@@ -54,17 +61,22 @@ return function(name)
|
||||
for n = 1, h do
|
||||
if (n == verticalAlign) then
|
||||
if (self:getValue() == true) then
|
||||
self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self.symbol, w, "center"), self.bgColor, self.fgColor)
|
||||
self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(symbol, w, "center"), self.bgColor, self.fgColor)
|
||||
else
|
||||
self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(" ", w, "center"), self.bgColor, self.fgColor)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
base.init(self)
|
||||
self.bgColor = self.parent:getTheme("CheckboxBG")
|
||||
self.fgColor = self.parent:getTheme("CheckboxText")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -26,12 +26,6 @@ return function(name)
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("DropdownBG")
|
||||
self.fgColor = self.parent:getTheme("DropdownText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
end,
|
||||
|
||||
setValuesByXMLData = function(self, data)
|
||||
base.setValuesByXMLData(self, data)
|
||||
@@ -51,6 +45,7 @@ return function(name)
|
||||
|
||||
setOffset = function(self, yOff)
|
||||
yOffset = yOff
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -60,6 +55,7 @@ return function(name)
|
||||
|
||||
addItem = function(self, text, bgCol, fgCol, ...)
|
||||
table.insert(list, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -69,6 +65,7 @@ return function(name)
|
||||
|
||||
removeItem = function(self, index)
|
||||
table.remove(list, index)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -88,6 +85,7 @@ return function(name)
|
||||
clear = function(self)
|
||||
list = {}
|
||||
self:setValue({})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -98,11 +96,13 @@ return function(name)
|
||||
editItem = function(self, index, text, bgCol, fgCol, ...)
|
||||
table.remove(list, index)
|
||||
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
selectItem = function(self, index)
|
||||
self:setValue(list[index] or {})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -110,55 +110,90 @@ return function(name)
|
||||
itemSelectedBG = bgCol or self.bgColor
|
||||
itemSelectedFG = fgCol or self.fgColor
|
||||
selectionColorActive = active
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setDropdownSize = function(self, width, height)
|
||||
dropdownW, dropdownH = width, height
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (isOpened) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
|
||||
|
||||
if(button==1)then
|
||||
if (#list > 0) then
|
||||
for n = 1, dropdownH do
|
||||
if (list[n + yOffset] ~= nil) then
|
||||
if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then
|
||||
self:setValue(list[n + yOffset])
|
||||
self:updateDraw()
|
||||
local val = self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", dir, x, y)
|
||||
if(val==false)then return val end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
isOpened = (not isOpened)
|
||||
self:updateDraw()
|
||||
return true
|
||||
else
|
||||
if(isOpened)then
|
||||
self:updateDraw()
|
||||
isOpened = false
|
||||
end
|
||||
return false
|
||||
end
|
||||
end,
|
||||
|
||||
if (event == "mouse_scroll") then
|
||||
yOffset = yOffset + button
|
||||
if (yOffset < 0) then
|
||||
yOffset = 0
|
||||
end
|
||||
if (button == 1) then
|
||||
if (#list > dropdownH) then
|
||||
if (yOffset > #list - dropdownH) then
|
||||
yOffset = #list - dropdownH
|
||||
mouseUpHandler = function(self, button, x, y)
|
||||
if (isOpened) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if(button==1)then
|
||||
if (#list > 0) then
|
||||
for n = 1, dropdownH do
|
||||
if (list[n + yOffset] ~= nil) then
|
||||
if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then
|
||||
isOpened = false
|
||||
self:updateDraw()
|
||||
local val = self:getEventSystem():sendEvent("mouse_up", self, "mouse_up", dir, x, y)
|
||||
if(val==false)then return val end
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
yOffset = math.min(#list - 1, 0)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
self:setVisualChanged()
|
||||
end
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
isOpened = true
|
||||
else
|
||||
isOpened = false
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if (isOpened)and(self:isFocused()) then
|
||||
yOffset = yOffset + dir
|
||||
if (yOffset < 0) then
|
||||
yOffset = 0
|
||||
end
|
||||
if (dir == 1) then
|
||||
if (#list > dropdownH) then
|
||||
if (yOffset > #list - dropdownH) then
|
||||
yOffset = #list - dropdownH
|
||||
end
|
||||
else
|
||||
yOffset = math.min(#list - 1, 0)
|
||||
end
|
||||
end
|
||||
local val = self:getEventSystem():sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y)
|
||||
if(val==false)then return val end
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
@@ -186,9 +221,20 @@ return function(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("DropdownBG")
|
||||
self.fgColor = self.parent:getTheme("DropdownText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -142,6 +142,7 @@ return function(name)
|
||||
loadImage = function(self, path)
|
||||
image = paintutils.loadImage(path)
|
||||
imageGotShrinked = false
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -149,6 +150,7 @@ return function(name)
|
||||
shrink = function(self)
|
||||
shrink()
|
||||
imageGotShrinked = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -192,9 +194,8 @@ return function(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local Object = require("Object")
|
||||
local utils = require("utils")
|
||||
local log = require("basaltLogs")
|
||||
local xmlValue = utils.getValueFromXML
|
||||
|
||||
return function(name)
|
||||
@@ -24,10 +25,6 @@ return function(name)
|
||||
local internalValueChange = false
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("InputBG")
|
||||
self.fgColor = self.parent:getTheme("InputFG")
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
@@ -36,6 +33,7 @@ return function(name)
|
||||
if (iType == "password") or (iType == "number") or (iType == "text") then
|
||||
inputType = iType
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -48,6 +46,7 @@ return function(name)
|
||||
else
|
||||
showingText = defaultText
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -58,8 +57,14 @@ return function(name)
|
||||
setValue = function(self, val)
|
||||
base.setValue(self, tostring(val))
|
||||
if not (internalValueChange) then
|
||||
textX = tostring(val):len() + 1
|
||||
if(self:isFocused())then
|
||||
textX = tostring(val):len() + 1
|
||||
wIndex = math.max(1, textX-self:getWidth()+1)
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self:getHeight()/2), self.fgColor)
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -70,6 +75,7 @@ return function(name)
|
||||
|
||||
setInputLimit = function(self, limit)
|
||||
inputLimit = tonumber(limit) or inputLimit
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -93,25 +99,28 @@ return function(name)
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
showingText = ""
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self.height/2), self.fgColor)
|
||||
if(defaultText~="")then
|
||||
self:updateDraw()
|
||||
end
|
||||
self.parent:setCursor(true, obx + textX - wIndex, oby+math.max(math.ceil(self:getHeight()/2-1, 1)), self.fgColor)
|
||||
end
|
||||
end;
|
||||
|
||||
loseFocusHandler = function(self)
|
||||
base.loseFocusHandler(self)
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(false)
|
||||
showingText = defaultText
|
||||
if(defaultText~="")then
|
||||
self:updateDraw()
|
||||
end
|
||||
self.parent:setCursor(false)
|
||||
end
|
||||
end;
|
||||
|
||||
keyHandler = function(self, event, key)
|
||||
if (base.keyHandler(self, event, key)) then
|
||||
keyHandler = function(self, key)
|
||||
if (base.keyHandler(self, key)) then
|
||||
local w,h = self:getSize()
|
||||
internalValueChange = true
|
||||
if (event == "key") then
|
||||
if (key == keys.backspace) then
|
||||
-- on backspace
|
||||
local text = tostring(base.getValue())
|
||||
@@ -167,52 +176,138 @@ return function(name)
|
||||
wIndex = 1
|
||||
end
|
||||
end
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local val = tostring(base.getValue())
|
||||
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
|
||||
|
||||
local inpX = self:getX()
|
||||
if (cursorX > inpX + w - 1) then
|
||||
cursorX = inpX + w - 1
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||
end
|
||||
self:updateDraw()
|
||||
internalValueChange = false
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
if (event == "char") then
|
||||
local text = base.getValue()
|
||||
if (text:len() < inputLimit or inputLimit <= 0) then
|
||||
if (inputType == "number") then
|
||||
local cache = text
|
||||
if (key == ".") or (tonumber(key) ~= nil) then
|
||||
self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len()))
|
||||
textX = textX + 1
|
||||
end
|
||||
if (tonumber(base.getValue()) == nil) then
|
||||
self:setValue(cache)
|
||||
end
|
||||
else
|
||||
self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len()))
|
||||
charHandler = function(self, char)
|
||||
if (base.charHandler(self, char)) then
|
||||
internalValueChange = true
|
||||
local w,h = self:getSize()
|
||||
local text = base.getValue()
|
||||
if (text:len() < inputLimit or inputLimit <= 0) then
|
||||
if (inputType == "number") then
|
||||
local cache = text
|
||||
if (char == ".") or (tonumber(char) ~= nil) then
|
||||
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
|
||||
textX = textX + 1
|
||||
end
|
||||
if (textX >= w + wIndex) then
|
||||
wIndex = wIndex + 1
|
||||
if (tonumber(base.getValue()) == nil) then
|
||||
self:setValue(cache)
|
||||
end
|
||||
else
|
||||
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
|
||||
textX = textX + 1
|
||||
end
|
||||
if (textX >= w + wIndex) then
|
||||
wIndex = wIndex + 1
|
||||
end
|
||||
end
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local val = tostring(base.getValue())
|
||||
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
|
||||
|
||||
if (cursorX > self.x + w - 1) then
|
||||
cursorX = self.x + w - 1
|
||||
local x = self:getX()
|
||||
if (cursorX > x + w - 1) then
|
||||
cursorX = x + w - 1
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.floor(h/2), self.fgColor)
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||
end
|
||||
internalValueChange = false
|
||||
end
|
||||
end;
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
if (event == "mouse_click") and (button == 1) then
|
||||
|
||||
end
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end;
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if(base.mouseHandler(self, button, x, y))then
|
||||
local ax, ay = self:getAnchorPosition()
|
||||
local obx, oby = self:getAbsolutePosition(ax, ay)
|
||||
local w, h = self:getSize()
|
||||
textX = x - obx + wIndex
|
||||
local text = base.getValue()
|
||||
if (textX > text:len()) then
|
||||
textX = text:len() + 1
|
||||
end
|
||||
if (textX < wIndex) then
|
||||
wIndex = textX - 1
|
||||
if (wIndex < 1) then
|
||||
wIndex = 1
|
||||
end
|
||||
end
|
||||
self.parent:setCursor(true, ax + textX - wIndex, ay+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||
return true
|
||||
end
|
||||
end,
|
||||
|
||||
dragHandler = function(self, btn, x, y, xOffset, yOffset)
|
||||
if(self:isFocused())then
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
if(base.dragHandler(self, btn, x, y, xOffset, yOffset))then
|
||||
return true
|
||||
end
|
||||
end
|
||||
self.parent:removeFocusedObject()
|
||||
end
|
||||
end,
|
||||
|
||||
eventHandler = function(self, event, paste, p2, p3, p4)
|
||||
if(base.eventHandler(self, event, paste, p2, p3, p4))then
|
||||
if(event=="paste")then
|
||||
if(self:isFocused())then
|
||||
local text = base.getValue()
|
||||
local w, h = self:getSize()
|
||||
internalValueChange = true
|
||||
if (inputType == "number") then
|
||||
local cache = text
|
||||
if (paste == ".") or (tonumber(paste) ~= nil) then
|
||||
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
|
||||
textX = textX + paste:len()
|
||||
end
|
||||
if (tonumber(base.getValue()) == nil) then
|
||||
self:setValue(cache)
|
||||
end
|
||||
else
|
||||
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
|
||||
textX = textX + paste:len()
|
||||
end
|
||||
if (textX >= w + wIndex) then
|
||||
wIndex = (textX+1)-w
|
||||
end
|
||||
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local val = tostring(base.getValue())
|
||||
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
|
||||
|
||||
local x = self:getX()
|
||||
if (cursorX > x + w - 1) then
|
||||
cursorX = x + w - 1
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||
end
|
||||
self:updateDraw()
|
||||
internalValueChange = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
@@ -246,14 +341,28 @@ return function(name)
|
||||
if (inputType == "password") and (val ~= "") then
|
||||
text = string.rep("*", text:len())
|
||||
end
|
||||
text = text .. string.rep(" ", space)
|
||||
text = text .. string.rep(self.bgSymbol, space)
|
||||
self.parent:writeText(obx, oby + (n - 1), text, bCol, fCol)
|
||||
end
|
||||
end
|
||||
if(self:isFocused())then
|
||||
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self:getHeight()/2), self.fgColor)
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("InputBG")
|
||||
self.fgColor = self.parent:getTheme("InputText")
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("key", self)
|
||||
self.parent:addEvent("char", self)
|
||||
self.parent:addEvent("other_event", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -33,27 +33,28 @@ return function(name)
|
||||
if (autoSize) then
|
||||
self.width = text:len()
|
||||
end
|
||||
if not(fgColChanged)then self.fgColor = self.parent:getForeground() or colors.white end
|
||||
if not(bgColChanged)then self.bgColor = self.parent:getBackground() or colors.black end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setBackground = function(self, col)
|
||||
base.setBackground(self, col)
|
||||
bgColChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
setForeground = function(self, col)
|
||||
base.setForeground(self, col)
|
||||
fgColChanged = true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
setTextAlign = function(self, hor, vert)
|
||||
textHorizontalAlign = hor or textHorizontalAlign
|
||||
textVerticalAlign = vert or textVerticalAlign
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -61,6 +62,7 @@ return function(name)
|
||||
if(size>0)and(size<=4)then
|
||||
fontsize = size-1 or 0
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -77,10 +79,10 @@ return function(name)
|
||||
return self
|
||||
end,
|
||||
|
||||
setSize = function(self, width, height)
|
||||
base.setSize(self, width, height)
|
||||
setSize = function(self, width, height, rel)
|
||||
base.setSize(self, width, height, rel)
|
||||
autoSize = false
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -90,47 +92,43 @@ return function(name)
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign)
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
|
||||
self.parent:drawTextBox(obx, oby, w, h, " ") end
|
||||
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end
|
||||
if(fontsize==0)then
|
||||
if not(autoSize)then
|
||||
local text = createText(self:getValue(), self:getWidth())
|
||||
for k,v in pairs(text)do
|
||||
self.parent:setText(obx, oby+k-1, v)
|
||||
self.parent:writeText(obx, oby+k-1, v, self.bgColor, self.fgColor)
|
||||
end
|
||||
else
|
||||
for n = 1, h do
|
||||
if (n == verticalAlign) then
|
||||
self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign))
|
||||
end
|
||||
end
|
||||
self.parent:writeText(obx, oby, self:getValue(), self.bgColor, self.fgColor)
|
||||
end
|
||||
else
|
||||
local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.black)
|
||||
local tData = bigFont(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.lightGray)
|
||||
if(autoSize)then
|
||||
self:setSize(#tData[1][1], #tData[1]-1)
|
||||
end
|
||||
for n = 1, h do
|
||||
if (n == verticalAlign) then
|
||||
local oX, oY = self.parent:getSize()
|
||||
local cX, cY = #tData[1][1], #tData[1]
|
||||
obx = obx or math.floor((oX - cX) / 2) + 1
|
||||
oby = oby or math.floor((oY - cY) / 2) + 1
|
||||
|
||||
for i = 1, cY do
|
||||
self.parent:setFG(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[2][i], w, textHorizontalAlign))
|
||||
self.parent:setBG(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[3][i], w, textHorizontalAlign, tHex[self.bgColor or colors.black]))
|
||||
self.parent:setText(obx, oby + i + n - 2, utils.getTextHorizontalAlign(tData[1][i], w, textHorizontalAlign))
|
||||
end
|
||||
local oX, oY = self.parent:getSize()
|
||||
local cX, cY = #tData[1][1], #tData[1]
|
||||
obx = obx or math.floor((oX - cX) / 2) + 1
|
||||
oby = oby or math.floor((oY - cY) / 2) + 1
|
||||
|
||||
for i = 1, cY do
|
||||
self.parent:setFG(obx, oby + i - 2, tData[2][i])
|
||||
self.parent:setBG(obx, oby + i - 2, tData[3][i])
|
||||
self.parent:setText(obx, oby + i - 2, tData[1][i])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
init = function(self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("LabelBG")
|
||||
self.fgColor = self.parent:getTheme("LabelText")
|
||||
if(self.parent.bgColor==colors.black)and(self.fgColor==colors.black)then
|
||||
self.fgColor = colors.lightGray
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,6 @@ return function(name)
|
||||
local scrollable = true
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ListBG")
|
||||
self.fgColor = self.parent:getTheme("ListText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
@@ -33,11 +27,13 @@ return function(name)
|
||||
if (#list == 1) then
|
||||
self:setValue(list[1])
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setOffset = function(self, yOff)
|
||||
yOffset = yOff
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -47,6 +43,7 @@ return function(name)
|
||||
|
||||
removeItem = function(self, index)
|
||||
table.remove(list, index)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -70,6 +67,7 @@ return function(name)
|
||||
clear = function(self)
|
||||
list = {}
|
||||
self:setValue({})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -80,23 +78,28 @@ return function(name)
|
||||
editItem = function(self, index, text, bgCol, fgCol, ...)
|
||||
table.remove(list, index)
|
||||
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
selectItem = function(self, index)
|
||||
self:setValue(list[index] or {})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setSelectedItem = function(self, bgCol, fgCol, active)
|
||||
itemSelectedBG = bgCol or self.bgColor
|
||||
itemSelectedFG = fgCol or self.fgColor
|
||||
selectionColorActive = active
|
||||
selectionColorActive = active~=nil and active or true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setScrollable = function(self, scroll)
|
||||
scrollable = scroll
|
||||
if(scroll==nil)then scrollable = true end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -116,29 +119,15 @@ return function(name)
|
||||
return self
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local w,h = self:getSize()
|
||||
if (obx <= x) and (obx + w > x) and (oby <= y) and (oby + h > y) and (self:isVisible()) then
|
||||
if (((event == "mouse_click") or (event == "mouse_drag"))and(button==1))or(event=="monitor_touch") then
|
||||
if (#list > 0) then
|
||||
for n = 1, h do
|
||||
if (list[n + yOffset] ~= nil) then
|
||||
if (obx <= x) and (obx + w > x) and (oby + n - 1 == y) then
|
||||
self:setValue(list[n + yOffset])
|
||||
self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n + yOffset])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (event == "mouse_scroll") and (scrollable) then
|
||||
yOffset = yOffset + button
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if(base.scrollHandler(self, dir, x, y))then
|
||||
if(scrollable)then
|
||||
local w,h = self:getSize()
|
||||
yOffset = yOffset + dir
|
||||
if (yOffset < 0) then
|
||||
yOffset = 0
|
||||
end
|
||||
if (button >= 1) then
|
||||
if (dir >= 1) then
|
||||
if (#list > h) then
|
||||
if (yOffset > #list - h) then
|
||||
yOffset = #list - h
|
||||
@@ -150,11 +139,39 @@ return function(name)
|
||||
yOffset = yOffset - 1
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
end
|
||||
self:setVisualChanged()
|
||||
return true
|
||||
end
|
||||
end;
|
||||
return false
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if(base.mouseHandler(self, button, x, y))then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local w,h = self:getSize()
|
||||
if (#list > 0) then
|
||||
for n = 1, h do
|
||||
if (list[n + yOffset] ~= nil) then
|
||||
if (obx <= x) and (obx + w > x) and (oby + n - 1 == y) then
|
||||
self:setValue(list[n + yOffset])
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
dragHandler = function(self, button, x, y)
|
||||
return self:mouseHandler(button, x, y)
|
||||
end,
|
||||
|
||||
touchHandler = function(self, x, y)
|
||||
return self:mouseHandler(1, x, y)
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
@@ -178,9 +195,18 @@ return function(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ListBG")
|
||||
self.fgColor = self.parent:getTheme("ListText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -40,13 +40,6 @@ return function(name)
|
||||
end
|
||||
|
||||
object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("MenubarBG")
|
||||
self.fgColor = self.parent:getTheme("MenubarText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
end,
|
||||
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
@@ -56,6 +49,7 @@ return function(name)
|
||||
if (#list == 1) then
|
||||
self:setValue(list[1])
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -75,11 +69,13 @@ return function(name)
|
||||
clear = function(self)
|
||||
list = {}
|
||||
self:setValue({})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setSpace = function(self, _space)
|
||||
space = _space or space
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -93,6 +89,7 @@ return function(name)
|
||||
if (itemOffset > mScroll) then
|
||||
itemOffset = mScroll
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -125,6 +122,7 @@ return function(name)
|
||||
|
||||
removeItem = function(self, index)
|
||||
table.remove(list, index)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -139,11 +137,13 @@ return function(name)
|
||||
editItem = function(self, index, text, bgCol, fgCol, ...)
|
||||
table.remove(list, index)
|
||||
table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
selectItem = function(self, index)
|
||||
self:setValue(list[index] or {})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -151,48 +151,49 @@ return function(name)
|
||||
itemSelectedBG = bgCol or self.bgColor
|
||||
itemSelectedFG = fgCol or self.fgColor
|
||||
selectionColorActive = active
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if(base.mouseHandler(self, event, button, x, y))then
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if(base.mouseHandler(self, button, x, y))then
|
||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local w,h = self:getSize()
|
||||
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) and (self:isVisible()) then
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
if (event == "mouse_click") or (event == "monitor_touch") then
|
||||
local xPos = 0
|
||||
for n = 1, #list do
|
||||
if (list[n] ~= nil) then
|
||||
if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then
|
||||
self:setValue(list[n])
|
||||
self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
|
||||
end
|
||||
xPos = xPos + list[n].text:len() + space * 2
|
||||
local xPos = 0
|
||||
for n = 1, #list do
|
||||
if (list[n] ~= nil) then
|
||||
if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then
|
||||
self:setValue(list[n])
|
||||
self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
if (event == "mouse_scroll") and (scrollable) then
|
||||
itemOffset = itemOffset + button
|
||||
if (itemOffset < 0) then
|
||||
itemOffset = 0
|
||||
end
|
||||
|
||||
local mScroll = maxScroll()
|
||||
|
||||
if (itemOffset > mScroll) then
|
||||
itemOffset = mScroll
|
||||
xPos = xPos + list[n].text:len() + space * 2
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(true)
|
||||
return true
|
||||
end
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end;
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if(base.scrollHandler(self, dir, x, y))then
|
||||
if(scrollable)then
|
||||
itemOffset = itemOffset + dir
|
||||
if (itemOffset < 0) then
|
||||
itemOffset = 0
|
||||
end
|
||||
|
||||
local mScroll = maxScroll()
|
||||
|
||||
if (itemOffset > mScroll) then
|
||||
itemOffset = mScroll
|
||||
end
|
||||
self:updateDraw()
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
@@ -221,9 +222,19 @@ return function(name)
|
||||
self.parent:setBG(obx, oby, textBGCol:sub(itemOffset+1, w+itemOffset))
|
||||
self.parent:setFG(obx, oby, textFGCol:sub(itemOffset+1, w+itemOffset))
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("MenubarBG")
|
||||
self.fgColor = self.parent:getTheme("MenubarText")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local Object = require("Object")
|
||||
local log = require("basaltLogs")
|
||||
|
||||
return function(name)
|
||||
-- Pane
|
||||
@@ -6,26 +7,21 @@ return function(name)
|
||||
local objectType = "Pane"
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("PaneBG")
|
||||
self.fgColor = self.parent:getTheme("PaneBG")
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
|
||||
self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor)
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
setBackground = function(self, col, sym, symC)
|
||||
base.setBackground(self, col, sym, symC)
|
||||
return self
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
if(base.init(self))then
|
||||
self.bgColor = self.parent:getTheme("PaneBG")
|
||||
self.fgColor = self.parent:getTheme("PaneBG")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -2,6 +2,7 @@ local Object = require("Object")
|
||||
local tHex = require("tHex")
|
||||
local process = require("process")
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
local log = require("basaltLogs")
|
||||
|
||||
local sub = string.sub
|
||||
|
||||
@@ -12,7 +13,7 @@ return function(name, parent)
|
||||
local object
|
||||
local cachedPath
|
||||
|
||||
local function createBasaltWindow(x, y, width, height)
|
||||
local function createBasaltWindow(x, y, width, height, self)
|
||||
local xCursor, yCursor = 1, 1
|
||||
local bgColor, fgColor = colors.black, colors.white
|
||||
local cursorBlink = false
|
||||
@@ -51,6 +52,7 @@ return function(name, parent)
|
||||
cacheFG[n] = sub(cacheFG[n] == nil and emptyFG or cacheFG[n] .. emptyFG:sub(1, width - cacheFG[n]:len()), 1, width)
|
||||
cacheBG[n] = sub(cacheBG[n] == nil and emptyBG or cacheBG[n] .. emptyBG:sub(1, width - cacheBG[n]:len()), 1, width)
|
||||
end
|
||||
base.updateDraw(base)
|
||||
end
|
||||
recreateWindowArray()
|
||||
|
||||
@@ -118,6 +120,7 @@ return function(name, parent)
|
||||
cacheFG[yCursor] = sNewTextColor
|
||||
cacheBG[yCursor] = sNewBackgroundColor
|
||||
end
|
||||
object:updateDraw()
|
||||
end
|
||||
xCursor = nEnd + 1
|
||||
if (visible) then
|
||||
@@ -133,6 +136,7 @@ return function(name, parent)
|
||||
cacheT[_y] = sub(gText:sub(1, _x - 1) .. text .. gText:sub(_x + (text:len()), width), 1, width)
|
||||
end
|
||||
end
|
||||
object:updateDraw()
|
||||
end
|
||||
|
||||
local function setBG(_x, _y, colorStr)
|
||||
@@ -142,6 +146,7 @@ return function(name, parent)
|
||||
cacheBG[_y] = sub(gBG:sub(1, _x - 1) .. colorStr .. gBG:sub(_x + (colorStr:len()), width), 1, width)
|
||||
end
|
||||
end
|
||||
object:updateDraw()
|
||||
end
|
||||
|
||||
local function setFG(_x, _y, colorStr)
|
||||
@@ -151,6 +156,7 @@ return function(name, parent)
|
||||
cacheFG[_y] = sub(gFG:sub(1, _x - 1) .. colorStr .. gFG:sub(_x + (colorStr:len()), width), 1, width)
|
||||
end
|
||||
end
|
||||
object:updateDraw()
|
||||
end
|
||||
|
||||
local setTextColor = function(color)
|
||||
@@ -417,10 +423,43 @@ return function(name, parent)
|
||||
local paused = false
|
||||
local queuedEvent = {}
|
||||
|
||||
local function updateCursor(self)
|
||||
local xCur, yCur = pWindow.getCursorPos()
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
|
||||
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
||||
end
|
||||
end
|
||||
|
||||
local function mouseEvent(self, event, p1, x, y)
|
||||
if (curProcess == nil) then
|
||||
return false
|
||||
end
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
|
||||
curProcess:resume(event, p1, x-absX+1, y-absY+1)
|
||||
updateCursor(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function keyEvent(self, event, key, isHolding)
|
||||
if (curProcess == nil) then
|
||||
return false
|
||||
end
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
if (self.draw) then
|
||||
curProcess:resume(event, key, isHolding)
|
||||
updateCursor(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ProgramBG")
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
@@ -461,7 +500,7 @@ return function(name, parent)
|
||||
|
||||
setSize = function(self, width, height, rel)
|
||||
base.setSize(self, width, height, rel)
|
||||
pWindow.basalt_resize(self:getSize())
|
||||
pWindow.basalt_resize(self:getWidth(), self:getHeight())
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -484,6 +523,16 @@ return function(name, parent)
|
||||
pWindow.basalt_setVisible(true)
|
||||
curProcess:resume()
|
||||
paused = false
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_up", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
self.parent:addEvent("key", self)
|
||||
self.parent:addEvent("key_up", self)
|
||||
self.parent:addEvent("char", self)
|
||||
self.parent:addEvent("other_event", self)
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -498,6 +547,7 @@ return function(name, parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
self.parent:removeEvents(self)
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -551,36 +601,61 @@ return function(name, parent)
|
||||
return self
|
||||
end;
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
if (curProcess == nil) then
|
||||
return false
|
||||
end
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
|
||||
curProcess:resume(event, button, x-absX+1, y-absY+1)
|
||||
end
|
||||
end
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
mouseEvent(self, "mouse_click", button, x, y)
|
||||
return true
|
||||
end
|
||||
end;
|
||||
return false
|
||||
end,
|
||||
|
||||
keyHandler = function(self, event, key)
|
||||
base.keyHandler(self, event, key)
|
||||
if (self:isFocused()) then
|
||||
if (curProcess == nil) then
|
||||
return false
|
||||
end
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
if (self.draw) then
|
||||
curProcess:resume(event, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
mouseUpHandler = function(self, button, x, y)
|
||||
if (base.mouseUpHandler(self, button, x, y)) then
|
||||
mouseEvent(self, "mouse_up", button, x, y)
|
||||
return true
|
||||
end
|
||||
end;
|
||||
return false
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if (base.scrollHandler(self, dir, x, y)) then
|
||||
mouseEvent(self, "mouse_scroll", dir, x, y)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
dragHandler = function(self, button, x, y)
|
||||
if (base.dragHandler(self, button, x, y)) then
|
||||
mouseEvent(self, "mouse_drag", button, x, y)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
keyHandler = function(self, key, isHolding)
|
||||
if(base.keyHandler(self, key, isHolding))then
|
||||
keyEvent(self, "key", key, isHolding)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
keyUpHandler = function(self, key)
|
||||
if(base.keyUpHandler(self, key))then
|
||||
keyEvent(self, "key_up", key)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
charHandler = function(self, char)
|
||||
if(base.charHandler(self, char))then
|
||||
keyEvent(self, "char", char)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
getFocusHandler = function(self)
|
||||
base.getFocusHandler(self)
|
||||
@@ -600,7 +675,7 @@ return function(name, parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
loseFocusHandler = function(self)
|
||||
base.loseFocusHandler(self)
|
||||
@@ -611,38 +686,54 @@ return function(name, parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
||||
if (curProcess == nil) then
|
||||
return
|
||||
end
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
if (event ~= "mouse_click") and (event ~= "monitor_touch") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then
|
||||
curProcess:resume(event, p1, p2, p3, p4)
|
||||
if(base.eventHandler(self, event, p1, p2, p3, p4))then
|
||||
if (curProcess == nil) then
|
||||
return
|
||||
end
|
||||
if(event=="dynamicValueEvent")then
|
||||
local w, h = pWindow.getSize()
|
||||
local pW, pH = self:getSize()
|
||||
if(w~=pW)or(h~=pH)then
|
||||
pWindow.basalt_resize(pW, pH)
|
||||
if not (curProcess:isDead()) then
|
||||
curProcess:resume("term_resize")
|
||||
end
|
||||
end
|
||||
if (self:isFocused()) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local xCur, yCur = pWindow.getCursorPos()
|
||||
if (self.parent ~= nil) then
|
||||
local w,h = self:getSize()
|
||||
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
|
||||
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
||||
pWindow.basalt_reposition(self:getAnchorPosition())
|
||||
|
||||
end
|
||||
if not (curProcess:isDead()) then
|
||||
if not (paused) then
|
||||
if(event ~= "terminate") then
|
||||
curProcess:resume(event, p1, p2, p3, p4)
|
||||
end
|
||||
if (self:isFocused()) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local xCur, yCur = pWindow.getCursorPos()
|
||||
if (self.parent ~= nil) then
|
||||
local w,h = self:getSize()
|
||||
if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then
|
||||
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
||||
end
|
||||
end
|
||||
|
||||
if (event == "terminate") then
|
||||
log(self:isFocused())
|
||||
curProcess:resume(event)
|
||||
self.parent:setCursor(false)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if (event == "terminate") and (self:isFocused()) then
|
||||
self:stop()
|
||||
end
|
||||
end
|
||||
else
|
||||
if (event ~= "mouse_click") and (event ~= "monitor_touch") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then
|
||||
else
|
||||
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
@@ -650,14 +741,14 @@ return function(name, parent)
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
pWindow.basalt_reposition(obx, oby)
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
|
||||
end
|
||||
pWindow.basalt_update()
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ProgramBG")
|
||||
end,
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ return function(name)
|
||||
|
||||
setDirection = function(self, dir)
|
||||
direction = dir
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -49,11 +50,13 @@ return function(name)
|
||||
activeBarColor = color or activeBarColor
|
||||
activeBarSymbol = symbol or activeBarSymbol
|
||||
activeBarSymbolCol = symbolcolor or activeBarSymbolCol
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setBackgroundSymbol = function(self, symbol)
|
||||
bgBarSymbol = symbol:sub(1, 1)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -65,6 +68,7 @@ return function(name)
|
||||
self:progressDoneHandler()
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -107,9 +111,8 @@ return function(name)
|
||||
self.parent:drawTextBox(obx, oby, w / 100 * progress, h, activeBarSymbol)
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,6 @@ return function(name)
|
||||
local align = "left"
|
||||
|
||||
local object = {
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("MenubarBG")
|
||||
self.fgColor = self.parent:getTheme("MenubarFG")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
boxSelectedBG = self.parent:getTheme("MenubarBG")
|
||||
boxSelectedFG = self.parent:getTheme("MenubarText")
|
||||
end,
|
||||
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
@@ -58,6 +48,7 @@ return function(name)
|
||||
if (#list == 1) then
|
||||
self:setValue(list[1])
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -67,6 +58,7 @@ return function(name)
|
||||
|
||||
removeItem = function(self, index)
|
||||
table.remove(list, index)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -86,6 +78,7 @@ return function(name)
|
||||
clear = function(self)
|
||||
list = {}
|
||||
self:setValue({})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -96,16 +89,19 @@ return function(name)
|
||||
editItem = function(self, index, text, x, y, bgCol, fgCol, ...)
|
||||
table.remove(list, index)
|
||||
table.insert(list, index, { x = x or 1, y = y or 1, text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
selectItem = function(self, index)
|
||||
self:setValue(list[index] or {})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setActiveSymbol = function(self, sym)
|
||||
symbol = sym:sub(1,1)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
@@ -115,23 +111,23 @@ return function(name)
|
||||
boxSelectedBG = boxBG or boxSelectedBG
|
||||
boxSelectedFG = boxFG or boxSelectedFG
|
||||
selectionColorActive = active~=nil and active or true
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if ((event == "mouse_click")and(button==1))or(event=="monitor_touch") then
|
||||
if (#list > 0) then
|
||||
for _, value in pairs(list) do
|
||||
if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 2 >= x) and (oby + value.y - 1 == y) then
|
||||
self:setValue(value)
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
self:getEventSystem():sendEvent(event, self, event, button, x, y)
|
||||
self:setVisualChanged()
|
||||
return true
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (#list > 0) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
for _, value in pairs(list) do
|
||||
if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 1 >= x) and (oby + value.y - 1 == y) then
|
||||
self:setValue(value)
|
||||
local val = self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", button, x, y)
|
||||
if(val==false)then return val end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -139,24 +135,32 @@ return function(name)
|
||||
end;
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
for _, value in pairs(list) do
|
||||
if (value == self:getValue()) then
|
||||
if (align == "left") then
|
||||
self.parent:writeText(value.x + obx - 1, value.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG)
|
||||
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG)
|
||||
end
|
||||
else
|
||||
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)
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
for _, value in pairs(list) do
|
||||
if (value == self:getValue()) then
|
||||
if (align == "left") then
|
||||
self.parent:writeText(value.x + obx - 1, value.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG)
|
||||
self.parent:writeText(value.x + 2 + obx - 1, value.y + oby - 1, value.text, itemSelectedBG, itemSelectedFG)
|
||||
end
|
||||
else
|
||||
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)
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
return true
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("MenubarBG")
|
||||
self.fgColor = self.parent:getTheme("MenubarFG")
|
||||
itemSelectedBG = self.parent:getTheme("SelectionBG")
|
||||
itemSelectedFG = self.parent:getTheme("SelectionText")
|
||||
boxSelectedBG = self.parent:getTheme("MenubarBG")
|
||||
boxSelectedFG = self.parent:getTheme("MenubarText")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -18,19 +18,37 @@ return function(name)
|
||||
local index = 1
|
||||
local symbolSize = 1
|
||||
|
||||
local function mouseEvent(self, button, x, y)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local w,h = self:getSize()
|
||||
if (barType == "horizontal") then
|
||||
for _index = 0, w do
|
||||
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
|
||||
index = math.min(_index + 1, w - (symbolSize - 1))
|
||||
self:setValue(maxValue / w * (index))
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
if (barType == "vertical") then
|
||||
for _index = 0, h do
|
||||
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
|
||||
index = math.min(_index + 1, h - (symbolSize - 1))
|
||||
self:setValue(maxValue / h * (index))
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ScrollbarBG")
|
||||
self.fgColor = self.parent:getTheme("ScrollbarText")
|
||||
symbolColor = self.parent:getTheme("ScrollbarSymbolColor")
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
|
||||
setSymbol = function(self, _symbol)
|
||||
symbol = _symbol:sub(1, 1)
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -53,6 +71,7 @@ return function(name)
|
||||
local w,h = self:getSize()
|
||||
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
|
||||
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
@@ -68,67 +87,62 @@ return function(name)
|
||||
elseif (barType == "horizontal") then
|
||||
self:setValue(index - 1 * (maxValue / (w - (symbolSize - 1))) - (maxValue / (w - (symbolSize - 1))))
|
||||
end
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setMaxValue = function(self, val)
|
||||
maxValue = val
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setBackgroundSymbol = function(self, _bgSymbol)
|
||||
bgSymbol = string.sub(_bgSymbol, 1, 1)
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setSymbolColor = function(self, col)
|
||||
symbolColor = col
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setBarType = function(self, _typ)
|
||||
barType = _typ:lower()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local w,h = self:getSize()
|
||||
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
|
||||
if (barType == "horizontal") then
|
||||
for _index = 0, w do
|
||||
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
|
||||
index = math.min(_index + 1, w - (symbolSize - 1))
|
||||
self:setValue(maxValue / w * (index))
|
||||
self:setVisualChanged()
|
||||
end
|
||||
end
|
||||
end
|
||||
if (barType == "vertical") then
|
||||
for _index = 0, h do
|
||||
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
|
||||
index = math.min(_index + 1, h - (symbolSize - 1))
|
||||
self:setValue(maxValue / h * (index))
|
||||
self:setVisualChanged()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if (event == "mouse_scroll") then
|
||||
index = index + button
|
||||
if (index < 1) then
|
||||
index = 1
|
||||
end
|
||||
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
|
||||
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
|
||||
end
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
mouseEvent(self, button, x, y)
|
||||
return true
|
||||
end
|
||||
end;
|
||||
return false
|
||||
end,
|
||||
|
||||
dragHandler = function(self, button, x, y)
|
||||
if (base.dragHandler(self, button, x, y)) then
|
||||
mouseEvent(self, button, x, y)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if(base.scrollHandler(self, dir, x, y))then
|
||||
local w,h = self:getSize()
|
||||
index = index + dir
|
||||
if (index < 1) then
|
||||
index = 1
|
||||
end
|
||||
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
|
||||
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
|
||||
self:updateDraw()
|
||||
end
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
@@ -155,9 +169,17 @@ return function(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("ScrollbarBG")
|
||||
self.fgColor = self.parent:getTheme("ScrollbarText")
|
||||
symbolColor = self.parent:getTheme("ScrollbarSymbolColor")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local Object = require("Object")
|
||||
local log = require("basaltLogs")
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
|
||||
return function(name)
|
||||
@@ -17,19 +18,37 @@ return function(name)
|
||||
local index = 1
|
||||
local symbolSize = 1
|
||||
|
||||
local function mouseEvent(self, button, x, y)
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local w,h = self:getSize()
|
||||
if (barType == "horizontal") then
|
||||
for _index = 0, w do
|
||||
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
|
||||
index = math.min(_index + 1, w - (symbolSize - 1))
|
||||
self:setValue(maxValue / w * (index))
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
if (barType == "vertical") then
|
||||
for _index = 0, h do
|
||||
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
|
||||
index = math.min(_index + 1, h - (symbolSize - 1))
|
||||
self:setValue(maxValue / h * (index))
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("SliderBG")
|
||||
self.fgColor = self.parent:getTheme("SliderText")
|
||||
symbolColor = self.parent:getTheme("SliderSymbolColor")
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
|
||||
setSymbol = function(self, _symbol)
|
||||
symbol = _symbol:sub(1, 1)
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -52,6 +71,7 @@ return function(name)
|
||||
local w,h = self:getSize()
|
||||
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
|
||||
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
@@ -66,7 +86,7 @@ return function(name)
|
||||
elseif (barType == "horizontal") then
|
||||
self:setValue(index - 1 * (maxValue / (w - (symbolSize - 1))) - (maxValue / (w - (symbolSize - 1))))
|
||||
end
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -77,56 +97,52 @@ return function(name)
|
||||
|
||||
setBackgroundSymbol = function(self, _bgSymbol)
|
||||
bgSymbol = string.sub(_bgSymbol, 1, 1)
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setSymbolColor = function(self, col)
|
||||
symbolColor = col
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setBarType = function(self, _typ)
|
||||
barType = _typ:lower()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local w,h = self:getSize()
|
||||
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
|
||||
if (barType == "horizontal") then
|
||||
for _index = 0, w do
|
||||
if (obx + _index == x) and (oby <= y) and (oby + h > y) then
|
||||
index = math.min(_index + 1, w - (symbolSize - 1))
|
||||
self:setValue(maxValue / w * (index))
|
||||
self:setVisualChanged()
|
||||
end
|
||||
end
|
||||
end
|
||||
if (barType == "vertical") then
|
||||
for _index = 0, h do
|
||||
if (oby + _index == y) and (obx <= x) and (obx + w > x) then
|
||||
index = math.min(_index + 1, h - (symbolSize - 1))
|
||||
self:setValue(maxValue / h * (index))
|
||||
self:setVisualChanged()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if (event == "mouse_scroll") then
|
||||
index = index + button
|
||||
if (index < 1) then
|
||||
index = 1
|
||||
end
|
||||
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
|
||||
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
|
||||
end
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
mouseEvent(self, button, x, y)
|
||||
return true
|
||||
end
|
||||
end;
|
||||
return false
|
||||
end,
|
||||
|
||||
dragHandler = function(self, button, x, y)
|
||||
if (base.dragHandler(self, button, x, y)) then
|
||||
mouseEvent(self, button, x, y)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if(base.scrollHandler(self, dir, x, y))then
|
||||
local w,h = self:getSize()
|
||||
index = index + dir
|
||||
if (index < 1) then
|
||||
index = 1
|
||||
end
|
||||
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
|
||||
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
@@ -141,7 +157,6 @@ return function(name)
|
||||
|
||||
if (barType == "vertical") then
|
||||
for n = 0, h - 1 do
|
||||
|
||||
if (index == n + 1) then
|
||||
for curIndexOffset = 0, math.min(symbolSize - 1, h) do
|
||||
self.parent:writeText(obx, oby + n + curIndexOffset, symbol, symbolColor, symbolColor)
|
||||
@@ -154,9 +169,17 @@ return function(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("SliderBG")
|
||||
self.fgColor = self.parent:getTheme("SliderText")
|
||||
symbolColor = self.parent:getTheme("SliderSymbolColor")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -17,32 +17,25 @@ return function(name)
|
||||
local activeBG = colors.green
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("SwitchBG")
|
||||
self.fgColor = self.parent:getTheme("SwitchText")
|
||||
bgSymbol = self.parent:getTheme("SwitchBGSymbol")
|
||||
inactiveBG = self.parent:getTheme("SwitchInactive")
|
||||
activeBG = self.parent:getTheme("SwitchActive")
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
|
||||
setSymbolColor = function(self, symbolColor)
|
||||
bgSymbol = symbolColor
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setActiveBackground = function(self, bgcol)
|
||||
activeBG = bgcol
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setInactiveBackground = function(self, bgcol)
|
||||
inactiveBG = bgcol
|
||||
self:setVisualChanged()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -54,12 +47,11 @@ return function(name)
|
||||
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
if ((event == "mouse_click") and (button == 1))or(event=="monitor_touch") then
|
||||
self:setValue(not self:getValue())
|
||||
end
|
||||
self:setValue(not self:getValue())
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
end;
|
||||
@@ -78,9 +70,17 @@ return function(name)
|
||||
self.parent:drawBackgroundBox(obx+1, oby, 1, h, inactiveBG)
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("SwitchBG")
|
||||
self.fgColor = self.parent:getTheme("SwitchText")
|
||||
bgSymbol = self.parent:getTheme("SwitchBGSymbol")
|
||||
inactiveBG = self.parent:getTheme("SwitchInactive")
|
||||
activeBG = self.parent:getTheme("SwitchActive")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
local Object = require("Object")
|
||||
local tHex = require("tHex")
|
||||
local log = require("basaltLogs")
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
|
||||
local rep = string.rep
|
||||
|
||||
return function(name)
|
||||
local base = Object(name)
|
||||
local objectType = "Textfield"
|
||||
@@ -65,6 +68,7 @@ return function(name)
|
||||
end
|
||||
fgLines[l] = fgLine
|
||||
bgLines[l] = bgLine
|
||||
self:updateDraw()
|
||||
end
|
||||
|
||||
local function updateAllColors(self)
|
||||
@@ -74,10 +78,6 @@ return function(name)
|
||||
end
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("TextfieldBG")
|
||||
self.fgColor = self.parent:getTheme("TextfieldText")
|
||||
end,
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end;
|
||||
@@ -144,6 +144,7 @@ return function(name)
|
||||
|
||||
editLine = function(self, index, text)
|
||||
lines[index] = text or lines[index]
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -152,6 +153,7 @@ return function(name)
|
||||
bgLines = {""}
|
||||
fgLines = {""}
|
||||
hIndex, wIndex, textX, textY = 1, 1, 1, 1
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
@@ -173,6 +175,7 @@ return function(name)
|
||||
table.insert(fgLines, tHex[self.fgColor]:rep(text:len()))
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -183,11 +186,13 @@ return function(name)
|
||||
for k,v in pairs(tab)do
|
||||
table.insert(keyWords[color], v)
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
addRule = function(self, rule, fg, bg)
|
||||
table.insert(rules, {rule, fg, bg})
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -198,6 +203,7 @@ return function(name)
|
||||
rules[k][3] = bg
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -207,11 +213,13 @@ return function(name)
|
||||
table.remove(rules, k)
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
setKeywords = function(self, color, tab)
|
||||
keyWords[color] = tab
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -220,6 +228,7 @@ return function(name)
|
||||
if (#lines <= 0) then
|
||||
table.insert(lines, "")
|
||||
end
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -244,11 +253,10 @@ return function(name)
|
||||
end
|
||||
end;
|
||||
|
||||
keyHandler = function(self, event, key)
|
||||
keyHandler = function(self, key)
|
||||
if (base.keyHandler(self, event, key)) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if (event == "key") then
|
||||
if (key == keys.backspace) then
|
||||
-- on backspace
|
||||
if (lines[textY] == "") then
|
||||
@@ -361,7 +369,14 @@ return function(name)
|
||||
if (textX > lines[textY]:len() + 1) then
|
||||
textX = lines[textY]:len() + 1
|
||||
end
|
||||
|
||||
if (wIndex > 1) then
|
||||
if (textX < wIndex) then
|
||||
wIndex = textX - w + 1
|
||||
if (wIndex < 1) then
|
||||
wIndex = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
if (textY >= hIndex + h) then
|
||||
hIndex = hIndex + 1
|
||||
end
|
||||
@@ -411,19 +426,6 @@ return function(name)
|
||||
wIndex = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (event == "char") then
|
||||
lines[textY] = lines[textY]:sub(1, textX - 1) .. key .. lines[textY]:sub(textX, lines[textY]:len())
|
||||
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor] .. fgLines[textY]:sub(textX, fgLines[textY]:len())
|
||||
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor] .. bgLines[textY]:sub(textX, bgLines[textY]:len())
|
||||
textX = textX + 1
|
||||
if (textX >= w + wIndex) then
|
||||
wIndex = wIndex + 1
|
||||
end
|
||||
updateColors(self)
|
||||
self:setValue("")
|
||||
end
|
||||
|
||||
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
|
||||
if (cursorX > self.x + w - 1) then
|
||||
@@ -434,17 +436,46 @@ return function(name)
|
||||
cursorX = 0
|
||||
end
|
||||
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, event, button, x, y)
|
||||
if (base.mouseHandler(self, event, button, x, y)) then
|
||||
charHandler = function(self, char)
|
||||
if(base.charHandler(self, char))then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
lines[textY] = lines[textY]:sub(1, textX - 1) .. char .. lines[textY]:sub(textX, lines[textY]:len())
|
||||
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor] .. fgLines[textY]:sub(textX, fgLines[textY]:len())
|
||||
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor] .. bgLines[textY]:sub(textX, bgLines[textY]:len())
|
||||
textX = textX + 1
|
||||
if (textX >= w + wIndex) then
|
||||
wIndex = wIndex + 1
|
||||
end
|
||||
updateColors(self)
|
||||
self:setValue("")
|
||||
|
||||
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
|
||||
if (cursorX > self.x + w - 1) then
|
||||
cursorX = self.x + w - 1
|
||||
end
|
||||
local cursorY = (textY - hIndex < h and textY - hIndex or textY - hIndex - 1)
|
||||
if (cursorX < 1) then
|
||||
cursorX = 0
|
||||
end
|
||||
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
end,
|
||||
|
||||
dragHandler = function(self, button, x, y)
|
||||
if (base.dragHandler(self, button, x, y)) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local anchx, anchy = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if (event == "mouse_click")or(event=="monitor_touch") then
|
||||
if (lines[y - oby + hIndex] ~= nil) then
|
||||
if (lines[y - oby + hIndex] ~= nil) then
|
||||
if(anchx+w > anchx + x - (obx+1)+ wIndex)and(anchx < anchx + x - obx+ wIndex)then
|
||||
textX = x - obx + wIndex
|
||||
textY = y - oby + hIndex
|
||||
if (textX > lines[textY]:len()) then
|
||||
@@ -459,61 +490,89 @@ return function(name)
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
end
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
if (event == "mouse_drag") then
|
||||
if (lines[y - oby + hIndex] ~= nil) then
|
||||
textX = x - obx + wIndex
|
||||
textY = y - oby + hIndex
|
||||
if (textX > lines[textY]:len()) then
|
||||
textX = lines[textY]:len() + 1
|
||||
end
|
||||
if (textX < wIndex) then
|
||||
wIndex = textX - 1
|
||||
if (wIndex < 1) then
|
||||
wIndex = 1
|
||||
end
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (event == "mouse_scroll") then
|
||||
hIndex = hIndex + button
|
||||
if (hIndex > #lines - (h - 1)) then
|
||||
hIndex = #lines - (h - 1)
|
||||
end
|
||||
|
||||
if (hIndex < 1) then
|
||||
hIndex = 1
|
||||
end
|
||||
|
||||
if (self.parent ~= nil) then
|
||||
if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h) then
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
else
|
||||
self.parent:setCursor(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:setVisualChanged()
|
||||
return true
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
if (base.scrollHandler(self, dir, x, y)) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local anchx, anchy = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
hIndex = hIndex + dir
|
||||
if (hIndex > #lines - (h - 1)) then
|
||||
hIndex = #lines - (h - 1)
|
||||
end
|
||||
|
||||
if (hIndex < 1) then
|
||||
hIndex = 1
|
||||
end
|
||||
|
||||
if (self.parent ~= nil) then
|
||||
if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h) then
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
else
|
||||
self.parent:setCursor(false)
|
||||
end
|
||||
end
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local anchx, anchy = self:getAnchorPosition()
|
||||
if (lines[y - oby + hIndex] ~= nil) then
|
||||
textX = x - obx + wIndex
|
||||
textY = y - oby + hIndex
|
||||
if (textX > lines[textY]:len()) then
|
||||
textX = lines[textY]:len() + 1
|
||||
end
|
||||
if (textX < wIndex) then
|
||||
wIndex = textX - 1
|
||||
if (wIndex < 1) then
|
||||
wIndex = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end,
|
||||
|
||||
eventHandler = function(self, event, paste, p2, p3, p4)
|
||||
if(base.eventHandler(self, event, paste, p2, p3, p4))then
|
||||
if(event=="paste")then
|
||||
if(self:isFocused())then
|
||||
local w, h = self:getSize()
|
||||
lines[textY] = lines[textY]:sub(1, textX - 1) .. paste .. lines[textY]:sub(textX, lines[textY]:len())
|
||||
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor]:rep(paste:len()) .. fgLines[textY]:sub(textX, fgLines[textY]:len())
|
||||
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor]:rep(paste:len()) .. bgLines[textY]:sub(textX, bgLines[textY]:len())
|
||||
textX = textX + paste:len()
|
||||
if (textX >= w + wIndex) then
|
||||
wIndex = (textX+1)-w
|
||||
end
|
||||
local anchx, anchy = self:getAnchorPosition()
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
updateColors(self)
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
draw = function(self)
|
||||
if (base.draw(self)) then
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
|
||||
end
|
||||
if(self.fgColor~=false)then
|
||||
self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor)
|
||||
end
|
||||
for n = 1, h do
|
||||
local text = ""
|
||||
local bg = ""
|
||||
@@ -530,17 +589,31 @@ return function(name)
|
||||
if (space < 0) then
|
||||
space = 0
|
||||
end
|
||||
text = text .. string.rep(" ", space)
|
||||
bg = bg .. string.rep(tHex[self.bgColor], space)
|
||||
fg = fg .. string.rep(tHex[self.fgColor], space)
|
||||
text = text .. rep(self.bgSymbol, space)
|
||||
bg = bg .. rep(tHex[self.bgColor], space)
|
||||
fg = fg .. rep(tHex[self.fgColor], space)
|
||||
self.parent:setText(obx, oby + n - 1, text)
|
||||
self.parent:setBG(obx, oby + n - 1, bg)
|
||||
self.parent:setFG(obx, oby + n - 1, fg)
|
||||
end
|
||||
if(self:isFocused())then
|
||||
local anchx, anchy = self:getAnchorPosition()
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
end
|
||||
end
|
||||
self:setVisualChanged(false)
|
||||
end
|
||||
end;
|
||||
end,
|
||||
|
||||
init = function(self)
|
||||
self.bgColor = self.parent:getTheme("TextfieldBG")
|
||||
self.fgColor = self.parent:getTheme("TextfieldText")
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
self.parent:addEvent("key", self)
|
||||
self.parent:addEvent("char", self)
|
||||
self.parent:addEvent("other_event", self)
|
||||
end,
|
||||
}
|
||||
|
||||
return setmetatable(object, base)
|
||||
|
||||
@@ -59,6 +59,7 @@ return function(name)
|
||||
error("Thread Error Occurred - " .. result)
|
||||
end
|
||||
end
|
||||
self.parent:addEvent("other_event", self)
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -71,6 +72,7 @@ return function(name)
|
||||
|
||||
stop = function(self, f)
|
||||
isActive = false
|
||||
self.parent:removeEvent("other_event", self)
|
||||
return self
|
||||
end;
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ return function(name)
|
||||
repeats = savedRepeats
|
||||
timerObj = os.startTimer(timer)
|
||||
timerIsActive = true
|
||||
self.parent:addEvent("other_event", self)
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -86,6 +87,7 @@ return function(name)
|
||||
os.cancelTimer(timerObj)
|
||||
end
|
||||
timerIsActive = false
|
||||
self.parent:removeEvent("other_event", self)
|
||||
return self
|
||||
end;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ return { -- The default main theme for basalt!
|
||||
ScrollbarBG = colors.lightGray,
|
||||
ScrollbarText = colors.gray,
|
||||
ScrollbarSymbolColor = colors.black,
|
||||
SliderBG = colors.lightGray,
|
||||
SliderBG = false,
|
||||
SliderText = colors.gray,
|
||||
SliderSymbolColor = colors.black,
|
||||
SwitchBG = colors.lightGray,
|
||||
@@ -39,5 +39,7 @@ return { -- The default main theme for basalt!
|
||||
SwitchBGSymbol = colors.black,
|
||||
SwitchInactive = colors.red,
|
||||
SwitchActive = colors.green,
|
||||
LabelBG = false,
|
||||
LabelText = colors.black
|
||||
|
||||
}
|
||||
23
CHANGELOG.md
Normal file
23
CHANGELOG.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Changelog
|
||||
|
||||
#### v. 1.5:
|
||||
- You can now mirror a frame to a monitor by using :setMirror(side)
|
||||
- with dynamic values you are able to use percentage values and even functions which get called everytime we need the size of that object
|
||||
- XML got added to make design and logic seperate (you don't have to) - you are now able to use xml to create your UI design.
|
||||
- Animations are now more advanced and provide many features to do cool stuff. They are also very easy to use now!
|
||||
- Also some smaller bugfixes
|
||||
- new bugs to explore
|
||||
- fixed monitor support
|
||||
- added :setIndex() for scrollbars
|
||||
- added dynamic value system (not fully done)
|
||||
- reworked the filesystem, now we use require instead of loadfile
|
||||
- from now on the single file will be complied on the end users computer
|
||||
- prepared everything for an advanced installer
|
||||
|
||||
#### v. 1:
|
||||
- created Basalt
|
||||
- added many objects (buttons, checkbox, labels, programs, switch, radio, lists, dropdowns, input, textfields, images, menubar, animations, threads, timers, progressbar, scrollbar, slider, pane)
|
||||
- added bigfont
|
||||
- added blittle
|
||||
- added coroutine management
|
||||
- added advanced event system
|
||||
46
README.md
46
README.md
@@ -1,39 +1,15 @@
|
||||
# Basalt - A UI Framework for CC:Tweaked
|
||||

|
||||

|
||||

|
||||

|
||||
[](https://discord.gg/yNNnmBVBpE)
|
||||
|
||||
Basalt is still under developement and you may find bugs!
|
||||
Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://www.curseforge.com/minecraft/mc-mods/cc-tweaked).<br>
|
||||
**Note:** Basalt is still under developement and you may find bugs!
|
||||
|
||||
## Information
|
||||
|
||||
Check out the [wiki](https://basalt.madefor.cc/) for information<br>
|
||||
If you have questions, feel free to join the discord server: [https://discord.gg/yM7kndJdJJ](https://discord.gg/yM7kndJdJJ)
|
||||
|
||||
## Changelogs
|
||||
From now on we will add changes:
|
||||
|
||||
#### Version 4:
|
||||
- You can now mirror a frame to a monitor by using :setMirror(side)
|
||||
- with dynamic values you are able to use percentage values and even functions which get called everytime we need the size of that object
|
||||
- XML got added to make design and logic seperate (you don't have to) - you are now able to use xml to create your UI design.
|
||||
- Animations are now more advanced and provide many features to do cool stuff. They are also very easy to use now!
|
||||
- Also some smaller bugfixes
|
||||
- new bugs to explore
|
||||
|
||||
#### Version 3:
|
||||
- fixed monitor support
|
||||
- added :setIndex() for scrollbars
|
||||
- added dynamic value system (not fully done)
|
||||
|
||||
#### Version 2:
|
||||
Note: You won't get any changes for now, so don't redownload the project! (:
|
||||
- reworked the filesystem, now we use require instead of loadfile
|
||||
- from now on the single file will be complied on the end users computer
|
||||
- prepared everything for an advanced installer
|
||||
|
||||
#### Version 1:
|
||||
- created Basalt
|
||||
- added many objects (buttons, checkbox, labels, programs, switch, radio, lists, dropdowns, input, textfields, images, menubar, animations, threads, timers, progressbar, scrollbar, slider, pane)
|
||||
- added bigfont
|
||||
- added blittle
|
||||
- added coroutine management
|
||||
- added advanced event system
|
||||
Check out the [wiki](https://basalt.madefor.cc/) for more information.<br>
|
||||
If you have questions, feel free to join the discord server: [https://discord.gg/yNNnmBVBpE](https://discord.gg/yNNnmBVBpE).
|
||||
|
||||
## Demo
|
||||
<img src="https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/basaltPreview2.gif" width="300">
|
||||
@@ -464,7 +464,8 @@ outputFile:write("project['default'] = {}")
|
||||
local function writeNewPackage(subdir, name, path)
|
||||
if not(fs.isDir(path))then
|
||||
outputFile:write("project['"..subdir.."']['"..name.."'] = ".."function(...)")
|
||||
local fileData = io.open(path, "r"):read("*all")
|
||||
local file = io.open(path, "r")
|
||||
local fileData = file:read("*all")
|
||||
if(minifyProject)then
|
||||
local success, data = minify(fileData)
|
||||
if(success)then
|
||||
@@ -475,6 +476,7 @@ local function writeNewPackage(subdir, name, path)
|
||||
else
|
||||
outputFile:write(fileData:gsub("]]", "] ]"):gsub("]]", "] ]").."\n")
|
||||
end
|
||||
file:close()
|
||||
outputFile:write("end; \n")
|
||||
end
|
||||
end
|
||||
@@ -489,16 +491,17 @@ for _,v in pairs(projectFiles)do
|
||||
end
|
||||
end
|
||||
|
||||
local main = io.open(fs.combine(projectPath, mainFile), "r"):read("*all")
|
||||
local main = io.open(fs.combine(projectPath, mainFile), "r")
|
||||
local mainData = main:read("*all")
|
||||
if(minifyProject)then
|
||||
local success,data = minify(main)
|
||||
local success,data = minify(mainData)
|
||||
if(success)then
|
||||
outputFile:write(data)
|
||||
else
|
||||
print("Error: Can't minify "..fs.combine(projectPath, mainFile))
|
||||
print("Error: Can't minify "..fs.combine(projectPath, mainFile).." "..data)
|
||||
end
|
||||
else
|
||||
outputFile:write(main)
|
||||
outputFile:write(mainData)
|
||||
end
|
||||
|
||||
outputFile:close()
|
||||
main:close()
|
||||
outputFile:close()
|
||||
|
||||
@@ -3,33 +3,30 @@
|
||||
- [Quick Start](home/Quick-Start.md)
|
||||
- [Installer](home/installer)
|
||||
- Objects
|
||||
- [Basalt](objects/Basalt)
|
||||
- [Object](objects/Object)
|
||||
- [Button](objects/Button)
|
||||
- [Checkbox](objects/Checkbox)
|
||||
- [Dropdown](objects/Dropdown)
|
||||
- [Frame](objects/Frame)
|
||||
- [Image](objects/Image)
|
||||
- [Input](objects/Input)
|
||||
- [Label](objects/Label)
|
||||
- [List](objects/List)
|
||||
- [Menubar](objects/Menubar)
|
||||
- [Pane](objects/Pane)
|
||||
- [Program](objects/Program)
|
||||
- [Progressbar](objects/Progressbar)
|
||||
- [Radio](objects/Radio)
|
||||
- [Scrollbar](objects/Scrollbar)
|
||||
- [Slider](objects/Slider)
|
||||
- [Textfield](objects/Textfield)
|
||||
- [Basalt](objects/Basalt.md)
|
||||
- [Object](objects/Object.md)
|
||||
- [Button](objects/Button.md)
|
||||
- [Checkbox](objects/Checkbox.md)
|
||||
- [Dropdown](objects/Dropdown.md)
|
||||
- [Frame](objects/Frame.md)
|
||||
- [Image](objects/Image.md)
|
||||
- [Input](objects/Input.md)
|
||||
- [Label](objects/Label.md)
|
||||
- [List](objects/List.md)
|
||||
- [Menubar](objects/Menubar.md)
|
||||
- [Pane](objects/Pane.md)
|
||||
- [Program](objects/Program.md)
|
||||
- [Progressbar](objects/Progressbar.md)
|
||||
- [Radio](objects/Radio.md)
|
||||
- [Scrollbar](objects/Scrollbar.md)
|
||||
- [Slider](objects/Slider.md)
|
||||
- [Textfield](objects/Textfield.md)
|
||||
- [Animation](objects/Animation.md)
|
||||
- [Thread](objects/Thread)
|
||||
- [Timer](objects/Timer)
|
||||
- Events
|
||||
- [Mouse Events](events/mouseEvents.md)
|
||||
- [Keyboard Events](events/keyEvents.md)
|
||||
- [Other Events](events/otherEvents.md)
|
||||
- [Thread](objects/Thread.md)
|
||||
- [Timer](objects/Timer.md)
|
||||
- Tips & Tricks
|
||||
- [Component Logic](tips/logic)
|
||||
- [Changing Button Color](tips/buttons)
|
||||
- [Advanced usage of Events](tips/events.md)
|
||||
- [Example Designs](tips/design.md)
|
||||
- [Your Logic](tips/logic.md)
|
||||
- [Button coloring](tips/buttonColoring.md)
|
||||
- [Designing/Animating](tips/design.md)
|
||||
- [Dynamic Values](tips/dynamicvalues.md)
|
||||
- [XML](tips/xml.md)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
Here we will talk about keyboard events and how you can manipulate them. There are 2 possible key events you can add to almost every visual object.
|
||||
|
||||
# onKey
|
||||
`onKey(self, event, key)`<br>
|
||||
The computercraft event which triggers this method is `key`.
|
||||
Any visual object can register onKey events.
|
||||
|
||||
Here is a example on how to add a onKey event to your frame:
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myMainFrame"):show()
|
||||
local subFrame = mainFrame:addFrame("subFrame"):setPosition(3,3):setSize(18,6):setBar("Sub Frame",colors.black):showBar():show()
|
||||
|
||||
function openSubFrame()
|
||||
subFrame:show()
|
||||
end
|
||||
mainFrame:onKey(openSubFrame)
|
||||
```
|
||||
|
||||
# onKeyUp
|
||||
`onKeyUp(self, event, key)`<br>
|
||||
The computercraft event which triggers this method is `key_up`.
|
||||
Any visual object can register onKeyUp events.
|
||||
|
||||
Here is a example on how to add a onKeyUp event to your frame:
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myMainFrame"):show()
|
||||
local subFrame = mainFrame:addFrame("subFrame"):setPosition(3,3):setSize(18,6):setBar("Sub Frame",colors.black):showBar():show()
|
||||
|
||||
function openSubFrame()
|
||||
subFrame:show()
|
||||
end
|
||||
mainFrame:onKeyUp(openSubFrame)
|
||||
```
|
||||
@@ -1,82 +0,0 @@
|
||||
Here we will talk about mouse events and how you can use them. You can register custom mouse events to all visual objects
|
||||
|
||||
# onClick
|
||||
`onClick(self, event, button, x, y)`<br>
|
||||
The computercraft event which triggers this method is `mouse_click` and `monitor_touch`.
|
||||
Any visual object can register onClick events.
|
||||
|
||||
Here is a example on how to add a onClick event to your button:
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myMainFrame"):show()
|
||||
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
|
||||
|
||||
function buttonOnClick()
|
||||
basalt.debug("Button got clicked!")
|
||||
end
|
||||
button:onClick(buttonOnClick())
|
||||
```
|
||||
|
||||
# onClickUp
|
||||
`onClickUp(self, event, button, x, y)`<br>
|
||||
The computercraft event which triggers this method is `mouse_up`.
|
||||
Any visual object can register onClickUp events.
|
||||
|
||||
Here is a example on how to add a onClickUp event to your button:
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myMainFrame"):show()
|
||||
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
|
||||
|
||||
function buttonOnClick(self, button, x, y)
|
||||
basalt.debug("Button got clicked!")
|
||||
end
|
||||
button:onClick(buttonOnClick)
|
||||
|
||||
function buttonOnRelease(self, button, x, y)
|
||||
basalt.debug("Button got released!")
|
||||
end
|
||||
button:onClickUp(buttonOnRelease)
|
||||
```
|
||||
|
||||
# onScroll
|
||||
`onScroll(self, event, direction, x, y)`<br>
|
||||
The computercraft event which triggers this method is `mouse_scroll`.
|
||||
Any visual object can register onScroll events.
|
||||
|
||||
Here is a example on how to add a onScroll event to your button:
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myMainFrame"):show()
|
||||
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
|
||||
|
||||
function buttonOnScroll(self, direction, x, y)
|
||||
basalt.debug("Someone scrolls on me!")
|
||||
end
|
||||
button:onScroll(buttonOnScroll)
|
||||
```
|
||||
|
||||
# onDrag
|
||||
`onDrag(self, event, button, x, y)`<br>
|
||||
The computercraft event which triggers this method is `mouse_drag`.
|
||||
Any visual object can register onDrag events.
|
||||
|
||||
Here is a example on how to add a onDrag event to your button:
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myMainFrame"):show()
|
||||
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
|
||||
|
||||
function buttonOnDrag(self, button, x, y)
|
||||
basalt.debug("Someone drags me (i know i wont reposition myself)!")
|
||||
end
|
||||
button:onDrag(buttonOnDrag)
|
||||
```
|
||||
@@ -1,79 +0,0 @@
|
||||
There are also other useful events you can listen to:
|
||||
|
||||
# onChange
|
||||
`onChange(self)`<br>
|
||||
This is a custom event which gets triggered as soon as the function :setValue() is called. This function is also called by basalt, for example if you change the input, textfield or checkbox (or all the different types of lists) objects.
|
||||
|
||||
Here is a example on how to add a onChange event to your input, and also another example for your checkbox:
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myMainFrame"):show()
|
||||
local aInput = mainFrame:addInput("specialInput"):setPosition(3,3):show()
|
||||
local aCheckbox = mainFrame:addCheckbox("specialCheckbox"):setPosition(3,5):show()
|
||||
|
||||
local function checkInput(input)
|
||||
if(string.lower(input:getValue())=="hello")then
|
||||
basalt.debug("Hello back!")
|
||||
end
|
||||
end
|
||||
|
||||
local function checkCheckbox(checkbox)
|
||||
if(checkbox:getValue()==true)then -- or if(checkbox:getValue())then
|
||||
basalt.debug("Checkbox is active, let us do something!")
|
||||
end
|
||||
end
|
||||
|
||||
aInput:onChange(checkInput)
|
||||
aCheckbox:onChange(checkCheckbox)
|
||||
```
|
||||
|
||||
# onResize
|
||||
`onResize(self)`<br>
|
||||
This is a custom event which gets triggered as soon as the parent frame gets resized.
|
||||
|
||||
Here is a example on how to add a onResize event to your button:
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myMainFrame"):show()
|
||||
local aButton = mainFrame:addButton("myButton"):setPosition(3,3):show()
|
||||
|
||||
local function onButtonResize(button)
|
||||
local width = mainFrame:getWidth()
|
||||
button:setSize()
|
||||
end
|
||||
|
||||
aButton:onResize(onButtonResize)
|
||||
```
|
||||
# onLoseFocus
|
||||
`onLoseFocus(self)`<br>
|
||||
This event gets triggered as soon as the object loses its focus.
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
||||
local aButton = mainFrame:addButton("exampleButton"):setPosition(3,3):onLoseFocus(
|
||||
function(self)
|
||||
basalt.debug("Please come back... :(")
|
||||
end
|
||||
):show()
|
||||
```
|
||||
|
||||
# onGetFocus
|
||||
`onGetFocus(self)`<br>
|
||||
This event gets triggered as soon as the object is the currently focused object.
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("myFirstFrame"):show()
|
||||
local aButton = mainFrame:addButton("exampleButton"):setPosition(3,3):onGetFocus(
|
||||
function(self)
|
||||
basalt.debug("Welcome back!")
|
||||
end
|
||||
):show()
|
||||
```
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
To load the framework into your project, make use of the following code on top of your code.
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
local basalt = require("basalt")
|
||||
```
|
||||
|
||||
It does not matter if you have installed the single file version or the full folder project. <br>
|
||||
@@ -43,11 +43,10 @@ The true keyword in the end is optional and would simply start BPM immediately.
|
||||
Here is a fully functioning example of Basalt code
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt") --> Load the Basalt framework
|
||||
local basalt = require("basalt") --> Load the Basalt framework
|
||||
|
||||
--> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events
|
||||
--> When Basalt#createFrame makes use of unique identifiers (commonly referred to as UIDs), meaning that the supplied value must be UNIQUE
|
||||
--> If the supplied UID is ambiguous, Basalt#createFrame returns a nil value
|
||||
local mainFrame = basalt.createFrame("mainFrame")
|
||||
|
||||
--> Show the frame to the user
|
||||
@@ -76,7 +75,7 @@ basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect us
|
||||
```
|
||||
If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above:
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame("mainFrame"):show()
|
||||
local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining"
|
||||
|
||||
487
docs/installer.lua
Normal file
487
docs/installer.lua
Normal file
@@ -0,0 +1,487 @@
|
||||
--Basalt configurated installer
|
||||
local filePath = "basalt.lua" --here you can change the file path default: basalt
|
||||
if not(fs.exists(filePath))then
|
||||
shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
|
||||
end
|
||||
local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
|
||||
|
||||
local maxCoWorker = 3
|
||||
|
||||
local recipeList = {}
|
||||
local craftingQueue = {}
|
||||
local bridge = peripheral.find("rsBridge")
|
||||
local w, h = term.getSize()
|
||||
|
||||
local main = basalt.createFrame()
|
||||
local home = main:addFrame():setPosition(1,2):setBackground(colors.lightGray):setSize(w, h-2)
|
||||
local recipes = main:addFrame():setPosition(1,2):setBackground(colors.lightGray):hide()
|
||||
local log = main:addFrame():setPosition(1,2):setBackground(colors.lightGray):hide()
|
||||
|
||||
local menuBar = main:addMenubar():addItem("Home"):addItem("Recipes"):addItem("Log"):setBackground(colors.gray):setSize(w, 1):setSpace(6):setScrollable():show()
|
||||
menuBar:onChange(function(self)
|
||||
home:hide()
|
||||
recipes:hide()
|
||||
log:hide()
|
||||
if(self:getValue().text=="Home")then
|
||||
home:show()
|
||||
elseif(self:getValue().text=="Recipes")then
|
||||
recipes:show()
|
||||
elseif(self:getValue().text=="Log")then
|
||||
log:show()
|
||||
end
|
||||
end)
|
||||
|
||||
local function buttonVisuals(btn)
|
||||
btn:onClick(basalt.schedule(function() btn:setBackground(colors.black) btn:setForeground(colors.lightGray) os.sleep(0.1) btn:setBackground(colors.gray) btn:setForeground(colors.black) end))
|
||||
end
|
||||
|
||||
local coworkerCount = home:addLabel():setText(maxCoWorker):setPosition(45,2):show()
|
||||
home:addLabel():setText("Co-Worker:"):setPosition(32,2):show()
|
||||
buttonVisuals(home:addButton():setText(">"):setSize(1,1):setPosition(47,2):onClick(function() if(maxCoWorker<100)then maxCoWorker = maxCoWorker+1 end coworkerCount:setText(maxCoWorker) end):show())
|
||||
buttonVisuals(home:addButton():setText("<"):setSize(1,1):setPosition(43,2):onClick(function() if(maxCoWorker>1)then maxCoWorker = maxCoWorker-1 end coworkerCount:setText(maxCoWorker) end):show())
|
||||
|
||||
local logList = log:addList():setPosition(2,2):setSize(w-2,h-3):setScrollable(false):show()
|
||||
local jobList = home:addList():setPosition(20,4):setSize(30,10):show()
|
||||
local rList = recipes:addList():setPosition(13,2):setSize(38,16):show()
|
||||
|
||||
local function logging(text)
|
||||
logList:addItem(text)
|
||||
if(logList:getItemCount()>h-3)then
|
||||
logList:removeItem(1)
|
||||
end
|
||||
end
|
||||
|
||||
logging("Loading autocrafter...")
|
||||
|
||||
function SaveToFile()
|
||||
local file = io.open("recipes", "wb")
|
||||
local sel = rList:getItemIndex()
|
||||
rList:clear()
|
||||
for _,v in pairs(recipeList)do
|
||||
if(v.useDmg)then
|
||||
file:write(v.name.."|"..v.damage.."|"..v.minAmount.."|"..v.maxCraftAmount.."|true|", "\n")
|
||||
else
|
||||
file:write(v.name.."|"..v.damage.."|"..v.minAmount.."|"..v.maxCraftAmount.."|false|", "\n")
|
||||
end
|
||||
rList:addItem(v.minAmount.."x "..v.name..":"..v.damage, nil, nil, v)
|
||||
end
|
||||
rList:selectItem(sel)
|
||||
file:close()
|
||||
end
|
||||
|
||||
buttonVisuals(recipes:addButton():setPosition(2,2):setText("Remove"):setSize(8,1):onClick(function()
|
||||
if(rList:getValue()~=nil)then
|
||||
local sel = rList:getValue().args[1]
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==sel.name)and(tonumber(v.damage)==tonumber(sel.damage))then
|
||||
table.remove(recipeList, k)
|
||||
logging("Removed recipe: "..v.name..":"..v.damage)
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
end
|
||||
end))
|
||||
local changeAmn = recipes:addInput():setPosition(4,4):setSize(5,1):setInputType("number"):setForeground(colors.black):setDefaultText("32", colors.black):onChange(function(self)
|
||||
local val = tonumber(self:getValue()) or 32
|
||||
if(val<0)then
|
||||
self:setValue(0)
|
||||
end
|
||||
end)
|
||||
buttonVisuals(recipes:addButton():setPosition(2,4):setSize(1,1):setText("-"):onClick(function()
|
||||
local val = tonumber(changeAmn:getValue()) or 32
|
||||
if(rList:getValue()~=nil)then
|
||||
local sel = rList:getValue().args[1]
|
||||
if(val>0)and(sel.name~=nil)and(sel.damage~=nil)then
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==sel.name)and(tonumber(v.damage)==tonumber(sel.damage))then
|
||||
v.minAmount = v.minAmount - val
|
||||
if(v.minAmount < 0)then v.minAmount = 0 end
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end))
|
||||
buttonVisuals(recipes:addButton():setPosition(10,4):setSize(1,1):setText("+"):onClick(function()
|
||||
local val = tonumber(changeAmn:getValue()) or 32
|
||||
if(rList:getValue()~=nil)then
|
||||
local sel = rList:getValue().args[1]
|
||||
if(val>0)and(sel.name~=nil)and(sel.damage~=nil)then
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==sel.name)and(tonumber(v.damage)==tonumber(sel.damage))then
|
||||
v.minAmount = v.minAmount + val
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end))
|
||||
|
||||
buttonVisuals(recipes:addButton():setPosition(2,6):setSize(8,1):setText("Set"):onClick(function()
|
||||
local val = tonumber(changeAmn:getValue()) or 32
|
||||
if(rList:getValue()~=nil)then
|
||||
local sel = rList:getValue().args[1]
|
||||
if(val>0)and(sel.name~=nil)and(sel.damage~=nil)then
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==sel.name)and(tonumber(v.damage)==tonumber(sel.damage))then
|
||||
v.minAmount = val
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end))
|
||||
|
||||
local rItemFrame = home:addFrame():setPosition(7,3):setBackground(colors.gray):setSize(27,6):setMoveable(true):setBar("Remove Item", colors.black, colors.lightGray):showBar():hide()
|
||||
rItemFrame:addButton():setPosition(1,1):setAnchor("topRight"):setSize(1,1):setBackground(colors.black):setForeground(colors.lightGray):setText("x"):onClick(function() rItemFrame:hide() end):show()
|
||||
rItemFrame:addLabel():setText("Item ID:"):setPosition(2,3):show()
|
||||
local ritemId = rItemFrame:addInput("itemid"):setPosition(12,3):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setDefaultText("minecraft:stick", colors.gray):show()
|
||||
rItemFrame:addButton():setPosition(-7,0):setAnchor("bottomRight"):setSize(8,1):setBackground(colors.black):setForeground(colors.lightGray):setText("Remove"):onClick(function()
|
||||
local id = ritemId:getValue()
|
||||
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==id)then
|
||||
table.remove(recipeList, k)
|
||||
logging("Removed recipe: "..v.name..":"..v.damage)
|
||||
end
|
||||
end
|
||||
SaveToFile()
|
||||
end)
|
||||
|
||||
|
||||
local aItemFrame = home:addFrame():setPosition(7,3):setBackground(colors.gray):setSize(27,12):setMoveable(true):setBar("Add Item", colors.black, colors.lightGray):showBar():hide()
|
||||
aItemFrame:addLabel():setText("Item ID:"):setPosition(2,3)
|
||||
aItemFrame:addLabel():setText("Damage:"):setPosition(2,5)
|
||||
aItemFrame:addLabel():setText("Count:"):setPosition(2,7)
|
||||
aItemFrame:addLabel():setText("Max:"):setPosition(2,9)
|
||||
aItemFrame:addLabel():setText("Use Damage:"):setAnchor("bottomLeft"):setPosition(4,0)
|
||||
local itemId = aItemFrame:addInput():setPosition(12,3):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setDefaultText("minecraft:stick", colors.gray)
|
||||
local itemDamage = aItemFrame:addInput():setPosition(12,5):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setInputType("number"):setDefaultText("0", colors.gray)
|
||||
local itemCount = aItemFrame:addInput():setPosition(12,7):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setInputType("number"):setDefaultText("64", colors.gray)
|
||||
local itemMaxCount = aItemFrame:addInput():setPosition(12,9):setSize(15,1):setBackground(colors.black):setForeground(colors.lightGray):setInputType("number"):setDefaultText("0", colors.gray)
|
||||
local useDamage = aItemFrame:addCheckbox():setAnchor("bottomLeft"):setPosition(2,0):setBackground(colors.black):setForeground(colors.lightGray):setValue(true)
|
||||
aItemFrame:addButton():setAnchor("topRight"):setPosition(1,1):setSize(1,1):setBackground(colors.black):setForeground(colors.lightGray):setText("x"):onClick(function() aItemFrame:hide() end)
|
||||
aItemFrame:addButton():setAnchor("bottomRight"):setPosition(-4,0):setSize(5,1):setBackground(colors.black):setForeground(colors.lightGray):setText("Add"):onClick(function()
|
||||
local id = itemId:getValue()
|
||||
local dmg = itemDamage:getValue() == "" and 0 or itemDamage:getValue()
|
||||
local count = itemCount:getValue() == "" and 64 or itemCount:getValue()
|
||||
local maxCount = itemMaxCount:getValue() == "" and 0 or itemMaxCount:getValue()
|
||||
local usedamage = useDamage:getValue() or true
|
||||
if(id~="")then
|
||||
local itemExist = false
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name==id)then
|
||||
if(usedamage)then
|
||||
if(v.damage==dmg)then
|
||||
itemExist = true
|
||||
v.minAmount = count or 64
|
||||
v.maxCraftAmount = maxCount or 0
|
||||
logging("Edited recipe: "..(count).."x "..id..":"..dmg)
|
||||
end
|
||||
else
|
||||
itemExist = true
|
||||
v.minAmount = count or 64
|
||||
v.maxCraftAmount = maxCount or 0
|
||||
logging("Edited recipe: "..(count).."x "..id..":"..dmg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if(itemExist == false)then
|
||||
table.insert(recipeList, {name = id, damage = dmg or 0, minAmount = count, maxCraftAmount = maxCount or 0, useDmg = usedamage, fails = 0, timer = 0})
|
||||
logging("Added recipe: "..(count).."x "..id..":"..dmg)
|
||||
end
|
||||
SaveToFile()
|
||||
else
|
||||
logging("Please set a ID.")
|
||||
end
|
||||
end)
|
||||
|
||||
buttonVisuals(home:addButton():setText("Add Item"):setSize(12,3):setPosition(2,6):onClick(function() aItemFrame:show() aItemFrame:setFocus() end):show())
|
||||
buttonVisuals(home:addButton():setText("Remove Item"):setSize(12,3):setPosition(2,10):onClick(function() rItemFrame:show() rItemFrame:setFocus() end):show())
|
||||
|
||||
local function StringSeperate(str, seperator)
|
||||
local words = {}
|
||||
local word = ""
|
||||
|
||||
if(string.sub(str, str:len(), str:len())~=seperator)then
|
||||
str = str..""..seperator
|
||||
end
|
||||
for x=1,str:len() do
|
||||
local s = string.sub(str,x,x)
|
||||
if(s==seperator)then
|
||||
table.insert(words, word)
|
||||
word = ""
|
||||
else
|
||||
word = word..s
|
||||
end
|
||||
end
|
||||
return words
|
||||
end
|
||||
|
||||
if not(fs.exists("recipes"))then
|
||||
fs.open("recipes","w").close()
|
||||
end
|
||||
|
||||
local f = fs.open("recipes", "r")
|
||||
for line in f.readLine do
|
||||
local tab = StringSeperate(line, "|")
|
||||
if(tab[1]~=nil)and(tab[2]~=nil)and(tab[3]~=nil)and(tab[4]~=nil)and(tab[5]~=nil)then
|
||||
logging("Registered recipe: "..tab[3].."x "..tab[1]..":"..tab[2])
|
||||
local recipe = {name=tab[1],damage=tonumber(tab[2]),minAmount=tonumber(tab[3]),maxCraftAmount=tonumber(tab[4]),fails=0,timer=0}
|
||||
if(tab[5]=="true")then
|
||||
recipe.useDmg=true
|
||||
else
|
||||
recipe.useDmg=false
|
||||
end
|
||||
rList:addItem(recipe.minAmount.."x "..recipe.name..":"..recipe.damage, nil, nil, recipe)
|
||||
table.insert(recipeList, recipe)
|
||||
end
|
||||
end
|
||||
f.close()
|
||||
|
||||
local function findKeyWithItemName(table, itemname, damage)
|
||||
for k,v in pairs(table)do
|
||||
if(v.name==itemname)and(v.damage == damage)then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local scanChestBtn = home:addButton("scanChest"):setText("Scan Chest"):setSize(12,3):setPosition(2,2):show()
|
||||
local function checkChestForNewEntrys()
|
||||
scanChestBtn:setText("Scanning..")
|
||||
local inventory = peripheral.find("minecraft:chest")
|
||||
local items = {}
|
||||
local itemAmounts = {}
|
||||
local somethingChanged = false
|
||||
|
||||
if(inventory~=nil)then
|
||||
for x=1,inventory.size(), 1 do
|
||||
local item = inventory.getItemDetail(x)
|
||||
if(item~=nil)then
|
||||
if(item.damage==nil)then item.damage = 0 end
|
||||
table.insert(items, item)
|
||||
end
|
||||
os.sleep(0.1)
|
||||
end
|
||||
else
|
||||
logging("No chest available!")
|
||||
end
|
||||
|
||||
if(#items > 0)then
|
||||
for _,v in pairs(items)do
|
||||
local key = findKeyWithItemName(itemAmounts, v.name, v.damage)
|
||||
if(key~=nil)then
|
||||
itemAmounts[key].count = itemAmounts[key].count + v.count
|
||||
else
|
||||
table.insert( itemAmounts, {name=v.name, damage=v.damage, count = v.count})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if(#itemAmounts > 0)then
|
||||
for _,v in pairs(itemAmounts)do
|
||||
local key = findKeyWithItemName(recipeList, v.name, v.damage)
|
||||
if(key~=nil)then
|
||||
if(recipeList[key].minAmount ~= v.count)then
|
||||
logging("Edited recipe: "..v.name.. ":"..v.damage.." new count: "..v.count)
|
||||
end
|
||||
somethingChanged = true
|
||||
recipeList[key].minAmount = v.count
|
||||
else
|
||||
table.insert( recipeList, {name=v.name, damage=v.damage, minAmount = v.count, maxCraftAmount = 0, useDmg = true, fails = 0, timer = 0})
|
||||
somethingChanged = true
|
||||
logging("Registered recipe: "..v.count.."x "..v.name.. ":"..v.damage)
|
||||
end
|
||||
end
|
||||
if(somethingChanged)then
|
||||
SaveToFile()
|
||||
end
|
||||
end
|
||||
scanChestBtn:setText("Scan Chest")
|
||||
logging("Scanning chest done.")
|
||||
end
|
||||
|
||||
local chestScanThread = main:addThread("chestScanThread")
|
||||
buttonVisuals(scanChestBtn:onClick(function() chestScanThread:start(checkChestForNewEntrys) end))
|
||||
|
||||
|
||||
local function GetAmount(itemAmount, recipe)
|
||||
local amount = 0
|
||||
if(itemAmount < recipe.minAmount)then
|
||||
if(recipe.maxCraftAmount > 0)then
|
||||
if(recipe.minAmount-itemAmount > recipe.maxCraftAmount)then
|
||||
amount = recipe.maxCraftAmount
|
||||
else
|
||||
amount = recipe.minAmount-itemAmount
|
||||
end
|
||||
else
|
||||
amount = recipe.minAmount-itemAmount
|
||||
end
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
function GetRecipeKey(pattern)
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name == pattern.name)then
|
||||
if(pattern.damage==nil)then return k end
|
||||
if(v.useDmg)then
|
||||
if(v.damage == pattern.damage)then
|
||||
return k
|
||||
end
|
||||
else
|
||||
return k
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function CheckCraftingRecipe(recipe)
|
||||
local pattern = bridge.getItem({name=recipe.name})
|
||||
local item = {pattern=pattern, amount=0}
|
||||
if(pattern~=nil)then
|
||||
local storedAmount = pattern.amount
|
||||
local neededItemAmount = GetAmount(storedAmount, recipe)
|
||||
if(neededItemAmount > 0)then
|
||||
item.amount = neededItemAmount
|
||||
table.insert(craftingQueue, item)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function RemoveRecipe(item)
|
||||
local key = -1
|
||||
for k,v in pairs(recipeList)do
|
||||
if(v.name == item.name)and(v.damage== item.damage)then
|
||||
key = k
|
||||
end
|
||||
end
|
||||
if(key>=0)then
|
||||
table.remove(recipeList, key)
|
||||
end
|
||||
SaveToFile()
|
||||
end
|
||||
|
||||
local function FindKeyInTable(table, item)
|
||||
for k,v in pairs(table)do
|
||||
if(v==item)then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function CheckAllRecipes()
|
||||
for _,v in pairs(recipeList)do
|
||||
if(type(v)=="table")then
|
||||
CheckCraftingRecipe(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function jobCrafting(coworker, item)
|
||||
if(jobList:getItem(coworker)~=nil)then
|
||||
jobList:editItem(coworker, "Co-Worker "..coworker..": "..item.amountToCraft.."x "..item.item.displayName:gsub(" ", ""))
|
||||
else
|
||||
jobList:addItem("Co-Worker "..coworker..": "..item.amountToCraft.."x "..item.item.displayName:gsub(" ", ""))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local function jobDone(coworker)
|
||||
if(jobList:getItem(coworker)~=nil)then
|
||||
jobList:editItem(coworker, "Co-Worker "..coworker..": waiting...")
|
||||
else
|
||||
jobList:addItem("Co-Worker "..coworker..": waiting...")
|
||||
end
|
||||
end
|
||||
|
||||
local coWorkerId = 1
|
||||
local function UpdateCraftingQueue()
|
||||
while(#craftingQueue > 0)do
|
||||
local activeCoWorkers = {}
|
||||
local craftingQueuesToRemove = {}
|
||||
for _,v in pairs(craftingQueue)do
|
||||
if(#activeCoWorkers+1 <= maxCoWorker)then
|
||||
local stack = v.pattern
|
||||
local recipeKey = GetRecipeKey(stack)
|
||||
|
||||
local waittimer = 0
|
||||
local multiplier = 1
|
||||
|
||||
if(recipeList[recipeKey].fails > 0)and(recipeList[recipeKey].fails <=10)then
|
||||
multiplier = recipeList[recipeKey].fails
|
||||
elseif(recipeList[recipeKey].fails > 10)then
|
||||
multiplier = 20
|
||||
end
|
||||
waittimer = multiplier * 30
|
||||
if(os.clock()>=recipeList[recipeKey].timer+waittimer)then
|
||||
if not(bridge.isItemCrafting(stack.name))then
|
||||
local currentItemState = {item=stack, curAmount = stack.count, amountToCraft = v.amount}
|
||||
if(bridge.isItemCraftable({name=stack.name}))then
|
||||
local task, errormsg = bridge.craftItem({name=stack.name, count = v.amount})
|
||||
if(task)then
|
||||
logging("Sheduled Task: "..v.amount.." ("..stack.name..") "..stack.displayName:gsub(" ", ""))
|
||||
jobCrafting(coWorkerId, currentItemState)
|
||||
currentItemState.coWorker = coWorkerId
|
||||
coWorkerId = coWorkerId + 1
|
||||
if(coWorkerId > maxCoWorker)then coWorkerId = 1 end
|
||||
table.insert(activeCoWorkers, currentItemState)
|
||||
recipeList[recipeKey].fails = 0
|
||||
else
|
||||
logging("Error sheduling task: "..v.amount.."x ("..stack.name..") "..stack.displayName:gsub(" ", ""))
|
||||
logging("Not enough materials!")
|
||||
recipeList[recipeKey].fails = recipeList[recipeKey].fails + 1
|
||||
recipeList[recipeKey].timer = os.clock()
|
||||
end
|
||||
else
|
||||
logging("Error sheduling task: "..v.amount.."x ("..stack.name..") "..stack.displayName:gsub(" ", ""))
|
||||
logging("No pattern available!")
|
||||
recipeList[recipeKey].fails = recipeList[recipeKey].fails + 1
|
||||
recipeList[recipeKey].timer = os.clock()
|
||||
end
|
||||
end
|
||||
end
|
||||
table.insert(craftingQueuesToRemove, v)
|
||||
end
|
||||
end
|
||||
|
||||
if(#craftingQueuesToRemove > 0)then
|
||||
for _,v in pairs(craftingQueuesToRemove)do
|
||||
local id = FindKeyInTable(craftingQueue, v)
|
||||
table.remove(craftingQueue, id)
|
||||
end
|
||||
end
|
||||
|
||||
while(#activeCoWorkers > 0)do
|
||||
local finishedCoworker = {}
|
||||
for _,v in pairs(activeCoWorkers)do
|
||||
if not(bridge.isItemCrafting(v.item.name))then
|
||||
logging("Task done: "..v.amountToCraft.."x ("..v.item.name..") "..v.item.displayName:gsub(" ", ""))
|
||||
table.insert(finishedCoworker, v)
|
||||
end
|
||||
end
|
||||
if(#finishedCoworker>0)then
|
||||
for _,v in pairs(finishedCoworker)do
|
||||
local id = FindKeyInTable(activeCoWorkers, v)
|
||||
table.remove(activeCoWorkers, id)
|
||||
jobDone(v.coWorker)
|
||||
end
|
||||
end
|
||||
os.sleep(0.75)
|
||||
end
|
||||
os.sleep(0.75)
|
||||
end
|
||||
end
|
||||
|
||||
main:addThread("craftingThread"):start(function() while true do CheckAllRecipes() os.sleep(1) UpdateCraftingQueue() os.sleep(1) end end)
|
||||
|
||||
logging("Autocrafter successfully loaded!")
|
||||
|
||||
basalt.autoUpdate()
|
||||
@@ -1,303 +1,21 @@
|
||||
With animations, you can create a beautiful experience for users while interacting with objects.<br>
|
||||
For now the animation class is very basic, it will be expanded in the future, but we have to say you can already do almost everything you can imagine!
|
||||
With animations, you can create a beautiful experience for users while interacting with your program.<br>
|
||||
|
||||
Right now animation is a class which makes use of the timer event.<br>
|
||||
You can find more information below:
|
||||
|
||||
`The animation object is still a WIP and the way you use it right now could change in the future!`
|
||||
|
||||
## add
|
||||
Adds a new function to an animation
|
||||
#### Parameters:
|
||||
1. `function` The function containing animation logic
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
|
||||
#### Usage:
|
||||
* This will set the button position to 3,3, waits 1 second, then sets position to 4,4, waits 2 seconds, and then sets the position to 5,5
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
|
||||
aAnimation:play()
|
||||
```
|
||||
|
||||
## wait
|
||||
Sets a wait timer for the next function after the previous function got executed, no wait timer calls the next function immediately
|
||||
#### Parameters:
|
||||
1. `number` The length of delay between the functions _(in seconds)_
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
|
||||
|
||||
aAnimation:play()
|
||||
```
|
||||
|
||||
## play
|
||||
Plays the animation
|
||||
#### Parameters:
|
||||
1. `boolean` Whether it will loop forever, will most likely be replaced with a count in the future
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() testButton:setBackground(colors.gray) end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
|
||||
|
||||
aAnimation:play() -- changes the background color of that button from black to gray and then to lightGray
|
||||
```
|
||||
|
||||
## cancel
|
||||
Cancels the animation
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() aAnimation:cancel() end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
|
||||
|
||||
aAnimation:play()
|
||||
```
|
||||
|
||||
|
||||
## setObject
|
||||
Sets the object which the animation should reposition/resize
|
||||
|
||||
#### Parameters:
|
||||
1. `table` object
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton)
|
||||
```
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" />
|
||||
```
|
||||
|
||||
## move
|
||||
Moves the object which got defined by setObject
|
||||
|
||||
#### Parameters:
|
||||
1. `number` x coordinate
|
||||
2. `number` y coordinate
|
||||
3. `number` duration in seconds
|
||||
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
5. `table` object - optional, you could also define the object here
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
* Takes 2 seconds to move the object from its current position to x15 y3
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):move(15,3,2):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<move><x>15</x><y>6</y><duration>2</duration></move>
|
||||
</animation>
|
||||
```
|
||||
|
||||
## offset
|
||||
Changes the offset on the object which got defined by setObject
|
||||
|
||||
#### Parameters:
|
||||
1. `number` x offset
|
||||
2. `number` y offset
|
||||
3. `number` duration in seconds
|
||||
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
5. `table` object - optional, you could also define the object here
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local subFrame = mainFrame:addFrame("frameToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(subFrame):offset(1,12,1):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="frameToAnimate" play="true">
|
||||
<offset><x>1</x><y>12</y><duration>1</duration></offset>
|
||||
</animation>
|
||||
```
|
||||
|
||||
## size
|
||||
Changes the size on the object which got defined by setObject
|
||||
|
||||
#### Parameters:
|
||||
1. `number` width
|
||||
2. `number` height
|
||||
3. `number` duration in seconds
|
||||
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
5. `table` object - optional, you could also define the object here
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):size(15,3,1):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<offset><w>15</w><h>3</h><duration>1</duration></offset>
|
||||
</animation>
|
||||
```
|
||||
|
||||
## changeText
|
||||
Changes the text while animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple text strings - example: {"i", "am", "groot"}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText({"i", "am", "groot"}, 2):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<text>
|
||||
<text>i</text>
|
||||
<text>am</text>
|
||||
<text>groot</text>
|
||||
<duration>2</duration>
|
||||
</text>
|
||||
</animation>
|
||||
```
|
||||
|
||||
## changeTextColor
|
||||
Changes the text color while the animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<textColor>
|
||||
<color>red</color>
|
||||
<color>yellow</color>
|
||||
<color>green</color>
|
||||
<duration>2</duration>
|
||||
</textColor>
|
||||
</animation>
|
||||
```
|
||||
|
||||
## changeBackground
|
||||
Changes the background color while the animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<background>
|
||||
<color>red</color>
|
||||
<color>yellow</color>
|
||||
<color>green</color>
|
||||
<duration>2</duration>
|
||||
</background>
|
||||
</animation>
|
||||
```
|
||||
| | |
|
||||
|---|---|
|
||||
|[add](objects/Animation/add.md)|Adds a new custom function to call at the current time
|
||||
|[wait](objects/Animation/wait.md)|Adds a amount to the animation time
|
||||
|[play](objects/Animation/play.md)|Plays the animation
|
||||
|[cancel](objects/Animation/cancel.md)|Cancels the animation
|
||||
|[setObject](objects/Animation/setObject.md)|Sets an object on which predefined animations should work on
|
||||
|[move](objects/Animation/move.md)|Predefined animation: moves the object to a new position
|
||||
|[offset](objects/Animation/offset.md)|Predefined animation: Changes the offset of that object
|
||||
|[size](objects/Animation/size.md)|Predefined animation: Changes the size on a object
|
||||
|[changeText](objects/Animation/changeText.md)|Predefined animation: Changes the text (object needs a setText method)
|
||||
|[changeTextColor](objects/Animation/changeTextColor.md)|Predefined animation: changes the foreground/textcolor on a object
|
||||
|[changeBackground](objects/Animation/changeBackground.md)|Predefined animation: changes the background on a object
|
||||
|
||||
# Events
|
||||
|
||||
## onDone
|
||||
`onDone(self)`<br>
|
||||
This is a event which gets fired as soon as the animation has finished.
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
|
||||
aAnimation:onDone(function()
|
||||
basalt.debug("The animation is done")
|
||||
end)
|
||||
```
|
||||
|
||||
In XML you are also able to queue multiple animations, like this:
|
||||
|
||||
```xml
|
||||
<animation id="anim2" object="buttonToAnimate">
|
||||
<textColor>
|
||||
<color>red</color>
|
||||
<color>yellow</color>
|
||||
<color>green</color>
|
||||
<duration>2</duration>
|
||||
</textColor>
|
||||
</animation>
|
||||
<animation onDone="#anim2" object="buttonToAnimate" play="true">
|
||||
<background>
|
||||
<color>red</color>
|
||||
<color>yellow</color>
|
||||
<color>green</color>
|
||||
<duration>2</duration>
|
||||
</background>
|
||||
</animation>
|
||||
```
|
||||
| | |
|
||||
|---|---|
|
||||
|[onDone](objects/Animation/onDone.md)|Gets called as soon as the animation has finished
|
||||
|
||||
17
docs/objects/Animation/add.md
Normal file
17
docs/objects/Animation/add.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## add
|
||||
Adds a new function to an animation
|
||||
#### Parameters:
|
||||
1. `function` The function containing animation logic
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
|
||||
#### Usage:
|
||||
* This will set the button position to 3,3, waits 1 second, then sets position to 4,4, waits 2 seconds, and then sets the position to 5,5
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
|
||||
aAnimation:play()
|
||||
```
|
||||
15
docs/objects/Animation/cancel.md
Normal file
15
docs/objects/Animation/cancel.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## cancel
|
||||
Cancels the animation
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() aAnimation:cancel() end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
|
||||
|
||||
aAnimation:play()
|
||||
```
|
||||
28
docs/objects/Animation/changeBackground.md
Normal file
28
docs/objects/Animation/changeBackground.md
Normal file
@@ -0,0 +1,28 @@
|
||||
## changeBackground
|
||||
Changes the background color while the animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor(2, 0, colors.red, colors.yellow, colors.green):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<background>
|
||||
<color>red</color>
|
||||
<color>yellow</color>
|
||||
<color>green</color>
|
||||
<duration>2</duration>
|
||||
</background>
|
||||
</animation>
|
||||
```
|
||||
28
docs/objects/Animation/changeText.md
Normal file
28
docs/objects/Animation/changeText.md
Normal file
@@ -0,0 +1,28 @@
|
||||
## changeText
|
||||
Changes the text while animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple text strings - example: {"i", "am", "groot"}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText(2, 0, "i", "am", "groot"):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<text>
|
||||
<text>i</text>
|
||||
<text>am</text>
|
||||
<text>groot</text>
|
||||
<duration>2</duration>
|
||||
</text>
|
||||
</animation>
|
||||
```
|
||||
28
docs/objects/Animation/changeTextColor.md
Normal file
28
docs/objects/Animation/changeTextColor.md
Normal file
@@ -0,0 +1,28 @@
|
||||
## changeTextColor
|
||||
Changes the text color while the animation is running
|
||||
|
||||
#### Parameters:
|
||||
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
|
||||
2. `number` duration in seconds
|
||||
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor(2, 0, colors.red, colors.yellow, colors.green):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<textColor>
|
||||
<color>red</color>
|
||||
<color>yellow</color>
|
||||
<color>green</color>
|
||||
<duration>2</duration>
|
||||
</textColor>
|
||||
</animation>
|
||||
```
|
||||
25
docs/objects/Animation/move.md
Normal file
25
docs/objects/Animation/move.md
Normal file
@@ -0,0 +1,25 @@
|
||||
## move
|
||||
Moves the object which got defined by setObject
|
||||
|
||||
#### Parameters:
|
||||
1. `number` x coordinate
|
||||
2. `number` y coordinate
|
||||
3. `number` duration in seconds
|
||||
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
5. `table` object - optional, you could also define the object here
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
* Takes 2 seconds to move the object from its current position to x15 y3
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):move(15,3,2):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<move><x>15</x><y>6</y><duration>2</duration></move>
|
||||
</animation>
|
||||
```
|
||||
25
docs/objects/Animation/offset.md
Normal file
25
docs/objects/Animation/offset.md
Normal file
@@ -0,0 +1,25 @@
|
||||
## offset
|
||||
Changes the offset on the object which got defined by setObject
|
||||
|
||||
#### Parameters:
|
||||
1. `number` x offset
|
||||
2. `number` y offset
|
||||
3. `number` duration in seconds
|
||||
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
5. `table` object - optional, you could also define the object here
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local subFrame = mainFrame:addFrame("frameToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(subFrame):offset(1,12,1):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="frameToAnimate" play="true">
|
||||
<offset><x>1</x><y>12</y><duration>1</duration></offset>
|
||||
</animation>
|
||||
```
|
||||
35
docs/objects/Animation/onDone.md
Normal file
35
docs/objects/Animation/onDone.md
Normal file
@@ -0,0 +1,35 @@
|
||||
## onDone
|
||||
`onDone(self)`<br>
|
||||
This is a event which gets fired as soon as the animation has finished.
|
||||
|
||||
```lua
|
||||
local basalt = require("Basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
|
||||
aAnimation:onDone(function()
|
||||
basalt.debug("The animation is done")
|
||||
end)
|
||||
```
|
||||
|
||||
In XML you are also able to queue multiple animations, like this:
|
||||
|
||||
```xml
|
||||
<animation id="anim2" object="buttonToAnimate">
|
||||
<textColor>
|
||||
<color>red</color>
|
||||
<color>yellow</color>
|
||||
<color>green</color>
|
||||
<duration>2</duration>
|
||||
</textColor>
|
||||
</animation>
|
||||
<animation onDone="#anim2" object="buttonToAnimate" play="true">
|
||||
<background>
|
||||
<color>red</color>
|
||||
<color>yellow</color>
|
||||
<color>green</color>
|
||||
<duration>2</duration>
|
||||
</background>
|
||||
</animation>
|
||||
```
|
||||
16
docs/objects/Animation/play.md
Normal file
16
docs/objects/Animation/play.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## play
|
||||
Plays the animation
|
||||
#### Parameters:
|
||||
1. `boolean` Whether it will loop forever, will most likely be replaced with a count in the future
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():add(function() testButton:setBackground(colors.black) end):wait(1):add(function() testButton:setBackground(colors.gray) end):wait(1):add(function() testButton:setBackground(colors.lightGray) end)
|
||||
|
||||
aAnimation:play() -- changes the background color of that button from black to gray and then to lightGray
|
||||
```
|
||||
24
docs/objects/Animation/setObject.md
Normal file
24
docs/objects/Animation/setObject.md
Normal file
@@ -0,0 +1,24 @@
|
||||
## setObject
|
||||
Sets the object which the animation should reposition/resize
|
||||
|
||||
#### Parameters:
|
||||
1. `table` object
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton)
|
||||
```
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" />
|
||||
```
|
||||
24
docs/objects/Animation/size.md
Normal file
24
docs/objects/Animation/size.md
Normal file
@@ -0,0 +1,24 @@
|
||||
## size
|
||||
Changes the size on the object which got defined by setObject
|
||||
|
||||
#### Parameters:
|
||||
1. `number` width
|
||||
2. `number` height
|
||||
3. `number` duration in seconds
|
||||
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
|
||||
5. `table` object - optional, you could also define the object here
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton("buttonToAnimate")
|
||||
local aAnimation = mainFrame:addAnimation():setObject(testButton):size(15,3,1):play()
|
||||
```
|
||||
```xml
|
||||
<animation object="buttonToAnimate" play="true">
|
||||
<offset><w>15</w><h>3</h><duration>1</duration></offset>
|
||||
</animation>
|
||||
```
|
||||
16
docs/objects/Animation/wait.md
Normal file
16
docs/objects/Animation/wait.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## wait
|
||||
Sets a wait timer for the next function after the previous function got executed, no wait timer calls the next function immediately
|
||||
#### Parameters:
|
||||
1. `number` The length of delay between the functions _(in seconds)_
|
||||
|
||||
#### Returns:
|
||||
1. `animation` Animation in use
|
||||
|
||||
#### Usage:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local testButton = mainFrame:addButton()
|
||||
local aAnimation = mainFrame:addAnimation():add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end)
|
||||
|
||||
aAnimation:play()
|
||||
```
|
||||
@@ -1,201 +1,37 @@
|
||||
This is the UI Manager and the first thing you want to access.
|
||||
Before you can access Basalt, you need to add the following code on top of your file:
|
||||
|
||||
`local basalt = require("Basalt")`
|
||||
`local basalt = require("basalt")`
|
||||
|
||||
Now you are able to access the following methods:
|
||||
require loads the UI Framework into your project.
|
||||
|
||||
## basalt.createFrame
|
||||
Create a base-frame (main frame)
|
||||
#### Parameters:
|
||||
1. `string` name
|
||||
Now you are able to access the following list of methods:
|
||||
|
||||
#### Returns:
|
||||
1. `frame` object
|
||||
| | |
|
||||
|---|---|
|
||||
|[createFrame](objects/Basalt/createFrame.md)|Creates a new base frame
|
||||
|[removeFrame](objects/Basalt/removeFrame.md)|Removes a previously created base frame
|
||||
|[getFrame](objects/Basalt/getFrame.md)|Returns a frame object by it's id
|
||||
|[getActiveFrame](objects/Basalt/getActiveFrame.md)|Returns the currently active base frame
|
||||
|[autoUpdate](objects/Basalt/autoUpdate.md)|Starts the event and draw listener
|
||||
|[update](objects/Basalt/update.md)|Starts the event and draw listener once
|
||||
|[stopUpdate](objects/Basalt/stopUpdate.md)|Stops the currently active event and draw listener
|
||||
|[isKeyDown](objects/Basalt/isKeyDown.md)|Returns if the key is held down
|
||||
|[debug](objects/Basalt/debug.md)|Writes something into the debug console
|
||||
|[log](objects/Basalt/log.md)|Writes something into the log file
|
||||
|[setTheme](objects/Basalt/setTheme.md)|Changes the base theme of basalt
|
||||
|[setVariable](objects/Basalt/setVariable.md)|Sets a variable which you can access via XML
|
||||
|[schedule](objects/Basalt/schedule.md)|Schedules a new task
|
||||
|
||||
#### Usage:
|
||||
* Create and show a frame with id "myFirstFrame"
|
||||
# Examples
|
||||
|
||||
Here is a lua example on how to create a empty base frame and start basalt's listener.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame("myFirstFrame")
|
||||
```
|
||||
local basalt = require("basalt") -- we load the UI Framework into our project
|
||||
|
||||
## basalt.removeFrame
|
||||
Removes a base frame
|
||||
local main = basalt.createFrame() -- we create a base frame - on that frame we are able to add object's
|
||||
|
||||
#### Parameters:
|
||||
1. `string` name
|
||||
-- here we would add additional object's
|
||||
|
||||
#### Usage:
|
||||
* Removes the previously created frame with id "myFirstFrame"
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame("myFirstFrame")
|
||||
basalt.removeFrame("myFirstFrame")
|
||||
```
|
||||
|
||||
## basalt.getFrame
|
||||
Returns a base frame with the given name
|
||||
#### Parameters:
|
||||
1. `string` name
|
||||
|
||||
#### Returns:
|
||||
1. `frame` object
|
||||
|
||||
#### Usage:
|
||||
* Creates, fetches and shows the "myFirstFrame" object
|
||||
```lua
|
||||
basalt.createFrame("myFirstFrame"):hide()
|
||||
basalt.getFrame("myFirstFrame"):show()
|
||||
```
|
||||
|
||||
## basalt.getActiveFrame
|
||||
Returns the currently active base frame
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The current frame
|
||||
|
||||
#### Usage:
|
||||
* Displays the active frame name in the debug console
|
||||
```lua
|
||||
basalt.createFrame()
|
||||
basalt.debug(basalt.getActiveFrame():getName()) -- returns the uuid
|
||||
```
|
||||
|
||||
## basalt.autoUpdate
|
||||
Starts the draw and event handler until basalt.stopUpdate() is called
|
||||
|
||||
#### Usage:
|
||||
* Enable the basalt updates, otherwise the screen will not continue to update
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
|
||||
## basalt.update
|
||||
Calls the draw and event handler once - this gives more flexibility about which events basalt should process. For example you could filter the terminate event.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The event to be received
|
||||
2. `...` Additional event variables to capture
|
||||
|
||||
#### Usage:
|
||||
* Creates and starts a custom update cycle
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setPosition(2,2)
|
||||
while true do
|
||||
basalt.update(os.pullEventRaw())
|
||||
end
|
||||
```
|
||||
|
||||
## basalt.stopUpdate
|
||||
Stops the automatic draw and event handler which got started by basalt.autoUpdate()
|
||||
|
||||
#### Usage:
|
||||
* When the quit button is clicked, the button stops basalt auto updates
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setPosition(2,2):setText("Stop Basalt!")
|
||||
aButton:onClick(function()
|
||||
basalt.stopUpdate()
|
||||
end)
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
|
||||
## basalt.isKeyDown
|
||||
Checks if the user is currently holding a key
|
||||
|
||||
#### Parameters:
|
||||
1. `number` key code (use the keys table for that)
|
||||
|
||||
#### Returns:
|
||||
1. `boolean` true or false
|
||||
|
||||
#### Usage:
|
||||
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setPosition(2,2):setText("Check Ctrl")
|
||||
aButton:onClick(function()
|
||||
basalt.debug(basalt.isKeyDown(keys.leftCtrl))
|
||||
end)
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
|
||||
## basalt.debug
|
||||
creates a label with some information on the main frame on the bottom left, if you click on that label it will open a log view for you. See it as the new print for debugging
|
||||
|
||||
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable basalt.debugLabel
|
||||
which returns the debug Label.
|
||||
|
||||
Also basalt.debugFrame and basalt.debugList are available.
|
||||
|
||||
#### Parameters:
|
||||
1. `...` (multiple parameters are possible, like print does)
|
||||
|
||||
#### Usage:
|
||||
* Prints "Hello! ^-^" to the debug console
|
||||
```lua
|
||||
basalt.debug("Hello! ", "^-^")
|
||||
```
|
||||
|
||||
## basalt.setTheme
|
||||
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua)
|
||||
|
||||
#### Parameters:
|
||||
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
|
||||
|
||||
#### Usage:
|
||||
* Sets the default theme of basalt.
|
||||
```lua
|
||||
basalt.setTheme({
|
||||
ButtonBG = colors.yellow,
|
||||
ButtonText = colors.red,
|
||||
...,
|
||||
})
|
||||
```
|
||||
|
||||
## basalt.setVariable
|
||||
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` a key name
|
||||
1. `any` any variable
|
||||
|
||||
#### Usage:
|
||||
* Adds a function to basalt.
|
||||
```lua
|
||||
basalt.setVariable("clickMe", function()
|
||||
basalt.debug("I got clicked")
|
||||
end)
|
||||
```
|
||||
```xml
|
||||
<button onClick="clickMe" text="Click me" />
|
||||
```
|
||||
|
||||
## basalt.schedule
|
||||
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
|
||||
|
||||
#### Parameters:
|
||||
1. `function` a function which should get executed
|
||||
|
||||
#### Returns:
|
||||
1. `function` it returns the function which you have to execute in order to start the coroutine
|
||||
|
||||
#### Usage:
|
||||
* Creates a schedule which switches the color between red and gray
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setText("Click me")
|
||||
aButton:onClick(basalt.schedule(function(self)
|
||||
self:setBackground(colors.red)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.gray)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.red)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.gray)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.red)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.gray)
|
||||
end))
|
||||
```
|
||||
basalt.autoUpdate() -- we start listening to incoming events and draw stuff on the screen
|
||||
```
|
||||
12
docs/objects/Basalt/autoUpdate.md
Normal file
12
docs/objects/Basalt/autoUpdate.md
Normal file
@@ -0,0 +1,12 @@
|
||||
## basalt.autoUpdate
|
||||
This starts the event and draw handler for you. The listeners will run until you stop them.
|
||||
|
||||
#### Parameters:
|
||||
1. `boolean` optional - if you use false as the first parameter it would stop the listeners.
|
||||
|
||||
#### Usage:
|
||||
* Enable the basalt listeners, otherwise the screen will not continue to update
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
27
docs/objects/Basalt/createFrame.md
Normal file
27
docs/objects/Basalt/createFrame.md
Normal file
@@ -0,0 +1,27 @@
|
||||
## basalt.createFrame
|
||||
Creates a new base-frame, you can have as many base-frames as you want, but only 1 can be active (visible) at the same time.
|
||||
You can always switch between your base frames.
|
||||
|
||||
Only the currently active base-frame listens to incoming events (except for some events like time-events and peripheral-events)
|
||||
|
||||
#### Parameters:
|
||||
1. `string` id - optional (if you dont set a id it will automatically create a uuid for you)
|
||||
|
||||
#### Returns:
|
||||
1. `frame` object
|
||||
|
||||
#### Usage:
|
||||
* How to use multiple base frames:
|
||||
```lua
|
||||
local main1 = basalt.createFrame() -- Visible base frame on program start
|
||||
local main2 = basalt.createFrame()
|
||||
local main3 = basalt.createFrame()
|
||||
main1:addButton()
|
||||
:setPosition(2,2)
|
||||
:setText("Switch")
|
||||
:onClick(function()
|
||||
main2:show() -- this function automatically "hides" the first one and shows the second one
|
||||
end)
|
||||
main2:addLabel()
|
||||
:setText("We are currently on main2")
|
||||
```
|
||||
22
docs/objects/Basalt/debug.md
Normal file
22
docs/objects/Basalt/debug.md
Normal file
@@ -0,0 +1,22 @@
|
||||
## basalt.debug
|
||||
Creates a label with some information on the main frame on the bottom left. When you click on that label it will open a log view for you. See it as the new print for debugging
|
||||
|
||||
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable basalt.debugLabel
|
||||
which returns the debug Label.
|
||||
|
||||
Also basalt.debugFrame and basalt.debugList are available.
|
||||
|
||||
#### Parameters:
|
||||
1. `...` (multiple parameters are possible, like print does)
|
||||
|
||||
#### Usage:
|
||||
* Prints "Hello! ^-^" to the debug console
|
||||
```lua
|
||||
basalt.debug("Hello! ", "^-^")
|
||||
```
|
||||
|
||||
* Changes the debug label's anchor
|
||||
```lua
|
||||
basalt.debugLabel:setAnchor("topLeft") -- default anchor is bottomLeft
|
||||
basalt.debug("Hello!")
|
||||
```
|
||||
12
docs/objects/Basalt/getActiveFrame.md
Normal file
12
docs/objects/Basalt/getActiveFrame.md
Normal file
@@ -0,0 +1,12 @@
|
||||
## basalt.getActiveFrame
|
||||
Returns the currently active/visible base frame
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The current frame
|
||||
|
||||
#### Usage:
|
||||
* Displays the active frame name in the debug console
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
basalt.debug(basalt.getActiveFrame():getName()) -- returns the id
|
||||
```
|
||||
23
docs/objects/Basalt/getFrame.md
Normal file
23
docs/objects/Basalt/getFrame.md
Normal file
@@ -0,0 +1,23 @@
|
||||
## basalt.getFrame
|
||||
Returns a base frame by the given id
|
||||
|
||||
#### Parameters:
|
||||
1. `string` id
|
||||
|
||||
#### Returns:
|
||||
1. `frame` object
|
||||
|
||||
#### Usage:
|
||||
* Creates, fetches and shows the "myFirstFrame" object
|
||||
```lua
|
||||
local main = basalt.createFrame("firstBaseFrame")
|
||||
local main2 = basalt.createFrame("secondBaseFrame")
|
||||
main:addButton()
|
||||
:setText("Show")
|
||||
:onClick(function()
|
||||
local frame2 = basalt.getFrame("secondBaseFrame")
|
||||
if(frame2~=nil)then
|
||||
frame2:show()
|
||||
end
|
||||
end)
|
||||
```
|
||||
21
docs/objects/Basalt/isKeyDown.md
Normal file
21
docs/objects/Basalt/isKeyDown.md
Normal file
@@ -0,0 +1,21 @@
|
||||
## basalt.isKeyDown
|
||||
Checks if the user is currently holding a key
|
||||
|
||||
#### Parameters:
|
||||
1. `number` key code (use the keys table for that)
|
||||
|
||||
#### Returns:
|
||||
1. `boolean` true or false
|
||||
|
||||
#### Usage:
|
||||
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton()
|
||||
:setPosition(2,2)
|
||||
:setText("Check Ctrl")
|
||||
:onClick(function()
|
||||
basalt.debug(basalt.isKeyDown(keys.leftCtrl))
|
||||
end)
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
15
docs/objects/Basalt/log.md
Normal file
15
docs/objects/Basalt/log.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## basalt.log
|
||||
This writes something into a file. The main goal is to make debugging errors easier. Lets say you'r program is crashing and
|
||||
you don't know why, you could use basalt.log
|
||||
|
||||
The log files will automatically removed after you start your program again
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The text to write into the log file
|
||||
2. `string` - optional (default: "Debug") - the type to write
|
||||
|
||||
#### Usage:
|
||||
* Writes "Hello!" into the log file
|
||||
```lua
|
||||
basalt.log("Hello!")
|
||||
```
|
||||
17
docs/objects/Basalt/removeFrame.md
Normal file
17
docs/objects/Basalt/removeFrame.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## basalt.removeFrame
|
||||
Removes the base frame by it's id. This only works for base-frames.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` id
|
||||
|
||||
#### Usage:
|
||||
* Removes the previously created frame with id "myFirstFrame"
|
||||
```lua
|
||||
local main = basalt.createFrame("firstBaseFrame")
|
||||
local main2 = basalt.createFrame("secondBaseFrame")
|
||||
main:addButton()
|
||||
:setText("Remove")
|
||||
:onClick(function()
|
||||
basalt.removeFrame(main2:getName()) -- you can use main2:getName() to find out the id or just use "secondBaseFrame"
|
||||
end)
|
||||
```
|
||||
28
docs/objects/Basalt/schedule.md
Normal file
28
docs/objects/Basalt/schedule.md
Normal file
@@ -0,0 +1,28 @@
|
||||
## basalt.schedule
|
||||
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
|
||||
|
||||
#### Parameters:
|
||||
1. `function` a function which should get executed
|
||||
|
||||
#### Returns:
|
||||
1. `function` it returns the function which you have to execute in order to start the coroutine
|
||||
|
||||
#### Usage:
|
||||
* Creates a schedule which switches the color between red and gray
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setText("Click me")
|
||||
aButton:onClick(basalt.schedule(function(self)
|
||||
self:setBackground(colors.red)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.gray)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.red)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.gray)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.red)
|
||||
os.sleep(0.1)
|
||||
self:setBackground(colors.gray)
|
||||
end))
|
||||
```
|
||||
15
docs/objects/Basalt/setTheme.md
Normal file
15
docs/objects/Basalt/setTheme.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## basalt.setTheme
|
||||
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua)
|
||||
|
||||
#### Parameters:
|
||||
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
|
||||
|
||||
#### Usage:
|
||||
* Sets the default theme of basalt.
|
||||
```lua
|
||||
basalt.setTheme({
|
||||
ButtonBG = colors.yellow,
|
||||
ButtonText = colors.red,
|
||||
...,
|
||||
})
|
||||
```
|
||||
17
docs/objects/Basalt/setVariable.md
Normal file
17
docs/objects/Basalt/setVariable.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## basalt.setVariable
|
||||
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` a key name
|
||||
1. `any` any variable
|
||||
|
||||
#### Usage:
|
||||
* Adds a function to basalt.
|
||||
```lua
|
||||
basalt.setVariable("clickMe", function()
|
||||
basalt.debug("I got clicked")
|
||||
end)
|
||||
```
|
||||
```xml
|
||||
<button onClick="clickMe" text="Click me" />
|
||||
```
|
||||
15
docs/objects/Basalt/stopUpdate.md
Normal file
15
docs/objects/Basalt/stopUpdate.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## basalt.stopUpdate or basalt.stop
|
||||
Stops the automatic draw and event handler which got started by basalt.autoUpdate()
|
||||
|
||||
#### Usage:
|
||||
* When the quit button is clicked, the button stops basalt's event listeners and draw handlers
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
local aButton = main:addButton()
|
||||
:setPosition(2,2)
|
||||
:setText("Stop Basalt!")
|
||||
:onClick(function()
|
||||
basalt.stopUpdate()
|
||||
end)
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
18
docs/objects/Basalt/update.md
Normal file
18
docs/objects/Basalt/update.md
Normal file
@@ -0,0 +1,18 @@
|
||||
## basalt.update
|
||||
Calls the draw and event handler once - this gives more flexibility about which events basalt should process. For example you could filter the terminate event.
|
||||
Which means you have to pass the events into basalt.update.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The event to be received
|
||||
2. `...` Additional event variables to capture
|
||||
|
||||
#### Usage:
|
||||
* Creates and starts a custom update cycle
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setPosition(2,2)
|
||||
while true do
|
||||
local ev = table.pack(os.pullEventRaw())
|
||||
basalt.update(table.unpack(ev))
|
||||
end
|
||||
```
|
||||
@@ -1,73 +1,19 @@
|
||||
Buttons are objects, which execute something by clicking on them.<br>
|
||||
The button object is for creating buttons If you click on them, they should execute something. You decide what should happen when clicking on them.
|
||||
|
||||
Remember button also inherits from [Object](objects/Object.md)
|
||||
[Object](objects/Object.md) methods also apply for buttons.
|
||||
|
||||
## setText
|
||||
Sets the displayed button text
|
||||
#### Parameters:
|
||||
1. `string` the text the button should show
|
||||
| | |
|
||||
|---|---|
|
||||
|[setText](objects/Button/setText.md)|Changes the button text
|
||||
|[setHorizontalAlign](objects/Button/setHorizontalAlign.md)|Changes the horizontal text position
|
||||
|[setVerticalAlign](objects/Button/setVerticalAlign.md)|Changes the vertical text position
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a button with "Click me!" as text.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local button = mainFrame:addButton():setText("Click me!")
|
||||
```
|
||||
```xml
|
||||
<button text="Click me!" />
|
||||
```
|
||||
|
||||
## setHorizontalAlign
|
||||
Sets the horizontal align of the button text
|
||||
|
||||
#### Parameters:
|
||||
1. `string` the position as string ("left", "center", "right") - default is center.
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Sets the button's horizontal text align to right.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local button = mainFrame:addButton()
|
||||
:setText("Click me!")
|
||||
:setHorizontalAlign("right")
|
||||
```
|
||||
```xml
|
||||
<button text="Click me!" horizontalAlign="right" />
|
||||
```
|
||||
|
||||
## setVerticalAlign
|
||||
Sets the vertical align of the button text
|
||||
|
||||
#### Parameters:
|
||||
1. `string` the position as string ("top", "center", "bottom") - default is center.
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Sets the button's horizontal text align to right and the vertical text align to bottom.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local button = mainFrame:addButton()
|
||||
:setText("Click me!")
|
||||
:setHorizontalAlign("right")
|
||||
:setVerticalAlign("bottom")
|
||||
```
|
||||
```xml
|
||||
<button text="Click me!" horizontalAlign="right" verticalAlign="bottom" />
|
||||
```
|
||||
|
||||
# Example
|
||||
This is a example on how you would create a fully working button:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aButton = mainFrame:addButton():setText("Click")
|
||||
local main = basalt.createFrame()
|
||||
local aButton = main:addButton():setText("Click")
|
||||
|
||||
aButton:onClick(function(self,event,button,x,y)
|
||||
if(event=="mouse_click")and(button==1)then
|
||||
@@ -76,15 +22,15 @@ aButton:onClick(function(self,event,button,x,y)
|
||||
end)
|
||||
```
|
||||
|
||||
and this would be the xml way to do it:
|
||||
and this would be the xml way:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():addLayout("example.xml")
|
||||
|
||||
basalt.setVariable("buttonClick", function(self,event,button,x,y)
|
||||
if(event=="mouse_click")and(button==1)then
|
||||
basalt.debug("Left mousebutton got clicked!")
|
||||
end
|
||||
end)
|
||||
|
||||
local main = basalt.createFrame():addLayout("example.xml")
|
||||
```
|
||||
```xml
|
||||
<button onClick="buttonClick" text="Click" />
|
||||
|
||||
20
docs/objects/Button/setHorizontalAlign.md
Normal file
20
docs/objects/Button/setHorizontalAlign.md
Normal file
@@ -0,0 +1,20 @@
|
||||
## setHorizontalAlign
|
||||
Sets the horizontal align of the button text
|
||||
|
||||
#### Parameters:
|
||||
1. `string` the position as string ("left", "center", "right") - default is center.
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Sets the button's horizontal text align to right.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local button = mainFrame:addButton()
|
||||
:setText("Click me!")
|
||||
:setHorizontalAlign("right")
|
||||
```
|
||||
```xml
|
||||
<button text="Click me!" horizontalAlign="right" />
|
||||
```
|
||||
17
docs/objects/Button/setText.md
Normal file
17
docs/objects/Button/setText.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## setText
|
||||
Sets the displayed button text
|
||||
#### Parameters:
|
||||
1. `string` the text the button should show
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a button with "Click me!" as text.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local button = mainFrame:addButton():setText("Click me!")
|
||||
```
|
||||
```xml
|
||||
<button text="Click me!" />
|
||||
```
|
||||
21
docs/objects/Button/setVerticalAlign.md
Normal file
21
docs/objects/Button/setVerticalAlign.md
Normal file
@@ -0,0 +1,21 @@
|
||||
## setVerticalAlign
|
||||
Sets the vertical align of the button text
|
||||
|
||||
#### Parameters:
|
||||
1. `string` the position as string ("top", "center", "bottom") - default is center.
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Sets the button's horizontal text align to right and the vertical text align to bottom.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local button = mainFrame:addButton()
|
||||
:setText("Click me!")
|
||||
:setHorizontalAlign("right")
|
||||
:setVerticalAlign("bottom")
|
||||
```
|
||||
```xml
|
||||
<button text="Click me!" horizontalAlign="right" verticalAlign="bottom" />
|
||||
```
|
||||
@@ -1,14 +1,17 @@
|
||||
With checkbox objects the user can set a bool to true or false
|
||||
With checkboxes the user can set a boolean to true or false by clicking on them.
|
||||
|
||||
Remember checkbox also inherits from [Object](objects/Object.md)
|
||||
[Object](objects/Object.md) methods also apply for checkboxes.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|[setSymbol](objects/Checkbox/setSymbol.md)|Changes the symbol when checkbox is checked
|
||||
|
||||
A checkbox does not have any custom methods. All required methods are provided by the base [object](objects/Object.md) class.
|
||||
|
||||
# Example
|
||||
This is how you would create a event which gets fired as soon as the value gets changed:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aCheckbox = mainFrame:addCheckbox()
|
||||
local main = basalt.createFrame()
|
||||
local aCheckbox = main:addCheckbox()
|
||||
|
||||
local function checkboxChange(self)
|
||||
local checked = self:getValue()
|
||||
@@ -19,7 +22,7 @@ aCheckbox:onChange(checkboxChange)
|
||||
|
||||
also possible via xml:
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():addLayout("example.xml")
|
||||
local main = basalt.createFrame():addLayout("example.xml")
|
||||
|
||||
basalt.setVariable("checkboxChange", function(self)
|
||||
local checked = self:getValue()
|
||||
|
||||
18
docs/objects/Checkbox/setSymbol.md
Normal file
18
docs/objects/Checkbox/setSymbol.md
Normal file
@@ -0,0 +1,18 @@
|
||||
## setSymbol
|
||||
Changes the checkbox symbol, default is "\42"
|
||||
|
||||
#### Parameters:
|
||||
1. `string` symbol
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a new checkbox and changes the symbol to o
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
local checkbox = main:addCheckbox():setSymbol("o")
|
||||
```
|
||||
```xml
|
||||
<checkbox symbol="o" />
|
||||
```
|
||||
@@ -1,307 +1,31 @@
|
||||
Dropdowns are objects where the user can click on a button, this will open a list where the user can choose from.
|
||||
|
||||
If you want to access values inside items this is how the table for single items is made (just a example):
|
||||
[Object](objects/Object.md) methods also apply for dropdowns.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|[addItem](objects/Dropdown/addItem.md)|Adds a new item into the list
|
||||
|[removeItem](objects/Dropdown/removeItem.md)|Removes a item from the list
|
||||
|[editItem](objects/Dropdown/editItem.md)|Changes a already existing item in the list
|
||||
|[getItem](objects/Dropdown/getItem.md)|Returns a item by its index
|
||||
|[getItemCount](objects/Dropdown/getItemCount.md)|Returns the item count
|
||||
|[getAll](objects/Dropdown/getAll.md)|Returns the entire list as a table
|
||||
|[selectItem](objects/Dropdown/selectItem.md)|Selects a item
|
||||
|[clear](objects/Dropdown/clear.md)|Makes the entire list empty
|
||||
|[getItemIndex](objects/Dropdown/getItemIndex.md)|Returns the currently active item index
|
||||
|[setSelectedItem](objects/Dropdown/setSelectedItem.md)|Changes the default bg and fg, when the user selects a item
|
||||
|[setOffset](objects/Dropdown/setOffset.md)|Changes the list offset
|
||||
|[getOffset](objects/Dropdown/getOffset.md)|Returns the current offset
|
||||
|[setDropdownSize](objects/Dropdown/setDropdownSize.md)|Changes the dropdown size
|
||||
|
||||
|
||||
A item-table in dropdowns looks like the following example:
|
||||
|
||||
```lua
|
||||
item = {
|
||||
text="1. Entry",
|
||||
bgCol=colors.black,
|
||||
fgCol=colors.white
|
||||
args = {}
|
||||
text="1. Entry", -- the text its showing
|
||||
bgCol=colors.black, -- the background color
|
||||
fgCol=colors.white -- the foreground color
|
||||
args = {} -- custom args you want to pass, which you will be able to access in for example onChange events
|
||||
}
|
||||
```
|
||||
|
||||
Remember Dropdown also inherits from [Object](objects/Object.md)
|
||||
|
||||
## addItem
|
||||
Adds a item into the dropdown
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The entry name
|
||||
2. `number|color` unique default background color - optional
|
||||
3. `number|color` unique default text color - optional
|
||||
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
```
|
||||
```xml
|
||||
<dropdown>
|
||||
<item><text>1. Entry</text></item>
|
||||
<item><text>2. Entry</text><bg>yellow</bg></item>
|
||||
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
|
||||
</dropdown>
|
||||
```
|
||||
|
||||
## removeItem
|
||||
Removes a item from the dropdown
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The index which should get removed
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and removes the second one.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:removeItem(2)
|
||||
```
|
||||
|
||||
## editItem
|
||||
Edits a item from the dropdown
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The index which should be edited
|
||||
2. `string` The new item name
|
||||
3. `number` the new item background color - optional
|
||||
4. `number` The new item text color - optional
|
||||
5. `any` New additional information - optional
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and edits the second one.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:editItem(2, "Still 2. Entry", colors.red)
|
||||
```
|
||||
|
||||
## getItem
|
||||
Returns a item by index
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The index which should be returned
|
||||
|
||||
#### Returns:
|
||||
1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and edits the second one.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
basalt.debug(aDropdown:getItem(2).text)
|
||||
```
|
||||
|
||||
## getItemCount
|
||||
Returns the current item count
|
||||
|
||||
#### Returns:
|
||||
1. `number` The item list count
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and prints the current item count.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
basalt.debug(aDropdown:getItemCount())
|
||||
```
|
||||
|
||||
## getAll
|
||||
Returns all items as table
|
||||
|
||||
#### Returns:
|
||||
1. `table` All items
|
||||
|
||||
#### Usage:
|
||||
* Creates a default menubar with 3 entries and prints a table.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
basalt.debug(aDropdown:getAll())
|
||||
```
|
||||
|
||||
## selectItem
|
||||
selects a item in the dropdown (same as a player would click on a item)
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The index which should get selected
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and selects the second entry.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:selectItem(2)
|
||||
```
|
||||
|
||||
## clear
|
||||
Removes all items.
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and removes them immediatley. Which makes no sense.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:clear()
|
||||
```
|
||||
|
||||
## getItemIndex
|
||||
returns the item index of the currently selected item
|
||||
|
||||
#### Returns:
|
||||
1. `number` The current index
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries selects the second entry and prints the currently selected index.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:selectItem(2)
|
||||
basalt.debug(aDropdown:getItemIndex())
|
||||
```
|
||||
|
||||
## setSelectedItem
|
||||
Sets the background and the foreground of the item which is currently selected
|
||||
|
||||
#### Parameters:
|
||||
1. `number|color` The background color which should be used
|
||||
2. `number|color` The text color which should be used
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 4 entries and sets the selection background color to green.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:addItem("4. Entry")
|
||||
aDropdown:setSelectedItem(colors.green, colors.red)
|
||||
```
|
||||
```xml
|
||||
<dropdown selectionBG="green" selectionFG="red">
|
||||
<item><text>1. Entry</text></item>
|
||||
<item><text>2. Entry</text><bg>yellow</bg></item>
|
||||
<item><text>2. Entry</text><bg>yellow</bg><fg>green</fg></item>
|
||||
</dropdown>
|
||||
```
|
||||
|
||||
## setOffset
|
||||
Sets the offset of the dropdown (the same as you would scroll) - default is 0
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The offset value
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 6 entries and sets the offset to 3.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
:addItem("1. Entry")
|
||||
:addItem("2. Entry")
|
||||
:addItem("3. Entry")
|
||||
:addItem("4. Entry")
|
||||
:addItem("5. Entry")
|
||||
:addItem("6. Entry")
|
||||
:setOffset(3)
|
||||
```
|
||||
```xml
|
||||
<dropdown offset="3">
|
||||
<item><text>1. Entry</text></item>
|
||||
<item><text>2. Entry</text></item>
|
||||
<item><text>3. Entry</text></item>
|
||||
<item><text>4. Entry</text></item>
|
||||
<item><text>5. Entry</text></item>
|
||||
<item><text>6. Entry</text></item>
|
||||
</dropdown>
|
||||
```
|
||||
|
||||
## getOffset
|
||||
Returns the current index offset
|
||||
|
||||
#### Returns:
|
||||
1. `number` offset value
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 6 entries and sets the offset to 3, also prints the current offset.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
:addItem("1. Entry")
|
||||
:addItem("2. Entry")
|
||||
:addItem("3. Entry")
|
||||
:addItem("4. Entry")
|
||||
:addItem("5. Entry")
|
||||
:addItem("6. Entry")
|
||||
:setOffset(3)
|
||||
basalt.debug(aDropdown:getOffset())
|
||||
```
|
||||
|
||||
## setDropdownSize
|
||||
Sets the size of the opened dropdown
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The width value
|
||||
2. `number` The height value
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown, adds 3 entries and sets the dropdown size to 15w, 8h
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown():setDropdownSize(15,8)
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry")
|
||||
aDropdown:addItem("3. Entry")
|
||||
```
|
||||
```xml
|
||||
<dropdown dropdownWidth="15" dropdownHeight="8">
|
||||
<item><text>1. Entry</text></item>
|
||||
<item><text>2. Entry</text></item>
|
||||
<item><text>3. Entry</text></item>
|
||||
</dropdown>
|
||||
```
|
||||
|
||||
```
|
||||
28
docs/objects/Dropdown/addItem.md
Normal file
28
docs/objects/Dropdown/addItem.md
Normal file
@@ -0,0 +1,28 @@
|
||||
## addItem
|
||||
Adds a item into the dropdown
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The entry name
|
||||
2. `number|color` unique default background color - optional
|
||||
3. `number|color` unique default text color - optional
|
||||
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
```
|
||||
```xml
|
||||
<dropdown>
|
||||
<item><text>1. Entry</text></item>
|
||||
<item><text>2. Entry</text><bg>yellow</bg></item>
|
||||
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
|
||||
</dropdown>
|
||||
```
|
||||
16
docs/objects/Dropdown/clear.md
Normal file
16
docs/objects/Dropdown/clear.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## clear
|
||||
Removes all items.
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and removes them immediatley. Which makes no sense.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:clear()
|
||||
```
|
||||
23
docs/objects/Dropdown/editItem.md
Normal file
23
docs/objects/Dropdown/editItem.md
Normal file
@@ -0,0 +1,23 @@
|
||||
## editItem
|
||||
Edits a item from the dropdown
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The index which should be edited
|
||||
2. `string` The new item name
|
||||
3. `number` the new item background color - optional
|
||||
4. `number` The new item text color - optional
|
||||
5. `any` New additional information - optional
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and edits the second one.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:editItem(2, "Still 2. Entry", colors.red)
|
||||
```
|
||||
16
docs/objects/Dropdown/getAll.md
Normal file
16
docs/objects/Dropdown/getAll.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## getAll
|
||||
Returns all items as table
|
||||
|
||||
#### Returns:
|
||||
1. `table` All items
|
||||
|
||||
#### Usage:
|
||||
* Creates a default menubar with 3 entries and prints a table.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
basalt.debug(aDropdown:getAll())
|
||||
```
|
||||
19
docs/objects/Dropdown/getItem.md
Normal file
19
docs/objects/Dropdown/getItem.md
Normal file
@@ -0,0 +1,19 @@
|
||||
## getItem
|
||||
Returns a item by index
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The index which should be returned
|
||||
|
||||
#### Returns:
|
||||
1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and edits the second one.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
basalt.debug(aDropdown:getItem(2).text)
|
||||
```
|
||||
16
docs/objects/Dropdown/getItemCount.md
Normal file
16
docs/objects/Dropdown/getItemCount.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## getItemCount
|
||||
Returns the current item count
|
||||
|
||||
#### Returns:
|
||||
1. `number` The item list count
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and prints the current item count.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
basalt.debug(aDropdown:getItemCount())
|
||||
```
|
||||
17
docs/objects/Dropdown/getItemIndex.md
Normal file
17
docs/objects/Dropdown/getItemIndex.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## getItemIndex
|
||||
returns the item index of the currently selected item
|
||||
|
||||
#### Returns:
|
||||
1. `number` The current index
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries selects the second entry and prints the currently selected index.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:selectItem(2)
|
||||
basalt.debug(aDropdown:getItemIndex())
|
||||
```
|
||||
20
docs/objects/Dropdown/getOffset.md
Normal file
20
docs/objects/Dropdown/getOffset.md
Normal file
@@ -0,0 +1,20 @@
|
||||
## getOffset
|
||||
Returns the current index offset
|
||||
|
||||
#### Returns:
|
||||
1. `number` offset value
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 6 entries and sets the offset to 3, also prints the current offset.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
:addItem("1. Entry")
|
||||
:addItem("2. Entry")
|
||||
:addItem("3. Entry")
|
||||
:addItem("4. Entry")
|
||||
:addItem("5. Entry")
|
||||
:addItem("6. Entry")
|
||||
:setOffset(3)
|
||||
basalt.debug(aDropdown:getOffset())
|
||||
```
|
||||
19
docs/objects/Dropdown/removeItem.md
Normal file
19
docs/objects/Dropdown/removeItem.md
Normal file
@@ -0,0 +1,19 @@
|
||||
## removeItem
|
||||
Removes a item from the dropdown
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The index which should get removed
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and removes the second one.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:removeItem(2)
|
||||
```
|
||||
19
docs/objects/Dropdown/selectItem.md
Normal file
19
docs/objects/Dropdown/selectItem.md
Normal file
@@ -0,0 +1,19 @@
|
||||
## selectItem
|
||||
selects a item in the dropdown (same as a player would click on a item)
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The index which should get selected
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 3 entries and selects the second entry.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:selectItem(2)
|
||||
```
|
||||
26
docs/objects/Dropdown/setDropdownSize.md
Normal file
26
docs/objects/Dropdown/setDropdownSize.md
Normal file
@@ -0,0 +1,26 @@
|
||||
## setDropdownSize
|
||||
Sets the size of the opened dropdown
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The width value
|
||||
2. `number` The height value
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown, adds 3 entries and sets the dropdown size to 15w, 8h
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown():setDropdownSize(15,8)
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry")
|
||||
aDropdown:addItem("3. Entry")
|
||||
```
|
||||
```xml
|
||||
<dropdown dropdownWidth="15" dropdownHeight="8">
|
||||
<item><text>1. Entry</text></item>
|
||||
<item><text>2. Entry</text></item>
|
||||
<item><text>3. Entry</text></item>
|
||||
</dropdown>
|
||||
```
|
||||
32
docs/objects/Dropdown/setOffset.md
Normal file
32
docs/objects/Dropdown/setOffset.md
Normal file
@@ -0,0 +1,32 @@
|
||||
## setOffset
|
||||
Sets the offset of the dropdown (the same as you would scroll) - default is 0
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The offset value
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 6 entries and sets the offset to 3.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
:addItem("1. Entry")
|
||||
:addItem("2. Entry")
|
||||
:addItem("3. Entry")
|
||||
:addItem("4. Entry")
|
||||
:addItem("5. Entry")
|
||||
:addItem("6. Entry")
|
||||
:setOffset(3)
|
||||
```
|
||||
```xml
|
||||
<dropdown offset="3">
|
||||
<item><text>1. Entry</text></item>
|
||||
<item><text>2. Entry</text></item>
|
||||
<item><text>3. Entry</text></item>
|
||||
<item><text>4. Entry</text></item>
|
||||
<item><text>5. Entry</text></item>
|
||||
<item><text>6. Entry</text></item>
|
||||
</dropdown>
|
||||
```
|
||||
28
docs/objects/Dropdown/setSelectedItem.md
Normal file
28
docs/objects/Dropdown/setSelectedItem.md
Normal file
@@ -0,0 +1,28 @@
|
||||
## setSelectedItem
|
||||
Sets the background and the foreground of the item which is currently selected
|
||||
|
||||
#### Parameters:
|
||||
1. `number|color` The background color which should be used
|
||||
2. `number|color` The text color which should be used
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Creates a default dropdown with 4 entries and sets the selection background color to green.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aDropdown = mainFrame:addDropdown()
|
||||
aDropdown:addItem("1. Entry")
|
||||
aDropdown:addItem("2. Entry",colors.yellow)
|
||||
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
|
||||
aDropdown:addItem("4. Entry")
|
||||
aDropdown:setSelectedItem(colors.green, colors.red)
|
||||
```
|
||||
```xml
|
||||
<dropdown selectionBG="green" selectionFG="red">
|
||||
<item><text>1. Entry</text></item>
|
||||
<item><text>2. Entry</text><bg>yellow</bg></item>
|
||||
<item><text>2. Entry</text><bg>yellow</bg><fg>green</fg></item>
|
||||
</dropdown>
|
||||
```
|
||||
@@ -1,409 +1,40 @@
|
||||
<a href="https://i.imgur.com/aikc0K1.png"><img src="https://i.imgur.com/aikc0K1.png" height="500" /></a>
|
||||
|
||||
Frames are like containers, but are also normal objects.
|
||||
In other words, you can add other objects _(even frames)_ to a frame; if the frame itself is visible
|
||||
all sub-objects _(if they are set as visible)_ are also visible. A better description will follow.
|
||||
|
||||
## basalt.createFrame
|
||||
Creates a new non-parent frame - in most cases it is the first thing you'll need.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` name (should be unique)
|
||||
|
||||
#### Returns:
|
||||
1. `frame | nil` The frame created by createFrame, or `nil` if there is already a frame with the given name.
|
||||
|
||||
#### Usage:
|
||||
* Create a frame with an id "myFirstFrame", stored in a variable named frame
|
||||
```lua
|
||||
local myFrame = basalt.createFrame("myFirstFrame")
|
||||
```
|
||||
|
||||
## addFrame
|
||||
Creates a child frame on the frame, the same as [basalt.createFrame](https://github.com/Pyroxenium/Basalt/wiki/Frame#basaltcreateframe) except the frames are given a parent-child relationship automatically
|
||||
|
||||
#### Parameters:
|
||||
1. `string` name (should be unique)
|
||||
|
||||
#### Returns:
|
||||
1. `frame | nil` The frame created by addFrame, or `nil` if there is already a child frame with the given name.<br>
|
||||
|
||||
#### Usage:
|
||||
* Create a new main frame and adds a child frame to it
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local myFrame = mainFrame:addFrame()
|
||||
```
|
||||
```xml
|
||||
<frame></frame>
|
||||
```
|
||||
|
||||
## setBar
|
||||
Sets the text, background, and foreground of the upper bar of the frame, accordingly.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The title text to set the bar to
|
||||
2. `number` The background color
|
||||
2. `number` The foreground color
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Set the title to "My first frame!", with a background of black and a foreground of light gray.
|
||||
```lua
|
||||
frame:setBar("My first Frame!", colors.black, colors.lightGray)
|
||||
```
|
||||
* Store the frame, use the named frame variable after assigning.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local myFrame = MainFrame:addFrame()
|
||||
myFrame:setBar("My first Frame!")
|
||||
```
|
||||
* This abuses the call-chaining that Basalt uses.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local myFrame = mainFrame:addFrame():setBar("My first Frame!")
|
||||
```
|
||||
```xml
|
||||
<frame barText="My first Frame!" barBG="black" barFG="lightGray"></frame>
|
||||
```
|
||||
|
||||
## setBarTextAlign
|
||||
Sets the frame's bar-text alignment
|
||||
|
||||
#### Parameters:
|
||||
1. `string` Can be supplied with "left", "center", or "right"
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Set the title of myFrame to "My first frame!", and align it to the right.
|
||||
```lua
|
||||
myFrame:setBar("My first Frame!"):setBarTextAlign("right")
|
||||
```
|
||||
```xml
|
||||
<frame barAlign="right"></frame>
|
||||
```
|
||||
|
||||
## showBar
|
||||
Toggles the frame's upper bar
|
||||
|
||||
#### Parameters:
|
||||
1. `boolean | nil` Whether the frame's bar is visible or if supplied `nil`, is automatically visible
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Sets myFrame to have a bar titled "Hello World!" and subsequently displays it.
|
||||
```lua
|
||||
myFrame:setBar("Hello World!"):showBar()
|
||||
```
|
||||
```xml
|
||||
<frame bar="true"></frame>
|
||||
```
|
||||
|
||||
|
||||
## setMonitor
|
||||
Sets this frame as a monitor frame
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new monitor frame, you can use to show objects on a monitor.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local monitorFrame = basalt.createFrame():setMonitor("right")
|
||||
monitorFrame:setBar("Monitor 1"):showBar()
|
||||
```
|
||||
```xml
|
||||
<frame monitor="right"></frame>
|
||||
```
|
||||
|
||||
## setMirror
|
||||
mirrors this frame to another peripheral monitor object.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates mirror of your main frame to a monitor on the left side.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():setMirror("left")
|
||||
```
|
||||
```xml
|
||||
<frame mirror="left"></frame>
|
||||
```
|
||||
|
||||
## getObject
|
||||
Returns a child object of the frame
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The name of the child object
|
||||
|
||||
#### Returns:
|
||||
1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name
|
||||
|
||||
#### Usage:
|
||||
* Adds a button with id "myFirstButton", then retrieves it again through the frame object
|
||||
```lua
|
||||
myFrame:addButton("myFirstButton")
|
||||
local aButton = myFrame:getObject("myFirstButton")
|
||||
```
|
||||
|
||||
## removeObject
|
||||
Removes a child object from the frame
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The name of the child object
|
||||
|
||||
#### Returns:
|
||||
1. `boolean` Whether the object with the given name was properly removed
|
||||
|
||||
#### Usage:
|
||||
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id
|
||||
```lua
|
||||
myFrame:addButton("myFirstButton")
|
||||
myFrame:removeObject("myFirstButton")
|
||||
```
|
||||
|
||||
## setFocusedObject
|
||||
Sets the currently focused object
|
||||
|
||||
#### Parameters:
|
||||
1. `object` The child object to focus on
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new button, sets the focused object to the previously mentioned button
|
||||
```lua
|
||||
local aButton = myFrame:addButton()
|
||||
myFrame:setFocusedObject(aButton)
|
||||
```
|
||||
|
||||
## removeFocusedObject
|
||||
Removes the focus of the supplied object
|
||||
|
||||
#### Parameters:
|
||||
1. `object` The child object to remove focus from
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new button then removes the focus from that button when clicking on it
|
||||
```lua
|
||||
local aButton = myFrame:addButton():setFocus():onClick(function()
|
||||
myFrame:removeFocusedObject(aButton)
|
||||
end)
|
||||
```
|
||||
|
||||
## getFocusedObject
|
||||
Gets the currently focused object
|
||||
|
||||
#### Returns:
|
||||
1. `object` The currently focused object
|
||||
|
||||
#### Usage:
|
||||
* Gets the currently focused object from the frame, storing it in a variable
|
||||
```lua
|
||||
local focusedObject = myFrame:getFocusedObject()
|
||||
```
|
||||
|
||||
## setMovable
|
||||
Sets whether the frame can be moved. _In order to move the frame click and drag the upper bar of the frame_
|
||||
|
||||
#### Parameters:
|
||||
1. `boolean` Whether the object is movable
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a frame with id "myFirstFrame" and makes it movable
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():setMovable(true)
|
||||
```
|
||||
```xml
|
||||
<frame moveable="true"></frame>
|
||||
```
|
||||
|
||||
## setOffset
|
||||
Sets the frame's coordinate offset. The frame's child objects will receive the frame's coordinate offset. For example, when using a scrollbar, if you use its value to add an offset to a frame, you will get a scrollable frame.
|
||||
Objects are also able to ignore the offset by using :ignoreOffset() (For example, you may want to ignore the offset on the scrollbar itself)
|
||||
|
||||
The function can also be supplied with negative values
|
||||
|
||||
#### Parameters:
|
||||
1. `number` The x direction offset (+/-)
|
||||
2. `number` The y direction offset (+/-)
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame with x offset of 5 and a y offset of 3
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():setOffset(5, 3)
|
||||
```
|
||||
* Creates with x offset of 5 and a y offset of -5 (Meaning if you added a button with y position 5, it would be at y position 0)
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():setOffset(5, -5)
|
||||
```
|
||||
```xml
|
||||
<frame xOffset="5" yOffset="-5"></frame>
|
||||
```
|
||||
|
||||
## addLayout
|
||||
Adds a new XML Layout into your frame.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` Path to your layout
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and adds the mainframe.xml layout
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():addLayout("mainframe.xml")
|
||||
```
|
||||
```xml
|
||||
<frame layout="mainframe.xml"></frame>
|
||||
```
|
||||
|
||||
## addLayoutFromString
|
||||
Adds a new XML Layout as string into your frame.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` xml
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and adds the mainframe.xml layout
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():addLayoutFromString("<button x='12' y='5' bg='black' />")
|
||||
```
|
||||
|
||||
## getLastLayout
|
||||
returns a table of all objects this frame has created via xml (useful if you'd like to access all of them for some reason)
|
||||
|
||||
#### Returns:
|
||||
1. `table` table with objects
|
||||
|
||||
## setTheme
|
||||
Sets the default theme of that frame children objects always try to get the theme of its parent frame, if it does not exist it goes to its parent parent frame, and so on until it reaches the basalt managers theme - which is sotred in theme.lua (Please checkout [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for how it could look like.
|
||||
|
||||
#### Parameters:
|
||||
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and adds a new theme which only changes the default color of buttons.
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():setTheme({
|
||||
ButtonBG = colors.yellow,
|
||||
ButtonText = colors.red,
|
||||
})
|
||||
```
|
||||
|
||||
## setScrollable
|
||||
Makes the frame scrollable with mousewheel.
|
||||
|
||||
#### Parameters:
|
||||
1. `bool` scrollable or not
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and makes it scrollable
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():setScrollable()
|
||||
```
|
||||
```xml
|
||||
<frame scrollable="true"></frame>
|
||||
```
|
||||
|
||||
## setMinScroll
|
||||
Sets the minimum offset it is allowed to scroll (default 0)
|
||||
|
||||
#### Parameters:
|
||||
1. `number` minimum y offset
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and makes it scrollable and sets the minimum amount to -5
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():setScrollable():setMinScroll(-5)
|
||||
```
|
||||
```xml
|
||||
<frame minScroll="-5"></frame>
|
||||
```
|
||||
|
||||
## setMaxScroll
|
||||
Sets the maximum offset it is allowed to scroll (default 10)
|
||||
|
||||
#### Parameters:
|
||||
1. `number` maximum y offset
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and makes it scrollable and sets the maximum amount to 25
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():setScrollable():setMaxScroll(25)
|
||||
```
|
||||
```xml
|
||||
<frame maxScroll="25"></frame>
|
||||
```
|
||||
|
||||
## setImportantScroll
|
||||
By default if you hovering your mouse over children objects, you wont scroll the frame, if you set this to true the frame scrolling becomes more important
|
||||
|
||||
#### Parameters:
|
||||
1. `bool` important or not
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and makes it scrollable and defines it as important
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():setScrollable():setImportantScroll(true)
|
||||
```
|
||||
```xml
|
||||
<frame importantScroll="true"></frame>
|
||||
```
|
||||
|
||||
# XML Example
|
||||
|
||||
*This is how you would implement frames via xml:
|
||||
Frames are like groups or windows. You can add objects on them and if you move the frame, all its children objects will also be moved. Frames also have
|
||||
some special functionality to create very advanced programs.
|
||||
|
||||
[Object](objects/Object.md) methods also apply for frames.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
|[addObject](objects/Frame/addObject.md)|Adds a new object
|
||||
|[setBar](objects/Frame/setBar.md)|Sets the top bar text and colors - deprecated
|
||||
|[setBarTextAlign](objects/Frame/setBarTextAlign.md)|Sets the top bars text align - deprecated
|
||||
|[showBar](objects/Frame/showBar.md)|Shows the top bar - deprecated
|
||||
|[setMonitor](objects/Frame/setMonitor.md)|Sets the frame to be a monitor frame (only for base frames)
|
||||
|[setMonitorScale](objects/Frame/setMonitorScale.md)|Sets the monitor scale (same as monitor.setTextScale)
|
||||
|[setMirror](objects/Frame/setMirror.md)|Sets the frame to mirror onto a monitor (only for base frames)
|
||||
|[getObject](objects/Frame/getObject.md)|Returns the object by its name (or id)
|
||||
|[removeObject](objects/Frame/removeObject.md)|Removes the object by its name (or id)
|
||||
|[setFocusedObject](objects/Frame/setFocusedObject.md)|Sets the currently focused object by this frame
|
||||
|[removeFocusedObject](objects/Frame/removeFocusedObject.md)|Removes the currenlty focused object (it only removes beeing focused)
|
||||
|[getFocusedObject](objects/Frame/getFocusedObject.md)|Returns the currently focused object
|
||||
|[setMovable](objects/Frame/setMovable.md)|Makes the frame movable (only for sub frames)
|
||||
|[setOffset](objects/Frame/setOffset.md)|Sets the frames offset (will be added to the childrens x and y positions)
|
||||
|[getOffset](objects/Frame/getOffset.md)|Returns the current x and y offset
|
||||
|[addLayout](objects/Frame/addLayout.md)|Adds a new XML Layout into the frame
|
||||
|[addLayoutFromString](objects/Frame/addLayoutFromString.md)|Adds a new XML Layout via string into the frame
|
||||
|[getLastLayout](objects/Frame/getLastLayout.md)|Returns a table of all objects generated by the last addLayout/FromString method
|
||||
|[setTheme](objects/Frame/setTheme.md)|Sets the theme of that frame and all its childrens
|
||||
|[setScrollable](objects/Frame/setScrollable.md)|Makes the frame scrollable via mousewheel (internally this uses setOffset)
|
||||
|[setScrollAmount](objects/Frame/setScrollAmount.md)|Sets how far the user is allowed to scroll
|
||||
|
||||
This is how you would implement frames via xml:
|
||||
```xml
|
||||
<frame>
|
||||
<frame width="50%" bg="red">
|
||||
<frame width="parent.w * 0.5" bg="red">
|
||||
<button x="2" y="2" width="17" text="Example Button!"/>
|
||||
</frame>
|
||||
<frame x="50%+1" width="50%+1" bg="black">
|
||||
<textfield bg="green" x="2" width="100%-2" />
|
||||
<frame x="parent.w * 0.5 + 1" width="parent.w * 0.5 +1" bg="black">
|
||||
<textfield bg="green" x="2" width="parent.w-2" />
|
||||
</frame>
|
||||
</frame>
|
||||
```
|
||||
```
|
||||
17
docs/objects/Frame/addLayout.md
Normal file
17
docs/objects/Frame/addLayout.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## addLayout
|
||||
Adds a new XML Layout into your frame.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` Path to your layout
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and adds the mainframe.xml layout
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():addLayout("mainframe.xml")
|
||||
```
|
||||
```xml
|
||||
<frame layout="mainframe.xml"></frame>
|
||||
```
|
||||
14
docs/objects/Frame/addLayoutFromString.md
Normal file
14
docs/objects/Frame/addLayoutFromString.md
Normal file
@@ -0,0 +1,14 @@
|
||||
## addLayoutFromString
|
||||
Adds a new XML Layout as string into your frame.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` xml
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame and adds the mainframe.xml layout
|
||||
```lua
|
||||
local myFrame = basalt.createFrame():addLayoutFromString("<button x='12' y='5' bg='black' />")
|
||||
```
|
||||
18
docs/objects/Frame/addObject.md
Normal file
18
docs/objects/Frame/addObject.md
Normal file
@@ -0,0 +1,18 @@
|
||||
## add<Object>
|
||||
Adds a new object. Don't use add<Object> please use addTheObjectYouNeed For example if you want a new Frame, use
|
||||
addFrame, if you want to add a button, use addButton
|
||||
|
||||
#### Parameters:
|
||||
1. `string` optional - the id if you don't add a id it will autimatically generate one for you
|
||||
|
||||
#### Returns:
|
||||
1. `object` The new object you've created
|
||||
|
||||
#### Usage:
|
||||
* Creates some example objects
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
local button = main:addButton()
|
||||
local label = main:addLabel()
|
||||
local frame = main:addFrame()
|
||||
```
|
||||
11
docs/objects/Frame/getFocusedObject.md
Normal file
11
docs/objects/Frame/getFocusedObject.md
Normal file
@@ -0,0 +1,11 @@
|
||||
## getFocusedObject
|
||||
Gets the currently focused object
|
||||
|
||||
#### Returns:
|
||||
1. `object` The currently focused object
|
||||
|
||||
#### Usage:
|
||||
* Gets the currently focused object from the frame, storing it in a variable
|
||||
```lua
|
||||
local focusedObject = myFrame:getFocusedObject()
|
||||
```
|
||||
5
docs/objects/Frame/getLastLayout.md
Normal file
5
docs/objects/Frame/getLastLayout.md
Normal file
@@ -0,0 +1,5 @@
|
||||
## getLastLayout
|
||||
returns a table of all objects this frame has created via xml (useful if you'd like to access all of them for some reason)
|
||||
|
||||
#### Returns:
|
||||
1. `table` table with objects
|
||||
15
docs/objects/Frame/getObject.md
Normal file
15
docs/objects/Frame/getObject.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## getObject
|
||||
Returns a child object of the frame
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The name of the child object
|
||||
|
||||
#### Returns:
|
||||
1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name
|
||||
|
||||
#### Usage:
|
||||
* Adds a button with id "myFirstButton", then retrieves it again through the frame object
|
||||
```lua
|
||||
myFrame:addButton("myFirstButton")
|
||||
local aButton = myFrame:getObject("myFirstButton")
|
||||
```
|
||||
0
docs/objects/Frame/getOffset.md
Normal file
0
docs/objects/Frame/getOffset.md
Normal file
15
docs/objects/Frame/removeFocusedObject.md
Normal file
15
docs/objects/Frame/removeFocusedObject.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## removeFocusedObject
|
||||
Removes the currently focused object of that frame
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new button then removes the focus from that button when clicking on it
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
local input = main:addInput():setFocus()
|
||||
local aButton = main:addButton():onClick(function()
|
||||
main:removeFocusedObject()
|
||||
end)
|
||||
```
|
||||
18
docs/objects/Frame/removeObject.md
Normal file
18
docs/objects/Frame/removeObject.md
Normal file
@@ -0,0 +1,18 @@
|
||||
## removeObject
|
||||
Removes a child object from the frame
|
||||
|
||||
#### Parameters:
|
||||
1. `string|object` The name of the child object or the object itself
|
||||
|
||||
#### Returns:
|
||||
1. `boolean` Whether the object with the given name was properly removed
|
||||
|
||||
#### Usage:
|
||||
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id
|
||||
```lua
|
||||
local main = basalt.createFrame()
|
||||
main:addButton("myFirstButton"):setText("Close")
|
||||
:onClick(function(self)
|
||||
main:removeObject("myFirstButton") -- or main:removeObject(self)
|
||||
end)
|
||||
```
|
||||
30
docs/objects/Frame/setBar.md
Normal file
30
docs/objects/Frame/setBar.md
Normal file
@@ -0,0 +1,30 @@
|
||||
## setBar
|
||||
Sets the text, background, and foreground of the upper bar of the frame, accordingly.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The title text to set the bar to
|
||||
2. `number` The background color
|
||||
2. `number` The foreground color
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Set the title to "My first frame!", with a background of black and a foreground of light gray.
|
||||
```lua
|
||||
frame:setBar("My first Frame!", colors.black, colors.lightGray)
|
||||
```
|
||||
* Store the frame, use the named frame variable after assigning.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local myFrame = MainFrame:addFrame()
|
||||
myFrame:setBar("My first Frame!")
|
||||
```
|
||||
* This abuses the call-chaining that Basalt uses.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local myFrame = mainFrame:addFrame():setBar("My first Frame!")
|
||||
```
|
||||
```xml
|
||||
<frame barText="My first Frame!" barBG="black" barFG="lightGray"></frame>
|
||||
```
|
||||
17
docs/objects/Frame/setBarTextAlign.md
Normal file
17
docs/objects/Frame/setBarTextAlign.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## setBarTextAlign
|
||||
Sets the frame's bar-text alignment
|
||||
|
||||
#### Parameters:
|
||||
1. `string` Can be supplied with "left", "center", or "right"
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Set the title of myFrame to "My first frame!", and align it to the right.
|
||||
```lua
|
||||
myFrame:setBar("My first Frame!"):setBarTextAlign("right")
|
||||
```
|
||||
```xml
|
||||
<frame barAlign="right"></frame>
|
||||
```
|
||||
15
docs/objects/Frame/setFocusedObject.md
Normal file
15
docs/objects/Frame/setFocusedObject.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## setFocusedObject
|
||||
Sets the currently focused object
|
||||
|
||||
#### Parameters:
|
||||
1. `object` The child object to focus on
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new button, sets the focused object to the previously mentioned button
|
||||
```lua
|
||||
local aButton = myFrame:addButton()
|
||||
myFrame:setFocusedObject(aButton)
|
||||
```
|
||||
17
docs/objects/Frame/setMirror.md
Normal file
17
docs/objects/Frame/setMirror.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## setMirror
|
||||
mirrors this frame to another peripheral monitor object.
|
||||
|
||||
#### Parameters:
|
||||
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates mirror of your main frame to a monitor on the left side.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():setMirror("left")
|
||||
```
|
||||
```xml
|
||||
<frame mirror="left"></frame>
|
||||
```
|
||||
41
docs/objects/Frame/setMonitor.md
Normal file
41
docs/objects/Frame/setMonitor.md
Normal file
@@ -0,0 +1,41 @@
|
||||
## setMonitor
|
||||
You can set base frames as monitor frames, don't try to use setMonitor on sub frames
|
||||
|
||||
#### Parameters:
|
||||
1. `string|table` The monitor name ("right", "left",... "monitor_1", "monitor_2",...) OR a table to create multi-monitors (see example)
|
||||
2. `number` optional - a number between 0.5 to 5 which sets the monitor scale
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new monitor frame, you can use to show objects on a monitor.
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame()
|
||||
local monitorFrame = basalt.createFrame():setMonitor("right")
|
||||
monitorFrame:addLabel():setText("Hellooo!")
|
||||
```
|
||||
```xml
|
||||
<frame monitor="right"></frame>
|
||||
```
|
||||
|
||||
* Here is a example on how to create mutlimonitors. You always have to start on the top left of your screen and go to the bottom right, which means in this example
|
||||
monitor_1 is always your most top left monitor while monitor_6 is your most bottom right monitor.
|
||||
|
||||
Table structure:
|
||||
local monitors = {
|
||||
[y1] = {x1,x2,x3},
|
||||
[y2] = {x1,x2,x3}
|
||||
...
|
||||
}
|
||||
|
||||
```lua
|
||||
local monitors = {
|
||||
{"monitor_1", "monitor_2", "monitor_3"},
|
||||
{"monitor_4", "monitor_5", "monitor_6"}
|
||||
}
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local monitorFrame = basalt.createFrame():setMonitor(monitors)
|
||||
monitorFrame:addLabel():setText("Hellooo!")
|
||||
```
|
||||
15
docs/objects/Frame/setMonitorScale.md
Normal file
15
docs/objects/Frame/setMonitorScale.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## setMonitorScale
|
||||
Changes the scale on the the monitor which the frame is attached to
|
||||
|
||||
#### Parameters:
|
||||
1. `number` A number from 0.5 to 5
|
||||
|
||||
#### Returns:
|
||||
1. `frame` The frame being used
|
||||
|
||||
#### Usage:
|
||||
* Creates a new base frame, sets the frame as a monitor frame and changes the monitor scale
|
||||
```lua
|
||||
local myFrame = basalt.createFrame()setMonitor("left"):setMonitorScale(2)
|
||||
myFrame:addLabel("Monitor scale is bigger")
|
||||
```
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user