From 2ca2af6ea64d91e7c82698bbf14b2788d474fae9 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 10 May 2013 14:36:23 +0200 Subject: [PATCH] Moved CCursor --- Vocaluxe/Base/CCover.cs | 10 +-- Vocaluxe/Base/CCursor.cs | 138 +++++++++++++++++++++++++++++++++ Vocaluxe/Base/CGraphics.cs | 135 +------------------------------- Vocaluxe/Lib/Draw/CDirect3D.cs | 2 - Vocaluxe/Vocaluxe.csproj | 1 + 5 files changed, 143 insertions(+), 143 deletions(-) create mode 100644 Vocaluxe/Base/CCursor.cs diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 2f99b82d..43abe8e8 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -136,16 +136,12 @@ namespace Vocaluxe.Base /// private static SCoverTheme _CoverTheme(string coverThemeName) { - SCoverTheme coverTheme = new SCoverTheme(); for (int i = 0; i < _CoverThemes.Count; i++) { if (_CoverThemes[i].Name == coverThemeName) - { - coverTheme = _CoverThemes[i]; - break; - } + return _CoverThemes[i]; } - return coverTheme; + return new SCoverTheme(); } /// @@ -231,7 +227,7 @@ namespace Vocaluxe.Base if (_CoverExists(name)) continue; // ReSharper disable AssignNullToNotNullAttribute - SCover sk = new SCover {Name = name, Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, Path.GetFileName(file)))}; + SCover sk = new SCover {Name = name, Texture = CDraw.AddTexture(file)}; // ReSharper restore AssignNullToNotNullAttribute _Cover.Add(sk); diff --git a/Vocaluxe/Base/CCursor.cs b/Vocaluxe/Base/CCursor.cs new file mode 100644 index 00000000..4a3b45d0 --- /dev/null +++ b/Vocaluxe/Base/CCursor.cs @@ -0,0 +1,138 @@ +using System; +using System.Diagnostics; +using VocaluxeLib.Draw; +using VocaluxeLib.Menu; + +namespace Vocaluxe.Base +{ + class CCursor + { + private readonly Stopwatch _CursorFadingTimer = new Stopwatch(); + private float _CursorTargetAlpha = 1f; + private float _CursorStartAlpha; + private float _CursorFadingTime = 0.5f; + private CTexture _Cursor; + + private readonly Stopwatch _Movetimer = new Stopwatch(); + + public bool ShowCursor = true; + public bool Visible = true; + + public int X + { + get { return (int)_Cursor.Rect.X; } + } + + public int Y + { + get { return (int)_Cursor.Rect.Y; } + } + + public bool IsActive + { + get { return _Movetimer.IsRunning; } + } + + public void Draw() + { + if (_Movetimer.IsRunning && _Movetimer.ElapsedMilliseconds / 1000f > CSettings.MouseMoveOffTime) + { + _Movetimer.Stop(); + _Fade(0f, 0.5f); + } + + + if (_CursorFadingTimer.IsRunning) + { + float t = _CursorFadingTimer.ElapsedMilliseconds / 1000f; + if (t < _CursorFadingTime) + { + if (_CursorTargetAlpha >= _CursorStartAlpha) + _Cursor.Color.A = _CursorStartAlpha + (_CursorTargetAlpha - _CursorStartAlpha) * t / _CursorFadingTime; + else + _Cursor.Color.A = (_CursorStartAlpha - _CursorTargetAlpha) * (1f - t / _CursorFadingTime); + } + else + { + _CursorFadingTimer.Stop(); + _Cursor.Color.A = _CursorTargetAlpha; + } + } + + if (Visible && (CSettings.GameState == EGameState.EditTheme || ShowCursor)) + CDraw.DrawTexture(_Cursor); + } + + public void UpdatePosition(int x, int y) + { + if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin || + Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin) + { + if (_CursorTargetAlpha < 0.01) + _Fade(1f, 0.2f); + + _Movetimer.Reset(); + _Movetimer.Start(); + CSettings.MouseActive(); + } + + _Cursor.Rect.X = x; + _Cursor.Rect.Y = y; + } + + public void LoadTextures() + { + _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(CTheme.Cursor.SkinName, -1)); + + _Cursor.Color = !String.IsNullOrEmpty(CTheme.Cursor.Color) + ? CTheme.GetColor(CTheme.Cursor.Color, -1) : new SColorF(CTheme.Cursor.R, CTheme.Cursor.G, CTheme.Cursor.B, CTheme.Cursor.A); + _Cursor.Rect.W = CTheme.Cursor.W; + _Cursor.Rect.H = CTheme.Cursor.H; + _Cursor.Rect.Z = CSettings.ZNear; + } + + public void UnloadTextures() + { + CDraw.RemoveTexture(ref _Cursor); + } + + public void ReloadTextures() + { + int x = X; + int y = Y; + UnloadTextures(); + LoadTextures(); + UpdatePosition(x, y); + } + + public void FadeOut() + { + _Movetimer.Stop(); + _Fade(0f, 0.5f); + } + + public void FadeIn() + { + _Movetimer.Reset(); + _Movetimer.Start(); + _Fade(1f, 0.2f); + } + + private void _Fade(float targetAlpha, float time) + { + _CursorFadingTimer.Stop(); + _CursorFadingTimer.Reset(); + + if (targetAlpha >= 0f && targetAlpha <= 1f) + _CursorTargetAlpha = targetAlpha; + else + _CursorTargetAlpha = 1f; + + if (time >= 0f) + _CursorFadingTime = time; + + _CursorStartAlpha = _Cursor.Color.A; + _CursorFadingTimer.Start(); + } + } +} \ No newline at end of file diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 7b2f3247..945d30e0 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -24,144 +24,11 @@ using System.Drawing; using System.Windows.Forms; using Vocaluxe.Base.Fonts; using Vocaluxe.Screens; -using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.PartyModes; namespace Vocaluxe.Base { - class CCursor - { - private readonly Stopwatch _CursorFadingTimer = new Stopwatch(); - private float _CursorTargetAlpha = 1f; - private float _CursorStartAlpha; - private float _CursorFadingTime = 0.5f; - private CTexture _Cursor; - - private readonly Stopwatch _Movetimer = new Stopwatch(); - - public bool ShowCursor = true; - public bool Visible = true; - public bool CursorVisible = true; - - public int X - { - get { return (int)_Cursor.Rect.X; } - } - - public int Y - { - get { return (int)_Cursor.Rect.Y; } - } - - public bool IsActive - { - get { return _Movetimer.IsRunning; } - } - - public void Draw() - { - if (_Movetimer.IsRunning && _Movetimer.ElapsedMilliseconds / 1000f > CSettings.MouseMoveOffTime) - { - _Movetimer.Stop(); - _Fade(0f, 0.5f); - } - - - if (_CursorFadingTimer.IsRunning) - { - float t = _CursorFadingTimer.ElapsedMilliseconds / 1000f; - if (t < _CursorFadingTime) - { - if (_CursorTargetAlpha >= _CursorStartAlpha) - _Cursor.Color.A = _CursorStartAlpha + (_CursorTargetAlpha - _CursorStartAlpha) * t / _CursorFadingTime; - else - _Cursor.Color.A = (_CursorStartAlpha - _CursorTargetAlpha) * (1f - t / _CursorFadingTime); - } - else - { - _CursorFadingTimer.Stop(); - _Cursor.Color.A = _CursorTargetAlpha; - } - } - - if (CursorVisible && (CSettings.GameState == EGameState.EditTheme || ShowCursor)) - CDraw.DrawTexture(_Cursor); - } - - public void UpdatePosition(int x, int y) - { - if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin || - Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin) - { - if (_CursorTargetAlpha < 0.01) - _Fade(1f, 0.2f); - - _Movetimer.Reset(); - _Movetimer.Start(); - CSettings.MouseActive(); - } - - _Cursor.Rect.X = x; - _Cursor.Rect.Y = y; - } - - public void LoadTextures() - { - _Cursor = CDraw.AddTexture(CTheme.GetSkinFilePath(CTheme.Cursor.SkinName, -1)); - - _Cursor.Color = !String.IsNullOrEmpty(CTheme.Cursor.Color) - ? CTheme.GetColor(CTheme.Cursor.Color, -1) : new SColorF(CTheme.Cursor.R, CTheme.Cursor.G, CTheme.Cursor.B, CTheme.Cursor.A); - _Cursor.Rect.W = CTheme.Cursor.W; - _Cursor.Rect.H = CTheme.Cursor.H; - _Cursor.Rect.Z = CSettings.ZNear; - } - - public void UnloadTextures() - { - CDraw.RemoveTexture(ref _Cursor); - } - - public void ReloadTextures() - { - int x = X; - int y = Y; - UnloadTextures(); - LoadTextures(); - UpdatePosition(x, y); - } - - public void FadeOut() - { - _Movetimer.Stop(); - _Fade(0f, 0.5f); - } - - public void FadeIn() - { - _Movetimer.Reset(); - _Movetimer.Start(); - _Fade(1f, 0.2f); - } - - private void _Fade(float targetAlpha, float time) - { - _CursorFadingTimer.Stop(); - _CursorFadingTimer.Reset(); - - if (targetAlpha >= 0f && targetAlpha <= 1f) - _CursorTargetAlpha = targetAlpha; - else - _CursorTargetAlpha = 1f; - - if (time >= 0f) - _CursorFadingTime = time; - - _CursorStartAlpha = _Cursor.Color.A; - _CursorFadingTimer.Start(); - } - } - static class CGraphics { private static bool _Fading; @@ -299,7 +166,7 @@ namespace Vocaluxe.Base public static bool UpdateGameLogic(CKeys keys, CMouse mouse) { bool run = true; - _Cursor.CursorVisible = mouse.Visible; + _Cursor.Visible = mouse.Visible; mouse.CopyEvents(); keys.CopyEvents(); diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 9d92cb2b..c3e0798f 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -735,8 +735,6 @@ namespace Vocaluxe.Lib.Draw screen.Save(Path.Combine(path, file + i.ToString("00000") + ".bmp"), ImageFormat.Bmp); screen.Dispose(); } - Cursor.Hide(); - _Mouse.Visible = true; } /// diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 53c2b29b..bd9bb9b2 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -174,6 +174,7 @@ +