genode/repos/demo/src/app/launchpad/section.h

86 lines
2.2 KiB
C
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Section widget
* \author Norman Feske
* \date 2006-08-30
*/
/*
* Copyright (C) 2006-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 _SECTION_H_
#define _SECTION_H_
#include "widgets.h"
template <typename PT>
class Section : public Scout::Parent_element
2011-12-22 16:19:25 +01:00
{
private:
enum { _SH = 8 }; /* shadow height */
enum { _STH = 20 }; /* shadow height */
Scout::Horizontal_shadow<PT, 40> _bg;
Scout::Horizontal_shadow<PT, 160> _shadow;
char const *_txt;
int _txt_w, _txt_h;
int _txt_len;
Scout::Font *_font;
int _r_add;
2011-12-22 16:19:25 +01:00
public:
Section(const char *txt, Scout::Font *font)
2011-12-22 16:19:25 +01:00
: _bg(_STH), _shadow(_SH), _txt(txt), _font(font), _r_add(100)
{
_txt_w = font->str_w(_txt, Scout::strlen(_txt));
_txt_h = font->str_h(_txt, Scout::strlen(_txt));
_txt_len = Scout::strlen(_txt);
2011-12-22 16:19:25 +01:00
append(&_bg);
append(&_shadow);
}
/**
* Element interface
*/
void format_fixed_width(int w)
{
using namespace Scout;
_min_size = Area(w, _format_children(0, w) + _SH/2);
_bg.geometry(Rect(_bg.position(),
Area(_bg.size().w() + _r_add, _bg.size().h())));
2011-12-22 16:19:25 +01:00
_shadow.geometry(Rect(_shadow.position(),
Area(_shadow.size().w() + _r_add,
_shadow.size().h())));
2011-12-22 16:19:25 +01:00
}
void draw(Scout::Canvas_base &canvas, Scout::Point abs_position)
2011-12-22 16:19:25 +01:00
{
using namespace Scout;
canvas.draw_box(abs_position.x() + _position.x(),
abs_position.y() + _position.y() + 1,
_size.w() + _r_add, _txt_h - 1, Color(240,240,240,130));
int _txt_x = abs_position.x() + _position.x() + max((_size.w() - _txt_w)/2, 8UL);
int _txt_y = abs_position.y() + _position.y() + max((_STH - _SH - _txt_h)/2, 0) - 1;
2011-12-22 16:19:25 +01:00
Parent_element::draw(canvas, abs_position);
2011-12-22 16:19:25 +01:00
canvas.draw_string(_txt_x , _txt_y, _font, Color(0,0,0,150), _txt, strlen(_txt));
canvas.draw_box(abs_position.x() + _position.x(), abs_position.y() + _position.y(),
_size.w() + _r_add, 1, Color(0,0,0,64));
2011-12-22 16:19:25 +01:00
}
};
#endif