]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout-gfx/include/titlebar
Update
[l4.git] / l4 / pkg / scout-gfx / include / titlebar
1 // vi:ft=cpp
2 /*
3  * \brief   Titlebar interface
4  * \date    2005-10-24
5  * \author  Norman Feske <norman.feske@genode-labs.com>
6  */
7
8 /*
9  * Copyright (C) 2005-2009
10  * Genode Labs, Feske & Helmuth Systementwicklung GbR
11  *
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.
14  */
15
16 #pragma once
17
18 #include <l4/mag-gfx/geometry>
19 #include <l4/mag-gfx/canvas>
20
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>
26
27 #include <cstring>
28
29 namespace Scout_gfx {
30
31 /***************
32  ** Title bar **
33  ***************/
34 class Titlebar : public Parent_widget
35 {
36 private:
37   Icon *_fg;
38   const char *_txt;
39   Mag_gfx::Area _txt_sz;
40   int _txt_len;
41   Mag_gfx::Font const *_font;
42
43 public:
44
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); }
48
49   Orientations expanding() const { return Horizontal; }
50   bool empty() const { return false; }
51
52   void set_geometry(Rect const &r)
53   {
54
55     _pos = r.p1(); _size = r.area().min(max_size());
56     if (_fg)
57       _fg->set_geometry(Rect(Point(0,0), _size));
58   }
59
60   Rect geometry() const { return Rect(_pos, _size); }
61
62   void text(const char *txt)
63   {
64     _txt     = txt ? txt : "Scout";
65     _txt_sz  = Area(_font->str_w(_txt), _font->str_h(_txt));
66     _txt_len = strlen(_txt);
67   }
68
69   /**
70    * Constructor
71    */
72   explicit Titlebar(Factory *f, Mag_gfx::Font const *font)
73   : _fg(f->create_icon()), _font(font)
74   {
75     _fg->alpha(255);
76     _fg->findable(0);
77     text(0);
78
79     append(_fg);
80   }
81
82   /**
83    * Define foreground of titlebar
84    */
85   void rgba(unsigned char *rgba)
86   { _fg->rgba(rgba, Area(32, 32), 0, 0); };
87
88   /**
89    * Element interface
90    */
91
92   void draw(Mag_gfx::Canvas *c, Mag_gfx::Point const &p)
93   {
94     using Mag_gfx::Point;
95
96     const int b = 180, a = 200;
97     c->draw_box(Rect(_size) + p, Color(b, b, b, a));
98
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);
102   }
103 };
104
105 }