Update basalt.lua
This commit is contained in:
608
basalt.lua
608
basalt.lua
@@ -25,7 +25,6 @@ local basalt = {debugger=true}
|
|||||||
local activeFrame
|
local activeFrame
|
||||||
local frames = {}
|
local frames = {}
|
||||||
|
|
||||||
local animationQueue = {}
|
|
||||||
local keyModifier = {}
|
local keyModifier = {}
|
||||||
local parentTerminal = term.current()
|
local parentTerminal = term.current()
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ local function rpairs(t)
|
|||||||
end, t, #t + 1
|
end, t, #t + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local tHex = { -- copy paste is a very important feature everyone should make use of
|
local tHex = { -- copy paste is a very important feature
|
||||||
[ colors.white ] = "0",
|
[ colors.white ] = "0",
|
||||||
[ colors.orange ] = "1",
|
[ colors.orange ] = "1",
|
||||||
[ colors.magenta ] = "2",
|
[ colors.magenta ] = "2",
|
||||||
@@ -123,34 +122,87 @@ local function basaltDrawHelper()
|
|||||||
recreateWindowArray()
|
recreateWindowArray()
|
||||||
|
|
||||||
local function setText(x,y,text)
|
local function setText(x,y,text)
|
||||||
local gText = cacheT[y]
|
|
||||||
if(y>=1)and(y<=h)then
|
if(y>=1)and(y<=h)then
|
||||||
if(x>=1)then
|
if(x+text:len()>0)and(x<=w)then
|
||||||
cacheT[y] = sub(gText:sub(1,x-1)..text..gText:sub(x+(text:len()),w),1, w)
|
local oldCache = cacheT[y]
|
||||||
else
|
local newCache
|
||||||
cacheT[y] = sub(text:sub(math.abs(x) + 2, text:len())..gText:sub((text:len() - (math.abs(x))),w),1, w)
|
local nEnd = x + #text - 1
|
||||||
|
|
||||||
|
if(x < 1)then
|
||||||
|
local startN = 1 - x + 1
|
||||||
|
local endN = w - x + 1
|
||||||
|
text = sub(text, startN, endN)
|
||||||
|
elseif(nEnd > w)then
|
||||||
|
local endN = w - x + 1
|
||||||
|
text = sub(text, 1, endN)
|
||||||
|
end
|
||||||
|
|
||||||
|
if(x > 1)then
|
||||||
|
local endN = x - 1
|
||||||
|
newCache = sub( oldCache, 1, endN )..text
|
||||||
|
else
|
||||||
|
newCache = text
|
||||||
|
end
|
||||||
|
if nEnd < w then
|
||||||
|
newCache = newCache .. sub(oldCache, nEnd + 1, w)
|
||||||
|
end
|
||||||
|
cacheT[y] = newCache
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setBG(x,y,colorStr)
|
local function setBG(x,y,colorStr)
|
||||||
local gBG = cacheBG[y]
|
|
||||||
if(y>=1)and(y<=h)then
|
if(y>=1)and(y<=h)then
|
||||||
if(x>=1)then
|
if(x+colorStr:len()>0)and(x<=w)then
|
||||||
cacheBG[y] = sub(gBG:sub(1,x-1)..colorStr..gBG:sub(x+(colorStr:len()),w),1,w)
|
local oldCache = cacheBG[y]
|
||||||
else
|
local newCache
|
||||||
cacheBG[y] = sub(colorStr:sub(math.abs(x) + 2, colorStr:len())..gBG:sub((colorStr:len() - (math.abs(x))),w),1,w)
|
local nEnd = x + #colorStr - 1
|
||||||
|
|
||||||
|
if(x < 1)then
|
||||||
|
colorStr = sub(colorStr, 1 - x + 1, w - x + 1)
|
||||||
|
elseif(nEnd > w)then
|
||||||
|
colorStr = sub(colorStr, 1, w - x + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
if(x > 1)then
|
||||||
|
newCache = sub( oldCache, 1, x - 1)..colorStr
|
||||||
|
else
|
||||||
|
newCache = colorStr
|
||||||
|
end
|
||||||
|
if nEnd < w then
|
||||||
|
newCache = newCache .. sub(oldCache, nEnd + 1, w)
|
||||||
|
end
|
||||||
|
cacheBG[y] = newCache
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setFG(x,y,colorStr)
|
local function setFG(x,y,colorStr)
|
||||||
local gFG = cacheFG[y]
|
|
||||||
if(y>=1)and(y<=h)then
|
if(y>=1)and(y<=h)then
|
||||||
if(x>=1)then
|
if(x+colorStr:len()>0)and(x<=w)then
|
||||||
cacheFG[y] = sub(gFG:sub(1,x-1)..colorStr..gFG:sub(x+(colorStr:len()),w),1,w)
|
local oldCache = cacheFG[y]
|
||||||
else
|
local newCache
|
||||||
cacheFG[y] = sub(colorStr:sub(math.abs(x) + 2, colorStr:len())..gFG:sub((colorStr:len() - (math.abs(x))),w),1,w)
|
local nEnd = x + #colorStr - 1
|
||||||
|
|
||||||
|
if(x < 1)then
|
||||||
|
local startN = 1 - x + 1
|
||||||
|
local endN = w - x + 1
|
||||||
|
colorStr = sub(colorStr, startN, endN)
|
||||||
|
elseif(nEnd > w)then
|
||||||
|
local endN = w - x + 1
|
||||||
|
colorStr = sub(colorStr, 1, endN)
|
||||||
|
end
|
||||||
|
|
||||||
|
if(x > 1)then
|
||||||
|
local endN = x - 1
|
||||||
|
newCache = sub( oldCache, 1, endN )..colorStr
|
||||||
|
else
|
||||||
|
newCache = colorStr
|
||||||
|
end
|
||||||
|
if nEnd < w then
|
||||||
|
newCache = newCache .. sub( oldCache, nEnd + 1, w )
|
||||||
|
end
|
||||||
|
cacheFG[y] = newCache
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -327,6 +379,7 @@ local function Object(name) -- Base object
|
|||||||
|
|
||||||
hide = function(self)
|
hide = function(self)
|
||||||
isVisible = false
|
isVisible = false
|
||||||
|
visualsChanged = true
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -338,6 +391,12 @@ local function Object(name) -- Base object
|
|||||||
return zIndex;
|
return zIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
setFocus = function(self)
|
||||||
|
if(self.parent~=nil)then
|
||||||
|
self.parent:setFocusedObject(self)
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
setZIndex = function(self, index)
|
setZIndex = function(self, index)
|
||||||
zIndex = index
|
zIndex = index
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
@@ -469,30 +528,18 @@ local function Object(name) -- Base object
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
calcRelToAbsPosition = function(self, x,y) -- relative position
|
getAbsolutePosition = function(self, x,y) -- relative position
|
||||||
if(x==nil)then x = self.x end
|
if(x==nil)then x = self.x end
|
||||||
if(y==nil)then y = self.y end
|
if(y==nil)then y = self.y end
|
||||||
|
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
local fx,fy = self.parent:calcRelToAbsPosition()
|
local fx,fy = self.parent:getAbsolutePosition()
|
||||||
x=fx+x-1
|
x=fx+x-1
|
||||||
y=fy+y-1
|
y=fy+y-1
|
||||||
end
|
end
|
||||||
return x, y
|
return x, y
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getOffset = function(self, x, y)
|
|
||||||
if(self.parent~=nil)and(ignOffset==false)then
|
|
||||||
return self.parent:getFrameOffset()
|
|
||||||
end
|
|
||||||
return 0, 0
|
|
||||||
end;
|
|
||||||
|
|
||||||
ignoreOffset = function(self, ignore)
|
|
||||||
ignOffset = ignore or true
|
|
||||||
return self
|
|
||||||
end;
|
|
||||||
|
|
||||||
getAnchorPosition = function(self,x, y, ignOff)
|
getAnchorPosition = function(self,x, y, ignOff)
|
||||||
if(x==nil)then x = self.x end
|
if(x==nil)then x = self.x end
|
||||||
if(y==nil)then y = self.y end
|
if(y==nil)then y = self.y end
|
||||||
@@ -509,6 +556,18 @@ local function Object(name) -- Base object
|
|||||||
return x+xO, y+yO
|
return x+xO, y+yO
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
getOffset = function(self)
|
||||||
|
if(self.parent~=nil)and(ignOffset==false)then
|
||||||
|
return self.parent:getFrameOffset()
|
||||||
|
end
|
||||||
|
return 0, 0
|
||||||
|
end;
|
||||||
|
|
||||||
|
ignoreOffset = function(self, ignore)
|
||||||
|
ignOffset = ignore or true
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
setAnchor = function(self,...)
|
setAnchor = function(self,...)
|
||||||
for _,v in pairs(table.pack(...))do
|
for _,v in pairs(table.pack(...))do
|
||||||
if(v=="right")or(v=="left")then
|
if(v=="right")or(v=="left")then
|
||||||
@@ -559,7 +618,7 @@ local function Object(name) -- Base object
|
|||||||
|
|
||||||
isFocused = function(self)
|
isFocused = function(self)
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
return self.parent:getFocus()==self
|
return self.parent:getFocusedObject()==self
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end;
|
end;
|
||||||
@@ -583,9 +642,9 @@ local function Object(name) -- Base object
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
local objX,objY = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local objX,objY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(objX<=x)and(objX+self.w>x)and(objY<=y)and(objY+self.h>y)and(isVisible)then
|
if(objX<=x)and(objX+self.w>x)and(objY<=y)and(objY+self.h>y)and(isVisible)then
|
||||||
if(self.parent~=nil)then self.parent:setFocus(self) end
|
if(self.parent~=nil)then self.parent:setFocusedObject(self) end
|
||||||
eventSystem:sendEvent(event, self, event, button, x, y)
|
eventSystem:sendEvent(event, self, event, button, x, y)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -660,10 +719,11 @@ local function Button(name) -- Button
|
|||||||
local verticalAlign = getTextVerticalAlign(self.h, textVerticalAlign)
|
local verticalAlign = getTextVerticalAlign(self.h, textVerticalAlign)
|
||||||
|
|
||||||
self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor)
|
self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor)
|
||||||
|
self.parent:drawForegroundBox(obx, oby, self.w, self.h, self.fgcolor)
|
||||||
self.parent:drawTextBox(obx, oby, self.w, self.h, " ")
|
self.parent:drawTextBox(obx, oby, self.w, self.h, " ")
|
||||||
for n=1,self.h do
|
for n=1,self.h do
|
||||||
if(n==verticalAlign)then
|
if(n==verticalAlign)then
|
||||||
self.parent:writeText(obx, oby+(n-1), getTextHorizontalAlign(self:getValue(), self.w, textHorizontalAlign), self.bgcolor, self.fgcolor)
|
self.parent:setText(obx, oby+(n-1), getTextHorizontalAlign(self:getValue(), self.w, textHorizontalAlign))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1190,7 +1250,7 @@ local function Program(name)
|
|||||||
if(curProcess==nil)then return false end
|
if(curProcess==nil)then return false end
|
||||||
if not(curProcess:isDead())then
|
if not(curProcess:isDead())then
|
||||||
if not(paused)then
|
if not(paused)then
|
||||||
local absX,absY = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local absX,absY = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
curProcess:resume(event, button, x-absX+1, y-absY+1)
|
curProcess:resume(event, button, x-absX+1, y-absY+1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1298,6 +1358,7 @@ local function Label(name) -- Label
|
|||||||
return typ
|
return typ
|
||||||
end;
|
end;
|
||||||
setText = function(self,text)
|
setText = function(self,text)
|
||||||
|
text = tostring(text)
|
||||||
base:setValue(text)
|
base:setValue(text)
|
||||||
if(autoWidth)then
|
if(autoWidth)then
|
||||||
self.w = text:len()
|
self.w = text:len()
|
||||||
@@ -1443,7 +1504,7 @@ local function Input(name) -- Input
|
|||||||
|
|
||||||
getValue = function(self)
|
getValue = function(self)
|
||||||
local val = base.getValue(self)
|
local val = base.getValue(self)
|
||||||
return inputType == "number" and tonumber(val) or val
|
return inputType == "number" and tonumber(val)or val
|
||||||
end;
|
end;
|
||||||
|
|
||||||
setInputLimit = function(self, limit)
|
setInputLimit = function(self, limit)
|
||||||
@@ -1492,7 +1553,7 @@ local function Input(name) -- Input
|
|||||||
end
|
end
|
||||||
if(key==257)then -- on enter
|
if(key==257)then -- on enter
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
--self.parent:removeFocus(self)
|
--self.parent:removeFocusedObject(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(key==262)then -- right arrow
|
if(key==262)then -- right arrow
|
||||||
@@ -1806,7 +1867,7 @@ local function Textfield(name)
|
|||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
if(base.mouseHandler(self, event, button, x, y))then
|
if(base.mouseHandler(self, event, button, x, y))then
|
||||||
local obx,oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx,oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
local anchx,anchy = self:getAnchorPosition()
|
local anchx,anchy = self:getAnchorPosition()
|
||||||
if(event=="mouse_click")then
|
if(event=="mouse_click")then
|
||||||
if(lines[y-oby+hIndex]~=nil)then
|
if(lines[y-oby+hIndex]~=nil)then
|
||||||
@@ -1883,20 +1944,30 @@ local function List(name)
|
|||||||
local selectionColorActive = true
|
local selectionColorActive = true
|
||||||
local align = "left"
|
local align = "left"
|
||||||
local yOffset = 0
|
local yOffset = 0
|
||||||
|
local scrollable = true
|
||||||
|
|
||||||
local object = {
|
local object = {
|
||||||
getType = function(self)
|
getType = function(self)
|
||||||
return typ
|
return typ
|
||||||
end;
|
end;
|
||||||
|
|
||||||
addItem = function(self, text, bgCol, fgCol)
|
addItem = function(self, text, bgCol, fgCol, ...)
|
||||||
table.insert(list, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor})
|
table.insert(list, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}})
|
||||||
if(#list==1)then
|
if(#list==1)then
|
||||||
self:setValue(list[1])
|
self:setValue(list[1])
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
setIndexOffset = function(self, yOff)
|
||||||
|
yOffset = yOff
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
getIndexOffset = function(self)
|
||||||
|
return yOffset
|
||||||
|
end;
|
||||||
|
|
||||||
removeItem = function(self, index)
|
removeItem = function(self, index)
|
||||||
table.remove(list, index)
|
table.remove(list, index)
|
||||||
return self
|
return self
|
||||||
@@ -1906,13 +1977,28 @@ local function List(name)
|
|||||||
return list[index]
|
return list[index]
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
getItemIndex = function(self)
|
||||||
|
local selected = self:getValue()
|
||||||
|
for k,v in pairs(list)do
|
||||||
|
if(v==selected)then
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
clear = function(self)
|
||||||
|
list = {}
|
||||||
|
self:setValue({})
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
getItemCount = function(self)
|
getItemCount = function(self)
|
||||||
return #list
|
return #list
|
||||||
end;
|
end;
|
||||||
|
|
||||||
editItem = function(self, index, text, bgCol, fgCol)
|
editItem = function(self, index, text, bgCol, fgCol, ...)
|
||||||
table.remove(list, index)
|
table.remove(list, index)
|
||||||
table.insert(list, index, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor})
|
table.insert(list, index, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}})
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -1921,16 +2007,21 @@ local function List(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
selectedItem = function(self, bgCol, fgCol, active)
|
setSelectedItem = function(self, bgCol, fgCol, active)
|
||||||
itemSelectedBG = bgCol or self.bgcolor
|
itemSelectedBG = bgCol or self.bgcolor
|
||||||
itemSelectedFG = fgCol or self.fgcolor
|
itemSelectedFG = fgCol or self.fgcolor
|
||||||
selectionColorActive = active
|
selectionColorActive = active
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
setScrollable = function(self, scroll)
|
||||||
|
scrollable = scroll
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
if(base.mouseHandler(self, event, button, x, y))then
|
if(base.mouseHandler(self, event, button, x, y))then
|
||||||
local obx,oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx,oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(event=="mouse_click")or(event=="mouse_drag")then -- remove mouse_drag if i want to make objects moveable uwuwuwuw
|
if(event=="mouse_click")or(event=="mouse_drag")then -- remove mouse_drag if i want to make objects moveable uwuwuwuw
|
||||||
if(button==1)then
|
if(button==1)then
|
||||||
if(#list>0)then
|
if(#list>0)then
|
||||||
@@ -1945,16 +2036,17 @@ local function List(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if(event=="mouse_scroll")then
|
if(event=="mouse_scroll")and(scrollable)then
|
||||||
yOffset = yOffset+button
|
yOffset = yOffset+button
|
||||||
if(yOffset<0)then yOffset = 0 end
|
if(yOffset<0)then yOffset = 0 end
|
||||||
if(button==1)then
|
if(button>=1)then
|
||||||
if(#list>self.h)then
|
if(#list>self.h)then
|
||||||
if(yOffset>#list-self.h)then
|
if(yOffset>#list-self.h)then
|
||||||
yOffset = #list-self.h
|
yOffset = #list-self.h
|
||||||
end
|
end
|
||||||
|
if(yOffset>=#list)then yOffset = #list-1 end
|
||||||
else
|
else
|
||||||
yOffset = list-1
|
yOffset = yOffset-1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1989,6 +2081,182 @@ local function List(name)
|
|||||||
return setmetatable(object, base)
|
return setmetatable(object, base)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function Menubar(name)
|
||||||
|
local base = Object(name)
|
||||||
|
local typ = "Menubar"
|
||||||
|
|
||||||
|
base.w = 30
|
||||||
|
base.h = 1
|
||||||
|
base.bgcolor = colors.gray
|
||||||
|
base.fgcolor = colors.lightGray
|
||||||
|
base:setZIndex(5)
|
||||||
|
|
||||||
|
local list = {}
|
||||||
|
local itemSelectedBG = theme.selectionBG
|
||||||
|
local itemSelectedFG = theme.selectionFG
|
||||||
|
local selectionColorActive = true
|
||||||
|
local align = "left"
|
||||||
|
local itemOffset = 0
|
||||||
|
local space = 2
|
||||||
|
local scrollable = false
|
||||||
|
|
||||||
|
local function maxScroll()
|
||||||
|
local mScroll = 0
|
||||||
|
local xPos = 1
|
||||||
|
for n=1,#list do
|
||||||
|
if(xPos + list[n].text:len() + space*2 > base.w)then
|
||||||
|
mScroll = mScroll + 1
|
||||||
|
end
|
||||||
|
xPos = xPos+list[n].text:len()+space*2
|
||||||
|
|
||||||
|
end
|
||||||
|
return mScroll
|
||||||
|
end
|
||||||
|
|
||||||
|
local object = {
|
||||||
|
getType = function(self)
|
||||||
|
return typ
|
||||||
|
end;
|
||||||
|
|
||||||
|
addItem = function(self, text, bgCol, fgCol, ...)
|
||||||
|
table.insert(list, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}})
|
||||||
|
if(#list==1)then
|
||||||
|
self:setValue(list[1])
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
getItemIndex = function(self)
|
||||||
|
local selected = self:getValue()
|
||||||
|
for k,v in pairs(list)do
|
||||||
|
if(v==selected)then
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
clear = function(self)
|
||||||
|
list = {}
|
||||||
|
self:setValue({})
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
setSpace = function(self, _space)
|
||||||
|
space = _space or space
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
setButtonOffset = function(self, offset)
|
||||||
|
itemOffset = offset or 0
|
||||||
|
if(itemOffset<0)then
|
||||||
|
itemOffset = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
local mScroll = maxScroll()
|
||||||
|
if(itemOffset>mScroll)then
|
||||||
|
itemOffset = mScroll
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
setScrollable = function(self, scroll)
|
||||||
|
scrollable = scroll
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
removeItem = function(self, index)
|
||||||
|
table.remove(list, index)
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
getItem = function(self, index)
|
||||||
|
return list[index]
|
||||||
|
end;
|
||||||
|
|
||||||
|
getItemCount = function(self)
|
||||||
|
return #list
|
||||||
|
end;
|
||||||
|
|
||||||
|
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={...}})
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
selectItem = function(self, index)
|
||||||
|
self:setValue(list[index] or {})
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
setSelectedItem = function(self, bgCol, fgCol, active)
|
||||||
|
itemSelectedBG = bgCol or self.bgcolor
|
||||||
|
itemSelectedFG = fgCol or self.fgcolor
|
||||||
|
selectionColorActive = active
|
||||||
|
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())
|
||||||
|
if(event=="mouse_click")then
|
||||||
|
local xPos = 1
|
||||||
|
for n=1+itemOffset,#list do
|
||||||
|
if(list[n]~=nil)then
|
||||||
|
if(xPos + list[n].text:len() + space*2 <= self.w)then
|
||||||
|
if(obx + (xPos-1)<= x)and(obx + (xPos-1) + list[n].text:len() + space*2 > x)and(oby == y)then
|
||||||
|
self:setValue(list[n])
|
||||||
|
end
|
||||||
|
xPos = xPos+list[n].text:len()+space*2
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
draw = function(self)
|
||||||
|
if(base.draw(self))then
|
||||||
|
if(self.parent~=nil)then
|
||||||
|
local obx, oby = self:getAnchorPosition()
|
||||||
|
self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor)
|
||||||
|
local xPos = 1
|
||||||
|
for n=1+itemOffset,#list do
|
||||||
|
if(list[n]~=nil)then
|
||||||
|
if(xPos + list[n].text:len() + space*2 <= self.w)then
|
||||||
|
if(list[n]==self:getValue())then
|
||||||
|
self.parent:writeText(obx + (xPos-1), oby, getTextHorizontalAlign((" "):rep(space)..list[n].text..(" "):rep(space), list[n].text:len()+space*2, align), itemSelectedBG or list[n].bgCol, itemSelectedFG or list[n].fgCol)
|
||||||
|
else
|
||||||
|
self.parent:writeText(obx + (xPos-1), oby, getTextHorizontalAlign((" "):rep(space)..list[n].text..(" "):rep(space), list[n].text:len()+space*2, align), list[n].bgCol, list[n].fgCol)
|
||||||
|
end
|
||||||
|
xPos = xPos+list[n].text:len()+space*2
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
}
|
||||||
|
|
||||||
|
return setmetatable(object, base)
|
||||||
|
end
|
||||||
|
|
||||||
local function Dropdown(name)
|
local function Dropdown(name)
|
||||||
local base = Object(name)
|
local base = Object(name)
|
||||||
local typ = "Dropdown"
|
local typ = "Dropdown"
|
||||||
@@ -2016,8 +2284,17 @@ local function Dropdown(name)
|
|||||||
return typ
|
return typ
|
||||||
end;
|
end;
|
||||||
|
|
||||||
addItem = function(self, text, bgCol, fgCol)
|
setIndexOffset = function(self, yOff)
|
||||||
table.insert(list, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor})
|
yOffset = yOff
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
getIndexOffset = function(self)
|
||||||
|
return yOffset
|
||||||
|
end;
|
||||||
|
|
||||||
|
addItem = function(self, text, bgCol, fgCol, ...)
|
||||||
|
table.insert(list, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}})
|
||||||
if(#list==1)then
|
if(#list==1)then
|
||||||
self:setValue(list[1])
|
self:setValue(list[1])
|
||||||
end
|
end
|
||||||
@@ -2033,13 +2310,28 @@ local function Dropdown(name)
|
|||||||
return list[index]
|
return list[index]
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
getItemIndex = function(self)
|
||||||
|
local selected = self:getValue()
|
||||||
|
for k,v in pairs(list)do
|
||||||
|
if(v==selected)then
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
clear = function(self)
|
||||||
|
list = {}
|
||||||
|
self:setValue({})
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
getItemCount = function(self)
|
getItemCount = function(self)
|
||||||
return #list
|
return #list
|
||||||
end;
|
end;
|
||||||
|
|
||||||
editItem = function(self, index, text, bgCol, fgCol)
|
editItem = function(self, index, text, bgCol, fgCol, ...)
|
||||||
table.remove(list, index)
|
table.remove(list, index)
|
||||||
table.insert(list, index, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor})
|
table.insert(list, index, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}})
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -2048,7 +2340,7 @@ local function Dropdown(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
selectedItem = function(self, bgCol, fgCol, active)
|
setSelectedItem = function(self, bgCol, fgCol, active)
|
||||||
itemSelectedBG = bgCol or self.bgcolor
|
itemSelectedBG = bgCol or self.bgcolor
|
||||||
itemSelectedFG = fgCol or self.fgcolor
|
itemSelectedFG = fgCol or self.fgcolor
|
||||||
selectionColorActive = active
|
selectionColorActive = active
|
||||||
@@ -2062,7 +2354,7 @@ local function Dropdown(name)
|
|||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
if(state == 2)then
|
if(state == 2)then
|
||||||
local obx,oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx,oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(event=="mouse_click")then -- remove mouse_drag if i want to make objects moveable uwuwuwuw
|
if(event=="mouse_click")then -- remove mouse_drag if i want to make objects moveable uwuwuwuw
|
||||||
if(button==1)then
|
if(button==1)then
|
||||||
if(#list>0)then
|
if(#list>0)then
|
||||||
@@ -2160,8 +2452,8 @@ local function Radio(name)
|
|||||||
return typ
|
return typ
|
||||||
end;
|
end;
|
||||||
|
|
||||||
addItem = function(self,text, x, y, bgCol, fgCol)
|
addItem = function(self,text, x, y, bgCol, fgCol, ...)
|
||||||
table.insert(list, {x=x or 1, y=y or 1, text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor})
|
table.insert(list, {x=x or 1, y=y or 1, text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}})
|
||||||
if(#list==1)then
|
if(#list==1)then
|
||||||
self:setValue(list[1])
|
self:setValue(list[1])
|
||||||
end
|
end
|
||||||
@@ -2177,13 +2469,28 @@ local function Radio(name)
|
|||||||
return list[index]
|
return list[index]
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
getItemIndex = function(self)
|
||||||
|
local selected = self:getValue()
|
||||||
|
for k,v in pairs(list)do
|
||||||
|
if(v==selected)then
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
clear = function(self)
|
||||||
|
list = {}
|
||||||
|
self:setValue({})
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
getItemCount = function(self)
|
getItemCount = function(self)
|
||||||
return #list
|
return #list
|
||||||
end;
|
end;
|
||||||
|
|
||||||
editItem = function(self, index, text, x, y, bgCol, fgCol)
|
editItem = function(self, index, text, x, y, bgCol, fgCol, ...)
|
||||||
table.remove(list, index)
|
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})
|
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={...}})
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -2192,7 +2499,7 @@ local function Radio(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
selectedItem = function(self, bgCol, fgCol, boxBG, boxFG, active)
|
setSelectedItem = function(self, bgCol, fgCol, boxBG, boxFG, active)
|
||||||
itemSelectedBG = bgCol or itemSelectedBG
|
itemSelectedBG = bgCol or itemSelectedBG
|
||||||
itemSelectedFG = fgCol or itemSelectedFG
|
itemSelectedFG = fgCol or itemSelectedFG
|
||||||
boxSelectedBG = boxBG or boxSelectedBG
|
boxSelectedBG = boxBG or boxSelectedBG
|
||||||
@@ -2202,14 +2509,14 @@ local function Radio(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
local obx,oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx,oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(event=="mouse_click")then -- remove mouse_drag if i want to make objects moveable uwuwuwuw
|
if(event=="mouse_click")then -- remove mouse_drag if i want to make objects moveable uwuwuwuw
|
||||||
if(button==1)then
|
if(button==1)then
|
||||||
if(#list>0)then
|
if(#list>0)then
|
||||||
for _,v in pairs(list)do
|
for _,v in pairs(list)do
|
||||||
if(obx+v.x-1<=x)and(obx+v.x-1+v.text:len()+2>=x)and(oby+v.y-1==y)then
|
if(obx+v.x-1<=x)and(obx+v.x-1+v.text:len()+2>=x)and(oby+v.y-1==y)then
|
||||||
self:setValue(v)
|
self:setValue(v)
|
||||||
if(self.parent~=nil)then self.parent:setFocus(self) end
|
if(self.parent~=nil)then self.parent:setFocusedObject(self) end
|
||||||
--eventSystem:sendEvent(event, self, event, button, x, y)
|
--eventSystem:sendEvent(event, self, event, button, x, y)
|
||||||
self:setVisualChanged()
|
self:setVisualChanged()
|
||||||
return true
|
return true
|
||||||
@@ -2310,6 +2617,74 @@ local function Timer(name)
|
|||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function Thread(name)
|
||||||
|
local object
|
||||||
|
local typ = "Thread"
|
||||||
|
|
||||||
|
local func
|
||||||
|
local cRoutine
|
||||||
|
local isActive = false
|
||||||
|
|
||||||
|
object = {
|
||||||
|
name = name,
|
||||||
|
getType = function(self)
|
||||||
|
return typ
|
||||||
|
end;
|
||||||
|
getZIndex = function(self)
|
||||||
|
return 1
|
||||||
|
end;
|
||||||
|
getName = function(self)
|
||||||
|
return self.name
|
||||||
|
end;
|
||||||
|
|
||||||
|
start = function(self, f)
|
||||||
|
if(f==nil)then error("function is nil") end
|
||||||
|
func = f
|
||||||
|
cRoutine = coroutine.create(func)
|
||||||
|
isActive = true
|
||||||
|
local ok, result = coroutine.resume(cRoutine)
|
||||||
|
if not(ok)then
|
||||||
|
if(result~="Terminated")then
|
||||||
|
error("Threaderror - "..result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
getStatus = function(self, f)
|
||||||
|
if(cRoutine~=nil)then
|
||||||
|
return coroutine.status(cRoutine)
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end;
|
||||||
|
|
||||||
|
stop = function(self, f)
|
||||||
|
isActive = false
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
eventHandler = function(self, event, p1,p2,p3)
|
||||||
|
if(isActive)then
|
||||||
|
if(coroutine.status(cRoutine)~="dead")then
|
||||||
|
local ok, result = coroutine.resume(cRoutine, event,p1,p2,p3)
|
||||||
|
if not(ok)then
|
||||||
|
if(result~="Terminated")then
|
||||||
|
error("Threaderror - "..result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
isActive = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
object.__index = object
|
||||||
|
|
||||||
|
return object
|
||||||
|
end
|
||||||
|
|
||||||
local function Animation(name)
|
local function Animation(name)
|
||||||
local object = {}
|
local object = {}
|
||||||
local typ = "Animation"
|
local typ = "Animation"
|
||||||
@@ -2454,7 +2829,7 @@ local function Slider(name)
|
|||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
if(base.mouseHandler(self,event,button,x,y))then
|
if(base.mouseHandler(self,event,button,x,y))then
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(barType=="horizontal")then
|
if(barType=="horizontal")then
|
||||||
for _index=0,self.w-1 do
|
for _index=0,self.w-1 do
|
||||||
if(obx+_index==x)and(oby<=y)and(oby+self.h>y)then
|
if(obx+_index==x)and(oby<=y)and(oby+self.h>y)then
|
||||||
@@ -2577,7 +2952,7 @@ local function Scrollbar(name)
|
|||||||
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
mouseHandler = function(self, event, button, x, y)
|
||||||
if(base.mouseHandler(self,event,button,x,y))then
|
if(base.mouseHandler(self,event,button,x,y))then
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if((event=="mouse_click")or(event=="mouse_drag"))and(button==1)then
|
if((event=="mouse_click")or(event=="mouse_drag"))and(button==1)then
|
||||||
if(barType=="horizontal")then
|
if(barType=="horizontal")then
|
||||||
for _index=0,self.w do
|
for _index=0,self.w do
|
||||||
@@ -2604,6 +2979,7 @@ local function Scrollbar(name)
|
|||||||
index = math.min(index, (barType=="vertical" and self.h or self.w)-(symbolSize-1))
|
index = math.min(index, (barType=="vertical" and self.h or self.w)-(symbolSize-1))
|
||||||
self:setValue(maxValue/(barType=="vertical" and self.h or self.w)*index)
|
self:setValue(maxValue/(barType=="vertical" and self.h or self.w)*index)
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -2634,15 +3010,12 @@ local function Scrollbar(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return setmetatable(object, base)
|
return setmetatable(object, base)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function Frame(name,parent) -- Frame
|
local function Frame(name,parent) -- Frame
|
||||||
local base = Object(name)
|
local base = Object(name)
|
||||||
local typ = "Frame"
|
local typ = "Frame"
|
||||||
@@ -2729,7 +3102,7 @@ local function Frame(name,parent) -- Frame
|
|||||||
return typ
|
return typ
|
||||||
end;
|
end;
|
||||||
|
|
||||||
setFocus = function(self, obj)
|
setFocusedObject = function(self, obj)
|
||||||
for _,index in pairs(objZIndex)do
|
for _,index in pairs(objZIndex)do
|
||||||
for _,v in pairs(objects[index])do
|
for _,v in pairs(objects[index])do
|
||||||
if(v == obj)then
|
if(v == obj)then
|
||||||
@@ -2752,13 +3125,13 @@ local function Frame(name,parent) -- Frame
|
|||||||
return xOffset, yOffset
|
return xOffset, yOffset
|
||||||
end;
|
end;
|
||||||
|
|
||||||
removeFocus = function(self)
|
removeFocusedObject = function(self)
|
||||||
if(focusedObject~=nil)then focusedObject:loseFocusHandler() end
|
if(focusedObject~=nil)then focusedObject:loseFocusHandler() end
|
||||||
focusedObject = nil
|
focusedObject = nil
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getFocus = function(self)
|
getFocusedObject = function(self)
|
||||||
return focusedObject
|
return focusedObject
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -2771,7 +3144,7 @@ local function Frame(name,parent) -- Frame
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
setCursor = function(self, _blink, _xCursor, _yCursor, color)
|
setCursor = function(self, _blink, _xCursor, _yCursor, color)
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
cursorBlink = _blink or false
|
cursorBlink = _blink or false
|
||||||
if(_xCursor~=nil)then xCursor = obx+_xCursor-1 end
|
if(_xCursor~=nil)then xCursor = obx+_xCursor-1 end
|
||||||
if(_yCursor~=nil)then yCursor = oby+_yCursor-1 end
|
if(_yCursor~=nil)then yCursor = oby+_yCursor-1 end
|
||||||
@@ -2823,7 +3196,6 @@ local function Frame(name,parent) -- Frame
|
|||||||
|
|
||||||
loseFocusHandler = function(self)
|
loseFocusHandler = function(self)
|
||||||
base.loseFocusHandler(self)
|
base.loseFocusHandler(self)
|
||||||
self.drag = false
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getFocusHandler = function(self)
|
getFocusHandler = function(self)
|
||||||
@@ -2871,7 +3243,7 @@ local function Frame(name,parent) -- Frame
|
|||||||
if(event=="mouse_drag")then
|
if(event=="mouse_drag")then
|
||||||
local parentX=1;local parentY=1
|
local parentX=1;local parentY=1
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
parentX,parentY = self.parent:calcRelToAbsPosition(self.parent:getAnchorPosition())
|
parentX,parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
|
||||||
end
|
end
|
||||||
self:setPosition(x+self.xToRem-(parentX-1) + xO,y-(parentY-1) + yO)
|
self:setPosition(x+self.xToRem-(parentX-1) + xO,y-(parentY-1) + yO)
|
||||||
end
|
end
|
||||||
@@ -2882,7 +3254,7 @@ local function Frame(name,parent) -- Frame
|
|||||||
end
|
end
|
||||||
|
|
||||||
if(base.mouseHandler(self,event,button,x,y))then
|
if(base.mouseHandler(self,event,button,x,y))then
|
||||||
local fx,fy = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local fx,fy = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
for _,index in pairs(objZIndex)do
|
for _,index in pairs(objZIndex)do
|
||||||
if(objects[index]~=nil)then
|
if(objects[index]~=nil)then
|
||||||
for _,v in rpairs(objects[index])do
|
for _,v in rpairs(objects[index])do
|
||||||
@@ -2892,6 +3264,7 @@ local function Frame(name,parent) -- Frame
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if(focusedObject~=nil)then focusedObject:loseFocusHandler() end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2908,64 +3281,103 @@ local function Frame(name,parent) -- Frame
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
setText = function(self, x, y, text)
|
setText = function(self, x, y, text)
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(y>=1)and(y<=self.h)then
|
if(y>=1)and(y<=self.h)then
|
||||||
drawHelper.setText(math.max(x+(obx-1),obx), oby+y-1, sub( text, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
if(self.parent~=nil)then
|
||||||
|
self.parent:setText(math.max(x+(obx-1),obx)-(self.parent.x-1), oby+y-1-(self.parent.y-1), sub( text, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
||||||
|
else
|
||||||
|
drawHelper.setText(math.max(x+(obx-1),obx), oby+y-1, sub( text, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
setBG = function(self, x, y, bgCol)
|
setBG = function(self, x, y, bgCol)
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(y>=1)and(y<=self.h)then
|
if(y>=1)and(y<=self.h)then
|
||||||
drawHelper.setBG(math.max(x+(obx-1),obx), oby+y-1, sub( bgCol, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
if(self.parent~=nil)then
|
||||||
|
self.parent:setBG(math.max(x+(obx-1),obx)-(self.parent.x-1), oby+y-1-(self.parent.y-1), sub( bgCol, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
||||||
|
else
|
||||||
|
drawHelper.setBG(math.max(x+(obx-1),obx), oby+y-1, sub( bgCol, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
setFG = function(self, x, y, fgCol)
|
setFG = function(self, x, y, fgCol)
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(y>=1)and(y<=self.h)then
|
if(y>=1)and(y<=self.h)then
|
||||||
drawHelper.setFG(math.max(x+(obx-1),obx), oby+y-1, sub( fgCol, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
if(self.parent~=nil)then
|
||||||
|
self.parent:setFG(math.max(x+(obx-1),obx)-(self.parent.x-1), oby+y-1-(self.parent.y-1), sub( fgCol, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
||||||
|
else
|
||||||
|
drawHelper.setFG(math.max(x+(obx-1),obx), oby+y-1, sub( fgCol, math.max(1 - x + 1, 1), self.w - x + 1 ))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
writeText = function(self, x, y, text, bgCol, fgCol)
|
writeText = function(self, x, y, text, bgCol, fgCol)
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
if(y>=1)and(y<=self.h)then
|
if(y>=1)and(y<=self.h)then
|
||||||
drawHelper.writeText(math.max(x+(obx-1),obx), oby+y-1, sub( text, math.max(1 - x + 1, 1), self.w - x + 1 ), bgCol, fgCol)
|
if(self.parent~=nil)then
|
||||||
|
self.parent:writeText(math.max(x+(obx-1),obx)-(self.parent.x-1), oby+y-1-(self.parent.y-1), sub( text, math.max(1 - x + 1, 1), self.w - x + 1 ), bgCol, fgCol)
|
||||||
|
else
|
||||||
|
drawHelper.writeText(math.max(x+(obx-1),obx), oby+y-1, sub( text, math.max(1 - x + 1, 1), self.w - x + 1 ), bgCol, fgCol)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
drawBackgroundBox = function(self, x, y, w, h, bgCol)
|
drawBackgroundBox = function(self, x, y, w, h, bgCol)
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h))
|
h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h))
|
||||||
w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w))
|
w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w))
|
||||||
drawHelper.drawBackgroundBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, bgCol)
|
if(self.parent~=nil)then
|
||||||
|
self.parent:drawBackgroundBox(math.max(x+(obx-1),obx)-(self.parent.x-1), math.max(y+(oby-1),oby)-(self.parent.y-1), w, h, bgCol)
|
||||||
|
else
|
||||||
|
drawHelper.drawBackgroundBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, bgCol)
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
drawTextBox = function(self, x, y, w, h, symbol)
|
drawTextBox = function(self, x, y, w, h, symbol)
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h))
|
h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h))
|
||||||
w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w))
|
w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w))
|
||||||
drawHelper.drawTextBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, symbol:sub(1,1))
|
if(self.parent~=nil)then
|
||||||
|
self.parent:drawTextBox(math.max(x+(obx-1),obx)-(self.parent.x-1), math.max(y+(oby-1),oby)-(self.parent.y-1), w, h, symbol:sub(1,1))
|
||||||
|
else
|
||||||
|
drawHelper.drawTextBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, symbol:sub(1,1))
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
drawForegroundBox = function(self, x, y, w, h, fgCol)
|
drawForegroundBox = function(self, x, y, w, h, fgCol)
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h))
|
h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h))
|
||||||
w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w))
|
w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w))
|
||||||
drawHelper.drawForegroundBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, fgCol)
|
if(self.parent~=nil)then
|
||||||
|
self.parent:drawForegroundBox(math.max(x+(obx-1),obx)-(self.parent.x-1), math.max(y+(oby-1),oby)-(self.parent.y-1), w, h, fgCol)
|
||||||
|
else
|
||||||
|
drawHelper.drawForegroundBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, fgCol)
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
draw = function(self)
|
draw = function(self)
|
||||||
if(self:getVisualChanged())then
|
if(self:getVisualChanged())then
|
||||||
if(base.draw(self))then
|
if(base.draw(self))then
|
||||||
local obx, oby = self:calcRelToAbsPosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
drawHelper.drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor)
|
local anchx, anchy = self:getAnchorPosition()
|
||||||
drawHelper.drawForegroundBox(obx, oby, self.w, self.h, self.fgcolor)
|
if(self.parent~=nil)then
|
||||||
drawHelper.drawTextBox(obx, oby, self.w, self.h, " ")
|
self.parent:drawBackgroundBox(anchx, anchy, self.w, self.h, self.bgcolor)
|
||||||
|
self.parent:drawForegroundBox(anchx, anchy, self.w, self.h, self.fgcolor)
|
||||||
|
self.parent:drawTextBox(anchx, anchy, self.w, self.h, " ")
|
||||||
|
else
|
||||||
|
drawHelper.drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor)
|
||||||
|
drawHelper.drawForegroundBox(obx, oby, self.w, self.h, self.fgcolor)
|
||||||
|
drawHelper.drawTextBox(obx, oby, self.w, self.h, " ")
|
||||||
|
end
|
||||||
parentTerminal.setCursorBlink(false)
|
parentTerminal.setCursorBlink(false)
|
||||||
if(self.barActive)then
|
if(self.barActive)then
|
||||||
drawHelper.writeText(obx, oby, getTextHorizontalAlign(self.barText, self.w, self.barTextAlign), self.barBackground, self.barTextcolor)
|
if(self.parent~=nil)then
|
||||||
|
self.parent:writeText(anchx, anchy, getTextHorizontalAlign(self.barText, self.w, self.barTextAlign), self.barBackground, self.barTextcolor)
|
||||||
|
else
|
||||||
|
drawHelper.writeText(obx, oby, getTextHorizontalAlign(self.barText, self.w, self.barTextAlign), self.barBackground, self.barTextcolor)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,index in rpairs(objZIndex)do
|
for _,index in rpairs(objZIndex)do
|
||||||
@@ -3080,6 +3492,18 @@ local function Frame(name,parent) -- Frame
|
|||||||
return addObject(obj)
|
return addObject(obj)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
addMenubar = function(self, name)
|
||||||
|
local obj = Menubar(name)
|
||||||
|
obj.name = name
|
||||||
|
return addObject(obj)
|
||||||
|
end;
|
||||||
|
|
||||||
|
addThread = function(self, name)
|
||||||
|
local obj = Thread(name)
|
||||||
|
obj.name = name
|
||||||
|
return addObject(obj)
|
||||||
|
end;
|
||||||
|
|
||||||
addFrame = function(self, name)
|
addFrame = function(self, name)
|
||||||
local obj = Frame(name, self)
|
local obj = Frame(name, self)
|
||||||
obj.name = name
|
obj.name = name
|
||||||
|
|||||||
Reference in New Issue
Block a user