86 lines
2.5 KiB
Lua
86 lines
2.5 KiB
Lua
--[[
|
|
barGraphValue: the current bargraph value [0..100]
|
|
imageHeight: the height of the imageHeight
|
|
pixelHeight: the amount of pixels used (e.g. without transparency)
|
|
return:
|
|
textureRectangle: the textureRectangle for the bargraph
|
|
--]]
|
|
function roadbookMiniBarGraphTextureRectangle(barGraphValue, imageHeight, pixelHeight)
|
|
u = 0.0
|
|
v = 0.0
|
|
width = 1.0
|
|
height = 1.0
|
|
|
|
if barGraphValue >= 0 and barGraphValue <= 100 then
|
|
v = 0.0 - ( barGraphValue / 100.0 ) * ( pixelHeight / imageHeight )
|
|
end
|
|
|
|
return { x=u, y=v, z=width, w=height }
|
|
end
|
|
|
|
--[[
|
|
alphaMaskOffset: alpha mask offset in the range of [0..1]
|
|
rotation: current compass rotation
|
|
startValue: start value of fading
|
|
endValue: end value of fading
|
|
return:
|
|
opacity value
|
|
--]]
|
|
function roadbookMINICardinalOpacityValue( alphaMaskOffset, rotation, startValue, endValue )
|
|
if alphaMaskOffset <= 0.0 then
|
|
return 1.0
|
|
end
|
|
|
|
startValue = math.fmod(startValue + rotation + 1.0, 1.0)
|
|
endValue = math.fmod(endValue + rotation + 1.0, 1.0)
|
|
|
|
if endValue < startValue then
|
|
-- we animate from -something to + something, so lets clamp to 0.0 as fadeout starts here...
|
|
startValue = 0.0
|
|
end
|
|
|
|
delta = endValue - startValue
|
|
|
|
if alphaMaskOffset <= startValue then
|
|
return 1.0
|
|
elseif alphaMaskOffset >= endValue then
|
|
return 0.0
|
|
else
|
|
return 1.0 - ( alphaMaskOffset - startValue ) / delta
|
|
end
|
|
end
|
|
|
|
--[[
|
|
alphaMaskOffset: alpha mask offset in the range of [0..1]
|
|
rotation: current compass rotation
|
|
opacity: widget opacity
|
|
return:
|
|
opacity values for N, E, S, W
|
|
--]]
|
|
function roadbookMINICardinalOpacity( alphaMaskOffset, rotation, opacity )
|
|
rotation = math.fmod(rotation + 1.0, 1.0)
|
|
alphaMaskOffset = math.max(alphaMaskOffset, 0.0)
|
|
e = roadbookMINICardinalOpacityValue(alphaMaskOffset, rotation, 0.0, 0.25) * opacity
|
|
s = roadbookMINICardinalOpacityValue(alphaMaskOffset, rotation, 0.25, 0.5) * opacity
|
|
w = roadbookMINICardinalOpacityValue(alphaMaskOffset, rotation, 0.5, 0.75) * opacity
|
|
n = roadbookMINICardinalOpacityValue(alphaMaskOffset, rotation, 0.75, 0.99) * opacity
|
|
|
|
return n, e, s, w
|
|
end
|
|
|
|
--[[
|
|
compassFadeOutValue: current value of a fading out compass
|
|
opacity: widget opacity
|
|
return:
|
|
opacity of the compass
|
|
--]]
|
|
function roadbookMINICompassOpacity( compassFadeOutValue, targetOpacity )
|
|
compassOpacity = targetOpacity
|
|
|
|
if compassFadeOutValue > 0.0 then
|
|
compassOpacity = 1.0
|
|
end
|
|
|
|
return compassOpacity
|
|
end
|