2025-06-09 15:07:26 +02:00

73 lines
2.4 KiB
Lua

function calculateBalanceFadingPointPosition(XMinValue, YMinValue, XMaxValue, YMaxValue, XValue, YValue)
local vX = 308.0 * (XValue - XMinValue)/(XMaxValue - XMinValue)
local vY = 298.0 * (YValue - YMinValue)/(YMaxValue - YMinValue)
local pointPosition = { x=vX+76.0, y=0.0, z=vY+54.0 }
return pointPosition
end
-- returns true, if slider edit mode (selected state) should be toggled (on controller release)
function sliderBalanceFadingControllerInputFunction( keyCode, pressed, pressedPrev, param )
local result = (keyCode == KeyCodes.KEY_PRESS and pressedPrev and not pressed)
return result
end
-- returns true, if slider should change its value (controller rotate, and active edit mode)
function sliderBalanceFadingControllerInputChangeValueFunction( keyCode, pressed, pressedPrev, param, editMode )
if not editMode then
return false, false
end
local decreaseX = (keyCode == KeyCodes.KEY_LEFT)
local increaseX = (keyCode == KeyCodes.KEY_RIGHT)
return decreaseX, increaseX
end
function sliderBalanceFadingTouchInputSetValueFunction( posX, posY, minValueX, maxValueX, minValueY, maxValueY)
local xBoundaryLeft = -0.6044
local xBoundaryRight = 0.4963
local yBoundaryBottom = -0.6046
local yBoundaryTop = 0.5933
-- map [xBoundaryLeft, xBoundaryRight] to [-1,1]
local xValue = (2.0 * (posX - xBoundaryLeft)) / (xBoundaryRight - xBoundaryLeft) - 1.0;
-- map [yBoundaryBottom, yBoundaryTop] to [-1,1]
local yValue = (2.0 * (posY - yBoundaryBottom)) / (yBoundaryTop - yBoundaryBottom) - 1.0;
-- touch position range is in [-1,1]; map to [minValue,maxValue]
local vX = (minValueX + (xValue + 1.0) / 2.0 * (maxValueX - minValueX)) + 0.5
local vY = (minValueY + (yValue + 1.0) / 2.0 * (maxValueY - minValueY)) + 0.5
if vX < minValueX then
vX = minValueX
elseif vX > maxValueX then
vX = maxValueX
end
if vY < minValueY then
vY = minValueY
elseif vY > maxValueY then
vY = maxValueY
end
return vX, vY
end
-- returns startEdit, endEdit flags; this is more robust than a "toggle" flag
-- (accidentally starting edit mode twice shouldn't turn it off)
function sliderBalanceFadingTouchInputToggleEditFunction( down, event )
local startEdit = (event == ETouchEvent.Start)
local endEdit = (event == ETouchEvent.End)
return startEdit, endEdit
end