GdiImageDrawer.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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, int posX, int posY, bool mouseHover, bool mouseDown, int forceWidth, int forceHeight)
  49. {
  50. int width = m_pStdImage->m_pBitmap->GetWidth();
  51. if (forceWidth != INT_MAX)
  52. width = forceWidth;
  53. int height = m_pStdImage->m_pBitmap->GetHeight();
  54. if (forceHeight != INT_MAX)
  55. height = forceHeight;
  56. CRect rectWithBorder(posX, posY, posX + width, posY + height);
  57. //int two = theApp.m_metrics.ScaleX(2);
  58. //rectWithBorder.InflateRect(two, two, two, two);
  59. CDC dcBk;
  60. CBitmap bmp;
  61. CClientDC clDC(pWnd);
  62. //Copy the background over the entire area
  63. dcBk.CreateCompatibleDC(&clDC);
  64. bmp.CreateCompatibleBitmap(&clDC, 1, 1);
  65. dcBk.SelectObject(&bmp);
  66. dcBk.BitBlt(0, 0, 1, 1, &clDC, rectWithBorder.left-1, rectWithBorder.top, SRCCOPY);
  67. bmp.DeleteObject();
  68. //Draw the png file
  69. if (mouseDown)
  70. {
  71. int one = theApp.m_metrics.ScaleX(1);
  72. posX += one;
  73. posY += one;
  74. }
  75. Gdiplus::Graphics graphics(pScreenDC->m_hDC);
  76. graphics.DrawImage(*m_pStdImage, posX, posY, width, height);
  77. //If we are hoving over then draw the border
  78. //if(mouseHover && mouseDown == false)
  79. //{
  80. // pScreenDC->Draw3dRect(rectWithBorder, RGB(255, 255, 255), RGB(255, 255, 255));
  81. //}
  82. }