PatchDialog.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "qe3.h"
  23. #include "Radiant.h"
  24. #include "PatchDialog.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CPatchDialog dialog
  32. CPatchDialog g_PatchDialog;
  33. CPatchDialog::CPatchDialog(CWnd* pParent /*=NULL*/)
  34. : CDialog(CPatchDialog::IDD, pParent)
  35. {
  36. //{{AFX_DATA_INIT(CPatchDialog)
  37. m_strName = _T("");
  38. m_fS = 0.0f;
  39. m_fT = 0.0f;
  40. m_fX = 0.0f;
  41. m_fY = 0.0f;
  42. m_fZ = 0.0f;
  43. m_fHScale = 0.05f;
  44. m_fHShift = 0.05f;
  45. m_fRotate = 45;
  46. m_fVScale = 0.05f;
  47. m_fVShift = 0.05f;
  48. //}}AFX_DATA_INIT
  49. m_Patch = NULL;
  50. }
  51. void CPatchDialog::DoDataExchange(CDataExchange* pDX)
  52. {
  53. CDialog::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(CPatchDialog)
  55. DDX_Control(pDX, IDC_SPIN_VSHIFT, m_wndVShift);
  56. DDX_Control(pDX, IDC_SPIN_VSCALE, m_wndVScale);
  57. DDX_Control(pDX, IDC_SPIN_ROTATE, m_wndRotate);
  58. DDX_Control(pDX, IDC_SPIN_HSHIFT, m_wndHShift);
  59. DDX_Control(pDX, IDC_SPIN_HSCALE, m_wndHScale);
  60. DDX_Control(pDX, IDC_COMBO_TYPE, m_wndType);
  61. DDX_Control(pDX, IDC_COMBO_ROW, m_wndRows);
  62. DDX_Control(pDX, IDC_COMBO_COL, m_wndCols);
  63. DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
  64. DDX_Text(pDX, IDC_EDIT_S, m_fS);
  65. DDX_Text(pDX, IDC_EDIT_T, m_fT);
  66. DDX_Text(pDX, IDC_EDIT_X, m_fX);
  67. DDX_Text(pDX, IDC_EDIT_Y, m_fY);
  68. DDX_Text(pDX, IDC_EDIT_Z, m_fZ);
  69. DDX_Text(pDX, IDC_HSCALE, m_fHScale);
  70. DDX_Text(pDX, IDC_HSHIFT, m_fHShift);
  71. DDX_Text(pDX, IDC_ROTATE, m_fRotate);
  72. DDX_Text(pDX, IDC_VSCALE, m_fVScale);
  73. DDX_Text(pDX, IDC_VSHIFT, m_fVShift);
  74. //}}AFX_DATA_MAP
  75. }
  76. BEGIN_MESSAGE_MAP(CPatchDialog, CDialog)
  77. //{{AFX_MSG_MAP(CPatchDialog)
  78. ON_BN_CLICKED(IDC_BTN_PATCHDETAILS, OnBtnPatchdetails)
  79. ON_BN_CLICKED(IDC_BTN_PATCHFIT, OnBtnPatchfit)
  80. ON_BN_CLICKED(IDC_BTN_PATCHNATURAL, OnBtnPatchnatural)
  81. ON_BN_CLICKED(IDC_BTN_PATCHRESET, OnBtnPatchreset)
  82. ON_CBN_SELCHANGE(IDC_COMBO_COL, OnSelchangeComboCol)
  83. ON_CBN_SELCHANGE(IDC_COMBO_ROW, OnSelchangeComboRow)
  84. ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType)
  85. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HSCALE, OnDeltaposSpin)
  86. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_ROTATE, OnDeltaposSpin)
  87. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VSCALE, OnDeltaposSpin)
  88. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VSHIFT, OnDeltaposSpin)
  89. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HSHIFT, OnDeltaposSpin)
  90. ON_WM_DESTROY()
  91. ON_BN_CLICKED(IDC_APPLY, OnApply)
  92. //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CPatchDialog message handlers
  96. void CPatchDialog::OnBtnPatchdetails()
  97. {
  98. Patch_NaturalizeSelected(true);
  99. Sys_UpdateWindows(W_ALL);
  100. }
  101. void CPatchDialog::OnBtnPatchfit()
  102. {
  103. Patch_FitTexturing();
  104. Sys_UpdateWindows(W_ALL);
  105. }
  106. void CPatchDialog::OnBtnPatchnatural()
  107. {
  108. Patch_NaturalizeSelected();
  109. Sys_UpdateWindows(W_ALL);
  110. }
  111. void CPatchDialog::OnBtnPatchreset()
  112. {
  113. //CTextureLayout dlg;
  114. //if (dlg.DoModal() == IDOK)
  115. //{
  116. // Patch_ResetTexturing(dlg.m_fX, dlg.m_fY);
  117. //}
  118. //Sys_UpdateWindows(W_ALL);
  119. }
  120. void CPatchDialog::OnSelchangeComboCol()
  121. {
  122. UpdateRowColInfo();
  123. }
  124. void CPatchDialog::OnSelchangeComboRow()
  125. {
  126. UpdateRowColInfo();
  127. }
  128. void CPatchDialog::OnSelchangeComboType()
  129. {
  130. // TODO: Add your control notification handler code here
  131. }
  132. void CPatchDialog::OnOK()
  133. {
  134. m_Patch = NULL;
  135. CDialog::OnOK();
  136. }
  137. void CPatchDialog::OnDeltaposSpin(NMHDR* pNMHDR, LRESULT* pResult)
  138. {
  139. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  140. UpdateSpinners((pNMUpDown->iDelta > 0), pNMUpDown->hdr.idFrom);
  141. *pResult = 0;
  142. }
  143. BOOL CPatchDialog::OnInitDialog()
  144. {
  145. CDialog::OnInitDialog();
  146. m_wndHScale.SetRange(0, 1000);
  147. m_wndVScale.SetRange(0, 1000);
  148. m_wndHShift.SetRange(0, 1000);
  149. m_wndVShift.SetRange(0, 1000);
  150. m_wndRotate.SetRange(0, 1000);
  151. GetPatchInfo();
  152. // TODO: Add extra initialization here
  153. return TRUE; // return TRUE unless you set the focus to a control
  154. // EXCEPTION: OCX Property Pages should return FALSE
  155. }
  156. void CPatchDialog::GetPatchInfo()
  157. {
  158. m_Patch = SinglePatchSelected();
  159. if (m_Patch != NULL)
  160. {
  161. CString str;
  162. int i;
  163. m_wndRows.ResetContent();
  164. for (i = 0; i < m_Patch->height; i++)
  165. {
  166. str.Format("%i", i);
  167. m_wndRows.AddString(str);
  168. }
  169. m_wndRows.SetCurSel(0);
  170. m_wndCols.ResetContent();
  171. for (i = 0; i < m_Patch->width; i++)
  172. {
  173. str.Format("%i", i);
  174. m_wndCols.AddString(str);
  175. }
  176. m_wndCols.SetCurSel(0);
  177. }
  178. UpdateRowColInfo();
  179. }
  180. void CPatchDialog::SetPatchInfo()
  181. {
  182. }
  183. void DoPatchInspector()
  184. {
  185. if (g_PatchDialog.GetSafeHwnd() == NULL)
  186. {
  187. g_PatchDialog.Create(IDD_DIALOG_PATCH);
  188. CRect rct;
  189. LONG lSize = sizeof(rct);
  190. if (LoadRegistryInfo("Radiant::PatchWindow", &rct, &lSize))
  191. {
  192. g_PatchDialog.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE);
  193. }
  194. }
  195. g_PatchDialog.ShowWindow(SW_SHOW);
  196. g_PatchDialog.GetPatchInfo();
  197. }
  198. void UpdatePatchInspector()
  199. {
  200. if (g_PatchDialog.GetSafeHwnd() != NULL)
  201. {
  202. g_PatchDialog.UpdateInfo();
  203. }
  204. }
  205. void CPatchDialog::OnDestroy()
  206. {
  207. if (GetSafeHwnd())
  208. {
  209. CRect rct;
  210. GetWindowRect(rct);
  211. SaveRegistryInfo("Radiant::PatchWindow", &rct, sizeof(rct));
  212. }
  213. CDialog::OnDestroy();
  214. }
  215. void CPatchDialog::UpdateRowColInfo()
  216. {
  217. m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0;
  218. if (m_Patch != NULL)
  219. {
  220. int r = m_wndRows.GetCurSel();
  221. int c = m_wndCols.GetCurSel();
  222. if (r >= 0 && r < m_Patch->height && c >= 0 && c < m_Patch->width)
  223. {
  224. m_fX = m_Patch->ctrl(c,r).xyz[0];
  225. m_fY = m_Patch->ctrl(c,r).xyz[1];
  226. m_fZ = m_Patch->ctrl(c,r).xyz[2];
  227. m_fS = m_Patch->ctrl(c,r).st[0];
  228. m_fT = m_Patch->ctrl(c,r).st[1];
  229. }
  230. }
  231. UpdateData(FALSE);
  232. }
  233. void CPatchDialog::UpdateInfo()
  234. {
  235. GetPatchInfo();
  236. }
  237. void CPatchDialog::OnApply()
  238. {
  239. UpdateData(TRUE);
  240. if (m_Patch != NULL)
  241. {
  242. int r = m_wndRows.GetCurSel();
  243. int c = m_wndCols.GetCurSel();
  244. if (r >= 0 && r < m_Patch->height && c >= 0 && c < m_Patch->width)
  245. {
  246. m_Patch->ctrl(c,r).xyz[0] = m_fX;
  247. m_Patch->ctrl(c,r).xyz[1] = m_fY;
  248. m_Patch->ctrl(c,r).xyz[2] = m_fZ;
  249. m_Patch->ctrl(c,r).st[0] = m_fS;
  250. m_Patch->ctrl(c,r).st[1] = m_fT;
  251. Patch_MakeDirty(m_Patch);
  252. Sys_UpdateWindows(W_ALL);
  253. }
  254. }
  255. }
  256. void CPatchDialog::UpdateSpinners(bool bUp, int nID)
  257. {
  258. texdef_t td;
  259. td.rotate = 0.0;
  260. td.scale[0] = td.scale[1] = 0.0;
  261. td.shift[0] = td.shift[1] = 0.0;
  262. td.value = 0;
  263. UpdateData(TRUE);
  264. if (nID == IDC_SPIN_ROTATE)
  265. {
  266. if (bUp)
  267. td.rotate = m_fRotate;
  268. else
  269. td.rotate = -m_fRotate;
  270. }
  271. else if (nID == IDC_SPIN_HSCALE)
  272. {
  273. if (bUp)
  274. td.scale[0] = 1 - m_fHScale;
  275. else
  276. td.scale[0] = 1 + m_fHScale;
  277. }
  278. else if (nID == IDC_SPIN_VSCALE)
  279. {
  280. if (bUp)
  281. td.scale[1] = 1 - m_fVScale;
  282. else
  283. td.scale[1] = 1 + m_fVScale;
  284. }
  285. else if (nID == IDC_SPIN_HSHIFT)
  286. {
  287. if (bUp)
  288. td.shift[0] = m_fHShift;
  289. else
  290. td.shift[0] = -m_fHShift;
  291. }
  292. else if (nID == IDC_SPIN_VSHIFT)
  293. {
  294. if (bUp)
  295. td.shift[1] = m_fVShift;
  296. else
  297. td.shift[1] = -m_fVShift;
  298. }
  299. Patch_SetTextureInfo(&td);
  300. Sys_UpdateWindows(W_CAMERA);
  301. }