Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TextureMapDialog.cpp
Go to the documentation of this file.
1 /* Project Magic 2.0
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Magic.exe
6  FILE: TextureMapDialog.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Texture Mapping Dialog implementation file
13 */
14 
15 
16 #include "stdafx.h"
17 #include "Magic.h"
18 #include "MagicDoc.h"
19 #include "MagicView.h"
20 #include "Selection.h"
21 #include "TextureMapDialog.h"
22 #include "Thumbnail.h"
23 
24 #include "Bitmap.h"
25 #include "Solid.h"
26 #include "Polygon.h"
27 #include "Pcx.h"
28 
29 #ifdef _DEBUG
30 #define new DEBUG_NEW
31 #undef THIS_FILE
32 static char THIS_FILE[] = __FILE__;
33 #endif
34 
35 // +--------------------------------------------------------------------+
36 // TextureMapDialog dialog
37 // +--------------------------------------------------------------------+
38 
40  : CDialog(TextureMapDialog::IDD, pParent), doc(0), material(0), model(0), blank(0)
41 {
42  //{{AFX_DATA_INIT(TextureMapDialog)
43  mMaterialIndex = -1;
44  mFlip = FALSE;
45  mMirror = FALSE;
46  mRotate = FALSE;
47  mScaleV = 0.0;
48  mAxis = -1;
49  mScaleU = 0.0;
50  mMapType = -1;
51  //}}AFX_DATA_INIT
52 
53  Color gray = Color::LightGray;
54  blank = new Bitmap(1,1,&gray);
55  blank->ScaleTo(128,128);
56 
57  if (pParent) {
58  doc = pParent->GetDocument();
59 
60  if (doc && doc->GetSolid()) {
61  model = doc->GetSolid()->GetModel();
62  }
63 
64  if (doc && doc->GetSelection()) {
65  Selection* seln = doc->GetSelection();
66 
67  if (seln->GetPolys().size() > 0) {
68  material = seln->GetPolys().first()->material;
70  }
71  }
72  }
73 }
74 
76 {
77  delete blank;
78 }
79 
80 void TextureMapDialog::DoDataExchange(CDataExchange* pDX)
81 {
83  //{{AFX_DATA_MAP(TextureMapDialog)
84  DDX_Control(pDX, IDC_MAPPING, mMapping);
85  DDX_Control(pDX, IDC_MATERIAL, mMaterialList);
86  DDX_Control(pDX, IDC_TEXTURE_PREVIEW, mMaterialThumb);
87  DDX_CBIndex(pDX, IDC_MATERIAL, mMaterialIndex);
88  DDX_Check(pDX, IDC_ALIGN_FLIP, mFlip);
89  DDX_Check(pDX, IDC_ALIGN_MIRROR, mMirror);
90  DDX_Check(pDX, IDC_ALIGN_ROTATE, mRotate);
91  DDX_Text(pDX, IDC_SCALE_V, mScaleV);
92  DDX_Radio(pDX, IDC_ALIGN_X, mAxis);
93  DDX_Text(pDX, IDC_SCALE_U, mScaleU);
94  DDX_CBIndex(pDX, IDC_MAPPING, mMapType);
95  //}}AFX_DATA_MAP
96 
97  if (pDX->m_bSaveAndValidate) {
98  mMaterialIndex = mMaterialList.GetCurSel()-1;
99  }
100 }
101 
102 
103 BEGIN_MESSAGE_MAP(TextureMapDialog, CDialog)
104  //{{AFX_MSG_MAP(TextureMapDialog)
105  ON_WM_PAINT()
106  ON_CBN_SELCHANGE(IDC_MATERIAL, OnSelectMaterial)
107  ON_BN_CLICKED(IDC_ALIGN_X, OnAlign)
108  ON_BN_CLICKED(IDC_ALIGN_Y, OnAlign)
109  ON_BN_CLICKED(IDC_ALIGN_Z, OnAlign)
110  //}}AFX_MSG_MAP
111 END_MESSAGE_MAP()
112 
113 // +--------------------------------------------------------------------+
114 // TextureMapDialog message handlers
115 // +--------------------------------------------------------------------+
116 
117 BOOL TextureMapDialog::OnInitDialog()
118 {
119  CDialog::OnInitDialog();
120 
121  mMaterialList.AddString("<none>");
122 
123  if (model && model->NumMaterials()) {
124  ListIter<Material> iter = model->GetMaterials();
125  while (++iter) {
126  Material* mtl = iter.value();
127  mMaterialList.AddString(mtl->name);
128  }
129  }
130 
131  mMaterialList.SetCurSel(mMaterialIndex);
132  mMapping.SetCurSel(0);
133 
134  if (material) {
135  material->CreateThumbnail();
136  ThumbPreview(mMaterialThumb.GetSafeHwnd(), material->thumbnail);
137  }
138 
139  return TRUE;
140 }
141 
142 // +--------------------------------------------------------------------+
143 
145 {
146  CPaintDC dc(this); // device context for painting
147 
148  if (material && material->thumbnail) {
150  }
151  else {
152  ThumbPreview(mMaterialThumb.GetSafeHwnd(), blank);
153  }
154 }
155 
157 {
158  mMaterialIndex = mMaterialList.GetCurSel()-1;
159  material = 0;
160 
161  if (model && mMaterialIndex >= 0 && mMaterialIndex < model->NumMaterials()) {
163  }
164 
165  if (material) {
168  }
169  else {
170  ThumbPreview(mMaterialThumb.GetSafeHwnd(), blank);
171  }
172 }
173 
175 {
176  if (mMapping.GetCurSel() == 0) {
177  mMapping.SetCurSel(1);
178  UpdateData(TRUE);
179 
180  mScaleU = 1;
181  mScaleV = 1;
182  mMaterialIndex++;
183  UpdateData(FALSE);
184  }
185 }