]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/mag/include/server/view_stack
96a7ce94292e0e8bada9e5f624f3f0cc29e696cc
[l4.git] / l4 / pkg / mag / include / server / view_stack
1 // vi:ft=cpp
2 /*
3  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #pragma once
11
12 #include <l4/re/video/view>
13
14 #include <l4/mag-gfx/canvas>
15 #include <l4/mag/server/view>
16
17 #include <assert.h>
18
19 namespace Mag_server {
20
21 using namespace Mag_gfx;
22
23 class View_stack
24 {
25 private:
26   class Dummy_view : public View
27   {
28   public:
29     Dummy_view() : View(Rect(Point(0,0), Area(0,0)), F_ignore) {}
30     void draw(Canvas *, View_stack const *, Mode) const {}
31   };
32
33   Canvas *_canvas;
34   View *const _no_stay_top;
35   View *_top;
36   View *const _background;
37
38   Mode _mode;
39
40   L4Re::Video::View *_canvas_view;
41
42
43   Dummy_view _no_stay_top_v;
44
45   View *top() const { return _top; }
46
47   Rect outline(View const *v) const;
48
49   void draw_frame(View const *v) const;
50   void draw_label(View const *v) const;
51
52   void insert_before(View *o, View *p)
53   {
54     o->_n = p;
55     o->_pn = p->_pn;
56     *p->_pn = o;
57     p->_pn = &o->_n;
58   }
59
60   void insert_after(View *o, View *p)
61   {
62     o->_n = p->_n;
63     o->_pn = &p->_n;
64     if (p->_n)
65       p->_n->_pn = &o->_n;
66
67     p->_n = o;
68   }
69
70 public:
71   explicit View_stack(Canvas *canvas, L4Re::Video::View *canvas_view, View *bg)
72   : _canvas(canvas), _no_stay_top(&_no_stay_top_v),  _top(bg),
73     _background(bg), _canvas_view(canvas_view)
74   {
75     bg->_pn = &_top;
76     insert_before(_no_stay_top, _top);
77   }
78
79   virtual
80   void refresh_view(View const *v, View const *dst, Rect const &rect) const;
81
82   /**
83    * Draw whole view stack
84    */
85   void update_all_views() const
86   {
87     //_place_labels(Rect(Point(), _canvas->size()));
88     refresh_view(0, 0, Rect(Point(), _canvas->size()));
89   }
90
91   virtual void flush();
92
93   Canvas *canvas() const { return _canvas; }
94
95   Mode mode() const { return _mode; }
96
97   void toggle_mode(Mode::Mode_flag m, bool update = false)
98   {
99     _mode.toggle(m);
100     if (update)
101       update_all_views();
102   }
103
104   void set_mode(Mode::Mode_flag m, bool on, bool update = false)
105   {
106     _mode.set(m, on);
107     if (update)
108       update_all_views();
109   }
110
111   virtual
112   void viewport(View *v, Rect const &pos, bool redraw) const;
113   virtual
114   void draw_recursive(View const *v, View const *dst, Rect const &) const;
115
116   virtual
117   void stack(View *v, View *pivot, bool behind = true);
118
119   void push_top(View *v, bool stay_top = false)
120   { stack(v, _no_stay_top, !stay_top); }
121
122   void push_bottom(View *v) { stack(v, _background, false); }
123
124   void remove(View *v)
125   {
126     if (!v->_pn)
127       return;
128
129     *v->_pn = v->_n;
130     if (v->_n)
131       v->_n->_pn = v->_pn;
132
133     v->_pn = 0;
134   }
135
136
137   void forget_view(View *v)
138   {
139     assert (v != _no_stay_top);
140     assert (v != _background);
141     remove(v);
142     refresh_view(0, 0, outline(v));
143   }
144
145   bool on_top(View const *v) const
146   { return _no_stay_top->next() == v; }
147
148   virtual
149   View *find(Point const &pos) const;
150
151   virtual ~View_stack() {}
152
153 };
154
155 }