diff options
| author | Arne Dußin | 2021-01-27 14:01:50 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-02-02 22:16:15 +0100 |
| commit | f92e9f6f07b1e3834c2ca58ce3510734819d08e4 (patch) | |
| tree | 20e3d3afce342a56ae98f6c20491482ccd2b5c6b /src/client/grid.rs | |
| parent | c60a6d07efb120724b308e29e8e70f27c87c952d (diff) | |
| download | graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.tar.gz graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.zip | |
Rework graf karto to fit the client/server structure
Diffstat (limited to 'src/client/grid.rs')
| -rw-r--r-- | src/client/grid.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/client/grid.rs b/src/client/grid.rs new file mode 100644 index 0000000..17d537d --- /dev/null +++ b/src/client/grid.rs @@ -0,0 +1,56 @@ +//! The grid used to divide the map into evenly sized chunks. + +use crate::client::colours::DEFAULT_COLOURS; +use crate::client::transform::Transform; +use crate::math; +use raylib::drawing::RaylibDraw; + +/// Draw an infinite grid that can be moved around on the screen and zoomed in and out of. +pub fn draw_grid<D>(rld: &mut D, screen_width: i32, screen_height: i32, transform: &Transform) +where + D: RaylibDraw, +{ + /* Calculate the first whole meter that can be seen on the grid. This is the first meter that + * will be seen on screen. + */ + let mut first_cell = *transform.translation_px() / -transform.pixels_per_m(); + first_cell.x = first_cell.x.floor(); + first_cell.y = first_cell.y.floor(); + + let mut cell = first_cell; + let mut draw_y = transform.point_m_to_px(&cell).y; + loop { + draw_y = math::round(draw_y, 1.); + rld.draw_line( + 0, + draw_y as i32, + screen_width, + draw_y as i32, + DEFAULT_COLOURS.grid_lines, + ); + cell.y += 1.; + draw_y = transform.point_m_to_px(&cell).y; + + if draw_y as i32 > screen_height { + break; + } + } + + let mut draw_x = transform.point_m_to_px(&cell).x; + loop { + draw_x = math::round(draw_x, 1.); + rld.draw_line( + draw_x as i32, + 0, + draw_x as i32, + screen_height, + DEFAULT_COLOURS.grid_lines, + ); + cell.x += 1.; + draw_x = transform.point_m_to_px(&cell).x; + + if draw_x as i32 > screen_width { + break; + } + } +} |
