|
|
|
|
@ -10,6 +10,7 @@ use sdl2::rect::Point; |
|
|
|
|
const GLYPH_WIDTH: usize = 8; |
|
|
|
|
const GLYPH_HEIGHT: usize = 14; |
|
|
|
|
const GLYPH_AREA: usize = GLYPH_WIDTH * GLYPH_HEIGHT; |
|
|
|
|
|
|
|
|
|
type Glyph = Vec<Point>; |
|
|
|
|
|
|
|
|
|
/// Reads the file and turns it into a Vec of u8s
|
|
|
|
|
@ -52,7 +53,7 @@ pub fn generate_glyph_atlas() -> Vec<Glyph> { |
|
|
|
|
|
|
|
|
|
let multiplier = y * width; |
|
|
|
|
let offset = glyph * GLYPH_WIDTH as u16; |
|
|
|
|
let position = (x as u16 + multiplier + offset) as usize; |
|
|
|
|
let position = (x + multiplier + offset) as usize; |
|
|
|
|
|
|
|
|
|
if gtable_prune[position] == 1 { |
|
|
|
|
new_glyph.push(Point::new(x as i32, y as i32)); |
|
|
|
|
@ -64,7 +65,7 @@ pub fn generate_glyph_atlas() -> Vec<Glyph> { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Method for generating points to render, using given string
|
|
|
|
|
pub fn draw_text(content: &str, glyph_atlas: Vec<Glyph>) -> Vec<Point> { |
|
|
|
|
pub fn draw_text(glyph_atlas: &Vec<Glyph>, content: &str, offset: Point) -> Vec<Point> { |
|
|
|
|
let mut points: Vec<Point> = vec![]; |
|
|
|
|
|
|
|
|
|
let lines = content.split('\n'); |
|
|
|
|
@ -78,12 +79,12 @@ pub fn draw_text(content: &str, glyph_atlas: Vec<Glyph>) -> Vec<Point> { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for pixel in &glyph_atlas[index - 32] { |
|
|
|
|
let x_offset = x * GLYPH_WIDTH; |
|
|
|
|
let y_offset = y * GLYPH_HEIGHT; |
|
|
|
|
let x_glyph = x * GLYPH_WIDTH; |
|
|
|
|
let y_glyph = y * GLYPH_HEIGHT; |
|
|
|
|
|
|
|
|
|
let positioned_pixel = Point::new( |
|
|
|
|
pixel.x + x_offset as i32, |
|
|
|
|
pixel.y + y_offset as i32, |
|
|
|
|
pixel.x + x_glyph as i32 + offset.x, |
|
|
|
|
pixel.y + y_glyph as i32 + offset.y |
|
|
|
|
); |
|
|
|
|
points.push(positioned_pixel); |
|
|
|
|
} |
|
|
|
|
@ -92,7 +93,7 @@ pub fn draw_text(content: &str, glyph_atlas: Vec<Glyph>) -> Vec<Point> { |
|
|
|
|
points |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn draw_cursor(content: &str, mut cursor_position: usize) -> (Point, Point) { |
|
|
|
|
pub fn draw_cursor(mut cursor_position: usize, content: &str, offset: Point) -> (Point, Point) { |
|
|
|
|
let mut x = 0; |
|
|
|
|
let mut y = 0; |
|
|
|
|
|
|
|
|
|
@ -106,8 +107,8 @@ pub fn draw_cursor(content: &str, mut cursor_position: usize) -> (Point, Point) |
|
|
|
|
y += 1; |
|
|
|
|
} |
|
|
|
|
if idx == cursor_position { |
|
|
|
|
let point_a = Point::new((x * GLYPH_WIDTH) as i32, |
|
|
|
|
(y * GLYPH_HEIGHT) as i32 |
|
|
|
|
let point_a = Point::new((x * GLYPH_WIDTH) as i32 + offset.x, |
|
|
|
|
(y * GLYPH_HEIGHT) as i32 + offset.y |
|
|
|
|
); |
|
|
|
|
let point_b = Point::new(point_a.x, |
|
|
|
|
point_a.y + GLYPH_HEIGHT as i32 |
|
|
|
|
@ -116,5 +117,5 @@ pub fn draw_cursor(content: &str, mut cursor_position: usize) -> (Point, Point) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
(Point::new(0, 0), Point::new(0, GLYPH_HEIGHT as i32)) |
|
|
|
|
(Point::new(offset.x, offset.y), Point::new(offset.x, offset.y + GLYPH_HEIGHT as i32)) |
|
|
|
|
} |
|
|
|
|
|