(&mut self, input: &WinitInputHelper, width: u16, height: u16)
| 35 | } |
| 36 | |
| 37 | fn input(&mut self, input: &WinitInputHelper, width: u16, height: u16) { |
| 38 | self.info_window_open ^= input.key_pressed(VirtualKeyCode::T); |
| 39 | |
| 40 | if input.key_pressed(VirtualKeyCode::Space) { |
| 41 | let val = PAUSED.load(Ordering::Relaxed); |
| 42 | PAUSED.store(!val, Ordering::Relaxed) |
| 43 | } |
| 44 | |
| 45 | if let Some((mx, my)) = input.mouse() { |
| 46 | // Scroll steps to double/halve the scale |
| 47 | let steps = 5.0; |
| 48 | |
| 49 | // Modify input |
| 50 | let zoom = (-input.scroll_diff() / steps).exp2(); |
| 51 | |
| 52 | // Screen space -> view space |
| 53 | let target = |
| 54 | Vec2::new(mx * 2.0 - width as f32, height as f32 - my * 2.0) / height as f32; |
| 55 | |
| 56 | // Move view position based on target |
| 57 | self.pos += target * self.scale * (1.0 - zoom); |
| 58 | |
| 59 | // Zoom |
| 60 | self.scale *= zoom; |
| 61 | } |
| 62 | |
| 63 | // Grab |
| 64 | if input.mouse_held(2) { |
| 65 | let (mdx, mdy) = input.mouse_diff(); |
| 66 | self.pos.x -= mdx / height as f32 * self.scale * 2.0; |
| 67 | self.pos.y += mdy / height as f32 * self.scale * 2.0; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | fn render(&mut self, ctx: &mut quarkstrom::RenderContext) { |
| 72 | ctx.set_view_pos(self.pos); |
nothing calls this directly
no outgoing calls
no test coverage detected