Small Changes

- Fixed a bug in basalt.setMouseDragThrottle
- Added some new curves for animation (anim:setMode("curveyouwant")
- Small fix for checkbox -> mouse_up
- Fix for Input (if type is number and you use . or - it gets ignored)
This commit is contained in:
Robert Jelic
2022-09-29 17:34:53 +02:00
parent ba29ceb3eb
commit 40650d16c1
5 changed files with 188 additions and 11 deletions

View File

@@ -190,18 +190,20 @@ local function moveHandlerTimer()
end
local btn, dragX, dragY = nil, nil, nil
local dragTimer = nil
local function dragHandlerTimer()
log("Event registered")
dragTimer = nil
mainFrame:dragHandler(btn, dragX, dragY)
activeFrame = mainFrame
end
local dragTimer = nil
local function mouseDragEvent(b, x, y)
btn, dragX, dragY = b, x, y
if(dragThrottle<50)then
dragHandlerTimer()
else
log("Draggi"..(tostring(dragTimer)..(dragThrottle/1000)))
if(dragTimer==nil)then
dragTimer = os.startTimer(dragThrottle/1000)
end
@@ -215,8 +217,6 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
mainFrame:mouseHandler(p1, p2, p3, false)
activeFrame = mainFrame
elseif (event == "mouse_drag") then
--mainFrame:dragHandler(p1, p2, p3, p4)
--activeFrame = mainFrame
mouseDragEvent(p1, p2, p3)
elseif (event == "mouse_up") then
mainFrame:mouseUpHandler(p1, p2, p3, p4)
@@ -315,9 +315,11 @@ basalt = {
end,
setMouseDragThrottle = function(amount)
if(amount<0)then
log("Drag Throttle "..amount)
if(amount<=0)then
dragThrottle = 0
else
dragTimer = nil
dragThrottle = amount
end
end,

View File

@@ -1,7 +1,9 @@
local xmlValue = require("utils").getValueFromXML
local basaltEvent = require("basaltEvent")
local floor,sin,cos,pi = math.floor,math.sin,math.cos,math.pi
local floor,sin,cos,pi,sqrt,pow = math.floor,math.sin,math.cos,math.pi,math.sqrt,math.pow
-- You can find the easing curves here https://easings.net
local lerp = function(s, e, pct)
return s + (e - s) * pct
@@ -39,16 +41,183 @@ local easeInOutSine = function(t)
return -(cos(pi * x) - 1) / 2
end
local easeInBack = function(t)
local c1 = 1.70158;
local c3 = c1 + 1
return c3*t^3-c1*t^2
end
local easeInCubic = function(t)
return t^3
end
local easeInElastic = function(t)
local c4 = (2*pi)/3;
return t == 0 and 0 or (t == 1 and 1 or (
-2^(10*t-10)*sin((t*10-10.75)*c4)
))
end
local function easeInExpo(t)
return t == 0 and 0 or 2^(10*t-10)
end
local function easeInExpo(t)
return t == 0 and 0 or 2^(10*t-10)
end
local function easeInOutBack(t)
local c1 = 1.70158;
local c2 = c1 * 1.525;
return t < 0.5 and ((2*t)^2*((c2+1)*2*t-c2))/2 or ((2*t-2)^2*((c2+1)*(t*2-2)+c2)+2)/2
end
local function easeInOutCubic(t)
return t < 0.5 and 4 * t^3 or 1-(-2*t+2)^3 / 2
end
local function easeInOutElastic(t)
local c5 = (2*pi) / 4.5
return t==0 and 0 or (t == 1 and 1 or (t < 0.5 and -(2^(20*t-10) * sin((20*t - 11.125) * c5))/2 or (2^(-20*t+10) * sin((20*t - 11.125) * c5))/2 + 1))
end
local function easeInOutExpo(t)
return t == 0 and 0 or (t == 1 and 1 or (t < 0.5 and 2^(20*t-10)/2 or (2-2^(-20*t+10)) /2))
end
local function easeInOutQuad(t)
return t < 0.5 and 2*t^2 or 1-(-2*t+2)^2/2
end
local function easeInOutQuart(t)
return t < 0.5 and 8*t^4 or 1 - (-2*t+2)^4 / 2
end
local function easeInOutQuint(t)
return t < 0.5 and 16*t^5 or 1-(-2*t+2)^5 / 2
end
local function easeInQuad(t)
return t^2
end
local function easeInQuart(t)
return t^4
end
local function easeInQuint(t)
return t^5
end
local function easeOutBack(t)
local c1 = 1.70158;
local c3 = c1 + 1
return 1+c3*(t-1)^3+c1*(t-1)^2
end
local function easeOutCubic(t)
return 1 - (1-t)^3
end
local function easeOutElastic(t)
local c4 = (2*pi)/3;
return t == 0 and 0 or (t == 1 and 1 or (2^(-10*t)*sin((t*10-0.75)*c4)+1))
end
local function easeOutExpo(t)
return t == 1 and 1 or 1-2^(-10*t)
end
local function easeOutQuad(t)
return 1 - (1 - t) * (1 - t)
end
local function easeOutQuart(t)
return 1 - (1-t)^4
end
local function easeOutQuint(t)
return 1 - (1 - t)^5
end
local function easeInCirc(t)
return 1 - sqrt(1 - pow(t, 2))
end
local function easeOutCirc(t)
return sqrt(1 - pow(t - 1, 2))
end
local function easeInOutCirc(t)
return t < 0.5 and (1 - sqrt(1 - pow(2 * t, 2))) / 2 or (sqrt(1 - pow(-2 * t + 2, 2)) + 1) / 2;
end
local function easeOutBounce(t)
local n1 = 7.5625;
local d1 = 2.75;
if (t < 1 / d1)then
return n1 * t * t
elseif (t < 2 / d1)then
local a = t - 1.5 / d1
return n1 * a * a + 0.75;
elseif (t < 2.5 / d1)then
local a = t - 2.25 / d1
return n1 * a * a + 0.9375;
else
local a = t - 2.625 / d1
return n1 * a * a + 0.984375;
end
end
local function easeInBounce(t)
return 1 - easeOutBounce(1 - t)
end
local function easeInOutBounce(t)
return x < 0.5 and (1 - easeOutBounce(1 - 2 * t)) / 2 or (1 + easeOutBounce(2 * t - 1)) / 2;
end
local lerp = {
linear = linear,
lerp = lerp,
flip=flip,
easeIn=easeIn,
easeOut=easeOut,
easeInOut=easeInOut,
easeOutSine = easeOutSine,
easeInSine = easeInSine,
easeInBack=easeInBack,
easeInCubic=easeInCubic,
easeInElastic=easeInElastic,
easeInExpo=easeInExpo,
easeInQuad=easeInQuad,
easeInQuart=easeInQuart,
easeInQuint=easeInQuint,
easeInCirc=easeInCirc,
easeInBounce=easeInBounce,
easeOut=easeOut,
easeOutSine = easeOutSine,
easeOutBack=easeOutBack,
easeOutCubic=easeOutCubic,
easeOutElastic=easeOutElastic,
easeOutExpo=easeOutExpo,
easeOutQuad=easeOutQuad,
easeOutQuart=easeOutQuart,
easeOutQuint=easeOutQuint,
easeOutCirc=easeOutCirc,
easeOutBounce=easeOutBounce,
easeInOut=easeInOut,
easeInOutSine = easeInOutSine,
easeInOutBack=easeInOutBack,
easeInOutCubic=easeInOutCubic,
easeInOutElastic=easeInOutElastic,
easeInOutExpo=easeInOutExpo,
easeInOutQuad=easeInOutQuad,
easeInOutQuart=easeInOutQuart,
easeInOutQuint=easeInOutQuint,
easeInOutCirc=easeInOutCirc,
easeInOutBounce=easeInOutBounce,
}
local activeAnimations = {}
@@ -185,6 +354,11 @@ return function(name)
return self
end,
addMode = function(self, modeId, modeF)
lerp[modeId] = modeF
return self
end,
generateXMLEventFunction = function(self, func, val)
local createF = function(str)
if(str:sub(1,1)=="#")then

View File

@@ -76,6 +76,7 @@ return function(name)
self.bgColor = self.parent:getTheme("CheckboxBG")
self.fgColor = self.parent:getTheme("CheckboxText")
self.parent:addEvent("mouse_click", self)
self.parent:addEvent("mouse_up", self)
end,
}

View File

@@ -202,12 +202,12 @@ return function(name)
if (text:len() < inputLimit or inputLimit <= 0) then
if (inputType == "number") then
local cache = text
if (char == ".") or (tonumber(char) ~= nil) then
if (#text==0 and char == "-") or (char == ".") or (tonumber(char) ~= nil) then
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))
textX = textX + 1
end
if (tonumber(base.getValue()) == nil) then
self:setValue(cache)
--self:setValue(cache)
end
else
self:setValue(text:sub(1, textX - 1) .. char .. text:sub(textX, text:len()))

View File

@@ -31,7 +31,7 @@ return function(name)
text = tostring(text)
base:setValue(text)
if (autoSize) then
self.width = text:len()
base.width = text:len()
end
self:updateDraw()
return self