/platform/win/platform/vars/view.d

http://github.com/wilkie/djehuty · D · 160 lines · 95 code · 38 blank · 27 comment · 9 complexity · 885db371754568b429b4790e2c849704 MD5 · raw file

  1. /*
  2. * view.d
  3. *
  4. * This module has the structure that is kept with a View class for Windows.
  5. *
  6. * Author: Dave Wilkinson
  7. * Originated: July 22th, 2009
  8. *
  9. */
  10. module platform.vars.view;
  11. import platform.win.common;
  12. import binding.win32.gdiplusgpstubs;
  13. import binding.win32.gdiplustypes;
  14. import binding.win32.gdiplusimaging;
  15. struct ViewPlatformVars {
  16. // antialias
  17. bool aa;
  18. RECT bounds;
  19. HDC dc;
  20. GpImage* image;
  21. Rect rt;
  22. BitmapData bdata;
  23. void* bits;
  24. int length;
  25. int penClr;
  26. GpBrush* curBrush = null;
  27. GpPen* curPen = null;
  28. GpBrush* curTextBrush = null;
  29. GpFont* curFont = null;
  30. GpGraphics* g = null;
  31. _clipList clipRegions;
  32. }
  33. class _clipList {
  34. this() {
  35. }
  36. // make sure to delete the regions from the list
  37. ~this() {
  38. HANDLE rgn;
  39. while(remove(rgn)) {
  40. DeleteObject(rgn);
  41. }
  42. }
  43. // add to the head
  44. // Description: Will add the data to the head of the list.
  45. // data: The information you wish to store. It must correspond to the type of data you specified in the declaration of the class.
  46. void addItem(HANDLE data) {
  47. LinkedListNode* newNode = new LinkedListNode;
  48. newNode.data = data;
  49. if (head is null) {
  50. head = newNode;
  51. tail = newNode;
  52. newNode.next = newNode;
  53. newNode.prev = newNode;
  54. }
  55. else {
  56. newNode.next = head;
  57. newNode.prev = tail;
  58. head.prev = newNode;
  59. tail.next = newNode;
  60. head = newNode;
  61. }
  62. _count++;
  63. }
  64. // remove the tail
  65. // Description: Will remove an item from the tail of the list, which would remove in a first-in-first-out ordering (FIFO).
  66. // data: Will be set to the data retreived.
  67. bool remove(out HANDLE data) {
  68. if (tail == null) {
  69. return false;
  70. }
  71. data = tail.data;
  72. //tail.next = null;
  73. //tail.prev = null;
  74. if (head is tail) {
  75. // unlink all
  76. head = null;
  77. tail = null;
  78. }
  79. else {
  80. tail = tail.prev;
  81. }
  82. _count--;
  83. return true;
  84. }
  85. bool remove() {
  86. if (tail == null) {
  87. return false;
  88. }
  89. //tail.next = null;
  90. //tail.prev = null;
  91. if (head is tail)
  92. {
  93. // unlink all
  94. head = null;
  95. tail = null;
  96. }
  97. else
  98. {
  99. tail = tail.prev;
  100. }
  101. _count--;
  102. return true;
  103. }
  104. uint length() {
  105. return _count;
  106. }
  107. protected:
  108. // the contents of a node
  109. struct LinkedListNode {
  110. LinkedListNode* next;
  111. LinkedListNode* prev;
  112. HANDLE data;
  113. }
  114. // the head and tail of the list
  115. LinkedListNode* head = null;
  116. LinkedListNode* tail = null;
  117. // the last accessed node is cached
  118. LinkedListNode* last = null;
  119. uint lastIndex = 0;
  120. // the number of items in the list
  121. uint _count;
  122. }