fixes and changes
- added other events (now animations/threads/timers should work like intended) - fixed a bug with auto resize (especially for craftos pc) - removed importantScroll (i really disliked this, but now its just not necessary anymore) - removed setMaxScroll and setMinScroll, now it's only 1 method called :setScrollAmount() - if you make a frame scrollable (:setScrollable()) the frame will calculate the allowed scroll amount by it's childrens object's position+height unless you are using :setScrollAmount()
This commit is contained in:
@@ -7,6 +7,7 @@ local layout = require("layout")
|
|||||||
local uuid = utils.uuid
|
local uuid = utils.uuid
|
||||||
local rpairs = utils.rpairs
|
local rpairs = utils.rpairs
|
||||||
local xmlValue = utils.getValueFromXML
|
local xmlValue = utils.getValueFromXML
|
||||||
|
local tableCount = utils.tableCount
|
||||||
|
|
||||||
local sub,min,max = string.sub,math.min,math.max
|
local sub,min,max = string.sub,math.min,math.max
|
||||||
|
|
||||||
@@ -35,7 +36,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
local mirrorActive = false
|
local mirrorActive = false
|
||||||
local mirrorAttached = false
|
local mirrorAttached = false
|
||||||
local mirrorSide = ""
|
local mirrorSide = ""
|
||||||
local importantScroll = false
|
|
||||||
local isMovable = false
|
local isMovable = false
|
||||||
local isDragging =false
|
local isDragging =false
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
if (value == obj) then
|
if (value == obj) then
|
||||||
table.remove(events[a][c], key)
|
table.remove(events[a][c], key)
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
if(#events[a]<=0)then
|
if(tableCount(events[event])<=0)then
|
||||||
self.parent:removeEvent(a, self)
|
self.parent:removeEvent(a, self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -183,7 +183,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function addEvent(self, event, obj)
|
local function addEvent(self, event, obj)
|
||||||
log("Registered Event: "..event.." for "..obj:getName())
|
|
||||||
local zIndex = obj:getZIndex()
|
local zIndex = obj:getZIndex()
|
||||||
if(events[event]==nil)then events[event] = {} end
|
if(events[event]==nil)then events[event] = {} end
|
||||||
if(eventZIndex[event]==nil)then eventZIndex[event] = {} end
|
if(eventZIndex[event]==nil)then eventZIndex[event] = {} end
|
||||||
@@ -224,11 +223,11 @@ return function(name, parent, pTerm, basalt)
|
|||||||
table.remove(events[event][a], key)
|
table.remove(events[event][a], key)
|
||||||
if(#events[event][a]<=0)then
|
if(#events[event][a]<=0)then
|
||||||
events[event][a] = nil
|
events[event][a] = nil
|
||||||
end
|
if(self.parent~=nil)then
|
||||||
if(self.parent~=nil)then
|
if(tableCount(events[event])<=0)then
|
||||||
if(#events[event]<=0)then
|
activeEvents[event] = false
|
||||||
activeEvents[event] = false
|
self.parent:removeEvent(event, self)
|
||||||
self.parent:removeEvent(event, self)
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true;
|
return true;
|
||||||
@@ -341,7 +340,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
object = {
|
object = {
|
||||||
barActive = false,
|
barActive = false,
|
||||||
barBackground = colors.gray,
|
barBackground = colors.gray,
|
||||||
@@ -374,7 +372,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
setSize = function(self, w, h, rel)
|
setSize = function(self, w, h, rel)
|
||||||
base.setSize(self, w, h, rel)
|
base.setSize(self, w, h, rel)
|
||||||
if(self.parent==nil)then
|
if(self.parent==nil)then
|
||||||
basaltDraw = BasaltDraw()
|
basaltDraw = BasaltDraw(termObject)
|
||||||
end
|
end
|
||||||
for _, index in pairs(objZIndex) do
|
for _, index in pairs(objZIndex) do
|
||||||
if (objects[index] ~= nil) then
|
if (objects[index] ~= nil) then
|
||||||
@@ -468,8 +466,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
activeEvents["mouse_up"] = true
|
activeEvents["mouse_up"] = true
|
||||||
self.parent:addEvent("mouse_drag", self)
|
self.parent:addEvent("mouse_drag", self)
|
||||||
activeEvents["mouse_drag"] = true
|
activeEvents["mouse_drag"] = true
|
||||||
self.parent:addEvent("mouse_scroll", self)
|
|
||||||
activeEvents["mouse_scroll"] = true
|
|
||||||
end
|
end
|
||||||
return self;
|
return self;
|
||||||
end;
|
end;
|
||||||
@@ -483,11 +479,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
setImportantScroll = function(self, imp)
|
|
||||||
importantScroll = imp and true or false
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
|
|
||||||
setScrollAmount = function(self, max)
|
setScrollAmount = function(self, max)
|
||||||
scrollAmount = max or scrollAmount
|
scrollAmount = max or scrollAmount
|
||||||
autoScroll = false
|
autoScroll = false
|
||||||
@@ -569,7 +560,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
if(xmlValue("xOffset", data)~=nil)then self:setOffset(xmlValue("xOffset", data), yOffset) end
|
if(xmlValue("xOffset", data)~=nil)then self:setOffset(xmlValue("xOffset", data), yOffset) end
|
||||||
if(xmlValue("yOffset", data)~=nil)then self:setOffset(yOffset, xmlValue("yOffset", data)) end
|
if(xmlValue("yOffset", data)~=nil)then self:setOffset(yOffset, xmlValue("yOffset", data)) end
|
||||||
if(xmlValue("scrollAmount", data)~=nil)then self:setScrollAmount(xmlValue("scrollAmount", data)) end
|
if(xmlValue("scrollAmount", data)~=nil)then self:setScrollAmount(xmlValue("scrollAmount", data)) end
|
||||||
if(xmlValue("importantScroll", data)~=nil)then self:setImportantScroll(xmlValue("importantScroll", data)) end
|
|
||||||
|
|
||||||
local objectList = data:children()
|
local objectList = data:children()
|
||||||
|
|
||||||
@@ -671,13 +661,15 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
getFocusHandler = function(self)
|
getFocusHandler = function(self)
|
||||||
base.getFocusHandler(self)
|
base.getFocusHandler(self)
|
||||||
if (self.parent ~= nil) then
|
if(isMovable)then
|
||||||
self.parent:removeEvents(self)
|
if (self.parent ~= nil) then
|
||||||
self.parent:removeObject(self)
|
self.parent:removeEvents(self)
|
||||||
self.parent:addObject(self)
|
self.parent:removeObject(self)
|
||||||
for k,v in pairs(activeEvents)do
|
self.parent:addObject(self)
|
||||||
if(v)then
|
for k,v in pairs(activeEvents)do
|
||||||
self.parent:addEvent(k, self)
|
if(v)then
|
||||||
|
self.parent:addEvent(k, self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -685,18 +677,22 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
eventHandler = function(self, event, p1, p2, p3, p4)
|
||||||
base.eventHandler(self, event, p1, p2, p3, p4)
|
base.eventHandler(self, event, p1, p2, p3, p4)
|
||||||
for _, index in pairs(objZIndex) do
|
if(events["other_event"]~=nil)then
|
||||||
if (objects[index] ~= nil) then
|
for _, index in ipairs(eventZIndex["other_event"]) do
|
||||||
for _, value in pairs(objects[index]) do
|
if (events["other_event"][index] ~= nil) then
|
||||||
if (value.eventHandler ~= nil) then
|
for _, value in rpairs(events["other_event"][index]) do
|
||||||
value:eventHandler(event, p1, p2, p3, p4)
|
if (value.eventHandler ~= nil) then
|
||||||
|
if (value:eventHandler(event, p1, p2, p3, p4)) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(autoSize)then
|
if(autoSize)then
|
||||||
if(self.parent==nil)then
|
if(self.parent==nil)then
|
||||||
if(event=="term_resize")then
|
if(event=="term_resize")or(event=="monitor_resize")then
|
||||||
self:setSize(termObject.getSize())
|
self:setSize(termObject.getSize())
|
||||||
autoSize = true
|
autoSize = true
|
||||||
end
|
end
|
||||||
@@ -788,14 +784,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
scrollHandler = function(self, dir, x, y)
|
scrollHandler = function(self, dir, x, y)
|
||||||
if(base.scrollHandler(self, dir, x, y))then
|
if(base.scrollHandler(self, dir, x, y))then
|
||||||
if(isScrollable)and(autoScroll)then
|
|
||||||
calculateMaxScroll(self)
|
|
||||||
end
|
|
||||||
if(isScrollable)and(importantScroll)then
|
|
||||||
if(dir>0)or(dir<0)then
|
|
||||||
yOffset = max(min(yOffset-dir, 0),-scrollAmount)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if(events["mouse_scroll"]~=nil)then
|
if(events["mouse_scroll"]~=nil)then
|
||||||
for _, index in pairs(eventZIndex["mouse_scroll"]) do
|
for _, index in pairs(eventZIndex["mouse_scroll"]) do
|
||||||
if (events["mouse_scroll"][index] ~= nil) then
|
if (events["mouse_scroll"][index] ~= nil) then
|
||||||
@@ -809,11 +797,14 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(isScrollable)and not(importantScroll)then
|
local cache = yOffset
|
||||||
|
if(isScrollable)then
|
||||||
|
calculateMaxScroll(self)
|
||||||
if(dir>0)or(dir<0)then
|
if(dir>0)or(dir<0)then
|
||||||
yOffset = max(min(yOffset-dir, 0),-scrollAmount)
|
yOffset = max(min(yOffset-dir, 0),-scrollAmount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if(yOffset==cache)then return false end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -573,9 +573,13 @@ return function(name)
|
|||||||
onEvent = function(self, ...)
|
onEvent = function(self, ...)
|
||||||
for _,v in pairs(table.pack(...))do
|
for _,v in pairs(table.pack(...))do
|
||||||
if(type(v)=="function")then
|
if(type(v)=="function")then
|
||||||
self:registerEvent("custom_event_handler", v)
|
self:registerEvent("other_event", v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if(self.parent~=nil)then
|
||||||
|
self.parent:addEvent("other_event", self)
|
||||||
|
activeEvents["other_event"] = true
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -755,55 +759,6 @@ return function(name)
|
|||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--[[
|
|
||||||
mouseHandler = function(self, event, button, x, y)
|
|
||||||
if(isEnabled)and(isVisible)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
|
|
||||||
|
|
||||||
|
|
||||||
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;]]
|
|
||||||
|
|
||||||
keyHandler = function(self, key)
|
keyHandler = function(self, key)
|
||||||
if(isEnabled)then
|
if(isEnabled)then
|
||||||
if (self:isFocused()) then
|
if (self:isFocused()) then
|
||||||
@@ -842,7 +797,8 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
eventHandler = function(self, event, p1, p2, p3, p4)
|
||||||
eventSystem:sendEvent("custom_event_handler", self, event, p1, p2, p3, p4)
|
eventSystem:sendEvent("other_event", self, event, p1, p2, p3, p4)
|
||||||
|
return true
|
||||||
end;
|
end;
|
||||||
|
|
||||||
getFocusHandler = function(self)
|
getFocusHandler = function(self)
|
||||||
|
|||||||
@@ -378,6 +378,7 @@ return function(name)
|
|||||||
|
|
||||||
animationDoneHandler = function(self)
|
animationDoneHandler = function(self)
|
||||||
eventSystem:sendEvent("animation_done", self)
|
eventSystem:sendEvent("animation_done", self)
|
||||||
|
self.parent:removeEvent("other_event", self)
|
||||||
if(autoDestroy)then
|
if(autoDestroy)then
|
||||||
self.parent:removeObject(self)
|
self.parent:removeObject(self)
|
||||||
self = nil
|
self = nil
|
||||||
@@ -413,6 +414,7 @@ return function(name)
|
|||||||
else
|
else
|
||||||
self:animationDoneHandler()
|
self:animationDoneHandler()
|
||||||
end
|
end
|
||||||
|
self.parent:addEvent("other_event", self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -422,6 +424,7 @@ return function(name)
|
|||||||
infinitePlay = false
|
infinitePlay = false
|
||||||
end
|
end
|
||||||
animationActive = false
|
animationActive = false
|
||||||
|
self.parent:removeEvent("other_event", self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@@ -525,6 +525,7 @@ return function(name, parent)
|
|||||||
self.parent:addEvent("key", self)
|
self.parent:addEvent("key", self)
|
||||||
self.parent:addEvent("key_up", self)
|
self.parent:addEvent("key_up", self)
|
||||||
self.parent:addEvent("char", self)
|
self.parent:addEvent("char", self)
|
||||||
|
self.parent:addEvent("other_event", self)
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -540,6 +541,7 @@ return function(name, parent)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self.parent:removeEvents(self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -681,30 +683,30 @@ return function(name, parent)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
eventHandler = function(self, event, p1, p2, p3, p4)
|
||||||
if (curProcess == nil) then
|
if(base.eventHandler(self, event, p1, p2, p3, p4))then
|
||||||
return
|
if (curProcess == nil) then
|
||||||
end
|
return
|
||||||
if not (curProcess:isDead()) then
|
end
|
||||||
if not (paused) then
|
if not (curProcess:isDead()) then
|
||||||
if(event ~= "terminate") then
|
if not (paused) then
|
||||||
curProcess:resume(event, p1, p2, p3, p4)
|
if(event ~= "terminate") then
|
||||||
end
|
curProcess:resume(event, p1, p2, p3, p4)
|
||||||
if (self:isFocused()) then
|
end
|
||||||
local obx, oby = self:getAnchorPosition()
|
if (self:isFocused()) then
|
||||||
local xCur, yCur = pWindow.getCursorPos()
|
local obx, oby = self:getAnchorPosition()
|
||||||
if (self.parent ~= nil) then
|
local xCur, yCur = pWindow.getCursorPos()
|
||||||
local w,h = self:getSize()
|
if (self.parent ~= nil) then
|
||||||
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
|
local w,h = self:getSize()
|
||||||
self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor())
|
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") and (self:isFocused()) then
|
||||||
|
self:stop()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
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
|
|
||||||
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
|
table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ return function(name)
|
|||||||
error("Thread Error Occurred - " .. result)
|
error("Thread Error Occurred - " .. result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self.parent:addEvent("other_event", self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ return function(name)
|
|||||||
|
|
||||||
stop = function(self, f)
|
stop = function(self, f)
|
||||||
isActive = false
|
isActive = false
|
||||||
|
self.parent:removeEvent("other_event", self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ return function(name)
|
|||||||
repeats = savedRepeats
|
repeats = savedRepeats
|
||||||
timerObj = os.startTimer(timer)
|
timerObj = os.startTimer(timer)
|
||||||
timerIsActive = true
|
timerIsActive = true
|
||||||
|
self.parent:addEvent("other_event", self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ return function(name)
|
|||||||
os.cancelTimer(timerObj)
|
os.cancelTimer(timerObj)
|
||||||
end
|
end
|
||||||
timerIsActive = false
|
timerIsActive = false
|
||||||
|
self.parent:removeEvent("other_event", self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,16 @@ rpairs = function(t)
|
|||||||
end, t, #t + 1
|
end, t, #t + 1
|
||||||
end,
|
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,
|
splitString = splitString,
|
||||||
|
|
||||||
createText = function(str, width)
|
createText = function(str, width)
|
||||||
|
|||||||
Reference in New Issue
Block a user