Merge branch 'Font_Rewrite' into Automatic_Covers

This commit is contained in:
Flamefire committed 2014-09-10 17:19:25 +02:00
commit eaa709813d
40 files changed
+1206 -813

No files matched your search

+12 -8
View File
@@ -4,10 +4,12 @@
<Font1> <Font1>
<Name>Normal</Name> <Name>Normal</Name>
<Outline>0,00</Outline> <Outline>0,00</Outline>
<OutlineColorR>0,00</OutlineColorR> <OutlineColor>
<OutlineColorG>0,00</OutlineColorG> <R>0,00</R>
<OutlineColorB>0,00</OutlineColorB> <G>0,00</G>
<OutlineColorA>1,00</OutlineColorA> <B>0,00</B>
<A>1,00</A>
</OutlineColor>
<Folder>FreeSans</Folder> <Folder>FreeSans</Folder>
<FileNormal>FreeSans.ttf</FileNormal> <FileNormal>FreeSans.ttf</FileNormal>
<FileBold>FreeSansBold.ttf</FileBold> <FileBold>FreeSansBold.ttf</FileBold>
@@ -17,10 +19,12 @@
<Font2> <Font2>
<Name>Outline</Name> <Name>Outline</Name>
<Outline>0,10</Outline> <Outline>0,10</Outline>
<OutlineColorR>0,00</OutlineColorR> <OutlineColor>
<OutlineColorG>0,00</OutlineColorG> <R>0,00</R>
<OutlineColorB>0,00</OutlineColorB> <G>0,00</G>
<OutlineColorA>1,00</OutlineColorA> <B>0,00</B>
<A>1,00</A>
</OutlineColor>
<Folder>FreeSans</Folder> <Folder>FreeSans</Folder>
<FileNormal>FreeSans.ttf</FileNormal> <FileNormal>FreeSans.ttf</FileNormal>
<FileBold>FreeSansBold.ttf</FileBold> <FileBold>FreeSansBold.ttf</FileBold>
+1
View File
@@ -76,6 +76,7 @@
<string name="TR_CONFIG_OWN_MUSIC">Own Music and Background Music</string> <string name="TR_CONFIG_OWN_MUSIC">Own Music and Background Music</string>
<string name="TR_CONFIG_NO_OWN_MUSIC">No own Music</string> <string name="TR_CONFIG_NO_OWN_MUSIC">No own Music</string>
<string name="TR_CONFIG_ONLY_OWN_MUSIC">Only own Music</string> <string name="TR_CONFIG_ONLY_OWN_MUSIC">Only own Music</string>
<string name="TR_CONFIG_ONLY_SONG">Only selected song</string>
<string name="TR_CONFIG_FADEPLAYERINFO_ALL">All</string> <string name="TR_CONFIG_FADEPLAYERINFO_ALL">All</string>
<string name="TR_CONFIG_FADEPLAYERINFO_INFO">Only names and avatars</string> <string name="TR_CONFIG_FADEPLAYERINFO_INFO">Only names and avatars</string>
<string name="TR_CONFIG_FADEPLAYERINFO_OFF">Nothing</string> <string name="TR_CONFIG_FADEPLAYERINFO_OFF">Nothing</string>
@@ -446,7 +446,7 @@ namespace VocaluxeLib.PartyModes.Challenge
_RoundsTableScrollArea.Y = numberY; _RoundsTableScrollArea.Y = numberY;
_RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20; _RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20;
float delta = _Texts[_TextRoundNumber].Height; float delta = _Texts[_TextRoundNumber].Rect.H;
//Update statics and texts for rounds //Update statics and texts for rounds
foreach (CRoundsTableRow roundRow in _RoundsTable) foreach (CRoundsTableRow roundRow in _RoundsTable)
@@ -479,7 +479,7 @@ namespace VocaluxeLib.PartyModes.Challenge
roundRow.TextScores[column].Y = numberY + delta; roundRow.TextScores[column].Y = numberY + delta;
roundRow.TextScores[column].MaxWidth = maxw; roundRow.TextScores[column].MaxWidth = maxw;
} }
numberY = numberY + delta + delta; numberY = numberY + 2*delta;
} }
numberY = numberY + delta / 2; numberY = numberY + delta / 2;
} }
@@ -532,7 +532,7 @@ namespace VocaluxeLib.PartyModes.Challenge
_PlayerTableScrollArea = new SRectF {X = _Texts[_TextPosition].X, Y = _Texts[_TextPosition].Y, W = _Texts[_TextGamePoints].X - _Texts[_TextPosition].X}; _PlayerTableScrollArea = new SRectF {X = _Texts[_TextPosition].X, Y = _Texts[_TextPosition].Y, W = _Texts[_TextGamePoints].X - _Texts[_TextPosition].X};
_PlayerTable = new List<STableRow>(); _PlayerTable = new List<STableRow>();
float delta = _Texts[_TextPosition].Height * 1.2f; float delta = _Texts[_TextPosition].Rect.H * 1.2f;
float h = 0; float h = 0;
@@ -446,7 +446,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
_RoundsTableScrollArea.Y = numberY; _RoundsTableScrollArea.Y = numberY;
_RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20; _RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20;
float delta = _Texts[_TextRoundNumber].Height; float delta = _Texts[_TextRoundNumber].Rect.H;
//Update statics and texts for rounds //Update statics and texts for rounds
foreach (CRoundsTableRow roundRow in _RoundsTable) foreach (CRoundsTableRow roundRow in _RoundsTable)
@@ -532,7 +532,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
_PlayerTableScrollArea = new SRectF {X = _Texts[_TextPosition].X, Y = _Texts[_TextPosition].Y, W = _Texts[_TextGamePoints].X - _Texts[_TextPosition].X}; _PlayerTableScrollArea = new SRectF {X = _Texts[_TextPosition].X, Y = _Texts[_TextPosition].Y, W = _Texts[_TextGamePoints].X - _Texts[_TextPosition].X};
_PlayerTable = new List<STableRow>(); _PlayerTable = new List<STableRow>();
float delta = _Texts[_TextPosition].Height * 1.2f; float delta = _Texts[_TextPosition].Rect.H * 1.2f;
float h = 0; float h = 0;
@@ -379,7 +379,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
{ {
base.OnClose(); base.OnClose();
CBase.BackgroundMusic.SetDisabled(false); CBase.BackgroundMusic.SetDisabled(false);
CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close);
} }
private void _CreateFields() private void _CreateFields()
@@ -574,7 +574,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
{ {
_GameData.NumJokerRandom[teamNr]--; _GameData.NumJokerRandom[teamNr]--;
if (!CBase.Sound.IsFinished(_PreviewStream)) if (!CBase.Sound.IsFinished(_PreviewStream))
CBase.Sound.FadeAndClose(_PreviewStream, 0, 1); CBase.Sound.Fade(_PreviewStream, 0, 1, EStreamAction.Close);
_FieldSelected(true); _FieldSelected(true);
} }
break; break;
@@ -586,7 +586,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
_GameData.NumJokerRetry[teamNr]--; _GameData.NumJokerRetry[teamNr]--;
_GameData.Team = teamNr; _GameData.Team = teamNr;
if (!CBase.Sound.IsFinished(_PreviewStream)) if (!CBase.Sound.IsFinished(_PreviewStream))
CBase.Sound.FadeAndClose(_PreviewStream, 0, 1); CBase.Sound.Fade(_PreviewStream, 0, 1, EStreamAction.Close);
_Status = EStatus.JokerRetry; _Status = EStatus.JokerRetry;
_OldSelectedField = _SelectedField; _OldSelectedField = _SelectedField;
_SelectedField = -1; _SelectedField = -1;
@@ -627,7 +627,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
private void _NextRound() private void _NextRound()
{ {
CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close);
_Data.ScreenMain.Rounds = _GameData.Rounds; _Data.ScreenMain.Rounds = _GameData.Rounds;
_Data.ScreenMain.FadeToNameSelection = false; _Data.ScreenMain.FadeToNameSelection = false;
_Data.ScreenMain.FadeToSinging = true; _Data.ScreenMain.FadeToSinging = true;
@@ -640,7 +640,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
private void _EndParty() private void _EndParty()
{ {
CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close);
_FadeTo(EScreens.ScreenParty); _FadeTo(EScreens.ScreenParty);
} }
@@ -659,7 +659,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
private void _Back() private void _Back()
{ {
CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close);
_Data.ScreenMain.FadeToNameSelection = true; _Data.ScreenMain.FadeToNameSelection = true;
_Data.ScreenMain.FadeToSinging = false; _Data.ScreenMain.FadeToSinging = false;
_Data.ScreenMain.SingRoundNr = _SelectedField; _Data.ScreenMain.SingRoundNr = _SelectedField;
+155 -145
View File
@@ -22,6 +22,7 @@ using System.IO;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Songs; using VocaluxeLib.Songs;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
using VocaluxeLib.Utils.Player;
namespace Vocaluxe.Base namespace Vocaluxe.Base
{ {
@@ -29,89 +30,98 @@ namespace Vocaluxe.Base
{ {
private static bool _Initialized; private static bool _Initialized;
private static CSongPlayer _SongPlayer;
private static CSongPlayer _PreviewPlayer;
private static bool _OwnSongsAvailable; private static bool _OwnSongsAvailable;
private static EBackgroundMusicSource _MusicSource; private static EBackgroundMusicSource _MusicSource;
private static bool _VideoEnabled; private static bool _VideoEnabled;
private static CPlaylistElement _CurrentPlaylistElement; //Currently played music private static CPlaylistElement _CurrentPlaylistElement; //Currently played music
private static int _CurrentMusicStream = -1; //Current active music stream private static int _PreviousMusicIndex = -1;
private static int _PreviousMusicIndex; //Index of _CurrentPlaylistElement in _PreviousFiles (kept for performance)
private static readonly List<CPlaylistElement> _BGMusicFiles = new List<CPlaylistElement>(); //Background music files private static readonly List<CPlaylistElement> _BGMusicFiles = new List<CPlaylistElement>(); //Background music files
private static readonly List<CPlaylistElement> _NotPlayedFiles = new List<CPlaylistElement>(); //Not played files private static readonly List<CPlaylistElement> _NotPlayedFiles = new List<CPlaylistElement>(); //Not played files
private static readonly List<CPlaylistElement> _PreviousFiles = new List<CPlaylistElement>(); //Played files private static readonly List<CPlaylistElement> _PreviousFiles = new List<CPlaylistElement>(); //Played files
private static int _Video = -1;
private static CTexture _CurrentVideoTexture;
private static CFading _VideoFading;
private static bool _OwnMusicAdded; private static bool _OwnMusicAdded;
private static bool _BackgroundMusicAdded; private static bool _BackgroundMusicAdded;
private static bool _Disabled; private static bool _Disabled;
private static bool _PlaysPreview;
public static bool VideoEnabled public static bool VideoEnabled
{ {
get { return _VideoEnabled; } get { return _PlaysPreview ? _PreviewPlayer.VideoEnabled : _SongPlayer.VideoEnabled; }
set set {
{ if(_PlaysPreview)
if (_VideoEnabled == value) _PreviewPlayer.VideoEnabled = value;
return; else
_VideoEnabled = value; _SongPlayer.VideoEnabled = value;
if (_VideoEnabled)
_LoadVideo();
else if (_Video != -1)
{
CVideo.Close(_Video);
CDraw.RemoveTexture(ref _CurrentVideoTexture);
_Video = -1;
}
} }
} }
public static bool CanSing { get; private set; } public static bool CanSing
{
get
{
if (_PlaysPreview)
return false;
else
if (_BGMusicFiles.Contains(_CurrentPlaylistElement))
return false;
else return true;
}
}
public static bool Disabled public static bool Disabled
{ {
get { return _Disabled; } get { return _Disabled; }
set set
{ {
if (Disabled == value)
return;
_Disabled = value; _Disabled = value;
if (_Disabled)
Pause(); Pause();
else
Play();
} }
} }
public static bool RepeatSong { get; set; } public static bool RepeatSong {
get { return _SongPlayer.RepeatSong; }
set { _SongPlayer.RepeatSong = value; }
}
public static int SongID public static int SongID
{ {
get { return _CurrentPlaylistElement == null ? -1 : _CurrentPlaylistElement.SongID; } get { return _SongPlayer.SongID; }
} }
public static bool SongHasVideo public static bool SongHasVideo
{ {
get { return _CurrentPlaylistElement != null && File.Exists(_CurrentPlaylistElement.VideoFilePath); } get { return _SongPlayer.SongHasVideo; }
} }
public static bool IsPlaying { get; private set; } public static bool IsPlaying { get { return _PlaysPreview ? _PreviewPlayer.IsPlaying : _SongPlayer.IsPlaying; } }
public static bool IsPlayingPreview { get { return _PlaysPreview; } }
public static string ArtistAndTitle public static string ArtistAndTitle
{ {
get get {
{ if (_PlaysPreview)
if (_CurrentPlaylistElement == null) return _PreviewPlayer.ArtistAndTitle;
return ""; else
if (_CurrentPlaylistElement.Artist != "" && _CurrentPlaylistElement.Title != "") return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath) : _SongPlayer.ArtistAndTitle;
return _CurrentPlaylistElement.Artist + " - " + _CurrentPlaylistElement.Title;
return Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath);
} }
} }
public static float Length
{
get { return _PlaysPreview ? _PreviewPlayer.Length : _SongPlayer.Length; }
}
public static CTexture Cover public static CTexture Cover
{ {
get { return _CurrentPlaylistElement == null ? CCover.NoCover : _CurrentPlaylistElement.Cover; } get { return _PlaysPreview ? _PreviewPlayer.Cover : _SongPlayer.Cover; }
} }
//Use this to set whether own songs are available for access //Use this to set whether own songs are available for access
@@ -143,8 +153,13 @@ namespace Vocaluxe.Base
_MusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; _MusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC;
_AddBackgroundMusic(); _AddBackgroundMusic();
_PreviousMusicIndex = -1; _SongPlayer = new CSongPlayer();
IsPlaying = false; _SongPlayer.Volume = CConfig.BackgroundMusicVolume;
_PreviewPlayer = new CSongPlayer();
_PreviewPlayer.Volume = CConfig.PreviewMusicVolume;
_PreviewPlayer.RepeatSong = true;
_VideoEnabled = (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON); _VideoEnabled = (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON);
SetMusicSource(CConfig.BackgroundMusicSource); SetMusicSource(CConfig.BackgroundMusicSource);
_Initialized = true; _Initialized = true;
@@ -152,40 +167,27 @@ namespace Vocaluxe.Base
public static void Close() public static void Close()
{ {
if (_CurrentMusicStream >= 0) _SongPlayer.Stop();
{ _PreviewPlayer.Stop();
CSound.Close(_CurrentMusicStream);
_CurrentMusicStream = -1;
}
if (_Video != -1)
{
CVideo.Close(_Video);
CDraw.RemoveTexture(ref _CurrentVideoTexture);
_Video = -1;
}
_BGMusicFiles.Clear(); _BGMusicFiles.Clear();
_NotPlayedFiles.Clear(); _NotPlayedFiles.Clear();
_PreviousFiles.Clear(); _PreviousFiles.Clear();
IsPlaying = false;
_Initialized = false; _Initialized = false;
} }
public static void Play() public static void Play()
{ {
if (IsPlaying || CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) if (IsPlaying || (CConfig.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_ON && !_PlaysPreview))
return; return;
if (_CurrentMusicStream != -1) if (_PlaysPreview)
{ _PreviewPlayer.Play();
else if(CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF)
if (_SongPlayer.SongLoaded)
//Resume //Resume
CSound.SetStreamVolume(_CurrentMusicStream, 0f); _SongPlayer.TogglePause();
CSound.Fade(_CurrentMusicStream, 100f, CSettings.BackgroundMusicFadeTime);
CSound.Play(_CurrentMusicStream);
if (_VideoEnabled && _Video != -1)
CVideo.Resume(_Video);
IsPlaying = true;
}
else else
Next(); Next();
} }
@@ -195,34 +197,39 @@ namespace Vocaluxe.Base
if (!IsPlaying) if (!IsPlaying)
return; return;
if (_Video != -1) if (_PlaysPreview)
{ {
CVideo.Close(_Video); _PreviewPlayer.Stop();
CDraw.RemoveTexture(ref _CurrentVideoTexture); _PlaysPreview = false;
_Video = -1; Pause();
} }
CSound.FadeAndClose(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime); else
_CurrentMusicStream = -1; {
_SongPlayer.Stop();
_CurrentPlaylistElement = null; _CurrentPlaylistElement = null;
IsPlaying = false; }
} }
public static void Pause() public static void Pause()
{ {
if (!IsPlaying) if (_PlaysPreview)
return;
if (_Video != -1)
{ {
CVideo.Pause(_Video); if (!_PreviewPlayer.SongLoaded)
CVideo.Skip(_Video, CSound.GetPosition(_CurrentMusicStream) + CSettings.BackgroundMusicFadeTime, _CurrentPlaylistElement.VideoGap); return;
_PreviewPlayer.TogglePause();
}
else if (CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
{
if (!_SongPlayer.SongLoaded)
Next();
else
_SongPlayer.TogglePause();
} }
CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime);
IsPlaying = false;
} }
public static void Next() public static void Next()
{
if (!_PlaysPreview)
{ {
Stop(); //stop last song if any Stop(); //stop last song if any
if (_PreviousMusicIndex < _PreviousFiles.Count - 2) if (_PreviousMusicIndex < _PreviousFiles.Count - 2)
@@ -248,68 +255,45 @@ namespace Vocaluxe.Base
_PreviousMusicIndex = _PreviousFiles.Count - 1; _PreviousMusicIndex = _PreviousFiles.Count - 1;
} }
_StartSong(); _StartSong();
CanSing = !_IsBackgroundFile(_CurrentPlaylistElement); }
} }
public static void Previous() public static void Previous()
{
if (!_PlaysPreview)
{ {
if (_PreviousMusicIndex < 0) if (_PreviousMusicIndex < 0)
return; return;
Debug.Assert(_CurrentMusicStream != -1 && _CurrentPlaylistElement != null); Debug.Assert(_CurrentPlaylistElement != null);
if (CSound.GetPosition(_CurrentMusicStream) <= 1.5f && _PreviousMusicIndex > 0) if (_SongPlayer.Position <= 1.5f && _PreviousMusicIndex > 0)
{ {
Stop(); //stop last song Stop(); //stop last song
_PreviousMusicIndex--; _PreviousMusicIndex--;
_CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex];
CanSing = !_IsBackgroundFile(_CurrentPlaylistElement);
} }
_StartSong(); _StartSong();
} }
}
public static void Update() public static void Update()
{ {
if (!IsPlaying) if (!IsPlaying && (!_SongPlayer.SongLoaded || !_PreviewPlayer.SongLoaded) )
return; return;
Debug.Assert(_CurrentMusicStream != -1 && _CurrentPlaylistElement != null);
float timeToPlay; if (_PlaysPreview)
if (Math.Abs(_CurrentPlaylistElement.Finish) < 0.001) _PreviewPlayer.Update();
{
//No End-Tag defined
float len = CSound.GetLength(_CurrentMusicStream);
timeToPlay = (len > 0f) ? len - CSound.GetPosition(_CurrentMusicStream) : CSettings.BackgroundMusicFadeTime + 1f;
}
else //End-Tag found
timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream);
bool finished = CSound.IsFinished(_CurrentMusicStream);
if (timeToPlay <= CSettings.BackgroundMusicFadeTime || finished)
{
if (RepeatSong)
_StartSong();
else else
{
_SongPlayer.Update();
if (_SongPlayer.IsFinished)
Next(); Next();
} }
} }
public static CTexture GetVideoTexture() public static CTexture GetVideoTexture()
{ {
if (_Video == -1) return _PlaysPreview ? _PreviewPlayer.GetVideoTexture() : _SongPlayer.GetVideoTexture();
return null;
float vtime;
if (CVideo.GetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime))
{
if (_VideoFading != null)
{
bool finished;
_CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished);
if (finished)
_VideoFading = null;
}
return _CurrentVideoTexture;
}
return null;
} }
public static void SetMusicSource(EBackgroundMusicSource source) public static void SetMusicSource(EBackgroundMusicSource source)
@@ -335,37 +319,74 @@ namespace Vocaluxe.Base
} }
} }
public static void LoadPreview(CSong song, float start = 0f)
{
if (!_PlaysPreview)
Pause();
else
StopPreview();
if (song == null)
return;
if (start == 0f)
start = song.Preview.StartTime;
_PlaysPreview = true;
_PreviewPlayer.Load(song, start);
float startposition = song.Preview.StartTime;
float length = _PreviewPlayer.Length;
if (song.Preview.Source == EDataSource.None)
startposition = length / 4f;
else if (startposition > length - 5f)
startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f));
if (startposition >= 0.5f)
startposition -= 0.5f;
_PreviewPlayer.Position = startposition;
Play();
}
public static void PlayPreview(float start = -1f)
{
if (start > -1f)
_PreviewPlayer.Position = start;
Play();
}
public static void StopPreview()
{
_PreviewPlayer.Stop();
_PlaysPreview = false;
}
/// <summary> /// <summary>
/// (Re-)Starts the _CurrentPlaylistElement /// (Re-)Starts the _CurrentPlaylistElement
/// </summary> /// </summary>
private static void _StartSong() private static void _StartSong()
{ {
Debug.Assert(_CurrentPlaylistElement != null); Debug.Assert(_CurrentPlaylistElement != null);
//If we have an active stream, reuse it
if (_CurrentMusicStream < 0)
{
//otherwhise load
_CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.MusicFilePath);
if (_CurrentMusicStream < 0)
return;
CSound.SetStreamVolume(_CurrentMusicStream, 0f);
CSound.Fade(_CurrentMusicStream, 100f, CSettings.BackgroundMusicFadeTime);
}
//Seek to #Start-Tag, if found
if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start);
if (_VideoEnabled) //If current song same as loaded restart only
{ if (_CurrentPlaylistElement.SongID == _SongPlayer.SongID && _SongPlayer.SongLoaded)
if (_Video != -1) _SongPlayer.Play();
//otherwhise load
if (_BGMusicFiles.Contains(_CurrentPlaylistElement))
_SongPlayer.LoadFile(_CurrentPlaylistElement.MusicFilePath, 0f, true);
else
{ {
//Seek to #Start-Tag, if found
float start = 0f;
if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap + _CurrentPlaylistElement.Start); start = _CurrentPlaylistElement.Start;
else _SongPlayer.Load(CBase.Songs.GetSongByID(_CurrentPlaylistElement.SongID), start, true);
CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap);
}
else
_LoadVideo();
} }
} }
@@ -419,16 +440,5 @@ namespace Vocaluxe.Base
return _BGMusicFiles.Contains(element); return _BGMusicFiles.Contains(element);
} }
private static void _LoadVideo()
{
if (_Video != -1 || String.IsNullOrEmpty(_CurrentPlaylistElement.VideoFilePath))
return;
_Video = CVideo.Load(_CurrentPlaylistElement.VideoFilePath);
if (CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap + _CurrentPlaylistElement.Start); //Use gap, otherwhise we will overwrite position in GetVideoTexture
else
CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap);
_VideoFading = new CFading(0f, 1f, 3f);
}
} }
} }
+3 -3
View File
@@ -97,7 +97,7 @@ namespace Vocaluxe.Base
public static EBufferSize AudioBufferSize = EBufferSize.B2048; public static EBufferSize AudioBufferSize = EBufferSize.B2048;
public static int AudioLatency; public static int AudioLatency;
private static int _BackgroundMusicVolume = 30; private static int _BackgroundMusicVolume = 30;
public static EOffOn BackgroundMusic = EOffOn.TR_CONFIG_ON; public static EBackgroundMusicOffOn BackgroundMusic = EBackgroundMusicOffOn.TR_CONFIG_ON;
public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC;
public static EOffOn BackgroundMusicUseStart = EOffOn.TR_CONFIG_ON; public static EOffOn BackgroundMusicUseStart = EOffOn.TR_CONFIG_ON;
private static int _PreviewMusicVolume = 50; private static int _PreviewMusicVolume = 50;
@@ -478,8 +478,8 @@ namespace Vocaluxe.Base
writer.WriteComment("AudioLatency from -500 to 500 ms"); writer.WriteComment("AudioLatency from -500 to 500 ms");
writer.WriteElementString("AudioLatency", AudioLatency.ToString()); writer.WriteElementString("AudioLatency", AudioLatency.ToString());
writer.WriteComment("Background Music: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); writer.WriteComment("Background Music: " + CHelper.ListStrings(Enum.GetNames(typeof(EBackgroundMusicOffOn))));
writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EOffOn), BackgroundMusic)); writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EBackgroundMusicOffOn), BackgroundMusic));
writer.WriteComment("Background Music Volume from 0 to 100"); writer.WriteComment("Background Music Volume from 0 to 100");
writer.WriteElementString("BackgroundMusicVolume", BackgroundMusicVolume.ToString()); writer.WriteElementString("BackgroundMusicVolume", BackgroundMusicVolume.ToString());
+13 -9
View File
@@ -60,6 +60,11 @@ namespace Vocaluxe.Base
get { return _CurrentScreen; } get { return _CurrentScreen; }
} }
public static EScreens NextScreen
{
get { return _NextScreen; }
}
#region public methods #region public methods
public static void Init() public static void Init()
{ {
@@ -335,7 +340,7 @@ namespace Vocaluxe.Base
bool popupVolumeControlAllowed = _CurrentScreen != EScreens.ScreenCredits && _CurrentScreen != EScreens.ScreenOptionsRecord; bool popupVolumeControlAllowed = _CurrentScreen != EScreens.ScreenCredits && _CurrentScreen != EScreens.ScreenOptionsRecord;
//Hide volume control for bg-music if bg-music is disabled //Hide volume control for bg-music if bg-music is disabled
if (popupVolumeControlAllowed && (_CurrentScreen != EScreens.ScreenSong || CSongs.Category == -1) if (popupVolumeControlAllowed && (_CurrentScreen != EScreens.ScreenSong || CSongs.Category == -1)
&& _CurrentScreen != EScreens.ScreenSing && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) && _CurrentScreen != EScreens.ScreenSing && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF)
popupVolumeControlAllowed = false; popupVolumeControlAllowed = false;
@@ -391,13 +396,13 @@ namespace Vocaluxe.Base
if (popupPlayerControlAllowed && keyEvent.Key == Keys.Tab) if (popupPlayerControlAllowed && keyEvent.Key == Keys.Tab)
{ {
if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
ShowPopup(EPopupScreens.PopupPlayerControl); ShowPopup(EPopupScreens.PopupPlayerControl);
else else
HidePopup(EPopupScreens.PopupPlayerControl); HidePopup(EPopupScreens.PopupPlayerControl);
} }
if (popupPlayerControlAllowed && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) if (popupPlayerControlAllowed && CConfig.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_OFF)
{ {
if (keyEvent.Key == Keys.MediaNextTrack) if (keyEvent.Key == Keys.MediaNextTrack)
CBackgroundMusic.Next(); CBackgroundMusic.Next();
@@ -497,7 +502,7 @@ namespace Vocaluxe.Base
bool isOverPopupPlayerControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupPlayerControl].ScreenArea, mouseEvent); bool isOverPopupPlayerControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupPlayerControl].ScreenArea, mouseEvent);
if (popupPlayerControlAllowed && isOverPopupPlayerControl) if (popupPlayerControlAllowed && isOverPopupPlayerControl)
{ {
if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
ShowPopup(EPopupScreens.PopupPlayerControl); ShowPopup(EPopupScreens.PopupPlayerControl);
} }
@@ -624,16 +629,15 @@ namespace Vocaluxe.Base
} }
} }
} }
CFonts.Style = EStyle.Normal; CFont font=new CFont("Normal",EStyle.Normal, 25);
CFonts.SetFont("Normal");
CFonts.Height = 25;
SColorF gray = new SColorF(1f, 1f, 1f, 0.5f); SColorF gray = new SColorF(1f, 1f, 1f, 0.5f);
float y = 0; float y = 0;
foreach (string txt in debugOutput) foreach (string txt in debugOutput)
{ {
RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), y, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); float textWidth = CFonts.GetTextWidth(txt, font);
RectangleF rect = new RectangleF(CSettings.RenderW - textWidth, y, textWidth, CFonts.GetTextHeight(txt,font));
CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear));
CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); CFonts.DrawText(txt, font, rect.X, rect.Y, CSettings.ZNear);
y += rect.Height; y += rect.Height;
} }
} }
+68 -28
View File
@@ -76,6 +76,11 @@ namespace Vocaluxe.Base
return CConfig.BackgroundMusicVolume; return CConfig.BackgroundMusicVolume;
} }
public EBackgroundMusicOffOn GetBackgroundMusicStatus()
{
return CConfig.BackgroundMusic;
}
public int GetPreviewMusicVolume() public int GetPreviewMusicVolume()
{ {
return CConfig.PreviewMusicVolume; return CConfig.PreviewMusicVolume;
@@ -243,6 +248,11 @@ namespace Vocaluxe.Base
{ {
return CSettings.SlideShowFadeTime; return CSettings.SlideShowFadeTime;
} }
public float GetSoundPlayerFadeTime()
{
return CSettings.SoundPlayerFadeTime;
}
} }
class CBtheme : ITheme class CBtheme : ITheme
@@ -335,11 +345,21 @@ namespace Vocaluxe.Base
return CBackgroundMusic.VideoEnabled; return CBackgroundMusic.VideoEnabled;
} }
public bool IsPlayingPreview()
{
return CBackgroundMusic.IsPlayingPreview;
}
public void SetDisabled(bool disabled) public void SetDisabled(bool disabled)
{ {
CBackgroundMusic.Disabled = disabled; CBackgroundMusic.Disabled = disabled;
} }
public float GetLength()
{
return CBackgroundMusic.Length;
}
public void Next() public void Next()
{ {
CBackgroundMusic.Next(); CBackgroundMusic.Next();
@@ -360,6 +380,26 @@ namespace Vocaluxe.Base
CBackgroundMusic.Play(); CBackgroundMusic.Play();
} }
public void Stop()
{
CBackgroundMusic.Stop();
}
public void LoadPreview(CSong song, float start = 0f)
{
CBackgroundMusic.LoadPreview(song, start);
}
public void PlayPreview(float start = -1f)
{
CBackgroundMusic.PlayPreview(start);
}
public void StopPreview()
{
CBackgroundMusic.StopPreview();
}
public CTexture GetVideoTexture() public CTexture GetVideoTexture()
{ {
return CBackgroundMusic.GetVideoTexture(); return CBackgroundMusic.GetVideoTexture();
@@ -430,6 +470,11 @@ namespace Vocaluxe.Base
{ {
return CGraphics.GlobalAlpha; return CGraphics.GlobalAlpha;
} }
public EScreens GetNextScreen()
{
return CGraphics.NextScreen;
}
} }
class CBlog : ILog class CBlog : ILog
@@ -452,39 +497,24 @@ namespace Vocaluxe.Base
class CBfonts : IFonts class CBfonts : IFonts
{ {
public void SetFont(string fontName)
{
CFonts.SetFont(fontName);
}
public void SetStyle(EStyle fontStyle)
{
CFonts.Style = fontStyle;
}
public RectangleF GetTextBounds(CText text) public RectangleF GetTextBounds(CText text)
{ {
return CFonts.GetTextBounds(text); return CFonts.GetTextBounds(text);
} }
public RectangleF GetTextBounds(CText text, float textHeight) public void DrawText(string text, CFont font, float x, float y, float z, SColorF color)
{ {
return CFonts.GetTextBounds(text, textHeight); CFonts.DrawText(text, font, x, y, z, color);
} }
public void DrawText(string text, float textHeight, float x, float y, float z, SColorF color) public void DrawTextReflection(string text, CFont font, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight)
{ {
CFonts.DrawText(text, textHeight, x, y, z, color); CFonts.DrawTextReflection(text, font, x, y, z, color, reflectionSpace, reflectionHeight);
} }
public void DrawTextReflection(string text, float textHeight, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight) public void DrawText(string text, CFont font, float x, float y, float z, SColorF color, float begin, float end)
{ {
CFonts.DrawTextReflection(text, textHeight, x, y, z, color, reflectionSpace, reflectionHeight); CFonts.DrawText(text, font, x, y, z, color, begin, end);
}
public void DrawText(string text, float textHeight, float x, float y, float z, SColorF color, float begin, float end)
{
CFonts.DrawText(text, textHeight, x, y, z, color, begin, end);
} }
} }
@@ -784,6 +814,16 @@ namespace Vocaluxe.Base
{ {
CVideo.SetLoop(streamID, loop); CVideo.SetLoop(streamID, loop);
} }
public void Pause(int streamID)
{
CVideo.Pause(streamID);
}
public void Resume(int streamID)
{
CVideo.Resume(streamID);
}
} }
class CBsound : ISound class CBsound : ISound
@@ -803,9 +843,14 @@ namespace Vocaluxe.Base
CSound.Play(soundStream); CSound.Play(soundStream);
} }
public void Fade(int soundStream, float targetVolume, float duration) public void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing)
{ {
CSound.Fade(soundStream, targetVolume, duration); CSound.Fade(soundStream, targetVolume, duration, afterFadeAction);
}
public void Close(int soundStream)
{
CSound.Close(soundStream);
} }
public bool IsFinished(int soundStream) public bool IsFinished(int soundStream)
@@ -823,11 +868,6 @@ namespace Vocaluxe.Base
return CSound.GetLength(soundStream); return CSound.GetLength(soundStream);
} }
public void FadeAndClose(int soundStream, float targetVolume, float duration)
{
CSound.FadeAndClose(soundStream, targetVolume, duration);
}
public void SetStreamVolume(int soundStream, float volume) public void SetStreamVolume(int soundStream, float volume)
{ {
CSound.SetStreamVolume(soundStream, volume); CSound.SetStreamVolume(soundStream, volume);
+2
View File
@@ -151,6 +151,8 @@ namespace Vocaluxe.Base
public const float BackgroundMusicFadeTime = 0.5f; public const float BackgroundMusicFadeTime = 0.5f;
public const float PauseResetTime = 1f; public const float PauseResetTime = 1f;
public const float SoundPlayerFadeTime = 0.5f;
public const float SlideShowImageTime = 3500f; public const float SlideShowImageTime = 3500f;
public const float SlideShowFadeTime = 500f; public const float SlideShowFadeTime = 500f;
+1 -1
View File
@@ -266,7 +266,7 @@ namespace Vocaluxe.Base
{ {
CFonts.LoadThemeFonts( CFonts.LoadThemeFonts(
_Themes[themeIndex].Name, _Themes[themeIndex].Name,
Path.Combine(Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].SkinFolder), CSettings.FolderNameThemeFonts), Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].SkinFolder, CSettings.FolderNameThemeFonts),
xmlReader); xmlReader);
} }
else else
@@ -24,48 +24,64 @@ using VocaluxeLib.Draw;
namespace Vocaluxe.Base.Fonts namespace Vocaluxe.Base.Fonts
{ {
class CFont : IDisposable class CFontStyle : IDisposable
{ {
private readonly Dictionary<char, CGlyph> _Glyphs; private readonly string _FilePath;
private readonly EStyle _Style;
public readonly float Outline; //0..1, 0=not outline 1=100% outline
public readonly SColorF OutlineColor;
private readonly float _MaxGlyphHeight;
private readonly Dictionary<char, CGlyph> _Glyphs = new Dictionary<char, CGlyph>();
private PrivateFontCollection _Fonts; private PrivateFontCollection _Fonts;
private FontFamily _Family; private FontFamily _Family;
private readonly float _MaxGlyphHeight;
private readonly string _FilePath; public CFontStyle(string file, EStyle style, float outline, SColorF outlineColor)
private bool _Disposed;
public CFont(string file)
{ {
_FilePath = file; _FilePath = file;
_Style = style;
_Glyphs = new Dictionary<char, CGlyph>(); Outline = outline;
OutlineColor = outlineColor;
switch (CConfig.TextureQuality) switch (CConfig.TextureQuality)
{ {
case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST: case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST:
_MaxGlyphHeight = 25f; _MaxGlyphHeight = 20f;
break; break;
case ETextureQuality.TR_CONFIG_TEXTURE_LOW: case ETextureQuality.TR_CONFIG_TEXTURE_LOW:
_MaxGlyphHeight = 50f; _MaxGlyphHeight = 40f;
break; break;
case ETextureQuality.TR_CONFIG_TEXTURE_MEDIUM: case ETextureQuality.TR_CONFIG_TEXTURE_MEDIUM:
_MaxGlyphHeight = 100f; _MaxGlyphHeight = 60f;
break; break;
case ETextureQuality.TR_CONFIG_TEXTURE_HIGH: case ETextureQuality.TR_CONFIG_TEXTURE_HIGH:
_MaxGlyphHeight = 200f; _MaxGlyphHeight = 80f;
break; break;
case ETextureQuality.TR_CONFIG_TEXTURE_HIGHEST: case ETextureQuality.TR_CONFIG_TEXTURE_HIGHEST:
_MaxGlyphHeight = 400f;
break;
default:
_MaxGlyphHeight = 100f; _MaxGlyphHeight = 100f;
break; break;
default:
_MaxGlyphHeight = 60f;
break;
} }
_MaxGlyphHeight = 50;
} }
public Font GetFont() private FontStyle _GetSystemFontStyle()
{
switch (_Style)
{
case EStyle.Normal:
return FontStyle.Regular;
case EStyle.Italic:
return FontStyle.Italic;
case EStyle.Bold:
return FontStyle.Bold;
case EStyle.BoldItalic:
return FontStyle.Bold | FontStyle.Italic;
}
throw new ArgumentException("Invalid style: " + _Style);
}
public Font GetSystemFont(float height)
{ {
if (_Fonts == null) if (_Fonts == null)
{ {
@@ -80,100 +96,83 @@ namespace Vocaluxe.Base.Fonts
CLog.LogError("Error opening font file " + _FilePath + ": " + e.Message); CLog.LogError("Error opening font file " + _FilePath + ": " + e.Message);
} }
} }
return new Font(_Family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel); return new Font(_Family, height, _GetSystemFontStyle(), GraphicsUnit.Pixel);
} }
public void DrawGlyph(char chr, float x, float y, float z, SColorF color) public void DrawGlyph(char chr, float fontHeight, float x, float y, float z, SColorF color)
{ {
CTexture texture; CTexture texture;
SRectF rect; SRectF rect;
GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); GetOrAddGlyph(chr, fontHeight).GetTextureAndRect(fontHeight, x, y, z, out texture, out rect);
CDraw.DrawTexture(texture, rect, color); CDraw.DrawTexture(texture, rect, color);
} }
public void DrawGlyph(char chr, float x, float y, float z, SColorF color, float begin, float end) public void DrawGlyph(char chr, float fontHeight, float x, float y, float z, SColorF color, float begin, float end)
{ {
CTexture texture; CTexture texture;
SRectF rect; SRectF rect;
GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); GetOrAddGlyph(chr, fontHeight).GetTextureAndRect(fontHeight, x, y, z, out texture, out rect);
CDraw.DrawTexture(texture, rect, color, begin, end); CDraw.DrawTexture(texture, rect, color, begin, end);
} }
public void DrawGlyphReflection(char chr, float x, float y, float z, SColorF color, float rspace, float rheight) public void DrawGlyphReflection(char chr, float fontHeight, float x, float y, float z, SColorF color, float rspace, float rheight)
{ {
CTexture texture; CTexture texture;
SRectF rect; SRectF rect;
GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); GetOrAddGlyph(chr, fontHeight).GetTextureAndRect(fontHeight, x, y, z, out texture, out rect);
CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight); CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight);
} }
public float GetWidth(char chr) public float GetWidth(char chr, float height)
{ {
return GetOrAddGlyph(chr).Width; return GetOrAddGlyph(chr, height).GetWidth(height);
} }
public float GetHeight(char chr) public float GetHeight(char chr, float height)
{ {
return GetOrAddGlyph(chr).Height; return GetOrAddGlyph(chr, height).GetHeight(height);
} }
public CGlyph GetOrAddGlyph(char chr) public CGlyph GetOrAddGlyph(char chr, float height)
{ {
CGlyph glyph; CGlyph glyph;
if (!_Glyphs.TryGetValue(chr, out glyph)) if (!_Glyphs.TryGetValue(chr, out glyph))
{ {
glyph = new CGlyph(chr, _MaxGlyphHeight); float maxHeight = (height < 0 || _MaxGlyphHeight + 50 >= height) ? _MaxGlyphHeight : (float)Math.Round(height / 50) * 50;
glyph = new CGlyph(chr, this, maxHeight);
_Glyphs.Add(chr, glyph); _Glyphs.Add(chr, glyph);
} }
if (glyph.MaxHeight + 50 < CFonts.Height) if (glyph.MaxHeight + 50 < height)
{ {
glyph.UnloadTexture(); glyph.UnloadTexture();
glyph = new CGlyph(chr, (float)Math.Round(CFonts.Height / 50) * 50); glyph = new CGlyph(chr, this, (float)Math.Round(height / 50) * 50);
_Glyphs[chr] = glyph; _Glyphs[chr] = glyph;
} }
return glyph; return glyph;
} }
public void UnloadGlyphs() private void _UnloadGlyphs()
{ {
foreach (CGlyph glyph in _Glyphs.Values) foreach (CGlyph glyph in _Glyphs.Values)
glyph.UnloadTexture(); glyph.UnloadTexture();
_Glyphs.Clear(); _Glyphs.Clear();
} }
private bool _Disposed;
public void Dispose() public void Dispose()
{ {
if (!_Disposed) if (!_Disposed)
{ {
if (_Fonts != null) if (_Fonts != null)
{
_Fonts.Dispose(); _Fonts.Dispose();
UnloadGlyphs(); _Fonts = null;
}
_UnloadGlyphs();
_Disposed = true; _Disposed = true;
} }
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
} }
struct SFont
{
public string Name;
public bool IsThemeFont;
public int PartyModeID;
public string ThemeName;
public string Folder;
public string FileNormal;
public string FileItalic;
public string FileBold;
public string FileBoldItalic;
public float Outline; //0..1, 0=not outline 1=100% outline
public SColorF OutlineColor;
public CFont Normal;
public CFont Italic;
public CFont Bold;
public CFont BoldItalic;
}
} }
+234 -316
View File
@@ -15,6 +15,7 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>. // along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
@@ -25,206 +26,150 @@ using VocaluxeLib.Menu;
namespace Vocaluxe.Base.Fonts namespace Vocaluxe.Base.Fonts
{ {
/// <summary>
/// Struct used for describing a font family (a type of text with 4 different styles)
/// </summary>
struct SFontFamily
{
public string Name;
public int PartyModeID;
public string ThemeName;
public string Folder;
public string FileNormal;
public string FileItalic;
public string FileBold;
public string FileBoldItalic;
public float Outline; //0..1, 0=not outline 1=100% outline
public SColorF OutlineColor;
public CFontStyle Normal;
public CFontStyle Italic;
public CFontStyle Bold;
public CFontStyle BoldItalic;
}
static class CFonts static class CFonts
{ {
private static readonly List<SFont> _Fonts = new List<SFont>(); private static bool _IsInitialized;
private static int _CurrentFont; private static readonly List<SFontFamily> _FontFamilies = new List<SFontFamily>();
private static float _Height = 1f; private static readonly List<String> _LoggedMissingFonts = new List<string>();
// ReSharper disable MemberCanBePrivate.Global
public static int PartyModeID { get; set; } public static int PartyModeID { get; set; }
// ReSharper restore MemberCanBePrivate.Global
public static EStyle Style = EStyle.Normal; public static bool Init()
public static float Height
{ {
get { return _Height; } if (_IsInitialized)
set { _Height = value < 0f ? 0f : value; } return false;
}
public static float Outline
{
get { return _Fonts[_CurrentFont].Outline; }
}
public static SColorF OutlineColor
{
get { return _Fonts[_CurrentFont].OutlineColor; }
}
public static void Init()
{
_CurrentFont = 0;
PartyModeID = -1; PartyModeID = -1;
_BuildFonts(); return _LoadDefaultFonts();
} }
private static void _BuildFonts() public static void Close()
{ {
foreach (SFont font in _Fonts) foreach (SFontFamily font in _FontFamilies)
{ {
font.Normal.Dispose(); font.Normal.Dispose();
font.Bold.Dispose(); font.Bold.Dispose();
font.Italic.Dispose(); font.Italic.Dispose();
font.BoldItalic.Dispose(); font.BoldItalic.Dispose();
} }
_Fonts.Clear(); _FontFamilies.Clear();
_CurrentFont = 0; _IsInitialized = false;
_LoadFontList();
}
public static Font GetFont()
{
return _GetCurrentFont().GetFont();
}
private static CFont _GetCurrentFont()
{
switch (Style)
{
case EStyle.Normal:
return _Fonts[_CurrentFont].Normal;
case EStyle.Italic:
return _Fonts[_CurrentFont].Italic;
case EStyle.Bold:
return _Fonts[_CurrentFont].Bold;
case EStyle.BoldItalic:
return _Fonts[_CurrentFont].BoldItalic;
}
//Just in case...
return _Fonts[_CurrentFont].Normal;
} }
#region DrawText #region DrawText
public static void DrawText(string text, int x, int y, int h) /// <summary>
/// Draws a black text
/// </summary>
/// <param name="text">The text to be drawn</param>
/// <param name="font">The texts font</param>
/// <param name="x">The texts x-position</param>
/// <param name="y">The texts y-position</param>
/// <param name="z">The texts z-position</param>
public static void DrawText(string text, CFont font, float x, float y, float z)
{ {
DrawText(text, h, x, y, 0f, new SColorF(0f, 0f, 0f, 1f)); DrawText(text, font, x, y, z, new SColorF(0f, 0f, 0f, 1f));
}
public static void DrawText(string text, float x, float y, float z)
{
DrawText(text, Height, x, y, z, new SColorF(0f, 0f, 0f, 1f));
} }
/// <summary> /// <summary>
/// Draws a text string /// Draws a text
/// </summary> /// </summary>
/// <param name="text">The text to be drawn</param> /// <param name="text">The text to be drawn</param>
/// <param name="x">The text's x-position</param> /// <param name="font">The texts font</param>
/// <param name="y">The text's y-position</param> /// <param name="x">The texts x-position</param>
/// <param name="h">The text's height</param> /// <param name="y">The texts y-position</param>
/// <param name="z">The text's z-position</param> /// <param name="z">The texts z-position</param>
/// <param name="color">The text color</param> /// <param name="color">The text color</param>
public static void DrawText(string text, float h, float x, float y, float z, SColorF color) public static void DrawText(string text, CFont font, float x, float y, float z, SColorF color)
{ {
if (h <= 0f) if (font.Height <= 0f || text == "")
return; return;
if (text == "") CFontStyle fontStyle = _GetFontStyle(font);
return;
Height = h;
CFont font = _GetCurrentFont();
float dx = x; float dx = x;
foreach (char chr in text) foreach (char chr in text)
{ {
font.DrawGlyph(chr, dx, y, z, color); fontStyle.DrawGlyph(chr, font.Height, dx, y, z, color);
dx += font.GetWidth(chr); dx += fontStyle.GetWidth(chr, font.Height);
} }
} }
public static void DrawTextReflection(string text, float h, float x, float y, float z, SColorF color, float rspace, float rheight) public static void DrawTextReflection(string text, CFont font, float x, float y, float z, SColorF color, float rspace, float rheight)
{ {
if (h <= 0f) if (font.Height <= 0f || text == "")
return; return;
if (text == "") CFontStyle fontStyle = _GetFontStyle(font);
return;
Height = h;
CFont font = _GetCurrentFont();
float dx = x; float dx = x;
foreach (char chr in text) foreach (char chr in text)
{ {
font.DrawGlyphReflection(chr, dx, y, z, color, rspace, rheight); fontStyle.DrawGlyphReflection(chr, font.Height, dx, y, z, color, rspace, rheight);
dx += font.GetWidth(chr); dx += fontStyle.GetWidth(chr, font.Height);
} }
} }
public static void DrawText(string text, float h, float x, float y, float z, SColorF color, float begin, float end) public static void DrawText(string text, CFont font, float x, float y, float z, SColorF color, float begin, float end)
{ {
if (h <= 0f) if (font.Height <= 0f || text == "")
return; return;
if (text == "") float w = GetTextWidth(text, font);
return;
Height = h;
float dx = x;
float w = GetTextWidth(text);
if (w <= 0f) if (w <= 0f)
return; return;
float x1 = x + w * begin; float xStart = x + w * begin;
float x2 = x + w * end; float xEnd = x + w * end;
float xCur = x;
CFont font = _GetCurrentFont(); CFontStyle fontStyle = _GetFontStyle(font);
foreach (char chr in text) foreach (char chr in text)
{ {
float w2 = font.GetWidth(chr); float w2 = fontStyle.GetWidth(chr, font.Height);
float b = (x1 - dx) / w2; float b = (xStart - xCur) / w2;
if (b < 1f) if (b < 1f)
{ {
if (b < 0f) if (b < 0f)
b = 0f; b = 0f;
float e = (x2 - dx) / w2; float e = (xEnd - xCur) / w2;
if (e > 0f) if (e > 0f)
{ {
if (e > 1f) if (e > 1f)
e = 1f; e = 1f;
font.DrawGlyph(chr, dx, y, z, color, b, e); fontStyle.DrawGlyph(chr, font.Height, xCur, y, z, color, b, e);
} }
} }
dx += w2; xCur += w2;
} }
} }
#endregion DrawText #endregion DrawText
public static FontStyle GetFontStyle()
{
switch (Style)
{
case EStyle.Normal:
return FontStyle.Regular;
case EStyle.Italic:
return FontStyle.Italic;
case EStyle.Bold:
return FontStyle.Bold;
case EStyle.BoldItalic:
return FontStyle.Bold | FontStyle.Italic;
default:
return FontStyle.Regular;
}
}
public static void SetFont(string fontName)
{
int index = _GetPartyFontIndex(PartyModeID, fontName);
if (index < 0)
index = _GetThemeFontIndex(CConfig.Theme, fontName);
if (index < 0)
index = _GetFontIndex(fontName);
if (index >= 0)
_CurrentFont = index;
}
/// <summary> /// <summary>
/// Calculates the bounds for a CText object /// Calculates the bounds for a CText object
/// </summary> /// </summary>
@@ -232,94 +177,154 @@ namespace Vocaluxe.Base.Fonts
/// <returns>RectangleF object containing the bounds</returns> /// <returns>RectangleF object containing the bounds</returns>
public static RectangleF GetTextBounds(CText text) public static RectangleF GetTextBounds(CText text)
{ {
return GetTextBounds(text, text.Height); return new RectangleF(text.X, text.Y, GetTextWidth(text.TranslatedText, text.Font), GetTextHeight(text.TranslatedText, text.Font));
}
private static CFontStyle _GetFontStyle(CFont font)
{
int index = _GetPartyFontIndex(font.Name, PartyModeID);
if (index < 0)
index = _GetThemeFontIndex(font.Name, CConfig.Theme);
if (index < 0)
index = _GetFontIndex(font.Name);
if (index < 0)
{
if (!_LoggedMissingFonts.Contains(font.Name))
{
_LoggedMissingFonts.Add(font.Name);
CLog.LogError("Font \"" + font.Name + "\" not found!");
}
index = 0;
}
switch (font.Style)
{
case EStyle.Normal:
return _FontFamilies[index].Normal;
case EStyle.Italic:
return _FontFamilies[index].Italic;
case EStyle.Bold:
return _FontFamilies[index].Bold;
case EStyle.BoldItalic:
return _FontFamilies[index].BoldItalic;
}
throw new ArgumentException("Invalid Style: " + font.Style);
}
public static float GetTextWidth(string text, CFont font)
{
CFontStyle fontStyle = _GetFontStyle(font);
return text.Sum(chr => fontStyle.GetWidth(chr, font.Height));
}
public static float GetTextHeight(string text, CFont font)
{
CFontStyle fontStyle = _GetFontStyle(font);
return text == "" ? 0 : text.Select(chr => fontStyle.GetHeight(chr, font.Height)).Max();
}
private static int _GetFontIndex(string fontName)
{
for (int i = 0; i < _FontFamilies.Count; i++)
{
if (_FontFamilies[i].Name == fontName)
return i;
}
return -1;
}
private static int _GetThemeFontIndex(string fontName, string themeName)
{
if (themeName == "" || fontName == "")
return -1;
for (int i = 0; i < _FontFamilies.Count; i++)
{
if (_FontFamilies[i].Name == fontName && _FontFamilies[i].ThemeName == themeName)
return i;
}
return -1;
}
private static int _GetPartyFontIndex(string fontName, int partyModeID)
{
if (partyModeID == -1 || fontName == "")
return -1;
for (int i = 0; i < _FontFamilies.Count; i++)
{
if (_FontFamilies[i].PartyModeID == partyModeID && _FontFamilies[i].Name == fontName)
return i;
}
return -1;
} }
/// <summary> /// <summary>
/// Calculates the bounds for a CText object /// Load default fonts
/// </summary> /// </summary>
/// <param name="text">The CText object of which the bounds should be calculated for</param> /// <returns></returns>
/// <param name="height">The height of the CText object</param> private static bool _LoadDefaultFonts()
/// <returns>RectangleF object containing the bounds</returns>
public static RectangleF GetTextBounds(CText text, float height)
{ {
float oldHeight = Height; CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts, CSettings.FileNameFonts));
int oldFont = _CurrentFont; if (xmlReader == null)
EStyle oldStyle = Style; return false;
Height = height;
SetFont(text.Font); return _LoadFontFile(xmlReader, Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts));
Style = text.Style;
var result = new RectangleF(text.X, text.Y, GetTextWidth(CLanguage.Translate(text.Text, text.TranslationID)),
GetTextHeight(CLanguage.Translate(text.Text, text.TranslationID)));
//restore old values
Height = oldHeight;
_CurrentFont = oldFont;
Style = oldStyle;
return result;
} }
public static float GetTextWidth(string text) /// <summary>
/// Loads theme fonts from skin file
/// </summary>
public static bool LoadThemeFonts(string themeName, string fontFolder, CXMLReader xmlReader)
{ {
CFont font = _GetCurrentFont(); bool ok = _LoadFontFile(xmlReader, fontFolder, themeName);
return text.Sum(chr => font.GetWidth(chr)); CLog.StartBenchmark("BuildGlyphs");
_BuildGlyphs();
CLog.StopBenchmark("BuildGlyphs");
return ok;
} }
public static float GetTextHeight(string text) /// <summary>
/// Loads party mode fonts from skin file
/// </summary>
public static bool LoadPartyModeFonts(int partyModeID, string fontFolder, CXMLReader xmlReader)
{ {
//return TextRenderer.MeasureText(text, GetFont()).Height; bool ok = _LoadFontFile(xmlReader, fontFolder, "", partyModeID);
CFont font = _GetCurrentFont(); CLog.StartBenchmark("BuildGlyphs");
return text == "" ? 0 : text.Select(font.GetHeight).Max(); _BuildGlyphs();
CLog.StopBenchmark("BuildGlyphs");
return ok;
} }
private static void _LoadFontFiles(CXMLReader xmlReader, string fontFolder, string themeName = "", int partyModeId = -1) private static bool _LoadFontFile(CXMLReader xmlReader, string fontFolder, string themeName = "", int partyModeId = -1)
{ {
string value = string.Empty; string value;
int i = 1; int i = 1;
while (xmlReader.GetValue("//root/Fonts/Font" + i + "/Folder", out value, value)) while (xmlReader.GetValue("//root/Fonts/Font" + i + "/Folder", out value))
{ {
var sf = new SFont {Folder = value, IsThemeFont = themeName != "", ThemeName = themeName, PartyModeID = partyModeId}; var sf = new SFontFamily {Folder = value, ThemeName = themeName, PartyModeID = partyModeId};
bool ok = true; bool ok = true;
string name; ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/Name", out sf.Name);
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/Name", out name, value); ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileNormal", out sf.FileNormal);
sf.Name = name; ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileItalic", out sf.FileItalic);
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBold", out sf.FileBold);
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileNormal", out value, value); ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBoldItalic", out sf.FileBoldItalic);
sf.FileNormal = value; ok &= xmlReader.TryGetNormalizedFloatValue("//root/Fonts/Font" + i + "/Outline", ref sf.Outline);
value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); ok &= xmlReader.TryGetColorFromRGBA("//root/Fonts/Font" + i + "/OutlineColor", ref sf.OutlineColor);
var f = new CFont(value);
sf.Normal = f;
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileItalic", out value, value);
sf.FileItalic = value;
value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value));
f = new CFont(value);
sf.Italic = f;
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBold", out value, value);
sf.FileBold = value;
value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value));
f = new CFont(value);
sf.Bold = f;
ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBoldItalic", out value, value);
sf.FileBoldItalic = value;
value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value));
f = new CFont(value);
sf.BoldItalic = f;
sf.Outline = 0f;
ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/Outline", ref sf.Outline);
sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f);
ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorR", ref sf.OutlineColor.R);
ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorG", ref sf.OutlineColor.G);
ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorB", ref sf.OutlineColor.B);
ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorA", ref sf.OutlineColor.A);
if (ok) if (ok)
_Fonts.Add(sf); {
sf.Normal = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileNormal), EStyle.Normal, sf.Outline, sf.OutlineColor);
sf.Italic = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileItalic), EStyle.Italic, sf.Outline, sf.OutlineColor);
sf.Bold = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileBold), EStyle.Bold, sf.Outline, sf.OutlineColor);
sf.BoldItalic = new CFontStyle(Path.Combine(fontFolder, sf.Folder, sf.FileBoldItalic), EStyle.BoldItalic, sf.Outline, sf.OutlineColor);
_FontFamilies.Add(sf);
}
else else
{ {
string fontTypes; string fontTypes;
@@ -330,170 +335,83 @@ namespace Vocaluxe.Base.Fonts
else else
fontTypes = "basic fonts"; fontTypes = "basic fonts";
CLog.LogError("Error loading " + fontTypes + ": Error in Font" + i); CLog.LogError("Error loading " + fontTypes + ": Error in Font" + i);
return false;
} }
i++; i++;
} }
} return true;
/// <summary>
/// Load default fonts
/// </summary>
/// <returns></returns>
private static void _LoadFontList()
{
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts, CSettings.FileNameFonts));
if (xmlReader == null)
return;
_LoadFontFiles(xmlReader, Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts));
}
/// <summary>
/// Loads theme fonts from skin file
/// </summary>
public static void LoadThemeFonts(string themeName, string fontFolder, CXMLReader xmlReader)
{
_LoadFontFiles(xmlReader, fontFolder, themeName);
CLog.StartBenchmark("BuildGlyphs");
_BuildGlyphs();
CLog.StopBenchmark("BuildGlyphs");
}
/// <summary>
/// Loads party mode fonts from skin file
/// </summary>
public static void LoadPartyModeFonts(int partyModeID, string fontFolder, CXMLReader xmlReader)
{
_LoadFontFiles(xmlReader, fontFolder, "", partyModeID);
CLog.StartBenchmark("BuildGlyphs");
_BuildGlyphs();
CLog.StopBenchmark("BuildGlyphs");
} }
public static void SaveThemeFonts(string themeName, XmlWriter writer) public static void SaveThemeFonts(string themeName, XmlWriter writer)
{ {
if (_Fonts.Count == 0) if (_FontFamilies.Count == 0)
return; return;
int index = 0;
int fontNr = 1;
bool setStart = false;
while (index < _Fonts.Count)
{
if (_Fonts[index].IsThemeFont && _Fonts[index].ThemeName == themeName)
{
if (!setStart)
{
writer.WriteStartElement("Fonts"); writer.WriteStartElement("Fonts");
setStart = true; int fontNr = 1;
} foreach (SFontFamily font in _FontFamilies)
{
if (font.ThemeName == themeName)
{
writer.WriteStartElement("Font" + fontNr); writer.WriteStartElement("Font" + fontNr);
writer.WriteElementString("Name", _Fonts[index].Name); writer.WriteElementString("Name", font.Name);
writer.WriteElementString("Folder", _Fonts[index].Folder); writer.WriteElementString("Folder", font.Folder);
writer.WriteElementString("Outline", _Fonts[index].Outline.ToString("#0.00")); writer.WriteElementString("Outline", font.Outline.ToString("#0.00"));
writer.WriteElementString("OutlineColorR", _Fonts[index].OutlineColor.R.ToString("#0.00")); writer.WriteStartElement("OutlineColor");
writer.WriteElementString("OutlineColorG", _Fonts[index].OutlineColor.G.ToString("#0.00")); writer.WriteElementString("R", font.OutlineColor.R.ToString("#0.00"));
writer.WriteElementString("OutlineColorB", _Fonts[index].OutlineColor.B.ToString("#0.00")); writer.WriteElementString("G", font.OutlineColor.G.ToString("#0.00"));
writer.WriteElementString("OutlineColorA", _Fonts[index].OutlineColor.A.ToString("#0.00")); writer.WriteElementString("B", font.OutlineColor.B.ToString("#0.00"));
writer.WriteElementString("A", font.OutlineColor.A.ToString("#0.00"));
writer.WriteEndElement();
writer.WriteElementString("FileNormal", _Fonts[index].FileNormal); writer.WriteElementString("FileNormal", font.FileNormal);
writer.WriteElementString("FileBold", _Fonts[index].FileBold); writer.WriteElementString("FileBold", font.FileBold);
writer.WriteElementString("FileItalic", _Fonts[index].FileItalic); writer.WriteElementString("FileItalic", font.FileItalic);
writer.WriteElementString("FileBoldItalic", _Fonts[index].FileBoldItalic); writer.WriteElementString("FileBoldItalic", font.FileBoldItalic);
writer.WriteEndElement(); writer.WriteEndElement();
fontNr++; fontNr++;
} }
index++;
} }
if (setStart)
writer.WriteEndElement(); writer.WriteEndElement();
} }
public static void UnloadThemeFonts(string themeName) public static void UnloadThemeFonts(string themeName)
{ {
int index = 0; int index = 0;
while (index < _Fonts.Count) while (index < _FontFamilies.Count)
{ {
if (_Fonts[index].IsThemeFont && _Fonts[index].ThemeName == themeName) if (_FontFamilies[index].ThemeName == themeName)
{ {
_Fonts[index].Normal.UnloadGlyphs(); _FontFamilies[index].Normal.Dispose();
_Fonts[index].Italic.UnloadGlyphs(); _FontFamilies[index].Italic.Dispose();
_Fonts[index].Bold.UnloadGlyphs(); _FontFamilies[index].Bold.Dispose();
_Fonts[index].BoldItalic.UnloadGlyphs(); _FontFamilies[index].BoldItalic.Dispose();
_Fonts.RemoveAt(index); _FontFamilies.RemoveAt(index);
} }
else else
index++; index++;
} }
} }
private static int _GetFontIndex(string fontName)
{
for (int i = 0; i < _Fonts.Count; i++)
{
if (!_Fonts[i].IsThemeFont && _Fonts[i].Name == fontName)
return i;
}
return -1;
}
private static int _GetThemeFontIndex(string themeName, string fontName)
{
if (themeName == "" || fontName == "")
return -1;
for (int i = 0; i < _Fonts.Count; i++)
{
if (_Fonts[i].IsThemeFont && _Fonts[i].Name == fontName && _Fonts[i].ThemeName == themeName)
return i;
}
return -1;
}
private static int _GetPartyFontIndex(int partyModeID, string fontName)
{
if (partyModeID == -1 || fontName == "")
return -1;
for (int i = 0; i < _Fonts.Count; i++)
{
if (!_Fonts[i].IsThemeFont && _Fonts[i].PartyModeID == partyModeID && _Fonts[i].Name == fontName)
return i;
}
return -1;
}
private static void _BuildGlyphs() private static void _BuildGlyphs()
{ {
const string text = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; const string text = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
for (int i = 0; i < _Fonts.Count; i++) foreach (SFontFamily fontFamily in _FontFamilies)
{ {
_CurrentFont = i;
foreach (char chr in text) foreach (char chr in text)
{ {
Style = EStyle.Normal; fontFamily.Normal.GetOrAddGlyph(chr, -1);
_Fonts[_CurrentFont].Normal.GetOrAddGlyph(chr); fontFamily.Bold.GetOrAddGlyph(chr, -1);
Style = EStyle.Bold; fontFamily.Italic.GetOrAddGlyph(chr, -1);
_Fonts[_CurrentFont].Bold.GetOrAddGlyph(chr); fontFamily.BoldItalic.GetOrAddGlyph(chr, -1);
Style = EStyle.Italic;
_Fonts[_CurrentFont].Italic.GetOrAddGlyph(chr);
Style = EStyle.BoldItalic;
_Fonts[_CurrentFont].BoldItalic.GetOrAddGlyph(chr);
} }
} }
Style = EStyle.Normal;
SetFont("Normal");
} }
} }
} }
+19 -23
View File
@@ -36,26 +36,13 @@ namespace Vocaluxe.Base.Fonts
private readonly RectangleF _DrawBounding; private readonly RectangleF _DrawBounding;
public readonly float MaxHeight; public readonly float MaxHeight;
public float Width public CGlyph(char chr, CFontStyle fontStyle, float maxHeight)
{
get { return _BoundingBox.Width * _GetFactor(); }
}
public float Height
{
get { return _BoundingBox.Height * _GetFactor(); }
}
public CGlyph(char chr, float maxHeight)
{ {
MaxHeight = maxHeight; MaxHeight = maxHeight;
float oldHeight = CFonts.Height; float outlineSize = fontStyle.Outline * maxHeight;
float outline = CFonts.Outline;
float outlineSize = outline * maxHeight;
string chrString = chr.ToString(); string chrString = chr.ToString();
CFonts.Height = maxHeight; Font fo = fontStyle.GetSystemFont(maxHeight);
Font fo = CFonts.GetFont();
SizeF fullSize; SizeF fullSize;
Size bmpSize; Size bmpSize;
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
@@ -64,7 +51,7 @@ namespace Vocaluxe.Base.Fonts
if (chr != ' ') if (chr != ' ')
{ {
//Gets exact height and width for drawing more than 1 char. But width is to small to draw char on bitmap as e.g. italic chars will get cropped //Gets exact height and width for drawing more than 1 char. But width is to small to draw char on bitmap as e.g. italic chars will get cropped
_BoundingBox = g.MeasureString(chrString, fo, -1, new StringFormat(StringFormat.GenericTypographic)); _BoundingBox = g.MeasureString(chrString, fo, -1, StringFormat.GenericTypographic);
// ReSharper disable CompareOfFloatsByEqualityOperator // ReSharper disable CompareOfFloatsByEqualityOperator
if (_BoundingBox.Height == 0) if (_BoundingBox.Height == 0)
// ReSharper restore CompareOfFloatsByEqualityOperator // ReSharper restore CompareOfFloatsByEqualityOperator
@@ -105,7 +92,7 @@ namespace Vocaluxe.Base.Fonts
float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style); float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style);
path.AddString(chrString, fo.FontFamily, (int)fo.Style, emSize, point, new StringFormat()); path.AddString(chrString, fo.FontFamily, (int)fo.Style, emSize, point, new StringFormat());
using (var pen = new Pen(CFonts.OutlineColor.AsColor(), outlineSize)) using (var pen = new Pen(fontStyle.OutlineColor.AsColor(), outlineSize))
{ {
pen.LineJoin = LineJoin.Round; pen.LineJoin = LineJoin.Round;
g.DrawPath(pen, path); g.DrawPath(pen, path);
@@ -134,7 +121,6 @@ namespace Vocaluxe.Base.Fonts
} }
} }
} }
CFonts.Height = oldHeight;
} }
public void UnloadTexture() public void UnloadTexture()
@@ -142,15 +128,25 @@ namespace Vocaluxe.Base.Fonts
CDraw.RemoveTexture(ref _Texture); CDraw.RemoveTexture(ref _Texture);
} }
private float _GetFactor() private float _GetFactor(float fontHeight)
{ {
return CFonts.Height / _BoundingBox.Height; return fontHeight / _BoundingBox.Height;
} }
public void GetTextureAndRect(float x, float y, float z, out CTexture texture, out SRectF rect) public float GetWidth(float fontHeight)
{
return _BoundingBox.Width * _GetFactor(fontHeight);
}
public float GetHeight(float fontHeight)
{
return _BoundingBox.Height * _GetFactor(fontHeight);
}
public void GetTextureAndRect(float fontHeight, float x, float y, float z, out CTexture texture, out SRectF rect)
{ {
texture = _Texture; texture = _Texture;
float factor = _GetFactor(); float factor = _GetFactor(fontHeight);
x += _DrawBounding.X * factor; x += _DrawBounding.X * factor;
y += _DrawBounding.Y * factor; y += _DrawBounding.Y * factor;
float h = _DrawBounding.Height * factor; float h = _DrawBounding.Height * factor;
@@ -16,6 +16,7 @@
#endregion #endregion
using System; using System;
using VocaluxeLib;
namespace Vocaluxe.Lib.Sound.Playback namespace Vocaluxe.Lib.Sound.Playback
{ {
+2 -7
View File
@@ -15,15 +15,10 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>. // along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion #endregion
using VocaluxeLib;
namespace Vocaluxe.Lib.Sound.Playback namespace Vocaluxe.Lib.Sound.Playback
{ {
public enum EStreamAction
{
Nothing,
Pause,
Stop,
Close
}
interface IPlayback interface IPlayback
{ {
+6 -4
View File
@@ -173,10 +173,11 @@ namespace Vocaluxe
Application.DoEvents(); Application.DoEvents();
// Init Font // Init Fonts
CLog.StartBenchmark("Init Font"); CLog.StartBenchmark("Init Fonts");
CFonts.Init(); if (!CFonts.Init())
CLog.StopBenchmark("Init Font"); throw new CLoadingException("fonts");
CLog.StopBenchmark("Init Fonts");
Application.DoEvents(); Application.DoEvents();
@@ -264,6 +265,7 @@ namespace Vocaluxe
CVocaluxeServer.Close(); CVocaluxeServer.Close();
CGraphics.Close(); CGraphics.Close();
CCover.Close(); CCover.Close();
CFonts.Close();
CBackgroundMusic.Close(); CBackgroundMusic.Close();
CWebcam.Close(); CWebcam.Close();
CDataBase.Close(); CDataBase.Close();
+13 -2
View File
@@ -115,7 +115,7 @@ namespace Vocaluxe.Screens
if (_Buttons[_ButtonPrevious].Selected) if (_Buttons[_ButtonPrevious].Selected)
CBackgroundMusic.Previous(); CBackgroundMusic.Previous();
if (_Buttons[_ButtonPlay].Selected) if (_Buttons[_ButtonPlay].Selected)
CBackgroundMusic.Play(); CBackgroundMusic.Pause();
if (_Buttons[_ButtonPause].Selected) if (_Buttons[_ButtonPause].Selected)
CBackgroundMusic.Pause(); CBackgroundMusic.Pause();
if (_Buttons[_ButtonRepeat].Selected) if (_Buttons[_ButtonRepeat].Selected)
@@ -143,7 +143,7 @@ namespace Vocaluxe.Screens
if (_Buttons[_ButtonPrevious].Selected) if (_Buttons[_ButtonPrevious].Selected)
CBackgroundMusic.Previous(); CBackgroundMusic.Previous();
if (_Buttons[_ButtonPlay].Selected) if (_Buttons[_ButtonPlay].Selected)
CBackgroundMusic.Play(); CBackgroundMusic.Pause();
if (_Buttons[_ButtonPause].Selected) if (_Buttons[_ButtonPause].Selected)
CBackgroundMusic.Pause(); CBackgroundMusic.Pause();
if (_Buttons[_ButtonRepeat].Selected) if (_Buttons[_ButtonRepeat].Selected)
@@ -168,6 +168,17 @@ namespace Vocaluxe.Screens
return true; return true;
} }
public override void OnShow()
{
base.OnShow();
_Buttons[_ButtonNext].Visible = !CBackgroundMusic.IsPlayingPreview;
_Buttons[_ButtonPause].Visible = !CBackgroundMusic.IsPlayingPreview;
_Buttons[_ButtonPlay].Visible = !CBackgroundMusic.IsPlayingPreview;
_Buttons[_ButtonPrevious].Visible = !CBackgroundMusic.IsPlayingPreview;
_Buttons[_ButtonRepeat].Visible = !CBackgroundMusic.IsPlayingPreview;
_Buttons[_ButtonSing].Visible = !CBackgroundMusic.IsPlayingPreview;
}
public override bool UpdateGame() public override bool UpdateGame()
{ {
_Statics[_StaticCover].Visible = !_VideoPreviewInt || !CBackgroundMusic.SongHasVideo; _Statics[_StaticCover].Visible = !_VideoPreviewInt || !CBackgroundMusic.SongHasVideo;
+3
View File
@@ -152,6 +152,9 @@ namespace Vocaluxe.Screens
{ {
CBackgroundMusic.OwnSongsAvailable = true; CBackgroundMusic.OwnSongsAvailable = true;
if (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON || CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON)
CBackgroundMusic.VideoEnabled = true;
CBackgroundMusic.Play(); CBackgroundMusic.Play();
} }
+3 -3
View File
@@ -52,7 +52,7 @@ namespace Vocaluxe.Screens
public override void LoadTheme(string xmlPath) public override void LoadTheme(string xmlPath)
{ {
base.LoadTheme(xmlPath); base.LoadTheme(xmlPath);
_SelectSlides[_SelectSlideBackgroundMusic].SetValues<EOffOn>((int)CConfig.BackgroundMusic); _SelectSlides[_SelectSlideBackgroundMusic].SetValues<EBackgroundMusicOffOn>((int)CConfig.BackgroundMusic);
_SelectSlides[_SelectSlideBackgroundMusicVolume].AddValues(new string[] _SelectSlides[_SelectSlideBackgroundMusicVolume].AddValues(new string[]
{"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"}); {"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"});
_SelectSlides[_SelectSlideBackgroundMusicVolume].Selection = CConfig.BackgroundMusicVolume / 5; _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection = CConfig.BackgroundMusicVolume / 5;
@@ -150,14 +150,14 @@ namespace Vocaluxe.Screens
{ {
CConfig.GameMusicVolume = _SelectSlides[_SelectSlideGameMusicVolume].Selection * 5; CConfig.GameMusicVolume = _SelectSlides[_SelectSlideGameMusicVolume].Selection * 5;
CConfig.PreviewMusicVolume = _SelectSlides[_SelectSlidePreviewMusicVolume].Selection * 5; CConfig.PreviewMusicVolume = _SelectSlides[_SelectSlidePreviewMusicVolume].Selection * 5;
CConfig.BackgroundMusic = (EOffOn)_SelectSlides[_SelectSlideBackgroundMusic].Selection; CConfig.BackgroundMusic = (EBackgroundMusicOffOn)_SelectSlides[_SelectSlideBackgroundMusic].Selection;
CConfig.BackgroundMusicSource = (EBackgroundMusicSource)_SelectSlides[_SelectSlideBackgroundMusicSource].Selection; CConfig.BackgroundMusicSource = (EBackgroundMusicSource)_SelectSlides[_SelectSlideBackgroundMusicSource].Selection;
CConfig.BackgroundMusicVolume = _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection * 5; CConfig.BackgroundMusicVolume = _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection * 5;
CConfig.SaveConfig(); CConfig.SaveConfig();
CBackgroundMusic.SetMusicSource(CConfig.BackgroundMusicSource); CBackgroundMusic.SetMusicSource(CConfig.BackgroundMusicSource);
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) if (CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
CBackgroundMusic.Play(); CBackgroundMusic.Play();
else else
CBackgroundMusic.Pause(); CBackgroundMusic.Pause();
+2
View File
@@ -123,6 +123,8 @@ namespace Vocaluxe.Screens
public override void OnShow() public override void OnShow()
{ {
CBackgroundMusic.Disabled = false;
base.OnShow(); base.OnShow();
//-1 --> Show average //-1 --> Show average
_Round = CGame.NumRounds > 1 ? -1 : 0; _Round = CGame.NumRounds > 1 ? -1 : 0;
+7 -7
View File
@@ -537,8 +537,6 @@ namespace Vocaluxe.Screens
_CloseSong(); _CloseSong();
if (_Webcam) if (_Webcam)
CWebcam.Stop(); CWebcam.Stop();
CBackgroundMusic.Disabled = false;
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
} }
private void _CloseSong() private void _CloseSong()
@@ -569,6 +567,8 @@ namespace Vocaluxe.Screens
_Texts[_TextSongName].Text = String.Empty; _Texts[_TextSongName].Text = String.Empty;
_Texts[_TextDuetName1].Text = String.Empty; _Texts[_TextDuetName1].Text = String.Empty;
_Texts[_TextDuetName2].Text = String.Empty; _Texts[_TextDuetName2].Text = String.Empty;
_Texts[_TextMedleyCountdown].Visible = false;
_Texts[_TextMedleyCountdown].Text = String.Empty;
} }
private void _LoadNextSong() private void _LoadNextSong()
@@ -991,13 +991,13 @@ namespace Vocaluxe.Screens
float partSeconds = timeDiff - fullSeconds; float partSeconds = timeDiff - fullSeconds;
_Texts[_TextMedleyCountdown].Visible = true; _Texts[_TextMedleyCountdown].Visible = true;
_Texts[_TextMedleyCountdown].Text = fullSeconds.ToString(); _Texts[_TextMedleyCountdown].Text = fullSeconds.ToString();
float h = partSeconds * CSettings.RenderH; _Texts[_TextMedleyCountdown].Font.Height = partSeconds * CSettings.RenderH;
float w = CFonts.GetTextBounds(_Texts[_TextMedleyCountdown], h).Width;
float x = CSettings.RenderW / 2 - w / 2; RectangleF textBounds = CFonts.GetTextBounds(_Texts[_TextMedleyCountdown]);
float y = CSettings.RenderH / 2 - h / 2; float x = CSettings.RenderW / 2 - textBounds.Width / 2;
float y = CSettings.RenderH / 2 - textBounds.Height / 2;
_Texts[_TextMedleyCountdown].X = x; _Texts[_TextMedleyCountdown].X = x;
_Texts[_TextMedleyCountdown].Y = y; _Texts[_TextMedleyCountdown].Y = y;
_Texts[_TextMedleyCountdown].Height = h;
} }
else else
_Texts[_TextMedleyCountdown].Visible = false; _Texts[_TextMedleyCountdown].Visible = false;
+6 -6
View File
@@ -662,11 +662,6 @@ namespace Vocaluxe.Screens
_Texts[_TextCategory].Text = CSongs.GetCurrentCategoryName(); _Texts[_TextCategory].Text = CSongs.GetCurrentCategoryName();
if (CSongs.IsInCategory || CConfig.Tabs == EOffOn.TR_CONFIG_OFF)
CBackgroundMusic.Disabled = true;
else
CBackgroundMusic.Disabled = false;
string selectionText = ""; string selectionText = "";
if (CSongs.IsInCategory) if (CSongs.IsInCategory)
{ {
@@ -716,9 +711,14 @@ namespace Vocaluxe.Screens
public override void OnClose() public override void OnClose()
{ {
base.OnClose(); base.OnClose();
_SongMenu.OnHide();
if (CGraphics.NextScreen != EScreens.ScreenNames)
{
CBackgroundMusic.Disabled = false; CBackgroundMusic.Disabled = false;
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
_SongMenu.OnHide(); }
} }
private void _HandlePartySongSelection(int songNr) private void _HandlePartySongSelection(int songNr)
+1 -1
View File
@@ -242,7 +242,7 @@
<Compile Include="Base\CDraw.cs" /> <Compile Include="Base\CDraw.cs" />
<Compile Include="Lib\Sound\Playback\PortAudio\CPt1.cs" /> <Compile Include="Lib\Sound\Playback\PortAudio\CPt1.cs" />
<Compile Include="Lib\Sound\Playback\PortAudio\CSyncTimer.cs" /> <Compile Include="Lib\Sound\Playback\PortAudio\CSyncTimer.cs" />
<Compile Include="Base\Fonts\CFont.cs" /> <Compile Include="Base\Fonts\CFontStyle.cs" />
<Compile Include="Base\CGame.cs" /> <Compile Include="Base\CGame.cs" />
<Compile Include="Base\CController.cs" /> <Compile Include="Base\CController.cs" />
<Compile Include="Base\CLanguage.cs" /> <Compile Include="Base\CLanguage.cs" />
+87
View File
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
namespace VocaluxeLib
{
public interface IFontObserver
{
void FontChanged();
}
public class CFont
{
private string _Name;
private EStyle _Style;
private float _Height;
private readonly List<IFontObserver> _Observers = new List<IFontObserver>();
public string Name
{
get { return _Name; }
set
{
if (_Name == value)
return;
_Name = value;
foreach (IFontObserver observer in _Observers)
observer.FontChanged();
}
}
public EStyle Style
{
get { return _Style; }
set
{
if (_Style == value)
return;
_Style = value;
foreach (IFontObserver observer in _Observers)
observer.FontChanged();
}
}
public float Height
{
get { return _Height; }
set
{
if (Math.Abs(_Height - value) < 0.001)
return;
_Height = value;
foreach (IFontObserver observer in _Observers)
observer.FontChanged();
}
}
public CFont()
{
_Name = "Normal";
_Style = EStyle.Normal;
_Height = 25f;
}
public CFont(CFont font)
{
_Name = font.Name;
_Style = font.Style;
_Height = font.Height;
}
public CFont(string fontFamily, EStyle style, float h)
{
_Name = fontFamily;
_Style = style;
_Height = h;
}
public void AddObserver(IFontObserver observer)
{
if (!_Observers.Contains(observer))
_Observers.Add(observer);
}
public void RemoveObserver(IFontObserver observer)
{
_Observers.Remove(observer);
}
}
}
+6
View File
@@ -64,6 +64,12 @@ namespace VocaluxeLib
return (int)result; return (int)result;
} }
public static bool InRange<T>(this T val, T min, T max) where T : IComparable<T>
{
Debug.Assert(min.CompareTo(max) <= 0);
return val.CompareTo(min) >= 0 && val.CompareTo(max) <= 0;
}
/// <summary> /// <summary>
/// Makes sure val is between min and max /// Makes sure val is between min and max
/// Asserts that min&lt;=max /// Asserts that min&lt;=max
+16 -11
View File
@@ -88,20 +88,25 @@ namespace VocaluxeLib
return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value); return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value);
} }
/// <summary>
/// Gets a normalized (0&lt;=x&lt;=1) float value
/// </summary>
/// <param name="xPath"></param>
/// <param name="value"></param>
/// <returns>True if exists and is normalized</returns>
public bool TryGetNormalizedFloatValue(string xPath, ref float value)
{
string val;
return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value) && value.InRange(0f, 1f);
}
public bool TryGetColorFromRGBA(string xPath, ref SColorF value) public bool TryGetColorFromRGBA(string xPath, ref SColorF value)
{ {
bool result = true; bool result = true;
result &= TryGetFloatValue(xPath + "/R", ref value.R); result &= TryGetNormalizedFloatValue(xPath + "/R", ref value.R);
result &= TryGetFloatValue(xPath + "/G", ref value.G); result &= TryGetNormalizedFloatValue(xPath + "/G", ref value.G);
result &= TryGetFloatValue(xPath + "/B", ref value.B); result &= TryGetNormalizedFloatValue(xPath + "/B", ref value.B);
result &= TryGetFloatValue(xPath + "/A", ref value.A); result &= TryGetNormalizedFloatValue(xPath + "/A", ref value.A);
if (result)
{
value.R = value.R.Clamp(0f, 1f);
value.G = value.G.Clamp(0f, 1f);
value.B = value.B.Clamp(0f, 1f);
value.A = value.A.Clamp(0f, 1f);
}
return result; return result;
} }
+15
View File
@@ -248,6 +248,13 @@ namespace VocaluxeLib
// ReSharper restore InconsistentNaming // ReSharper restore InconsistentNaming
} }
public enum EBackgroundMusicOffOn
{
TR_CONFIG_OFF,
TR_CONFIG_ONLY_SONG,
TR_CONFIG_ON
}
public enum EPlayerInfo public enum EPlayerInfo
{ {
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
@@ -288,6 +295,14 @@ namespace VocaluxeLib
} }
#endregion Config #endregion Config
public enum EStreamAction
{
Nothing,
Pause,
Stop,
Close
}
public enum EProgramState public enum EProgramState
{ {
Start, Start,
+34 -9
View File
@@ -35,6 +35,8 @@ namespace VocaluxeLib
void SetBackgroundMusicVolume(int newVolume); void SetBackgroundMusicVolume(int newVolume);
int GetBackgroundMusicVolume(); int GetBackgroundMusicVolume();
EBackgroundMusicOffOn GetBackgroundMusicStatus();
int GetPreviewMusicVolume(); int GetPreviewMusicVolume();
EOffOn GetVideosToBackground(); EOffOn GetVideosToBackground();
@@ -89,6 +91,8 @@ namespace VocaluxeLib
float GetSlideShowImageTime(); float GetSlideShowImageTime();
float GetSlideShowFadeTime(); float GetSlideShowFadeTime();
float GetSoundPlayerFadeTime();
} }
public interface ITheme public interface ITheme
@@ -115,16 +119,24 @@ namespace VocaluxeLib
{ {
bool IsDisabled(); bool IsDisabled();
bool IsPlaying(); bool IsPlaying();
bool IsPlayingPreview();
bool SongHasVideo(); bool SongHasVideo();
bool VideoEnabled(); bool VideoEnabled();
float GetLength();
void SetDisabled(bool disabled); void SetDisabled(bool disabled);
void Next(); void Next();
void Previous(); void Previous();
void Pause(); void Pause();
void Play(); void Play();
void Stop();
CTexture GetVideoTexture(); CTexture GetVideoTexture();
void LoadPreview(CSong song, float start = 0f);
void PlayPreview(float start = -1f);
void StopPreview();
} }
public interface IDrawing public interface IDrawing
@@ -148,6 +160,8 @@ namespace VocaluxeLib
void FadeTo(EScreens nextScreen); void FadeTo(EScreens nextScreen);
float GetGlobalAlpha(); float GetGlobalAlpha();
EScreens GetNextScreen();
} }
public interface ILog public interface ILog
@@ -159,15 +173,11 @@ namespace VocaluxeLib
public interface IFonts public interface IFonts
{ {
void SetFont(string fontName);
void SetStyle(EStyle fontStyle);
RectangleF GetTextBounds(CText text); RectangleF GetTextBounds(CText text);
RectangleF GetTextBounds(CText text, float textHeight);
void DrawText(string text, float textHeight, float x, float y, float z, SColorF color); void DrawText(string text, CFont font, float x, float y, float z, SColorF color);
void DrawTextReflection(string text, float textHeight, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight); void DrawTextReflection(string text, CFont font, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight);
void DrawText(string text, float textHeight, float x, float y, float z, SColorF color, float begin, float end); void DrawText(string text, CFont font, float x, float y, float z, SColorF color, float begin, float end);
} }
public interface ILanguage public interface ILanguage
@@ -255,6 +265,8 @@ namespace VocaluxeLib
bool IsFinished(int streamID); bool IsFinished(int streamID);
bool Close(int streamID); bool Close(int streamID);
void SetLoop(int streamID, bool loop = true); void SetLoop(int streamID, bool loop = true);
void Resume(int streamID);
void Pause(int streamID);
} }
public interface ISound public interface ISound
@@ -262,12 +274,12 @@ namespace VocaluxeLib
int Load(string soundFile, bool loop = false, bool prescan = false); int Load(string soundFile, bool loop = false, bool prescan = false);
void SetPosition(int soundStream, float newPosition); void SetPosition(int soundStream, float newPosition);
void Play(int soundStream); void Play(int soundStream);
void Fade(int soundStream, float targetVolume, float duration); void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing);
void Close(int soundStream);
bool IsFinished(int soundStream); bool IsFinished(int soundStream);
float GetPosition(int soundStream); float GetPosition(int soundStream);
float GetLength(int soundStream); float GetLength(int soundStream);
void FadeAndClose(int soundStream, float targetVolume, float duration);
void SetStreamVolume(int soundStream, float volume); void SetStreamVolume(int soundStream, float volume);
} }
@@ -311,4 +323,17 @@ namespace VocaluxeLib
int GetSongCount(int playlistID); int GetSongCount(int playlistID);
CPlaylistSong GetSong(int playlistID, int songIndex); CPlaylistSong GetSong(int playlistID, int songIndex);
} }
public interface IPreviewPlayer
{
void Play(float start = -1);
void Load(CSong song, float start = 0f);
void Stop();
void TogglePause();
CTexture GetCover();
CTexture GetVideoTexture();
bool IsPlaying();
float GetLength();
}
} }
+1 -1
View File
@@ -194,7 +194,7 @@ namespace VocaluxeLib.Menu
if (!String.IsNullOrEmpty(_Theme.TextureName) && if (!String.IsNullOrEmpty(_Theme.TextureName) &&
(_Theme.Type == EBackgroundTypes.Texture || (_Theme.Type == EBackgroundTypes.Texture ||
(_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok)))) (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF)))
ok = _DrawTexture(); ok = _DrawTexture();
if (_Theme.Type == EBackgroundTypes.Color || _Theme.Type == EBackgroundTypes.Texture && !ok || if (_Theme.Type == EBackgroundTypes.Color || _Theme.Type == EBackgroundTypes.Texture && !ok ||
+5 -8
View File
@@ -205,10 +205,7 @@ namespace VocaluxeLib.Menu
private void _SetText(CSongNote note) private void _SetText(CSongNote note)
{ {
_Text.Text = note.Text; _Text.Text = note.Text;
_Text.Style = EStyle.Bold; _Text.Font.Style = (note.Type == ENoteType.Freestyle)? EStyle.BoldItalic:EStyle.Bold;
if (note.Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
} }
public void Clear() public void Clear()
@@ -350,11 +347,11 @@ namespace VocaluxeLib.Menu
p = 1f - p; p = 1f - p;
float ty = _Text.Y; float ty = _Text.Y;
float th = _Text.Height; float th = _Text.Font.Height;
float tz = _Text.Z; float tz = _Text.Z;
SRectF normalRect = _Text.Rect; SRectF normalRect = _Text.Rect;
_Text.Height += _Text.Height * p * 0.4f; _Text.Font.Height *= 1f+ p * 0.4f;
_Text.X -= (_Text.Rect.W - normalRect.W) / 2f; _Text.X -= (_Text.Rect.W - normalRect.W) / 2f;
_Text.Y -= (_Text.Rect.H - normalRect.H) / 2f; _Text.Y -= (_Text.Rect.H - normalRect.H) / 2f;
_Text.Z -= 0.1f; _Text.Z -= 0.1f;
@@ -364,7 +361,7 @@ namespace VocaluxeLib.Menu
_Text.Draw(); _Text.Draw();
_Text.Y = ty; _Text.Y = ty;
_Text.Height = th; _Text.Font.Height = th;
_Text.Z = tz; _Text.Z = tz;
} }
} }
@@ -456,7 +453,7 @@ namespace VocaluxeLib.Menu
else else
{ {
float y = _Text.Y; float y = _Text.Y;
_Text.Y -= _Text.Height * 0.1f * p; _Text.Y -= _Text.Font.Height * 0.1f * p;
_Text.Draw(); _Text.Draw();
_Text.Y = y; _Text.Y = y;
} }
+46 -68
View File
@@ -28,9 +28,12 @@ namespace VocaluxeLib.Menu
public string Text; public string Text;
public string ColorName; public string ColorName;
public string SelColorName; //for Buttons public string SelColorName; //for Buttons
public string FontFamily;
public EStyle FontStyle;
public float FontHeight;
} }
public class CText : IMenuElement public class CText : IMenuElement, IFontObserver
{ {
private SThemeText _Theme; private SThemeText _Theme;
private bool _ThemeLoaded; private bool _ThemeLoaded;
@@ -82,20 +85,6 @@ namespace VocaluxeLib.Menu
set { _Z = value; } set { _Z = value; }
} }
private float _Height;
public float Height
{
get { return _Height; }
set
{
if (Math.Abs(_Height - value) > 0.01)
{
_Height = value;
_PositionNeedsUpdate = true;
}
}
}
private float _MaxWidth; private float _MaxWidth;
public float MaxWidth public float MaxWidth
{ {
@@ -138,29 +127,17 @@ namespace VocaluxeLib.Menu
} }
} }
private EStyle _Style = EStyle.Normal; private CFont _Font = new CFont();
public EStyle Style public CFont Font
{
get { return _Style; }
set
{
if (_Style != value)
{
_Style = value;
_PositionNeedsUpdate = true;
}
}
}
private string _Font = String.Empty;
public string Font
{ {
get { return _Font; } get { return _Font; }
set set
{ {
if (_Font != value) if (!_Font.Equals(value))
{ {
_Font.RemoveObserver(this);
_Font = value; _Font = value;
_Font.AddObserver(this);
_PositionNeedsUpdate = true; _PositionNeedsUpdate = true;
} }
} }
@@ -199,10 +176,16 @@ namespace VocaluxeLib.Menu
_Text = translation; _Text = translation;
if (_EditMode) if (_EditMode)
_Text += "|"; _Text += "|";
//Reset height, it might have been reduced in _UpdatePosition
Font.Height = _Theme.FontHeight;
_PositionNeedsUpdate = true; _PositionNeedsUpdate = true;
} }
} }
} }
public string TranslatedText
{
get { return _Text; }
}
public int PartyModeID public int PartyModeID
{ {
@@ -246,7 +229,7 @@ namespace VocaluxeLib.Menu
{ {
_PartyModeID = partyModeID; _PartyModeID = partyModeID;
_TranslationID = _PartyModeID; _TranslationID = _PartyModeID;
_Font = "Normal"; _Font.AddObserver(this);
} }
public CText(CText text) public CText(CText text)
@@ -257,12 +240,10 @@ namespace VocaluxeLib.Menu
_X = text._X; _X = text._X;
_Y = text._Y; _Y = text._Y;
_Z = text._Z; _Z = text._Z;
_Height = text._Height;
_MaxWidth = text._MaxWidth; _MaxWidth = text._MaxWidth;
_Align = text._Align; _Align = text._Align;
_ResizeAlign = text._ResizeAlign; _ResizeAlign = text._ResizeAlign;
_Style = text._Style; Font = text.Font; //Use setter to set observer
_Font = text._Font;
Color = new SColorF(text.Color); Color = new SColorF(text.Color);
SelColor = new SColorF(text.SelColor); SelColor = new SColorF(text.SelColor);
@@ -277,24 +258,23 @@ namespace VocaluxeLib.Menu
_EditMode = text._EditMode; _EditMode = text._EditMode;
} }
public CText(float x, float y, float z, float h, float mw, EAlignment align, EStyle style, string font, SColorF col, string text, int partyModeID = -1, float rheight = 0, public CText(float x, float y, float z, float h, float mw, EAlignment align, EStyle style, string fontFamily, SColorF col, string text, int partyModeID = -1,
float rspace = 0) float rheight = 0,
float rspace = 0) : this(partyModeID)
{ {
_Theme = new SThemeText(); _Theme = new SThemeText {FontFamily = fontFamily, FontStyle = style, FontHeight = h, Text = text};
_ThemeLoaded = false; _ThemeLoaded = false;
_ButtonText = false; _ButtonText = false;
_PartyModeID = partyModeID;
_TranslationID = _PartyModeID;
X = x; X = x;
Y = y; Y = y;
Z = z; Z = z;
Height = h;
MaxWidth = mw; MaxWidth = mw;
Align = align; Align = align;
ResizeAlign = EHAlignment.Center; ResizeAlign = EHAlignment.Center;
Style = style; _Font.Name = fontFamily;
Font = font; _Font.Style = style;
_Font.Height = h;
Color = col; Color = col;
SelColor = new SColorF(col); SelColor = new SColorF(col);
@@ -323,7 +303,6 @@ namespace VocaluxeLib.Menu
if (!buttonText) if (!buttonText)
_ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Z", ref _Z); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Z", ref _Z);
_ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref _Height);
xmlReader.TryGetFloatValue(item + "/MaxW", ref _MaxWidth); xmlReader.TryGetFloatValue(item + "/MaxW", ref _MaxWidth);
if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty))
@@ -350,8 +329,10 @@ namespace VocaluxeLib.Menu
_ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Align", ref _Align); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Align", ref _Align);
xmlReader.TryGetEnumValue(item + "/ResizeAlign", ref _ResizeAlign); xmlReader.TryGetEnumValue(item + "/ResizeAlign", ref _ResizeAlign);
_ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Style", ref _Style); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref _Theme.FontHeight);
_ThemeLoaded &= xmlReader.GetValue(item + "/Font", out _Font, "Normal"); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Style", ref _Theme.FontStyle);
_ThemeLoaded &= xmlReader.GetValue(item + "/Font", out _Theme.FontFamily);
Font = new CFont(_Theme.FontFamily, _Theme.FontStyle, _Theme.FontHeight);
_ThemeLoaded &= xmlReader.GetValue(item + "/Text", out _Theme.Text, String.Empty); _ThemeLoaded &= xmlReader.GetValue(item + "/Text", out _Theme.Text, String.Empty);
@@ -388,7 +369,7 @@ namespace VocaluxeLib.Menu
} }
writer.WriteComment("<H>: Text height"); writer.WriteComment("<H>: Text height");
writer.WriteElementString("H", Height.ToString("#0")); writer.WriteElementString("H", _Theme.FontHeight.ToString("#0"));
writer.WriteComment("<MaxW>: Maximum text width (if exists)"); writer.WriteComment("<MaxW>: Maximum text width (if exists)");
if (MaxWidth > 0) if (MaxWidth > 0)
@@ -425,10 +406,10 @@ namespace VocaluxeLib.Menu
writer.WriteElementString("ResizeAlign", Enum.GetName(typeof(EHAlignment), ResizeAlign)); writer.WriteElementString("ResizeAlign", Enum.GetName(typeof(EHAlignment), ResizeAlign));
writer.WriteComment("<Style>: Text style: " + CHelper.ListStrings(Enum.GetNames(typeof(EStyle)))); writer.WriteComment("<Style>: Text style: " + CHelper.ListStrings(Enum.GetNames(typeof(EStyle))));
writer.WriteElementString("Style", Enum.GetName(typeof(EStyle), Style)); writer.WriteElementString("Style", Enum.GetName(typeof(EStyle), _Theme.FontStyle));
writer.WriteComment("<Font>: Text font name"); writer.WriteComment("<Font>: Text font name");
writer.WriteElementString("Font", Font); writer.WriteElementString("Font", _Theme.FontFamily);
writer.WriteComment("<Text>: Nothing or translation tag"); writer.WriteComment("<Text>: Nothing or translation tag");
writer.WriteElementString("Text", CBase.Language.TranslationExists(_Theme.Text) ? _Theme.Text : string.Empty); writer.WriteElementString("Text", CBase.Language.TranslationExists(_Theme.Text) ? _Theme.Text : string.Empty);
@@ -463,16 +444,13 @@ namespace VocaluxeLib.Menu
// Update Text // Update Text
Text = Text; Text = Text;
CBase.Fonts.SetFont(Font);
CBase.Fonts.SetStyle(Style);
SColorF currentColor = (Selected) ? SelColor : Color; SColorF currentColor = (Selected) ? SelColor : Color;
var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha); var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
CBase.Fonts.DrawText(_Text, Rect.H, Rect.X, Rect.Y, Z, color); CBase.Fonts.DrawText(_Text, Font, Rect.X, Rect.Y, Z, color);
if (ReflectionHeight > 0) if (ReflectionHeight > 0)
CBase.Fonts.DrawTextReflection(_Text, Rect.H, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight); CBase.Fonts.DrawTextReflection(_Text, Font, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight);
if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme)) if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
CBase.Drawing.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z)); CBase.Drawing.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z));
@@ -480,13 +458,10 @@ namespace VocaluxeLib.Menu
public void Draw(float begin, float end) public void Draw(float begin, float end)
{ {
CBase.Fonts.SetFont(Font);
CBase.Fonts.SetStyle(Style);
SColorF currentColor = (Selected) ? SelColor : Color; SColorF currentColor = (Selected) ? SelColor : Color;
var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha); var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
CBase.Fonts.DrawText(Text, Rect.H, Rect.X, Rect.Y, Z, color, begin, end); CBase.Fonts.DrawText(Text, Font, Rect.X, Rect.Y, Z, color, begin, end);
if (ReflectionHeight > 0) if (ReflectionHeight > 0)
{ {
@@ -543,9 +518,10 @@ namespace VocaluxeLib.Menu
public void ResizeElement(int stepW, int stepH) public void ResizeElement(int stepW, int stepH)
{ {
Height += stepH; _Theme.FontHeight += stepH;
if (Height <= 0) if (_Theme.FontHeight <= 0)
Height = 1; _Theme.FontHeight = 1;
_Font.Height = _Theme.FontHeight;
} }
#endregion ThemeEdit #endregion ThemeEdit
@@ -554,10 +530,7 @@ namespace VocaluxeLib.Menu
if (_Text == "") if (_Text == "")
return; return;
CBase.Fonts.SetFont(Font); float h = Font.Height;
CBase.Fonts.SetStyle(Style);
float h = Height;
float y = Y; float y = Y;
RectangleF bounds = CBase.Fonts.GetTextBounds(this); RectangleF bounds = CBase.Fonts.GetTextBounds(this);
@@ -578,8 +551,8 @@ namespace VocaluxeLib.Menu
y += step * 0.75f; y += step * 0.75f;
break; break;
} }
Font.Height = h;
bounds = CBase.Fonts.GetTextBounds(this, h); bounds = CBase.Fonts.GetTextBounds(this);
} }
float x = X; float x = X;
@@ -600,5 +573,10 @@ namespace VocaluxeLib.Menu
_PositionNeedsUpdate = false; _PositionNeedsUpdate = false;
} }
public void FontChanged()
{
_PositionNeedsUpdate = true;
}
} }
} }
+16 -73
View File
@@ -115,18 +115,15 @@ namespace VocaluxeLib.Menu.SongMenu
_PlaySong(value); _PlaySong(value);
} }
else if (value >= CBase.Songs.GetNumCategories()) else if (value >= CBase.Songs.GetNumCategories())
{
value = -1; value = -1;
CBase.BackgroundMusic.Stop();
}
_PreviewNrInternal = value; _PreviewNrInternal = value;
} }
} }
protected int _PreviewSongStream { get; private set; }
protected int _PreviewVideoStream { get; private set; }
private CFading _VideoFading;
protected CTexture _Vidtex;
private SColorF _ColorInternal; private SColorF _ColorInternal;
protected SColorF _Color protected SColorF _Color
{ {
@@ -160,8 +157,6 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
Visible = true; Visible = true;
_PartyModeID = partyModeID; _PartyModeID = partyModeID;
_PreviewVideoStream = -1;
_PreviewSongStream = -1;
_Theme = new SThemeSongMenu _Theme = new SThemeSongMenu
{ {
SongMenuTileBoard = SongMenuTileBoard =
@@ -346,7 +341,7 @@ namespace VocaluxeLib.Menu.SongMenu
public virtual void Init() public virtual void Init()
{ {
_ResetPreview(); _ResetPreview(false);
_Initialized = true; _Initialized = true;
} }
@@ -354,39 +349,13 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
if (!_Initialized) if (!_Initialized)
return; return;
if (_PreviewSongStream == -1 || _PreviewVideoStream == -1)
return;
if (CBase.Video.IsFinished(_PreviewVideoStream) || CBase.Sound.IsFinished(_PreviewSongStream))
{
CBase.Video.Close(_PreviewVideoStream);
_PreviewVideoStream = -1;
return;
}
float time = CBase.Sound.GetPosition(_PreviewSongStream);
float vtime;
if (CBase.Video.GetFrame(_PreviewVideoStream, ref _Vidtex, time, out vtime))
{
if (_Vidtex != null)
{
if (_VideoFading != null)
{
bool finished;
_Vidtex.Color.A = _VideoFading.GetValue(out finished);
if (finished)
_VideoFading = null;
}
}
}
} }
public virtual void OnShow() {} public virtual void OnShow() {}
public virtual void OnHide() public virtual void OnHide()
{ {
if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames)
_ResetPreview(); _ResetPreview();
} }
@@ -399,8 +368,8 @@ namespace VocaluxeLib.Menu.SongMenu
if (!_Initialized || !Visible) if (!_Initialized || !Visible)
return; return;
if (_PreviewVideoStream != -1) if (CBase.BackgroundMusic.IsPlaying())
CBase.Drawing.DrawTexture(_Vidtex, new SRectF(0, 0, 1280, 720, 0)); CBase.Drawing.DrawTexture(CBase.BackgroundMusic.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0));
} }
public bool IsMouseOverSelectedSong(SMouseEvent mEvent) public bool IsMouseOverSelectedSong(SMouseEvent mEvent)
@@ -486,7 +455,7 @@ namespace VocaluxeLib.Menu.SongMenu
if (categoryNr >= CBase.Songs.GetNumCategories()) if (categoryNr >= CBase.Songs.GetNumCategories())
return; return;
_ResetPreview(); _ResetPreview(false);
CBase.Songs.SetCategory(categoryNr); CBase.Songs.SetCategory(categoryNr);
} }
@@ -504,50 +473,24 @@ namespace VocaluxeLib.Menu.SongMenu
private void _PlaySong(int nr) private void _PlaySong(int nr)
{ {
_ResetPreview(); _PreviewNrInternal = -1;
CSong song = CBase.Songs.GetVisibleSong(nr); CSong song = CBase.Songs.GetVisibleSong(nr);
if (song == null) if (song == null)
return; return;
//TODO: Using prescan here causes Vocaluxe to hang a bit on loading the song but we need the length below CBase.BackgroundMusic.LoadPreview(song);
_PreviewSongStream = CBase.Sound.Load(Path.Combine(song.Folder, song.MP3FileName), true, true); }
float startposition = song.Preview.StartTime; protected void _ResetPreview(bool playBGagain = true)
float length = CBase.Sound.GetLength(_PreviewSongStream);
if (song.Preview.Source == EDataSource.None)
startposition = length / 4f;
else if (startposition > length - 5f)
startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f));
CBase.Sound.SetPosition(_PreviewSongStream, startposition);
CBase.Sound.Play(_PreviewSongStream);
CBase.Sound.SetStreamVolume(_PreviewSongStream, 0f);
CBase.Sound.Fade(_PreviewSongStream, 100f, 3f);
if (song.VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON)
{ {
_PreviewVideoStream = CBase.Video.Load(Path.Combine(song.Folder, song.VideoFileName)); if (_PreviewNrInternal == -1)
if (_PreviewVideoStream == -1)
return; return;
CBase.Video.SetLoop(_PreviewVideoStream);
CBase.Video.Skip(_PreviewVideoStream, startposition, song.VideoGap);
_VideoFading = new CFading(0f, 1f, 3f);
}
}
protected void _ResetPreview() CBase.BackgroundMusic.StopPreview();
{
if (_PreviewSongStream >= 0)
CBase.Sound.FadeAndClose(_PreviewSongStream, 0f, 0.75f);
_PreviewSongStream = -1; if (playBGagain)
CBase.BackgroundMusic.Play();
CBase.Video.Close(_PreviewVideoStream);
_PreviewVideoStream = -1;
CBase.Drawing.RemoveTexture(ref _Vidtex);
//Make sure we don't have a preview here otherwise a change won't be recognized //Make sure we don't have a preview here otherwise a change won't be recognized
//(e.g. leave a category with one song and set preview to 0 --> previewOld=previewNew=0 --> No change --> Old data shown //(e.g. leave a category with one song and set preview to 0 --> previewOld=previewNew=0 --> No change --> Old data shown
@@ -110,7 +110,11 @@ namespace VocaluxeLib.Menu.SongMenu
set set
{ {
if (value == base._PreviewNr) if (value == base._PreviewNr)
{
if (!CBase.BackgroundMusic.IsPlaying() && value != -1)
CBase.BackgroundMusic.PlayPreview();
return; return;
}
base._PreviewNr = value; base._PreviewNr = value;
_UpdatePreview(); _UpdatePreview();
} }
@@ -179,7 +183,7 @@ namespace VocaluxeLib.Menu.SongMenu
if (songOptions.Selection.RandomOnly) if (songOptions.Selection.RandomOnly)
_PreviewNr = _SelectionNr; _PreviewNr = _SelectionNr;
if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.Sound.GetLength(_PreviewSongStream) > 0) if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.BackgroundMusic.GetLength() > 0)
_UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr)); _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr));
} }
@@ -244,7 +248,7 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
if (song == null) if (song == null)
return; return;
float time = CBase.Sound.GetLength(_PreviewSongStream); float time = CBase.BackgroundMusic.GetLength();
if (Math.Abs(song.Finish) > 0.001) if (Math.Abs(song.Finish) > 0.001)
time = song.Finish; time = song.Finish;
@@ -463,18 +467,20 @@ namespace VocaluxeLib.Menu.SongMenu
_TextBG.Draw(); _TextBG.Draw();
if (_Vidtex != null && _PreviewVideoStream != -1) CTexture vidtex = CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null;
if (vidtex != null)
{ {
if (_Vidtex.Color.A < 1) if (vidtex.Color.A < 1)
_CoverBig.Draw(EAspect.Crop); _CoverBig.Draw(EAspect.Crop);
var bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); var bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H);
RectangleF rect; RectangleF rect;
CHelper.SetRect(bounds, out rect, _Vidtex.OrigAspect, EAspect.Crop); CHelper.SetRect(bounds, out rect, vidtex.OrigAspect, EAspect.Crop);
var vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); var vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z);
var vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); var vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f);
CBase.Drawing.DrawTexture(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds); CBase.Drawing.DrawTexture(vidtex, vidRect, vidtex.Color, vidRectBounds);
CBase.Drawing.DrawTextureReflection(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight); CBase.Drawing.DrawTextureReflection(vidtex, vidRect, vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight);
} }
else else
_CoverBig.Draw(EAspect.Crop); _CoverBig.Draw(EAspect.Crop);
+1 -3
View File
@@ -32,11 +32,9 @@ namespace VocaluxeLib.PartyModes
public override void LoadTheme(string xmlPath) public override void LoadTheme(string xmlPath)
{ {
_Warning = GetNewText(); _Warning = GetNewText();
_Warning.Height = 100f; _Warning.Font.Height = 100f;
_Warning.X = 150; _Warning.X = 150;
_Warning.Y = 300; _Warning.Y = 300;
_Warning.Font = "Normal";
_Warning.Style = EStyle.Normal;
_Warning.Color = new SColorF(1f, 0f, 0f, 1f); _Warning.Color = new SColorF(1f, 0f, 0f, 1f);
_Warning.SelColor = new SColorF(1f, 0f, 0f, 1f); _Warning.SelColor = new SColorF(1f, 0f, 0f, 1f);
_Warning.Text = "SOMETHING WENT WRONG!"; _Warning.Text = "SOMETHING WENT WRONG!";
+3
View File
@@ -458,7 +458,10 @@ namespace VocaluxeLib.Songs
if (Preview.Source == EDataSource.None) if (Preview.Source == EDataSource.None)
{ {
if (Medley.Source != EDataSource.None) if (Medley.Source != EDataSource.None)
{
Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM); Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM);
Preview.Source = EDataSource.Calculated;
}
} }
} }
+1
View File
@@ -416,6 +416,7 @@ namespace VocaluxeLib.Songs
{ {
//PreviewStart is not set or <=0 //PreviewStart is not set or <=0
_Song.Preview.StartTime = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(_Song.Medley.StartBeat, _Song.BPM) : 0f; _Song.Preview.StartTime = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(_Song.Medley.StartBeat, _Song.BPM) : 0f;
_Song.Preview.Source = _Song.Preview.StartTime == 0 ? EDataSource.None : EDataSource.Calculated;
} }
if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0) if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0)
+185
View File
@@ -0,0 +1,185 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using VocaluxeLib.Draw;
using VocaluxeLib.Songs;
namespace VocaluxeLib.Utils.Player
{
public class CSongPlayer : CSoundPlayer
{
private CSong _Song;
private bool _VideoEnabled;
private int _Video = -1;
private CTexture _CurrentVideoTexture;
private CFading _VideoFading;
public bool VideoEnabled
{
get { return _VideoEnabled; }
set
{
if (_VideoEnabled == value)
return;
_VideoEnabled = value;
if (_VideoEnabled)
_LoadVideo();
else if (_Video != -1)
{
CBase.Video.Close(_Video);
CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture);
_Video = -1;
}
}
}
public int SongID
{
get { return _Song == null ? -1 : _Song.ID; }
}
public bool SongHasVideo
{
get { return _Song != null && File.Exists(Path.Combine(_Song.Folder,_Song.VideoFileName)); }
}
public string ArtistAndTitle
{
get
{
if (_Song == null)
return "";
if (_Song.Artist != "" && _Song.Title != "")
return _Song.Artist + " - " + _Song.Title;
return Path.GetFileNameWithoutExtension(_Song.MP3FileName);
}
}
public CTexture Cover
{
get { return _Song == null ? CBase.Cover.GetNoCover() : _Song.CoverTextureBig; }
}
public bool SongLoaded
{
get { return _StreamID != -1; }
}
public CSongPlayer(bool loop = false) : base(loop) { }
public CSongPlayer(CSong song, bool loop = false, float position = 0f, bool autoplay = false)
: base(Path.Combine(song.Folder,song.MP3FileName), loop, position, autoplay)
{
_Song = song;
_LoadVideo();
}
public CSongPlayer(string file, bool loop = false, float position = 0f, bool autoplay = false)
: base(file, loop, position, autoplay)
{
_Song = null;
}
public CTexture GetVideoTexture()
{
if (_Video == -1 || _Song == null)
return null;
float vtime;
if (CBase.Video.GetFrame(_Video, ref _CurrentVideoTexture, CBase.Sound.GetPosition(_StreamID), out vtime))
{
if (_VideoFading != null)
{
bool finished;
_CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished);
if (finished)
_VideoFading = null;
}
return _CurrentVideoTexture;
}
return null;
}
public void Load(CSong song, float position = 0f, bool autoplay = false)
{
if (song == null)
return;
Stop();
_Song = song;
base.Load(Path.Combine(song.Folder, song.MP3FileName), position, false);
_LoadVideo();
if (autoplay)
Play();
}
public void LoadFile(string file, float position = 0f, bool autoplay = false)
{
if (String.IsNullOrEmpty(file))
return;
Stop();
base.Load(file, position, autoplay);
}
public new void Play()
{
CBase.Sound.SetPosition(_StreamID, _StartPosition);
CBase.Video.Skip(_Video, _StartPosition, _Song.VideoGap);
TogglePause();
}
public new void Stop()
{
base.Stop();
_Song = null;
if (_Video != -1)
{
CBase.Video.Close(_Video);
CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture);
_Video = -1;
}
}
public new void TogglePause()
{
if (IsPlaying && _Video != -1)
{
CBase.Video.Pause(_Video);
CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap);
}
else if(_Video != -1)
{
CBase.Video.Resume(_Video);
}
base.TogglePause();
}
private void _LoadVideo()
{
if (_Song == null)
return;
string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName);
if (_Video != -1 || String.IsNullOrEmpty(videoFilePath))
return;
_Video = CBase.Video.Load(videoFilePath);
CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture
_VideoFading = new CFading(0f, 1f, 3f);
if (IsPlaying)
{
CBase.Video.Skip(_Video, Position, _Song.VideoGap);
CBase.Video.Resume(_Video);
}
}
}
}
+153
View File
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace VocaluxeLib.Utils.Player
{
public class CSoundPlayer
{
protected int _StreamID = -1;
protected float _Volume;
protected float _StartPosition;
protected float _FadeTime = CBase.Settings.GetSoundPlayerFadeTime();
public float Volume
{
set
{
_Volume = value;
_ApplyVolume();
}
get { return _Volume; }
}
public bool Loop;
public float Position
{
set {
if(_StreamID == -1)
return;
_StartPosition = value;
}
get {
if(_StreamID == -1)
return -1;
return CBase.Sound.GetPosition(_StreamID);
}
}
public float Length
{
get
{
if (_StreamID == -1)
return 0;
return CBase.Sound.GetLength(_StreamID);
}
}
public bool RepeatSong;
public bool IsPlaying { get; protected set; }
public bool IsFinished { get { return RepeatSong ? false : CBase.Sound.IsFinished(_StreamID); } }
public CSoundPlayer(bool loop = false)
{
Loop = loop;
}
public CSoundPlayer(string file, bool loop = false, float position = 0f, bool autoplay = false)
{
_StreamID = CBase.Sound.Load(file, false, true);
if(position > 0f)
Position = position;
Loop = loop;
if (autoplay)
Play();
}
public void Load(string file, float position = 0f, bool autoplay = false)
{
if (IsPlaying)
Stop();
_StreamID = CBase.Sound.Load(file, false, true);
if (position > 0f)
Position = position;
if (autoplay)
Play();
}
public void Play()
{
if (_StreamID == -1 || IsPlaying)
return;
CBase.Sound.SetPosition(_StreamID, _StartPosition);
CBase.Sound.SetStreamVolume(_StreamID, 0f);
CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
CBase.Sound.Play(_StreamID);
IsPlaying = true;
}
public void TogglePause()
{
if (_StreamID == -1)
return;
if(IsPlaying)
CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Pause);
else
{
CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
CBase.Sound.Play(_StreamID);
}
IsPlaying = !IsPlaying;
}
public void Stop()
{
if (_StreamID == -1 || !IsPlaying)
return;
CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Close);
_StreamID = -1;
IsPlaying = false;
}
public void Update()
{
if (_StreamID == -1 || !IsPlaying)
return;
float timeToPlay;
float len = CBase.Sound.GetLength(_StreamID);
timeToPlay = (len > 0f) ? len - CBase.Sound.GetPosition(_StreamID) : _FadeTime + 1f;
bool finished = CBase.Sound.IsFinished(_StreamID);
if (timeToPlay <= _FadeTime || finished)
{
if (RepeatSong)
{
//Set to false for restarting
IsPlaying = false;
Play();
}
else
Stop();
}
}
private void _ApplyVolume()
{
if (_StreamID == -1)
return;
CBase.Sound.SetStreamVolume(_StreamID, Volume);
}
}
}
+3
View File
@@ -77,6 +77,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CFading.cs" /> <Compile Include="CFading.cs" />
<Compile Include="CFont.cs" />
<Compile Include="Extensions.cs" /> <Compile Include="Extensions.cs" />
<Compile Include="GlobalSuppressions.cs" /> <Compile Include="GlobalSuppressions.cs" />
<Compile Include="IBasic.cs" /> <Compile Include="IBasic.cs" />
@@ -135,6 +136,8 @@
<Compile Include="PartyModes\IPartyMode.cs" /> <Compile Include="PartyModes\IPartyMode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\CWavFile.cs" /> <Compile Include="Utils\CWavFile.cs" />
<Compile Include="Utils\Player\CSongPlayer.cs" />
<Compile Include="Utils\Player\CSoundPlayer.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>