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