Small update to 1.6.4
- added bimg support - reworked graphic object - added blit for drawsystem (makes drawing bit faster - added bimg lib - reworked image object - fixed thread bug
This commit is contained in:
132
Basalt/Frame.lua
132
Basalt/Frame.lua
@@ -49,6 +49,8 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
local activeEvents = {}
|
local activeEvents = {}
|
||||||
|
|
||||||
|
local colorTheme = {}
|
||||||
|
|
||||||
base:setZIndex(10)
|
base:setZIndex(10)
|
||||||
|
|
||||||
local basaltDraw = BasaltDraw(termObject)
|
local basaltDraw = BasaltDraw(termObject)
|
||||||
@@ -81,6 +83,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function getObject(name)
|
local function getObject(name)
|
||||||
|
if(type(name)~="string")then name = name.name end
|
||||||
for _, value in pairs(objects) do
|
for _, value in pairs(objects) do
|
||||||
for _, b in pairs(value) do
|
for _, b in pairs(value) do
|
||||||
if (b:getName() == name) then
|
if (b:getName() == name) then
|
||||||
@@ -240,11 +243,11 @@ return function(name, parent, pTerm, basalt)
|
|||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
local math = math
|
||||||
local function stringToNumber(str)
|
local function stringToNumber(str)
|
||||||
local ok, err = pcall(load("return " .. str))
|
local ok, result = pcall(load("return " .. str, "", nil, {math=math}))
|
||||||
if not(ok)then error(str.." is not a valid dynamic code") end
|
if not(ok)then error(str.." is not a valid dynamic code") end
|
||||||
return load("return " .. str)()
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
local function newDynamicValue(_, obj, str)
|
local function newDynamicValue(_, obj, str)
|
||||||
@@ -327,8 +330,13 @@ return function(name, parent, pTerm, basalt)
|
|||||||
for _, index in pairs(objZIndex) do
|
for _, index in pairs(objZIndex) do
|
||||||
if (objects[index] ~= nil) then
|
if (objects[index] ~= nil) then
|
||||||
for _, value in pairs(objects[index]) do
|
for _, value in pairs(objects[index]) do
|
||||||
if (value.eventHandler ~= nil) then
|
if(basalt.getDynamicValueEventSetting())then
|
||||||
value:eventHandler("dynamicValueEvent", self)
|
if (value.eventHandler ~= nil) then
|
||||||
|
value:eventHandler("basalt_dynamicvalue", self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (value.customEventHandler ~= nil) then
|
||||||
|
value:customEventHandler("basalt_resize", self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -340,17 +348,49 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return dynamicValues[id][1]
|
return dynamicValues[id][1]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function calculateMaxScroll(self)
|
local function getVerticalScrollAmount(self)
|
||||||
|
local amount = 0
|
||||||
for _, value in pairs(objects) do
|
for _, value in pairs(objects) do
|
||||||
for _, b in pairs(value) do
|
for _, b in pairs(value) do
|
||||||
if(b.getHeight~=nil)and(b.getY~=nil)then
|
if(b.getHeight~=nil)and(b.getY~=nil)then
|
||||||
local h, y = b:getHeight(), b:getY()
|
if(b:getType()=="Dropdown")then
|
||||||
if (h + y - self:getHeight() > scrollAmount) then
|
local h, y = b:getHeight(), b:getY()
|
||||||
scrollAmount = max(h + y - self:getHeight(), 0)
|
local wD, hD = b:getDropdownSize()
|
||||||
|
h = h + hD - 1
|
||||||
|
if (h + y - self:getHeight() >= amount) then
|
||||||
|
amount = max(h + y - self:getHeight(), 0)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local h, y = b:getHeight(), b:getY()
|
||||||
|
if (h + y - self:getHeight() >= amount) then
|
||||||
|
amount = max(h + y - self:getHeight(), 0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return amount
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getHorizontalScrollAmount(self)
|
||||||
|
local amount = 0
|
||||||
|
for _, value in pairs(objects) do
|
||||||
|
for _, b in pairs(value) do
|
||||||
|
if(b.getWidth~=nil)and(b.getX~=nil)then
|
||||||
|
local h, y = b:getWidth(), b:getX()
|
||||||
|
if (h + y - self:getWidth() >= amount) then
|
||||||
|
amount = max(h + y - self:getWidth(), 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return amount
|
||||||
|
end
|
||||||
|
|
||||||
|
local function calculateMaxScroll(self)
|
||||||
|
if(autoScroll)then
|
||||||
|
scrollAmount = getVerticalScrollAmount(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
object = {
|
object = {
|
||||||
@@ -371,8 +411,8 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
getType = function(self)
|
getType = function(self)
|
||||||
return objectType
|
return objectType
|
||||||
end,
|
end;
|
||||||
|
|
||||||
setZIndex = function(self, newIndex)
|
setZIndex = function(self, newIndex)
|
||||||
base.setZIndex(self, newIndex)
|
base.setZIndex(self, newIndex)
|
||||||
for k,v in pairs(activeEvents)do
|
for k,v in pairs(activeEvents)do
|
||||||
@@ -386,10 +426,14 @@ return function(name, parent, pTerm, basalt)
|
|||||||
setFocusedObject = function(self, obj)
|
setFocusedObject = function(self, obj)
|
||||||
if(focusedObject~=obj)then
|
if(focusedObject~=obj)then
|
||||||
if(focusedObject~=nil)then
|
if(focusedObject~=nil)then
|
||||||
focusedObject:loseFocusHandler()
|
if(getObject(focusedObject)~=nil)then
|
||||||
|
focusedObject:loseFocusHandler()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if(obj~=nil)then
|
if(obj~=nil)then
|
||||||
obj:getFocusHandler()
|
if(getObject(obj)~=nil)then
|
||||||
|
obj:getFocusHandler()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
focusedObject = obj
|
focusedObject = obj
|
||||||
end
|
end
|
||||||
@@ -408,8 +452,8 @@ return function(name, parent, pTerm, basalt)
|
|||||||
for _, index in pairs(objZIndex) do
|
for _, index in pairs(objZIndex) do
|
||||||
if (objects[index] ~= nil) then
|
if (objects[index] ~= nil) then
|
||||||
for _, value in pairs(objects[index]) do
|
for _, value in pairs(objects[index]) do
|
||||||
if (value.eventHandler ~= nil) then
|
if (value.customEventHandler ~= nil) then
|
||||||
value:eventHandler("basalt_resize", value, self)
|
value:customEventHandler("basalt_resize", self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -433,17 +477,34 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return theme[name] or (self.parent~=nil and self.parent:getTheme(name) or basalt.getTheme(name))
|
return theme[name] or (self.parent~=nil and self.parent:getTheme(name) or basalt.getTheme(name))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
setPosition = function(self, x, y, rel)
|
getThemeColor = function(self, col)
|
||||||
base.setPosition(self, x, y, rel)
|
return col~=nil and colorTheme[col] or colorTheme
|
||||||
for _, index in pairs(objZIndex) do
|
end,
|
||||||
if (objects[index] ~= nil) then
|
|
||||||
for _, value in pairs(objects[index]) do
|
setThemeColor = function(self, col, ...)
|
||||||
if (value.eventHandler ~= nil) then
|
if(self.parent==nil)then
|
||||||
value:eventHandler("basalt_reposition", value, self)
|
if(self==basalt.getActiveFrame())then
|
||||||
|
if(type(col)=="string")then
|
||||||
|
colorTheme[col] = ...
|
||||||
|
termObject.setPaletteColor(type(col)=="number" and col or colors[col], ...)
|
||||||
|
elseif(type(col)=="table")then
|
||||||
|
for k,v in pairs(col)do
|
||||||
|
colorTheme[k] = v
|
||||||
|
if(type(v)=="number")then
|
||||||
|
termObject.setPaletteColor(type(k)=="number" and k or colors[k], v)
|
||||||
|
else
|
||||||
|
local r,g,b = table.unpack(v)
|
||||||
|
termObject.setPaletteColor(type(k)=="number" and k or colors[k], r,g,b)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
setPosition = function(self, x, y, rel)
|
||||||
|
base.setPosition(self, x, y, rel)
|
||||||
self:recalculateDynamicValues()
|
self:recalculateDynamicValues()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -469,7 +530,9 @@ return function(name, parent, pTerm, basalt)
|
|||||||
|
|
||||||
removeFocusedObject = function(self)
|
removeFocusedObject = function(self)
|
||||||
if(focusedObject~=nil)then
|
if(focusedObject~=nil)then
|
||||||
focusedObject:loseFocusHandler()
|
if(getObject(focusedObject)~=nil)then
|
||||||
|
focusedObject:loseFocusHandler()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
focusedObject = nil
|
focusedObject = nil
|
||||||
return self
|
return self
|
||||||
@@ -537,10 +600,26 @@ return function(name, parent, pTerm, basalt)
|
|||||||
return autoScroll and calculateMaxScroll(self) or scrollAmount
|
return autoScroll and calculateMaxScroll(self) or scrollAmount
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
getCalculatedVerticalScroll = getVerticalScrollAmount,
|
||||||
|
getCalculatedHorizontalScroll = getHorizontalScrollAmount,
|
||||||
|
|
||||||
show = function(self)
|
show = function(self)
|
||||||
base.show(self)
|
base.show(self)
|
||||||
if(self.parent==nil)then
|
if(self.parent==nil)then
|
||||||
basalt.setActiveFrame(self)
|
basalt.setActiveFrame(self)
|
||||||
|
for k,v in pairs(colors)do
|
||||||
|
if(type(v)=="number")then
|
||||||
|
termObject.setPaletteColor(v, colors.packRGB(term.nativePaletteColor((v))))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for k,v in pairs(colorTheme)do
|
||||||
|
if(type(v)=="number")then
|
||||||
|
termObject.setPaletteColor(type(k)=="number" and k or colors[k], v)
|
||||||
|
else
|
||||||
|
local r,g,b = table.unpack(v)
|
||||||
|
termObject.setPaletteColor(type(k)=="number" and k or colors[k], r,g,b)
|
||||||
|
end
|
||||||
|
end
|
||||||
if(isMonitor)and not(isGroupedMonitor)then
|
if(isMonitor)and not(isGroupedMonitor)then
|
||||||
basalt.setMonitorFrame(monSide, self)
|
basalt.setMonitorFrame(monSide, self)
|
||||||
elseif(isGroupedMonitor)then
|
elseif(isGroupedMonitor)then
|
||||||
@@ -555,7 +634,7 @@ return function(name, parent, pTerm, basalt)
|
|||||||
hide = function (self)
|
hide = function (self)
|
||||||
base.hide(self)
|
base.hide(self)
|
||||||
if(self.parent==nil)then
|
if(self.parent==nil)then
|
||||||
if(activeFrame == self)then activeFrame = nil end -- bug activeFrame always nil
|
if(activeFrame == self)then activeFrame = nil end
|
||||||
if(isMonitor)and not(isGroupedMonitor)then
|
if(isMonitor)and not(isGroupedMonitor)then
|
||||||
if(basalt.getMonitorFrame(monSide) == self)then
|
if(basalt.getMonitorFrame(monSide) == self)then
|
||||||
basalt.setActiveFrame(nil)
|
basalt.setActiveFrame(nil)
|
||||||
@@ -804,9 +883,6 @@ return function(name, parent, pTerm, basalt)
|
|||||||
self:mouseHandler(1, p2, p3, true)
|
self:mouseHandler(1, p2, p3, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (event == "terminate")and(self.parent==nil)then
|
|
||||||
basalt.stop()
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
mouseHandler = function(self, button, x, y, _, side)
|
mouseHandler = function(self, button, x, y, _, side)
|
||||||
@@ -891,8 +967,8 @@ return function(name, parent, pTerm, basalt)
|
|||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:removeFocusedObject()
|
|
||||||
if(yOffset==cache)then return false end
|
if(yOffset==cache)then return false end
|
||||||
|
self:removeFocusedObject()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
local basaltEvent = require("basaltEvent")
|
local basaltEvent = require("basaltEvent")
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
local module = require("module")
|
||||||
|
local images = module("images")
|
||||||
local split = utils.splitString
|
local split = utils.splitString
|
||||||
local numberFromString = utils.numberFromString
|
local numberFromString = utils.numberFromString
|
||||||
local xmlValue = utils.getValueFromXML
|
local xmlValue = utils.getValueFromXML
|
||||||
|
|
||||||
|
local unpack,sub = table.unpack,string.sub
|
||||||
|
|
||||||
return function(name)
|
return function(name)
|
||||||
-- Base object
|
-- Base object
|
||||||
local objectType = "Object" -- not changeable
|
local objectType = "Object" -- not changeable
|
||||||
@@ -30,6 +34,13 @@ return function(name)
|
|||||||
local isDragging = false
|
local isDragging = false
|
||||||
local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0
|
local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0
|
||||||
|
|
||||||
|
local bimg
|
||||||
|
local texture
|
||||||
|
local textureId = 1
|
||||||
|
local textureTimerId
|
||||||
|
local textureMode
|
||||||
|
local infinitePlay = true
|
||||||
|
|
||||||
local draw = true
|
local draw = true
|
||||||
local activeEvents = {}
|
local activeEvents = {}
|
||||||
|
|
||||||
@@ -97,8 +108,8 @@ return function(name)
|
|||||||
|
|
||||||
setValuesByXMLData = function(self, data)
|
setValuesByXMLData = function(self, data)
|
||||||
local baseFrame = self:getBaseFrame()
|
local baseFrame = self:getBaseFrame()
|
||||||
if(xmlValue("x", data)~=nil)then self:setPosition(xmlValue("x", data), self.y) end
|
if(xmlValue("x", data)~=nil)then self:setPosition(xmlValue("x", data), self:getY()) end
|
||||||
if(xmlValue("y", data)~=nil)then self:setPosition(self.x, xmlValue("y", data)) end
|
if(xmlValue("y", data)~=nil)then self:setPosition(self:getX(), xmlValue("y", data)) end
|
||||||
if(xmlValue("width", data)~=nil)then self:setSize(xmlValue("width", data), self.height) end
|
if(xmlValue("width", data)~=nil)then self:setSize(xmlValue("width", data), self.height) end
|
||||||
if(xmlValue("height", data)~=nil)then self:setSize(self.width, xmlValue("height", data)) end
|
if(xmlValue("height", data)~=nil)then self:setSize(self.width, xmlValue("height", data)) end
|
||||||
if(xmlValue("bg", data)~=nil)then self:setBackground(colors[xmlValue("bg", data)]) end
|
if(xmlValue("bg", data)~=nil)then self:setBackground(colors[xmlValue("bg", data)]) end
|
||||||
@@ -195,11 +206,13 @@ return function(name)
|
|||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
setValue = function(self, _value)
|
setValue = function(self, _value, valueChangedHandler)
|
||||||
if (value ~= _value) then
|
if (value ~= _value) then
|
||||||
value = _value
|
value = _value
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
self:valueChangedHandler()
|
if(valueChangedHandler~=false)then
|
||||||
|
self:valueChangedHandler()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -245,7 +258,7 @@ return function(name)
|
|||||||
end
|
end
|
||||||
self.parent:recalculateDynamicValues()
|
self.parent:recalculateDynamicValues()
|
||||||
end
|
end
|
||||||
eventSystem:sendEvent("basalt_reposition", self)
|
self:customEventHandler("basalt_reposition")
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -288,24 +301,27 @@ return function(name)
|
|||||||
end
|
end
|
||||||
self.parent:recalculateDynamicValues()
|
self.parent:recalculateDynamicValues()
|
||||||
end
|
end
|
||||||
eventSystem:sendEvent("basalt_resize", self)
|
if(bimg~=nil)and(textureMode=="stretch")then
|
||||||
|
texture = images.resizeBIMG(bimg, self:getSize())[textureId]
|
||||||
|
end
|
||||||
|
self:customEventHandler("basalt_resize")
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end,
|
||||||
|
|
||||||
getHeight = function(self)
|
getHeight = function(self)
|
||||||
return type(self.height) == "number" and self.height or math.floor(self.height[1]+0.5)
|
return type(self.height) == "number" and self.height or math.floor(self.height[1]+0.5)
|
||||||
end;
|
end,
|
||||||
|
|
||||||
getWidth = function(self)
|
getWidth = function(self)
|
||||||
return type(self.width) == "number" and self.width or math.floor(self.width[1]+0.5)
|
return type(self.width) == "number" and self.width or math.floor(self.width[1]+0.5)
|
||||||
end;
|
end,
|
||||||
|
|
||||||
getSize = function(self)
|
getSize = function(self)
|
||||||
return self:getWidth(), self:getHeight()
|
return self:getWidth(), self:getHeight()
|
||||||
end;
|
end,
|
||||||
|
|
||||||
calculateDynamicValues = function(self)
|
calculateDynamicValues = function(self)
|
||||||
if(type(self.width)=="table")then self.width:calculate() end
|
if(type(self.width)=="table")then self.width:calculate() end
|
||||||
if(type(self.height)=="table")then self.height:calculate() end
|
if(type(self.height)=="table")then self.height:calculate() end
|
||||||
if(type(self.x)=="table")then self.x:calculate() end
|
if(type(self.x)=="table")then self.x:calculate() end
|
||||||
@@ -320,12 +336,38 @@ return function(name)
|
|||||||
self.bgSymbolColor = symbolCol or self.bgSymbolColor
|
self.bgSymbolColor = symbolCol or self.bgSymbolColor
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end,
|
||||||
|
|
||||||
|
setTexture = function(self, tex, mode, infPlay)
|
||||||
|
if(type(tex)=="string")then
|
||||||
|
bimg = images.loadImageAsBimg(tex)
|
||||||
|
elseif(type(tex)=="table")then
|
||||||
|
bimg = tex
|
||||||
|
end
|
||||||
|
if(bimg.animated)then
|
||||||
|
local t = bimg[textureId].duration or bimg.secondsPerFrame or 0.2
|
||||||
|
textureTimerId = os.startTimer(t)
|
||||||
|
self.parent:addEvent("other_event", self)
|
||||||
|
activeEvents["other_event"] = true
|
||||||
|
end
|
||||||
|
infinitePlay = infPlay==false and false or true
|
||||||
|
textureId = 1
|
||||||
|
textureMode = mode or "normal"
|
||||||
|
if(textureMode=="stretch")then
|
||||||
|
texture = images.resizeBIMG(bimg, self:getSize())[1]
|
||||||
|
else
|
||||||
|
texture = bimg[1]
|
||||||
|
end
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
setTransparent = function(self, color)
|
setTransparent = function(self, color)
|
||||||
self.transparentColor = color or false
|
self.transparentColor = color or false
|
||||||
self.bgSymbol = false
|
if(color~=false)then
|
||||||
self.bgSymbolColor = false
|
self.bgSymbol = false
|
||||||
|
self.bgSymbolColor = false
|
||||||
|
end
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -403,18 +445,50 @@ return function(name)
|
|||||||
local w,h = self:getSize()
|
local w,h = self:getSize()
|
||||||
local wP,hP = self.parent:getSize()
|
local wP,hP = self.parent:getSize()
|
||||||
if(x+w<1)or(x>wP)or(y+h<1)or(y>hP)then return false end
|
if(x+w<1)or(x>wP)or(y+h<1)or(y>hP)then return false end
|
||||||
if(self.transparentColor~=false)then
|
if(self.transparentColor~=false)then
|
||||||
self.parent:drawForegroundBox(x, y, w, h, self.transparentColor)
|
self.parent:drawForegroundBox(x, y, w, h, self.transparentColor)
|
||||||
end
|
end
|
||||||
if(self.bgColor~=false)then
|
if(self.bgColor~=false)then
|
||||||
self.parent:drawBackgroundBox(x, y, w, h, self.bgColor)
|
self.parent:drawBackgroundBox(x, y, w, h, self.bgColor)
|
||||||
end
|
end
|
||||||
if(self.bgSymbol~=false)then
|
if(self.bgSymbol~=false)then
|
||||||
self.parent:drawTextBox(x, y, w, h, self.bgSymbol)
|
self.parent:drawTextBox(x, y, w, h, self.bgSymbol)
|
||||||
if(self.bgSymbol~=" ")then
|
if(self.bgSymbol~=" ")then
|
||||||
self.parent:drawForegroundBox(x, y, w, h, self.bgSymbolColor)
|
self.parent:drawForegroundBox(x, y, w, h, self.bgSymbolColor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(texture~=nil)then
|
||||||
|
if(textureMode=="center")then
|
||||||
|
local tW,tH = #texture[1][1],#texture
|
||||||
|
local xO = tW < w and math.floor((w-tW)/2) or 0
|
||||||
|
local yO = tH < h and math.floor((h-tH)/2) or 0
|
||||||
|
local sL = tW<w and 1 or math.floor((tW-w)/2)
|
||||||
|
local eL = tW<w and w or w - math.floor((w-tW)/2+0.5)-1
|
||||||
|
local sH = tH<h and 1 or math.floor((tH-h)/2)
|
||||||
|
local eH = tH<h and h or h - math.floor((h-tH)/2+0.5)-1
|
||||||
|
local yTex = 1
|
||||||
|
for k=sH,#texture do
|
||||||
|
if(texture[k]~=nil)then
|
||||||
|
local t, f, b = unpack(texture[k])
|
||||||
|
t = sub(t, sL,eL)
|
||||||
|
f = sub(f, sL,eL)
|
||||||
|
b = sub(b, sL,eL)
|
||||||
|
self.parent:blit(x+xO, y+yTex-1+yO, t, f, b)
|
||||||
|
end
|
||||||
|
yTex = yTex + 1
|
||||||
|
if(k==eH)then break end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for k,v in pairs(texture)do
|
||||||
|
local t, f, b = unpack(v)
|
||||||
|
t = sub(t, 1,w)
|
||||||
|
f = sub(f, 1,w)
|
||||||
|
b = sub(b, 1,w)
|
||||||
|
self.parent:blit(x, y+k-1, t, f, b)
|
||||||
|
if(k==h)then break end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
if(shadow)then
|
if(shadow)then
|
||||||
self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor)
|
self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor)
|
||||||
self.parent:drawBackgroundBox(x+w, y+1, 1, h, shadowColor)
|
self.parent:drawBackgroundBox(x+w, y+1, 1, h, shadowColor)
|
||||||
@@ -425,11 +499,10 @@ return function(name)
|
|||||||
local bgCol = self.bgColor
|
local bgCol = self.bgColor
|
||||||
if(borderColors["left"]~=false)then
|
if(borderColors["left"]~=false)then
|
||||||
self.parent:drawTextBox(x, y, 1, h, "\149")
|
self.parent:drawTextBox(x, y, 1, h, "\149")
|
||||||
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, 1, h, self.bgColor) end
|
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, 1, h, bgCol) end
|
||||||
self.parent:drawForegroundBox(x, y, 1, h, borderColors["left"])
|
self.parent:drawForegroundBox(x, y, 1, h, borderColors["left"])
|
||||||
end
|
end
|
||||||
if(borderColors["top"]~=false)then
|
if(borderColors["top"]~=false)then
|
||||||
|
|
||||||
self.parent:drawTextBox(x, y, w, 1, "\131")
|
self.parent:drawTextBox(x, y, w, 1, "\131")
|
||||||
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, w, 1, self.bgColor) end
|
if(bgCol~=false)then self.parent:drawBackgroundBox(x, y, w, 1, self.bgColor) end
|
||||||
self.parent:drawForegroundBox(x, y, w, 1, borderColors["top"])
|
self.parent:drawForegroundBox(x, y, w, 1, borderColors["top"])
|
||||||
@@ -792,7 +865,7 @@ 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 objX, objY = self:getAbsolutePosition()
|
local objX, objY = self:getAbsolutePosition()
|
||||||
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x - (objX-1), y - (objY-1), isMon)
|
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x - (objX-1), y - (objY-1), x, y, 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)
|
||||||
@@ -809,12 +882,12 @@ return function(name)
|
|||||||
isDragging = false
|
isDragging = false
|
||||||
if(isClicked)then
|
if(isClicked)then
|
||||||
local objX, objY = self:getAbsolutePosition()
|
local objX, objY = self:getAbsolutePosition()
|
||||||
local val = eventSystem:sendEvent("mouse_release", self, "mouse_release", button, x - (objX-1), y - (objY-1))
|
local val = eventSystem:sendEvent("mouse_release", self, "mouse_release", button, x - (objX-1), y - (objY-1), x, y)
|
||||||
isClicked = false
|
isClicked = false
|
||||||
end
|
end
|
||||||
if(self:isCoordsInObject(x, y))then
|
if(self:isCoordsInObject(x, y))then
|
||||||
local objX, objY = self:getAbsolutePosition()
|
local objX, objY = self:getAbsolutePosition()
|
||||||
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x - (objX-1), y - (objY-1))
|
local val = eventSystem:sendEvent("mouse_up", self, "mouse_up", button, x - (objX-1), y - (objY-1), x, y)
|
||||||
if(val==false)then return false end
|
if(val==false)then return false end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -906,11 +979,46 @@ return function(name)
|
|||||||
eventSystem:sendEvent("value_changed", self, value)
|
eventSystem:sendEvent("value_changed", self, value)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
eventHandler = function(self, event, p1, p2, p3, p4)
|
eventHandler = function(self, event, ...)
|
||||||
local val = eventSystem:sendEvent("other_event", self, event, p1, p2, p3, p4)
|
local args = {...}
|
||||||
|
if(event=="timer")and(args[1]==textureTimerId)then
|
||||||
|
if(bimg[textureId+1]~=nil)then
|
||||||
|
textureId = textureId + 1
|
||||||
|
if(textureMode=="stretch")then
|
||||||
|
texture = images.resizeBIMG(bimg, self:getSize())[textureId]
|
||||||
|
else
|
||||||
|
texture = bimg[textureId]
|
||||||
|
end
|
||||||
|
local t = bimg[textureId].duration or bimg.secondsPerFrame or 0.2
|
||||||
|
textureTimerId = os.startTimer(t)
|
||||||
|
else
|
||||||
|
if(infinitePlay)then
|
||||||
|
textureId = 1
|
||||||
|
if(textureMode=="stretch")then
|
||||||
|
texture = images.resizeBIMG(bimg, self:getSize())[1]
|
||||||
|
else
|
||||||
|
texture = bimg[1]
|
||||||
|
end
|
||||||
|
local t = bimg[1].duration or bimg.secondsPerFrame or 0.2
|
||||||
|
textureTimerId = os.startTimer(t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:updateDraw()
|
||||||
|
end
|
||||||
|
local val = eventSystem:sendEvent("other_event", self, event, ...)
|
||||||
if(val~=nil)then return val end
|
if(val~=nil)then return val end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
customEventHandler = function(self, event, ...)
|
||||||
|
if(bimg~=nil)and(textureMode=="stretch")and(event=="basalt_resize")then
|
||||||
|
texture = images.resizeBIMG(bimg, self:getSize())[textureId]
|
||||||
|
self:updateDraw()
|
||||||
|
end
|
||||||
|
local val = eventSystem:sendEvent("custom_event", self, event, ...)
|
||||||
|
if(val~=nil)then return val end
|
||||||
|
return true
|
||||||
|
end;
|
||||||
|
|
||||||
getFocusHandler = function(self)
|
getFocusHandler = function(self)
|
||||||
local val = eventSystem:sendEvent("get_focus", self)
|
local val = eventSystem:sendEvent("get_focus", self)
|
||||||
if(val~=nil)then return val end
|
if(val~=nil)then return val end
|
||||||
@@ -943,4 +1051,4 @@ return function(name)
|
|||||||
|
|
||||||
object.__index = object
|
object.__index = object
|
||||||
return object
|
return object
|
||||||
end
|
end
|
||||||
@@ -14,4 +14,4 @@ end
|
|||||||
local Basalt = require("main")
|
local Basalt = require("main")
|
||||||
package.path = defaultPath
|
package.path = defaultPath
|
||||||
|
|
||||||
return Basalt
|
return Basalt
|
||||||
@@ -126,6 +126,52 @@ return function(drawTerm)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function blit(x, y, t, fg, bg)
|
||||||
|
if(#t == #fg)or(#t == #bg)then
|
||||||
|
if (y >= 1) and (y <= height) then
|
||||||
|
if (x + t:len() > 0) and (x <= width) then
|
||||||
|
local oldCacheT = cacheT[y]
|
||||||
|
local oldCacheFG = cacheFG[y]
|
||||||
|
local oldCacheBG = cacheBG[y]
|
||||||
|
local newCacheT, newCacheFG, newCacheBG
|
||||||
|
local nEnd = x + #t - 1
|
||||||
|
|
||||||
|
if (x < 1) then
|
||||||
|
local startN = 1 - x + 1
|
||||||
|
local endN = width - x + 1
|
||||||
|
t = sub(t, startN, endN)
|
||||||
|
fg = sub(fg, startN, endN)
|
||||||
|
bg = sub(bg, startN, endN)
|
||||||
|
elseif (nEnd > width) then
|
||||||
|
local endN = width - x + 1
|
||||||
|
t = sub(t, 1, endN)
|
||||||
|
fg = sub(fg, 1, endN)
|
||||||
|
bg = sub(bg, 1, endN)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (x > 1) then
|
||||||
|
local endN = x - 1
|
||||||
|
newCacheT = sub(oldCacheT, 1, endN) .. t
|
||||||
|
newCacheFG = sub(oldCacheFG, 1, endN) .. fg
|
||||||
|
newCacheBG = sub(oldCacheBG, 1, endN) .. bg
|
||||||
|
else
|
||||||
|
newCacheT = t
|
||||||
|
newCacheFG = fg
|
||||||
|
newCacheBG = bg
|
||||||
|
end
|
||||||
|
if nEnd < width then
|
||||||
|
newCacheT = newCacheT .. sub(oldCacheT, nEnd + 1, width)
|
||||||
|
newCacheFG = newCacheFG .. sub(oldCacheFG, nEnd + 1, width)
|
||||||
|
newCacheBG = newCacheBG .. sub(oldCacheBG, nEnd + 1, width)
|
||||||
|
end
|
||||||
|
cacheT[y] = newCacheT
|
||||||
|
cacheFG[y] = newCacheFG
|
||||||
|
cacheBG[y] = newCacheBG
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local drawHelper = {
|
local drawHelper = {
|
||||||
setSize = function(w, h)
|
setSize = function(w, h)
|
||||||
width, height = w, h
|
width, height = w, h
|
||||||
@@ -147,6 +193,10 @@ return function(drawTerm)
|
|||||||
setFG(x, y, colorStr)
|
setFG(x, y, colorStr)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
blit = function(x, y, t, fg, bg)
|
||||||
|
blit(x, y, t, fg, bg)
|
||||||
|
end,
|
||||||
|
|
||||||
drawBackgroundBox = function(x, y, width, height, bgCol)
|
drawBackgroundBox = function(x, y, width, height, bgCol)
|
||||||
for n = 1, height do
|
for n = 1, height do
|
||||||
setBG(x, y + (n - 1), rep(tHex[bgCol], width))
|
setBG(x, y + (n - 1), rep(tHex[bgCol], width))
|
||||||
|
|||||||
381
Basalt/libraries/bimg.lua
Normal file
381
Basalt/libraries/bimg.lua
Normal file
@@ -0,0 +1,381 @@
|
|||||||
|
local sub,rep = string.sub,string.rep
|
||||||
|
|
||||||
|
local function frame(base, manager)
|
||||||
|
local w, h = 0, 0
|
||||||
|
local t,fg,bg = {}, {}, {}
|
||||||
|
local x, y = 1,1
|
||||||
|
|
||||||
|
local data = {}
|
||||||
|
|
||||||
|
local function recalculateSize()
|
||||||
|
for y=1,h do
|
||||||
|
if(t[y]==nil)then
|
||||||
|
t[y] = rep(" ", w)
|
||||||
|
else
|
||||||
|
t[y] = t[y]..rep(" ", w-#t[y])
|
||||||
|
end
|
||||||
|
if(fg[y]==nil)then
|
||||||
|
fg[y] = rep("0", w)
|
||||||
|
else
|
||||||
|
fg[y] = fg[y]..rep("0", w-#fg[y])
|
||||||
|
end
|
||||||
|
if(bg[y]==nil)then
|
||||||
|
bg[y] = rep("f", w)
|
||||||
|
else
|
||||||
|
bg[y] = bg[y]..rep("f", w-#bg[y])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local addText = function(text, _x, _y)
|
||||||
|
x = _x or x
|
||||||
|
y = _y or y
|
||||||
|
if(t[y]==nil)then
|
||||||
|
t[y] = rep(" ", x-1)..text..rep(" ", w-(#text+x))
|
||||||
|
else
|
||||||
|
t[y] = sub(t[y], 1, x-1)..rep(" ", x-#t[y])..text..sub(t[y], x+#text, w)
|
||||||
|
end
|
||||||
|
if(#t[y]>w)then w = #t[y] end
|
||||||
|
if(y > h)then h = y end
|
||||||
|
manager.updateSize(w, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
local addBg = function(b, _x, _y)
|
||||||
|
x = _x or x
|
||||||
|
y = _y or y
|
||||||
|
if(bg[y]==nil)then
|
||||||
|
bg[y] = rep("f", x-1)..b..rep("f", w-(#b+x))
|
||||||
|
else
|
||||||
|
bg[y] = sub(bg[y], 1, x-1)..rep("f", x-#bg[y])..b..sub(bg[y], x+#b, w)
|
||||||
|
end
|
||||||
|
if(#bg[y]>w)then w = #bg[y] end
|
||||||
|
if(y > h)then h = y end
|
||||||
|
manager.updateSize(w, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
local addFg = function(f, _x, _y)
|
||||||
|
x = _x or x
|
||||||
|
y = _y or y
|
||||||
|
if(fg[y]==nil)then
|
||||||
|
fg[y] = rep("0", x-1)..f..rep("0", w-(#f+x))
|
||||||
|
else
|
||||||
|
fg[y] = sub(fg[y], 1, x-1)..rep("0", x-#fg[y])..f..sub(fg[y], x+#f, w)
|
||||||
|
end
|
||||||
|
if(#fg[y]>w)then w = #fg[y] end
|
||||||
|
if(y > h)then h = y end
|
||||||
|
manager.updateSize(w, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setFrame(frm)
|
||||||
|
data = {}
|
||||||
|
t, fg, bg = {}, {}, {}
|
||||||
|
for k,v in pairs(base)do
|
||||||
|
if(type(k)=="string")then
|
||||||
|
data[k] = v
|
||||||
|
else
|
||||||
|
t[k], fg[k], bg[k] = v[1], v[2], v[3]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
manager.updateSize(w, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
if(base~=nil)then
|
||||||
|
w = #base[1][1]
|
||||||
|
h = #base
|
||||||
|
setFrame(base)
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
recalculateSize = recalculateSize,
|
||||||
|
setFrame = setFrame,
|
||||||
|
|
||||||
|
getFrame = function()
|
||||||
|
local f = {}
|
||||||
|
|
||||||
|
for k,v in pairs(t)do
|
||||||
|
table.insert(f, {v, fg[k], bg[k]})
|
||||||
|
end
|
||||||
|
|
||||||
|
for k,v in pairs(data)do
|
||||||
|
f[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
|
return f, w, h
|
||||||
|
end,
|
||||||
|
|
||||||
|
getImage = function()
|
||||||
|
local i = {}
|
||||||
|
for k,v in pairs(t)do
|
||||||
|
table.insert(i, {v, fg[k], bg[k]})
|
||||||
|
end
|
||||||
|
return i
|
||||||
|
end,
|
||||||
|
|
||||||
|
setFrameData = function(key, value)
|
||||||
|
if(value~=nil)then
|
||||||
|
data[key] = value
|
||||||
|
else
|
||||||
|
if(type(key)=="table")then
|
||||||
|
data = key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
setFrameImage = function(imgData)
|
||||||
|
for k,v in pairs(imgData.t)do
|
||||||
|
t[k] = imgData.t[k]
|
||||||
|
fg[k] = imgData.fg[k]
|
||||||
|
bg[k] = imgData.bg[k]
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrameImage = function()
|
||||||
|
return {t = t, fg = fg, bg = bg}
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrameData = function(key)
|
||||||
|
return (key~= nil and data[key] or data)
|
||||||
|
end,
|
||||||
|
|
||||||
|
blit = function(text, fgCol, bgCol, x, y)
|
||||||
|
addText(text, x, y)
|
||||||
|
addFg(fgCol, x, y)
|
||||||
|
addBg(bgCol, x, y)
|
||||||
|
end,
|
||||||
|
|
||||||
|
text = addText,
|
||||||
|
fg = addFg,
|
||||||
|
bg = addBg,
|
||||||
|
|
||||||
|
getSize = function()
|
||||||
|
return w, h
|
||||||
|
end,
|
||||||
|
|
||||||
|
setSize = function(_w, _h)
|
||||||
|
local nt,nfg,nbg = {}, {}, {}
|
||||||
|
for _y=1,_h do
|
||||||
|
if(t[_y]~=nil)then
|
||||||
|
nt[_y] = sub(t[_y], 1, _w)..rep(" ", _w - w)
|
||||||
|
else
|
||||||
|
nt[_y] = rep(" ", _w)
|
||||||
|
end
|
||||||
|
if(fg[_y]~=nil)then
|
||||||
|
nfg[_y] = sub(fg[_y], 1, _w)..rep("0", _w - w)
|
||||||
|
else
|
||||||
|
nfg[_y] = rep("0", _w)
|
||||||
|
end
|
||||||
|
if(bg[_y]~=nil)then
|
||||||
|
nbg[_y] = sub(bg[_y], 1, _w)..rep("f", _w - w)
|
||||||
|
else
|
||||||
|
nbg[_y] = rep("f", _w)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
t, fg, bg = nt, nfg, nbg
|
||||||
|
w, h = _w, _h
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return function(img)
|
||||||
|
local frames = {}
|
||||||
|
local metadata = {creator="Bimg Library by NyoriE", date=os.date("!%Y-%m-%dT%TZ")}
|
||||||
|
local width,height = 0, 0
|
||||||
|
|
||||||
|
local manager = {}
|
||||||
|
|
||||||
|
local function addFrame(id, data)
|
||||||
|
id = id or #frames+1
|
||||||
|
table.insert(frames, id, frame(data, manager))
|
||||||
|
if(data==nil)then
|
||||||
|
frames[id].setSize(width, height)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function removeFrame(id)
|
||||||
|
table.remove(frames, id or #frames)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function moveFrame(id, dir)
|
||||||
|
local f = frames[id]
|
||||||
|
if(f~=nil)then
|
||||||
|
local newId = id+dir
|
||||||
|
if(newId>=1)and(newId<=#frames)then
|
||||||
|
table.remove(frames, id)
|
||||||
|
table.insert(frames, newId, f)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
manager = {
|
||||||
|
updateSize = function(w, h, force)
|
||||||
|
local changed = force==true and true or false
|
||||||
|
if(w > width)then changed = true width = w end
|
||||||
|
if(h > height)then changed = true height = h end
|
||||||
|
if(changed)then
|
||||||
|
for k,v in pairs(frames)do
|
||||||
|
v.setSize(width, height)
|
||||||
|
v.recalculateSize()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
text = function(frame, text, x, y)
|
||||||
|
local f = frames[frame]
|
||||||
|
if(f==nil)then
|
||||||
|
f = addFrame(frame)
|
||||||
|
end
|
||||||
|
f.text(text, x, y)
|
||||||
|
end,
|
||||||
|
|
||||||
|
fg = function(frame, fg, x, y)
|
||||||
|
local f = frames[frame]
|
||||||
|
if(f==nil)then
|
||||||
|
f = addFrame(frame)
|
||||||
|
end
|
||||||
|
f.fg(fg, x, y)
|
||||||
|
end,
|
||||||
|
|
||||||
|
bg = function(frame, bg, x, y)
|
||||||
|
local f = frames[frame]
|
||||||
|
if(f==nil)then
|
||||||
|
f = addFrame(frame)
|
||||||
|
end
|
||||||
|
f.bg(bg, x, y)
|
||||||
|
end,
|
||||||
|
|
||||||
|
blit = function(frame, text, fg, bg, x, y)
|
||||||
|
local f = frames[frame]
|
||||||
|
if(f==nil)then
|
||||||
|
f = addFrame(frame)
|
||||||
|
end
|
||||||
|
f.blit(text, fg, bg, x, y)
|
||||||
|
end,
|
||||||
|
|
||||||
|
setSize = function(w, h)
|
||||||
|
width = w
|
||||||
|
height = h
|
||||||
|
for k,v in pairs(frames)do
|
||||||
|
v.setSize(w, h)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrame = function(id)
|
||||||
|
if(frames[id]~=nil)then
|
||||||
|
return frames[id].getFrame()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrameObjects = function()
|
||||||
|
return frames
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrames = function()
|
||||||
|
local f = {}
|
||||||
|
for k,v in pairs(frames)do
|
||||||
|
local frame = v.getFrame()
|
||||||
|
table.insert(f, frame)
|
||||||
|
end
|
||||||
|
return f
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrameObject = function(id)
|
||||||
|
return frames[id]
|
||||||
|
end,
|
||||||
|
|
||||||
|
addFrame = function(id)
|
||||||
|
local f = frame()
|
||||||
|
if(#frames<=1)then
|
||||||
|
if(metadata.animated==nil)then
|
||||||
|
metadata.animated = true
|
||||||
|
end
|
||||||
|
if(metadata.secondsPerFrame==nil)then
|
||||||
|
metadata.secondsPerFrame = 0.2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
addFrame(id)
|
||||||
|
return f
|
||||||
|
end,
|
||||||
|
|
||||||
|
removeFrame = function(id)
|
||||||
|
removeFrame(id)
|
||||||
|
if(#frames<=1)then
|
||||||
|
if(metadata.animated==nil)then
|
||||||
|
metadata.animated = true
|
||||||
|
end
|
||||||
|
if(metadata.secondsPerFrame==nil)then
|
||||||
|
metadata.secondsPerFrame = 0.2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
moveFrame = moveFrame,
|
||||||
|
|
||||||
|
setFrameData = function(id, key, value)
|
||||||
|
if(frames[id]~=nil)then
|
||||||
|
frames[id].setFrameData(key, value)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrameData = function(id, key)
|
||||||
|
return frames[id]~=nil and frames[id].getFrameData(key)
|
||||||
|
end,
|
||||||
|
|
||||||
|
getSize = function()
|
||||||
|
return width, height
|
||||||
|
end,
|
||||||
|
|
||||||
|
setAnimation = function(anim)
|
||||||
|
metadata.animation = anim
|
||||||
|
end,
|
||||||
|
|
||||||
|
setMetadata = function(key, val)
|
||||||
|
if(val~=nil)then
|
||||||
|
metadata[key] = val
|
||||||
|
else
|
||||||
|
if(type(key)=="table")then
|
||||||
|
metadata = key
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
getMetadata = function(key)
|
||||||
|
return key~=nil and metadata[key] or metadata
|
||||||
|
end,
|
||||||
|
|
||||||
|
createBimg = function()
|
||||||
|
local bimg = {}
|
||||||
|
for k,v in pairs(frames)do
|
||||||
|
local f = v.getFrame()
|
||||||
|
table.insert(bimg, f)
|
||||||
|
end
|
||||||
|
for k,v in pairs(metadata)do
|
||||||
|
bimg[k] = v
|
||||||
|
end
|
||||||
|
bimg.width = width
|
||||||
|
bimg.height = height
|
||||||
|
return bimg
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
if(img~=nil)then
|
||||||
|
for k,v in pairs(img)do
|
||||||
|
if(type(k)=="string")then
|
||||||
|
metadata[k] = v
|
||||||
|
else
|
||||||
|
addFrame(k, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if(metadata.width==nil)or(metadata.height==nil)then
|
||||||
|
for k,v in pairs(frames)do
|
||||||
|
local w, h = v.getSize()
|
||||||
|
if(w>width)then w = width end
|
||||||
|
if(h>height)then h = height end
|
||||||
|
end
|
||||||
|
manager.updateSize(width, height, true)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
addFrame(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return manager
|
||||||
|
end
|
||||||
89
Basalt/libraries/images.lua
Normal file
89
Basalt/libraries/images.lua
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
local sub,floor = string.sub,math.floor
|
||||||
|
|
||||||
|
local function loadNFPAsBimg(path)
|
||||||
|
return {[1]={{}, {}, paintutils.loadImage(path)}}, "bimg"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function loadNFP(path)
|
||||||
|
return paintutils.loadImage(path), "nfp"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function loadBIMG(path)
|
||||||
|
local f = fs.open(path, "rb")
|
||||||
|
local content = textutils.unserialize(f.readAll())
|
||||||
|
f.close()
|
||||||
|
if(content~=nil)then
|
||||||
|
return content, "bimg"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function loadBBF(path)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local function loadBBFAsBimg(path)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local function loadImage(path, f)
|
||||||
|
if(f==nil)then
|
||||||
|
if(path:find(".bimg"))then
|
||||||
|
return loadBIMG(path)
|
||||||
|
elseif(path:find(".bbf"))then
|
||||||
|
return loadBBF(path)
|
||||||
|
else
|
||||||
|
return loadNFP(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- ...
|
||||||
|
end
|
||||||
|
|
||||||
|
local function loadImageAsBimg(path, f)
|
||||||
|
if(f==nil)then
|
||||||
|
if(path:find(".bimg"))then
|
||||||
|
return loadBIMG(path)
|
||||||
|
elseif(path:find(".bbf"))then
|
||||||
|
return loadBBFAsBimg(path)
|
||||||
|
else
|
||||||
|
return loadNFPAsBimg(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function resizeBIMG(source, w, h)
|
||||||
|
local oW, oH = source.width or #source[1][1][1], source.height or #source[1]
|
||||||
|
local newImg = {}
|
||||||
|
for k,v in pairs(source)do
|
||||||
|
if(type(k)=="number")then
|
||||||
|
local frame = {}
|
||||||
|
for y=1, h do
|
||||||
|
local xT,xFG,xBG = "","",""
|
||||||
|
local yR = floor(y / h * oH + 0.5)
|
||||||
|
if(v[yR]~=nil)then
|
||||||
|
for x=1, w do
|
||||||
|
local xR = floor(x / w * oW + 0.5)
|
||||||
|
xT = xT..sub(v[yR][1], xR,xR)
|
||||||
|
xFG = xFG..sub(v[yR][2], xR,xR)
|
||||||
|
xBG = xBG..sub(v[yR][3], xR,xR)
|
||||||
|
end
|
||||||
|
table.insert(frame, {xT, xFG, xBG})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(newImg, k, frame)
|
||||||
|
else
|
||||||
|
newImg[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
newImg.width = w
|
||||||
|
newImg.height = h
|
||||||
|
return newImg
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
loadNFP = loadNFP,
|
||||||
|
loadBIMG = loadBIMG,
|
||||||
|
loadImage = loadImage,
|
||||||
|
resizeBIMG = resizeBIMG,
|
||||||
|
loadImageAsBimg = loadImageAsBimg,
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
local sub = string.sub
|
||||||
|
|
||||||
local splitString = function(str, sep)
|
local splitString = function(str, sep)
|
||||||
if sep == nil then
|
if sep == nil then
|
||||||
sep = "%s"
|
sep = "%s"
|
||||||
@@ -9,6 +11,74 @@ local splitString = function(str, sep)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local relations = {[0] = {8, 4, 3, 6, 5}, {4, 14, 8, 7}, {6, 10, 8, 7}, {9, 11, 8, 0}, {1, 14, 8, 0}, {13, 12, 8, 0}, {2, 10, 8, 0}, {15, 8, 10, 11, 12, 14},
|
||||||
|
{0, 7, 1, 9, 2, 13}, {3, 11, 8, 7}, {2, 6, 7, 15}, {9, 3, 7, 15}, {13, 5, 7, 15}, {5, 12, 8, 7}, {1, 4, 7, 15}, {7, 10, 11, 12, 14}}
|
||||||
|
|
||||||
|
local colourNum, exponents, colourChar = {}, {}, {}
|
||||||
|
for i = 0, 15 do exponents[2^i] = i end
|
||||||
|
do
|
||||||
|
local hex = "0123456789abcdef"
|
||||||
|
for i = 1, 16 do
|
||||||
|
colourNum[hex:sub(i, i)] = i - 1
|
||||||
|
colourNum[i - 1] = hex:sub(i, i)
|
||||||
|
colourChar[hex:sub(i, i)] = 2 ^ (i - 1)
|
||||||
|
colourChar[2 ^ (i - 1)] = hex:sub(i, i)
|
||||||
|
|
||||||
|
local thisRel = relations[i - 1]
|
||||||
|
for i = 1, #thisRel do thisRel[i] = 2 ^ thisRel[i] end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getBestColourMatch(usage)
|
||||||
|
local lastCol = relations[exponents[usage[#usage][1]]]
|
||||||
|
|
||||||
|
for j = 1, #lastCol do
|
||||||
|
local thisRelation = lastCol[j]
|
||||||
|
for i = 1, #usage - 1 do if usage[i][1] == thisRelation then return i end end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function colsToChar(pattern, totals)
|
||||||
|
if not totals then
|
||||||
|
local newPattern = {}
|
||||||
|
totals = {}
|
||||||
|
for i = 1, 6 do
|
||||||
|
local thisVal = pattern[i]
|
||||||
|
local thisTot = totals[thisVal]
|
||||||
|
totals[thisVal], newPattern[i] = thisTot and (thisTot + 1) or 1, thisVal
|
||||||
|
end
|
||||||
|
pattern = newPattern
|
||||||
|
end
|
||||||
|
|
||||||
|
local usage = {}
|
||||||
|
for key, value in pairs(totals) do usage[#usage + 1] = {key, value} end
|
||||||
|
|
||||||
|
if #usage > 1 then
|
||||||
|
-- Reduce the chunk to two colours:
|
||||||
|
while #usage > 2 do
|
||||||
|
table.sort(usage, function (a, b) return a[2] > b[2] end)
|
||||||
|
local matchToInd, usageLen = getBestColourMatch(usage), #usage
|
||||||
|
local matchFrom, matchTo = usage[usageLen][1], usage[matchToInd][1]
|
||||||
|
for i = 1, 6 do if pattern[i] == matchFrom then
|
||||||
|
pattern[i] = matchTo
|
||||||
|
usage[matchToInd][2] = usage[matchToInd][2] + 1
|
||||||
|
end end
|
||||||
|
usage[usageLen] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Convert to character. Adapted from oli414's function:
|
||||||
|
-- http://www.computercraft.info/forums2/index.php?/topic/25340-cc-176-easy-drawing-characters/
|
||||||
|
local data = 128
|
||||||
|
for i = 1, #pattern - 1 do if pattern[i] ~= pattern[6] then data = data + 2^(i-1) end end
|
||||||
|
return string.char(data), colourChar[usage[1][1] == pattern[6] and usage[2][1] or usage[1][1]], colourChar[pattern[6]]
|
||||||
|
else
|
||||||
|
-- Solid colour character:
|
||||||
|
return "\128", colourChar[pattern[1]], colourChar[pattern[1]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getTextHorizontalAlign = function(text, width, textAlign, replaceChar)
|
getTextHorizontalAlign = function(text, width, textAlign, replaceChar)
|
||||||
text = string.sub(text, 1, width)
|
text = string.sub(text, 1, width)
|
||||||
@@ -117,4 +187,36 @@ uuid = function()
|
|||||||
end
|
end
|
||||||
return uuid()
|
return uuid()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
array = function(arraysize, hashsize)
|
||||||
|
return load("return {" .. ("nil,"):rep(arraysize) .. ("[0]=nil,"):rep(hashsize) .. "}")()
|
||||||
|
end,
|
||||||
|
|
||||||
|
shrink = function(image, bgCol)
|
||||||
|
local results, width, height, bgCol = {{}, {}, {}}, 0, #image + #image % 3, bgCol or colours.black
|
||||||
|
for i = 1, #image do if #image[i] > width then width = #image[i] end end
|
||||||
|
|
||||||
|
for y = 0, height - 1, 3 do
|
||||||
|
local cRow, tRow, bRow, counter = {}, {}, {}, 1
|
||||||
|
|
||||||
|
for x = 0, width - 1, 2 do
|
||||||
|
-- Grab a 2x3 chunk:
|
||||||
|
local pattern, totals = {}, {}
|
||||||
|
|
||||||
|
for yy = 1, 3 do for xx = 1, 2 do
|
||||||
|
pattern[#pattern + 1] = (image[y + yy] and image[y + yy][x + xx]) and (image[y + yy][x + xx] == 0 and bgCol or image[y + yy][x + xx]) or bgCol
|
||||||
|
totals[pattern[#pattern]] = totals[pattern[#pattern]] and (totals[pattern[#pattern]] + 1) or 1
|
||||||
|
end end
|
||||||
|
|
||||||
|
cRow[counter], tRow[counter], bRow[counter] = colsToChar(pattern, totals)
|
||||||
|
counter = counter + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
results[1][#results[1] + 1], results[2][#results[2] + 1], results[3][#results[3] + 1] = table.concat(cRow), table.concat(tRow), table.concat(bRow)
|
||||||
|
end
|
||||||
|
|
||||||
|
results.width, results.height = #results[1][1], #results[1]
|
||||||
|
|
||||||
|
return results
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
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
|
||||||
@@ -71,4 +71,4 @@ return function(name)
|
|||||||
|
|
||||||
}
|
}
|
||||||
return setmetatable(object, base)
|
return setmetatable(object, base)
|
||||||
end
|
end
|
||||||
@@ -84,7 +84,7 @@ return function(name)
|
|||||||
|
|
||||||
clear = function(self)
|
clear = function(self)
|
||||||
list = {}
|
list = {}
|
||||||
self:setValue({})
|
self:setValue({}, false)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -101,7 +101,7 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
selectItem = function(self, index)
|
selectItem = function(self, index)
|
||||||
self:setValue(list[index] or {})
|
self:setValue(list[index] or {}, false)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -109,7 +109,7 @@ return function(name)
|
|||||||
setSelectedItem = function(self, bgCol, fgCol, active)
|
setSelectedItem = function(self, bgCol, fgCol, active)
|
||||||
itemSelectedBG = bgCol or self.bgColor
|
itemSelectedBG = bgCol or self.bgColor
|
||||||
itemSelectedFG = fgCol or self.fgColor
|
itemSelectedFG = fgCol or self.fgColor
|
||||||
selectionColorActive = active
|
selectionColorActive = active~=nil and active
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -120,6 +120,10 @@ return function(name)
|
|||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
getDropdownSize = function(self)
|
||||||
|
return dropdownW, dropdownH
|
||||||
|
end,
|
||||||
|
|
||||||
mouseHandler = function(self, button, x, y)
|
mouseHandler = function(self, button, x, y)
|
||||||
if (isOpened) then
|
if (isOpened) then
|
||||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
|
|||||||
214
Basalt/objects/Graphic.lua
Normal file
214
Basalt/objects/Graphic.lua
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
local Object = require("Object")
|
||||||
|
local tHex = require("tHex")
|
||||||
|
local xmlValue = require("utils").getValueFromXML
|
||||||
|
local bimgLib = require("bimg")
|
||||||
|
local images = require("images")
|
||||||
|
|
||||||
|
local sub,len,max,min = string.sub,string.len,math.max,math.min
|
||||||
|
|
||||||
|
return function(name)
|
||||||
|
-- Graphic
|
||||||
|
local base = Object(name)
|
||||||
|
local objectType = "Graphic"
|
||||||
|
local imgData = bimgLib()
|
||||||
|
local bimgFrame = imgData.getFrameObject(1)
|
||||||
|
local bimg
|
||||||
|
local selectedFrame = 1
|
||||||
|
base:setZIndex(5)
|
||||||
|
|
||||||
|
local xOffset, yOffset = 0, 0
|
||||||
|
|
||||||
|
local object = {
|
||||||
|
getType = function(self)
|
||||||
|
return objectType
|
||||||
|
end;
|
||||||
|
|
||||||
|
setOffset = function(self, _x, _y, rel)
|
||||||
|
if(rel)then
|
||||||
|
xOffset = xOffset + _x or 0
|
||||||
|
yOffset = yOffset + _y or 0
|
||||||
|
else
|
||||||
|
xOffset = _x or xOffset
|
||||||
|
yOffset = _y or yOffset
|
||||||
|
end
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
getOffset = function(self)
|
||||||
|
return xOffset,yOffset
|
||||||
|
end,
|
||||||
|
|
||||||
|
setValuesByXMLData = function(self, data)
|
||||||
|
base.setValuesByXMLData(self, data)
|
||||||
|
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
selectFrame = function(self, id)
|
||||||
|
if(imgData.getFrameObject(id)==nil)then
|
||||||
|
imgData.addFrame(id)
|
||||||
|
end
|
||||||
|
bimgFrame = imgData.getFrameObject(id)
|
||||||
|
bimg = bimgFrame.getImage(id)
|
||||||
|
selectedFrame = id
|
||||||
|
self:updateDraw()
|
||||||
|
end,
|
||||||
|
|
||||||
|
addFrame = function(self, id)
|
||||||
|
imgData.addFrame(id)
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrameMetadata = function(self, id, key)
|
||||||
|
return imgData.getFrameData(id, key)
|
||||||
|
end,
|
||||||
|
|
||||||
|
setFrameMetadata = function(self, id, key, val)
|
||||||
|
imgData.setFrameData(id, key, val)
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
getMetadata = function(self, key)
|
||||||
|
return imgData.getMetadata(key)
|
||||||
|
end,
|
||||||
|
|
||||||
|
setMetadata = function(self, key, value)
|
||||||
|
return imgData.setMetadata(key, value)
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrame = function(self, id)
|
||||||
|
return imgData.getFrame(id)
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrameObject = function(self, id)
|
||||||
|
return imgData.getFrameObject(id)
|
||||||
|
end,
|
||||||
|
|
||||||
|
removeFrame = function(self, id)
|
||||||
|
imgData.removeFrame(id)
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
moveFrame = function(self, id, dir)
|
||||||
|
imgData.moveFrame(id, dir)
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrames = function(self)
|
||||||
|
return imgData.getFrames()
|
||||||
|
end,
|
||||||
|
|
||||||
|
getFrameCount = function(self)
|
||||||
|
return #imgData.getFrames()
|
||||||
|
end,
|
||||||
|
|
||||||
|
getSelectedFrame = function(self)
|
||||||
|
return selectedFrame
|
||||||
|
end,
|
||||||
|
|
||||||
|
blit = function(self, text, fg, bg, _x, _y)
|
||||||
|
x = _x or x
|
||||||
|
y = _y or y
|
||||||
|
bimgFrame.blit(text, fg, bg, x, y)
|
||||||
|
bimg = bimgFrame.getImage()
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
setText = function(self, text, _x, _y)
|
||||||
|
x = _x or x
|
||||||
|
y = _y or y
|
||||||
|
bimgFrame.text(text, x, y)
|
||||||
|
bimg = bimgFrame.getImage()
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
setBg = function(self, bg, _x, _y)
|
||||||
|
x = _x or x
|
||||||
|
y = _y or y
|
||||||
|
bimgFrame.bg(bg, x, y)
|
||||||
|
bimg = bimgFrame.getImage()
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
setFg = function(self, fg, _x, _y)
|
||||||
|
x = _x or x
|
||||||
|
y = _y or y
|
||||||
|
bimgFrame.fg(fg, x, y)
|
||||||
|
bimg = bimgFrame.getImage()
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
getImageSize = function(self)
|
||||||
|
return imgData.getSize()
|
||||||
|
end,
|
||||||
|
|
||||||
|
setImageSize = function(self, w, h)
|
||||||
|
imgData.setSize(w, h)
|
||||||
|
bimg = bimgFrame.getImage()
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
resizeImage = function(self, w, h)
|
||||||
|
local newBimg = images.resizeBIMG(imgData.createBimg(), w, h)
|
||||||
|
imgData = bimgLib(newBimg)
|
||||||
|
selectedFrame = 1
|
||||||
|
bimgFrame = imgData.getFrameObject(1)
|
||||||
|
bimg = bimgFrame.getImage()
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
loadImage = function(self, path)
|
||||||
|
if(fs.exists(path))then
|
||||||
|
local newBimg = images.loadBIMG(path)
|
||||||
|
imgData = bimgLib(newBimg)
|
||||||
|
selectedFrame = 1
|
||||||
|
bimgFrame = imgData.getFrameObject(1)
|
||||||
|
bimg = bimgFrame.getImage()
|
||||||
|
self:updateDraw()
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
clear = function(self)
|
||||||
|
imgData = bimgLib()
|
||||||
|
bimg = nil
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
getImage = function(self)
|
||||||
|
return imgData.createBimg()
|
||||||
|
end,
|
||||||
|
|
||||||
|
draw = function(self)
|
||||||
|
if (base.draw(self)) then
|
||||||
|
if (self.parent ~= nil) then
|
||||||
|
local obx, oby = self:getAnchorPosition()
|
||||||
|
local w,h = self:getSize()
|
||||||
|
if(bimg~=nil)then
|
||||||
|
for k,v in pairs(bimg)do
|
||||||
|
if(k<=h-yOffset)and(k+yOffset>=1)then
|
||||||
|
self.parent:blit(obx+xOffset, oby+k-1+yOffset, v[1], v[2], v[3])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
init = function(self)
|
||||||
|
if(base.init(self))then
|
||||||
|
self.bgColor = self.parent:getTheme("GraphicBG")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
return setmetatable(object, base)
|
||||||
|
end
|
||||||
@@ -1,197 +1,158 @@
|
|||||||
local Object = require("Object")
|
local Object = require("Object")
|
||||||
local xmlValue = require("utils").getValueFromXML
|
local xmlValue = require("utils").getValueFromXML
|
||||||
|
local images = require("images")
|
||||||
|
|
||||||
|
local unpack,sub = table.unpack,string.sub
|
||||||
return function(name)
|
return function(name)
|
||||||
-- Image
|
-- Image
|
||||||
local base = Object(name)
|
local base = Object(name)
|
||||||
local objectType = "Image"
|
local objectType = "Image"
|
||||||
base:setZIndex(2)
|
base:setZIndex(2)
|
||||||
|
local originalImage
|
||||||
local image
|
local image
|
||||||
local shrinkedImage
|
local curFrame = 1
|
||||||
local imageGotShrinked = false
|
local infinitePlay = false
|
||||||
|
local animTimer
|
||||||
|
local usePalette = false
|
||||||
|
|
||||||
local function shrink()
|
base.width = 24
|
||||||
-- shrinkSystem is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/
|
base.height = 8
|
||||||
local relations = { [0] = { 8, 4, 3, 6, 5 }, { 4, 14, 8, 7 }, { 6, 10, 8, 7 }, { 9, 11, 8, 0 }, { 1, 14, 8, 0 }, { 13, 12, 8, 0 }, { 2, 10, 8, 0 }, { 15, 8, 10, 11, 12, 14 },
|
|
||||||
{ 0, 7, 1, 9, 2, 13 }, { 3, 11, 8, 7 }, { 2, 6, 7, 15 }, { 9, 3, 7, 15 }, { 13, 5, 7, 15 }, { 5, 12, 8, 7 }, { 1, 4, 7, 15 }, { 7, 10, 11, 12, 14 } }
|
|
||||||
|
|
||||||
local colourNum, exponents, colourChar = {}, {}, {}
|
local function getPalette(id)
|
||||||
for i = 0, 15 do
|
if(originalImage~=nil)then
|
||||||
exponents[2 ^ i] = i
|
local p = {}
|
||||||
end
|
for k,v in pairs(colors)do
|
||||||
do
|
if(type(v)=="number")then
|
||||||
local hex = "0123456789abcdef"
|
p[k] = {term.nativePaletteColor(v)}
|
||||||
for i = 1, 16 do
|
|
||||||
colourNum[hex:sub(i, i)] = i - 1
|
|
||||||
colourNum[i - 1] = hex:sub(i, i)
|
|
||||||
colourChar[hex:sub(i, i)] = 2 ^ (i - 1)
|
|
||||||
colourChar[2 ^ (i - 1)] = hex:sub(i, i)
|
|
||||||
|
|
||||||
local thisRel = relations[i - 1]
|
|
||||||
for i = 1, #thisRel do
|
|
||||||
thisRel[i] = 2 ^ thisRel[i]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if(originalImage.palette~=nil)then
|
||||||
|
for k,v in pairs(originalImage.palette)do
|
||||||
local function getBestColourMatch(usage)
|
p[k] = tonumber(v)
|
||||||
local lastCol = relations[exponents[usage[#usage][1]]]
|
|
||||||
|
|
||||||
for j = 1, #lastCol do
|
|
||||||
local thisRelation = lastCol[j]
|
|
||||||
for i = 1, #usage - 1 do
|
|
||||||
if usage[i][1] == thisRelation then
|
|
||||||
return i
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if(originalImage[id]~=nil)and(originalImage[id].palette~=nil)then
|
||||||
return 1
|
for k,v in pairs(originalImage[id].palette)do
|
||||||
end
|
p[k] = tonumber(v)
|
||||||
|
|
||||||
local function colsToChar(pattern, totals)
|
|
||||||
if not totals then
|
|
||||||
local newPattern = {}
|
|
||||||
totals = {}
|
|
||||||
for i = 1, 6 do
|
|
||||||
local thisVal = pattern[i]
|
|
||||||
local thisTot = totals[thisVal]
|
|
||||||
totals[thisVal], newPattern[i] = thisTot and (thisTot + 1) or 1, thisVal
|
|
||||||
end
|
end
|
||||||
pattern = newPattern
|
|
||||||
end
|
|
||||||
|
|
||||||
local usage = {}
|
|
||||||
for key, value in pairs(totals) do
|
|
||||||
usage[#usage + 1] = { key, value }
|
|
||||||
end
|
|
||||||
|
|
||||||
if #usage > 1 then
|
|
||||||
-- Reduce the chunk to two colours:
|
|
||||||
while #usage > 2 do
|
|
||||||
table.sort(usage, function(a, b)
|
|
||||||
return a[2] > b[2]
|
|
||||||
end)
|
|
||||||
local matchToInd, usageLen = getBestColourMatch(usage), #usage
|
|
||||||
local matchFrom, matchTo = usage[usageLen][1], usage[matchToInd][1]
|
|
||||||
for i = 1, 6 do
|
|
||||||
if pattern[i] == matchFrom then
|
|
||||||
pattern[i] = matchTo
|
|
||||||
usage[matchToInd][2] = usage[matchToInd][2] + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
usage[usageLen] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Convert to character. Adapted from oli414's function:
|
|
||||||
-- http://www.computercraft.info/forums2/index.php?/topic/25340-cc-176-easy-drawing-characters/
|
|
||||||
local data = 128
|
|
||||||
for i = 1, #pattern - 1 do
|
|
||||||
if pattern[i] ~= pattern[6] then
|
|
||||||
data = data + 2 ^ (i - 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return string.char(data), colourChar[usage[1][1] == pattern[6] and usage[2][1] or usage[1][1]], colourChar[pattern[6]]
|
|
||||||
else
|
|
||||||
-- Solid colour character:
|
|
||||||
return "\128", colourChar[pattern[1]], colourChar[pattern[1]]
|
|
||||||
end
|
end
|
||||||
|
return p
|
||||||
end
|
end
|
||||||
|
|
||||||
local results, width, height, bgCol = { {}, {}, {} }, 0, #image + #image % 3, base.bgColor or colors.black
|
|
||||||
for i = 1, #image do
|
|
||||||
if #image[i] > width then
|
|
||||||
width = #image[i]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for y = 0, height - 1, 3 do
|
|
||||||
local cRow, tRow, bRow, counter = {}, {}, {}, 1
|
|
||||||
|
|
||||||
for x = 0, width - 1, 2 do
|
|
||||||
-- Grab a 2x3 chunk:
|
|
||||||
local pattern, totals = {}, {}
|
|
||||||
|
|
||||||
for yy = 1, 3 do
|
|
||||||
for xx = 1, 2 do
|
|
||||||
pattern[#pattern + 1] = (image[y + yy] and image[y + yy][x + xx]) and (image[y + yy][x + xx] == 0 and bgCol or image[y + yy][x + xx]) or bgCol
|
|
||||||
totals[pattern[#pattern]] = totals[pattern[#pattern]] and (totals[pattern[#pattern]] + 1) or 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cRow[counter], tRow[counter], bRow[counter] = colsToChar(pattern, totals)
|
|
||||||
counter = counter + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
results[1][#results[1] + 1], results[2][#results[2] + 1], results[3][#results[3] + 1] = table.concat(cRow), table.concat(tRow), table.concat(bRow)
|
|
||||||
end
|
|
||||||
|
|
||||||
results.width, results.height = #results[1][1], #results[1]
|
|
||||||
|
|
||||||
shrinkedImage = results
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local object = {
|
local object = {
|
||||||
init = function(self)
|
init = function(self)
|
||||||
self.bgColor = self.parent:getTheme("ImageBG")
|
if(base.init(self))then
|
||||||
|
self.bgColor = self.parent:getTheme("ImageBG")
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
getType = function(self)
|
getType = function(self)
|
||||||
return objectType
|
return objectType
|
||||||
end;
|
end;
|
||||||
|
|
||||||
loadImage = function(self, path)
|
loadImage = function(self, path, f)
|
||||||
image = paintutils.loadImage(path)
|
if not(fs.exists(path))then error("No valid path: "..path) end
|
||||||
imageGotShrinked = false
|
originalImage = images.loadImageAsBimg(path, f)
|
||||||
|
curFrame = 1
|
||||||
|
image = originalImage
|
||||||
|
if(animTimer~=nil)then
|
||||||
|
os.cancelTimer(animTimer)
|
||||||
|
end
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
setImage = function(self, data)
|
||||||
shrink = function(self)
|
originalImage = data
|
||||||
shrink()
|
image = originalImage
|
||||||
imageGotShrinked = true
|
curFrame = 1
|
||||||
|
if(animTimer~=nil)then
|
||||||
|
os.cancelTimer(animTimer)
|
||||||
|
end
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end,
|
||||||
|
|
||||||
|
usePalette = function(self, use)
|
||||||
|
usePalette = use~=nil and use or true
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
play = function(self, inf)
|
||||||
|
if(originalImage.animated)then
|
||||||
|
local t = originalImage[curFrame].duration or originalImage.secondsPerFrame or 0.2
|
||||||
|
self.parent:addEvent("other_event", self)
|
||||||
|
animTimer = os.startTimer(t)
|
||||||
|
infinitePlay = inf or false
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
selectFrame = function(self, fr)
|
||||||
|
if(originalImage[fr]~=nil)then
|
||||||
|
curFrame = fr
|
||||||
|
if(animTimer~=nil)then
|
||||||
|
os.cancelTimer(animTimer)
|
||||||
|
end
|
||||||
|
self:updateDraw()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
eventHandler = function(self, event, timerId, ...)
|
||||||
|
base.eventHandler(self, event, timerId, ...)
|
||||||
|
if(event=="timer")then
|
||||||
|
if(timerId==animTimer)then
|
||||||
|
if(originalImage[curFrame+1]~=nil)then
|
||||||
|
curFrame = curFrame + 1
|
||||||
|
local t = originalImage[curFrame].duration or originalImage.secondsPerFrame or 0.2
|
||||||
|
animTimer = os.startTimer(t)
|
||||||
|
else
|
||||||
|
if(infinitePlay)then
|
||||||
|
curFrame = 1
|
||||||
|
local t = originalImage[curFrame].duration or originalImage.secondsPerFrame or 0.2
|
||||||
|
animTimer = os.startTimer(t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:updateDraw()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
getMetadata = function(self, key)
|
||||||
|
return originalImage[key]
|
||||||
|
end,
|
||||||
|
|
||||||
|
getImageSize = function(self)
|
||||||
|
return originalImage.width, originalImage.height
|
||||||
|
end,
|
||||||
|
|
||||||
|
resizeImage = function(self, w, h)
|
||||||
|
image = images.resizeBIMG(originalImage, w, h)
|
||||||
|
self:updateDraw()
|
||||||
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
setValuesByXMLData = function(self, data)
|
setValuesByXMLData = function(self, data)
|
||||||
base.setValuesByXMLData(self, data)
|
base.setValuesByXMLData(self, data)
|
||||||
if(xmlValue("shrink", data)~=nil)then if(xmlValue("shrink", data))then self:shrink() end end
|
|
||||||
if(xmlValue("path", data)~=nil)then self:loadImage(xmlValue("path", data)) end
|
if(xmlValue("path", data)~=nil)then self:loadImage(xmlValue("path", data)) end
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
|
||||||
draw = function(self)
|
draw = function(self)
|
||||||
if (base.draw(self)) then
|
if (base.draw(self)) then
|
||||||
if (self.parent ~= nil) then
|
if (image ~= nil) then
|
||||||
if (image ~= nil) then
|
if(usePalette)then
|
||||||
local obx, oby = self:getAnchorPosition()
|
self:getBaseFrame():setThemeColor(getPalette(curFrame))
|
||||||
local w,h = self:getSize()
|
end
|
||||||
if (imageGotShrinked) then
|
local obx, oby = self:getAnchorPosition()
|
||||||
-- this is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/
|
local w,h = self:getSize()
|
||||||
local t, tC, bC = shrinkedImage[1], shrinkedImage[2], shrinkedImage[3]
|
for y,v in ipairs(image[curFrame])do
|
||||||
for i = 1, shrinkedImage.height do
|
local t, f, b = unpack(v)
|
||||||
local tI = t[i]
|
t = sub(t, 1,w)
|
||||||
if type(tI) == "string" then
|
f = sub(f, 1,w)
|
||||||
self.parent:setText(obx, oby + i - 1, tI)
|
b = sub(b, 1,w)
|
||||||
self.parent:setFG(obx, oby + i - 1, tC[i])
|
self.parent:blit(obx, oby+y-1, t, f, b)
|
||||||
self.parent:setBG(obx, oby + i - 1, bC[i])
|
if(y==h)then break end
|
||||||
elseif type(tI) == "table" then
|
|
||||||
self.parent:setText(obx, oby + i - 1, tI[2])
|
|
||||||
self.parent:setFG(obx, oby + i - 1, tC[i])
|
|
||||||
self.parent:setBG(obx, oby + i - 1, bC[i])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for yPos = 1, math.min(#image, h) do
|
|
||||||
local line = image[yPos]
|
|
||||||
for xPos = 1, math.min(#line, w) do
|
|
||||||
if line[xPos] > 0 then
|
|
||||||
self.parent:drawBackgroundBox(obx + xPos - 1, oby + yPos - 1, 1, 1, line[xPos])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ return function(name)
|
|||||||
setValue = function(self, val)
|
setValue = function(self, val)
|
||||||
base.setValue(self, tostring(val))
|
base.setValue(self, tostring(val))
|
||||||
if not (internalValueChange) then
|
if not (internalValueChange) then
|
||||||
|
textX = tostring(val):len() + 1
|
||||||
|
wIndex = math.max(1, textX-self:getWidth()+1)
|
||||||
if(self:isFocused())then
|
if(self:isFocused())then
|
||||||
textX = tostring(val):len() + 1
|
|
||||||
wIndex = math.max(1, textX-self:getWidth()+1)
|
|
||||||
local obx, oby = self:getAnchorPosition()
|
local obx, oby = self:getAnchorPosition()
|
||||||
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self:getHeight()/2), self.fgColor)
|
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self:getHeight()/2), self.fgColor)
|
||||||
end
|
end
|
||||||
@@ -202,12 +202,15 @@ return function(name)
|
|||||||
if (text:len() < inputLimit or inputLimit <= 0) then
|
if (text:len() < inputLimit or inputLimit <= 0) then
|
||||||
if (inputType == "number") then
|
if (inputType == "number") then
|
||||||
local cache = text
|
local cache = text
|
||||||
if (#text==0 and char == "-") or (char == ".") or (tonumber(char) ~= nil) then
|
if (textX==1 and char == "-") or (char == ".") or (tonumber(char) ~= nil) then
|
||||||
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
|
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
|
||||||
textX = textX + 1
|
textX = textX + 1
|
||||||
end
|
if(char==".")or(char=="-")and(#text>0)then
|
||||||
if (tonumber(base.getValue()) == nil) then
|
if (tonumber(base.getValue()) == nil) then
|
||||||
--self:setValue(cache)
|
self:setValue(cache)
|
||||||
|
textX = textX - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
|
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
|
||||||
@@ -267,44 +270,43 @@ return function(name)
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
eventHandler = function(self, event, paste, p2, p3, p4)
|
eventHandler = function(self, event, paste, ...)
|
||||||
if(base.eventHandler(self, event, paste, p2, p3, p4))then
|
base.eventHandler(self, event, paste, ...)
|
||||||
if(event=="paste")then
|
if(event=="paste")then
|
||||||
if(self:isFocused())then
|
if(self:isFocused())then
|
||||||
local text = base.getValue()
|
local text = base.getValue()
|
||||||
local w, h = self:getSize()
|
local w, h = self:getSize()
|
||||||
internalValueChange = true
|
internalValueChange = true
|
||||||
if (inputType == "number") then
|
if (inputType == "number") then
|
||||||
local cache = text
|
local cache = text
|
||||||
if (paste == ".") or (tonumber(paste) ~= nil) then
|
if (paste == ".") or (tonumber(paste) ~= nil) then
|
||||||
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
|
|
||||||
textX = textX + paste:len()
|
|
||||||
end
|
|
||||||
if (tonumber(base.getValue()) == nil) then
|
|
||||||
self:setValue(cache)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
|
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
|
||||||
textX = textX + paste:len()
|
textX = textX + paste:len()
|
||||||
end
|
end
|
||||||
if (textX >= w + wIndex) then
|
if (tonumber(base.getValue()) == nil) then
|
||||||
wIndex = (textX+1)-w
|
self:setValue(cache)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
local obx, oby = self:getAnchorPosition()
|
self:setValue(text:sub(1, textX - 1) .. paste .. text:sub(textX, text:len()))
|
||||||
local val = tostring(base.getValue())
|
textX = textX + paste:len()
|
||||||
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
|
|
||||||
|
|
||||||
local x = self:getX()
|
|
||||||
if (cursorX > x + w - 1) then
|
|
||||||
cursorX = x + w - 1
|
|
||||||
end
|
|
||||||
if (self.parent ~= nil) then
|
|
||||||
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
|
||||||
end
|
|
||||||
self:updateDraw()
|
|
||||||
internalValueChange = false
|
|
||||||
end
|
end
|
||||||
|
if (textX >= w + wIndex) then
|
||||||
|
wIndex = (textX+1)-w
|
||||||
|
end
|
||||||
|
|
||||||
|
local obx, oby = self:getAnchorPosition()
|
||||||
|
local val = tostring(base.getValue())
|
||||||
|
local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1)
|
||||||
|
|
||||||
|
local x = self:getX()
|
||||||
|
if (cursorX > x + w - 1) then
|
||||||
|
cursorX = x + w - 1
|
||||||
|
end
|
||||||
|
if (self.parent ~= nil) then
|
||||||
|
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||||
|
end
|
||||||
|
self:updateDraw()
|
||||||
|
internalValueChange = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ return function(name)
|
|||||||
text = tostring(text)
|
text = tostring(text)
|
||||||
base:setValue(text)
|
base:setValue(text)
|
||||||
if (autoSize) then
|
if (autoSize) then
|
||||||
if(text:len()+self:getX()>self.parent:getWidth())then
|
local xOffset = self.parent:getOffset()
|
||||||
local newW = self.parent:getWidth() - self:getX()
|
if(text:len()+self:getX()>self.parent:getWidth()+xOffset)then
|
||||||
|
local newW = self.parent:getWidth()+xOffset - self:getX()
|
||||||
base.setSize(self, newW, #createText(text, newW))
|
base.setSize(self, newW, #createText(text, newW))
|
||||||
else
|
else
|
||||||
base.setSize(self, text:len(), 1)
|
base.setSize(self, text:len(), 1)
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ return function(name)
|
|||||||
|
|
||||||
addItem = function(self, text, bgCol, fgCol, ...)
|
addItem = function(self, text, bgCol, fgCol, ...)
|
||||||
table.insert(list, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
|
table.insert(list, { text = text, bgCol = bgCol or self.bgColor, fgCol = fgCol or self.fgColor, args = { ... } })
|
||||||
if (#list == 1) then
|
if (#list <= 1) then
|
||||||
self:setValue(list[1])
|
self:setValue(list[1], false)
|
||||||
end
|
end
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
@@ -66,7 +66,7 @@ return function(name)
|
|||||||
|
|
||||||
clear = function(self)
|
clear = function(self)
|
||||||
list = {}
|
list = {}
|
||||||
self:setValue({})
|
self:setValue({}, false)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -83,7 +83,7 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
selectItem = function(self, index)
|
selectItem = function(self, index)
|
||||||
self:setValue(list[index] or {})
|
self:setValue(list[index] or {}, false)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ return function(name)
|
|||||||
|
|
||||||
clear = function(self)
|
clear = function(self)
|
||||||
list = {}
|
list = {}
|
||||||
self:setValue({})
|
self:setValue({}, false)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -142,7 +142,7 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
selectItem = function(self, index)
|
selectItem = function(self, index)
|
||||||
self:setValue(list[index] or {})
|
self:setValue(list[index] or {}, false)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ return function(name, parent)
|
|||||||
pWindow.setTextColor(self.fgColor)
|
pWindow.setTextColor(self.fgColor)
|
||||||
pWindow.basalt_setVisible(true)
|
pWindow.basalt_setVisible(true)
|
||||||
|
|
||||||
--resumeProcess(self)
|
resumeProcess(self)
|
||||||
paused = false
|
paused = false
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
self.parent:addEvent("mouse_click", self)
|
self.parent:addEvent("mouse_click", self)
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ return function(name)
|
|||||||
|
|
||||||
clear = function(self)
|
clear = function(self)
|
||||||
list = {}
|
list = {}
|
||||||
self:setValue({})
|
self:setValue({}, false)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -94,7 +94,7 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
selectItem = function(self, index)
|
selectItem = function(self, index)
|
||||||
self:setValue(list[index] or {})
|
self:setValue(list[index] or {}, false)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|||||||
@@ -1,35 +1,101 @@
|
|||||||
local Object = require("Object")
|
local Object = require("Object")
|
||||||
local tHex = require("tHex")
|
local tHex = require("tHex")
|
||||||
local log = require("basaltLogs")
|
|
||||||
local xmlValue = require("utils").getValueFromXML
|
local xmlValue = require("utils").getValueFromXML
|
||||||
|
local log = require("basaltLogs")
|
||||||
|
|
||||||
local rep = string.rep
|
local rep,find,gmatch,sub,len = string.rep,string.find,string.gmatch,string.sub,string.len
|
||||||
|
|
||||||
return function(name)
|
return function(name)
|
||||||
local base = Object(name)
|
local base = Object(name)
|
||||||
local objectType = "Textfield"
|
local objectType = "Textfield"
|
||||||
local hIndex, wIndex, textX, textY = 1, 1, 1, 1
|
local hIndex, wIndex, textX, textY = 1, 1, 1, 1
|
||||||
|
|
||||||
local lines = { "" }
|
local lines = { " " }
|
||||||
local bgLines = { "" }
|
local bgLines = { "" }
|
||||||
local fgLines = { "" }
|
local fgLines = { "" }
|
||||||
local keyWords = { }
|
local keyWords = { }
|
||||||
local rules = { }
|
local rules = { }
|
||||||
|
|
||||||
|
local startSelX,endSelX,startSelY,endSelY
|
||||||
|
|
||||||
|
local selectionBG,selectionFG = colors.lightBlue,colors.black
|
||||||
|
|
||||||
base.width = 30
|
base.width = 30
|
||||||
base.height = 12
|
base.height = 12
|
||||||
base:setZIndex(5)
|
base:setZIndex(5)
|
||||||
|
|
||||||
|
local function isSelected()
|
||||||
|
if(startSelX~=nil)and(endSelX~=nil)and(startSelY~=nil)and(endSelY~=nil)then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getSelectionCoordinates()
|
||||||
|
local sx,ex,sy,ey
|
||||||
|
if(isSelected())then
|
||||||
|
if(startSelX>endSelX)then
|
||||||
|
sx,ex = endSelX,startSelX
|
||||||
|
else
|
||||||
|
sx,ex = startSelX,endSelX
|
||||||
|
end
|
||||||
|
if(startSelY>endSelY)then
|
||||||
|
sy,ey = endSelY,startSelY
|
||||||
|
else
|
||||||
|
sy,ey = startSelY,endSelY
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return sx,ex,sy,ey
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getSelection()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local function removeSelection(self)
|
||||||
|
local sx,ex,sy,ey = getSelectionCoordinates(self)
|
||||||
|
for n=ey,sy,-1 do
|
||||||
|
if(n==sy)or(n==ey)then
|
||||||
|
local l = lines[n]
|
||||||
|
local b = bgLines[n]
|
||||||
|
local f = fgLines[n]
|
||||||
|
if(n==sy)and(n==ey)then
|
||||||
|
l = l:sub(1,sx-1)..l:sub(ex+1,l:len())
|
||||||
|
b = b:sub(1,sx-1)..b:sub(ex+1,b:len())
|
||||||
|
f = f:sub(1,sx-1)..f:sub(ex+1,f:len())
|
||||||
|
elseif(n==sx)then
|
||||||
|
l = l:sub(1, sx)
|
||||||
|
b = b:sub(1, sx)
|
||||||
|
f = f:sub(1, sx)
|
||||||
|
elseif(n==sy)then
|
||||||
|
l = l:sub(ex, l:len())
|
||||||
|
b = b:sub(ex, b:len())
|
||||||
|
f = f:sub(ex, f:len())
|
||||||
|
end
|
||||||
|
lines[n] = l
|
||||||
|
bgLines[n] = b
|
||||||
|
fgLines[n] = f
|
||||||
|
else
|
||||||
|
table.remove(lines, n)
|
||||||
|
table.remove(bgLines, n)
|
||||||
|
table.remove(fgLines, n)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
textX,textY = startSelX,startSelY
|
||||||
|
startSelX,endSelX,startSelY,endSelY = nil,nil,nil,nil
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
local function stringGetPositions(str, word)
|
local function stringGetPositions(str, word)
|
||||||
local pos = {}
|
local pos = {}
|
||||||
if(str:len()>0)then
|
if(str:len()>0)then
|
||||||
for w in string.gmatch(str, word)do
|
for w in gmatch(str, word)do
|
||||||
local s, e = string.find(str, w)
|
local s, e = find(str, w)
|
||||||
if(s~=nil)and(e~=nil)then
|
if(s~=nil)and(e~=nil)then
|
||||||
table.insert(pos,s)
|
table.insert(pos,s)
|
||||||
table.insert(pos,e)
|
table.insert(pos,e)
|
||||||
local startL = string.sub(str, 1, (s-1))
|
local startL = sub(str, 1, (s-1))
|
||||||
local endL = string.sub(str, e+1, str:len())
|
local endL = sub(str, e+1, str:len())
|
||||||
str = startL..(":"):rep(w:len())..endL
|
str = startL..(":"):rep(w:len())..endL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -150,9 +216,10 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
clear = function(self)
|
clear = function(self)
|
||||||
lines = {""}
|
lines = {" "}
|
||||||
bgLines = {""}
|
bgLines = {""}
|
||||||
fgLines = {""}
|
fgLines = {""}
|
||||||
|
startSelX,endSelX,startSelY,endSelY = nil,nil,nil,nil
|
||||||
hIndex, wIndex, textX, textY = 1, 1, 1, 1
|
hIndex, wIndex, textX, textY = 1, 1, 1, 1
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
@@ -227,9 +294,14 @@ return function(name)
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
removeLine = function(self, index)
|
removeLine = function(self, index)
|
||||||
table.remove(lines, index or #lines)
|
if(#lines>1)then
|
||||||
if (#lines <= 0) then
|
table.remove(lines, index or #lines)
|
||||||
table.insert(lines, "")
|
table.remove(bgLines, index or #bgLines)
|
||||||
|
table.remove(fgLines, index or #fgLines)
|
||||||
|
else
|
||||||
|
lines = {" "}
|
||||||
|
bgLines = {""}
|
||||||
|
fgLines = {""}
|
||||||
end
|
end
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return self
|
return self
|
||||||
@@ -311,17 +383,21 @@ return function(name)
|
|||||||
|
|
||||||
if (key == keys.delete) then
|
if (key == keys.delete) then
|
||||||
-- on delete
|
-- on delete
|
||||||
if (textX > lines[textY]:len()) then
|
if(isSelected())then
|
||||||
if (lines[textY + 1] ~= nil) then
|
removeSelection(self)
|
||||||
lines[textY] = lines[textY] .. lines[textY + 1]
|
|
||||||
table.remove(lines, textY + 1)
|
|
||||||
table.remove(bgLines, textY + 1)
|
|
||||||
table.remove(fgLines, textY + 1)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
lines[textY] = lines[textY]:sub(1, textX - 1) .. lines[textY]:sub(textX + 1, lines[textY]:len())
|
if (textX > lines[textY]:len()) then
|
||||||
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. fgLines[textY]:sub(textX + 1, fgLines[textY]:len())
|
if (lines[textY + 1] ~= nil) then
|
||||||
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. bgLines[textY]:sub(textX + 1, bgLines[textY]:len())
|
lines[textY] = lines[textY] .. lines[textY + 1]
|
||||||
|
table.remove(lines, textY + 1)
|
||||||
|
table.remove(bgLines, textY + 1)
|
||||||
|
table.remove(fgLines, textY + 1)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
lines[textY] = lines[textY]:sub(1, textX - 1) .. lines[textY]:sub(textX + 1, lines[textY]:len())
|
||||||
|
fgLines[textY] = fgLines[textY]:sub(1, textX - 1) .. fgLines[textY]:sub(textX + 1, fgLines[textY]:len())
|
||||||
|
bgLines[textY] = bgLines[textY]:sub(1, textX - 1) .. bgLines[textY]:sub(textX + 1, bgLines[textY]:len())
|
||||||
|
end
|
||||||
end
|
end
|
||||||
updateColors(self)
|
updateColors(self)
|
||||||
end
|
end
|
||||||
@@ -430,9 +506,14 @@ return function(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not((obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h)) then
|
||||||
|
wIndex = math.max(1, lines[textY]:len()-w+1)
|
||||||
|
hIndex = math.max(1, textY - h + 1)
|
||||||
|
end
|
||||||
|
|
||||||
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
|
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
|
||||||
if (cursorX > self.x + w - 1) then
|
if (cursorX > self:getX() + w - 1) then
|
||||||
cursorX = self.x + w - 1
|
cursorX = self:getX() + w - 1
|
||||||
end
|
end
|
||||||
local cursorY = (textY - hIndex < h and textY - hIndex or textY - hIndex - 1)
|
local cursorY = (textY - hIndex < h and textY - hIndex or textY - hIndex - 1)
|
||||||
if (cursorX < 1) then
|
if (cursorX < 1) then
|
||||||
@@ -458,14 +539,22 @@ return function(name)
|
|||||||
updateColors(self)
|
updateColors(self)
|
||||||
self:setValue("")
|
self:setValue("")
|
||||||
|
|
||||||
|
if not((obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (oby + textY - hIndex >= oby and oby + textY - hIndex < oby + h)) then
|
||||||
|
wIndex = math.max(1, lines[textY]:len()-w+1)
|
||||||
|
hIndex = math.max(1, textY - h + 1)
|
||||||
|
end
|
||||||
|
|
||||||
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
|
local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1)
|
||||||
if (cursorX > self.x + w - 1) then
|
if (cursorX > self:getX() + w - 1) then
|
||||||
cursorX = self.x + w - 1
|
cursorX = self:getX() + w - 1
|
||||||
end
|
end
|
||||||
local cursorY = (textY - hIndex < h and textY - hIndex or textY - hIndex - 1)
|
local cursorY = (textY - hIndex < h and textY - hIndex or textY - hIndex - 1)
|
||||||
if (cursorX < 1) then
|
if (cursorX < 1) then
|
||||||
cursorX = 0
|
cursorX = 0
|
||||||
end
|
end
|
||||||
|
if(isSelected())then
|
||||||
|
removeSelection(self)
|
||||||
|
end
|
||||||
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
|
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return true
|
return true
|
||||||
@@ -481,18 +570,21 @@ return function(name)
|
|||||||
if(anchx+w > anchx + x - (obx+1)+ wIndex)and(anchx < anchx + x - obx+ wIndex)then
|
if(anchx+w > anchx + x - (obx+1)+ wIndex)and(anchx < anchx + x - obx+ wIndex)then
|
||||||
textX = x - obx + wIndex
|
textX = x - obx + wIndex
|
||||||
textY = y - oby + hIndex
|
textY = y - oby + hIndex
|
||||||
|
endSelX = textX
|
||||||
|
endSelY = textY
|
||||||
if (textX > lines[textY]:len()) then
|
if (textX > lines[textY]:len()) then
|
||||||
textX = lines[textY]:len() + 1
|
textX = lines[textY]:len() + 1
|
||||||
|
endSelX = textX
|
||||||
end
|
end
|
||||||
|
|
||||||
if (textX < wIndex) then
|
if (textX < wIndex) then
|
||||||
wIndex = textX - 1
|
wIndex = textX - 1
|
||||||
if (wIndex < 1) then
|
if (wIndex < 1) then
|
||||||
wIndex = 1
|
wIndex = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (self.parent ~= nil) then
|
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
|
||||||
end
|
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -514,12 +606,10 @@ return function(name)
|
|||||||
hIndex = 1
|
hIndex = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if (self.parent ~= nil) then
|
if (obx + textX - wIndex >= obx and obx + textX - wIndex < obx + w) and (anchy + textY - hIndex >= anchy and anchy + textY - hIndex < anchy + h) 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)
|
||||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
else
|
||||||
else
|
self.parent:setCursor(false)
|
||||||
self.parent:setCursor(false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
self:updateDraw()
|
self:updateDraw()
|
||||||
return true
|
return true
|
||||||
@@ -533,8 +623,13 @@ return function(name)
|
|||||||
if (lines[y - oby + hIndex] ~= nil) then
|
if (lines[y - oby + hIndex] ~= nil) then
|
||||||
textX = x - obx + wIndex
|
textX = x - obx + wIndex
|
||||||
textY = y - oby + hIndex
|
textY = y - oby + hIndex
|
||||||
|
endSelX = nil
|
||||||
|
endSelY = nil
|
||||||
|
startSelX = textX
|
||||||
|
startSelY = textY
|
||||||
if (textX > lines[textY]:len()) then
|
if (textX > lines[textY]:len()) then
|
||||||
textX = lines[textY]:len() + 1
|
textX = lines[textY]:len() + 1
|
||||||
|
startSelX = textX
|
||||||
end
|
end
|
||||||
if (textX < wIndex) then
|
if (textX < wIndex) then
|
||||||
wIndex = textX - 1
|
wIndex = textX - 1
|
||||||
@@ -542,6 +637,7 @@ return function(name)
|
|||||||
wIndex = 1
|
wIndex = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self:updateDraw()
|
||||||
end
|
end
|
||||||
if (self.parent ~= nil) then
|
if (self.parent ~= nil) then
|
||||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||||
@@ -550,6 +646,25 @@ return function(name)
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
mouseUpHandler = function(self, button, x, y)
|
||||||
|
if (base.mouseUpHandler(self, button, x, y)) then
|
||||||
|
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||||
|
local anchx, anchy = self:getAnchorPosition()
|
||||||
|
if (lines[y - oby + hIndex] ~= nil) then
|
||||||
|
endSelX = x - obx + wIndex
|
||||||
|
endSelY = y - oby + hIndex
|
||||||
|
if (endSelX > lines[endSelY]:len()) then
|
||||||
|
endSelX = lines[endSelY]:len() + 1
|
||||||
|
end
|
||||||
|
if(startSelX==endSelX)and(startSelY==endSelY)then
|
||||||
|
startSelX, endSelX, startSelY, endSelY = nil, nil, nil, nil
|
||||||
|
end
|
||||||
|
self:updateDraw()
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
eventHandler = function(self, event, paste, p2, p3, p4)
|
eventHandler = function(self, event, paste, p2, p3, p4)
|
||||||
if(base.eventHandler(self, event, paste, p2, p3, p4))then
|
if(base.eventHandler(self, event, paste, p2, p3, p4))then
|
||||||
if(event=="paste")then
|
if(event=="paste")then
|
||||||
@@ -599,9 +714,27 @@ return function(name)
|
|||||||
self.parent:setBG(obx, oby + n - 1, bg)
|
self.parent:setBG(obx, oby + n - 1, bg)
|
||||||
self.parent:setFG(obx, oby + n - 1, fg)
|
self.parent:setFG(obx, oby + n - 1, fg)
|
||||||
end
|
end
|
||||||
|
if(startSelX~=nil)and(endSelX~=nil)and(startSelY~=nil)and(endSelY~=nil)then
|
||||||
|
local sx,ex,sy,ey = getSelectionCoordinates(self)
|
||||||
|
for n=sy,ey do
|
||||||
|
local line = lines[n]:len()
|
||||||
|
local xOffset = 0
|
||||||
|
if(n==sy)and(n==ey)then
|
||||||
|
xOffset = sx-1
|
||||||
|
line = line - (sx-1) - (line - ex)
|
||||||
|
elseif(n==ey)then
|
||||||
|
line = line - (line - ex)
|
||||||
|
elseif(n==sy)then
|
||||||
|
line = line-(sx-1)
|
||||||
|
xOffset = sx-1
|
||||||
|
end
|
||||||
|
self.parent:setBG(obx + xOffset, oby + n - 1, rep(tHex[selectionBG], line))
|
||||||
|
self.parent:setFG(obx + xOffset, oby + n - 1, rep(tHex[selectionFG], line))
|
||||||
|
end
|
||||||
|
end
|
||||||
if(self:isFocused())then
|
if(self:isFocused())then
|
||||||
local anchx, anchy = self:getAnchorPosition()
|
local anchx, anchy = self:getAnchorPosition()
|
||||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
--self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -609,6 +742,7 @@ return function(name)
|
|||||||
|
|
||||||
init = function(self)
|
init = function(self)
|
||||||
self.parent:addEvent("mouse_click", self)
|
self.parent:addEvent("mouse_click", self)
|
||||||
|
self.parent:addEvent("mouse_up", self)
|
||||||
self.parent:addEvent("mouse_scroll", self)
|
self.parent:addEvent("mouse_scroll", self)
|
||||||
self.parent:addEvent("mouse_drag", self)
|
self.parent:addEvent("mouse_drag", self)
|
||||||
self.parent:addEvent("key", self)
|
self.parent:addEvent("key", self)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ return function(name)
|
|||||||
local func
|
local func
|
||||||
local cRoutine
|
local cRoutine
|
||||||
local isActive = false
|
local isActive = false
|
||||||
|
local filter
|
||||||
|
|
||||||
local generateXMLEventFunction = function(self, str)
|
local generateXMLEventFunction = function(self, str)
|
||||||
if(str:sub(1,1)=="#")then
|
if(str:sub(1,1)=="#")then
|
||||||
@@ -53,12 +54,21 @@ return function(name)
|
|||||||
func = f
|
func = f
|
||||||
cRoutine = coroutine.create(func)
|
cRoutine = coroutine.create(func)
|
||||||
isActive = true
|
isActive = true
|
||||||
|
filter=nil
|
||||||
local ok, result = coroutine.resume(cRoutine)
|
local ok, result = coroutine.resume(cRoutine)
|
||||||
|
filter = result
|
||||||
if not (ok) then
|
if not (ok) then
|
||||||
if (result ~= "Terminated") then
|
if (result ~= "Terminated") then
|
||||||
error("Thread Error Occurred - " .. result)
|
error("Thread Error Occurred - " .. result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self.parent:addEvent("mouse_click", self)
|
||||||
|
self.parent:addEvent("mouse_up", self)
|
||||||
|
self.parent:addEvent("mouse_scroll", self)
|
||||||
|
self.parent:addEvent("mouse_drag", self)
|
||||||
|
self.parent:addEvent("key", self)
|
||||||
|
self.parent:addEvent("key_up", self)
|
||||||
|
self.parent:addEvent("char", self)
|
||||||
self.parent:addEvent("other_event", self)
|
self.parent:addEvent("other_event", self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
@@ -72,21 +82,58 @@ return function(name)
|
|||||||
|
|
||||||
stop = function(self, f)
|
stop = function(self, f)
|
||||||
isActive = false
|
isActive = false
|
||||||
|
self.parent:removeEvent("mouse_click", self)
|
||||||
|
self.parent:removeEvent("mouse_up", self)
|
||||||
|
self.parent:removeEvent("mouse_scroll", self)
|
||||||
|
self.parent:removeEvent("mouse_drag", self)
|
||||||
|
self.parent:removeEvent("key", self)
|
||||||
|
self.parent:removeEvent("key_up", self)
|
||||||
|
self.parent:removeEvent("char", self)
|
||||||
self.parent:removeEvent("other_event", self)
|
self.parent:removeEvent("other_event", self)
|
||||||
return self
|
return self
|
||||||
end;
|
end;
|
||||||
|
|
||||||
eventHandler = function(self, event, p1, p2, p3)
|
mouseHandler = function(self, ...)
|
||||||
|
self:eventHandler("mouse_click", ...)
|
||||||
|
end,
|
||||||
|
mouseUpHandler = function(self, ...)
|
||||||
|
self:eventHandler("mouse_up", ...)
|
||||||
|
end,
|
||||||
|
mouseScrollHandler = function(self, ...)
|
||||||
|
self:eventHandler("mouse_scroll", ...)
|
||||||
|
end,
|
||||||
|
mouseDragHandler = function(self, ...)
|
||||||
|
self:eventHandler("mouse_drag", ...)
|
||||||
|
end,
|
||||||
|
mouseMoveHandler = function(self, ...)
|
||||||
|
self:eventHandler("mouse_move", ...)
|
||||||
|
end,
|
||||||
|
keyHandler = function(self, ...)
|
||||||
|
self:eventHandler("key", ...)
|
||||||
|
end,
|
||||||
|
keyUpHandler = function(self, ...)
|
||||||
|
self:eventHandler("key_up", ...)
|
||||||
|
end,
|
||||||
|
charHandler = function(self, ...)
|
||||||
|
self:eventHandler("char", ...)
|
||||||
|
end,
|
||||||
|
|
||||||
|
eventHandler = function(self, event, ...)
|
||||||
if (isActive) then
|
if (isActive) then
|
||||||
if (coroutine.status(cRoutine) ~= "dead") then
|
if (coroutine.status(cRoutine) == "suspended") then
|
||||||
local ok, result = coroutine.resume(cRoutine, event, p1, p2, p3)
|
if(filter~=nil)then
|
||||||
|
if(event~=filter)then return end
|
||||||
|
filter=nil
|
||||||
|
end
|
||||||
|
local ok, result = coroutine.resume(cRoutine, event, ...)
|
||||||
|
filter = result
|
||||||
if not (ok) then
|
if not (ok) then
|
||||||
if (result ~= "Terminated") then
|
if (result ~= "Terminated") then
|
||||||
error("Thread Error Occurred - " .. result)
|
error("Thread Error Occurred - " .. result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
isActive = false
|
self:stop()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ return { -- The default main theme for basalt!
|
|||||||
SwitchInactive = colors.red,
|
SwitchInactive = colors.red,
|
||||||
SwitchActive = colors.green,
|
SwitchActive = colors.green,
|
||||||
LabelBG = false,
|
LabelBG = false,
|
||||||
LabelText = colors.black
|
LabelText = colors.black,
|
||||||
|
GraphBG = colors.gray,
|
||||||
|
GraphText = colors.black
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user