Changed usage of CTexture.Index: You only need to check for null as of last commit
This commit is contained in:
1 parent
142a690cc6
commit
e43f5e7b0a
8 files changed
+37
-51
No files matched your search
@@ -130,7 +130,7 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
CTexture tex = CDraw.AddTexture(file);
|
CTexture tex = CDraw.AddTexture(file);
|
||||||
|
|
||||||
if (tex.Index != -1)
|
if (tex != null)
|
||||||
{
|
{
|
||||||
SAvatar avatar = new SAvatar {Texture = tex, FileName = Path.GetFileName(file)};
|
SAvatar avatar = new SAvatar {Texture = tex, FileName = Path.GetFileName(file)};
|
||||||
_Avatars.Add(avatar);
|
_Avatars.Add(avatar);
|
||||||
|
|||||||
@@ -1002,13 +1002,8 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
lock (_MutexTexture)
|
lock (_MutexTexture)
|
||||||
{
|
{
|
||||||
if (texture != null && _Textures.ContainsKey(texture.Index))
|
return texture != null && _Textures.ContainsKey(texture.Index);
|
||||||
{
|
|
||||||
if (_Textures[texture.Index].ID > 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1017,7 +1012,7 @@ 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)
|
||||||
{
|
{
|
||||||
if (texture != null && texture.Index >= 0)
|
if (_TextureExists(texture))
|
||||||
{
|
{
|
||||||
lock (_MutexTexture)
|
lock (_MutexTexture)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
private bool _TopMost;
|
private bool _TopMost;
|
||||||
private Rectangle _Bounds;
|
private Rectangle _Bounds;
|
||||||
|
|
||||||
private readonly List<CTexture> _Textures;
|
private readonly Dictionary<int, CTexture> _Textures = new Dictionary<int, CTexture>();
|
||||||
private readonly List<Bitmap> _Bitmaps;
|
private readonly List<Bitmap> _Bitmaps = new List<Bitmap>();
|
||||||
|
|
||||||
private readonly Color _ClearColor = Color.DarkBlue;
|
private readonly Color _ClearColor = Color.DarkBlue;
|
||||||
|
|
||||||
@@ -55,9 +55,6 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon));
|
Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon));
|
||||||
|
|
||||||
_Textures = new List<CTexture>();
|
|
||||||
_Bitmaps = new List<Bitmap>();
|
|
||||||
|
|
||||||
_Keys = new CKeys();
|
_Keys = new CKeys();
|
||||||
_Mouse = new CMouse();
|
_Mouse = new CMouse();
|
||||||
ClientSize = new Size(1280, 720);
|
ClientSize = new Size(1280, 720);
|
||||||
@@ -297,14 +294,14 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height);
|
CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height);
|
||||||
|
|
||||||
// Add to Texture List
|
// Add to Texture List
|
||||||
_Textures.Add(texture);
|
_Textures[texture.Index] = texture;
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyScreen(ref CTexture texture)
|
public void CopyScreen(ref CTexture texture)
|
||||||
{
|
{
|
||||||
if (texture.Index == 0 || 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();
|
||||||
@@ -341,9 +338,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height);
|
CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height);
|
||||||
|
|
||||||
// Add to Texture List
|
// Add to Texture List
|
||||||
texture.TexturePath = String.Empty;
|
_Textures[texture.Index] = texture;
|
||||||
|
|
||||||
_Textures.Add(texture);
|
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
@@ -352,7 +347,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
if (File.Exists(texturePath))
|
if (File.Exists(texturePath))
|
||||||
{
|
{
|
||||||
foreach (CTexture tex in _Textures)
|
foreach (CTexture tex in _Textures.Values)
|
||||||
{
|
{
|
||||||
if (tex.TexturePath == texturePath)
|
if (tex.TexturePath == texturePath)
|
||||||
return tex;
|
return tex;
|
||||||
@@ -367,19 +362,17 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _TextureExists(CTexture texture)
|
||||||
|
{
|
||||||
|
return texture != null && _Textures.ContainsKey(texture.Index);
|
||||||
|
}
|
||||||
|
|
||||||
public void RemoveTexture(ref CTexture texture)
|
public void RemoveTexture(ref CTexture texture)
|
||||||
{
|
{
|
||||||
if (texture != null && texture.Index >= 0)
|
if (_TextureExists(texture))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _Textures.Count; i++)
|
_Bitmaps[texture.Index].Dispose();
|
||||||
{
|
_Textures.Remove(texture.Index);
|
||||||
if (_Textures[i].Index == texture.Index)
|
|
||||||
{
|
|
||||||
_Bitmaps[texture.Index].Dispose();
|
|
||||||
_Textures.RemoveAt(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
texture = null;
|
texture = null;
|
||||||
}
|
}
|
||||||
@@ -402,7 +395,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
|
|
||||||
public bool UpdateTexture(CTexture texture, byte[] data)
|
public bool UpdateTexture(CTexture texture, byte[] data)
|
||||||
{
|
{
|
||||||
if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index))
|
if (_TextureExists(texture))
|
||||||
{
|
{
|
||||||
BitmapData bmpData = _Bitmaps[texture.Index].LockBits(new Rectangle(0, 0, _Bitmaps[texture.Index].Width, _Bitmaps[texture.Index].Height),
|
BitmapData bmpData = _Bitmaps[texture.Index].LockBits(new Rectangle(0, 0, _Bitmaps[texture.Index].Width, _Bitmaps[texture.Index].Height),
|
||||||
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||||
@@ -415,30 +408,29 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
|
|
||||||
public void DrawTexture(CTexture texture)
|
public void DrawTexture(CTexture texture)
|
||||||
{
|
{
|
||||||
if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index))
|
if (texture != null)
|
||||||
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.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index))
|
if (texture != null)
|
||||||
DrawTexture(texture, rect, texture.Color);
|
DrawTexture(texture, rect, texture.Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTexture(CTexture texture, SRectF rect, SColorF color, bool mirrored = false)
|
public void DrawTexture(CTexture texture, SRectF rect, SColorF color, bool mirrored = false)
|
||||||
{
|
{
|
||||||
if ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index))
|
if (texture != null)
|
||||||
DrawTexture(texture, rect, color, rect, mirrored);
|
DrawTexture(texture, rect, color, rect, mirrored);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ((texture.Index >= 0) && (_Textures.Count > 0) && (_Bitmaps.Count > texture.Index))
|
if (!_TextureExists(texture))
|
||||||
{
|
return;
|
||||||
Bitmap coloredBitmap = _ColorizeBitmap(_Bitmaps[texture.Index], color);
|
Bitmap coloredBitmap = _ColorizeBitmap(_Bitmaps[texture.Index], color);
|
||||||
_G.DrawImage(coloredBitmap, new RectangleF(rect.X, rect.Y, rect.W, rect.H));
|
_G.DrawImage(coloredBitmap, new RectangleF(rect.X, rect.Y, rect.W, rect.H));
|
||||||
coloredBitmap.Dispose();
|
coloredBitmap.Dispose();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {}
|
||||||
|
|||||||
@@ -883,7 +883,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
|
|
||||||
public void RemoveTexture(ref CTexture texture)
|
public void RemoveTexture(ref CTexture texture)
|
||||||
{
|
{
|
||||||
if (texture != null && texture.Index > 0)
|
if (_TextureExists(texture, false))
|
||||||
{
|
{
|
||||||
lock (_MutexTexture)
|
lock (_MutexTexture)
|
||||||
{
|
{
|
||||||
@@ -897,13 +897,13 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
texture = null;
|
texture = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _TextureExists(CTexture texture)
|
private bool _TextureExists(CTexture texture, bool checkIfLoaded = true)
|
||||||
{
|
{
|
||||||
lock (_MutexTexture)
|
lock (_MutexTexture)
|
||||||
{
|
{
|
||||||
if (texture != null && _Textures.ContainsKey(texture.Index))
|
if (texture != null && _Textures.ContainsKey(texture.Index))
|
||||||
{
|
{
|
||||||
if (_Textures[texture.Index].ID > 0)
|
if (!checkIfLoaded || _Textures[texture.Index].ID > 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Drawing;
|
||||||
using System.Drawing;
|
|
||||||
using VocaluxeLib.Menu;
|
using VocaluxeLib.Menu;
|
||||||
|
|
||||||
namespace VocaluxeLib.Draw
|
namespace VocaluxeLib.Draw
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ namespace VocaluxeLib.Menu
|
|||||||
|
|
||||||
if (!Selected && !Pressed || !Enabled)
|
if (!Selected && !Pressed || !Enabled)
|
||||||
{
|
{
|
||||||
texture = Texture.Index != -1 ? Texture : CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID);
|
texture = Texture ?? CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID);
|
||||||
|
|
||||||
CBase.Drawing.DrawTexture(texture, Rect, Color);
|
CBase.Drawing.DrawTexture(texture, Rect, Color);
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ namespace VocaluxeLib.Menu
|
|||||||
}
|
}
|
||||||
else if (!_IsSelText)
|
else if (!_IsSelText)
|
||||||
{
|
{
|
||||||
texture = Texture.Index != -1 ? Texture : CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID);
|
texture = Texture ?? CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID);
|
||||||
|
|
||||||
CBase.Drawing.DrawTexture(texture, Rect, SelColor);
|
CBase.Drawing.DrawTexture(texture, Rect, SelColor);
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ namespace VocaluxeLib.Menu
|
|||||||
}
|
}
|
||||||
else if (_IsSelText)
|
else if (_IsSelText)
|
||||||
{
|
{
|
||||||
texture = SelTexture.Index != -1 ? SelTexture : CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID);
|
texture = SelTexture ?? CBase.Theme.GetSkinTexture(_Theme.SelTextureName, _PartyModeID);
|
||||||
|
|
||||||
CBase.Drawing.DrawTexture(texture, Rect, SelColor);
|
CBase.Drawing.DrawTexture(texture, Rect, SelColor);
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
get { return _CoverTextureBig ?? _CoverTextureSmall; }
|
get { return _CoverTextureBig ?? _CoverTextureSmall; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value.Index == -1)
|
if (value == null)
|
||||||
return;
|
return;
|
||||||
_CoverTextureBig = value;
|
_CoverTextureBig = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
{
|
{
|
||||||
foreach (CStatic tile in _Tiles)
|
foreach (CStatic tile in _Tiles)
|
||||||
{
|
{
|
||||||
if ((tile.Texture.Index != _CoverTexture.Index) && CHelper.IsInBounds(tile.Rect, mouseEvent) && !sel)
|
if (tile.Texture != _CoverTexture && CHelper.IsInBounds(tile.Rect, mouseEvent) && !sel)
|
||||||
{
|
{
|
||||||
if (mouseEvent.LB || !CBase.Songs.IsInCategory())
|
if (mouseEvent.LB || !CBase.Songs.IsInCategory())
|
||||||
{
|
{
|
||||||
@@ -371,7 +371,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
{
|
{
|
||||||
foreach (CStatic tile in _Tiles)
|
foreach (CStatic tile in _Tiles)
|
||||||
{
|
{
|
||||||
if ((tile.Texture.Index != _CoverTexture.Index) && CHelper.IsInBounds(tile.Rect, mouseEvent))
|
if (tile.Texture != _CoverTexture && CHelper.IsInBounds(tile.Rect, mouseEvent))
|
||||||
{
|
{
|
||||||
_EnterCategory(_PreviewSelected);
|
_EnterCategory(_PreviewSelected);
|
||||||
mouseEvent.Handled = true;
|
mouseEvent.Handled = true;
|
||||||
@@ -394,7 +394,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// ReSharper disable ConvertIfStatementToConditionalTernaryExpression
|
// ReSharper disable ConvertIfStatementToConditionalTernaryExpression
|
||||||
if (tile.Texture.Index != _CoverTexture.Index)
|
if (tile.Texture != _CoverTexture)
|
||||||
// ReSharper restore ConvertIfStatementToConditionalTernaryExpression
|
// ReSharper restore ConvertIfStatementToConditionalTernaryExpression
|
||||||
tile.Draw(1f, tile.Rect.Z, EAspect.Crop);
|
tile.Draw(1f, tile.Rect.Z, EAspect.Crop);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user