diff --git a/examples/avr/display/dogm128/benchmark/main.cpp b/examples/avr/display/dogm128/benchmark/main.cpp index 1e1666a4e6..0c763947c4 100644 --- a/examples/avr/display/dogm128/benchmark/main.cpp +++ b/examples/avr/display/dogm128/benchmark/main.cpp @@ -161,7 +161,7 @@ main() while (!timer.execute()) { // rectangle in left side of screen - display.setColor(Color::black()); + // TODO display.setColor(Color::black()); display.drawRectangle(Point(0, 0), 62, 62); // rounded rectangle around text area @@ -176,14 +176,14 @@ main() display.drawCircle(Point(31, 31), 31); // clear previous spinner position - display.setColor(Color::white()); + // TODO display.setColor(Color::white()); display.fillRectangle(Point(87, 40), 16, 16); static uint8_t loops = 0; - display.setColor(Color::black()); + // TODO display.setColor(Color::black()); drawSpinner(Point(95, 48), loops++); - display.setColor(Color::white()); + // TODO display.setColor(Color::white()); display.setCursor(Point(25, 40)); display << ++iter; display.update(); @@ -192,7 +192,7 @@ main() // print number of iterations in one second display.clear(); display.setCursor(Point(80, 10)); - display.setColor(Color::white()); + // TODO display.setColor(Color::white()); display << "FPS=" << iter; } } diff --git a/examples/avr/display/dogm128/draw/main.cpp b/examples/avr/display/dogm128/draw/main.cpp index e3df5d7eaa..236e4ae748 100644 --- a/examples/avr/display/dogm128/draw/main.cpp +++ b/examples/avr/display/dogm128/draw/main.cpp @@ -71,11 +71,11 @@ main() display.fillRectangle(Point(10, 10), 20, 20); display.fillCircle(Point(45, 40), 23); - display.setColor(Color::white()); + // TODO display.setColor(Color::white()); display.fillRectangle(Point(20, 20), 20, 20); display.fillCircle(Point(55, 50), 8); - display.setColor(Color::black()); + // TODO display.setColor(Color::black()); display.drawLine(Point(0, 0), Point(127, 63)); display.update(); diff --git a/examples/avr/display/dogm128/touch/main.cpp b/examples/avr/display/dogm128/touch/main.cpp index 334c3815ed..c9739f6a09 100644 --- a/examples/avr/display/dogm128/touch/main.cpp +++ b/examples/avr/display/dogm128/touch/main.cpp @@ -53,11 +53,11 @@ modm::DogM128< lcd::SPI, lcd::Cs, lcd::A0, lcd::Reset, true > display; void drawCross(uint8_t x, uint8_t y) { - display.drawPixel(x - 1, y - 1); - display.drawPixel(x - 1, y + 1); - display.drawPixel(x, y); - display.drawPixel(x + 1, y - 1); - display.drawPixel(x + 1, y + 1); + display.setPixel(x - 1, y - 1); + display.setPixel(x - 1, y + 1); + display.setPixel(x, y); + display.setPixel(x + 1, y - 1); + display.setPixel(x + 1, y + 1); } int @@ -152,11 +152,11 @@ main() if (x >= 0 && y >= 0) { - display.drawPixel(x, y); - display.drawPixel(x, y+1); + display.setPixel(x, y); + display.setPixel(x, y+1); - display.drawPixel(x+1, y); - display.drawPixel(x+1, y+1); + display.setPixel(x+1, y); + display.setPixel(x+1, y+1); } display.update(); diff --git a/examples/stm32_f4ve/gui/main.cpp b/examples/stm32_f4ve/gui/main.cpp index f0e9a1c09a..45552f287c 100644 --- a/examples/stm32_f4ve/gui/main.cpp +++ b/examples/stm32_f4ve/gui/main.cpp @@ -140,7 +140,7 @@ initDisplay() tft.initialize(); tft.enableBacklight(true); - tft.setRotation(Display::Rotation::Rotate90); + tft.setOrientation(modm::glcd::Orientation::Portrait90); } @@ -164,7 +164,7 @@ initTouchscreen() // ---------------------------------------------------------------------------- /* screen calibration */ static void -drawCross(modm::GraphicDisplay& display, modm::glcd::Point center) +drawCross(modm::ColorGraphicDisplay& display, modm::glcd::Point center) { display.setColor(modm::glcd::Color::red()); display.drawLine(center.x - 15, center.y, center.x - 2, center.y); @@ -187,7 +187,7 @@ drawCross(modm::GraphicDisplay& display, modm::glcd::Point center) } static void -calibrateTouchscreen(modm::GraphicDisplay& display, modm::glcd::Point *fixed_samples = NULL) +calibrateTouchscreen(modm::ColorGraphicDisplay& display, modm::glcd::Point *fixed_samples = nullptr) { MODM_LOG_DEBUG << __PRETTY_FUNCTION__ << modm::endl; modm::glcd::Point calibrationPoint[3] = { { 45, 45 }, { 270, 90 }, { 100, 190 } }; @@ -229,10 +229,10 @@ drawPoint(modm::GraphicDisplay& display, modm::glcd::Point point) return; } - display.drawPixel(point.x, point.y); - display.drawPixel(point.x + 1, point.y); - display.drawPixel(point.x, point.y + 1); - display.drawPixel(point.x + 1, point.y + 1); + display.setPixel(point.x, point.y); + display.setPixel(point.x + 1, point.y); + display.setPixel(point.x, point.y + 1); + display.setPixel(point.x + 1, point.y + 1); } // ---------------------------------------------------------------------------- diff --git a/examples/stm32f469_discovery/display/main.cpp b/examples/stm32f469_discovery/display/main.cpp index d96ec1f57a..12c4eeebcd 100644 --- a/examples/stm32f469_discovery/display/main.cpp +++ b/examples/stm32f469_discovery/display/main.cpp @@ -20,7 +20,7 @@ main() Board::initialize(); Board::initializeDisplay(); - modm::GraphicDisplay& display = Board::getDisplay(); + modm::ColorGraphicDisplay& display = Board::getDisplay(); display.setFont(modm::font::Assertion); display.drawRectangle(0,0, 10, 10); diff --git a/examples/stm32f469_discovery/game_of_life/main.cpp b/examples/stm32f469_discovery/game_of_life/main.cpp index b8e01feef6..2c1dc59b72 100644 --- a/examples/stm32f469_discovery/game_of_life/main.cpp +++ b/examples/stm32f469_discovery/game_of_life/main.cpp @@ -135,7 +135,7 @@ static inline void touch(framebuffer_t buffer) } } -static inline void drawPixel(int x, int y, uint8_t color) +static inline void setPixel(int x, int y, uint8_t color) { #define DRAW(x, y) displayBuffer[(y) * 800 + (x)] = GET_TRAIL_COLOR(color).getValue(); #if SCALE >= 8 @@ -202,7 +202,7 @@ static inline void drawPixel(int x, int y, uint8_t color) static inline void drawScreen(framebuffer_t before, framebuffer_t next) { for_yx(bw, bh) { - drawPixel(x*SCALE + SCALE/2, y*SCALE + SCALE/2, next[y][x]); + setPixel(x*SCALE + SCALE/2, y*SCALE + SCALE/2, next[y][x]); before[y][x] = next[y][x]; } diff --git a/examples/stm32f469_discovery/touchscreen/main.cpp b/examples/stm32f469_discovery/touchscreen/main.cpp index e792066904..b83fbb4bc4 100644 --- a/examples/stm32f469_discovery/touchscreen/main.cpp +++ b/examples/stm32f469_discovery/touchscreen/main.cpp @@ -84,7 +84,7 @@ class LineDrawer : public modm::pt::Protothread private: Touch::Data touchData; Touch touch; - modm::GraphicDisplay& display; + modm::ColorGraphicDisplay& display; int16_t px[2], py[2]; Color c[2]; }; diff --git a/examples/stm32f4_discovery/open407v-d/gui/main.cpp b/examples/stm32f4_discovery/open407v-d/gui/main.cpp index 7ade2fade2..51229d694b 100644 --- a/examples/stm32f4_discovery/open407v-d/gui/main.cpp +++ b/examples/stm32f4_discovery/open407v-d/gui/main.cpp @@ -173,7 +173,7 @@ initTouchscreen() // ---------------------------------------------------------------------------- /* screen calibration */ static void -drawCross(modm::GraphicDisplay& display, modm::glcd::Point center) +drawCross(modm::ColorGraphicDisplay& display, modm::glcd::Point center) { display.setColor(modm::glcd::Color::red()); display.drawLine(center.x - 15, center.y, center.x - 2, center.y); @@ -196,7 +196,7 @@ drawCross(modm::GraphicDisplay& display, modm::glcd::Point center) } static void -calibrateTouchscreen(modm::GraphicDisplay& display, modm::glcd::Point *fixed_samples = NULL) +calibrateTouchscreen(modm::ColorGraphicDisplay& display, modm::glcd::Point *fixed_samples = NULL) { modm::glcd::Point calibrationPoint[3] = { { 45, 45 }, { 270, 90 }, { 100, 190 } }; modm::glcd::Point sample[3]; @@ -236,10 +236,10 @@ drawPoint(modm::GraphicDisplay& display, modm::glcd::Point point) return; } - display.drawPixel(point.x, point.y); - display.drawPixel(point.x + 1, point.y); - display.drawPixel(point.x, point.y + 1); - display.drawPixel(point.x + 1, point.y + 1); + display.setPixel(point.x, point.y); + display.setPixel(point.x + 1, point.y); + display.setPixel(point.x, point.y + 1); + display.setPixel(point.x + 1, point.y + 1); } // ---------------------------------------------------------------------------- diff --git a/examples/stm32f4_discovery/open407v-d/touchscreen/main.cpp b/examples/stm32f4_discovery/open407v-d/touchscreen/main.cpp index 5a804b30fc..a8f21388c0 100644 --- a/examples/stm32f4_discovery/open407v-d/touchscreen/main.cpp +++ b/examples/stm32f4_discovery/open407v-d/touchscreen/main.cpp @@ -130,7 +130,7 @@ initTouchscreen() // ---------------------------------------------------------------------------- static void -drawCross(modm::GraphicDisplay& display, modm::glcd::Point center) +drawCross(modm::ColorGraphicDisplay& display, modm::glcd::Point center) { display.setColor(modm::glcd::Color::red()); display.drawLine(center.x - 15, center.y, center.x - 2, center.y); @@ -153,7 +153,7 @@ drawCross(modm::GraphicDisplay& display, modm::glcd::Point center) } static void -calibrateTouchscreen(modm::GraphicDisplay& display) +calibrateTouchscreen(modm::ColorGraphicDisplay& display) { modm::glcd::Point calibrationPoint[3] = { { 45, 45 }, { 270, 90 }, { 100, 190 } }; modm::glcd::Point sample[3]; @@ -186,10 +186,10 @@ drawPoint(modm::GraphicDisplay& display, modm::glcd::Point point) return; } - display.drawPixel(point.x, point.y); - display.drawPixel(point.x + 1, point.y); - display.drawPixel(point.x, point.y + 1); - display.drawPixel(point.x + 1, point.y + 1); + display.setPixel(point.x, point.y); + display.setPixel(point.x + 1, point.y); + display.setPixel(point.x, point.y + 1); + display.setPixel(point.x + 1, point.y + 1); } // ---------------------------------------------------------------------------- diff --git a/src/modm/board/disco_f469ni/board.hpp b/src/modm/board/disco_f469ni/board.hpp index 47dd89b8f2..008663aa19 100644 --- a/src/modm/board/disco_f469ni/board.hpp +++ b/src/modm/board/disco_f469ni/board.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -209,7 +209,7 @@ setDisplayBuffer(void * buffer); void * getDisplayBuffer(); -modm::GraphicDisplay& +modm::ColorGraphicDisplay& getDisplay(); inline void diff --git a/src/modm/board/disco_f469ni/board_display.cpp b/src/modm/board/disco_f469ni/board_display.cpp index d446651e23..ed7105cf0f 100644 --- a/src/modm/board/disco_f469ni/board_display.cpp +++ b/src/modm/board/disco_f469ni/board_display.cpp @@ -12,11 +12,13 @@ #include "board.hpp" #include +#include + extern void board_initialize_display(uint8_t); // Basic implementation of display running on memory mapped buffer -class DsiDisplay : public modm::GraphicDisplay +class DsiDisplay : public modm::ColorGraphicDisplay { public: DsiDisplay() : buffer(new (modm::MemoryExternal) uint16_t[800*480]) @@ -32,40 +34,49 @@ class DsiDisplay : public modm::GraphicDisplay getHeight() const override { return 480; } + inline std::size_t + getBufferWidth() const final + { + return 800; + } + + inline std::size_t + getBufferHeight() const final + { + return 480; + } + void - clear() override + clear() final { - for (int ii = 0; ii < 800*480; ii++) - { - buffer[ii] = this->backgroundColor.getValue(); - } + std::fill(buffer, buffer + this->getBufferWidth()*this->getBufferHeight(), this->backgroundColor.getValue()); } void - update() override + update() final { // FIXME: avoid tearing by using double buffering! } void - setPixel(int16_t x, int16_t y) override + setPixel(int16_t x, int16_t y) final { if (x < 0 or 800 <= x or y < 0 or 480 <= y) return; buffer[y * 800 + x] = this->foregroundColor.getValue(); } void - clearPixel(int16_t x, int16_t y) override + clearPixel(int16_t x, int16_t y) final { if (x < 0 or 800 <= x or y < 0 or 480 <= y) return; buffer[y * 800 + x] = this->backgroundColor.getValue(); } - bool - getPixel(int16_t x, int16_t y) override + modm::glcd::Color + getPixel(int16_t x, int16_t y) const final { if (x < 0 or 800 <= x or y < 0 or 480 <= y) return false; - return (buffer[y * 800 + x] != this->backgroundColor.getValue()); + return buffer[y * 800 + x]; } protected: @@ -97,7 +108,7 @@ Board::getDisplayBuffer() return (void *) LTDC_Layer1->CFBAR; } -modm::GraphicDisplay& +modm::ColorGraphicDisplay& Board::getDisplay() { static DsiDisplay display; diff --git a/src/modm/driver/display/hd44780.hpp b/src/modm/driver/display/hd44780.hpp index 22007c5c03..7f4ea1dfaf 100644 --- a/src/modm/driver/display/hd44780.hpp +++ b/src/modm/driver/display/hd44780.hpp @@ -69,7 +69,7 @@ class Hd44780 : public CharacterDisplay clear(); protected: - typedef Hd44780Base driver; + using driver = Hd44780Base; public: /** @@ -129,8 +129,8 @@ class Hd44780Dual : public CharacterDisplay clear(); protected: - typedef Hd44780Base driver1; - typedef Hd44780Base driver2; + using driver1 = Hd44780Base; + using driver2 = Hd44780Base; }; } // namespace modm diff --git a/src/modm/driver/display/hd44780_base_impl.hpp b/src/modm/driver/display/hd44780_base_impl.hpp index 4d1035ccd3..623527056f 100644 --- a/src/modm/driver/display/hd44780_base_impl.hpp +++ b/src/modm/driver/display/hd44780_base_impl.hpp @@ -45,7 +45,7 @@ modm::Hd44780Base::initialize(LineMode lineMode) Bus::writeHighNibble(Set4BitBus); } - while(!writeCommand(static_cast(lineMode) | + while(!writeCommand(InternalCommand(lineMode) | Bus::Mode)) ; while(!writeCommand(DisableDisplay)) diff --git a/src/modm/driver/display/hd44780_impl.hpp b/src/modm/driver/display/hd44780_impl.hpp index 97632929f7..dc03af3dfb 100644 --- a/src/modm/driver/display/hd44780_impl.hpp +++ b/src/modm/driver/display/hd44780_impl.hpp @@ -35,7 +35,7 @@ template void modm::Hd44780::writeRaw(char c) { - while(!driver::writeRAM(static_cast(c))) + while(!driver::writeRAM(uint8_t(c))) ; } @@ -48,7 +48,7 @@ modm::Hd44780::setCursor(uint8_t column, uint8_t line) uint8_t address = this->column + 0x40 * this->line; if (this->line >= 2) { - address += 20; + address += this->lineWidth; } while(!driver::writeAddress(address)) ; @@ -105,10 +105,10 @@ void modm::Hd44780Dual::writeRaw(char c) { if (this->line < 2) { - while(!driver1::writeRAM(static_cast(c))) + while(!driver1::writeRAM(uint8_t(c))) ; } else { - while(!driver2::writeRAM(static_cast(c))) + while(!driver2::writeRAM(uint8_t(c))) ; } } diff --git a/src/modm/driver/display/ili9341.hpp b/src/modm/driver/display/ili9341.hpp index 7267a4c9ee..0fb75fc1e2 100644 --- a/src/modm/driver/display/ili9341.hpp +++ b/src/modm/driver/display/ili9341.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace modm { @@ -129,17 +129,6 @@ struct ili9341 /// @endcond public: - enum class - Rotation : uint8_t - { - Rotate0, - Rotate90, - Rotate180, - Rotate270, - Normal = Rotate0, - UpsideDown = Rotate180, - }; - enum class DisplayMode : uint8_t { @@ -150,7 +139,7 @@ struct ili9341 /// @ingroup modm_driver_ili9341 template -class Ili9341 : public Interface, public modm::GraphicDisplay +class Ili9341 : public Interface, public modm::ColorGraphicDisplay { static_assert(BufferSize >= 16, "at least a small buffer is required"); @@ -159,18 +148,11 @@ class Ili9341 : public Interface, public modm::GraphicDisplay using BatchHandle = typename Interface::BatchHandle; using Command = ili9341::Command; public: - using Rotation = ili9341::Rotation; + using Orientation = glcd::Orientation; using DisplayMode = ili9341::DisplayMode; - template, std::enable_if_t = 0> - Ili9341(): Interface() - { - Reset::setOutput(modm::Gpio::High); - Backlight::setOutput(modm::Gpio::Low); - } - - template, T>> - Ili9341(T& r): Interface(r) + template + Ili9341(Args&&... args): Interface(std::forward(args)...) { Reset::setOutput(modm::Gpio::High); Backlight::setOutput(modm::Gpio::Low); @@ -187,58 +169,94 @@ class Ili9341 : public Interface, public modm::GraphicDisplay void turnOn(); + void turnOff(); void enableBacklight(bool enable) { Backlight::set(enable); } + void setBrightness(uint8_t level); + void setInvert(bool invert); void setIdle(bool enable); + void enableSleep(bool enable); - virtual uint16_t - getWidth() const override + uint16_t + getWidth() const final { - switch (rotation_) + switch (orientation) { - case Rotation::Rotate90: - case Rotation::Rotate270: + case Orientation::Portrait90: + case Orientation::Portrait270: return Height; default: return Width; } } - virtual uint16_t - getHeight() const override + + uint16_t + getHeight() const final { - switch (rotation_) + switch (orientation) { - case Rotation::Rotate90: - case Rotation::Rotate270: + case Orientation::Portrait90: + case Orientation::Portrait270: return Width; default: return Height; } } - virtual void - clear() override; - virtual void - update() override - { /* nothing to do, data is directly written to TFT RAM */ } + inline std::size_t + getBufferWidth() const final + { + return Width; + } + + inline std::size_t + getBufferHeight() const final + { + return Height; + } + + void + setPixel(int16_t x, int16_t y) final + { setColoredPixel(x, y, foregroundColor); } void - setRotation(Rotation rotation); + clearPixel(int16_t x, int16_t y) final + { setColoredPixel(x, y, backgroundColor); } + + // TODO implement getPixel for ili9341 + glcd::Color + getPixel(int16_t x, int16_t y) const final + { + (void) x; + (void) y; + return glcd::Color::white(); + } + + void + clear() final; + + inline void + update() final + { /* nothing to do, data is directly written to TFT RAM */ } + + inline void + setOrientation(glcd::Orientation orientation); void fillRectangle(glcd::Point upperLeft, uint16_t width, uint16_t height); + inline void fillRectangle(int16_t x, int16_t y, uint16_t width, uint16_t height) { fillRectangle(glcd::Point(x, y), width, height); } @@ -246,16 +264,17 @@ class Ili9341 : public Interface, public modm::GraphicDisplay void fillCircle(glcd::Point center, uint16_t radius); - virtual void + void drawImageRaw(glcd::Point upperLeft, uint16_t width, uint16_t height, - modm::accessor::Flash data) override; + modm::accessor::Flash data) final; - virtual void + void drawRaw(glcd::Point upperLeft, uint16_t width, uint16_t height, glcd::Color* data); void setScrollArea(uint16_t topFixedRows, uint16_t bottomFixedRows, uint16_t firstRow); + void scrollTo(uint16_t row); @@ -263,28 +282,21 @@ class Ili9341 : public Interface, public modm::GraphicDisplay drawBitmap(glcd::Point upperLeft, uint16_t width, uint16_t height, modm::accessor::Flash data); protected: - virtual void - setPixel(int16_t x, int16_t y) override - { setColoredPixel(x, y, foregroundColor); } - virtual void - clearPixel(int16_t x, int16_t y) override - { setColoredPixel(x, y, backgroundColor); } - virtual bool - getPixel(int16_t /*x*/, int16_t /*y*/) override - { return false; } + void + drawHorizontalLine(glcd::Point start, uint16_t length) final; - virtual void - drawHorizontalLine(glcd::Point start, uint16_t length) override; - virtual void - drawVerticalLine(glcd::Point start, uint16_t length) override; + void + drawVerticalLine(glcd::Point start, uint16_t length) final; private: void setColoredPixel(int16_t x, int16_t y, glcd::Color const &color); + void setClipping(uint16_t x, uint16_t y, uint16_t width, uint16_t height); - Rotation rotation_{Rotation::Rotate0}; + Orientation orientation{Orientation::Landscape0}; + uint8_t buffer[BufferSize * 2]{0}; }; diff --git a/src/modm/driver/display/ili9341_impl.hpp b/src/modm/driver/display/ili9341_impl.hpp index e01fe65b62..f6e9ca2cf0 100644 --- a/src/modm/driver/display/ili9341_impl.hpp +++ b/src/modm/driver/display/ili9341_impl.hpp @@ -74,7 +74,7 @@ Ili9341::initialize() this->writeCommand(Command::InversionOff); this->writeCommand(Command::DisplayOn); - setRotation(rotation_); + setOrientation(orientation); } } @@ -110,22 +110,22 @@ Ili9341::getIcModel() } template -void -Ili9341::setRotation(Rotation rotation) +inline void +Ili9341::setOrientation(glcd::Orientation orientation) { using MemoryAccessCtrl_t = ili9341::MemoryAccessCtrl_t; using MemoryAccessCtrl = ili9341::MemoryAccessCtrl; MemoryAccessCtrl_t madCtrl { MemoryAccessCtrl::BGR }; - switch (rotation) + switch (orientation) { - case Rotation::Rotate90: + case glcd::Orientation::Portrait90: madCtrl |= MemoryAccessCtrl::MV | MemoryAccessCtrl::MX; break; - case Rotation::Rotate180: + case glcd::Orientation::Landscape180: madCtrl |= MemoryAccessCtrl::MX | MemoryAccessCtrl::MY; break; - case Rotation::Rotate270: + case glcd::Orientation::Portrait270: madCtrl |= MemoryAccessCtrl::MV | MemoryAccessCtrl::MY; break; default: @@ -133,7 +133,7 @@ Ili9341::setRotation(Rotation rotation) break; } - rotation_ = rotation; + this->orientation = orientation; BatchHandle h(*this); this->writeCommandValue8(Command::MemoryAccessCtrl, madCtrl.value); diff --git a/src/modm/driver/display/ks0108.hpp b/src/modm/driver/display/ks0108.hpp index c43f74440d..cf0cc3e2b2 100644 --- a/src/modm/driver/display/ks0108.hpp +++ b/src/modm/driver/display/ks0108.hpp @@ -15,7 +15,7 @@ #define MODM_KS0108_HPP #include -#include +#include namespace modm { @@ -40,7 +40,7 @@ namespace modm */ template < typename E, typename RW, typename RS, typename PIN_CS1, typename PIN_CS2, typename PORT > - class Ks0108 : public MonochromeGraphicDisplayBufferedVertical<128, 64> + class Ks0108 : public MonochromeGraphicDisplayVertical<128, 64> { public: /** diff --git a/src/modm/driver/display/ks0108_impl.hpp b/src/modm/driver/display/ks0108_impl.hpp index ce3932a69f..11e6393164 100644 --- a/src/modm/driver/display/ks0108_impl.hpp +++ b/src/modm/driver/display/ks0108_impl.hpp @@ -105,11 +105,11 @@ modm::Ks0108::update() { this->selectLeftChip(); this->waitBusy(); - this->writeData(this->display_buffer[i][page]); + this->writeData(this->buffer[i][page]); this->selectRightChip(); this->waitBusy(); - this->writeData(this->display_buffer[i + 64][page]); + this->writeData(this->buffer[i + 64][page]); } } } diff --git a/src/modm/driver/display/max7219.hpp b/src/modm/driver/display/max7219.hpp index dfefb3c2cd..5aa64ed2bb 100644 --- a/src/modm/driver/display/max7219.hpp +++ b/src/modm/driver/display/max7219.hpp @@ -127,7 +127,7 @@ class Max7219 // Write the command multiple times, for each MODULES for (uint8_t i = 0; i < MODULES; ++i) { - SPI::transferBlocking(static_cast(reg)); + SPI::transferBlocking(uint8_t(reg)); SPI::transferBlocking(data); } CS::set(); diff --git a/src/modm/driver/display/max7219_matrix.hpp b/src/modm/driver/display/max7219_matrix.hpp index ba460bb084..456ad44f0b 100644 --- a/src/modm/driver/display/max7219_matrix.hpp +++ b/src/modm/driver/display/max7219_matrix.hpp @@ -15,7 +15,7 @@ #include "max7219.hpp" -#include +#include namespace modm { @@ -50,7 +50,7 @@ namespace modm * @ingroup modm_driver_max7219 */ template -class Max7219Matrix : public MonochromeGraphicDisplayBufferedVertical<8 * COLUMNS, 8 * ROWS> +class Max7219Matrix : public MonochromeGraphicDisplayVertical<8 * COLUMNS, 8 * ROWS> { public: virtual ~Max7219Matrix() = default; @@ -105,7 +105,7 @@ modm::Max7219Matrix::update() // a group of eight pixels vertical for (uint8_t row = 0; row < ROWS; ++row) { - buf[idx] = this->display_buffer[col * 8 + ledCol][row]; + buf[idx] = this->buffer[col * 8 + ledCol][row]; ++idx; } } diff --git a/src/modm/driver/display/max7219_matrix_horizontal.hpp b/src/modm/driver/display/max7219_matrix_horizontal.hpp index 1effcffed4..6a8de4ddd4 100644 --- a/src/modm/driver/display/max7219_matrix_horizontal.hpp +++ b/src/modm/driver/display/max7219_matrix_horizontal.hpp @@ -12,7 +12,7 @@ #define MODM_MAX7219_MATRIX_HORIZONTAL_HPP #include -#include +#include namespace modm { @@ -45,7 +45,7 @@ namespace modm */ template class Max7219MatrixHorizontal - : public MonochromeGraphicDisplayBufferedHorizontal<8 * COLUMNS, 8 * ROWS> + : public MonochromeGraphicDisplayHorizontal<8 * COLUMNS, 8 * ROWS> { public: virtual ~Max7219MatrixHorizontal() = default; @@ -95,7 +95,7 @@ Max7219MatrixHorizontal::update() // a group of eight pixels horizontal for (uint8_t col = 0; col < COLUMNS; ++col) { - buf[--idx] = this->mDisplayBuffer[row * 8 + ledCol][col]; + buf[--idx] = this->buffer[row * 8 + ledCol][col]; } } diff --git a/src/modm/driver/display/nokia5110.hpp b/src/modm/driver/display/nokia5110.hpp index 6c880634c1..2b9cd6ab11 100644 --- a/src/modm/driver/display/nokia5110.hpp +++ b/src/modm/driver/display/nokia5110.hpp @@ -12,7 +12,7 @@ #ifndef MODM_NOKIA5110_HPP #define MODM_NOKIA5110_HPP -#include +#include namespace modm { @@ -28,7 +28,7 @@ namespace modm * \ingroup modm_driver_nokia5110 */ template < typename Spi, typename Ce, typename Dc, typename Reset > -class Nokia5110 : public MonochromeGraphicDisplayBufferedVertical< 84, 48 > +class Nokia5110 : public MonochromeGraphicDisplayVertical< 84, 48 > { public: void diff --git a/src/modm/driver/display/nokia5110_impl.hpp b/src/modm/driver/display/nokia5110_impl.hpp index e53de1bd21..8622ff9875 100644 --- a/src/modm/driver/display/nokia5110_impl.hpp +++ b/src/modm/driver/display/nokia5110_impl.hpp @@ -29,7 +29,7 @@ Nokia5110< Spi, Ce, Dc, Reset >::initialize() writeCommand(0xc2); // Set Vop // Basic instruction set, vertical addressing - // Matches well with modm's BufferedGraphicDisplay memory layout + // Matches well with modm's GraphicDisplay memory layout writeCommand(0x20 | (1 << 1)); // writeCommand(0x08); // display blank @@ -50,7 +50,7 @@ Nokia5110< Spi, Ce, Dc, Reset >::update() Dc::set(); // high = data for (uint8_t xx = 0; xx < this->getWidth(); ++xx) { for (uint8_t yy = 0; yy < this->getHeight() / 8; ++yy) { - Spi::transferBlocking(this->display_buffer[xx][yy]); + Spi::transferBlocking(this->buffer[xx][yy]); } } Ce::set(); diff --git a/src/modm/driver/display/nokia6610.hpp b/src/modm/driver/display/nokia6610.hpp index dd6758b2e2..0ec027eef0 100644 --- a/src/modm/driver/display/nokia6610.hpp +++ b/src/modm/driver/display/nokia6610.hpp @@ -16,7 +16,7 @@ #define MODM_NOKIA6610_HPP #include -#include +#include namespace modm { @@ -33,7 +33,7 @@ namespace modm * \ingroup modm_driver_nokia6610 */ template - class Nokia6610 : public MonochromeGraphicDisplayBufferedVertical<130, 128> + class Nokia6610 : public MonochromeGraphicDisplayVertical<130, 128> { public: void diff --git a/src/modm/driver/display/nokia6610_impl.hpp b/src/modm/driver/display/nokia6610_impl.hpp index d0d886e169..fa10b7bdf9 100644 --- a/src/modm/driver/display/nokia6610_impl.hpp +++ b/src/modm/driver/display/nokia6610_impl.hpp @@ -153,7 +153,7 @@ modm::Nokia6610::lcdSettings() // Page Address set writeSpiCommand(nokia::NOKIA_GE8_PASET); writeSpiData(2); // start at 2 others corrupt display settings in a unpredictable way - writeSpiData(2 + this->getHeight()-1 + 2); // 2 more for filling, but not handled by buffered display + writeSpiData(2 + this->getHeight()-1 + 2); // 2 more for filling, but not handled by display // Page Column set writeSpiCommand(nokia::NOKIA_GE8_CASET); @@ -197,7 +197,7 @@ modm::Nokia6610::update() for(uint8_t x = 0; x < this->getWidth(); ++x) { for(uint8_t y = 0; y < this->getHeight()/8; ++y) { - uint8_t group = this->display_buffer[x][y]; + uint8_t group = this->buffer[x][y]; for (uint8_t pix = 0; pix < 8; pix+=2, group>>=2){ uint32_t data = ((group&1)?mask1Filled:mask1Blank)| @@ -208,7 +208,7 @@ modm::Nokia6610::update() writeSpiData(data); } } - // fill pixel not handled by buffered display + // fill pixel not handled by display uint32_t data = mask1Blank | mask2Blank; writeSpiData(data>>16); writeSpiData(data>>8); diff --git a/src/modm/driver/display/parallel_tft.hpp b/src/modm/driver/display/parallel_tft.hpp index ca2c6539ac..d1f186d416 100644 --- a/src/modm/driver/display/parallel_tft.hpp +++ b/src/modm/driver/display/parallel_tft.hpp @@ -16,88 +16,104 @@ #define MODM_PARALLEL_TFT_HPP #include -#include +#include namespace modm { - /** - * TFT display connected to a 16 bit parallel bus - * - * Supports (among others) the following displays: - * - WaveShare 3,2" TFT (Model B), Controller SSD1289 - * - * @author Fabian Greif - * @ingroup modm_driver_parallel_tft_display - */ - template - class ParallelTft : public GraphicDisplay +/** + * TFT display connected to a 16 bit parallel bus + * + * Supports (among others) the following displays: + * - WaveShare 3,2" TFT (Model B), Controller SSD1289 + * + * @author Fabian Greif + * @ingroup modm_driver_parallel_tft_display + */ +template +class ParallelTft : public ColorGraphicDisplay +{ +public: + ParallelTft(INTERFACE& interface); + + void + initialize(); + + // see GraphicDisplay::getWidth() + uint16_t + getWidth() const final + { + // TODO + return 320; + } + + // see GraphicDisplay::getHeight() + uint16_t + getHeight() const final + { + // TODO + return 240; + } + + inline std::size_t + getBufferWidth() const final + { + return 0; + } + + inline std::size_t + getBufferHeight() const final { - public: - ParallelTft(INTERFACE& interface); - - void - initialize(); - - // see GraphicDisplay::getWidth() - virtual uint16_t - getWidth() const; - - // see GraphicDisplay::getHeight() - virtual uint16_t - getHeight() const; - - // set GraphicDisplay::clear() - virtual void - clear(); - - /** - * Not used here as all operations are performed directly - * on the display. - */ - virtual void - update() - { - } - - private: - enum class Device - { - ILI9320, // device code = 0x9320 - ILI9325, // device code = 0x9325 - ILI9328, // device code = 0x9328 - ILI9331, // device code = 0x9331 - SSD1298, // device code = 0x8999 - SSD1289, // device code = 0x8989 - ST7781, // device code = 0x7783 - LGDP4531, // device code = 0x4531 - SPFD5408B, // device code = 0x5408 - R61505U, // device code = 0x1505 or 0x0505 - //HX8347D, // device code = 0x0047 - //HX8347A, // device code = 0x0047 - LGDP4535, // device code = 0x4535 - //SSD2119, // 3.5 LCD, device code = 0x9919 - }; - - virtual void - setPixel(int16_t x, int16_t y); - - virtual void - clearPixel(int16_t x, int16_t y); - - virtual bool - getPixel(int16_t x, int16_t y); - - void - writeCursor(uint16_t x, uint16_t y); - - void - writeRegister(uint16_t reg, uint16_t value); - - INTERFACE& interface; - Device deviceCode; + return 0; + } + + void + setPixel(int16_t x, int16_t y) final; + + void + clearPixel(int16_t x, int16_t y) final; + + glcd::Color + getPixel(int16_t x, int16_t y) const final; + + // set GraphicDisplay::clear() + void + clear() final; + + inline void + update() final + { /* nothing to do, data is directly written to TFT RAM */ + } + +private: + enum class Device + { + ILI9320, // device code = 0x9320 + ILI9325, // device code = 0x9325 + ILI9328, // device code = 0x9328 + ILI9331, // device code = 0x9331 + SSD1298, // device code = 0x8999 + SSD1289, // device code = 0x8989 + ST7781, // device code = 0x7783 + LGDP4531, // device code = 0x4531 + SPFD5408B, // device code = 0x5408 + R61505U, // device code = 0x1505 or 0x0505 + // HX8347D, // device code = 0x0047 + // HX8347A, // device code = 0x0047 + LGDP4535, // device code = 0x4535 + // SSD2119, // 3.5 LCD, device code = 0x9919 }; -} + + void + writeCursor(uint16_t x, uint16_t y); + + void + writeRegister(uint16_t reg, uint16_t value); + + INTERFACE& interface; + Device deviceCode; +}; +} // namespace modm #include "parallel_tft_impl.hpp" -#endif // MODM_PARALLEL_TFT_HPP +#endif // MODM_PARALLEL_TFT_HPP diff --git a/src/modm/driver/display/parallel_tft_impl.hpp b/src/modm/driver/display/parallel_tft_impl.hpp index 9828abc5c0..c32f82ce46 100644 --- a/src/modm/driver/display/parallel_tft_impl.hpp +++ b/src/modm/driver/display/parallel_tft_impl.hpp @@ -101,22 +101,6 @@ modm::ParallelTft::initialize() clear(); } -template -uint16_t -modm::ParallelTft::getWidth() const -{ - // TODO - return 320; -} - -template -uint16_t -modm::ParallelTft::getHeight() const -{ - // TODO - return 240; -} - template void modm::ParallelTft::clear() @@ -158,8 +142,8 @@ modm::ParallelTft::clearPixel(int16_t x, int16_t y) } template -bool -modm::ParallelTft::getPixel(int16_t x, int16_t y) +modm::glcd::Color +modm::ParallelTft::getPixel(int16_t x, int16_t y) const { (void) x; (void) y; diff --git a/src/modm/driver/display/siemens_m55.hpp b/src/modm/driver/display/siemens_m55.hpp index a82214e2df..370c0d9d32 100644 --- a/src/modm/driver/display/siemens_m55.hpp +++ b/src/modm/driver/display/siemens_m55.hpp @@ -16,7 +16,7 @@ #define MODM_SIEMENS_M55_HPP #include -#include +#include namespace modm { @@ -28,7 +28,7 @@ namespace modm * \ingroup modm_driver_siemens_m55 */ template - class SiemensM55 : public MonochromeGraphicDisplayBufferedVertical<101, 80> + class SiemensM55 : public MonochromeGraphicDisplayVertical<101, 80> { public: void diff --git a/src/modm/driver/display/siemens_m55_impl.hpp b/src/modm/driver/display/siemens_m55_impl.hpp index cf870e2378..41f3ad0417 100644 --- a/src/modm/driver/display/siemens_m55_impl.hpp +++ b/src/modm/driver/display/siemens_m55_impl.hpp @@ -165,7 +165,7 @@ modm::SiemensM55::update() { for (uint8_t x = 0; x < 101; ++x) { // group of 8 black-and-white pixels - uint8_t group = this->display_buffer[x][y/8]; + uint8_t group = this->buffer[x][y/8]; if (group & (1 << (y % 8))) { diff --git a/src/modm/driver/display/siemens_s65.hpp b/src/modm/driver/display/siemens_s65.hpp index 1c836ffef2..632cf25151 100644 --- a/src/modm/driver/display/siemens_s65.hpp +++ b/src/modm/driver/display/siemens_s65.hpp @@ -16,7 +16,7 @@ #define MODM_SIEMENS_S65_HPP #include -#include +#include // to enable this define add it to your ``project.cfg`` and // include before including this file. @@ -33,7 +33,7 @@ namespace modm * ot 132 x 176 pixels in 18 bit colour. * * The portrait mode is a bit more 'native' for this display because - * modm::BufferedGraphicDisplay requests that the vertical resolution is + * modm::GraphicDisplay requests that the vertical resolution is * dividable by 8. * * In portrait mode the connector is at the bottom. @@ -67,7 +67,7 @@ namespace modm /// \ingroup modm_driver_siemens_s65 template class SiemensS65Portrait : - public MonochromeGraphicDisplayBufferedVertical<132, 176>, + public MonochromeGraphicDisplayVertical<132, 176>, public SiemensS65Common { public: @@ -84,13 +84,13 @@ namespace modm /** * The display in landscape mode does not match the required - * alignment of BufferedGraphicDisplay which requests that + * alignment of GraphicDisplay which requests that * the vertical resolution can be divided by 8. * \ingroup modm_driver_siemens_s65 */ template class SiemensS65Landscape : - public MonochromeGraphicDisplayBufferedVertical<176, 136>, + public MonochromeGraphicDisplayVertical<176, 136>, public SiemensS65Common { public: diff --git a/src/modm/driver/display/siemens_s65_impl.hpp b/src/modm/driver/display/siemens_s65_impl.hpp index 85320fa58a..94eeddc200 100644 --- a/src/modm/driver/display/siemens_s65_impl.hpp +++ b/src/modm/driver/display/siemens_s65_impl.hpp @@ -233,7 +233,7 @@ modm::SiemensS65Portrait::update() { for (uint8_t y = 0; y < height; ++y) { // group of 8 black-and-white pixels - uint8_t group = this->display_buffer[x][y]; + uint8_t group = this->buffer[x][y]; // 8 pixels of 16 bits fit in the Tx FIFO if it is empty. while (!(LPC_SSP0->SR & SPI_SRn_TFE)); @@ -262,7 +262,7 @@ modm::SiemensS65Portrait::update() { for (uint8_t y = 0; y < height; ++y) { // group of 8 black-and-white pixels - uint8_t group = this->display_buffer[x][y]; + uint8_t group = this->buffer[x][y]; uint8_t spiBuffer[16]; uint8_t spiIdx = 0; @@ -320,7 +320,7 @@ modm::SiemensS65Landscape::update() { for (uint8_t y = 0; y < height; ++y) { // group of 8 black-and-white pixels - uint8_t group = this->display_buffer[x][y]; + uint8_t group = this->buffer[x][y]; // 8 pixels of 16 bits fit in the Tx FIFO if it is empty. while (!(LPC_SSP0->SR & SPI_SRn_TFE)); @@ -352,7 +352,7 @@ modm::SiemensS65Landscape::update() { for (uint8_t y = 0; y < height; ++y) { // group of 8 black-and-white pixels - uint8_t group = this->display_buffer[x][y]; + uint8_t group = this->buffer[x][y]; uint8_t spiBuffer[16]; uint8_t bufSize = 16; diff --git a/src/modm/driver/display/siemens_s75.hpp b/src/modm/driver/display/siemens_s75.hpp index 83e6534b93..2a4e7b41c6 100644 --- a/src/modm/driver/display/siemens_s75.hpp +++ b/src/modm/driver/display/siemens_s75.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include namespace modm { @@ -38,7 +38,7 @@ namespace modm uint16_t HEIGHT, modm::Orientation ORIENTATION> class SiemensS75Common : - public MonochromeGraphicDisplayBufferedVertical + public MonochromeGraphicDisplayVertical { public: SiemensS75Common(MEMORY& interface) : @@ -79,7 +79,7 @@ namespace modm /** * The display in landscape mode does not match the required - * alignment of BufferedGraphicDisplay which requests that + * alignment of GraphicDisplay which requests that * the vertical resolution can be divided by 8. * * @ingroup modm_driver_siemens_s75 diff --git a/src/modm/driver/display/siemens_s75.md b/src/modm/driver/display/siemens_s75.md index 79b72c35f7..f8b23657da 100644 --- a/src/modm/driver/display/siemens_s75.md +++ b/src/modm/driver/display/siemens_s75.md @@ -4,7 +4,7 @@ The controller in displays manufactured by Alps is a SOLOMON SYSTECH SSD1286 which can drive color displays of up to 132 x 176 pixels in 18 bit color. The portrait mode is a bit more 'native' for this display because -`modm::BufferedGraphicDisplay` requests that the vertical resolution is +`modm::GraphicDisplay` requests that the vertical resolution is divisible by 8. In portrait mode the connector is at the top. diff --git a/src/modm/driver/display/siemens_s75_impl.hpp b/src/modm/driver/display/siemens_s75_impl.hpp index 0ae2484f47..af13983898 100644 --- a/src/modm/driver/display/siemens_s75_impl.hpp +++ b/src/modm/driver/display/siemens_s75_impl.hpp @@ -65,7 +65,7 @@ modm::SiemensS75Common::update() for (int_fast16_t y = 0; y < height; ++y) { // group of 8 black-and-white pixels - uint_fast8_t group = this->display_buffer[x][y]; + uint_fast8_t group = this->buffer[x][y]; uint16_t PortBuffer[8]; uint_fast8_t PortIdx = 0; diff --git a/src/modm/driver/display/ssd1306.hpp b/src/modm/driver/display/ssd1306.hpp index b5e9fa0fc5..0db73ed44c 100644 --- a/src/modm/driver/display/ssd1306.hpp +++ b/src/modm/driver/display/ssd1306.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include namespace modm { @@ -153,7 +153,7 @@ struct ssd1306 * @ingroup modm_driver_ssd1306 */ template < class I2cMaster, uint8_t Height = 64 > -class Ssd1306 : public ssd1306, public MonochromeGraphicDisplayBufferedVertical<128, Height>, +class Ssd1306 : public ssd1306, public MonochromeGraphicDisplayVertical<128, Height>, public I2cDevice> { static_assert((Height == 64) or (Height == 32), "Display height must be either 32 or 64 pixel!"); @@ -210,7 +210,7 @@ class Ssd1306 : public ssd1306, public MonochromeGraphicDisplayBufferedVertical< { return writeCommand(Command::SetContrastControl, contrast); } modm::ResumableResult - setRotation(Rotation rotation=Rotation::Normal); + setOrientation(glcd::Orientation orientation = glcd::Orientation::Landscape0); modm::ResumableResult diff --git a/src/modm/driver/display/ssd1306_impl.hpp b/src/modm/driver/display/ssd1306_impl.hpp index 8e56f151e8..aa884659d2 100644 --- a/src/modm/driver/display/ssd1306_impl.hpp +++ b/src/modm/driver/display/ssd1306_impl.hpp @@ -60,9 +60,9 @@ modm::Ssd1306::startWriteDisplay() RF_BEGIN(); RF_WAIT_UNTIL( - this->transaction.configureDisplayWrite(this->display_buffer, - (this->displayBufferWidth * this->displayBufferHeight)) - and this->startTransaction()); + this->transaction.configureDisplayWrite( + this->buffer, + this->getBufferWidth() * this->getBufferHeight()) and this->startTransaction()); RF_END(); } @@ -82,14 +82,14 @@ modm::Ssd1306::writeDisplay() template < class I2cMaster, uint8_t Height > modm::ResumableResult -modm::Ssd1306::setRotation(Rotation rotation) +modm::Ssd1306::setOrientation(glcd::Orientation orientation) { RF_BEGIN(); - if ( RF_CALL(writeCommand((rotation == Rotation::Normal) ? + if ( RF_CALL(writeCommand((orientation == glcd::Orientation::Landscape0) ? Command::SetSegmentRemap127 : Command::SetSegmentRemap0)) ) { - RF_RETURN_CALL(writeCommand((rotation == Rotation::Normal) ? + RF_RETURN_CALL(writeCommand((orientation == glcd::Orientation::Landscape0) ? Command::SetComOutputScanDirectionDecrement : Command::SetComOutputScanDirectionIncrement)); } diff --git a/src/modm/driver/display/st7565.hpp b/src/modm/driver/display/st7565.hpp index bae148069e..c1b4e0aa9d 100644 --- a/src/modm/driver/display/st7565.hpp +++ b/src/modm/driver/display/st7565.hpp @@ -17,7 +17,7 @@ #include #include -#include +#include namespace modm { @@ -29,7 +29,7 @@ namespace modm */ template - class St7565 : public MonochromeGraphicDisplayBufferedVertical + class St7565 : public MonochromeGraphicDisplayVertical { public: virtual ~St7565() diff --git a/src/modm/driver/display/st7565_impl.hpp b/src/modm/driver/display/st7565_impl.hpp index 06d21ca1c2..1ac77d16e7 100644 --- a/src/modm/driver/display/st7565_impl.hpp +++ b/src/modm/driver/display/st7565_impl.hpp @@ -41,7 +41,7 @@ modm::St7565::update() // switch to data mode a0.set(); for(uint8_t x = 0; x < Width; ++x) { - spi.transferBlocking(this->display_buffer[x][y]); + spi.transferBlocking(this->buffer[x][y]); } } cs.set(); diff --git a/src/modm/ui/display.hpp b/src/modm/ui/display.hpp index c7a02cf479..c54170c96d 100644 --- a/src/modm/ui/display.hpp +++ b/src/modm/ui/display.hpp @@ -3,6 +3,7 @@ * Copyright (c) 2009-2011, 2019, Fabian Greif * Copyright (c) 2012, Sascha Schade * Copyright (c) 2012-2014, Niklas Hauser + * Copyright (c) 2021, Thomas Sommer * * This file is part of the modm project. * @@ -15,6 +16,5 @@ #include "display/image.hpp" #include "display/character_display.hpp" -#include "display/graphic_display.hpp" -#include "display/monochrome_graphic_display_buffered_horizontal.hpp" -#include "display/monochrome_graphic_display_buffered_vertical.hpp" +#include "display/color_graphic_display.hpp" +#include "display/monochrome_graphic_display.hpp" diff --git a/src/modm/ui/display/color_graphic_display.hpp b/src/modm/ui/display/color_graphic_display.hpp new file mode 100644 index 0000000000..08159c1fcd --- /dev/null +++ b/src/modm/ui/display/color_graphic_display.hpp @@ -0,0 +1,121 @@ +#ifndef MODM_COLOR_GRAPHIC_DISPLAY_HPP +#define MODM_COLOR_GRAPHIC_DISPLAY_HPP + +#include + +#include "graphic_display.hpp" + +using namespace modm::platform; + +namespace modm +{ + +// Backwards compatibility +namespace glcd +{ +/// @ingroup modm_ui_display +using Point = Vector; + +// RGB16 (565) Format +/// @ingroup modm_ui_display +class Color +{ +public: + static constexpr Color white() { return Color(0xffff); }; + static constexpr Color yellow() { return Color(0xFFE0); }; + static constexpr Color magenta() { return Color(0xF81F); }; + static constexpr Color red() { return Color(0xF800); }; + static constexpr Color orange() { return Color(0xFD20); }; + static constexpr Color silver() { return Color(0xC618); }; + static constexpr Color gray() { return Color(0x8410); }; + static constexpr Color maroon() { return Color(0x8000); }; + static constexpr Color lime() { return Color(0x07E0); }; + static constexpr Color green() { return Color(0x0400); }; + static constexpr Color blue() { return Color(0x001F); }; + static constexpr Color navy() { return Color(0x0010); }; + static constexpr Color black() { return Color(0x0000); }; + static constexpr Color signalViolet() { return Color(0x8010); }; + static constexpr Color emeraldGreen() { return Color(0x5DCC); }; + + constexpr Color() = default; + + constexpr Color(uint16_t color) : color(color) {} + + /** + * @param red + * Range [0..255] + * @param green + * Range [0..255] + * @param blue + * Range [0..255] + */ + constexpr Color(uint8_t red, uint8_t green, uint8_t blue) : + color(uint16_t((red >> 3) << 11) | uint16_t((green >> 2) << 5) | uint16_t(blue >> 3)) + {} + + inline uint16_t + getValue() const + { + return color; + } + + bool + operator==(const Color &other) const + { + return (color == other.color); + } + +private: + uint16_t color{0x000}; +}; +} // namespace glcd + +class ColorGraphicDisplay : public GraphicDisplay +{ +public: + ColorGraphicDisplay() + : foregroundColor(glcd::Color::white()), backgroundColor(glcd::Color::black()) + {} + + virtual glcd::Color + getPixel(int16_t x, int16_t y) const = 0; + + /** + * Set a new foreground color. + * Used for drawing operations. Default is white. + */ + inline void + setColor(const glcd::Color color) + { + foregroundColor = color; + } + + inline glcd::Color + getColor() const + { + return foregroundColor; + } + + /** + * Set background color. + * Used when clearing the screen. Default is black. + */ + inline void + setBackgroundColor(const glcd::Color color) + { + backgroundColor = color; + } + + inline glcd::Color + getBackgroundColor() const + { + return backgroundColor; + } + +protected: + glcd::Color foregroundColor; + glcd::Color backgroundColor; +}; +} // namespace modm + +#endif // MODM_COLOR_GRAPHIC_DISPLAY_HPP diff --git a/src/modm/ui/display/graphic_display.cpp b/src/modm/ui/display/graphic_display.cpp index 832dea5801..1c5727e66e 100644 --- a/src/modm/ui/display/graphic_display.cpp +++ b/src/modm/ui/display/graphic_display.cpp @@ -16,47 +16,17 @@ */ // ---------------------------------------------------------------------------- +#include "graphic_display.hpp" + #include #include #include "font/fixed_width_5x8.hpp" -#include "graphic_display.hpp" - -// ---------------------------------------------------------------------------- -modm::GraphicDisplay::GraphicDisplay() : - IOStream(writer), - writer(this), - draw(&modm::GraphicDisplay::setPixel), - foregroundColor(glcd::Color::white()), - backgroundColor(glcd::Color::black()), - font(modm::accessor::asFlash(modm::font::FixedWidth5x8)) -{ -} // ---------------------------------------------------------------------------- -void -modm::GraphicDisplay::setColor(const glcd::Color& newColor) -{ -// if (newColor == glcd::Color::black()) { -// draw = &modm::GraphicDisplay::clearPixel; -// } -// else { -// draw = &modm::GraphicDisplay::setPixel; -// } - - /* When using a multicolor display we don't need clearPixel(), or at least - * not the way it was implemented above. Maybe check if newColor equals - * backgroundColor. - * */ - draw = &modm::GraphicDisplay::setPixel; - this->foregroundColor = newColor; -} - -void -modm::GraphicDisplay::setBackgroundColor(const glcd::Color& newColor) -{ - this->backgroundColor = newColor; -} +modm::GraphicDisplay::GraphicDisplay() + : IOStream(writer), writer(this), font(modm::accessor::asFlash(modm::font::FixedWidth5x8)) +{} // ---------------------------------------------------------------------------- void @@ -65,28 +35,25 @@ modm::GraphicDisplay::drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2) if (x1 == x2) { // x1|y1 must be the upper point - if (y1 > y2) { - modm::swap(y1, y2); - } + if (y1 > y2) { modm::swap(y1, y2); } this->drawVerticalLine(glcd::Point(x1, y1), y2 - y1 + 1); - } - else if (y1 == y2) + } else if (y1 == y2) { // x1|y1 must be the left point - if (x1 > x2) { - modm::swap(x1, x2); - } + if (x1 > x2) { modm::swap(x1, x2); } this->drawHorizontalLine(glcd::Point(x1, y1), x2 - x1 + 1); - } - else + } else { // bresenham algorithm bool steep = abs(y2 - y1) > abs(x2 - x1); - if (steep) { + if (steep) + { modm::swap(x1, y1); modm::swap(x2, y2); } - if (x1 > x2) { + + if (x1 > x2) + { modm::swap(x1, x2); modm::swap(y1, y2); } @@ -98,23 +65,22 @@ modm::GraphicDisplay::drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2) int16_t yStep; int16_t y = y1; - if (y1 < y2) { + if (y1 < y2) yStep = 1; - } - else { + else yStep = -1; - } for (int_fast16_t x = x1; x <= x2; ++x) { - if (steep) { - (this->*draw)(y, x); - } - else { - (this->*draw)(x, y); - } + if (steep) + this->setPixel(y, x); + else + this->setPixel(x, y); + error = error - deltaY; - if (error < 0) { + + if (error < 0) + { y += yStep; error += deltaX; } @@ -125,63 +91,63 @@ modm::GraphicDisplay::drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2) void modm::GraphicDisplay::drawHorizontalLine(glcd::Point start, uint16_t length) { - for (int_fast16_t i = start.getX(); i < static_cast(start.getX() + length); ++i) { - (this->*draw)(i, start.getY()); + for (int_fast16_t i = start.x; i < static_cast(start.x + length); ++i) + { + this->setPixel(i, start.y); } } void modm::GraphicDisplay::drawVerticalLine(glcd::Point start, uint16_t length) { - for (int_fast16_t i = start.getY(); i < static_cast(start.getY() + length); ++i) { - (this->*draw)(start.getX(), i); + for (int_fast16_t i = start.y; i < static_cast(start.y + length); ++i) + { + this->setPixel(start.x, i); } } void -modm::GraphicDisplay::drawRectangle(glcd::Point upperLeft, - uint16_t width, uint16_t height) +modm::GraphicDisplay::drawRectangle(glcd::Point start, uint16_t width, uint16_t height) { - uint16_t x2 = upperLeft.getX() + width - 1; - uint16_t y2 = upperLeft.getY() + height - 1; + uint16_t x2 = start.x + width - 1; + uint16_t y2 = start.y + height - 1; - this->drawHorizontalLine(upperLeft, width); - this->drawHorizontalLine(glcd::Point(upperLeft.getX(), y2), width); - this->drawVerticalLine(upperLeft, height); - this->drawVerticalLine(glcd::Point(x2, upperLeft.getY()), height); + this->drawHorizontalLine(start, width); + this->drawHorizontalLine(glcd::Point(start.x, y2), width); + this->drawVerticalLine(start, height); + this->drawVerticalLine(glcd::Point(x2, start.y), height); } void -modm::GraphicDisplay::drawRoundedRectangle(glcd::Point upperLeft, - uint16_t width, uint16_t height, uint16_t radius) +modm::GraphicDisplay::drawRoundedRectangle(glcd::Point start, uint16_t width, uint16_t height, + uint16_t radius) { - if (radius == 0) { - this->drawRectangle(upperLeft, width, height); - } + if (radius == 0) { this->drawRectangle(start, width, height); } - const int16_t x = upperLeft.getX(); - const int16_t y = upperLeft.getY(); + const int16_t x = start.x; + const int16_t y = start.y; int16_t x1 = 0; int16_t y1 = radius; - int16_t f = 3 - 2 * radius; + int16_t f = 3 - 2 * radius; while (x1 <= y1) { - (this->*draw)(x + radius - x1, y + radius - y1); - (this->*draw)(x + radius - x1, y + height - radius + y1); - (this->*draw)(x + radius - y1, y + radius - x1); - (this->*draw)(x + radius - y1, y + height - radius + x1); + this->setPixel(x + radius - x1, y + radius - y1); + this->setPixel(x + radius - x1, y + height - radius + y1); + this->setPixel(x + radius - y1, y + radius - x1); + this->setPixel(x + radius - y1, y + height - radius + x1); - (this->*draw)(x + width - radius + x1, y + radius - y1); - (this->*draw)(x + width - radius + x1, y + height - radius + y1); - (this->*draw)(x + width - radius + y1, y + radius - x1); - (this->*draw)(x + width - radius + y1, y + height - radius + x1); + this->setPixel(x + width - radius + x1, y + radius - y1); + this->setPixel(x + width - radius + x1, y + height - radius + y1); + this->setPixel(x + width - radius + y1, y + radius - x1); + this->setPixel(x + width - radius + y1, y + height - radius + x1); - if (f < 0) { + if (f < 0) + { f += (4 * x1 + 6); - } - else { + } else + { f += (4 * (x1 - y1) + 10); y1--; } @@ -197,9 +163,7 @@ modm::GraphicDisplay::drawRoundedRectangle(glcd::Point upperLeft, void modm::GraphicDisplay::drawCircle(glcd::Point center, uint16_t radius) { - if (radius == 0) { - return; - } + if (radius == 0) { return; } int16_t error = -radius; int16_t x = radius; @@ -227,17 +191,13 @@ modm::GraphicDisplay::drawCircle(glcd::Point center, uint16_t radius) void modm::GraphicDisplay::drawCircle4(glcd::Point center, int16_t x, int16_t y) { - const int16_t cx = center.getX(); - const int16_t cy = center.getY(); + const int16_t cx = center.x; + const int16_t cy = center.y; - (this->*draw)(cx + x, cy + y); - (this->*draw)(cx - x, cy - y); - if (x != 0) { - (this->*draw)(cx - x, cy + y); - } - if (y != 0) { - (this->*draw)(cx + x, cy - y); - } + this->setPixel(cx + x, cy + y); + this->setPixel(cx - x, cy - y); + if (x != 0) { this->setPixel(cx - x, cy + y); } + if (y != 0) { this->setPixel(cx + x, cy - y); } } void @@ -260,10 +220,11 @@ modm::GraphicDisplay::drawEllipse(glcd::Point center, int16_t rx, int16_t ry) x++; fx += ry_2 * 2; - if (p < 0) { + if (p < 0) + { p += (fx + ry_2); - } - else { + } else + { y--; fy -= rx_2 * 2; p += (fx + ry_2 - fy); @@ -272,19 +233,20 @@ modm::GraphicDisplay::drawEllipse(glcd::Point center, int16_t rx, int16_t ry) drawCircle4(center, x, y); } - p = ((ry_2 * (4 * x * x + 4 * x + 1) / 2) + - 2 * (rx_2 * (y - 1) * (y - 1)) - - 2 * (rx_2 * ry_2) - + 1) / 2; + p = ((ry_2 * (4 * x * x + 4 * x + 1) / 2) + 2 * (rx_2 * (y - 1) * (y - 1)) - 2 * (rx_2 * ry_2) + + 1) / + 2; - while (y > 0) { + while (y > 0) + { y--; fy -= rx_2 * 2; - if (p >= 0) { + if (p >= 0) + { p += (rx_2 - fy); - } - else { + } else + { x++; fx += ry_2 * 2; p += (fx + rx_2 - fy); @@ -296,20 +258,17 @@ modm::GraphicDisplay::drawEllipse(glcd::Point center, int16_t rx, int16_t ry) // ---------------------------------------------------------------------------- void -modm::GraphicDisplay::drawImage(glcd::Point upperLeft, - modm::accessor::Flash image) +modm::GraphicDisplay::drawImage(glcd::Point start, modm::accessor::Flash image) { uint8_t width = image[0]; uint8_t height = image[1]; - drawImageRaw(upperLeft, width, height, - modm::accessor::Flash(image.getPointer() + 2)); + drawImageRaw(start, width, height, modm::accessor::Flash(image.getPointer() + 2)); } void -modm::GraphicDisplay::drawImageRaw(glcd::Point upperLeft, - uint16_t width, uint16_t height, - modm::accessor::Flash data) +modm::GraphicDisplay::drawImageRaw(glcd::Point start, uint16_t width, uint16_t height, + modm::accessor::Flash data) { uint16_t rows = (height + 7) / 8; for (uint16_t i = 0; i < width; i++) @@ -318,17 +277,14 @@ modm::GraphicDisplay::drawImageRaw(glcd::Point upperLeft, { uint16_t byte = data[i + k * width]; uint16_t rowHeight = height - k * 8; - if (rowHeight > 8) { - rowHeight = 8; - } + if (rowHeight > 8) { rowHeight = 8; } for (uint16_t j = 0; j < rowHeight; j++) { - if (byte & 0x01) { - this->setPixel(upperLeft.getX() + i, upperLeft.getY() + k * 8 + j); - } - else { - this->clearPixel(upperLeft.getX() + i, upperLeft.getY() + k * 8 + j); - } + if (byte & 0x01) + this->setPixel(start.x + i, start.y + k * 8 + j); + else + this->clearPixel(start.x + i, start.y + k * 8 + j); + byte >>= 1; } } diff --git a/src/modm/ui/display/graphic_display.hpp b/src/modm/ui/display/graphic_display.hpp index f2e8692c01..7afdacb1ef 100644 --- a/src/modm/ui/display/graphic_display.hpp +++ b/src/modm/ui/display/graphic_display.hpp @@ -6,6 +6,7 @@ * Copyright (c) 2013, Hans Schily * Copyright (c) 2014, Daniel Krebs * Copyright (c) 2015, Niclas Rohrer + * Copyright (c) 2021, Thomas Sommer * * This file is part of the modm project. * @@ -19,461 +20,439 @@ #define MODM_GRAPHIC_DISPLAY_HPP #include -#include - #include #include +#include #include "font.hpp" namespace modm { - /// @ingroup modm_ui_display - namespace glcd + +/// @ingroup modm_ui_display +namespace glcd +{ + +/// @ingroup modm_ui_display +using Point = Vector; + +enum Orientation : uint8_t +{ + Landscape0, + Portrait90, + Landscape180, + Portrait270, +}; + +} // namespace glcd + +/** + * Base class for graphical displays. + * + * \ingroup modm_ui_display + */ + +/* + * + * Text mode: + * - left adjusted (default) + * - right adjusted + * - centered + * + * All modes relative to the current viewport. This would make + * drawing a menu system easier. + */ +class GraphicDisplay : public IOStream +{ +public: + friend class VirtualGraphicDisplay; + + GraphicDisplay(); + + virtual ~GraphicDisplay() {} + + /** + * Number of pixel in horizontal direction. + */ + virtual uint16_t + getWidth() const = 0; + + /** + * Number of pixel in vertical direction. + */ + virtual uint16_t + getHeight() const = 0; + + // TODO Requires all inherited drivers work with resumable functions + // virtual modm::ResumableResult + // setOrientation() = 0; + + /** + * Buffer-array size of first dimension + */ + virtual std::size_t + getBufferWidth() const = 0; + + /** + * Buffer-array size of second dimension + */ + virtual std::size_t + getBufferHeight() const = 0; + + /** + * Set a pixel to foregroundColor + * + * \param x x-position + * \param y y-position + */ + virtual void + setPixel(int16_t x, int16_t y) = 0; + + /** + * Set a pixel to foregroundColor + * + * \param p point + */ + inline void + setPixel(glcd::Point p) + { + this->setPixel(p.x, p.y); + } + + /** + * Set a pixel to backgroundColor + * + * \param x x-position + * \param y y-position + */ + virtual void + clearPixel(int16_t x, int16_t y) = 0; + + /** + * Set a pixel to backgroundColor + * + * \param p point + */ + inline void + clearPixel(glcd::Point p) { - /// @ingroup modm_ui_display - typedef Vector Point; - - // RGB16 (565) Format - /// @ingroup modm_ui_display - class Color - { - public: - static modm_always_inline Color white() { return Color(0xffff); }; - static modm_always_inline Color yellow() { return Color(0xFFE0); }; - static modm_always_inline Color magenta() { return Color(0xF81F); }; - static modm_always_inline Color red() { return Color(0xF800); }; - static modm_always_inline Color orange() { return Color(0xFD20); }; - static modm_always_inline Color sliver() { return Color(0xC618); }; - static modm_always_inline Color gray() { return Color(0x8410); }; - static modm_always_inline Color maroon() { return Color(0x8000); }; - static modm_always_inline Color lime() { return Color(0x07E0); }; - static modm_always_inline Color green() { return Color(0x0400); }; - static modm_always_inline Color blue() { return Color(0x001F); }; - static modm_always_inline Color navy() { return Color(0x0010); }; - static modm_always_inline Color black() { return Color(0x0000); }; - static modm_always_inline Color signalViolet() { return Color(0x8010); }; //0x84D0 - static modm_always_inline Color emeraldGreen() { return Color(0x5DCC); }; - - /** - * @param red - * Range [0..255] - * @param green - * Range [0..255] - * @param blue - * Range [0..255] - */ - Color(uint8_t red, uint8_t green, uint8_t blue) : - color(((static_cast(red >> 3) << 11) | - (static_cast(green >> 2) << 5) | - static_cast(blue >> 3))) - { - } - - Color(uint16_t color) : - color(color) - { - } - - Color() : color(0) - { - } - - inline uint16_t - getValue() const - { - return color; - } - - bool - operator == (const Color& other) const { - return (color == other.color); - } - - private: - uint16_t color; - }; + this->setPixel(p.x, p.y); } - // TODO -// enum class Orientation : uint8_t -// { -// Portrait, //< Connector top -// LandscapeRight, //< Connector right -// LandscapeLeft, //< Connector left -// PortraitUpsideDown, //< Connector bottom -// }; + /** + * Set whole screen to backgroundColor + */ + virtual void + clear() = 0; + + /** + * Transfer the content of the RAM buffer to the real display. + */ + virtual void + update() = 0; + + // TODO Requires all inherited drivers work with resumable functions + // modm::ResumableResult + // writeDisplay(); + + // TODO Set a clipping area + // Everything drawn outside this area will be discarded. + // inline void + // setClippingWindow(glcd::Point start, glcd::Point end); /** - * Base class for graphical displays. + * Draw a line. + * + * Uses the faster drawHorizontalLine() or drawVerticalLine() if + * possible, otherwise the line is rastered with the Bresenham line + * algorithm. * - * \ingroup modm_ui_display + * \param start first point + * \param end second point */ - /* - * TODO + inline void + drawLine(glcd::Point start, glcd::Point end) + { + this->drawLine(start.x, start.y, end.x, end.y); + } + + /** + * Draw a line * - * setBrush() and setPen() for filling and the border? - * possible Brush/Pen modes: - * - NONE - * - BLACK - * - WHITE - * - INVERT + * \param x1 Start x-position + * \param y1 Start y-position + * \param x2 End x-position + * \param y3 End y-position + */ + void + drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2); + + /** + * Draw a rectangle. * - * Text mode: - * - left adjusted (default) - * - right adjusted - * - centered + * \param start Upper left corner + * \param width Width of rectangle + * \param height Height of rectangle + */ + void + drawRectangle(glcd::Point start, uint16_t width, uint16_t height); + + /** + * Draw a rectangle. * - * All modes relative to the current viewport. This would make - * drawing a menu system easier. + * \param x Upper left corner x-position + * \param y Upper left corner y-position + * \param width Width of rectangle + * \param height Height of rectangle */ - class GraphicDisplay : public IOStream + inline void + drawRectangle(int16_t x, int16_t y, uint16_t width, uint16_t height) { - public: - friend class VirtualGraphicDisplay; - - GraphicDisplay(); - - virtual - ~GraphicDisplay() - { - } - - /** - * Number of pixel in horizontal direction. - */ - virtual uint16_t - getWidth() const = 0; - - /** - * Number of pixel in vertical direction. - */ - virtual uint16_t - getHeight() const = 0; - - /** - * Clear screen and reset the cursor. - */ - virtual void - clear() = 0; + drawRectangle(glcd::Point(x, y), width, height); + } - /** - * Transfer the content of the RAM buffer to the real display. - */ - virtual void - update() = 0; - - /** - * Set a new foreground color. - * - * The foreground color is used for all drawing operations. Default - * is white. - * - * @see setBackgroundColor() - */ - void - setColor(const glcd::Color& color); - - inline glcd::Color - getForegroundColor() const - { - return this->foregroundColor; - } - - /** - * Set new background color. - * - * The background color used when clearing the screen. Default is black. - * - * @see setColor() - */ - void - setBackgroundColor(const glcd::Color& color); - - /** - * Limit the coordinate system to a smaller area. - * - * The default viewport is the complete screen. - */ - //void - //setViewport(); - - // TODO Set a clipping area - // Everything drawn outside this area will be discarded. - //void - //setClippingWindow(); - - /** - * Draw a pixel in currently active foreground color. - * - * \param x x-position - * \param y y-position - */ - inline void - drawPixel(int16_t x, int16_t y) - { - (this->*draw)(x, y); - } - - inline void - drawPixel(glcd::Point center) - { - (this->*draw)(center.x, center.y); - } - - /** - * Draw a line. - * - * Uses the faster drawHorizontalLine() or drawVerticalLine() if - * possible, otherwise the line is rastered with the Bresenham line - * algorithm. - * - * \param start first point - * \param end second point - */ - inline void - drawLine(glcd::Point start, glcd::Point end) - { - this->drawLine(start.getX(), start.getY(), end.getX(), end.getY()); - } - - /** - * Draw a line specified by x and y coordinates of both points. - */ - void - drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2); - - inline void - drawRectangle(int16_t x, int16_t y, uint16_t width, uint16_t height) - { - drawRectangle(glcd::Point(x, y), width, height); - } - - /** - * Draw a rectangle. - */ - void - drawRectangle(glcd::Point upperLeft, uint16_t width, uint16_t height); - - /** - * Draw a rectangle with rounded corners. - */ - void - drawRoundedRectangle(glcd::Point upperLeft, - uint16_t width, uint16_t height, - uint16_t radius); - - /** - * Draw a circle - * - * Uses the midpoint circle algorithm. - * - * \param center Center of the circle - * \param radius Radius of the circle - */ - void - drawCircle(glcd::Point center, uint16_t radius); - - /** - * Draw an ellipse. - * - * Uses a variation of the midpoint algorithm. May be improved through - * simplification of the used formula. - * - * \param center Center of the ellipse - * \param rx radius in x-direction - * \param ry radius in y-direction - */ - void - drawEllipse(glcd::Point center, int16_t rx, int16_t ry); - - /** - * Draw an image. - * - * The first byte in the image data specifies the with, the second - * byte the height. Afterwards the actual image data. - * - * \param upperLeft Upper left corner - * \param image Image data - * - * \see drawImage() - */ - void - drawImage(glcd::Point upperLeft, modm::accessor::Flash image); - - /** - * Draw an image. - * - * \p data is the actual image data without any size information. - */ - virtual void - drawImageRaw(glcd::Point upperLeft, - uint16_t width, uint16_t height, - modm::accessor::Flash data); + /** + * Draw a filled rectangle. + * + * \param start Upper left corner + * \param width Width of rectangle + * \param height Height of rectangle + */ + void + fillRectangle(glcd::Point start, uint16_t width, uint16_t height); - /** - * Fill a rectangle. - */ - virtual void - fillRectangle(glcd::Point upperLeft, uint16_t width, uint16_t height); + /** + * Draw a rectangle. + * + * \param x Upper left corner x-position + * \param y Upper left corner y-position + * \param width Width of rectangle + * \param height Height of rectangle + */ + inline void + fillRectangle(int16_t x, int16_t y, uint16_t width, uint16_t height) + { + fillRectangle(glcd::Point(x, y), width, height); + } + + /** + * Draw a rectangle with rounded corners + * + * \param start Upper left corner + * \param width Width of rectangle + * \param height Height of rectangle + * \param radius Rounding radius + */ + void + drawRoundedRectangle(glcd::Point start, uint16_t width, uint16_t height, uint16_t radius); - inline void - fillRectangle(int16_t x, int16_t y, uint16_t width, uint16_t height) - { - fillRectangle(glcd::Point(x, y), width, height); - } + /** + * Draw a filled rectangle with rounded corners + * + * \param start Upper left corner + * \param width Width of rectangle + * \param height Height of rectangle + * \param radius Rounding radius + */ + // TODO Not yet implemented + // void + // fillRoundedRectangle(glcd::Point start, uint16_t width, uint16_t height, uint16_t radius); - /** - * Fill a circle. - */ - virtual void - fillCircle(glcd::Point center, uint16_t radius); + /** + * Draw a circle + * + * Uses the midpoint circle algorithm. + * + * \param center Center of the circle + * \param radius Radius of the circle + */ + void + drawCircle(glcd::Point center, uint16_t radius); - public: - /** - * Set a new font. - * - * Default font is modm::font::FixedWidth5x8. - * - * \param newFont Active font - * \see modm::font - */ - inline void - setFont(const uint8_t *newFont) - { - this->font = modm::accessor::asFlash(newFont); - } - - inline void - setFont(const modm::accessor::Flash *font) - { - this->font = *font; - } - - /** - * Get the height of a character. - */ - uint8_t - getFontHeight() const; - - static uint8_t - getFontHeight(const modm::accessor::Flash *font); - - /** - * Get the width of (null terminated) string. - */ - uint16_t - getStringWidth(const char* s) const; - - static uint16_t - getStringWidth(const char* s, const modm::accessor::Flash *font); - - /** - * Set the cursor for text drawing. - * - * \param position Cursor position - */ - inline void - setCursor(glcd::Point position) - { - this->cursor = position; - } - - /** - * Set the cursor for text drawing. - * - * \param x Cursor x-position - * \param y Cursor y-position - */ - inline void - setCursor(int16_t x, int16_t y) - { - this->cursor = glcd::Point(x, y); - } - - inline void - setCursorX(int16_t x) - { - this->cursor.x = x; - } - - inline void - setCursorY(int16_t y) - { - this->cursor.y = y; - } - - inline glcd::Point - getCursor() const - { - return this->cursor; - } - - /** - * Write a single character. - */ - void - write(char c); + /** + * Draw a filled circle. + * + * \param center Center of the circle + * \param radius Radius of the circle + */ + virtual void + fillCircle(glcd::Point center, uint16_t radius); - protected: - /// helper method for drawCircle() and drawEllipse() - void - drawCircle4(glcd::Point center, int16_t x, int16_t y); + /** + * Draw an ellipse. + * + * Uses a variation of the midpoint algorithm. May be improved through + * simplification of the used formula. + * + * \param center Center of the ellipse + * \param rx Radius in x-direction + * \param ry Radius in y-direction + */ + void + drawEllipse(glcd::Point center, int16_t rx, int16_t ry); - virtual void - drawHorizontalLine(glcd::Point start, uint16_t length); + /** + * Draw an image. + * + * The first byte in the image data specifies the with, the second + * byte the height. Afterwards the actual image data. + * + * \param start Upper left corner + * \param image Image data in Flash + * + * \see drawImage() + */ + void + drawImage(glcd::Point start, modm::accessor::Flash image); - virtual void - drawVerticalLine(glcd::Point start, uint16_t length); + /** + * Draw an image. + * + * \param start Upper left corner + * \param width Image width + * \param height Image height + * \param data Image data in Flash without any size information. + */ + virtual void + drawImageRaw(glcd::Point start, uint16_t width, uint16_t height, + modm::accessor::Flash data); + + /** + * Set the cursor for text drawing. + * + * \param position Cursor position + */ + inline void + setCursor(glcd::Point position) + { + this->cursor = position; + } + + /** + * Set the cursor for text drawing. + * + * \param x Cursor x-position + * \param y Cursor y-position + */ + inline void + setCursor(int16_t x, int16_t y) + { + this->cursor = glcd::Point(x, y); + } + + /** + * Set the cursor x-position for text drawing. + * + * \param x Cursor x-position + */ + inline void + setCursorX(int16_t x) + { + this->cursor.x = x; + } + + /** + * Set the cursor y-position for text drawing. + * + * \param y Cursor y-position + */ + inline void + setCursorY(int16_t y) + { + this->cursor.y = y; + } + + inline glcd::Point + getCursor() const + { + return this->cursor; + } + + /** + * Set a new font. + * + * Default font is modm::font::FixedWidth5x8. + * + * \param newFont Active font + * \see modm::font + */ + inline void + setFont(const uint8_t *newFont) + { + this->font = modm::accessor::asFlash(newFont); + } + + inline void + setFont(const modm::accessor::Flash *font) + { + this->font = *font; + } + /** + * Get the height of a character. + */ + uint8_t + getFontHeight() const; + + static uint8_t + getFontHeight(const modm::accessor::Flash *font); + + /** + * Get the width of (null terminated) string. + */ + uint16_t + getStringWidth(const char *s) const; + + static uint16_t + getStringWidth(const char *s, const modm::accessor::Flash *font); + + /** + * Write a single character. + */ + void + write(char c); + +protected: + /// helper method for drawCircle() and drawEllipse() + void + drawCircle4(glcd::Point center, int16_t x, int16_t y); + + virtual void + drawHorizontalLine(glcd::Point start, uint16_t length); + + virtual void + drawVerticalLine(glcd::Point start, uint16_t length); + +protected: + // Interface class for the IOStream + class Writer : public IODevice + { + public: + Writer(GraphicDisplay *parent) : parent(parent) {} + + /// Draw a single character virtual void - setPixel(int16_t x, int16_t y) = 0; + write(char c); + + using IODevice::write; + // unused virtual void - clearPixel(int16_t x, int16_t y) = 0; + flush(); + // unused, returns always `false` virtual bool - getPixel(int16_t x, int16_t y) = 0; - - protected: - // Interface class for the IOStream - class Writer : public IODevice - { - public: - Writer(GraphicDisplay *parent) : - parent(parent) - { - } - - /// Draw a single character - virtual void - write(char c); - - using IODevice::write; - - // unused - virtual void - flush(); - - // unused, returns always `false` - virtual bool - read(char& c); - - private: - GraphicDisplay *parent; - }; - - protected: - Writer writer; - - // callback function for drawing pixels - void (GraphicDisplay::*draw)(int16_t x, int16_t y); - - glcd::Color foregroundColor; - glcd::Color backgroundColor; - modm::accessor::Flash font; - glcd::Point cursor; + read(char &c); + + private: + GraphicDisplay *parent; }; -} -#endif // MODM_GRAPHIC_DISPLAY_HPP +protected: + Writer writer; + modm::accessor::Flash font; + glcd::Point cursor; +}; +} // namespace modm + +#endif // MODM_GRAPHIC_DISPLAY_HPP diff --git a/src/modm/ui/display/graphic_display_fill.cpp b/src/modm/ui/display/graphic_display_fill.cpp index 0b2794c46f..389f8e8564 100644 --- a/src/modm/ui/display/graphic_display_fill.cpp +++ b/src/modm/ui/display/graphic_display_fill.cpp @@ -16,20 +16,12 @@ // ---------------------------------------------------------------------------- void -modm::GraphicDisplay::fillRectangle(glcd::Point upperLeft, +modm::GraphicDisplay::fillRectangle(glcd::Point start, uint16_t width, uint16_t height) { - for (uint16_t i = upperLeft.getX(); - (i < upperLeft.getX() + width) && (i < getWidth()); - ++i) - { - for (uint16_t k = upperLeft.getY(); - (k < upperLeft.getY() + height) && (k < getHeight()); - ++k) - { - (this->*draw)(i, k); - } - } + for (uint16_t i = start.x; (i < start.x + width) && (i < getWidth()); ++i) + for (uint16_t k = start.y; (k < start.y + height) && (k < getHeight()); ++k) + this->setPixel(i, k); } void @@ -41,7 +33,7 @@ modm::GraphicDisplay::fillCircle(glcd::Point center, uint16_t radius) uint16_t x = 0; uint16_t y = radius; - this->drawVerticalLine(glcd::Point(center.getX(), center.getY() - radius), 2 * radius); + this->drawVerticalLine(glcd::Point(center.x, center.y - radius), 2 * radius); while(x < y) { @@ -55,9 +47,9 @@ modm::GraphicDisplay::fillCircle(glcd::Point center, uint16_t radius) ddF_x += 2; f += ddF_x + 1; - this->drawVerticalLine(glcd::Point(center.getX() + x, center.getY() - y), 2 * y); - this->drawVerticalLine(glcd::Point(center.getX() + y, center.getY() - x), 2 * x); - this->drawVerticalLine(glcd::Point(center.getX() - x, center.getY() - y), 2 * y); - this->drawVerticalLine(glcd::Point(center.getX() - y, center.getY() - x), 2 * x); + this->drawVerticalLine(glcd::Point(center.x + x, center.y - y), 2 * y); + this->drawVerticalLine(glcd::Point(center.x + y, center.y - x), 2 * x); + this->drawVerticalLine(glcd::Point(center.x - x, center.y - y), 2 * y); + this->drawVerticalLine(glcd::Point(center.x - y, center.y - x), 2 * x); } } diff --git a/src/modm/ui/display/graphic_display_text.cpp b/src/modm/ui/display/graphic_display_text.cpp index 7fb86b2e1d..b7920853bb 100644 --- a/src/modm/ui/display/graphic_display_text.cpp +++ b/src/modm/ui/display/graphic_display_text.cpp @@ -71,7 +71,7 @@ modm::GraphicDisplay::write(char c) const uint8_t vspace = font[5]; if (character == '\n') { - this->cursor.set(0, this->cursor.getY() + height + hspace); + this->cursor.set(0, this->cursor.y + height + hspace); return; } @@ -97,7 +97,7 @@ modm::GraphicDisplay::write(char c) this->drawImageRaw(cursor, width, height, accessor::asFlash(font.getPointer() + offset)); - cursor.setX(cursor.getX() + width); + cursor.setX(cursor.x + width); // all characters below 128 have whitespace afterwards (number given // by vspace). @@ -107,7 +107,7 @@ modm::GraphicDisplay::write(char c) //this->setColor(glcd::Color::white()); for (uint_fast8_t i = 0; i < vspace; ++i) { //this->drawVerticalLine(cursor, height); - cursor.setX(cursor.getX() + 1); + cursor.setX(cursor.x + 1); } // restore color diff --git a/src/modm/ui/display/monochrome_graphic_display.hpp b/src/modm/ui/display/monochrome_graphic_display.hpp new file mode 100644 index 0000000000..aefba749aa --- /dev/null +++ b/src/modm/ui/display/monochrome_graphic_display.hpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2009, Georgi Grinshpun + * Copyright (c) 2009-2011, 2013, 2019, Fabian Greif + * Copyright (c) 2010, Martin Rosekeit + * Copyright (c) 2011, Thorsten Lajewski + * Copyright (c) 2012-2015, Niklas Hauser + * Copyright (c) 2021, Thomas Sommer + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_HPP +#define MODM_MONOCHROME_GRAPHIC_DISPLAY_HPP + +#include + +#include "graphic_display.hpp" + +namespace modm +{ +/** + * Base class for monochrome graphical displays with a RAM buffer. + * + * Every operation works on the internal RAM buffer, therefore the content + * of the real display is not changed until a call of update(). + * + * \tparam Width Horizontal number of Pixels + * \tparam Height Vertical number of Pixels + * \tparam BufferWidth Horizontal (first) dimension of Buffer + * \tparam BufferHeight Vertical (first) dimension of Buffer + * + * \author Thomas Sommer + * \ingroup modm_ui_display + */ +template +class MonochromeGraphicDisplay : public GraphicDisplay +{ + static_assert(Width > 0, "width must be greater than 0"); + static_assert(Height > 0, "height must be greater than 0"); + +public: + virtual ~MonochromeGraphicDisplay() = default; + + inline uint16_t + getWidth() const final + { + return Width; + } + + inline uint16_t + getHeight() const final + { + return Height; + } + + inline std::size_t + getBufferWidth() const final + { + return BufferWidth; + } + + inline std::size_t + getBufferHeight() const final + { + return BufferHeight; + } + + virtual bool + getPixel(int16_t x, int16_t y) const = 0; + + void + clear() final; + +protected: + uint8_t buffer[BufferWidth][BufferHeight]; +}; +} // namespace modm + +#include "monochrome_graphic_display_impl.hpp" + +#endif // MODM_MONOCHROME_GRAPHIC_DISPLAY_HPP \ No newline at end of file diff --git a/src/modm/ui/display/monochrome_graphic_display_buffered_horizontal.hpp b/src/modm/ui/display/monochrome_graphic_display_buffered_horizontal.hpp deleted file mode 100644 index 08b5da318e..0000000000 --- a/src/modm/ui/display/monochrome_graphic_display_buffered_horizontal.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2019, Fabian Greif - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_BUFFERED_HORIZONTAL_HPP -#define MODM_MONOCHROME_GRAPHIC_DISPLAY_BUFFERED_HORIZONTAL_HPP - -#include - -#include - -namespace modm -{ -/** - * Base class for monochrome graphical displays with a RAM buffer. - * - * The pixel are compressed horizontally, this means that 8 pixel in - * y-direction are combined into one byte in the RAM buffer. - * - * Every operation works on the internal RAM buffer, therefore the content - * of the real display is not changed until a call of update(). - * - * \tparam Width Width of the display. Must be a multiple of 8! - * \tparam Height Height of the display. - * - * \ingroup modm_ui_display - */ -template -class MonochromeGraphicDisplayBufferedHorizontal : public GraphicDisplay -{ - // Height must be a multiple of 8 - static_assert((Width % 8) == 0, "width must be a multiple of 8"); - - static_assert(Width > 0, "width must be greater than 0"); - static_assert(Height > 0, "height must be greater than 0"); - -public: - static constexpr int16_t displayBufferWidth = Width / 8; - static constexpr int16_t displayBufferHeight = Height; - - virtual ~MonochromeGraphicDisplayBufferedHorizontal() = default; - - virtual inline uint16_t - getWidth() const override - { - return Width; - } - - virtual inline uint16_t - getHeight() const override - { - return Height; - } - - virtual void - clear() override; - -protected: - virtual void - setPixel(int16_t x, int16_t y) override; - - virtual void - clearPixel(int16_t x, int16_t y) override; - - virtual bool - getPixel(int16_t x, int16_t y) override; - - uint8_t mDisplayBuffer[displayBufferHeight][displayBufferWidth]; -}; -} // namespace modm - -#include "monochrome_graphic_display_buffered_horizontal_impl.hpp" - -#endif diff --git a/src/modm/ui/display/monochrome_graphic_display_buffered_horizontal_impl.hpp b/src/modm/ui/display/monochrome_graphic_display_buffered_horizontal_impl.hpp deleted file mode 100644 index 6c203329bd..0000000000 --- a/src/modm/ui/display/monochrome_graphic_display_buffered_horizontal_impl.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2019, Fabian Greif - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include "monochrome_graphic_display_buffered_horizontal.hpp" - -namespace modm -{ -template -void -MonochromeGraphicDisplayBufferedHorizontal::clear() -{ - for (int_fast16_t y = 0; y < displayBufferHeight; ++y) - { - for (int_fast16_t x = 0; x < displayBufferWidth; ++x) - { - mDisplayBuffer[y][x] = 0; - } - } - - // reset the cursor - this->cursor = glcd::Point(0, 0); -} - -template -void -MonochromeGraphicDisplayBufferedHorizontal::setPixel(int16_t x, int16_t y) -{ - if ((x < Width) && (y < Height)) - { - mDisplayBuffer[y][x / 8] |= (1 << (x & 0x07)); - } -} - -template -void -MonochromeGraphicDisplayBufferedHorizontal::clearPixel(int16_t x, int16_t y) -{ - if ((x < Width) && (y < Height)) - { - mDisplayBuffer[y][x / 8] &= ~(1 << (x & 0x07)); - } -} - -template -bool -MonochromeGraphicDisplayBufferedHorizontal::getPixel(int16_t x, int16_t y) -{ - if ((x < Width) && (y < Height)) - { - return (mDisplayBuffer[y][x / 8] & (1 << (x & 0x07))); - } - else - { - return false; - } -} -} // namespace modm diff --git a/src/modm/ui/display/monochrome_graphic_display_buffered_vertical.hpp b/src/modm/ui/display/monochrome_graphic_display_buffered_vertical.hpp deleted file mode 100644 index a5979e6b38..0000000000 --- a/src/modm/ui/display/monochrome_graphic_display_buffered_vertical.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2009, Georgi Grinshpun - * Copyright (c) 2009-2011, 2013, 2019, Fabian Greif - * Copyright (c) 2010, Martin Rosekeit - * Copyright (c) 2011, Thorsten Lajewski - * Copyright (c) 2012-2015, Niklas Hauser - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_BUFFERED_VERTICAL_HPP -#define MODM_MONOCHROME_GRAPHIC_DISPLAY_BUFFERED_VERTICAL_HPP - -#include "graphic_display.hpp" - -#include - -namespace modm -{ -/** - * Base class for graphical displays with a RAM buffer. - * - * Every operation works on the internal RAM buffer, therefore the content - * of the real display is not changed until a call of update(). - * - * \tparam Width Width of the display. - * \tparam Height Height of the display. Must be a multiple of 8! - * - * \author Fabian Greif - * \ingroup modm_ui_display - */ -template -class MonochromeGraphicDisplayBufferedVertical : public GraphicDisplay -{ - // Height must be a multiple of 8 - static_assert((Height % 8) == 0, "height must be a multiple of 8"); - - static_assert(Width > 0, "width must be greater than 0"); - static_assert(Height > 0, "height must be greater than 0"); - -public: - static constexpr int16_t displayBufferWidth = Width; - static constexpr int16_t displayBufferHeight = Height / 8; - - virtual ~MonochromeGraphicDisplayBufferedVertical() = default; - - virtual inline uint16_t - getWidth() const override - { - return Width; - } - - virtual inline uint16_t - getHeight() const override - { - return Height; - } - - /** - * \brief Clear the complete screen - * - * Use fillRectangle() to clear certain areas of the screen. - */ - virtual void - clear() override; - - // Faster version adapted for the RAM buffer - virtual void - drawImageRaw(glcd::Point upperLeft, - uint16_t width, - uint16_t height, - modm::accessor::Flash data) override; - -protected: - // Faster version adapted for the RAM buffer - virtual void - drawHorizontalLine(glcd::Point start, uint16_t length) override; - - // TODO Faster version adapted for the RAM buffer - // virtual void - // drawVerticalLine(glcd::Point start, uint8_t length); - - virtual void - setPixel(int16_t x, int16_t y) override; - - virtual void - clearPixel(int16_t x, int16_t y) override; - - virtual bool - getPixel(int16_t x, int16_t y) override; - - uint8_t display_buffer[displayBufferWidth][displayBufferHeight]; -}; -} // namespace modm - -#include "monochrome_graphic_display_buffered_vertical_impl.hpp" - -#endif // MODM_GRAPHIC_DISPLAY_HPP diff --git a/src/modm/ui/display/monochrome_graphic_display_buffered_vertical_impl.hpp b/src/modm/ui/display/monochrome_graphic_display_buffered_vertical_impl.hpp deleted file mode 100644 index 418a28edc6..0000000000 --- a/src/modm/ui/display/monochrome_graphic_display_buffered_vertical_impl.hpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2009-2011, 2013, 2019, Fabian Greif - * Copyright (c) 2011, Martin Rosekeit - * Copyright (c) 2012-2013, Niklas Hauser - * Copyright (c) 2016, Antal Szabó - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_BUFFERED_VERTICAL_IMPL_HPP -#define MODM_MONOCHROME_GRAPHIC_DISPLAY_BUFFERED_VERTICAL_IMPL_HPP - -#include "monochrome_graphic_display_buffered_vertical.hpp" - -template -void -modm::MonochromeGraphicDisplayBufferedVertical::clear() -{ - for (int_fast16_t y = 0; y < Height / 8; ++y) - { - for (int_fast16_t x = 0; x < Width; ++x) - { - this->display_buffer[x][y] = 0; - } - } - - // reset the cursor - this->cursor = glcd::Point(0, 0); -} - -template -void -modm::MonochromeGraphicDisplayBufferedVertical::drawHorizontalLine(glcd::Point start, - uint16_t length) -{ - const int16_t y = start.getY() / 8; - - if (this->foregroundColor == glcd::Color::black()) - { - const uint8_t mask = 1 << (start.getY() & 0x07); - for (int_fast16_t x = start.getX(); x < static_cast(start.getX() + length); ++x) - { - if (x < Width && y < Height) - { - this->display_buffer[x][y] |= mask; - } - } - } - else - { - const uint8_t mask = ~(1 << (start.getY() & 0x07)); - for (int_fast16_t x = start.getX(); x < static_cast(start.getX() + length); ++x) - { - if (x < Width && y < Height) - { - this->display_buffer[x][y] &= mask; - } - } - } -} - -template -void -modm::MonochromeGraphicDisplayBufferedVertical::drawImageRaw( - glcd::Point upperLeft, uint16_t width, uint16_t height, modm::accessor::Flash data) -{ - if ((upperLeft.getY() & 0x07) == 0) - { - uint16_t row = upperLeft.getY() / 8; - uint16_t rowCount = (height + 7) / 8; // always round up - - if ((height & 0x07) == 0) - { - for (uint_fast16_t i = 0; i < width; i++) - { - for (uint_fast16_t k = 0; k < rowCount; k++) - { - uint16_t x = upperLeft.getX() + i; - uint16_t y = k + row; - - if (x < Width && y < Height) - { - this->display_buffer[x][y] = data[i + k * width]; - } - } - } - return; - } - } - - GraphicDisplay::drawImageRaw(upperLeft, width, height, data); -} - -template -void -modm::MonochromeGraphicDisplayBufferedVertical::setPixel(int16_t x, int16_t y) -{ - if (x < Width && y < Height) - { - this->display_buffer[x][y / 8] |= (1 << (y & 0x07)); - } -} - -template -void -modm::MonochromeGraphicDisplayBufferedVertical::clearPixel(int16_t x, int16_t y) -{ - if (x < Width && y < Height) - { - this->display_buffer[x][y / 8] &= ~(1 << (y & 0x07)); - } -} - -template -bool -modm::MonochromeGraphicDisplayBufferedVertical::getPixel(int16_t x, int16_t y) -{ - if (x < Width && y < Height) - { - return (this->display_buffer[x][y / 8] & (1 << (y & 0x07))); - } - else - { - return false; - } -} - -#endif diff --git a/src/modm/ui/display/monochrome_graphic_display_horizontal.hpp b/src/modm/ui/display/monochrome_graphic_display_horizontal.hpp new file mode 100644 index 0000000000..43ce0be339 --- /dev/null +++ b/src/modm/ui/display/monochrome_graphic_display_horizontal.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019, Fabian Greif + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_HORIZONTAL_HPP +#define MODM_MONOCHROME_GRAPHIC_DISPLAY_HORIZONTAL_HPP + +#include + +#include "monochrome_graphic_display.hpp" + +namespace modm +{ +/** + * Base class for monochrome graphical displays with a RAM buffer. + * + * The pixel are compressed horizontally, this means that 8 pixel in + * y-direction are combined into one byte in the RAM buffer. + * + * Every operation works on the internal RAM buffer, therefore the content + * of the real display is not changed until a call of update(). + * + * \tparam Width Width of the display. Must be a multiple of 8! + * \tparam Height Height of the display. + * + * \ingroup modm_ui_display + */ +template +class MonochromeGraphicDisplayHorizontal + : public MonochromeGraphicDisplay +{ + // Height must be a multiple of 8 + static_assert((Width % 8) == 0, "width must be a multiple of 8"); + +public: + virtual ~MonochromeGraphicDisplayHorizontal() = default; + +protected: + void + setPixel(int16_t x, int16_t y) final; + + void + clearPixel(int16_t x, int16_t y) final; + + bool + getPixel(int16_t x, int16_t y) const final; +}; +} // namespace modm + +#include "monochrome_graphic_display_horizontal_impl.hpp" + +#endif // MODM_MONOCHROME_GRAPHIC_DISPLAY_HORIZONTAL_HPP diff --git a/src/modm/ui/display/monochrome_graphic_display_horizontal_impl.hpp b/src/modm/ui/display/monochrome_graphic_display_horizontal_impl.hpp new file mode 100644 index 0000000000..41fe64fd38 --- /dev/null +++ b/src/modm/ui/display/monochrome_graphic_display_horizontal_impl.hpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019, Fabian Greif + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_HORIZONTAL_HPP +#error "Don't include this file directly, use 'monochrome_graphic_display_horizontal.hpp' instead!" +#endif + +namespace modm +{ +template +void +MonochromeGraphicDisplayHorizontal::setPixel(int16_t x, int16_t y) +{ + if ((x < Width) and (y < Height)) { buffer[y][x / 8] |= (1 << (x % 8)); } +} + +template +void +MonochromeGraphicDisplayHorizontal::clearPixel(int16_t x, int16_t y) +{ + if ((x < Width) and (y < Height)) { buffer[y][x / 8] &= ~(1 << (x % 8)); } +} + +template +bool +MonochromeGraphicDisplayHorizontal::getPixel(int16_t x, int16_t y) +{ + if ((x < Width) and (y < Height)) + return (buffer[y][x / 8] & (1 << (x % 8))); + else + return false; +} +} // namespace modm diff --git a/src/modm/ui/display/monochrome_graphic_display_impl.hpp b/src/modm/ui/display/monochrome_graphic_display_impl.hpp new file mode 100644 index 0000000000..53adb5f429 --- /dev/null +++ b/src/modm/ui/display/monochrome_graphic_display_impl.hpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2009-2011, 2013, 2019, Fabian Greif + * Copyright (c) 2011, Martin Rosekeit + * Copyright (c) 2012-2013, Niklas Hauser + * Copyright (c) 2016, Antal Szabó + * Copyright (c) 2021, Thomas Sommer + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_HPP +#error "Don't include this file directly, use 'monochrome_graphic_display.hpp' instead!" +#endif + +template +void +modm::MonochromeGraphicDisplay::clear() +{ + std::fill(&buffer[0][0], &buffer[BufferWidth][BufferHeight], 0); + this->cursor = glcd::Point(0, 0); +} \ No newline at end of file diff --git a/src/modm/ui/display/monochrome_graphic_display_vertical.hpp b/src/modm/ui/display/monochrome_graphic_display_vertical.hpp new file mode 100644 index 0000000000..3377d476b9 --- /dev/null +++ b/src/modm/ui/display/monochrome_graphic_display_vertical.hpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2009, Georgi Grinshpun + * Copyright (c) 2009-2011, 2013, 2019, Fabian Greif + * Copyright (c) 2010, Martin Rosekeit + * Copyright (c) 2011, Thorsten Lajewski + * Copyright (c) 2012-2015, Niklas Hauser + * Copyright (c) 2021, Thomas Sommer + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_VERTICAL_HPP +#define MODM_MONOCHROME_GRAPHIC_DISPLAY_VERTICAL_HPP + +#include + +#include "monochrome_graphic_display.hpp" + +namespace modm +{ +/** + * Base class for graphical displays with a RAM buffer. + * + * Every operation works on the internal RAM buffer, therefore the content + * of the real display is not changed until a call of update(). + * + * \tparam Width Width of the display. + * \tparam Height Height of the display. Must be a multiple of 8! + * + * \author Fabian Greif + * \ingroup modm_ui_display + */ +template +class MonochromeGraphicDisplayVertical + : public MonochromeGraphicDisplay +{ + static_assert((Height % 8) == 0, "height must be a multiple of 8"); + +public: + virtual ~MonochromeGraphicDisplayVertical() = default; + + // Faster version adapted for the RAM buffer + void + drawImageRaw(glcd::Point start, uint16_t width, uint16_t height, + modm::accessor::Flash data) final; + + void + setPixel(int16_t x, int16_t y) final; + + void + clearPixel(int16_t x, int16_t y) final; + + bool + getPixel(int16_t x, int16_t y) const final; + +protected: + // Faster version adapted for the RAM buffer + void + drawHorizontalLine(glcd::Point start, uint16_t length) final; + + // Faster version adapted for the RAM buffer + void + drawVerticalLine(glcd::Point start, uint16_t length) final; +}; +} // namespace modm + +#include "monochrome_graphic_display_vertical_impl.hpp" + +#endif // MODM_MONOCHROME_GRAPHIC_DISPLAY_VERTICAL_HPP diff --git a/src/modm/ui/display/monochrome_graphic_display_vertical_impl.hpp b/src/modm/ui/display/monochrome_graphic_display_vertical_impl.hpp new file mode 100644 index 0000000000..3384a1c029 --- /dev/null +++ b/src/modm/ui/display/monochrome_graphic_display_vertical_impl.hpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2009-2011, 2013, 2019, Fabian Greif + * Copyright (c) 2011, Martin Rosekeit + * Copyright (c) 2012-2013, Niklas Hauser + * Copyright (c) 2016, Antal Szabó + * Copyright (c) 2021, Thomas Sommer + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef MODM_MONOCHROME_GRAPHIC_DISPLAY_VERTICAL_HPP +#error "Don't include this file directly, use 'monochrome_graphic_display_vertical.hpp' instead!" +#endif + +template +void +modm::MonochromeGraphicDisplayVertical::drawHorizontalLine(glcd::Point start, + uint16_t length) +{ + if (start.y >= 0 and start.y < Height) + { + const int16_t y = start.y / 8; + + // TODO Implement draw / clear pixels for monochrome displays + // if (draw mode) + // { + const uint8_t byte = 1 << (start.y % 8); + for (int_fast16_t x = start.x; x < static_cast(start.x + length); ++x) + { + if (x < Width) { this->buffer[x][y] |= byte; } + } + // } else + // { + // const uint8_t byte = ~(1 << (start.y % 8)); + // for (int_fast16_t x = start.x; x < static_cast(start.x + length); + // ++x) + // { + // if (x < Width and y < Height) { this->buffer[x][y] &= byte; } + // } + // } + } +} + +template +void +modm::MonochromeGraphicDisplayVertical::drawVerticalLine(glcd::Point start, + uint16_t length) +{ + if (start.x >= 0 and start.x < Width) + { + const int8_t end_y = start.y + length; + const uint8_t y_last = end_y / 8; + + uint_fast8_t y = start.y / 8; + // Mask out start + uint_fast8_t byte = 0xFF << start.y % 8; + while (y != y_last) + { + if (y < Height / 8) + { + this->buffer[start.x][y] |= byte; + byte = 0xFF; + } + y++; + } + // Mask out end + if (y < Height / 8) + { + byte &= 0xFF >> (8 - end_y % 8); + this->buffer[start.x][y] |= byte; + } + } +} + +template +void +modm::MonochromeGraphicDisplayVertical::drawImageRaw( + glcd::Point start, uint16_t width, uint16_t height, modm::accessor::Flash data) +{ + if ((start.y % 8) == 0) + { + uint16_t row = start.y / 8; + uint16_t rowCount = (height + 7) / 8; // always round up + + if ((height % 8) == 0) + { + for (uint_fast16_t i = 0; i < width; i++) + { + for (uint_fast16_t k = 0; k < rowCount; k++) + { + uint16_t x = start.x + i; + uint16_t y = k + row; + + if (x < Width and y < Height) + { + this->buffer[x][y] = data[i + k * width]; + } + } + } + return; + } + } + + GraphicDisplay::drawImageRaw(start, width, height, data); +} + +template +void +modm::MonochromeGraphicDisplayVertical::setPixel(int16_t x, int16_t y) +{ + if (x < Width and y < Height) { this->buffer[x][y / 8] |= (1 << y % 8); } +} + +template +void +modm::MonochromeGraphicDisplayVertical::clearPixel(int16_t x, int16_t y) +{ + if (x < Width and y < Height) { this->buffer[x][y / 8] &= ~(1 << y % 8); } +} + +template +bool +modm::MonochromeGraphicDisplayVertical::getPixel(int16_t x, int16_t y) const +{ + if (x < Width and y < Height) + { + return (this->buffer[x][y / 8] & (1 << y % 8)); + } else + { + return false; + } +} \ No newline at end of file diff --git a/src/modm/ui/display/virtual_graphic_display.cpp b/src/modm/ui/display/virtual_graphic_display.cpp index 3e7e10a16c..b86a4b6438 100644 --- a/src/modm/ui/display/virtual_graphic_display.cpp +++ b/src/modm/ui/display/virtual_graphic_display.cpp @@ -12,7 +12,7 @@ #include "virtual_graphic_display.hpp" -modm::VirtualGraphicDisplay::VirtualGraphicDisplay(modm::GraphicDisplay* display, +modm::VirtualGraphicDisplay::VirtualGraphicDisplay(modm::ColorGraphicDisplay* display, modm::glcd::Point leftUpper, modm::glcd::Point rightLower): display(display), leftUpper(leftUpper), rightLower(rightLower), width(static_cast(this->rightLower[0] - this->leftUpper[0])), @@ -21,7 +21,7 @@ modm::VirtualGraphicDisplay::VirtualGraphicDisplay(modm::GraphicDisplay* display } void -modm::VirtualGraphicDisplay::setDisplay(modm::GraphicDisplay* display) +modm::VirtualGraphicDisplay::setDisplay(modm::ColorGraphicDisplay* display) { this->display = display; return; @@ -55,8 +55,8 @@ modm::VirtualGraphicDisplay::clearPixel(int16_t x, int16_t y) this->display->clearPixel(x + this->leftUpper[0], y + this->leftUpper[1] ); } -bool -modm::VirtualGraphicDisplay::getPixel(int16_t x, int16_t y) +modm::glcd::Color +modm::VirtualGraphicDisplay::getPixel(int16_t x, int16_t y) const { return this->display->getPixel(x + this->leftUpper[0], y + this->leftUpper[1] ); -} +} \ No newline at end of file diff --git a/src/modm/ui/display/virtual_graphic_display.hpp b/src/modm/ui/display/virtual_graphic_display.hpp index b73363a1fe..4c2795bf50 100644 --- a/src/modm/ui/display/virtual_graphic_display.hpp +++ b/src/modm/ui/display/virtual_graphic_display.hpp @@ -16,59 +16,56 @@ #ifndef MODM_VIRTUAL_GRAPHIC_DISPLAY #define MODM_VIRTUAL_GRAPHIC_DISPLAY -#include +#include namespace modm { - /// @ingroup modm_ui_display - class VirtualGraphicDisplay: - public modm::GraphicDisplay - { - public: - VirtualGraphicDisplay(modm::GraphicDisplay* display, - modm::glcd::Point leftUpper, modm::glcd::Point rightLower); - - void - setDisplay(modm::GraphicDisplay* display); - - virtual inline uint16_t - getWidth() const - { - return this->width; - } +/// @ingroup modm_ui_display +class VirtualGraphicDisplay : public modm::ColorGraphicDisplay +{ +public: + VirtualGraphicDisplay(modm::ColorGraphicDisplay* display, modm::glcd::Point leftUpper, + modm::glcd::Point rightLower); - virtual inline uint16_t - getHeight() const - { - return this->height; - } + void + setDisplay(modm::ColorGraphicDisplay* display); - virtual void - clear(); + virtual inline uint16_t + getWidth() const + { + return this->width; + } - virtual void - update(); + virtual inline uint16_t + getHeight() const + { + return this->height; + } - protected: + virtual void + clear(); - virtual void - setPixel(int16_t x, int16_t y); + virtual void + update(); - virtual void - clearPixel(int16_t x, int16_t y); +protected: + void + setPixel(int16_t x, int16_t y) final; - virtual bool - getPixel(int16_t x, int16_t y); + void + clearPixel(int16_t x, int16_t y) final; - private: - modm::GraphicDisplay* display; - modm::glcd::Point leftUpper; - modm::glcd::Point rightLower; - const uint16_t width; - const uint16_t height; - }; + glcd::Color + getPixel(int16_t x, int16_t y) const final; +private: + modm::ColorGraphicDisplay* display; + modm::glcd::Point leftUpper; + modm::glcd::Point rightLower; + const uint16_t width; + const uint16_t height; +}; -} +} // namespace modm -#endif //MODM_VIRTUAL_GRAPHIC_DISPLAY +#endif // MODM_VIRTUAL_GRAPHIC_DISPLAY diff --git a/src/modm/ui/gui/colorpalette.hpp b/src/modm/ui/gui/colorpalette.hpp index 759cda205f..078253c3fb 100644 --- a/src/modm/ui/gui/colorpalette.hpp +++ b/src/modm/ui/gui/colorpalette.hpp @@ -15,7 +15,7 @@ #ifndef MODM_GUI_COLORPALETTE_HPP #define MODM_GUI_COLORPALETTE_HPP -#include +#include namespace modm diff --git a/src/modm/ui/gui/view.hpp b/src/modm/ui/gui/view.hpp index a161a47002..69d02fcca3 100644 --- a/src/modm/ui/gui/view.hpp +++ b/src/modm/ui/gui/view.hpp @@ -18,7 +18,7 @@ #ifndef MODM_GUI_VIEW_HPP #define MODM_GUI_VIEW_HPP -#include +#include #include "types.hpp" #include "widgets/widget.hpp" diff --git a/src/modm/ui/gui/view_stack.cpp b/src/modm/ui/gui/view_stack.cpp index ad0cbe1333..de116a93fc 100644 --- a/src/modm/ui/gui/view_stack.cpp +++ b/src/modm/ui/gui/view_stack.cpp @@ -19,7 +19,7 @@ #include "view_stack.hpp" // ---------------------------------------------------------------------------- -modm::gui::GuiViewStack::GuiViewStack(modm::GraphicDisplay* display, modm::gui::inputQueue* queue) : +modm::gui::GuiViewStack::GuiViewStack(modm::ColorGraphicDisplay* display, modm::gui::inputQueue* queue) : ViewStack(display), input_queue(queue) { diff --git a/src/modm/ui/gui/view_stack.hpp b/src/modm/ui/gui/view_stack.hpp index 48b5e88390..308ce0085d 100644 --- a/src/modm/ui/gui/view_stack.hpp +++ b/src/modm/ui/gui/view_stack.hpp @@ -18,7 +18,7 @@ #ifndef MODM_GUI_VIEWSTACK_HPP #define MODM_GUI_VIEWSTACK_HPP -#include +#include #include #include #include @@ -44,7 +44,7 @@ namespace gui class GuiViewStack : public modm::ViewStack { public: - GuiViewStack(modm::GraphicDisplay* display, modm::gui::inputQueue* queue); + GuiViewStack(modm::ColorGraphicDisplay* display, modm::gui::inputQueue* queue); virtual ~GuiViewStack(); diff --git a/src/modm/ui/gui/widgets/button.cpp b/src/modm/ui/gui/widgets/button.cpp index 1ca4504090..e4c2f2996c 100644 --- a/src/modm/ui/gui/widgets/button.cpp +++ b/src/modm/ui/gui/widgets/button.cpp @@ -20,7 +20,7 @@ modm::gui::ButtonWidget::render(View* view) return; // output device of view - modm::GraphicDisplay* out = &view->display(); + modm::ColorGraphicDisplay* out = &view->display(); // color palette of view ColorPalette cp = this->color_palette; @@ -56,8 +56,8 @@ modm::gui::ButtonWidget::render(View* view) * TODO: center text */ - const uint16_t stringWidth = modm::GraphicDisplay::getStringWidth(this->label, &(this->font)); - const uint16_t stringHeight = modm::GraphicDisplay::getFontHeight(&(this->font)); + const uint16_t stringWidth = modm::ColorGraphicDisplay::getStringWidth(this->label, &(this->font)); + const uint16_t stringHeight = modm::ColorGraphicDisplay::getFontHeight(&(this->font)); if(this->font.isValid()) out->setFont(&(this->font)); @@ -74,7 +74,7 @@ modm::gui::ArrowButton::render(View* view) return; // output device of view - modm::GraphicDisplay* out = &view->display(); + modm::ColorGraphicDisplay* out = &view->display(); // color palette of view ColorPalette cp = this->color_palette; @@ -127,7 +127,7 @@ modm::gui::FilledAreaButton::render(View* view) return; // output device of view - modm::GraphicDisplay* out = &view->display(); + modm::ColorGraphicDisplay* out = &view->display(); // position and dimensions const uint16_t x = this->getPosition().x; diff --git a/src/modm/ui/gui/widgets/checkbox.cpp b/src/modm/ui/gui/widgets/checkbox.cpp index 83171b62ee..53a182ccb8 100644 --- a/src/modm/ui/gui/widgets/checkbox.cpp +++ b/src/modm/ui/gui/widgets/checkbox.cpp @@ -23,7 +23,7 @@ modm::gui::CheckboxWidget::render(View* view) constexpr uint16_t padding = 5; // output device of view - modm::GraphicDisplay* out = &view->display(); + modm::ColorGraphicDisplay* out = &view->display(); // color palette of view ColorPalette cp = this->color_palette; diff --git a/src/modm/ui/gui/widgets/label.cpp b/src/modm/ui/gui/widgets/label.cpp index 0179e87b4e..1527f1e965 100644 --- a/src/modm/ui/gui/widgets/label.cpp +++ b/src/modm/ui/gui/widgets/label.cpp @@ -21,7 +21,7 @@ modm::gui::Label::render(View* view) return; // output device of view - modm::GraphicDisplay* out = &view->display(); + modm::ColorGraphicDisplay* out = &view->display(); out->setColor(color); diff --git a/src/modm/ui/gui/widgets/label.hpp b/src/modm/ui/gui/widgets/label.hpp index 2329fb32f9..06dbce9685 100644 --- a/src/modm/ui/gui/widgets/label.hpp +++ b/src/modm/ui/gui/widgets/label.hpp @@ -76,8 +76,8 @@ class Label : public Widget // Update label dimension if(this->font.isValid()) { - this->dimension.width = modm::GraphicDisplay::getStringWidth(this->label, &(this->font)); - this->dimension.height = modm::GraphicDisplay::getFontHeight(&(this->font)); + this->dimension.width = modm::ColorGraphicDisplay::getStringWidth(this->label, &(this->font)); + this->dimension.height = modm::ColorGraphicDisplay::getFontHeight(&(this->font)); } } diff --git a/src/modm/ui/gui/widgets/numberfield.cpp b/src/modm/ui/gui/widgets/numberfield.cpp index ffdc491235..d8b12fa972 100644 --- a/src/modm/ui/gui/widgets/numberfield.cpp +++ b/src/modm/ui/gui/widgets/numberfield.cpp @@ -27,7 +27,7 @@ modm::gui::FloatField::render(View* view) return; // output device of view - modm::GraphicDisplay* out = &view->display(); + modm::ColorGraphicDisplay* out = &view->display(); // color palette of view ColorPalette cp = this->color_palette; diff --git a/src/modm/ui/gui/widgets/numberfield_impl.hpp b/src/modm/ui/gui/widgets/numberfield_impl.hpp index c64c23c352..d6d02177a2 100644 --- a/src/modm/ui/gui/widgets/numberfield_impl.hpp +++ b/src/modm/ui/gui/widgets/numberfield_impl.hpp @@ -23,7 +23,7 @@ modm::gui::NumberField::render(View* view) return; // output device of view - modm::GraphicDisplay* out = &view->display(); + modm::ColorGraphicDisplay* out = &view->display(); // color palette of view ColorPalette cp = this->color_palette; diff --git a/src/modm/ui/gui/widgets/stringfield.cpp b/src/modm/ui/gui/widgets/stringfield.cpp index 02aae1ad05..d3928862a7 100644 --- a/src/modm/ui/gui/widgets/stringfield.cpp +++ b/src/modm/ui/gui/widgets/stringfield.cpp @@ -22,7 +22,7 @@ modm::gui::StringField::render(View* view) return; // output device of view - modm::GraphicDisplay* out = &view->display(); + modm::ColorGraphicDisplay* out = &view->display(); // color palette of view ColorPalette cp = this->color_palette; diff --git a/src/modm/ui/gui/widgets/widget.hpp b/src/modm/ui/gui/widgets/widget.hpp index 6dd68c4c56..3b6c812ab7 100644 --- a/src/modm/ui/gui/widgets/widget.hpp +++ b/src/modm/ui/gui/widgets/widget.hpp @@ -15,7 +15,7 @@ #ifndef MODM_GUI_WIDGET_HPP #define MODM_GUI_WIDGET_HPP -#include +#include #include #include diff --git a/src/modm/ui/menu/abstract_view.cpp b/src/modm/ui/menu/abstract_view.cpp index d39b8d9d59..96b5ba6e05 100644 --- a/src/modm/ui/menu/abstract_view.cpp +++ b/src/modm/ui/menu/abstract_view.cpp @@ -61,7 +61,7 @@ modm::AbstractView::onRemove() // ---------------------------------------------------------------------------- -modm::GraphicDisplay& +modm::ColorGraphicDisplay& modm::AbstractView::display() { return stack->getDisplay(); diff --git a/src/modm/ui/menu/abstract_view.hpp b/src/modm/ui/menu/abstract_view.hpp index 5c8da4d7e9..42a141d5ec 100644 --- a/src/modm/ui/menu/abstract_view.hpp +++ b/src/modm/ui/menu/abstract_view.hpp @@ -17,7 +17,7 @@ #ifndef MODM_ABSTRACT_VIEW_HPP #define MODM_ABSTRACT_VIEW_HPP -#include +#include #include "menu_buttons.hpp" @@ -99,7 +99,7 @@ namespace modm public: - modm::GraphicDisplay& + modm::ColorGraphicDisplay& display(); /** diff --git a/src/modm/ui/menu/choice_menu.cpp b/src/modm/ui/menu/choice_menu.cpp index a4dac6972c..d8cb4a192c 100644 --- a/src/modm/ui/menu/choice_menu.cpp +++ b/src/modm/ui/menu/choice_menu.cpp @@ -72,7 +72,7 @@ modm::ChoiceMenu::setTitle(const char* text) void modm::ChoiceMenu::draw() { - modm::GraphicDisplay* display = &getViewStack()->getDisplay(); + modm::ColorGraphicDisplay* display = &getViewStack()->getDisplay(); display->clear(); display->setCursor(0,2); (*display) << this->title; diff --git a/src/modm/ui/menu/communicating_view_stack.hpp b/src/modm/ui/menu/communicating_view_stack.hpp index 77a6933266..9f1c5cf7ed 100644 --- a/src/modm/ui/menu/communicating_view_stack.hpp +++ b/src/modm/ui/menu/communicating_view_stack.hpp @@ -29,7 +29,7 @@ namespace modm class CommunicatingViewStack : public ViewStack { public: - CommunicatingViewStack(modm::GraphicDisplay* display, xpcc::Communicator* communicator) : + CommunicatingViewStack(modm::ColorGraphicDisplay* display, xpcc::Communicator* communicator) : ViewStack(display), communicator(communicator) { diff --git a/src/modm/ui/menu/standard_menu.cpp b/src/modm/ui/menu/standard_menu.cpp index 2e606597e3..892f075a7b 100644 --- a/src/modm/ui/menu/standard_menu.cpp +++ b/src/modm/ui/menu/standard_menu.cpp @@ -64,7 +64,7 @@ modm::StandardMenu::setTitle(const char* text) void modm::StandardMenu::draw() { - modm::GraphicDisplay* display = &getViewStack()->getDisplay(); + modm::ColorGraphicDisplay* display = &getViewStack()->getDisplay(); display->clear(); display->setCursor(0,2); (*display) << this->title; diff --git a/src/modm/ui/menu/view_stack.cpp b/src/modm/ui/menu/view_stack.cpp index 47b311696b..f133ecffbe 100644 --- a/src/modm/ui/menu/view_stack.cpp +++ b/src/modm/ui/menu/view_stack.cpp @@ -17,7 +17,7 @@ #include "view_stack.hpp" // ---------------------------------------------------------------------------- -modm::ViewStack::ViewStack(modm::GraphicDisplay* display) : +modm::ViewStack::ViewStack(modm::ColorGraphicDisplay* display) : display(display) { } diff --git a/src/modm/ui/menu/view_stack.hpp b/src/modm/ui/menu/view_stack.hpp index 0ed1f04ad4..188e884af8 100644 --- a/src/modm/ui/menu/view_stack.hpp +++ b/src/modm/ui/menu/view_stack.hpp @@ -39,7 +39,7 @@ namespace modm class ViewStack { public: - ViewStack(modm::GraphicDisplay* display); + ViewStack(modm::ColorGraphicDisplay* display); virtual ~ViewStack(); @@ -74,7 +74,7 @@ namespace modm /** * @brief getDisplay access underlying GraphicDisplay */ - inline modm::GraphicDisplay& + inline modm::ColorGraphicDisplay& getDisplay() { return *this->display; @@ -100,7 +100,7 @@ namespace modm shortButtonPress(modm::MenuButtons::Button button); protected: - modm::GraphicDisplay* display; + modm::ColorGraphicDisplay* display; modm::Stack< modm::AbstractView* , modm::LinkedList< modm::AbstractView* > > stack; }; }