Use CFading where possible

This commit is contained in:
Flamefire committed 2014-03-14 18:15:12 +01:00
1 parent 23364c3bcb
commit 790eda4e15
10 files changed
+119 -202

No files matched your search

+7 -9
View File
@@ -17,7 +17,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using VocaluxeLib; using VocaluxeLib;
@@ -39,7 +38,7 @@ namespace Vocaluxe.Base
private static int _Video = -1; private static int _Video = -1;
private static CTexture _CurrentVideoTexture; private static CTexture _CurrentVideoTexture;
private static readonly Stopwatch _FadeTimer = new Stopwatch(); private static CFading _VideoFading;
private static bool _VideoEnabled; private static bool _VideoEnabled;
private static bool _OwnMusicAdded; private static bool _OwnMusicAdded;
@@ -442,12 +441,12 @@ namespace Vocaluxe.Base
float vtime; float vtime;
if (CVideo.GetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime)) if (CVideo.GetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime))
{ {
if (_FadeTimer.ElapsedMilliseconds <= 3000L) if (_VideoFading != null)
_CurrentVideoTexture.Color.A = _FadeTimer.ElapsedMilliseconds / 3000f;
else
{ {
_CurrentVideoTexture.Color.A = 1f; bool finished;
_FadeTimer.Stop(); _CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished);
if (finished)
_VideoFading = null;
} }
return _CurrentVideoTexture; return _CurrentVideoTexture;
} }
@@ -469,8 +468,7 @@ namespace Vocaluxe.Base
CVideo.Skip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); CVideo.Skip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap);
else else
CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap);
_FadeTimer.Reset(); _VideoFading = new CFading(0f, 1f, 3f);
_FadeTimer.Start();
} }
} }
+11 -37
View File
@@ -24,10 +24,7 @@ namespace Vocaluxe.Base
{ {
class CCursor class CCursor
{ {
private readonly Stopwatch _CursorFadingTimer = new Stopwatch(); private CFading _Fading;
private float _CursorTargetAlpha = 1f;
private float _CursorStartAlpha;
private float _CursorFadingTime = 0.5f;
private CTexture _Cursor; private CTexture _Cursor;
private readonly Stopwatch _Movetimer = new Stopwatch(); private readonly Stopwatch _Movetimer = new Stopwatch();
@@ -52,28 +49,19 @@ namespace Vocaluxe.Base
public void Draw() public void Draw()
{ {
if (_Movetimer.IsRunning && _Movetimer.ElapsedMilliseconds / 1000f > CSettings.MouseMoveOffTime) if (_Movetimer.IsRunning && _Movetimer.ElapsedMilliseconds > CSettings.MouseMoveOffTime)
{ {
_Movetimer.Stop(); _Movetimer.Stop();
_Fade(0f, 0.5f); _Fade(0f, 0.5f);
} }
if (_CursorFadingTimer.IsRunning) if (_Fading != null)
{ {
float t = _CursorFadingTimer.ElapsedMilliseconds / 1000f; bool finished;
if (t < _CursorFadingTime) _Cursor.Color.A = _Fading.GetValue(out finished);
{ if (finished)
if (_CursorTargetAlpha >= _CursorStartAlpha) _Fading = null;
_Cursor.Color.A = _CursorStartAlpha + (_CursorTargetAlpha - _CursorStartAlpha) * t / _CursorFadingTime;
else
_Cursor.Color.A = (_CursorStartAlpha - _CursorTargetAlpha) * (1f - t / _CursorFadingTime);
}
else
{
_CursorFadingTimer.Stop();
_Cursor.Color.A = _CursorTargetAlpha;
}
} }
if (Visible && (CSettings.GameState == EGameState.EditTheme || ShowCursor)) if (Visible && (CSettings.GameState == EGameState.EditTheme || ShowCursor))
@@ -85,11 +73,10 @@ namespace Vocaluxe.Base
if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin || if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin ||
Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin) Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin)
{ {
if (_CursorTargetAlpha < 0.01) if (!IsActive)
_Fade(1f, 0.2f); _Fade(1f, 0.2f);
_Movetimer.Reset(); _Movetimer.Restart();
_Movetimer.Start();
CSettings.MouseActive(); CSettings.MouseActive();
} }
@@ -130,26 +117,13 @@ namespace Vocaluxe.Base
public void FadeIn() public void FadeIn()
{ {
_Movetimer.Reset(); _Movetimer.Restart();
_Movetimer.Start();
_Fade(1f, 0.2f); _Fade(1f, 0.2f);
} }
private void _Fade(float targetAlpha, float time) private void _Fade(float targetAlpha, float time)
{ {
_CursorFadingTimer.Stop(); _Fading = new CFading(_Cursor.Color.A, targetAlpha, time);
_CursorFadingTimer.Reset();
if (targetAlpha >= 0f && targetAlpha <= 1f)
_CursorTargetAlpha = targetAlpha;
else
_CursorTargetAlpha = 1f;
if (time >= 0f)
_CursorFadingTime = time;
_CursorStartAlpha = _Cursor.Color.A;
_CursorFadingTimer.Start();
} }
} }
} }
+35 -66
View File
@@ -30,13 +30,11 @@ namespace Vocaluxe.Base
{ {
static class CGraphics static class CGraphics
{ {
private static bool _Fading; private static CFading _Fading;
private static Stopwatch _FadingTimer;
private static readonly CCursor _Cursor = new CCursor(); private static readonly CCursor _Cursor = new CCursor();
private static float _GlobalAlpha; private static float _GlobalAlpha;
private static float _ZOffset; private static float _ZOffset;
private static IMenu _OldScreen;
private static EScreens _CurrentScreen; private static EScreens _CurrentScreen;
private static EScreens _NextScreen; private static EScreens _NextScreen;
private static EPopupScreens _CurrentPopupScreen; private static EPopupScreens _CurrentPopupScreen;
@@ -98,7 +96,6 @@ namespace Vocaluxe.Base
_CurrentScreen = EScreens.ScreenLoad; _CurrentScreen = EScreens.ScreenLoad;
_NextScreen = EScreens.ScreenNull; _NextScreen = EScreens.ScreenNull;
_CurrentPopupScreen = EPopupScreens.NoPopup; _CurrentPopupScreen = EPopupScreens.NoPopup;
_FadingTimer = new Stopwatch();
_VolumePopupTimer = new Stopwatch(); _VolumePopupTimer = new Stopwatch();
_GlobalAlpha = 1f; _GlobalAlpha = 1f;
@@ -198,11 +195,9 @@ namespace Vocaluxe.Base
public static bool Draw() public static bool Draw()
{ {
if ((_NextScreen != EScreens.ScreenNull) && !_Fading) if (_NextScreen != EScreens.ScreenNull && _Fading == null)
{ {
_Fading = true; _Fading = new CFading(0f, 1f, CConfig.FadeTime);
_FadingTimer.Reset();
_FadingTimer.Start();
if (_NextScreen == EScreens.ScreenPartyDummy) if (_NextScreen == EScreens.ScreenPartyDummy)
{ {
@@ -216,49 +211,29 @@ namespace Vocaluxe.Base
HidePopup(EPopupScreens.PopupPlayerControl); HidePopup(EPopupScreens.PopupPlayerControl);
} }
if (_Fading) if (_Fading != null)
{ {
long fadeTime = (long)(CConfig.FadeTime * 1000); bool finished;
float newAlpha = _Fading.GetValue(out finished);
if ((_FadingTimer.ElapsedMilliseconds < fadeTime) && (CConfig.FadeTime > 0)) if (!finished)
{ {
long ms = 1; _GlobalAlpha = 1f; // -newAlpha / 100f;
if (_FadingTimer.ElapsedMilliseconds > 0)
ms = _FadingTimer.ElapsedMilliseconds;
float factor = (float)ms / fadeTime;
_GlobalAlpha = 1f; // -factor / 100f;
_ZOffset = CSettings.ZFar / 2; _ZOffset = CSettings.ZFar / 2;
if (_CurrentScreen == EScreens.ScreenPartyDummy) _DrawScreen(_CurrentScreen);
{
CFonts.PartyModeID = CParty.CurrentPartyModeID;
_OldScreen.Draw();
CFonts.PartyModeID = -1;
}
else
_OldScreen.Draw();
_GlobalAlpha = factor; _GlobalAlpha = newAlpha;
_ZOffset = 0f; _ZOffset = 0f;
if (_NextScreen == EScreens.ScreenPartyDummy) _DrawScreen(_NextScreen);
{
CFonts.PartyModeID = CParty.CurrentPartyModeID;
_Screens[(int)_NextScreen].Draw();
CFonts.PartyModeID = -1;
}
else
_Screens[(int)_NextScreen].Draw();
_GlobalAlpha = 1f; _GlobalAlpha = 1f;
} }
else else
{ {
_Screens[(int)_CurrentScreen].OnClose(); _Screens[(int)_CurrentScreen].OnClose();
GC.Collect();
_CurrentScreen = _NextScreen; _CurrentScreen = _NextScreen;
_NextScreen = EScreens.ScreenNull; _NextScreen = EScreens.ScreenNull;
if (CBackgroundMusic.IsPlaying) if (CBackgroundMusic.IsPlaying)
@@ -266,32 +241,13 @@ namespace Vocaluxe.Base
_Screens[(int)_CurrentScreen].OnShowFinish(); _Screens[(int)_CurrentScreen].OnShowFinish();
_Screens[(int)_CurrentScreen].ProcessMouseMove(_Cursor.X, _Cursor.Y); _Screens[(int)_CurrentScreen].ProcessMouseMove(_Cursor.X, _Cursor.Y);
if (_CurrentScreen == EScreens.ScreenPartyDummy) _DrawScreen(_CurrentScreen);
{
CFonts.PartyModeID = CParty.CurrentPartyModeID;
_Screens[(int)_CurrentScreen].Draw();
CFonts.PartyModeID = -1;
}
else
_Screens[(int)_CurrentScreen].Draw();
_Fading = false; _Fading = null;
_FadingTimer.Stop();
} }
} }
else else
{ _DrawScreen(_CurrentScreen);
if (_CurrentScreen == EScreens.ScreenPartyDummy)
{
CFonts.PartyModeID = CParty.CurrentPartyModeID;
_Screens[(int)_CurrentScreen].Draw();
CFonts.PartyModeID = -1;
}
else
_Screens[(int)_CurrentScreen].Draw();
_OldScreen = _Screens[(int)_CurrentScreen];
}
foreach (IMenu popup in _PopupScreens) foreach (IMenu popup in _PopupScreens)
popup.Draw(); popup.Draw();
@@ -302,6 +258,18 @@ namespace Vocaluxe.Base
return true; return true;
} }
private static void _DrawScreen(EScreens screen)
{
if (screen == EScreens.ScreenPartyDummy)
{
CFonts.PartyModeID = CParty.CurrentPartyModeID;
_Screens[(int)screen].Draw();
CFonts.PartyModeID = -1;
}
else
_Screens[(int)screen].Draw();
}
public static void FadeTo(EScreens screen) public static void FadeTo(EScreens screen)
{ {
if (screen == EScreens.ScreenPartyDummy) if (screen == EScreens.ScreenPartyDummy)
@@ -483,8 +451,7 @@ namespace Vocaluxe.Base
if (_CurrentPopupScreen == EPopupScreens.NoPopup && diff != 0) if (_CurrentPopupScreen == EPopupScreens.NoPopup && diff != 0)
{ {
ShowPopup(EPopupScreens.PopupVolumeControl); ShowPopup(EPopupScreens.PopupVolumeControl);
_VolumePopupTimer.Reset(); _VolumePopupTimer.Restart();
_VolumePopupTimer.Start();
} }
CBackgroundMusic.ApplyVolume(); CBackgroundMusic.ApplyVolume();
@@ -498,7 +465,7 @@ namespace Vocaluxe.Base
CDraw.MakeScreenShot(); CDraw.MakeScreenShot();
else else
{ {
if (!_Fading) if (_Fading == null)
{ {
bool handled = false; bool handled = false;
if (_CurrentPopupScreen != EPopupScreens.NoPopup) if (_CurrentPopupScreen != EPopupScreens.NoPopup)
@@ -562,12 +529,14 @@ namespace Vocaluxe.Base
bool handled = false; bool handled = false;
if (_CurrentPopupScreen != EPopupScreens.NoPopup) if (_CurrentPopupScreen != EPopupScreens.NoPopup)
{
handled = _PopupScreens[(int)_CurrentPopupScreen].HandleMouse(mouseEvent); handled = _PopupScreens[(int)_CurrentPopupScreen].HandleMouse(mouseEvent);
if (handled && _CurrentPopupScreen == EPopupScreens.PopupVolumeControl) if (handled && _CurrentPopupScreen == EPopupScreens.PopupVolumeControl)
_Screens[(int)_CurrentScreen].ApplyVolume(); _Screens[(int)_CurrentScreen].ApplyVolume();
}
if (!handled && !_Fading && (_Cursor.IsActive || mouseEvent.LB || mouseEvent.RB || mouseEvent.MB)) if (!handled && _Fading == null && (_Cursor.IsActive || mouseEvent.LB || mouseEvent.RB || mouseEvent.MB))
resume &= _Screens[(int)_CurrentScreen].HandleMouse(mouseEvent); resume &= _Screens[(int)_CurrentScreen].HandleMouse(mouseEvent);
if (!eventsAvailable) if (!eventsAvailable)
@@ -594,14 +563,14 @@ namespace Vocaluxe.Base
CDraw.MakeScreenShot(); CDraw.MakeScreenShot();
else else
{ {
if (!_Fading) if (_Fading == null)
_Screens[(int)_CurrentScreen].HandleInputThemeEditor(keyEvent); _Screens[(int)_CurrentScreen].HandleInputThemeEditor(keyEvent);
} }
} }
while (mouse.PollEvent(ref mouseEvent)) while (mouse.PollEvent(ref mouseEvent))
{ {
if (!_Fading) if (_Fading == null)
_Screens[(int)_CurrentScreen].HandleMouseThemeEditor(mouseEvent); _Screens[(int)_CurrentScreen].HandleMouseThemeEditor(mouseEvent);
_UpdateMousePosition(mouseEvent.X, mouseEvent.Y); _UpdateMousePosition(mouseEvent.X, mouseEvent.Y);
+1 -1
View File
@@ -129,7 +129,7 @@ namespace Vocaluxe.Base
public const int NumNoteLines = 11; public const int NumNoteLines = 11;
public static int MouseMoveDiffMin = 2; public static int MouseMoveDiffMin = 2;
public const float MouseMoveOffTime = 3f; public const int MouseMoveOffTime = 3000; //in ms
public const int MaxNumPlayer = 6; public const int MaxNumPlayer = 6;
public const int MaxScore = 10000; public const int MaxScore = 10000;
@@ -213,14 +213,6 @@ namespace Vocaluxe.Lib.Sound
private class CGstreamerSharpAudioStream private class CGstreamerSharpAudioStream
{ {
private enum EStreamAction
{
Nothing,
Pause,
Stop,
Close
}
private Element _Element; private Element _Element;
private bool _Loop; private bool _Loop;
public volatile bool Closed = true; public volatile bool Closed = true;
+23 -31
View File
@@ -24,6 +24,7 @@ using System.IO;
using System.Threading; using System.Threading;
using Vocaluxe.Base; using Vocaluxe.Base;
using Vocaluxe.Lib.Sound.Decoder; using Vocaluxe.Lib.Sound.Decoder;
using VocaluxeLib;
namespace Vocaluxe.Lib.Sound namespace Vocaluxe.Lib.Sound
{ {
@@ -370,14 +371,8 @@ namespace Vocaluxe.Lib.Sound
private float _Volume = 1f; private float _Volume = 1f;
private float _VolumeMax = 1f; private float _VolumeMax = 1f;
private readonly Stopwatch _FadeTimer = new Stopwatch(); private EStreamAction _AfterFadeAction;
private CFading _Fading;
private float _FadeTime;
private float _TargetVolume = 1f;
private float _StartVolume = 1f;
private bool _CloseStreamAfterFade;
private bool _PauseStreamAfterFade;
private bool _Fading;
private readonly Stopwatch _Timer = new Stopwatch(); private readonly Stopwatch _Timer = new Stopwatch();
@@ -519,33 +514,28 @@ namespace Vocaluxe.Lib.Sound
public void Fade(float targetVolume, float fadeTime) public void Fade(float targetVolume, float fadeTime)
{ {
_Fading = true; _Fading = new CFading(_Volume, targetVolume, fadeTime);
_FadeTimer.Stop(); _AfterFadeAction = EStreamAction.Nothing;
_FadeTimer.Reset();
_StartVolume = _Volume;
_TargetVolume = targetVolume / 100f;
_FadeTime = fadeTime;
_FadeTimer.Start();
} }
public void FadeAndPause(float targetVolume, float fadeTime) public void FadeAndPause(float targetVolume, float fadeTime)
{ {
_PauseStreamAfterFade = true;
Fade(targetVolume, fadeTime); Fade(targetVolume, fadeTime);
_AfterFadeAction = EStreamAction.Pause;
} }
public void FadeAndStop(float targetVolume, float fadeTime, Closeproc closeProc, int streamID) public void FadeAndStop(float targetVolume, float fadeTime, Closeproc closeProc, int streamID)
{ {
_Closeproc = closeProc; _Closeproc = closeProc;
_StreamID = streamID; _StreamID = streamID;
_CloseStreamAfterFade = true;
Fade(targetVolume, fadeTime); Fade(targetVolume, fadeTime);
_AfterFadeAction = EStreamAction.Stop;
} }
public void Play() public void Play()
{ {
Paused = false; Paused = false;
_PauseStreamAfterFade = false; _AfterFadeAction = EStreamAction.Nothing;
AL.SourcePlay(_Source); AL.SourcePlay(_Source);
} }
@@ -745,21 +735,23 @@ namespace Vocaluxe.Lib.Sound
private void _Update() private void _Update()
{ {
if (_Fading) if (_Fading != null)
{ {
if (_FadeTimer.ElapsedMilliseconds / 1000f < _FadeTime) bool finished;
_Volume = _StartVolume + (_TargetVolume - _StartVolume) * ((_FadeTimer.ElapsedMilliseconds / 1000f) / _FadeTime); _Volume = _Fading.GetValue(out finished);
else if (finished)
{ {
_Volume = _TargetVolume; switch (_AfterFadeAction)
_FadeTimer.Stop(); {
_Fading = false; case EStreamAction.Close:
case EStreamAction.Stop:
if (_CloseStreamAfterFade) _Terminated = true;
_Terminated = true; break;
case EStreamAction.Pause:
if (_PauseStreamAfterFade) Paused = true;
Paused = true; break;
}
_Fading = null;
} }
} }
} }
+25 -40
View File
@@ -17,7 +17,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -25,6 +24,7 @@ using System.Threading;
using Vocaluxe.Base; using Vocaluxe.Base;
using Vocaluxe.Lib.Sound.Decoder; using Vocaluxe.Lib.Sound.Decoder;
using Vocaluxe.Lib.Sound.PortAudio; using Vocaluxe.Lib.Sound.PortAudio;
using VocaluxeLib;
namespace Vocaluxe.Lib.Sound namespace Vocaluxe.Lib.Sound
{ {
@@ -351,15 +351,8 @@ namespace Vocaluxe.Lib.Sound
private float _Volume = 1f; private float _Volume = 1f;
private float _VolumeMax = 1f; private float _VolumeMax = 1f;
private readonly Stopwatch _FadeTimer = new Stopwatch(); private EStreamAction _AfterFadeAction;
private CFading _Fading;
private float _FadeTime;
private float _TargetVolume = 1f;
private float _StartVolume = 1f;
private bool _CloseStreamAfterFade;
private bool _PauseStreamAfterFade;
private bool _StopStreamAfterFade;
private bool _Fading;
private static CPortAudio.SPaHostApiInfo _ApiInfo; private static CPortAudio.SPaHostApiInfo _ApiInfo;
private static CPortAudio.SPaDeviceInfo _OutputDeviceInfo; private static CPortAudio.SPaDeviceInfo _OutputDeviceInfo;
@@ -507,19 +500,12 @@ namespace Vocaluxe.Lib.Sound
public void Fade(float targetVolume, float fadeTime) public void Fade(float targetVolume, float fadeTime)
{ {
_Fading = true; _Fading = new CFading(_Volume, targetVolume, fadeTime);
_FadeTimer.Stop(); _AfterFadeAction = EStreamAction.Nothing;
_FadeTimer.Reset();
_StartVolume = _Volume;
_TargetVolume = targetVolume / 100f;
_FadeTime = fadeTime;
_FadeTimer.Start();
} }
public void FadeAndPause(float targetVolume, float fadeTime) public void FadeAndPause(float targetVolume, float fadeTime)
{ {
_PauseStreamAfterFade = true;
Fade(targetVolume, fadeTime); Fade(targetVolume, fadeTime);
} }
@@ -527,25 +513,22 @@ namespace Vocaluxe.Lib.Sound
{ {
_Closeproc = closeProc; _Closeproc = closeProc;
_StreamID = streamID; _StreamID = streamID;
_CloseStreamAfterFade = true;
Fade(targetVolume, fadeTime); Fade(targetVolume, fadeTime);
_AfterFadeAction = EStreamAction.Close;
} }
public void FadeAndStop(float targetVolume, float fadeTime, Closeproc closeProc, int streamID) public void FadeAndStop(float targetVolume, float fadeTime, Closeproc closeProc, int streamID)
{ {
_Closeproc = closeProc; _Closeproc = closeProc;
_StreamID = streamID; _StreamID = streamID;
_StopStreamAfterFade = true;
Fade(targetVolume, fadeTime); Fade(targetVolume, fadeTime);
_AfterFadeAction = EStreamAction.Stop;
} }
public void Play() public void Play()
{ {
Paused = false; Paused = false;
_PauseStreamAfterFade = false; _AfterFadeAction = EStreamAction.Nothing;
_StopStreamAfterFade = false;
lock (_Mutex) lock (_Mutex)
{ {
_ErrorCheck("StartStream", CPortAudio.Pa_StartStream(_Ptr)); _ErrorCheck("StartStream", CPortAudio.Pa_StartStream(_Ptr));
@@ -927,23 +910,25 @@ namespace Vocaluxe.Lib.Sound
private void _Update() private void _Update()
{ {
if (_Fading) if (_Fading != null)
{ {
if (_FadeTimer.ElapsedMilliseconds / 1000f < _FadeTime) bool finished;
_Volume = _StartVolume + (_TargetVolume - _StartVolume) * ((_FadeTimer.ElapsedMilliseconds / 1000f) / _FadeTime); _Volume = _Fading.GetValue(out finished);
else if (finished)
{ {
_Volume = _TargetVolume; switch (_AfterFadeAction)
_FadeTimer.Stop(); {
_Fading = false; case EStreamAction.Close:
_Terminated = true;
if (_CloseStreamAfterFade) break;
_Terminated = true; case EStreamAction.Stop:
Stop();
if (_PauseStreamAfterFade) break;
Paused = true; case EStreamAction.Pause:
if (_StopStreamAfterFade) Paused = true;
Stop(); break;
}
_Fading = null;
} }
} }
} }
+8
View File
@@ -17,6 +17,14 @@
namespace Vocaluxe.Lib.Sound namespace Vocaluxe.Lib.Sound
{ {
public enum EStreamAction
{
Nothing,
Pause,
Stop,
Close
}
struct SAudioStreams struct SAudioStreams
{ {
public int Handle; public int Handle;
+2
View File
@@ -34,6 +34,8 @@ namespace VocaluxeLib
/// <param name="duration">Duration of the fading in seconds</param> /// <param name="duration">Duration of the fading in seconds</param>
public CFading(float fromValue, float toValue, float duration) public CFading(float fromValue, float toValue, float duration)
{ {
if (duration < 0)
duration = 0;
_FromValue = fromValue; _FromValue = fromValue;
_ToValue = toValue; _ToValue = toValue;
_Duration = duration * 1000f; _Duration = duration * 1000f;
@@ -17,7 +17,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
@@ -99,7 +98,7 @@ namespace VocaluxeLib.Menu.SongMenu
protected SThemeSongMenu _Theme; protected SThemeSongMenu _Theme;
private bool _ThemeLoaded; private bool _ThemeLoaded;
private readonly Stopwatch _VideoFadeTimer = new Stopwatch(); private CFading _VideoFading;
private readonly List<int> _Streams = new List<int>(); private readonly List<int> _Streams = new List<int>();
protected CTexture _Vidtex; protected CTexture _Vidtex;
@@ -388,12 +387,12 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
if (_Vidtex != null) if (_Vidtex != null)
{ {
if (_VideoFadeTimer.ElapsedMilliseconds <= 3000L) if (_VideoFading != null)
_Vidtex.Color.A = _VideoFadeTimer.ElapsedMilliseconds / 3000f;
else
{ {
_Vidtex.Color.A = 1f; bool finished;
_VideoFadeTimer.Stop(); _Vidtex.Color.A = _VideoFading.GetValue(out finished);
if (finished)
_VideoFading = null;
} }
} }
} }
@@ -563,9 +562,7 @@ namespace VocaluxeLib.Menu.SongMenu
if (_PreviewVideoStream == -1) if (_PreviewVideoStream == -1)
return; return;
CBase.Video.Skip(_PreviewVideoStream, startposition, song.VideoGap); CBase.Video.Skip(_PreviewVideoStream, startposition, song.VideoGap);
_VideoFadeTimer.Stop(); _VideoFading = new CFading(0f, 1f, 3f);
_VideoFadeTimer.Reset();
_VideoFadeTimer.Start();
} }
} }
} }