]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout-gfx/lib/doc/token.cc
Inital import
[l4.git] / l4 / pkg / scout-gfx / lib / doc / token.cc
1 #include <l4/scout-gfx/doc/token>
2 #include <l4/mag-gfx/canvas>
3
4 namespace Scout_gfx {
5 /***********
6  ** Token **
7  ***********/
8
9 Token::Token(Style *style, const char *str, int len)
10 : _next(this)
11 {
12   _str               = str;
13   _len               = len;
14   _style             = style;
15   _flags.takes_focus = 0;
16   _col               = _style ? _style->color : Color(0, 0, 0);
17   _outline           = Color(0, 0, 0, 0);
18
19   if (!_style)
20     return
21 ;
22   _size = Area(_style->font->str_w(str, len) + _style->font->str_w(" ", 1),
23       _style->font->str_h(str, len));
24 }
25
26 void Token::draw(Canvas *c, Point const &p)
27 {
28   if (!_style)
29     return;
30
31   if (_style->attr & Style::ATTR_BOLD)
32     _outline = Color(_col.r(), _col.g(), _col.b(), 32);
33
34   Point np = p + Point(1,1);
35
36   if (_outline.a())
37     for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++)
38       c->draw_string(np + Point(i,j), _style->font, _outline, _str, _len);
39
40   c->draw_string(np, _style->font, _col, _str, _len);
41
42   if (_style->attr & Style::ATTR_UNDERLINE)
43     c->draw_box(Rect(_size).bottom(1) + p, Color(0,0,255));
44 }
45
46 }