PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 11module platform.vars.view;
 12
 13import platform.win.common;
 14
 15import binding.win32.gdiplusgpstubs;
 16import binding.win32.gdiplustypes;
 17import binding.win32.gdiplusimaging;
 18
 19struct ViewPlatformVars {
 20	// antialias
 21	bool aa;
 22
 23	RECT bounds;
 24	HDC dc;
 25	
 26	GpImage* image;
 27	Rect rt;
 28	BitmapData bdata;
 29
 30	void* bits;
 31	int length;
 32
 33	int penClr;
 34
 35	GpBrush* curBrush = null;
 36	GpPen* curPen = null;
 37	GpBrush* curTextBrush = null;
 38	GpFont* curFont = null;
 39
 40	GpGraphics* g = null;
 41
 42	_clipList clipRegions;
 43}
 44
 45class _clipList {
 46	this() {
 47	}
 48
 49	// make sure to delete the regions from the list
 50	~this() {
 51		HANDLE rgn;
 52		while(remove(rgn)) {
 53			DeleteObject(rgn);
 54		}
 55	}
 56
 57	// add to the head
 58
 59	// Description: Will add the data to the head of the list.
 60	// data: The information you wish to store.  It must correspond to the type of data you specified in the declaration of the class.
 61	void addItem(HANDLE data) {
 62		LinkedListNode* newNode = new LinkedListNode;
 63		newNode.data = data;
 64
 65		if (head is null) {
 66			head = newNode;
 67			tail = newNode;
 68
 69			newNode.next = newNode;
 70			newNode.prev = newNode;
 71		}
 72		else {
 73			newNode.next = head;
 74			newNode.prev = tail;
 75
 76			head.prev = newNode;
 77			tail.next = newNode;
 78
 79			head = newNode;
 80		}
 81
 82		_count++;
 83	}
 84
 85	// remove the tail
 86
 87	// Description: Will remove an item from the tail of the list, which would remove in a first-in-first-out ordering (FIFO).
 88	// data: Will be set to the data retreived.
 89	bool remove(out HANDLE data) {
 90		if (tail == null) {
 91			return false;
 92		}
 93
 94		data = tail.data;
 95
 96		//tail.next = null;
 97		//tail.prev = null;
 98
 99		if (head is tail) {
100			// unlink all
101			head = null;
102			tail = null;
103		}
104		else {
105			tail = tail.prev;
106		}
107
108		_count--;
109
110		return true;
111	}
112
113	bool remove() {
114		if (tail == null) {
115			return false;
116		}
117
118		//tail.next = null;
119		//tail.prev = null;
120
121		if (head is tail)
122		{
123			// unlink all
124			head = null;
125			tail = null;
126		}
127		else
128		{
129			tail = tail.prev;
130		}
131
132		_count--;
133
134		return true;
135	}
136
137	uint length() {
138	   return _count;
139	}
140
141protected:
142
143	// the contents of a node
144	struct LinkedListNode {
145		LinkedListNode* next;
146		LinkedListNode* prev;
147		HANDLE data;
148	}
149
150	// the head and tail of the list
151	LinkedListNode* head = null;
152	LinkedListNode* tail = null;
153
154	// the last accessed node is cached
155	LinkedListNode* last = null;
156	uint lastIndex = 0;
157
158	// the number of items in the list
159	uint _count;
160}