Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.3 KiB

  1. /*
  2. * Surface
  3. */
  4. #ifndef DUI_BASE_SURFACE_H_INCLUDED
  5. #define DUI_BASE_SURFACE_H_INCLUDED
  6. #pragma once
  7. #pragma warning(disable: 4127) // conditional expression is constant
  8. namespace DirectUI
  9. {
  10. ////////////////////////////////////////////////////////
  11. // Surface
  12. class Surface
  13. {
  14. public:
  15. enum EType
  16. {
  17. stDC = GSURFACE_HDC,
  18. #ifdef GADGET_ENABLE_GDIPLUS
  19. stGdiPlus = GSURFACE_GPGRAPHICS
  20. #endif
  21. };
  22. virtual EType GetType() const PURE;
  23. inline static Surface::EType GetSurfaceType(UINT nSurfaceType);
  24. inline static UINT GetSurfaceType(Surface::EType type);
  25. };
  26. class DCSurface : public Surface
  27. {
  28. public:
  29. inline DCSurface(HDC hdc) { _hdc = hdc; }
  30. inline HDC GetHDC() { return _hdc; }
  31. virtual EType GetType() const { return Surface::stDC; }
  32. protected:
  33. HDC _hdc;
  34. };
  35. #ifdef GADGET_ENABLE_GDIPLUS
  36. class GpSurface : public Surface
  37. {
  38. public:
  39. inline GpSurface(Gdiplus::Graphics* pgpgr) { _pgpgr = pgpgr; }
  40. inline Gdiplus::Graphics* GetGraphics() { return _pgpgr; }
  41. virtual EType GetType() const { return Surface::stGdiPlus; }
  42. protected:
  43. Gdiplus::Graphics* _pgpgr;
  44. };
  45. #endif // GADGET_ENABLE_GDIPLUS
  46. inline Surface::EType Surface::GetSurfaceType(UINT nSurfaceType)
  47. {
  48. DUIAssert(stDC == GSURFACE_HDC, "ID's must match");
  49. return (EType)nSurfaceType;
  50. }
  51. inline UINT Surface::GetSurfaceType(Surface::EType type)
  52. {
  53. DUIAssert(stDC == GSURFACE_HDC, "ID's must match");
  54. return (UINT) type;
  55. }
  56. inline HDC CastHDC(Surface* psrf)
  57. {
  58. DUIAssert(psrf->GetType() == Surface::stDC, "Must be an HDC surface");
  59. return ((DCSurface*)psrf)->GetHDC();
  60. }
  61. #ifdef GADGET_ENABLE_GDIPLUS
  62. inline Gdiplus::Graphics* CastGraphics(Surface* psrf)
  63. {
  64. DUIAssert(psrf->GetType() == Surface::stGdiPlus, "Must be a GDI+ surface");
  65. return ((GpSurface*)psrf)->GetGraphics();
  66. }
  67. #endif // GADGET_ENABLE_GDIPLUS
  68. //
  69. // Some handy alpha-value operations that are used throughout DirectUI
  70. //
  71. #define ARGB(a, r, g, b) ((a << 24) | RGB(r, g, b)) // Current A values may be 255 (opaque) or 0 (transparent)
  72. #define ORGB(r, g, b) ARGB(255, r, g, b) // Opaque color
  73. #define GetAValue(v) ((BYTE)((v & 0xFF000000) >> 24))
  74. }; // namespace DirectUI
  75. #endif // DUI_BASE_SURFACE_H_INCLUDED