52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#ifndef Pixels_h_
|
|
#define Pixels_h_
|
|
|
|
#include "SDL.h"
|
|
#include "Box.hpp"
|
|
#include "Color.hpp"
|
|
#include "extension.hpp"
|
|
|
|
struct Sprite;
|
|
|
|
struct Pixels
|
|
{
|
|
|
|
const int TEXTURE_ACCESS_SCREEN = 128;
|
|
void* source = nullptr;
|
|
SDL_PixelFormat* format = nullptr;
|
|
SDL_Texture* texture;
|
|
SDL_Renderer* renderer;
|
|
int texture_access = 0;
|
|
SDL_Rect rect;
|
|
bool allocated = false;
|
|
|
|
Pixels(SDL_Renderer*, SDL_Texture* texture, const Box&);
|
|
Pixels(SDL_Renderer*, SDL_Texture* texture);
|
|
Pixels(SDL_Renderer*);
|
|
Pixels(Sprite&);
|
|
Pixels(Sprite&, const Box&);
|
|
int get_bytes_per_row() const;
|
|
Color get(int x, int y);
|
|
void set(const SDL_Color&, int x, int y);
|
|
void apply();
|
|
~Pixels();
|
|
|
|
template <typename T = void*>
|
|
T operator()(int x = 0, int y = 0)
|
|
{
|
|
std::uint8_t* access = static_cast<std::uint8_t*>(source);
|
|
if (x < 0 || x >= rect.w)
|
|
{
|
|
x = sb::mod(x, static_cast<int>(rect.w));
|
|
}
|
|
if (y < 0 || y >= rect.y)
|
|
{
|
|
y = sb::mod(y, static_cast<int>(rect.h));
|
|
}
|
|
return reinterpret_cast<T>(access + y * get_bytes_per_row() + x * format->BytesPerPixel);
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|