1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-26 23:33:01 +00:00

Compliant BMFont renderer

This commit is contained in:
Alula 2022-01-22 05:07:53 +01:00
parent 4325dcad86
commit dcd33d943e
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
4 changed files with 7 additions and 12 deletions

View file

@ -56,8 +56,7 @@ impl BMFontRenderer {
for chr in iter {
if let Some(glyph) = self.font.chars.get(&chr) {
offset_x += ((glyph.width as f32 + glyph.xoffset as f32) * constants.font_scale).floor()
+ if chr != ' ' { constants.font_scale } else { constants.font_space_offset };
offset_x += glyph.xadvance as f32 * constants.font_scale;
}
}
@ -131,16 +130,15 @@ impl BMFontRenderer {
for chr in iter {
if let Some(glyph) = self.font.chars.get(&chr) {
batch.add_rect_scaled_tinted(
offset_x,
y + (glyph.yoffset as f32 * constants.font_scale).floor(),
offset_x + (glyph.xoffset as f32 * constants.font_scale),
y + (glyph.yoffset as f32 * constants.font_scale),
color,
constants.font_scale,
constants.font_scale,
&Rect::new_size(glyph.x as u16, glyph.y as u16, glyph.width as u16, glyph.height as u16),
);
offset_x += ((glyph.width as f32 + glyph.xoffset as f32) * constants.font_scale).floor()
+ if chr != ' ' { constants.font_scale } else { constants.font_space_offset };
offset_x += glyph.xadvance as f32 * constants.font_scale;
}
}
@ -169,8 +167,8 @@ impl BMFontRenderer {
for (chr, glyph) in chars.iter() {
if glyph.page == page {
batch.add_rect_scaled_tinted(
offset_x,
y + (glyph.yoffset as f32 * constants.font_scale).floor(),
offset_x + (glyph.xoffset as f32 * constants.font_scale),
y + (glyph.yoffset as f32 * constants.font_scale),
color,
constants.font_scale * scale,
constants.font_scale * scale,
@ -178,9 +176,7 @@ impl BMFontRenderer {
);
}
offset_x += scale
* (((glyph.width as f32 + glyph.xoffset as f32) * constants.font_scale).floor()
+ if *chr != ' ' { constants.font_scale } else { constants.font_space_offset });
offset_x += scale * (glyph.xadvance as f32 * constants.font_scale);
}
batch.draw(ctx)?;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

@ -1529,7 +1529,6 @@ impl EngineConstants {
self.title.logo_rect = Rect { left: 0, top: 0, right: 214, bottom: 50 };
self.font_path = "csfont.fnt".to_owned();
self.font_scale = 0.5;
self.font_space_offset = 3.0;
self.soundtracks.insert("Remastered".to_owned(), "/base/Ogg11/".to_owned());
self.soundtracks.insert("New".to_owned(), "/base/Ogg/".to_owned());