3 * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
12 #include <l4/mag-gfx/canvas>
13 #include <l4/scout-gfx/widget>
15 namespace Scout_gfx { namespace Pt {
17 template <typename PT>
18 class Horizontal_shadow : public Widget
26 explicit Horizontal_shadow(int height, int intensity)
27 : _intensity(intensity), _h(height)
28 { _size = Area(0, height); }
33 void draw(Canvas *c, Point const &p);
34 Widget *find(Point const &) { return 0; }
36 Area min_size() const { return Area(0, _h); }
37 Area preferred_size() const { return Area(0, _h); }
38 Area max_size() const { return Area(Area::Max_w, _h); }
39 bool empty() const { return false; }
40 Orientations expanding() const { return Horizontal; }
41 Rect geometry() const { return Rect(_pos, _size); }
42 void set_geometry(Rect const &s)
44 Area x = s.area().max(min_size()).max(min_size());
45 _pos = s.p1(); _size = x;
51 /***********************
52 ** Horizontal shadow **
53 ***********************/
55 template <typename PT>
56 void Horizontal_shadow<PT>::draw(Canvas *c, Point const &_p)
58 typedef typename PT::Pixel Pixel;
59 typedef typename PT::Color Color;
61 char *addr = (char *)c->buffer();
66 Rect clip = c->clip();
67 Rect cr = (Rect(_size) + _p) & clip;
72 int curr_a = _intensity;
73 int step = _size.h() ? (curr_a/_size.h()) : 0;
75 int bpl = c->bytes_per_line();
77 addr += bpl * cr.y1() + cr.x1() * sizeof(Pixel);
79 Color shadow_color(0,0,0);
82 for (int j = 0; j < h; j++, addr += bpl)
84 Pixel *d = reinterpret_cast<Pixel*>(addr);
87 for (int i = 0; i < w; i++, d++)
88 *d = PT::mix(*d, shadow_color, curr_a);