#include "Window.h" #include "functions.h" Window* Window::getFullWindow() { static Window win; return &win; } void Window::setPixel(uint8_t x, uint8_t y, CRGB* color) { if (x>=this->width || y>=this->height) return; leds[this->coordsToGlobalIndex(x, y)] = *color; } void Window::setPixelByIndex(uint16_t index, CRGB* color) { uint8_t x = index % this->width; uint8_t y = index / this->width; this->setPixel(x, y, color); } uint16_t Window::coordsToGlobalIndex(uint8_t x, uint8_t y) { return XYsafe(x + this->x, y+this->y); } uint16_t Window::localToGlobalIndex(uint16_t index) { uint8_t x = index % this->width; uint8_t y = index / this->width; return coordsToGlobalIndex(x, y); } void Window::clear() { CRGB black(0x000000); this->clear(&black); } void Window::clear(CRGB* color) { for(int x=0; xwidth; x++) for(int y=0; yheight; y++) this->setPixel(x, y, color); } void Window::drawChar(Font* font, uint8_t xPos, uint8_t yPos, const char c, CRGB* color, bool mask) { if (!font->isCharAllowed(c)) return; uint16_t position = font->getCharPosition(c); uint8_t* data = new uint8_t[font->width]; memcpy_P(data, font->data + (position*font->width), font->width); for(uint8_t y=0; yheight; y++) for(uint8_t x=0; xwidth; x++) { bool on = (data[x]>>(font->height - 1 - y) & 1) * 255; if (mask) on = !on; if (on) this->setPixel(x + xPos, y + yPos, color); } free(data); } void Window::addPixelColor(uint16_t index, CRGB* color) { leds[localToGlobalIndex(index)] += *color; } void Window::fadeToBlackBy(fract8 speed) { for (uint8_t x=0; xwidth; x++) for(uint8_t y=0; yheight; y++) { leds[coordsToGlobalIndex(x, y)].nscale8(255 - speed); } }