/[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/17 13:54:18	102
+++ trunk/gr2lib/core/coretypes/implementation/Texture.cs	2010/07/24 06:31:50	191
@@ -5,35 +5,98 @@
 
 using gr2lib.core.interfaces;
 using System.Diagnostics;
+using gr2lib.core.exceptions;
+using gr2lib.core.ui.helpers;
+using System.ComponentModel;
+using gr2lib.core.typedefs;
+using gr2lib.core.ui.typeeditors;
+using System.Drawing.Design;
 
 namespace gr2lib.core.coretypes.implementation
 {
+    /// <summary>
+    /// Represents a Granny_Texture
+    /// </summary>
     public class Texture : ITexture
     {
+        private GrannyRigResource _rigResource;
+
         private FilePath _FromFileName;
-        private int _TextureType;
+        private NameValuePair<string, granny_texture_type> _TextureType;
         private int _Width;
         private int _Height;
-        private int _Encoding;
-        private int _SubFormat;
+        private NameValuePair<string, granny_texture_encoding> _Encoding;
+        private NameValuePair<string, granny_pixel_layout> _SubFormat;
         private Layout _Layout;
         private List<Image> _Images;
 
+        /// <summary>
+        /// Gets the string representation of this instance
+        /// </summary>
+        /// <returns></returns>
+        public override string ToString()
+        {
+            return this.FromFileName.Name;
+        }
 
-        
-
-        public Texture()
+        //private string _ParentResourceName;
+        /// <summary>
+        /// Get's the parent resource name
+        /// </summary>
+        protected internal string ParentResourceName { get { return "Textures"; } }
+
+        /// <summary>
+        /// default constructor
+        /// </summary>
+        public Texture()// : base("Textures")
+        {
+            this.FromFileName = "";
+            this.TextureType = new NameValuePair<string, granny_texture_type>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_type>(granny_texture_type.GrannyColorMapTextureType), granny_texture_type.GrannyColorMapTextureType);
+            this.Width = 0;
+            this.Height = 0;
+            this.Encoding = new NameValuePair<string, granny_texture_encoding>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_encoding>(granny_texture_encoding.GrannyBinkTextureEncoding), granny_texture_encoding.GrannyBinkTextureEncoding);
+            this.SubFormat = new NameValuePair<string, granny_pixel_layout>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_pixel_layout>(granny_pixel_layout.GrannyBGRA8888PixelFormat), granny_pixel_layout.GrannyBGRA8888PixelFormat);
+            this.Layout = new Layout();
+            this.Images = new List<Image>();
+            //this.ExtendedData = new IntPtr();
+            //this.NativePointer = IntPtr.Zero;
+            this._rigResource = new GrannyRigResource();
+        }
+        /// <summary>
+        /// default constructor (specifying index)
+        /// </summary>
+        /// <param name="index">the texture's index</param>
+        public Texture(int index)
         {
             this.FromFileName = "";
-            this.TextureType = 0;
+            this.TextureType = new NameValuePair<string, granny_texture_type>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_type>(granny_texture_type.GrannyColorMapTextureType), granny_texture_type.GrannyColorMapTextureType);
             this.Width = 0;
             this.Height = 0;
-            this.Encoding = 0;
-            this.SubFormat = 0;
+            this.Encoding = new NameValuePair<string, granny_texture_encoding>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_encoding>(granny_texture_encoding.GrannyBinkTextureEncoding), granny_texture_encoding.GrannyBinkTextureEncoding);
+            this.SubFormat = new NameValuePair<string, granny_pixel_layout>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_pixel_layout>(granny_pixel_layout.GrannyBGRA8888PixelFormat), granny_pixel_layout.GrannyBGRA8888PixelFormat);
             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 native.Texture AssignToStructure(Texture texture)
+        {
+            native.Texture _texture_struct = new gr2lib.core.coretypes.native.Texture();
+
+            //_texture_struct.Encoding = texture.Encoding;
+            //_texture_struct.ExtendedData = texture.ExtendedData;
+            //_texture_struct.FromFileName = texture.FromFileName.FullPath;
+            //_texture_struct.Height = texture.Height;
+            ////_texture_struct.Images = texture.Images;
+            //_texture_struct.Layout = Layout.AssignToStructure(texture.Layout);
+            //_texture_struct.SubFormat = texture.SubFormat;
+            //_texture_struct.TextureType = texture.TextureType;
+            //_texture_struct.Width = texture.Width;
+
+            return _texture_struct;
         }
 
         internal static Texture ReadFromMemory(IntPtr pointer)
@@ -46,11 +109,11 @@
             managed.NativePointer = pointer;
             return managed;
             }
-            catch
+            catch (Exception ex)
             {
                 StackTrace st = new StackTrace(true);
                 #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
-                Console.WriteLine(st.ToString());
+                Granny2ExceptionWriter.WriteToConsole(ex,st);
 #endif
                 return default(Texture);
             }
@@ -62,11 +125,11 @@
             {
                 Texture managed = new Texture();
                 managed.FromFileName = native.FromFileName;
-                managed.TextureType = native.TextureType;
+                managed.TextureType = new NameValuePair<string, granny_texture_type>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_type>((granny_texture_type)native.TextureType), (granny_texture_type)native.TextureType);
                 managed.Width = native.Width;
                 managed.Height = native.Height;
-                managed.Encoding = native.Encoding;
-                managed.SubFormat = native.SubFormat;
+                managed.Encoding = new NameValuePair<string, granny_texture_encoding>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_encoding>((granny_texture_encoding)native.Encoding), (granny_texture_encoding)native.Encoding);
+                managed.SubFormat = new NameValuePair<string, granny_pixel_layout>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_pixel_layout>((granny_pixel_layout)native.SubFormat), (granny_pixel_layout)native.SubFormat);
                 managed.Layout = Layout.ReadFromNative(native.Layout);
                 IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
                 int length = images.Length;
@@ -79,40 +142,109 @@
                 }
                 for (int i = 0; i < length; i++)
                 {
-                    managed.Images[i] = Image.ReadFromMemory(images[i]);
+                    managed.Images[i] = Image.ReadFromMemory(images[i]);   
                 }
+
+                for (int i = 0; i < managed.Images.Count; i++)
+                {
+                    for (int j = 0; j < managed.Images[i].MIPLevels.Count; j++)
+                    {
+                        for (int k = 0; k < managed.Images[i].MIPLevels[j].Pixels.Count; k++)
+                        {
+                            managed.Images[i].MIPLevels[j].Pixels[k].ReferenceTexture = managed;
+                        }
+                    }
+                }
+
+
                 managed.ExtendedData = native.ExtendedData;
                 return managed;
             }
-            catch
+            catch (Exception ex)
             {
                 StackTrace st = new StackTrace(true);
 #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
-                Console.WriteLine(st.ToString());
+                Granny2ExceptionWriter.WriteToConsole(ex,st);
 #endif
                 return default(Texture);
             }
         }
 
         #region ITexture Members
+        /// <summary>
+        /// Get's the texture's name
+        /// </summary>
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
-        public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
+        /// <summary>
+        /// Get's the texture's type
+        /// </summary>
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        [Editor(typeof(UIComboValueSelector<granny_texture_type, int>), typeof(UITypeEditor))]
+        public NameValuePair<string, granny_texture_type> TextureType { get { return _TextureType; } set { _TextureType = value; } }
+        /// <summary>
+        /// Get's the texture's widh
+        /// </summary>
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public int Width { get { return _Width; } set { _Width = value; } }
+        /// <summary>
+        /// Get's the texture's height
+        /// </summary>
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public int Height { get { return _Height; } set { _Height = value; } }
-        public int Encoding { get { return _Encoding; } set { _Encoding = value; } }
-        public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
+        /// <summary>
+        /// Get's the texture's encoding
+        /// </summary>
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        [Editor(typeof(UIComboValueSelector<granny_texture_encoding, int>), typeof(UITypeEditor))]
+        public NameValuePair<string, granny_texture_encoding> Encoding { get { return _Encoding; } set { _Encoding = value; } }
+        /// <summary>
+        /// Get's the texture's subformat
+        /// </summary>
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        [Editor(typeof(UIComboValueSelector<granny_pixel_layout, int>), typeof(UITypeEditor))]
+        public NameValuePair<string, granny_pixel_layout> SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
+        /// <summary>
+        /// Get's the texture's Pixel Layout
+        /// </summary>
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
+        [Browsable(true)]
         public Layout Layout { get { return _Layout; } set { _Layout = value; } }
+        /// <summary>
+        /// Get a List of Images associated with this texture
+        /// </summary>
+        [RefreshPropertiesAttribute(RefreshProperties.All)]
         public List<Image> Images { get { return _Images; } set { _Images = value; } }
         #endregion
 
         #region INativePointer Members
         private IntPtr _NativePointer;
+        /// <summary>
+        /// When used in a derived class, gets the native pointer for this instance
+        /// </summary>
         public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
         #endregion
 
         #region IExtendedData Members
         private IntPtr _ExtendedData;
+        /// <summary>
+        /// When used in a derived class, gets the ExtendedData pointer for this instance
+        /// </summary>
         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