1.7 stuff
The master branch was reverted to 1.7 because it was very unstable (bugs and stuff that wasn't mentioned on the documentation page yet) - features will come back with 2.0 - fixed debug window - fixed flexbox not sending drag events to it's children - small docs updates for 1.7 - removed the examples because the are outdated
This commit is contained in:
@@ -2,29 +2,24 @@ local tHex = require("tHex")
|
||||
|
||||
return function(name, basalt)
|
||||
local base = basalt.getObject("ChangeableObject")(name, basalt)
|
||||
base:setType("Slider")
|
||||
local objectType = "Slider"
|
||||
|
||||
base:setSize(12, 1)
|
||||
base:setValue(1)
|
||||
base:setBackground(false, "\140", colors.black)
|
||||
|
||||
base:addProperty("SymbolText", "char", " ")
|
||||
base:addProperty("SymbolForeground", "color", colors.black)
|
||||
base:addProperty("SymbolBackground", "color", colors.gray)
|
||||
base:combineProperty("Symbol", "SymbolText", "SymbolForeground", "SymbolBackground")
|
||||
base:addProperty("SymbolSize", "number", 1)
|
||||
base:addProperty("BarType", {"vertical", "horizontal"}, "horizontal")
|
||||
base:addProperty("MaxValue", "number", 12)
|
||||
|
||||
local barType = "horizontal"
|
||||
local symbol = " "
|
||||
local symbolFG = colors.black
|
||||
local symbolBG = colors.gray
|
||||
local maxValue = 12
|
||||
local index = 1
|
||||
local symbolSize = 1
|
||||
|
||||
local function mouseEvent(self, _, x, y)
|
||||
local function mouseEvent(self, button, x, y)
|
||||
local obx, oby = self:getPosition()
|
||||
local w,h = self:getSize()
|
||||
local barType = self:getBarType()
|
||||
local size = barType == "vertical" and h or w
|
||||
local symbolSize = self:getSymbolSize()
|
||||
local symbol = self:getSymbol()
|
||||
local maxValue = self:getMaxValue()
|
||||
for i = 0, size do
|
||||
if ((barType == "vertical" and oby + i == y) or (barType == "horizontal" and obx + i == x)) and (obx <= x) and (obx + w > x) and (oby <= y) and (oby + h > y) then
|
||||
index = math.min(i + 1, size - (#symbol + symbolSize - 2))
|
||||
@@ -35,27 +30,32 @@ return function(name, basalt)
|
||||
end
|
||||
|
||||
local object = {
|
||||
init = function(self)
|
||||
base.init(self)
|
||||
base:setBgSymbol("\140")
|
||||
base:setBgSymbolColor(colors.black)
|
||||
base:setBackground(nil)
|
||||
getType = function(self)
|
||||
return objectType
|
||||
end,
|
||||
|
||||
load = function(self)
|
||||
self:listenEvent("mouse_click")
|
||||
self:listenEvent("mouse_drag")
|
||||
self:listenEvent("mouse_scroll")
|
||||
end,
|
||||
|
||||
setSymbol = function(self, _symbol)
|
||||
symbol = _symbol:sub(1, 1)
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
getSymbol = function(self)
|
||||
return symbol
|
||||
end,
|
||||
|
||||
setIndex = function(self, _index)
|
||||
index = _index
|
||||
if (index < 1) then
|
||||
index = 1
|
||||
end
|
||||
local w,h = self:getSize()
|
||||
local symbolSize = self:getSymbolSize()
|
||||
local maxValue = self:getMaxValue()
|
||||
local barType = self:getBarType()
|
||||
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
|
||||
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
|
||||
self:updateDraw()
|
||||
@@ -66,6 +66,35 @@ return function(name, basalt)
|
||||
return index
|
||||
end,
|
||||
|
||||
setMaxValue = function(self, val)
|
||||
maxValue = val
|
||||
return self
|
||||
end,
|
||||
|
||||
getMaxValue = function(self)
|
||||
return maxValue
|
||||
end,
|
||||
|
||||
setSymbolColor = function(self, col)
|
||||
symbolColor = col
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
getSymbolColor = function(self)
|
||||
return symbolColor
|
||||
end,
|
||||
|
||||
setBarType = function(self, _typ)
|
||||
barType = _typ:lower()
|
||||
self:updateDraw()
|
||||
return self
|
||||
end,
|
||||
|
||||
getBarType = function(self)
|
||||
return barType
|
||||
end,
|
||||
|
||||
mouseHandler = function(self, button, x, y)
|
||||
if (base.mouseHandler(self, button, x, y)) then
|
||||
mouseEvent(self, button, x, y)
|
||||
@@ -89,9 +118,6 @@ return function(name, basalt)
|
||||
if (index < 1) then
|
||||
index = 1
|
||||
end
|
||||
local symbolSize = self:getSymbolSize()
|
||||
local maxValue = self:getMaxValue()
|
||||
local barType = self:getBarType()
|
||||
index = math.min(index, (barType == "vertical" and h or w) - (symbolSize - 1))
|
||||
self:setValue(maxValue / (barType == "vertical" and h or w) * index)
|
||||
self:updateDraw()
|
||||
@@ -105,27 +131,21 @@ return function(name, basalt)
|
||||
self:addDraw("slider", function()
|
||||
local w,h = self:getSize()
|
||||
local bgCol,fgCol = self:getBackground(), self:getForeground()
|
||||
local symbolSize = self:getSymbolSize()
|
||||
local symbol = self:getSymbolText()
|
||||
local symbolFG = self:getSymbolForeground()
|
||||
local symbolBG = self:getSymbolBackground()
|
||||
local barType = self:getBarType()
|
||||
local obx, oby = self:getPosition()
|
||||
if (barType == "horizontal") then
|
||||
self:addText(index, oby, symbol:rep(symbolSize))
|
||||
if(symbolBG~=false)then self:addBg(index, 1, tHex[symbolBG]:rep(#symbol*symbolSize)) end
|
||||
if(symbolFG~=false)then self:addFg(index, 1, tHex[symbolFG]:rep(#symbol*symbolSize)) end
|
||||
if(symbolBG~=false)then self:addBG(index, 1, tHex[symbolBG]:rep(#symbol*symbolSize)) end
|
||||
if(symbolFG~=false)then self:addFG(index, 1, tHex[symbolFG]:rep(#symbol*symbolSize)) end
|
||||
end
|
||||
|
||||
if (barType == "vertical") then
|
||||
for n = 0, h - 1 do
|
||||
if (index == n + 1) then
|
||||
for curIndexOffset = 0, math.min(symbolSize - 1, h) do
|
||||
self:addBlit(1, 1+n+curIndexOffset, symbol, tHex[symbolFG], tHex[symbolFG])
|
||||
self:addBlit(1, 1+n+curIndexOffset, symbol, tHex[symbolColor], tHex[symbolColor])
|
||||
end
|
||||
else
|
||||
if (n + 1 < index) or (n + 1 > index - 1 + symbolSize) then
|
||||
self:addBlit(1, 1+n, " ", tHex[fgCol], tHex[bgCol])
|
||||
self:addBlit(1, 1+n, bgSymbol, tHex[fgCol], tHex[bgCol])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user