Merge remote-tracking branch 'upstream/release-0.1' into release-0.1

This commit is contained in:
Florian Kuepper committed 2012-03-17 17:30:06 +01:00
commit 863ecb9b07
22 files changed
+1203 -343

No files matched your search

+3 -5
View File
@@ -16,9 +16,7 @@
================================= =================================
= 1. About = = 1. About =
================================= =================================
Vocaluxe is a free and open source singing game. It allows up to three players (currently) to sing along with music using microphones in order to score points, depending on the pitch of the voice and the rhythm of singing. Vocaluxe is a free and open source singing game, inspired by the original UltraStar (developed by corvus5) and the great Ultrastar Deluxe project - yet it is an entirely new development in C#. It allows up to three players (currently) to sing along with music using microphones in order to score points, depending on the pitch of the voice and the rhythm of singing. It features mouse and keyboard navigation, a multi-language interface, and singer profiles with avatars and supports songs in CP1250/52 and UTF8 encodings.
Vocaluxe is an entirely new development in C#, inspired by the original UltraStar (developed by corvus5) and the great Ultrastar Deluxe project.
Supported Operating Systems / Requirements: Supported Operating Systems / Requirements:
- WinXP, Vista, Windows 7 with .NET 2.0 - WinXP, Vista, Windows 7 with .NET 2.0
@@ -28,9 +26,9 @@ Supported Operating Systems / Requirements:
================================= =================================
= 2. Download = = 2. Download =
================================= =================================
You can donwloadn precompiles Windows binaries at SourceForge: You can download precompiled Windows binaries at SourceForge:
Download: http://sourceforge.net/projects/vocaluxe/ http://sourceforge.net/projects/vocaluxe/
================================= =================================
+1 -1
View File
@@ -191,7 +191,7 @@ namespace Vocaluxe.Base
public static EPlaybackLib PlayBackLib = EPlaybackLib.PortAudio; public static EPlaybackLib PlayBackLib = EPlaybackLib.PortAudio;
public static ERecordLib RecordLib = ERecordLib.PortAudio; public static ERecordLib RecordLib = ERecordLib.PortAudio;
public static EBufferSize AudioBufferSize = EBufferSize.b2048; public static EBufferSize AudioBufferSize = EBufferSize.b2048;
public static int AudioLatency = 125; public static int AudioLatency = 0;
public static int BackgroundMusicVolume = 50; public static int BackgroundMusicVolume = 50;
public static EOffOn BackgroundMusic = EOffOn.TR_CONFIG_ON; public static EOffOn BackgroundMusic = EOffOn.TR_CONFIG_ON;
public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC;
+40 -17
View File
@@ -29,6 +29,9 @@ namespace Vocaluxe.Base
private static string _CoverFilePath; private static string _CoverFilePath;
private static string _CreditsRessourcesFilePath; private static string _CreditsRessourcesFilePath;
private static SQLiteConnection _ConnectionCover = null;
private static SQLiteTransaction _TransactionCover = null;
public static void Init() public static void Init()
{ {
_HighscoreFilePath = Path.Combine(System.Environment.CurrentDirectory, CSettings.sFileHighscoreDB); _HighscoreFilePath = Path.Combine(System.Environment.CurrentDirectory, CSettings.sFileHighscoreDB);
@@ -959,18 +962,15 @@ namespace Vocaluxe.Base
return false; return false;
} }
SQLiteConnection connection = new SQLiteConnection(); if (_ConnectionCover == null)
connection.ConnectionString = "Data Source=" + _CoverFilePath; {
_ConnectionCover = new SQLiteConnection();
_ConnectionCover.ConnectionString = "Data Source=" + _CoverFilePath;
_ConnectionCover.Open();
}
SQLiteCommand command; SQLiteCommand command;
try command = new SQLiteCommand(_ConnectionCover);
{
connection.Open();
}
catch (Exception)
{
return false;
}
command = new SQLiteCommand(connection);
command.CommandText = "SELECT id, width, height FROM Cover WHERE [Path] = @path"; command.CommandText = "SELECT id, width, height FROM Cover WHERE [Path] = @path";
command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath;
@@ -1008,7 +1008,7 @@ namespace Vocaluxe.Base
result = true; result = true;
reader.Read(); reader.Read();
byte[] data = GetBytes(reader); byte[] data = GetBytes(reader);
tex = CDraw.AddTexture(w, h, ref data); tex = CDraw.QuequeTexture(w, h, ref data);
} }
} }
else else
@@ -1016,6 +1016,11 @@ namespace Vocaluxe.Base
if (reader != null) if (reader != null)
reader.Close(); reader.Close();
if (_TransactionCover == null)
{
_TransactionCover = _ConnectionCover.BeginTransaction();
}
Bitmap origin; Bitmap origin;
try try
{ {
@@ -1032,8 +1037,6 @@ namespace Vocaluxe.Base
reader.Dispose(); reader.Dispose();
} }
command.Dispose(); command.Dispose();
connection.Close();
connection.Dispose();
return false; return false;
} }
@@ -1050,7 +1053,7 @@ namespace Vocaluxe.Base
Graphics g = Graphics.FromImage(bmp); Graphics g = Graphics.FromImage(bmp);
g.DrawImage(origin, new Rectangle(0, 0, w, h)); g.DrawImage(origin, new Rectangle(0, 0, w, h));
g.Dispose(); g.Dispose();
tex = CDraw.AddTexture(bmp);
byte[] data = new byte[w * h * 4]; byte[] data = new byte[w * h * 4];
BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
@@ -1058,6 +1061,8 @@ namespace Vocaluxe.Base
bmp.UnlockBits(bmp_data); bmp.UnlockBits(bmp_data);
bmp.Dispose(); bmp.Dispose();
tex = CDraw.QuequeTexture(w, h, ref data);
command.CommandText = "INSERT INTO Cover (Path, width, height) " + command.CommandText = "INSERT INTO Cover (Path, width, height) " +
"VALUES (@path, " + w.ToString() + ", " + h.ToString() + ")"; "VALUES (@path, " + w.ToString() + ", " + h.ToString() + ")";
command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath;
@@ -1094,12 +1099,30 @@ namespace Vocaluxe.Base
reader.Dispose(); reader.Dispose();
} }
command.Dispose(); command.Dispose();
connection.Close();
connection.Dispose();
return result; return result;
} }
public static void CommitCovers()
{
if (_TransactionCover != null)
{
_TransactionCover.Commit();
_TransactionCover = null;
}
}
public static void CloseConnections()
{
CommitCovers();
if (_ConnectionCover != null)
{
_ConnectionCover.Close();
_ConnectionCover = null;
}
}
private static bool InitCoverDB() private static bool InitCoverDB()
{ {
SQLiteConnection connection = new SQLiteConnection(); SQLiteConnection connection = new SQLiteConnection();
+4 -88
View File
@@ -12,8 +12,6 @@ namespace Vocaluxe.Base
{ {
static class CDraw static class CDraw
{ {
private static Object mutex = new object();
private static IDraw _Draw = null; private static IDraw _Draw = null;
public static void InitDraw() public static void InitDraw()
@@ -49,48 +47,31 @@ namespace Vocaluxe.Base
} }
public static int GetScreenWidth() public static int GetScreenWidth()
{
lock (mutex)
{ {
return _Draw.GetScreenWidth(); return _Draw.GetScreenWidth();
} }
}
public static int GetScreenHeight() public static int GetScreenHeight()
{
lock (mutex)
{ {
return _Draw.GetScreenHeight(); return _Draw.GetScreenHeight();
} }
}
public static RectangleF GetTextBounds(CText text) public static RectangleF GetTextBounds(CText text)
{
lock (mutex)
{ {
return _Draw.GetTextBounds(text); return _Draw.GetTextBounds(text);
} }
}
public static RectangleF GetTextBounds(CText text, float Height) public static RectangleF GetTextBounds(CText text, float Height)
{
lock (mutex)
{ {
return _Draw.GetTextBounds(text, Height); return _Draw.GetTextBounds(text, Height);
} }
}
public static void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) public static void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2)
{
lock (mutex)
{ {
_Draw.DrawLine(a, r, g, b, w, x1, y1, x2, y2); _Draw.DrawLine(a, r, g, b, w, x1, y1, x2, y2);
} }
}
public static void DrawRect(SColorF Color, SRectF Rect, float Thickness) public static void DrawRect(SColorF Color, SRectF Rect, float Thickness)
{
lock (mutex)
{ {
if (Thickness <= 0f) if (Thickness <= 0f)
return; return;
@@ -100,76 +81,49 @@ namespace Vocaluxe.Base
_Draw.DrawColor(Color, new SRectF(Rect.X - Thickness / 2, Rect.Y - Thickness / 2, Thickness, Rect.H + Thickness, Rect.Z)); _Draw.DrawColor(Color, new SRectF(Rect.X - Thickness / 2, Rect.Y - Thickness / 2, Thickness, Rect.H + Thickness, Rect.Z));
_Draw.DrawColor(Color, new SRectF(Rect.X + Rect.W - Thickness / 2, Rect.Y - Thickness / 2, Thickness, Rect.H + Thickness, Rect.Z)); _Draw.DrawColor(Color, new SRectF(Rect.X + Rect.W - Thickness / 2, Rect.Y - Thickness / 2, Thickness, Rect.H + Thickness, Rect.Z));
} }
}
public static void DrawColor(SColorF color, SRectF rect) public static void DrawColor(SColorF color, SRectF rect)
{
lock (mutex)
{ {
_Draw.DrawColor(color, rect); _Draw.DrawColor(color, rect);
} }
}
public static void ClearScreen() public static void ClearScreen()
{
lock (mutex)
{ {
_Draw.ClearScreen(); _Draw.ClearScreen();
} }
}
public static STexture CopyScreen() public static STexture CopyScreen()
{
lock (mutex)
{ {
return _Draw.CopyScreen(); return _Draw.CopyScreen();
} }
}
public static void CopyScreen(ref STexture Texture) public static void CopyScreen(ref STexture Texture)
{
lock (mutex)
{ {
_Draw.CopyScreen(ref Texture); _Draw.CopyScreen(ref Texture);
} }
}
public static void MakeScreenShot() public static void MakeScreenShot()
{
lock (mutex)
{ {
_Draw.MakeScreenShot(); _Draw.MakeScreenShot();
} }
}
// Draw Basic Text (must be deleted later) // Draw Basic Text (must be deleted later)
public static void DrawText(string Text, int x, int y, int h) public static void DrawText(string Text, int x, int y, int h)
{
lock (mutex)
{ {
_Draw.DrawText(Text, x, y, h); _Draw.DrawText(Text, x, y, h);
} }
}
public static STexture AddTexture(Bitmap Bitmap) public static STexture AddTexture(Bitmap Bitmap)
{
lock (mutex)
{ {
return _Draw.AddTexture(Bitmap); return _Draw.AddTexture(Bitmap);
} }
}
public static STexture AddTexture(string TexturePath) public static STexture AddTexture(string TexturePath)
{
lock (mutex)
{ {
return _Draw.AddTexture(TexturePath); return _Draw.AddTexture(TexturePath);
} }
}
public static STexture AddTexture(string TexturePath, int MaxSize) public static STexture AddTexture(string TexturePath, int MaxSize)
{
lock (mutex)
{ {
if (MaxSize == 0) if (MaxSize == 0)
return _Draw.AddTexture(TexturePath); return _Draw.AddTexture(TexturePath);
@@ -191,120 +145,82 @@ namespace Vocaluxe.Base
bmp.Dispose(); bmp.Dispose();
return tex; return tex;
} }
}
public static STexture AddTexture(int W, int H, IntPtr Data) public static STexture AddTexture(int W, int H, IntPtr Data)
{
lock (mutex)
{ {
return _Draw.AddTexture(W, H, Data); return _Draw.AddTexture(W, H, Data);
} }
}
public static STexture AddTexture(int W, int H, ref byte[] Data) public static STexture AddTexture(int W, int H, ref byte[] Data)
{
lock (mutex)
{ {
return _Draw.AddTexture(W, H, ref Data); return _Draw.AddTexture(W, H, ref Data);
} }
public static STexture QuequeTexture(int W, int H, ref byte[] Data)
{
return _Draw.QuequeTexture(W, H, ref Data);
} }
public static bool UpdateTexture(ref STexture Texture, ref byte[] Data) public static bool UpdateTexture(ref STexture Texture, ref byte[] Data)
{
lock (mutex)
{ {
return _Draw.UpdateTexture(ref Texture, ref Data); return _Draw.UpdateTexture(ref Texture, ref Data);
} }
}
public static bool UpdateTexture(ref STexture Texture, IntPtr Data) public static bool UpdateTexture(ref STexture Texture, IntPtr Data)
{
lock (mutex)
{ {
return _Draw.UpdateTexture(ref Texture, Data); return _Draw.UpdateTexture(ref Texture, Data);
} }
}
public static void RemoveTexture(ref STexture Texture) public static void RemoveTexture(ref STexture Texture)
{
lock (mutex)
{ {
_Draw.RemoveTexture(ref Texture); _Draw.RemoveTexture(ref Texture);
} }
}
public static void DrawTexture(STexture Texture) public static void DrawTexture(STexture Texture)
{
lock (mutex)
{ {
_Draw.DrawTexture(Texture); _Draw.DrawTexture(Texture);
} }
}
public static void DrawTexture(STexture Texture, SRectF rect) public static void DrawTexture(STexture Texture, SRectF rect)
{
lock (mutex)
{ {
_Draw.DrawTexture(Texture, rect); _Draw.DrawTexture(Texture, rect);
} }
}
public static void DrawTexture(STexture Texture, SRectF rect, SColorF color) public static void DrawTexture(STexture Texture, SRectF rect, SColorF color)
{
lock (mutex)
{ {
_Draw.DrawTexture(Texture, rect, color); _Draw.DrawTexture(Texture, rect, color);
} }
}
public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds) public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds)
{
lock (mutex)
{ {
_Draw.DrawTexture(Texture, rect, color, bounds); _Draw.DrawTexture(Texture, rect, color, bounds);
} }
}
public static void DrawTexture(STexture Texture, SRectF rect, SColorF color,bool mirrored) public static void DrawTexture(STexture Texture, SRectF rect, SColorF color,bool mirrored)
{
lock (mutex)
{ {
_Draw.DrawTexture(Texture, rect, color, mirrored); _Draw.DrawTexture(Texture, rect, color, mirrored);
} }
}
public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored) public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored)
{
lock (mutex)
{ {
_Draw.DrawTexture(Texture, rect, color, bounds, mirrored); _Draw.DrawTexture(Texture, rect, color, bounds, mirrored);
} }
}
public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end) public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end)
{
lock (mutex)
{ {
_Draw.DrawTexture(Texture, rect, color, begin, end); _Draw.DrawTexture(Texture, rect, color, begin, end);
} }
}
public static void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) public static void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height)
{
lock (mutex)
{ {
_Draw.DrawTextureReflection(Texture, rect, color, bounds, space, height); _Draw.DrawTextureReflection(Texture, rect, color, bounds, space, height);
} }
}
public static int TextureCount() public static int TextureCount()
{
lock (mutex)
{ {
return _Draw.TextureCount(); return _Draw.TextureCount();
} }
} }
}
enum EParticeType enum EParticeType
{ {
+14 -2
View File
@@ -12,6 +12,7 @@ using System.Xml;
using System.Xml.XPath; using System.Xml.XPath;
using Vocaluxe.Lib.Draw; using Vocaluxe.Lib.Draw;
using Vocaluxe.Menu;
namespace Vocaluxe.Base namespace Vocaluxe.Base
{ {
@@ -32,7 +33,7 @@ namespace Vocaluxe.Base
class CGlyph class CGlyph
{ {
public readonly float SIZEh = 100f; public readonly float SIZEh = 50f;
public STexture Texture; public STexture Texture;
public char Chr; public char Chr;
public int width; public int width;
@@ -133,7 +134,7 @@ namespace Vocaluxe.Base
sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
//size = g.MeasureString(chr.ToString(), fo); //size = g.MeasureString(chr.ToString(), fo);
float h_style = sizeB.Height; float h_style = sizeB.Height;
g.Dispose();
return h_normal / h_style; return h_normal / h_style;
} }
} }
@@ -552,6 +553,17 @@ namespace Vocaluxe.Base
} }
} }
public static RectangleF GetTextBounds(CText text)
{
return GetTextBounds(text, text.Height);
}
public static RectangleF GetTextBounds(CText text, float height)
{
Height = height;
return new RectangleF(text.X, text.Y, GetTextWidth(CLanguage.Translate(text.Text)), GetTextHeight(CLanguage.Translate(text.Text)));
}
public static float GetTextWidth(string text) public static float GetTextWidth(string text)
{ {
float dx = 0; float dx = 0;
+1 -1
View File
@@ -47,7 +47,7 @@ namespace Vocaluxe.Base
public const int iVersionSub = 0; // steps public const int iVersionSub = 0; // steps
public const ERevision VersionRevision = ERevision.Beta; public const ERevision VersionRevision = ERevision.Beta;
public const int iBuild = 54; // Increase on every published version! Never Reset! public const int iBuild = 55; // Increase on every published version! Never Reset!
public const int iDatabaseHighscoreVersion = 1; public const int iDatabaseHighscoreVersion = 1;
public const int iDatabaseCoverVersion = 1; public const int iDatabaseCoverVersion = 1;
+34 -12
View File
@@ -826,11 +826,32 @@ namespace Vocaluxe.Base
CLog.StopBenchmark(2, "Sort Songs"); CLog.StopBenchmark(2, "Sort Songs");
Category = -1; Category = -1;
_SongsLoaded = true; _SongsLoaded = true;
if (CConfig.Renderer != ERenderer.TR_CONFIG_SOFTWARE && CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
{
CLog.StartBenchmark(2, "Load Cover");
for (int i = 0; i < _Songs.Count; i++)
{
CSong song = _Songs[i];
song.ReadNotes();
STexture texture = song.CoverTextureSmall;
song.CoverTextureBig = texture;
_CoverLoadIndex++;
}
_CoverLoaded = true;
CDataBase.CommitCovers();
CLog.StopBenchmark(2, "Load Cover");
}
CLog.StopBenchmark(1, "Load Songs "); CLog.StopBenchmark(1, "Load Songs ");
} }
public static void LoadCover(long WaitTime) public static void LoadCover(long WaitTime, int NumLoads)
{ {
if (CConfig.Renderer != ERenderer.TR_CONFIG_SOFTWARE)
return; //should be removed as soon as the other renderer are ready for queque
if (!SongsLoaded) if (!SongsLoaded)
return; return;
@@ -845,23 +866,23 @@ namespace Vocaluxe.Base
STexture texture = new STexture(-1); STexture texture = new STexture(-1);
if (_CoverLoadTimer.ElapsedMilliseconds >= WaitTime) if (_CoverLoadTimer.ElapsedMilliseconds >= WaitTime)
{
for (int i = 0; i < NumLoads; i++)
{ {
CSong song = new CSong(); CSong song = new CSong();
int i = GetNextSongWithoutCover(ref song); int n = GetNextSongWithoutCover(ref song);
if (i < 0) if (n < 0)
return; return;
song.ReadNotes(); song.ReadNotes();
if (song.CoverFileName != String.Empty) texture = song.CoverTextureSmall;
{
if (!CDataBase.GetCover(Path.Combine(song.Folder, song.CoverFileName), ref texture, CConfig.CoverSize)) SetCoverSmall(n, texture);
texture = CCover.NoCover; SetCoverBig(n, texture);
}
else if (CoverLoaded)
texture = CCover.NoCover; CDataBase.CommitCovers();
SetCoverSmall(i, texture);
SetCoverBig(i, texture);
_CoverLoadTimer.Reset(); _CoverLoadTimer.Reset();
_CoverLoadTimer.Start(); _CoverLoadTimer.Start();
@@ -869,3 +890,4 @@ namespace Vocaluxe.Base
} }
} }
} }
}
+3 -3
View File
@@ -501,7 +501,7 @@ namespace Vocaluxe.Base
long ticks = _Timer.ElapsedTicks; long ticks = _Timer.ElapsedTicks;
float dt = _Timer.ElapsedMilliseconds / 1000f; float dt = _Timer.ElapsedMilliseconds / 1000f;
if (Stopwatch.IsHighResolution) if (Stopwatch.IsHighResolution && ticks != 0)
dt = (float)(ticks * nanosecPerTick / 1000000000.0); dt = (float)(ticks * nanosecPerTick / 1000000000.0);
return _SetValue + dt; return _SetValue + dt;
@@ -581,7 +581,7 @@ namespace Vocaluxe.Base
long ticks = _STimer.ElapsedTicks; long ticks = _STimer.ElapsedTicks;
float dt = _STimer.ElapsedMilliseconds / 1000f; float dt = _STimer.ElapsedMilliseconds / 1000f;
if (Stopwatch.IsHighResolution) if (Stopwatch.IsHighResolution && ticks != 0)
dt = (float)(ticks * nanosecPerTick / 1000000000.0); dt = (float)(ticks * nanosecPerTick / 1000000000.0);
return _CurrentTime + dt; return _CurrentTime + dt;
@@ -617,7 +617,7 @@ namespace Vocaluxe.Base
long ticks = _STimer.ElapsedTicks; long ticks = _STimer.ElapsedTicks;
float dt = _STimer.ElapsedMilliseconds / 1000f; float dt = _STimer.ElapsedMilliseconds / 1000f;
if (Stopwatch.IsHighResolution) if (Stopwatch.IsHighResolution && ticks != 0)
dt = (float)(ticks * nanosecPerTick / 1000000000.0); dt = (float)(ticks * nanosecPerTick / 1000000000.0);
float Ts = 0f; float Ts = 0f;
+3 -2
View File
@@ -147,8 +147,9 @@ namespace Vocaluxe.Base
{ {
if (_Stopwatch.IsRunning) if (_Stopwatch.IsRunning)
{ {
if (Stopwatch.IsHighResolution) long ticks = _Stopwatch.ElapsedTicks;
return (float)(((double)nanosecPerTick * (double)_Stopwatch.ElapsedTicks) / (1000.0 * 1000.0)); if (Stopwatch.IsHighResolution && ticks != 0)
return (float)(((double)nanosecPerTick * (double)ticks) / (1000.0 * 1000.0));
else else
return (float)_Stopwatch.ElapsedMilliseconds; return (float)_Stopwatch.ElapsedMilliseconds;
} }
+462 -36
View File
@@ -36,6 +36,9 @@ namespace Vocaluxe.Lib.Draw
private List<STexture> _Textures; private List<STexture> _Textures;
private List<Texture> _D3DTextures; private List<Texture> _D3DTextures;
private List<STextureQueque> _Queque;
private Object MutexTexture = new Object();
private VertexBuffer _VertexBuffer; private VertexBuffer _VertexBuffer;
@@ -46,14 +49,20 @@ namespace Vocaluxe.Lib.Draw
private Bitmap blankMap; private Bitmap blankMap;
private STexture blankTexture; private STexture blankTexture;
private Texture transparentTexture;
#endregion private vars #endregion private vars
/// <summary>
/// Creates a new Instance of the CDirect3D Class
/// </summary>
public CDirect3D() public CDirect3D()
{ {
this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon));
_Textures = new List<STexture>(); _Textures = new List<STexture>();
_D3DTextures = new List<Texture>(); _D3DTextures = new List<Texture>();
_Queque = new List<STextureQueque>();
_Keys = new CKeys(); _Keys = new CKeys();
_D3D = new Direct3D(); _D3D = new Direct3D();
@@ -86,6 +95,8 @@ namespace Vocaluxe.Lib.Draw
_PresentParameters.Multisample = MultisampleType.None; _PresentParameters.Multisample = MultisampleType.None;
_PresentParameters.MultisampleQuality = 0; _PresentParameters.MultisampleQuality = 0;
//Apply antialiasing and check if antialiasing mode is supported
#region Antialiasing
int quality = 0; int quality = 0;
if (CConfig.AAMode == EAntiAliasingModes.x0) if (CConfig.AAMode == EAntiAliasingModes.x0)
{ {
@@ -132,12 +143,15 @@ namespace Vocaluxe.Lib.Draw
else else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
} }
#endregion Antialiasing
//Apply the VSync configuration
if (CConfig.VSync == EOffOn.TR_CONFIG_ON) if (CConfig.VSync == EOffOn.TR_CONFIG_ON)
_PresentParameters.PresentationInterval = PresentInterval.Default; _PresentParameters.PresentationInterval = PresentInterval.Default;
else else
_PresentParameters.PresentationInterval = PresentInterval.Immediate; _PresentParameters.PresentationInterval = PresentInterval.Immediate;
//GMA 950 graphics devices can only process vertices in software mode
Capabilities caps = _D3D.GetDeviceCaps(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware); Capabilities caps = _D3D.GetDeviceCaps(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware);
CreateFlags flags = CreateFlags.None; CreateFlags flags = CreateFlags.None;
if ((caps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) if ((caps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0)
@@ -148,13 +162,15 @@ namespace Vocaluxe.Lib.Draw
this.CenterToScreen(); this.CenterToScreen();
blankMap = new Bitmap(1, 1); //Quick and Dirty, used for DrawColor //This creates a new white texture and adds it to the texture pool
//This texture is used for the DrawRect method
blankMap = new Bitmap(1, 1);
Graphics g = Graphics.FromImage(blankMap); Graphics g = Graphics.FromImage(blankMap);
g.Clear(Color.White); g.Clear(Color.White);
g.Dispose(); g.Dispose();
blankTexture = AddTexture(blankMap); blankTexture = AddTexture(blankMap);
h = ClientSize.Height;
w = ClientSize.Width; transparentTexture = new Texture(_Device, 1, 1, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);
blankMap.Dispose(); blankMap.Dispose();
} }
@@ -186,9 +202,12 @@ namespace Vocaluxe.Lib.Draw
RResize(); RResize();
} }
#endregion form events #endregion form events
/// <summary>
/// Resizes the viewport
/// </summary>
private void RResize() private void RResize()
{ {
// The window was minimized, so restore it to the last known size
if (ClientSize.Width == 0 || ClientSize.Height == 0) if (ClientSize.Width == 0 || ClientSize.Height == 0)
{ {
ClientSize = _SizeBeforeMinimize; ClientSize = _SizeBeforeMinimize;
@@ -202,28 +221,41 @@ namespace Vocaluxe.Lib.Draw
if ((float)w / (float)h > CSettings.GetRenderAspect()) if ((float)w / (float)h > CSettings.GetRenderAspect())
{ {
//The windows's width is too big
w = (int)Math.Round((float)h * CSettings.GetRenderAspect()); w = (int)Math.Round((float)h * CSettings.GetRenderAspect());
x = (ClientSize.Width - w) / 2; x = (ClientSize.Width - w) / 2;
} }
else else
{ {
//The windows's height is too big
h = (int)Math.Round((float)w / CSettings.GetRenderAspect()); h = (int)Math.Round((float)w / CSettings.GetRenderAspect());
y = (ClientSize.Height - h) / 2; y = (ClientSize.Height - h) / 2;
} }
//Apply the new sizes to the PresentParameters
_PresentParameters.BackBufferWidth = ClientSize.Width; _PresentParameters.BackBufferWidth = ClientSize.Width;
_PresentParameters.BackBufferHeight = ClientSize.Height; _PresentParameters.BackBufferHeight = ClientSize.Height;
ClearScreen(); ClearScreen();
//To set new PresentParameters the device has to be resetted
Reset(); Reset();
//All configurations got flushed due to Reset(), so apply them again
Init(); Init();
//Set the new Viewport
_Device.Viewport = new Viewport(x, y, w, h); _Device.Viewport = new Viewport(x, y, w, h);
//Store size so it can get restored after the window gets minimized
_SizeBeforeMinimize = ClientSize; _SizeBeforeMinimize = ClientSize;
} }
} }
/// <summary>
/// Triggers the Fullscreen mode
/// </summary>
private void EnterFullScreen() private void EnterFullScreen()
{ {
//This currently not using real fullscreen mode but a borderless window
//Real fullscreen could be gained setting _PresentParameters.Windowed = true
//And calling Reset() and Init() after
_OldSize = this.ClientSize; _OldSize = this.ClientSize;
this.ClientSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); this.ClientSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
this.FormBorderStyle = FormBorderStyle.None; this.FormBorderStyle = FormBorderStyle.None;
@@ -237,7 +269,9 @@ namespace Vocaluxe.Lib.Draw
CConfig.SaveConfig(); CConfig.SaveConfig();
} }
/// <summary>
/// Triggers the windowed mode
/// </summary>
private void LeaveFullScreen() private void LeaveFullScreen()
{ {
this.ClientSize = _OldSize; this.ClientSize = _OldSize;
@@ -312,7 +346,13 @@ namespace Vocaluxe.Lib.Draw
#region implementation #region implementation
/// <summary>
/// Inits the Device
/// </summary>
/// <returns>True if it succeeded else false</returns>
public bool Init() public bool Init()
{
if (!_Device.Disposed)
{ {
this.Text = CSettings.GetFullVersionText(); this.Text = CSettings.GetFullVersionText();
Matrix translate = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); Matrix translate = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0));
@@ -339,7 +379,12 @@ namespace Vocaluxe.Lib.Draw
_Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate); _Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate);
return true; return true;
} }
else
return false;
}
/// <summary>
/// Starts the rendering
/// </summary>
public void MainLoop() public void MainLoop()
{ {
_Run = true; _Run = true;
@@ -358,23 +403,33 @@ namespace Vocaluxe.Lib.Draw
if (_Run) if (_Run)
{ {
//Clear the previous Frame
ClearScreen(); ClearScreen();
//We want to begin drawing
_Device.BeginScene(); _Device.BeginScene();
CheckQueque();
_Run = _Run && CGraphics.Draw(); _Run = _Run && CGraphics.Draw();
_Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); //We finished drawing the frame
_Device.EndScene(); _Device.EndScene();
_Run = CGraphics.UpdateGameLogic(_Keys, _Mouse);
try try
{ {
//Now push the frame to the Viewport
_Device.Present(); _Device.Present();
} }
catch (Direct3D9Exception) catch (Direct3D9Exception)
{ {
if (_Device.TestCooperativeLevel() == ResultCode.DeviceNotReset) //Do only reset when the device in a resetable state! //In Direct3D devices can get lost.
//This happens for example when opening the Task Manager in Vista/Windows 7 or if a UAC message is opening
//We need to reset the device to get it to workable state again
//After a reset Init() needs to be called because all data in the Direct3D default pool are lost and need to be recreated
if (_Device.TestCooperativeLevel() == ResultCode.DeviceNotReset)
{ {
Reset(); Reset();
Init(); Init();
} }
} }
//Apply fullscreen mode
if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen)) if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen))
{ {
if (!_fullscreen) if (!_fullscreen)
@@ -387,7 +442,7 @@ namespace Vocaluxe.Lib.Draw
if (delay >= 1) if (delay >= 1)
System.Threading.Thread.Sleep(delay); System.Threading.Thread.Sleep(delay);
//Calculate the FPS Rate and restart the timer after a frame
CTime.CalculateFPS(); CTime.CalculateFPS();
CTime.Restart(); CTime.Restart();
} }
@@ -396,19 +451,28 @@ namespace Vocaluxe.Lib.Draw
} }
} }
/// <summary>
/// Resets the device, all objects in the Direct3D default pool get flushed and need to be recreated
/// </summary>
public void Reset() public void Reset()
{ {
//Dispose all objects in the default pool, those need to be recreated
TexturedColoredVertex.GetDeclaration(_Device).Dispose(); TexturedColoredVertex.GetDeclaration(_Device).Dispose();
_VertexBuffer.Dispose(); _VertexBuffer.Dispose();
_Device.Reset(_PresentParameters); _Device.Reset(_PresentParameters);
} }
/// <summary>
/// Unloads all Textures and other objects used by Direct3D for rendering
/// </summary>
/// <returns></returns>
public bool Unload() public bool Unload()
{ {
//Dispose all textures
for (int i = 0; i < _D3DTextures.Count; i++) for (int i = 0; i < _D3DTextures.Count; i++)
{ {
if(_D3DTextures[i] != null)
_D3DTextures[i].Dispose(); _D3DTextures[i].Dispose();
} }
TexturedColoredVertex.GetDeclaration(_Device).Dispose(); TexturedColoredVertex.GetDeclaration(_Device).Dispose();
_VertexBuffer.Dispose(); _VertexBuffer.Dispose();
@@ -417,46 +481,82 @@ namespace Vocaluxe.Lib.Draw
return true; return true;
} }
/// <summary>
/// Gets the current viewport width
/// </summary>
/// <returns>The current viewport width</returns>
public int GetScreenWidth() public int GetScreenWidth()
{ {
return _Device.Viewport.Width; return _Device.Viewport.Width;
} }
/// <summary>
/// Gets the current viewport height
/// </summary>
/// <returns>The current viewport height</returns>
public int GetScreenHeight() public int GetScreenHeight()
{ {
return _Device.Viewport.Height; return _Device.Viewport.Height;
} }
/// <summary>
/// Calculates the bounds for a CText object
/// </summary>
/// <param name="text">The CText object of which the bounds should be calculated for</param>
/// <returns>RectangleF object containing the bounds</returns>
public RectangleF GetTextBounds(CText text) public RectangleF GetTextBounds(CText text)
{ {
return GetTextBounds(text, text.Height); return GetTextBounds(text, text.Height);
} }
/// <summary>
/// Calculates the bounds for a CText object
/// </summary>
/// <param name="text">The CText object of which the bounds should be calculated for</param>
/// <param name="Height">The height of the CText object</param>
/// <returns>RectangleF object containing the bounds</returns>
public RectangleF GetTextBounds(CText text, float Height) public RectangleF GetTextBounds(CText text, float Height)
{ {
CFonts.Height = Height; CFonts.Height = Height;
CFonts.SetFont(text.Fon); CFonts.SetFont(text.Fon);
CFonts.Style = text.Style; CFonts.Style = text.Style;
return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(text.Text)); return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text)));
} }
#region Basic Draw Methods #region Basic Draw Methods
/// <summary>
/// Removes all textures from the screen
/// </summary>
public void ClearScreen() public void ClearScreen()
{ {
_Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); _Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
} }
/// <summary>
/// Not implemented yet
/// </summary>
/// <returns></returns>
public STexture CopyScreen() public STexture CopyScreen()
{ {
//FIXME
STexture texture = new STexture(-1); STexture texture = new STexture(-1);
return texture; return texture;
} }
/// <summary>
/// Not implemented yet
/// </summary>
/// <returns></returns>
public void CopyScreen(ref STexture Texture) public void CopyScreen(ref STexture Texture)
{ {
//FIXME
return; return;
} }
/// <summary>
/// Creates a Screenshot of the current frame
/// </summary>
public void MakeScreenShot() public void MakeScreenShot()
{ {
string file = "Screenshot_"; string file = "Screenshot_";
@@ -466,6 +566,7 @@ namespace Vocaluxe.Lib.Draw
while (File.Exists(Path.Combine(path, file + i.ToString("00000") + ".bmp"))) while (File.Exists(Path.Combine(path, file + i.ToString("00000") + ".bmp")))
i++; i++;
//create a surface of the frame
using (Surface surface = _Device.GetBackBuffer(0, 0)) using (Surface surface = _Device.GetBackBuffer(0, 0))
{ {
Bitmap screen = new Bitmap(Surface.ToStream(surface, ImageFileFormat.Bmp)); Bitmap screen = new Bitmap(Surface.ToStream(surface, ImageFileFormat.Bmp));
@@ -476,29 +577,74 @@ namespace Vocaluxe.Lib.Draw
_Mouse.Visible = true; _Mouse.Visible = true;
} }
/// <summary>
/// Draws a line
/// </summary>
/// <param name="a">The alpha value from 0-255</param>
/// <param name="r">The red value from 0-255</param>
/// <param name="g">The red value from 0-255</param>
/// <param name="b">The red value from 0-255</param>
/// <param name="w">The width of the line</param>
/// <param name="x1">The start x-value</param>
/// <param name="y1">The start y-value</param>
/// <param name="x2">The end x-value</param>
/// <param name="y2">The end y-value</param>
public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2)
{ {
SColorF color = new SColorF(a / 255, g / 255, b / 255, a / 255); SColorF color = new SColorF(a / 255, g / 255, b / 255, a / 255);
DrawTexture(blankTexture, new SRectF(x1, y1, x2, y2, 1), color); DrawTexture(blankTexture, new SRectF(x1, y1, x2, y2, 1), color);
} }
/// <summary>
/// Draws a text string
/// </summary>
/// <param name="Text">The text to be drawn</param>
/// <param name="x">The text's x-position</param>
/// <param name="y">The text's y-position</param>
/// <param name="h">The text's height</param>
public void DrawText(string Text, int x, int y, int h) public void DrawText(string Text, int x, int y, int h)
{ {
DrawText(Text, x, y, h, 0f); DrawText(Text, x, y, h, 0f);
} }
/// <summary>
/// Draws a text string
/// </summary>
/// <param name="Text">The text to be drawn</param>
/// <param name="x">The text's x-position</param>
/// <param name="y">The text's y-position</param>
/// <param name="h">The text's height</param>
/// <param name="z">The text's x-position</param>
public void DrawText(string Text, int x, int y, float h, float z) public void DrawText(string Text, int x, int y, float h, float z)
{ {
CFonts.DrawText(Text, h, x, y, z, new SColorF(1f, 1f, 1f, 1f)); CFonts.DrawText(Text, h, x, y, z, new SColorF(1f, 1f, 1f, 1f));
} }
/// <summary>
/// Draws a colored rectangle
/// </summary>
/// <param name="color">The color in which the rectangle will be drawn in</param>
/// <param name="rect">The coordinates in a SRectF struct</param>
public void DrawColor(SColorF color, SRectF rect) public void DrawColor(SColorF color, SRectF rect)
{ {
//blankMap = new Bitmap(1, 1);
//Graphics g = Graphics.FromImage(blankMap);
//g.Clear(Color.White);
//g.Dispose();
//blankTexture = AddTexture(blankMap);
//blankMap.Dispose();
DrawTexture(blankTexture, rect, color); DrawTexture(blankTexture, rect, color);
//RemoveTexture(ref blankTexture);
} }
#endregion Basic Draw Methods #endregion Basic Draw Methods
#region Textures #region Textures
/// <summary>
/// Adds a texture and stores it in the VRam
/// </summary>
/// <param name="TexturePath">The texture's filepath</param>
/// <returns>A STexture object containing the added texture</returns>
public STexture AddTexture(string TexturePath) public STexture AddTexture(string TexturePath)
{ {
if (System.IO.File.Exists(TexturePath)) if (System.IO.File.Exists(TexturePath))
@@ -519,18 +665,30 @@ namespace Vocaluxe.Lib.Draw
return new STexture(-1); return new STexture(-1);
} }
/// <summary>
/// Calculates the next power of two
/// </summary>
/// <param name="n">The value of which the next power of two will be calculated</param>
/// <returns>The next power of two</returns>
private static float NextPowerOfTwo(float n) private static float NextPowerOfTwo(float n)
{ {
if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive.");
return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2)));
} }
/// <summary>
/// Adds a texture and stores it in the Vram
/// </summary>
/// <param name="bmp">The Bitmap of which the texute will be created from</param>
/// <param name="TexturePath">The path to the texture</param>
/// <returns>A STexture object containing the added texture</returns>
public STexture AddTexture(Bitmap bmp, string TexturePath) public STexture AddTexture(Bitmap bmp, string TexturePath)
{ {
STexture texture = new STexture(-1); STexture texture = new STexture(-1);
if (bmp.Height == 0 || bmp.Width == 0) if (bmp.Height == 0 || bmp.Width == 0)
return texture; return texture;
int MaxSize; int MaxSize;
//Apply the right max size
switch (CConfig.TextureQuality) switch (CConfig.TextureQuality)
{ {
case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST: case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST:
@@ -571,10 +729,13 @@ namespace Vocaluxe.Lib.Draw
texture.width = w; texture.width = w;
texture.height = h; texture.height = h;
//Older graphics card can only handle textures with sizes being powers of two
texture.w2 = (float)NextPowerOfTwo(w); texture.w2 = (float)NextPowerOfTwo(w);
texture.h2 = (float)NextPowerOfTwo(h); texture.h2 = (float)NextPowerOfTwo(h);
//Create a new Bitmap with the new sizes
Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2); Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2);
//Scale the texture
Graphics g = Graphics.FromImage(bmp2); Graphics g = Graphics.FromImage(bmp2);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
@@ -584,12 +745,16 @@ namespace Vocaluxe.Lib.Draw
texture.width_ratio = 1f; texture.width_ratio = 1f;
texture.height_ratio = 1f; texture.height_ratio = 1f;
//Fill the new Bitmap with the texture data
BitmapData bmp_data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData bmp_data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
byte[] Data = new byte[4 * bmp2.Width * bmp2.Height]; byte[] Data = new byte[4 * bmp2.Width * bmp2.Height];
Marshal.Copy(bmp_data.Scan0, Data, 0, Data.Length); Marshal.Copy(bmp_data.Scan0, Data, 0, Data.Length);
bmp2.UnlockBits(bmp_data); bmp2.UnlockBits(bmp_data);
//Create a new texture in the managed pool, which does not need to be recreated on a lost device
//because a copy of the texture is hold in the Ram
Texture t = new Texture(_Device, (int)texture.w2, (int)texture.h2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); Texture t = new Texture(_Device, (int)texture.w2, (int)texture.h2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed);
//Lock the texture and fill it with the data
DataRectangle rect = t.LockRectangle(0, LockFlags.None); DataRectangle rect = t.LockRectangle(0, LockFlags.None);
for (int i = 0; i < Data.Length; ) for (int i = 0; i < Data.Length; )
{ {
@@ -599,20 +764,29 @@ namespace Vocaluxe.Lib.Draw
rect.Data.Position += rect.Pitch; rect.Data.Position += rect.Pitch;
} }
t.UnlockRectangle(0); t.UnlockRectangle(0);
_D3DTextures.Add(t);
bmp2.Dispose(); bmp2.Dispose();
bmp_data = null; bmp_data = null;
// Add to Texture List // Add to Texture List
texture.index = _D3DTextures.Count - 1;
texture.color = new SColorF(1f, 1f, 1f, 1f); texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
texture.TexturePath = String.Empty; texture.TexturePath = String.Empty;
lock (MutexTexture)
{
_D3DTextures.Add(t);
texture.index = _D3DTextures.Count - 1;
_Textures.Add(texture); _Textures.Add(texture);
}
return texture; return texture;
} }
/// <summary>
/// Adds a texture and stores it in the Vram
/// </summary>
/// <param name="bmp">The Bitmap of which the texute will be created from</param>
/// <returns>A STexture object containing the added texture</returns>
public STexture AddTexture(Bitmap bmp) public STexture AddTexture(Bitmap bmp)
{ {
return AddTexture(bmp, String.Empty); return AddTexture(bmp, String.Empty);
@@ -625,6 +799,26 @@ namespace Vocaluxe.Lib.Draw
return AddTexture(W, H, ref PointerData); return AddTexture(W, H, ref PointerData);
} }
public STexture QuequeTexture(int W, int H, ref byte[] Data)
{
STexture texture = new STexture(-1);
STextureQueque queque = new STextureQueque();
queque.data = Data;
queque.height = H;
queque.width = W;
lock (MutexTexture)
{
_D3DTextures.Add(null);
texture.index = _D3DTextures.Count - 1;
queque.ID = texture.index;
_Queque.Add(queque);
_Textures.Add(texture);
}
return texture;
}
public STexture AddTexture(int W, int H, ref byte[] Data) public STexture AddTexture(int W, int H, ref byte[] Data)
{ {
STexture texture = new STexture(-1); STexture texture = new STexture(-1);
@@ -645,16 +839,26 @@ namespace Vocaluxe.Lib.Draw
rect.Data.Position += rect.Pitch; rect.Data.Position += rect.Pitch;
} }
t.UnlockRectangle(0); t.UnlockRectangle(0);
_D3DTextures.Add(t);
texture.index = _D3DTextures.Count - 1;
texture.color = new SColorF(1f, 1f, 1f, 1f); texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
texture.TexturePath = String.Empty; texture.TexturePath = String.Empty;
lock (MutexTexture)
{
_D3DTextures.Add(t);
texture.index = _D3DTextures.Count - 1;
_Textures.Add(texture); _Textures.Add(texture);
}
return texture; return texture;
} }
/// <summary>
/// Updates the data of a texture
/// </summary>
/// <param name="Texture">The texture to update</param>
/// <param name="Data">A Pointer containing the data of which the texture should be updated</param>
/// <returns>True if succeeded</returns>
public bool UpdateTexture(ref STexture Texture, IntPtr Data) public bool UpdateTexture(ref STexture Texture, IntPtr Data)
{ {
byte[] PointerData = new Byte[4 * (int)Texture.width * (int)Texture.height]; byte[] PointerData = new Byte[4 * (int)Texture.width * (int)Texture.height];
@@ -663,9 +867,15 @@ namespace Vocaluxe.Lib.Draw
return UpdateTexture(ref Texture, ref PointerData); return UpdateTexture(ref Texture, ref PointerData);
} }
/// <summary>
/// Updates the data of a texture
/// </summary>
/// <param name="Texture">The texture to update</param>
/// <param name="Data">A byte array containing the new texture's data</param>
/// <returns>True if succeeded</returns>
public bool UpdateTexture(ref STexture Texture, ref byte[] Data) public bool UpdateTexture(ref STexture Texture, ref byte[] Data)
{ {
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture))
{ {
DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None); DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None);
for (int i = 0; i < Data.Length; ) for (int i = 0; i < Data.Length; )
@@ -679,26 +889,44 @@ namespace Vocaluxe.Lib.Draw
Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height); Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height);
Texture.width_ratio = Texture.width / NextPowerOfTwo(Texture.width); Texture.width_ratio = Texture.width / NextPowerOfTwo(Texture.width);
}
return true; return true;
} }
else
return false;
}
private bool _TextureExists(STexture Texture) /// <summary>
/// Checks if a texture exists
/// </summary>
/// <param name="Texture">The texture to check</param>
/// <returns>True if the texture exists</returns>
private bool _TextureExists(ref STexture Texture)
{ {
if ((Texture.index > 0) && (_Textures.Count > 0)) lock (MutexTexture)
{ {
for (int i = 0; i < _Textures.Count; i++) for (int i = 0; i < _Textures.Count; i++)
{ {
if (_Textures[i].index == Texture.index) if (Texture.index == _Textures[i].index)
{ {
if (_Textures[i].index >= 0)
{
Texture = _Textures[i];
return true; return true;
} }
break;
}
} }
} }
return false; return false;
} }
/// <summary>
/// Removes a texture from the Vram
/// </summary>
/// <param name="Texture">The texture to be removed</param>
public void RemoveTexture(ref STexture Texture) public void RemoveTexture(ref STexture Texture)
{
lock (MutexTexture)
{ {
if ((Texture.index >= 0) && (_Textures.Count > 0)) if ((Texture.index >= 0) && (_Textures.Count > 0))
{ {
@@ -707,49 +935,88 @@ namespace Vocaluxe.Lib.Draw
if (_Textures[i].index == Texture.index) if (_Textures[i].index == Texture.index)
{ {
_D3DTextures[Texture.index].Dispose(); _D3DTextures[Texture.index].Dispose();
_D3DTextures[Texture.index] = null;
_Textures.RemoveAt(i); _Textures.RemoveAt(i);
Texture.index = -1; Texture.index = -1;
GC.Collect(); Texture.ID = -1;
break; }
} }
} }
} }
} }
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="Texture">The texture to be drawn</param>
public void DrawTexture(STexture Texture) public void DrawTexture(STexture Texture)
{ {
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
DrawTexture(Texture, Texture.rect, Texture.color); DrawTexture(Texture, Texture.rect, Texture.color);
} }
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="Texture">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
public void DrawTexture(STexture Texture, SRectF rect) public void DrawTexture(STexture Texture, SRectF rect)
{ {
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
DrawTexture(Texture, rect, Texture.color, false); DrawTexture(Texture, rect, Texture.color, false);
} }
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="Texture">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
public void DrawTexture(STexture Texture, SRectF rect, SColorF color) public void DrawTexture(STexture Texture, SRectF rect, SColorF color)
{ {
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
DrawTexture(Texture, rect, color, false); DrawTexture(Texture, rect, color, false);
} }
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="Texture">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds) public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds)
{ {
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
DrawTexture(Texture, rect, color, bounds, false); DrawTexture(Texture, rect, color, bounds, false);
} }
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="Texture">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, bool mirrored) public void DrawTexture(STexture Texture, SRectF rect, SColorF color, bool mirrored)
{ {
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index))
DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored); DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored);
} }
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="Texture">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored) public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored)
{ {
if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture))
{ {
//Calculate the position
float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio;
@@ -767,6 +1034,7 @@ namespace Vocaluxe.Lib.Draw
if (y2 > Texture.height_ratio) if (y2 > Texture.height_ratio)
y2 = Texture.height_ratio; y2 = Texture.height_ratio;
//Calculate the size
float rx1 = rect.X; float rx1 = rect.X;
float rx2 = rect.X + rect.W; float rx2 = rect.X + rect.W;
float ry1 = rect.Y; float ry1 = rect.Y;
@@ -784,7 +1052,8 @@ namespace Vocaluxe.Lib.Draw
if (ry2 > bounds.Y + bounds.H) if (ry2 > bounds.Y + bounds.H)
ry2 = bounds.Y + bounds.H; ry2 = bounds.Y + bounds.H;
rx1 -= 0.5f; // Align pixels //Align the pixels because Direct3D expects the pixels to be the left top corner
rx1 -= 0.5f;
ry1 -= 0.5f; ry1 -= 0.5f;
rx2 -= 0.5f; rx2 -= 0.5f;
ry2 -= 0.5f; ry2 -= 0.5f;
@@ -796,6 +1065,8 @@ namespace Vocaluxe.Lib.Draw
if (color.G >= 1f) if (color.G >= 1f)
color.G = 1f; color.G = 1f;
//Apply rotation
//FIXME: Rotated textures get distorted when they hit the border of the window
if (rect.Rotation != 0) if (rect.Rotation != 0)
{ {
rect.Rotation = rect.Rotation * (float)Math.PI / 180; rect.Rotation = rect.Rotation * (float)Math.PI / 180;
@@ -807,12 +1078,18 @@ namespace Vocaluxe.Lib.Draw
Matrix rotation = Matrix.RotationZ(-rect.Rotation); Matrix rotation = Matrix.RotationZ(-rect.Rotation);
Matrix translationB = Matrix.Translation(centerX, centerY, 0); Matrix translationB = Matrix.Translation(centerX, centerY, 0);
//Multiplicate the matrices to get the real world matrix,
//First shift the texture into the center
//Rotate it and shift it back to the origin position
//Apply the originTranslation after
Matrix result = translationA * rotation * translationB * originTranslation; Matrix result = translationA * rotation * translationB * originTranslation;
_Device.SetTransform(TransformState.World, result); _Device.SetTransform(TransformState.World, result);
} }
Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255));
//Create new vertices and write them into a vertexbuffer
DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard);
if (!mirrored) if (!mirrored)
{ {
@@ -834,9 +1111,12 @@ namespace Vocaluxe.Lib.Draw
} }
_VertexBuffer.Unlock(); _VertexBuffer.Unlock();
stream.Dispose(); stream.Dispose();
//Set the texture
_Device.SetTexture(0, _D3DTextures[Texture.index]); _Device.SetTexture(0, _D3DTextures[Texture.index]);
//Draw 2 triangles to build a quad
_Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
//Reapply old matrices if the texture was rotated
if (rect.Rotation != 0) if (rect.Rotation != 0)
{ {
Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0));
@@ -845,9 +1125,19 @@ namespace Vocaluxe.Lib.Draw
} }
} }
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="Texture">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="begin">A Value ranging from 0 to 1 containing the beginning of the texture</param>
/// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param>
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end) public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end)
{ {
if (_TextureExists(ref Texture))
{
float x1 = 0f + begin * Texture.width_ratio; float x1 = 0f + begin * Texture.width_ratio;
float x2 = Texture.width_ratio * end; float x2 = Texture.width_ratio * end;
float y1 = 0f; float y1 = 0f;
@@ -858,26 +1148,72 @@ namespace Vocaluxe.Lib.Draw
float ry1 = rect.Y; float ry1 = rect.Y;
float ry2 = rect.Y + rect.H; float ry2 = rect.Y + rect.H;
rx1 -= 0.5f; // Align pixels //Align the pixels because Direct3D expects the pixels to be the left top corner
rx1 -= 0.5f;
ry1 -= 0.5f; ry1 -= 0.5f;
rx2 -= 0.5f; rx2 -= 0.5f;
ry2 -= 0.5f; ry2 -= 0.5f;
Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255));
//Apply rotation
//FIXME: Rotated textures get distorted when they hit the border of the window
if (rect.Rotation != 0)
{
rect.Rotation = rect.Rotation * (float)Math.PI / 180;
float centerX = (rx1 + rx2) / 2f;
float centerY = -(ry1 + ry2) / 2f;
Matrix originTranslation = _Device.GetTransform(TransformState.World);
Matrix translationA = Matrix.Translation(-centerX, -centerY, 0);
Matrix rotation = Matrix.RotationZ(-rect.Rotation);
Matrix translationB = Matrix.Translation(centerX, centerY, 0);
//Multiplicate the matrices to get the real world matrix,
//First shift the texture into the center
//Rotate it and shift it back to the origin position
//Apply the originTranslation after
Matrix result = translationA * rotation * translationB * originTranslation;
_Device.SetTransform(TransformState.World, result);
}
//Create new vertices and write them into a vertexbuffer
DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard);
stream.WriteRange(new[] { stream.WriteRange(new[] {
new TexturedColoredVertex(new Vector3(rx1, ry1*-1f, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()),
new TexturedColoredVertex(new Vector3(rx1, ry2*-1f, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()),
new TexturedColoredVertex(new Vector3(rx2, ry2*-1f, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()),
new TexturedColoredVertex(new Vector3(rx2, ry1*-1f, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()),
}); });
_VertexBuffer.Unlock(); _VertexBuffer.Unlock();
stream.Dispose(); stream.Dispose();
//Set the texture
_Device.SetTexture(0, _D3DTextures[Texture.index]); _Device.SetTexture(0, _D3DTextures[Texture.index]);
//Draw 2 triangles to build a quad
_Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
//Reapply old matrices if the texture was rotated
if (rect.Rotation != 0)
{
Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0));
_Device.SetTransform(TransformState.World, originTranslation);
}
}
} }
/// <summary>
/// Draws a reflection of a texture
/// </summary>
/// <param name="Texture">The texture of which a reflection should be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="space">The space between the texture and the reflection</param>
/// <param name="height">The height of the reflection</param>
public void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) public void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height)
{
if (_TextureExists(ref Texture))
{ {
if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f) if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f)
return; return;
@@ -891,7 +1227,7 @@ namespace Vocaluxe.Lib.Draw
if (height > bounds.H) if (height > bounds.H)
height = bounds.H; height = bounds.H;
if (_TextureExists(Texture)) if (_TextureExists(ref Texture))
{ {
float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
@@ -928,29 +1264,119 @@ namespace Vocaluxe.Lib.Draw
if (ry2 > bounds.Y + bounds.H + space + height) if (ry2 > bounds.Y + bounds.H + space + height)
ry2 = bounds.Y + bounds.H + space + height; ry2 = bounds.Y + bounds.H + space + height;
rx1 -= 0.5f; // Align pixels //Align the pixels because Direct3D expects the pixels to be the left top corner
rx1 -= 0.5f;
ry1 -= 0.5f; ry1 -= 0.5f;
rx2 -= 0.5f; rx2 -= 0.5f;
ry2 -= 0.5f; ry2 -= 0.5f;
DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); //Apply rotation
//FIXME: Rotated textures get distorted when they hit the border of the window
if (rect.Rotation != 0)
{
rect.Rotation = rect.Rotation * (float)Math.PI / 180;
float centerX = (rx1 + rx2) / 2f;
float centerY = -(ry1 + ry2) / 2f;
Matrix originTranslation = _Device.GetTransform(TransformState.World);
Matrix translationA = Matrix.Translation(-centerX, -centerY, 0);
Matrix rotation = Matrix.RotationZ(-rect.Rotation);
Matrix translationB = Matrix.Translation(centerX, centerY, 0);
//Multiplicate the matrices to get the real world matrix,
//First shift the texture into the center
//Rotate it and shift it back to the origin position
//Apply the originTranslation after
Matrix result = translationA * rotation * translationB * originTranslation;
_Device.SetTransform(TransformState.World, result);
}
Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255));
Color t = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); Color transparent = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255));
//Create new vertices and write them into a vertexbuffer
DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard);
stream.WriteRange(new[] { stream.WriteRange(new[] {
new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()),
new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), t.ToArgb()), new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb()),
new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), t.ToArgb()), new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb()),
new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()),
}); });
_VertexBuffer.Unlock(); _VertexBuffer.Unlock();
stream.Dispose(); stream.Dispose();
//Set the texture
_Device.SetTexture(0, _D3DTextures[Texture.index]); _Device.SetTexture(0, _D3DTextures[Texture.index]);
//Draw 2 triangles to build a quad
_Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
//Reapply old matrices if the texture was rotated
if (rect.Rotation != 0)
{
Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0));
_Device.SetTransform(TransformState.World, originTranslation);
}
}
} }
} }
private void CheckQueque()
{
lock (MutexTexture)
{
if (_Queque.Count == 0)
return;
STextureQueque q = _Queque[0];
STexture texture = new STexture(-1);
int index = -1;
for (int i = 0; i < _Textures.Count; i++)
{
if (_Textures[i].index == q.ID)
{
texture = _Textures[i];
index = i;
break;
}
}
if (texture.index < 0)
return;
texture.width = q.width;
texture.height = q.height;
texture.w2 = NextPowerOfTwo(texture.width);
texture.h2 = NextPowerOfTwo(texture.height);
texture.width_ratio = texture.width / texture.w2;
texture.height_ratio = texture.height / texture.h2;
Texture t = new Texture(_Device, (int)texture.w2, (int)texture.h2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed);
DataRectangle rect = t.LockRectangle(0, LockFlags.None);
for (int i = 0; i < q.data.Length; )
{
rect.Data.Write(q.data, i, 4 * q.width);
i += 4 * q.width;
rect.Data.Position = rect.Data.Position - 4 * q.width;
rect.Data.Position += rect.Pitch;
}
t.UnlockRectangle(0);
_D3DTextures[q.ID] = t;
// Add to Texture List
texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
texture.TexturePath = String.Empty;
_Textures[index] = texture;
_Queque.RemoveAt(0);
}
}
/// <summary>
/// Gets the count of current textures
/// </summary>
/// <returns>The amount of textures</returns>
public int TextureCount() public int TextureCount()
{ {
return _Textures.Count; return _Textures.Count;
+6 -1
View File
@@ -256,7 +256,7 @@ namespace Vocaluxe.Lib.Draw
CFonts.Height = Height; CFonts.Height = Height;
CFonts.SetFont(text.Fon); CFonts.SetFont(text.Fon);
CFonts.Style = text.Style; CFonts.Style = text.Style;
return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(text.Text)); return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text)));
} }
public void ClearScreen() public void ClearScreen()
@@ -400,6 +400,11 @@ namespace Vocaluxe.Lib.Draw
return new STexture(-1); return new STexture(-1);
} }
public STexture QuequeTexture(int W, int H, ref byte[] Data)
{
return AddTexture(W, H, ref Data);
}
public STexture AddTexture(int W, int H, ref byte[] Data) public STexture AddTexture(int W, int H, ref byte[] Data)
{ {
Bitmap bmp = new Bitmap(W, H); Bitmap bmp = new Bitmap(W, H);
+174 -27
View File
@@ -18,13 +18,20 @@ using Vocaluxe.Menu;
namespace Vocaluxe.Lib.Draw namespace Vocaluxe.Lib.Draw
{ {
public struct SClientRect struct SClientRect
{ {
public Point location; public Point location;
public int width; public int width;
public int height; public int height;
}; };
struct STextureQueque
{
public int ID;
public int width;
public int height;
public byte[] data;
}
class COpenGL : Form, IDraw class COpenGL : Form, IDraw
{ {
@@ -40,6 +47,10 @@ namespace Vocaluxe.Lib.Draw
private bool _fullscreen = false; private bool _fullscreen = false;
private List<STexture> _Textures; private List<STexture> _Textures;
private Queue<int> _IDs;
private List<STextureQueque> _Queque;
private Object MutexTexture = new Object();
private int h = 1; private int h = 1;
private int w = 1; private int w = 1;
@@ -55,6 +66,13 @@ namespace Vocaluxe.Lib.Draw
this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon));
_Textures = new List<STexture>(); _Textures = new List<STexture>();
_Queque = new List<STextureQueque>();
_IDs = new Queue<int>(1000000);
for (int i = 1; i < 1000000; i++)
{
_IDs.Enqueue(i);
}
//Check AA Mode //Check AA Mode
CConfig.AAMode = (EAntiAliasingModes)CheckAntiAliasingMode((int)CConfig.AAMode); CConfig.AAMode = (EAntiAliasingModes)CheckAntiAliasingMode((int)CConfig.AAMode);
@@ -440,12 +458,15 @@ namespace Vocaluxe.Lib.Draw
ClearScreen(); ClearScreen();
_Run = _Run && CGraphics.Draw(); _Run = _Run && CGraphics.Draw();
_Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse);
control.SwapBuffers(); control.SwapBuffers();
if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen)) if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen))
ToggleFullScreen(); ToggleFullScreen();
CheckQueque();
if (CTime.IsRunning()) if (CTime.IsRunning())
delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds());
@@ -490,7 +511,7 @@ namespace Vocaluxe.Lib.Draw
CFonts.Height = Height; CFonts.Height = Height;
CFonts.SetFont(text.Fon); CFonts.SetFont(text.Fon);
CFonts.Style = text.Style; CFonts.Style = text.Style;
return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(text.Text)); return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text)));
} }
#region Basic Draw Methods #region Basic Draw Methods
@@ -505,7 +526,7 @@ namespace Vocaluxe.Lib.Draw
int id = GL.GenTexture(); int id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, id); GL.BindTexture(TextureTarget.Texture2D, id);
texture.index = id; texture.ID = id;
texture.width = w; texture.width = w;
texture.height = h; texture.height = h;
@@ -529,21 +550,26 @@ namespace Vocaluxe.Lib.Draw
// Add to Texture List // Add to Texture List
texture.color = new SColorF(1f, 1f, 1f, 1f); texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
lock (MutexTexture)
{
texture.index = _IDs.Dequeue();
_Textures.Add(texture); _Textures.Add(texture);
}
return texture; return texture;
} }
public void CopyScreen(ref STexture Texture) public void CopyScreen(ref STexture Texture)
{ {
if (!_TextureExists(Texture) || (Texture.width != GetScreenWidth()) || (Texture.height != GetScreenHeight())) if (!_TextureExists(ref Texture) || (Texture.width != GetScreenWidth()) || (Texture.height != GetScreenHeight()))
{ {
RemoveTexture(ref Texture); RemoveTexture(ref Texture);
Texture = CopyScreen(); Texture = CopyScreen();
} }
else else
{ {
GL.BindTexture(TextureTarget.Texture2D, Texture.index); GL.BindTexture(TextureTarget.Texture2D, Texture.ID);
GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0,
(int)Texture.width, (int)Texture.height); (int)Texture.width, (int)Texture.height);
@@ -643,10 +669,6 @@ namespace Vocaluxe.Lib.Draw
if (bmp.Height == 0 || bmp.Width == 0) if (bmp.Height == 0 || bmp.Width == 0)
return texture; return texture;
int id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, id);
texture.index = id;
int MaxSize; int MaxSize;
switch (CConfig.TextureQuality) switch (CConfig.TextureQuality)
{ {
@@ -685,6 +707,10 @@ namespace Vocaluxe.Lib.Draw
h = MaxSize; h = MaxSize;
} }
int id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, id);
texture.ID = id;
texture.width = w; texture.width = w;
texture.height = h; texture.height = h;
@@ -696,6 +722,7 @@ namespace Vocaluxe.Lib.Draw
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height));
g.Dispose();
texture.width_ratio = 1f; texture.width_ratio = 1f;
texture.height_ratio = 1f; texture.height_ratio = 1f;
@@ -727,7 +754,12 @@ namespace Vocaluxe.Lib.Draw
texture.color = new SColorF(1f, 1f, 1f, 1f); texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
texture.TexturePath = String.Empty; texture.TexturePath = String.Empty;
lock (MutexTexture)
{
texture.index = _IDs.Dequeue();
_Textures.Add(texture); _Textures.Add(texture);
}
return texture; return texture;
} }
@@ -753,7 +785,7 @@ namespace Vocaluxe.Lib.Draw
int id = GL.GenTexture(); int id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, id); GL.BindTexture(TextureTarget.Texture2D, id);
texture.index = id; texture.ID = id;
texture.width = W; texture.width = W;
texture.height = H; texture.height = H;
@@ -786,7 +818,12 @@ namespace Vocaluxe.Lib.Draw
texture.color = new SColorF(1f, 1f, 1f, 1f); texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
texture.TexturePath = String.Empty; texture.TexturePath = String.Empty;
lock (MutexTexture)
{
texture.index = _IDs.Dequeue();
_Textures.Add(texture); _Textures.Add(texture);
}
return texture; return texture;
} }
@@ -813,7 +850,7 @@ namespace Vocaluxe.Lib.Draw
int id = GL.GenTexture(); int id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, id); GL.BindTexture(TextureTarget.Texture2D, id);
texture.index = id; texture.ID = id;
texture.width = W; texture.width = W;
texture.height = H; texture.height = H;
@@ -846,14 +883,39 @@ namespace Vocaluxe.Lib.Draw
texture.color = new SColorF(1f, 1f, 1f, 1f); texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
texture.TexturePath = String.Empty; texture.TexturePath = String.Empty;
lock (MutexTexture)
{
texture.index = _IDs.Dequeue();
_Textures.Add(texture); _Textures.Add(texture);
}
return texture;
}
public STexture QuequeTexture(int W, int H, ref byte[] Data)
{
STexture texture = new STexture(-1);
STextureQueque queque = new STextureQueque();
queque.data = Data;
queque.height = H;
queque.width = W;
lock (MutexTexture)
{
texture.index = _IDs.Dequeue();
queque.ID = texture.index;
_Queque.Add(queque);
_Textures.Add(texture);
}
return texture; return texture;
} }
public bool UpdateTexture(ref STexture Texture, IntPtr Data) public bool UpdateTexture(ref STexture Texture, IntPtr Data)
{ {
if (_TextureExists(Texture)) if (_TextureExists(ref Texture))
{ {
if (_UsePBO) if (_UsePBO)
{ {
@@ -869,7 +931,7 @@ namespace Vocaluxe.Lib.Draw
GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer);
GL.BindTexture(TextureTarget.Texture2D, Texture.index); GL.BindTexture(TextureTarget.Texture2D, Texture.ID);
GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height, GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);
@@ -884,7 +946,7 @@ namespace Vocaluxe.Lib.Draw
} }
} }
GL.BindTexture(TextureTarget.Texture2D, Texture.index); GL.BindTexture(TextureTarget.Texture2D, Texture.ID);
GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height, GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, Data); OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, Data);
@@ -908,7 +970,7 @@ namespace Vocaluxe.Lib.Draw
public bool UpdateTexture(ref STexture Texture, ref byte[] Data) public bool UpdateTexture(ref STexture Texture, ref byte[] Data)
{ {
if (_TextureExists(Texture)) if (_TextureExists(ref Texture))
{ {
if (_UsePBO) if (_UsePBO)
{ {
@@ -921,7 +983,7 @@ namespace Vocaluxe.Lib.Draw
GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer);
GL.BindTexture(TextureTarget.Texture2D, Texture.index); GL.BindTexture(TextureTarget.Texture2D, Texture.ID);
GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height, GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);
@@ -937,7 +999,7 @@ namespace Vocaluxe.Lib.Draw
} }
} }
GL.BindTexture(TextureTarget.Texture2D, Texture.index); GL.BindTexture(TextureTarget.Texture2D, Texture.ID);
GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height, GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, Data); OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, Data);
@@ -962,32 +1024,43 @@ namespace Vocaluxe.Lib.Draw
public void RemoveTexture(ref STexture Texture) public void RemoveTexture(ref STexture Texture)
{ {
if ((Texture.index > 0) && (_Textures.Count > 0)) if ((Texture.index > 0) && (_Textures.Count > 0))
{
lock (MutexTexture)
{ {
for (int i = 0; i < _Textures.Count; i++) for (int i = 0; i < _Textures.Count; i++)
{ {
if (_Textures[i].index == Texture.index) if (_Textures[i].index == Texture.index)
{ {
GL.DeleteTexture(Texture.index); _IDs.Enqueue(Texture.index);
GL.DeleteTexture(Texture.ID);
if (Texture.PBO > 0) if (Texture.PBO > 0)
GL.DeleteBuffers(1, ref Texture.PBO); GL.DeleteBuffers(1, ref Texture.PBO);
_Textures.RemoveAt(i); _Textures.RemoveAt(i);
Texture.index = -1; Texture.index = -1;
Texture.ID = -1;
break; break;
} }
} }
} }
} }
}
private bool _TextureExists(STexture Texture) private bool _TextureExists(ref STexture Texture)
{ {
if ((Texture.index > 0) && (_Textures.Count > 0)) lock (MutexTexture)
{ {
for (int i = 0; i < _Textures.Count; i++) for (int i = 0; i < _Textures.Count; i++)
{ {
if (_Textures[i].index == Texture.index) if (Texture.index == _Textures[i].index)
{ {
if (_Textures[i].ID > 0)
{
Texture = _Textures[i];
return true; return true;
} }
break;
}
} }
} }
return false; return false;
@@ -1029,9 +1102,9 @@ namespace Vocaluxe.Lib.Draw
if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y)
return; return;
if (_TextureExists(Texture)) if (_TextureExists(ref Texture))
{ {
GL.BindTexture(TextureTarget.Texture2D, Texture.index); GL.BindTexture(TextureTarget.Texture2D, Texture.ID);
float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
@@ -1127,9 +1200,9 @@ namespace Vocaluxe.Lib.Draw
public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end) public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end)
{ {
if (_TextureExists(Texture)) if (_TextureExists(ref Texture))
{ {
GL.BindTexture(TextureTarget.Texture2D, Texture.index); GL.BindTexture(TextureTarget.Texture2D, Texture.ID);
GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Blend);
GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
@@ -1171,9 +1244,9 @@ namespace Vocaluxe.Lib.Draw
if (height > bounds.H) if (height > bounds.H)
height = bounds.H; height = bounds.H;
if (_TextureExists(Texture)) if (_TextureExists(ref Texture))
{ {
GL.BindTexture(TextureTarget.Texture2D, Texture.index); GL.BindTexture(TextureTarget.Texture2D, Texture.ID);
float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
@@ -1255,6 +1328,80 @@ namespace Vocaluxe.Lib.Draw
{ {
return _Textures.Count; return _Textures.Count;
} }
private void CheckQueque()
{
lock (MutexTexture)
{
if (_Queque.Count == 0)
return;
STextureQueque q = _Queque[0];
STexture texture = new STexture(-1);
int index = -1;
for (int i = 0; i < _Textures.Count; i++)
{
if (_Textures[i].index == q.ID)
{
texture = _Textures[i];
index = i;
break;
}
}
if (texture.index < 1)
return;
if (_UsePBO)
{
try
{
GL.GenBuffers(1, out texture.PBO);
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO);
GL.BufferData(BufferTarget.PixelUnpackBuffer, (IntPtr)q.data.Length, IntPtr.Zero, BufferUsageHint.StreamDraw);
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);
}
catch (Exception)
{
//throw;
_UsePBO = false;
}
}
int id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, id);
texture.ID = id;
texture.width = q.width;
texture.height = q.height;
texture.w2 = (float)MathHelper.NextPowerOfTwo(texture.width);
texture.h2 = (float)MathHelper.NextPowerOfTwo(texture.height);
texture.width_ratio = texture.width / texture.w2;
texture.height_ratio = texture.height / texture.h2;
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)texture.w2, (int)texture.h2, 0,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);
GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, q.width, q.height,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, q.data);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.BindTexture(TextureTarget.Texture2D, 0);
// Add to Texture List
texture.color = new SColorF(1f, 1f, 1f, 1f);
texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f);
texture.TexturePath = String.Empty;
_Textures[index] = texture;
q.data = null;
_Queque.RemoveAt(0);
}
}
#endregion Textures #endregion Textures
#endregion implementation #endregion implementation
+5 -2
View File
@@ -67,6 +67,7 @@ namespace Vocaluxe.Lib.Draw
{ {
public int index; public int index;
public int PBO; public int PBO;
public int ID;
public string TexturePath; public string TexturePath;
@@ -85,10 +86,11 @@ namespace Vocaluxe.Lib.Draw
{ {
index = Index; index = Index;
PBO = 0; PBO = 0;
ID = -1;
TexturePath = String.Empty; TexturePath = String.Empty;
width = 0f; width = 1f;
height = 0f; height = 1f;
rect = new SRectF(0f, 0f, 1f, 1f, 0f); rect = new SRectF(0f, 0f, 1f, 1f, 0f);
w2 = 2f; w2 = 2f;
@@ -136,6 +138,7 @@ namespace Vocaluxe.Lib.Draw
STexture AddTexture(Bitmap Bitmap); STexture AddTexture(Bitmap Bitmap);
STexture AddTexture(int W, int H, IntPtr Data); STexture AddTexture(int W, int H, IntPtr Data);
STexture AddTexture(int W, int H, ref byte[] Data); STexture AddTexture(int W, int H, ref byte[] Data);
STexture QuequeTexture(int W, int H, ref byte[] Data);
bool UpdateTexture(ref STexture Texture, ref byte[] Data); bool UpdateTexture(ref STexture Texture, ref byte[] Data);
bool UpdateTexture(ref STexture Texture, IntPtr Data); bool UpdateTexture(ref STexture Texture, IntPtr Data);
+36 -30
View File
@@ -245,6 +245,8 @@ namespace Vocaluxe.Lib.Song
private int _EndBeat; private int _EndBeat;
private bool _PerfectLine; // for drawing perfect line effect private bool _PerfectLine; // for drawing perfect line effect
private int _MinBeat = int.MaxValue;
private int _MaxBeat = int.MinValue;
private List<CNote> _Notes; private List<CNote> _Notes;
#region Constructors #region Constructors
@@ -263,14 +265,7 @@ namespace Vocaluxe.Lib.Song
get { return _StartBeat; } get { return _StartBeat; }
set set
{ {
int min = int.MaxValue; if (value <= _MinBeat)
foreach (CNote note in _Notes)
{
if (note.StartBeat < min)
min = note.StartBeat;
}
if (value <= min)
_StartBeat = value; _StartBeat = value;
} }
} }
@@ -280,14 +275,7 @@ namespace Vocaluxe.Lib.Song
get { return _EndBeat; } get { return _EndBeat; }
set set
{ {
int max = int.MinValue; if (value >= _MaxBeat)
foreach (CNote note in _Notes)
{
if (note.EndBeat > max)
max = note.EndBeat;
}
if (value >= max)
_EndBeat = value; _EndBeat = value;
} }
} }
@@ -302,13 +290,7 @@ namespace Vocaluxe.Lib.Song
{ {
get get
{ {
int Result = int.MaxValue; return _MinBeat;
foreach (CNote note in _Notes)
{
if (note.StartBeat < Result)
Result = note.StartBeat;
}
return Result;
} }
} }
@@ -316,13 +298,7 @@ namespace Vocaluxe.Lib.Song
{ {
get get
{ {
int Result = int.MinValue; return _MaxBeat;
foreach (CNote note in _Notes)
{
if (note.EndBeat > Result)
Result = note.EndBeat;
}
return Result;
} }
} }
@@ -429,6 +405,7 @@ namespace Vocaluxe.Lib.Song
public void AddNote(CNote Note) public void AddNote(CNote Note)
{ {
_Notes.Add(Note); _Notes.Add(Note);
updateMinMaxBeat(Note);
} }
public bool InsertNote(CNote Note, int Index) public bool InsertNote(CNote Note, int Index)
@@ -436,6 +413,7 @@ namespace Vocaluxe.Lib.Song
if (_Notes.Count >= Index) if (_Notes.Count >= Index)
{ {
_Notes.Insert(Index, Note); _Notes.Insert(Index, Note);
updateMinMaxBeat(Note);
return true; return true;
} }
return false; return false;
@@ -446,6 +424,7 @@ namespace Vocaluxe.Lib.Song
if (_Notes.Count > Index) if (_Notes.Count > Index)
{ {
_Notes.RemoveAt(Index); _Notes.RemoveAt(Index);
updateMinMaxBeat();
return true; return true;
} }
return false; return false;
@@ -457,6 +436,7 @@ namespace Vocaluxe.Lib.Song
{ {
_Notes.RemoveAt(Index); _Notes.RemoveAt(Index);
_Notes.Insert(Index, Note); _Notes.Insert(Index, Note);
updateMinMaxBeat();
return true; return true;
} }
return false; return false;
@@ -467,6 +447,7 @@ namespace Vocaluxe.Lib.Song
if (_Notes.Count > 0) if (_Notes.Count > 0)
{ {
_Notes[_Notes.Count - 1].Duration++; _Notes[_Notes.Count - 1].Duration++;
updateMinMaxBeat();
} }
return false; return false;
} }
@@ -474,6 +455,31 @@ namespace Vocaluxe.Lib.Song
public void DeleteAllNotes() public void DeleteAllNotes()
{ {
_Notes.Clear(); _Notes.Clear();
_MinBeat = int.MaxValue;
_MaxBeat = int.MinValue;
}
private void updateMinMaxBeat(CNote Note)
{
if (Note.StartBeat < _MinBeat)
{
_MinBeat = Note.StartBeat;
}
if (Note.EndBeat > _MaxBeat)
{
_MaxBeat = Note.EndBeat;
}
}
private void updateMinMaxBeat()
{
_MinBeat = int.MaxValue;
_MaxBeat = int.MinValue;
foreach (CNote note in _Notes)
{
updateMinMaxBeat(note);
}
} }
#endregion Methods #endregion Methods
} }
+4
View File
@@ -25,6 +25,7 @@ namespace Vocaluxe.Lib.Song
class CSong class CSong
{ {
private bool _CoverLoaded = false; private bool _CoverLoaded = false;
private bool _NotesLoaded = false;
private STexture _CoverTextureSmall = new STexture(-1); private STexture _CoverTextureSmall = new STexture(-1);
private STexture _CoverTextureBig = new STexture(-1); private STexture _CoverTextureBig = new STexture(-1);
@@ -54,7 +55,9 @@ namespace Vocaluxe.Lib.Song
{ {
if (!_CoverLoaded) if (!_CoverLoaded)
{ {
if (!_NotesLoaded)
this.ReadNotes(); this.ReadNotes();
if (this.CoverFileName != String.Empty) if (this.CoverFileName != String.Empty)
{ {
if (!CDataBase.GetCover(Path.Combine(this.Folder, this.CoverFileName), ref _CoverTextureSmall, CConfig.CoverSize)) if (!CDataBase.GetCover(Path.Combine(this.Folder, this.CoverFileName), ref _CoverTextureSmall, CConfig.CoverSize))
@@ -466,6 +469,7 @@ namespace Vocaluxe.Lib.Song
CLog.LogError("Error loading song. Line No.: " + FileLineNo.ToString() + ". An unhandled exception occured (" + e.Message + "): " + FilePath); CLog.LogError("Error loading song. Line No.: " + FileLineNo.ToString() + ". An unhandled exception occured (" + e.Message + "): " + FilePath);
return false; return false;
} }
_NotesLoaded = true;
return true; return true;
} }
+1 -13
View File
@@ -248,51 +248,39 @@ namespace Vocaluxe.Menu
CSettings.zNear); CSettings.zNear);
for (int i = 0; i < Screens.Length; i++) for (int i = 0; i < Screens.Length; i++)
{
if (Enum.GetNames(typeof(EScreens))[i] != Enum.GetName(typeof(EScreens), (int)EScreens.ScreenCredits))
{ {
CLog.StartBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); CLog.StartBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]);
Screens[i].LoadTheme(); Screens[i].LoadTheme();
CLog.StopBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]); CLog.StopBenchmark(1, "Load Theme " + Enum.GetNames(typeof(EScreens))[i]);
} }
} }
}
public static void ReloadTheme() public static void ReloadTheme()
{ {
ReloadCursor(); ReloadCursor();
for (int i = 0; i < Screens.Length; i++) for (int i = 0; i < Screens.Length; i++)
{
if (Enum.GetNames(typeof(EScreens))[i] != Enum.GetName(typeof(EScreens), (int)EScreens.ScreenCredits))
{ {
Screens[i].ReloadTheme(); Screens[i].ReloadTheme();
} }
} }
}
public static void ReloadSkin() public static void ReloadSkin()
{ {
ReloadCursor(); ReloadCursor();
for (int i = 0; i < Screens.Length; i++) for (int i = 0; i < Screens.Length; i++)
{
if (Enum.GetNames(typeof(EScreens))[i] != Enum.GetName(typeof(EScreens), (int)EScreens.ScreenCredits))
{ {
Screens[i].ReloadTextures(); Screens[i].ReloadTextures();
} }
} }
}
public static void SaveTheme() public static void SaveTheme()
{ {
CTheme.SaveTheme(); CTheme.SaveTheme();
for (int i = 0; i < Screens.Length; i++) for (int i = 0; i < Screens.Length; i++)
{
if (Enum.GetNames(typeof(EScreens))[i] != Enum.GetName(typeof(EScreens), (int)EScreens.ScreenCredits))
{ {
Screens[i].SaveTheme(); Screens[i].SaveTheme();
} }
} }
}
public static void InitFirstScreen() public static void InitFirstScreen()
{ {
@@ -317,7 +305,7 @@ namespace Vocaluxe.Menu
CBackgroundMusic.Update(); CBackgroundMusic.Update();
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && ActualScreen != EScreens.ScreenSing) if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && ActualScreen != EScreens.ScreenSing)
CSongs.LoadCover(30L); CSongs.LoadCover(30L, 1);
if (CSettings.GameState != EGameState.EditTheme) if (CSettings.GameState != EGameState.EditTheme)
{ {
+245 -60
View File
@@ -14,26 +14,163 @@ namespace Vocaluxe.Menu
{ {
public string Name; public string Name;
public string Text;
public string ColorName; public string ColorName;
public string SColorName; //for Buttons public string SColorName; //for Buttons
} }
struct STextPosition
{
public float X;
public float Y;
public float tH;
public float Width;
public float Height;
public STextPosition(int dummy)
{
X = 0f;
Y = 0f;
tH = 0f;
Width = 0f;
Height = 0f;
}
}
class CText : IMenuElement class CText : IMenuElement
{ {
private SThemeText _Theme; private SThemeText _Theme;
private bool _ThemeLoaded; private bool _ThemeLoaded;
private bool _ButtonText; private bool _ButtonText;
private bool _PositionNeedsUpdate = true;
public float X; //left private STextPosition _DrawPosition = new STextPosition(0);
public float Y; //higher
public float Z;
public float Height;
public float MaxWidth;
public SRectF Bounds;
public EAlignment Align; private float _X = 0f;
public EStyle Style; public float X //left
public string Fon; {
get { return _X; }
set
{
if (_X != value)
{
_X = value;
_PositionNeedsUpdate = true;
}
}
}
private float _Y = 0f;
public float Y //higher
{
get { return _Y; }
set
{
if (_Y != value)
{
_Y = value;
_PositionNeedsUpdate = true;
}
}
}
private float _Z = 0f;
public float Z
{
get { return _Z; }
set
{
if (_Z != value)
{
_Z = value;
_PositionNeedsUpdate = true;
}
}
}
private float _Height = 0f;
public float Height
{
get { return _Height; }
set
{
if (_Height != value)
{
_Height = value;
_PositionNeedsUpdate = true;
}
}
}
private float _MaxWidth = 0f;
public float MaxWidth
{
get { return _MaxWidth; }
set
{
if (_MaxWidth != value)
{
_MaxWidth = value;
_PositionNeedsUpdate = true;
}
}
}
private SRectF _Bounds = new SRectF();
public SRectF Bounds
{
get { return _Bounds; }
set
{
if (_Bounds.X != value.X || _Bounds.Y != value.Y || _Bounds.W != value.W || _Bounds.H != value.H || _Bounds.Z != value.Z)
{
_Bounds = value;
_PositionNeedsUpdate = true;
}
}
}
private EAlignment _Align = EAlignment.Left;
public EAlignment Align
{
get { return _Align; }
set
{
if (_Align != value)
{
_Align = value;
_PositionNeedsUpdate = true;
}
}
}
private EStyle _Style = EStyle.Normal;
public EStyle Style
{
get { return _Style; }
set
{
if (_Style != value)
{
_Style = value;
_PositionNeedsUpdate = true;
}
}
}
private string _Fon = String.Empty;
public string Fon
{
get { return _Fon; }
set
{
if (_Fon != value)
{
_Fon = value;
_PositionNeedsUpdate = true;
}
}
}
public SColorF Color; //normal Color public SColorF Color; //normal Color
public SColorF SColor; //selected Color for Buttons public SColorF SColor; //selected Color for Buttons
@@ -42,7 +179,22 @@ namespace Vocaluxe.Menu
public float ReflectionSpace; public float ReflectionSpace;
public float ReflectionHeight; public float ReflectionHeight;
public string Text; private string _Text = String.Empty;
public string Text
{
get { return _Theme.Text; }
set
{
string translation = CLanguage.Translate(value);
if (_Theme.Text != value || translation != _Text)
{
_Theme.Text = value;
_Text = translation;
_PositionNeedsUpdate = true;
}
}
}
public bool Selected; public bool Selected;
public bool Visible = true; public bool Visible = true;
@@ -94,7 +246,7 @@ namespace Vocaluxe.Menu
Color = new SColorF(r, g, b, a); Color = new SColorF(r, g, b, a);
SColor = new SColorF(r, g, b, a); SColor = new SColorF(r, g, b, a);
text = Text; Text = text;
Selected = false; Selected = false;
@@ -130,7 +282,7 @@ namespace Vocaluxe.Menu
Color = new SColorF(r, g, b, a); Color = new SColorF(r, g, b, a);
SColor = new SColorF(r, g, b, a); SColor = new SColorF(r, g, b, a);
text = Text; Text = text;
Selected = false; Selected = false;
@@ -226,14 +378,14 @@ namespace Vocaluxe.Menu
string item = XmlPath + "/" + ElementName; string item = XmlPath + "/" + ElementName;
_ThemeLoaded = true; _ThemeLoaded = true;
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/X", navigator, ref X); _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/X", navigator, ref _X);
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/Y", navigator, ref Y); _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/Y", navigator, ref _Y);
if (!ButtonText) if (!ButtonText)
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/Z", navigator, ref Z); _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/Z", navigator, ref _Z);
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/H", navigator, ref Height); _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/H", navigator, ref _Height);
CHelper.TryGetFloatValueFromXML(item + "/MaxW", navigator, ref MaxWidth); CHelper.TryGetFloatValueFromXML(item + "/MaxW", navigator, ref _MaxWidth);
if (CHelper.GetValueFromXML(item + "/Color", navigator, ref _Theme.ColorName, String.Empty)) if (CHelper.GetValueFromXML(item + "/Color", navigator, ref _Theme.ColorName, String.Empty))
{ {
@@ -261,11 +413,11 @@ namespace Vocaluxe.Menu
} }
} }
_ThemeLoaded &= CHelper.TryGetEnumValueFromXML<EAlignment>(item + "/Align", navigator, ref Align); _ThemeLoaded &= CHelper.TryGetEnumValueFromXML<EAlignment>(item + "/Align", navigator, ref _Align);
_ThemeLoaded &= CHelper.TryGetEnumValueFromXML<EStyle>(item + "/Style", navigator, ref Style); _ThemeLoaded &= CHelper.TryGetEnumValueFromXML<EStyle>(item + "/Style", navigator, ref _Style);
_ThemeLoaded &= CHelper.GetValueFromXML(item + "/Font", navigator, ref Fon, "Normal"); _ThemeLoaded &= CHelper.GetValueFromXML(item + "/Font", navigator, ref _Fon, "Normal");
_ThemeLoaded &= CHelper.GetValueFromXML(item + "/Text", navigator, ref Text, String.Empty); _ThemeLoaded &= CHelper.GetValueFromXML(item + "/Text", navigator, ref _Theme.Text, String.Empty);
if (CHelper.ItemExistsInXML(item + "/Reflection", navigator) && !ButtonText) if (CHelper.ItemExistsInXML(item + "/Reflection", navigator) && !ButtonText)
{ {
@@ -276,6 +428,17 @@ namespace Vocaluxe.Menu
else else
Reflection = false; Reflection = false;
// Set values
X = _X;
Y = _Y;
Z = _Z;
Height = _Height;
MaxWidth = _MaxWidth;
Text = _Theme.Text;
Fon = _Fon;
Align = _Align;
Style = _Style;
if (_ThemeLoaded) if (_ThemeLoaded)
{ {
_Theme.Name = ElementName; _Theme.Name = ElementName;
@@ -352,8 +515,8 @@ namespace Vocaluxe.Menu
writer.WriteElementString("Font", Fon); writer.WriteElementString("Font", Fon);
writer.WriteComment("<Text>: Text or translation tag"); writer.WriteComment("<Text>: Text or translation tag");
if (CLanguage.TranslationExists(Text)) if (CLanguage.TranslationExists(_Theme.Text))
writer.WriteElementString("Text", Text); writer.WriteElementString("Text", _Theme.Text);
else else
writer.WriteElementString("Text", string.Empty); writer.WriteElementString("Text", string.Empty);
@@ -394,29 +557,14 @@ namespace Vocaluxe.Menu
if (!ForceDraw && !Visible && CSettings.GameState != EGameState.EditTheme) if (!ForceDraw && !Visible && CSettings.GameState != EGameState.EditTheme)
return; return;
float h = Height; // Update Text
float y = Y; Text = Text;
RectangleF bounds = CDraw.GetTextBounds(this);
while (bounds.Width > Bounds.W) if (_PositionNeedsUpdate)
{ UpdateTextPosition();
h -= 0.2f;
y += 0.1f;
bounds = CDraw.GetTextBounds(this, h);
}
float x = X; CFonts.SetFont(Fon);
switch (Align) CFonts.Style = Style;
{
case EAlignment.Center:
x = X - bounds.Width / 2;
break;
case EAlignment.Right:
x = X - bounds.Width;
break;
default:
break;
}
SColorF CurrentColor = new SColorF(Color); SColorF CurrentColor = new SColorF(Color);
if (Selected) if (Selected)
@@ -424,22 +572,21 @@ namespace Vocaluxe.Menu
SColorF color = new SColorF(CurrentColor.R, CurrentColor.G, CurrentColor.B, CurrentColor.A * Alpha); SColorF color = new SColorF(CurrentColor.R, CurrentColor.G, CurrentColor.B, CurrentColor.A * Alpha);
CFonts.SetFont(Fon);
CFonts.Style = Style; CFonts.DrawText(_Text, _DrawPosition.tH, _DrawPosition.X, _DrawPosition.Y, Z, color);
CFonts.DrawText(CLanguage.Translate(Text), h, x, y, Z, color);
if (Reflection) if (Reflection)
{ {
CFonts.DrawTextReflection(CLanguage.Translate(Text), h, x, y, Z, color, ReflectionSpace, ReflectionHeight); CFonts.DrawTextReflection(_Text, _DrawPosition.tH, _DrawPosition.X, _DrawPosition.Y, Z, color, ReflectionSpace, ReflectionHeight);
} }
if (Selected && (CSettings.GameState == EGameState.EditTheme)) if (Selected && (CSettings.GameState == EGameState.EditTheme))
{ {
CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f * CGraphics.GlobalAlpha), new SRectF(x, y, bounds.Width, bounds.Height, Z)); CDraw.DrawColor(
new SColorF(0.5f, 1f, 0.5f, 0.5f * CGraphics.GlobalAlpha),
new SRectF(_DrawPosition.X, _DrawPosition.Y, _DrawPosition.Width, _DrawPosition.Height, Z)
);
} }
CFonts.SetFont("Normal");
CFonts.Style = EStyle.Normal;
} }
public void Draw(float begin, float end) public void Draw(float begin, float end)
@@ -478,9 +625,6 @@ namespace Vocaluxe.Menu
{ {
CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(x, Y, bounds.Width, bounds.Height, Z)); CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(x, Y, bounds.Width, bounds.Height, Z));
} }
CFonts.SetFont("Normal");
CFonts.Style = EStyle.Normal;
} }
public void DrawRelative(float x, float y) public void DrawRelative(float x, float y)
@@ -495,6 +639,9 @@ namespace Vocaluxe.Menu
public void DrawRelative(float rx, float ry, bool reflection, float reflectionSpace, float reflectionHeight, float rectHeight) public void DrawRelative(float rx, float ry, bool reflection, float reflectionSpace, float reflectionHeight, float rectHeight)
{ {
// Update Text
Text = Text;
float h = Height; float h = Height;
float x = X + rx; float x = X + rx;
@@ -529,22 +676,19 @@ namespace Vocaluxe.Menu
CFonts.SetFont(Fon); CFonts.SetFont(Fon);
CFonts.Style = Style; CFonts.Style = Style;
CFonts.DrawText(CLanguage.Translate(Text), h, x, y, Z, color); CFonts.DrawText(_Text, h, x, y, Z, color);
if (reflection) if (reflection)
{ {
float space = (rectHeight - Y - bounds.Height) * 2f + reflectionSpace; float space = (rectHeight - Y - bounds.Height) * 2f + reflectionSpace;
float height = reflectionHeight - (rectHeight - Y) + bounds.Height; float height = reflectionHeight - (rectHeight - Y) + bounds.Height;
CFonts.DrawTextReflection(CLanguage.Translate(Text), h, x, y, Z, color, space, height); CFonts.DrawTextReflection(_Text, h, x, y, Z, color, space, height);
} }
if (Selected && (CSettings.GameState == EGameState.EditTheme)) if (Selected && (CSettings.GameState == EGameState.EditTheme))
{ {
CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f * CGraphics.GlobalAlpha), new SRectF(x, y, bounds.Width, bounds.Height, Z)); CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f * CGraphics.GlobalAlpha), new SRectF(x, y, bounds.Width, bounds.Height, Z));
} }
CFonts.SetFont("Normal");
CFonts.Style = EStyle.Normal;
} }
public void UnloadTextures() public void UnloadTextures()
@@ -580,5 +724,46 @@ namespace Vocaluxe.Menu
Height = 1; Height = 1;
} }
#endregion ThemeEdit #endregion ThemeEdit
private void UpdateTextPosition()
{
if (_Text == String.Empty)
return;
CFonts.SetFont(Fon);
CFonts.Style = Style;
float h = Height;
float y = Y;
RectangleF bounds = CFonts.GetTextBounds(this);
while (bounds.Width > Bounds.W)
{
h -= 0.2f;
y += 0.1f;
bounds = CFonts.GetTextBounds(this, h);
}
float x = X;
switch (Align)
{
case EAlignment.Center:
x = X - bounds.Width / 2;
break;
case EAlignment.Right:
x = X - bounds.Width;
break;
default:
break;
}
_DrawPosition.X = x;
_DrawPosition.Y = y;
_DrawPosition.tH = h;
_DrawPosition.Width = bounds.Width;
_DrawPosition.Height = bounds.Height;
_PositionNeedsUpdate = false;
}
} }
} }
+1
View File
@@ -152,6 +152,7 @@ namespace Vocaluxe
CVideo.VdCloseAll(); CVideo.VdCloseAll();
CDraw.Unload(); CDraw.Unload();
CLog.CloseAll(); CLog.CloseAll();
CDataBase.CloseConnections();
} }
static Assembly AssemblyResolver(Object sender, ResolveEventArgs args) static Assembly AssemblyResolver(Object sender, ResolveEventArgs args)
+132 -40
View File
@@ -33,7 +33,6 @@ namespace Vocaluxe.Screens
// Version number for theme files. Increment it, if you've changed something on the theme files! // Version number for theme files. Increment it, if you've changed something on the theme files!
const int ScreenVersion = 1; const int ScreenVersion = 1;
private CStatic logo; private CStatic logo;
private CParticleEffect starsRed; private CParticleEffect starsRed;
private CParticleEffect starsBlue; private CParticleEffect starsBlue;
@@ -46,6 +45,18 @@ namespace Vocaluxe.Screens
private List<string[]> paragraphs; private List<string[]> paragraphs;
private List<CText> paragraphTexts; private List<CText> paragraphTexts;
private STexture _TexLogo;
private STexture _TexPerfectNoteStar;
private STexture _TexNameBrunzel;
private STexture _TexNameDarkice;
private STexture _TexNameFlokuep;
private STexture _TexNameMesand;
private STexture _TexNameBohning;
private STexture _TexNameBabene03;
private STexture _TexNamePantero;
private STexture _TexNamePinky007;
public CScreenCredits() public CScreenCredits()
{ {
Init(); Init();
@@ -65,23 +76,113 @@ namespace Vocaluxe.Screens
//Text for last part of credits. //Text for last part of credits.
paragraphTexts = new List<CText>(); paragraphTexts = new List<CText>();
paragraphs = new List<string[]>(); paragraphs = new List<string[]>();
string paragraph = "Inspired by the achievements of UltraStar Deluxe and its variants and pursuing the goal of making a good thing even better, we ended up rewriting the game from scratch. And a new implementation in a new programming language called for a new name - and VOCALUXE it is!";
string[] words = paragraph.Split(new Char[] { ' ' });
paragraphs.Add(words);
paragraph = "This first public version has already implemented many of the original features and it is fully compatible with all the song files in your existing song collection. The code design allows a much faster implementation of new features, thus the roadmap for the next few stable releases is packed and we expect much shorter release cycles than ever before. And, of course, our and your ideas may be the features of tomorrow."; string paragraph;
string[] words;
paragraph = "Inspired by the achievements of UltraStar Deluxe and its variants and pursuing the goal of making " +
"a good thing even better, we ended up rewriting the game from scratch. And a new implementation in a new " +
"programming language called for a new name - and VOCALUXE [ˈvoʊˈkəˈlʌks] it is!";
words = paragraph.Split(new Char[] { ' ' }); words = paragraph.Split(new Char[] { ' ' });
paragraphs.Add(words); paragraphs.Add(words);
paragraph = "We appreciate the feedback in the beta release phase and are, of course, always open for bug reports, suggestions for improve- ments and ideas for new features. We would also like to thank the translators who make Vocaluxe an international experience from the very beginning. Last, but most definitely not least, we thank all those diligent song makers out there - there's a song for everyone!"; paragraph = "This first public version has already implemented many of the original features and it is fully " +
"compatible with all the song files in your existing song collection. The code design allows a much faster " +
"implementation of new features, thus the roadmap for the next few stable releases is packed and we expect much " +
"shorter release cycles than ever before. And, of course, our and your ideas may be the features of tomorrow.";
words = paragraph.Split(new Char[] { ' ' }); words = paragraph.Split(new Char[] { ' ' });
paragraphs.Add(words); paragraphs.Add(words);
paragraph = "Go ahead and grab your mics, crank up your stereo, warm up your voice and get ready to sing to the best of your abilities!"; paragraph = "We appreciate the feedback in the beta release phase and are, of course, always open for bug reports, " +
"suggestions for improvements and ideas for new features. We would also like to thank the translators who make " +
"Vocaluxe an international experience from the very beginning and all those diligent song makers out there - " +
"there's something for everyone in the huge collection of available songs! Last but not least, thanks to " +
"Kosal Sen's Philly Sans type used in the Vocaluxe Logo.";
words = paragraph.Split(new Char[] { ' ' });
paragraphs.Add(words);
paragraph = "Go ahead and grab your mics, crank up your stereo, warm up your voice and get ready to sing to the best " +
"of your abilities!";
words = paragraph.Split(new Char[] { ' ' }); words = paragraph.Split(new Char[] { ' ' });
paragraphs.Add(words); paragraphs.Add(words);
} }
public override void LoadTheme()
{
//Vocaluxe-Logo
CDataBase.GetCreditsRessource("Logo_voc.png", ref _TexLogo);
//Little stars for logo
CDataBase.GetCreditsRessource("PerfectNoteStar.png", ref _TexPerfectNoteStar);
//brunzel
CDataBase.GetCreditsRessource("brunzel.png", ref _TexNameBrunzel);
//Darkice
CDataBase.GetCreditsRessource("Darkice.png", ref _TexNameDarkice);
//flokuep
CDataBase.GetCreditsRessource("flokuep.png", ref _TexNameFlokuep);
//bohning
CDataBase.GetCreditsRessource("bohning.png", ref _TexNameBohning);
//mesand
CDataBase.GetCreditsRessource("mesand.png", ref _TexNameMesand);
//babene03
CDataBase.GetCreditsRessource("babene03.png", ref _TexNameBabene03);
//pantero
CDataBase.GetCreditsRessource("pantero.png", ref _TexNamePantero);
//Pinky007
CDataBase.GetCreditsRessource("Pinky007.png", ref _TexNamePinky007);
//Prepare Text
int lastY = 280;
for (int i = 0; i < paragraphs.Count; i++)
{
string line = "";
for (int e = 0; e < paragraphs[i].Length; e++)
{
if (paragraphs[i][e] != null)
{
string newline = line + " " + paragraphs[i][e];
CText text = new CText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line);
if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 220))
{
line = line + " " + paragraphs[i][e];
//Check if all words are used
if ((e + 1) == paragraphs[i].Length)
{
text.Text = line;
paragraphTexts.Add(text);
line = "";
lastY += 40;
}
}
else
{
paragraphTexts.Add(text);
line = " " + paragraphs[i][e];
lastY += 27;
}
}
}
}
}
public override void ReloadTheme() {}
public override void SaveTheme() {}
public override void UnloadTextures() {}
public override void ReloadTextures() {}
public override bool HandleInput(KeyEvent KeyEvent) public override bool HandleInput(KeyEvent KeyEvent)
{ {
if (KeyEvent.KeyPressed && !Char.IsControl(KeyEvent.Unicode)) if (KeyEvent.KeyPressed && !Char.IsControl(KeyEvent.Unicode))
@@ -136,100 +237,88 @@ namespace Vocaluxe.Screens
public override void OnShow() public override void OnShow()
{ {
STexture tex = new STexture(); base.OnShow();
STexture particleTex = new STexture();
//Vocaluxe-Logo //Vocaluxe-Logo
CDataBase.GetCreditsRessource("Logo_voc.png", ref tex); logo = new CStatic(_TexLogo, new SColorF(1, 1, 1, 1), new SRectF((CSettings.iRenderW - _TexLogo.width) / 2, -270, _TexLogo.width, _TexLogo.height, -2));
logo = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF((CSettings.iRenderW - tex.width)/2, -270 , tex.width, tex.height, -2));
//Little stars for logo //Little stars for logo
CDataBase.GetCreditsRessource("PerfectNoteStar.png", ref particleTex);
int numstars = (int)(logo.Rect.W * 0.25f / 2f); int numstars = (int)(logo.Rect.W * 0.25f / 2f);
starsRed = new CParticleEffect(numstars, new SColorF(1, 0, 0, 1), new SRectF(logo.Rect.X, logo.Rect.Y, logo.Rect.W, logo.Rect.H, -1), particleTex, 35, EParticeType.Star); starsRed = new CParticleEffect(numstars, new SColorF(1, 0, 0, 1), new SRectF(logo.Rect.X, logo.Rect.Y, logo.Rect.W, logo.Rect.H, -1), _TexPerfectNoteStar, 35, EParticeType.Star);
starsBlue = new CParticleEffect(numstars, new SColorF(0.149f, 0.415f, 0.819f, 1), new SRectF(logo.Rect.X, logo.Rect.Y, logo.Rect.W, logo.Rect.H, -1), particleTex, 35, EParticeType.Star); starsBlue = new CParticleEffect(numstars, new SColorF(0.149f, 0.415f, 0.819f, 1), new SRectF(logo.Rect.X, logo.Rect.Y, logo.Rect.W, logo.Rect.H, -1), _TexPerfectNoteStar, 35, EParticeType.Star);
//Credit names //Credit names
_CreditNames = new List<CCreditName>(); _CreditNames = new List<CCreditName>();
CCreditName CreditEntry = new CCreditName(); CCreditName CreditEntry = new CCreditName();
//brunzel //brunzel
CDataBase.GetCreditsRessource("brunzel.png", ref tex);
CCreditName CreditEntryBrunzel = new CCreditName(); CCreditName CreditEntryBrunzel = new CCreditName();
CreditEntryBrunzel.image = new CStatic(tex, new SColorF(1,1,1,1), new SRectF(-450, 580, 400, 120, -4)); CreditEntryBrunzel.image = new CStatic(_TexNameBrunzel, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 400, 120, -4));
CreditEntryBrunzel.particleRect = new SRectF(CreditEntryBrunzel.image.Rect.X + 342, CreditEntryBrunzel.image.Rect.Y + 4, 30, 30, -5); CreditEntryBrunzel.particleRect = new SRectF(CreditEntryBrunzel.image.Rect.X + 342, CreditEntryBrunzel.image.Rect.Y + 4, 30, 30, -5);
CreditEntryBrunzel.particle = new CParticleEffect(8, new SColorF(1, 0, 0, 1), CreditEntryBrunzel.particleRect, particleTex, 35, EParticeType.Star); CreditEntryBrunzel.particle = new CParticleEffect(8, new SColorF(1, 0, 0, 1), CreditEntryBrunzel.particleRect, _TexPerfectNoteStar, 35, EParticeType.Star);
CreditEntryBrunzel.active = true; CreditEntryBrunzel.active = true;
CreditEntryBrunzel.direction = EDirection.Left; CreditEntryBrunzel.direction = EDirection.Left;
_CreditNames.Add(CreditEntryBrunzel); _CreditNames.Add(CreditEntryBrunzel);
//Darkice //Darkice
CDataBase.GetCreditsRessource("Darkice.png", ref tex);
CCreditName CreditEntryDarkice = new CCreditName(); CCreditName CreditEntryDarkice = new CCreditName();
CreditEntryDarkice.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 400, 120, -4)); CreditEntryDarkice.image = new CStatic(_TexNameDarkice, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 400, 120, -4));
CreditEntryDarkice.particleRect = new SRectF(CreditEntryDarkice.image.Rect.X + 242, CreditEntryDarkice.image.Rect.Y + 23, 30, 30, -5); CreditEntryDarkice.particleRect = new SRectF(CreditEntryDarkice.image.Rect.X + 242, CreditEntryDarkice.image.Rect.Y + 23, 30, 30, -5);
CreditEntryDarkice.particle = new CParticleEffect(8, new SColorF(0.149f, 0.415f ,0.819f, 1), CreditEntryDarkice.particleRect, particleTex, 35, EParticeType.Star); CreditEntryDarkice.particle = new CParticleEffect(8, new SColorF(0.149f, 0.415f, 0.819f, 1), CreditEntryDarkice.particleRect, _TexPerfectNoteStar, 35, EParticeType.Star);
CreditEntryDarkice.active = true; CreditEntryDarkice.active = true;
CreditEntryDarkice.direction = EDirection.Right; CreditEntryDarkice.direction = EDirection.Right;
_CreditNames.Add(CreditEntryDarkice); _CreditNames.Add(CreditEntryDarkice);
//flokuep //flokuep
CDataBase.GetCreditsRessource("flokuep.png", ref tex);
CCreditName CreditEntryFlokuep = new CCreditName(); CCreditName CreditEntryFlokuep = new CCreditName();
CreditEntryFlokuep.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 400, 120, -4)); CreditEntryFlokuep.image = new CStatic(_TexNameFlokuep, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 400, 120, -4));
CreditEntryFlokuep.particleRect = new SRectF(CreditEntryFlokuep.image.Rect.X + 141, CreditEntryFlokuep.image.Rect.Y - 2, 30, 30, -5); CreditEntryFlokuep.particleRect = new SRectF(CreditEntryFlokuep.image.Rect.X + 141, CreditEntryFlokuep.image.Rect.Y - 2, 30, 30, -5);
CreditEntryFlokuep.particle = new CParticleEffect(8, new SColorF(1, 0, 0, 1), CreditEntryFlokuep.particleRect, particleTex, 35, EParticeType.Star); CreditEntryFlokuep.particle = new CParticleEffect(8, new SColorF(1, 0, 0, 1), CreditEntryFlokuep.particleRect, _TexPerfectNoteStar, 35, EParticeType.Star);
CreditEntryFlokuep.active = true; CreditEntryFlokuep.active = true;
CreditEntryFlokuep.direction = EDirection.Left; CreditEntryFlokuep.direction = EDirection.Left;
_CreditNames.Add(CreditEntryFlokuep); _CreditNames.Add(CreditEntryFlokuep);
//bohning //bohning
CDataBase.GetCreditsRessource("bohning.png", ref tex);
CCreditName CreditEntryBohning = new CCreditName(); CCreditName CreditEntryBohning = new CCreditName();
CreditEntryBohning.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); CreditEntryBohning.image = new CStatic(_TexNameBohning, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4));
CreditEntryBohning.particleRect = new SRectF(CreditEntryBohning.image.Rect.X + 172, CreditEntryBohning.image.Rect.Y + 16, 10, 10, -5); CreditEntryBohning.particleRect = new SRectF(CreditEntryBohning.image.Rect.X + 172, CreditEntryBohning.image.Rect.Y + 16, 10, 10, -5);
CreditEntryBohning.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f ,0.819f, 1), CreditEntryBohning.particleRect, particleTex, 25, EParticeType.Star); CreditEntryBohning.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f, 0.819f, 1), CreditEntryBohning.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star);
CreditEntryBohning.active = true; CreditEntryBohning.active = true;
CreditEntryBohning.direction = EDirection.Right; CreditEntryBohning.direction = EDirection.Right;
_CreditNames.Add(CreditEntryBohning); _CreditNames.Add(CreditEntryBohning);
//mesand //mesand
CDataBase.GetCreditsRessource("mesand.png", ref tex);
CCreditName CreditEntryMesand = new CCreditName(); CCreditName CreditEntryMesand = new CCreditName();
CreditEntryMesand.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 350, 110, -4)); CreditEntryMesand.image = new CStatic(_TexNameMesand, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 350, 110, -4));
CreditEntryMesand.particleRect = new SRectF(CreditEntryMesand.image.Rect.X + 240, CreditEntryMesand.image.Rect.Y - 2, 10, 10, -5); CreditEntryMesand.particleRect = new SRectF(CreditEntryMesand.image.Rect.X + 240, CreditEntryMesand.image.Rect.Y - 2, 10, 10, -5);
CreditEntryMesand.particle = new CParticleEffect(4, new SColorF(1, 0, 0, 1), CreditEntryMesand.particleRect, particleTex, 25, EParticeType.Star); CreditEntryMesand.particle = new CParticleEffect(4, new SColorF(1, 0, 0, 1), CreditEntryMesand.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star);
CreditEntryMesand.active = true; CreditEntryMesand.active = true;
CreditEntryMesand.direction = EDirection.Left; CreditEntryMesand.direction = EDirection.Left;
_CreditNames.Add(CreditEntryMesand); _CreditNames.Add(CreditEntryMesand);
//babene03 //babene03
CDataBase.GetCreditsRessource("babene03.png", ref tex);
CCreditName CreditEntryBabene03 = new CCreditName(); CCreditName CreditEntryBabene03 = new CCreditName();
CreditEntryBabene03.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); CreditEntryBabene03.image = new CStatic(_TexNameBabene03, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4));
CreditEntryBabene03.particleRect = new SRectF(CreditEntryBabene03.image.Rect.X + 7, CreditEntryBabene03.image.Rect.Y + 4, 10, 10, -5); CreditEntryBabene03.particleRect = new SRectF(CreditEntryBabene03.image.Rect.X + 7, CreditEntryBabene03.image.Rect.Y + 4, 10, 10, -5);
CreditEntryBabene03.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f ,0.819f, 1), CreditEntryBabene03.particleRect, particleTex, 25, EParticeType.Star); CreditEntryBabene03.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f, 0.819f, 1), CreditEntryBabene03.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star);
CreditEntryBabene03.active = true; CreditEntryBabene03.active = true;
CreditEntryBabene03.direction = EDirection.Right; CreditEntryBabene03.direction = EDirection.Right;
_CreditNames.Add(CreditEntryBabene03); _CreditNames.Add(CreditEntryBabene03);
//pantero //pantero
CDataBase.GetCreditsRessource("pantero.png", ref tex);
CCreditName CreditEntrypantero = new CCreditName(); CCreditName CreditEntrypantero = new CCreditName();
CreditEntrypantero.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 350, 110, -4)); CreditEntrypantero.image = new CStatic(_TexNamePantero, new SColorF(1, 1, 1, 1), new SRectF(-450, 580, 350, 110, -4));
CreditEntrypantero.particleRect = new SRectF(CreditEntrypantero.image.Rect.X + 140, CreditEntrypantero.image.Rect.Y + 15, 10, 10, -5); CreditEntrypantero.particleRect = new SRectF(CreditEntrypantero.image.Rect.X + 140, CreditEntrypantero.image.Rect.Y + 15, 10, 10, -5);
CreditEntrypantero.particle = new CParticleEffect(4, new SColorF(1, 0, 0, 1), CreditEntrypantero.particleRect, particleTex, 25, EParticeType.Star); CreditEntrypantero.particle = new CParticleEffect(4, new SColorF(1, 0, 0, 1), CreditEntrypantero.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star);
CreditEntrypantero.active = true; CreditEntrypantero.active = true;
CreditEntrypantero.direction = EDirection.Left; CreditEntrypantero.direction = EDirection.Left;
_CreditNames.Add(CreditEntrypantero); _CreditNames.Add(CreditEntrypantero);
//Pinky007 //Pinky007
CDataBase.GetCreditsRessource("Pinky007.png", ref tex);
CCreditName CreditEntryPinky007 = new CCreditName(); CCreditName CreditEntryPinky007 = new CCreditName();
CreditEntryPinky007.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4)); CreditEntryPinky007.image = new CStatic(_TexNamePinky007, new SColorF(1, 1, 1, 1), new SRectF(CSettings.iRenderW, 580, 350, 110, -4));
CreditEntryPinky007.particleRect = new SRectF(CreditEntryPinky007.image.Rect.X + 42, CreditEntryPinky007.image.Rect.Y + 15, 10, 10, -5); CreditEntryPinky007.particleRect = new SRectF(CreditEntryPinky007.image.Rect.X + 42, CreditEntryPinky007.image.Rect.Y + 15, 10, 10, -5);
CreditEntryPinky007.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f ,0.819f, 1), CreditEntryPinky007.particleRect, particleTex, 25, EParticeType.Star); CreditEntryPinky007.particle = new CParticleEffect(4, new SColorF(0.149f, 0.415f, 0.819f, 1), CreditEntryPinky007.particleRect, _TexPerfectNoteStar, 25, EParticeType.Star);
CreditEntryPinky007.active = true; CreditEntryPinky007.active = true;
CreditEntryPinky007.direction = EDirection.Right; CreditEntryPinky007.direction = EDirection.Right;
_CreditNames.Add(CreditEntryPinky007); _CreditNames.Add(CreditEntryPinky007);
@@ -267,6 +356,9 @@ namespace Vocaluxe.Screens
} }
} }
} }
TextTimer.Reset();
LogoTimer.Reset();
CreditsTimer.Reset();
} }
public override void OnShowFinish() public override void OnShowFinish()
@@ -427,7 +519,7 @@ namespace Vocaluxe.Screens
if (TextTimer.IsRunning) if (TextTimer.IsRunning)
{ {
if (TextTimer.ElapsedMilliseconds > 10000) if (TextTimer.ElapsedMilliseconds > 600000)
{ {
active = false; active = false;
} }
+3 -1
View File
@@ -135,6 +135,7 @@ namespace Vocaluxe.Screens
} }
CLog.StartBenchmark(3, "Load Cover"); CLog.StartBenchmark(3, "Load Cover");
_SongLoaderThread.IsBackground = true;
_SongLoaderThread.Start(); _SongLoaderThread.Start();
_timer.Start(); _timer.Start();
@@ -153,7 +154,7 @@ namespace Vocaluxe.Screens
if (CSongs.SongsLoaded && CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART && _timer.ElapsedMilliseconds > 1000L) if (CSongs.SongsLoaded && CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART && _timer.ElapsedMilliseconds > 1000L)
{ {
CSongs.LoadCover(20L); CSongs.LoadCover(0L, 1);
} }
bool next = ((CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART && CSongs.CoverLoaded) || bool next = ((CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART && CSongs.CoverLoaded) ||
@@ -306,6 +307,7 @@ namespace Vocaluxe.Screens
_Finished = CVideo.VdFinished(_VideoStream); _Finished = CVideo.VdFinished(_VideoStream);
STexture tex = new STexture(-1); STexture tex = new STexture(-1);
tex.height = 0f;
CVideo.VdGetFrame(_VideoStream, ref tex, VideoTime, ref VideoTime); CVideo.VdGetFrame(_VideoStream, ref tex, VideoTime, ref VideoTime);
if (tex.height > 0) if (tex.height > 0)
+4
View File
@@ -140,7 +140,11 @@ namespace Vocaluxe.Screens
base.DrawFG(); base.DrawFG();
if (CSettings.VersionRevision != ERevision.Release) if (CSettings.VersionRevision != ERevision.Release)
{
CFonts.SetFont("Normal");
CFonts.Style = EStyle.Normal;
CDraw.DrawText(CSettings.GetFullVersionText(), 10, 680, 40); CDraw.DrawText(CSettings.GetFullVersionText(), 10, 680, 40);
}
return true; return true;
} }
+27 -2
View File
@@ -54,9 +54,16 @@ namespace Vocaluxe.Screens
{ {
base.HandleInput(KeyEvent); base.HandleInput(KeyEvent);
if (KeyEvent.KeyPressed && !Char.IsControl(KeyEvent.Unicode) && _SearchActive) if (KeyEvent.KeyPressed && !Char.IsControl(KeyEvent.Unicode))
{ {
if (_SearchActive)
ApplyNewSearchFilter(_SearchText + KeyEvent.Unicode); ApplyNewSearchFilter(_SearchText + KeyEvent.Unicode);
/*
else if (!Char.IsControl(KeyEvent.Unicode))
{
JumpTo(KeyEvent.Unicode);
return true;
}*/
} }
else else
{ {
@@ -128,7 +135,7 @@ namespace Vocaluxe.Screens
break; break;
case Keys.R: case Keys.R:
if (CSongs.Category != -1) if (CSongs.Category != -1 && KeyEvent.Mod == Modifier.Ctrl)
{ {
SongMenus[htSongMenus(SongMenu)].SetSelectedSong(CSongs.GetRandomSong()); SongMenus[htSongMenus(SongMenu)].SetSelectedSong(CSongs.GetRandomSong());
} }
@@ -288,6 +295,24 @@ namespace Vocaluxe.Screens
CGraphics.FadeTo(EScreens.ScreenNames); CGraphics.FadeTo(EScreens.ScreenNames);
} }
private void JumpTo(char Letter)
{
int song = SongMenus[htSongMenus(SongMenu)].GetSelectedSong();
int id = -1;
if (song > -1 && song < CSongs.NumVisibleSongs)
{
id = CSongs.VisibleSongs[song].ID;
}
// here is a fault: SetSelectedSong should point to the visible index
Vocaluxe.Lib.Song.CSong s = Array.Find<Vocaluxe.Lib.Song.CSong>(CSongs.VisibleSongs, element => element.Artist.StartsWith(Letter.ToString(), StringComparison.OrdinalIgnoreCase));
if (s != null && s.ID > -1)
{
id = s.ID;
SongMenus[htSongMenus(SongMenu)].SetSelectedSong(id);
}
}
private void ApplyNewSearchFilter(string NewFilterString) private void ApplyNewSearchFilter(string NewFilterString)
{ {
int song = SongMenus[htSongMenus(SongMenu)].GetSelectedSong(); int song = SongMenus[htSongMenus(SongMenu)].GetSelectedSong();