roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
tile.cpp
Go to the documentation of this file.
1#include "tile.h"
2
6
7namespace roo_display {
8
9namespace internal {
10
11void TileBase::draw(const Surface& s, const Drawable& content) const {
12 if (background_ != nullptr) {
13 BackgroundFilter filter(s.out(), background_, s.dx(), s.dy());
14 Surface news(filter, s.dx(), s.dy(), s.clip_box(), s.is_write_once(),
15 color::Transparent, s.fill_mode(), s.blending_mode());
17 } else {
19 }
20}
21
22void TileBase::drawInternal(const Surface& s, const Drawable& content) const {
24 bgcolor_ == color::Transparent ? s.fill_mode() : FillMode::kExtents;
25 Box extents =
26 Box::Intersect(s.clip_box(), border_.extents().translate(s.dx(), s.dy()));
27 if (extents.empty()) return;
28 Color bgcolor = AlphaBlend(s.bgcolor(), bgcolor_);
29 Box interior = Box::Intersect(s.clip_box(),
30 border_.interior().translate(s.dx(), s.dy()));
31 if (interior.empty()) {
33 s.out().fillRect(
34 s.blending_mode(),
36 bgcolor);
37 }
38 return;
39 }
41 if (extents.yMin() < interior.yMin()) {
42 // Draw the top bg bar.
43 s.out().fillRect(s.blending_mode(),
45 interior.yMin() - 1),
46 bgcolor);
47 }
48 if (extents.xMin() < interior.xMin()) {
49 // Draw the left bg bar.
50 s.out().fillRect(s.blending_mode(),
51 Box(extents.xMin(), interior.yMin(), interior.xMin() - 1,
52 interior.yMax()),
53 bgcolor);
54 }
55 }
56 Surface inner(s.out(), s.dx() + border_.x_offset(),
57 s.dy() + border_.y_offset(), extents, s.is_write_once(),
58 bgcolor, fill_mode, s.blending_mode());
59 inner.drawObject(content);
61 if (extents.xMax() > interior.xMax()) {
62 // Draw the right bg bar.
63 s.out().fillRect(s.blending_mode(),
64 Box(interior.xMax() + 1, interior.yMin(), extents.xMax(),
65 interior.yMax()),
66 bgcolor);
67 }
68 if (extents.yMax() > interior.yMax()) {
69 // Draw the bottom bg bar.
70 s.out().fillRect(s.blending_mode(),
71 Box(extents.xMin(), interior.yMax() + 1, extents.xMax(),
72 extents.yMax()),
73 bgcolor);
74 }
75 }
76}
77
78} // namespace internal
79
80} // namespace roo_display
Axis-aligned integer rectangle.
Definition box.h:12
int16_t xMin() const
Minimum x (inclusive).
Definition box.h:65
int16_t xMax() const
Maximum x (inclusive).
Definition box.h:71
bool empty() const
Return whether the box is empty.
Definition box.h:62
Box translate(int16_t x_offset, int16_t y_offset) const
Return a translated copy of this box.
Definition box.h:127
int16_t yMax() const
Maximum y (inclusive).
Definition box.h:74
static Box Intersect(const Box &a, const Box &b)
Return the intersection of two boxes (may be empty).
Definition box.h:25
int16_t yMin() const
Minimum y (inclusive).
Definition box.h:68
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
Interface for objects that can be drawn to an output device.
Definition drawable.h:229
Low-level handle used to draw to an underlying device.
Definition drawable.h:60
const Box & interior() const
Definition tile.h:24
const Box & extents() const
Definition tile.h:21
void draw(const Surface &s, const Drawable &interior) const
Definition tile.cpp:11
void drawInternal(const Surface &s, const Drawable &interior) const
Definition tile.cpp:22
Box extents() const override
Return the bounding box encompassing all pixels that need to be drawn.
Definition tile.h:58
Defines 140 opaque HTML named colors.
Color AlphaBlend(Color bgc, Color fgc)
Definition blending.h:598
FillMode
Specifies whether a Drawable should fill its entire extents box, including fully transparent pixels.
Definition drawable.h:15
@ kExtents
Fill the entire extents box (possibly with fully transparent pixels).
Color bgcolor
Definition smooth.cpp:889
FillMode fill_mode
Definition smooth.cpp:887