renderbug/lib/Figments/Surface.cpp

41 lines
976 B
C++
Raw Normal View History

2019-05-10 05:17:29 +00:00
#include "./Surface.h"
#include "./Display.h"
2021-03-29 08:10:55 +00:00
#include <ArduinoLog.h>
2019-05-10 05:17:29 +00:00
Surface::Surface(Display* dpy, const VirtualCoordinates& start, const VirtualCoordinates& end)
: start(dpy->coordinateMapping()->virtualToPhysicalCoords(start)),
end(dpy->coordinateMapping()->virtualToPhysicalCoords(end)),
m_display(dpy)
{
}
Surface&
2021-03-29 08:10:55 +00:00
Surface::operator=(const CRGB& color)
2019-05-10 05:17:29 +00:00
{
2021-03-29 08:10:55 +00:00
paintWith([&](CRGB& pixel) {
2019-05-10 05:17:29 +00:00
pixel = color;
});
return *this;
}
Surface&
2021-03-29 08:10:55 +00:00
Surface::operator+=(const CRGB& color)
2019-05-10 05:17:29 +00:00
{
2021-03-29 08:10:55 +00:00
paintWith([&](CRGB& pixel) {
2019-05-10 05:17:29 +00:00
pixel += color;
});
return *this;
}
void
2021-03-29 08:10:55 +00:00
Surface::paintWith(std::function<void(CRGB&)> func)
2019-05-10 05:17:29 +00:00
{
2021-03-29 08:10:55 +00:00
//Log.verbose("Painting startx=%d endx=%d starty=%d endy=%d", start.x, end.x, start.y, end.y);
for(auto x = start.x; x <= end.x; x++) {
for(auto y = start.y; y <= end.y; y++) {
//Log.verbose("x=%d y=%d", x, y);
2019-05-10 05:17:29 +00:00
func(m_display->pixelAt(PhysicalCoordinates{x, y}));
}
}
}