Draws sprite OAM tiles to bitmaps for preview rendering. More...
#include <sprite_drawer.h>
Public Member Functions | |
| SpriteDrawer (const uint8_t *sprite_gfx_buffer=nullptr) | |
| Construct a SpriteDrawer with graphics buffer. | |
| void | SetGraphicsBuffer (const uint8_t *buffer) |
| Set the graphics buffer for tile lookup. | |
| void | SetPalettes (const gfx::PaletteGroup *palettes) |
| Set the palette group for color mapping. | |
| void | DrawOamTile (gfx::Bitmap &bitmap, const zsprite::OamTile &tile, int origin_x, int origin_y) |
| Draw a single ZSM OAM tile to bitmap. | |
| void | DrawFrame (gfx::Bitmap &bitmap, const zsprite::Frame &frame, int origin_x, int origin_y) |
| Draw all tiles in a ZSM frame. | |
| void | ClearBitmap (gfx::Bitmap &bitmap) |
| Clear the bitmap with transparent color. | |
| bool | IsReady () const |
| Check if drawer is ready to render. | |
Private Member Functions | |
| void | DrawTile8x8 (gfx::Bitmap &bitmap, uint16_t tile_id, int x, int y, bool flip_x, bool flip_y, uint8_t palette) |
| Draw an 8x8 tile to bitmap. | |
| void | DrawTile16x16 (gfx::Bitmap &bitmap, uint16_t tile_id, int x, int y, bool flip_x, bool flip_y, uint8_t palette) |
| Draw a 16x16 tile (4 8x8 tiles) to bitmap. | |
| uint8_t | GetTilePixel (uint16_t tile_id, int px, int py) const |
| Get pixel value from graphics buffer. | |
Private Attributes | |
| const uint8_t * | sprite_gfx_ = nullptr |
| const gfx::PaletteGroup * | sprite_palettes_ = nullptr |
Static Private Attributes | |
| static constexpr int | kTilesPerRow = 16 |
| static constexpr int | kTileSize = 8 |
| static constexpr int | kRowStride = 128 |
| static constexpr int | kTileRowSize = 1024 |
| static constexpr int | kMaxTileId = 1023 |
Draws sprite OAM tiles to bitmaps for preview rendering.
This class handles static rendering of sprite graphics for both:
Architecture:
Definition at line 27 of file sprite_drawer.h.
|
explicit |
Construct a SpriteDrawer with graphics buffer.
| sprite_gfx_buffer | Pointer to 8BPP graphics data (0x10000 bytes) |
Definition at line 8 of file sprite_drawer.cc.
|
inline |
Set the graphics buffer for tile lookup.
| buffer | Pointer to 8BPP graphics data |
Definition at line 39 of file sprite_drawer.h.
References sprite_gfx_.
Referenced by yaze::editor::SpriteEditor::LoadSpriteGraphicsBuffer().
|
inline |
Set the palette group for color mapping.
| palettes | Palette group containing sprite palettes |
Definition at line 45 of file sprite_drawer.h.
References sprite_palettes_.
Referenced by yaze::editor::SpriteEditor::LoadSpritePalettes().
| void yaze::editor::SpriteDrawer::DrawOamTile | ( | gfx::Bitmap & | bitmap, |
| const zsprite::OamTile & | tile, | ||
| int | origin_x, | ||
| int | origin_y ) |
Draw a single ZSM OAM tile to bitmap.
| bitmap | Target bitmap to draw to |
| tile | OAM tile definition from ZSM file |
| origin_x | X origin offset (center of sprite canvas) |
| origin_y | Y origin offset (center of sprite canvas) |
Definition at line 18 of file sprite_drawer.cc.
References DrawTile16x16(), DrawTile8x8(), yaze::editor::zsprite::OamTile::id, yaze::gfx::Bitmap::is_active(), yaze::editor::zsprite::OamTile::mirror_x, yaze::editor::zsprite::OamTile::mirror_y, yaze::editor::zsprite::OamTile::palette, yaze::editor::zsprite::OamTile::size, sprite_gfx_, yaze::editor::zsprite::OamTile::x, and yaze::editor::zsprite::OamTile::y.
Referenced by DrawFrame(), and yaze::editor::SpriteEditor::RenderVanillaSprite().
| void yaze::editor::SpriteDrawer::DrawFrame | ( | gfx::Bitmap & | bitmap, |
| const zsprite::Frame & | frame, | ||
| int | origin_x, | ||
| int | origin_y ) |
Draw all tiles in a ZSM frame.
| bitmap | Target bitmap to draw to |
| frame | Frame containing OAM tile list |
| origin_x | X origin offset |
| origin_y | Y origin offset |
Definition at line 43 of file sprite_drawer.cc.
References DrawOamTile(), and yaze::editor::zsprite::Frame::Tiles.
Referenced by yaze::editor::SpriteEditor::RenderZSpriteFrame().
| void yaze::editor::SpriteDrawer::ClearBitmap | ( | gfx::Bitmap & | bitmap | ) |
Clear the bitmap with transparent color.
| bitmap | Bitmap to clear |
Definition at line 11 of file sprite_drawer.cc.
References yaze::gfx::Bitmap::is_active(), and yaze::gfx::Bitmap::mutable_data().
Referenced by yaze::editor::SpriteEditor::RenderVanillaSprite(), and yaze::editor::SpriteEditor::RenderZSpriteFrame().
|
inline |
Check if drawer is ready to render.
Definition at line 79 of file sprite_drawer.h.
References sprite_gfx_.
Referenced by yaze::editor::SpriteEditor::RenderVanillaSprite(), and yaze::editor::SpriteEditor::RenderZSpriteFrame().
|
private |
Draw an 8x8 tile to bitmap.
| bitmap | Target bitmap |
| tile_id | Tile ID in graphics buffer (0-1023) |
| x | Destination X coordinate in bitmap |
| y | Destination Y coordinate in bitmap |
| flip_x | Horizontal mirror flag |
| flip_y | Vertical mirror flag |
| palette | Palette index (0-7) |
Definition at line 74 of file sprite_drawer.cc.
References GetTilePixel(), yaze::gfx::Bitmap::height(), kMaxTileId, kTileSize, yaze::gfx::Bitmap::mutable_data(), sprite_gfx_, and yaze::gfx::Bitmap::width().
Referenced by DrawOamTile(), and DrawTile16x16().
|
private |
Draw a 16x16 tile (4 8x8 tiles) to bitmap.
| bitmap | Target bitmap |
| tile_id | Base tile ID (top-left of 2x2 grid) |
| x | Destination X coordinate in bitmap |
| y | Destination Y coordinate in bitmap |
| flip_x | Horizontal mirror flag |
| flip_y | Vertical mirror flag |
| palette | Palette index (0-7) |
16x16 tile layout (unmirrored): [tile_id + 0] [tile_id + 1] [tile_id + 16] [tile_id + 17]
Definition at line 112 of file sprite_drawer.cc.
References DrawTile8x8().
Referenced by DrawOamTile().
|
private |
Get pixel value from graphics buffer.
| tile_id | Tile ID |
| px | Pixel X within tile (0-7) |
| py | Pixel Y within tile (0-7) |
Definition at line 52 of file sprite_drawer.cc.
References kMaxTileId, kRowStride, kTileRowSize, kTileSize, kTilesPerRow, and sprite_gfx_.
Referenced by DrawTile8x8().
|
private |
Definition at line 121 of file sprite_drawer.h.
Referenced by DrawOamTile(), DrawTile8x8(), GetTilePixel(), IsReady(), and SetGraphicsBuffer().
|
private |
Definition at line 122 of file sprite_drawer.h.
Referenced by SetPalettes().
|
staticconstexprprivate |
Definition at line 125 of file sprite_drawer.h.
Referenced by GetTilePixel().
|
staticconstexprprivate |
Definition at line 126 of file sprite_drawer.h.
Referenced by DrawTile8x8(), and GetTilePixel().
|
staticconstexprprivate |
Definition at line 127 of file sprite_drawer.h.
Referenced by GetTilePixel().
|
staticconstexprprivate |
Definition at line 128 of file sprite_drawer.h.
Referenced by GetTilePixel().
|
staticconstexprprivate |
Definition at line 129 of file sprite_drawer.h.
Referenced by DrawTile8x8(), and GetTilePixel().