Added CreateTiles function very important
This commit is contained in:
@@ -24,6 +24,21 @@ Bitmap::Bitmap(int width, int height, int depth, uchar *data)
|
|||||||
surface_->pixels = data;
|
surface_->pixels = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bitmap::Bitmap(int width, int height, int depth, int data_size)
|
||||||
|
: width_(width), height_(height), depth_(depth), data_size_(data_size) {
|
||||||
|
surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth,
|
||||||
|
SDL_PIXELFORMAT_INDEX8);
|
||||||
|
// Default grayscale palette
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
surface_->format->palette->colors[i].r = i * 31;
|
||||||
|
surface_->format->palette->colors[i].g = i * 31;
|
||||||
|
surface_->format->palette->colors[i].b = i * 31;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel_data_ = (uchar *)SDL_malloc(data_size);
|
||||||
|
surface_->pixels = pixel_data_;
|
||||||
|
}
|
||||||
|
|
||||||
void Bitmap::Create(int width, int height, int depth, uchar *data) {
|
void Bitmap::Create(int width, int height, int depth, uchar *data) {
|
||||||
width_ = width;
|
width_ = width;
|
||||||
height_ = height;
|
height_ = height;
|
||||||
@@ -77,6 +92,23 @@ void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
|
|||||||
|
|
||||||
void Bitmap::ApplyPalette(const SNESPalette &palette) { palette_ = palette; }
|
void Bitmap::ApplyPalette(const SNESPalette &palette) { palette_ = palette; }
|
||||||
|
|
||||||
|
std::vector<Bitmap> Bitmap::CreateTiles() {
|
||||||
|
std::vector<Bitmap> tiles;
|
||||||
|
for (int i = 0; i < 16; ++i) {
|
||||||
|
for (int j = 0; j < 4; ++j) {
|
||||||
|
tiles.emplace_back(8, 8, 8, 32);
|
||||||
|
auto surface = tiles[i + j].GetSurface();
|
||||||
|
SDL_Rect src_rect;
|
||||||
|
src_rect.x = i;
|
||||||
|
src_rect.y = j;
|
||||||
|
src_rect.w = 8;
|
||||||
|
src_rect.h = 8;
|
||||||
|
SDL_BlitSurface(surface_, &src_rect, surface, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tiles;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
} // namespace app
|
} // namespace app
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class Bitmap {
|
|||||||
public:
|
public:
|
||||||
Bitmap() = default;
|
Bitmap() = default;
|
||||||
Bitmap(int width, int height, int depth, uchar *data);
|
Bitmap(int width, int height, int depth, uchar *data);
|
||||||
|
Bitmap(int width, int height, int depth, int data_size);
|
||||||
|
|
||||||
void Create(int width, int height, int depth, uchar *data);
|
void Create(int width, int height, int depth, uchar *data);
|
||||||
void Create(int width, int height, int depth, int data_size);
|
void Create(int width, int height, int depth, int data_size);
|
||||||
@@ -25,10 +26,13 @@ class Bitmap {
|
|||||||
|
|
||||||
void ApplyPalette(const SNESPalette &palette);
|
void ApplyPalette(const SNESPalette &palette);
|
||||||
|
|
||||||
|
std::vector<Bitmap> CreateTiles();
|
||||||
|
|
||||||
int GetWidth() const { return width_; }
|
int GetWidth() const { return width_; }
|
||||||
int GetHeight() const { return height_; }
|
int GetHeight() const { return height_; }
|
||||||
uchar *GetData() const { return pixel_data_; }
|
auto GetData() const { return pixel_data_; }
|
||||||
SDL_Texture *GetTexture() const { return texture_; }
|
auto GetTexture() const { return texture_; }
|
||||||
|
auto GetSurface() const { return surface_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int width_ = 0;
|
int width_ = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user