TinyMaterialDesign
Loading...
Searching...
No Matches
OffsetSurface.h
Go to the documentation of this file.
1#pragma once
2#include <stdint.h>
3
4#include "TinyGPU/Surface/ISurface.h"
5#include "TinyGPU/Surface/SurfaceBase.h"
6
7namespace tinymd {
8
9/**
10 * @brief Draws into `target` moved up by `dy` pixels, only inside the rows
11 * [clipTop, clipBottom) of `target`.
12 *
13 * TinyGPU's drawing primitives take unsigned coordinates, and toPx() clamps
14 * negative values to 0: a widget whose top is above the edge of the surface
15 * (e.g. scrolled up in a Container) would be drawn at y = 0 with its full
16 * height instead of partly hidden. Container draws such a widget through an
17 * OffsetSurface: the widget is moved down by `dy` (so all its coordinates
18 * are >= 0) and every pixel is written `dy` rows higher, where it belongs.
19 * Pixel by pixel (via SurfaceBase), so only used for those widgets.
20 */
21template <typename RGB_T>
23 public:
24 OffsetSurface(tinygpu::ISurface<RGB_T>& target, int32_t dy, int32_t clipTop, int32_t clipBottom)
25 : tinygpu::SurfaceBase<RGB_T>(target.width(), target.height() + static_cast<size_t>(dy), target.font()),
27 dy_(dy),
30
31 void setPixel(size_t x, size_t y, RGB_T color) override {
32 const int32_t ty = static_cast<int32_t>(y) - dy_;
33 if (ty < clipTop_ || ty >= clipBottom_ || ty < 0 || x >= target_.width()) return;
34 target_.setPixel(x, static_cast<size_t>(ty), color);
35 }
36
37 RGB_T getPixel(size_t x, size_t y) const override {
38 const int32_t ty = static_cast<int32_t>(y) - dy_;
39 if (ty < 0 || static_cast<size_t>(ty) >= target_.height() || x >= target_.width()) return RGB_T();
40 return target_.getPixel(x, static_cast<size_t>(ty));
41 }
42
43 bool resizeBuffer(size_t, size_t) override { return true; }
44 const uint8_t* data() const override { return nullptr; }
45 size_t size() const override { return 0; }
46
47 private:
48 tinygpu::ISurface<RGB_T>& target_;
49 int32_t dy_;
50 int32_t clipTop_;
51 int32_t clipBottom_;
52};
53
54} // namespace tinymd
Draws into target moved up by dy pixels, only inside the rows [clipTop, clipBottom) of target.
Definition: OffsetSurface.h:22
OffsetSurface(tinygpu::ISurface< RGB_T > &target, int32_t dy, int32_t clipTop, int32_t clipBottom)
Definition: OffsetSurface.h:24
const uint8_t * data() const override
Definition: OffsetSurface.h:44
bool resizeBuffer(size_t, size_t) override
Definition: OffsetSurface.h:43
void setPixel(size_t x, size_t y, RGB_T color) override
Definition: OffsetSurface.h:31
size_t size() const override
Definition: OffsetSurface.h:45
RGB_T getPixel(size_t x, size_t y) const override
Definition: OffsetSurface.h:37
Definition: AnchorLayout.h:4