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. | |
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. | |
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.
| #define AFFINE_BG_CBB 2 |
Definition at line 36 of file graphic_utils.h.
| #define AFFINE_BG_SBB 2 |
Definition at line 35 of file graphic_utils.h.
| #define MAIN_BG_CBB 1 |
Definition at line 32 of file graphic_utils.h.
| #define MAIN_BG_SBB 31 |
Definition at line 31 of file graphic_utils.h.
| #define NUM_PALETTES 16 |
Definition at line 38 of file graphic_utils.h.
| #define PAL_ROW_LEN 16 |
Definition at line 37 of file graphic_utils.h.
| #define SE_COL_LEN 32 |
Definition at line 202 of file graphic_utils.h.
| #define SE_ROW_LEN 32 |
Definition at line 199 of file graphic_utils.h.
| #define TEXT_CLR_BLACK RGB15(3, 5, 5) |
Definition at line 171 of file graphic_utils.h.
| #define TEXT_CLR_BLUE RGB15(0, 18, 31) |
Definition at line 177 of file graphic_utils.h.
| #define TEXT_CLR_DARK_BLUE RGB15(10, 5, 15) |
Definition at line 168 of file graphic_utils.h.
| #define TEXT_CLR_DARK_GREEN RGB15(0, 14, 8) |
Definition at line 165 of file graphic_utils.h.
| #define TEXT_CLR_GREEN RGB15(10, 27, 16) |
Definition at line 159 of file graphic_utils.h.
| #define TEXT_CLR_PURPLE RGB15(25, 15, 31) |
Definition at line 162 of file graphic_utils.h.
| #define TEXT_CLR_RED RGB15(31, 9, 8) |
Definition at line 180 of file graphic_utils.h.
| #define TEXT_CLR_WHITE CLR_WHITE |
Definition at line 183 of file graphic_utils.h.
| #define TEXT_CLR_YELLOW RGB15(31, 20, 0) |
Definition at line 174 of file graphic_utils.h.
| #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.
| #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.
| #define TTE_BIT_ON_CLR_IDX TTE_BIT_UNPACK_OFFSET + 1 |
Definition at line 64 of file graphic_utils.h.
| #define TTE_BIT_UNPACK_OFFSET 14 |
Definition at line 61 of file graphic_utils.h.
| #define TTE_BLACK_PB 10 |
Definition at line 79 of file graphic_utils.h.
| #define TTE_BLACK_TAG "#{cx:0xA000}" |
Definition at line 124 of file graphic_utils.h.
| #define TTE_BLUE_PB 12 |
Definition at line 85 of file graphic_utils.h.
| #define TTE_BLUE_TAG "#{cx:0xC000}" |
Definition at line 130 of file graphic_utils.h.
| #define TTE_CBB 0 |
Definition at line 34 of file graphic_utils.h.
| #define TTE_CHAR_SIZE TILE_SIZE |
By default TTE characters occupy a single tile.
Definition at line 101 of file graphic_utils.h.
| #define TTE_CLUB_TAG TTE_DARK_GREEN_TAG "Club " |
Definition at line 148 of file graphic_utils.h.
| #define TTE_DARK_BLUE_PB 9 |
Definition at line 76 of file graphic_utils.h.
| #define TTE_DARK_BLUE_TAG "#{cx:0x9000}" |
Definition at line 121 of file graphic_utils.h.
| #define TTE_DARK_GREEN_PB 8 |
Definition at line 73 of file graphic_utils.h.
| #define TTE_DARK_GREEN_TAG "#{cx:0x8000}" |
Definition at line 118 of file graphic_utils.h.
| #define TTE_DIAMOND_TAG TTE_YELLOW_TAG "Diamond " |
Definition at line 139 of file graphic_utils.h.
| #define TTE_GREEN_PB 6 |
Definition at line 67 of file graphic_utils.h.
| #define TTE_GREEN_TAG "#{cx:0x6000}" |
Definition at line 112 of file graphic_utils.h.
| #define TTE_HEART_TAG TTE_RED_TAG "Hearts " |
Definition at line 142 of file graphic_utils.h.
| #define TTE_PURPLE_PB 7 |
Definition at line 70 of file graphic_utils.h.
| #define TTE_PURPLE_TAG "#{cx:0x7000}" |
Definition at line 115 of file graphic_utils.h.
| #define TTE_RED_PB 13 |
Definition at line 88 of file graphic_utils.h.
| #define TTE_RED_TAG "#{cx:0xD000}" |
Definition at line 133 of file graphic_utils.h.
| #define TTE_SBB 30 |
Definition at line 33 of file graphic_utils.h.
| #define TTE_SPADE_TAG TTE_DARK_BLUE_TAG "Spade " |
Definition at line 145 of file graphic_utils.h.
| #define TTE_SPECIAL_PB_MULT_OFFSET 0x1000 |
Definition at line 94 of file graphic_utils.h.
| #define TTE_WHITE_PB 14 |
Definition at line 91 of file graphic_utils.h.
| #define TTE_WHITE_TAG "#{cx:0xE000}" |
Definition at line 136 of file graphic_utils.h.
| #define TTE_YELLOW_PB 11 |
Definition at line 82 of file graphic_utils.h.
| #define TTE_YELLOW_TAG "#{cx:0xB000}" |
Definition at line 127 of file graphic_utils.h.
| 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:
| typedef RECT Rect |
Definition at line 233 of file graphic_utils.h.
| enum OverflowDir |
Definition at line 218 of file graphic_utils.h.
| enum ScreenHorzDir |
Definition at line 212 of file graphic_utils.h.
| enum ScreenVertDir |
Definition at line 206 of file graphic_utils.h.
| enum TextJustifyFlag |
Definition at line 224 of file graphic_utils.h.
| 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.
| bg_sbb | the SBB of the background in which to move the rect. |
| se_rect | dimensions are in number of tiles. |
| direction | must be either SE_UP or SE_DOWN. |
Definition at line 104 of file graphic_utils.c.
| void main_bg_se_clear_rect | ( | Rect | se_rect | ) |
Clears a rect in the main background.
| se_rect | dimensions need to be in number of tiles. |
Definition at line 490 of file graphic_utils.c.
| 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:
| se_rect_dest | destination 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_pnt | points to the leftmost tile of the source 3-width rect. |
Definition at line 209 of file graphic_utils.c.
| 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:
| se_rect_dest | destination 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_left | points to the top left corner of the source 3x3 rect. |
Definition at line 172 of file graphic_utils.c.
| 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:
se_rect_dest minus the patch's margins.| se_rect_dest | Destination 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_ptch | Pointer to the properties of the 9-patch we want to stretch. |
Definition at line 355 of file graphic_utils.c.
| 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.
| se_rect_dest | dimensions are in number of tiles. |
| se_tile_src | x and y are the coordinates in number of tiles. |
Definition at line 167 of file graphic_utils.c.
| 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).
| se_rect | dimensions are in number of tiles. |
| dest_pos | x and y are the coordinates in number of tiles. |
Definition at line 124 of file graphic_utils.c.
| 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.
| se_rect | dimensions are in number of tiles. |
| direction | must be either SE_UP or SE_DOWN. |
Definition at line 114 of file graphic_utils.c.
| 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
| se_rect | dimensions are in number of tiles. |
| direction | must be either SE_UP or SE_DOWN. |
Definition at line 119 of file graphic_utils.c.
| 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[]
| dst | destination charblock |
| src | destination charblock |
| wcount | Number of words to copy |
| palette_offset | palette offset to shift to |
Definition at line 439 of file graphic_utils.c.
| 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[]
| dst | destination charblock |
| src | destination charblock |
| wcount | Number of words to copy |
| palette_offset | palette offset to shift to |
Definition at line 449 of file graphic_utils.c.
| INLINE int rect_height | ( | const Rect * | rect | ) |
Get the height of a rectangle.
| rect | a Rect to measure |
Definition at line 298 of file graphic_utils.h.
| INLINE int rect_width | ( | const Rect * | rect | ) |
Get the width of a rectangle.
| rect | a Rect to measure |
Definition at line 286 of file graphic_utils.h.
| 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.
| win0 | the visibility state for window 0 |
| win1 | the visibility state for window 1 |
Definition at line 460 of file graphic_utils.c.
| INLINE void tte_colors_setup | ( | void | ) |
Definition at line 266 of file graphic_utils.h.
| void tte_erase_rect_wrapper | ( | Rect | rect | ) |
A wrapper for tte_erase_rect that would use the rect struct.
| rect | rectangle to erase |
Definition at line 397 of file graphic_utils.c.
| 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.
{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.| raw_text | The unformatted text. The ' ' character and custom formatting {TAGS} will not count towards the computed line widths, as they won't appear on screen. |
| dst_rect | Rectangle the justified text must fit into. Will overflow at the bottom if text is too long. Size in tiles |
| justify_direction | Align the text either to the left or center. |
| bias_direction | Used with JUSTIFY_CENTER only. Determines if lines that cannot be centered are to be slightly to the left or to the right. |
| do_print | does not actually print anything, only does the calculations to determine the number of lines taken by the paragraph |
Definition at line 506 of file graphic_utils.c.
| 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.
| rect | The 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. |
| str | The string, the center of the string will be at the center of the updated rect. |
| bias_direction | Which 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.
| 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
| rect | is in number of pixels but should be a multiple of TILE_SIZE, so it's a whole number of tiles to fit TTE characters |
| num | number to display |
| overflow_direction | either OVERFLOW_LEFT or OVERFLOW_RIGHT. |
Definition at line 402 of file graphic_utils.c.