yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::SpriteDrawer Class Reference

Draws sprite OAM tiles to bitmaps for preview rendering. More...

#include <sprite_drawer.h>

Collaboration diagram for yaze::editor::SpriteDrawer:

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::PaletteGroupsprite_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
 

Detailed Description

Draws sprite OAM tiles to bitmaps for preview rendering.

This class handles static rendering of sprite graphics for both:

  • ZSM custom sprites (using OamTile definitions from .zsm files)
  • Vanilla ROM sprites (using hardcoded OAM layouts)

Architecture:

  • Graphics buffer is 8BPP linear format (same as room graphics)
  • 16 tiles per row (128 bytes per scanline)
  • Each tile is 8x8 pixels
  • OamTile.size determines 8x8 or 16x16 mode

Definition at line 27 of file sprite_drawer.h.

Constructor & Destructor Documentation

◆ SpriteDrawer()

yaze::editor::SpriteDrawer::SpriteDrawer ( const uint8_t * sprite_gfx_buffer = nullptr)
explicit

Construct a SpriteDrawer with graphics buffer.

Parameters
sprite_gfx_bufferPointer to 8BPP graphics data (0x10000 bytes)

Definition at line 8 of file sprite_drawer.cc.

Member Function Documentation

◆ SetGraphicsBuffer()

void yaze::editor::SpriteDrawer::SetGraphicsBuffer ( const uint8_t * buffer)
inline

Set the graphics buffer for tile lookup.

Parameters
bufferPointer to 8BPP graphics data

Definition at line 39 of file sprite_drawer.h.

References sprite_gfx_.

Referenced by yaze::editor::SpriteEditor::LoadSpriteGraphicsBuffer().

◆ SetPalettes()

void yaze::editor::SpriteDrawer::SetPalettes ( const gfx::PaletteGroup * palettes)
inline

Set the palette group for color mapping.

Parameters
palettesPalette group containing sprite palettes

Definition at line 45 of file sprite_drawer.h.

References sprite_palettes_.

Referenced by yaze::editor::SpriteEditor::LoadSpritePalettes().

◆ DrawOamTile()

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.

Parameters
bitmapTarget bitmap to draw to
tileOAM tile definition from ZSM file
origin_xX origin offset (center of sprite canvas)
origin_yY 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().

Here is the call graph for this function:

◆ DrawFrame()

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.

Parameters
bitmapTarget bitmap to draw to
frameFrame containing OAM tile list
origin_xX origin offset
origin_yY 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().

Here is the call graph for this function:

◆ ClearBitmap()

void yaze::editor::SpriteDrawer::ClearBitmap ( gfx::Bitmap & bitmap)

Clear the bitmap with transparent color.

Parameters
bitmapBitmap 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().

Here is the call graph for this function:

◆ IsReady()

bool yaze::editor::SpriteDrawer::IsReady ( ) const
inline

Check if drawer is ready to render.

Returns
true if graphics buffer and palettes are set

Definition at line 79 of file sprite_drawer.h.

References sprite_gfx_.

Referenced by yaze::editor::SpriteEditor::RenderVanillaSprite(), and yaze::editor::SpriteEditor::RenderZSpriteFrame().

◆ DrawTile8x8()

void yaze::editor::SpriteDrawer::DrawTile8x8 ( gfx::Bitmap & bitmap,
uint16_t tile_id,
int x,
int y,
bool flip_x,
bool flip_y,
uint8_t palette )
private

Draw an 8x8 tile to bitmap.

Parameters
bitmapTarget bitmap
tile_idTile ID in graphics buffer (0-1023)
xDestination X coordinate in bitmap
yDestination Y coordinate in bitmap
flip_xHorizontal mirror flag
flip_yVertical mirror flag
palettePalette 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().

Here is the call graph for this function:

◆ DrawTile16x16()

void yaze::editor::SpriteDrawer::DrawTile16x16 ( gfx::Bitmap & bitmap,
uint16_t tile_id,
int x,
int y,
bool flip_x,
bool flip_y,
uint8_t palette )
private

Draw a 16x16 tile (4 8x8 tiles) to bitmap.

Parameters
bitmapTarget bitmap
tile_idBase tile ID (top-left of 2x2 grid)
xDestination X coordinate in bitmap
yDestination Y coordinate in bitmap
flip_xHorizontal mirror flag
flip_yVertical mirror flag
palettePalette 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().

Here is the call graph for this function:

◆ GetTilePixel()

uint8_t yaze::editor::SpriteDrawer::GetTilePixel ( uint16_t tile_id,
int px,
int py ) const
private

Get pixel value from graphics buffer.

Parameters
tile_idTile ID
pxPixel X within tile (0-7)
pyPixel Y within tile (0-7)
Returns
Pixel value (0 = transparent, 1-15 = color index)

Definition at line 52 of file sprite_drawer.cc.

References kMaxTileId, kRowStride, kTileRowSize, kTileSize, kTilesPerRow, and sprite_gfx_.

Referenced by DrawTile8x8().

Member Data Documentation

◆ sprite_gfx_

const uint8_t* yaze::editor::SpriteDrawer::sprite_gfx_ = nullptr
private

Definition at line 121 of file sprite_drawer.h.

Referenced by DrawOamTile(), DrawTile8x8(), GetTilePixel(), IsReady(), and SetGraphicsBuffer().

◆ sprite_palettes_

const gfx::PaletteGroup* yaze::editor::SpriteDrawer::sprite_palettes_ = nullptr
private

Definition at line 122 of file sprite_drawer.h.

Referenced by SetPalettes().

◆ kTilesPerRow

constexpr int yaze::editor::SpriteDrawer::kTilesPerRow = 16
staticconstexprprivate

Definition at line 125 of file sprite_drawer.h.

Referenced by GetTilePixel().

◆ kTileSize

constexpr int yaze::editor::SpriteDrawer::kTileSize = 8
staticconstexprprivate

Definition at line 126 of file sprite_drawer.h.

Referenced by DrawTile8x8(), and GetTilePixel().

◆ kRowStride

constexpr int yaze::editor::SpriteDrawer::kRowStride = 128
staticconstexprprivate

Definition at line 127 of file sprite_drawer.h.

Referenced by GetTilePixel().

◆ kTileRowSize

constexpr int yaze::editor::SpriteDrawer::kTileRowSize = 1024
staticconstexprprivate

Definition at line 128 of file sprite_drawer.h.

Referenced by GetTilePixel().

◆ kMaxTileId

constexpr int yaze::editor::SpriteDrawer::kMaxTileId = 1023
staticconstexprprivate

Definition at line 129 of file sprite_drawer.h.

Referenced by DrawTile8x8(), and GetTilePixel().


The documentation for this class was generated from the following files: