Moved CCursor
This commit is contained in:
1 parent
7f5cbbf686
commit
2ca2af6ea6
5 files changed
+143
-143
No files matched your search
@@ -136,16 +136,12 @@ namespace Vocaluxe.Base
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static SCoverTheme _CoverTheme(string coverThemeName)
|
private static SCoverTheme _CoverTheme(string coverThemeName)
|
||||||
{
|
{
|
||||||
SCoverTheme coverTheme = new SCoverTheme();
|
|
||||||
for (int i = 0; i < _CoverThemes.Count; i++)
|
for (int i = 0; i < _CoverThemes.Count; i++)
|
||||||
{
|
{
|
||||||
if (_CoverThemes[i].Name == coverThemeName)
|
if (_CoverThemes[i].Name == coverThemeName)
|
||||||
{
|
return _CoverThemes[i];
|
||||||
coverTheme = _CoverThemes[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return coverTheme;
|
return new SCoverTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -231,7 +227,7 @@ namespace Vocaluxe.Base
|
|||||||
if (_CoverExists(name))
|
if (_CoverExists(name))
|
||||||
continue;
|
continue;
|
||||||
// ReSharper disable AssignNullToNotNullAttribute
|
// 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
|
// ReSharper restore AssignNullToNotNullAttribute
|
||||||
|
|
||||||
_Cover.Add(sk);
|
_Cover.Add(sk);
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-134
@@ -24,144 +24,11 @@ using System.Drawing;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Vocaluxe.Base.Fonts;
|
using Vocaluxe.Base.Fonts;
|
||||||
using Vocaluxe.Screens;
|
using Vocaluxe.Screens;
|
||||||
using VocaluxeLib.Draw;
|
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
using VocaluxeLib.PartyModes;
|
using VocaluxeLib.PartyModes;
|
||||||
|
|
||||||
namespace Vocaluxe.Base
|
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
|
static class CGraphics
|
||||||
{
|
{
|
||||||
private static bool _Fading;
|
private static bool _Fading;
|
||||||
@@ -299,7 +166,7 @@ namespace Vocaluxe.Base
|
|||||||
public static bool UpdateGameLogic(CKeys keys, CMouse mouse)
|
public static bool UpdateGameLogic(CKeys keys, CMouse mouse)
|
||||||
{
|
{
|
||||||
bool run = true;
|
bool run = true;
|
||||||
_Cursor.CursorVisible = mouse.Visible;
|
_Cursor.Visible = mouse.Visible;
|
||||||
|
|
||||||
mouse.CopyEvents();
|
mouse.CopyEvents();
|
||||||
keys.CopyEvents();
|
keys.CopyEvents();
|
||||||
|
|||||||
@@ -735,8 +735,6 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
screen.Save(Path.Combine(path, file + i.ToString("00000") + ".bmp"), ImageFormat.Bmp);
|
screen.Save(Path.Combine(path, file + i.ToString("00000") + ".bmp"), ImageFormat.Bmp);
|
||||||
screen.Dispose();
|
screen.Dispose();
|
||||||
}
|
}
|
||||||
Cursor.Hide();
|
|
||||||
_Mouse.Visible = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -174,6 +174,7 @@
|
|||||||
<Compile Include="Base\CBackgroundMusic.cs" />
|
<Compile Include="Base\CBackgroundMusic.cs" />
|
||||||
<Compile Include="Base\CConfig.cs" />
|
<Compile Include="Base\CConfig.cs" />
|
||||||
<Compile Include="Base\CCover.cs" />
|
<Compile Include="Base\CCover.cs" />
|
||||||
|
<Compile Include="Base\CCursor.cs" />
|
||||||
<Compile Include="Base\CDataBase.cs" />
|
<Compile Include="Base\CDataBase.cs" />
|
||||||
<Compile Include="Base\CDraw.cs" />
|
<Compile Include="Base\CDraw.cs" />
|
||||||
<Compile Include="Base\Fonts\CFont.cs" />
|
<Compile Include="Base\Fonts\CFont.cs" />
|
||||||
|
|||||||
Reference in new issue
Block a user