roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
rasterizable_stack.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
8
9namespace roo_display {
10
11/// Multi-layer stack of rasterizables composited in order.
13 public:
14 /// An input layer in the stack.
15 class Input {
16 public:
17 /// Create an input layer using the source extents.
19 : obj_(obj),
20 extents_(extents),
21 dx_(0),
22 dy_(0),
23 blending_mode_(BlendingMode::kSourceOver) {}
24
25 /// Create an input layer with an offset.
27 : obj_(obj),
28 extents_(extents.translate(dx, dy)),
29 dx_(dx),
30 dy_(dy),
31 blending_mode_(BlendingMode::kSourceOver) {}
32
33 /// Return extents in stack coordinates.
34 const Box& extents() const { return extents_; }
35
36 /// X offset applied to the input.
37 int16_t dx() const { return dx_; }
38 /// Y offset applied to the input.
39 int16_t dy() const { return dy_; }
40
41 /// Source rasterizable.
42 const Rasterizable* source() const { return obj_; }
43
44 /// Blending mode used for this input.
45 BlendingMode blending_mode() const { return blending_mode_; }
46
47 /// Set blending mode for this input.
49 blending_mode_ = mode;
50 return *this;
51 }
52
53 private:
54 const Rasterizable* obj_;
55 Box extents_; // After translation, i.e. in the stack coordinates.
56 int16_t dx_;
57 int16_t dy_;
58 BlendingMode blending_mode_;
59 };
60
61 /// Create a stack with the given extents.
63 : extents_(extents), anchor_extents_(extents) {}
64
65 /// Add an input using its full extents.
67 inputs_.emplace_back(input, input->extents());
68 return inputs_.back();
69 }
70
71 /// Add an input clipped to `clip_box`.
72 Input& addInput(const Rasterizable* input, Box clip_box) {
73 inputs_.emplace_back(input, Box::Intersect(input->extents(), clip_box));
74 return inputs_.back();
75 }
76
77 /// Add an input with an offset.
79 inputs_.emplace_back(input, input->extents(), dx, dy);
80 return inputs_.back();
81 }
82
83 /// Add an input with an offset and clip box.
85 uint16_t dy) {
86 inputs_.emplace_back(input, Box::Intersect(input->extents(), clip_box), dx,
87 dy);
88 return inputs_.back();
89 }
90
91 /// Return the overall extents of the stack.
92 Box extents() const override { return extents_; }
93
94 Box anchorExtents() const override { return anchor_extents_; }
95
96 /// Return minimal extents that fit all inputs without clipping.
98 if (inputs_.empty()) return Box(0, 0, -1, -1);
99 Box result = inputs_[0].extents();
100 for (size_t i = 1; i < inputs_.size(); i++) {
101 result = Box::Extent(result, inputs_[i].extents());
102 }
103 return result;
104 }
105
106 /// Set the stack extents.
107 void setExtents(const Box& extents) { extents_ = extents; }
108
109 /// Set anchor extents used for alignment.
111 anchor_extents_ = anchor_extents;
112 }
113
114 void readColors(const int16_t* x, const int16_t* y, uint32_t count,
115 Color* result) const override;
116
117 bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax,
118 Color* result) const override;
119
120 private:
121 Box extents_;
122 Box anchor_extents_;
123 std::vector<Input> inputs_;
124};
125
126} // namespace roo_display
Axis-aligned integer rectangle.
Definition box.h:12
static Box Extent(const Box &a, const Box &b)
Return the smallest box that contains both input boxes.
Definition box.h:34
static Box Intersect(const Box &a, const Box &b)
Return the intersection of two boxes (may be empty).
Definition box.h:25
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
int16_t dx() const
X offset applied to the input.
const Rasterizable * source() const
Source rasterizable.
int16_t dy() const
Y offset applied to the input.
BlendingMode blending_mode() const
Blending mode used for this input.
Input & withMode(BlendingMode mode)
Set blending mode for this input.
Input(const Rasterizable *obj, Box extents)
Create an input layer using the source extents.
const Box & extents() const
Return extents in stack coordinates.
Input(const Rasterizable *obj, Box extents, uint16_t dx, uint16_t dy)
Create an input layer with an offset.
Multi-layer stack of rasterizables composited in order.
RasterizableStack(const Box &extents)
Create a stack with the given extents.
Box extents() const override
Return the overall extents of the stack.
Input & addInput(const Rasterizable *input, Box clip_box)
Add an input clipped to clip_box.
Input & addInput(const Rasterizable *input)
Add an input using its full extents.
void readColors(const int16_t *x, const int16_t *y, uint32_t count, Color *result) const override
Read colors for the given points.
void setAnchorExtents(const Box &anchor_extents)
Set anchor extents used for alignment.
Input & addInput(const Rasterizable *input, uint16_t dx, uint16_t dy)
Add an input with an offset.
Box anchorExtents() const override
Return the bounds used for alignment.
Input & addInput(const Rasterizable *input, Box clip_box, uint16_t dx, uint16_t dy)
Add an input with an offset and clip box.
bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax, Color *result) const override
Read colors for a rectangle.
Box naturalExtents()
Return minimal extents that fit all inputs without clipping.
void setExtents(const Box &extents)
Set the stack extents.
Drawable that can provide a color for any point within its extents.
Defines 140 opaque HTML named colors.
BlendingMode
Porter-Duff style blending modes.
Definition blending.h:17
@ kSourceOver
Source is placed (alpha-blended) over the destination. This is the default blending mode.