1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #ifndef __RECTLIST_HPP_
|
---|
10 | #define __RECTLIST_HPP_
|
---|
11 |
|
---|
12 | #include "arch.hh"
|
---|
13 | #include "memory/lalloc.hh"
|
---|
14 | #include "isllist.hh"
|
---|
15 |
|
---|
16 | /*
|
---|
17 |
|
---|
18 | A rect list manages a list of disjoint rectangles. This is used for clipping, dirty_rectangles,
|
---|
19 | and a few other misc. things. The operations should be straitforward.
|
---|
20 |
|
---|
21 | The rectlist is actually just a point to a list of area nodes. Rectlist should be passed as
|
---|
22 | a reference.
|
---|
23 |
|
---|
24 | ussage example :
|
---|
25 |
|
---|
26 | // create a list containing the rectangle [0,0-320,200]
|
---|
27 | i4_rectlist l(0,0,320,200);
|
---|
28 |
|
---|
29 | // list now contains the area above minus the area in the rectangle [5,5,320-5,200-5]
|
---|
30 | l.remove_area(5,5,320-5,200-5);
|
---|
31 |
|
---|
32 | // list now conains the areas [100,0,105,5] & [100,200-5,105,200]
|
---|
33 | l. intersect_area(100,0,105,200);
|
---|
34 |
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | class i4_rect_list_class
|
---|
39 | {
|
---|
40 | public:
|
---|
41 | class area
|
---|
42 | {
|
---|
43 | public :
|
---|
44 | typedef i4_linear_allocator area_allocator;
|
---|
45 |
|
---|
46 | static area_allocator *area_alloc;
|
---|
47 |
|
---|
48 | i4_coord x1,y1,x2,y2;
|
---|
49 | area *next;
|
---|
50 |
|
---|
51 | #ifndef __MAC__
|
---|
52 | area(i4_coord X1, i4_coord Y1,i4_coord X2,i4_coord Y2)
|
---|
53 | {
|
---|
54 | x1=X1; y1=Y1;
|
---|
55 | x2=X2; y2=Y2;
|
---|
56 | }
|
---|
57 |
|
---|
58 | #ifndef i4_NEW_CHECK
|
---|
59 | void *operator new(size_t size)
|
---|
60 | {
|
---|
61 | return area_alloc->alloc();
|
---|
62 | }
|
---|
63 |
|
---|
64 | void operator delete(void *ptr)
|
---|
65 | {
|
---|
66 | area_alloc->free((area *)ptr);
|
---|
67 | }
|
---|
68 | #endif
|
---|
69 | #endif
|
---|
70 | };
|
---|
71 |
|
---|
72 | #ifdef __MAC__
|
---|
73 | area *new_area(i4_coord X1, i4_coord Y1, i4_coord X2, i4_coord Y2)
|
---|
74 | {
|
---|
75 | area *r = (area *)area::area_alloc->alloc();
|
---|
76 |
|
---|
77 | r->x1=X1; r->y1=Y1;
|
---|
78 | r->x2=X2; r->y2=Y2;
|
---|
79 |
|
---|
80 | return r;
|
---|
81 | }
|
---|
82 |
|
---|
83 | void delete_area(area *ptr)
|
---|
84 | {
|
---|
85 | area::area_alloc->free(ptr);
|
---|
86 | }
|
---|
87 | #else
|
---|
88 | area *new_area(i4_coord X1, i4_coord Y1, i4_coord X2, i4_coord Y2)
|
---|
89 | {
|
---|
90 | return new area(X1,Y1,X2,Y2);
|
---|
91 | }
|
---|
92 | void delete_area(area *ptr) { delete ptr; }
|
---|
93 | #endif
|
---|
94 | private:
|
---|
95 |
|
---|
96 |
|
---|
97 | public:
|
---|
98 | typedef i4_isl_list<area>::iterator area_iter;
|
---|
99 | i4_isl_list<area> list;
|
---|
100 |
|
---|
101 | i4_rect_list_class() {}
|
---|
102 | i4_rect_list_class(i4_rect_list_class *copy_from, i4_coord xoff, i4_coord yoff);
|
---|
103 |
|
---|
104 | // initial size of rect area
|
---|
105 | i4_rect_list_class(i4_coord x1, i4_coord y1, i4_coord x2, i4_coord y2)
|
---|
106 | { list.insert(*(new_area(x1,y1,x2,y2))); }
|
---|
107 |
|
---|
108 | // exchanges the contents of two rect_list : used to replace the display's clip list
|
---|
109 | void swap(i4_rect_list_class *other);
|
---|
110 |
|
---|
111 | i4_bool empty() { return list.empty(); }
|
---|
112 | void delete_list()
|
---|
113 | {
|
---|
114 | area *a;
|
---|
115 |
|
---|
116 | while (!empty())
|
---|
117 | {
|
---|
118 | a = &*list.begin();
|
---|
119 | list.erase();
|
---|
120 | delete_area(a);
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | // subtracts this area from rect rects
|
---|
125 | void remove_area(i4_coord x1, i4_coord y1, i4_coord x2, i4_coord y2);
|
---|
126 |
|
---|
127 | // combines this area with rects in list
|
---|
128 | void add_area(i4_coord x1, i4_coord y1, i4_coord x2, i4_coord y2,
|
---|
129 | i4_bool combine=i4_F);
|
---|
130 |
|
---|
131 | // reduces area list to that which intersects this area
|
---|
132 | void intersect_area(i4_coord x1, i4_coord y1, i4_coord x2, i4_coord y2);
|
---|
133 |
|
---|
134 | // reduces area list to that which intersects this area list
|
---|
135 | void intersect_list(i4_rect_list_class *other);
|
---|
136 |
|
---|
137 | // return i4_T if area is totally clipped away
|
---|
138 | // this can be used to skip expensive drawing operations
|
---|
139 | i4_bool clipped_away(i4_coord x1, i4_coord y1, i4_coord x2, i4_coord y2);
|
---|
140 |
|
---|
141 | // debuggin purposes only
|
---|
142 | void inspect(int print=0);
|
---|
143 |
|
---|
144 |
|
---|
145 | ~i4_rect_list_class() { delete_list(); }
|
---|
146 | } ;
|
---|
147 |
|
---|
148 |
|
---|
149 | #endif
|
---|
150 | //{{{ Emacs Locals
|
---|
151 | // Local Variables:
|
---|
152 | // folded-file: t
|
---|
153 | // End:
|
---|
154 | //}}}
|
---|