GdiImageDrawer.cpp 3.0 KB

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