2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Window with holding a fixed-size content element
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-09-21
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* 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
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _FRAMEBUFFER_WINDOW_H_
|
|
|
|
#define _FRAMEBUFFER_WINDOW_H_
|
|
|
|
|
2013-12-30 01:21:53 +01:00
|
|
|
#include <scout/window.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
#include "titlebar.h"
|
|
|
|
#include "sky_texture.h"
|
2013-05-22 19:24:20 +02:00
|
|
|
#include "fade_icon.h"
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
#define TITLEBAR_RGBA _binary_titlebar_rgba_start
|
2013-05-22 19:24:20 +02:00
|
|
|
#define SIZER_RGBA _binary_sizer_rgba_start
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
extern unsigned char TITLEBAR_RGBA[];
|
2013-05-22 19:24:20 +02:00
|
|
|
extern unsigned char SIZER_RGBA[];
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
template <typename PT>
|
2013-12-30 01:21:53 +01:00
|
|
|
class Framebuffer_window : public Scout::Window
|
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
|
|
|
|
*/
|
|
|
|
Framebuffer_window(Framebuffer_window const &);
|
|
|
|
Framebuffer_window &operator = (Framebuffer_window const &);
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
enum { _TH = 32 }; /* height of title bar */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Widgets
|
|
|
|
*/
|
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
|
|
|
Scout::Titlebar<PT> _titlebar { };
|
|
|
|
Scout::Sky_texture<PT, 512, 512> _bg_texture { };
|
|
|
|
int _bg_offset { 0 };
|
|
|
|
Scout::Fade_icon<PT, 32, 32> _sizer { };
|
2013-12-30 01:21:53 +01:00
|
|
|
Scout::Element *_content;
|
|
|
|
bool _config_alpha;
|
|
|
|
bool _config_resize_handle;
|
|
|
|
bool _config_decoration;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2013-12-30 01:21:53 +01:00
|
|
|
Framebuffer_window(Scout::Graphics_backend &gfx_backend,
|
|
|
|
Scout::Element *content,
|
|
|
|
Scout::Point position,
|
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
|
|
|
Scout::Area /* size */,
|
2013-12-30 01:21:53 +01:00
|
|
|
Scout::Area max_size,
|
|
|
|
char const *name,
|
|
|
|
bool config_alpha,
|
|
|
|
bool config_resize_handle,
|
|
|
|
bool config_decoration)
|
2011-12-22 16:19:25 +01:00
|
|
|
:
|
2013-12-30 01:21:53 +01:00
|
|
|
Scout::Window(gfx_backend, position,
|
|
|
|
Scout::Area(content->min_size().w() + 2,
|
|
|
|
content->min_size().h() + 1 + _TH),
|
|
|
|
max_size, false),
|
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
|
|
|
_content(content), _config_alpha(config_alpha),
|
2013-05-22 19:21:29 +02:00
|
|
|
_config_resize_handle(config_resize_handle),
|
|
|
|
_config_decoration(config_decoration)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
/* titlebar */
|
|
|
|
_titlebar.rgba(TITLEBAR_RGBA);
|
|
|
|
_titlebar.text(name);
|
2013-12-30 01:21:53 +01:00
|
|
|
_titlebar.event_handler(new Scout::Mover_event_handler(this));
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-05-22 19:24:20 +02:00
|
|
|
/* resize handle */
|
|
|
|
_sizer.rgba(SIZER_RGBA);
|
2013-12-30 01:21:53 +01:00
|
|
|
_sizer.event_handler(new Scout::Sizer_event_handler(this));
|
2013-05-22 19:24:20 +02:00
|
|
|
_sizer.alpha(100);
|
|
|
|
|
2013-05-22 19:21:29 +02:00
|
|
|
if (config_decoration)
|
|
|
|
append(&_titlebar);
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
append(_content);
|
|
|
|
|
2013-05-22 19:21:29 +02:00
|
|
|
if (config_resize_handle)
|
|
|
|
append(&_sizer);
|
|
|
|
|
2013-12-30 01:21:53 +01:00
|
|
|
unsigned const BORDER = 1, TITLE = _TH, RESIZER = 32;
|
|
|
|
_min_size = Scout::Area(BORDER + RESIZER + BORDER,
|
|
|
|
BORDER + TITLE + RESIZER + BORDER);
|
2013-05-22 19:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the window title
|
|
|
|
*/
|
|
|
|
void name(const char *name)
|
|
|
|
{
|
|
|
|
_titlebar.text(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the alpha config option
|
|
|
|
*/
|
|
|
|
void config_alpha(bool alpha)
|
|
|
|
{
|
|
|
|
_config_alpha = alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the resize_handle config option
|
|
|
|
*/
|
|
|
|
void config_resize_handle(bool resize_handle)
|
|
|
|
{
|
|
|
|
if (!_config_resize_handle && resize_handle)
|
|
|
|
append(&_sizer);
|
|
|
|
else if (_config_resize_handle && !resize_handle)
|
|
|
|
remove(&_sizer);
|
|
|
|
|
|
|
|
_config_resize_handle = resize_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the decoration config option
|
|
|
|
*/
|
|
|
|
void config_decoration(bool decoration)
|
|
|
|
{
|
|
|
|
_config_decoration = decoration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move window to new position
|
|
|
|
*/
|
2019-02-14 22:39:08 +01:00
|
|
|
void vpos(int x, int y) override
|
2013-05-22 19:21:29 +02:00
|
|
|
{
|
|
|
|
Window::vpos(x, y);
|
2013-12-30 01:21:53 +01:00
|
|
|
format(_size);
|
2013-05-22 19:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize the window according to the new content size
|
|
|
|
*/
|
|
|
|
void content_geometry(int x, int y, int w, int h)
|
|
|
|
{
|
2014-01-29 23:29:22 +01:00
|
|
|
if (_config_decoration) {
|
|
|
|
x -= 1; /* border */
|
|
|
|
y -= _TH; /* title bar */
|
|
|
|
}
|
2013-05-22 19:21:29 +02:00
|
|
|
Window::vpos(x, y);
|
2013-12-30 01:21:53 +01:00
|
|
|
format(Scout::Area(w + 2, h + 1 + _TH));
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Window interface
|
|
|
|
*/
|
2019-02-14 22:39:08 +01:00
|
|
|
void format(Scout::Area size) override
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2013-12-30 01:21:53 +01:00
|
|
|
using namespace Scout;
|
|
|
|
|
|
|
|
unsigned w = size.w();
|
|
|
|
unsigned h = size.h();
|
|
|
|
|
2013-05-22 19:21:29 +02:00
|
|
|
/* limit window size to valid values */
|
2013-12-30 01:21:53 +01:00
|
|
|
w = max(w, min_size().w());
|
|
|
|
h = max(h, min_size().h());
|
|
|
|
w = min(w, max_size().w());
|
|
|
|
h = min(h, max_size().h());
|
|
|
|
|
|
|
|
_size = Scout::Area(w, h);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-05-22 19:24:20 +02:00
|
|
|
int y = 0;
|
|
|
|
|
2014-01-29 23:29:22 +01:00
|
|
|
if (_config_decoration) {
|
|
|
|
_titlebar.format_fixed_width(w);
|
|
|
|
_titlebar.geometry(Rect(Point(1, y),
|
|
|
|
Area(_titlebar.min_size().w(),
|
|
|
|
_titlebar.min_size().h())));
|
|
|
|
y += _titlebar.min_size().h();
|
|
|
|
}
|
2013-05-22 19:24:20 +02:00
|
|
|
|
2013-12-30 01:21:53 +01:00
|
|
|
int const content_h = ((int)h > y + 1) ? (h - y - 1) : 0;
|
2014-01-29 23:29:22 +01:00
|
|
|
int const content_x = _config_decoration ? 1 : 0;
|
2013-05-22 19:24:20 +02:00
|
|
|
int const content_w = w - 2;
|
2014-01-29 23:29:22 +01:00
|
|
|
|
2013-12-30 01:21:53 +01:00
|
|
|
_content->format_fixed_size(Area(content_w, content_h));
|
2014-01-29 23:29:22 +01:00
|
|
|
_content->geometry(Rect(Point(content_x, y),
|
|
|
|
Area(content_w, content_h)));
|
2013-05-22 19:24:20 +02:00
|
|
|
|
2013-12-30 01:21:53 +01:00
|
|
|
_sizer.geometry(Rect(Point(_size.w() - 32, _size.h() - 32), Area(32, 32)));
|
2013-05-22 19:21:29 +02:00
|
|
|
|
|
|
|
if (_config_decoration)
|
2013-12-30 01:21:53 +01:00
|
|
|
Window::format(_size);
|
2013-05-22 19:21:29 +02:00
|
|
|
else
|
2013-12-30 01:21:53 +01:00
|
|
|
Window::format(Area(_size.w() - 2, _size.h() - 1 - _TH));
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure background texture offset (for background animation)
|
|
|
|
*/
|
|
|
|
void bg_offset(int bg_offset) { _bg_offset = bg_offset; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Element interface
|
|
|
|
*/
|
2019-02-14 22:39:08 +01:00
|
|
|
void draw(Scout::Canvas_base &canvas, Scout::Point abs_position) override
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2013-12-30 01:21:53 +01:00
|
|
|
using namespace Scout;
|
|
|
|
|
2013-05-22 19:24:20 +02:00
|
|
|
if (_config_alpha)
|
2013-12-30 01:21:53 +01:00
|
|
|
_bg_texture.draw(canvas, Point(0, - _bg_offset));
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-12-30 01:21:53 +01:00
|
|
|
Parent_element::draw(canvas, abs_position);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* border */
|
2013-12-30 01:21:53 +01:00
|
|
|
Color color(0, 0, 0);
|
|
|
|
canvas.draw_box(0, 0, _size.w(), 1, color);
|
2014-01-29 23:29:22 +01:00
|
|
|
if (_config_decoration)
|
|
|
|
canvas.draw_box(0, _TH, _size.w(), 1, color);
|
2013-12-30 01:21:53 +01:00
|
|
|
canvas.draw_box(0, _size.h() - 1, _size.w(), 1, color);
|
|
|
|
canvas.draw_box(0, 1, 1, _size.h() - 2, color);
|
|
|
|
canvas.draw_box(_size.w() - 1, 1, 1, _size.h() - 2, color);
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|