added switch
This commit is contained in:
@@ -3404,25 +3404,45 @@ local function Switch(name)
|
|||||||
local base = Object(name)
|
local base = Object(name)
|
||||||
local objectType = "Switch"
|
local objectType = "Switch"
|
||||||
|
|
||||||
base.width = 3
|
base.width = 2
|
||||||
base.height = 1
|
base.height = 1
|
||||||
base.bgColor = colors.lightGray
|
base.bgColor = colors.lightGray
|
||||||
base.fgColor = colors.gray
|
base.fgColor = colors.gray
|
||||||
base:setValue(false)
|
base:setValue(false)
|
||||||
base:setZIndex(5)
|
base:setZIndex(5)
|
||||||
|
|
||||||
|
local bgSymbol = colors.black
|
||||||
|
local inactiveBG = colors.red
|
||||||
|
local activeBG = colors.green
|
||||||
|
|
||||||
local object = {
|
local object = {
|
||||||
getType = function(self)
|
getType = function(self)
|
||||||
return objectType
|
return objectType
|
||||||
end;
|
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)
|
mouseClickHandler = function(self, event, button, x, y)
|
||||||
if (base.mouseClickHandler(self, event, button, x, y)) then
|
if (base.mouseClickHandler(self, event, button, x, y)) then
|
||||||
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
|
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
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -3432,7 +3452,14 @@ local function Switch(name)
|
|||||||
if (base.draw(self)) then
|
if (base.draw(self)) then
|
||||||
if (self.parent ~= nil) then
|
if (self.parent ~= nil) then
|
||||||
local obx, oby = self:getAnchorPosition()
|
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
|
end
|
||||||
self:setVisualChanged(false)
|
self:setVisualChanged(false)
|
||||||
end
|
end
|
||||||
@@ -4504,6 +4531,11 @@ local function Frame(name, parent)
|
|||||||
return addObject(obj)
|
return addObject(obj)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
addSwitch = function(self, name)
|
||||||
|
local obj = Switch(name)
|
||||||
|
return addObject(obj)
|
||||||
|
end;
|
||||||
|
|
||||||
addFrame = function(self, name)
|
addFrame = function(self, name)
|
||||||
local obj = Frame(name, self)
|
local obj = Frame(name, self)
|
||||||
return addObject(obj)
|
return addObject(obj)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user