UIRender.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef __UIRENDER_H__
  2. #define __UIRENDER_H__
  3. #pragma once
  4. #ifdef USE_XIMAGE_EFFECT
  5. class CxImage;
  6. #endif
  7. namespace DuiLib {
  8. /////////////////////////////////////////////////////////////////////////////////////
  9. //
  10. class UILIB_API CRenderClip
  11. {
  12. public:
  13. ~CRenderClip();
  14. RECT rcItem;
  15. HDC hDC;
  16. HRGN hRgn;
  17. HRGN hOldRgn;
  18. static void GenerateClip(HDC hDC, RECT rc, CRenderClip& clip);
  19. static void GenerateRoundClip(HDC hDC, RECT rc, RECT rcItem, int width, int height, CRenderClip& clip);
  20. static void UseOldClipBegin(HDC hDC, CRenderClip& clip);
  21. static void UseOldClipEnd(HDC hDC, CRenderClip& clip);
  22. };
  23. /////////////////////////////////////////////////////////////////////////////////////
  24. //
  25. class UILIB_API CRenderEngine
  26. {
  27. public:
  28. // 图片加载
  29. #ifdef USE_XIMAGE_EFFECT
  30. static CxImage *LoadGifImageX(STRINGorID bitmap, LPCTSTR type = NULL, DWORD mask = 0);
  31. #endif
  32. static TImageInfo* LoadImage(STRINGorID bitmap, LPCTSTR type = NULL, DWORD mask = 0, HINSTANCE instance = NULL);
  33. static void FreeImage(TImageInfo* pImageInfo, bool bDelete = true);
  34. static TImageInfo* LoadImage(LPCTSTR pStrImage, LPCTSTR type = NULL, DWORD mask = 0, HINSTANCE instance = NULL);
  35. static TImageInfo* LoadImage(UINT nID, LPCTSTR type = NULL, DWORD mask = 0, HINSTANCE instance = NULL);
  36. static void DrawImage(HDC hDC, HBITMAP hBitmap, const RECT& rc, const RECT& rcPaint, const RECT& rcBmpPart, const RECT& rcCorners, bool bAlpha, UINT uFade = 255, bool hole = false, bool xtiled = false, bool ytiled = false);
  37. static bool DrawImageInfo(HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, const TDrawInfo* pDrawInfo, HINSTANCE instance = NULL);
  38. static bool DrawImageString(HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, LPCTSTR pStrImage, LPCTSTR pStrModify = NULL, HINSTANCE instance = NULL);
  39. // Gdiplus绘制
  40. static TImageInfo* GdiplusLoadImage(STRINGorID bitmap, LPCTSTR type = NULL, DWORD mask = 0, HINSTANCE instance = NULL);
  41. static void GdiplusDrawImage(HDC hDC, Gdiplus::Image* image, const RECT& rc, const RECT& rcPaint, const RECT& rcBmpPart, bool bAlpha, UINT uFade = 255, UINT uRotate = 0);
  42. static void GdiplusDrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, int iFont, UINT uStyle);
  43. // 以下函数中的颜色参数alpha值无效
  44. // 图元绘制
  45. static void DrawColor(HDC hDC, const RECT& rc, DWORD color);
  46. static void DrawGradient(HDC hDC, const RECT& rc, DWORD dwFirst, DWORD dwSecond, bool bVertical, int nSteps);
  47. static void DrawLine(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor,int nStyle = PS_SOLID);
  48. static void DrawRect(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor,int nStyle = PS_SOLID);
  49. static void DrawRoundRect(HDC hDC, const RECT& rc, int width, int height, int nSize, DWORD dwPenColor,int nStyle = PS_SOLID);
  50. // 字体绘制
  51. static void DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText,DWORD dwTextColor, int iFont, UINT uStyle, DWORD dwTextBKColor);
  52. static void DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, int iFont, UINT uStyle);
  53. static void DrawHtmlText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, RECT* pLinks, CDuiString* sLinks, int& nLinkRects, int iFont, UINT uStyle);
  54. // 辅助函数
  55. static void CheckAlphaColor(DWORD& dwColor);
  56. static DWORD AdjustColor(DWORD dwColor, short H, short S, short L);
  57. static HBITMAP CreateARGB32Bitmap(HDC hDC, int cx, int cy, BYTE** pBits);
  58. static void AdjustImage(bool bUseHSL, TImageInfo* imageInfo, short H, short S, short L);
  59. static HBITMAP GenerateBitmap(CPaintManagerUI* pManager, RECT rc, CControlUI* pStopControl = NULL, DWORD dwFilterColor = 0);
  60. static HBITMAP GenerateBitmap(CPaintManagerUI* pManager, CControlUI* pControl, RECT rc, DWORD dwFilterColor = 0);
  61. static SIZE GetTextSize(HDC hDC, CPaintManagerUI* pManager , LPCTSTR pstrText, int iFont, UINT uStyle);
  62. };
  63. } // namespace DuiLib
  64. #endif // __UIRENDER_H__