diff --git a/Vocaluxe/Base/Fonts/CGlyph.cs b/Vocaluxe/Base/Fonts/CGlyph.cs index 707f5aa7..5ccb6a6e 100644 --- a/Vocaluxe/Base/Fonts/CGlyph.cs +++ b/Vocaluxe/Base/Fonts/CGlyph.cs @@ -161,7 +161,7 @@ namespace Vocaluxe.Base.Fonts private static Rectangle _GetRealBounds(Bitmap bmp) { int minX = 0, maxX = bmp.Width - 1, minY = 0; - BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); + BitmapData bmpData = bmp.LockBits(bmp.GetRect(), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int values = bmpData.Width * bmp.Height; var rgbValues = new Int32[values]; Marshal.Copy(bmpData.Scan0, rgbValues, 0, values); diff --git a/Vocaluxe/Lib/Database/CCoverDB.cs b/Vocaluxe/Lib/Database/CCoverDB.cs index 8faf0460..1554a4df 100644 --- a/Vocaluxe/Lib/Database/CCoverDB.cs +++ b/Vocaluxe/Lib/Database/CCoverDB.cs @@ -22,6 +22,7 @@ using System.Drawing.Imaging; using System.IO; using System.Runtime.InteropServices; using Vocaluxe.Base; +using VocaluxeLib; using VocaluxeLib.Draw; #if WIN using System.Data.SQLite; @@ -142,7 +143,7 @@ namespace Vocaluxe.Lib.Database g.DrawImage(origin, new Rectangle(0, 0, w, h)); data = new byte[w * h * 4]; - BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); + BitmapData bmpData = bmp.LockBits(bmp.GetRect(), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); Marshal.Copy(bmpData.Scan0, data, 0, w * h * 4); bmp.UnlockBits(bmpData); } diff --git a/Vocaluxe/Lib/Draw/CDrawBase.cs b/Vocaluxe/Lib/Draw/CDrawBase.cs index 8dc9bbdb..78f1598d 100644 --- a/Vocaluxe/Lib/Draw/CDrawBase.cs +++ b/Vocaluxe/Lib/Draw/CDrawBase.cs @@ -44,7 +44,7 @@ namespace Vocaluxe.Lib.Draw { TextureRef = new WeakReference(textureRef); Action = action; - DataSize = new Size(bmp.Width, bmp.Height); + DataSize = bmp.GetSize(); Data = null; DataBmp = bmp; } @@ -473,7 +473,7 @@ namespace Vocaluxe.Lib.Draw if (bmp.Height == 0 || bmp.Width == 0) return null; - Size origSize = new Size(bmp.Width, bmp.Height); + Size origSize = bmp.GetSize(); TTextureType texture = null; _WriteBitmapToTexture(ref texture, bmp); @@ -502,7 +502,7 @@ namespace Vocaluxe.Lib.Draw { lock (_Textures) { - CTextureRef textureRef = _GetTextureReference(bmp.Width, bmp.Height, null); + CTextureRef textureRef = _GetTextureReference(bmp.GetSize(), null); _TexturesToLoad.Enqueue(new STextureQueue(textureRef, EQueueAction.Add, bmp)); return textureRef; } diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 1828dea1..070f38b4 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -232,6 +232,7 @@ namespace Vocaluxe.Lib.Draw if (_Run) { + ClearScreen(); _Run = _Run && CGraphics.Draw(); _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); _FlipBuffer(); @@ -281,7 +282,7 @@ namespace Vocaluxe.Lib.Draw { var bmp = new Bitmap(_Backbuffer); _Bitmaps.Add(bmp); - CTextureRef texture = _GetNewTexture(bmp.Width, bmp.Height); + CTextureRef texture = _GetNewTexture(bmp.GetSize()); // Add to Texture List _Textures[texture.ID] = texture; @@ -320,7 +321,7 @@ namespace Vocaluxe.Lib.Draw { var bmp2 = new Bitmap(bmp); _Bitmaps.Add(bmp2); - CTextureRef texture = _GetNewTexture(bmp.Width, bmp.Height); + CTextureRef texture = _GetNewTexture(bmp.GetSize()); // Add to Texture List _Textures[texture.ID] = texture; @@ -328,9 +329,9 @@ namespace Vocaluxe.Lib.Draw return texture; } - private CTextureRef _GetNewTexture(int w, int h) + private CTextureRef _GetNewTexture(Size size) { - return new CTextureRef(_Bitmaps.Count - 1, new Size(w, h)); + return new CTextureRef(_Bitmaps.Count - 1, size); } public CTextureRef AddTexture(string texturePath) @@ -393,7 +394,7 @@ namespace Vocaluxe.Lib.Draw { using (var bmp = new Bitmap(w, h)) { - BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); + BitmapData bmpData = bmp.LockBits(bmp.GetRect(), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Marshal.Copy(data, 0, bmpData.Scan0, data.Length); bmp.UnlockBits(bmpData); return AddTexture(bmp); diff --git a/VocaluxeLib/Extensions.cs b/VocaluxeLib/Extensions.cs index f04d5f40..80d0ce3e 100644 --- a/VocaluxeLib/Extensions.cs +++ b/VocaluxeLib/Extensions.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Globalization; using System.Linq; @@ -134,5 +135,15 @@ namespace VocaluxeLib rect.H + 2 * rect.H * (scale - 1f), rect.Z); } + + public static Size GetSize(this Bitmap bmp) + { + return new Size(bmp.Width, bmp.Height); + } + + public static Rectangle GetRect(this Bitmap bmp) + { + return new Rectangle(0, 0, bmp.Width, bmp.Height); + } } } \ No newline at end of file