genode/os/include/nitpicker_gfx/box_painter.h
Norman Feske 8c8d53777f Generalization of nitpicker's graphics backend
This patch re-arranges nitpicker's graphics backend in a more modular
and expandable way. Generalized versions of the 'Canvas',
'Chunky_canvas', and 'Pixel_*' classes have been moved to
'os/include/util/' and 'os/include/os'. The only remaining parts that
are specific to nitpicker's needs are a few drawing functions, each
located in a distinct header at 'os/include/nitpicker_gfx/'.
2014-01-27 18:54:06 +01:00

59 lines
1.5 KiB
C++

/*
* \brief Functor for drawing filled boxes into a surface
* \author Norman Feske
* \date 2006-08-04
*/
/*
* Copyright (C) 2006-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__NITPICKER_GFX__BOX_PAINTER_H_
#define _INCLUDE__NITPICKER_GFX__BOX_PAINTER_H_
#include <os/surface.h>
struct Box_painter
{
typedef Genode::Surface_base::Rect Rect;
/**
* Draw filled box
*
* \param rect position and size of box
* \param color drawing color
*/
template <typename PT>
static inline void paint(Genode::Surface<PT> &surface,
Rect rect,
Genode::Color color)
{
Rect clipped = Rect::intersect(surface.clip(), rect);
if (!clipped.valid()) return;
PT pix(color.r, color.g, color.b);
PT *dst, *dst_line = surface.addr() + surface.size().w()*clipped.y1() + clipped.x1();
int const alpha = color.a;
if (color.is_opaque())
for (int w, h = clipped.h() ; h--; dst_line += surface.size().w())
for (dst = dst_line, w = clipped.w(); w--; dst++)
*dst = pix;
else if (!color.is_transparent())
for (int w, h = clipped.h() ; h--; dst_line += surface.size().w())
for (dst = dst_line, w = clipped.w(); w--; dst++)
*dst = PT::mix(*dst, pix, alpha);
surface.flush_pixels(clipped);
}
};
#endif /* _INCLUDE__NITPICKER_GFX__BOX_PAINTER_H_ */