NewTexWnd.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  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 "NewTexWnd.h"
  25. #include "io.h"
  26. #include "../../renderer/tr_local.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /*
  33. =======================================================================================================================
  34. =======================================================================================================================
  35. */
  36. bool Sys_KeyDown( int key ) {
  37. return ( ( ::GetAsyncKeyState( key ) & 0x8000 ) != 0 );
  38. }
  39. // CNewTexWnd
  40. IMPLEMENT_DYNCREATE(CNewTexWnd, CWnd);
  41. /*
  42. =======================================================================================================================
  43. =======================================================================================================================
  44. */
  45. CNewTexWnd::CNewTexWnd() {
  46. m_bNeedRange = true;
  47. hglrcTexture = NULL;
  48. hdcTexture = NULL;
  49. cursor.x = cursor.y = 0;
  50. origin.x = origin.y = 0;
  51. }
  52. /*
  53. =======================================================================================================================
  54. =======================================================================================================================
  55. */
  56. CNewTexWnd::~CNewTexWnd() {
  57. }
  58. BEGIN_MESSAGE_MAP(CNewTexWnd, CWnd)
  59. //{{AFX_MSG_MAP(CNewTexWnd)
  60. ON_WM_CREATE()
  61. ON_WM_SIZE()
  62. ON_WM_PARENTNOTIFY()
  63. ON_WM_KEYDOWN()
  64. ON_WM_KEYUP()
  65. ON_WM_PAINT()
  66. ON_WM_VSCROLL()
  67. ON_WM_LBUTTONDOWN()
  68. ON_WM_MBUTTONDOWN()
  69. ON_WM_RBUTTONDOWN()
  70. ON_WM_LBUTTONUP()
  71. ON_WM_MBUTTONUP()
  72. ON_WM_RBUTTONUP()
  73. ON_WM_MOUSEMOVE()
  74. ON_WM_MOUSEWHEEL()
  75. //}}AFX_MSG_MAP
  76. ON_WM_SETFOCUS()
  77. END_MESSAGE_MAP()
  78. //
  79. // =======================================================================================================================
  80. // CNewTexWnd message handlers
  81. // =======================================================================================================================
  82. //
  83. BOOL CNewTexWnd::PreCreateWindow(CREATESTRUCT &cs) {
  84. WNDCLASS wc;
  85. HINSTANCE hInstance = AfxGetInstanceHandle();
  86. if (::GetClassInfo(hInstance, TEXTURE_WINDOW_CLASS, &wc) == FALSE) {
  87. // Register a new class
  88. memset(&wc, 0, sizeof(wc));
  89. wc.style = CS_NOCLOSE | CS_PARENTDC; // | CS_OWNDC;
  90. wc.lpszClassName = TEXTURE_WINDOW_CLASS;
  91. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  92. wc.lpfnWndProc = ::DefWindowProc;
  93. if (AfxRegisterClass(&wc) == FALSE) {
  94. Error("CNewTexWnd RegisterClass: failed");
  95. }
  96. }
  97. cs.lpszClass = TEXTURE_WINDOW_CLASS;
  98. cs.lpszName = "TEX";
  99. if (cs.style != QE3_CHILDSTYLE && cs.style != QE3_STYLE) {
  100. cs.style = QE3_SPLITTER_STYLE;
  101. }
  102. return CWnd::PreCreateWindow(cs);
  103. }
  104. /*
  105. =======================================================================================================================
  106. =======================================================================================================================
  107. */
  108. int CNewTexWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) {
  109. if (CWnd::OnCreate(lpCreateStruct) == -1) {
  110. return -1;
  111. }
  112. ShowScrollBar(SB_VERT, g_PrefsDlg.m_bTextureScrollbar);
  113. m_bNeedRange = true;
  114. hdcTexture = GetDC();
  115. QEW_SetupPixelFormat(hdcTexture->m_hDC, false);
  116. EnableToolTips(TRUE);
  117. EnableTrackingToolTips(TRUE);
  118. return 0;
  119. }
  120. /*
  121. =======================================================================================================================
  122. =======================================================================================================================
  123. */
  124. void CNewTexWnd::OnSize(UINT nType, int cx, int cy) {
  125. CWnd::OnSize(nType, cx, cy);
  126. GetClientRect(rectClient);
  127. m_bNeedRange = true;
  128. }
  129. /*
  130. =======================================================================================================================
  131. =======================================================================================================================
  132. */
  133. void CNewTexWnd::OnParentNotify(UINT message, LPARAM lParam) {
  134. CWnd::OnParentNotify(message, lParam);
  135. }
  136. /*
  137. =======================================================================================================================
  138. =======================================================================================================================
  139. */
  140. void CNewTexWnd::UpdatePrefs() {
  141. ShowScrollBar(SB_VERT, g_PrefsDlg.m_bTextureScrollbar);
  142. m_bNeedRange = true;
  143. Invalidate();
  144. UpdateWindow();
  145. }
  146. /*
  147. =======================================================================================================================
  148. =======================================================================================================================
  149. */
  150. void CNewTexWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) {
  151. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
  152. }
  153. /*
  154. =======================================================================================================================
  155. =======================================================================================================================
  156. */
  157. void CNewTexWnd::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) {
  158. g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags, false);
  159. }
  160. /*
  161. =======================================================================================================================
  162. =======================================================================================================================
  163. */
  164. const idMaterial *CNewTexWnd::NextPos() {
  165. const idMaterial *mat = NULL;
  166. while (1) {
  167. if (currentIndex >= declManager->GetNumDecls( DECL_MATERIAL )) {
  168. return NULL;
  169. }
  170. mat = declManager->MaterialByIndex(currentIndex, false);
  171. currentIndex++;
  172. //if (mat->getName()[0] == '(') { // fake color texture
  173. // continue;
  174. //}
  175. if ( !mat->IsValid() ) {
  176. continue;
  177. }
  178. if (!mat->TestMaterialFlag(MF_EDITOR_VISIBLE)) {
  179. continue;
  180. }
  181. break;
  182. }
  183. // ensure it is uploaded
  184. declManager->FindMaterial(mat->GetName());
  185. int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100);
  186. int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100);
  187. if (current.x + width > rectClient.Width() - 8 && currentRow) {
  188. // go to the next row unless the texture is the first on the row
  189. current.x = 8;
  190. current.y -= currentRow + FONT_HEIGHT + 4;
  191. currentRow = 0;
  192. }
  193. draw = current;
  194. // Is our texture larger than the row? If so, grow the row height to match it
  195. if (currentRow < height) {
  196. currentRow = height;
  197. }
  198. // never go less than 64, or the names get all crunched up
  199. current.x += width < 64 ? 64 : width;
  200. current.x += 8;
  201. return mat;
  202. }
  203. /*
  204. =======================================================================================================================
  205. =======================================================================================================================
  206. */
  207. void CNewTexWnd::OnPaint() {
  208. CPaintDC dc(this); // device context for painting
  209. int nOld = g_qeglobals.d_texturewin.m_nTotalHeight;
  210. //hdcTexture = GetDC();
  211. if (!qwglMakeCurrent(dc.GetSafeHdc(), win32.hGLRC)) {
  212. common->Printf("ERROR: wglMakeCurrent failed..\n ");
  213. }
  214. else {
  215. const char *name;
  216. qglClearColor
  217. (
  218. g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][0],
  219. g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][1],
  220. g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][2],
  221. 0
  222. );
  223. qglViewport(0, 0, rectClient.Width(), rectClient.Height());
  224. qglScissor(0, 0, rectClient.Width(), rectClient.Height());
  225. qglMatrixMode(GL_PROJECTION);
  226. qglLoadIdentity();
  227. qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  228. qglDisable(GL_DEPTH_TEST);
  229. qglDisable(GL_BLEND);
  230. qglOrtho(0, rectClient.Width(), origin.y - rectClient.Height(), origin.y, -100, 100);
  231. qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  232. // init stuff
  233. current.x = 8;
  234. current.y = -8;
  235. currentRow = 0;
  236. currentIndex = 0;
  237. while (1) {
  238. const idMaterial *mat = NextPos();
  239. if (mat == NULL) {
  240. break;
  241. }
  242. int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100);
  243. int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100);
  244. // Is this texture visible?
  245. if ((draw.y - height - FONT_HEIGHT < origin.y) && (draw.y > origin.y - rectClient.Height())) {
  246. // if in use, draw a background
  247. qglLineWidth(1);
  248. qglColor3f(1, 1, 1);
  249. globalImages->BindNull();
  250. qglBegin(GL_LINE_LOOP);
  251. qglVertex2f(draw.x - 1, draw.y + 1 - FONT_HEIGHT);
  252. qglVertex2f(draw.x - 1, draw.y - height - 1 - FONT_HEIGHT);
  253. qglVertex2f(draw.x + 1 + width, draw.y - height - 1 - FONT_HEIGHT);
  254. qglVertex2f(draw.x + 1 + width, draw.y + 1 - FONT_HEIGHT);
  255. qglEnd();
  256. // Draw the texture
  257. float fScale = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? ((float)g_PrefsDlg.m_nTextureScale / 100) : 1.0;
  258. mat->GetEditorImage()->Bind();
  259. QE_CheckOpenGLForErrors();
  260. qglColor3f(1, 1, 1);
  261. qglBegin(GL_QUADS);
  262. qglTexCoord2f(0, 0);
  263. qglVertex2f(draw.x, draw.y - FONT_HEIGHT);
  264. qglTexCoord2f(1, 0);
  265. qglVertex2f(draw.x + width, draw.y - FONT_HEIGHT);
  266. qglTexCoord2f(1, 1);
  267. qglVertex2f(draw.x + width, draw.y - FONT_HEIGHT - height);
  268. qglTexCoord2f(0, 1);
  269. qglVertex2f(draw.x, draw.y - FONT_HEIGHT - height);
  270. qglEnd();
  271. // draw the selection border
  272. if ( !idStr::Icmp(g_qeglobals.d_texturewin.texdef.name, mat->GetName()) ) {
  273. qglLineWidth(3);
  274. qglColor3f(1, 0, 0);
  275. globalImages->BindNull();
  276. qglBegin(GL_LINE_LOOP);
  277. qglVertex2f(draw.x - 4, draw.y - FONT_HEIGHT + 4);
  278. qglVertex2f(draw.x - 4, draw.y - FONT_HEIGHT - height - 4);
  279. qglVertex2f(draw.x + 4 + width, draw.y - FONT_HEIGHT - height - 4);
  280. qglVertex2f(draw.x + 4 + width, draw.y - FONT_HEIGHT + 4);
  281. qglEnd();
  282. qglLineWidth(1);
  283. }
  284. // draw the texture name
  285. globalImages->BindNull();
  286. qglColor3f(1, 1, 1);
  287. qglRasterPos2f(draw.x, draw.y - FONT_HEIGHT + 2);
  288. // don't draw the directory name
  289. for (name = mat->GetName(); *name && *name != '/' && *name != '\\'; name++) {
  290. ;
  291. }
  292. if (!*name) {
  293. name = mat->GetName();
  294. }
  295. else {
  296. name++;
  297. }
  298. qglCallLists(strlen(name), GL_UNSIGNED_BYTE, name);
  299. //qglCallLists(va("%s -- %d, %d" strlen(name), GL_UNSIGNED_BYTE, name);
  300. }
  301. }
  302. g_qeglobals.d_texturewin.m_nTotalHeight = abs(draw.y) + 100;
  303. // reset the current texture
  304. globalImages->BindNull();
  305. qglFinish();
  306. qwglSwapBuffers(dc.GetSafeHdc());
  307. TRACE("Texture Paint\n");
  308. }
  309. if (g_PrefsDlg.m_bTextureScrollbar && (m_bNeedRange || g_qeglobals.d_texturewin.m_nTotalHeight != nOld)) {
  310. m_bNeedRange = false;
  311. SetScrollRange(SB_VERT, 0, g_qeglobals.d_texturewin.m_nTotalHeight, TRUE);
  312. }
  313. //ReleaseDC(hdcTexture);
  314. }
  315. /*
  316. =======================================================================================================================
  317. =======================================================================================================================
  318. */
  319. void CNewTexWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) {
  320. CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
  321. int n = GetScrollPos(SB_VERT);
  322. switch (nSBCode)
  323. {
  324. case SB_LINEUP: {
  325. n = (n - 15 > 0) ? n - 15 : 0;
  326. break;
  327. }
  328. case SB_LINEDOWN: {
  329. n = (n + 15 < g_qeglobals.d_texturewin.m_nTotalHeight) ? n + 15 : n;
  330. break;
  331. }
  332. case SB_PAGEUP: {
  333. n = (n - g_qeglobals.d_texturewin.height > 0) ? n - g_qeglobals.d_texturewin.height : 0;
  334. break;
  335. }
  336. case SB_PAGEDOWN: {
  337. n = (n + g_qeglobals.d_texturewin.height < g_qeglobals.d_texturewin.m_nTotalHeight) ? n + g_qeglobals.d_texturewin.height : n;
  338. break;
  339. }
  340. case SB_THUMBPOSITION: {
  341. n = nPos;
  342. break;
  343. }
  344. case SB_THUMBTRACK: {
  345. n = nPos;
  346. break;
  347. }
  348. }
  349. SetScrollPos(SB_VERT, n);
  350. origin.y = -n;
  351. Invalidate();
  352. UpdateWindow();
  353. // Sys_UpdateWindows(W_TEXTURE);
  354. }
  355. BOOL CNewTexWnd::DestroyWindow() {
  356. ReleaseDC(hdcTexture);
  357. return CWnd::DestroyWindow();
  358. }
  359. /*
  360. =======================================================================================================================
  361. =======================================================================================================================
  362. */
  363. BOOL CNewTexWnd::Create
  364. (
  365. LPCTSTR lpszClassName,
  366. LPCTSTR lpszWindowName,
  367. DWORD dwStyle,
  368. const RECT &rect,
  369. CWnd *pParentWnd,
  370. UINT nID,
  371. CCreateContext *pContext
  372. ) {
  373. BOOL ret = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  374. if (ret) {
  375. hdcTexture = GetDC();
  376. QEW_SetupPixelFormat(hdcTexture->m_hDC, false);
  377. }
  378. return ret;
  379. }
  380. const idMaterial *CNewTexWnd::getMaterialAtPoint(CPoint point) {
  381. // init stuff
  382. int my = rectClient.Height() - 1 - point.y;
  383. my += origin.y - rectClient.Height();
  384. current.x = 8;
  385. current.y = -8;
  386. currentRow = 0;
  387. currentIndex = 0;
  388. while (1) {
  389. const idMaterial *mat = NextPos();
  390. if (mat == NULL) {
  391. return NULL;
  392. }
  393. int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100);
  394. int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100);
  395. //if (point.x > draw.x && point.x - draw.x < width && my < draw.y && my + draw.y < height + FONT_HEIGHT) {
  396. if (point.x > draw.x && point.x - draw.x < width && my < draw.y && draw.y - my < height + FONT_HEIGHT) {
  397. return mat;
  398. }
  399. }
  400. }
  401. /*
  402. =======================================================================================================================
  403. =======================================================================================================================
  404. */
  405. void CNewTexWnd::OnLButtonDown(UINT nFlags, CPoint point) {
  406. cursor = point;
  407. SetFocus();
  408. bool fitScale = Sys_KeyDown(VK_CONTROL);
  409. bool edit = Sys_KeyDown(VK_SHIFT) && !fitScale;
  410. const idMaterial *mat = getMaterialAtPoint(point);
  411. if (mat) {
  412. Select_SetDefaultTexture(mat, fitScale, true);
  413. } else {
  414. Sys_Status("Did not select a texture\n", 0);
  415. }
  416. //
  417. UpdateSurfaceDialog();
  418. UpdatePatchInspector();
  419. }
  420. /*
  421. =======================================================================================================================
  422. =======================================================================================================================
  423. */
  424. void CNewTexWnd::OnMButtonDown(UINT nFlags, CPoint point) {
  425. CWnd::OnMButtonDown(nFlags, point);
  426. }
  427. /*
  428. =======================================================================================================================
  429. =======================================================================================================================
  430. */
  431. void CNewTexWnd::OnRButtonDown(UINT nFlags, CPoint point) {
  432. cursor = point;
  433. SetFocus();
  434. }
  435. /*
  436. ===============================t========================================================================================
  437. =======================================================================================================================
  438. */
  439. void CNewTexWnd::OnLButtonUp(UINT nFlags, CPoint point) {
  440. CWnd::OnLButtonUp(nFlags, point);
  441. g_pParentWnd->SetFocus();
  442. }
  443. /*
  444. =======================================================================================================================
  445. =======================================================================================================================
  446. */
  447. void CNewTexWnd::OnMButtonUp(UINT nFlags, CPoint point) {
  448. CWnd::OnMButtonUp(nFlags, point);
  449. }
  450. /*
  451. =======================================================================================================================
  452. =======================================================================================================================
  453. */
  454. void CNewTexWnd::OnRButtonUp(UINT nFlags, CPoint point) {
  455. CWnd::OnRButtonUp(nFlags, point);
  456. }
  457. extern float fDiff(float f1, float f2);
  458. /*
  459. =======================================================================================================================
  460. =======================================================================================================================
  461. */
  462. void CNewTexWnd::OnMouseMove(UINT nFlags, CPoint point) {
  463. int scale = 1;
  464. if (Sys_KeyDown(VK_SHIFT)) {
  465. scale = 4;
  466. }
  467. // rbutton = drag texture origin
  468. if (Sys_KeyDown(VK_RBUTTON)) {
  469. if (point.y != cursor.y) {
  470. if (Sys_KeyDown(VK_MENU)) {
  471. long *px = &point.x;
  472. long *px2 = &cursor.x;
  473. if (fDiff(point.y, cursor.y) > fDiff(point.x, cursor.x)) {
  474. px = &point.y;
  475. px2 = &cursor.y;
  476. }
  477. if (*px > *px2) {
  478. // zoom in
  479. g_PrefsDlg.m_nTextureScale += 4;
  480. if (g_PrefsDlg.m_nTextureScale > 500) {
  481. g_PrefsDlg.m_nTextureScale = 500;
  482. }
  483. }
  484. else if (*px < *px2) {
  485. // zoom out
  486. g_PrefsDlg.m_nTextureScale -= 4;
  487. if (g_PrefsDlg.m_nTextureScale < 1) {
  488. g_PrefsDlg.m_nTextureScale = 1;
  489. }
  490. }
  491. *px2 = *px;
  492. CPoint screen = cursor;
  493. ClientToScreen(&screen);
  494. SetCursorPos(screen.x, screen.y);
  495. //Sys_SetCursorPos(cursor.x, cursor.y);
  496. InvalidateRect(NULL, false);
  497. UpdateWindow();
  498. }
  499. else if (point.y != cursor.y || point.x != cursor.x) {
  500. origin.y += (point.y - cursor.y) * scale;
  501. if (origin.y > 0) {
  502. origin.y = 0;
  503. }
  504. //Sys_SetCursorPos(cursor.x, cursor.y);
  505. CPoint screen = cursor;
  506. ClientToScreen(&screen);
  507. SetCursorPos(screen.x, screen.y);
  508. if (g_PrefsDlg.m_bTextureScrollbar) {
  509. SetScrollPos(SB_VERT, abs(origin.y));
  510. }
  511. InvalidateRect(NULL, false);
  512. UpdateWindow();
  513. }
  514. }
  515. return;
  516. }
  517. }
  518. /*
  519. =======================================================================================================================
  520. =======================================================================================================================
  521. */
  522. void CNewTexWnd::LoadMaterials() {
  523. }
  524. void Texture_SetTexture(texdef_t *texdef, brushprimit_texdef_t *brushprimit_texdef, bool bFitScale, bool bSetSelection) {
  525. if (texdef->name[0] == '(') {
  526. Sys_Status("Can't select an entity texture\n", 0);
  527. return;
  528. }
  529. g_qeglobals.d_texturewin.texdef = *texdef;
  530. //
  531. // store the texture coordinates for new brush primitive mode be sure that all the
  532. // callers are using the default 2x2 texture
  533. //
  534. if (g_qeglobals.m_bBrushPrimitMode) {
  535. g_qeglobals.d_texturewin.brushprimit_texdef = *brushprimit_texdef;
  536. }
  537. g_dlgFind.updateTextures(texdef->name);
  538. if (!g_dlgFind.isOpen() && bSetSelection) {
  539. Select_SetTexture(texdef, brushprimit_texdef, bFitScale);
  540. }
  541. g_Inspectors->texWnd.EnsureTextureIsVisible(texdef->name);
  542. if ( g_Inspectors->mediaDlg.IsWindowVisible() ) {
  543. g_Inspectors->mediaDlg.SelectCurrentItem(true, g_qeglobals.d_texturewin.texdef.name, CDialogTextures::MATERIALS);
  544. }
  545. g_qeglobals.d_texturewin.texdef = *texdef;
  546. // store the texture coordinates for new brush primitive mode be sure that all the
  547. // callers are using the default 2x2 texture
  548. //
  549. if (g_qeglobals.m_bBrushPrimitMode) {
  550. g_qeglobals.d_texturewin.brushprimit_texdef = *brushprimit_texdef;
  551. }
  552. Sys_UpdateWindows(W_TEXTURE);
  553. }
  554. const idMaterial *Texture_LoadLight(const char *name) {
  555. return declManager->FindMaterial(name);
  556. }
  557. void Texture_ClearInuse(void) {
  558. }
  559. void Texture_ShowAll(void) {
  560. int count = declManager->GetNumDecls( DECL_MATERIAL );
  561. for (int i = 0; i < count; i++) {
  562. const idMaterial *mat = declManager->MaterialByIndex(i, false);
  563. if ( mat ) {
  564. mat->SetMaterialFlag(MF_EDITOR_VISIBLE);
  565. }
  566. }
  567. g_Inspectors->SetWindowText("Textures (all)");
  568. Sys_UpdateWindows(W_TEXTURE);
  569. }
  570. void Texture_HideAll() {
  571. int count = declManager->GetNumDecls( DECL_MATERIAL );
  572. for (int i = 0; i < count; i++) {
  573. const idMaterial *mat = declManager->MaterialByIndex(i, false);
  574. if ( mat ) {
  575. mat->ClearMaterialFlag(MF_EDITOR_VISIBLE);
  576. }
  577. }
  578. g_Inspectors->SetWindowText("Textures (all)");
  579. Sys_UpdateWindows(W_TEXTURE);
  580. }
  581. const idMaterial *Texture_ForName(const char *name) {
  582. const idMaterial *mat = declManager->FindMaterial(name);
  583. if ( !mat ) {
  584. mat = declManager->FindMaterial("_default");
  585. } else {
  586. mat->SetMaterialFlag(MF_EDITOR_VISIBLE);
  587. }
  588. return mat;
  589. }
  590. void Texture_ShowInuse(void) {
  591. Texture_HideAll();
  592. brush_t *b;
  593. for (b = active_brushes.next; b != NULL && b != &active_brushes; b = b->next) {
  594. if (b->pPatch) {
  595. Texture_ForName(b->pPatch->d_texture->GetName());
  596. } else {
  597. for (face_t *f = b->brush_faces; f; f = f->next) {
  598. Texture_ForName(f->texdef.name);
  599. }
  600. }
  601. }
  602. for (b = selected_brushes.next; b != NULL && b != &selected_brushes; b = b->next) {
  603. if (b->pPatch) {
  604. Texture_ForName(b->pPatch->d_texture->GetName());
  605. } else {
  606. for (face_t *f = b->brush_faces; f; f = f->next) {
  607. Texture_ForName(f->texdef.name);
  608. }
  609. }
  610. }
  611. Sys_UpdateWindows(W_TEXTURE);
  612. g_Inspectors->SetWindowText("Textures (in use)");
  613. }
  614. void Texture_Cleanup(CStringList *pList) {
  615. }
  616. int texture_mode = GL_LINEAR_MIPMAP_LINEAR;
  617. bool texture_showinuse = true;
  618. /*
  619. =======================================================================================================================
  620. Texture_SetMode
  621. =======================================================================================================================
  622. */
  623. void Texture_SetMode(int iMenu) {
  624. int iMode;
  625. HMENU hMenu;
  626. bool texturing = true;
  627. hMenu = GetMenu(g_pParentWnd->GetSafeHwnd());
  628. switch (iMenu)
  629. {
  630. case ID_VIEW_NEAREST:
  631. iMode = GL_NEAREST;
  632. break;
  633. case ID_VIEW_NEARESTMIPMAP:
  634. iMode = GL_NEAREST_MIPMAP_NEAREST;
  635. break;
  636. case ID_VIEW_LINEAR:
  637. iMode = GL_NEAREST_MIPMAP_LINEAR;
  638. break;
  639. case ID_VIEW_BILINEAR:
  640. iMode = GL_LINEAR;
  641. break;
  642. case ID_VIEW_BILINEARMIPMAP:
  643. iMode = GL_LINEAR_MIPMAP_NEAREST;
  644. break;
  645. case ID_VIEW_TRILINEAR:
  646. iMode = GL_LINEAR_MIPMAP_LINEAR;
  647. break;
  648. case ID_TEXTURES_WIREFRAME:
  649. iMode = 0;
  650. texturing = false;
  651. break;
  652. case ID_TEXTURES_FLATSHADE:
  653. default:
  654. iMode = 0;
  655. texturing = false;
  656. break;
  657. }
  658. CheckMenuItem(hMenu, ID_VIEW_NEAREST, MF_BYCOMMAND | MF_UNCHECKED);
  659. CheckMenuItem(hMenu, ID_VIEW_NEARESTMIPMAP, MF_BYCOMMAND | MF_UNCHECKED);
  660. CheckMenuItem(hMenu, ID_VIEW_LINEAR, MF_BYCOMMAND | MF_UNCHECKED);
  661. CheckMenuItem(hMenu, ID_VIEW_BILINEARMIPMAP, MF_BYCOMMAND | MF_UNCHECKED);
  662. CheckMenuItem(hMenu, ID_VIEW_BILINEAR, MF_BYCOMMAND | MF_UNCHECKED);
  663. CheckMenuItem(hMenu, ID_VIEW_TRILINEAR, MF_BYCOMMAND | MF_UNCHECKED);
  664. CheckMenuItem(hMenu, ID_TEXTURES_WIREFRAME, MF_BYCOMMAND | MF_UNCHECKED);
  665. CheckMenuItem(hMenu, ID_TEXTURES_FLATSHADE, MF_BYCOMMAND | MF_UNCHECKED);
  666. CheckMenuItem(hMenu, iMenu, MF_BYCOMMAND | MF_CHECKED);
  667. g_qeglobals.d_savedinfo.iTexMenu = iMenu;
  668. texture_mode = iMode;
  669. if (!texturing && iMenu == ID_TEXTURES_WIREFRAME) {
  670. g_pParentWnd->GetCamera()->Camera().draw_mode = cd_wire;
  671. Map_BuildBrushData();
  672. Sys_UpdateWindows(W_ALL);
  673. return;
  674. }
  675. else if (!texturing && iMenu == ID_TEXTURES_FLATSHADE) {
  676. g_pParentWnd->GetCamera()->Camera().draw_mode = cd_solid;
  677. Map_BuildBrushData();
  678. Sys_UpdateWindows(W_ALL);
  679. return;
  680. }
  681. if (g_pParentWnd->GetCamera()->Camera().draw_mode != cd_texture) {
  682. g_pParentWnd->GetCamera()->Camera().draw_mode = cd_texture;
  683. Map_BuildBrushData();
  684. }
  685. Sys_UpdateWindows(W_ALL);
  686. }
  687. void CNewTexWnd::EnsureTextureIsVisible(const char *name) {
  688. // scroll origin so the texture is completely on screen
  689. // init stuff
  690. current.x = 8;
  691. current.y = -8;
  692. currentRow = 0;
  693. currentIndex = 0;
  694. while (1) {
  695. const idMaterial *mat = NextPos();
  696. if (mat == NULL) {
  697. break;
  698. }
  699. int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100);
  700. int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100);
  701. if ( !idStr::Icmp(name, mat->GetName()) ) {
  702. if (current.y > origin.y) {
  703. origin.y = current.y;
  704. Sys_UpdateWindows(W_TEXTURE);
  705. return;
  706. }
  707. if (current.y - height - 2 * FONT_HEIGHT < origin.y - rectClient.Height()) {
  708. origin.y = current.y - height - 2 * FONT_HEIGHT + rectClient.Height();
  709. Sys_UpdateWindows(W_TEXTURE);
  710. return;
  711. }
  712. return;
  713. }
  714. }
  715. }
  716. BOOL CNewTexWnd::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult ) {
  717. static char tip[1024];
  718. CPoint point;
  719. GetCursorPos(&point);
  720. const idMaterial *mat = getMaterialAtPoint(point);
  721. if (mat) {
  722. TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  723. strcpy(tip, mat->GetDescription());
  724. pTTT->lpszText = tip;
  725. pTTT->hinst = NULL;
  726. return(TRUE);
  727. }
  728. return(FALSE);
  729. }
  730. int CNewTexWnd::OnToolHitTest(CPoint point, TOOLINFO * pTI)
  731. {
  732. const idMaterial *mat = getMaterialAtPoint(point);
  733. if (mat) {
  734. return 0;
  735. }
  736. return -1;
  737. }
  738. BOOL CNewTexWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  739. {
  740. OnVScroll((zDelta >= 0) ? SB_LINEUP : SB_LINEDOWN, 0, NULL);
  741. OnVScroll((zDelta >= 0) ? SB_LINEUP : SB_LINEDOWN, 0, NULL);
  742. OnVScroll((zDelta >= 0) ? SB_LINEUP : SB_LINEDOWN, 0, NULL);
  743. OnVScroll((zDelta >= 0) ? SB_LINEUP : SB_LINEDOWN, 0, NULL);
  744. OnVScroll((zDelta >= 0) ? SB_LINEUP : SB_LINEDOWN, 0, NULL);
  745. OnVScroll((zDelta >= 0) ? SB_LINEUP : SB_LINEDOWN, 0, NULL);
  746. return TRUE;
  747. }
  748. BOOL CNewTexWnd::PreTranslateMessage(MSG* pMsg)
  749. {
  750. if (pMsg->message == WM_KEYDOWN) {
  751. if (pMsg->wParam == VK_ESCAPE) {
  752. g_pParentWnd->GetCamera()->SetFocus();
  753. Select_Deselect();
  754. return TRUE;
  755. }
  756. if (pMsg->wParam == VK_RIGHT || pMsg->wParam == VK_LEFT || pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN) {
  757. g_pParentWnd->PostMessage(WM_KEYDOWN, pMsg->wParam);
  758. return TRUE;
  759. }
  760. }
  761. return CWnd::PreTranslateMessage(pMsg);
  762. }
  763. void CNewTexWnd::OnSetFocus(CWnd* pOldWnd)
  764. {
  765. CWnd::OnSetFocus(pOldWnd);
  766. Invalidate();
  767. RedrawWindow();
  768. }