SurfaceDlg.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // SurfaceDlg.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "Radiant.h"
  22. #include "SurfaceDlg.h"
  23. #include "PrefsDlg.h"
  24. #include "mainfrm.h"
  25. #include "TextureLayout.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // surface properties plugin
  33. // global flag for surface properties plugin is g_qeglobals.bSurfacePropertiesPlugin
  34. _QERPlugSurfaceTable g_SurfaceTable;
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CSurfaceDlg dialog
  37. CSurfaceDlg g_dlgSurface;
  38. CSurfaceDlg::CSurfaceDlg(CWnd* pParent /*=NULL*/)
  39. : CDialog(CSurfaceDlg::IDD, pParent)
  40. {
  41. //{{AFX_DATA_INIT(CSurfaceDlg)
  42. m_nHeight = 1;
  43. m_nWidth = 1;
  44. //}}AFX_DATA_INIT
  45. }
  46. void CSurfaceDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CDialog::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CSurfaceDlg)
  50. DDX_Control(pDX, IDC_SPIN_WIDTH, m_wndWidth);
  51. DDX_Control(pDX, IDC_SPIN_HEIGHT, m_wndHeight);
  52. DDX_Control(pDX, IDC_SPIN_VSHIFT, m_wndVShift);
  53. DDX_Control(pDX, IDC_SPIN_VSCALE, m_wndVScale);
  54. DDX_Control(pDX, IDC_SPIN_ROTATE, m_wndRotate);
  55. DDX_Control(pDX, IDC_SPIN_HSHIFT, m_wndHShift);
  56. DDX_Control(pDX, IDC_SPIN_HSCALE, m_wndHScale);
  57. DDX_Text(pDX, IDC_EDIT_HEIGHT, m_nHeight);
  58. DDV_MinMaxInt(pDX, m_nHeight, 1, 32);
  59. DDX_Text(pDX, IDC_EDIT_WIDTH, m_nWidth);
  60. DDV_MinMaxInt(pDX, m_nWidth, 1, 32);
  61. //}}AFX_DATA_MAP
  62. }
  63. BEGIN_MESSAGE_MAP(CSurfaceDlg, CDialog)
  64. //{{AFX_MSG_MAP(CSurfaceDlg)
  65. ON_WM_HSCROLL()
  66. ON_WM_KEYDOWN()
  67. ON_WM_VSCROLL()
  68. ON_BN_CLICKED(IDAPPLY, OnApply)
  69. ON_WM_CLOSE()
  70. ON_WM_DESTROY()
  71. ON_BN_CLICKED(ID_BTN_CANCEL, OnBtnCancel)
  72. ON_BN_CLICKED(IDC_BTN_COLOR, OnBtnColor)
  73. ON_WM_CTLCOLOR()
  74. ON_WM_CREATE()
  75. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HSHIFT, OnDeltaPosSpin)
  76. ON_BN_CLICKED(IDC_BTN_PATCHDETAILS, OnBtnPatchdetails)
  77. ON_BN_CLICKED(IDC_BTN_PATCHNATURAL, OnBtnPatchnatural)
  78. ON_BN_CLICKED(IDC_BTN_PATCHRESET, OnBtnPatchreset)
  79. ON_BN_CLICKED(IDC_BTN_PATCHFIT, OnBtnPatchfit)
  80. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HSCALE, OnDeltaPosSpin)
  81. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_ROTATE, OnDeltaPosSpin)
  82. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VSCALE, OnDeltaPosSpin)
  83. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VSHIFT, OnDeltaPosSpin)
  84. ON_BN_CLICKED(IDC_BTN_AXIAL, OnBtnAxial)
  85. ON_BN_CLICKED(IDC_BTN_BRUSHFIT, OnBtnBrushfit)
  86. ON_BN_CLICKED(IDC_BTN_FACEFIT, OnBtnFacefit)
  87. //}}AFX_MSG_MAP
  88. END_MESSAGE_MAP()
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CSurfaceDlg message handlers
  91. /*
  92. ===================================================
  93. SURFACE INSPECTOR
  94. ===================================================
  95. */
  96. texdef_t g_old_texdef;
  97. texdef_t g_patch_texdef;
  98. HWND g_surfwin = NULL;
  99. qboolean g_changed_surface;
  100. int g_checkboxes[64] = {
  101. IDC_CHECK1, IDC_CHECK2, IDC_CHECK3, IDC_CHECK4,
  102. IDC_CHECK5, IDC_CHECK6, IDC_CHECK7, IDC_CHECK8,
  103. IDC_CHECK9, IDC_CHECK10, IDC_CHECK11, IDC_CHECK12,
  104. IDC_CHECK13, IDC_CHECK14, IDC_CHECK15, IDC_CHECK16,
  105. IDC_CHECK17, IDC_CHECK18, IDC_CHECK19, IDC_CHECK20,
  106. IDC_CHECK21, IDC_CHECK22, IDC_CHECK23, IDC_CHECK24,
  107. IDC_CHECK25, IDC_CHECK26, IDC_CHECK27, IDC_CHECK28,
  108. IDC_CHECK29, IDC_CHECK30, IDC_CHECK31, IDC_CHECK32,
  109. IDC_CHECK33, IDC_CHECK34, IDC_CHECK35, IDC_CHECK36,
  110. IDC_CHECK37, IDC_CHECK38, IDC_CHECK39, IDC_CHECK40,
  111. IDC_CHECK41, IDC_CHECK42, IDC_CHECK43, IDC_CHECK44,
  112. IDC_CHECK45, IDC_CHECK46, IDC_CHECK47, IDC_CHECK48,
  113. IDC_CHECK49, IDC_CHECK50, IDC_CHECK51, IDC_CHECK52,
  114. IDC_CHECK53, IDC_CHECK54, IDC_CHECK55, IDC_CHECK56,
  115. IDC_CHECK57, IDC_CHECK58, IDC_CHECK59, IDC_CHECK60,
  116. IDC_CHECK61, IDC_CHECK62, IDC_CHECK63, IDC_CHECK64
  117. };
  118. /*
  119. ==============
  120. SetTexMods
  121. Set the fields to the current texdef
  122. if one face selected -> will read this face texdef, else current texdef
  123. if only patches selected, will read the patch texdef
  124. ===============
  125. */
  126. bool g_bNewFace = false;
  127. bool g_bNewApplyHandling = false;
  128. bool g_bGatewayhack = false;
  129. void CSurfaceDlg::SetTexMods()
  130. {
  131. char sz[128];
  132. texdef_t *pt;
  133. brushprimit_texdef_t *bpt;
  134. // local copy if a width=2 height=2 qtetxture_t is needed
  135. brushprimit_texdef_t local_bp;
  136. int i;
  137. if (!g_surfwin)
  138. return;
  139. m_bPatchMode = false;
  140. if (OnlyPatchesSelected())
  141. {
  142. pt = &g_qeglobals.d_texturewin.texdef;
  143. if (QE_SingleBrush())
  144. {
  145. //strcpy(g_patch_texdef.name, Patch_GetTextureName());
  146. g_patch_texdef.SetName(Patch_GetTextureName());
  147. }
  148. else
  149. {
  150. //strcpy(g_patch_texdef.name, pt->name);
  151. g_patch_texdef.SetName(pt->name);
  152. }
  153. g_patch_texdef.contents = pt->contents;
  154. g_patch_texdef.flags = pt->flags;
  155. g_patch_texdef.value = pt->value;
  156. pt = &g_patch_texdef;
  157. m_bPatchMode = true;
  158. }
  159. else
  160. {
  161. if (g_bNewFace && g_ptrSelectedFaces.GetSize() > 0)
  162. {
  163. face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
  164. pt = &selFace->texdef;
  165. if (g_qeglobals.m_bBrushPrimitMode)
  166. {
  167. // compute a texture matrix related to the default matrix width=2 height=2
  168. ConvertTexMatWithQTexture( &selFace->brushprimit_texdef, selFace->d_texture, &local_bp, NULL );
  169. bpt = &local_bp;
  170. }
  171. }
  172. else
  173. {
  174. pt = &g_qeglobals.d_texturewin.texdef;
  175. if (g_qeglobals.m_bBrushPrimitMode)
  176. {
  177. bpt = &g_qeglobals.d_texturewin.brushprimit_texdef;
  178. }
  179. }
  180. // brush primitive mode : compute fake shift scale rot representation
  181. if (g_qeglobals.m_bBrushPrimitMode)
  182. TexMatToFakeTexCoords( bpt->coords, m_shift, &m_rotate, m_scale );
  183. }
  184. SendMessage (WM_SETREDRAW, 0, 0);
  185. ::SetWindowText(GetDlgItem(IDC_TEXTURE)->GetSafeHwnd(), pt->name);
  186. if (m_bPatchMode)
  187. sprintf(sz, "%4.6f", pt->shift[0]);
  188. else
  189. if (g_qeglobals.m_bBrushPrimitMode)
  190. sprintf(sz, "%d", (int)m_shift[0]);
  191. else
  192. sprintf(sz, "%d", (int)pt->shift[0]);
  193. ::SetWindowText(GetDlgItem(IDC_HSHIFT)->GetSafeHwnd(), sz);
  194. if (m_bPatchMode)
  195. sprintf(sz, "%4.6f", pt->shift[1]);
  196. else
  197. if (g_qeglobals.m_bBrushPrimitMode)
  198. sprintf(sz, "%d", (int)m_shift[1]);
  199. else
  200. sprintf(sz, "%d", (int)pt->shift[1]);
  201. ::SetWindowText(GetDlgItem(IDC_VSHIFT)->GetSafeHwnd(), sz);
  202. sprintf(sz, m_bPatchMode ? "%4.6f" : "%4.6f", g_qeglobals.m_bBrushPrimitMode ? m_scale[0] : pt->scale[0]);
  203. ::SetWindowText(GetDlgItem(IDC_HSCALE)->GetSafeHwnd(), sz);
  204. sprintf(sz, m_bPatchMode ? "%4.6f" : "%4.6f", g_qeglobals.m_bBrushPrimitMode ? m_scale[1] : pt->scale[1]);
  205. ::SetWindowText(GetDlgItem(IDC_VSCALE)->GetSafeHwnd(), sz);
  206. //++timo compute BProtate as int ..
  207. sprintf(sz, "%d", g_qeglobals.m_bBrushPrimitMode ? (int)m_rotate : (int)pt->rotate);
  208. ::SetWindowText(GetDlgItem(IDC_ROTATE)->GetSafeHwnd(), sz);
  209. sprintf(sz, "%d", (int)pt->value);
  210. ::SetWindowText(GetDlgItem(IDC_VALUE)->GetSafeHwnd(), sz);
  211. for (i=0 ; i<32 ; i++)
  212. ::SendMessage(GetDlgItem(g_checkboxes[i])->GetSafeHwnd(), BM_SETCHECK, !!(pt->flags&(1<<i)), 0 );
  213. for (i=0 ; i<32 ; i++)
  214. ::SendMessage(GetDlgItem(g_checkboxes[32+i])->GetSafeHwnd(), BM_SETCHECK, !!(pt->contents&(1<<i)), 0 );
  215. SendMessage (WM_SETREDRAW, 1, 0);
  216. InvalidateRect (NULL, true);
  217. }
  218. void CSurfaceDlg::GrabPatchMods()
  219. {
  220. char sz[128];
  221. int i;
  222. bool b;
  223. texdef_t *pt = & g_patch_texdef;
  224. ::GetWindowText (GetDlgItem(IDC_HSHIFT)->GetSafeHwnd(), sz, 127);
  225. pt->shift[0] = atof(sz);
  226. ::GetWindowText (GetDlgItem(IDC_VSHIFT)->GetSafeHwnd(), sz, 127);
  227. pt->shift[1] = atof(sz);
  228. ::GetWindowText(GetDlgItem(IDC_HSCALE)->GetSafeHwnd(), sz, 127);
  229. pt->scale[0] = atof(sz);
  230. ::GetWindowText(GetDlgItem(IDC_VSCALE)->GetSafeHwnd(), sz, 127);
  231. pt->scale[1] = atof(sz);
  232. ::GetWindowText(GetDlgItem(IDC_ROTATE)->GetSafeHwnd(), sz, 127);
  233. pt->rotate = atof(sz);
  234. ::GetWindowText(GetDlgItem(IDC_VALUE)->GetSafeHwnd(), sz, 127);
  235. pt->value = atof(sz);
  236. pt->flags = 0;
  237. for (i=0 ; i<32 ; i++)
  238. {
  239. b = ::SendMessage(GetDlgItem(g_checkboxes[i])->GetSafeHwnd(), BM_GETCHECK, 0, 0);
  240. if (b != 1 && b != 0)
  241. continue;
  242. pt->flags |= b<<i;
  243. }
  244. pt->contents = 0;
  245. for (i=0 ; i<32 ; i++)
  246. {
  247. b = ::SendMessage(GetDlgItem(g_checkboxes[32+i])->GetSafeHwnd(), BM_GETCHECK, 0, 0);
  248. if (b != 1 && b != 0)
  249. continue;
  250. pt->contents |= b<<i;
  251. }
  252. }
  253. /*
  254. ==============
  255. GetTexMods
  256. Reads the fields to get the current texdef
  257. in brush primitive mode, grab the fake shift scale rot and compute a new texture matrix
  258. ===============
  259. */
  260. void CSurfaceDlg::GetTexMods()
  261. {
  262. char sz[128];
  263. texdef_t *pt;
  264. int b;
  265. int i;
  266. m_bPatchMode = false;
  267. if (OnlyPatchesSelected())
  268. {
  269. pt = &g_qeglobals.d_texturewin.texdef;
  270. m_bPatchMode = true;
  271. }
  272. else
  273. {
  274. if (g_bNewFace && g_ptrSelectedFaces.GetSize() > 0)
  275. {
  276. face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
  277. pt = &selFace->texdef;
  278. }
  279. else
  280. {
  281. pt = &g_qeglobals.d_texturewin.texdef;
  282. }
  283. }
  284. ::GetWindowText (GetDlgItem(IDC_TEXTURE)->GetSafeHwnd(), sz, 127);
  285. //strncpy (pt->name, sz, sizeof(pt->name)-1);
  286. pt->SetName(sz);
  287. if (pt->name[0] <= ' ')
  288. {
  289. //strcpy (pt->name, "none");
  290. pt->SetName("none");
  291. ::SetWindowText(GetDlgItem(IDC_TEXTURE)->GetSafeHwnd(), pt->name);
  292. }
  293. ::GetWindowText (GetDlgItem(IDC_HSHIFT)->GetSafeHwnd(), sz, 127);
  294. ( g_qeglobals.m_bBrushPrimitMode ? m_shift[0] : pt->shift[0] ) = atof(sz);
  295. ::GetWindowText (GetDlgItem(IDC_VSHIFT)->GetSafeHwnd(), sz, 127);
  296. ( g_qeglobals.m_bBrushPrimitMode ? m_shift[1] : pt->shift[1] ) = atof(sz);
  297. ::GetWindowText(GetDlgItem(IDC_HSCALE)->GetSafeHwnd(), sz, 127);
  298. ( g_qeglobals.m_bBrushPrimitMode ? m_scale[0] : pt->scale[0] ) = atof(sz);
  299. ::GetWindowText(GetDlgItem(IDC_VSCALE)->GetSafeHwnd(), sz, 127);
  300. ( g_qeglobals.m_bBrushPrimitMode ? m_scale[1] : pt->scale[1] ) = atof(sz);
  301. ::GetWindowText(GetDlgItem(IDC_ROTATE)->GetSafeHwnd(), sz, 127);
  302. ( g_qeglobals.m_bBrushPrimitMode ? m_rotate : pt->rotate ) = atof(sz);
  303. ::GetWindowText(GetDlgItem(IDC_VALUE)->GetSafeHwnd(), sz, 127);
  304. pt->value = atof(sz);
  305. pt->flags = 0;
  306. for (i=0 ; i<32 ; i++)
  307. {
  308. b = ::SendMessage(GetDlgItem(g_checkboxes[i])->GetSafeHwnd(), BM_GETCHECK, 0, 0);
  309. if (b != 1 && b != 0)
  310. continue;
  311. pt->flags |= b<<i;
  312. }
  313. pt->contents = 0;
  314. for (i=0 ; i<32 ; i++)
  315. {
  316. b = ::SendMessage(GetDlgItem(g_checkboxes[32+i])->GetSafeHwnd(), BM_GETCHECK, 0, 0);
  317. if (b != 1 && b != 0)
  318. continue;
  319. pt->contents |= b<<i;
  320. }
  321. g_changed_surface = true;
  322. // a local copy of the texture matrix, given for a qtexture_t with width=2 height=2
  323. brushprimit_texdef_t local_bp;
  324. brushprimit_texdef_t *bpt;
  325. if (g_qeglobals.m_bBrushPrimitMode)
  326. {
  327. face_t *selFace = NULL;
  328. if (g_bNewFace && g_ptrSelectedFaces.GetSize() > 0)
  329. {
  330. selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
  331. bpt = &selFace->brushprimit_texdef;
  332. }
  333. else
  334. {
  335. bpt = &g_qeglobals.d_texturewin.brushprimit_texdef;
  336. }
  337. // compute texture matrix
  338. // the matrix returned must be understood as a qtexture_t with width=2 height=2
  339. FakeTexCoordsToTexMat( m_shift, m_rotate, m_scale, local_bp.coords );
  340. // copy the texture matrix in the global struct
  341. // fit the qtexture if we have a face selected, otherwise g_qeglobals.d_texturewin.brushprimit_texdef uses the basic qtexture_t with width=2 height=2
  342. ConvertTexMatWithQTexture( &local_bp, NULL, bpt, ( ( g_bNewFace && selFace ) ? selFace->d_texture : NULL ) );
  343. }
  344. Select_SetTexture(pt,&local_bp);
  345. //if (m_bPatchMode)
  346. //{
  347. // Patch_SetTextureInfo(pt);
  348. //}
  349. }
  350. /*
  351. =================
  352. UpdateSpinners
  353. =================
  354. */
  355. void CSurfaceDlg::UpdateSpinners(bool bUp, int nID)
  356. {
  357. texdef_t *pt;
  358. texdef_t td;
  359. if (m_bPatchMode)
  360. {
  361. td.rotate = 0.0;
  362. td.scale[0] = td.scale[1] = 0.0;
  363. td.shift[0] = td.shift[1] = 0.0;
  364. GrabPatchMods();
  365. pt = &g_patch_texdef;
  366. td.contents = pt->contents;
  367. td.flags = pt->flags;
  368. td.value = pt->value;
  369. if (nID == IDC_SPIN_ROTATE)
  370. {
  371. if (bUp)
  372. td.rotate = pt->rotate;
  373. else
  374. td.rotate = -pt->rotate;
  375. }
  376. else if (nID == IDC_SPIN_HSCALE)
  377. {
  378. if (bUp)
  379. td.scale[0] = 1-pt->scale[0];
  380. else
  381. td.scale[0] = 1+pt->scale[0];
  382. }
  383. else if (nID == IDC_SPIN_VSCALE)
  384. {
  385. if (bUp)
  386. td.scale[1] = 1-pt->scale[1];
  387. else
  388. td.scale[1] = 1+pt->scale[1];
  389. }
  390. else if (nID == IDC_SPIN_HSHIFT)
  391. {
  392. if (bUp)
  393. td.shift[0] = pt->shift[0];
  394. else
  395. td.shift[0] = -pt->shift[0];
  396. }
  397. else if (nID == IDC_SPIN_VSHIFT)
  398. {
  399. if (bUp)
  400. td.shift[1] = pt->shift[1];
  401. else
  402. td.shift[1] = -pt->shift[1];
  403. }
  404. pt = &g_qeglobals.d_texturewin.texdef;
  405. Patch_SetTextureInfo(&td);
  406. }
  407. else
  408. {
  409. // in brush primitive mode, will read up-to-date m_shift m_rotate m_scale
  410. GetTexMods ();
  411. if (g_bNewFace && g_ptrSelectedFaces.GetSize() > 0)
  412. {
  413. face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
  414. pt = &selFace->texdef;
  415. }
  416. else
  417. {
  418. pt = &g_qeglobals.d_texturewin.texdef;
  419. }
  420. if (nID == IDC_SPIN_ROTATE)
  421. {
  422. if (g_qeglobals.m_bBrushPrimitMode)
  423. {
  424. if (bUp)
  425. m_rotate += 45;
  426. else
  427. m_rotate -= 45;
  428. }
  429. else
  430. {
  431. if (bUp)
  432. pt->rotate += 45;
  433. else
  434. pt->rotate -= 45;
  435. if (pt->rotate < 0)
  436. pt->rotate += 360;
  437. if (pt->rotate >= 360)
  438. pt->rotate -= 360;
  439. }
  440. }
  441. else if (nID == IDC_SPIN_HSCALE)
  442. {
  443. if (g_qeglobals.m_bBrushPrimitMode)
  444. {
  445. if (bUp)
  446. m_scale[0] += 0.1;
  447. else
  448. m_scale[0] -= 0.1;
  449. }
  450. else
  451. {
  452. if (bUp)
  453. pt->scale[0] += 0.1;
  454. else
  455. pt->scale[0] -= 0.1;
  456. }
  457. }
  458. else if (nID == IDC_SPIN_VSCALE)
  459. {
  460. if (g_qeglobals.m_bBrushPrimitMode)
  461. {
  462. if (bUp)
  463. m_scale[1] += 0.1;
  464. else
  465. m_scale[1] -= 0.1;
  466. }
  467. else
  468. {
  469. if (bUp)
  470. pt->scale[1] += 0.1;
  471. else
  472. pt->scale[1] -= 0.1;
  473. }
  474. }
  475. else if (nID == IDC_SPIN_HSHIFT)
  476. {
  477. if (g_qeglobals.m_bBrushPrimitMode)
  478. {
  479. if (bUp)
  480. m_shift[0] += 8;
  481. else
  482. m_shift[0] -= 8;
  483. }
  484. else
  485. {
  486. if (bUp)
  487. pt->shift[0] += 8;
  488. else
  489. pt->shift[0] -= 8;
  490. }
  491. }
  492. else if (nID == IDC_SPIN_VSHIFT)
  493. {
  494. if (g_qeglobals.m_bBrushPrimitMode)
  495. {
  496. if (bUp)
  497. m_shift[1] += 8;
  498. else
  499. m_shift[1] -= 8;
  500. }
  501. else
  502. {
  503. if (bUp)
  504. pt->shift[1] += 8;
  505. else
  506. pt->shift[1] -= 8;
  507. }
  508. }
  509. }
  510. // a local copy of the texture matrix, given for a qtexture_t with width=2 height=2
  511. brushprimit_texdef_t local_bp;
  512. brushprimit_texdef_t *bpt;
  513. if (g_qeglobals.m_bBrushPrimitMode)
  514. {
  515. face_t *selFace = NULL;
  516. if (g_bNewFace && g_ptrSelectedFaces.GetSize() > 0)
  517. {
  518. selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
  519. bpt = &selFace->brushprimit_texdef;
  520. }
  521. else
  522. {
  523. bpt = &g_qeglobals.d_texturewin.brushprimit_texdef;
  524. }
  525. // compute texture matrix
  526. // the matrix returned must be understood as a qtexture_t with width=2 height=2
  527. FakeTexCoordsToTexMat( m_shift, m_rotate, m_scale, local_bp.coords );
  528. // copy the texture matrix in the global struct
  529. // fit the qtexture if we have a face selected, otherwise g_qeglobals.d_texturewin.brushprimit_texdef uses the basic qtexture_t with width=2 height=2
  530. ConvertTexMatWithQTexture( &local_bp, NULL, bpt, ( ( g_bNewFace && selFace ) ? selFace->d_texture : NULL ) );
  531. }
  532. // brush primit : will update the widgets after reading back texture matrix and computing fake shift scale rot
  533. SetTexMods();
  534. g_changed_surface = true;
  535. Select_SetTexture(pt,&local_bp);
  536. }
  537. void CSurfaceDlg::UpdateSpinners(int nScrollCode, int nPos, CScrollBar* pBar)
  538. {
  539. texdef_t *pt;
  540. GetTexMods ();
  541. if (g_bNewFace && g_ptrSelectedFaces.GetSize() > 0)
  542. {
  543. face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));
  544. pt = &selFace->texdef;
  545. }
  546. else
  547. {
  548. pt = &g_qeglobals.d_texturewin.texdef;
  549. }
  550. if ((nScrollCode != SB_LINEUP) && (nScrollCode != SB_LINEDOWN))
  551. return;
  552. if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_ROTATEA))
  553. {
  554. if (nScrollCode == SB_LINEUP)
  555. pt->rotate += 45;
  556. else
  557. pt->rotate -= 45;
  558. if (pt->rotate < 0)
  559. pt->rotate += 360;
  560. if (pt->rotate >= 360)
  561. pt->rotate -= 360;
  562. }
  563. else if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_HSCALEA))
  564. {
  565. if (nScrollCode == SB_LINEDOWN)
  566. pt->scale[0] -= 0.1;
  567. else
  568. pt->scale[0] += 0.1;
  569. }
  570. else if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_VSCALEA))
  571. {
  572. if (nScrollCode == SB_LINEUP)
  573. pt->scale[1] += 0.1;
  574. else
  575. pt->scale[1] -= 0.1;
  576. }
  577. else if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_HSHIFTA))
  578. {
  579. if (nScrollCode == SB_LINEDOWN)
  580. pt->shift[0] -= 8;
  581. else
  582. pt->shift[0] += 8;
  583. }
  584. else if (pBar->GetSafeHwnd() == ::GetDlgItem(GetSafeHwnd(), IDC_VSHIFTA))
  585. {
  586. if (nScrollCode == SB_LINEUP)
  587. pt->shift[1] += 8;
  588. else
  589. pt->shift[1] -= 8;
  590. }
  591. SetTexMods();
  592. g_changed_surface = true;
  593. //++timo if !g_qeglobals.m_bBrushPrimitMode send a NULL brushprimit_texdef
  594. if (!g_qeglobals.m_bBrushPrimitMode)
  595. {
  596. Sys_Printf("Warning : non brush primitive mode call to CSurfaceDlg::GetTexMods broken\n");
  597. Sys_Printf(" ( Select_SetTexture not called )\n");
  598. }
  599. // Select_SetTexture(pt);
  600. }
  601. void UpdateSurfaceDialog()
  602. {
  603. if (g_qeglobals.bSurfacePropertiesPlugin)
  604. {
  605. g_SurfaceTable.m_pfnUpdateSurfaceDialog();
  606. }
  607. else
  608. {
  609. if (g_surfwin)
  610. g_dlgSurface.SetTexMods();
  611. }
  612. g_pParentWnd->UpdateTextureBar();
  613. }
  614. bool ByeByeSurfaceDialog();
  615. void DoSurface (void)
  616. {
  617. // surface properties plugin ?
  618. if (g_qeglobals.bSurfacePropertiesPlugin)
  619. {
  620. g_SurfaceTable.m_pfnDoSurface();
  621. return;
  622. }
  623. g_bNewFace = g_PrefsDlg.m_bFace;
  624. g_bNewApplyHandling = g_PrefsDlg.m_bNewApplyHandling;
  625. g_bGatewayhack = g_PrefsDlg.m_bGatewayHack;
  626. // save current state for cancel
  627. g_old_texdef = g_qeglobals.d_texturewin.texdef;
  628. g_changed_surface = false;
  629. if (g_surfwin == NULL && g_dlgSurface.GetSafeHwnd() == NULL)
  630. {
  631. g_patch_texdef.scale[0] = 0.05;
  632. g_patch_texdef.scale[1] = 0.05;
  633. g_patch_texdef.shift[0] = 0.05;
  634. g_patch_texdef.shift[1] = 0.05;
  635. // use rotation increment from preferences
  636. g_patch_texdef.rotate = g_PrefsDlg.m_nRotation;
  637. g_dlgSurface.Create(IDD_SURFACE);
  638. CRect rct;
  639. LONG lSize = sizeof(rct);
  640. if (LoadRegistryInfo("Radiant::SurfaceWindow", &rct, &lSize))
  641. g_dlgSurface.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE | SWP_SHOWWINDOW);
  642. Sys_UpdateWindows(W_ALL);
  643. }
  644. else
  645. {
  646. g_surfwin = g_dlgSurface.GetSafeHwnd();
  647. g_dlgSurface.SetTexMods ();
  648. g_dlgSurface.ShowWindow(SW_SHOW);
  649. }
  650. }
  651. bool ByeByeSurfaceDialog()
  652. {
  653. // surface properties plugin ?
  654. if (g_qeglobals.bSurfacePropertiesPlugin)
  655. {
  656. return g_SurfaceTable.m_pfnByeByeSurfaceDialog();
  657. }
  658. if (g_surfwin)
  659. {
  660. if (g_bGatewayhack)
  661. PostMessage(g_surfwin, WM_COMMAND, IDAPPLY, 0);
  662. else
  663. PostMessage(g_surfwin, WM_COMMAND, IDCANCEL, 0);
  664. return true;
  665. }
  666. else return false;
  667. }
  668. BOOL CSurfaceDlg::OnInitDialog()
  669. {
  670. CDialog::OnInitDialog();
  671. g_surfwin = GetSafeHwnd();
  672. SetTexMods ();
  673. #ifdef QUAKE3
  674. GetDlgItem(IDC_CHECK32)->SetWindowText("Curve");
  675. GetDlgItem(IDC_CHECK64)->SetWindowText("Inverted");
  676. #endif
  677. m_wndHScale.SetRange(0, 1000);
  678. m_wndVScale.SetRange(0, 1000);
  679. m_wndHShift.SetRange(0, 1000);
  680. m_wndVShift.SetRange(0, 1000);
  681. m_wndRotate.SetRange(0, 1000);
  682. m_wndWidth.SetRange(1, 32);
  683. m_wndHeight.SetRange(1, 32);
  684. LPVOID lpv = g_pParentWnd->GetPlugInMgr().GetSurfaceFlags();
  685. if (lpv != NULL)
  686. {
  687. int i = 0;
  688. char* p = reinterpret_cast<char*>(lpv);
  689. char* pBuff = new char[strlen(p)+1];
  690. strcpy(pBuff, p);
  691. char* pToken = strtok(pBuff, ";\0");
  692. while (pToken != NULL)
  693. {
  694. GetDlgItem(g_checkboxes[i++])->SetWindowText(pToken);
  695. pToken = strtok(NULL, ";\0");
  696. }
  697. }
  698. if (strstr(g_PrefsDlg.m_strWhatGame, "Quake3") != NULL) {
  699. for (int i=0 ; i < 64 ; i++) {
  700. ::EnableWindow(GetDlgItem(g_checkboxes[i])->GetSafeHwnd(), FALSE);
  701. }
  702. }
  703. return TRUE; // return TRUE unless you set the focus to a control
  704. // EXCEPTION: OCX Property Pages should return FALSE
  705. }
  706. void CSurfaceDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  707. {
  708. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  709. UpdateSpinners(nSBCode, nPos, pScrollBar);
  710. Sys_UpdateWindows(W_CAMERA);
  711. }
  712. void CSurfaceDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  713. {
  714. CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
  715. }
  716. void CSurfaceDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  717. {
  718. CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
  719. UpdateSpinners(nSBCode, nPos, pScrollBar);
  720. Sys_UpdateWindows(W_CAMERA);
  721. }
  722. void CSurfaceDlg::OnApply()
  723. {
  724. GetTexMods ();
  725. Sys_UpdateWindows(W_CAMERA);
  726. if (g_bNewApplyHandling)
  727. OnOK();
  728. }
  729. void CSurfaceDlg::OnOK()
  730. {
  731. GetTexMods();
  732. g_surfwin = NULL;
  733. CDialog::OnOK();
  734. Sys_UpdateWindows(W_ALL);
  735. }
  736. void CSurfaceDlg::OnClose()
  737. {
  738. g_surfwin = NULL;
  739. CDialog::OnClose();
  740. }
  741. void CSurfaceDlg::OnCancel()
  742. {
  743. if (g_bGatewayhack)
  744. OnOK();
  745. else
  746. OnBtnCancel();
  747. }
  748. void CSurfaceDlg::OnDestroy()
  749. {
  750. if (GetSafeHwnd())
  751. {
  752. CRect rct;
  753. GetWindowRect(rct);
  754. SaveRegistryInfo("Radiant::SurfaceWindow", &rct, sizeof(rct));
  755. }
  756. CDialog::OnDestroy();
  757. g_surfwin = NULL;
  758. Sys_UpdateWindows(W_ALL);
  759. }
  760. void CSurfaceDlg::OnBtnCancel()
  761. {
  762. g_qeglobals.d_texturewin.texdef = g_old_texdef;
  763. if (g_changed_surface)
  764. {
  765. //++timo if !g_qeglobals.m_bBrushPrimitMode send a NULL brushprimit_texdef
  766. if (!g_qeglobals.m_bBrushPrimitMode)
  767. {
  768. Sys_Printf("Warning : non brush primitive mode call to CSurfaceDlg::GetTexMods broken\n");
  769. Sys_Printf(" ( Select_SetTexture not called )\n");
  770. }
  771. // Select_SetTexture(&g_qeglobals.d_texturewin.texdef);
  772. }
  773. g_surfwin = NULL;
  774. DestroyWindow();
  775. }
  776. void CSurfaceDlg::OnBtnColor()
  777. {
  778. }
  779. HBRUSH CSurfaceDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  780. {
  781. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  782. return hbr;
  783. }
  784. int CSurfaceDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  785. {
  786. if (CDialog::OnCreate(lpCreateStruct) == -1)
  787. return -1;
  788. return 0;
  789. }
  790. BOOL CSurfaceDlg::PreCreateWindow(CREATESTRUCT& cs)
  791. {
  792. // TODO: Add your specialized code here and/or call the base class
  793. return CDialog::PreCreateWindow(cs);
  794. }
  795. void CSurfaceDlg::OnDeltaPosSpin(NMHDR* pNMHDR, LRESULT* pResult)
  796. {
  797. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  798. UpdateSpinners((pNMUpDown->iDelta > 0), pNMUpDown->hdr.idFrom);
  799. *pResult = 0;
  800. }
  801. void CSurfaceDlg::OnBtnPatchdetails()
  802. {
  803. Patch_NaturalizeSelected(true);
  804. Sys_UpdateWindows(W_ALL);
  805. }
  806. void CSurfaceDlg::OnBtnPatchnatural()
  807. {
  808. Patch_NaturalizeSelected();
  809. Sys_UpdateWindows(W_ALL);
  810. }
  811. void CSurfaceDlg::OnBtnPatchreset()
  812. {
  813. CTextureLayout dlg;
  814. if (dlg.DoModal() == IDOK)
  815. {
  816. Patch_ResetTexturing(dlg.m_fX, dlg.m_fY);
  817. }
  818. Sys_UpdateWindows(W_ALL);
  819. }
  820. void CSurfaceDlg::OnBtnPatchfit()
  821. {
  822. Patch_FitTexturing();
  823. Sys_UpdateWindows(W_ALL);
  824. }
  825. void CSurfaceDlg::OnBtnAxial()
  826. {
  827. Select_SetTexture (&g_qeglobals.d_texturewin.texdef, &g_qeglobals.d_texturewin.brushprimit_texdef, true);
  828. g_changed_surface = true;
  829. SetTexMods();
  830. Sys_UpdateWindows(W_ALL);
  831. }
  832. void CSurfaceDlg::OnBtnBrushfit()
  833. {
  834. // TODO: Add your control notification handler code here
  835. }
  836. void CSurfaceDlg::OnBtnFacefit()
  837. {
  838. UpdateData(TRUE);
  839. if (g_ptrSelectedFaces.GetSize() == 0)
  840. {
  841. brush_t *b;
  842. for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  843. {
  844. for (face_t* pFace = b->brush_faces; pFace; pFace = pFace->next)
  845. {
  846. g_ptrSelectedFaces.Add(pFace);
  847. g_ptrSelectedFaceBrushes.Add(b);
  848. }
  849. }
  850. }
  851. Select_FitTexture(m_nHeight, m_nWidth);
  852. SetTexMods();
  853. g_changed_surface = true;
  854. Sys_UpdateWindows(W_ALL);
  855. }