41 lines
976 B
C++
41 lines
976 B
C++
#include "./Surface.h"
|
|
#include "./Display.h"
|
|
#include <ArduinoLog.h>
|
|
|
|
Surface::Surface(Display* dpy, const VirtualCoordinates& start, const VirtualCoordinates& end)
|
|
: start(dpy->coordinateMapping()->virtualToPhysicalCoords(start)),
|
|
end(dpy->coordinateMapping()->virtualToPhysicalCoords(end)),
|
|
m_display(dpy)
|
|
{
|
|
}
|
|
|
|
Surface&
|
|
Surface::operator=(const CRGB& color)
|
|
{
|
|
paintWith([&](CRGB& pixel) {
|
|
pixel = color;
|
|
});
|
|
return *this;
|
|
}
|
|
|
|
Surface&
|
|
Surface::operator+=(const CRGB& color)
|
|
{
|
|
paintWith([&](CRGB& pixel) {
|
|
pixel += color;
|
|
});
|
|
return *this;
|
|
}
|
|
|
|
void
|
|
Surface::paintWith(std::function<void(CRGB&)> func)
|
|
{
|
|
//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);
|
|
func(m_display->pixelAt(PhysicalCoordinates{x, y}));
|
|
}
|
|
}
|
|
}
|