3 * \brief Titlebar interface
5 * \author Norman Feske <norman.feske@genode-labs.com>
9 * Copyright (C) 2005-2009
10 * Genode Labs, Feske & Helmuth Systementwicklung GbR
12 * This file is part of the Genode OS framework, which is distributed
13 * under the terms of the GNU General Public License version 2.
18 #include <l4/mag-gfx/geometry>
19 #include <l4/mag-gfx/canvas>
21 #include <l4/scout-gfx/icon>
22 #include <l4/scout-gfx/fonts>
23 #include <l4/scout-gfx/widget>
24 #include <l4/scout-gfx/factory>
25 #include <l4/scout-gfx/style>
34 class Titlebar : public Parent_widget
39 Mag_gfx::Area _txt_sz;
41 Mag_gfx::Font const *_font;
45 Area preferred_size() const { return _txt_sz + Area(32, 10); }
46 Area min_size() const { return _txt_sz + Area(32, 10); }
47 Area max_size() const { return Area(Area::Max_w, _txt_sz.h() + 10); }
49 Orientations expanding() const { return Horizontal; }
50 bool empty() const { return false; }
52 void set_geometry(Rect const &r)
55 _pos = r.p1(); _size = r.area().min(max_size());
57 _fg->set_geometry(Rect(Point(0,0), _size));
60 Rect geometry() const { return Rect(_pos, _size); }
62 void text(const char *txt)
64 _txt = txt ? txt : "Scout";
65 _txt_sz = Area(_font->str_w(_txt), _font->str_h(_txt));
66 _txt_len = strlen(_txt);
72 explicit Titlebar(Factory *f, Mag_gfx::Font const *font)
73 : _fg(f->create_icon()), _font(font)
83 * Define foreground of titlebar
85 void rgba(unsigned char *rgba)
86 { _fg->rgba(rgba, Area(32, 32), 0, 0); };
92 void draw(Mag_gfx::Canvas *c, Mag_gfx::Point const &p)
96 const int b = 180, a = 200;
97 c->draw_box(Rect(_size) + p, Color(b, b, b, a));
99 Point _txt_pos = p + Point(8, 0).max(Rect(_size).center(_txt_sz)) - Point(0, 1);
100 c->draw_string(_txt_pos, _font, Color(0,0,0,200), _txt);
101 Parent_widget::draw(c, p);