WndDisplayTexture.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // WndDisplayTexture.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "WorldEditor.h"
  16. #include "WndDisplayTexture.h"
  17. #ifdef _DEBUG
  18. #undef new
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CWndDisplayTexture
  25. CWndDisplayTexture::CWndDisplayTexture()
  26. {
  27. m_ptd=NULL;
  28. m_pDrawPort = NULL;
  29. m_pViewPort = NULL;
  30. }
  31. CWndDisplayTexture::~CWndDisplayTexture()
  32. {
  33. if( m_pViewPort != NULL)
  34. {
  35. _pGfx->DestroyWindowCanvas( m_pViewPort);
  36. m_pViewPort = NULL;
  37. }
  38. }
  39. BEGIN_MESSAGE_MAP(CWndDisplayTexture, CWnd)
  40. //{{AFX_MSG_MAP(CWndDisplayTexture)
  41. ON_WM_PAINT()
  42. ON_WM_KILLFOCUS()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CWndDisplayTexture message handlers
  47. void CWndDisplayTexture::OnPaint()
  48. {
  49. {
  50. CPaintDC dc(this); // device context for painting
  51. }
  52. POINT ptMouse;
  53. GetCursorPos( &ptMouse);
  54. ScreenToClient( &ptMouse);
  55. // if there is a valid drawport, and the drawport can be locked
  56. if( (m_pDrawPort != NULL) && (m_pDrawPort->Lock()) )
  57. {
  58. CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
  59. ASSERT( pWorldEditorView != NULL);
  60. // clear background
  61. m_pDrawPort->Fill( C_vdGRAY|CT_OPAQUE);
  62. // erase z-buffer
  63. m_pDrawPort->FillZBuffer(ZBUF_BACK);
  64. CTextureObject to;
  65. to.SetData(m_ptd);
  66. m_pDrawPort->PutTexture( &to, m_boxTexture);
  67. m_pDrawPort->DrawBorder( 0,0, m_pDrawPort->GetWidth(),m_pDrawPort->GetHeight(), C_mdGRAY|CT_OPAQUE);
  68. m_pDrawPort->SetFont( _pfdConsoleFont);
  69. m_pDrawPort->SetTextAspect( 1.0f);
  70. m_pDrawPort->SetTextScaling( 1.0f);
  71. m_pDrawPort->PutTextCXY( m_strText1, m_boxText1.Center()(1), m_boxText1.Center()(2), C_YELLOW|CT_OPAQUE);
  72. m_pDrawPort->PutTextCXY( m_strText2, m_boxText2.Center()(1), m_boxText2.Center()(2), C_GRAY|CT_OPAQUE);
  73. // unlock the drawport
  74. m_pDrawPort->Unlock();
  75. // if there is a valid viewport
  76. if (m_pViewPort!=NULL)
  77. {
  78. m_pViewPort->SwapBuffers();
  79. }
  80. }
  81. }
  82. BOOL CWndDisplayTexture::Initialize(PIX pixX, PIX pixY, CTextureData *ptd,
  83. CTString strText1/*""*/, CTString strText2/*""*/, BOOL bDown/*=FALSE*/)
  84. {
  85. m_ptd=ptd;
  86. m_strText1=strText1;
  87. m_strText2=strText2;
  88. // calculate window's size
  89. CRect rectWindow;
  90. rectWindow.left = pixX;
  91. rectWindow.bottom = pixY;
  92. PIX pixWidth=ptd->GetPixWidth();
  93. PIX pixHeight=ptd->GetPixHeight();
  94. PIX pixScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
  95. PIX pixScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
  96. if( pixX+pixWidth>pixScreenWidth)
  97. {
  98. pixX=pixScreenWidth-pixWidth;
  99. }
  100. if( pixY+pixHeight>pixScreenHeight)
  101. {
  102. pixY=pixScreenHeight-pixHeight;
  103. }
  104. m_boxTexture=PIXaabbox2D( PIX2D(0,0), PIX2D(pixWidth,pixHeight));
  105. if( strText1!="")
  106. {
  107. pixHeight+=_pfdConsoleFont->fd_pixCharHeight+4;
  108. }
  109. m_boxText1=PIXaabbox2D( PIX2D(0,m_boxTexture.Max()(2)), PIX2D(pixWidth,pixHeight));
  110. if( strText2!="")
  111. {
  112. pixHeight+=_pfdConsoleFont->fd_pixCharHeight+4;
  113. }
  114. m_boxText2=PIXaabbox2D( PIX2D(0,m_boxText1.Max()(2)), PIX2D(pixWidth,pixHeight));
  115. rectWindow.right = rectWindow.left + pixWidth;
  116. if( bDown)
  117. {
  118. rectWindow.top = rectWindow.bottom;
  119. rectWindow.bottom+=pixHeight;
  120. }
  121. else
  122. {
  123. rectWindow.top = rectWindow.bottom - pixHeight;
  124. }
  125. if( IsWindow(m_hWnd))
  126. {
  127. SetWindowPos( NULL, rectWindow.left, rectWindow.top,
  128. rectWindow.right-rectWindow.left, rectWindow.top-rectWindow.bottom,
  129. SWP_NOZORDER | SWP_NOACTIVATE);
  130. ShowWindow(SW_SHOW);
  131. }
  132. else
  133. {
  134. // create window
  135. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  136. BOOL bResult = CreateEx( WS_EX_TOOLWINDOW,
  137. NULL, L"Display texture", WS_CHILD|WS_POPUP|WS_VISIBLE,
  138. rectWindow.left, rectWindow.top, rectWindow.Width(), rectWindow.Height(),
  139. pMainFrame->m_hWnd, NULL, NULL);
  140. if( !bResult)
  141. {
  142. AfxMessageBox( L"Error: Failed to create display texture window!");
  143. return FALSE;
  144. }
  145. _pGfx->CreateWindowCanvas( m_hWnd, &m_pViewPort, &m_pDrawPort);
  146. }
  147. return TRUE;
  148. }
  149. void CWndDisplayTexture::OnKillFocus(CWnd* pNewWnd)
  150. {
  151. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  152. if(pNewWnd!=pMainFrame->m_pwndToolTip && pNewWnd!=this)
  153. {
  154. DestroyWindow();
  155. DeleteTempMap();
  156. }
  157. }
  158. BOOL CWndDisplayTexture::PreTranslateMessage(MSG* pMsg)
  159. {
  160. if( pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_ESCAPE)
  161. {
  162. DestroyWindow();
  163. DeleteTempMap();
  164. return TRUE;
  165. }
  166. return CWnd::PreTranslateMessage(pMsg);
  167. }