palette_view.h 896 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef SIMPLE_GRAPHICAL_PALETTE_VIEW_H
  2. #define SIMPLE_GRAPHICAL_PALETTE_VIEW_H
  3. #include <SDL2/SDL.h>
  4. #include "simple/support/range.hpp"
  5. #include "color.h"
  6. namespace simple::graphical
  7. {
  8. class palette_view
  9. {
  10. using range = support::range<const rgba_pixel*>;
  11. public:
  12. size_t size() const noexcept;
  13. void set_color(size_t index, rgba_pixel) const noexcept;
  14. size_t set_colors(range colors, size_t start_index = 0) const noexcept;
  15. template<typename Range>
  16. size_t set_colors(const Range& colors, size_t start_index = 0) const noexcept
  17. { return set_colors({colors.begin(), colors.end()}, start_index); }
  18. rgba_pixel operator[](size_t index) const noexcept;
  19. rgba_pixel at(size_t index) const;
  20. private:
  21. SDL_Palette* raw;
  22. explicit palette_view(SDL_Palette* raw) noexcept;
  23. friend class pixel_format;
  24. };
  25. } // namespace simple::graphical
  26. #endif /* end of include guard */