2013-12-28 21:29:30 +00:00
|
|
|
/*
|
|
|
|
* \brief Functor for drawing filled boxes into a surface
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-08-04
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
2013-12-28 21:29:30 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-12-28 21:29:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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);
|
Make util/geometry.h C++20 friendly
- 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
2024-06-05 10:40:13 +00:00
|
|
|
PT *dst, *dst_line = surface.addr() + surface.size().w*clipped.y1() + clipped.x1();
|
2013-12-28 21:29:30 +00:00
|
|
|
|
|
|
|
int const alpha = color.a;
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
if (color.opaque())
|
Make util/geometry.h C++20 friendly
- 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
2024-06-05 10:40:13 +00:00
|
|
|
for (unsigned w, h = clipped.h() ; h--; dst_line += surface.size().w)
|
2013-12-28 21:29:30 +00:00
|
|
|
for (dst = dst_line, w = clipped.w(); w--; dst++)
|
|
|
|
*dst = pix;
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
else if (!color.transparent())
|
Make util/geometry.h C++20 friendly
- 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
2024-06-05 10:40:13 +00:00
|
|
|
for (unsigned w, h = clipped.h() ; h--; dst_line += surface.size().w)
|
2013-12-28 21:29:30 +00:00
|
|
|
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_ */
|