mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Extract method
This commit is contained in:
parent
fec4015978
commit
6485cc895a
|
@ -91,11 +91,6 @@ pub struct TextRenderer<'a> {
|
|||
|
||||
impl<'a> Write for TextRenderer<'a> {
|
||||
fn write_str(&mut self, text: &str) -> Result<(), Error> {
|
||||
let vram_manager = &mut self.vram_manager;
|
||||
let tiles = &mut self.tiles;
|
||||
let foreground_colour = self.foreground_colour;
|
||||
let background_colour = self.background_colour;
|
||||
|
||||
for c in text.chars() {
|
||||
if c == '\n' {
|
||||
self.current_y_pos += self.font.line_height;
|
||||
|
@ -105,6 +100,25 @@ impl<'a> Write for TextRenderer<'a> {
|
|||
|
||||
let letter = self.font.letter(c);
|
||||
|
||||
self.render_letter(letter);
|
||||
|
||||
self.current_x_pos += letter.advance_width as i32;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn div_ceil(quotient: i32, divisor: i32) -> i32 {
|
||||
(quotient + divisor - 1) / divisor
|
||||
}
|
||||
|
||||
impl<'a> TextRenderer<'a> {
|
||||
fn render_letter(&mut self, letter: &FontLetter) {
|
||||
let vram_manager = &mut self.vram_manager;
|
||||
let foreground_colour = self.foreground_colour;
|
||||
let background_colour = self.background_colour;
|
||||
|
||||
let x_start = (self.current_x_pos + letter.xmin as i32).max(0);
|
||||
let y_start =
|
||||
self.current_y_pos + self.font.ascent - letter.height as i32 - letter.ymin as i32;
|
||||
|
@ -126,8 +140,7 @@ impl<'a> Write for TextRenderer<'a> {
|
|||
let tile_y = y_tile_start + letter_y_tile;
|
||||
|
||||
for letter_x_tile in 0..(x_tiles + 1) {
|
||||
let letter_x_start =
|
||||
0.max(letter_offset_x - 8 * letter_x_tile) + 8 * letter_x_tile;
|
||||
let letter_x_start = 0.max(letter_offset_x - 8 * letter_x_tile) + 8 * letter_x_tile;
|
||||
let letter_x_end =
|
||||
(letter_offset_x + letter.width as i32).min((letter_x_tile + 1) * 8);
|
||||
|
||||
|
@ -152,7 +165,7 @@ impl<'a> Write for TextRenderer<'a> {
|
|||
}
|
||||
|
||||
if !zero {
|
||||
let tile = tiles.entry((tile_x, tile_y)).or_insert_with(|| {
|
||||
let tile = self.tiles.entry((tile_x, tile_y)).or_insert_with(|| {
|
||||
vram_manager.new_dynamic_tile().fill_with(background_colour)
|
||||
});
|
||||
|
||||
|
@ -162,19 +175,8 @@ impl<'a> Write for TextRenderer<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.current_x_pos += letter.advance_width as i32;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn div_ceil(quotient: i32, divisor: i32) -> i32 {
|
||||
(quotient + divisor - 1) / divisor
|
||||
}
|
||||
|
||||
impl<'a> TextRenderer<'a> {
|
||||
pub fn commit(mut self) {
|
||||
let tiles = core::mem::take(&mut self.tiles);
|
||||
|
||||
|
|
Loading…
Reference in a new issue