/[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

revision 141 by william, Mon Jul 19 06:23:28 2010 UTC revision 191 by william, Sat Jul 24 06:31:50 2010 UTC
# Line 9  using gr2lib.core.exceptions; Line 9  using gr2lib.core.exceptions;
9  using gr2lib.core.ui.helpers;  using gr2lib.core.ui.helpers;
10  using System.ComponentModel;  using System.ComponentModel;
11  using gr2lib.core.typedefs;  using gr2lib.core.typedefs;
12    using gr2lib.core.ui.typeeditors;
13    using System.Drawing.Design;
14    
15  namespace gr2lib.core.coretypes.implementation  namespace gr2lib.core.coretypes.implementation
16  {  {
17      public class Texture : GrannyRigParentResource, ITexture      /// <summary>
18        /// Represents a Granny_Texture
19        /// </summary>
20        public class Texture : ITexture
21      {      {
22          private GrannyRigResource _rigResource;          private GrannyRigResource _rigResource;
23    
24          private FilePath _FromFileName;          private FilePath _FromFileName;
25          private int _TextureType;          private NameValuePair<string, granny_texture_type> _TextureType;
26          private int _Width;          private int _Width;
27          private int _Height;          private int _Height;
28          private int _Encoding;          private NameValuePair<string, granny_texture_encoding> _Encoding;
29          private int _SubFormat;          private NameValuePair<string, granny_pixel_layout> _SubFormat;
30          private Layout _Layout;          private Layout _Layout;
31          private List<Image> _Images;          private List<Image> _Images;
32    
33            /// <summary>
34            /// Gets the string representation of this instance
35            /// </summary>
36            /// <returns></returns>
37          public override string ToString()          public override string ToString()
38          {          {
39              return this.FromFileName.Name;              return this.FromFileName.Name;
40          }          }
           
41    
42          public Texture() : base("Textures")          //private string _ParentResourceName;
43            /// <summary>
44            /// Get's the parent resource name
45            /// </summary>
46            protected internal string ParentResourceName { get { return "Textures"; } }
47    
48            /// <summary>
49            /// default constructor
50            /// </summary>
51            public Texture()// : base("Textures")
52          {          {
53              this.FromFileName = "";              this.FromFileName = "";
54              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);
55              this.Width = 0;              this.Width = 0;
56              this.Height = 0;              this.Height = 0;
57              this.Encoding = 0;              this.Encoding = new NameValuePair<string, granny_texture_encoding>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_encoding>(granny_texture_encoding.GrannyBinkTextureEncoding), granny_texture_encoding.GrannyBinkTextureEncoding);
58              this.SubFormat = 0;              this.SubFormat = new NameValuePair<string, granny_pixel_layout>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_pixel_layout>(granny_pixel_layout.GrannyBGRA8888PixelFormat), granny_pixel_layout.GrannyBGRA8888PixelFormat);
59              this.Layout = new Layout();              this.Layout = new Layout();
60              this.Images = new List<Image>();              this.Images = new List<Image>();
61              //this.ExtendedData = new IntPtr();              //this.ExtendedData = new IntPtr();
62              //this.NativePointer = IntPtr.Zero;              //this.NativePointer = IntPtr.Zero;
63              this._rigResource = new GrannyRigResource();              this._rigResource = new GrannyRigResource();
64          }          }
65            /// <summary>
66            /// default constructor (specifying index)
67            /// </summary>
68            /// <param name="index">the texture's index</param>
69          public Texture(int index)          public Texture(int index)
             : base("Textures")  
70          {          {
71              this.FromFileName = "";              this.FromFileName = "";
72              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);
73              this.Width = 0;              this.Width = 0;
74              this.Height = 0;              this.Height = 0;
75              this.Encoding = 0;              this.Encoding = new NameValuePair<string, granny_texture_encoding>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_encoding>(granny_texture_encoding.GrannyBinkTextureEncoding), granny_texture_encoding.GrannyBinkTextureEncoding);
76              this.SubFormat = 0;              this.SubFormat = new NameValuePair<string, granny_pixel_layout>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_pixel_layout>(granny_pixel_layout.GrannyBGRA8888PixelFormat), granny_pixel_layout.GrannyBGRA8888PixelFormat);
77              this.Layout = new Layout();              this.Layout = new Layout();
78              this.Images = new List<Image>();              this.Images = new List<Image>();
79              //this.ExtendedData = new IntPtr();              //this.ExtendedData = new IntPtr();
# Line 62  namespace gr2lib.core.coretypes.implemen Line 81  namespace gr2lib.core.coretypes.implemen
81              this._rigResource = new GrannyRigResource();              this._rigResource = new GrannyRigResource();
82              this.Index = index;              this.Index = index;
83          }          }
84    
85            internal static native.Texture AssignToStructure(Texture texture)
86            {
87                native.Texture _texture_struct = new gr2lib.core.coretypes.native.Texture();
88    
89                //_texture_struct.Encoding = texture.Encoding;
90                //_texture_struct.ExtendedData = texture.ExtendedData;
91                //_texture_struct.FromFileName = texture.FromFileName.FullPath;
92                //_texture_struct.Height = texture.Height;
93                ////_texture_struct.Images = texture.Images;
94                //_texture_struct.Layout = Layout.AssignToStructure(texture.Layout);
95                //_texture_struct.SubFormat = texture.SubFormat;
96                //_texture_struct.TextureType = texture.TextureType;
97                //_texture_struct.Width = texture.Width;
98    
99                return _texture_struct;
100            }
101    
102          internal static Texture ReadFromMemory(IntPtr pointer)          internal static Texture ReadFromMemory(IntPtr pointer)
103          {          {
104              try              try
# Line 88  namespace gr2lib.core.coretypes.implemen Line 125  namespace gr2lib.core.coretypes.implemen
125              {              {
126                  Texture managed = new Texture();                  Texture managed = new Texture();
127                  managed.FromFileName = native.FromFileName;                  managed.FromFileName = native.FromFileName;
128                  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);
129                  managed.Width = native.Width;                  managed.Width = native.Width;
130                  managed.Height = native.Height;                  managed.Height = native.Height;
131                  managed.Encoding = native.Encoding;                  managed.Encoding = new NameValuePair<string, granny_texture_encoding>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_texture_encoding>((granny_texture_encoding)native.Encoding), (granny_texture_encoding)native.Encoding);
132                  managed.SubFormat = native.SubFormat;                  managed.SubFormat = new NameValuePair<string, granny_pixel_layout>(coreapi.EnumToStringSupport.GetGrannyEnumTypeString<granny_pixel_layout>((granny_pixel_layout)native.SubFormat), (granny_pixel_layout)native.SubFormat);
133                  managed.Layout = Layout.ReadFromNative(native.Layout);                  managed.Layout = Layout.ReadFromNative(native.Layout);
134                  IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);                  IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
135                  int length = images.Length;                  int length = images.Length;
# Line 105  namespace gr2lib.core.coretypes.implemen Line 142  namespace gr2lib.core.coretypes.implemen
142                  }                  }
143                  for (int i = 0; i < length; i++)                  for (int i = 0; i < length; i++)
144                  {                  {
145                      managed.Images[i] = Image.ReadFromMemory(images[i]);                      managed.Images[i] = Image.ReadFromMemory(images[i]);  
146                  }                  }
147    
148                    for (int i = 0; i < managed.Images.Count; i++)
149                    {
150                        for (int j = 0; j < managed.Images[i].MIPLevels.Count; j++)
151                        {
152                            for (int k = 0; k < managed.Images[i].MIPLevels[j].Pixels.Count; k++)
153                            {
154                                managed.Images[i].MIPLevels[j].Pixels[k].ReferenceTexture = managed;
155                            }
156                        }
157                    }
158    
159    
160                  managed.ExtendedData = native.ExtendedData;                  managed.ExtendedData = native.ExtendedData;
161                  return managed;                  return managed;
162              }              }
# Line 121  namespace gr2lib.core.coretypes.implemen Line 171  namespace gr2lib.core.coretypes.implemen
171          }          }
172    
173          #region ITexture Members          #region ITexture Members
174            /// <summary>
175          [RefreshPropertiesAttribute(RefreshProperties.All)]          /// Get's the texture's name
176          public string TextureTypeFormat          /// </summary>
         {  
             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;  
             }  
         }  
   
177          [RefreshPropertiesAttribute(RefreshProperties.All)]          [RefreshPropertiesAttribute(RefreshProperties.All)]
178          public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }          public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
179          [RefreshPropertiesAttribute(RefreshProperties.All)]          /// <summary>
180          public int TextureType { get { return _TextureType; } set { _TextureType = value; } }          /// Get's the texture's type
181            /// </summary>
182            [RefreshPropertiesAttribute(RefreshProperties.All)]
183            [Editor(typeof(UIComboValueSelector<granny_texture_type, int>), typeof(UITypeEditor))]
184            public NameValuePair<string, granny_texture_type> TextureType { get { return _TextureType; } set { _TextureType = value; } }
185            /// <summary>
186            /// Get's the texture's widh
187            /// </summary>
188          [RefreshPropertiesAttribute(RefreshProperties.All)]          [RefreshPropertiesAttribute(RefreshProperties.All)]
189          public int Width { get { return _Width; } set { _Width = value; } }          public int Width { get { return _Width; } set { _Width = value; } }
190            /// <summary>
191            /// Get's the texture's height
192            /// </summary>
193          [RefreshPropertiesAttribute(RefreshProperties.All)]          [RefreshPropertiesAttribute(RefreshProperties.All)]
194          public int Height { get { return _Height; } set { _Height = value; } }          public int Height { get { return _Height; } set { _Height = value; } }
195          [RefreshPropertiesAttribute(RefreshProperties.All)]          /// <summary>
196          public int Encoding { get { return _Encoding; } set { _Encoding = value; } }          /// Get's the texture's encoding
197          [RefreshPropertiesAttribute(RefreshProperties.All)]          /// </summary>
198          public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }          [RefreshPropertiesAttribute(RefreshProperties.All)]
199            [Editor(typeof(UIComboValueSelector<granny_texture_encoding, int>), typeof(UITypeEditor))]
200            public NameValuePair<string, granny_texture_encoding> Encoding { get { return _Encoding; } set { _Encoding = value; } }
201            /// <summary>
202            /// Get's the texture's subformat
203            /// </summary>
204            [RefreshPropertiesAttribute(RefreshProperties.All)]
205            [Editor(typeof(UIComboValueSelector<granny_pixel_layout, int>), typeof(UITypeEditor))]
206            public NameValuePair<string, granny_pixel_layout> SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
207            /// <summary>
208            /// Get's the texture's Pixel Layout
209            /// </summary>
210          [RefreshPropertiesAttribute(RefreshProperties.All)]          [RefreshPropertiesAttribute(RefreshProperties.All)]
211          [Browsable(true)]          [Browsable(true)]
212          public Layout Layout { get { return _Layout; } set { _Layout = value; } }          public Layout Layout { get { return _Layout; } set { _Layout = value; } }
213            /// <summary>
214            /// Get a List of Images associated with this texture
215            /// </summary>
216          [RefreshPropertiesAttribute(RefreshProperties.All)]          [RefreshPropertiesAttribute(RefreshProperties.All)]
217          public List<Image> Images { get { return _Images; } set { _Images = value; } }          public List<Image> Images { get { return _Images; } set { _Images = value; } }
218          #endregion          #endregion
219    
220          #region INativePointer Members          #region INativePointer Members
221          private IntPtr _NativePointer;          private IntPtr _NativePointer;
222            /// <summary>
223            /// When used in a derived class, gets the native pointer for this instance
224            /// </summary>
225          public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }          public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
226          #endregion          #endregion
227    
228          #region IExtendedData Members          #region IExtendedData Members
229          private IntPtr _ExtendedData;          private IntPtr _ExtendedData;
230            /// <summary>
231            /// When used in a derived class, gets the ExtendedData pointer for this instance
232            /// </summary>
233          public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }          public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
234          #endregion          #endregion
235    

Legend:
Removed from v.141  
changed lines
  Added in v.191

  ViewVC Help
Powered by ViewVC 1.1.22