bitmap font/char rendering now requires a FontRenderOpts

this is more flexible for future font types, which may not require
only a simple u8 color value (e.g. bitmap fonts)
This commit is contained in:
Gered 2022-05-27 17:52:23 -04:00
parent 51cb8a5bf5
commit bc03961a49
6 changed files with 15 additions and 14 deletions

View file

@ -109,7 +109,7 @@ fn main() -> Result<()> {
system
.video
.print_string("hello, world!", 10, 10, 15, &font);
.print_string("hello, world!", 10, 10, FontRenderOpts::Color(15), &font);
for i in 0..NUM_BALLS {
system.video.blit(

View file

@ -95,7 +95,7 @@ impl GameState<Game> for SimulationState {
fn render(&mut self, _state: State, context: &mut Game) {
context.context.system.video.clear(2);
context.component_systems.render(&mut context.context);
context.context.system.video.print_string("hello, world!", 10, 10, 15, &context.context.font);
context.context.system.video.print_string("hello, world!", 10, 10, FontRenderOpts::Color(15), &context.context.font);
}
fn transition(&mut self, _state: State, _context: &mut Game) -> bool {

View file

@ -3,6 +3,7 @@ use std::path::Path;
use sdl2::keyboard::Scancode;
use libretrogd::entities::*;
use libretrogd::graphics::*;
use libretrogd::math::Vector2;
use libretrogd::states::*;
@ -64,10 +65,10 @@ impl GameState<Game> for MainMenuState {
draw_window(&mut context.core.system.video, &context.core.ui, x, y, x + width, y + height);
let selection_y = y + SPACER + (self.selection as i32 * 16);
context.core.system.video.print_string(">", x + SPACER, selection_y, 15, &context.core.font);
context.core.system.video.print_string(">", x + SPACER, selection_y, FontRenderOpts::Color(15), &context.core.font);
context.core.system.video.print_string("Play", x + SPACER + SPACER, y + SPACER, 15, &context.core.font);
context.core.system.video.print_string("Quit", x + SPACER + SPACER, y + SPACER + 16, 15, &context.core.font);
context.core.system.video.print_string("Play", x + SPACER + SPACER, y + SPACER, FontRenderOpts::Color(15), &context.core.font);
context.core.system.video.print_string("Quit", x + SPACER + SPACER, y + SPACER + 16, FontRenderOpts::Color(15), &context.core.font);
}
fn transition(&mut self, state: State, context: &mut Game) -> bool {
@ -176,10 +177,10 @@ impl GameState<Game> for GamePlayState {
draw_window(&mut context.core.system.video, &context.core.ui, x, y, x + width, y + height);
let selection_y = y + SPACER + (self.selection as i32 * 16);
context.core.system.video.print_string(">", x + SPACER, selection_y, 15, &context.core.font);
context.core.system.video.print_string(">", x + SPACER, selection_y, FontRenderOpts::Color(15), &context.core.font);
context.core.system.video.print_string("Continue", x + SPACER + SPACER, y + SPACER, 15, &context.core.font);
context.core.system.video.print_string("Quit", x + SPACER + SPACER, y + SPACER + 16, 15, &context.core.font);
context.core.system.video.print_string("Continue", x + SPACER + SPACER, y + SPACER, FontRenderOpts::Color(15), &context.core.font);
context.core.system.video.print_string("Quit", x + SPACER + SPACER, y + SPACER + 16, FontRenderOpts::Color(15), &context.core.font);
}
}

View file

@ -13,7 +13,7 @@ fn main() -> Result<()> {
let font = BitmaskFont::new_vga_font()?;
system.video.clear(0);
system.video.print_string("Hello, world!", 20, 20, 15, &font);
system.video.print_string("Hello, world!", 20, 20, FontRenderOpts::Color(15), &font);
while is_running {
system.do_events_with(|event| {

View file

@ -47,13 +47,13 @@ impl Bitmap {
/// Renders a single character using the font given.
#[inline]
pub fn print_char<T: Font>(&mut self, ch: char, x: i32, y: i32, color: u8, font: &T) {
pub fn print_char<T: Font>(&mut self, ch: char, x: i32, y: i32, opts: FontRenderOpts, font: &T) {
font.character(ch)
.draw(self, x, y, FontRenderOpts::Color(color));
.draw(self, x, y, opts);
}
/// Renders the string of text using the font given.
pub fn print_string<T: Font>(&mut self, text: &str, x: i32, y: i32, color: u8, font: &T) {
pub fn print_string<T: Font>(&mut self, text: &str, x: i32, y: i32, opts: FontRenderOpts, font: &T) {
let mut current_x = x;
let mut current_y = y;
for ch in text.chars() {
@ -65,7 +65,7 @@ impl Bitmap {
}
'\r' => (),
otherwise => {
self.print_char(otherwise, current_x, current_y, color, font);
self.print_char(otherwise, current_x, current_y, opts, font);
current_x += font.character(otherwise).bounds().width as i32;
}
}

View file

@ -23,7 +23,7 @@ pub enum FontError {
IOError(#[from] std::io::Error),
}
#[derive(Debug)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum FontRenderOpts {
Color(u8),
None,