renderbug-cpp/lib/Figments/Display.h

57 lines
1.9 KiB
C
Raw Normal View History

2019-05-10 05:17:29 +00:00
#pragma once
2021-03-29 08:10:55 +00:00
#include <FastLED.h>
2019-05-10 05:17:29 +00:00
#include "Geometry.h"
struct CoordinateMapping {
virtual VirtualCoordinates physicalToVirtualCoords(const PhysicalCoordinates localCoords) const = 0;
virtual PhysicalCoordinates virtualToPhysicalCoords(const VirtualCoordinates virtualCoords) const = 0;
virtual int physicalCoordsToIndex(const PhysicalCoordinates localCoords) const = 0;
virtual unsigned int physicalPixelCount() const = 0;
};
struct LinearCoordinateMapping: CoordinateMapping {
unsigned int pixelCount = 1;
unsigned int startPixel = 0;
LinearCoordinateMapping() {}
LinearCoordinateMapping(unsigned int count, unsigned int start) : pixelCount(count), startPixel(start) {}
VirtualCoordinates physicalToVirtualCoords(const PhysicalCoordinates localCoords) const override {
return VirtualCoordinates{map8(localCoords.x, 0, pixelCount), 0};
2019-05-10 05:17:29 +00:00
}
PhysicalCoordinates virtualToPhysicalCoords(const VirtualCoordinates virtualCoords) const override {
2021-03-29 08:10:55 +00:00
return PhysicalCoordinates{scale8(pixelCount, virtualCoords.x), 0};
2019-05-10 05:17:29 +00:00
}
int physicalCoordsToIndex(const PhysicalCoordinates localCoords) const override {
return localCoords.x + startPixel;
}
unsigned int physicalPixelCount() const override {
2019-05-10 05:17:29 +00:00
return pixelCount;
}
};
class Display {
public:
2021-03-29 08:10:55 +00:00
Display(CRGB* pixels, int pixelCount, const CoordinateMapping* map)
2019-05-10 05:17:29 +00:00
: m_pixels(pixels), m_pixelCount(pixelCount), m_coordMap(map) {}
2021-03-29 08:10:55 +00:00
CRGB& pixelAt(const PhysicalCoordinates coords);
CRGB& pixelAt(const VirtualCoordinates coords);
CRGB& pixelAt(int idx);
2019-05-10 05:17:29 +00:00
int pixelCount() const;
2021-03-29 08:10:55 +00:00
CRGB* pixelBacking() const;
2019-05-10 05:17:29 +00:00
const CoordinateMapping* coordinateMapping() const;
void clear();
2021-03-29 08:10:55 +00:00
void clear(const CRGB& color);
void clear(VirtualCoordinates& start, VirtualCoordinates& end, const CRGB& color);
2019-05-10 05:17:29 +00:00
private:
2021-03-29 08:10:55 +00:00
CRGB* m_pixels;
2019-05-10 05:17:29 +00:00
int m_pixelCount;
const CoordinateMapping* m_coordMap;
};