-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up text render code and add end-game screens
- Loading branch information
Showing
3 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use graphics::{Context, DrawState, Transformed}; | ||
use graphics::text::Text; | ||
use opengl_graphics::{GlGraphics, GlyphCache}; | ||
|
||
pub fn draw_text(txt: &str, pos: [f64; 2], size: u32, gc: &mut GlyphCache, c: &Context, gl: &mut GlGraphics) { | ||
|
||
let transform = c.transform.trans(pos[0], pos[1]); | ||
|
||
Text::new_color(::color::WHITE, size) | ||
.draw(txt, gc, &DrawState::default(), transform, gl) | ||
.unwrap(); | ||
} | ||
|
||
// Draw text centered in the window | ||
pub fn draw_center(txt: &str, size: u32, bounds: [f64; 2], gc: &mut GlyphCache, c: &Context, gl: &mut GlGraphics) { | ||
let half_size = size as f64 / 2.0; | ||
let num_chars = txt.len() as f64; | ||
|
||
let x = (bounds[0] / 2.0) - (num_chars * half_size) / 2.0; | ||
let y = (bounds[1] / 2.0) - half_size; | ||
|
||
draw_text(txt, [x, y], size, gc, c, gl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters