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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 141 - (show 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 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.helpers;
5
6 using gr2lib.core.interfaces;
7 using System.Diagnostics;
8 using gr2lib.core.exceptions;
9 using gr2lib.core.ui.helpers;
10 using System.ComponentModel;
11 using gr2lib.core.typedefs;
12
13 namespace gr2lib.core.coretypes.implementation
14 {
15 public class Texture : GrannyRigParentResource, ITexture
16 {
17 private GrannyRigResource _rigResource;
18
19 private FilePath _FromFileName;
20 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
29 public override string ToString()
30 {
31 return this.FromFileName.Name;
32 }
33
34
35 public Texture() : base("Textures")
36 {
37 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 //this.ExtendedData = new IntPtr();
46 //this.NativePointer = IntPtr.Zero;
47 this._rigResource = new GrannyRigResource();
48 }
49 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 internal static Texture ReadFromMemory(IntPtr pointer)
66 {
67 try
68 {
69 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 }
75 catch (Exception ex)
76 {
77 StackTrace st = new StackTrace(true);
78 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
79 Granny2ExceptionWriter.WriteToConsole(ex,st);
80 #endif
81 return default(Texture);
82 }
83 }
84
85 internal static Texture ReadFromNative(native.Texture native)
86 {
87 try
88 {
89 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 }
113 catch (Exception ex)
114 {
115 StackTrace st = new StackTrace(true);
116 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
117 Granny2ExceptionWriter.WriteToConsole(ex,st);
118 #endif
119 return default(Texture);
120 }
121 }
122
123 #region ITexture Members
124
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 public FilePath FromFileName { get { return _FromFileName; } set { _FromFileName = value; } }
164 [RefreshPropertiesAttribute(RefreshProperties.All)]
165 public int TextureType { get { return _TextureType; } set { _TextureType = value; } }
166 [RefreshPropertiesAttribute(RefreshProperties.All)]
167 public int Width { get { return _Width; } set { _Width = value; } }
168 [RefreshPropertiesAttribute(RefreshProperties.All)]
169 public int Height { get { return _Height; } set { _Height = value; } }
170 [RefreshPropertiesAttribute(RefreshProperties.All)]
171 public int Encoding { get { return _Encoding; } set { _Encoding = value; } }
172 [RefreshPropertiesAttribute(RefreshProperties.All)]
173 public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
174 [RefreshPropertiesAttribute(RefreshProperties.All)]
175 [Browsable(true)]
176 public Layout Layout { get { return _Layout; } set { _Layout = value; } }
177 [RefreshPropertiesAttribute(RefreshProperties.All)]
178 public List<Image> Images { get { return _Images; } set { _Images = value; } }
179 #endregion
180
181 #region INativePointer Members
182 private IntPtr _NativePointer;
183 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
184 #endregion
185
186 #region IExtendedData Members
187 private IntPtr _ExtendedData;
188 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
189 #endregion
190
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 }
205 }

  ViewVC Help
Powered by ViewVC 1.1.22