Using null instead of CTexture(-1) for "no texture"

This commit is contained in:
Flamefire committed 2013-05-05 20:02:28 +02:00
1 parent f370693dde
commit 142a690cc6
27 files changed
+160 -318

No files matched your search

+2 -2
View File
@@ -40,7 +40,7 @@ namespace Vocaluxe.Base
private static readonly List<CPlaylistElement> _PreviousFileNames = new List<CPlaylistElement>(); private static readonly List<CPlaylistElement> _PreviousFileNames = new List<CPlaylistElement>();
private static int _Video = -1; private static int _Video = -1;
private static CTexture _CurrentVideoTexture = new CTexture(-1); private static CTexture _CurrentVideoTexture;
private static readonly Stopwatch _FadeTimer = new Stopwatch(); private static readonly Stopwatch _FadeTimer = new Stopwatch();
private static bool _VideoEnabled; private static bool _VideoEnabled;
@@ -473,7 +473,7 @@ namespace Vocaluxe.Base
} }
return _CurrentVideoTexture; return _CurrentVideoTexture;
} }
return new CTexture(-1); return null;
} }
private static bool _IsBackgroundFile(CPlaylistElement element) private static bool _IsBackgroundFile(CPlaylistElement element)
+16 -28
View File
@@ -31,7 +31,6 @@ namespace Vocaluxe.Base
struct SCover struct SCover
{ {
public string Name; public string Name;
public string Value;
public CTexture Texture; public CTexture Texture;
} }
@@ -47,14 +46,10 @@ namespace Vocaluxe.Base
private static readonly XmlWriterSettings _Settings = new XmlWriterSettings(); private static readonly XmlWriterSettings _Settings = new XmlWriterSettings();
private static readonly List<SCover> _Cover = new List<SCover>(); private static readonly List<SCover> _Cover = new List<SCover>();
private static readonly List<SCoverTheme> _CoverThemes = new List<SCoverTheme>(); private static readonly List<SCoverTheme> _CoverThemes = new List<SCoverTheme>();
private static CTexture _NoCover = new CTexture(-1);
private static readonly Object _MutexCover = new Object(); private static readonly Object _MutexCover = new Object();
public static CTexture NoCover public static CTexture NoCover { get; private set; }
{
get { return _NoCover; }
}
public static void Init() public static void Init()
{ {
@@ -100,19 +95,15 @@ namespace Vocaluxe.Base
/// </summary> /// </summary>
public static CTexture Cover(string name) public static CTexture Cover(string name)
{ {
CTexture cov = _NoCover;
lock (_MutexCover) lock (_MutexCover)
{ {
foreach (SCover cover in _Cover) foreach (SCover cover in _Cover)
{ {
if (cover.Name == name) if (cover.Name == name)
{ return cover.Texture;
cov = cover.Texture;
break;
} }
} }
} return NoCover;
return cov;
} }
/// <summary> /// <summary>
@@ -207,31 +198,30 @@ namespace Vocaluxe.Base
List<string> cover = xmlReader.GetValues("Cover"); List<string> cover = xmlReader.GetValues("Cover");
foreach (string coverName in cover) foreach (string coverName in cover)
{ {
SCover sk = new SCover();
string name; string name;
string value; string filePath;
xmlReader.GetValue("//root/Cover/" + coverName + "/Name", out name, String.Empty); xmlReader.GetValue("//root/Cover/" + coverName + "/Name", out name, String.Empty);
xmlReader.GetValue("//root/Cover/" + coverName + "/Path", out value, String.Empty); xmlReader.GetValue("//root/Cover/" + coverName + "/Path", out filePath, String.Empty);
sk.Name = name; string coverFilePath = Path.Combine(CSettings.FolderCover, Path.Combine(coverTheme.Folder, filePath));
sk.Value = Path.Combine(coverTheme.Folder, value); if (!File.Exists(coverFilePath))
sk.Texture = File.Exists(Path.Combine(CSettings.FolderCover, sk.Value)) continue;
? CDraw.AddTexture(Path.Combine(CSettings.FolderCover, Path.Combine(coverTheme.Folder, value))) : _NoCover; SCover sk = new SCover {Name = name, Texture = CDraw.AddTexture(coverFilePath)};
_Cover.Add(sk); _Cover.Add(sk);
if (sk.Name == "NoCover") if (sk.Name == "NoCover")
_NoCover = sk.Texture; NoCover = sk.Texture;
} }
} }
} }
List<string> files = new List<string>(); List<string> files = new List<string>();
string path = Path.Combine(CSettings.FolderCover, coverTheme.Folder); string coverPath = Path.Combine(CSettings.FolderCover, coverTheme.Folder);
files.AddRange(CHelper.ListFiles(path, "*.png", true, true)); files.AddRange(CHelper.ListFiles(coverPath, "*.png", true, true));
files.AddRange(CHelper.ListFiles(path, "*.jpg", true, true)); files.AddRange(CHelper.ListFiles(coverPath, "*.jpg", true, true));
files.AddRange(CHelper.ListFiles(path, "*.jpeg", true, true)); files.AddRange(CHelper.ListFiles(coverPath, "*.jpeg", true, true));
files.AddRange(CHelper.ListFiles(path, "*.bmp", true, true)); files.AddRange(CHelper.ListFiles(coverPath, "*.bmp", true, true));
foreach (string file in files) foreach (string file in files)
@@ -241,11 +231,9 @@ namespace Vocaluxe.Base
if (_CoverExists(name)) if (_CoverExists(name))
continue; continue;
// ReSharper disable AssignNullToNotNullAttribute // ReSharper disable AssignNullToNotNullAttribute
SCover sk = new SCover {Name = name, Value = Path.Combine(coverTheme.Folder, Path.GetFileName(file))}; SCover sk = new SCover {Name = name, Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, Path.GetFileName(file)))};
// ReSharper restore AssignNullToNotNullAttribute // ReSharper restore AssignNullToNotNullAttribute
sk.Texture = CDraw.AddTexture(Path.Combine(CSettings.FolderCover, sk.Value));
_Cover.Add(sk); _Cover.Add(sk);
} }
} }
+3 -3
View File
@@ -160,9 +160,9 @@ namespace Vocaluxe.Base
return _Draw.EnqueueTexture(w, h, data); return _Draw.EnqueueTexture(w, h, data);
} }
public static bool UpdateTexture(ref CTexture texture, byte[] data) public static bool UpdateTexture(CTexture texture, byte[] data)
{ {
return _Draw.UpdateTexture(ref texture, data); return _Draw.UpdateTexture(texture, data);
} }
public static void RemoveTexture(ref CTexture texture) public static void RemoveTexture(ref CTexture texture)
@@ -197,7 +197,7 @@ namespace Vocaluxe.Base
public static void DrawTexture(CStatic staticBounds, CTexture texture, EAspect aspect) public static void DrawTexture(CStatic staticBounds, CTexture texture, EAspect aspect)
{ {
if (texture.OrigSize.Height <= 0) if (texture == null)
return; return;
RectangleF bounds = new RectangleF(staticBounds.Rect.X, staticBounds.Rect.Y, staticBounds.Rect.W, staticBounds.Rect.H); RectangleF bounds = new RectangleF(staticBounds.Rect.X, staticBounds.Rect.Y, staticBounds.Rect.W, staticBounds.Rect.H);
+3 -3
View File
@@ -203,7 +203,7 @@ namespace Vocaluxe.Base
sk.VideoIndex = CVideo.Load(Path.Combine(_Skins[skinIndex].Path, sk.Value)); sk.VideoIndex = CVideo.Load(Path.Combine(_Skins[skinIndex].Path, sk.Value));
CVideo.SetLoop(sk.VideoIndex, true); CVideo.SetLoop(sk.VideoIndex, true);
CVideo.Pause(sk.VideoIndex); CVideo.Pause(sk.VideoIndex);
sk.Texture = new CTexture(-1); sk.Texture = null;
_Skins[skinIndex].VideoList[i] = sk; _Skins[skinIndex].VideoList[i] = sk;
} }
catch (Exception e) catch (Exception e)
@@ -585,7 +585,7 @@ namespace Vocaluxe.Base
int skinIndex = GetSkinIndex(partyModeID); int skinIndex = GetSkinIndex(partyModeID);
if (skinIndex != -1 && textureName != null && _Skins[skinIndex].SkinList.ContainsKey(textureName)) if (skinIndex != -1 && textureName != null && _Skins[skinIndex].SkinList.ContainsKey(textureName))
return _Skins[skinIndex].SkinList[textureName].Texture; return _Skins[skinIndex].SkinList[textureName].Texture;
return new CTexture(-1); return null;
} }
public static string GetSkinFilePath(string skinName, int partyModeID) public static string GetSkinFilePath(string skinName, int partyModeID)
@@ -627,7 +627,7 @@ namespace Vocaluxe.Base
} }
} }
} }
return new CTexture(-1); return null;
} }
public static void SkinVideoPause(string videoName, int partyModeID) public static void SkinVideoPause(string videoName, int partyModeID)
+3 -18
View File
@@ -119,7 +119,7 @@ namespace Vocaluxe.Base
{ {
private CTexture _VideoTexture; private CTexture _VideoTexture;
private int _VideoStream; private int _VideoStream;
private readonly Stopwatch _VideoTimer; private readonly Stopwatch _VideoTimer = new Stopwatch();
private bool _Finished; private bool _Finished;
private bool _Loaded; private bool _Loaded;
@@ -133,14 +133,6 @@ namespace Vocaluxe.Base
set { CVideo.SetLoop(_VideoStream, value); } set { CVideo.SetLoop(_VideoStream, value); }
} }
public CVideoPlayer()
{
_VideoTimer = new Stopwatch();
_VideoTexture = new CTexture(-1);
_Finished = false;
_Loaded = false;
}
public void Load(string videoName) public void Load(string videoName)
{ {
_VideoStream = CVideo.Load(CTheme.GetVideoFilePath(videoName, -1)); _VideoStream = CVideo.Load(CTheme.GetVideoFilePath(videoName, -1));
@@ -172,14 +164,7 @@ namespace Vocaluxe.Base
float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f;
_Finished = CVideo.Finished(_VideoStream); _Finished = CVideo.Finished(_VideoStream);
CTexture tex = new CTexture(-1); CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime);
CVideo.GetFrame(_VideoStream, ref tex, videoTime, out videoTime);
if (tex.Index > 0)
{
CDraw.RemoveTexture(ref _VideoTexture);
_VideoTexture = tex;
}
} }
RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH);
RectangleF rect; RectangleF rect;
@@ -191,7 +176,7 @@ namespace Vocaluxe.Base
public void PreLoad() public void PreLoad()
{ {
float videoTime = 0f; float videoTime = 0f;
while (_VideoTexture.Index == -1 && videoTime < 1f) while (_VideoTexture == null && videoTime < 1f)
{ {
float dummy; float dummy;
CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy); CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy);
+1 -2
View File
@@ -49,8 +49,7 @@ namespace Vocaluxe.Base
public static bool GetFrame(ref CTexture tex) public static bool GetFrame(ref CTexture tex)
{ {
_Webcam.GetFrame(ref tex); return _Webcam.GetFrame(ref tex);
return true;
} }
public static Bitmap GetBitmap() public static Bitmap GetBitmap()
+32 -42
View File
@@ -679,9 +679,7 @@ namespace Vocaluxe.Lib.Draw
/// </summary> /// </summary>
public CTexture CopyScreen() public CTexture CopyScreen()
{ {
CTexture texture = new CTexture(-1, _W, _H); CTexture texture = new CTexture(-1, _W, _H) {W2 = _CheckForNextPowerOf2(_W), H2 = _CheckForNextPowerOf2(_H)};
texture.W2 = _CheckForNextPowerOf2(_W);
texture.H2 = _CheckForNextPowerOf2(_H);
Surface backbufferSurface = _Device.GetBackBuffer(0, 0); Surface backbufferSurface = _Device.GetBackBuffer(0, 0);
Texture tex = new Texture(_Device, _W, _H, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); Texture tex = new Texture(_Device, _W, _H, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed);
@@ -705,7 +703,7 @@ namespace Vocaluxe.Lib.Draw
public void CopyScreen(ref CTexture texture) public void CopyScreen(ref CTexture texture)
{ {
//Check for actual texture sizes! (W2/H2) as it may be up/downsized compared to OrigSize //Check for actual texture sizes! (W2/H2) as it may be up/downsized compared to OrigSize
if (!_TextureExists(ref texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) if (!_TextureExists(texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight())
{ {
RemoveTexture(ref texture); RemoveTexture(ref texture);
texture = CopyScreen(); texture = CopyScreen();
@@ -798,8 +796,11 @@ namespace Vocaluxe.Lib.Draw
/// <returns>A STexture object containing the added texture</returns> /// <returns>A STexture object containing the added texture</returns>
public CTexture AddTexture(string texturePath) public CTexture AddTexture(string texturePath)
{ {
if (File.Exists(texturePath)) if (!File.Exists(texturePath))
{ {
CLog.LogError("Can't find File: " + texturePath);
return null;
}
Bitmap bmp; Bitmap bmp;
try try
{ {
@@ -808,7 +809,7 @@ namespace Vocaluxe.Lib.Draw
catch (Exception) catch (Exception)
{ {
CLog.LogError("Error loading Texture: " + texturePath); CLog.LogError("Error loading Texture: " + texturePath);
return new CTexture(-1); return null;
} }
CTexture s; CTexture s;
try try
@@ -821,9 +822,6 @@ namespace Vocaluxe.Lib.Draw
} }
return s; return s;
} }
CLog.LogError("Can't find File: " + texturePath);
return new CTexture(-1);
}
/// <summary> /// <summary>
/// Adds a texture and stores it in the Vram /// Adds a texture and stores it in the Vram
@@ -833,7 +831,7 @@ namespace Vocaluxe.Lib.Draw
public CTexture AddTexture(Bitmap bmp) public CTexture AddTexture(Bitmap bmp)
{ {
if (bmp.Height == 0 || bmp.Width == 0) if (bmp.Height == 0 || bmp.Width == 0)
return new CTexture(-1); return null;
int maxSize; int maxSize;
//Apply the right max size //Apply the right max size
switch (CConfig.TextureQuality) switch (CConfig.TextureQuality)
@@ -909,7 +907,7 @@ namespace Vocaluxe.Lib.Draw
private CTexture _AddTexture(CTexture texture, int w, byte[] data) private CTexture _AddTexture(CTexture texture, int w, byte[] data)
{ {
Texture t = _CreateTexture(ref texture, w, data); Texture t = _CreateTexture(texture, w, data);
lock (_MutexTexture) lock (_MutexTexture)
{ {
@@ -920,7 +918,7 @@ namespace Vocaluxe.Lib.Draw
return texture; return texture;
} }
private Texture _CreateTexture(ref CTexture texture, int w, byte[] data) private Texture _CreateTexture(CTexture texture, int w, byte[] data)
{ {
//Create a new texture in the managed pool, which does not need to be recreated on a lost device //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 //because a copy of the texture is hold in the Ram
@@ -959,7 +957,7 @@ namespace Vocaluxe.Lib.Draw
{ {
_D3DTextures.Add(_IDs.Peek(), null); _D3DTextures.Add(_IDs.Peek(), null);
texture.Index = _IDs.Dequeue(); texture.Index = _IDs.Dequeue();
queue.ID = texture.Index; queue.Index = texture.Index;
_Queue.Add(queue); _Queue.Add(queue);
_Textures[texture.Index] = texture; _Textures[texture.Index] = texture;
} }
@@ -974,10 +972,10 @@ namespace Vocaluxe.Lib.Draw
/// <param name="texture">The texture to update</param> /// <param name="texture">The texture to update</param>
/// <param name="data">A byte array containing the new texture's data</param> /// <param name="data">A byte array containing the new texture's data</param>
/// <returns>True if succeeded</returns> /// <returns>True if succeeded</returns>
public bool UpdateTexture(ref CTexture texture, byte[] data) public bool UpdateTexture(CTexture texture, byte[] data)
{
if ((texture.Index >= 0) && (_Textures.Count > 0) && _TextureExists(ref texture))
{ {
if (!_TextureExists(texture))
return false;
lock (_MutexTexture) lock (_MutexTexture)
{ {
DataRectangle rect = _D3DTextures[texture.Index].LockRectangle(0, LockFlags.Discard); DataRectangle rect = _D3DTextures[texture.Index].LockRectangle(0, LockFlags.Discard);
@@ -993,8 +991,6 @@ namespace Vocaluxe.Lib.Draw
} }
return true; return true;
} }
return false;
}
#endregion updating #endregion updating
/// <summary> /// <summary>
@@ -1002,19 +998,16 @@ namespace Vocaluxe.Lib.Draw
/// </summary> /// </summary>
/// <param name="texture">The texture to check</param> /// <param name="texture">The texture to check</param>
/// <returns>True if the texture exists</returns> /// <returns>True if the texture exists</returns>
private bool _TextureExists(ref CTexture texture) private bool _TextureExists(CTexture texture)
{ {
lock (_MutexTexture) lock (_MutexTexture)
{ {
if (_Textures.ContainsKey(texture.Index)) if (texture != null && _Textures.ContainsKey(texture.Index))
{ {
if (_Textures[texture.Index].Index >= 0) if (_Textures[texture.Index].ID > 0)
{
texture = _Textures[texture.Index];
return true; return true;
} }
} }
}
return false; return false;
} }
@@ -1024,18 +1017,17 @@ namespace Vocaluxe.Lib.Draw
/// <param name="texture">The texture to be removed</param> /// <param name="texture">The texture to be removed</param>
public void RemoveTexture(ref CTexture texture) public void RemoveTexture(ref CTexture texture)
{ {
lock (_MutexTexture) if (texture != null && texture.Index >= 0)
{ {
if ((texture.Index >= 0) && (_Textures.Count > 0)) lock (_MutexTexture)
{ {
_D3DTextures[texture.Index].Dispose(); _D3DTextures[texture.Index].Dispose();
_D3DTextures.Remove(texture.Index); _D3DTextures.Remove(texture.Index);
_Textures.Remove(texture.Index); _Textures.Remove(texture.Index);
_IDs.Enqueue(texture.Index); _IDs.Enqueue(texture.Index);
texture.Index = -1;
texture.ID = -1;
} }
} }
texture = null;
} }
#region drawing #region drawing
@@ -1045,6 +1037,8 @@ namespace Vocaluxe.Lib.Draw
/// <param name="texture">The texture to be drawn</param> /// <param name="texture">The texture to be drawn</param>
public void DrawTexture(CTexture texture) public void DrawTexture(CTexture texture)
{ {
if (texture == null)
return;
DrawTexture(texture, texture.Rect, texture.Color); DrawTexture(texture, texture.Rect, texture.Color);
} }
@@ -1055,6 +1049,8 @@ namespace Vocaluxe.Lib.Draw
/// <param name="rect">A SRectF struct containing the destination coordinates</param> /// <param name="rect">A SRectF struct containing the destination coordinates</param>
public void DrawTexture(CTexture texture, SRectF rect) public void DrawTexture(CTexture texture, SRectF rect)
{ {
if (texture == null)
return;
DrawTexture(texture, rect, texture.Color); DrawTexture(texture, rect, texture.Color);
} }
@@ -1080,8 +1076,8 @@ namespace Vocaluxe.Lib.Draw
/// <param name="mirrored">True if the texture should be mirrored</param> /// <param name="mirrored">True if the texture should be mirrored</param>
public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false)
{ {
if (_TextureExists(ref texture)) if (!_TextureExists(texture))
{ return;
if (_D3DTextures[texture.Index] == null) if (_D3DTextures[texture.Index] == null)
return; return;
@@ -1159,7 +1155,6 @@ namespace Vocaluxe.Lib.Draw
_AddToVertexBuffer(vert, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); _AddToVertexBuffer(vert, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
} }
} }
}
/// <summary> /// <summary>
/// Draws a texture /// Draws a texture
@@ -1171,7 +1166,7 @@ namespace Vocaluxe.Lib.Draw
/// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param> /// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param>
public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end)
{ {
if (!_TextureExists(ref texture)) if (!_TextureExists(texture))
return; return;
if (_D3DTextures[texture.Index] == null) if (_D3DTextures[texture.Index] == null)
return; return;
@@ -1215,7 +1210,7 @@ namespace Vocaluxe.Lib.Draw
/// <param name="height">The height of the reflection</param> /// <param name="height">The height of the reflection</param>
public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height)
{ {
if (!_TextureExists(ref texture)) if (!_TextureExists(texture))
return; return;
if (_D3DTextures[texture.Index] == null) if (_D3DTextures[texture.Index] == null)
return; return;
@@ -1233,8 +1228,6 @@ namespace Vocaluxe.Lib.Draw
if (height > bounds.H) if (height > bounds.H)
height = bounds.H; height = bounds.H;
if (_TextureExists(ref texture))
{
float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio; float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio;
float x2 = (bounds.X + bounds.W - rect.X) / rect.W * texture.WidthRatio; float x2 = (bounds.X + bounds.W - rect.X) / rect.W * texture.WidthRatio;
float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * texture.HeightRatio; float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * texture.HeightRatio;
@@ -1288,7 +1281,6 @@ namespace Vocaluxe.Lib.Draw
vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()); vert[3] = new STexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb());
_AddToVertexBuffer(vert, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2)); _AddToVertexBuffer(vert, _D3DTextures[texture.Index], _CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
} }
}
#endregion drawing #endregion drawing
private void _CheckQueue() private void _CheckQueue()
@@ -1299,17 +1291,15 @@ namespace Vocaluxe.Lib.Draw
{ {
STextureQueue q = _Queue[0]; STextureQueue q = _Queue[0];
_Queue.RemoveAt(0); _Queue.RemoveAt(0);
if (!_Textures.ContainsKey(q.ID)) CTexture texture;
if (!_Textures.TryGetValue(q.Index, out texture))
continue; continue;
CTexture texture = _Textures[q.ID];
if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height)
{ {
texture.W2 = _CheckForNextPowerOf2(texture.OrigSize.Width); texture.W2 = _CheckForNextPowerOf2(texture.OrigSize.Width);
texture.H2 = _CheckForNextPowerOf2(texture.OrigSize.Height); texture.H2 = _CheckForNextPowerOf2(texture.OrigSize.Height);
Texture t = _CreateTexture(ref texture, q.Width, q.Data); Texture t = _CreateTexture(texture, q.Width, q.Data);
_D3DTextures[q.ID] = t; _D3DTextures[q.Index] = t;
_Textures[texture.Index] = texture;
} }
else else
CLog.LogError("Wrong texture size in queue!"); CLog.LogError("Wrong texture size in queue!");
+10 -16
View File
@@ -350,33 +350,26 @@ namespace Vocaluxe.Lib.Draw
public CTexture AddTexture(string texturePath) public CTexture AddTexture(string texturePath)
{ {
CTexture texture = new CTexture();
if (File.Exists(texturePath)) if (File.Exists(texturePath))
{ {
bool found = false;
foreach (CTexture tex in _Textures) foreach (CTexture tex in _Textures)
{ {
if (tex.TexturePath == texturePath) if (tex.TexturePath == texturePath)
{ return tex;
texture = tex;
found = true;
break;
} }
}
if (!found)
{
using (Bitmap bmp = new Bitmap(texturePath)) using (Bitmap bmp = new Bitmap(texturePath))
return AddTexture(bmp); {
CTexture texture = AddTexture(bmp);
texture.TexturePath = texturePath;
} }
} }
return texture; return null;
} }
public void RemoveTexture(ref CTexture texture) public void RemoveTexture(ref CTexture texture)
{ {
if ((texture.Index >= 0) && (_Textures.Count > 0)) if (texture != null && texture.Index >= 0)
{ {
for (int i = 0; i < _Textures.Count; i++) for (int i = 0; i < _Textures.Count; i++)
{ {
@@ -384,11 +377,11 @@ namespace Vocaluxe.Lib.Draw
{ {
_Bitmaps[texture.Index].Dispose(); _Bitmaps[texture.Index].Dispose();
_Textures.RemoveAt(i); _Textures.RemoveAt(i);
texture.Index = -1;
break; break;
} }
} }
} }
texture = null;
} }
public CTexture EnqueueTexture(int w, int h, byte[] data) public CTexture EnqueueTexture(int w, int h, byte[] data)
@@ -407,7 +400,7 @@ namespace Vocaluxe.Lib.Draw
} }
} }
public bool UpdateTexture(ref CTexture texture, byte[] data) public bool UpdateTexture(CTexture texture, byte[] data)
{ {
if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index)) if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index))
{ {
@@ -415,9 +408,10 @@ namespace Vocaluxe.Lib.Draw
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
Marshal.Copy(data, 0, bmpData.Scan0, data.Length); Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
_Bitmaps[texture.Index].UnlockBits(bmpData); _Bitmaps[texture.Index].UnlockBits(bmpData);
}
return true; return true;
} }
return false;
}
public void DrawTexture(CTexture texture) public void DrawTexture(CTexture texture)
{ {
+33 -43
View File
@@ -65,7 +65,7 @@ namespace Vocaluxe.Lib.Draw
struct STextureQueue struct STextureQueue
{ {
public int ID; public int Index;
public int Width; public int Width;
public int Height; public int Height;
public byte[] Data; public byte[] Data;
@@ -522,7 +522,7 @@ namespace Vocaluxe.Lib.Draw
public void CopyScreen(ref CTexture texture) public void CopyScreen(ref CTexture texture)
{ {
//Check for actual texture sizes! (W2/H2) as it may be up/downsized compared to OrigSize //Check for actual texture sizes! (W2/H2) as it may be up/downsized compared to OrigSize
if (!_TextureExists(ref texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight()) if (!_TextureExists(texture) || texture.W2 != GetScreenWidth() || texture.H2 != GetScreenHeight())
{ {
RemoveTexture(ref texture); RemoveTexture(ref texture);
texture = CopyScreen(); texture = CopyScreen();
@@ -646,8 +646,11 @@ namespace Vocaluxe.Lib.Draw
#region adding #region adding
public CTexture AddTexture(string texturePath) public CTexture AddTexture(string texturePath)
{ {
if (File.Exists(texturePath)) if (!File.Exists(texturePath))
{ {
CLog.LogError("Can't find File: " + texturePath);
return null;
}
Bitmap bmp; Bitmap bmp;
try try
{ {
@@ -656,7 +659,7 @@ namespace Vocaluxe.Lib.Draw
catch (Exception) catch (Exception)
{ {
CLog.LogError("Error loading Texture: " + texturePath); CLog.LogError("Error loading Texture: " + texturePath);
return new CTexture(-1); return null;
} }
try try
{ {
@@ -667,14 +670,11 @@ namespace Vocaluxe.Lib.Draw
bmp.Dispose(); bmp.Dispose();
} }
} }
CLog.LogError("Can't find File: " + texturePath);
return new CTexture(-1);
}
public CTexture AddTexture(Bitmap bmp) public CTexture AddTexture(Bitmap bmp)
{ {
if (bmp.Height == 0 || bmp.Width == 0) if (bmp.Height == 0 || bmp.Width == 0)
return new CTexture(-1); return null;
int maxSize; int maxSize;
switch (CConfig.TextureQuality) switch (CConfig.TextureQuality)
@@ -766,7 +766,7 @@ namespace Vocaluxe.Lib.Draw
{ {
CTexture texture = new CTexture(-1, w, h); CTexture texture = new CTexture(-1, w, h);
_CreateTexture(data, ref texture); _CreateTexture(texture, data);
lock (_MutexTexture) lock (_MutexTexture)
{ {
@@ -777,7 +777,7 @@ namespace Vocaluxe.Lib.Draw
return texture; return texture;
} }
private void _CreateTexture(byte[] data, ref CTexture texture) private void _CreateTexture(CTexture texture, byte[] data)
{ {
int w = texture.OrigSize.Width; int w = texture.OrigSize.Width;
int h = texture.OrigSize.Height; int h = texture.OrigSize.Height;
@@ -831,7 +831,7 @@ namespace Vocaluxe.Lib.Draw
lock (_MutexTexture) lock (_MutexTexture)
{ {
texture.Index = _IDs.Dequeue(); texture.Index = _IDs.Dequeue();
queue.ID = texture.Index; queue.Index = texture.Index;
_Queue.Add(queue); _Queue.Add(queue);
_Textures[texture.Index] = texture; _Textures[texture.Index] = texture;
} }
@@ -841,10 +841,10 @@ namespace Vocaluxe.Lib.Draw
#endregion adding #endregion adding
#region updating #region updating
public bool UpdateTexture(ref CTexture texture, byte[] data) public bool UpdateTexture(CTexture texture, byte[] data)
{
if (_TextureExists(ref texture))
{ {
if (!_TextureExists(texture))
return false;
if (_UsePBO) if (_UsePBO)
{ {
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO); GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO);
@@ -879,13 +879,11 @@ namespace Vocaluxe.Lib.Draw
return true; return true;
} }
return false;
}
#endregion updating #endregion updating
public void RemoveTexture(ref CTexture texture) public void RemoveTexture(ref CTexture texture)
{ {
if ((texture.Index > 0) && (_Textures.Count > 0)) if (texture != null && texture.Index > 0)
{ {
lock (_MutexTexture) lock (_MutexTexture)
{ {
@@ -894,36 +892,36 @@ namespace Vocaluxe.Lib.Draw
if (texture.PBO > 0) if (texture.PBO > 0)
GL.DeleteBuffers(1, ref texture.PBO); GL.DeleteBuffers(1, ref texture.PBO);
_Textures.Remove(texture.Index); _Textures.Remove(texture.Index);
texture.Index = -1;
texture.ID = -1;
} }
} }
texture = null;
} }
private bool _TextureExists(ref CTexture texture) private bool _TextureExists(CTexture texture)
{ {
lock (_MutexTexture) lock (_MutexTexture)
{ {
if (_Textures.ContainsKey(texture.Index)) if (texture != null && _Textures.ContainsKey(texture.Index))
{ {
if (_Textures[texture.Index].ID > 0) if (_Textures[texture.Index].ID > 0)
{
texture = _Textures[texture.Index];
return true; return true;
} }
} }
}
return false; return false;
} }
#region drawing #region drawing
public void DrawTexture(CTexture texture) public void DrawTexture(CTexture texture)
{ {
if (texture == null)
return;
DrawTexture(texture, texture.Rect, texture.Color); DrawTexture(texture, texture.Rect, texture.Color);
} }
public void DrawTexture(CTexture texture, SRectF rect) public void DrawTexture(CTexture texture, SRectF rect)
{ {
if (texture == null)
return;
DrawTexture(texture, rect, texture.Color); DrawTexture(texture, rect, texture.Color);
} }
@@ -934,6 +932,9 @@ namespace Vocaluxe.Lib.Draw
public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) public void DrawTexture(CTexture texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false)
{ {
if (!_TextureExists(texture))
return;
if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(bounds.H) < float.Epsilon || Math.Abs(bounds.W) < float.Epsilon || if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(bounds.H) < float.Epsilon || Math.Abs(bounds.W) < float.Epsilon ||
Math.Abs(color.A) < float.Epsilon) Math.Abs(color.A) < float.Epsilon)
return; return;
@@ -944,9 +945,6 @@ 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(ref texture))
return;
GL.BindTexture(TextureTarget.Texture2D, texture.ID); GL.BindTexture(TextureTarget.Texture2D, texture.ID);
float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio; float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio;
@@ -1042,8 +1040,8 @@ namespace Vocaluxe.Lib.Draw
public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end)
{ {
if (_TextureExists(ref texture)) if (!_TextureExists(texture))
{ return;
GL.BindTexture(TextureTarget.Texture2D, texture.ID); GL.BindTexture(TextureTarget.Texture2D, texture.ID);
GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Blend);
@@ -1070,10 +1068,12 @@ namespace Vocaluxe.Lib.Draw
GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Blend);
GL.BindTexture(TextureTarget.Texture2D, 0); GL.BindTexture(TextureTarget.Texture2D, 0);
} }
}
public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) public void DrawTextureReflection(CTexture texture, SRectF rect, SColorF color, SRectF bounds, float space, float height)
{ {
if (!_TextureExists(texture))
return;
if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(bounds.H) < float.Epsilon || Math.Abs(bounds.W) < float.Epsilon || if (Math.Abs(rect.W) < float.Epsilon || Math.Abs(rect.H) < float.Epsilon || Math.Abs(bounds.H) < float.Epsilon || Math.Abs(bounds.W) < float.Epsilon ||
Math.Abs(color.A) < float.Epsilon || height <= float.Epsilon) Math.Abs(color.A) < float.Epsilon || height <= float.Epsilon)
return; return;
@@ -1087,8 +1087,6 @@ namespace Vocaluxe.Lib.Draw
if (height > bounds.H) if (height > bounds.H)
height = bounds.H; height = bounds.H;
if (_TextureExists(ref texture))
{
GL.BindTexture(TextureTarget.Texture2D, texture.ID); GL.BindTexture(TextureTarget.Texture2D, texture.ID);
float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio; float x1 = (bounds.X - rect.X) / rect.W * texture.WidthRatio;
@@ -1165,7 +1163,6 @@ namespace Vocaluxe.Lib.Draw
GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Blend);
GL.BindTexture(TextureTarget.Texture2D, 0); GL.BindTexture(TextureTarget.Texture2D, 0);
} }
}
#endregion drawing #endregion drawing
public int GetTextureCount() public int GetTextureCount()
@@ -1181,19 +1178,12 @@ namespace Vocaluxe.Lib.Draw
{ {
STextureQueue q = _Queue[0]; STextureQueue q = _Queue[0];
_Queue.RemoveAt(0); _Queue.RemoveAt(0);
CTexture texture = new CTexture(-1); CTexture texture;
if (_Textures.ContainsKey(q.ID)) if (!_Textures.TryGetValue(q.Index, out texture))
texture = _Textures[q.ID];
if (texture.Index < 1)
continue; continue;
if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height)
{ _CreateTexture(texture, q.Data);
_CreateTexture(q.Data, ref texture);
_Textures[texture.Index] = texture;
}
else else
CLog.LogError("Wrong texture size in queue!"); CLog.LogError("Wrong texture size in queue!");
} }
+1 -1
View File
@@ -43,7 +43,7 @@ namespace Vocaluxe.Lib.Draw
CTexture AddTexture(Bitmap bitmap); CTexture AddTexture(Bitmap bitmap);
CTexture AddTexture(int w, int h, byte[] data); CTexture AddTexture(int w, int h, byte[] data);
CTexture EnqueueTexture(int w, int h, byte[] data); CTexture EnqueueTexture(int w, int h, byte[] data);
bool UpdateTexture(ref CTexture texture, byte[] data); bool UpdateTexture(CTexture texture, byte[] data);
void RemoveTexture(ref CTexture texture); void RemoveTexture(ref CTexture texture);
// Basic Draw Methods // Basic Draw Methods
+2 -2
View File
@@ -662,13 +662,13 @@ namespace Vocaluxe.Lib.Video
if (num >= 0) if (num >= 0)
{ {
if (frame.Index == -1 || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) if (frame == null || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height)
{ {
CDraw.RemoveTexture(ref frame); CDraw.RemoveTexture(ref frame);
frame = CDraw.AddTexture(_Width, _Height, _FrameBuffer[num].Data); frame = CDraw.AddTexture(_Width, _Height, _FrameBuffer[num].Data);
} }
else else
CDraw.UpdateTexture(ref frame, _FrameBuffer[num].Data); CDraw.UpdateTexture(frame, _FrameBuffer[num].Data);
lock (_MutexSyncSignals) lock (_MutexSyncSignals)
{ {
+2 -2
View File
@@ -122,13 +122,13 @@ namespace Vocaluxe.Lib.Video
{ {
if (data == null) if (data == null)
return; return;
if (frame.Index == -1 || width != frame.OrigSize.Width || height != frame.OrigSize.Height || data.Length == 0) if (frame == null || width != frame.OrigSize.Width || height != frame.OrigSize.Height || data.Length == 0)
{ {
CDraw.RemoveTexture(ref frame); CDraw.RemoveTexture(ref frame);
frame = CDraw.AddTexture(width, height, data); frame = CDraw.AddTexture(width, height, data);
} }
else else
CDraw.UpdateTexture(ref frame, data); CDraw.UpdateTexture(frame, data);
data = null; data = null;
} }
} }
+2 -2
View File
@@ -57,13 +57,13 @@ namespace Vocaluxe.Lib.Webcam
{ {
lock (_MutexData) lock (_MutexData)
{ {
if (frame.Index == -1 || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height) if (frame == null || _Width != frame.OrigSize.Width || _Height != frame.OrigSize.Height)
{ {
CDraw.RemoveTexture(ref frame); CDraw.RemoveTexture(ref frame);
frame = CDraw.AddTexture(_Width, _Height, _Data); frame = CDraw.AddTexture(_Width, _Height, _Data);
} }
else else
CDraw.UpdateTexture(ref frame, _Data); CDraw.UpdateTexture(frame, _Data);
} }
} }
return false; return false;
+1 -1
View File
@@ -46,7 +46,7 @@ namespace Vocaluxe.Screens
private const string _ButtonExit = "ButtonExit"; private const string _ButtonExit = "ButtonExit";
private SWebcamConfig _Config; private SWebcamConfig _Config;
private CTexture _WebcamTexture = new CTexture(-1); private CTexture _WebcamTexture;
private int _DeviceNr; private int _DeviceNr;
private int _CapabilityNr; private int _CapabilityNr;
+3 -3
View File
@@ -61,7 +61,7 @@ namespace Vocaluxe.Screens
private EEditMode _EditMode; private EEditMode _EditMode;
private CTexture _WebcamTexture = new CTexture(-1); private CTexture _WebcamTexture;
private Bitmap _Snapshot; private Bitmap _Snapshot;
public override void Init() public override void Init()
@@ -210,7 +210,7 @@ namespace Vocaluxe.Screens
{ {
CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection, CProfiles.SetAvatar(_SelectSlides[_SelectSlideProfiles].Selection,
_SelectSlides[_SelectSlideAvatars].Selection); _SelectSlides[_SelectSlideAvatars].Selection);
if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0) if (CWebcam.IsDeviceAvailable() && _WebcamTexture != null)
_OnDiscardSnapshot(); _OnDiscardSnapshot();
} }
else if (_SelectSlides[_SelectSlideGuestProfile].Selected) else if (_SelectSlides[_SelectSlideGuestProfile].Selected)
@@ -311,7 +311,7 @@ namespace Vocaluxe.Screens
int avatarNr = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection); int avatarNr = CProfiles.GetAvatarNr(_SelectSlides[_SelectSlideProfiles].Selection);
_SelectSlides[_SelectSlideAvatars].Selection = avatarNr; _SelectSlides[_SelectSlideAvatars].Selection = avatarNr;
if (CWebcam.IsDeviceAvailable() && _WebcamTexture.Index > 0) if (CWebcam.IsDeviceAvailable() && _WebcamTexture != null)
{ {
if (_Snapshot == null) if (_Snapshot == null)
CWebcam.GetFrame(ref _WebcamTexture); CWebcam.GetFrame(ref _WebcamTexture);
+1 -1
View File
@@ -368,7 +368,7 @@ namespace Vocaluxe.Screens
_Statics[_StaticPointsBarBG[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; _Statics[_StaticPointsBarBG[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer;
_Statics[_StaticAvatar[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer; _Statics[_StaticAvatar[player, numplayer]].Visible = numplayer + 1 == CGame.NumPlayer;
_Statics[_StaticAvatar[player, numplayer]].Texture = new CTexture(-1); _Statics[_StaticAvatar[player, numplayer]].Texture = null;
} }
} }
} }
+12 -10
View File
@@ -97,9 +97,9 @@ namespace Vocaluxe.Screens
private const float _Volume = 100f; private const float _Volume = 100f;
private int _CurrentVideo = -1; private int _CurrentVideo = -1;
private EAspect _VideoAspect = EAspect.Crop; private EAspect _VideoAspect = EAspect.Crop;
private CTexture _CurrentVideoTexture = new CTexture(-1); private CTexture _CurrentVideoTexture;
private CTexture _CurrentWebcamFrameTexture = new CTexture(-1); private CTexture _CurrentWebcamFrameTexture;
private CTexture _Background = new CTexture(-1); private CTexture _Background;
private float _CurrentTime; private float _CurrentTime;
private float _FinishTime; private float _FinishTime;
@@ -412,8 +412,8 @@ namespace Vocaluxe.Screens
_FadeOut = false; _FadeOut = false;
_CurrentVideo = -1; _CurrentVideo = -1;
_CurrentVideoTexture = new CTexture(-1); _CurrentVideoTexture = null;
_CurrentWebcamFrameTexture = new CTexture(-1); _CurrentWebcamFrameTexture = null;
_CurrentBeat = -100; _CurrentBeat = -100;
_CurrentTime = 0f; _CurrentTime = 0f;
_FinishTime = 0f; _FinishTime = 0f;
@@ -468,12 +468,14 @@ namespace Vocaluxe.Screens
} }
else else
background = _Background; background = _Background;
if (background != null)
{
RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH); RectangleF bounds = new RectangleF(0, 0, CSettings.RenderW, CSettings.RenderH);
RectangleF rect; RectangleF rect;
CHelper.SetRect(bounds, out rect, (float)background.OrigAspect, aspect); CHelper.SetRect(bounds, out rect, background.OrigAspect, aspect);
CDraw.DrawTexture(background, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f),
CDraw.DrawTexture(_Background, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, 0f), background.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f));
_Background.Color, new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f)); }
} }
_DrawBG(); _DrawBG();
@@ -1354,7 +1356,7 @@ namespace Vocaluxe.Screens
foreach (CLine line in voice.Lines.Where(line => line.VisibleInTimeLine)) foreach (CLine line in voice.Lines.Where(line => line.VisibleInTimeLine))
{ {
STimeRect trect = new STimeRect {StartBeat = line.FirstNoteBeat, EndBeat = line.EndBeat}; STimeRect trect = new STimeRect {StartBeat = line.FirstNoteBeat, EndBeat = line.EndBeat};
trect.Rect = GetNewStatic(new CTexture(-1), trect.Rect = GetNewStatic(null,
new SColorF(1f, 1f, 1f, 1f), new SColorF(1f, 1f, 1f, 1f),
new SRectF( new SRectF(
stat.Rect.X + stat.Rect.W * ((CGame.GetTimeFromBeats(trect.StartBeat, song.BPM) + song.Gap - song.Start) / totalTime), stat.Rect.X + stat.Rect.W * ((CGame.GetTimeFromBeats(trect.StartBeat, song.BPM) + song.Gap - song.Start) / totalTime),
+6 -23
View File
@@ -6,11 +6,11 @@ namespace VocaluxeLib.Draw
{ {
public class CTexture public class CTexture
{ {
public int Index; public int Index = -1;
public int PBO; public int PBO;
public int ID; public int ID = -1;
public string TexturePath; public string TexturePath = "";
/// <summary> /// <summary>
/// Original size (e.g. of bmp) /// Original size (e.g. of bmp)
@@ -26,10 +26,9 @@ namespace VocaluxeLib.Draw
/// </summary> /// </summary>
public SRectF Rect; public SRectF Rect;
public SColorF Color; public SColorF Color = new SColorF(1f, 1f, 1f, 1f);
private int _W2, _H2; private int _W2, _H2;
private float _WidthRatio, _HeightRatio;
private bool _UseFullTexture; private bool _UseFullTexture;
/// <summary> /// <summary>
/// Internal texture width (on device), a power of 2 if necessary /// Internal texture width (on device), a power of 2 if necessary
@@ -61,19 +60,11 @@ namespace VocaluxeLib.Draw
/// <summary> /// <summary>
/// Internal use. Specifies which part of texture memory is actually used /// Internal use. Specifies which part of texture memory is actually used
/// </summary> /// </summary>
public float WidthRatio public float WidthRatio { get; private set; }
{
get { return _WidthRatio; }
private set { _WidthRatio = value; }
}
/// <summary> /// <summary>
/// Internal use. Specifies which part of texture memory is actually used /// Internal use. Specifies which part of texture memory is actually used
/// </summary> /// </summary>
public float HeightRatio public float HeightRatio { get; private set; }
{
get { return _HeightRatio; }
private set { _HeightRatio = value; }
}
/// <summary> /// <summary>
/// Internal use. Specifies if full texture memory should be used /// Internal use. Specifies if full texture memory should be used
@@ -101,20 +92,12 @@ namespace VocaluxeLib.Draw
public CTexture(int index, int origWidth = 1, int origHeight = 1) public CTexture(int index, int origWidth = 1, int origHeight = 1)
{ {
Index = index; Index = index;
PBO = 0;
ID = -1;
TexturePath = String.Empty;
OrigSize = new Size(origWidth, origHeight); OrigSize = new Size(origWidth, origHeight);
Rect = new SRectF(0f, 0f, origWidth, origHeight, 0f); Rect = new SRectF(0f, 0f, origWidth, origHeight, 0f);
Color = new SColorF(1f, 1f, 1f, 1f);
_W2 = origWidth; _W2 = origWidth;
_H2 = origHeight; _H2 = origHeight;
_WidthRatio = 1;
_HeightRatio = 1;
_UseFullTexture = false;
} }
} }
} }
+2 -23
View File
@@ -80,8 +80,8 @@ namespace VocaluxeLib.Menu
Text.Selected = value; Text.Selected = value;
} }
} }
public bool Visible; public bool Visible = true;
public bool Enabled; public bool Enabled = true;
public string GetThemeName() public string GetThemeName()
{ {
@@ -91,28 +91,10 @@ namespace VocaluxeLib.Menu
public CButton(int partyModeID) public CButton(int partyModeID)
{ {
_PartyModeID = partyModeID; _PartyModeID = partyModeID;
_Theme = new SThemeButton();
Rect = new SRectF();
Color = new SColorF();
SelColor = new SColorF();
Texture = new CTexture(-1);
SelTexture = new CTexture(-1);
_IsSelText = false;
Text = new CText(_PartyModeID); Text = new CText(_PartyModeID);
_SelText = new CText(_PartyModeID); _SelText = new CText(_PartyModeID);
Selected = false; Selected = false;
Visible = true;
EditMode = false; EditMode = false;
Enabled = true;
_Reflection = false;
_ReflectionSpace = 0f;
_ReflectionHeight = 0f;
_SelReflection = false;
_SelReflectionSpace = 0f;
_SelReflectionHeight = 0f;
} }
public CButton(CButton button) public CButton(CButton button)
@@ -132,13 +114,10 @@ namespace VocaluxeLib.Menu
Texture = button.Texture; Texture = button.Texture;
SelTexture = button.SelTexture; SelTexture = button.SelTexture;
_IsSelText = false;
Text = new CText(button.Text); Text = new CText(button.Text);
_SelText = new CText(button._SelText); _SelText = new CText(button._SelText);
Selected = false; Selected = false;
Visible = true;
EditMode = false; EditMode = false;
_ThemeLoaded = false;
Enabled = button.Enabled; Enabled = button.Enabled;
_Reflection = button._Reflection; _Reflection = button._Reflection;
+3 -15
View File
@@ -50,7 +50,7 @@ namespace VocaluxeLib.Menu
private SRectF _Rect; private SRectF _Rect;
private float _Size; private float _Size;
private SColorF _Color; private SColorF _Color;
private float _Alpha; private float _Alpha = 1;
private float _Angle; //0..360° private float _Angle; //0..360°
private readonly float _MaxAge; //[s] private readonly float _MaxAge; //[s]
private float _Age; //[s] private float _Age; //[s]
@@ -62,7 +62,7 @@ namespace VocaluxeLib.Menu
private float _LastTime; private float _LastTime;
private readonly EParticleType _Type; private readonly EParticleType _Type;
private readonly Stopwatch _Timer; private readonly Stopwatch _Timer = new Stopwatch();
#endregion private vars #endregion private vars
#region public vars #region public vars
@@ -116,21 +116,15 @@ namespace VocaluxeLib.Menu
{ {
_PartyModeID = partyModeID; _PartyModeID = partyModeID;
_TextureName = textureName; _TextureName = textureName;
_Texture = new CTexture(-1);
_Color = color; _Color = color;
_Rect = new SRectF(x, y, size, size, z); _Rect = new SRectF(x, y, size, size, z);
_Size = size; _Size = size;
_Alpha = 1f;
_Angle = 0f;
_Vx = vx; _Vx = vx;
_Vy = vy; _Vy = vy;
_Vr = vr; _Vr = vr;
_Vsize = vsize; _Vsize = vsize;
_LastTime = 0f;
_Type = type; _Type = type;
_Timer = new Stopwatch();
_Age = 0f;
_MaxAge = maxage; _MaxAge = maxage;
_Rotation = (float)(CBase.Game.GetRandomDouble() * 360.0); _Rotation = (float)(CBase.Game.GetRandomDouble() * 360.0);
} }
@@ -144,17 +138,12 @@ namespace VocaluxeLib.Menu
_Color = color; _Color = color;
_Rect = new SRectF(x, y, size, size, z); _Rect = new SRectF(x, y, size, size, z);
_Size = size; _Size = size;
_Alpha = 1f;
_Angle = 0f;
_Vx = vx; _Vx = vx;
_Vy = vy; _Vy = vy;
_Vr = vr; _Vr = vr;
_Vsize = vsize; _Vsize = vsize;
_LastTime = 0f;
_Type = type; _Type = type;
_Timer = new Stopwatch();
_Age = 0f;
_MaxAge = maxage; _MaxAge = maxage;
_Rotation = (float)(CBase.Game.GetRandomDouble() * 360.0); _Rotation = (float)(CBase.Game.GetRandomDouble() * 360.0);
} }
@@ -357,7 +346,6 @@ namespace VocaluxeLib.Menu
Rect = rect; Rect = rect;
Color = color; Color = color;
_Theme.TextureName = textureName; _Theme.TextureName = textureName;
Texture = new CTexture(-1);
_MaxNumber = maxNumber; _MaxNumber = maxNumber;
_Size = size; _Size = size;
_Type = type; _Type = type;
@@ -603,7 +591,7 @@ namespace VocaluxeLib.Menu
public void UnloadTextures() public void UnloadTextures()
{ {
Texture = new CTexture(); Texture = null;
} }
public void LoadTextures() public void LoadTextures()
+3 -8
View File
@@ -531,7 +531,7 @@ namespace VocaluxeLib.Menu
public void AddValue(string value, int partyModeID) public void AddValue(string value, int partyModeID)
{ {
AddValue(value, new CTexture(-1), _ValueIndexes.Count, partyModeID); AddValue(value, null, _ValueIndexes.Count, partyModeID);
} }
public void AddValue(string value, CTexture texture) public void AddValue(string value, CTexture texture)
@@ -560,7 +560,7 @@ namespace VocaluxeLib.Menu
public void AddValues(IEnumerable<string> values) public void AddValues(IEnumerable<string> values)
{ {
foreach (string value in values) foreach (string value in values)
_AddValue(value, new CTexture(-1), _PartyModeID); _AddValue(value, null, _PartyModeID);
_ValueBounds.Clear(); _ValueBounds.Clear();
} }
@@ -589,12 +589,7 @@ namespace VocaluxeLib.Menu
RenameValue(Selection, newName); RenameValue(Selection, newName);
} }
public void RenameValue(int selection, string newName) public void RenameValue(int selection, string newName, CTexture newTexture = null)
{
RenameValue(selection, newName, new CTexture(-1));
}
public void RenameValue(int selection, string newName, CTexture newTexture)
{ {
if (selection < 0 && selection >= _ValueNames.Count) if (selection < 0 && selection >= _ValueNames.Count)
return; return;
+5 -39
View File
@@ -46,7 +46,7 @@ namespace VocaluxeLib.Menu
private CTexture _Texture; private CTexture _Texture;
public CTexture Texture public CTexture Texture
{ {
get { return _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); } get { return _Texture?? CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); }
set { _Texture = value; } set { _Texture = value; }
} }
@@ -59,35 +59,20 @@ namespace VocaluxeLib.Menu
public float ReflectionHeight; public float ReflectionHeight;
public bool Selected; public bool Selected;
public bool Visible; public bool Visible=true;
public float Alpha; public float Alpha=1;
public EAspect Aspect = EAspect.Stretch; public EAspect Aspect = EAspect.Stretch;
public CStatic(int partyModeID) public CStatic(int partyModeID)
{ {
_PartyModeID = partyModeID; _PartyModeID = partyModeID;
_Theme = new SThemeStatic();
_ThemeLoaded = false;
_Texture = new CTexture(-1);
Color = new SColorF();
Rect = new SRectF();
Reflection = false;
ReflectionSpace = 0f;
ReflectionHeight = 0f;
Selected = false;
Alpha = 1f;
Visible = true;
} }
public CStatic(CStatic s) public CStatic(CStatic s)
{ {
_PartyModeID = s._PartyModeID; _PartyModeID = s._PartyModeID;
_Theme = new SThemeStatic();
_ThemeLoaded = false;
_Texture = s.Texture; _Texture = s.Texture;
Color = new SColorF(s.Color); Color = new SColorF(s.Color);
@@ -104,37 +89,18 @@ namespace VocaluxeLib.Menu
public CStatic(int partyModeID, CTexture texture, SColorF color, SRectF rect) public CStatic(int partyModeID, CTexture texture, SColorF color, SRectF rect)
{ {
_PartyModeID = partyModeID; _PartyModeID = partyModeID;
_Theme = new SThemeStatic();
_ThemeLoaded = false;
_Texture = texture; _Texture = texture;
Color = color; Color = color;
Rect = rect; Rect = rect;
Reflection = false;
ReflectionSpace = 0f;
ReflectionHeight = 0f;
Selected = false;
Alpha = 1f;
Visible = true;
} }
public CStatic(int partyModeID, string textureSkinName, SColorF color, SRectF rect) public CStatic(int partyModeID, string textureSkinName, SColorF color, SRectF rect)
{ {
_PartyModeID = partyModeID; _PartyModeID = partyModeID;
_Theme = new SThemeStatic {TextureName = textureSkinName}; _Theme.TextureName = textureSkinName;
_ThemeLoaded = false;
_Texture = new CTexture(-1);
Color = color; Color = color;
Rect = rect; Rect = rect;
Reflection = false;
ReflectionSpace = 0f;
ReflectionHeight = 0f;
Selected = false;
Alpha = 1f;
Visible = true;
} }
public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex) public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex)
@@ -239,7 +205,7 @@ namespace VocaluxeLib.Menu
public void Draw(float scale, float z, EAspect aspect, bool forceDraw = false) public void Draw(float scale, float z, EAspect aspect, bool forceDraw = false)
{ {
CTexture texture = _Texture.Index != -1 ? _Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); CTexture texture = Texture;
SRectF bounds = new SRectF( SRectF bounds = new SRectF(
Rect.X - Rect.W * (scale - 1f), Rect.X - Rect.W * (scale - 1f),
+3 -5
View File
@@ -25,9 +25,8 @@ namespace VocaluxeLib.Menu.SongMenu
public class CCategory public class CCategory
{ {
public readonly string Name; public readonly string Name;
private CTexture _CoverTextureSmall = new CTexture(-1); private CTexture _CoverTextureSmall;
private CTexture _CoverTextureBig = new CTexture(-1); private CTexture _CoverTextureBig;
private bool _CoverBigLoaded;
public readonly List<CSongPointer> Songs = new List<CSongPointer>(); public readonly List<CSongPointer> Songs = new List<CSongPointer>();
public CCategory(string name) public CCategory(string name)
@@ -44,13 +43,12 @@ namespace VocaluxeLib.Menu.SongMenu
public CTexture CoverTextureBig public CTexture CoverTextureBig
{ {
get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } get { return _CoverTextureBig ?? _CoverTextureSmall; }
set set
{ {
if (value.Index == -1) if (value.Index == -1)
return; return;
_CoverTextureBig = value; _CoverTextureBig = value;
_CoverBigLoaded = true;
} }
} }
+7 -21
View File
@@ -70,10 +70,8 @@ namespace VocaluxeLib.Menu.SongMenu
public class CSong public class CSong
{ {
private bool _CoverSmallLoaded; private CTexture _CoverTextureSmall;
private bool _CoverBigLoaded; private CTexture _CoverTextureBig;
private CTexture _CoverTextureSmall = new CTexture(-1);
private CTexture _CoverTextureBig = new CTexture(-1);
public SMedley Medley; public SMedley Medley;
@@ -101,26 +99,18 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
get get
{ {
if (!_CoverSmallLoaded) if (_CoverTextureSmall == null)
LoadSmallCover(); LoadSmallCover();
return _CoverTextureSmall; return _CoverTextureSmall;
} }
set set { _CoverTextureSmall = value; }
{
_CoverTextureSmall = value;
_CoverSmallLoaded = true;
}
} }
public CTexture CoverTextureBig public CTexture CoverTextureBig
{ {
get { return _CoverBigLoaded ? _CoverTextureBig : _CoverTextureSmall; } get { return _CoverTextureBig ?? _CoverTextureSmall; }
set set { _CoverTextureBig = value; }
{
_CoverTextureBig = value;
_CoverBigLoaded = true;
}
} }
public string Title = String.Empty; public string Title = String.Empty;
@@ -215,8 +205,6 @@ namespace VocaluxeLib.Menu.SongMenu
VideoFileName = song.VideoFileName; VideoFileName = song.VideoFileName;
VideoAspect = song.VideoAspect; VideoAspect = song.VideoAspect;
_CoverSmallLoaded = song._CoverSmallLoaded;
_CoverBigLoaded = song._CoverBigLoaded;
NotesLoaded = song.NotesLoaded; NotesLoaded = song.NotesLoaded;
Artist = song.Artist; Artist = song.Artist;
@@ -751,7 +739,7 @@ namespace VocaluxeLib.Menu.SongMenu
public void LoadSmallCover() public void LoadSmallCover()
{ {
if (_CoverSmallLoaded) if (_CoverTextureSmall != null)
return; return;
if (CoverFileName != "") if (CoverFileName != "")
{ {
@@ -760,8 +748,6 @@ namespace VocaluxeLib.Menu.SongMenu
} }
else else
_CoverTextureSmall = CBase.Cover.GetNoCover(); _CoverTextureSmall = CBase.Cover.GetNoCover();
_CoverSmallLoaded = true;
} }
private void _CheckFiles() private void _CheckFiles()
@@ -105,7 +105,7 @@ namespace VocaluxeLib.Menu.SongMenu
private readonly List<int> _Streams = new List<int>(); private readonly List<int> _Streams = new List<int>();
private int _Actsong = -1; private int _Actsong = -1;
private int _Actsongstream = -1; private int _Actsongstream = -1;
protected CTexture _Vidtex = new CTexture(-1); protected CTexture _Vidtex;
protected bool _Initialized; protected bool _Initialized;
protected int _LastKnownNumSongs; protected int _LastKnownNumSongs;
@@ -464,7 +464,7 @@ namespace VocaluxeLib.Menu.SongMenu
public virtual void OnShow() public virtual void OnShow()
{ {
_Actsongstream = -1; _Actsongstream = -1;
_Vidtex = new CTexture(-1); _Vidtex = null;
} }
public virtual void OnHide() public virtual void OnHide()
@@ -453,8 +453,7 @@ namespace VocaluxeLib.Menu.SongMenu
_TextBG.Draw(); _TextBG.Draw();
if (_Vidtex != null && _Video != -1)
if (_Vidtex.Index != -1 && _Video != -1)
{ {
if (_Vidtex.Color.A < 1) if (_Vidtex.Color.A < 1)
_CoverBig.Draw(1f, EAspect.Crop); _CoverBig.Draw(1f, EAspect.Crop);
+1 -1
View File
@@ -201,7 +201,7 @@ namespace VocaluxeLib.Menu
// ReSharper restore UnusedParameter.Local // ReSharper restore UnusedParameter.Local
{ {
FileName = String.Empty; FileName = String.Empty;
Texture = new CTexture(-1); Texture = null;
} }
} }
#endregion Profiles #endregion Profiles