Skip to Content
The Alchemy Project

src/window/window_sprites.c

Characters drawn into windows, as glyph sprites, into a text canvas or as tilemap tiles, and the per-tick update that moves and shows the sprites windows carry. More…

Included by window.c.

Structures

NameDescription
structQUEUED_SPR_BYTESA queued sprite (QUEUED_SPR) as mnWindowSpriteUpdateAll writes it: the OAM_DATA fields, with the first attribute's y and the bits after it as bytes of their own.
structWINDOW_SPR_BYTESA window sprite (WINDOW_SPR) as mnWindowSpriteUpdateAll reads it: its kind, motion and index unsigned, and its queued sprite as QUEUED_SPR_BYTES.
structPOP_TRANSFORMA pop's affine transform as mnWindowSpriteUpdateAll packs it: x and y scale and the angle.

Macros

NameDescription
#defineGLYPH_SPRITE_SIZE (OBJ_SIZE_16X16 >> 16)A glyph sprite's size in its OAM attribute 1: 16 by 16, four tiles.
#defineGLYPH_SPRITE_OFFSET_X JAPANESE_OR(1, 2)Where a glyph sprite sits against its text position, in pixels: the Japanese font's glyphs are drawn into their tiles differently (mnTextDrawGlyphPair), one pixel further left and two lower.
#defineGLYPH_SPRITE_OFFSET_Y JAPANESE_OR(0, (-2))
#definePAGE_ARROW_OFFSET_X JAPANESE_OR(3, 4)Where the next-page arrow sits on the window interior's last tile, in pixels right and down from that tile's corner; it moves with the glyph sprites.
#definePAGE_ARROW_OFFSET_Y JAPANESE_OR(1, (-1))
#defineMARK_OVER_BORDER_TILE 30The tiles a voiced mark takes in place of its own over the border's top edge and over a divider; a semi-voiced mark takes the next.
#defineMARK_OVER_DIVIDER_TILE 14
#defineTILEMAP_WIDTH BG_SCREEN_WIDTHA window tilemap's width in tiles, and its entries over the screen's rows.
#defineTILEMAP_ENTRIES (TILEMAP_WIDTH * DISPLAY_TILE_HEIGHT)
#defineBOUNCE_SCALE_STEPS 32The steps of WindowSpriteBounceScales: a swell to 1.5 times and back.
#definePAGE_ARROW_PICTURE_BYTES (2 * TILE_SIZE_8BPP)A picture of the next-page arrow: an 8 by 16 sprite of 256 colors.
#defineWOBBLE_STEPS 20The steps of WindowSpriteWobbleOffsets and WindowSpriteBounceOffsets.
#defineHOP_STEPS 16

Typedefs

NameDescription
typedef Sint32 (*GLYPH_ROUTINE )( WINDOW *, Uint32, Uint32, Uint32, const Uint8 *);The glyph drawer a text canvas window runs from RAM: draws a character at pixel (x, y) of the canvas in the given font and returns its width.

Functions

NameDescription
Sint32mnGlyphDraw (WINDOW *window, Sint32 character, Sint32 x, Sint32 y, Sint32 kind)Draws a character of a window's text with its top-left corner at pixel (x, y) of the window's interior and returns how far the text advances.
Sint32mnGlyphDrawAsSprite (WINDOW *window, Sint32 character, Sint32 x, Sint32 y)Draws a character as a still glyph sprite on the window at pixel (x, y) of its interior and returns its width, or 0 when no window sprite is free.
voidmnGlyphDrawToTiles (Sint32 character, void *dest)Draws a character into the four tiles of a 16 by 16 glyph sprite at dest: the symbols of the password that brings The Broken Seal's data over (scene/clear.c).
void *mnGlyphAddBlankSprite (WINDOW *window, Sint32 character, Sint32 x, Sint32 y)Places a glyph sprite on the window at pixel (x, y) as mnGlyphDrawAsSprite does, but draws nothing into it (character is not read), and returns the VRAM address of its tiles for the caller to fill, or NULL when no window sprite is free.
voidmnWindowPutGlyph ( WINDOW *window, Uint32 tile, Uint32 x, Uint32 y, Sint32 kind)Puts a character into a window's tilemap as a tile, at tile (x, y) of its interior; GLYPH_DRAW_PAGE_ARROW instead shows the next-page arrow sprite on the interior's last tile.
voidmnWindowSetTilemapEntry ( WINDOW *window, Sint32 value, Sint32 x, Sint32 y, Uint32 kind)Writes value into a window's tilemap at tile (x, y) of its interior, in the palette that kind names (TILEMAP_ENTRY_), or as it is for TILEMAP_ENTRY_PLAIN; TILEMAP_ENTRY_NONE writes nothing. y -1 is the border's top row, where the menus put their page numbers and arrows (menu/menu_shared.c); a place beyond the bottom or right border, or outside the tilemap, is ignored.
voidmnWindowSpriteUpdateScaleAnimation (WINDOW_SPR *windowSprite)Steps a scaling sprite's animation (WINDOW_SPRITE_MOTION_SWELL to WINDOW_SPRITE_MOTION_SHRINK_HALF) and sets its affine scale for this tick.
voidmnWindowSpriteUpdateAll (void)The per-tick sprite update: moves each sprite that an open window carries by its motion (WINDOW_SPRITE_MOTION_) and queues it for drawing, at its depth (WINDOW_SPR.depth).

Variables

NameDescription
extern const Uint8mnGlyphDrawCode []The glyph drawer's code, which RAM_CODE_LOAD copies to RAM to run, and its size, as this symbol's address.
extern Uint8mnGlyphDrawCodeSize []
extern const Uint8WindowSpritePageArrowTiles []The next-page arrow's pictures, which it turns through as it bobs.
extern const Sint8WindowSpriteWobbleOffsets [][2]articles.c's WindowSpriteWobbleOffsets, as {x, y} pairs, and WindowSpriteBounceOffsets.
extern const Sint8WindowSpriteBounceOffsets []A hop of up to 8 pixels over 16 ticks, for WINDOW_SPRITE_MOTION_HOP_UP and the other hops.

Description

Characters drawn into windows, as glyph sprites, into a text canvas or as tilemap tiles, and the per-tick update that moves and shows the sprites windows carry. Part of window.c.

Macros in detail

GLYPH_SPRITE_SIZE

#define GLYPH_SPRITE_SIZE (OBJ_SIZE_16X16 >> 16)

A glyph sprite's size in its OAM attribute 1: 16 by 16, four tiles.

Referenced by mnGlyphAddBlankSprite(), mnGlyphDraw() and mnGlyphDrawAsSprite().

Definition at line 11 of file window_sprites.c.

GLYPH_SPRITE_OFFSET_X

#define GLYPH_SPRITE_OFFSET_X JAPANESE_OR(1, 2)

Where a glyph sprite sits against its text position, in pixels: the Japanese font's glyphs are drawn into their tiles differently (mnTextDrawGlyphPair), one pixel further left and two lower.

Referenced by mnGlyphAddBlankSprite(), mnGlyphDraw() and mnGlyphDrawAsSprite().

Definition at line 21 of file window_sprites.c.

GLYPH_SPRITE_OFFSET_Y

#define GLYPH_SPRITE_OFFSET_Y JAPANESE_OR(0, (-2))

Referenced by mnGlyphAddBlankSprite(), mnGlyphDraw() and mnGlyphDrawAsSprite().

Definition at line 22 of file window_sprites.c.

PAGE_ARROW_OFFSET_X

#define PAGE_ARROW_OFFSET_X JAPANESE_OR(3, 4)

Where the next-page arrow sits on the window interior's last tile, in pixels right and down from that tile's corner; it moves with the glyph sprites.

Referenced by mnGlyphDraw() and mnWindowPutGlyph().

Definition at line 26 of file window_sprites.c.

PAGE_ARROW_OFFSET_Y

#define PAGE_ARROW_OFFSET_Y JAPANESE_OR(1, (-1))

Referenced by mnGlyphDraw() and mnWindowPutGlyph().

Definition at line 27 of file window_sprites.c.

MARK_OVER_BORDER_TILE

#define MARK_OVER_BORDER_TILE 30

The tiles a voiced mark takes in place of its own over the border's top edge and over a divider; a semi-voiced mark takes the next.

Referenced by mnWindowPutGlyph().

Definition at line 302 of file window_sprites.c.

MARK_OVER_DIVIDER_TILE

#define MARK_OVER_DIVIDER_TILE 14

Referenced by mnWindowPutGlyph().

Definition at line 303 of file window_sprites.c.

TILEMAP_WIDTH

#define TILEMAP_WIDTH BG_SCREEN_WIDTH

A window tilemap's width in tiles, and its entries over the screen's rows.

Referenced by mnWindowSetTilemapEntry().

Definition at line 391 of file window_sprites.c.

TILEMAP_ENTRIES

#define TILEMAP_ENTRIES (TILEMAP_WIDTH * DISPLAY_TILE_HEIGHT)

Referenced by mnWindowSetTilemapEntry().

Definition at line 392 of file window_sprites.c.

BOUNCE_SCALE_STEPS

#define BOUNCE_SCALE_STEPS 32

The steps of WindowSpriteBounceScales: a swell to 1.5 times and back.

Referenced by mnWindowSpriteUpdateScaleAnimation().

Definition at line 450 of file window_sprites.c.

PAGE_ARROW_PICTURE_BYTES

#define PAGE_ARROW_PICTURE_BYTES (2 * TILE_SIZE_8BPP)

A picture of the next-page arrow: an 8 by 16 sprite of 256 colors.

Referenced by mnWindowSpriteUpdateAll().

Definition at line 570 of file window_sprites.c.

WOBBLE_STEPS

#define WOBBLE_STEPS 20

The steps of WindowSpriteWobbleOffsets and WindowSpriteBounceOffsets.

Referenced by mnWindowSpriteUpdateAll().

Definition at line 572 of file window_sprites.c.

HOP_STEPS

#define HOP_STEPS 16

Referenced by mnWindowSpriteUpdateAll().

Definition at line 573 of file window_sprites.c.

Typedefs in detail

GLYPH_ROUTINE

typedef Sint32 (*GLYPH_ROUTINE)( WINDOW *, Uint32, Uint32, Uint32, const Uint8 *);

The glyph drawer a text canvas window runs from RAM: draws a character at pixel (x, y) of the canvas in the given font and returns its width.

Referenced by mnGlyphDraw().

Definition at line 7 of file window_sprites.c.

Functions in detail

mnGlyphDraw

Sint32 mnGlyphDraw(WINDOW *window, Sint32 character, Sint32 x, Sint32 y, Sint32 kind)

Draws a character of a window's text with its top-left corner at pixel (x, y) of the window's interior and returns how far the text advances. A text canvas window draws it into the canvas; other windows show it as a sprite carried by the window, moving as the text style says. GLYPH_DRAW_PAGE_ARROW shows the next-page arrow instead. A sprite glyph takes a window sprite and its four tiles from the glyph sheet (WIN_STATE.glyphTiles, four for each sprite); with no sprite free nothing is drawn and it returns 0. The sprite stays until its window is cleared or closed.

References FontMarkGlyphCodes, mnGlyphDrawCode, mnGlyphDrawCodeSize, mnTextDrawGlyphPair(), mnWindowSpriteAcquireFree(), mnWindowSpriteAppendToList(), mnWindowSpriteGetSprite(), result, Sint32, syDMAXCopy(), syHeapRelease(), syResourceGetTableEntry() and syVRAMCacheFindFreeEntry().

Referenced by mnMessageType() and mnTextDrawWideStringAtOffset().

Definition at line 37 of file window_sprites.c.

mnGlyphDrawAsSprite

Sint32 mnGlyphDrawAsSprite(WINDOW *window, Sint32 character, Sint32 x, Sint32 y)

Draws a character as a still glyph sprite on the window at pixel (x, y) of its interior and returns its width, or 0 when no window sprite is free.

References mnTextDrawGlyphPair(), mnWindowSpriteAcquireFree(), mnWindowSpriteAppendToList(), mnWindowSpriteGetSprite(), Sint32 and syDMAXCopy().

Definition at line 209 of file window_sprites.c.

mnGlyphDrawToTiles

void mnGlyphDrawToTiles(Sint32 character, void *dest)

Draws a character into the four tiles of a 16 by 16 glyph sprite at dest: the symbols of the password that brings The Broken Seal's data over (scene/clear.c).

References mnTextDrawGlyphPair(), Sint32 and syDMAXCopy().

Referenced by scClearEnterPassword().

Definition at line 249 of file window_sprites.c.

mnGlyphAddBlankSprite

void * mnGlyphAddBlankSprite(WINDOW *window, Sint32 character, Sint32 x, Sint32 y)

Places a glyph sprite on the window at pixel (x, y) as mnGlyphDrawAsSprite does, but draws nothing into it (character is not read), and returns the VRAM address of its tiles for the caller to fill, or NULL when no window sprite is free.

References mnWindowSpriteAcquireFree(), mnWindowSpriteAppendToList(), mnWindowSpriteGetSprite() and Sint32.

Referenced by scClearEnterPassword().

Definition at line 261 of file window_sprites.c.

mnWindowPutGlyph

void mnWindowPutGlyph( WINDOW *window, Uint32 tile, Uint32 x, Uint32 y, Sint32 kind)

Puts a character into a window's tilemap as a tile, at tile (x, y) of its interior; GLYPH_DRAW_PAGE_ARROW instead shows the next-page arrow sprite on the interior's last tile. In Japanese, a kana mark goes in the tile above the character before it.

References mnWindowSpriteAcquireFree(), mnWindowSpriteAppendToList(), mnWindowSpriteGetSprite(), Sint32 and syVRAMCacheFindFreeEntry().

Referenced by mnBattleCollectPartyCommands(), mnBattleSummonMenuRun() and mnTextDrawWideStringInWindow().

Definition at line 310 of file window_sprites.c.

mnWindowSetTilemapEntry

void mnWindowSetTilemapEntry( WINDOW *window, Sint32 value, Sint32 x, Sint32 y, Uint32 kind)

Writes value into a window's tilemap at tile (x, y) of its interior, in the palette that kind names (TILEMAP_ENTRY_), or as it is for TILEMAP_ENTRY_PLAIN; TILEMAP_ENTRY_NONE writes nothing. y -1 is the border's top row, where the menus put their page numbers and arrows (menu/menu_shared.c); a place beyond the bottom or right border, or outside the tilemap, is ignored.

References Sint32.

Referenced by mnBattleCollectPartyCommands(), mnBattleDjinnMenuRun(), mnBattleDjinnMenuShowChangePreview(), mnBattleItemMenuRun(), mnBattlePsynergyMenuRun(), mnBattleStatusScreenRun(), mnBattleSummonMenuRun(), mnPartyStatusDraw(), mnRangeIconDraw() and scClearEnterPassword().

Definition at line 400 of file window_sprites.c.

mnWindowSpriteUpdateScaleAnimation

void mnWindowSpriteUpdateScaleAnimation(WINDOW_SPR *windowSprite)

Steps a scaling sprite's animation (WINDOW_SPRITE_MOTION_SWELL to WINDOW_SPRITE_MOTION_SHRINK_HALF) and sets its affine scale for this tick.

References mnWindowSpriteGetSprite(), Sint32, syOAMMatrixAllocateFromTransform() and WindowSpriteBounceScales.

Referenced by mnWindowSpriteUpdateAll().

Definition at line 454 of file window_sprites.c.

mnWindowSpriteUpdateAll

void mnWindowSpriteUpdateAll(void)

The per-tick sprite update: moves each sprite that an open window carries by its motion (WINDOW_SPRITE_MOTION_) and queues it for drawing, at its depth (WINDOW_SPR.depth).

References FrameCount, mnWindowSpriteUpdateScaleAnimation(), Sint32, syCos(), syOAMAddSpriteAtDepth(), syOAMMatrixAllocateFromTransform(), sySin(), syVRAMCacheLoad(), WindowSpriteBounceOffsets, WindowSpriteCursorBobOffsets, WindowSpritePageArrowTiles and WindowSpriteWobbleOffsets.

Referenced by mnWindowSystemUpdate() and mnWindowSystemUpdateBattle().

Definition at line 578 of file window_sprites.c.

Variables in detail

mnGlyphDrawCode

extern const Uint8 mnGlyphDrawCode[]

The glyph drawer's code, which RAM_CODE_LOAD copies to RAM to run, and its size, as this symbol's address.

Referenced by mnGlyphDraw().

Definition at line 15 of file window_sprites.c.

mnGlyphDrawCodeSize

extern Uint8 mnGlyphDrawCodeSize[]

Referenced by mnGlyphDraw().

Definition at line 16 of file window_sprites.c.

WindowSpritePageArrowTiles

extern const Uint8 WindowSpritePageArrowTiles[]

The next-page arrow's pictures, which it turns through as it bobs.

Referenced by mnWindowSpriteUpdateAll().

Definition at line 562 of file window_sprites.c.