Monitor/Mirror fixes
- Fixed monitor events - Monitor's now automatically resize - Fixed mirror events - Fixed input's cursor position if height is bigger than 1
This commit is contained in:
@@ -623,6 +623,7 @@ return function(name, parent, pTerm, basalt)
|
||||
end;
|
||||
|
||||
setMirror = function(self, side)
|
||||
if(self.parent~=nil)then error("Frame has to be a base frame in order to attach a mirror.") end
|
||||
mirrorSide = side
|
||||
if(mirror~=nil)then
|
||||
basaltDraw.setMirror(mirror)
|
||||
@@ -643,21 +644,23 @@ return function(name, parent, pTerm, basalt)
|
||||
if(peripheral.getType(side)=="monitor")then
|
||||
termObject = peripheral.wrap(side)
|
||||
monitorAttached = true
|
||||
self:setSize(termObject.getSize())
|
||||
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:removeObject(self)
|
||||
end
|
||||
isMonitor = true
|
||||
basalt.setMonitorFrame(side, self)
|
||||
else
|
||||
termObject = parentTerminal
|
||||
isMonitor = false
|
||||
if(basalt.getMonitorFrame(monSide)==self)then
|
||||
basalt.setMonitorFrame(monSide, nil)
|
||||
end
|
||||
self:setSize(termObject.getSize())
|
||||
end
|
||||
basaltDraw = BasaltDraw(termObject)
|
||||
self:setSize(termObject.getSize())
|
||||
autoSize = true
|
||||
monSide = side or nil
|
||||
self:updateDraw()
|
||||
return self;
|
||||
@@ -701,15 +704,22 @@ return function(name, parent, pTerm, basalt)
|
||||
end
|
||||
end
|
||||
end
|
||||
if(autoSize)then
|
||||
if(autoSize)and not(isMonitor)then
|
||||
if(self.parent==nil)then
|
||||
if(event=="term_resize")or(event=="monitor_resize")then
|
||||
if(event=="term_resize")then
|
||||
self:setSize(termObject.getSize())
|
||||
autoSize = true
|
||||
end
|
||||
end
|
||||
end
|
||||
if(isMonitor)then
|
||||
if(autoSize)then
|
||||
if(event=="monitor_resize")and(p1==monSide)then
|
||||
self:setSize(termObject.getSize())
|
||||
autoSize = true
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
if(event == "peripheral")and(p1==monSide)then
|
||||
if(peripheral.getType(monSide)=="monitor")then
|
||||
monitorAttached = true
|
||||
@@ -730,8 +740,8 @@ return function(name, parent, pTerm, basalt)
|
||||
if(event == "peripheral_detach")and(p1==mirrorSide)then
|
||||
monitorAttached = false
|
||||
end
|
||||
if(event=="monitor_touch")then
|
||||
self:mouseHandler(1, p1, p2)
|
||||
if(event=="monitor_touch")and(mirrorSide==p1)then
|
||||
self:mouseHandler(1, p2, p3, true)
|
||||
end
|
||||
end
|
||||
if (event == "terminate") then
|
||||
|
||||
@@ -26,11 +26,6 @@ return function(name)
|
||||
local isDragging = false
|
||||
local dragStartX, dragStartY, dragXOffset, dragYOffset = 0, 0, 0, 0
|
||||
|
||||
local bgSymbol = " "
|
||||
local bgSymbolColor = colors.black
|
||||
local bgColor = colors.black
|
||||
local transparentColor = false
|
||||
|
||||
local draw = true
|
||||
local activeEvents = {}
|
||||
|
||||
@@ -42,7 +37,10 @@ return function(name)
|
||||
width = 1,
|
||||
height = 1,
|
||||
bgColor = colors.black,
|
||||
bgSymbol = " ",
|
||||
bgSymbolColor = colors.black,
|
||||
fgColor = colors.white,
|
||||
transparentColor = false,
|
||||
name = name or "Object",
|
||||
parent = nil,
|
||||
|
||||
@@ -309,9 +307,8 @@ return function(name)
|
||||
|
||||
setBackground = function(self, color, symbol, symbolCol)
|
||||
self.bgColor = color or false
|
||||
bgColor = color or false
|
||||
bgSymbol = symbol or (color~=false and bgSymbol or false)
|
||||
bgSymbolColor = symbolCol or bgSymbolColor
|
||||
self.bgSymbol = symbol or (color~=false and self.bgSymbol or false)
|
||||
self.bgSymbolColor = symbolCol or self.bgSymbolColor
|
||||
self:updateDraw()
|
||||
return self
|
||||
end;
|
||||
@@ -354,16 +351,16 @@ return function(name)
|
||||
|
||||
showBorder = function(self, ...)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(v=="left")then
|
||||
if(v=="left")or(...==nil)then
|
||||
borderLeft = true
|
||||
end
|
||||
if(v=="top")then
|
||||
if(v=="top")or(...==nil)then
|
||||
borderTop = true
|
||||
end
|
||||
if(v=="right")then
|
||||
if(v=="right")or(...==nil)then
|
||||
borderRight = true
|
||||
end
|
||||
if(v=="bottom")then
|
||||
if(v=="bottom")or(...==nil)then
|
||||
borderBottom = true
|
||||
end
|
||||
end
|
||||
@@ -399,15 +396,15 @@ return function(name)
|
||||
local w,h = self: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(transparentColor~=false)then
|
||||
self.parent:drawForegroundBox(x, y, w, h, transparentColor)
|
||||
if(self.transparentColor~=false)then
|
||||
self.parent:drawForegroundBox(x, y, w, h, self.transparentColor)
|
||||
end
|
||||
if(bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(x, y, w, h, bgColor)
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(x, y, w, h, self.bgColor)
|
||||
end
|
||||
if(bgSymbol~=false)then
|
||||
self.parent:drawForegroundBox(x, y, w, h, bgSymbolColor)
|
||||
self.parent:drawTextBox(x, y, w, h, bgSymbol)
|
||||
if(self.bgSymbol~=false)then
|
||||
self.parent:drawForegroundBox(x, y, w, h, self.bgSymbolColor)
|
||||
self.parent:drawTextBox(x, y, w, h, self.bgSymbol)
|
||||
end
|
||||
if(shadow)then
|
||||
self.parent:drawBackgroundBox(x+1, y+h, w, 1, shadowColor)
|
||||
@@ -547,7 +544,6 @@ return function(name)
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("mouse_click", v)
|
||||
self:registerEvent("monitor_touch", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
@@ -649,7 +645,6 @@ return function(name)
|
||||
end;
|
||||
|
||||
onKeyUp = function(self, ...)
|
||||
if(isEnabled)then
|
||||
for _,v in pairs(table.pack(...))do
|
||||
if(type(v)=="function")then
|
||||
self:registerEvent("key_up", v)
|
||||
@@ -659,7 +654,6 @@ return function(name)
|
||||
self.parent:addEvent("key_up", self)
|
||||
activeEvents["key_up"] = true
|
||||
end
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -676,6 +670,10 @@ return function(name)
|
||||
self:registerEvent("get_focus", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -685,6 +683,10 @@ return function(name)
|
||||
self:registerEvent("lose_focus", v)
|
||||
end
|
||||
end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:addEvent("mouse_click", self)
|
||||
activeEvents["mouse_click"] = true
|
||||
end
|
||||
return self
|
||||
end;
|
||||
|
||||
@@ -711,9 +713,9 @@ return function(name)
|
||||
return false
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, button, x, y)
|
||||
mouseHandler = function(self, button, x, y, isMon)
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x, y)
|
||||
local val = eventSystem:sendEvent("mouse_click", self, "mouse_click", button, x, y, isMon)
|
||||
if(val==false)then return false end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:setFocusedObject(self)
|
||||
@@ -725,18 +727,6 @@ return function(name)
|
||||
return false
|
||||
end,
|
||||
|
||||
touchHandler = function(self, x, y)
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
local val = eventSystem:sendEvent("monitor_touch", self, "monitor_touch", x, y)
|
||||
if(val==false)then return false end
|
||||
if(self.parent~=nil)then
|
||||
self.parent:setFocusedObject(self)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
|
||||
mouseUpHandler = function(self, button, x, y)
|
||||
isDragging = false
|
||||
if(self:isCoordsInObject(x, y))then
|
||||
|
||||
@@ -72,6 +72,7 @@ local bInstance = {
|
||||
end,
|
||||
|
||||
setMonitorFrame = function(name, frame)
|
||||
if(mainFrame == frame)then mainFrame = nil end
|
||||
monFrames[name] = frame
|
||||
end,
|
||||
|
||||
@@ -158,7 +159,7 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
||||
if(basaltEvent:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end
|
||||
if(mainFrame~=nil)then
|
||||
if (event == "mouse_click") then
|
||||
mainFrame:mouseHandler(p1, p2, p3, p4)
|
||||
mainFrame:mouseHandler(p1, p2, p3, false)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "mouse_drag") then
|
||||
mainFrame:dragHandler(p1, p2, p3, p4)
|
||||
@@ -169,11 +170,12 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
|
||||
elseif (event == "mouse_scroll") then
|
||||
mainFrame:scrollHandler(p1, p2, p3, p4)
|
||||
activeFrame = mainFrame
|
||||
elseif (event == "monitor_touch") then
|
||||
if(monFrames[p1]~=nil)then
|
||||
monFrames[p1]:touchHandler(p1, p2, p3, p4)
|
||||
activeFrame = monFrames[p1]
|
||||
end
|
||||
end
|
||||
end
|
||||
if(event == "monitor_touch") then
|
||||
if(monFrames[p1]~=nil)then
|
||||
monFrames[p1]:mouseHandler(1, p2, p3, true)
|
||||
activeFrame = monFrames[p1]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -320,6 +322,7 @@ basalt = {
|
||||
|
||||
debug = function(...)
|
||||
local args = { ... }
|
||||
if(mainFrame==nil)then print(...) return end
|
||||
if (mainFrame.name ~= "basaltDebuggingFrame") then
|
||||
if (mainFrame ~= basalt.debugFrame) then
|
||||
basalt.debugLabel:setParent(mainFrame)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local Object = require("Object")
|
||||
local utils = require("utils")
|
||||
local xmlValue = utils.getValueFromXML
|
||||
local tHex = require("tHex")
|
||||
|
||||
return function(name)
|
||||
-- Button
|
||||
@@ -55,14 +56,10 @@ return function(name)
|
||||
local w,h = self:getSize()
|
||||
local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign)
|
||||
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
|
||||
self.parent:drawTextBox(obx, oby, w, h, " ")
|
||||
end
|
||||
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor) end
|
||||
for n = 1, h do
|
||||
if (n == verticalAlign) then
|
||||
self.parent:setText(obx, oby + (n - 1), utils.getTextHorizontalAlign(self:getValue(), w, textHorizontalAlign))
|
||||
self.parent:setFG(obx, oby + (n - 1), utils.getTextHorizontalAlign(tHex[self.fgColor]:rep(self:getValue():len()), w, textHorizontalAlign))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -100,7 +100,7 @@ return function(name)
|
||||
if(defaultText~="")then
|
||||
self:updateDraw()
|
||||
end
|
||||
self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self:getHeight()/2), self.fgColor)
|
||||
self.parent:setCursor(true, obx + textX - wIndex, oby+math.max(math.ceil(self:getHeight()/2-1, 1)), self.fgColor)
|
||||
end
|
||||
end;
|
||||
|
||||
@@ -182,7 +182,7 @@ return function(name)
|
||||
cursorX = self.x + w - 1
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.floor(h/2), self.fgColor)
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||
end
|
||||
internalValueChange = false
|
||||
return true
|
||||
@@ -222,7 +222,7 @@ return function(name)
|
||||
cursorX = x + w - 1
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.floor(h/2), self.fgColor)
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||
end
|
||||
internalValueChange = false
|
||||
self:updateDraw()
|
||||
@@ -247,6 +247,7 @@ return function(name)
|
||||
wIndex = 1
|
||||
end
|
||||
end
|
||||
self.parent:setCursor(true, obx + textX-1, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||
return true
|
||||
end
|
||||
end,
|
||||
@@ -284,7 +285,7 @@ return function(name)
|
||||
cursorX = x + w - 1
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.floor(h/2), self.fgColor)
|
||||
self.parent:setCursor(true, obx + cursorX, oby+math.max(math.ceil(h/2-1, 1)), self.fgColor)
|
||||
end
|
||||
self:updateDraw()
|
||||
internalValueChange = false
|
||||
@@ -325,7 +326,7 @@ return function(name)
|
||||
if (inputType == "password") and (val ~= "") then
|
||||
text = string.rep("*", text:len())
|
||||
end
|
||||
text = text .. string.rep(" ", space)
|
||||
text = text .. string.rep(self.bgSymbol, space)
|
||||
self.parent:writeText(obx, oby + (n - 1), text, bCol, fCol)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,8 @@ local tHex = require("tHex")
|
||||
local log = require("basaltLogs")
|
||||
local xmlValue = require("utils").getValueFromXML
|
||||
|
||||
local rep = string.rep
|
||||
|
||||
return function(name)
|
||||
local base = Object(name)
|
||||
local objectType = "Textfield"
|
||||
@@ -434,6 +436,7 @@ return function(name)
|
||||
cursorX = 0
|
||||
end
|
||||
self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgColor)
|
||||
self:updateDraw()
|
||||
return true
|
||||
end
|
||||
end,
|
||||
@@ -470,20 +473,24 @@ return function(name)
|
||||
if (base.dragHandler(self, button, x, y)) then
|
||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
||||
local anchx, anchy = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if (lines[y - oby + hIndex] ~= nil) then
|
||||
textX = x - obx + wIndex
|
||||
textY = y - oby + hIndex
|
||||
if (textX > lines[textY]:len()) then
|
||||
textX = lines[textY]:len() + 1
|
||||
end
|
||||
if (textX < wIndex) then
|
||||
wIndex = textX - 1
|
||||
if (wIndex < 1) then
|
||||
wIndex = 1
|
||||
if(anchx+w > anchx + x - (obx+1)+ wIndex)and(anchx < anchx + x - obx+ wIndex)then
|
||||
textX = x - obx + wIndex
|
||||
textY = y - oby + hIndex
|
||||
if (textX > lines[textY]:len()) then
|
||||
textX = lines[textY]:len() + 1
|
||||
end
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
if (textX < wIndex) then
|
||||
wIndex = textX - 1
|
||||
if (wIndex < 1) then
|
||||
wIndex = 1
|
||||
end
|
||||
end
|
||||
if (self.parent ~= nil) then
|
||||
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
|
||||
end
|
||||
self:updateDraw()
|
||||
end
|
||||
end
|
||||
return true
|
||||
@@ -566,12 +573,6 @@ return function(name)
|
||||
if (self.parent ~= nil) then
|
||||
local obx, oby = self:getAnchorPosition()
|
||||
local w,h = self:getSize()
|
||||
if(self.bgColor~=false)then
|
||||
self.parent:drawBackgroundBox(obx, oby, w, h, self.bgColor)
|
||||
end
|
||||
if(self.fgColor~=false)then
|
||||
self.parent:drawForegroundBox(obx, oby, w, h, self.fgColor)
|
||||
end
|
||||
for n = 1, h do
|
||||
local text = ""
|
||||
local bg = ""
|
||||
@@ -588,9 +589,9 @@ return function(name)
|
||||
if (space < 0) then
|
||||
space = 0
|
||||
end
|
||||
text = text .. string.rep(" ", space)
|
||||
bg = bg .. string.rep(tHex[self.bgColor], space)
|
||||
fg = fg .. string.rep(tHex[self.fgColor], space)
|
||||
text = text .. rep(self.bgSymbol, space)
|
||||
bg = bg .. rep(tHex[self.bgColor], space)
|
||||
fg = fg .. rep(tHex[self.fgColor], space)
|
||||
self.parent:setText(obx, oby + n - 1, text)
|
||||
self.parent:setBG(obx, oby + n - 1, bg)
|
||||
self.parent:setFG(obx, oby + n - 1, fg)
|
||||
|
||||
Reference in New Issue
Block a user