GdiImageDrawer.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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, UINT id225, UINT id250, UINT id275, UINT id300, UINT id325, UINT id350)
  29. {
  30. BOOL ret = FALSE;
  31. if (dpi >= 336 && id350 != 0)
  32. {
  33. ret = LoadStdImage(id350, pType);
  34. }
  35. else if (dpi >= 312 && id325 != 0)
  36. {
  37. ret = LoadStdImage(id325, pType);
  38. }
  39. else if (dpi >= 288 && id300 != 0)
  40. {
  41. ret = LoadStdImage(id300, pType);
  42. }
  43. else if (dpi >= 264 && id275 != 0)
  44. {
  45. ret = LoadStdImage(id275, pType);
  46. }
  47. else if (dpi >= 240 && id250 != 0)
  48. {
  49. ret = LoadStdImage(id250, pType);
  50. }
  51. else if (dpi >= 216 && id225 != 0)
  52. {
  53. ret = LoadStdImage(id225, pType);
  54. }
  55. else if (dpi >= 192)
  56. {
  57. ret = LoadStdImage(id192, pType);
  58. }
  59. else if (dpi >= 168)
  60. {
  61. ret = LoadStdImage(id168, pType);
  62. }
  63. else if (dpi >= 144)
  64. {
  65. ret = LoadStdImage(id144, pType);
  66. }
  67. else if (dpi >= 120)
  68. {
  69. ret = LoadStdImage(id120, pType);
  70. }
  71. else
  72. {
  73. ret = LoadStdImage(id96, pType);
  74. }
  75. return ret;
  76. }
  77. void CGdiImageDrawer::Draw(CDC* pScreenDC, CDPI &dpi, CWnd *pWnd, CRect rc, bool mouseHover, bool mouseDown)
  78. {
  79. int width = m_pStdImage->m_pBitmap->GetWidth();
  80. int height = m_pStdImage->m_pBitmap->GetHeight();
  81. int x = rc.left + (rc.Width() / 2) - (width / 2);
  82. int y = rc.top + (rc.Height() / 2) - (height / 2);
  83. Draw(pScreenDC, dpi, pWnd, x, y, mouseHover, mouseDown);
  84. }
  85. void CGdiImageDrawer::Draw(CDC* pScreenDC, CDPI &dpi, CWnd *pWnd, int posX, int posY, bool mouseHover, bool mouseDown, int forceWidth, int forceHeight)
  86. {
  87. int width = m_pStdImage->m_pBitmap->GetWidth();
  88. if (forceWidth != INT_MAX)
  89. width = forceWidth;
  90. int height = m_pStdImage->m_pBitmap->GetHeight();
  91. if (forceHeight != INT_MAX)
  92. height = forceHeight;
  93. CRect rectWithBorder(posX, posY, posX + width, posY + height);
  94. CDC dcBk;
  95. CBitmap bmp;
  96. CClientDC clDC(pWnd);
  97. //Copy the background over the entire area
  98. dcBk.CreateCompatibleDC(&clDC);
  99. bmp.CreateCompatibleBitmap(&clDC, 1, 1);
  100. dcBk.SelectObject(&bmp);
  101. dcBk.BitBlt(0, 0, 1, 1, &clDC, rectWithBorder.left-1, rectWithBorder.top, SRCCOPY);
  102. bmp.DeleteObject();
  103. //Draw the png file
  104. if (mouseDown)
  105. {
  106. int one = dpi.Scale(1);
  107. posX += one;
  108. posY += one;
  109. }
  110. //ImageAttributes ia;
  111. //
  112. //ColorMap blackToRed;
  113. //blackToRed.oldColor = Color(255, 110, 114, 122); // black
  114. //blackToRed.newColor = Color(255, 255, 0, 0);// red
  115. //ia.SetRemapTable(1, &blackToRed);
  116. Gdiplus::Graphics graphics(pScreenDC->m_hDC);
  117. graphics.DrawImage(*m_pStdImage, posX, posY, width, height);
  118. //RectF grect; grect.X = posX, grect.Y = posY; grect.Width = width; grect.Height = height;
  119. //graphics.DrawImage(*m_pStdImage, grect, 0, 0, width, height, UnitPixel, &ia);
  120. //If we are hoving over then draw the border
  121. //if(mouseHover && mouseDown == false)
  122. //{
  123. // pScreenDC->Draw3dRect(rectWithBorder, RGB(255, 255, 255), RGB(255, 255, 255));
  124. //}
  125. }