..forgot to add (1.6.3)
- Fixed focus system bug - Fixed :getScrollAmount (frames) - added :onHover - added :onLeave - Made drawing a bit faster - Added a dragging throttle system - Mouse events should send now relative coordinates
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
|
local module = require("module")
|
||||||
local Object = require("Object")
|
local Object = require("Object")
|
||||||
local _OBJECTS = require("loadObjects")
|
local _OBJECTS = require("loadObjects")
|
||||||
local BasaltDraw = require("basaltDraw")
|
local BasaltDraw = require("basaltDraw")
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
local layout = require("layout")
|
local layout = module("layout")
|
||||||
local basaltMon = require("basaltMon")
|
local basaltMon = module("basaltMon")
|
||||||
local uuid = utils.uuid
|
local uuid = utils.uuid
|
||||||
local rpairs = utils.rpairs
|
local rpairs = utils.rpairs
|
||||||
local xmlValue = utils.getValueFromXML
|
local xmlValue = utils.getValueFromXML
|
||||||
@@ -352,19 +353,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function focusSystem(self)
|
|
||||||
if(focusedObject~=focusedObjectCache)then
|
|
||||||
if(focusedObject~=nil)then
|
|
||||||
focusedObject:loseFocusHandler()
|
|
||||||
end
|
|
||||||
if(focusedObjectCache~=nil)then
|
|
||||||
focusedObjectCache:getFocusHandler()
|
|
||||||
end
|
|
||||||
focusedObject = focusedObjectCache
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
object = {
|
object = {
|
||||||
barActive = false,
|
barActive = false,
|
||||||
barBackground = colors.gray,
|
barBackground = colors.gray,
|
||||||
@@ -386,8 +374,15 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
setFocusedObject = function(self, obj)
|
setFocusedObject = function(self, obj)
|
||||||
focusedObjectCache = obj
|
if(focusedObject~=obj)then
|
||||||
focusSystem(self)
|
if(focusedObject~=nil)then
|
||||||
|
focusedObject:loseFocusHandler()
|
||||||
|
end
|
||||||
|
if(obj~=nil)then
|
||||||
|
obj:getFocusHandler()
|
||||||
|
end
|
||||||
|
focusedObject = obj
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -463,8 +458,10 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
removeFocusedObject = function(self)
|
removeFocusedObject = function(self)
|
||||||
focusedObjectCache = nil
|
if(focusedObject~=nil)then
|
||||||
focusSystem(self)
|
focusedObject:loseFocusHandler()
|
||||||
|
end
|
||||||
|
focusedObject = nil
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -527,7 +524,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
|
|
||||||
getScrollAmount = function(self)
|
getScrollAmount = function(self)
|
||||||
return autoScroll and scrollAmount or calculateMaxScroll(self)
|
return autoScroll and calculateMaxScroll(self) or scrollAmount
|
||||||
end,
|
end,
|
||||||
|
|
||||||
show = function(self)
|
show = function(self)
|
||||||
@@ -732,14 +729,14 @@ return function(name, parent, pTerm, basalt)
|
|||||||
if(focusedObject~=nil)then focusedObject:getFocusHandler() end
|
if(focusedObject~=nil)then focusedObject:getFocusHandler() end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
eventHandler = function(self, event, ...)
|
||||||
base.eventHandler(self, event, p1, p2, p3, p4)
|
base.eventHandler(self, event, ...)
|
||||||
if(events["other_event"]~=nil)then
|
if(events["other_event"]~=nil)then
|
||||||
for _, index in ipairs(eventZIndex["other_event"]) do
|
for _, index in ipairs(eventZIndex["other_event"]) do
|
||||||
if (events["other_event"][index] ~= nil) then
|
if (events["other_event"][index] ~= nil) then
|
||||||
for _, value in rpairs(events["other_event"][index]) do
|
for _, value in rpairs(events["other_event"][index]) do
|
||||||
if (value.eventHandler ~= nil) then
|
if (value.eventHandler ~= nil) then
|
||||||
if (value:eventHandler(event, p1, p2, p3, p4)) then
|
if (value:eventHandler(event, ...)) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -816,7 +813,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
for _, value in rpairs(events["mouse_click"][index]) do
|
for _, value in rpairs(events["mouse_click"][index]) do
|
||||||
if (value.mouseHandler ~= nil) then
|
if (value.mouseHandler ~= nil) then
|
||||||
if (value:mouseHandler(button, x, y)) then
|
if (value:mouseHandler(button, x, y)) then
|
||||||
focusSystem(self)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -849,7 +846,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
for _, value in rpairs(events["mouse_up"][index]) do
|
for _, value in rpairs(events["mouse_up"][index]) do
|
||||||
if (value.mouseUpHandler ~= nil) then
|
if (value.mouseUpHandler ~= nil) then
|
||||||
if (value:mouseUpHandler(button, x, y)) then
|
if (value:mouseUpHandler(button, x, y)) then
|
||||||
focusSystem(self)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -857,7 +853,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
focusSystem(self)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
@@ -871,7 +866,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
for _, value in rpairs(events["mouse_scroll"][index]) do
|
for _, value in rpairs(events["mouse_scroll"][index]) do
|
||||||
if (value.scrollHandler ~= nil) then
|
if (value.scrollHandler ~= nil) then
|
||||||
if (value:scrollHandler(dir, x, y)) then
|
if (value:scrollHandler(dir, x, y)) then
|
||||||
focusSystem(self)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -894,6 +888,25 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
hoverHandler = function(self, x, y, stopped)
|
||||||
|
if(base.hoverHandler(self, x, y, stopped))then
|
||||||
|
if(events["mouse_move"]~=nil)then
|
||||||
|
for _, index in pairs(eventZIndex["mouse_move"]) do
|
||||||
|
if (events["mouse_move"][index] ~= nil) then
|
||||||
|
for _, value in rpairs(events["mouse_move"][index]) do
|
||||||
|
if (value.hoverHandler ~= nil) then
|
||||||
|
if (value:hoverHandler(x, y, stopped)) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
|
||||||
dragHandler = function(self, button, x, y)
|
dragHandler = function(self, button, x, y)
|
||||||
if (isDragging) then
|
if (isDragging) then
|
||||||
local xO, yO = self.parent:getOffsetInternal()
|
local xO, yO = self.parent:getOffsetInternal()
|
||||||
@@ -915,7 +928,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
for _, value in rpairs(events["mouse_drag"][index]) do
|
for _, value in rpairs(events["mouse_drag"][index]) do
|
||||||
if (value.dragHandler ~= nil) then
|
if (value.dragHandler ~= nil) then
|
||||||
if (value:dragHandler(button, x, y)) then
|
if (value:dragHandler(button, x, y)) then
|
||||||
focusSystem(self)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -924,7 +936,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
focusSystem(self)
|
|
||||||
base.dragHandler(self, button, x, y)
|
base.dragHandler(self, button, x, y)
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
@@ -1036,6 +1048,24 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
blit = function (self, x, y, t, f, b)
|
||||||
|
local obx, oby = self:getAnchorPosition()
|
||||||
|
if (y >= 1) and (y <= self:getHeight()) then
|
||||||
|
local w = self:getWidth()
|
||||||
|
if (self.parent ~= nil) then
|
||||||
|
t = sub(t, max(1 - x + 1, 1), w - x + 1)
|
||||||
|
f = sub(f, max(1 - x + 1, 1), w - x + 1)
|
||||||
|
b = sub(b, max(1 - x + 1, 1), w - x + 1)
|
||||||
|
self.parent:blit(max(x + (obx - 1), obx), oby + y - 1, t, f, b)
|
||||||
|
else
|
||||||
|
t = sub(t, max(1 - x + 1, 1), max(w - x + 1,1))
|
||||||
|
f = sub(f, max(1 - x + 1, 1), max(w - x + 1,1))
|
||||||
|
b = sub(b, max(1 - x + 1, 1), max(w - x + 1,1))
|
||||||
|
basaltDraw.blit(max(x + (obx - 1), obx), oby + y - 1, t, f, b)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
drawBackgroundBox = function(self, x, y, width, height, bgCol)
|
drawBackgroundBox = function(self, x, y, width, height, bgCol)
|
||||||
local obx, oby = self:getAnchorPosition()
|
local obx, oby = self:getAnchorPosition()
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ return function(name)
|
|||||||
local ignOffset = false
|
local ignOffset = false
|
||||||
local isVisible = true
|
local isVisible = true
|
||||||
local initialized = false
|
local initialized = false
|
||||||
|
local isHovered = false
|
||||||
|
local isClicked = false
|
||||||
|
|
||||||
local shadow = false
|
local shadow = false
|
||||||
local borderColors = {
|
local borderColors = {
|
||||||
@@ -118,6 +120,8 @@ return function(name)
|
|||||||
if(xmlValue("onClickUp", data)~=nil)then self:generateXMLEventFunction(self.onClickUp, xmlValue("onClickUp", data)) end
|
if(xmlValue("onClickUp", data)~=nil)then self:generateXMLEventFunction(self.onClickUp, xmlValue("onClickUp", data)) end
|
||||||
if(xmlValue("onScroll", data)~=nil)then self:generateXMLEventFunction(self.onScroll, xmlValue("onScroll", data)) end
|
if(xmlValue("onScroll", data)~=nil)then self:generateXMLEventFunction(self.onScroll, xmlValue("onScroll", data)) end
|
||||||
if(xmlValue("onDrag", data)~=nil)then self:generateXMLEventFunction(self.onDrag, xmlValue("onDrag", data)) end
|
if(xmlValue("onDrag", data)~=nil)then self:generateXMLEventFunction(self.onDrag, xmlValue("onDrag", data)) end
|
||||||
|
if(xmlValue("onHover", data)~=nil)then self:generateXMLEventFunction(self.onHover, xmlValue("onHover", data)) end
|
||||||
|
if(xmlValue("onLeave", data)~=nil)then self:generateXMLEventFunction(self.onLeave, xmlValue("onLeave", data)) end
|
||||||
if(xmlValue("onKey", data)~=nil)then self:generateXMLEventFunction(self.onKey, xmlValue("onKey", data)) end
|
if(xmlValue("onKey", data)~=nil)then self:generateXMLEventFunction(self.onKey, xmlValue("onKey", data)) end
|
||||||
if(xmlValue("onKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onKeyUp, xmlValue("onKeyUp", data)) end
|
if(xmlValue("onKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onKeyUp, xmlValue("onKeyUp", data)) end
|
||||||
if(xmlValue("onChange", data)~=nil)then self:generateXMLEventFunction(self.onChange, xmlValue("onChange", data)) end
|
if(xmlValue("onChange", data)~=nil)then self:generateXMLEventFunction(self.onChange, xmlValue("onChange", data)) end
|
||||||
@@ -270,10 +274,10 @@ return function(name)
|
|||||||
|
|
||||||
setSize = function(self, width, height, rel)
|
setSize = function(self, width, height, rel)
|
||||||
if(type(width)=="number")then
|
if(type(width)=="number")then
|
||||||
self.width = rel and self.width+width or width
|
self.width = rel and self:getWidth()+width or width
|
||||||
end
|
end
|
||||||
if(type(height)=="number")then
|
if(type(height)=="number")then
|
||||||
self.height = rel and self.height+height or height
|
self.height = rel and self:getHeight()+height or height
|
||||||
end
|
end
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
if(type(width)=="string")then
|
if(type(width)=="string")then
|
||||||
@@ -417,46 +421,48 @@ return function(name)
|
|||||||
self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor)
|
self.parent:drawForegroundBox(x+1, y+h, w, 1, shadowColor)
|
||||||
self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor)
|
self.parent:drawForegroundBox(x+w, y+1, 1, h, shadowColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local bgCol = self.bgColor
|
||||||
if(borderColors["left"]~=false)then
|
if(borderColors["left"]~=false)then
|
||||||
self.parent:drawTextBox(x-1, y, 1, h, "\149")
|
self.parent:drawTextBox(x, y, 1, h, "\149")
|
||||||
self.parent:drawBackgroundBox(x-1, y, 1, h, self.bgColor)
|
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, 1, h, self.bgColor) end
|
||||||
self.parent:drawForegroundBox(x-1, y, 1, h, borderColors["left"])
|
self.parent:drawForegroundBox(x, y, 1, h, borderColors["left"])
|
||||||
end
|
|
||||||
if(borderColors["left"]~=false)and(borderColors["top"]~=false)then
|
|
||||||
self.parent:drawTextBox(x-1, y-1, 1, 1, "\151")
|
|
||||||
self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor)
|
|
||||||
self.parent:drawForegroundBox(x-1, y-1, 1, 1, borderColors["left"])
|
|
||||||
end
|
end
|
||||||
if(borderColors["top"]~=false)then
|
if(borderColors["top"]~=false)then
|
||||||
|
|
||||||
self.parent:drawTextBox(x, y-1, w, 1, "\131")
|
self.parent:drawTextBox(x, y, w, 1, "\131")
|
||||||
self.parent:drawBackgroundBox(x, y-1, w, 1, self.bgColor)
|
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, w, 1, self.bgColor) end
|
||||||
self.parent:drawForegroundBox(x, y-1, w, 1, borderColors["top"])
|
self.parent:drawForegroundBox(x, y, w, 1, borderColors["top"])
|
||||||
end
|
end
|
||||||
if(borderColors["top"]~=false)and(borderColors["right"]~=false)then
|
if(borderColors["left"]~=false)and(borderColors["top"]~=false)then
|
||||||
self.parent:drawTextBox(x+w, y-1, 1, 1, "\148")
|
self.parent:drawTextBox(x, y, 1, 1, "\151")
|
||||||
self.parent:drawForegroundBox(x+w, y-1, 1, 1, self.bgColor)
|
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, 1, 1, self.bgColor) end
|
||||||
self.parent:drawBackgroundBox(x+w, y-1, 1, 1, borderColors["right"])
|
self.parent:drawForegroundBox(x, y, 1, 1, borderColors["left"])
|
||||||
end
|
end
|
||||||
if(borderColors["right"]~=false)then
|
if(borderColors["right"]~=false)then
|
||||||
self.parent:drawTextBox(x+w, y, 1, h, "\149")
|
self.parent:drawTextBox(x+w-1, y, 1, h, "\149")
|
||||||
self.parent:drawForegroundBox(x+w, y, 1, h, self.bgColor)
|
if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y, 1, h, self.bgColor) end
|
||||||
self.parent:drawBackgroundBox(x+w, y, 1, h, borderColors["right"])
|
self.parent:drawBackgroundBox(x+w-1, y, 1, h, borderColors["right"])
|
||||||
end
|
|
||||||
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
|
end
|
||||||
if(borderColors["bottom"]~=false)then
|
if(borderColors["bottom"]~=false)then
|
||||||
self.parent:drawTextBox(x, y+h, w, 1, "\143")
|
self.parent:drawTextBox(x, y+h-1, w, 1, "\143")
|
||||||
self.parent:drawForegroundBox(x, y+h, w, 1, self.bgColor)
|
if(bgCol~=false)then self.parent:drawForegroundBox(x, y+h-1, w, 1, self.bgColor) end
|
||||||
self.parent:drawBackgroundBox(x, y+h, w, 1, borderColors["bottom"])
|
self.parent:drawBackgroundBox(x, y+h-1, w, 1, borderColors["bottom"])
|
||||||
|
end
|
||||||
|
if(borderColors["top"]~=false)and(borderColors["right"]~=false)then
|
||||||
|
self.parent:drawTextBox(x+w-1, y, 1, 1, "\148")
|
||||||
|
if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y, 1, 1, self.bgColor) end
|
||||||
|
self.parent:drawBackgroundBox(x+w-1, y, 1, 1, borderColors["right"])
|
||||||
|
end
|
||||||
|
if(borderColors["right"]~=false)and(borderColors["bottom"]~=false)then
|
||||||
|
self.parent:drawTextBox(x+w-1, y+h-1, 1, 1, "\133")
|
||||||
|
if(bgCol~=false)then self.parent:drawForegroundBox(x+w-1, y+h-1, 1, 1, self.bgColor) end
|
||||||
|
self.parent:drawBackgroundBox(x+w-1, y+h-1, 1, 1, borderColors["right"])
|
||||||
end
|
end
|
||||||
if(borderColors["bottom"]~=false)and(borderColors["left"]~=false)then
|
if(borderColors["bottom"]~=false)and(borderColors["left"]~=false)then
|
||||||
self.parent:drawTextBox(x-1, y+h, 1, 1, "\138")
|
self.parent:drawTextBox(x, y+h-1, 1, 1, "\138")
|
||||||
self.parent:drawForegroundBox(x-1, y+h, 1, 1, self.bgColor)
|
if(bgCol~=false)then self.parent:drawForegroundBox(x-1, y+h-1, 1, 1, self.bgColor) end
|
||||||
self.parent:drawBackgroundBox(x-1, y+h, 1, 1, borderColors["left"])
|
self.parent:drawBackgroundBox(x, y+h-1, 1, 1, borderColors["left"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
draw = false
|
draw = false
|
||||||
@@ -560,6 +566,8 @@ return function(name)
|
|||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
self.parent:addEvent("mouse_click", self)
|
self.parent:addEvent("mouse_click", self)
|
||||||
activeEvents["mouse_click"] = true
|
activeEvents["mouse_click"] = true
|
||||||
|
self.parent:addEvent("mouse_up", self)
|
||||||
|
activeEvents["mouse_up"] = true
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -571,26 +579,68 @@ return function(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
|
self.parent:addEvent("mouse_click", self)
|
||||||
|
activeEvents["mouse_click"] = true
|
||||||
self.parent:addEvent("mouse_up", self)
|
self.parent:addEvent("mouse_up", self)
|
||||||
activeEvents["mouse_up"] = true
|
activeEvents["mouse_up"] = true
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
onRelease = function(self, ...)
|
||||||
onScroll = 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("mouse_scroll", v)
|
self:registerEvent("mouse_release", v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
self.parent:addEvent("mouse_scroll", self)
|
self.parent:addEvent("mouse_click", self)
|
||||||
activeEvents["mouse_scroll"] = true
|
activeEvents["mouse_click"] = true
|
||||||
|
self.parent:addEvent("mouse_up", self)
|
||||||
|
activeEvents["mouse_up"] = true
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
onScroll = function(self, ...)
|
||||||
|
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
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
onHover = function(self, ...)
|
||||||
|
for _,v in pairs(table.pack(...))do
|
||||||
|
if(type(v)=="function")then
|
||||||
|
self:registerEvent("mouse_hover", v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(self.parent~=nil)then
|
||||||
|
self.parent:addEvent("mouse_move", self)
|
||||||
|
activeEvents["mouse_move"] = true
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
onLeave = function(self, ...)
|
||||||
|
for _,v in pairs(table.pack(...))do
|
||||||
|
if(type(v)=="function")then
|
||||||
|
self:registerEvent("mouse_leave", v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(self.parent~=nil)then
|
||||||
|
self.parent:addEvent("mouse_move", self)
|
||||||
|
activeEvents["mouse_move"] = true
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
onDrag = function(self, ...)
|
onDrag = 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
|
||||||
@@ -626,13 +676,25 @@ return function(name)
|
|||||||
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("key", v)
|
self:registerEvent("key", v)
|
||||||
self:registerEvent("char", v)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
self.parent:addEvent("key", self)
|
self.parent:addEvent("key", self)
|
||||||
self.parent:addEvent("char", self)
|
|
||||||
activeEvents["key"] = true
|
activeEvents["key"] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end;
|
||||||
|
|
||||||
|
onChar = function(self, ...)
|
||||||
|
if(isEnabled)then
|
||||||
|
for _,v in pairs(table.pack(...))do
|
||||||
|
if(type(v)=="function")then
|
||||||
|
self:registerEvent("char", v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(self.parent~=nil)then
|
||||||
|
self.parent:addEvent("char", self)
|
||||||
activeEvents["char"] = true
|
activeEvents["char"] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -717,7 +779,8 @@ return function(name)
|
|||||||
|
|
||||||
isCoordsInObject = function(self, x, y)
|
isCoordsInObject = function(self, x, y)
|
||||||
if(isVisible)and(isEnabled)then
|
if(isVisible)and(isEnabled)then
|
||||||
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
|
if(x==nil)or(y==nil)then return false end
|
||||||
|
local objX, objY = self:getAbsolutePosition()
|
||||||
local w, h = self:getSize()
|
local w, h = self:getSize()
|
||||||
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) then
|
if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) then
|
||||||
return true
|
return true
|
||||||
@@ -728,11 +791,13 @@ return function(name)
|
|||||||
|
|
||||||
mouseHandler = function(self, button, x, y, isMon)
|
mouseHandler = function(self, button, x, y, isMon)
|
||||||
if(self:isCoordsInObject(x, y))then
|
if(self:isCoordsInObject(x, y))then
|
||||||
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x, y, isMon)
|
local objX, objY = self:getAbsolutePosition()
|
||||||
|
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x - (objX-1), y - (objY-1), isMon)
|
||||||
if(val==false)then return false end
|
if(val==false)then return false end
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
self.parent:setFocusedObject(self)
|
self.parent:setFocusedObject(self)
|
||||||
end
|
end
|
||||||
|
isClicked = true
|
||||||
isDragging = true
|
isDragging = true
|
||||||
dragStartX, dragStartY = x, y
|
dragStartX, dragStartY = x, y
|
||||||
return true
|
return true
|
||||||
@@ -742,8 +807,14 @@ return function(name)
|
|||||||
|
|
||||||
mouseUpHandler = function(self, button, x, y)
|
mouseUpHandler = function(self, button, x, y)
|
||||||
isDragging = false
|
isDragging = false
|
||||||
|
if(isClicked)then
|
||||||
|
local objX, objY = self:getAbsolutePosition()
|
||||||
|
local val = eventSystem:sendEvent("mouse_release", self, "mouse_release", button, x - (objX-1), y - (objY-1))
|
||||||
|
isClicked = false
|
||||||
|
end
|
||||||
if(self:isCoordsInObject(x, y))then
|
if(self:isCoordsInObject(x, y))then
|
||||||
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x, y)
|
local objX, objY = self:getAbsolutePosition()
|
||||||
|
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x - (objX-1), y - (objY-1))
|
||||||
if(val==false)then return false end
|
if(val==false)then return false end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -752,16 +823,8 @@ return function(name)
|
|||||||
|
|
||||||
dragHandler = function(self, button, x, y)
|
dragHandler = function(self, button, x, y)
|
||||||
if(isDragging)then
|
if(isDragging)then
|
||||||
local xO, yO, parentX, parentY = 0, 0, 1, 1
|
local objX, objY = self:getAbsolutePosition()
|
||||||
if (self.parent ~= nil) then
|
local val = eventSystem:sendEvent("mouse_drag", self, "mouse_drag", button, x - (objX-1), y - (objY-1), dragStartX-x, dragStartY-y, x, y)
|
||||||
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
|
dragStartX, dragStartY = x, y
|
||||||
if(val~=nil)then return val end
|
if(val~=nil)then return val end
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
@@ -780,7 +843,8 @@ return function(name)
|
|||||||
|
|
||||||
scrollHandler = function(self, dir, x, y)
|
scrollHandler = function(self, dir, x, y)
|
||||||
if(self:isCoordsInObject(x, y))then
|
if(self:isCoordsInObject(x, y))then
|
||||||
local val = eventSystem:sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y)
|
local objX, objY = self:getAbsolutePosition()
|
||||||
|
local val = eventSystem:sendEvent("mouse_scroll", self, "mouse_scroll", dir, x - (objX-1), y - (objY-1))
|
||||||
if(val==false)then return false end
|
if(val==false)then return false end
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
self.parent:setFocusedObject(self)
|
self.parent:setFocusedObject(self)
|
||||||
@@ -790,6 +854,21 @@ return function(name)
|
|||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
hoverHandler = function(self, x, y, stopped)
|
||||||
|
if(self:isCoordsInObject(x, y))then
|
||||||
|
local val = eventSystem:sendEvent("mouse_hover", self, "mouse_hover", x, y, stopped)
|
||||||
|
if(val==false)then return false end
|
||||||
|
isHovered = true
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if(isHovered)then
|
||||||
|
local val = eventSystem:sendEvent("mouse_leave", self, "mouse_leave", x, y, stopped)
|
||||||
|
if(val==false)then return false end
|
||||||
|
isHovered = false
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
|
||||||
keyHandler = function(self, key, isHolding)
|
keyHandler = function(self, key, isHolding)
|
||||||
if(isEnabled)and(isVisible)then
|
if(isEnabled)and(isVisible)then
|
||||||
if (self:isFocused()) then
|
if (self:isFocused()) then
|
||||||
@@ -815,7 +894,7 @@ return function(name)
|
|||||||
charHandler = function(self, char)
|
charHandler = function(self, char)
|
||||||
if(isEnabled)and(isVisible)then
|
if(isEnabled)and(isVisible)then
|
||||||
if (self:isFocused()) then
|
if (self:isFocused()) then
|
||||||
local val = eventSystem:sendEvent("char", self, "char", char)
|
local val = eventSystem:sendEvent("char", self, "char", char)
|
||||||
if(val==false)then return false end
|
if(val==false)then return false end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -858,6 +937,7 @@ return function(name)
|
|||||||
initialized = true
|
initialized = true
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
146
Basalt/main.lua
146
Basalt/main.lua
@@ -6,11 +6,11 @@ local log = require("basaltLogs")
|
|||||||
local uuid = utils.uuid
|
local uuid = utils.uuid
|
||||||
local createText = utils.createText
|
local createText = utils.createText
|
||||||
local count = utils.tableCount
|
local count = utils.tableCount
|
||||||
|
local moveThrottle = 300
|
||||||
|
local dragThrottle = 50
|
||||||
|
|
||||||
local baseTerm = term.current()
|
local baseTerm = term.current()
|
||||||
local version = "1.6.2"
|
local version = "1.6.2"
|
||||||
local debugger = true
|
|
||||||
|
|
||||||
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
|
local projectDirectory = fs.getDir(table.pack(...)[2] or "")
|
||||||
|
|
||||||
@@ -29,6 +29,39 @@ local function stop()
|
|||||||
baseTerm.setCursorPos(1, 1)
|
baseTerm.setCursorPos(1, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local basaltError = function(errMsg)
|
||||||
|
baseTerm.clear()
|
||||||
|
baseTerm.setBackgroundColor(colors.black)
|
||||||
|
baseTerm.setTextColor(colors.red)
|
||||||
|
local w,h = baseTerm.getSize()
|
||||||
|
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 schedule(f)
|
||||||
|
assert(f~="function", "Schedule needs a function in order to work!")
|
||||||
|
return function(...)
|
||||||
|
local co = coroutine.create(f)
|
||||||
|
local ok, result = coroutine.resume(co, ...)
|
||||||
|
if(ok)then
|
||||||
|
table.insert(schedules, co)
|
||||||
|
else
|
||||||
|
basaltError(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local setVariable = function(name, var)
|
local setVariable = function(name, var)
|
||||||
variables[name] = var
|
variables[name] = var
|
||||||
end
|
end
|
||||||
@@ -94,6 +127,8 @@ local bInstance = {
|
|||||||
return baseTerm
|
return baseTerm
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
schedule = schedule,
|
||||||
|
|
||||||
stop = stop,
|
stop = stop,
|
||||||
newFrame = Frame,
|
newFrame = Frame,
|
||||||
|
|
||||||
@@ -102,26 +137,6 @@ local bInstance = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local basaltError = function(errMsg)
|
|
||||||
baseTerm.clear()
|
|
||||||
baseTerm.setBackgroundColor(colors.black)
|
|
||||||
baseTerm.setTextColor(colors.red)
|
|
||||||
local w,h = baseTerm.getSize()
|
|
||||||
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)
|
local function handleSchedules(event, p1, p2, p3, p4)
|
||||||
if(#schedules>0)then
|
if(#schedules>0)then
|
||||||
local finished = {}
|
local finished = {}
|
||||||
@@ -159,6 +174,40 @@ local function drawFrames()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local stopped, moveX, moveY = nil, nil, nil
|
||||||
|
local moveTimer = nil
|
||||||
|
local function mouseMoveEvent(stp, x, y)
|
||||||
|
stopped, moveX, moveY = stopped, x, y
|
||||||
|
if(moveTimer==nil)then
|
||||||
|
moveTimer = os.startTimer(moveThrottle/1000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function moveHandlerTimer()
|
||||||
|
moveTimer = nil
|
||||||
|
mainFrame:hoverHandler(moveX, moveY, stopped)
|
||||||
|
activeFrame = mainFrame
|
||||||
|
end
|
||||||
|
|
||||||
|
local btn, dragX, dragY = nil, nil, nil
|
||||||
|
local dragTimer = nil
|
||||||
|
local function dragHandlerTimer()
|
||||||
|
dragTimer = nil
|
||||||
|
mainFrame:dragHandler(btn, dragX, dragY)
|
||||||
|
activeFrame = mainFrame
|
||||||
|
end
|
||||||
|
|
||||||
|
local function mouseDragEvent(b, x, y)
|
||||||
|
btn, dragX, dragY = b, x, y
|
||||||
|
if(dragThrottle<50)then
|
||||||
|
dragHandlerTimer()
|
||||||
|
else
|
||||||
|
if(dragTimer==nil)then
|
||||||
|
dragTimer = os.startTimer(dragThrottle/1000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
||||||
if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end
|
if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end
|
||||||
if(mainFrame~=nil)then
|
if(mainFrame~=nil)then
|
||||||
@@ -166,16 +215,18 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
|||||||
mainFrame:mouseHandler(p1, p2, p3, false)
|
mainFrame:mouseHandler(p1, p2, p3, false)
|
||||||
activeFrame = mainFrame
|
activeFrame = mainFrame
|
||||||
elseif (event == "mouse_drag") then
|
elseif (event == "mouse_drag") then
|
||||||
mainFrame:dragHandler(p1, p2, p3, p4)
|
mouseDragEvent(p1, p2, p3)
|
||||||
activeFrame = mainFrame
|
|
||||||
elseif (event == "mouse_up") then
|
elseif (event == "mouse_up") then
|
||||||
mainFrame:mouseUpHandler(p1, p2, p3, p4)
|
mainFrame:mouseUpHandler(p1, p2, p3, p4)
|
||||||
activeFrame = mainFrame
|
activeFrame = mainFrame
|
||||||
elseif (event == "mouse_scroll") then
|
elseif (event == "mouse_scroll") then
|
||||||
mainFrame:scrollHandler(p1, p2, p3, p4)
|
mainFrame:scrollHandler(p1, p2, p3, p4)
|
||||||
activeFrame = mainFrame
|
activeFrame = mainFrame
|
||||||
|
elseif (event == "mouse_move") then
|
||||||
|
mouseMoveEvent(p1, p2, p3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if(event == "monitor_touch") then
|
if(event == "monitor_touch") then
|
||||||
if(monFrames[p1]~=nil)then
|
if(monFrames[p1]~=nil)then
|
||||||
monFrames[p1]:mouseHandler(1, p2, p3, true)
|
monFrames[p1]:mouseHandler(1, p2, p3, true)
|
||||||
@@ -213,9 +264,15 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
|||||||
if(updaterActive==false)then return end
|
if(updaterActive==false)then return end
|
||||||
end
|
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
|
if(event~="mouse_click")and(event~="mouse_up")and(event~="mouse_scroll")and(event~="mouse_drag")and(event~="mouse_move")and(event~="key")and(event~="key_up")and(event~="char")and(event~="terminate")then
|
||||||
for k, v in pairs(frames) do
|
if(event=="timer")and(p1==moveTimer)then
|
||||||
v:eventHandler(event, p1, p2, p3, p4)
|
moveHandlerTimer()
|
||||||
|
elseif(event=="timer")and(p1==dragTimer)then
|
||||||
|
dragHandlerTimer()
|
||||||
|
else
|
||||||
|
for k, v in pairs(frames) do
|
||||||
|
v:eventHandler(event, p1, p2, p3, p4)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
handleSchedules(event, p1, p2, p3, p4)
|
handleSchedules(event, p1, p2, p3, p4)
|
||||||
@@ -242,6 +299,28 @@ basalt = {
|
|||||||
log(...)
|
log(...)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
setMouseMoveThrottle = function(amount)
|
||||||
|
if(_HOST:find("CraftOS%-PC"))then
|
||||||
|
if(config.get("mouse_move_throttle")~=10)then config.set("mouse_move_throttle", 10) end
|
||||||
|
if(amount<100)then
|
||||||
|
moveThrottle = 100
|
||||||
|
else
|
||||||
|
moveThrottle = amount
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
|
||||||
|
setMouseDragThrottle = function(amount)
|
||||||
|
if(amount<=0)then
|
||||||
|
dragThrottle = 0
|
||||||
|
else
|
||||||
|
dragTimer = nil
|
||||||
|
dragThrottle = amount
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
autoUpdate = function(isActive)
|
autoUpdate = function(isActive)
|
||||||
updaterActive = isActive
|
updaterActive = isActive
|
||||||
if(isActive==nil)then updaterActive = true end
|
if(isActive==nil)then updaterActive = true end
|
||||||
@@ -304,18 +383,7 @@ basalt = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
schedule = function(f)
|
schedule = schedule,
|
||||||
assert(f~="function", "Schedule needs a function in order to work!")
|
|
||||||
return function(...)
|
|
||||||
local co = coroutine.create(f)
|
|
||||||
local ok, result = coroutine.resume(co, ...)
|
|
||||||
if(ok)then
|
|
||||||
table.insert(schedules, co)
|
|
||||||
else
|
|
||||||
basaltError(result)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
|
|
||||||
createFrame = function(name)
|
createFrame = function(name)
|
||||||
name = name or uuid()
|
name = name or uuid()
|
||||||
|
|||||||
4
Basalt/module.lua
Normal file
4
Basalt/module.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
return function(path)
|
||||||
|
local exists, content = pcall(require, path)
|
||||||
|
return exists and content or nil
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user