/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/Texture.cs
ViewVC logotype

Diff of /trunk/gr2lib/core/coretypes/implementation/Texture.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/gr2lib/core/coretypes/implementation/Texture.cs	2010/07/15 21:50:56	79
+++ trunk/gr2lib/core/coretypes/implementation/Texture.cs	2010/07/19 06:23:28	141
@@ -4,11 +4,18 @@
 using gr2lib.core.helpers;
 
 using gr2lib.core.interfaces;
+using System.Diagnostics;
+using gr2lib.core.exceptions;
+using gr2lib.core.ui.helpers;
+using System.ComponentModel;
+using gr2lib.core.typedefs;
 
 namespace gr2lib.core.coretypes.implementation
 {
-    public class Texture : ITexture
+    public class Texture : GrannyRigParentResource, ITexture
     {
+        private GrannyRigResource _rigResource;
+
         private FilePath _FromFileName;
         private int _TextureType;
         private int _Width;
@@ -17,11 +24,15 @@
         private int _SubFormat;
         private Layout _Layout;
         private List<Image> _Images;
-        private IntPtr _ExtendedData;
 
+
+        public override string ToString()
+        {
+            return this.FromFileName.Name;
+        }
         
 
-        public Texture()
+        public Texture() : base("Textures")
         {
             this.FromFileName = "";
             this.TextureType = 0;
@@ -31,59 +42,164 @@
             this.SubFormat = 0;
             this.Layout = new Layout();
             this.Images = new List<Image>();
-            this.ExtendedData = IntPtr.Zero;
-            this.NativePointer = IntPtr.Zero;
+            //this.ExtendedData = new IntPtr();
+            //this.NativePointer = IntPtr.Zero;
+            this._rigResource = new GrannyRigResource();
+        }
+        public Texture(int index)
+            : base("Textures")
+        {
+            this.FromFileName = "";
+            this.TextureType = 0;
+            this.Width = 0;
+            this.Height = 0;
+            this.Encoding = 0;
+            this.SubFormat = 0;
+            this.Layout = new Layout();
+            this.Images = new List<Image>();
+            //this.ExtendedData = new IntPtr();
+            //this.NativePointer = IntPtr.Zero;
+            this._rigResource = new GrannyRigResource();
+            this.Index = index;
         }
-
         internal static Texture ReadFromMemory(IntPtr pointer)
         {
+            try 
+            {
             if (pointer == IntPtr.Zero) return null;
             native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);
             Texture managed = ReadFromNative(native);
             managed.NativePointer = pointer;
             return managed;
+            }
+            catch (Exception ex)
+            {
+                StackTrace st = new StackTrace(true);
+                #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
+                Granny2ExceptionWriter.WriteToConsole(ex,st);
+#endif
+                return default(Texture);
+            }
         }
 
         internal static Texture ReadFromNative(native.Texture native)
         {
-            Texture managed = new Texture();
-            managed.FromFileName = native.FromFileName;
-            managed.TextureType = native.TextureType;
-            managed.Width = native.Width;
-            managed.Height = native.Height;
-            managed.Encoding = native.Encoding;
-            managed.SubFormat = native.SubFormat;
-            managed.Layout = Layout.ReadFromNative(native.Layout);
-            IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
-            int length = images.Length;
-            managed.Images = new List<Image>(length);
-            foreach (IntPtr ptr in images)
+            try
             {
-                managed.Images.Add(new Image());
+                Texture managed = new Texture();
+                managed.FromFileName = native.FromFileName;
+                managed.TextureType = native.TextureType;
+                managed.Width = native.Width;
+                managed.Height = native.Height;
+                managed.Encoding = native.Encoding;
+                managed.SubFormat = native.SubFormat;
+                managed.Layout = Layout.ReadFromNative(native.Layout);
+                IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
+                int length = images.Length;
+                managed.Images = new List<Image>(length);
+                foreach (IntPtr ptr in images)
+                {
+                    Image _tmp = new Image();
+                    _tmp.NativePointer = ptr;
+                    managed.Images.Add(_tmp);
+                }
+                for (int i = 0; i < length; i++)
+                {
+                    managed.Images[i] = Image.ReadFromMemory(images[i]);
+                }
+                managed.ExtendedData = native.ExtendedData;
+                return managed;
             }
-            for (int i = 0; i < length; i++)
+            catch (Exception ex)
             {
-                managed.Images[i] = Image.ReadFromMemory(images[i]);
+                StackTrace st = new StackTrace(true);
+#if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
+                Granny2ExceptionWriter.WriteToConsole(ex,st);
+#endif
+                return default(Texture);
             }
-            managed.ExtendedData = native.ExtendedData;
-            return managed;
         }
 
         #region ITexture Members
+
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        public string TextureTypeFormat 
+        { 
+            get
+            {
+                string texture_type = "Unknown Texture Type";
+
+                foreach (int val in Enum.GetValues(typeof(granny_texture_type)))
+                {
+                    if (val == this.TextureType)
+                    {
+                        texture_type = Enum.GetName(typeof(granny_texture_type),val);
+                        break;
+                    }
+                }
+                return texture_type;
+            } 
+        }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        public string EncodingFormat
+        {
+            get
+            {
+                string encodingformat = "Unknown Encoding Format";
+
+                foreach (int val in Enum.GetValues(typeof(granny_texture_encoding)))
+                {
+                    if (val == this.Encoding)
+                    {
+                        encodingformat = Enum.GetName(typeof(granny_texture_encoding), val);
+                        break;
+                    }
+                }
+                return encodingformat;
+            }
+        }
+
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public int Width { get { return _Width; } set { _Width = value; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public int Height { get { return _Height; } set { _Height = value; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public int Encoding { get { return _Encoding; } set { _Encoding = value; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        [Browsable(true)]
         public Layout Layout { get { return _Layout; } set { _Layout = value; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public List<Image> Images { get { return _Images; } set { _Images = value; } }
-        public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
         #endregion
 
         #region INativePointer Members
         private IntPtr _NativePointer;
         public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
         #endregion
+
+        #region IExtendedData Members
+        private IntPtr _ExtendedData;
+        public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
+        #endregion
+
+        #region IResource Members
+        private int _index;
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        internal int Index { get { return _index; } set { _index = value; } }
+        #endregion
+        #region IEmbeddedResource Members
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        internal string IndexName { get { return new GrannyRigResource("Texture", this.Index, this.Name).ResourceBlockIndexFormat; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        internal string FullName { get { return new GrannyRigResource("Texture", this.Index, this.Name).ResourceBlockFormat; } }
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        internal string Name { get { return this.FromFileName; } set { this.FromFileName = value; } }
+        #endregion
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22