GdiImageDrawer.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "stdafx.h"
  2. #include "GdiImageDrawer.h"
  3. #include "MemDC.h"
  4. #include "CP_Main.h"
  5. CGdiImageDrawer::CGdiImageDrawer()
  6. {
  7. m_pStdImage = NULL;
  8. }
  9. CGdiImageDrawer::~CGdiImageDrawer()
  10. {
  11. delete m_pStdImage;
  12. }
  13. void CGdiImageDrawer::Reset()
  14. {
  15. delete m_pStdImage;
  16. m_pStdImage = NULL;
  17. }
  18. BOOL CGdiImageDrawer::LoadStdImage(UINT id, LPCTSTR pType)
  19. {
  20. m_pStdImage = new CGdiPlusBitmapResource;
  21. return m_pStdImage->Load(id, pType);
  22. }
  23. BOOL CGdiImageDrawer::LoadRaw(unsigned char* bitmapData, int imageSize)
  24. {
  25. m_pStdImage = new CGdiPlusBitmapResource;
  26. return m_pStdImage->LoadRaw(bitmapData, imageSize);
  27. }
  28. BOOL CGdiImageDrawer::LoadStdImageDPI(int dpi, UINT id96, UINT id120, UINT id144, UINT id168, UINT id192, LPCTSTR pType)
  29. {
  30. BOOL ret = FALSE;
  31. if (dpi >= 192)
  32. {
  33. ret = LoadStdImage(id192, pType);
  34. }
  35. else if (dpi >= 168)
  36. {
  37. ret = LoadStdImage(id168, pType);
  38. }
  39. else if (dpi >= 144)
  40. {
  41. ret = LoadStdImage(id144, pType);
  42. }
  43. else if (dpi >= 120)
  44. {
  45. ret = LoadStdImage(id120, pType);
  46. }
  47. else
  48. {
  49. ret = LoadStdImage(id96, pType);
  50. }
  51. return ret;
  52. }
  53. void CGdiImageDrawer::Draw(CDC* pScreenDC, CDPI &dpi, CWnd *pWnd, CRect rc, bool mouseHover, bool mouseDown)
  54. {
  55. int width = m_pStdImage->m_pBitmap->GetWidth();
  56. int height = m_pStdImage->m_pBitmap->GetHeight();
  57. int x = rc.left + (rc.Width() / 2) - (width / 2);
  58. int y = rc.top + (rc.Height() / 2) - (height / 2);
  59. Draw(pScreenDC, dpi, pWnd, x, y, mouseHover, mouseDown);
  60. }
  61. void CGdiImageDrawer::Draw(CDC* pScreenDC, CDPI &dpi, CWnd *pWnd, int posX, int posY, bool mouseHover, bool mouseDown, int forceWidth, int forceHeight)
  62. {
  63. int width = m_pStdImage->m_pBitmap->GetWidth();
  64. if (forceWidth != INT_MAX)
  65. width = forceWidth;
  66. int height = m_pStdImage->m_pBitmap->GetHeight();
  67. if (forceHeight != INT_MAX)
  68. height = forceHeight;
  69. CRect rectWithBorder(posX, posY, posX + width, posY + height);
  70. CDC dcBk;
  71. CBitmap bmp;
  72. CClientDC clDC(pWnd);
  73. //Copy the background over the entire area
  74. dcBk.CreateCompatibleDC(&clDC);
  75. bmp.CreateCompatibleBitmap(&clDC, 1, 1);
  76. dcBk.SelectObject(&bmp);
  77. dcBk.BitBlt(0, 0, 1, 1, &clDC, rectWithBorder.left-1, rectWithBorder.top, SRCCOPY);
  78. bmp.DeleteObject();
  79. //Draw the png file
  80. if (mouseDown)
  81. {
  82. int one = dpi.Scale(1);
  83. posX += one;
  84. posY += one;
  85. }
  86. //ImageAttributes ia;
  87. //
  88. //ColorMap blackToRed;
  89. //blackToRed.oldColor = Color(255, 110, 114, 122); // black
  90. //blackToRed.newColor = Color(255, 255, 0, 0);// red
  91. //ia.SetRemapTable(1, &blackToRed);
  92. Gdiplus::Graphics graphics(pScreenDC->m_hDC);
  93. graphics.DrawImage(*m_pStdImage, posX, posY, width, height);
  94. //RectF grect; grect.X = posX, grect.Y = posY; grect.Width = width; grect.Height = height;
  95. //graphics.DrawImage(*m_pStdImage, grect, 0, 0, width, height, UnitPixel, &ia);
  96. //If we are hoving over then draw the border
  97. //if(mouseHover && mouseDown == false)
  98. //{
  99. // pScreenDC->Draw3dRect(rectWithBorder, RGB(255, 255, 255), RGB(255, 255, 255));
  100. //}
  101. }