X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=DTXMania%2F%E3%82%B3%E3%83%BC%E3%83%89%2F%E5%85%A8%E4%BD%93%2FTextureFactory.cs;fp=DTXMania%2F%E3%82%B3%E3%83%BC%E3%83%89%2F%E5%85%A8%E4%BD%93%2FTextureFactory.cs;h=98575fe289b4db8f04faf5d632453e09057ea3cf;hb=7bf3e650c7c6f5afac463ea6e288fcd3fad4387b;hp=0000000000000000000000000000000000000000;hpb=296446998eeba408353da55a275458b590e4ebf5;p=dtxmania%2Fdtxmania.git
diff --git a/DTXMania/ã³ã¼ã/å
¨ä½/TextureFactory.cs b/DTXMania/ã³ã¼ã/å
¨ä½/TextureFactory.cs
new file mode 100644
index 00000000..98575fe2
--- /dev/null
+++ b/DTXMania/ã³ã¼ã/å
¨ä½/TextureFactory.cs
@@ -0,0 +1,150 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using FDK;
+using System.Drawing;
+
+namespace DTXMania
+{
+ public class TextureFactory
+ {
+
+ #region [ æ±ç¨ãã«ãã¼ ]
+ //-----------------
+ #region [ tãã¯ã¹ãã£ã®çæ ]
+ public static CTexture tãã¯ã¹ãã£ã®çæ(string fileName)
+ {
+ return tãã¯ã¹ãã£ã®çæ(fileName, false);
+ }
+
+ public static CTexture tãã¯ã¹ãã£ã®çæ(string fileName, bool bé»ãééãã)
+ {
+ if (CDTXMania.Instance == null)
+ {
+ return null;
+ }
+ try
+ {
+ return new CTexture(CDTXMania.Instance.Device, fileName, CDTXMania.Instance.TextureFormat, bé»ãééãã);
+ }
+ catch (CTextureCreateFailedException)
+ {
+ Trace.TraceError("ãã¯ã¹ãã£ã®çæã«å¤±æãã¾ããã({0})", fileName);
+ return null;
+ }
+ catch (FileNotFoundException)
+ {
+ Trace.TraceError("ãã¯ã¹ãã£ãã¡ã¤ã«ãè¦ã¤ããã¾ããã§ããã({0})", fileName);
+ return null;
+ }
+ }
+
+ public static CTextureAf tãã¯ã¹ãã£ã®çæAf(string fileName)
+ {
+ return tãã¯ã¹ãã£ã®çæAf(fileName, false);
+ }
+
+ public static CTextureAf tãã¯ã¹ãã£ã®çæAf(string fileName, bool bé»ãééãã)
+ {
+ if (CDTXMania.Instance == null)
+ {
+ return null;
+ }
+ try
+ {
+ return new CTextureAf(CDTXMania.Instance.Device, fileName, CDTXMania.Instance.TextureFormat, bé»ãééãã);
+ }
+ catch (CTextureCreateFailedException)
+ {
+ Trace.TraceError("ãã¯ã¹ãã£ã®çæã«å¤±æãã¾ããã({0})", fileName);
+ return null;
+ }
+ catch (FileNotFoundException)
+ {
+ Trace.TraceError("ãã¯ã¹ãã£ãã¡ã¤ã«ãè¦ã¤ããã¾ããã§ããã({0})", fileName);
+ return null;
+ }
+ }
+
+ public static void tãã¯ã¹ãã£ã®è§£æ¾(ref CTexture tx)
+ {
+ tå®å
¨ã«Disposeãã(ref tx);
+ }
+
+ public static void tãã¯ã¹ãã£ã®è§£æ¾(ref CTextureAf tx)
+ {
+ tå®å
¨ã«Disposeãã(ref tx);
+ }
+
+ public static CTexture tãã¯ã¹ãã£ã®çæ(byte[] txData)
+ {
+ return tãã¯ã¹ãã£ã®çæ(txData, false);
+ }
+
+ public static CTexture tãã¯ã¹ãã£ã®çæ(byte[] txData, bool bé»ãééãã)
+ {
+ if (CDTXMania.Instance == null)
+ {
+ return null;
+ }
+ if (txData == null)
+ {
+ Trace.TraceError("ãã¯ã¹ãã£ã®çæã«å¤±æãã¾ããã(txData==null)");
+ return null;
+ }
+ try
+ {
+ return new CTexture(CDTXMania.Instance.Device, txData, CDTXMania.Instance.TextureFormat, bé»ãééãã);
+ }
+ catch (CTextureCreateFailedException)
+ {
+ Trace.TraceError("ãã¯ã¹ãã£ã®çæã«å¤±æãã¾ããã(txData)");
+ return null;
+ }
+ }
+
+ public static CTexture tãã¯ã¹ãã£ã®çæ(Bitmap bitmap)
+ {
+ return tãã¯ã¹ãã£ã®çæ(bitmap, false);
+ }
+
+ public static CTexture tãã¯ã¹ãã£ã®çæ(Bitmap bitmap, bool bé»ãééãã)
+ {
+ if (CDTXMania.Instance == null)
+ {
+ return null;
+ }
+ if (bitmap == null)
+ {
+ Trace.TraceError("ãã¯ã¹ãã£ã®çæã«å¤±æãã¾ããã(bitmap==null)");
+ return null;
+ }
+ try
+ {
+ return new CTexture(CDTXMania.Instance.Device, bitmap, CDTXMania.Instance.TextureFormat, bé»ãééãã);
+ }
+ catch (CTextureCreateFailedException)
+ {
+ Trace.TraceError("ãã¯ã¹ãã£ã®çæã«å¤±æãã¾ããã(bitmap:{0}x{1} )", bitmap.Width, bitmap.Height);
+ return null;
+ }
+ }
+ #endregion
+
+ /// ããããã£ãã¤ã³ãã¯ãµã«ã¯ ref ã¯ä½¿ç¨ã§ããªãã®ã§æ³¨æã
+ public static void tå®å
¨ã«Disposeãã(ref T obj)
+ {
+ if (obj == null)
+ return;
+
+ var d = obj as IDisposable;
+
+ if (d != null)
+ d.Dispose();
+
+ obj = default(T);
+ }
+ //-----------------
+ #endregion
+ }
+}