/[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 57 - (hide annotations) (download)
Thu Aug 12 18:49:34 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 33444 byte(s)
update to account for change in pixels class

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

  ViewVC Help
Powered by ViewVC 1.1.22