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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 141 - (hide annotations) (download)
Mon Jul 19 06:23:28 2010 UTC (9 years, 4 months ago) by william
File size: 7922 byte(s)
bulk commit

1 william 72 using System;
2     using System.Collections.Generic;
3     using System.Text;
4     using gr2lib.core.helpers;
5    
6 william 79 using gr2lib.core.interfaces;
7 william 95 using System.Diagnostics;
8 william 106 using gr2lib.core.exceptions;
9 william 141 using gr2lib.core.ui.helpers;
10     using System.ComponentModel;
11     using gr2lib.core.typedefs;
12 william 79
13 william 72 namespace gr2lib.core.coretypes.implementation
14     {
15 william 141 public class Texture : GrannyRigParentResource, ITexture
16 william 72 {
17 william 141 private GrannyRigResource _rigResource;
18    
19 william 75 private FilePath _FromFileName;
20 william 72 private int _TextureType;
21     private int _Width;
22     private int _Height;
23     private int _Encoding;
24     private int _SubFormat;
25     private Layout _Layout;
26     private List<Image> _Images;
27    
28 william 82
29 william 141 public override string ToString()
30     {
31     return this.FromFileName.Name;
32     }
33 william 79
34 william 72
35 william 141 public Texture() : base("Textures")
36 william 72 {
37 william 73 this.FromFileName = "";
38     this.TextureType = 0;
39     this.Width = 0;
40     this.Height = 0;
41     this.Encoding = 0;
42     this.SubFormat = 0;
43     this.Layout = new Layout();
44     this.Images = new List<Image>();
45 william 83 //this.ExtendedData = new IntPtr();
46     //this.NativePointer = IntPtr.Zero;
47 william 141 this._rigResource = new GrannyRigResource();
48 william 72 }
49 william 141 public Texture(int index)
50     : base("Textures")
51     {
52     this.FromFileName = "";
53     this.TextureType = 0;
54     this.Width = 0;
55     this.Height = 0;
56     this.Encoding = 0;
57     this.SubFormat = 0;
58     this.Layout = new Layout();
59     this.Images = new List<Image>();
60     //this.ExtendedData = new IntPtr();
61     //this.NativePointer = IntPtr.Zero;
62     this._rigResource = new GrannyRigResource();
63     this.Index = index;
64     }
65 william 72 internal static Texture ReadFromMemory(IntPtr pointer)
66     {
67 william 86 try
68     {
69 william 72 if (pointer == IntPtr.Zero) return null;
70     native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);
71     Texture managed = ReadFromNative(native);
72     managed.NativePointer = pointer;
73     return managed;
74 william 86 }
75 william 106 catch (Exception ex)
76 william 86 {
77 william 95 StackTrace st = new StackTrace(true);
78 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
79 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
80 william 102 #endif
81 william 86 return default(Texture);
82     }
83 william 72 }
84    
85     internal static Texture ReadFromNative(native.Texture native)
86     {
87 william 86 try
88 william 72 {
89 william 86 Texture managed = new Texture();
90     managed.FromFileName = native.FromFileName;
91     managed.TextureType = native.TextureType;
92     managed.Width = native.Width;
93     managed.Height = native.Height;
94     managed.Encoding = native.Encoding;
95     managed.SubFormat = native.SubFormat;
96     managed.Layout = Layout.ReadFromNative(native.Layout);
97     IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
98     int length = images.Length;
99     managed.Images = new List<Image>(length);
100     foreach (IntPtr ptr in images)
101     {
102     Image _tmp = new Image();
103     _tmp.NativePointer = ptr;
104     managed.Images.Add(_tmp);
105     }
106     for (int i = 0; i < length; i++)
107     {
108     managed.Images[i] = Image.ReadFromMemory(images[i]);
109     }
110     managed.ExtendedData = native.ExtendedData;
111     return managed;
112 william 72 }
113 william 106 catch (Exception ex)
114 william 72 {
115 william 95 StackTrace st = new StackTrace(true);
116 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
117 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
118 william 102 #endif
119 william 86 return default(Texture);
120 william 72 }
121     }
122    
123     #region ITexture Members
124 william 141
125     [RefreshPropertiesAttribute(RefreshProperties.All)]
126     public string TextureTypeFormat
127     {
128     get
129     {
130     string texture_type = "Unknown Texture Type";
131    
132     foreach (int val in Enum.GetValues(typeof(granny_texture_type)))
133     {
134     if (val == this.TextureType)
135     {
136     texture_type = Enum.GetName(typeof(granny_texture_type),val);
137     break;
138     }
139     }
140     return texture_type;
141     }
142     }
143     [RefreshPropertiesAttribute(RefreshProperties.All)]
144     public string EncodingFormat
145     {
146     get
147     {
148     string encodingformat = "Unknown Encoding Format";
149    
150     foreach (int val in Enum.GetValues(typeof(granny_texture_encoding)))
151     {
152     if (val == this.Encoding)
153     {
154     encodingformat = Enum.GetName(typeof(granny_texture_encoding), val);
155     break;
156     }
157     }
158     return encodingformat;
159     }
160     }
161    
162     [RefreshPropertiesAttribute(RefreshProperties.All)]
163 william 75 public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
164 william 141 [RefreshPropertiesAttribute(RefreshProperties.All)]
165 william 72 public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
166 william 141 [RefreshPropertiesAttribute(RefreshProperties.All)]
167 william 72 public int Width { get { return _Width; } set { _Width = value; } }
168 william 141 [RefreshPropertiesAttribute(RefreshProperties.All)]
169 william 72 public int Height { get { return _Height; } set { _Height = value; } }
170 william 141 [RefreshPropertiesAttribute(RefreshProperties.All)]
171 william 72 public int Encoding { get { return _Encoding; } set { _Encoding = value; } }
172 william 141 [RefreshPropertiesAttribute(RefreshProperties.All)]
173 william 72 public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
174 william 141 [RefreshPropertiesAttribute(RefreshProperties.All)]
175     [Browsable(true)]
176 william 72 public Layout Layout { get { return _Layout; } set { _Layout = value; } }
177 william 141 [RefreshPropertiesAttribute(RefreshProperties.All)]
178 william 72 public List<Image> Images { get { return _Images; } set { _Images = value; } }
179     #endregion
180 william 79
181     #region INativePointer Members
182     private IntPtr _NativePointer;
183     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
184     #endregion
185 william 82
186     #region IExtendedData Members
187     private IntPtr _ExtendedData;
188     public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
189     #endregion
190 william 141
191     #region IResource Members
192     private int _index;
193     [RefreshPropertiesAttribute(RefreshProperties.All)]
194     internal int Index { get { return _index; } set { _index = value; } }
195     #endregion
196     #region IEmbeddedResource Members
197     [RefreshPropertiesAttribute(RefreshProperties.All)]
198     internal string IndexName { get { return new GrannyRigResource("Texture", this.Index, this.Name).ResourceBlockIndexFormat; } }
199     [RefreshPropertiesAttribute(RefreshProperties.All)]
200     internal string FullName { get { return new GrannyRigResource("Texture", this.Index, this.Name).ResourceBlockFormat; } }
201     [RefreshPropertiesAttribute(RefreshProperties.All)]
202     internal string Name { get { return this.FromFileName; } set { this.FromFileName = value; } }
203     #endregion
204 william 72 }
205     }

  ViewVC Help
Powered by ViewVC 1.1.22