Untitled
Loading...
Searching...
No Matches
fonts.c File Reference
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "cJSON/cJSON.h"
#include "utilities/types.h"
#include "ui/ui.h"
#include "utilities/utilities.h"
#include "ui/fonts.h"

Go to the source code of this file.

Functions

int find_empty_text_box_slot (UIMenu *m)
 Finds an empty slot for a TextBox that is marked as free.
Font * read_json_msdf (const char *json_path, const char *png_path)
 Reads the JSON for an MSDF Font, and creates a Font from it.
void determine_text_box_dimensions (TextBox *tb, float *width, float *height)
 Determines TextBox dimensions by iterating through its text as if it was rendering the Font.
void move_text_box_to_origin (TextBox *box)
 Moves a TextBox to \((0, 0)\), while accounting for Justify.
void delete_text_box (int menu, int id)
 Deletes a TextBox and its text and frees it from the UIMenu.
int create_text_box (int menu_id)
 Creates a DEFAULT_TEXT_BOX.

Variables

Vector FONTS = {0}
 All loaded Fonts.
uint32_t TEXT_INDEX_COUNT = 0

Function Documentation

◆ find_empty_text_box_slot()

int find_empty_text_box_slot ( UIMenu * m)

Finds an empty slot for a TextBox that is marked as free.

Parameters
mThe UIMenu to search.

Definition at line 21 of file fonts.c.

References find_empty_text_box_slot(), TextBox::free, MAX_TEXT_BOXES, and UIMenu::text_boxes.

Referenced by create_text_box(), find_empty_text_box_slot(), and move_text_box_to_menu().

◆ read_json_msdf()

Font * read_json_msdf ( const char * json_path,
const char * png_path )

Reads the JSON for an MSDF Font, and creates a Font from it.

Parameters
json_pathThe path to the json.
png_pathThe path to the png.
Returns
The pointer to the resulting Font.

Definition at line 33 of file fonts.c.

References Vector::count, FONTS, Font::glyph_count, Font::glyphs, Glyph::height, Font::highest_dist, Font::highest_y, Font::id, Glyph::id, Font::name, read_json_msdf(), Font::tex_h, Font::tex_w, Glyph::u0, Glyph::u1, Glyph::v0, Glyph::v1, vector_expand(), Glyph::width, Glyph::xadvance, Glyph::xoffset, and Glyph::yoffset.

Referenced by init_globals(), and read_json_msdf().

◆ determine_text_box_dimensions()

void determine_text_box_dimensions ( TextBox * tb,
float * width,
float * height )

Determines TextBox dimensions by iterating through its text as if it was rendering the Font.

Parameters
tbThe TextBox.
widthPointer to out width.
heightPointer to out height.

Definition at line 97 of file fonts.c.

References CAST_VEC, determine_text_box_dimensions(), TextBox::font_id, FONTS, Font::glyph_count, Font::glyphs, Glyph::height, Font::highest_dist, TextBox::start, Font::tex_h, Font::tex_w, TextBox::text, TextBox::text_size, Glyph::u0, Glyph::u1, Glyph::v0, Glyph::v1, TextBox::w, Glyph::width, vec2::x, Glyph::xadvance, Glyph::xoffset, vec2::y, and Glyph::yoffset.

Referenced by determine_text_box_dimensions(), and move_text_box_to_origin().

◆ move_text_box_to_origin()

void move_text_box_to_origin ( TextBox * box)

◆ delete_text_box()

void delete_text_box ( int menu,
int id )

◆ create_text_box()

int create_text_box ( int menu_id)

Variable Documentation

◆ FONTS

Vector FONTS = {0}

◆ TEXT_INDEX_COUNT

uint32_t TEXT_INDEX_COUNT = 0

Definition at line 16 of file fonts.c.

Referenced by add_all_text_boxes_to_draw_buffer(), and render().