ActiveTextureWnd.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // ActiveTextureWnd.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "ActiveTextureWnd.h"
  16. #ifdef _DEBUG
  17. #undef new
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CActiveTextureWnd
  24. CActiveTextureWnd::CActiveTextureWnd()
  25. {
  26. m_pDrawPort = NULL;
  27. m_pViewPort = NULL;
  28. }
  29. CActiveTextureWnd::~CActiveTextureWnd()
  30. {
  31. }
  32. BEGIN_MESSAGE_MAP(CActiveTextureWnd, CWnd)
  33. //{{AFX_MSG_MAP(CActiveTextureWnd)
  34. ON_WM_PAINT()
  35. ON_WM_LBUTTONDOWN()
  36. ON_WM_RBUTTONDOWN()
  37. ON_WM_DESTROY()
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CActiveTextureWnd message handlers
  42. void CActiveTextureWnd::OnPaint()
  43. {
  44. {
  45. CPaintDC dc(this);
  46. }
  47. if( (m_pViewPort == NULL) && (m_pDrawPort == NULL) )
  48. {
  49. // initialize canvas for active texture button
  50. _pGfx->CreateWindowCanvas( m_hWnd, &m_pViewPort, &m_pDrawPort);
  51. }
  52. // if there is a valid drawport, and the drawport can be locked
  53. if( (m_pDrawPort != NULL) && (m_pDrawPort->Lock()) )
  54. {
  55. PIXaabbox2D rectPict;
  56. rectPict = PIXaabbox2D( PIX2D(0, 0),
  57. PIX2D(m_pDrawPort->GetWidth(), m_pDrawPort->GetHeight()));
  58. // clear texture area to black
  59. m_pDrawPort->Fill( C_BLACK | CT_OPAQUE);
  60. // erase z-buffer
  61. m_pDrawPort->FillZBuffer(ZBUF_BACK);
  62. // if there is valid active texture
  63. if( theApp.m_ptdActiveTexture != NULL)
  64. {
  65. CTextureObject toActiveTexture;
  66. toActiveTexture.SetData( theApp.m_ptdActiveTexture);
  67. m_pDrawPort->PutTexture( &toActiveTexture, rectPict);
  68. }
  69. else
  70. {
  71. // type text saying none selected
  72. m_pDrawPort->SetFont( theApp.m_pfntSystem);
  73. m_pDrawPort->SetTextAspect( 1.0f);
  74. m_pDrawPort->PutText( "None", 25, 20);
  75. m_pDrawPort->PutText( "selected", 8, 50);
  76. }
  77. // unlock the drawport
  78. m_pDrawPort->Unlock();
  79. if (m_pViewPort!=NULL)
  80. {
  81. m_pViewPort->SwapBuffers();
  82. }
  83. }
  84. }
  85. void CActiveTextureWnd::OnLButtonDown(UINT nFlags, CPoint point)
  86. {
  87. if( theApp.m_ptdActiveTexture == NULL) return;
  88. HGLOBAL hglobal = CreateHDrop( theApp.m_ptdActiveTexture->GetName());
  89. m_DataSource.CacheGlobalData( CF_HDROP, hglobal);
  90. m_DataSource.DoDragDrop( DROPEFFECT_COPY);
  91. CWnd::OnLButtonDown(nFlags, point);
  92. }
  93. void CActiveTextureWnd::OnRButtonDown(UINT nFlags, CPoint point)
  94. {
  95. CWnd::OnRButtonDown(nFlags, point);
  96. }
  97. void CActiveTextureWnd::OnDestroy()
  98. {
  99. CWnd::OnDestroy();
  100. if( m_pViewPort != NULL)
  101. {
  102. _pGfx->DestroyWindowCanvas( m_pViewPort);
  103. m_pViewPort = NULL;
  104. }
  105. m_pViewPort = NULL;
  106. m_pDrawPort = NULL;
  107. }