WndTestAnimation.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. // WndTestAnimation.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "WorldEditor.h"
  16. #include "WndTestAnimation.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. // CWndTestAnimation
  25. CWndTestAnimation::CWndTestAnimation()
  26. {
  27. m_pDrawPort = NULL;
  28. m_pViewPort = NULL;
  29. // mark that timer is not yet started
  30. m_iTimerID = -1;
  31. }
  32. CWndTestAnimation::~CWndTestAnimation()
  33. {
  34. }
  35. BEGIN_MESSAGE_MAP(CWndTestAnimation, CWnd)
  36. //{{AFX_MSG_MAP(CWndTestAnimation)
  37. ON_WM_PAINT()
  38. ON_WM_TIMER()
  39. ON_WM_DESTROY()
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CWndTestAnimation message handlers
  44. void CWndTestAnimation::OnPaint()
  45. {
  46. {
  47. CPaintDC dc(this); // device context for painting
  48. }
  49. if( m_iTimerID == -1)
  50. {
  51. m_iTimerID = (int) SetTimer( 1, 50, NULL);
  52. }
  53. if( (m_pViewPort == NULL) && (m_pDrawPort == NULL) )
  54. {
  55. // initialize canvas for active texture button
  56. _pGfx->CreateWindowCanvas( m_hWnd, &m_pViewPort, &m_pDrawPort);
  57. }
  58. // if there is a valid drawport, and the drawport can be locked
  59. if( (m_pDrawPort != NULL) && (m_pDrawPort->Lock()) )
  60. {
  61. // get curently selected light animation combo member
  62. INDEX iLightAnimation = m_pParentDlg->GetSelectedLightAnimation();
  63. // if animation has changed
  64. if( iLightAnimation != m_aoAnimObject.GetAnim() )
  65. {
  66. // start new animation
  67. m_aoAnimObject.StartAnim( iLightAnimation);
  68. }
  69. // get current frame (color)
  70. SLONG col0, col1;
  71. FLOAT fRatio;
  72. m_aoAnimObject.GetFrame(col0, col1, fRatio);
  73. COLOR colorFrame = LerpColor(col0, col1, fRatio);
  74. // clear window background to black
  75. m_pDrawPort->Fill( colorFrame | CT_OPAQUE);
  76. // unlock the drawport
  77. m_pDrawPort->Unlock();
  78. // if there is a valid viewport
  79. if (m_pViewPort!=NULL)
  80. {
  81. // swap it
  82. m_pViewPort->SwapBuffers();
  83. }
  84. }
  85. }
  86. static TIME timeLastTick=TIME(0);
  87. void CWndTestAnimation::OnTimer(UINT nIDEvent)
  88. {
  89. // on our timer discard test animation window
  90. if( nIDEvent == 1)
  91. {
  92. TIME timeCurrentTick = _pTimer->GetRealTimeTick();
  93. if( timeCurrentTick > timeLastTick )
  94. {
  95. _pTimer->SetCurrentTick( timeCurrentTick);
  96. timeLastTick = timeCurrentTick;
  97. }
  98. Invalidate(FALSE);
  99. }
  100. CWnd::OnTimer(nIDEvent);
  101. }
  102. void CWndTestAnimation::OnDestroy()
  103. {
  104. KillTimer( m_iTimerID);
  105. _pTimer->SetCurrentTick( 0.0f);
  106. CWnd::OnDestroy();
  107. if( m_pViewPort != NULL)
  108. {
  109. _pGfx->DestroyWindowCanvas( m_pViewPort);
  110. m_pViewPort = NULL;
  111. }
  112. m_pViewPort = NULL;
  113. m_pDrawPort = NULL;
  114. }