roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
tile.h
Go to the documentation of this file.
1#pragma once
2
8
9namespace roo_display {
10
11namespace internal {
12
14 public:
16 : extents_(std::move(extents)),
17 offset_(alignment.resolveOffset(extents_, anchorExtents)),
18 interior_(Box::Intersect(interior.translate(offset_.dx, offset_.dy),
19 extents_)) {}
20
21 const Box &extents() const { return extents_; }
22 int16_t x_offset() const { return offset_.dx; }
23 int16_t y_offset() const { return offset_.dy; }
24 const Box &interior() const { return interior_; }
25
26 private:
27 // Absolute extents, when the border is drawn at (0, 0).
28 Box extents_;
29
30 // Absolute offset by which the interior needs to be shifted in order to
31 // comply with requested alignment.
32 Offset offset_;
33
34 // Absolute coordinates of the (aligned) interior, when the border is drawn at
35 // (0, 0), truncated to the extents_.
36 Box interior_;
37};
38
39class TileBase : public Drawable {
40 public:
42 Color bgcolor = color::Background)
43 : border_(std::move(extents), interior.extents(),
44 interior.anchorExtents(), alignment),
45 bgcolor_(bgcolor),
46 background_(nullptr) {}
47
49 bgcolor_ = bgcolor;
50 background_ = nullptr;
51 }
52
54 bgcolor_ = color::Background;
55 background_ = background;
56 }
57
58 Box extents() const override { return border_.extents(); }
59
60 protected:
61 void draw(const Surface &s, const Drawable &interior) const;
62 void drawInternal(const Surface &s, const Drawable &interior) const;
63
64 private:
66 Color bgcolor_;
67 const Rasterizable *background_;
68};
69
70} // namespace internal
71
72/// Rectangular drawable with background and aligned interior.
73///
74/// Useful for UI widgets (icons, text boxes, etc.). Handles alignment and
75/// flicker-minimized redraws.
76///
77/// Alignment: the interior is positioned inside the tile using the alignment
78/// specification (horizontal and vertical anchors plus optional offsets).
79///
80/// Flickerless redraws: the tile is drawn as up to 5 non-overlapping sections
81/// (top, left, interior, right, bottom) to avoid double draws.
82///
83/// Semi-transparent backgrounds are supported. The tile background is
84/// alpha-blended over the draw-time background color.
85class Tile : public internal::TileBase {
86 public:
87 /// Create a tile with the specified interior, extents, and alignment.
89 Color bgcolor = color::Background)
90 : internal::TileBase(*interior, extents, alignment, bgcolor),
91 interior_(interior) {}
92
93 void drawTo(const Surface &s) const override {
94 TileBase::draw(s, *interior_);
95 }
96
97 private:
98 const Drawable *interior_;
99};
100
101/// Tile with embedded interior object.
102///
103/// Useful when returning a tile without keeping a separate interior object.
104template <typename DrawableType>
106 public:
107 /// Create a tile with embedded interior and alignment.
109 Color bgcolor = color::Background)
110 : internal::TileBase(interior, extents, alignment, bgcolor),
111 interior_(std::move(interior)) {}
112
113 void drawTo(const Surface &s) const override { TileBase::draw(s, interior_); }
114
115 private:
116 DrawableType interior_;
117};
118
119/// Convenience factory for a `TileOf`.
120template <typename DrawableType>
123 Color bgcolor = color::Background) {
124 return TileOf<DrawableType>(std::move(interior), std::move(extents),
126}
127
128} // namespace roo_display
Combines horizontal and vertical alignment.
Definition alignment.h:172
Axis-aligned integer rectangle.
Definition box.h:12
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
virtual Box anchorExtents() const
Return the bounds used for alignment.
Definition drawable.h:246
Drawable that can provide a color for any point within its extents.
Low-level handle used to draw to an underlying device.
Definition drawable.h:60
Tile with embedded interior object.
Definition tile.h:105
TileOf(DrawableType interior, Box extents, Alignment alignment, Color bgcolor=color::Background)
Create a tile with embedded interior and alignment.
Definition tile.h:108
void drawTo(const Surface &s) const override
Draw this object's content, respecting the fill mode.
Definition tile.h:113
Rectangular drawable with background and aligned interior.
Definition tile.h:85
Tile(const Drawable *interior, Box extents, Alignment alignment, Color bgcolor=color::Background)
Create a tile with the specified interior, extents, and alignment.
Definition tile.h:88
void drawTo(const Surface &s) const override
Draw this object's content, respecting the fill mode.
Definition tile.h:93
const Box & interior() const
Definition tile.h:24
SolidBorder(Box extents, Box interior, Box anchorExtents, Alignment alignment)
Definition tile.h:15
const Box & extents() const
Definition tile.h:21
void setBgColor(Color bgcolor)
Definition tile.h:48
void setBackground(const Rasterizable *background)
Definition tile.h:53
TileBase(const Drawable &interior, Box extents, Alignment alignment, Color bgcolor=color::Background)
Definition tile.h:41
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.
TileOf< DrawableType > MakeTileOf(DrawableType interior, Box extents, Alignment alignment=kNoAlign, Color bgcolor=color::Background)
Convenience factory for a TileOf.
Definition tile.h:121
static constexpr Alignment kNoAlign
Absolute alignment (no repositioning).
Definition alignment.h:211
Color bgcolor
Definition smooth.cpp:889