--- a/rust/hwrunner/src/main.rs Fri Mar 22 21:09:17 2019 +0300
+++ b/rust/hwrunner/src/main.rs Fri Mar 22 21:44:06 2019 +0300
@@ -64,13 +64,10 @@
}
WindowEvent::MouseInput { button, state, .. } => {
if let MouseButton::Right = button {
- if let ElementState::Pressed = state {
- dragging = true;
- } else {
- dragging = false;
- }
+ dragging = state == ElementState::Pressed;
}
}
+
WindowEvent::MouseWheel { delta, .. } => {
let zoom_change = match delta {
MouseScrollDelta::LineDelta(x, y) => y as f32 * 0.1f32,
--- a/rust/lib-hedgewars-engine/src/render/camera.rs Fri Mar 22 21:09:17 2019 +0300
+++ b/rust/lib-hedgewars-engine/src/render/camera.rs Fri Mar 22 21:44:06 2019 +0300
@@ -21,6 +21,17 @@
}
pub fn viewport(&self) -> Rect {
- Rect::from_size(self.position, self.size)
+ #[inline]
+ fn scale(value: usize, zoom: f32) -> i32 {
+ (value as f32 / zoom / 2.0) as i32
+ }
+ let half_width = scale(self.size.width, self.zoom);
+ let half_height = scale(self.size.height, self.zoom);
+ Rect::from_box(
+ self.position.x - half_width,
+ self.position.x + half_width,
+ self.position.y - half_height,
+ self.position.y + half_height,
+ )
}
}
--- a/rust/lib-hedgewars-engine/src/world.rs Fri Mar 22 21:09:17 2019 +0300
+++ b/rust/lib-hedgewars-engine/src/world.rs Fri Mar 22 21:44:06 2019 +0300
@@ -99,8 +99,11 @@
}
pub fn move_camera(&mut self, position_shift: Point, zoom_shift: f32) {
- self.camera.position += position_shift;
self.camera.zoom += zoom_shift;
+ self.camera.position += Point::new(
+ (position_shift.x as f32 / self.camera.zoom) as i32,
+ (position_shift.y as f32 / self.camera.zoom) as i32,
+ );
}
pub fn render(&mut self) {