2 * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
9 #include <l4/mag-gfx/clip_guard>
17 namespace Mag_server {
22 enum { Num_entries = 100 };
24 // merge all overlapping rects in the queue
27 for (unsigned i = last; i > 0; --i)
28 for (unsigned j = 0; j < last; ++j)
33 if ((_q[j] & _q[i-1]).valid())
35 _q[j] = _q[j] | _q[i-1];
36 memmove(_q + i - 1, _q + i, (last - i) * sizeof(Rect));
47 //printf("q[%d,%d - %d,%d]\n", r.x1(), r.y1(), r.x2(), r.y2());
48 for (unsigned i = 0; i < last; ++i)
50 if ((_q[i] & r).valid())
52 // merge with overlapping rect
59 if (last < Num_entries)
60 _q[last++] = r; // add new entry
63 // queue is full, just merge with the last entry
64 _q[last-1] = _q[last - 1] | r;
72 typedef Rect const *iterator;
74 iterator begin() const { return _q; }
75 iterator end() const { return _q + last; }
82 static Redraw_queue rdq;
85 View_stack::outline(View const *v) const
87 if (_mode.flat() || !v->need_frame())
94 View_stack::viewport(View *v, Rect const &pos, bool) const
96 Rect old = outline(v);
98 /* take over new view parameters */
101 Rect compound = old | outline(v);
104 /* update labels (except when moving the mouse cursor) */
106 _place_labels(compound);
109 /* update area on screen */
111 // draw_recursive(top(), 0, /*redraw ? 0 : view->session(),*/ compound);
115 View_stack::draw_frame(View const *v) const
117 if (_mode.flat() || !v->need_frame())
120 Rgb32::Color color = v->focused() ? Rgb32::White : View::frame_color();
121 _canvas->draw_rect(v->offset(-3, -3, 3, 3), Rgb32::Black);
122 _canvas->draw_rect(v->offset(-2, -2, 2, 2), color);
123 _canvas->draw_rect(v->offset(-1, -1, 1, 1), Rgb32::Black);
127 View_stack::draw_label(View const *v) const
129 if (_mode.flat() || !v->need_frame())
134 View_stack::draw_recursive(View const *v, View const *dst, Rect const &rect) const
138 /* find next view that intersects with the current clipping rectangle */
139 for ( ; v && !(clipped = outline(v) & rect).valid(); )
145 Rect_tuple border = rect - clipped;
147 View const *n = v->next();
148 if (n && border.t.valid())
149 draw_recursive(n, dst, border.t);
150 if (n && border.l.valid())
151 draw_recursive(n, dst, border.l);
153 if (!dst || dst == v || v->transparent())
155 Clip_guard g(_canvas, clipped);
157 v->draw(_canvas, this, _mode);
161 if (n && border.r.valid())
162 draw_recursive(n, dst, border.r);
163 if (n && border.b.valid())
164 draw_recursive(n, dst, border.b);
168 View_stack::refresh_view(View const *v, View const *dst, Rect const &rect) const
176 //draw_recursive(top(), dst, r);
182 for (Redraw_queue::iterator i = rdq.begin(); i != rdq.end(); ++i)
184 draw_recursive(top(), 0, *i);
186 _canvas_view->refresh(i->x1(), i->y1(), i->w(), i->h());
193 View_stack::stack(View *v, View *pivot, bool behind)
197 insert_after(v, pivot);
199 insert_before(v, pivot);
201 refresh_view(v, 0, outline(v));
206 View_stack::find(Point const &pos) const
208 View *n = top()->next();
209 while (n && !n->contains(pos))