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 rpairs = utils.rpairs
|
||||
local xmlValue = utils.getValueFromXML
|
||||
local tableCount = utils.tableCount
|
||||
|
||||
local sub,min,max = string.sub,math.min,math.max
|
||||
|
||||
@@ -35,7 +36,6 @@ return function(name, parent, pTerm, basalt)
|
||||
local mirrorActive = false
|
||||
local mirrorAttached = false
|
||||
local mirrorSide = ""
|
||||
local importantScroll = false
|
||||
local isMovable = false
|
||||
local isDragging =false
|
||||
|
||||
@@ -149,7 +149,7 @@ return function(name, parent, pTerm, basalt)
|
||||
if (value == obj) then
|
||||
table.remove(events[a][c], key)
|
||||
if(self.parent~=nil)then
|
||||
if(#events[a]<=0)then
|
||||
if(tableCount(events[event])<=0)then
|
||||
self.parent:removeEvent(a, self)
|
||||
end
|
||||
end
|
||||
@@ -183,7 +183,6 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
|
||||
local function addEvent(self, event, obj)
|
||||
log("Registered Event: "..event.." for "..obj:getName())
|
||||
local zIndex = obj:getZIndex()
|
||||
if(events[event]==nil)then events[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)
|
||||
if(#events[event][a]<=0)then
|
||||
events[event][a] = nil
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
if(#events[event]<=0)then
|
||||
activeEvents[event] = false
|
||||
self.parent:removeEvent(event, self)
|
||||
if(self.parent~=nil)then
|
||||
if(tableCount(events[event])<=0)then
|
||||
activeEvents[event] = false
|
||||
self.parent:removeEvent(event, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true;
|
||||
@@ -341,7 +340,6 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
object = {
|
||||
barActive = false,
|
||||
barBackground = colors.gray,
|
||||
@@ -374,7 +372,7 @@ return function(name, parent, pTerm, basalt)
|
||||
setSize = function(self, w, h, rel)
|
||||
base.setSize(self, w, h, rel)
|
||||
if(self.parent==nil)then
|
||||
basaltDraw = BasaltDraw()
|
||||
basaltDraw = BasaltDraw(termObject)
|
||||
end
|
||||
for _, index in pairs(objZIndex) do
|
||||
if (objects[index] ~= nil) then
|
||||
@@ -468,8 +466,6 @@ return function(name, parent, pTerm, basalt)
|
||||
activeEvents["mouse_up"] = true
|
||||
self.parent:addEvent("mouse_drag", self)
|
||||
activeEvents["mouse_drag"] = true
|
||||
self.parent:addEvent("mouse_scroll", self)
|
||||
activeEvents["mouse_scroll"] = true
|
||||
end
|
||||
return self;
|
||||
end;
|
||||
@@ -483,11 +479,6 @@ return function(name, parent, pTerm, basalt)
|
||||
return self
|
||||
end,
|
||||
|
||||
setImportantScroll = function(self, imp)
|
||||
importantScroll = imp and true or false
|
||||
return self
|
||||
end,
|
||||
|
||||
setScrollAmount = function(self, max)
|
||||
scrollAmount = max or scrollAmount
|
||||
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("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("importantScroll", data)~=nil)then self:setImportantScroll(xmlValue("importantScroll", data)) end
|
||||
|
||||
local objectList = data:children()
|
||||
|
||||
@@ -671,13 +661,15 @@ return function(name, parent, pTerm, basalt)
|
||||
|
||||
getFocusHandler = function(self)
|
||||
base.getFocusHandler(self)
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:removeEvents(self)
|
||||
self.parent:removeObject(self)
|
||||
self.parent:addObject(self)
|
||||
for k,v in pairs(activeEvents)do
|
||||
if(v)then
|
||||
self.parent:addEvent(k, self)
|
||||
if(isMovable)then
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:removeEvents(self)
|
||||
self.parent:removeObject(self)
|
||||
self.parent:addObject(self)
|
||||
for k,v in pairs(activeEvents)do
|
||||
if(v)then
|
||||
self.parent:addEvent(k, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -685,18 +677,22 @@ return function(name, parent, pTerm, basalt)
|
||||
|
||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
||||
base.eventHandler(self, event, p1, p2, p3, p4)
|
||||
for _, index in pairs(objZIndex) do
|
||||
if (objects[index] ~= nil) then
|
||||
for _, value in pairs(objects[index]) do
|
||||
if (value.eventHandler ~= nil) then
|
||||
value:eventHandler(event, p1, p2, p3, p4)
|
||||
if(events["other_event"]~=nil)then
|
||||
for _, index in ipairs(eventZIndex["other_event"]) do
|
||||
if (events["other_event"][index] ~= nil) then
|
||||
for _, value in rpairs(events["other_event"][index]) do
|
||||
if (value.eventHandler ~= nil) then
|
||||
if (value:eventHandler(event, p1, p2, p3, p4)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if(autoSize)then
|
||||
if(self.parent==nil)then
|
||||
if(event=="term_resize")then
|
||||
if(event=="term_resize")or(event=="monitor_resize")then
|
||||
self:setSize(termObject.getSize())
|
||||
autoSize = true
|
||||
end
|
||||
@@ -788,14 +784,6 @@ return function(name, parent, pTerm, basalt)
|
||||
|
||||
scrollHandler = function(self, dir, x, y)
|
||||
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
|
||||
for _, index in pairs(eventZIndex["mouse_scroll"]) do
|
||||
if (events["mouse_scroll"][index] ~= nil) then
|
||||
@@ -809,11 +797,14 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
end
|
||||
end
|
||||
if(isScrollable)and not(importantScroll)then
|
||||
local cache = yOffset
|
||||
if(isScrollable)then
|
||||
calculateMaxScroll(self)
|
||||
if(dir>0)or(dir<0)then
|
||||
yOffset = max(min(yOffset-dir, 0),-scrollAmount)
|
||||
end
|
||||
end
|
||||
if(yOffset==cache)then return false end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
||||
@@ -573,9 +573,13 @@ return function(name)
|
||||
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;
|
||||
|
||||
@@ -755,55 +759,6 @@ return function(name)
|
||||
return false
|
||||
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)
|
||||
if(isEnabled)then
|
||||
if (self:isFocused()) then
|
||||
@@ -842,7 +797,8 @@ return function(name)
|
||||
end;
|
||||
|
||||
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;
|
||||
|
||||
getFocusHandler = function(self)
|
||||
|
||||
@@ -378,6 +378,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
|
||||
@@ -413,6 +414,7 @@ return function(name)
|
||||
else
|
||||
self:animationDoneHandler()
|
||||
end
|
||||
self.parent:addEvent("other_event", self)
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -422,6 +424,7 @@ return function(name)
|
||||
infinitePlay = false
|
||||
end
|
||||
animationActive = false
|
||||
self.parent:removeEvent("other_event", self)
|
||||
return self
|
||||
end;
|
||||
|
||||
|
||||
@@ -525,6 +525,7 @@ return function(name, parent)
|
||||
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;
|
||||
@@ -540,6 +541,7 @@ return function(name, parent)
|
||||
end
|
||||
end
|
||||
end
|
||||
self.parent:removeEvents(self)
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -681,30 +683,30 @@ return function(name, parent)
|
||||
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 ~= "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())
|
||||
if(base.eventHandler(self, event, p1, p2, p3, p4))then
|
||||
if (curProcess == nil) then
|
||||
return
|
||||
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") and (self:isFocused()) then
|
||||
self:stop()
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user