diff --git a/Basalt/Frame.lua b/Basalt/Frame.lua index 03fa110..1a45bc1 100644 --- a/Basalt/Frame.lua +++ b/Basalt/Frame.lua @@ -1,6 +1,6 @@ local Object = require("Object") local _OBJECTS = require("loadObjects") - +local log = require("basaltLogs") local BasaltDraw = require("basaltDraw") local utils = require("utils") local layout = require("layout") @@ -17,6 +17,8 @@ return function(name, parent, pTerm, basalt) local objects = {} local objZIndex = {} local object = {} + local events = {} + local eventZIndex = {} local variables = {} local theme = {} local dynamicValues = {} @@ -29,18 +31,21 @@ return function(name, parent, pTerm, basalt) local dragXOffset = 0 local dragYOffset = 0 local isScrollable = false - local minScroll = 0 - local maxScroll = 0 + local scrollAmount = 0 local mirrorActive = false local mirrorAttached = false local mirrorSide = "" local importantScroll = false + local isMovable = false + local isDragging =false local focusedOBjectCache local focusedObject local autoSize = true local autoScroll = true + local activeEvents = {} + base:setZIndex(10) local basaltDraw = BasaltDraw(termObject) @@ -137,11 +142,95 @@ return function(name, parent, pTerm, basalt) return obj end + local function removeEvents(self, obj) + for a, b in pairs(events) do + for c, d in pairs(b) do + for key, value in pairs(d) do + if (value == obj) then + table.remove(events[a][c], key) + if(self.parent~=nil)then + if(#events[a]<=0)then + self.parent:removeEvent(a, self) + end + end + end + end + end + end + end + local function removeObject(obj) for a, b in pairs(objects) do for key, value in pairs(b) do if (value == obj) then table.remove(objects[a], key) + removeEvents(object, obj) + return true; + end + end + end + return false + end + + local function getEvent(self, event, name) + for _, value in pairs(events[event]) do + for _, b in pairs(value) do + if (b:getName() == name) then + return b + end + end + end + 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 + if (getEvent(self, event, obj.name) ~= nil) then + return nil + end + if(self.parent~=nil)then + self.parent:addEvent(event, self) + end + activeEvents[event] = true + if (events[event][zIndex] == nil) then + for x = 1, #eventZIndex[event] + 1 do + if (eventZIndex[event][x] ~= nil) then + if (zIndex == eventZIndex[event][x]) then + break + end + if (zIndex > eventZIndex[event][x]) then + table.insert(eventZIndex[event], x, zIndex) + break + end + else + table.insert(eventZIndex[event], zIndex) + end + end + if (#eventZIndex[event] <= 0) then + table.insert(eventZIndex[event], zIndex) + end + events[event][zIndex] = {} + end + table.insert(events[event][zIndex], obj) + return obj + end + + local function removeEvent(self, event, obj) + for a, b in pairs(events[event]) do + for key, value in pairs(b) do + if (value == obj) then + 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) + end + end return true; end end @@ -242,9 +331,11 @@ return function(name, parent, pTerm, basalt) local function calculateMaxScroll(self) for _, value in pairs(objects) do for _, b in pairs(value) do - local h, y = b:getHeight(), b:getY() - if (h + y > maxScroll) then - maxScroll = math.max((h + y) - self:getHeight(), 0) + if(b.getHeight~=nil)and(b.getY~=nil)then + local h, y = b:getHeight(), b:getY() + if (h + y - self:getHeight() > scrollAmount) then + scrollAmount = max(h + y - self:getHeight(), 0) + end end end end @@ -257,7 +348,11 @@ return function(name, parent, pTerm, basalt) barTextcolor = colors.black, barText = "New Frame", barTextAlign = "left", - isMoveable = false, + + addEvent = addEvent, + removeEvent = removeEvent, + removeEvents = removeEvents, + getEvent = getEvent, newDynamicValue = newDynamicValue, recalculateDynamicValues = recalculateDynamicValues, @@ -332,7 +427,7 @@ return function(name, parent, pTerm, basalt) return xOffset, yOffset end; - getOffset = function(self) -- internal + getOffset = function(self) return xOffset < 0 and math.abs(xOffset) or -xOffset, yOffset < 0 and math.abs(yOffset) or -yOffset end; @@ -364,14 +459,27 @@ return function(name, parent, pTerm, basalt) return self end; - setMoveable = function(self, moveable) - self.isMoveable = moveable or not self.isMoveable - self:setVisualChanged() + setMovable = function(self, movable) + if(self.parent~=nil)then + isMovable = movable or not isMovable + self.parent:addEvent("mouse_click", self) + activeEvents["mouse_click"] = true + self.parent:addEvent("mouse_up", self) + 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; setScrollable = function(self, scrollable) isScrollable = scrollable and true or false + if(self.parent~=nil)then + self.parent:addEvent("mouse_scroll", self) + end + activeEvents["mouse_scroll"] = true return self end, @@ -380,23 +488,15 @@ return function(name, parent, pTerm, basalt) return self end, - setMaxScroll = function(self, max) - maxScroll = max or maxScroll + setScrollAmount = function(self, max) + scrollAmount = max or scrollAmount autoScroll = false return self end, - setMinScroll = function(self, min) - minScroll = min or minScroll - return self - end, - getMaxScroll = function(self) - return maxScroll - end, - - getMinScroll = function(self) - return minScroll + getScrollAmount = function(self) + return scrollAmount end, show = function(self) @@ -456,7 +556,7 @@ return function(name, parent, pTerm, basalt) setValuesByXMLData = function(self, data) base.setValuesByXMLData(self, data) - if(xmlValue("moveable", data)~=nil)then if(xmlValue("moveable", data))then self:setMoveable(true) end end + if(xmlValue("moveable", data)~=nil)then if(xmlValue("moveable", data))then self:setMovable(true) end end if(xmlValue("scrollable", data)~=nil)then if(xmlValue("scrollable", data))then self:setScrollable(true) end end if(xmlValue("monitor", data)~=nil)then self:setMonitor(xmlValue("monitor", data)):show() end if(xmlValue("mirror", data)~=nil)then self:setMirror(xmlValue("mirror", data)) end @@ -468,8 +568,7 @@ return function(name, parent, pTerm, basalt) if(xmlValue("layout", data)~=nil)then self:addLayout(xmlValue("layout", data)) 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("maxScroll", data)~=nil)then self:setMaxScroll(xmlValue("maxScroll", data)) end - if(xmlValue("minScroll", data)~=nil)then self:setMaxScroll(xmlValue("minScroll", 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() @@ -529,6 +628,7 @@ return function(name, parent, pTerm, basalt) if(peripheral.getType(side)=="monitor")then termObject = peripheral.wrap(side) monitorAttached = true + self:setSize(termObject.getSize()) end if(self.parent~=nil)then self.parent:removeObject(self) @@ -540,8 +640,8 @@ return function(name, parent, pTerm, basalt) if(basalt.getMonitorFrame(monSide)==self)then basalt.setMonitorFrame(monSide, nil) end + self:setSize(termObject.getSize()) end - self:setSize(termObject.getSize()) basaltDraw = BasaltDraw(termObject) monSide = side or nil return self; @@ -572,34 +672,12 @@ 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) - end - end; - - keyHandler = function(self, event, key) - if (focusedObject ~= nil) then - if(focusedObject~=self)then - if (focusedObject.keyHandler ~= nil) then - if (focusedObject:keyHandler(event, key)) then - return true - end - end - else - base.keyHandler(self, event, key) - end - end - return false - end; - - backgroundKeyHandler = function(self, event, key) - base.backgroundKeyHandler(self, event, key) - for _, index in pairs(objZIndex) do - if (objects[index] ~= nil) then - for _, value in pairs(objects[index]) do - if (value.backgroundKeyHandler ~= nil) then - value:backgroundKeyHandler(event, key) - end + for k,v in pairs(activeEvents)do + if(v)then + self.parent:addEvent(k, self) end end end @@ -653,75 +731,182 @@ return function(name, parent, pTerm, basalt) termObject.clear() basalt.stop() end - end; + end, - mouseHandler = function(self, event, button, x, y) - if (self.drag) then - local xO, yO = self.parent:getOffsetInternal() - xO = xO < 0 and math.abs(xO) or -xO - yO = yO < 0 and math.abs(yO) or -yO - if (event == "mouse_drag") then - local parentX = 1 - local parentY = 1 - if (self.parent ~= nil) then - parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition()) - end - self:setPosition(x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO) - end - if (event == "mouse_up") then - self.drag = false - end - return true - end - - local fx, fy = self:getAbsolutePosition(self:getAnchorPosition()) - local yOff = false - if(fy-1 == y)and(self:getBorder("top"))then - y = y+1 - yOff = true - end - - if (base.mouseHandler(self, event, button, x, y)) then - fx = fx + xOffset;fy = fy + yOffset; - if(isScrollable)and(importantScroll)then - if(event=="mouse_scroll")then - if(button>0)or(button<0)then - if(autoScroll)then calculateMaxScroll(self) end - yOffset = max(min(yOffset-button, -minScroll),-maxScroll) - end - end - end - for _, index in pairs(objZIndex) do - if (objects[index] ~= nil) then - for _, value in rpairs(objects[index]) do + mouseHandler = function(self, button, x, y) + if(base.mouseHandler(self, button, x, y))then + if(events["mouse_click"]~=nil)then + for _, index in ipairs(eventZIndex["mouse_click"]) do + if (events["mouse_click"][index] ~= nil) then + for _, value in rpairs(events["mouse_click"][index]) do if (value.mouseHandler ~= nil) then - if (value:mouseHandler(event, button, x, y)) then + if (value:mouseHandler(button, x, y)) then return true end end end end end - self:removeFocusedObject() - if (self.isMoveable) then - if (x >= fx) and (x <= fx + self:getWidth() - 1) and (y == fy) and (event == "mouse_click") then - self.drag = true - dragXOffset = fx - x - dragYOffset = yOff and 1 or 0 - end - end - if(isScrollable)and(not importantScroll)then - if(event=="mouse_scroll")then - if(button>0)or(button<0)then - if(autoScroll)then calculateMaxScroll(self) end - yOffset = max(min(yOffset-button, -minScroll),-maxScroll) - end - end + end + if (isMovable) then + local fx, fy = self:getAbsolutePosition(self:getAnchorPosition()) + if (x >= fx) and (x <= fx + self:getWidth() - 1) and (y == fy)then + isDragging = true + dragXOffset = fx - x + dragYOffset = yOff and 1 or 0 end + end + self:removeFocusedObject() return true end return false - end; + end, + + mouseUpHandler = function(self, button, x, y) + if (isDragging) then + isDragging = false + end + if(base.mouseUpHandler(self, button, x, y))then + if(events["mouse_up"]~=nil)then + for _, index in ipairs(eventZIndex["mouse_up"]) do + if (events["mouse_up"][index] ~= nil) then + for _, value in rpairs(events["mouse_up"][index]) do + if (value.mouseUpHandler ~= nil) then + if (value:mouseUpHandler(button, x, y)) then + return true + end + end + end + end + end + end + --self:removeFocusedObject() + return true + end + return false + end, + + 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 + for _, value in rpairs(events["mouse_scroll"][index]) do + if (value.scrollHandler ~= nil) then + if (value:scrollHandler(dir, x, y)) then + return true + end + end + end + end + end + end + if(isScrollable)and not(importantScroll)then + if(dir>0)or(dir<0)then + yOffset = max(min(yOffset-dir, 0),-scrollAmount) + end + end + return true + end + return false + end, + + dragHandler = function(self, button, x, y) + if (isDragging) then + local xO, yO = self.parent:getOffsetInternal() + xO = xO < 0 and math.abs(xO) or -xO + yO = yO < 0 and math.abs(yO) or -yO + local parentX = 1 + local parentY = 1 + if (self.parent ~= nil) then + parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition()) + end + self:setPosition(x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO) + return true + end + if(base.dragHandler(self, button, x, y))then + if(events["mouse_drag"]~=nil)then + for _, index in ipairs(eventZIndex["mouse_drag"]) do + if (events["mouse_drag"][index] ~= nil) then + for _, value in rpairs(events["mouse_drag"][index]) do + if (value.dragHandler ~= nil) then + if (value:dragHandler(button, x, y)) then + return true + end + end + end + end + end + end + return true + end + return false + end, + + keyHandler = function(self, key) + local val = self:getEventSystem():sendEvent("key", self, "key", key) + if(val==false)then return false end + if(events["key"]~=nil)then + for _, index in pairs(eventZIndex["key"]) do + if (events["key"][index] ~= nil) then + for _, value in rpairs(events["key"][index]) do + if (value.keyHandler ~= nil) then + if (value:keyHandler(key)) then + return true + end + end + end + end + end + end + return false + end, + + keyUpHandler = function(self, key) + local val = self:getEventSystem():sendEvent("key_up", self, "key_up", key) + if(val==false)then return false end + if(events["key_up"]~=nil)then + for _, index in pairs(eventZIndex["key_up"]) do + if (events["key_up"][index] ~= nil) then + for _, value in rpairs(events["key_up"][index]) do + if (value.keyUpHandler ~= nil) then + if (value:keyUpHandler(key)) then + return true + end + end + end + end + end + end + return false + end, + + charHandler = function(self, char) + local val = self:getEventSystem():sendEvent("char", self, "char", char) + if(val==false)then return false end + if(events["char"]~=nil)then + for _, index in pairs(eventZIndex["char"]) do + if (events["char"][index] ~= nil) then + for _, value in rpairs(events["char"][index]) do + if (value.charHandler ~= nil) then + if (value:charHandler(char)) then + return true + end + end + end + end + end + end + return false + end, setText = function(self, x, y, text) local obx, oby = self:getAnchorPosition() diff --git a/Basalt/Object.lua b/Basalt/Object.lua index 0720017..ffa02e4 100644 --- a/Basalt/Object.lua +++ b/Basalt/Object.lua @@ -27,6 +27,7 @@ return function(name) local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0 local visualsChanged = true + local activeEvents = {} local eventSystem = basaltEvent() @@ -117,8 +118,6 @@ return function(name) if(xmlValue("onEvent", data)~=nil)then self:generateXMLEventFunction(self.onEvent, xmlValue("onEvent", data)) end if(xmlValue("onGetFocus", data)~=nil)then self:generateXMLEventFunction(self.onGetFocus, xmlValue("onGetFocus", data)) end if(xmlValue("onLoseFocus", data)~=nil)then self:generateXMLEventFunction(self.onLoseFocus, xmlValue("onLoseFocus", data)) end - if(xmlValue("onBackgroundKey", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKey, xmlValue("onBackgroundKey", data)) end - if(xmlValue("onBackgroundKeyUp", data)~=nil)then self:generateXMLEventFunction(self.onBackgroundKeyUp, xmlValue("onBackgroundKeyUp", data)) end return self end, @@ -139,9 +138,18 @@ return function(name) if (self.parent ~= nil) then self.parent:removeObject(self) self.parent:addObject(self) + self:updateEventHandlers() end return self - end; + end, + + updateEventHandlers = function(self) + for k,v in pairs(activeEvents)do + if(v)then + self.parent:addEvent(k, self) + end + end + end, getZIndex = function(self) return zIndex; @@ -501,19 +509,31 @@ return function(name) end; onClick = function(self, ...) - for _,v in pairs(table.pack(...))do - if(type(v)=="function")then - self:registerEvent("mouse_click", v) - self:registerEvent("monitor_touch", v) + if(isEnabled)then + for _,v in pairs(table.pack(...))do + if(type(v)=="function")then + self:registerEvent("mouse_click", v) + self:registerEvent("monitor_touch", v) + end + end + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + activeEvents["mouse_click"] = true end end return self end; onClickUp = function(self, ...) - for _,v in pairs(table.pack(...))do - if(type(v)=="function")then - self:registerEvent("mouse_up", v) + if(isEnabled)then + for _,v in pairs(table.pack(...))do + if(type(v)=="function")then + self:registerEvent("mouse_up", v) + end + end + if(self.parent~=nil)then + self.parent:addEvent("mouse_up", self) + activeEvents["mouse_up"] = true end end return self @@ -521,9 +541,15 @@ return function(name) onScroll = function(self, ...) - for _,v in pairs(table.pack(...))do - if(type(v)=="function")then - self:registerEvent("mouse_scroll", v) + if(isEnabled)then + for _,v in pairs(table.pack(...))do + if(type(v)=="function")then + self:registerEvent("mouse_scroll", v) + end + end + if(self.parent~=nil)then + self.parent:addEvent("mouse_scroll", self) + activeEvents["mouse_scroll"] = true end end return self @@ -536,6 +562,10 @@ return function(name) self:registerEvent("mouse_drag", v) end end + if(self.parent~=nil)then + self.parent:addEvent("mouse_drag", self) + activeEvents["mouse_drag"] = true + end end return self end; @@ -550,10 +580,18 @@ return function(name) end; onKey = function(self, ...) - for _,v in pairs(table.pack(...))do - if(type(v)=="function")then - self:registerEvent("key", v) - self:registerEvent("char", v) + if(isEnabled)then + for _,v in pairs(table.pack(...))do + if(type(v)=="function")then + self:registerEvent("key", v) + self:registerEvent("char", v) + end + end + if(self.parent~=nil)then + self.parent:addEvent("key", self) + self.parent:addEvent("char", self) + activeEvents["key"] = true + activeEvents["char"] = true end end return self @@ -578,28 +616,15 @@ return function(name) end; onKeyUp = function(self, ...) - for _,v in pairs(table.pack(...))do - if(type(v)=="function")then - self:registerEvent("key_up", v) + if(isEnabled)then + for _,v in pairs(table.pack(...))do + if(type(v)=="function")then + self:registerEvent("key_up", v) + end end - end - return self - end; - - onBackgroundKey = function(self, ...) - for _,v in pairs(table.pack(...))do - if(type(v)=="function")then - self:registerEvent("background_key", v) - self:registerEvent("background_char", v) - end - end - return self - end; - - onBackgroundKeyUp = function(self, ...) - for _,v in pairs(table.pack(...))do - if(type(v)=="function")then - self:registerEvent("background_key_up", v) + if(self.parent~=nil)then + self.parent:addEvent("key_up", self) + activeEvents["key_up"] = true end end return self @@ -642,6 +667,95 @@ return function(name) return eventSystem:sendEvent(event, self, ...) end; + isCoordsInObject = function(self, x, y) + if(isVisible)and(isEnabled)then + local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) + local w, h = self:getSize() + if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) then + return true + end + end + return false + end, + + mouseHandler = function(self, button, x, y) + if(self:isCoordsInObject(x, y))then + local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x, y) + if(val==false)then return false end + if(self.parent~=nil)then + self.parent:setFocusedObject(self) + end + return true + end + return false + end, + + touchHandler = function(self, x, y) + if(self:isCoordsInObject(x, y))then + local val = eventSystem:sendEvent("monitor_touch", self, "monitor_touch", x, y) + if(val==false)then return false end + if(self.parent~=nil)then + self.parent:setFocusedObject(self) + end + return true + end + return false + end, + + mouseUpHandler = function(self, button, x, y) + isDragging = false + if(self:isCoordsInObject(x, y))then + local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x, y) + if(val==false)then return false end + if(self.parent~=nil)then + self.parent:setFocusedObject(self) + end + return true + end + return false + end, + + dragHandler = function(self, button, x, y) + if(isDragging)then + local xO, yO, parentX, parentY = 0, 0, 1, 1 + if (self.parent ~= nil) then + xO, yO = self.parent:getOffsetInternal() + xO = xO < 0 and math.abs(xO) or -xO + yO = yO < 0 and math.abs(yO) or -yO + parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition()) + end + local dX, dY = x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO + local val = eventSystem:sendEvent(event, self, event, button, dX, dY, dragStartX, dragStartY, x, y) + if(val==false)then return false end + return true + end + + if(self:isCoordsInObject(x, y))then + local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) + isDragging = true + dragStartX, dragStartY = x, y + dragXOffset, dragYOffset = objX - x, objY - y + if(self.parent~=nil)then + self.parent:setFocusedObject(self) + end + return true + end + return false + end, + + scrollHandler = function(self, dir, x, y) + if(self:isCoordsInObject(x, y))then + local val = eventSystem:sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y) + if(val==false)then return false end + if(self.parent~=nil)then + self.parent:setFocusedObject(self) + end + return true + end + return false + end, + + --[[ mouseHandler = function(self, event, button, x, y) if(isEnabled)and(isVisible)then local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) @@ -688,27 +802,41 @@ return function(name) end end return false - end; + end;]] - keyHandler = function(self, event, key) + keyHandler = function(self, key) if(isEnabled)then if (self:isFocused()) then - local val = eventSystem:sendEvent(event, self, event, key) - if(val~=nil)then return val end - return true + local val = eventSystem:sendEvent("key", self, "key", key) + if(val==false)then return false end + return true end end return false end; - backgroundKeyHandler = function(self, event, key) - if(isEnabled)then - local val = eventSystem:sendEvent("background_"..event, self, event, key) - if(val~=nil)then return val end + keyUpHandler = function(self, key) + if(isEnabled)then + if (self:isFocused()) then + local val = eventSystem:sendEvent("key_up", self, "key_up", key) + if(val==false)then return false end + return true + end end - return true + return false end; + charHandler = function(self, char) + if(isEnabled)then + if (self:isFocused()) then + local val = eventSystem:sendEvent("char", self, "char", char) + if(val==false)then return false end + return true + end + end + return false + end, + valueChangedHandler = function(self) eventSystem:sendEvent("value_changed", self) end; @@ -729,6 +857,15 @@ return function(name) return true end; + init = function(self) + if(self.parent~=nil)then + for k,v in pairs(activeEvents)do + if(v)then + self.parent:addEvent(k, self) + end + end + end + end } diff --git a/Basalt/libraries/basaltDraw.lua b/Basalt/basaltDraw.lua similarity index 100% rename from Basalt/libraries/basaltDraw.lua rename to Basalt/basaltDraw.lua diff --git a/Basalt/libraries/basaltEvent.lua b/Basalt/basaltEvent.lua similarity index 100% rename from Basalt/libraries/basaltEvent.lua rename to Basalt/basaltEvent.lua diff --git a/Basalt/libraries/basaltLogs.lua b/Basalt/libraries/basaltLogs.lua new file mode 100644 index 0000000..4edcd5a --- /dev/null +++ b/Basalt/libraries/basaltLogs.lua @@ -0,0 +1,20 @@ +local logDir = "" +local logFileName = "basaltLog.txt" + +local defaultLogType = "Debug" + +fs.delete(logDir~="" and logDir.."/"..logFileName or logFileName) + +local mt = { + __call = function(_,text, typ) + if(text==nil)then return end + local dirStr = logDir~="" and logDir.."/"..logFileName or logFileName + local handle = fs.open(dirStr, fs.exists(dirStr) and "a" or "w") + handle.writeLine("[Basalt]["..(typ and typ or defaultLogType).."]: "..tostring(text)) + handle.close() + end, +} + +return setmetatable({}, mt) + +--Work in progress \ No newline at end of file diff --git a/Basalt/libraries/logSystem.lua b/Basalt/libraries/logSystem.lua deleted file mode 100644 index b954707..0000000 --- a/Basalt/libraries/logSystem.lua +++ /dev/null @@ -1,16 +0,0 @@ -local logDir = "" -local logFileName = "log.txt" - -return { - setLogDir = function(dir) - logDir = dir - end, - - setLogFileName = function(name) - logFileName = name - end, - - __call = function() - --somelogs - end -} \ No newline at end of file diff --git a/Basalt/libraries/process.lua b/Basalt/libraries/process.lua index 63c459a..d2cf279 100644 --- a/Basalt/libraries/process.lua +++ b/Basalt/libraries/process.lua @@ -8,7 +8,7 @@ function process:new(path, window, ...) newP.window = window newP.processId = processId newP.coroutine = coroutine.create(function() - os.run({ }, path, table.unpack(args)) + os.run({ basaltProcess = true }, path, table.unpack(args)) end) processes[processId] = newP processId = processId + 1 diff --git a/Basalt/main.lua b/Basalt/main.lua index 422e6b7..11ae715 100644 --- a/Basalt/main.lua +++ b/Basalt/main.lua @@ -158,42 +158,47 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4) if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end if(mainFrame~=nil)then if (event == "mouse_click") then - mainFrame:mouseHandler(event, p1, p2, p3, p4) + mainFrame:mouseHandler(p1, p2, p3, p4) activeFrame = mainFrame elseif (event == "mouse_drag") then - mainFrame:mouseHandler(event, p1, p2, p3, p4) + mainFrame:dragHandler(p1, p2, p3, p4) activeFrame = mainFrame elseif (event == "mouse_up") then - mainFrame:mouseHandler(event, p1, p2, p3, p4) + mainFrame:mouseUpHandler(p1, p2, p3, p4) activeFrame = mainFrame elseif (event == "mouse_scroll") then - mainFrame:mouseHandler(event, p1, p2, p3, p4) + mainFrame:scrollHandler(p1, p2, p3, p4) activeFrame = mainFrame elseif (event == "monitor_touch") then if(monFrames[p1]~=nil)then - monFrames[p1]:mouseHandler(event, p1, p2, p3, p4) + monFrames[p1]:touchHandler(p1, p2, p3, p4) activeFrame = monFrames[p1] end end end - if(event == "key") or (event == "char") then + if(event == "char")then if(activeFrame~=nil)then - activeFrame:keyHandler(event, p1) - activeFrame:backgroundKeyHandler(event, p1) + activeFrame:charHandler(p1) end end - + if(event == "key_up")then + if(activeFrame~=nil)then + activeFrame:keyUpHandler(p1) + end + activeKey[p1] = false + end if(event == "key")then + if(activeFrame~=nil)then + activeFrame:keyHandler(p1) + end activeKey[p1] = true end - if(event == "key_up")then - activeKey[p1] = false - end - - for k, v in pairs(frames) do - v:eventHandler(event, p1, p2, p3, p4) + 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")then + for k, v in pairs(frames) do + v:eventHandler(event, p1, p2, p3, p4) + end end handleSchedules(event, p1, p2, p3, p4) drawFrames() diff --git a/Basalt/objects/Checkbox.lua b/Basalt/objects/Checkbox.lua index 15335b3..314aeaa 100644 --- a/Basalt/objects/Checkbox.lua +++ b/Basalt/objects/Checkbox.lua @@ -12,31 +12,36 @@ return function(name) base.width = 1 base.height = 1 - local object = { - symbol = "\42", + local symbol = "\42" - init = function(self) - self.bgColor = self.parent:getTheme("CheckboxBG") - self.fgColor = self.parent:getTheme("CheckboxText") - end, + local object = { getType = function(self) return objectType end; - mouseHandler = function(self, event, button, x, y) - if (base.mouseHandler(self, event, button, x, y)) then - if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then + setSymbol = function(self, sym) + symbol = sym + return self + end, + + mouseHandler = function(self, button, x, y) + if (base.mouseHandler(self, button, x, y)) then + if(button == 1)then if (self:getValue() ~= true) and (self:getValue() ~= false) then self:setValue(false) else self:setValue(not self:getValue()) end - end return true + end end return false - end; + end, + + touchHandler = function(self, x, y) + return self:mouseHandler(1, x, y) + end, setValuesByXMLData = function(self, data) base.setValuesByXMLData(self, data) @@ -54,7 +59,7 @@ return function(name) for n = 1, h do if (n == verticalAlign) then if (self:getValue() == true) then - self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self.symbol, w, "center"), self.bgColor, self.fgColor) + self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(symbol, w, "center"), self.bgColor, self.fgColor) else self.parent:writeText(obx, oby + (n - 1), utils.getTextHorizontalAlign(" ", w, "center"), self.bgColor, self.fgColor) end @@ -64,7 +69,12 @@ return function(name) self:setVisualChanged(false) end end; - + init = function(self) + base.init(self) + self.bgColor = self.parent:getTheme("CheckboxBG") + self.fgColor = self.parent:getTheme("CheckboxText") + self.parent:addEvent("mouse_click", self) + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Dropdown.lua b/Basalt/objects/Dropdown.lua index 3c288d6..5ba0f0d 100644 --- a/Basalt/objects/Dropdown.lua +++ b/Basalt/objects/Dropdown.lua @@ -26,12 +26,6 @@ return function(name) getType = function(self) return objectType end; - init = function(self) - self.bgColor = self.parent:getTheme("DropdownBG") - self.fgColor = self.parent:getTheme("DropdownText") - itemSelectedBG = self.parent:getTheme("SelectionBG") - itemSelectedFG = self.parent:getTheme("SelectionText") - end, setValuesByXMLData = function(self, data) base.setValuesByXMLData(self, data) @@ -51,6 +45,7 @@ return function(name) setOffset = function(self, yOff) yOffset = yOff + self:setVisualChanged() return self end; @@ -60,6 +55,7 @@ return function(name) addItem = function(self, text, bgCol, fgCol, ...) table.insert(list, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } }) + self:setVisualChanged() return self end; @@ -69,6 +65,7 @@ return function(name) removeItem = function(self, index) table.remove(list, index) + self:setVisualChanged() return self end; @@ -88,6 +85,7 @@ return function(name) clear = function(self) list = {} self:setValue({}) + self:setVisualChanged() return self end; @@ -98,11 +96,13 @@ return function(name) editItem = function(self, index, text, bgCol, fgCol, ...) table.remove(list, index) table.insert(list, index, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } }) + self:setVisualChanged() return self end; selectItem = function(self, index) self:setValue(list[index] or {}) + self:setVisualChanged() return self end; @@ -110,55 +110,90 @@ return function(name) itemSelectedBG = bgCol or self.bgColor itemSelectedFG = fgCol or self.fgColor selectionColorActive = active + self:setVisualChanged() return self end; setDropdownSize = function(self, width, height) dropdownW, dropdownH = width, height + self:setVisualChanged() return self - end; + end, - mouseHandler = function(self, event, button, x, y) + mouseHandler = function(self, button, x, y) if (isOpened) then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then - + if(button==1)then if (#list > 0) then for n = 1, dropdownH do if (list[n + yOffset] ~= nil) then if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then self:setValue(list[n + yOffset]) + self:setVisualChanged() + local val = self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", dir, x, y) + if(val==false)then return val end return true end end end end end + end + if (base.mouseHandler(self, button, x, y)) then + isOpened = (not isOpened) + self:setVisualChanged() + return true + else + if(isOpened)then + self:setVisualChanged() + isOpened = false + end + return false + end + end, - if (event == "mouse_scroll") then - yOffset = yOffset + button - if (yOffset < 0) then - yOffset = 0 - end - if (button == 1) then - if (#list > dropdownH) then - if (yOffset > #list - dropdownH) then - yOffset = #list - dropdownH + mouseUpHandler = function(self, button, x, y) + if (isOpened) then + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + if(button==1)then + if (#list > 0) then + for n = 1, dropdownH do + if (list[n + yOffset] ~= nil) then + if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then + isOpened = false + self:setVisualChanged() + local val = self:getEventSystem():sendEvent("mouse_up", self, "mouse_up", dir, x, y) + if(val==false)then return val end + return true + end end - else - yOffset = math.min(#list - 1, 0) end end - return true end + end + end, + + scrollHandler = function(self, dir, x, y) + if (isOpened)and(self:isFocused()) then + yOffset = yOffset + dir + if (yOffset < 0) then + yOffset = 0 + end + if (dir == 1) then + if (#list > dropdownH) then + if (yOffset > #list - dropdownH) then + yOffset = #list - dropdownH + end + else + yOffset = math.min(#list - 1, 0) + end + end + local val = self:getEventSystem():sendEvent("mouse_scroll", self, "mouse_scroll", dir, x, y) + if(val==false)then return val end self:setVisualChanged() + return true end - if (base.mouseHandler(self, event, button, x, y)) then - isOpened = true - else - isOpened = false - end - end; + end, draw = function(self) if (base.draw(self)) then @@ -186,9 +221,20 @@ return function(name) end end end - self:setVisualChanged(false) end - end; + end, + + init = function(self) + self.bgColor = self.parent:getTheme("DropdownBG") + self.fgColor = self.parent:getTheme("DropdownText") + itemSelectedBG = self.parent:getTheme("SelectionBG") + itemSelectedFG = self.parent:getTheme("SelectionText") + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_up", self) + self.parent:addEvent("mouse_scroll", self) + end + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Input.lua b/Basalt/objects/Input.lua index c476339..8fb5e28 100644 --- a/Basalt/objects/Input.lua +++ b/Basalt/objects/Input.lua @@ -24,10 +24,6 @@ return function(name) local internalValueChange = false local object = { - init = function(self) - self.bgColor = self.parent:getTheme("InputBG") - self.fgColor = self.parent:getTheme("InputFG") - end, getType = function(self) return objectType end; @@ -107,11 +103,10 @@ return function(name) end end; - keyHandler = function(self, event, key) - if (base.keyHandler(self, event, key)) then + keyHandler = function(self, key) + if (base.keyHandler(self, key)) then local w,h = self:getSize() internalValueChange = true - if (event == "key") then if (key == keys.backspace) then -- on backspace local text = tostring(base.getValue()) @@ -167,27 +162,43 @@ return function(name) wIndex = 1 end end - end + local obx, oby = self:getAnchorPosition() + local val = tostring(base.getValue()) + local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1) - if (event == "char") then - local text = base.getValue() - if (text:len() < inputLimit or inputLimit <= 0) then - if (inputType == "number") then - local cache = text - if (key == ".") or (tonumber(key) ~= nil) then - self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len())) - textX = textX + 1 - end - if (tonumber(base.getValue()) == nil) then - self:setValue(cache) - end - else - self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len())) + if (cursorX > self.x + w - 1) then + cursorX = self.x + w - 1 + end + if (self.parent ~= nil) then + self.parent:setCursor(true, obx + cursorX, oby+math.floor(h/2), self.fgColor) + end + internalValueChange = false + return true + end + return false + end, + + charHandler = function(self, char) + if (base.charHandler(self, char)) then + internalValueChange = true + local w,h = self:getSize() + local text = base.getValue() + if (text:len() < inputLimit or inputLimit <= 0) then + if (inputType == "number") then + local cache = text + if (char == ".") or (tonumber(char) ~= nil) then + self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len())) textX = textX + 1 end - if (textX >= w + wIndex) then - wIndex = wIndex + 1 + if (tonumber(base.getValue()) == nil) then + self:setValue(cache) end + else + self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len())) + textX = textX + 1 + end + if (textX >= w + wIndex) then + wIndex = wIndex + 1 end end local obx, oby = self:getAnchorPosition() @@ -201,18 +212,10 @@ return function(name) self.parent:setCursor(true, obx + cursorX, oby+math.floor(h/2), self.fgColor) end internalValueChange = false - end - end; - - mouseHandler = function(self, event, button, x, y) - if (base.mouseHandler(self, event, button, x, y)) then - if (event == "mouse_click") and (button == 1) then - - end return true end return false - end; + end, draw = function(self) if (base.draw(self)) then @@ -251,9 +254,18 @@ return function(name) end end end - self:setVisualChanged(false) end - end; + end, + + init = function(self) + self.bgColor = self.parent:getTheme("InputBG") + self.fgColor = self.parent:getTheme("InputText") + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("key", self) + self.parent:addEvent("char", self) + end + end, } return setmetatable(object, base) diff --git a/Basalt/objects/List.lua b/Basalt/objects/List.lua index f42c7fd..0f95dfe 100644 --- a/Basalt/objects/List.lua +++ b/Basalt/objects/List.lua @@ -18,12 +18,6 @@ return function(name) local scrollable = true local object = { - init = function(self) - self.bgColor = self.parent:getTheme("ListBG") - self.fgColor = self.parent:getTheme("ListText") - itemSelectedBG = self.parent:getTheme("SelectionBG") - itemSelectedFG = self.parent:getTheme("SelectionText") - end, getType = function(self) return objectType end; @@ -97,6 +91,7 @@ return function(name) setScrollable = function(self, scroll) scrollable = scroll + if(scroll==nil)then scrollable = true end return self end; @@ -116,29 +111,15 @@ return function(name) return self end, - mouseHandler = function(self, event, button, x, y) - local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - local w,h = self:getSize() - if (obx <= x) and (obx + w > x) and (oby <= y) and (oby + h > y) and (self:isVisible()) then - if (((event == "mouse_click") or (event == "mouse_drag"))and(button==1))or(event=="monitor_touch") then - if (#list > 0) then - for n = 1, h do - if (list[n + yOffset] ~= nil) then - if (obx <= x) and (obx + w > x) and (oby + n - 1 == y) then - self:setValue(list[n + yOffset]) - self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n + yOffset]) - end - end - end - end - end - - if (event == "mouse_scroll") and (scrollable) then - yOffset = yOffset + button + scrollHandler = function(self, dir, x, y) + if(base.scrollHandler(self, dir, x, y))then + if(scrollable)then + local w,h = self:getSize() + yOffset = yOffset + dir if (yOffset < 0) then yOffset = 0 end - if (button >= 1) then + if (dir >= 1) then if (#list > h) then if (yOffset > #list - h) then yOffset = #list - h @@ -151,10 +132,37 @@ return function(name) end end end - self:setVisualChanged() return true end - end; + return false + end, + + mouseHandler = function(self, button, x, y) + if(base.mouseHandler(self, button, x, y))then + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + local w,h = self:getSize() + if (#list > 0) then + for n = 1, h do + if (list[n + yOffset] ~= nil) then + if (obx <= x) and (obx + w > x) and (oby + n - 1 == y) then + self:setValue(list[n + yOffset]) + self:setVisualChanged() + end + end + end + end + return true + end + return false + end, + + dragHandler = function(self, button, x, y) + return self:mouseHandler(button, x, y) + end, + + touchHandler = function(self, x, y) + return self:mouseHandler(1, x, y) + end, draw = function(self) if (base.draw(self)) then @@ -181,6 +189,18 @@ return function(name) self:setVisualChanged(false) end end; + + init = function(self) + self.bgColor = self.parent:getTheme("ListBG") + self.fgColor = self.parent:getTheme("ListText") + itemSelectedBG = self.parent:getTheme("SelectionBG") + itemSelectedFG = self.parent:getTheme("SelectionText") + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_drag", self) + self.parent:addEvent("mouse_scroll", self) + end + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Menubar.lua b/Basalt/objects/Menubar.lua index 80dade1..403a61f 100644 --- a/Basalt/objects/Menubar.lua +++ b/Basalt/objects/Menubar.lua @@ -40,13 +40,6 @@ return function(name) end object = { - init = function(self) - self.bgColor = self.parent:getTheme("MenubarBG") - self.fgColor = self.parent:getTheme("MenubarText") - itemSelectedBG = self.parent:getTheme("SelectionBG") - itemSelectedFG = self.parent:getTheme("SelectionText") - end, - getType = function(self) return objectType end; @@ -154,45 +147,45 @@ return function(name) return self end; - mouseHandler = function(self, event, button, x, y) - if(base.mouseHandler(self, event, button, x, y))then + mouseHandler = function(self, button, x, y) + if(base.mouseHandler(self, button, x, y))then local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) local w,h = self:getSize() - if (objX <= x) and (objX + w > x) and (objY <= y) and (objY + h > y) and (self:isVisible()) then - if (self.parent ~= nil) then - self.parent:setFocusedObject(self) - end - if (event == "mouse_click") or (event == "monitor_touch") then - local xPos = 0 - for n = 1, #list do - if (list[n] ~= nil) then - if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then - self:setValue(list[n]) - self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n]) - end - xPos = xPos + list[n].text:len() + space * 2 + local xPos = 0 + for n = 1, #list do + if (list[n] ~= nil) then + if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then + self:setValue(list[n]) + self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n]) end - end - - end - if (event == "mouse_scroll") and (scrollable) then - itemOffset = itemOffset + button - if (itemOffset < 0) then - itemOffset = 0 - end - - local mScroll = maxScroll() - - if (itemOffset > mScroll) then - itemOffset = mScroll + xPos = xPos + list[n].text:len() + space * 2 end end - self:setVisualChanged(true) - return true - end + self:setVisualChanged() + return true end return false - end; + end, + + scrollHandler = function(self, dir, x, y) + if(base.scrollHandler(self, dir, x, y))then + if(scrollable)then + itemOffset = itemOffset + dir + if (itemOffset < 0) then + itemOffset = 0 + end + + local mScroll = maxScroll() + + if (itemOffset > mScroll) then + itemOffset = mScroll + end + self:setVisualChanged() + end + return true + end + return false + end, draw = function(self) if (base.draw(self)) then @@ -223,7 +216,19 @@ return function(name) end self:setVisualChanged(false) end - end; + end, + + init = function(self) + self.bgColor = self.parent:getTheme("MenubarBG") + self.fgColor = self.parent:getTheme("MenubarText") + itemSelectedBG = self.parent:getTheme("SelectionBG") + itemSelectedFG = self.parent:getTheme("SelectionText") + + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_scroll", self) + end + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Program.lua b/Basalt/objects/Program.lua index 92cc44c..97a6813 100644 --- a/Basalt/objects/Program.lua +++ b/Basalt/objects/Program.lua @@ -417,10 +417,43 @@ return function(name, parent) local paused = false local queuedEvent = {} + local function updateCursor(self) + local xCur, yCur = pWindow.getCursorPos() + local obx, oby = self:getAnchorPosition() + local w,h = self:getSize() + if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + h - 1) then + self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) + end + end + + local function mouseEvent(self, event, p1, x, y) + if (curProcess == nil) then + return false + end + if not (curProcess:isDead()) then + if not (paused) then + local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true)) + curProcess:resume(event, p1, x-absX+1, y-absY+1) + updateCursor(self) + end + end + end + + local function keyEvent(self, event, key) + if (curProcess == nil) then + return false + end + if not (curProcess:isDead()) then + if not (paused) then + if (self.draw) then + curProcess:resume(event, key) + updateCursor(self) + end + end + end + end + object = { - init = function(self) - self.bgColor = self.parent:getTheme("ProgramBG") - end, getType = function(self) return objectType end; @@ -484,6 +517,15 @@ return function(name, parent) pWindow.basalt_setVisible(true) curProcess:resume() paused = false + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_up", self) + self.parent:addEvent("mouse_drag", self) + self.parent:addEvent("mouse_scroll", self) + self.parent:addEvent("key", self) + self.parent:addEvent("key_up", self) + self.parent:addEvent("char", self) + end return self end; @@ -551,36 +593,61 @@ return function(name, parent) return self end; - mouseHandler = function(self, event, button, x, y) - if (base.mouseHandler(self, event, button, x, y)) then - if (curProcess == nil) then - return false - end - if not (curProcess:isDead()) then - if not (paused) then - local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true)) - curProcess:resume(event, button, x-absX+1, y-absY+1) - end - end + mouseHandler = function(self, button, x, y) + if (base.mouseHandler(self, button, x, y)) then + mouseEvent(self, "mouse_click", button, x, y) return true end - end; + return false + end, - keyHandler = function(self, event, key) - base.keyHandler(self, event, key) - if (self:isFocused()) then - if (curProcess == nil) then - return false - end - if not (curProcess:isDead()) then - if not (paused) then - if (self.draw) then - curProcess:resume(event, key) - end - end - end + mouseUpHandler = function(self, button, x, y) + if (base.mouseUpHandler(self, button, x, y)) then + mouseEvent(self, "mouse_up", button, x, y) + return true end - end; + return false + end, + + scrollHandler = function(self, dir, x, y) + if (base.scrollHandler(self, dir, x, y)) then + mouseEvent(self, "mouse_scroll", dir, x, y) + return true + end + return false + end, + + dragHandler = function(self, button, x, y) + if (base.dragHandler(self, button, x, y)) then + mouseEvent(self, "mouse_drag", button, x, y) + return true + end + return false + end, + + keyHandler = function(self, key) + if(base.keyHandler(self, key))then + keyEvent(self, "key", key) + return true + end + return false + end, + + keyUpHandler = function(self, key) + if(base.keyUpHandler(self, key))then + keyEvent(self, "key_up", key) + return true + end + return false + end, + + charHandler = function(self, char) + if(base.charHandler(self, char))then + keyEvent(self, "char", char) + return true + end + return false + end, getFocusHandler = function(self) base.getFocusHandler(self) @@ -619,7 +686,7 @@ return function(name, parent) end if not (curProcess:isDead()) then if not (paused) then - if (event ~= "mouse_click") and (event ~= "monitor_touch") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then + if(event ~= "terminate") then curProcess:resume(event, p1, p2, p3, p4) end if (self:isFocused()) then @@ -657,7 +724,12 @@ return function(name, parent) end self:setVisualChanged(false) end - end; + end, + + init = function(self) + self.bgColor = self.parent:getTheme("ProgramBG") + + end, } diff --git a/Basalt/objects/Radio.lua b/Basalt/objects/Radio.lua index 0b5f8e6..c6bbe88 100644 --- a/Basalt/objects/Radio.lua +++ b/Basalt/objects/Radio.lua @@ -20,16 +20,6 @@ return function(name) local align = "left" local object = { - - init = function(self) - self.bgColor = self.parent:getTheme("MenubarBG") - self.fgColor = self.parent:getTheme("MenubarFG") - itemSelectedBG = self.parent:getTheme("SelectionBG") - itemSelectedFG = self.parent:getTheme("SelectionText") - boxSelectedBG = self.parent:getTheme("MenubarBG") - boxSelectedFG = self.parent:getTheme("MenubarText") - end, - getType = function(self) return objectType end; @@ -118,20 +108,19 @@ return function(name) return self end; - mouseHandler = function(self, event, button, x, y) - local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if ((event == "mouse_click")and(button==1))or(event=="monitor_touch") then - if (#list > 0) then - for _, value in pairs(list) do - if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 2 >= x) and (oby + value.y - 1 == y) then - self:setValue(value) - if (self.parent ~= nil) then - self.parent:setFocusedObject(self) - end - self:getEventSystem():sendEvent(event, self, event, button, x, y) - self:setVisualChanged() - return true + mouseHandler = function(self, button, x, y) + if (#list > 0) then + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + for _, value in pairs(list) do + if (obx + value.x - 1 <= x) and (obx + value.x - 1 + value.text:len() + 1 >= x) and (oby + value.y - 1 == y) then + self:setValue(value) + local val = self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", button, x, y) + if(val==false)then return val end + if(self.parent~=nil)then + self.parent:setFocusedObject(self) end + self:setVisualChanged() + return true end end end @@ -157,6 +146,18 @@ return function(name) self:setVisualChanged(false) end end; + + init = function(self) + self.bgColor = self.parent:getTheme("MenubarBG") + self.fgColor = self.parent:getTheme("MenubarFG") + itemSelectedBG = self.parent:getTheme("SelectionBG") + itemSelectedFG = self.parent:getTheme("SelectionText") + boxSelectedBG = self.parent:getTheme("MenubarBG") + boxSelectedFG = self.parent:getTheme("MenubarText") + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + end + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Scrollbar.lua b/Basalt/objects/Scrollbar.lua index e03e4d4..24ee508 100644 --- a/Basalt/objects/Scrollbar.lua +++ b/Basalt/objects/Scrollbar.lua @@ -18,12 +18,30 @@ return function(name) local index = 1 local symbolSize = 1 + local function mouseEvent(self, button, x, y) + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + local w,h = self:getSize() + if (barType == "horizontal") then + for _index = 0, w do + if (obx + _index == x) and (oby <= y) and (oby + h > y) then + index = math.min(_index + 1, w - (symbolSize - 1)) + self:setValue(maxValue / w * (index)) + self:setVisualChanged() + end + end + end + if (barType == "vertical") then + for _index = 0, h do + if (oby + _index == y) and (obx <= x) and (obx + w > x) then + index = math.min(_index + 1, h - (symbolSize - 1)) + self:setValue(maxValue / h * (index)) + self:setVisualChanged() + end + end + end + end + local object = { - init = function(self) - self.bgColor = self.parent:getTheme("ScrollbarBG") - self.fgColor = self.parent:getTheme("ScrollbarText") - symbolColor = self.parent:getTheme("ScrollbarSymbolColor") - end, getType = function(self) return objectType end; @@ -94,41 +112,33 @@ return function(name) return self end; - mouseHandler = function(self, event, button, x, y) - if (base.mouseHandler(self, event, button, x, y)) then - local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - local w,h = self:getSize() - if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then - if (barType == "horizontal") then - for _index = 0, w do - if (obx + _index == x) and (oby <= y) and (oby + h > y) then - index = math.min(_index + 1, w - (symbolSize - 1)) - self:setValue(maxValue / w * (index)) - self:setVisualChanged() - end - end - end - if (barType == "vertical") then - for _index = 0, h do - if (oby + _index == y) and (obx <= x) and (obx + w > x) then - index = math.min(_index + 1, h - (symbolSize - 1)) - self:setValue(maxValue / h * (index)) - self:setVisualChanged() - end - end - end - end - if (event == "mouse_scroll") then - index = index + button - if (index < 1) then - index = 1 - end - index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) - self:setValue(maxValue / (barType == "vertical" and h or w) * index) - end + mouseHandler = function(self, button, x, y) + if (base.mouseHandler(self, button, x, y)) then + mouseEvent(self, button, x, y) return true end - end; + return false + end, + + dragHandler = function(self, button, x, y) + if (base.dragHandler(self, button, x, y)) then + mouseEvent(self, button, x, y) + return true + end + return false + end, + + scrollHandler = function(self, dir, x, y) + if(base.scrollHandler(self, dir, x, y))then + local w,h = self:getSize() + index = index + dir + if (index < 1) then + index = 1 + end + index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) + self:setValue(maxValue / (barType == "vertical" and h or w) * index) + end + end, draw = function(self) if (base.draw(self)) then @@ -155,9 +165,19 @@ return function(name) end end end - self:setVisualChanged(false) end - end; + end, + + init = function(self) + self.bgColor = self.parent:getTheme("ScrollbarBG") + self.fgColor = self.parent:getTheme("ScrollbarText") + symbolColor = self.parent:getTheme("ScrollbarSymbolColor") + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_drag", self) + self.parent:addEvent("mouse_scroll", self) + end + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Slider.lua b/Basalt/objects/Slider.lua index f2b4499..338b408 100644 --- a/Basalt/objects/Slider.lua +++ b/Basalt/objects/Slider.lua @@ -17,12 +17,30 @@ return function(name) local index = 1 local symbolSize = 1 + local function mouseEvent(self, button, x, y) + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + local w,h = self:getSize() + if (barType == "horizontal") then + for _index = 0, w do + if (obx + _index == x) and (oby <= y) and (oby + h > y) then + index = math.min(_index + 1, w - (symbolSize - 1)) + self:setValue(maxValue / w * (index)) + self:setVisualChanged() + end + end + end + if (barType == "vertical") then + for _index = 0, h do + if (oby + _index == y) and (obx <= x) and (obx + w > x) then + index = math.min(_index + 1, h - (symbolSize - 1)) + self:setValue(maxValue / h * (index)) + self:setVisualChanged() + end + end + end + end + local object = { - init = function(self) - self.bgColor = self.parent:getTheme("SliderBG") - self.fgColor = self.parent:getTheme("SliderText") - symbolColor = self.parent:getTheme("SliderSymbolColor") - end, getType = function(self) return objectType end; @@ -92,41 +110,33 @@ return function(name) return self end; - mouseHandler = function(self, event, button, x, y) - if (base.mouseHandler(self, event, button, x, y)) then - local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - local w,h = self:getSize() - if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then - if (barType == "horizontal") then - for _index = 0, w do - if (obx + _index == x) and (oby <= y) and (oby + h > y) then - index = math.min(_index + 1, w - (symbolSize - 1)) - self:setValue(maxValue / w * (index)) - self:setVisualChanged() - end - end - end - if (barType == "vertical") then - for _index = 0, h do - if (oby + _index == y) and (obx <= x) and (obx + w > x) then - index = math.min(_index + 1, h - (symbolSize - 1)) - self:setValue(maxValue / h * (index)) - self:setVisualChanged() - end - end - end - end - if (event == "mouse_scroll") then - index = index + button - if (index < 1) then - index = 1 - end - index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) - self:setValue(maxValue / (barType == "vertical" and h or w) * index) - end + mouseHandler = function(self, button, x, y) + if (base.mouseHandler(self, button, x, y)) then + mouseEvent(self, button, x, y) return true end - end; + return false + end, + + dragHandler = function(self, button, x, y) + if (base.dragHandler(self, button, x, y)) then + mouseEvent(self, button, x, y) + return true + end + return false + end, + + scrollHandler = function(self, dir, x, y) + if(base.scrollHandler(self, dir, x, y))then + local w,h = self:getSize() + index = index + dir + if (index < 1) then + index = 1 + end + index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1)) + self:setValue(maxValue / (barType == "vertical" and h or w) * index) + end + end, draw = function(self) if (base.draw(self)) then @@ -154,9 +164,19 @@ return function(name) end end end - self:setVisualChanged(false) end - end; + end, + + init = function(self) + self.bgColor = self.parent:getTheme("SliderBG") + self.fgColor = self.parent:getTheme("SliderText") + symbolColor = self.parent:getTheme("SliderSymbolColor") + if(self.parent~=nil)then + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_drag", self) + self.parent:addEvent("mouse_scroll", self) + end + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Switch.lua b/Basalt/objects/Switch.lua index 5d0aaed..b589832 100644 --- a/Basalt/objects/Switch.lua +++ b/Basalt/objects/Switch.lua @@ -17,13 +17,6 @@ return function(name) local activeBG = colors.green local object = { - init = function(self) - self.bgColor = self.parent:getTheme("SwitchBG") - self.fgColor = self.parent:getTheme("SwitchText") - bgSymbol = self.parent:getTheme("SwitchBGSymbol") - inactiveBG = self.parent:getTheme("SwitchInactive") - activeBG = self.parent:getTheme("SwitchActive") - end, getType = function(self) return objectType end; @@ -54,12 +47,10 @@ return function(name) end, - mouseHandler = function(self, event, button, x, y) - if (base.mouseHandler(self, event, button, x, y)) then + mouseHandler = function(self, button, x, y) + if (base.mouseHandler(self, button, x, y)) then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if ((event == "mouse_click") and (button == 1))or(event=="monitor_touch") then - self:setValue(not self:getValue()) - end + self:setValue(not self:getValue()) return true end end; @@ -80,7 +71,16 @@ return function(name) end self:setVisualChanged(false) end - end; + end, + + init = function(self) + self.bgColor = self.parent:getTheme("SwitchBG") + self.fgColor = self.parent:getTheme("SwitchText") + bgSymbol = self.parent:getTheme("SwitchBGSymbol") + inactiveBG = self.parent:getTheme("SwitchInactive") + activeBG = self.parent:getTheme("SwitchActive") + self.parent:addEvent("mouse_click", self) + end, } return setmetatable(object, base) diff --git a/Basalt/objects/Textfield.lua b/Basalt/objects/Textfield.lua index 19dbc76..0710052 100644 --- a/Basalt/objects/Textfield.lua +++ b/Basalt/objects/Textfield.lua @@ -74,10 +74,6 @@ return function(name) end local object = { - init = function(self) - self.bgColor = self.parent:getTheme("TextfieldBG") - self.fgColor = self.parent:getTheme("TextfieldText") - end, getType = function(self) return objectType end; @@ -244,11 +240,10 @@ return function(name) end end; - keyHandler = function(self, event, key) + keyHandler = function(self, key) if (base.keyHandler(self, event, key)) then local obx, oby = self:getAnchorPosition() local w,h = self:getSize() - if (event == "key") then if (key == keys.backspace) then -- on backspace if (lines[textY] == "") then @@ -361,7 +356,14 @@ return function(name) if (textX > lines[textY]:len() + 1) then textX = lines[textY]:len() + 1 end - + if (wIndex > 1) then + if (textX < wIndex) then + wIndex = textX - w + 1 + if (wIndex < 1) then + wIndex = 1 + end + end + end if (textY >= hIndex + h) then hIndex = hIndex + 1 end @@ -411,19 +413,6 @@ return function(name) wIndex = 1 end end - end - - if (event == "char") then - lines[textY] = lines[textY]:sub(1, textX - 1) .. key .. lines[textY]:sub(textX, lines[textY]:len()) - fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor] .. fgLines[textY]:sub(textX, fgLines[textY]:len()) - bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor] .. bgLines[textY]:sub(textX, bgLines[textY]:len()) - textX = textX + 1 - if (textX >= w + wIndex) then - wIndex = wIndex + 1 - end - updateColors(self) - self:setValue("") - end local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1) if (cursorX > self.x + w - 1) then @@ -436,14 +425,90 @@ return function(name) self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor) return true end - end; + end, - mouseHandler = function(self, event, button, x, y) - if (base.mouseHandler(self, event, button, x, y)) then + charHandler = function(self, char) + if(base.charHandler(self, char))then + local obx, oby = self:getAnchorPosition() + local w,h = self:getSize() + lines[textY] = lines[textY]:sub(1, textX - 1) .. char .. lines[textY]:sub(textX, lines[textY]:len()) + fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. tHex[self.fgColor] .. fgLines[textY]:sub(textX, fgLines[textY]:len()) + bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. tHex[self.bgColor] .. bgLines[textY]:sub(textX, bgLines[textY]:len()) + textX = textX + 1 + if (textX >= w + wIndex) then + wIndex = wIndex + 1 + end + updateColors(self) + self:setValue("") + + local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1) + if (cursorX > self.x + w - 1) then + cursorX = self.x + w - 1 + end + local cursorY = (textY - hIndex < h and textY - hIndex or textY - hIndex - 1) + if (cursorX < 1) then + cursorX = 0 + end + self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor) + return true + end + end, + + dragHandler = function(self, button, x, y) + if (base.dragHandler(self, button, x, y)) then + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + local anchx, anchy = self:getAnchorPosition() + if (lines[y - oby + hIndex] ~= nil) then + textX = x - obx + wIndex + textY = y - oby + hIndex + if (textX > lines[textY]:len()) then + textX = lines[textY]:len() + 1 + end + if (textX < wIndex) then + wIndex = textX - 1 + if (wIndex < 1) then + wIndex = 1 + end + end + if (self.parent ~= nil) then + self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor) + end + end + self:setVisualChanged() + return true + end + end, + + scrollHandler = function(self, dir, x, y) + if (base.scrollHandler(self, dir, x, y)) then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local anchx, anchy = self:getAnchorPosition() local w,h = self:getSize() - if (event == "mouse_click")or(event=="monitor_touch") then + hIndex = hIndex + dir + if (hIndex > #lines - (h - 1)) then + hIndex = #lines - (h - 1) + end + + if (hIndex < 1) then + hIndex = 1 + end + + if (self.parent ~= nil) then + if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h) then + self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor) + else + self.parent:setCursor(false) + end + end + self:setVisualChanged() + return true + end + end, + + mouseHandler = function(self, button, x, y) + if (base.mouseHandler(self, button, x, y)) then + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + local anchx, anchy = self:getAnchorPosition() if (lines[y - oby + hIndex] ~= nil) then textX = x - obx + wIndex textY = y - oby + hIndex @@ -460,44 +525,6 @@ return function(name) self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor) end end - end - if (event == "mouse_drag") then - if (lines[y - oby + hIndex] ~= nil) then - textX = x - obx + wIndex - textY = y - oby + hIndex - if (textX > lines[textY]:len()) then - textX = lines[textY]:len() + 1 - end - if (textX < wIndex) then - wIndex = textX - 1 - if (wIndex < 1) then - wIndex = 1 - end - end - if (self.parent ~= nil) then - self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor) - end - end - end - - if (event == "mouse_scroll") then - hIndex = hIndex + button - if (hIndex > #lines - (h - 1)) then - hIndex = #lines - (h - 1) - end - - if (hIndex < 1) then - hIndex = 1 - end - - if (self.parent ~= nil) then - if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h) then - self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor) - else - self.parent:setCursor(false) - end - end - end self:setVisualChanged() return true end @@ -540,7 +567,17 @@ return function(name) end self:setVisualChanged(false) end - end; + end, + + init = function(self) + self.bgColor = self.parent:getTheme("TextfieldBG") + self.fgColor = self.parent:getTheme("TextfieldText") + self.parent:addEvent("mouse_click", self) + self.parent:addEvent("mouse_scroll", self) + self.parent:addEvent("mouse_drag", self) + self.parent:addEvent("key", self) + self.parent:addEvent("char", self) + end, } return setmetatable(object, base) diff --git a/Basalt/libraries/tHex.lua b/Basalt/tHex.lua similarity index 100% rename from Basalt/libraries/tHex.lua rename to Basalt/tHex.lua diff --git a/Basalt/libraries/utils.lua b/Basalt/utils.lua similarity index 100% rename from Basalt/libraries/utils.lua rename to Basalt/utils.lua diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..12a654e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +# Changelog + +#### v. 1.5: +- You can now mirror a frame to a monitor by using :setMirror(side) +- with dynamic values you are able to use percentage values and even functions which get called everytime we need the size of that object +- XML got added to make design and logic seperate (you don't have to) - you are now able to use xml to create your UI design. +- Animations are now more advanced and provide many features to do cool stuff. They are also very easy to use now! +- Also some smaller bugfixes +- new bugs to explore +- fixed monitor support +- added :setIndex() for scrollbars +- added dynamic value system (not fully done) +- reworked the filesystem, now we use require instead of loadfile +- from now on the single file will be complied on the end users computer +- prepared everything for an advanced installer + +#### v. 1: +- created Basalt +- added many objects (buttons, checkbox, labels, programs, switch, radio, lists, dropdowns, input, textfields, images, menubar, animations, threads, timers, progressbar, scrollbar, slider, pane) +- added bigfont +- added blittle +- added coroutine management +- added advanced event system diff --git a/README.md b/README.md index 51b0ba9..c5adb25 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,15 @@ # Basalt - A UI Framework for CC:Tweaked +![GitHub Repo stars](https://img.shields.io/github/stars/Pyroxenium/Basalt?style=for-the-badge) +![GitHub commit activity](https://img.shields.io/github/commit-activity/y/Pyroxenium/Basalt?style=for-the-badge) +![GitHub Repo stars](https://img.shields.io/badge/Made%20for-CC%3AT-orange?style=for-the-badge) +![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/Pyroxenium/Basalt?style=for-the-badge) +[![Discord](https://img.shields.io/discord/976905222251233320?label=Discord&style=for-the-badge)](https://discord.gg/yNNnmBVBpE) -## Important Notice -#### Basalt has moved! We are now located at [Pyroxenium](https://github.com/Pyroxenium), please make sure to update your previous GitHub links, as they are now out of date. We apologize for any inconvenience. +Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://www.curseforge.com/minecraft/mc-mods/cc-tweaked).
+**Note:** Basalt is still under developement and you may find bugs! -Basalt is still under developement and you may find bugs! - -## Information - -Check out the [wiki](https://basalt.madefor.cc/) for information
-If you have questions, feel free to join the discord server: [https://discord.gg/yM7kndJdJJ](https://discord.gg/yM7kndJdJJ) - -## Changelogs -From now on we will add changes: - -#### Version 4: -- You can now mirror a frame to a monitor by using :setMirror(side) -- with dynamic values you are able to use percentage values and even functions which get called everytime we need the size of that object -- XML got added to make design and logic seperate (you don't have to) - you are now able to use xml to create your UI design. -- Animations are now more advanced and provide many features to do cool stuff. They are also very easy to use now! -- Also some smaller bugfixes -- new bugs to explore - -#### Version 3: -- fixed monitor support -- added :setIndex() for scrollbars -- added dynamic value system (not fully done) - -#### Version 2: -Note: You won't get any changes for now, so don't redownload the project! (: -- reworked the filesystem, now we use require instead of loadfile -- from now on the single file will be complied on the end users computer -- prepared everything for an advanced installer - -#### Version 1: -- created Basalt -- added many objects (buttons, checkbox, labels, programs, switch, radio, lists, dropdowns, input, textfields, images, menubar, animations, threads, timers, progressbar, scrollbar, slider, pane) -- added bigfont -- added blittle -- added coroutine management -- added advanced event system +Check out the [wiki](https://basalt.madefor.cc/) for more information.
+If you have questions, feel free to join the discord server: [https://discord.gg/yNNnmBVBpE](https://discord.gg/yNNnmBVBpE). +## Demo + \ No newline at end of file diff --git a/basaltPackageManager.lua b/basaltPackageManager.lua index 470bcaf..fea6e01 100644 --- a/basaltPackageManager.lua +++ b/basaltPackageManager.lua @@ -1062,7 +1062,7 @@ local animTime = 0.2 local animFrames = 8 local function download(url, file) -local httpReq = http.get(url) +local httpReq = http.get(url, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY}) if(httpReq~=nil)then local content = httpReq.readAll() if not content then @@ -1076,7 +1076,7 @@ end local function createTree(page) local tree = {} - local request = http.get(page) + local request = http.get(page, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY}) if not(request)then return end for k,v in pairs(textutils.unserialiseJSON(request.readAll()).tree)do if(v.type=="blob")then diff --git a/basaltPackager.lua b/basaltPackager.lua index 6a6ec87..084a610 100644 --- a/basaltPackager.lua +++ b/basaltPackager.lua @@ -464,7 +464,8 @@ outputFile:write("project['default'] = {}") local function writeNewPackage(subdir, name, path) if not(fs.isDir(path))then outputFile:write("project['"..subdir.."']['"..name.."'] = ".."function(...)") - local fileData = io.open(path, "r"):read("*all") + local file = io.open(path, "r") + local fileData = file:read("*all") if(minifyProject)then local success, data = minify(fileData) if(success)then @@ -475,7 +476,7 @@ local function writeNewPackage(subdir, name, path) else outputFile:write(fileData:gsub("]]", "] ]"):gsub("]]", "] ]").."\n") end - fileData.close() + file:close() outputFile:write("end; \n") end end @@ -490,16 +491,17 @@ for _,v in pairs(projectFiles)do end end -local main = io.open(fs.combine(projectPath, mainFile), "r"):read("*all") +local main = io.open(fs.combine(projectPath, mainFile), "r") +local mainData = main:read("*all") if(minifyProject)then - local success,data = minify(main) + local success,data = minify(mainData) if(success)then outputFile:write(data) else - print("Error: Can't minify "..fs.combine(projectPath, mainFile)) + print("Error: Can't minify "..fs.combine(projectPath, mainFile).." "..data) end else - outputFile:write(main) + outputFile:write(mainData) end - -outputFile:close() \ No newline at end of file +main:close() +outputFile:close() diff --git a/docs/Home.md b/docs/Home.md index 52cb1ea..8576b6b 100644 --- a/docs/Home.md +++ b/docs/Home.md @@ -9,7 +9,7 @@ Here you can find information about how to use Basalt as well as examples of fun Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://www.curseforge.com/minecraft/mc-mods/cc-tweaked). ## Quick Demo -![Preview](https://media0.giphy.com/media/fvmNPshXKeU7FFA9iA/giphy.gif) + ## Questions & Bugs @@ -21,4 +21,4 @@ Additionally, if you have questions about Basalt or how to make use of it, feel Feel free to join our [discord](https://discord.gg/yNNnmBVBpE)! -

\ No newline at end of file +

diff --git a/docs/_media/basaltPreview2.gif b/docs/_media/basaltPreview2.gif new file mode 100644 index 0000000..6b3da2b Binary files /dev/null and b/docs/_media/basaltPreview2.gif differ diff --git a/docs/home/Quick-Start.md b/docs/home/Quick-Start.md index 36375c0..5002627 100644 --- a/docs/home/Quick-Start.md +++ b/docs/home/Quick-Start.md @@ -2,7 +2,7 @@ To load the framework into your project, make use of the following code on top of your code. ```lua -local basalt = require("Basalt") +local basalt = require("basalt") ``` It does not matter if you have installed the single file version or the full folder project.
@@ -43,11 +43,10 @@ The true keyword in the end is optional and would simply start BPM immediately. Here is a fully functioning example of Basalt code ```lua -local basalt = require("Basalt") --> Load the Basalt framework +local basalt = require("basalt") --> Load the Basalt framework --> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events --> When Basalt#createFrame makes use of unique identifiers (commonly referred to as UIDs), meaning that the supplied value must be UNIQUE ---> If the supplied UID is ambiguous, Basalt#createFrame returns a nil value local mainFrame = basalt.createFrame("mainFrame") --> Show the frame to the user @@ -76,7 +75,7 @@ basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect us ``` If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above: ```lua -local basalt = require("Basalt") +local basalt = require("basalt") local mainFrame = basalt.createFrame("mainFrame"):show() local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining" diff --git a/docs/home/installer.md b/docs/home/installer.md index 4bd7895..831bb18 100644 --- a/docs/home/installer.md +++ b/docs/home/installer.md @@ -6,9 +6,9 @@ This is just a script which helps you to setup your program to automatically ins Here is a very basic one which just installs basalt.lua if don't exist: ```lua --Basalt configurated installer -local filePath = "basalt.lua" --here you can change the file path default: basalt.lua +local filePath = "basalt.lua" --here you can change the file path default: basalt if not(fs.exists(filePath))then - shell.run("pastebin run ESs1mg7P packed true "..filePath) -- this is an alternative to the wget command + shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command end local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt ``` @@ -18,7 +18,7 @@ This is a visual version, it asks the user if he wants to install basalt.lua (if ![](https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/installer.png) ```lua --Basalt configurated installer -local filePath = "basalt.lua" --here you can change the file path default: basalt.lua +local filePath = "basalt.lua" --here you can change the file path default: basalt if not(fs.exists(filePath))then local w,h = term.getSize() term.clear() @@ -51,7 +51,7 @@ if not(fs.exists(filePath))then local event, p1,p2,p3,p4 = os.pullEvent() if(event=="mouse_click")then if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then - shell.run("pastebin run ESs1mg7P packed true "..filePath) + shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) _installerWindow.setVisible(false) term.clear() break diff --git a/docs/objects/Basalt.md b/docs/objects/Basalt.md index e80aeaf..844f211 100644 --- a/docs/objects/Basalt.md +++ b/docs/objects/Basalt.md @@ -171,8 +171,8 @@ end)