Pip state machine for dev player
This commit is contained in:
1 parent
37b3e88b93
commit
b9b97c67fd
3 files changed
+173
-80
No files matched your search
@@ -0,0 +1,169 @@
|
||||
enum MinimizeState
|
||||
None ' None is not a valid state, but it is the default value pre-initialization
|
||||
Minimizing
|
||||
Minimized
|
||||
Maximizing
|
||||
Maximized
|
||||
end enum
|
||||
|
||||
function InitializePitctureInPicture()
|
||||
m.minRect = {
|
||||
translation: [834, 460]
|
||||
width: 426
|
||||
height: 240
|
||||
}
|
||||
|
||||
m.maxRect = {
|
||||
translation: [0, 0]
|
||||
width: 1280
|
||||
height: 720
|
||||
}
|
||||
|
||||
InitializePitctureInPictureAnimation()
|
||||
InitializePitctureInPictureFullScreenHint()
|
||||
|
||||
DisposableObserveField(m.top, "minimizeState", FuncName(OnMinimizeStateChange))
|
||||
DisposableObserveFieldScoped(m.container, "fullscreen", FuncName(OnFullScreenChange))
|
||||
|
||||
if m.container.fullscreen
|
||||
m.top.minimizeState = MinimizeState.Maximized
|
||||
else
|
||||
m.top.minimizeState = MinimizeState.Minimized
|
||||
end if
|
||||
end function
|
||||
|
||||
function InitializePitctureInPictureAnimation()
|
||||
m.minimizeAnimation = m.top.findNode("minimizeAnimation")
|
||||
m.widthInterpolator = m.minimizeAnimation.findNode("widthInterpolator")
|
||||
m.heightInterpolator = m.minimizeAnimation.findNode("heightInterpolator")
|
||||
m.translationInterpolator = m.minimizeAnimation.findNode("translationInterpolator")
|
||||
DisposableObserveFieldScoped(m.minimizeAnimation, "state", FuncName(OnMinimizeAnimationStateChange))
|
||||
|
||||
m.widthInterpolator.keyValue = [m.maxRect.width, (m.maxRect.width + m.minRect.width) / 2, m.minRect.width]
|
||||
m.heightInterpolator.keyValue = [m.maxRect.height, (m.maxRect.height + m.minRect.height) / 2, m.minRect.height]
|
||||
midTranslation = [(m.maxRect.translation[0] + m.minRect.translation[0]) / 2, (m.maxRect.translation[1] + m.minRect.translation[1]) / 2]
|
||||
m.translationInterpolator.keyValue = [m.maxRect.translation, midTranslation, m.minRect.translation]
|
||||
end function
|
||||
|
||||
function InitializePitctureInPictureFullScreenHint()
|
||||
m.fullScreenHint = m.top.findNode("fullScreenHint")
|
||||
m.fullScreenHintLabel = m.fullScreenHint.findNode("fullScreenHintLabel")
|
||||
m.fullScreenHintTimer = m.fullScreenHint.findNode("fullScreenHintTimer")
|
||||
DisposableObserveFieldScoped(m.fullScreenHintTimer, "fire", FuncName(HideFullScreenHint))
|
||||
|
||||
m.fullScreenHint.width = m.minRect.width
|
||||
m.fullScreenHintLabel.width = m.minRect.width
|
||||
m.fullScreenHint.translation = [0, m.minRect.height - m.fullScreenHint.height]
|
||||
end function
|
||||
|
||||
function OnMinimizeStateChange()
|
||||
state = m.top.minimizeState
|
||||
|
||||
if state = MinimizeState.Minimizing
|
||||
OnMinimizingState()
|
||||
else if state = MinimizeState.Minimized
|
||||
OnMinimizedState()
|
||||
else if state = MinimizeState.Maximizing
|
||||
OnMaximizingState()
|
||||
else if state = MinimizeState.Maximized
|
||||
OnMaximizedState()
|
||||
end if
|
||||
end function
|
||||
|
||||
function OnMinimizingState()
|
||||
m.videoUi.visible = false
|
||||
|
||||
m.widthInterpolator.reverse = false
|
||||
m.heightInterpolator.reverse = false
|
||||
m.translationInterpolator.reverse = false
|
||||
m.minimizeAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnMinimizedState()
|
||||
m.container.fullscreen = false
|
||||
|
||||
m.top.width = m.minRect.width
|
||||
m.top.height = m.minRect.height
|
||||
m.top.translation = m.minRect.translation
|
||||
|
||||
m.videoUi.visible = false
|
||||
ShowFullScreenHint()
|
||||
end function
|
||||
|
||||
function OnMaximizingState()
|
||||
m.videoUi.visible = true
|
||||
HideFullScreenHint()
|
||||
|
||||
m.widthInterpolator.reverse = true
|
||||
m.heightInterpolator.reverse = true
|
||||
m.translationInterpolator.reverse = true
|
||||
m.minimizeAnimation.control = "start"
|
||||
end function
|
||||
|
||||
function OnMaximizedState()
|
||||
m.container.fullscreen = true
|
||||
|
||||
m.top.width = m.maxRect.width
|
||||
m.top.height = m.maxRect.height
|
||||
m.top.translation = m.maxRect.translation
|
||||
|
||||
HideFullScreenHint()
|
||||
m.videoUi.visible = true
|
||||
end function
|
||||
|
||||
function OnFullScreenChange()
|
||||
if m.container.fullscreen
|
||||
Maximize()
|
||||
else
|
||||
Minimize()
|
||||
end if
|
||||
end function
|
||||
|
||||
function Minimize() as void
|
||||
state = m.top.minimizeState
|
||||
if state = MinimizeState.Minimized
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.minimizeState = MinimizeState.Minimizing
|
||||
end function
|
||||
|
||||
function Maximize() as void
|
||||
state = m.top.minimizeState
|
||||
if state = MinimizeState.Maximized
|
||||
return
|
||||
end if
|
||||
|
||||
m.top.minimizeState = MinimizeState.Maximizing
|
||||
end function
|
||||
|
||||
function ShowFullScreenHint()
|
||||
m.fullScreenHint.visible = true
|
||||
|
||||
m.fullScreenHintTimer.control = "stop"
|
||||
m.fullScreenHintTimer.control = "start"
|
||||
end function
|
||||
|
||||
function HideFullScreenHint()
|
||||
m.fullScreenHint.visible = false
|
||||
end function
|
||||
|
||||
function OnMinimizeAnimationStateChange() as void
|
||||
' "stopped" Indicates that the animation has either run to completion or has been explicitly stopped.
|
||||
' Since we don't stop the animation explicitly, we can assume that the animation has run to completion.
|
||||
' This assumption becomes invalid if we set m.minimizeAnimation.control = "stop"
|
||||
if m.minimizeAnimation.state <> "stopped"
|
||||
return
|
||||
end if
|
||||
|
||||
state = m.top.minimizeState
|
||||
if state = MinimizeState.Minimizing
|
||||
m.top.minimizeState = MinimizeState.Minimized
|
||||
else if state = MinimizeState.Maximizing
|
||||
m.top.minimizeState = MinimizeState.Maximized
|
||||
end if
|
||||
end function
|
||||
|
||||
function ShutDownPitctureInPicture()
|
||||
m.fullScreenHintTimer.control = "stop"
|
||||
end function
|
||||
Reference in new issue
Block a user