PageRenderTime 56ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdiplustypes.d

http://github.com/wilkie/djehuty
D | 624 lines | 423 code | 115 blank | 86 comment | 36 complexity | eace3efa246c9f6131bd7d2089219d7d MD5 | raw file
  1. /*
  2. * gdiplustypes.d
  3. *
  4. * This module binds GdiPlusTypes.h to D. The original copyright
  5. * notice is preserved below.
  6. *
  7. * Author: Dave Wilkinson
  8. * Originated: November 25th, 2009
  9. *
  10. */
  11. module binding.win32.gdiplustypes;
  12. import binding.win32.windef;
  13. import binding.win32.winbase;
  14. import binding.win32.winnt;
  15. import binding.win32.gdiplusenums;
  16. extern(System):
  17. /**************************************************************************\
  18. *
  19. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  20. *
  21. * Module Name:
  22. *
  23. * GdiplusTypes.hco
  24. *
  25. * Abstract:
  26. *
  27. * GDI+ Types
  28. *
  29. \**************************************************************************/
  30. extern(System) struct IDirectDrawSurface7;
  31. //--------------------------------------------------------------------------
  32. // Callback functions
  33. //--------------------------------------------------------------------------
  34. alias BOOL function(VOID*) ImageAbort;
  35. alias ImageAbort DrawImageAbort;
  36. alias ImageAbort GetThumbnailImageAbort;
  37. // Callback for EnumerateMetafile methods. The parameters are:
  38. // recordType WMF, EMF, or EMF+ record type
  39. // flags (always 0 for WMF/EMF records)
  40. // dataSize size of the record data (in bytes), or 0 if no data
  41. // data pointer to the record data, or NULL if no data
  42. // callbackData pointer to callbackData, if any
  43. // This method can then call Metafile::PlayRecord to play the
  44. // record that was just enumerated. If this method returns
  45. // FALSE, the enumeration process is aborted. Otherwise, it continues.
  46. alias BOOL function(EmfPlusRecordType, UINT, UINT, BYTE*, VOID*) EnumerateMetafileProc;
  47. // This is the main GDI+ Abort interface
  48. extern(C++) interface GdiplusAbort {
  49. HRESULT Abort();
  50. }
  51. //--------------------------------------------------------------------------
  52. // Primitive data types
  53. //
  54. // NOTE:
  55. // Types already defined in standard header files:
  56. // INT8
  57. // UINT8
  58. // INT16
  59. // UINT16
  60. // INT32
  61. // UINT32
  62. // INT64
  63. // UINT64
  64. //
  65. // Avoid using the following types:
  66. // LONG - use INT
  67. // ULONG - use UINT
  68. // DWORD - use UINT32
  69. //--------------------------------------------------------------------------
  70. alias float REAL;
  71. const auto REAL_MAX = REAL.max;
  72. const auto REAL_MIN = REAL.min;
  73. const auto REAL_TOLERANCE = (REAL.min * 100);
  74. const auto REAL_EPSILON = 1.192092896e-07F; /* FLT_EPSILON */
  75. //--------------------------------------------------------------------------
  76. // Status return values from GDI+ methods
  77. //--------------------------------------------------------------------------
  78. enum Status {
  79. Ok = 0,
  80. GenericError = 1,
  81. InvalidParameter = 2,
  82. OutOfMemory = 3,
  83. ObjectBusy = 4,
  84. InsufficientBuffer = 5,
  85. NotImplemented = 6,
  86. Win32Error = 7,
  87. WrongState = 8,
  88. Aborted = 9,
  89. FileNotFound = 10,
  90. ValueOverflow = 11,
  91. AccessDenied = 12,
  92. UnknownImageFormat = 13,
  93. FontFamilyNotFound = 14,
  94. FontStyleNotFound = 15,
  95. NotTrueTypeFont = 16,
  96. UnsupportedGdiplusVersion = 17,
  97. GdiplusNotInitialized = 18,
  98. PropertyNotFound = 19,
  99. PropertyNotSupported = 20,
  100. ProfileNotFound = 21,
  101. }
  102. //--------------------------------------------------------------------------
  103. // Represents a dimension in a 2D coordinate system (floating-point coordinates)
  104. //--------------------------------------------------------------------------
  105. struct SizeF {
  106. public:
  107. SizeF init(SizeF size) {
  108. SizeF ret;
  109. ret.Width = size.Width;
  110. ret.Height = size.Height;
  111. return ret;
  112. }
  113. SizeF init(REAL width, REAL height) {
  114. SizeF ret;
  115. ret.Width = width;
  116. ret.Height = height;
  117. return ret;
  118. }
  119. SizeF opAdd(SizeF sz) {
  120. return SizeF(Width + sz.Width, Height + sz.Height);
  121. }
  122. SizeF opSub(SizeF sz) {
  123. return SizeF(Width - sz.Width, Height - sz.Height);
  124. }
  125. BOOL Equals(SizeF sz) {
  126. return (Width == sz.Width) && (Height == sz.Height);
  127. }
  128. BOOL Empty() {
  129. return (Width == 0.0f && Height == 0.0f);
  130. }
  131. REAL Width = 0.0f;
  132. REAL Height = 0.0f;
  133. }
  134. //--------------------------------------------------------------------------
  135. // Represents a dimension in a 2D coordinate system (integer coordinates)
  136. //--------------------------------------------------------------------------
  137. struct Size {
  138. public:
  139. static Size init(Size size) {
  140. Size ret;
  141. ret.Width = size.Width;
  142. ret.Height = size.Height;
  143. return ret;
  144. }
  145. static Size init(INT width, INT height) {
  146. Size ret;
  147. ret.Width = width;
  148. ret.Height = height;
  149. return ret;
  150. }
  151. Size opAdd(Size sz) {
  152. return Size(Width + sz.Width, Height + sz.Height);
  153. }
  154. Size opSub(Size sz) {
  155. return Size(Width - sz.Width,
  156. Height - sz.Height);
  157. }
  158. BOOL Equals(Size sz) {
  159. return (Width == sz.Width) && (Height == sz.Height);
  160. }
  161. BOOL Empty() {
  162. return (Width == 0 && Height == 0);
  163. }
  164. INT Width;
  165. INT Height;
  166. }
  167. //--------------------------------------------------------------------------
  168. // Represents a location in a 2D coordinate system (floating-point coordinates)
  169. //--------------------------------------------------------------------------
  170. struct PointF {
  171. public:
  172. static PointF init(ref PointF point) {
  173. PointF ret;
  174. ret.X = point.X;
  175. ret.Y = point.Y;
  176. return ret;
  177. }
  178. static PointF init(ref SizeF size) {
  179. PointF ret;
  180. ret.X = size.Width;
  181. ret.Y = size.Height;
  182. return ret;
  183. }
  184. static PointF init(REAL x, REAL y) {
  185. PointF ret;
  186. ret.X = x;
  187. ret.Y = y;
  188. return ret;
  189. }
  190. PointF opAdd(ref PointF point) {
  191. return PointF(X + point.X, Y + point.Y);
  192. }
  193. PointF opSub(ref PointF point) {
  194. return PointF(X - point.X, Y - point.Y);
  195. }
  196. BOOL Equals(ref PointF point) {
  197. return (X == point.X) && (Y == point.Y);
  198. }
  199. REAL X;
  200. REAL Y;
  201. }
  202. //--------------------------------------------------------------------------
  203. // Represents a location in a 2D coordinate system (integer coordinates)
  204. //--------------------------------------------------------------------------
  205. struct Point {
  206. public:
  207. static Point init(in Point point) {
  208. Point ret;
  209. ret.X = point.X;
  210. ret.Y = point.Y;
  211. return ret;
  212. }
  213. static Point init(in Size size) {
  214. Point ret;
  215. ret.X = size.Width;
  216. ret.Y = size.Height;
  217. return ret;
  218. }
  219. Point init(INT x, INT y) {
  220. Point ret;
  221. ret.X = x;
  222. ret.Y = y;
  223. return ret;
  224. }
  225. Point opAdd(in Point point) {
  226. return Point(X + point.X, Y + point.Y);
  227. }
  228. Point opSub(in Point point) {
  229. return Point(X - point.X, Y - point.Y);
  230. }
  231. BOOL Equals(in Point point) {
  232. return (X == point.X) && (Y == point.Y);
  233. }
  234. INT X;
  235. INT Y;
  236. }
  237. //--------------------------------------------------------------------------
  238. // Represents a rectangle in a 2D coordinate system (floating-point coordinates)
  239. //--------------------------------------------------------------------------
  240. struct RectF {
  241. public:
  242. static RectF init(REAL x, REAL y, REAL width, REAL height) {
  243. RectF ret;
  244. ret.X = x;
  245. ret.Y = y;
  246. ret.Width = width;
  247. ret.Height = height;
  248. return ret;
  249. }
  250. static RectF init(in PointF location, in SizeF size) {
  251. RectF ret;
  252. ret.X = location.X;
  253. ret.Y = location.Y;
  254. ret.Width = size.Width;
  255. ret.Height = size.Height;
  256. return ret;
  257. }
  258. RectF Clone() {
  259. return RectF.init(X, Y, Width, Height);
  260. }
  261. alias Clone dup;
  262. VOID GetLocation(out PointF point) {
  263. point.X = X;
  264. point.Y = Y;
  265. }
  266. VOID GetSize(out SizeF size) {
  267. size.Width = Width;
  268. size.Height = Height;
  269. }
  270. VOID GetBounds(out RectF rect) {
  271. rect.X = X;
  272. rect.Y = Y;
  273. rect.Width = Width;
  274. rect.Height = Height;
  275. }
  276. REAL GetLeft() {
  277. return X;
  278. }
  279. REAL GetTop() {
  280. return Y;
  281. }
  282. REAL GetRight() {
  283. return X+Width;
  284. }
  285. REAL GetBottom() {
  286. return Y+Height;
  287. }
  288. BOOL IsEmptyArea() {
  289. return (Width <= REAL_EPSILON) || (Height <= REAL_EPSILON);
  290. }
  291. BOOL Equals(in RectF rect) {
  292. return X == rect.X &&
  293. Y == rect.Y &&
  294. Width == rect.Width &&
  295. Height == rect.Height;
  296. }
  297. BOOL Contains(in REAL x, in REAL y) {
  298. return x >= X && x < X+Width &&
  299. y >= Y && y < Y+Height;
  300. }
  301. BOOL Contains(in PointF pt) {
  302. return Contains(pt.X, pt.Y);
  303. }
  304. BOOL Contains(in RectF rect) {
  305. return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
  306. (Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
  307. }
  308. VOID Inflate(in REAL dx, in REAL dy) {
  309. X -= dx;
  310. Y -= dy;
  311. Width += 2*dx;
  312. Height += 2*dy;
  313. }
  314. VOID Inflate(in PointF point) {
  315. Inflate(point.X, point.Y);
  316. }
  317. BOOL Intersect(in RectF rect) {
  318. return Intersect(*this, *this, rect);
  319. }
  320. static BOOL Intersect(RectF c, in RectF a, in RectF b) {
  321. REAL right = ((a.GetRight() < b.GetRight()) ? a.GetRight() : b.GetRight());
  322. // REAL right = min(a.GetRight(), b.GetRight());
  323. REAL bottom = ((a.GetBottom() < b.GetBottom()) ? a.GetBottom() : b.GetBottom());
  324. REAL left = ((a.GetLeft() > b.GetLeft()) ? a.GetLeft() : b.GetLeft());
  325. REAL top = ((a.GetTop() > b.GetTop()) ? a.GetTop() : b.GetTop());
  326. c.X = left;
  327. c.Y = top;
  328. c.Width = right - left;
  329. c.Height = bottom - top;
  330. return !c.IsEmptyArea();
  331. }
  332. BOOL IntersectsWith(in RectF rect) {
  333. return (GetLeft() < rect.GetRight() &&
  334. GetTop() < rect.GetBottom() &&
  335. GetRight() > rect.GetLeft() &&
  336. GetBottom() > rect.GetTop());
  337. }
  338. static BOOL Union(out RectF c, in RectF a, in RectF b) {
  339. REAL right = ((a.GetRight() > b.GetRight()) ? a.GetRight() : b.GetRight());
  340. REAL bottom = ((a.GetBottom() > b.GetBottom()) ? a.GetBottom() : b.GetBottom());
  341. // REAL right = max(a.GetRight(), b.GetRight());
  342. // REAL bottom = max(a.GetBottom(), b.GetBottom());
  343. // REAL left = min(a.GetLeft(), b.GetLeft());
  344. // REAL top = min(a.GetTop(), b.GetTop());
  345. REAL left = ((a.GetLeft() < b.GetLeft()) ? a.GetLeft() : b.GetLeft());
  346. REAL top = ((a.GetTop() < b.GetTop()) ? a.GetTop() : b.GetTop());
  347. c.X = left;
  348. c.Y = top;
  349. c.Width = right - left;
  350. c.Height = bottom - top;
  351. return !c.IsEmptyArea();
  352. }
  353. VOID Offset(in PointF point) {
  354. Offset(point.X, point.Y);
  355. }
  356. VOID Offset(in REAL dx, in REAL dy) {
  357. X += dx;
  358. Y += dy;
  359. }
  360. REAL X;
  361. REAL Y;
  362. REAL Width;
  363. REAL Height;
  364. }
  365. //--------------------------------------------------------------------------
  366. // Represents a rectangle in a 2D coordinate system (integer coordinates)
  367. //--------------------------------------------------------------------------
  368. struct Rect {
  369. public:
  370. static Rect init(in INT x, in INT y, in INT width, in INT height) {
  371. Rect ret;
  372. ret.X = x;
  373. ret.Y = y;
  374. ret.Width = width;
  375. ret.Height = height;
  376. return ret;
  377. }
  378. static Rect init(in Point location, in Size size) {
  379. Rect ret;
  380. ret.X = location.X;
  381. ret.Y = location.Y;
  382. ret.Width = size.Width;
  383. ret.Height = size.Height;
  384. return ret;
  385. }
  386. Rect Clone() {
  387. return Rect.init(X, Y, Width, Height);
  388. }
  389. alias Clone dup;
  390. VOID GetLocation(out Point point) {
  391. point.X = X;
  392. point.Y = Y;
  393. }
  394. VOID GetSize(out Size size) {
  395. size.Width = Width;
  396. size.Height = Height;
  397. }
  398. VOID GetBounds(out Rect rect) {
  399. rect.X = X;
  400. rect.Y = Y;
  401. rect.Width = Width;
  402. rect.Height = Height;
  403. }
  404. INT GetLeft() {
  405. return X;
  406. }
  407. INT GetTop() {
  408. return Y;
  409. }
  410. INT GetRight() {
  411. return X+Width;
  412. }
  413. INT GetBottom() {
  414. return Y+Height;
  415. }
  416. BOOL IsEmptyArea() {
  417. return (Width <= 0) || (Height <= 0);
  418. }
  419. BOOL Equals(in Rect rect) {
  420. return X == rect.X &&
  421. Y == rect.Y &&
  422. Width == rect.Width &&
  423. Height == rect.Height;
  424. }
  425. BOOL Contains(in INT x, in INT y) {
  426. return x >= X && x < X+Width &&
  427. y >= Y && y < Y+Height;
  428. }
  429. BOOL Contains(in Point pt) {
  430. return Contains(pt.X, pt.Y);
  431. }
  432. BOOL Contains(in Rect rect) {
  433. return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
  434. (Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
  435. }
  436. VOID Inflate(in INT dx, in INT dy) {
  437. X -= dx;
  438. Y -= dy;
  439. Width += 2*dx;
  440. Height += 2*dy;
  441. }
  442. VOID Inflate(in Point point) {
  443. Inflate(point.X, point.Y);
  444. }
  445. BOOL Intersect(in Rect rect) {
  446. return Intersect(*this, *this, rect);
  447. }
  448. static BOOL Intersect(out Rect c, in Rect a, in Rect b) {
  449. INT right = ((a.GetRight() < b.GetRight()) ? a.GetRight() : b.GetRight());
  450. // INT right = min(a.GetRight(), b.GetRight());
  451. INT bottom = ((a.GetBottom() < b.GetBottom()) ? a.GetBottom() : b.GetBottom());
  452. INT left = ((a.GetLeft() > b.GetLeft()) ? a.GetLeft() : b.GetLeft());
  453. INT top = ((a.GetTop() > b.GetTop()) ? a.GetTop() : b.GetTop());
  454. c.X = left;
  455. c.Y = top;
  456. c.Width = right - left;
  457. c.Height = bottom - top;
  458. return !c.IsEmptyArea();
  459. }
  460. BOOL IntersectsWith(in Rect rect) {
  461. return (GetLeft() < rect.GetRight() &&
  462. GetTop() < rect.GetBottom() &&
  463. GetRight() > rect.GetLeft() &&
  464. GetBottom() > rect.GetTop());
  465. }
  466. static BOOL Union(out Rect c, in Rect a, in Rect b) {
  467. INT right = ((a.GetRight() > b.GetRight()) ? a.GetRight() : b.GetRight());
  468. INT bottom = ((a.GetBottom() > b.GetBottom()) ? a.GetBottom() : b.GetBottom());
  469. // INT right = max(a.GetRight(), b.GetRight());
  470. // INT bottom = max(a.GetBottom(), b.GetBottom());
  471. // INT left = min(a.GetLeft(), b.GetLeft());
  472. // INT top = min(a.GetTop(), b.GetTop());
  473. INT left = ((a.GetLeft() < b.GetLeft()) ? a.GetLeft() : b.GetLeft());
  474. INT top = ((a.GetTop() < b.GetTop()) ? a.GetTop() : b.GetTop());
  475. c.X = left;
  476. c.Y = top;
  477. c.Width = right - left;
  478. c.Height = bottom - top;
  479. return !c.IsEmptyArea();
  480. }
  481. VOID Offset(in Point point) {
  482. Offset(point.X, point.Y);
  483. }
  484. VOID Offset(in INT dx, in INT dy) {
  485. X += dx;
  486. Y += dy;
  487. }
  488. INT X;
  489. INT Y;
  490. INT Width;
  491. INT Height;
  492. }
  493. struct PathData {
  494. public:
  495. INT Count;
  496. PointF[] Points;
  497. BYTE[] Types;
  498. }
  499. struct CharacterRange {
  500. public:
  501. CharacterRange init(INT first, INT length) {
  502. CharacterRange ret;
  503. ret.First = first;
  504. ret.Length = length;
  505. return ret;
  506. }
  507. INT First;
  508. INT Length;
  509. }