genode/repos/demo/src/app/scout/widgets.h

178 lines
3.5 KiB
C
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Basic user interface elements
* \date 2005-10-24
* \author Norman Feske <norman.feske@genode-labs.com>
*/
/*
* Copyright (C) 2005-2017 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 Affero General Public License version 3.
2011-12-22 16:19:25 +01:00
*/
#ifndef _WIDGETS_H_
#define _WIDGETS_H_
#include "elements.h"
namespace Scout {
class Docview;
template <typename, int> class Horizontal_shadow;
class Generic_icon;
template <typename, int, int> class Icon;
}
2011-12-22 16:19:25 +01:00
class Scout::Docview : public Parent_element
2011-12-22 16:19:25 +01:00
{
private:
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
/*
* Noncopyable
*/
Docview(Docview const &);
Docview &operator = (Docview const &);
Element *_bg;
2011-12-22 16:19:25 +01:00
Element *_cont;
int _voffset;
int _right_pad;
int _padx;
public:
/**
* Constructor
*/
explicit Docview(int padx = 7) :
2011-12-22 16:19:25 +01:00
_bg(0), _cont(0), _voffset(0), _right_pad(0), _padx(padx) { }
/**
* Accessor functions
*/
Element *content() { return _cont; }
/**
* Define content to be presented in the Docview
*/
inline void content(Element *cont)
{
_cont = cont;
_last = _first = 0;
append(cont);
}
inline void voffset(int voffset) { _voffset = voffset; }
/**
* Define background texture
*/
inline void texture(Element *bg) { _bg = bg; }
2011-12-22 16:19:25 +01:00
/**
* Define right padding
*/
inline void right_pad(int pad) { _right_pad = pad; }
/**
* Element interface
*/
void format_fixed_width(int) override;
void draw(Canvas_base &, Point) override;
Element *find(Point) override;
void geometry(Rect) override;
2011-12-22 16:19:25 +01:00
};
template <typename PT, int INTENSITY>
struct Scout::Horizontal_shadow : Element
2011-12-22 16:19:25 +01:00
{
explicit Horizontal_shadow(int height = 8)
{
_min_size = Area(0, height);
}
/**
* Element interface
*/
void draw(Canvas_base &, Point) override;
Element *find(Point) override { return 0; }
void format_fixed_width(int w) override { _min_size = Area(w, _min_size.h()); }
2011-12-22 16:19:25 +01:00
};
class Scout::Generic_icon : public Element
2011-12-22 16:19:25 +01:00
{
public:
/**
* Request current alpha value
*/
virtual int alpha() = 0;
/**
* Define alpha value of the icon
*/
virtual void alpha(int alpha) = 0;
};
template <typename PT, int W, int H>
class Scout::Icon : public Generic_icon
2011-12-22 16:19:25 +01:00
{
private:
Follow practices suggested by "Effective C++" The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
2017-12-21 15:42:15 +01:00
PT _pixel [H][W]; /* icon pixels in PT pixel format */
unsigned char _alpha [H][W]; /* alpha channel of icon pixels */
unsigned char _shadow [H][W]; /* shadow calculation buffer */
int _icon_alpha = 255; /* alpha value of whole icon */
2011-12-22 16:19:25 +01:00
public:
/**
* Constructor
*/
Icon();
/**
* Define new icon pixels from rgba buffer
*
* \param vshift vertical shift of pixels
* \param shadow shadow divisor, low value -> dark shadow
* special case zero -> no shadow
*
* The buffer must contains W*H pixels. Each pixels consists
* of four bytes, red, green, blue, and alpha.
*/
void rgba(unsigned char *src, int vshift = 0, int shadow = 4);
/**
* Define icon to be a glow of an rgba image
*
* \param src source rgba image to extract the glow's shape from
* \param c glow color
*/
void glow(unsigned char *src, Color c);
/**
* Generic_icon interface
*/
int alpha() override { return _icon_alpha; }
void alpha(int alpha) override
2011-12-22 16:19:25 +01:00
{
_icon_alpha = alpha;
refresh();
}
/**
* Element interface
*/
void draw(Canvas_base &, Point) override;
Element *find(Point) override;
2011-12-22 16:19:25 +01:00
};
#endif /* _WIDGETS_H_ */