4 * \brief Titlebar interface
6 * \author Norman Feske <norman.feske@genode-labs.com>
10 * Copyright (C) 2005-2009
11 * Genode Labs, Feske & Helmuth Systementwicklung GbR
13 * This file is part of the Genode OS framework, which is distributed
14 * under the terms of the GNU General Public License version 2.
19 #include <l4/mag-gfx/geometry>
20 #include <l4/mag-gfx/canvas>
22 #include <l4/scout-gfx/widget>
23 #include <l4/scout-gfx/factory>
32 class Titlebar : public Parent_widget
37 Mag_gfx::Area _txt_sz;
39 Mag_gfx::Font const *_font;
43 Area preferred_size() const { return _txt_sz + Area(32, 10); }
44 Area min_size() const { return _txt_sz + Area(32, 10); }
45 Area max_size() const { return Area(Area::Max_w, _txt_sz.h() + 10); }
47 Orientations expanding() const { return Horizontal; }
48 bool empty() const { return false; }
50 void set_geometry(Rect const &r)
53 _pos = r.p1(); _size = r.area().min(max_size());
55 _fg->set_geometry(Rect(Point(0,0), _size));
58 Rect geometry() const { return Rect(_pos, _size); }
60 void text(const char *txt)
62 _txt = txt ? txt : "Scout";
63 _txt_sz = Area(_font->str_w(_txt), _font->str_h(_txt));
64 _txt_len = strlen(_txt);
70 explicit Titlebar(Factory *f, Mag_gfx::Font const *font)
71 : _fg(f->create_icon()), _font(font)
81 * Define foreground of titlebar
83 void rgba(unsigned char *rgba)
84 { _fg->rgba(rgba, Area(32, 32), 0, 0); };
90 void draw(Mag_gfx::Canvas *c, Mag_gfx::Point const &p)
94 const int b = 180, a = 200;
95 c->draw_box(Rect(_size) + p, Color(b, b, b, a));
97 Point _txt_pos = p + Point(8, 0).max(Rect(_size).center(_txt_sz)) - Point(0, 1);
98 c->draw_string(_txt_pos, _font, Color(0,0,0,200), _txt);
99 Parent_widget::draw(c, p);