]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/scout-gfx/include/fade_icon
update
[l4.git] / l4 / pkg / scout-gfx / include / fade_icon
1 // vi:ft=cpp
2 /*
3  * \brief   Implementation of fading icon
4  * \date    2005-10-24
5  * \author  Norman Feske <norman.feske@genode-labs.com>
6  *
7  * Fading icons are presented at a alpha value of 50 percent.
8  * When getting the mouse focus, we smoothly increase the
9  * alpha value to 100 percent.
10  */
11
12 /*
13  * Copyright (C) 2005-2009
14  * Genode Labs, Feske & Helmuth Systementwicklung GbR
15  *
16  * This file is part of the Genode OS framework, which is distributed
17  * under the terms of the GNU General Public License version 2.
18  */
19
20 #pragma once
21
22 #include <l4/scout-gfx/pt_icon>
23 #include <l4/scout-gfx/fader>
24
25 namespace Scout_gfx { namespace Pt {
26
27 template <typename PT>
28 class Fade_icon : public Fader, public Icon<PT>
29 {
30 private:
31
32   typedef Icon<PT> Base_icon;
33
34   int _default_alpha;
35   int _focus_alpha;
36
37 public:
38
39   /**
40    * Constructor
41    */
42   Fade_icon() : _default_alpha(100), _focus_alpha(255)
43   {
44     _curr_value = _dst_value = _default_alpha;
45     step(12);
46   }
47
48   /**
49    * Accessor functions
50    */
51   int default_alpha() { return _default_alpha; }
52
53   /**
54    * Define alpha value for unfocused icon
55    */
56   void default_alpha(int alpha ) { _default_alpha = alpha; }
57
58   /**
59    * Define alpha value when having the mouse focus
60    */
61   void focus_alpha(int alpha) { _focus_alpha = alpha; }
62
63   /**
64    * Tick interface
65    */
66   int on_tick()
67   {
68     /* call on_tick function of the fader */
69     if (Fader::on_tick() == 0) return 0;
70
71     Base_icon::alpha(_curr_value);
72     return 1;
73   }
74
75   /**
76    * Icon interface
77    */
78   void alpha(int alpha)
79   {
80     _curr_value = alpha;
81     Base_icon::alpha(alpha);
82   }
83
84   /**
85    * Element interface
86    */
87   void mfocus(int flag)
88   {
89     Base_icon::mfocus(flag);
90     int step = _focus_alpha - _default_alpha;
91     step *= flag ? 26 : 19;
92     fade_to(flag ? _focus_alpha : _default_alpha, step >> 8);
93   }
94 };
95
96
97 }}