/[Sims3RigEditor]/trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h
ViewVC logotype

Annotation of /trunk/gr2lib_cpp/gr2lib_rigeditor_frm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (hide annotations) (download)
Mon Aug 2 08:57:24 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 30597 byte(s)
Implement the importing/saving of user images...
Imported Image(s) Encoding must be forced to: granny_texture_encoding.GrannyRawTextureEncoding
For the images to be read/written properly.
If colors are messed up - try switching between the RGB(A) and BGR(A) SubFormats

1 william 19 #define SHOW_DEBUG_MENU // if defined, will show the debug menu -> else it will not be shown
2 william 23
3     #define granny_pixel_layout_bitshift_size 4
4    
5 william 5 #pragma once
6 william 7 //#include "gr2lib_core.h"
7     //#include "gr2lib_core_imports.h"
8     #ifndef GR2LIB_RIGEDITOR_FRM_H
9     #define GR2LIB_RIGEDITOR_FRM_H
10     #include "grannyfile.h"
11 william 12 //#include "guicon.h"
12 william 19 #include "VSDebugOutput.h"
13     #include "GrannyFileWriter.h"
14 william 7 #include <stdio.h>
15     #include <iostream>
16     #include <stdlib.h>
17     #include <assert.h>
18     #include <string>
19     #include <sstream>
20 william 12 #include <vcclr.h>
21 william 7 using namespace std;
22 william 5
23 william 7 using namespace gr2lib::core;
24     using namespace gr2lib::core::coretypes::implementation;
25 william 14 using namespace gr2lib::core::apiversion;
26 william 22 using namespace gr2lib::core::ui::helpers;
27     using namespace gr2lib::core::helpers;
28 william 5 using namespace System;
29     using namespace System::ComponentModel;
30     using namespace System::Collections;
31     using namespace System::Collections::Generic;
32     using namespace System::Windows::Forms;
33     using namespace System::Data;
34     using namespace System::Drawing;
35 william 6 using namespace System::Runtime::InteropServices;
36     //
37     //namespace gr2lib
38     //{
39     // namespace core
40     // {
41     // namespace rigeditor
42     // {
43 william 12 /// <summary>
44     /// Summary for gr2lib_rigeditor_frm
45     ///
46     /// WARNING: If you change the name of this class, you will need to change the
47     /// 'Resource File Name' property for the managed resource compiler tool
48     /// associated with all .resx files this class depends on. Otherwise,
49     /// the designers will not be able to interact properly with localized
50     /// resources associated with this form.
51     /// </summary>
52     public ref class gr2lib_rigeditor_frm : public System::Windows::Forms::Form
53     {
54     private:
55     grannyfile* _grn_file;
56     void LogApplicationStartup()
57     {
58     const char* ApplicationName = "GR2Lib Rig Editor: ";
59 william 5
60 william 12 const char* product_version = (char*)(void*)Marshal::StringToHGlobalAnsi(Application::ProductVersion);
61     const char* version_prefix = "v";
62     const char* startup_string = " {Starting up...}";
63 william 5
64 william 6
65 william 12 int msg_malloc = (strlen(ApplicationName) + strlen(product_version) + strlen(version_prefix) + strlen(startup_string)) + 3;
66 william 5
67 william 12 char* msg = (char*)malloc(msg_malloc);
68     for (int i=0; i<msg_malloc; i++) {
69     msg[i] = 0; // Initialize all elements to zero.
70     }
71 william 5
72 william 12 strcat(msg,ApplicationName);
73     strcat(msg,version_prefix);
74     strcat(msg,product_version);
75     strcat(msg,startup_string);
76     strcat(msg,"\n");
77     _grn_file->_logger->LogMessage(msg);
78     }
79     public:
80     gr2lib_rigeditor_frm(void)
81     {
82     InitializeComponent();
83     _grn_file = new grannyfile();
84     //
85     //TODO: Add the constructor code here
86     //
87     // Log Application Startup
88     LogApplicationStartup();
89     }
90     gr2lib_rigeditor_frm(grannyfile* grn_file)
91     {
92     InitializeComponent();
93     // parse art tool info
94     _grn_file = grn_file;
95    
96     // Log Application Startup
97     LogApplicationStartup();
98    
99 william 15 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
100     ConvertToManaged();
101     propgrid->SelectedObject = this->GR2LibPropertyWrapper;
102 william 12
103     }
104    
105     protected:
106     /// <summary>
107     /// Clean up any resources being used.
108     /// </summary>
109     ~gr2lib_rigeditor_frm()
110     {
111     if (components)
112     {
113     delete components;
114     }
115     }
116     private: System::Windows::Forms::PropertyGrid^ propgrid;
117     protected:
118     private: System::Windows::Forms::MenuStrip^ mainmenu;
119     private: System::Windows::Forms::ToolStripMenuItem^ mnuFile;
120     private: System::Windows::Forms::ToolStripMenuItem^ mnuItemExit;
121     private: System::Windows::Forms::ToolStripMenuItem^ mnuItemOpen;
122     private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSave;
123     private: System::Windows::Forms::ToolStripMenuItem^ mnuItemSaveAs;
124 william 19 private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug;
125     private: System::Windows::Forms::ToolStripMenuItem^ mnuDebug_UnitTests;
126     private: System::Windows::Forms::ToolStripMenuItem^ mnuTestArtToolInfoReturnValues;
127 william 12
128 william 19 private: System::Windows::Forms::OpenFileDialog^ RigLoader;
129     private: System::Windows::Forms::ToolStripMenuItem^ mnuTestExporterInfoReturnValues;
130     private: System::Windows::Forms::SaveFileDialog^ RigSaver;
131 william 26 private: System::Windows::Forms::ToolStripMenuItem^ mnuItemClose;
132 william 19
133    
134    
135    
136 william 12 protected:
137    
138     private:
139     /// <summary>
140     /// Required designer variable.
141     /// </summary>
142     System::ComponentModel::Container ^components;
143    
144     #pragma region Windows Form Designer generated code
145     /// <summary>
146     /// Required method for Designer support - do not modify
147     /// the contents of this method with the code editor.
148     /// </summary>
149     void InitializeComponent(void)
150     {
151     this->propgrid = (gcnew System::Windows::Forms::PropertyGrid());
152     this->mainmenu = (gcnew System::Windows::Forms::MenuStrip());
153     this->mnuFile = (gcnew System::Windows::Forms::ToolStripMenuItem());
154     this->mnuItemOpen = (gcnew System::Windows::Forms::ToolStripMenuItem());
155     this->mnuItemSave = (gcnew System::Windows::Forms::ToolStripMenuItem());
156     this->mnuItemSaveAs = (gcnew System::Windows::Forms::ToolStripMenuItem());
157     this->mnuItemExit = (gcnew System::Windows::Forms::ToolStripMenuItem());
158 william 19 this->mnuDebug = (gcnew System::Windows::Forms::ToolStripMenuItem());
159     this->mnuDebug_UnitTests = (gcnew System::Windows::Forms::ToolStripMenuItem());
160     this->mnuTestArtToolInfoReturnValues = (gcnew System::Windows::Forms::ToolStripMenuItem());
161     this->mnuTestExporterInfoReturnValues = (gcnew System::Windows::Forms::ToolStripMenuItem());
162     this->RigLoader = (gcnew System::Windows::Forms::OpenFileDialog());
163     this->RigSaver = (gcnew System::Windows::Forms::SaveFileDialog());
164 william 26 this->mnuItemClose = (gcnew System::Windows::Forms::ToolStripMenuItem());
165 william 12 this->mainmenu->SuspendLayout();
166     this->SuspendLayout();
167     //
168     // propgrid
169     //
170     this->propgrid->Dock = System::Windows::Forms::DockStyle::Fill;
171     this->propgrid->Location = System::Drawing::Point(0, 24);
172     this->propgrid->Name = L"propgrid";
173 william 22 this->propgrid->PropertySort = System::Windows::Forms::PropertySort::Categorized;
174 william 12 this->propgrid->Size = System::Drawing::Size(558, 456);
175     this->propgrid->TabIndex = 4;
176     this->propgrid->ToolbarVisible = false;
177     //
178     // mainmenu
179     //
180 william 19 this->mainmenu->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuFile, this->mnuDebug});
181 william 12 this->mainmenu->Location = System::Drawing::Point(0, 0);
182     this->mainmenu->Name = L"mainmenu";
183     this->mainmenu->Size = System::Drawing::Size(558, 24);
184     this->mainmenu->TabIndex = 3;
185     this->mainmenu->Text = L"menuStrip1";
186     //
187     // mnuFile
188     //
189 william 26 this->mnuFile->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->mnuItemOpen,
190     this->mnuItemClose, this->mnuItemSave, this->mnuItemSaveAs, this->mnuItemExit});
191 william 12 this->mnuFile->Name = L"mnuFile";
192     this->mnuFile->Size = System::Drawing::Size(37, 20);
193     this->mnuFile->Text = L"&File";
194     //
195     // mnuItemOpen
196     //
197     this->mnuItemOpen->Name = L"mnuItemOpen";
198 william 26 this->mnuItemOpen->Size = System::Drawing::Size(152, 22);
199 william 12 this->mnuItemOpen->Text = L"&Open";
200     this->mnuItemOpen->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemOpen_Click);
201     //
202     // mnuItemSave
203     //
204     this->mnuItemSave->Name = L"mnuItemSave";
205 william 26 this->mnuItemSave->Size = System::Drawing::Size(152, 22);
206 william 12 this->mnuItemSave->Text = L"&Save";
207 william 19 this->mnuItemSave->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSave_Click);
208 william 12 //
209     // mnuItemSaveAs
210     //
211     this->mnuItemSaveAs->Name = L"mnuItemSaveAs";
212 william 26 this->mnuItemSaveAs->Size = System::Drawing::Size(152, 22);
213 william 12 this->mnuItemSaveAs->Text = L"Save &As";
214 william 19 this->mnuItemSaveAs->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemSaveAs_Click);
215 william 12 //
216     // mnuItemExit
217     //
218     this->mnuItemExit->Name = L"mnuItemExit";
219 william 26 this->mnuItemExit->Size = System::Drawing::Size(152, 22);
220 william 12 this->mnuItemExit->Text = L"&Exit";
221     this->mnuItemExit->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemExit_Click);
222     //
223 william 19 // mnuDebug
224     //
225     this->mnuDebug->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->mnuDebug_UnitTests});
226     this->mnuDebug->Name = L"mnuDebug";
227     this->mnuDebug->Size = System::Drawing::Size(56, 20);
228     this->mnuDebug->Text = L"&DEBUG";
229     //
230     // mnuDebug_UnitTests
231     //
232     this->mnuDebug_UnitTests->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->mnuTestArtToolInfoReturnValues,
233     this->mnuTestExporterInfoReturnValues});
234     this->mnuDebug_UnitTests->Name = L"mnuDebug_UnitTests";
235     this->mnuDebug_UnitTests->Size = System::Drawing::Size(135, 22);
236     this->mnuDebug_UnitTests->Text = L"&Unit Tests...";
237     //
238     // mnuTestArtToolInfoReturnValues
239     //
240     this->mnuTestArtToolInfoReturnValues->Name = L"mnuTestArtToolInfoReturnValues";
241     this->mnuTestArtToolInfoReturnValues->Size = System::Drawing::Size(238, 22);
242     this->mnuTestArtToolInfoReturnValues->Text = L"Test ArtoolInfo Rerturn values";
243     this->mnuTestArtToolInfoReturnValues->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuTestArtToolInfoReturnValues_Click);
244     //
245     // mnuTestExporterInfoReturnValues
246     //
247     this->mnuTestExporterInfoReturnValues->Name = L"mnuTestExporterInfoReturnValues";
248     this->mnuTestExporterInfoReturnValues->Size = System::Drawing::Size(238, 22);
249     this->mnuTestExporterInfoReturnValues->Text = L"Test ExporterInfo Return Values";
250     this->mnuTestExporterInfoReturnValues->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuTestExporterInfoReturnValues_Click);
251     //
252     // RigLoader
253     //
254     this->RigLoader->DefaultExt = L"gr2";
255     this->RigLoader->Filter = L"Granny2 Files|*.gr2;*.grannyrig";
256     this->RigLoader->SupportMultiDottedExtensions = true;
257     this->RigLoader->Title = L"Please choose the Granny2 Rig file to load";
258     //
259     // RigSaver
260     //
261     this->RigSaver->DefaultExt = L"gr2";
262     this->RigSaver->Filter = L"Granny2 Files|*.gr2;*.grannyrig";
263     this->RigSaver->SupportMultiDottedExtensions = true;
264     this->RigSaver->Title = L"Please select the Granny2 Rig to write to or create";
265     //
266 william 26 // mnuItemClose
267     //
268     this->mnuItemClose->Name = L"mnuItemClose";
269     this->mnuItemClose->Size = System::Drawing::Size(152, 22);
270     this->mnuItemClose->Text = L"&Close";
271     this->mnuItemClose->Click += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::mnuItemClose_Click);
272     //
273 william 12 // gr2lib_rigeditor_frm
274     //
275     this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
276     this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
277     this->ClientSize = System::Drawing::Size(558, 480);
278     this->Controls->Add(this->propgrid);
279     this->Controls->Add(this->mainmenu);
280     this->Name = L"gr2lib_rigeditor_frm";
281     this->Text = L"gr2lib_rigeditor_frm";
282 william 19 this->Load += gcnew System::EventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_Load);
283 william 12 this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &gr2lib_rigeditor_frm::gr2lib_rigeditor_frm_FormClosed);
284     this->mainmenu->ResumeLayout(false);
285     this->mainmenu->PerformLayout();
286     this->ResumeLayout(false);
287     this->PerformLayout();
288    
289     }
290     #pragma endregion
291 william 23
292 william 6 #pragma region MarshalToMananaged
293 william 15 //ArtToolInfo^ _ArtToolInfo;
294     //ExporterInfo^ _ExporterInfo;
295     GR2LibWrapper^ GR2LibPropertyWrapper;
296 william 6
297 william 12 #pragma region ManagedNativeParsing
298 william 15 void ConvertToManaged()
299 william 12 {
300     // Art Tool info
301 william 15 ArtToolInfo_ToManaged(_grn_file->GrannyFileInfo->ArtToolInfo);
302 william 14 // Exporter Info
303 william 15 ExporterInfo_ToManaged(_grn_file->GrannyFileInfo->ExporterInfo);
304 william 22 // Texture List
305     Textures_ToManaged(_grn_file->GrannyFileInfo->Textures,_grn_file->GrannyFileInfo->TextureCount);
306 william 12 }
307     void ConvertToNative()
308     {
309     // Art Tool info
310     ArtToolInfo_ToNative();
311 william 14 // Exporter Info
312     ExporterInfo_ToNative();
313 william 23 // Texture List
314     Textures_ToNative();
315 william 12 }
316     #pragma endregion
317 william 6
318 william 14 #pragma region ArtToolInfo_ToManaged
319 william 15 void ArtToolInfo_ToManaged(granny_art_tool_info* toolinfo)
320 william 12 {
321 william 15 //GR2LibPropertyWrapper->ArtToolInfo = gcnew ArtToolInfo();
322 william 19 if (toolinfo != NULL)
323     {
324     GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName = gcnew String(reinterpret_cast<const char*>(toolinfo->FromArtToolName));
325 william 6
326 william 19 // Tool Vector
327     Vector3* Origin = new Vector3(
328     toolinfo->Origin[0],
329     toolinfo->Origin[1],
330     toolinfo->Origin[2]);
331     Vector3* Right = new Vector3(
332     toolinfo->RightVector[0],
333     toolinfo->RightVector[1],
334     toolinfo->RightVector[2]);
335     Vector3* Up = new Vector3(
336     toolinfo->UpVector[0],
337     toolinfo->UpVector[1],
338     toolinfo->UpVector[2]);
339     Vector3* Back = new Vector3(
340     toolinfo->BackVector[0],
341     toolinfo->BackVector[1],
342     toolinfo->BackVector[2]);
343     GR2LibPropertyWrapper->ArtToolInfo->Vector = gcnew ArtToolInfoVector(*Origin,*Right,*Up,*Back);
344 william 6
345 william 19 // Tool Version
346     GR2LibPropertyWrapper->ArtToolInfo->ToolVersion = gcnew ArtToolInfoVersion(toolinfo->ArtToolMajorRevision,toolinfo->ArtToolMinorRevision);
347     // Tool Units Per Meter
348     GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter = toolinfo->UnitsPerMeter;
349     }
350 william 12 }
351     #pragma endregion
352 william 14 #pragma region ExporterInfo_ToManaged
353 william 15 void ExporterInfo_ToManaged(granny_exporter_info* toolinfo)
354     {
355     //GR2LibPropertyWrapper->ExporterInfo = gcnew ExporterInfo();
356 william 19 if (toolinfo != NULL)
357     {
358     GR2LibPropertyWrapper->ExporterInfo->ExporterName = gcnew String(reinterpret_cast<const char*>(toolinfo->ExporterName));
359     GR2LibPropertyWrapper->ExporterInfo->Version = gcnew versiontype(
360     toolinfo->ExporterMajorRevision,
361     toolinfo->ExporterMinorRevision,
362     toolinfo->ExporterCustomization,
363     toolinfo->ExporterBuildNumber);
364     }
365 william 14 //_ExporterInfo->ExtendedData = new IntPtr(toolinfo->ExtendedData.Object);
366     }
367     #pragma endregion
368 william 22 #pragma region Textures_ToManaged
369     void Textures_ToManaged(granny_texture** toolinfo, granny_int32 TextureCount)
370     {
371     if (toolinfo != NULL)
372     {
373     /*GR2LibPropertyWrapper->ExporterInfo->ExporterName = gcnew String(reinterpret_cast<const char*>(toolinfo->ExporterName));
374     GR2LibPropertyWrapper->ExporterInfo->Version = gcnew versiontype(
375 william 29 toolinfo->ExporterMajorRevision,
376     toolinfo->ExporterMinorRevision,
377     toolinfo->ExporterCustomization,
378     toolinfo->ExporterBuildNumber);*/
379 william 22 GR2LibPropertyWrapper->Textures = gcnew List<Texture^>();
380     for(int i=0;i<TextureCount;i++)
381     {
382     Texture^ t = gcnew Texture();
383 william 29
384 william 22 t->FromFileName = gcnew FilePath(gcnew String(reinterpret_cast<const char*>(toolinfo[i]->FromFileName)));
385     t->TextureType = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_texture_type>(
386     ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_texture_type>(
387     (gr2lib::core::typedefs::granny_texture_type)toolinfo[i]->TextureType),
388     (gr2lib::core::typedefs::granny_texture_type)toolinfo[i]->TextureType);
389     t->Width = toolinfo[i]->Width;
390     t->Height = toolinfo[i]->Height;
391     t->Encoding = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_texture_encoding>(
392     ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_texture_encoding>(
393     (gr2lib::core::typedefs::granny_texture_encoding)toolinfo[i]->Encoding),
394     (gr2lib::core::typedefs::granny_texture_encoding)toolinfo[i]->Encoding);
395     t->SubFormat = gcnew NameValuePair<String^,gr2lib::core::typedefs::granny_pixel_layout>(
396     ::coreapi::EnumToStringSupport::GetGrannyEnumTypeString<gr2lib::core::typedefs::granny_pixel_layout>(
397     (gr2lib::core::typedefs::granny_pixel_layout)toolinfo[i]->SubFormat),
398     (gr2lib::core::typedefs::granny_pixel_layout)toolinfo[i]->SubFormat);
399     t->Layout = gcnew gr2lib::core::coretypes::implementation::Layout();
400 william 29 t->Layout->BytesPerPixel = toolinfo[i]->Layout.BytesPerPixel;
401     for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
402     {
403     t->Layout->ShiftForComponent[j] = toolinfo[i]->Layout.ShiftForComponent[j];
404     t->Layout->BitsForComponent[j] = toolinfo[i]->Layout.BitsForComponent[j];
405     }
406     t->Layout->NativePointer = *new IntPtr(&toolinfo[i]->Layout);
407 william 6
408 william 22 t->Images = gcnew List<gr2lib::core::coretypes::implementation::Image^>();
409     for(int j=0;j<toolinfo[i]->ImageCount;j++)
410     {
411     gr2lib::core::coretypes::implementation::Image^ img = gcnew gr2lib::core::coretypes::implementation::Image();
412     img->MIPLevels = gcnew List<gr2lib::core::coretypes::implementation::MIPLevel^>();
413 william 29
414 william 22 for(int k=0;k<toolinfo[i]->Images[j].MIPLevelCount;k++)
415     {
416     gr2lib::core::coretypes::implementation::MIPLevel^ mip = gcnew gr2lib::core::coretypes::implementation::MIPLevel();
417     mip->Stride = toolinfo[i]->Images[j].MIPLevels[k].Stride;
418     mip->Pixels = gcnew List<gr2lib::core::coretypes::implementation::Pixel^>();
419    
420     unsigned char* bytes = (unsigned char*)malloc(toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount);
421     for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
422     {
423     bytes[l] =0;
424     }
425     bytes = (unsigned char*)toolinfo[i]->Images[j].MIPLevels[k].PixelBytes;
426    
427     for(int l =0;l<toolinfo[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
428     {
429     gr2lib::core::coretypes::implementation::Pixel^ pix = gcnew gr2lib::core::coretypes::implementation::Pixel();
430     pix->UInt8 = bytes[l];
431 william 29 pix->NativeTexture = t;
432     pix->NativeTexturePointer = *new IntPtr(toolinfo[i]);
433 william 22 mip->Pixels->Add(pix);
434     }
435    
436     img->MIPLevels->Add(mip);
437     }
438    
439     t->Images->Add(img);
440 william 29 t->NativePointer = *new IntPtr(toolinfo[i]);
441 william 22 }
442     GR2LibPropertyWrapper->Textures->Add(t);
443     }
444     }
445     }
446     #pragma endregion
447    
448 william 12 #pragma region MarshalToNative
449 william 6
450 william 14 #pragma region ArtToolInfo_ToNative
451 william 12 void ArtToolInfo_ToNative()
452     {
453 william 19 if (_grn_file->GrannyFileInfo->ArtToolInfo == NULL)
454     {
455     _grn_file->GrannyFileInfo->ArtToolInfo = new granny_art_tool_info();
456     }
457 william 6
458 william 15 _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ArtToolInfo->FromArtToolName).ToPointer();
459     _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Major;
460     _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision = GR2LibPropertyWrapper->ArtToolInfo->ToolVersion->Minor;
461     _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter = GR2LibPropertyWrapper->ArtToolInfo->UnitsPerMeter;
462 william 6
463    
464 william 15 _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.x;
465     _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.y;
466     _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Origin.z;
467 william 12
468 william 15 _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.x;
469     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.y;
470     _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Right.z;
471 william 12
472 william 15 _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.x;
473     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.y;
474     _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Up.z;
475 william 12
476 william 15 _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.x;
477     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.y;
478     _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2] = GR2LibPropertyWrapper->ArtToolInfo->Vector->Back.z;
479 william 12
480     }
481     #pragma endregion
482 william 14 #pragma region ExporterInfo_ToNative
483     void ExporterInfo_ToNative()
484     {
485 william 19 if (_grn_file->GrannyFileInfo->ExporterInfo == NULL)
486     {
487     _grn_file->GrannyFileInfo->ExporterInfo = new granny_exporter_info();
488     }
489 william 15 _grn_file->GrannyFileInfo->ExporterInfo->ExporterName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->ExporterInfo->ExporterName).ToPointer();
490     _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->major;
491     _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision = GR2LibPropertyWrapper->ExporterInfo->Version->minor;
492     _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization = GR2LibPropertyWrapper->ExporterInfo->Version->customization;
493     _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber = GR2LibPropertyWrapper->ExporterInfo->Version->build;
494 william 14 //_grn_file->GrannyFileInfo->ExporterInfo->ExtendedData
495     }
496 william 12 #pragma endregion
497 william 22 #pragma region Textures_ToNative
498     void Textures_ToNative()
499     {
500 william 29 //_grn_file->GrannyFileInfo->Textures = (granny_texture**)malloc(GR2LibPropertyWrapper->Textures->Count);
501     //for(int i=0;i<GR2LibPropertyWrapper->Textures->Count;i++) { _grn_file->GrannyFileInfo->Textures[i] = new granny_texture(); }
502 william 23
503     _grn_file->GrannyFileInfo->TextureCount = GR2LibPropertyWrapper->Textures->Count;
504     for(int i=0;i<_grn_file->GrannyFileInfo->TextureCount;i++)
505 william 22 {
506 william 23 _grn_file->GrannyFileInfo->Textures[i]->FromFileName = (char*)Marshal::StringToHGlobalAnsi(GR2LibPropertyWrapper->Textures[i]->FromFileName->FullPath).ToPointer();
507     _grn_file->GrannyFileInfo->Textures[i]->TextureType = (granny_int32)GR2LibPropertyWrapper->Textures[i]->TextureType->Value;
508     _grn_file->GrannyFileInfo->Textures[i]->Width = GR2LibPropertyWrapper->Textures[i]->Width;
509     _grn_file->GrannyFileInfo->Textures[i]->Height = GR2LibPropertyWrapper->Textures[i]->Height;
510     _grn_file->GrannyFileInfo->Textures[i]->Encoding = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Encoding->Value;
511     _grn_file->GrannyFileInfo->Textures[i]->SubFormat = (granny_int32)GR2LibPropertyWrapper->Textures[i]->SubFormat->Value;
512 william 29
513 william 23 _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel = (granny_int32)GR2LibPropertyWrapper->Textures[i]->Layout->BytesPerPixel;
514 william 29 for(int j=0;j<granny_pixel_layout_bitshift_size;j++)
515     {
516     _grn_file->GrannyFileInfo->Textures[i]->Layout.ShiftForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->ShiftForComponent[j];
517     _grn_file->GrannyFileInfo->Textures[i]->Layout.BitsForComponent[j] = GR2LibPropertyWrapper->Textures[i]->Layout->BitsForComponent[j];
518     }
519 william 23
520     _grn_file->GrannyFileInfo->Textures[i]->ImageCount = GR2LibPropertyWrapper->Textures[i]->Images->Count;
521     _grn_file->GrannyFileInfo->Textures[i]->Images = (granny_texture_image*)malloc(_grn_file->GrannyFileInfo->Textures[i]->ImageCount);
522     for(int k=0;k<_grn_file->GrannyFileInfo->Textures[i]->ImageCount;k++) { _grn_file->GrannyFileInfo->Textures[i]->Images[k] = *(new granny_texture_image()); }
523    
524     for(int j=0;j<_grn_file->GrannyFileInfo->Textures[i]->ImageCount;j++)
525     {
526     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels->Count;
527     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels = (granny_texture_mip_level*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount);
528     for(int k=0;k<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount;k++) { _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k] = *(new granny_texture_mip_level()); }
529     for(int k=0;k<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevelCount;k++)
530     {
531     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].Stride = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Stride;
532     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels->Count;
533     _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes = (unsigned char*)malloc(_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount);
534 william 29
535    
536 william 23 for (int l=0;l<_grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelByteCount;l++)
537     {
538 william 29 _grn_file->GrannyFileInfo->Textures[i]->Images[j].MIPLevels[k].PixelBytes[l] = GR2LibPropertyWrapper->Textures[i]->Images[j]->MIPLevels[k]->Pixels[l]->UInt8;
539 william 23 }
540    
541 william 29 //// try to compress texture?
542     //if (_grn_file->GrannyFileInfo->Textures[i]->Encoding == granny_texture_encoding::GrannyBinkTextureEncoding)
543     //{
544     // granny_texture* src = _grn_file->GrannyFileInfo->Textures[i];
545     // granny_texture* dest = new granny_texture();
546     // GrannyBinkCompressTexture(
547     // _grn_file->GrannyFileInfo->Textures[i]->Width,
548     // _grn_file->GrannyFileInfo->Textures[i]->Height,
549     // _grn_file->GrannyFileInfo->Textures[i]->Width * _grn_file->GrannyFileInfo->Textures[i]->Layout.BytesPerPixel,
550     // src,
551     // granny_bink_texture_flags::GrannyBinkEncodeAlpha,
552     // granny_compression_type::GrannyNoCompression,
553     // &dest);
554     //}
555    
556 william 23 }
557     }
558 william 29 //granny_pixel_layout _layout;
559     //GrannyGetRecommendedPixelLayout(_grn_file->GrannyFileInfo->Textures[i],&_layout);
560     //_grn_file->GrannyFileInfo->Textures[i]->Layout = _layout;
561 william 23 _grn_file->GrannyFileInfo->Textures[i]->ExtendedData = *(new granny_variant());
562 william 22 }
563 william 23
564 william 22 }
565 william 14 #pragma endregion
566 william 22 #pragma endregion
567 william 12
568     #pragma endregion
569 william 6 private: System::Void mnuItemExit_Click(System::Object^ sender, System::EventArgs^ e)
570     {
571     ConvertToNative();
572     this->Close();
573     }
574     private: System::Void mnuItemOpen_Click(System::Object^ sender, System::EventArgs^ e)
575     {
576 william 19
577 william 29
578 william 19 System::Windows::Forms::DialogResult result = RigLoader->ShowDialog();
579     if (result != System::Windows::Forms::DialogResult::OK) return;
580     const char* fn = (char*)Marshal::StringToHGlobalAnsi(RigLoader->FileName).ToPointer();
581    
582 william 12 _grn_file = new grannyfile();
583     const char* loading_msg = "Loading File: ";
584     int msg_malloc = (strlen(loading_msg) + strlen(fn));
585     char* msg = (char*)malloc(msg_malloc);
586     for (int i=0; i<msg_malloc; i++) { msg[i] = 0; }
587     strcat(msg,loading_msg);
588     strcat(msg,fn);
589     strcat(msg,"\n");
590     _grn_file->_logger->LogMessage(msg);
591     //_grn_file->_logger->SetLogFileName("c:\\gr2_logs",fn);
592     _grn_file = new grannyfile(fn);
593    
594 william 29 this->GR2LibPropertyWrapper = gcnew GR2LibWrapper();
595     ConvertToManaged();
596 william 15 propgrid->SelectedObject = this->GR2LibPropertyWrapper;
597 william 6 }
598 william 12 private: System::Void gr2lib_rigeditor_frm_FormClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e)
599     {
600     //TerminateConsoleIO();
601     }
602 william 19 private: System::Void gr2lib_rigeditor_frm_Load(System::Object^ sender, System::EventArgs^ e)
603     {
604     #if defined SHOW_DEBUG_MENU
605     mnuDebug->Visible = true;
606     #else
607     mnuDebug->Visible = false;
608     #endif
609     }
610     private: System::Void mnuTestArtToolInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
611     {
612     // Convert ArtToolInfo To Native, and ouput the values -> to check that they were updated correctly
613     ArtToolInfo_ToNative();
614     VSDebugWriterW VSDebugWriter;
615     VSDebugWriter
616     << "\n\n\tArtToolInfo ->"
617     << "\n\t\tTool Name: "
618 william 29 << _grn_file->GrannyFileInfo->ArtToolInfo->FromArtToolName
619 william 19 << "\n\t\tTool Version: "
620 william 29 << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMajorRevision
621     << "." << _grn_file->GrannyFileInfo->ArtToolInfo->ArtToolMinorRevision
622     << "\n\t\tUnits Per Meter: "
623     << _grn_file->GrannyFileInfo->ArtToolInfo->UnitsPerMeter
624     << "\n\t\tOrigin: "
625     << "\n\t\t\tX: "
626     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[0]
627     << "\n\t\t\tY: "
628     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[1]
629     << "\n\t\t\tZ: "
630     << _grn_file->GrannyFileInfo->ArtToolInfo->Origin[2]
631     << "\n\t\tRight: "
632     << "\n\t\t\tX: "
633     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[0]
634     << "\n\t\t\tY: "
635     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[1]
636     << "\n\t\t\tZ: "
637     << _grn_file->GrannyFileInfo->ArtToolInfo->RightVector[2]
638     << "\n\t\tUp: "
639     << "\n\t\t\tX: "
640     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[0]
641     << "\n\t\t\tY: "
642     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[1]
643     << "\n\t\t\tZ: "
644     << _grn_file->GrannyFileInfo->ArtToolInfo->UpVector[2]
645     << "\n\t\tBack: "
646     << "\n\t\t\tX: "
647     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[0]
648     << "\n\t\t\tY: "
649     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[1]
650     << "\n\t\t\tZ: "
651     << _grn_file->GrannyFileInfo->ArtToolInfo->BackVector[2]
652 william 19 ;
653     }
654     private: System::Void mnuTestExporterInfoReturnValues_Click(System::Object^ sender, System::EventArgs^ e)
655     {
656 william 29 // Convert ExporterInfo To Native, and ouput the values -> to check that they were updated correctly
657     ExporterInfo_ToNative();
658 william 19 VSDebugWriterW VSDebugWriter;
659     VSDebugWriter
660     << "\n\n\tExporterInfo ->"
661     << "\n\t\tExporter Name: "
662 william 29 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterName
663 william 19 << "\n\t\tExporter Version: "
664 william 29 << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMajorRevision
665     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterMinorRevision
666     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterCustomization
667     << "." << _grn_file->GrannyFileInfo->ExporterInfo->ExporterBuildNumber
668 william 19 ;
669     }
670     private: System::Void mnuItemSave_Click(System::Object^ sender, System::EventArgs^ e)
671     {
672     // convert Data to Native
673     ConvertToNative();
674     const char* filename = _grn_file->_GrannyFilename;
675 william 20 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
676 william 19 }
677     private: System::Void mnuItemSaveAs_Click(System::Object^ sender, System::EventArgs^ e)
678     {
679 william 29 // convert Data to Native
680 william 19 ConvertToNative();
681     System::Windows::Forms::DialogResult result = RigSaver->ShowDialog();
682     if (result != System::Windows::Forms::DialogResult::OK) return;
683     const char* filename = (char*)Marshal::StringToHGlobalAnsi(RigSaver->FileName).ToPointer();
684 william 20 GrannyFileWriter::WriteFile(filename,_grn_file->GrannyFileInfo,_grn_file->_logger);
685 william 19 }
686 william 26 private: System::Void mnuItemClose_Click(System::Object^ sender, System::EventArgs^ e)
687     {
688 william 29 propgrid->SelectedObject = NULL;
689 william 26 }
690 william 6 };
691     // }
692     // }
693 william 7 //}
694     #endif /* GR2LIB_RIGEDITOR_FRM_H */

  ViewVC Help
Powered by ViewVC 1.1.22