Changed usage of CTexture.Index: You only need to check for null as of last commit

This commit is contained in:
Flamefire committed 2013-05-06 20:18:17 +02:00
1 parent 142a690cc6
commit e43f5e7b0a
8 files changed
+37 -51

No files matched your search

+1 -1
View File
@@ -130,7 +130,7 @@ namespace Vocaluxe.Base
{
CTexture tex = CDraw.AddTexture(file);
if (tex.Index != -1)
if (tex != null)
{
SAvatar avatar = new SAvatar {Texture = tex, FileName = Path.GetFileName(file)};
_Avatars.Add(avatar);
+2 -7
View File
@@ -1002,13 +1002,8 @@ namespace Vocaluxe.Lib.Draw
{
lock (_MutexTexture)
{
if (texture != null && _Textures.ContainsKey(texture.Index))
{
if (_Textures[texture.Index].ID > 0)
return true;
}
return texture != null && _Textures.ContainsKey(texture.Index);
}
return false;
}
/// <summary>
@@ -1017,7 +1012,7 @@ namespace Vocaluxe.Lib.Draw
/// <param name="texture">The texture to be removed</param>
public void RemoveTexture(ref CTexture texture)
{
if (texture != null && texture.Index >= 0)
if (_TextureExists(texture))
{
lock (_MutexTexture)
{
+23 -31
View File
@@ -46,8 +46,8 @@ namespace Vocaluxe.Lib.Draw
private bool _TopMost;
private Rectangle _Bounds;
private readonly List<CTexture> _Textures;
private readonly List<Bitmap> _Bitmaps;
private readonly Dictionary<int, CTexture> _Textures = new Dictionary<int, CTexture>();
private readonly List<Bitmap> _Bitmaps = new List<Bitmap>();
private readonly Color _ClearColor = Color.DarkBlue;
@@ -55,9 +55,6 @@ namespace Vocaluxe.Lib.Draw
{
Icon = new Icon(Path.Combine(Environment.CurrentDirectory, CSettings.Icon));
_Textures = new List<CTexture>();
_Bitmaps = new List<Bitmap>();
_Keys = new CKeys();
_Mouse = new CMouse();
ClientSize = new Size(1280, 720);
@@ -297,14 +294,14 @@ namespace Vocaluxe.Lib.Draw
CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height);
// Add to Texture List
_Textures.Add(texture);
_Textures[texture.Index] = texture;
return 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);
texture = CopyScreen();
@@ -341,9 +338,7 @@ namespace Vocaluxe.Lib.Draw
CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height);
// Add to Texture List
texture.TexturePath = String.Empty;
_Textures.Add(texture);
_Textures[texture.Index] = texture;
return texture;
}
@@ -352,7 +347,7 @@ namespace Vocaluxe.Lib.Draw
{
if (File.Exists(texturePath))
{
foreach (CTexture tex in _Textures)
foreach (CTexture tex in _Textures.Values)
{
if (tex.TexturePath == texturePath)
return tex;
@@ -367,19 +362,17 @@ namespace Vocaluxe.Lib.Draw
return null;
}
private bool _TextureExists(CTexture texture)
{
return texture != null && _Textures.ContainsKey(texture.Index);
}
public void RemoveTexture(ref CTexture texture)
{
if (texture != null && texture.Index >= 0)
if (_TextureExists(texture))
{
for (int i = 0; i < _Textures.Count; i++)
{
if (_Textures[i].Index == texture.Index)
{
_Bitmaps[texture.Index].Dispose();
_Textures.RemoveAt(i);
break;
}
}
_Bitmaps[texture.Index].Dispose();
_Textures.Remove(texture.Index);
}
texture = null;
}
@@ -402,7 +395,7 @@ namespace Vocaluxe.Lib.Draw
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),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
@@ -415,30 +408,29 @@ namespace Vocaluxe.Lib.Draw
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);
}
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);
}
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);
}
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))
{
Bitmap coloredBitmap = _ColorizeBitmap(_Bitmaps[texture.Index], color);
_G.DrawImage(coloredBitmap, new RectangleF(rect.X, rect.Y, rect.W, rect.H));
coloredBitmap.Dispose();
}
if (!_TextureExists(texture))
return;
Bitmap coloredBitmap = _ColorizeBitmap(_Bitmaps[texture.Index], color);
_G.DrawImage(coloredBitmap, new RectangleF(rect.X, rect.Y, rect.W, rect.H));
coloredBitmap.Dispose();
}
public void DrawTexture(CTexture texture, SRectF rect, SColorF color, float begin, float end) {}
+3 -3
View File
@@ -883,7 +883,7 @@ namespace Vocaluxe.Lib.Draw
public void RemoveTexture(ref CTexture texture)
{
if (texture != null && texture.Index > 0)
if (_TextureExists(texture, false))
{
lock (_MutexTexture)
{
@@ -897,13 +897,13 @@ namespace Vocaluxe.Lib.Draw
texture = null;
}
private bool _TextureExists(CTexture texture)
private bool _TextureExists(CTexture texture, bool checkIfLoaded = true)
{
lock (_MutexTexture)
{
if (texture != null && _Textures.ContainsKey(texture.Index))
{
if (_Textures[texture.Index].ID > 0)
if (!checkIfLoaded || _Textures[texture.Index].ID > 0)
return true;
}
}
+1 -2
View File
@@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Drawing;
using VocaluxeLib.Menu;
namespace VocaluxeLib.Draw
+3 -3
View File
@@ -285,7 +285,7 @@ namespace VocaluxeLib.Menu
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);
@@ -299,7 +299,7 @@ namespace VocaluxeLib.Menu
}
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);
@@ -313,7 +313,7 @@ namespace VocaluxeLib.Menu
}
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);
+1 -1
View File
@@ -46,7 +46,7 @@ namespace VocaluxeLib.Menu.SongMenu
get { return _CoverTextureBig ?? _CoverTextureSmall; }
set
{
if (value.Index == -1)
if (value == null)
return;
_CoverTextureBig = value;
}
@@ -323,7 +323,7 @@ namespace VocaluxeLib.Menu.SongMenu
{
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())
{
@@ -371,7 +371,7 @@ namespace VocaluxeLib.Menu.SongMenu
{
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);
mouseEvent.Handled = true;
@@ -394,7 +394,7 @@ namespace VocaluxeLib.Menu.SongMenu
else
{
// ReSharper disable ConvertIfStatementToConditionalTernaryExpression
if (tile.Texture.Index != _CoverTexture.Index)
if (tile.Texture != _CoverTexture)
// ReSharper restore ConvertIfStatementToConditionalTernaryExpression
tile.Draw(1f, tile.Rect.Z, EAspect.Crop);
else