doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PatchDialog.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "qe3.h"
33 #include "Radiant.h"
34 #include "PatchDialog.h"
35 
36 #ifdef _DEBUG
37 #define new DEBUG_NEW
38 #undef THIS_FILE
39 static char THIS_FILE[] = __FILE__;
40 #endif
41 
43 // CPatchDialog dialog
44 
46 
47 CPatchDialog::CPatchDialog(CWnd* pParent /*=NULL*/)
48  : CDialog(CPatchDialog::IDD, pParent)
49 {
50  //{{AFX_DATA_INIT(CPatchDialog)
51  m_strName = _T("");
52  m_fS = 0.0f;
53  m_fT = 0.0f;
54  m_fX = 0.0f;
55  m_fY = 0.0f;
56  m_fZ = 0.0f;
57  m_fHScale = 0.05f;
58  m_fHShift = 0.05f;
59  m_fRotate = 45;
60  m_fVScale = 0.05f;
61  m_fVShift = 0.05f;
62  //}}AFX_DATA_INIT
63  m_Patch = NULL;
64 }
65 
66 
67 void CPatchDialog::DoDataExchange(CDataExchange* pDX)
68 {
69  CDialog::DoDataExchange(pDX);
70  //{{AFX_DATA_MAP(CPatchDialog)
71  DDX_Control(pDX, IDC_SPIN_VSHIFT, m_wndVShift);
72  DDX_Control(pDX, IDC_SPIN_VSCALE, m_wndVScale);
73  DDX_Control(pDX, IDC_SPIN_ROTATE, m_wndRotate);
74  DDX_Control(pDX, IDC_SPIN_HSHIFT, m_wndHShift);
75  DDX_Control(pDX, IDC_SPIN_HSCALE, m_wndHScale);
76  DDX_Control(pDX, IDC_COMBO_TYPE, m_wndType);
77  DDX_Control(pDX, IDC_COMBO_ROW, m_wndRows);
78  DDX_Control(pDX, IDC_COMBO_COL, m_wndCols);
79  DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
80  DDX_Text(pDX, IDC_EDIT_S, m_fS);
81  DDX_Text(pDX, IDC_EDIT_T, m_fT);
82  DDX_Text(pDX, IDC_EDIT_X, m_fX);
83  DDX_Text(pDX, IDC_EDIT_Y, m_fY);
84  DDX_Text(pDX, IDC_EDIT_Z, m_fZ);
85  DDX_Text(pDX, IDC_HSCALE, m_fHScale);
86  DDX_Text(pDX, IDC_HSHIFT, m_fHShift);
87  DDX_Text(pDX, IDC_ROTATE, m_fRotate);
88  DDX_Text(pDX, IDC_VSCALE, m_fVScale);
89  DDX_Text(pDX, IDC_VSHIFT, m_fVShift);
90  //}}AFX_DATA_MAP
91 }
92 
93 
94 BEGIN_MESSAGE_MAP(CPatchDialog, CDialog)
95  //{{AFX_MSG_MAP(CPatchDialog)
96  ON_BN_CLICKED(IDC_BTN_PATCHDETAILS, OnBtnPatchdetails)
97  ON_BN_CLICKED(IDC_BTN_PATCHFIT, OnBtnPatchfit)
98  ON_BN_CLICKED(IDC_BTN_PATCHNATURAL, OnBtnPatchnatural)
99  ON_BN_CLICKED(IDC_BTN_PATCHRESET, OnBtnPatchreset)
100  ON_CBN_SELCHANGE(IDC_COMBO_COL, OnSelchangeComboCol)
101  ON_CBN_SELCHANGE(IDC_COMBO_ROW, OnSelchangeComboRow)
102  ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType)
103  ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HSCALE, OnDeltaposSpin)
104  ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_ROTATE, OnDeltaposSpin)
105  ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VSCALE, OnDeltaposSpin)
106  ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VSHIFT, OnDeltaposSpin)
107  ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HSHIFT, OnDeltaposSpin)
108  ON_WM_DESTROY()
109  ON_BN_CLICKED(IDC_APPLY, OnApply)
110  //}}AFX_MSG_MAP
111 END_MESSAGE_MAP()
112 
114 // CPatchDialog message handlers
115 
116 void CPatchDialog::OnBtnPatchdetails()
117 {
118  Patch_NaturalizeSelected(true);
119  Sys_UpdateWindows(W_ALL);
120 }
121 
123 {
124  Patch_FitTexturing();
125  Sys_UpdateWindows(W_ALL);
126 }
127 
129 {
130  Patch_NaturalizeSelected();
131  Sys_UpdateWindows(W_ALL);
132 }
133 
135 {
136  //CTextureLayout dlg;
137  //if (dlg.DoModal() == IDOK)
138  //{
139  // Patch_ResetTexturing(dlg.m_fX, dlg.m_fY);
140  //}
141  //Sys_UpdateWindows(W_ALL);
142 }
143 
145 {
147 }
148 
150 {
152 }
153 
155 {
156  // TODO: Add your control notification handler code here
157 
158 }
159 
161 {
162  m_Patch = NULL;
163 
164  CDialog::OnOK();
165 }
166 
167 void CPatchDialog::OnDeltaposSpin(NMHDR* pNMHDR, LRESULT* pResult)
168 {
169  NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
170  UpdateSpinners((pNMUpDown->iDelta > 0), pNMUpDown->hdr.idFrom);
171  *pResult = 0;
172 }
173 
175 {
176  CDialog::OnInitDialog();
177 
178  m_wndHScale.SetRange(0, 1000);
179  m_wndVScale.SetRange(0, 1000);
180  m_wndHShift.SetRange(0, 1000);
181  m_wndVShift.SetRange(0, 1000);
182  m_wndRotate.SetRange(0, 1000);
183 
184  GetPatchInfo();
185 
186  // TODO: Add extra initialization here
187 
188  return TRUE; // return TRUE unless you set the focus to a control
189  // EXCEPTION: OCX Property Pages should return FALSE
190 }
191 
192 
193 
195 {
196  m_Patch = SinglePatchSelected();
197  if (m_Patch != NULL)
198  {
199  CString str;
200  int i;
201  m_wndRows.ResetContent();
202  for (i = 0; i < m_Patch->height; i++)
203  {
204  str.Format("%i", i);
205  m_wndRows.AddString(str);
206  }
207  m_wndRows.SetCurSel(0);
208  m_wndCols.ResetContent();
209  for (i = 0; i < m_Patch->width; i++)
210  {
211  str.Format("%i", i);
212  m_wndCols.AddString(str);
213  }
214  m_wndCols.SetCurSel(0);
215  }
217 }
218 
220 {
221 
222 }
223 
225 {
226  if (g_PatchDialog.GetSafeHwnd() == NULL)
227  {
228  g_PatchDialog.Create(IDD_DIALOG_PATCH);
229  CRect rct;
230  LONG lSize = sizeof(rct);
231  if (LoadRegistryInfo("Radiant::PatchWindow", &rct, &lSize))
232  {
233  g_PatchDialog.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE);
234  }
235  }
236  g_PatchDialog.ShowWindow(SW_SHOW);
237  g_PatchDialog.GetPatchInfo();
238 }
239 
241 {
242  if (g_PatchDialog.GetSafeHwnd() != NULL)
243  {
244  g_PatchDialog.UpdateInfo();
245  }
246 
247 }
248 
250 {
251  if (GetSafeHwnd())
252  {
253  CRect rct;
254  GetWindowRect(rct);
255  SaveRegistryInfo("Radiant::PatchWindow", &rct, sizeof(rct));
256  }
257  CDialog::OnDestroy();
258 }
259 
261 {
262  m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0;
263 
264  if (m_Patch != NULL)
265  {
266  int r = m_wndRows.GetCurSel();
267  int c = m_wndCols.GetCurSel();
268  if (r >= 0 && r < m_Patch->height && c >= 0 && c < m_Patch->width)
269  {
270  m_fX = m_Patch->ctrl(c,r).xyz[0];
271  m_fY = m_Patch->ctrl(c,r).xyz[1];
272  m_fZ = m_Patch->ctrl(c,r).xyz[2];
273  m_fS = m_Patch->ctrl(c,r).st[0];
274  m_fT = m_Patch->ctrl(c,r).st[1];
275  }
276  }
277  UpdateData(FALSE);
278 }
279 
281 {
282  GetPatchInfo();
283 }
284 
286 {
287  UpdateData(TRUE);
288  if (m_Patch != NULL)
289  {
290  int r = m_wndRows.GetCurSel();
291  int c = m_wndCols.GetCurSel();
292  if (r >= 0 && r < m_Patch->height && c >= 0 && c < m_Patch->width)
293  {
294  m_Patch->ctrl(c,r).xyz[0] = m_fX;
295  m_Patch->ctrl(c,r).xyz[1] = m_fY;
296  m_Patch->ctrl(c,r).xyz[2] = m_fZ;
297  m_Patch->ctrl(c,r).st[0] = m_fS;
298  m_Patch->ctrl(c,r).st[1] = m_fT;
299  Patch_MakeDirty(m_Patch);
300  Sys_UpdateWindows(W_ALL);
301  }
302  }
303 }
304 
305 void CPatchDialog::UpdateSpinners(bool bUp, int nID)
306 {
307  texdef_t td;
308 
309  td.rotate = 0.0;
310  td.scale[0] = td.scale[1] = 0.0;
311  td.shift[0] = td.shift[1] = 0.0;
312  td.value = 0;
313 
314 
315  UpdateData(TRUE);
316 
317  if (nID == IDC_SPIN_ROTATE)
318  {
319  if (bUp)
320  td.rotate = m_fRotate;
321  else
322  td.rotate = -m_fRotate;
323  }
324  else if (nID == IDC_SPIN_HSCALE)
325  {
326  if (bUp)
327  td.scale[0] = 1 - m_fHScale;
328  else
329  td.scale[0] = 1 + m_fHScale;
330  }
331  else if (nID == IDC_SPIN_VSCALE)
332  {
333  if (bUp)
334  td.scale[1] = 1 - m_fVScale;
335  else
336  td.scale[1] = 1 + m_fVScale;
337  }
338 
339  else if (nID == IDC_SPIN_HSHIFT)
340  {
341  if (bUp)
342  td.shift[0] = m_fHShift;
343  else
344  td.shift[0] = -m_fHShift;
345  }
346  else if (nID == IDC_SPIN_VSHIFT)
347  {
348  if (bUp)
349  td.shift[1] = m_fVShift;
350  else
351  td.shift[1] = -m_fVShift;
352  }
353 
354  Patch_SetTextureInfo(&td);
355  Sys_UpdateWindows(W_CAMERA);
356 }
357 
358 
void GetPatchInfo()
patchMesh_t * m_Patch
Definition: PatchDialog.h:42
void WINAPI Sys_UpdateWindows(int nBits)
Definition: MainFrm.cpp:3974
CComboBox m_wndType
Definition: PatchDialog.h:59
afx_msg void OnDestroy()
void UpdateSpinners(bool bUp, int nID)
#define IDC_ROTATE
afx_msg void OnSelchangeComboCol()
CSpinButtonCtrl m_wndVShift
Definition: PatchDialog.h:54
afx_msg void OnBtnPatchfit()
float m_fVScale
Definition: PatchDialog.h:71
virtual void OnOK()
void SetPatchInfo()
CComboBox m_wndCols
Definition: PatchDialog.h:61
float m_fHScale
Definition: PatchDialog.h:68
#define IDC_HSCALE
afx_msg void OnSelchangeComboRow()
#define IDC_COMBO_ROW
CSpinButtonCtrl m_wndHShift
Definition: PatchDialog.h:57
float m_fVShift
Definition: PatchDialog.h:72
afx_msg void OnDeltaposSpin(NMHDR *pNMHDR, LRESULT *pResult)
bool LoadRegistryInfo(const char *pszName, void *pvBuf, long *plSize)
Definition: Radiant.cpp:405
#define IDC_SPIN_VSCALE
afx_msg void OnBtnPatchreset()
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
#define IDC_EDIT_NAME
CSpinButtonCtrl m_wndVScale
Definition: PatchDialog.h:55
CSpinButtonCtrl m_wndRotate
Definition: PatchDialog.h:56
void UpdatePatchInspector()
afx_msg void OnApply()
#define IDC_SPIN_HSHIFT
virtual void DoDataExchange(CDataExchange *pDX)
Definition: PatchDialog.cpp:67
float m_fHShift
Definition: PatchDialog.h:69
void UpdateRowColInfo()
const GLubyte * c
Definition: glext.h:4677
void UpdateInfo()
#define NULL
Definition: Lib.h:88
#define IDC_VSHIFT
CString m_strName
Definition: PatchDialog.h:62
afx_msg void OnBtnPatchnatural()
afx_msg void OnSelchangeComboType()
#define IDC_BTN_PATCHFIT
bool SaveRegistryInfo(const char *pszName, void *pvBuf, long lSize)
Definition: Radiant.cpp:398
#define IDC_EDIT_Y
GLenum GLsizei width
Definition: glext.h:2846
#define IDC_EDIT_Z
#define IDC_BTN_PATCHDETAILS
#define IDC_APPLY
#define IDC_BTN_PATCHNATURAL
GLenum GLsizei GLsizei height
Definition: glext.h:2856
#define IDC_COMBO_TYPE
CSpinButtonCtrl m_wndHScale
Definition: PatchDialog.h:58
#define IDC_HSHIFT
long LONG
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
void DoPatchInspector()
#define IDC_SPIN_VSHIFT
#define IDC_VSCALE
#define IDC_EDIT_T
#define IDD_DIALOG_PATCH
CPatchDialog g_PatchDialog
Definition: PatchDialog.cpp:45
CComboBox m_wndRows
Definition: PatchDialog.h:60
CPatchDialog(CWnd *pParent=NULL)
Definition: PatchDialog.cpp:47
#define IDC_EDIT_X
#define IDC_COMBO_COL
#define FALSE
Definition: mprintf.c:70
#define IDC_BTN_PATCHRESET
#define IDC_SPIN_ROTATE
#define TRUE
Definition: mprintf.c:69
#define IDC_EDIT_S
#define IDC_SPIN_HSCALE
float m_fRotate
Definition: PatchDialog.h:70
virtual BOOL OnInitDialog()