diff --git a/src/modm/driver/display/ili9341.hpp b/src/modm/driver/display/ili9341.hpp index c79996e0b1..9d4cf77e09 100644 --- a/src/modm/driver/display/ili9341.hpp +++ b/src/modm/driver/display/ili9341.hpp @@ -34,6 +34,7 @@ namespace modm /// @ingroup modm_driver_ili9341 template +// requires std::derived_from> class Ili9341 : public Interface, // : public RemotePainter, Interface>, public Display, Resolution<320, 240>, true>, @@ -99,11 +100,11 @@ class Ili9341 : public Interface, scrollTo(uint16_t row); // Write from Pattern (compiletime poly) - template + template // FIXME Concept not accepted - but why? // requires std::derived_from> modm::ResumableResult - writePattern(Rectangle rectangle, Pattern generator); + writePattern(Rectangle rectangle, P pattern); // Write equal colored Buffer (compiletime poly) template diff --git a/src/modm/driver/display/ili9341_impl.hpp b/src/modm/driver/display/ili9341_impl.hpp index 4b76897d38..180e06117d 100644 --- a/src/modm/driver/display/ili9341_impl.hpp +++ b/src/modm/driver/display/ili9341_impl.hpp @@ -237,9 +237,9 @@ modm::Ili9341::updateClipping() // -- Write from Pattern --------------------------------- template -template +template modm::ResumableResult -modm::Ili9341::writePattern(Rectangle rectangle, Pattern pattern) { +modm::Ili9341::writePattern(Rectangle rectangle, P pattern) { RF_BEGIN(); this->clipping = this->getIntersection(rectangle); diff --git a/src/modm/ui/color.hpp b/src/modm/ui/color.hpp index 3cf2670107..7f81221290 100644 --- a/src/modm/ui/color.hpp +++ b/src/modm/ui/color.hpp @@ -12,6 +12,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // ---------------------------------------------------------------------------- +#pragma once #include "color/rgb.hpp" #include "color/hsv.hpp" @@ -20,4 +21,8 @@ #include "color/rgb565.hpp" #include "color/rgbhtml.hpp" -#include "color/pattern.hpp" +namespace modm::color { + template + concept Color = requires + { std::convertible_to or std::is_same_v; }; +} \ No newline at end of file diff --git a/src/modm/ui/color/grayscale.hpp b/src/modm/ui/color/grayscale.hpp index b0172e911c..da6404ba0f 100644 --- a/src/modm/ui/color/grayscale.hpp +++ b/src/modm/ui/color/grayscale.hpp @@ -45,8 +45,6 @@ template class GrayscaleT { public: - static constexpr bool isColor = true; - T value{0}; constexpr GrayscaleT() = default; diff --git a/src/modm/ui/color/hsv.hpp b/src/modm/ui/color/hsv.hpp index 1ab1d87be7..0606091458 100644 --- a/src/modm/ui/color/hsv.hpp +++ b/src/modm/ui/color/hsv.hpp @@ -46,8 +46,6 @@ template class HsvT { public: - static constexpr bool isColor = true; - T hue{0}; T saturation{0}; T value{0}; diff --git a/src/modm/ui/color/pattern.hpp b/src/modm/ui/color/pattern.hpp index 813acb08c2..5a4fdb9e96 100644 --- a/src/modm/ui/color/pattern.hpp +++ b/src/modm/ui/color/pattern.hpp @@ -12,4 +12,13 @@ #pragma once #include "pattern/gradient.hpp" -#include "pattern/interference.hpp" \ No newline at end of file +#include "pattern/interference.hpp" + +#include "../shape.hpp" + +// TODO find a good place +template +concept ColorPattern = requires(P p) +{ + { p.operator()(modm::shape::Point()) } -> std::convertible_to; +}; \ No newline at end of file diff --git a/src/modm/ui/color/pattern/gradient.hpp b/src/modm/ui/color/pattern/gradient.hpp index 082007609d..2c2202a37e 100644 --- a/src/modm/ui/color/pattern/gradient.hpp +++ b/src/modm/ui/color/pattern/gradient.hpp @@ -12,31 +12,30 @@ #pragma once #include "pattern.hpp" +#include using namespace modm::shape; namespace modm::color { -template -requires C::isColor class Gradient +template +class Gradient : public BicolorPattern { protected: - Line line; - C start, end; + const Point direction; public: - constexpr Gradient() = default; - - constexpr Gradient(Line line, C start, C end) : line(line), start(start), end(end) {} + constexpr Gradient(C start, C end, Point direction = {1, 0}) + : BicolorPattern(start, end), direction(direction) {} constexpr C - operator()(Point position) + operator()(Point point) { // IMPLEMENT linear interpolate between start and end - // facilitating line and offset; - (void)position; - return start; + + // Creates a rainbow for now + return Hsv(point.x, 255, point.y); } }; } \ No newline at end of file diff --git a/src/modm/ui/color/pattern/interference.hpp b/src/modm/ui/color/pattern/interference.hpp index 77ae0df8ca..9c98995085 100644 --- a/src/modm/ui/color/pattern/interference.hpp +++ b/src/modm/ui/color/pattern/interference.hpp @@ -25,14 +25,14 @@ namespace modm::color namespace detail { template -class RectangularFunc +class RectFunc { protected: const T width; const modm::WideType period; public: - constexpr RectangularFunc(T low, T high) : width(low), period(low + high) {} + constexpr RectFunc(T low, T high) : width(low), period(low + high) {} constexpr bool operator()(modm::WideType input) @@ -41,100 +41,116 @@ class RectangularFunc } }; -// Preprocesses point.x and point.y with Preprocess -// Passes result to RectangularFunc -template -requires C::isColor -class PrePattern : public Pattern, protected RectangularFunc +/** + * @brief Generic Functor to generate a homogene 2D BicolorPattern + * Preprocess point.x and point.y with PreFn and pass result to RectFunc +* @tparam C Color + * @tparam PreFn Scalar Functor + */ +template +class PrePattern : public BicolorPattern, protected RectFunc { public: constexpr PrePattern(C odd, C even, uint8_t width) - : Pattern(odd, even), RectangularFunc(width, width) + : BicolorPattern(odd, even), RectFunc(width, width) {} constexpr PrePattern(C odd, C even, uint8_t low, uint8_t high) - : Pattern(odd, even), RectangularFunc(low, high) + : BicolorPattern(odd, even), RectFunc(low, high) {} constexpr C operator()(Point point) final { - return RectangularFunc::operator()(Preprocess()(point.x, point.y)) ? this->odd : this->even; + return RectFunc::operator()(PreFn()(point.x, point.y)) ? this->odd : this->even; } }; -// Takes results from passing point.x and point.y to RectangularFunc -// and Postprocesses with binary function Fn -template -requires C::isColor -class PostPattern : public Pattern, protected RectangularFunc +/** + * @brief Generic Functor to generate a homogene 2D BicolorPattern + * Pass point.x and point.y to RectFunc and Postprocess results with PostFn + * @tparam C Color + * @tparam PostFn Binary Functor + */ +template +class PostPattern : public BicolorPattern, protected RectFunc { public: constexpr PostPattern(C odd, C even, uint8_t width) - : Pattern(odd, even), RectangularFunc(width, width) + : BicolorPattern(odd, even), RectFunc(width, width) {} constexpr PostPattern(C odd, C even, uint8_t low, uint8_t high) - : Pattern(odd, even), RectangularFunc(low, high) + : BicolorPattern(odd, even), RectFunc(low, high) {} constexpr C operator()(Point point) final { // return odd; - bool h = RectangularFunc::operator()(point.x); - bool v = RectangularFunc::operator()(point.y); - return Postprocess()(h, v) ? this->odd : this->even; + bool h = RectFunc::operator()(point.x); + bool v = RectFunc::operator()(point.y); + return PostFn()(h, v) ? this->odd : this->even; } }; } // namespace detail using namespace detail; -// TODO I bet there's something out of the std-box +// TODO Bet there's a solution out of STL-box template struct takeX { - T operator() (const T&, const T& y) const {return y;} + constexpr T operator() (const T&, const T& y) const {return y;} +}; +template struct takeY { + constexpr T operator() (const T& x, const T&) const {return x;} }; -template +template class HorizontalStriped : public PrePattern> { public: using PrePattern>::PrePattern; }; -// TODO I bet there's something out of the std-box -template struct takeY { - T operator() (const T& x, const T&) const {return x;} -}; - -template +template class VerticalStriped : public PrePattern> { public: using PrePattern>::PrePattern; }; -template +template class FallingDiagonalStriped : public PrePattern> { public: using PrePattern>::PrePattern; }; -template +template class RisingDiagonalStriped : public PrePattern> { public: using PrePattern>::PrePattern; }; -template +template +class Checkerboard : public PostPattern> +{ public: using PostPattern>::PostPattern; }; +template +class Grid : public PostPattern> +{ public: using PostPattern>::PostPattern; }; + +// These are Try & Error. Some combinations produce beautiful results +template class MultiplyPattern : public PrePattern> { public: using PrePattern>::PrePattern; }; -template +template class DividePattern : public PrePattern> { public: using PrePattern>::PrePattern; }; -// Well, that's useless -template +template class ModulusPattern : public PrePattern> { public: using PrePattern>::PrePattern; }; -template -class Checkerboard : public PostPattern> -{ public: using PostPattern>::PostPattern; }; +template +class BitwiseAndPattern : public PrePattern> +{ public: using PrePattern>::PrePattern; }; + +template +class BitwiseOrPattern : public PrePattern> +{ public: using PrePattern>::PrePattern; }; + +template +class BitwiseXorPattern : public PrePattern> +{ public: using PrePattern>::PrePattern; }; -template -class Grid : public PostPattern> -{ public: using PostPattern>::PostPattern; }; } // namespace modm::color \ No newline at end of file diff --git a/src/modm/ui/color/pattern/mandelbrot.hpp b/src/modm/ui/color/pattern/mandelbrot.hpp new file mode 100644 index 0000000000..ff0ad1e6c7 --- /dev/null +++ b/src/modm/ui/color/pattern/mandelbrot.hpp @@ -0,0 +1,19 @@ +/* + * 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/. + */ +// ---------------------------------------------------------------------------- + +#pragma once + +namespace modm::color +{ + class MandelBrot { + + } +} \ No newline at end of file diff --git a/src/modm/ui/color/pattern/pattern.hpp b/src/modm/ui/color/pattern/pattern.hpp index c2a0ec8ed0..ae27d6f67a 100644 --- a/src/modm/ui/color/pattern/pattern.hpp +++ b/src/modm/ui/color/pattern/pattern.hpp @@ -4,20 +4,18 @@ namespace modm::color { - /** * @brief Unary Functor giving one of two colors for a Point * * @tparam C Type of Color to return */ -template -requires C::isColor -class Pattern +template +class BicolorPattern { protected: const C odd; const C even; - Pattern(C odd, C even) : odd(odd), even(even) {} + BicolorPattern(C odd, C even) : odd(odd), even(even) {} public: /** diff --git a/src/modm/ui/color/rgb.hpp b/src/modm/ui/color/rgb.hpp index a7f856a6eb..7304a0e192 100644 --- a/src/modm/ui/color/rgb.hpp +++ b/src/modm/ui/color/rgb.hpp @@ -51,8 +51,6 @@ template class RgbT { public: - static constexpr bool isColor = true; - T red{0}; T green{0}; T blue{0}; diff --git a/src/modm/ui/color/rgb565.hpp b/src/modm/ui/color/rgb565.hpp index 10a44dbdbe..997c6d9c98 100644 --- a/src/modm/ui/color/rgb565.hpp +++ b/src/modm/ui/color/rgb565.hpp @@ -42,8 +42,6 @@ template class Rgb565 { public: - static constexpr bool isColor = true; - uint16_t color{0x0000}; using RgbCalcType = RgbT; diff --git a/src/modm/ui/graphic/buffer.hpp b/src/modm/ui/graphic/buffer.hpp index a14cadd839..42c14e5c68 100644 --- a/src/modm/ui/graphic/buffer.hpp +++ b/src/modm/ui/graphic/buffer.hpp @@ -35,23 +35,21 @@ namespace modm */ // May inherit on modm::Matrix<..> or provide a conversion constructor for modm::Matrix<..> -template> -requires C::isColor or std::is_same_v -// and std::is_same -and std::derived_from> +template> +requires std::derived_from> class Buffer : public BufferInterface, public Painter, public TextPainter { public: Buffer() : BufferInterface(html::White) {}; // Copy construct from equal colored buffer of same size - template + template Buffer(const Buffer &other) : BufferInterface(other.color) { drawBufferFast(other); } // Copy construct from equal colored buffer of different size - template + template Buffer(const Buffer &other) : BufferInterface(other.color) { writeBuffer(other); } @@ -73,7 +71,7 @@ class Buffer : public BufferInterface, public Painter, public TextPainter return *this; } - template + template Buffer & operator=(const Buffer &other) { this->color = other.color; @@ -89,17 +87,17 @@ class Buffer : public BufferInterface, public Painter, public TextPainter } /** - * Write different colored, different sized buffer to origin + * Write colored buffer * - * @param other Other buffer + * @param other Other colored buffer * @param origin top left corner to copy to */ - template + template void writeBuffer(const Buffer &other, shape::Point origin = {0, 0}); /** - * Write monochrome Buffer with different size to origin + * Write monochrome Buffer * * @param other Other monochrome Buffer * @param origin top left corner to copy to @@ -109,6 +107,12 @@ class Buffer : public BufferInterface, public Painter, public TextPainter writeBuffer(const Buffer &other, shape::Point origin = {0, 0}); + /** + * Write monochrome Flash image + * + * @param other Monochrome Flash image + * @param origin top left corner to copy to + */ void writeFlash(modm::accessor::Flash data, uint16_t width, uint16_t height, shape::Point origin = {0, 0}) final; @@ -128,7 +132,7 @@ class Buffer : public BufferInterface, public Painter, public TextPainter /** * Buffer-manipulations - * CAUTION: No protection against segmentation errors! + * CAUTION: No protection against segmentation error! */ void drawFast(Point point) final; void drawFast(HLine hline) final; @@ -136,7 +140,7 @@ class Buffer : public BufferInterface, public Painter, public TextPainter void drawFast(Section section) final; private: - template + template void drawBufferFast(const Buffer &other); diff --git a/src/modm/ui/graphic/buffer_bool.hpp b/src/modm/ui/graphic/buffer_bool.hpp index 01c0eb61ee..639242396e 100644 --- a/src/modm/ui/graphic/buffer_bool.hpp +++ b/src/modm/ui/graphic/buffer_bool.hpp @@ -31,7 +31,6 @@ namespace modm * @ingroup modm_ui_graphic */ template -// requires std::is_same requires std::derived_from> class Buffer : public BufferInterface, public Painter, public TextPainter { @@ -96,7 +95,7 @@ class Buffer : public BufferInterface, public Painter, p /** * Buffer-manipulations - * CAUTION: No protection against segmentation errors! + * CAUTION: No protection against segmentation error! */ void drawFast(Point point) final; void drawFast(HLine hline) final; @@ -113,7 +112,7 @@ class Buffer : public BufferInterface, public Painter, p void drawBufferFast(const Buffer &other); - template + template friend class Buffer; }; diff --git a/src/modm/ui/graphic/buffer_impl.hpp b/src/modm/ui/graphic/buffer_impl.hpp index 5ef30384b2..723b676cea 100644 --- a/src/modm/ui/graphic/buffer_impl.hpp +++ b/src/modm/ui/graphic/buffer_impl.hpp @@ -27,8 +27,8 @@ using namespace modm::shape; // Copy buffer of same size -template -template +template +template void modm::Buffer::drawBufferFast( const Buffer &other) @@ -45,8 +45,8 @@ modm::Buffer::drawBufferFast( } // Write buffer (of different size) to position -template -template +template +template void modm::Buffer::writeBuffer( const Buffer &other, const Point origin) @@ -74,7 +74,7 @@ modm::Buffer::writeBuffer( } // Write monochrome Buffer (of different size) to position -template +template template void modm::Buffer::writeBuffer( @@ -115,7 +115,7 @@ modm::Buffer::writeBuffer( // --------------------------------------------------- -template +template void modm::Buffer::writeFlash(modm::accessor::Flash data, uint16_t width, uint16_t height, Point origin) @@ -143,14 +143,14 @@ modm::Buffer::writeFlash(modm::accessor::Flash data, } } -template +template void modm::Buffer::drawFast(Point point) { buffer[point.x][point.y] = this->color; } -template +template void modm::Buffer::drawFast(HLine hline) { @@ -161,7 +161,7 @@ modm::Buffer::drawFast(HLine hline) } } -template +template void modm::Buffer::drawFast(VLine vline) { @@ -172,7 +172,7 @@ modm::Buffer::drawFast(VLine vline) } } -template +template void modm::Buffer::drawFast(Section section) { @@ -186,7 +186,7 @@ modm::Buffer::drawFast(Section section) } } -template +template void modm::Buffer::clear(C color) { diff --git a/src/modm/ui/graphic/buffer_interface.hpp b/src/modm/ui/graphic/buffer_interface.hpp index e44cf2e891..b9f503eb0a 100644 --- a/src/modm/ui/graphic/buffer_interface.hpp +++ b/src/modm/ui/graphic/buffer_interface.hpp @@ -3,10 +3,11 @@ // TODO Find right #include for uint16_t #include #include "../shape/point.hpp" +#include "../color.hpp" namespace modm { -template +template class BufferInterface { public: diff --git a/src/modm/ui/graphic/display.hpp b/src/modm/ui/graphic/display.hpp index b92aed5ebc..3afcf7ac9c 100644 --- a/src/modm/ui/graphic/display.hpp +++ b/src/modm/ui/graphic/display.hpp @@ -14,6 +14,9 @@ #include "canvas.hpp" #include "buffer.hpp" #include "scanner.hpp" + +#include +#include namespace modm { @@ -47,8 +50,7 @@ enum Orientation : uint8_t */ // May inherit on modm::Matrix<..> or provide a conversion constructor for modm::Matrix<..> -template -requires C::isColor or std::is_same_v +template class Display : virtual public Canvas { public: @@ -88,8 +90,7 @@ class Display : virtual public Canvas }; // Same like Display but doesn't overwrite getWidth() and getHeight() -template -requires C::isColor or std::is_same_v +template class Display : virtual public Canvas { public: diff --git a/src/modm/ui/graphic/layout.hpp b/src/modm/ui/graphic/layout.hpp index 50fcfe81d8..3588ac1fe8 100644 --- a/src/modm/ui/graphic/layout.hpp +++ b/src/modm/ui/graphic/layout.hpp @@ -15,7 +15,7 @@ namespace modm { -template +template class Layout { private: diff --git a/src/modm/ui/graphic/painter_local.hpp b/src/modm/ui/graphic/painter_local.hpp index 1c05e599cb..8ae1e26b30 100644 --- a/src/modm/ui/graphic/painter_local.hpp +++ b/src/modm/ui/graphic/painter_local.hpp @@ -51,11 +51,9 @@ class LocalPainter : virtual public Canvas void drawQuadPoints(Point center, Point point); protected: - LocalPainter() = default; - /** * Buffer-manipulations - * CAUTION: No protection against segmentation errors! + * CAUTION: No protection against segmentation error! */ virtual void drawFast(Point point) = 0; virtual void drawFast(HLine hline) = 0; diff --git a/src/modm/ui/graphic/painter_remote.hpp b/src/modm/ui/graphic/painter_remote.hpp index d323245ff9..c329079ce3 100644 --- a/src/modm/ui/graphic/painter_remote.hpp +++ b/src/modm/ui/graphic/painter_remote.hpp @@ -53,13 +53,12 @@ class RemotePainter : public Interface, virtual public Canvas modm::ResumableResult drawQuadPoints(Point center, Point point); protected: - RemotePainter() = default; // template // RemotePainter(Args &&...args) : Interface(std::forward(args)...) {} /** * Buffer-manipulations - * CAUTION: No protection against segmentation errors! + * CAUTION: No protection against segmentation error! */ virtual modm::ResumableResult drawFast(Point point) = 0; virtual modm::ResumableResult drawFast(HLine hline) = 0;