/mingw-w64-v2.0.999/mingw/mingw-w64-headers/include/d2d1helper.h

# · C++ Header · 372 lines · 327 code · 40 blank · 5 comment · 0 complexity · 1b6561a300fb88f8f4f09e07054fbda4 MD5 · raw file

  1. /**
  2. * This file has no copyright assigned and is placed in the Public Domain.
  3. * This file is part of the w64 mingw-runtime package.
  4. * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  5. */
  6. #ifndef _INC_D2D1HELPER
  7. #define _INC_D2D1HELPER
  8. #ifdef __cplusplus
  9. namespace D2D1 {
  10. D2D1FORCEINLINE D2D1_MATRIX_3X2_F IdentityMatrix();
  11. static inline FLOAT FloatMax() {
  12. return 3.402823466e+38f;
  13. }
  14. D2D1FORCEINLINE D2D1_POINT_2F Point2F(FLOAT x = 0.f, FLOAT y = 0.f) {
  15. D2D1_POINT_2F r = {x,y};
  16. return r;
  17. }
  18. D2D1FORCEINLINE D2D1_POINT_2U Point2U(UINT32 x = 0, UINT32 y = 0) {
  19. D2D1_POINT_2U r = {x,y};
  20. return r;
  21. }
  22. D2D1FORCEINLINE D2D1_SIZE_F SizeF(FLOAT width = 0.0f, FLOAT height = 0.0f) {
  23. D2D1_SIZE_F r = {width, height};
  24. return r;
  25. }
  26. D2D1FORCEINLINE D2D1_SIZE_U SizeU(UINT32 width = 0, UINT32 height = 0) {
  27. D2D1_SIZE_U r = {width, height};
  28. return r;
  29. }
  30. D2D1FORCEINLINE D2D1_RECT_F RectF(FLOAT left = 0.0f, FLOAT top = 0.0f, FLOAT right = 0.0f, FLOAT bottom = 0.0f) {
  31. D2D1_RECT_F r = {left, top, right, bottom};
  32. return r;
  33. }
  34. D2D1FORCEINLINE D2D1_RECT_U RectU(UINT32 left = 0, UINT32 top = 0, UINT32 right = 0, UINT32 bottom = 0) {
  35. D2D1_RECT_U r = {left, top, right, bottom};
  36. return r;
  37. }
  38. D2D1FORCEINLINE D2D1_RECT_F InfiniteRect() {
  39. D2D1_RECT_F r = {-FloatMax(), -FloatMax(), FloatMax(), FloatMax()};
  40. return r;
  41. }
  42. D2D1FORCEINLINE D2D1_ARC_SEGMENT ArcSegment(const D2D1_POINT_2F &point, const D2D1_SIZE_F &size, const FLOAT rotationAngle, D2D1_SWEEP_DIRECTION sweepDirection, D2D1_ARC_SIZE arcSize) {
  43. D2D1_ARC_SEGMENT r = {point, size, rotationAngle, sweepDirection, arcSize};
  44. return r;
  45. }
  46. D2D1FORCEINLINE D2D1_BEZIER_SEGMENT BezierSegment(const D2D1_POINT_2F &point1, const D2D1_POINT_2F &point2, const D2D1_POINT_2F &point3) {
  47. D2D1_BEZIER_SEGMENT r = {point1, point2, point3};
  48. return r;
  49. }
  50. D2D1FORCEINLINE D2D1_BRUSH_PROPERTIES BrushProperties(
  51. FLOAT opacity = 1.0f,
  52. const D2D1_MATRIX_3X2_F &transform = D2D1::IdentityMatrix()) {
  53. D2D1_BRUSH_PROPERTIES r = {opacity, transform};
  54. return r;
  55. }
  56. D2D1FORCEINLINE D2D1_QUADRATIC_BEZIER_SEGMENT QuadraticBezierSegment(const D2D1_POINT_2F &point1, const D2D1_POINT_2F &point2) {
  57. D2D1_QUADRATIC_BEZIER_SEGMENT r = {point1, point2};
  58. return r;
  59. }
  60. D2D1FORCEINLINE D2D1_STROKE_STYLE_PROPERTIES StrokeStyleProperties(
  61. D2D1_CAP_STYLE startCap = D2D1_CAP_STYLE_FLAT,
  62. D2D1_CAP_STYLE endCap = D2D1_CAP_STYLE_FLAT,
  63. D2D1_CAP_STYLE dashCap = D2D1_CAP_STYLE_FLAT,
  64. D2D1_LINE_JOIN lineJoin = D2D1_LINE_JOIN_MITER,
  65. FLOAT miterLimit = 10.0f,
  66. D2D1_DASH_STYLE dashStyle = D2D1_DASH_STYLE_SOLID,
  67. FLOAT dashOffset = 0.0f) {
  68. D2D1_STROKE_STYLE_PROPERTIES r = {startCap, endCap, dashCap, lineJoin, miterLimit, dashStyle, dashOffset};
  69. return r;
  70. }
  71. D2D1FORCEINLINE D2D1_BITMAP_BRUSH_PROPERTIES BitmapBrushProperties(
  72. D2D1_EXTEND_MODE extendModeX = D2D1_EXTEND_MODE_CLAMP,
  73. D2D1_EXTEND_MODE extendModeY = D2D1_EXTEND_MODE_CLAMP,
  74. D2D1_BITMAP_INTERPOLATION_MODE interpolationMode = D2D1_BITMAP_INTERPOLATION_MODE_LINEAR) {
  75. D2D1_BITMAP_BRUSH_PROPERTIES r = {extendModeX, extendModeY, interpolationMode};
  76. return r;
  77. }
  78. D2D1FORCEINLINE D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES LinearGradientBrushProperties(const D2D1_POINT_2F &startPoint, const D2D1_POINT_2F &endPoint) {
  79. D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES r = {startPoint, endPoint};
  80. return r;
  81. }
  82. D2D1FORCEINLINE D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES RadialGradientBrushProperties(const D2D1_POINT_2F &center, const D2D1_POINT_2F &gradientOriginOffset, FLOAT radiusX, FLOAT radiusY) {
  83. D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES r = {center, gradientOriginOffset, radiusX, radiusY};
  84. return r;
  85. }
  86. D2D1FORCEINLINE D2D1_PIXEL_FORMAT PixelFormat(
  87. DXGI_FORMAT dxgiFormat = DXGI_FORMAT_UNKNOWN,
  88. D2D1_ALPHA_MODE alphaMode = D2D1_ALPHA_MODE_UNKNOWN)
  89. {
  90. D2D1_PIXEL_FORMAT r = {dxgiFormat, alphaMode};
  91. return r;
  92. }
  93. D2D1FORCEINLINE D2D1_BITMAP_PROPERTIES BitmapProperties(CONST D2D1_PIXEL_FORMAT &pixelFormat = D2D1::PixelFormat(),
  94. FLOAT dpiX = 96.0f, FLOAT dpiY = 96.0f) {
  95. D2D1_BITMAP_PROPERTIES r = {pixelFormat, dpiX, dpiY};
  96. return r;
  97. }
  98. D2D1FORCEINLINE D2D1_RENDER_TARGET_PROPERTIES RenderTargetProperties(
  99. D2D1_RENDER_TARGET_TYPE type = D2D1_RENDER_TARGET_TYPE_DEFAULT,
  100. CONST D2D1_PIXEL_FORMAT &pixelFormat = D2D1::PixelFormat(),
  101. FLOAT dpiX = 0.0,
  102. FLOAT dpiY = 0.0,
  103. D2D1_RENDER_TARGET_USAGE usage = D2D1_RENDER_TARGET_USAGE_NONE,
  104. D2D1_FEATURE_LEVEL minLevel = D2D1_FEATURE_LEVEL_DEFAULT)
  105. {
  106. D2D1_RENDER_TARGET_PROPERTIES r = {type, pixelFormat, dpiX, dpiY, usage, minLevel};
  107. return r;
  108. }
  109. D2D1FORCEINLINE D2D1_LAYER_PARAMETERS LayerParameters(
  110. CONST D2D1_RECT_F &contentBounds = D2D1::InfiniteRect(),
  111. ID2D1Geometry *geometricMask = NULL,
  112. D2D1_ANTIALIAS_MODE maskAntialiasMode = D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
  113. D2D1_MATRIX_3X2_F maskTransform = D2D1::IdentityMatrix(),
  114. FLOAT opacity = 1.0,
  115. ID2D1Brush *opacityBrush = NULL,
  116. D2D1_LAYER_OPTIONS layerOptions = D2D1_LAYER_OPTIONS_NONE) {
  117. D2D1_LAYER_PARAMETERS r =
  118. {contentBounds, geometricMask, maskAntialiasMode, maskTransform, opacity, opacityBrush, layerOptions };
  119. return r;
  120. }
  121. class ColorF : public D2D1_COLOR_F {
  122. public:
  123. enum Enum {
  124. AliceBlue = 0xf0f8ff,
  125. AntiqueWhite = 0xfaebd7,
  126. Aqua = 0x00ffff,
  127. Aquamarine = 0x7fffd4,
  128. Azure = 0xf0ffff,
  129. Beige = 0xf5f5dc,
  130. Bisque = 0xffe4c4,
  131. Black = 0x000000,
  132. BlanchedAlmond = 0xffebcd,
  133. Blue = 0x0000ff,
  134. BlueViolet = 0x8a2be2,
  135. Brown = 0xa52a2a,
  136. BurlyWood = 0xdeb887,
  137. CadetBlue = 0x5f9ea0,
  138. Chartreuse = 0x7fff00,
  139. Chocolate = 0xd2691e,
  140. Coral = 0xff7f50,
  141. CornflowerBlue = 0x6495ed,
  142. Cornsilk = 0xfff8dc,
  143. Crimson = 0xdc143c,
  144. Cyan = 0x00ffff,
  145. DarkBlue = 0x00008b,
  146. DarkCyan = 0x008b8b,
  147. DarkGoldenrod = 0xb8860b,
  148. DarkGray = 0xa9a9a9,
  149. DarkGreen = 0x006400,
  150. DarkKhaki = 0xbdb76b,
  151. DarkMagenta = 0x8b008b,
  152. DarkOliveGreen = 0x556B2f,
  153. DarkOrange = 0xff8c00,
  154. DarkOrchid = 0x9932cc,
  155. DarkRed = 0x8b0000,
  156. DarkSalmon = 0xe9967a,
  157. DarkSeaGreen = 0x8fbc8f,
  158. DarkSlateBlue = 0x483d8b,
  159. DarkSlateGray = 0x2f4f4f,
  160. DarkTurquoise = 0x00ced1,
  161. DarkViolet = 0x9400d3,
  162. DeepPink = 0xff1493,
  163. DeepSkyBlue = 0x00bfff,
  164. DimGray = 0x696969,
  165. DodgerBlue = 0x1e90ff,
  166. Firebrick = 0xb22222,
  167. FloralWhite = 0xfffaf0,
  168. ForestGreen = 0x228b22,
  169. Fuchsia = 0xff00ff,
  170. Gainsboro = 0xdcdcdc,
  171. GhostWhite = 0xf8f8ff,
  172. Gold = 0xffd700,
  173. Goldenrod = 0xdaa520,
  174. Gray = 0x808080,
  175. Green = 0x008000,
  176. GreenYellow = 0xadff2f,
  177. Honeydew = 0xf0fff0,
  178. HotPink = 0xff69b4,
  179. IndianRed = 0xcd5c5c,
  180. Indigo = 0x4b0082,
  181. Ivory = 0xfffff0,
  182. Khaki = 0xf0e68c,
  183. Lavender = 0xe6e6fa,
  184. LavenderBlush = 0xfff0f5,
  185. LawnGreen = 0x7cfc00,
  186. LemonChiffon = 0xfffacd,
  187. LightBlue = 0xadd8e6,
  188. LightCoral = 0xf08080,
  189. LightCyan = 0xe0ffff,
  190. LightGoldenrodYellow = 0xfafad2,
  191. LightGreen = 0x90ee90,
  192. LightGray = 0xd3d3d3,
  193. LightPink = 0xffb6c1,
  194. LightSalmon = 0xffa07a,
  195. LightSeaGreen = 0x20b2aa,
  196. LightSkyBlue = 0x87cefa,
  197. LightSlateGray = 0x778899,
  198. LightSteelBlue = 0xb0c4de,
  199. LightYellow = 0xffffe0,
  200. Lime = 0x00ff00,
  201. LimeGreen = 0x32cd32,
  202. Linen = 0xfaf0e6,
  203. Magenta = 0xff00ff,
  204. Maroon = 0x800000,
  205. MediumAquamarine = 0x66cdaa,
  206. MediumBlue = 0x0000cd,
  207. MediumOrchid = 0xba55d3,
  208. MediumPurple = 0x9370db,
  209. MediumSeaGreen = 0x3cb371,
  210. MediumSlateBlue = 0x7b68ee,
  211. MediumSpringGreen = 0x00fa9a,
  212. MediumTurquoise = 0x48d1cc,
  213. MediumVioletRed = 0xc71585,
  214. MidnightBlue = 0x191970,
  215. MintCream = 0xf5fffa,
  216. MistyRose = 0xffe4e1,
  217. Moccasin = 0xffe4b5,
  218. NavajoWhite = 0xffdead,
  219. Navy = 0x000080,
  220. OldLace = 0xfdf5e6,
  221. Olive = 0x808000,
  222. OliveDrab = 0x6b8e23,
  223. Orange = 0xffa500,
  224. OrangeRed = 0xff4500,
  225. Orchid = 0xda70d6,
  226. PaleGoldenrod = 0xeee8aa,
  227. PaleGreen = 0x98fb98,
  228. PaleTurquoise = 0xafeeee,
  229. PaleVioletRed = 0xdb7093,
  230. PapayaWhip = 0xffefd5,
  231. PeachPuff = 0xffdab9,
  232. Peru = 0xcd853f,
  233. Pink = 0xffc0cb,
  234. Plum = 0xdda0dd,
  235. PowderBlue = 0xb0e0e6,
  236. Purple = 0x800080,
  237. Red = 0xff0000,
  238. RosyBrown = 0xbc8f8f,
  239. RoyalBlue = 0x4169e1,
  240. SaddleBrown = 0x8b4513,
  241. Salmon = 0xfa8072,
  242. SandyBrown = 0xf4a460,
  243. SeaGreen = 0x2e8B57,
  244. SeaShell = 0xfff5ee,
  245. Sienna = 0xa0522d,
  246. Silver = 0xc0c0c0,
  247. SkyBlue = 0x87ceeb,
  248. SlateBlue = 0x6a5acd,
  249. SlateGray = 0x708090,
  250. Snow = 0xfffafa,
  251. SpringGreen = 0x00ff7f,
  252. SteelBlue = 0x4682B4,
  253. Tan = 0xd2b48c,
  254. Teal = 0x008080,
  255. Thistle = 0xd8bfd8,
  256. Tomato = 0xff6347,
  257. Turquoise = 0x40e0d0,
  258. Violet = 0xee82ee,
  259. Wheat = 0xf5deb3,
  260. White = 0xffffff,
  261. WhiteSmoke = 0xf5f5f5,
  262. Yellow = 0xffff00,
  263. YellowGreen = 0x9acd32
  264. };
  265. FORCEINLINE ColorF(UINT32 rgb, FLOAT _a = 1.0) {
  266. init(rgb, _a);
  267. }
  268. D2D1FORCEINLINE ColorF(Enum knownColor, FLOAT _a = 1.0) {
  269. init(knownColor, _a);
  270. }
  271. D2D1FORCEINLINE ColorF(FLOAT _r, FLOAT _g, FLOAT _b, FLOAT _a = 1.0) {
  272. r = _r;
  273. g = _g;
  274. b = _b;
  275. a = _a;
  276. }
  277. private:
  278. D2D1FORCEINLINE void init(UINT32 rgb, FLOAT _a) {
  279. r = static_cast<float>((rgb>>16)&0xff)/255.0f;
  280. g = static_cast<float>((rgb>>8)&0xff)/255.0f;
  281. b = static_cast<float>(rgb&0xff)/255.0f;
  282. a = _a;
  283. }
  284. };
  285. class Matrix3x2F : public D2D1_MATRIX_3X2_F {
  286. public:
  287. D2D1FORCEINLINE Matrix3x2F(FLOAT __11, FLOAT __12, FLOAT __21, FLOAT __22, FLOAT __31, FLOAT __32) {
  288. _11 = __11;
  289. _12 = __12;
  290. _21 = __21;
  291. _22 = __22;
  292. _31 = __31;
  293. _32 = __32;
  294. }
  295. D2D1FORCEINLINE Matrix3x2F() {}
  296. static inline const Matrix3x2F *ReinterpretBaseType(const D2D1_MATRIX_3X2_F *pMatrix) {
  297. return static_cast<const Matrix3x2F *>(pMatrix);
  298. }
  299. static inline Matrix3x2F *ReinterpretBaseType(D2D1_MATRIX_3X2_F *pMatrix) {
  300. return static_cast<Matrix3x2F *>(pMatrix);
  301. }
  302. inline FLOAT Determinant() const {
  303. return _11*_22 - _12*_21;
  304. }
  305. static D2D1FORCEINLINE Matrix3x2F Identity() {
  306. return Matrix3x2F(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
  307. }
  308. inline void SetProduct(const Matrix3x2F &a, const Matrix3x2F &b) {
  309. _11 = a._11*b._11 + a._12*b._21;
  310. _12 = a._11*b._12 + a._12*b._22;
  311. _21 = a._21*b._11 + a._22*b._21;
  312. _22 = a._21*b._12 + a._22*b._22;
  313. _31 = a._31*b._11 + a._32*b._21 + b._31;
  314. _32 = a._31*b._12 + a._32*b._22 + b._32;
  315. }
  316. D2D1FORCEINLINE Matrix3x2F operator*(const Matrix3x2F &matrix) const {
  317. Matrix3x2F r;
  318. r.SetProduct(*this, matrix);
  319. return r;
  320. }
  321. };
  322. D2D1FORCEINLINE D2D1_MATRIX_3X2_F IdentityMatrix() {
  323. return Matrix3x2F::Identity();
  324. }
  325. }
  326. D2D1FORCEINLINE D2D1_MATRIX_3X2_F operator*(const D2D1_MATRIX_3X2_F &matrix1, const D2D1_MATRIX_3X2_F &matrix2) {
  327. D2D1::Matrix3x2F r;
  328. r.SetProduct(*D2D1::Matrix3x2F::ReinterpretBaseType(&matrix1), *D2D1::Matrix3x2F::ReinterpretBaseType(&matrix2));
  329. return r;
  330. }
  331. #endif /* __cplusplus */
  332. #endif /*_INC_D2D1HELPER*/