ddstruct.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #ifndef _ddstruct_h_
  2. #define _ddstruct_h_
  3. //////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Zero fill for structs with a dwSize member
  6. //
  7. //////////////////////////////////////////////////////////////////////////////
  8. template<class Type>
  9. class TZeroFillWithSize : public Type {
  10. protected:
  11. TZeroFillWithSize()
  12. {
  13. Reinitialize();
  14. }
  15. public:
  16. void Reinitialize()
  17. {
  18. memset(this, 0, sizeof(Type));
  19. this->dwSize = sizeof(Type);
  20. }
  21. };
  22. //////////////////////////////////////////////////////////////////////////////
  23. //
  24. // Missing DirectX 5 declarations
  25. //
  26. //////////////////////////////////////////////////////////////////////////////
  27. #define DDSCL_SETFOCUSWINDOW 0x00000080l
  28. #define DDSCL_SETDEVICEWINDOW 0x00000100l
  29. #define DDSCL_CREATEDEVICEWINDOW 0x00000200l
  30. //////////////////////////////////////////////////////////////////////////////
  31. //
  32. //
  33. //
  34. //////////////////////////////////////////////////////////////////////////////
  35. class DDPixelFormat : public TZeroFillWithSize<DDPIXELFORMAT> {};
  36. class DDDeviceIdentifier : public TZeroFill<DDDEVICEIDENTIFIER> {};
  37. //////////////////////////////////////////////////////////////////////////////
  38. //
  39. // DDSurface Description
  40. //
  41. //////////////////////////////////////////////////////////////////////////////
  42. class DDSDescription : public TZeroFillWithSize<DDSURFACEDESCX> {
  43. public:
  44. DDSDescription()
  45. {
  46. ddpfPixelFormat.dwSize = sizeof(DDPixelFormat);
  47. }
  48. DDPixelFormat& GetPixelFormat()
  49. {
  50. return *(DDPixelFormat*)&ddpfPixelFormat;
  51. }
  52. const DDPixelFormat& GetPixelFormat() const
  53. {
  54. return *(DDPixelFormat*)&ddpfPixelFormat;
  55. }
  56. BYTE* Pointer() const { return (BYTE*)lpSurface; }
  57. BYTE* Pointer(const WinPoint& point) const
  58. {
  59. return
  60. Pointer()
  61. + point.Y() * Pitch()
  62. + point.X() * ddpfPixelFormat.dwRGBBitCount / 8;
  63. }
  64. int XSize() const { return (int)dwWidth; }
  65. int YSize() const { return (int)dwHeight; }
  66. WinPoint Size() const { return WinPoint(dwWidth, dwHeight); }
  67. WinRect Rect() const
  68. {
  69. return WinRect(0, 0, dwWidth, dwHeight);
  70. }
  71. DWORD Pitch() const { return lPitch; }
  72. };
  73. //////////////////////////////////////////////////////////////////////////////
  74. //
  75. // DD Device Caps
  76. //
  77. //////////////////////////////////////////////////////////////////////////////
  78. class DDSCaps : public TZeroFill<DDSCAPSX> {};
  79. //////////////////////////////////////////////////////////////////////////////
  80. //
  81. // DD Device Caps
  82. //
  83. //////////////////////////////////////////////////////////////////////////////
  84. class DDCaps : public TZeroFillWithSize<DDCAPS> {};
  85. //////////////////////////////////////////////////////////////////////////////
  86. //
  87. // D3D Device Description
  88. //
  89. //////////////////////////////////////////////////////////////////////////////
  90. class D3DDeviceDescription : public TZeroFillWithSize<D3DDEVICEDESC> {};
  91. //////////////////////////////////////////////////////////////////////////////
  92. //
  93. // D3D Device Description
  94. //
  95. //////////////////////////////////////////////////////////////////////////////
  96. class DDBltFX : public TZeroFillWithSize<DDBLTFX> {};
  97. //////////////////////////////////////////////////////////////////////////////
  98. //
  99. // D3D class wrappers
  100. //
  101. //////////////////////////////////////////////////////////////////////////////
  102. class D3DRect : public D3DRECT {
  103. public:
  104. D3DRect() {}
  105. D3DRect(long x1Arg, long y1Arg, long x2Arg, long y2Arg)
  106. {
  107. x1 = x1Arg;
  108. y1 = y1Arg;
  109. x2 = x2Arg;
  110. y2 = y2Arg;
  111. }
  112. };
  113. class D3DColorValue : public D3DCOLORVALUE {
  114. public:
  115. D3DColorValue() {}
  116. D3DColorValue(const Color& Color)
  117. {
  118. r = Color.GetRed();
  119. g = Color.GetGreen();
  120. b = Color.GetBlue();
  121. a = Color.GetAlpha();
  122. }
  123. friend bool operator==(const D3DColorValue& c1, const D3DColorValue& c2)
  124. {
  125. return
  126. c1.r == c2.r
  127. && c1.g == c2.g
  128. && c1.b == c2.b
  129. && c1.a == c2.a;
  130. }
  131. D3DCOLOR MakeD3DCOLOR()
  132. {
  133. return D3DRGBA(r, g, b, a);
  134. }
  135. operator Color()
  136. {
  137. return Color(r, g, b, a);
  138. }
  139. };
  140. #endif