From 8a638d8e9a11e3703e7ae7796626978a9bccb126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sat, 26 Oct 2013 14:36:26 +0200 Subject: [PATCH] Added new background-option: SlideShow. --- Vocaluxe/Base/CMain.cs | 10 ++++ Vocaluxe/Base/CSettings.cs | 3 ++ VocaluxeLib/IBasic.cs | 3 ++ VocaluxeLib/Menu/CBackground.cs | 87 ++++++++++++++++++++++++++++++++- 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index dbf75632..ff9f0f5d 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -233,6 +233,16 @@ namespace Vocaluxe.Base { return CSettings.DataPath; } + + public float GetSlideShowImageTime() + { + return CSettings.SlideShowImageTime; + } + + public float GetSlideShowFadeTime() + { + return CSettings.SlideShowFadeTime; + } } class CBtheme : ITheme diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 9fe7b69f..74f2ed94 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -142,6 +142,9 @@ namespace Vocaluxe.Base public const float BackgroundMusicFadeTime = 0.5f; public const float PauseResetTime = 1f; + public const float SlideShowImageTime = 3500f; + public const float SlideShowFadeTime = 500f; + public static readonly List MusicFileTypes = new List { "*.mp3", diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index b64e5e60..ac8ed878 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -86,6 +86,9 @@ namespace VocaluxeLib string GetFolderProfiles(); string GetDataPath(); + + float GetSlideShowImageTime(); + float GetSlideShowFadeTime(); } public interface ITheme diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 2e77ffc7..7d5a8e4f 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -18,6 +18,8 @@ using System; using System.Drawing; using System.Xml; +using System.Diagnostics; +using System.Collections.Generic; using VocaluxeLib.Draw; namespace VocaluxeLib.Menu @@ -27,6 +29,7 @@ namespace VocaluxeLib.Menu None, Color, Texture, + SlideShow, Video } @@ -36,6 +39,8 @@ namespace VocaluxeLib.Menu public EBackgroundTypes Type; + public List SlideShowTextures; + public string VideoName; public string TextureName; @@ -48,6 +53,10 @@ namespace VocaluxeLib.Menu private SThemeBackground _Theme; private bool _ThemeLoaded; + private int _SlideShowCurrent; + private Stopwatch _SlideShowTimer = new Stopwatch(); + private List _SlideShowTextures = new List(); + public SColorF Color; public string GetThemeName() @@ -92,6 +101,17 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= success; } + string slideShow = ""; + int i = 1; + _Theme.SlideShowTextures = new List(); + while (xmlReader.ItemExists(item + "/SlideShow" + i)) + { + xmlReader.GetValue(item + "/SlideShow" + i, out slideShow, String.Empty); + if (slideShow != "") + _Theme.SlideShowTextures.Add(slideShow); + i++; + } + if (_ThemeLoaded) { _Theme.Name = elementName; @@ -115,6 +135,12 @@ namespace VocaluxeLib.Menu writer.WriteComment(": Background Texture name"); writer.WriteElementString("Skin", _Theme.TextureName); + writer.WriteComment(": Texture name for slide-show"); + for (int i = 0; i < _Theme.SlideShowTextures.Count; i++) + { + writer.WriteElementString("SlideShow" + (i + 1), _Theme.SlideShowTextures[i]); + } + writer.WriteComment(": Background color for type \"Color\" from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.ColorName)) @@ -164,6 +190,11 @@ namespace VocaluxeLib.Menu ok = _DrawVideo(); } + if (_Theme.Type == EBackgroundTypes.SlideShow && _Theme.SlideShowTextures.Count > 0) + { + ok = _DrawSlideShow(); + } + if (!String.IsNullOrEmpty(_Theme.TextureName) && (_Theme.Type == EBackgroundTypes.Texture || (_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok)))) @@ -176,12 +207,15 @@ namespace VocaluxeLib.Menu return true; } - public void UnloadTextures() {} + public void UnloadTextures() { _SlideShowTextures.Clear(); } public void LoadTextures() { if (!String.IsNullOrEmpty(_Theme.ColorName)) Color = CBase.Theme.GetColor(_Theme.ColorName, _PartyModeID); + + foreach (string s in _Theme.SlideShowTextures) + _SlideShowTextures.Add(CBase.Theme.GetSkinTexture(s, _PartyModeID)); } public void ReloadTextures() @@ -214,6 +248,57 @@ namespace VocaluxeLib.Menu return false; } + private bool _DrawSlideShow() + { + if (_SlideShowTextures.Count > 0) + { + if (!_SlideShowTimer.IsRunning) + { + _SlideShowTimer.Start(); + _SlideShowCurrent = 0; + } + + CTexture texture = _SlideShowTextures[_SlideShowCurrent]; + + if (texture == null) + return false; + + var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); + RectangleF rect; + CHelper.SetRect(bounds, out rect, texture.OrigAspect, EAspect.Crop); + + CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4)); + + if (_SlideShowTimer.ElapsedMilliseconds >= (CBase.Settings.GetSlideShowFadeTime() + CBase.Settings.GetSlideShowImageTime())) + { + _SlideShowTimer.Restart(); + if (_SlideShowCurrent + 1 < _SlideShowTextures.Count) + _SlideShowCurrent++; + else if (_SlideShowCurrent != 0) + _SlideShowCurrent = 0; + } + else if (_SlideShowTimer.ElapsedMilliseconds >= CBase.Settings.GetSlideShowImageTime()) + { + if (_SlideShowCurrent + 1 < _SlideShowTextures.Count) + texture = _SlideShowTextures[_SlideShowCurrent + 1]; + else if (_SlideShowCurrent != 0) + texture = _SlideShowTextures[0]; + else + texture = null; + + if (texture != null) + { + float alpha = (_SlideShowTimer.ElapsedMilliseconds - CBase.Settings.GetSlideShowImageTime()) / CBase.Settings.GetSlideShowFadeTime(); + CHelper.SetRect(bounds, out rect, texture.OrigAspect, EAspect.Crop); + CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, (CBase.Settings.GetZFar() / 4) - 1), new SColorF(1,1,1, alpha)); + } + } + + return true; + } + return false; + } + private bool _DrawVideo() { CTexture videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID);