diff --git a/source/simple/graphical/algorithm/fill.cpp b/source/simple/graphical/algorithm/fill.cpp index 85caf0c28e5b5084120afd5266f00c3136c24583..b950279c79d7b383919fb4f63d9a9ff502f3ca55 100644 --- a/source/simple/graphical/algorithm/fill.cpp +++ b/source/simple/graphical/algorithm/fill.cpp @@ -1,5 +1,5 @@ #include "simple/sdlcore/utils.hpp" -#include "fill.h" +#include "fill.hpp" #include "../surface.h" #include "../renderer.h" @@ -42,4 +42,28 @@ namespace simple::graphical return fill(rend, area); } + void fill(pixel_writer_variant writer, color color) + { + std::visit([&color](auto&& writer) + { + fill_color(writer, color); + }, writer); + } + + + // hmmm... is this guaranteed to work? + [[maybe_unused]] + void instantiate_fill(pixel_writer_variant var) + { + std::visit([](auto writer) + { + fill(writer, typename decltype(writer)::pixel_type{}); + }, var); + } + + // template void fill<rgba_pixel, pixel_byte>(const pixel_writer<rgba_pixel, pixel_byte>&, rgba_pixel); + // template void fill<rgb_pixel, pixel_byte>(const pixel_writer<rgb_pixel, pixel_byte>&, rgb_pixel); + // template void fill<uint16_t, pixel_byte>(const pixel_writer<uint16_t, pixel_byte>&, uint16_t); + // template void fill<pixel_byte, pixel_byte>(const pixel_writer<pixel_byte, pixel_byte>&, pixel_byte); + } // namespace simple::graphical diff --git a/source/simple/graphical/algorithm/fill.h b/source/simple/graphical/algorithm/fill.h index 384db55130add27b7977ca71093bcbc800de381a..8ccccef6e2d5e3fa2cb1102a598eded98e3292bf 100644 --- a/source/simple/graphical/algorithm/fill.h +++ b/source/simple/graphical/algorithm/fill.h @@ -3,17 +3,24 @@ #include "../common_def.h" #include "../color.h" +#include "../pixels.h" + namespace simple::graphical { class surface; class renderer; - bool fill(const surface& surf, color col); - bool fill(const surface& surf, color col, const range2D& area); + bool fill(const surface& surf, color); + bool fill(const surface& surf, color, const range2D&); bool fill(const renderer& rend); - bool fill(const renderer& rend, const rgba_pixel& color); - bool fill(const renderer& rend, const range2D& area); - bool fill(const renderer& rend, const rgba_pixel& color, const range2D& area); + bool fill(const renderer& rend, const rgba_pixel&); + bool fill(const renderer& rend, const range2D&); + bool fill(const renderer& rend, const rgba_pixel&, const range2D& area); + + template <typename Pixel, typename RawType> + void fill(const pixel_writer<Pixel,RawType>&, Pixel); + + void fill(pixel_writer_variant, color); } // namespace simple::graphical diff --git a/source/simple/graphical/algorithm/fill.hpp b/source/simple/graphical/algorithm/fill.hpp new file mode 100644 index 0000000000000000000000000000000000000000..08e8bbc746f893e7ca6d6044d2bac01ae4367586 --- /dev/null +++ b/source/simple/graphical/algorithm/fill.hpp @@ -0,0 +1,19 @@ +#include "fill.h" + +namespace simple::graphical +{ + template <typename Pixel, typename RawType, typename Color> + void fill_color(const pixel_writer<Pixel, RawType>& writer, Color color) + { + for(int2 i = int2::zero(), size = writer.size(); i.y() < size.y(); ++i.y()) + for(i.x() = 0; i.x() < size.x(); ++i.x()) + writer.set(color, i); + } + + template <typename Pixel, typename RawType> + void fill(const pixel_writer<Pixel, RawType>& writer, Pixel pixel) + { + fill_color(writer, pixel); + } + +} // namespace simple::graphical