Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
4.5 KiB

  1. #include "precomp.h"
  2. #include "painters.h"
  3. #include <windowsx.h>
  4. #include "ssutil.h"
  5. CImagePainter::CImagePainter(CBitmapImage *pBitmapImage,
  6. CSimpleDC &ClientDC,
  7. const RECT &rcScreen,
  8. bool bToolbarVisible )
  9. : m_pBitmapImage(pBitmapImage),
  10. m_dwInitialTickCount(0),
  11. m_rcScreen(rcScreen),
  12. m_bFirstFrame(true),
  13. m_dwDuration(0),
  14. m_bAlreadyPaintedLastFrame(false),
  15. m_bNeedPainting(false),
  16. m_dwLastInput(NULL),
  17. m_bToolbarVisible(bToolbarVisible)
  18. {
  19. ComputeImageLayout();
  20. }
  21. CImagePainter::~CImagePainter(void)
  22. {
  23. if (m_pBitmapImage)
  24. {
  25. delete m_pBitmapImage;
  26. m_pBitmapImage = NULL;
  27. }
  28. }
  29. // sets m_rcFinal
  30. void CImagePainter::ComputeImageLayout()
  31. {
  32. if (m_pBitmapImage)
  33. {
  34. // always center image
  35. m_rcFinal.top = (m_rcScreen.bottom/2)-((m_pBitmapImage->ImageSize().cy)/2);
  36. m_rcFinal.left = (m_rcScreen.right/2)-((m_pBitmapImage->ImageSize().cx)/2);
  37. m_rcFinal.bottom = 0;
  38. m_rcFinal.right = 0;
  39. }
  40. }
  41. void CImagePainter::SetToolbarVisible(bool bVisible)
  42. {
  43. m_bToolbarVisible = bVisible;
  44. }
  45. DWORD CImagePainter::ElapsedTime(void) const
  46. {
  47. DWORD dwElapsed = GetTickCount() - m_dwInitialTickCount;
  48. if (dwElapsed > m_dwDuration)
  49. {
  50. dwElapsed = m_dwDuration;
  51. }
  52. return(dwElapsed);
  53. }
  54. CBitmapImage* CImagePainter::BitmapImage(void) const
  55. {
  56. return(m_pBitmapImage);
  57. }
  58. void CImagePainter::Paint( CSimpleDC &PaintDC )
  59. {
  60. if (PaintDC.IsValid() && m_pBitmapImage)
  61. {
  62. ScreenSaverUtil::SelectPalette( PaintDC, m_pBitmapImage->Palette(), FALSE );
  63. CSimpleDC MemoryDC;
  64. if (MemoryDC.CreateCompatibleDC(PaintDC))
  65. {
  66. ScreenSaverUtil::SelectPalette( MemoryDC, m_pBitmapImage->Palette(), FALSE );
  67. Paint( PaintDC, MemoryDC );
  68. }
  69. }
  70. }
  71. void CImagePainter::Paint(CSimpleDC &PaintDC, CSimpleDC &MemoryDC)
  72. {
  73. SelectBitmap( MemoryDC, BitmapImage()->GetBitmap() );
  74. BitBlt(PaintDC,
  75. m_rcFinal.left,
  76. m_rcFinal.top,
  77. RECTWIDTH(m_rcFinal),
  78. RECTHEIGHT(m_rcFinal),
  79. MemoryDC,
  80. 0,
  81. 0,
  82. SRCCOPY);
  83. }
  84. void CImagePainter::OnInput()
  85. {
  86. m_dwLastInput = GetTickCount();
  87. }
  88. bool CImagePainter::TimerTick( CSimpleDC &ClientDC )
  89. {
  90. bool bStopPainting = false;
  91. if (m_bFirstFrame)
  92. {
  93. m_dwInitialTickCount = GetTickCount();
  94. Erase( ClientDC, m_rcScreen );
  95. }
  96. if (m_bFirstFrame || NeedPainting())
  97. {
  98. if (m_pBitmapImage && ClientDC.IsValid())
  99. {
  100. ScreenSaverUtil::SelectPalette( ClientDC, m_pBitmapImage->Palette(), FALSE );
  101. CSimpleDC MemoryDC;
  102. if (MemoryDC.CreateCompatibleDC(ClientDC))
  103. {
  104. ScreenSaverUtil::SelectPalette( MemoryDC, m_pBitmapImage->Palette(), FALSE );
  105. PaintFrame( ClientDC, MemoryDC );
  106. }
  107. }
  108. if (m_bFirstFrame)
  109. {
  110. m_bFirstFrame = false;
  111. }
  112. }
  113. else
  114. {
  115. bStopPainting = true;
  116. }
  117. m_bNeedPainting = false;
  118. return bStopPainting;
  119. }
  120. //PERF:: should double buffer this
  121. void CImagePainter::Erase( CSimpleDC &ClientDC, RECT &rc )
  122. {
  123. FillRect( ClientDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH) );
  124. m_bNeedPainting = true;
  125. }
  126. bool CImagePainter::NeedPainting(void)
  127. {
  128. return(m_bNeedPainting);
  129. }
  130. bool CImagePainter::IsValid(void)
  131. {
  132. return(m_pBitmapImage && m_pBitmapImage->GetBitmap());
  133. }
  134. /****************************************************************************
  135. CSimpleTransitionPainter
  136. *****************************************************************************/
  137. CSimpleTransitionPainter::CSimpleTransitionPainter( CBitmapImage *pBitmapImage,
  138. CSimpleDC &ClientDC,
  139. const RECT &rcScreen,
  140. bool bToolbarVisible )
  141. : CImagePainter( pBitmapImage,
  142. ClientDC,
  143. rcScreen,
  144. bToolbarVisible )
  145. {
  146. }
  147. CSimpleTransitionPainter::~CSimpleTransitionPainter(void)
  148. {
  149. }
  150. void CSimpleTransitionPainter::PaintFrame(CSimpleDC &ClientDC, CSimpleDC &MemoryDC)
  151. {
  152. SelectBitmap(MemoryDC, BitmapImage()->GetBitmap());
  153. SIZE sizeImage = BitmapImage()->ImageSize();
  154. BitBlt(ClientDC,
  155. m_rcFinal.left,
  156. m_rcFinal.top,
  157. sizeImage.cx,
  158. sizeImage.cy,
  159. MemoryDC,
  160. 0,
  161. 0,
  162. SRCCOPY);
  163. }