GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
graphic_utils.h File Reference

Graphic utility functions. More...

#include <tonc_math.h>
#include <tonc_video.h>

Go to the source code of this file.

Data Structures

struct  NinePatchRect
 Structure to represent arbitrary-sized 9-patches. More...
 

Macros

Graphics Utilities Constants

Reminder: Screen Base Block is the base for the screenblock entries i.e. tilemap Character Base Block is the base for the tiles themselves

#define MAIN_BG_SBB   31
 
#define MAIN_BG_CBB   1
 
#define TTE_SBB   30
 
#define TTE_CBB   0
 
#define AFFINE_BG_SBB   2
 
#define AFFINE_BG_CBB   2
 
#define PAL_ROW_LEN   16
 
#define NUM_PALETTES   16
 
#define TILE_SIZE   8
 Tile size in pixels, both height and width as tiles are square.
 
#define TILE_MEM_OBJ_CHARBLOCK0_IDX   4
 The index for the first charblock of the object memory in tonc's tile_mem.
 
TTE Palette constants
#define TTE_BIT_UNPACK_OFFSET   14
 
#define TTE_BIT_ON_CLR_IDX   TTE_BIT_UNPACK_OFFSET + 1
 
#define TTE_GREEN_PB   6
 
#define TTE_PURPLE_PB   7
 
#define TTE_DARK_GREEN_PB   8
 
#define TTE_DARK_BLUE_PB   9
 
#define TTE_BLACK_PB   10
 
#define TTE_YELLOW_PB   11
 
#define TTE_BLUE_PB   12
 
#define TTE_RED_PB   13
 
#define TTE_WHITE_PB   14
 
#define TTE_SPECIAL_PB_MULT_OFFSET   0x1000
 
#define TTE_CHAR_SIZE   TILE_SIZE
 By default TTE characters occupy a single tile.
 
TTE Text formatting Tags
#define TTE_GREEN_TAG   "#{cx:0x6000}"
 
#define TTE_PURPLE_TAG   "#{cx:0x7000}"
 
#define TTE_DARK_GREEN_TAG   "#{cx:0x8000}"
 
#define TTE_DARK_BLUE_TAG   "#{cx:0x9000}"
 
#define TTE_BLACK_TAG   "#{cx:0xA000}"
 
#define TTE_YELLOW_TAG   "#{cx:0xB000}"
 
#define TTE_BLUE_TAG   "#{cx:0xC000}"
 
#define TTE_RED_TAG   "#{cx:0xD000}"
 
#define TTE_WHITE_TAG   "#{cx:0xE000}"
 
#define TTE_DIAMOND_TAG   TTE_YELLOW_TAG "Diamond "
 
#define TTE_HEART_TAG   TTE_RED_TAG "Hearts "
 
#define TTE_SPADE_TAG   TTE_DARK_BLUE_TAG "Spade "
 
#define TTE_CLUB_TAG   TTE_DARK_GREEN_TAG "Club "
 
Text colors
#define TEXT_CLR_GREEN   RGB15(10, 27, 16)
 
#define TEXT_CLR_PURPLE   RGB15(25, 15, 31)
 
#define TEXT_CLR_DARK_GREEN   RGB15(0, 14, 8)
 
#define TEXT_CLR_DARK_BLUE   RGB15(10, 5, 15)
 
#define TEXT_CLR_BLACK   RGB15(3, 5, 5)
 
#define TEXT_CLR_YELLOW   RGB15(31, 20, 0)
 
#define TEXT_CLR_BLUE   RGB15(0, 18, 31)
 
#define TEXT_CLR_RED   RGB15(31, 9, 8)
 
#define TEXT_CLR_WHITE   CLR_WHITE
 
Dimensions for a screenblock.

A 1024 size screenblock is arranged in a grid of 32x32 screen entries Interestingly since each block is 8x8 pixels, the 240x160 GBA screen is smaller than the screenblock, only the top left part of the screenblock is displayed on the screen.

#define SE_ROW_LEN   32
 
#define SE_COL_LEN   32
 

Typedefs

typedef RECT Rect
 
typedef struct NinePatchRect NinePatchRect
 Structure to represent arbitrary-sized 9-patches.
 

Enumerations

enum  ScreenVertDir { SCREEN_UP = -1 , SCREEN_DOWN = 1 }
 
enum  ScreenHorzDir { SCREEN_LEFT = -1 , SCREEN_RIGHT = 1 }
 
enum  OverflowDir { OVERFLOW_LEFT = SCREEN_LEFT , OVERFLOW_RIGHT = SCREEN_RIGHT }
 
enum  TextJustifyFlag { JUSTIFY_LEFT , JUSTIFY_CENTER }
 

Functions

INLINE void tte_colors_setup (void)
 
INLINE int rect_width (const Rect *rect)
 Get the width of a rectangle.
 
INLINE int rect_height (const Rect *rect)
 Get the height of a rectangle.
 
void bg_se_copy_rect_1_tile_vert (u16 bg_sbb, Rect se_rect, enum ScreenVertDir direction)
 Copies an SE rect vertically in direction by a single tile.
 
void main_bg_se_clear_rect (Rect se_rect)
 Clears a rect in the main background.
 
void main_bg_se_copy_rect_1_tile_vert (Rect se_rect, enum ScreenVertDir direction)
 Copies a rect in the main background vertically in direction by a single tile.
 
void main_bg_se_copy_rect (Rect se_rect, BG_POINT dest_pos)
 Copies a rect in the main background from se_rect to the position (x, y).
 
void main_bg_se_copy_expand_tile (Rect se_rect_dest, BG_POINT se_tile_src)
 Copies a tile in the main background at se_tile_src to fill se_rect_dest.
 
void main_bg_se_copy_expand_9_patch (Rect se_dest_rect, const NinePatchRect *src_9_ptch)
 Copies a 9-patch and expands it to fit a passed rect.
 
void main_bg_se_copy_expand_3x3_rect (Rect se_rect_dest, BG_POINT se_rect_src_3x3_top_left)
 Copies a 3x3 rect and expands it to fit a passed rect. Special case of the 9-patch.
 
void main_bg_se_copy_expand_3w_row (Rect se_dest_rect, BG_POINT src_row_left_pnt)
 Copies a 3-width SE rect and expands it to fit a passed rect.
 
void main_bg_se_move_rect_1_tile_vert (Rect se_rect, enum ScreenVertDir direction)
 Moves a rect in the main background vertically in direction by a single tile.
 
void tte_erase_rect_wrapper (Rect rect)
 A wrapper for tte_erase_rect that would use the rect struct.
 
void update_text_rect_to_right_align_str (Rect *rect, const char *str, enum OverflowDir overflow_direction)
 Changes rect->left so it fits the digits of num exactly when right aligned to rect->right. Assumes num is not negative.
 
void update_text_rect_to_center_str (Rect *rect, const char *str, enum ScreenHorzDir bias_direction)
 Updates a rect so a string is centered within it.
 
void memcpy16_tile8_with_palette_offset (u16 *dst, const u16 *src, uint hwcount, u8 palette_offset)
 Copies 16 bit data from src to dst, applying a palette offset to the data.
 
void memcpy32_tile8_with_palette_offset (u32 *dst, const u32 *src, uint wcount, u8 palette_offset)
 Copies 32 bit data from src to dst, applying a palette offset to the data.
 
void toggle_windows (bool win0, bool win1)
 Toggles the visibility of the window layers.
 
int tte_printf_justified_in_rect (const char *raw_text, Rect dst_rect, enum TextJustifyFlag justify_direction, enum ScreenHorzDir bias_direction, bool do_print)
 Justify a text with custom formatting tags according to the given justification and bias direction tags.
 

Detailed Description

Graphic utility functions.

This file contains general utils and wrappers that relate to graphics/video/vram and generally displaying things on the screen. Mostly wrappers and defines for using tonc.

Note: the code here assumes we're working with a single screenblock which should be true for this entire game since a screenblock is enough to contain a full screen (and more) and there isn't any scrolling etc.

Definition in file graphic_utils.h.

Macro Definition Documentation

◆ AFFINE_BG_CBB

#define AFFINE_BG_CBB   2

Definition at line 36 of file graphic_utils.h.

◆ AFFINE_BG_SBB

#define AFFINE_BG_SBB   2

Definition at line 35 of file graphic_utils.h.

◆ MAIN_BG_CBB

#define MAIN_BG_CBB   1

Definition at line 32 of file graphic_utils.h.

◆ MAIN_BG_SBB

#define MAIN_BG_SBB   31

Definition at line 31 of file graphic_utils.h.

◆ NUM_PALETTES

#define NUM_PALETTES   16

Definition at line 38 of file graphic_utils.h.

◆ PAL_ROW_LEN

#define PAL_ROW_LEN   16

Definition at line 37 of file graphic_utils.h.

◆ SE_COL_LEN

#define SE_COL_LEN   32

Definition at line 202 of file graphic_utils.h.

◆ SE_ROW_LEN

#define SE_ROW_LEN   32

Definition at line 199 of file graphic_utils.h.

◆ TEXT_CLR_BLACK

#define TEXT_CLR_BLACK   RGB15(3, 5, 5)

Definition at line 171 of file graphic_utils.h.

◆ TEXT_CLR_BLUE

#define TEXT_CLR_BLUE   RGB15(0, 18, 31)

Definition at line 177 of file graphic_utils.h.

◆ TEXT_CLR_DARK_BLUE

#define TEXT_CLR_DARK_BLUE   RGB15(10, 5, 15)

Definition at line 168 of file graphic_utils.h.

◆ TEXT_CLR_DARK_GREEN

#define TEXT_CLR_DARK_GREEN   RGB15(0, 14, 8)

Definition at line 165 of file graphic_utils.h.

◆ TEXT_CLR_GREEN

#define TEXT_CLR_GREEN   RGB15(10, 27, 16)

Definition at line 159 of file graphic_utils.h.

◆ TEXT_CLR_PURPLE

#define TEXT_CLR_PURPLE   RGB15(25, 15, 31)

Definition at line 162 of file graphic_utils.h.

◆ TEXT_CLR_RED

#define TEXT_CLR_RED   RGB15(31, 9, 8)

Definition at line 180 of file graphic_utils.h.

◆ TEXT_CLR_WHITE

#define TEXT_CLR_WHITE   CLR_WHITE

Definition at line 183 of file graphic_utils.h.

◆ TEXT_CLR_YELLOW

#define TEXT_CLR_YELLOW   RGB15(31, 20, 0)

Definition at line 174 of file graphic_utils.h.

◆ TILE_MEM_OBJ_CHARBLOCK0_IDX

#define TILE_MEM_OBJ_CHARBLOCK0_IDX   4

The index for the first charblock of the object memory in tonc's tile_mem.

Definition at line 50 of file graphic_utils.h.

◆ TILE_SIZE

#define TILE_SIZE   8

Tile size in pixels, both height and width as tiles are square.

Definition at line 44 of file graphic_utils.h.

◆ TTE_BIT_ON_CLR_IDX

#define TTE_BIT_ON_CLR_IDX   TTE_BIT_UNPACK_OFFSET + 1

Definition at line 64 of file graphic_utils.h.

◆ TTE_BIT_UNPACK_OFFSET

#define TTE_BIT_UNPACK_OFFSET   14

Definition at line 61 of file graphic_utils.h.

◆ TTE_BLACK_PB

#define TTE_BLACK_PB   10

Definition at line 79 of file graphic_utils.h.

◆ TTE_BLACK_TAG

#define TTE_BLACK_TAG   "#{cx:0xA000}"

Definition at line 124 of file graphic_utils.h.

◆ TTE_BLUE_PB

#define TTE_BLUE_PB   12

Definition at line 85 of file graphic_utils.h.

◆ TTE_BLUE_TAG

#define TTE_BLUE_TAG   "#{cx:0xC000}"

Definition at line 130 of file graphic_utils.h.

◆ TTE_CBB

#define TTE_CBB   0

Definition at line 34 of file graphic_utils.h.

◆ TTE_CHAR_SIZE

#define TTE_CHAR_SIZE   TILE_SIZE

By default TTE characters occupy a single tile.

Definition at line 101 of file graphic_utils.h.

◆ TTE_CLUB_TAG

#define TTE_CLUB_TAG   TTE_DARK_GREEN_TAG "Club "

Definition at line 148 of file graphic_utils.h.

◆ TTE_DARK_BLUE_PB

#define TTE_DARK_BLUE_PB   9

Definition at line 76 of file graphic_utils.h.

◆ TTE_DARK_BLUE_TAG

#define TTE_DARK_BLUE_TAG   "#{cx:0x9000}"

Definition at line 121 of file graphic_utils.h.

◆ TTE_DARK_GREEN_PB

#define TTE_DARK_GREEN_PB   8

Definition at line 73 of file graphic_utils.h.

◆ TTE_DARK_GREEN_TAG

#define TTE_DARK_GREEN_TAG   "#{cx:0x8000}"

Definition at line 118 of file graphic_utils.h.

◆ TTE_DIAMOND_TAG

#define TTE_DIAMOND_TAG   TTE_YELLOW_TAG "Diamond "

Definition at line 139 of file graphic_utils.h.

◆ TTE_GREEN_PB

#define TTE_GREEN_PB   6

Definition at line 67 of file graphic_utils.h.

◆ TTE_GREEN_TAG

#define TTE_GREEN_TAG   "#{cx:0x6000}"

Definition at line 112 of file graphic_utils.h.

◆ TTE_HEART_TAG

#define TTE_HEART_TAG   TTE_RED_TAG "Hearts "

Definition at line 142 of file graphic_utils.h.

◆ TTE_PURPLE_PB

#define TTE_PURPLE_PB   7

Definition at line 70 of file graphic_utils.h.

◆ TTE_PURPLE_TAG

#define TTE_PURPLE_TAG   "#{cx:0x7000}"

Definition at line 115 of file graphic_utils.h.

◆ TTE_RED_PB

#define TTE_RED_PB   13

Definition at line 88 of file graphic_utils.h.

◆ TTE_RED_TAG

#define TTE_RED_TAG   "#{cx:0xD000}"

Definition at line 133 of file graphic_utils.h.

◆ TTE_SBB

#define TTE_SBB   30

Definition at line 33 of file graphic_utils.h.

◆ TTE_SPADE_TAG

#define TTE_SPADE_TAG   TTE_DARK_BLUE_TAG "Spade "

Definition at line 145 of file graphic_utils.h.

◆ TTE_SPECIAL_PB_MULT_OFFSET

#define TTE_SPECIAL_PB_MULT_OFFSET   0x1000

Definition at line 94 of file graphic_utils.h.

◆ TTE_WHITE_PB

#define TTE_WHITE_PB   14

Definition at line 91 of file graphic_utils.h.

◆ TTE_WHITE_TAG

#define TTE_WHITE_TAG   "#{cx:0xE000}"

Definition at line 136 of file graphic_utils.h.

◆ TTE_YELLOW_PB

#define TTE_YELLOW_PB   11

Definition at line 82 of file graphic_utils.h.

◆ TTE_YELLOW_TAG

#define TTE_YELLOW_TAG   "#{cx:0xB000}"

Definition at line 127 of file graphic_utils.h.

Typedef Documentation

◆ NinePatchRect

typedef struct NinePatchRect NinePatchRect

Structure to represent arbitrary-sized 9-patches.

While expanding a 3x3 rect is simple enough and has its purpose, this is an attempt to generalize the idea to a struct representing a 9-patch like this, such that areas 1, 2, 3 and 4 have no null dimensions and don't overlap:

margins.left margins.right │ Such as:
╭───┴───╮ ╭─┴─╮ │
╔═══════╤═════╤═══╗ ╮ │ 1) margins.left + margins.right <= width (patch_rect)
║ 1 │ 6 │ 2 ║ ├─ margins.top │
╟───────┼─────┼───╢ ╯ │ 2) margins.top + margins.bottom <= height(patch_rect)
║ 5 │ 0 │ 7 ║ │
║ │ │ ║ │ 3) margins values are inclusive, in number of tiles
╟───────┼─────┼───╢ ╮ │
║ │ │ ║ │ │
║ 4 │ 8 │ 3 ║ ├─ margins.bottom │
║ │ │ ║ │ │
╚═══════╧═════╧═══╝ ╯ │
╰────────┬────────╯ │
patch_rect │

◆ Rect

typedef RECT Rect

Definition at line 233 of file graphic_utils.h.

Enumeration Type Documentation

◆ OverflowDir

enum OverflowDir

Definition at line 218 of file graphic_utils.h.

◆ ScreenHorzDir

enum ScreenHorzDir

Definition at line 212 of file graphic_utils.h.

◆ ScreenVertDir

enum ScreenVertDir

Definition at line 206 of file graphic_utils.h.

◆ TextJustifyFlag

enum TextJustifyFlag

Definition at line 224 of file graphic_utils.h.

Function Documentation

◆ bg_se_copy_rect_1_tile_vert()

void bg_se_copy_rect_1_tile_vert ( u16  bg_sbb,
Rect  se_rect,
enum ScreenVertDir  direction 
)

Copies an SE rect vertically in direction by a single tile.

bg_sbb is the SBB of the background in which to move the rect se_rect dimensions are in number of tiles.

NOTE: This does not work with TTE_SBB, probably because it's 4BPP...

If you are doing this operation you are probably doing this in the main background and you should use main_bg_se_copy_rect_1_tile_vert() instead.

Parameters
bg_sbbthe SBB of the background in which to move the rect.
se_rectdimensions are in number of tiles.
directionmust be either SE_UP or SE_DOWN.

Definition at line 104 of file graphic_utils.c.

◆ main_bg_se_clear_rect()

void main_bg_se_clear_rect ( Rect  se_rect)

Clears a rect in the main background.

Parameters
se_rectdimensions need to be in number of tiles.

Definition at line 490 of file graphic_utils.c.

◆ main_bg_se_copy_expand_3w_row()

void main_bg_se_copy_expand_3w_row ( Rect  se_dest_rect,
BG_POINT  src_row_left_pnt 
)

Copies a 3-width SE rect and expands it to fit a passed rect.

Performs the following operation:

  1. The sides are stretched
  2. The center is filled.
Parameters
se_rect_destdestination for the copy; if rect width is 2, the center is not filled and only the sides are copied. But dest rect width must be at least 2.
src_row_left_pntpoints to the leftmost tile of the source 3-width rect.

Definition at line 209 of file graphic_utils.c.

◆ main_bg_se_copy_expand_3x3_rect()

void main_bg_se_copy_expand_3x3_rect ( Rect  se_rect_dest,
BG_POINT  se_rect_src_3x3_top_left 
)

Copies a 3x3 rect and expands it to fit a passed rect. Special case of the 9-patch.

Performs the following operation:

  1. The 3x3 rect is stretched to fill se_rect_dest.
  2. The corners are copied
  3. The sides are stretched
  4. The center is filled.
Parameters
se_rect_destdestination for the 3x3 copy, if rect sides are length 2, then the sides are not copied, and the center is not filled (in the case of both top and bottom sides), and only the corners are copied. But dest rect sides must be at least 2.
se_rect_src_3x3_top_leftpoints to the top left corner of the source 3x3 rect.

Definition at line 172 of file graphic_utils.c.

◆ main_bg_se_copy_expand_9_patch()

void main_bg_se_copy_expand_9_patch ( Rect  se_dest_rect,
const NinePatchRect src_9_ptch 
)

Copies a 9-patch and expands it to fit a passed rect.

Performs the following operation:

  1. The corners are copied
  2. The sides are stretched
  3. The center is stretched to fill se_rect_dest minus the patch's margins.
Parameters
se_rect_destDestination for the 9-patch copy. Needs to be at least large enough to fit the corners and sides of the patch, (margins.left + margins.right by margins.top + margins.bottom) in which case only the corners are copied.
src_9_ptchPointer to the properties of the 9-patch we want to stretch.
See also
NinePatchRect

Definition at line 355 of file graphic_utils.c.

◆ main_bg_se_copy_expand_tile()

void main_bg_se_copy_expand_tile ( Rect  se_rect_dest,
BG_POINT  se_tile_src 
)

Copies a tile in the main background at se_tile_src to fill se_rect_dest.

Parameters
se_rect_destdimensions are in number of tiles.
se_tile_srcx and y are the coordinates in number of tiles.

Definition at line 167 of file graphic_utils.c.

◆ main_bg_se_copy_rect()

void main_bg_se_copy_rect ( Rect  se_rect,
BG_POINT  dest_pos 
)

Copies a rect in the main background from se_rect to the position (x, y).

Parameters
se_rectdimensions are in number of tiles.
dest_posx and y are the coordinates in number of tiles.

Definition at line 124 of file graphic_utils.c.

◆ main_bg_se_copy_rect_1_tile_vert()

void main_bg_se_copy_rect_1_tile_vert ( Rect  se_rect,
enum ScreenVertDir  direction 
)

Copies a rect in the main background vertically in direction by a single tile.

Parameters
se_rectdimensions are in number of tiles.
directionmust be either SE_UP or SE_DOWN.

Definition at line 114 of file graphic_utils.c.

◆ main_bg_se_move_rect_1_tile_vert()

void main_bg_se_move_rect_1_tile_vert ( Rect  se_rect,
enum ScreenVertDir  direction 
)

Moves a rect in the main background vertically in direction by a single tile.

Note that tiles in the previous location will be transparent (0x000) so maybe copy would be a better choice if you don't want to delete things

Parameters
se_rectdimensions are in number of tiles.
directionmust be either SE_UP or SE_DOWN.

Definition at line 119 of file graphic_utils.c.

◆ memcpy16_tile8_with_palette_offset()

void memcpy16_tile8_with_palette_offset ( u16 *  dst,
const u16 *  src,
uint  hwcount,
u8  palette_offset 
)

Copies 16 bit data from src to dst, applying a palette offset to the data.

This is intended solely for use with tile8/8bpp data for dst and src. The palette offset allows the tiles to use a different location in the palette * memory This is useful because grit always loads the palette to the beginning of pal_bg_mem[]

Parameters
dstdestination charblock
srcdestination charblock
wcountNumber of words to copy
palette_offsetpalette offset to shift to

Definition at line 439 of file graphic_utils.c.

◆ memcpy32_tile8_with_palette_offset()

void memcpy32_tile8_with_palette_offset ( u32 *  dst,
const u32 *  src,
uint  wcount,
u8  palette_offset 
)

Copies 32 bit data from src to dst, applying a palette offset to the data.

This is intended solely for use with tile8/8bpp data for dst and src. The palette offset allows the tiles to use a different location in the palette memory This is useful because grit always loads the palette to the beginning of pal_bg_mem[]

Parameters
dstdestination charblock
srcdestination charblock
wcountNumber of words to copy
palette_offsetpalette offset to shift to

Definition at line 449 of file graphic_utils.c.

◆ rect_height()

INLINE int rect_height ( const Rect *  rect)

Get the height of a rectangle.

Parameters
recta Rect to measure
Returns
The height of the rectangle, or 0 if rect->right < rect->left

Definition at line 298 of file graphic_utils.h.

◆ rect_width()

INLINE int rect_width ( const Rect *  rect)

Get the width of a rectangle.

Parameters
recta Rect to measure
Returns
The width of the rectangle.

Definition at line 286 of file graphic_utils.h.

◆ toggle_windows()

void toggle_windows ( bool  win0,
bool  win1 
)

Toggles the visibility of the window layers.

These windows are primarily used for the shadows on held jokers, consumables and cards.

Parameters
win0the visibility state for window 0
win1the visibility state for window 1

Definition at line 460 of file graphic_utils.c.

◆ tte_colors_setup()

INLINE void tte_colors_setup ( void  )

Definition at line 266 of file graphic_utils.h.

◆ tte_erase_rect_wrapper()

void tte_erase_rect_wrapper ( Rect  rect)

A wrapper for tte_erase_rect that would use the rect struct.

Parameters
rectrectangle to erase

Definition at line 397 of file graphic_utils.c.

◆ tte_printf_justified_in_rect()

int tte_printf_justified_in_rect ( const char *  raw_text,
Rect  dst_rect,
enum TextJustifyFlag  justify_direction,
enum ScreenHorzDir  bias_direction,
bool  do_print 
)

Justify a text with custom formatting tags according to the given justification and bias direction tags.

  • The raw_text will be divided into Words, separated by 1 space, and 1 space only.
  • Each Word can have one or more formatting {TAGS} attached to it, and they MUST be right next to each other. It might not apply correctly otherwise if the line wraps.
  • {TAGS} must be one of TTE_BLACK_TAG, TTE_YELLOW_TAG, etc.
Parameters
raw_textThe unformatted text. The '
' character and custom formatting {TAGS} will not count towards the computed line widths, as they won't appear on screen.
dst_rectRectangle the justified text must fit into. Will overflow at the bottom if text is too long. Size in tiles
justify_directionAlign the text either to the left or center.
bias_directionUsed with JUSTIFY_CENTER only. Determines if lines that cannot be centered are to be slightly to the left or to the right.
do_printdoes not actually print anything, only does the calculations to determine the number of lines taken by the paragraph
Returns
the number of lines the wrapped paragraph takes
See also
update_text_rect_to_center_str
TTE_BLACK_TAG

Definition at line 506 of file graphic_utils.c.

◆ update_text_rect_to_center_str()

void update_text_rect_to_center_str ( Rect *  rect,
const char *  str,
enum ScreenHorzDir  bias_direction 
)

Updates a rect so a string is centered within it.

Parameters
rectThe rect provided, the provided values are used to determine the center and it is then updated so the string starting in rect->left is centered The rect is in number of pixels but should be a multiple of TTE_CHAR_SIZE so it's a whole number of tiles to fit TTE characters.
strThe string, the center of the string will be at the center of the updated rect.
bias_directionWhich direction to bias when the string can't be evenly centered with respect to char tiles. Examples: | |S|T|R| | - Can be evenly centered, bias has no effect | | |S|T|R| | - Bias right | |S|T|R| | | - Bias left |A|B|C|D| | - Bias left | |A|B|C|D| - Bias right

Definition at line 423 of file graphic_utils.c.

◆ update_text_rect_to_right_align_str()

void update_text_rect_to_right_align_str ( Rect *  rect,
const char *  str,
enum OverflowDir  overflow_direction 
)

Changes rect->left so it fits the digits of num exactly when right aligned to rect->right. Assumes num is not negative.

overflow_direction determines the direction the number will overflow if it's too large to fit inside the rect.

Note that both rect->left and rect-right need to be defined, top and bottom don't matter

Parameters
rectis in number of pixels but should be a multiple of TILE_SIZE, so it's a whole number of tiles to fit TTE characters
numnumber to display
overflow_directioneither OVERFLOW_LEFT or OVERFLOW_RIGHT.

Definition at line 402 of file graphic_utils.c.