Struct dzahui::simulation::drawable::text::CharacterSet
source · pub(crate) struct CharacterSet {
characters: HashMap<char, Character>,
font_type: String,
font_size: u32,
is_italic: bool,
is_bold: bool,
encoding: String,
line_height: u32,
character_number: usize,
texture_file: String,
texture_size: (u32, u32),
pub(crate) binder: Binder,
image_as_vec: Vec<u8>,
}
Expand description
General Information
A list of characters with a series of important options that make it into a font.
Fields
characters
- Every character literal (char) with it’s corresponding character struct.font_type
- Name of the font.font_size
- Size of the font (pt).is_italic
- Self-explanatory.is_bool
- Self-explanatory.encoding
- Type of encoding (unicode, normally)line_height
- Where characters should start to be drawn vertically.character_number
- Number of characters in font.texture_file
- Where texture file is located.texture_size
- Dimension of the texture file.binder
- Binder associated to font.image_as_vec
- Image as a vector.
Fields§
§characters: HashMap<char, Character>
§font_type: String
§font_size: u32
§is_italic: bool
§is_bold: bool
§encoding: String
§line_height: u32
§character_number: usize
§texture_file: String
§texture_size: (u32, u32)
§binder: Binder
§image_as_vec: Vec<u8>
Implementations§
source§impl CharacterSet
impl CharacterSet
sourcepub fn new(character_file: &str) -> Result<Self, Error>
pub fn new(character_file: &str) -> Result<Self, Error>
General Information
Creates new character set given a character file (fnt). It reads every line, substracting information neccesary to create every struct and later create every character struct associating them to their char version. It also loads the image and generates a vector with it inside.
Parameters
character_file
- fnt file. It is important that the file is correctly created since metadata is important to struct instance.
sourcepub(crate) fn send_to_gpu(&self)
pub(crate) fn send_to_gpu(&self)
General Information
Struct has it’s own method to send to gpu since texture has to be considered. This means send_to_gpu method inside bindable trait does not work with this struct. Text are sent by letter. Performance is not affected much since the amount of letters is small. Image vector is sent in it’s entirety.
Parameters
&self
- Only a couple properties within self are enough to configure: vector from image, size of image.
sourcefn get_vertices_from_text<A: AsRef<str>>(
&self,
text: A
) -> Result<(Vec<[f32; 30]>, Vec<[u32; 12]>), Error>
fn get_vertices_from_text<A: AsRef<str>>(
&self,
text: A
) -> Result<(Vec<[f32; 30]>, Vec<[u32; 12]>), Error>
General Information
Obtains every letter given an entry of text, generating everything necessary to send each one to the gpu: indices, coordinates and texture coordinates.
Parameters
&self
- Obtain character struct for a given character to access it’s properties.text
- A text string to parse and display on screen. Every character has to be in the original font (CharacterSet).
sourcepub(crate) fn draw_text<A: AsRef<str>>(&self, text: A) -> Result<(), Error>
pub(crate) fn draw_text<A: AsRef<str>>(&self, text: A) -> Result<(), Error>
General Information
Draw a given text string. It can even be dynamic and, as long as the text is not too big, there will be no framerate drop.
Parameters
&self
- Obtain vertices from text functiontext
- A given text input to draw into screen
sourcepub(crate) fn matrix_for_screen(
viewport_x: f32,
viewport_y: f32,
projection_matrix: &Matrix4<f32>,
window_height: u32,
window_width: u32,
text_scale: f32
) -> Result<Matrix4<f32>, Error>
pub(crate) fn matrix_for_screen(
viewport_x: f32,
viewport_y: f32,
projection_matrix: &Matrix4<f32>,
window_height: u32,
window_width: u32,
text_scale: f32
) -> Result<Matrix4<f32>, Error>
General Information
Obtain a matrix to make text appear on screen in a certain position with a certain size. There’s still a problem of scale happening: should be chosen dynamically.
Parameters
viewport_x
- Place where text will be rendered in viewportviewport_y
- Place where text will be rendered in viewportprojection_matrix
- Matrix to inverse and obtain view coordinatescamera
- A reference to a camera to obtain a projection matrix (should change)window_height
- Size of viewport to normalize coordinateswindow_width
- Size of viewport to normalize coordinatestext_scale
- Scale of text to display