added switch

This commit is contained in:
Robert Jelic
2022-06-06 20:49:30 +02:00
parent c5b9a5f568
commit 4f3ffc328d
2 changed files with 38 additions and 6 deletions

View File

@@ -3404,25 +3404,45 @@ local function Switch(name)
local base = Object(name)
local objectType = "Switch"
base.width = 3
base.width = 2
base.height = 1
base.bgColor = colors.lightGray
base.fgColor = colors.gray
base:setValue(false)
base:setZIndex(5)
local bgSymbol = colors.black
local inactiveBG = colors.red
local activeBG = colors.green
local object = {
getType = function(self)
return objectType
end;
setSymbolColor = function(self, symbolColor)
bgSymbol = symbolColor
self:setVisualChanged()
return self
end;
setActiveBackground = function(self, bgcol)
activeBG = bgcol
self:setVisualChanged()
return self
end;
setInactiveBackground = function(self, bgcol)
inactiveBG = bgcol
self:setVisualChanged()
return self
end;
mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
if ((event == "mouse_click") and (button == 1))or(event=="monitor_touch") then
self:setValue(not self:getValue())
end
return true
end
@@ -3432,7 +3452,14 @@ local function Switch(name)
if (base.draw(self)) then
if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
if(self:getValue())then
self.parent:drawBackgroundBox(obx, oby, 1, self.height, activeBG)
self.parent:drawBackgroundBox(obx+1, oby, 1, self.height, bgSymbol)
else
self.parent:drawBackgroundBox(obx, oby, 1, self.height, bgSymbol)
self.parent:drawBackgroundBox(obx+1, oby, 1, self.height, inactiveBG)
end
end
self:setVisualChanged(false)
end
@@ -4504,6 +4531,11 @@ local function Frame(name, parent)
return addObject(obj)
end;
addSwitch = function(self, name)
local obj = Switch(name)
return addObject(obj)
end;
addFrame = function(self, name)
local obj = Frame(name, self)
return addObject(obj)

File diff suppressed because one or more lines are too long