mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-22 15:02:25 +00:00
c629c54153
- Move header to base/include to make it applicable for base types like 'Affinity' down the road. - Represent 'Rect' as typle of point and area, which is the most common form of initialization, creates in valid 'Rect' by default. - Turn Point, Area, and Rect into compound types, making x, y, w, h, at, area accessible without a method call - 'Rect::Compound' function for constructing a 'Rect' from two points, replacing a former constructor - Use result type 'Rect::Cut_remainder' instead of out parameters. Fixes #5239
59 lines
1.5 KiB
C++
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-2017 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
*/
|
|
|
|
#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.opaque())
|
|
for (unsigned w, h = clipped.h() ; h--; dst_line += surface.size().w)
|
|
for (dst = dst_line, w = clipped.w(); w--; dst++)
|
|
*dst = pix;
|
|
|
|
else if (!color.transparent())
|
|
for (unsigned 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_ */
|