2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Implementation of fading icon
|
|
|
|
* \date 2005-10-24
|
|
|
|
* \author Norman Feske <norman.feske@genode-labs.com>
|
|
|
|
*
|
|
|
|
* Fading icons are presented at a alpha value of 50 percent.
|
|
|
|
* When getting the mouse focus, we smoothly increase the
|
|
|
|
* alpha value to 100 percent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2005-2013 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _FADE_ICON_H_
|
|
|
|
#define _FADE_ICON_H_
|
|
|
|
|
2013-12-30 01:21:53 +01:00
|
|
|
#include <scout/misc_math.h>
|
|
|
|
#include <scout/fader.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include "widgets.h"
|
2013-12-30 01:21:53 +01:00
|
|
|
|
|
|
|
namespace Scout { template <typename PT, int W, int H> class Fade_icon; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
template <typename PT, int W, int H>
|
2013-12-30 01:21:53 +01:00
|
|
|
class Scout::Fade_icon : public Fader, public Icon<PT, W, H>
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
int _default_alpha;
|
|
|
|
int _focus_alpha;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Fade_icon()
|
|
|
|
{
|
|
|
|
_curr_value = _dst_value = _default_alpha = 100;
|
|
|
|
_focus_alpha = 255;
|
|
|
|
step(12);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accessor functions
|
|
|
|
*/
|
|
|
|
int default_alpha() { return _default_alpha; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define alpha value for unfocused icon
|
|
|
|
*/
|
|
|
|
void default_alpha(int alpha ) { _default_alpha = alpha; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define alpha value when having the mouse focus
|
|
|
|
*/
|
|
|
|
void focus_alpha(int alpha) { _focus_alpha = alpha; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tick interface
|
|
|
|
*/
|
|
|
|
int on_tick()
|
|
|
|
{
|
|
|
|
/* call on_tick function of the fader */
|
2013-12-30 01:21:53 +01:00
|
|
|
if (Fader::on_tick() == 0) return 0;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
Icon<PT, W,H>::alpha(_curr_value);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Icon interface
|
|
|
|
*/
|
|
|
|
void alpha(int alpha)
|
|
|
|
{
|
|
|
|
_curr_value = alpha;
|
2013-12-30 01:21:53 +01:00
|
|
|
Icon<PT, W, H>::alpha(alpha);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Element interface
|
|
|
|
*/
|
|
|
|
void mfocus(int flag)
|
|
|
|
{
|
|
|
|
Icon<PT, W, H>::mfocus(flag);
|
|
|
|
int step = _focus_alpha - _default_alpha;
|
|
|
|
step *= flag ? 26 : 19;
|
|
|
|
fade_to(flag ? _focus_alpha : _default_alpha, step >> 8);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _FADE_ICON_H_ */
|