GdiImageDrawer.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 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() >= 144)
  31. {
  32. ret = LoadStdImage(id144, pType);
  33. }
  34. else if (theApp.m_metrics.GetDPIX() >= 120)
  35. {
  36. ret = LoadStdImage(id120, pType);
  37. }
  38. else
  39. {
  40. ret = LoadStdImage(id96, pType);
  41. }
  42. return ret;
  43. }
  44. void CGdiImageDrawer::Draw(CDC* pScreenDC, CWnd *pWnd, int posX, int posY, bool mouseHover, bool mouseDown, int forceWidth, int forceHeight)
  45. {
  46. int width = m_pStdImage->m_pBitmap->GetWidth();
  47. if (forceWidth != INT_MAX)
  48. width = forceWidth;
  49. int height = m_pStdImage->m_pBitmap->GetHeight();
  50. if (forceHeight != INT_MAX)
  51. height = forceHeight;
  52. CRect rectWithBorder(posX, posY, posX + width, posY + height);
  53. int two = theApp.m_metrics.ScaleX(2);
  54. rectWithBorder.InflateRect(two, two, two, two);
  55. CDC dcBk;
  56. CBitmap bmp;
  57. CClientDC clDC(pWnd);
  58. //Copy the background over the entire area
  59. dcBk.CreateCompatibleDC(&clDC);
  60. bmp.CreateCompatibleBitmap(&clDC, 1, 1);
  61. dcBk.SelectObject(&bmp);
  62. dcBk.BitBlt(0, 0, 1, 1, &clDC, rectWithBorder.left-1, rectWithBorder.top, SRCCOPY);
  63. bmp.DeleteObject();
  64. //Draw the png file
  65. if (mouseDown)
  66. {
  67. int one = theApp.m_metrics.ScaleX(1);
  68. posX += one;
  69. posY += one;
  70. }
  71. Gdiplus::Graphics graphics(pScreenDC->m_hDC);
  72. graphics.DrawImage(*m_pStdImage, posX, posY, width, height);
  73. //If we are hoving over then draw the border
  74. if(mouseHover && mouseDown == false)
  75. {
  76. pScreenDC->Draw3dRect(rectWithBorder, RGB(255, 255, 255), RGB(255, 255, 255));
  77. }
  78. }