/[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 49 - (hide annotations) (download)
Sun Aug 8 07:43:37 2010 UTC (9 years, 6 months ago) by william
File MIME type: text/plain
File size: 31131 byte(s)
continue support for ST3C textures...

Have BGR ST3C Texture Colors somwhate correct.
BGRA, still having problems with colors & alpha bein applied when there is no alpha

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

  ViewVC Help
Powered by ViewVC 1.1.22