diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs index 81677e2..4969261 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,7 @@ +pub mod infinite_grid; pub mod transform; + +use infinite_grid::*; use transform::*; use piston_window::grid::Grid; @@ -25,6 +28,7 @@ fn main() { // The amount of on-screen pixels used to represent a meter of actual terrain. let mut transform = Transform::new(); + let mut grid = InfiniteGrid::new(&transform, window.draw_size()); /* Create a rectangle that is used to draw all rectangles that were created by the user. It has * a thicc blacc border and white colour. @@ -37,13 +41,11 @@ fn main() { let mut starting_rect_point: Option<[f64; 2]> = None; let mut rectangles = Vec::new(); - // Line used to draw the square grid. - let grid_line = Line::new([1., 1., 1., 0.3], 1.5); - let mut mouse_pos_px = [0., 0.]; let mut mouse_pos_m = [0., 0.]; - let mut events = Events::new(EventSettings::new().lazy(true)); let mut canvas_follows_mouse = false; + + let mut events = Events::new(EventSettings::new().lazy(true)); while let Some(e) = events.next(&mut window) { // Update the mouse cursor position and possibly the canvas position too, in case the user // is currently dragging the canvas. @@ -69,6 +71,7 @@ fn main() { // Notify the user of the change if there was any if scale_changed { + grid.on_scale_change(&transform, window.draw_size()); println!( "Changed scale to {} pixels per m.", transform.pixels_per_m() @@ -105,26 +108,10 @@ fn main() { window.set_should_close(true); } - /* Update the Grid draw size to the actual window draw size. - * TODO: Currently, the window canvas draw size is never updated. This has to be changed in - * order to deal with the user resizing the window. - */ - let win_size = window.draw_size(); - let grid = Grid { - cols: (win_size.width / transform.pixels_per_m()) as u32 + 1, - rows: (win_size.height / transform.pixels_per_m()) as u32 + 1, - units: transform.pixels_per_m(), - }; - window.draw_2d(&e, |c, g, _device| { clear([0.4, 0.2, 0., 1.], g); - grid.draw( - &grid_line, - &c.draw_state, - c.trans_pos(transform.translation_px()).transform, - g, - ); + grid.draw(&transform, &c, g); // Draw all rectangles that are part of the map for &rect in &rectangles { |
