mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Improve handling of touch
This commit is contained in:
parent
b31de71054
commit
4359e04810
@ -157,8 +157,8 @@ impl CameraController {
|
||||
}
|
||||
|
||||
pub fn process_touch(&mut self, touch_dx: f64, touch_dy: f64) {
|
||||
self.rotate_horizontal = touch_dx as f32;
|
||||
self.rotate_vertical = touch_dy as f32;
|
||||
self.amount_right += touch_dx as f32;
|
||||
self.amount_up += touch_dy as f32;
|
||||
}
|
||||
|
||||
pub fn process_scroll(&mut self, delta: &winit::event::MouseScrollDelta) {
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
use std::cmp;
|
||||
use std::io::Cursor;
|
||||
use std::ops::Range;
|
||||
use log::warn;
|
||||
|
||||
use log::warn;
|
||||
use lyon::tessellation::VertexBuffers;
|
||||
use vector_tile::parse_tile_reader;
|
||||
use wgpu::util::DeviceExt;
|
||||
use wgpu::{Extent3d, Limits};
|
||||
use wgpu::util::DeviceExt;
|
||||
use winit::dpi::PhysicalSize;
|
||||
use winit::event::{DeviceEvent, ElementState, KeyboardInput, MouseButton, TouchPhase, WindowEvent};
|
||||
use winit::window::Window;
|
||||
|
||||
use vector_tile::parse_tile_reader;
|
||||
|
||||
use crate::fps_meter::FPSMeter;
|
||||
use crate::io::static_database;
|
||||
use crate::render::camera;
|
||||
@ -55,7 +56,6 @@ const MASK_FILL_PRIM_ID: u32 = 3;
|
||||
const SECOND_TILE_STROKE_PRIM_ID: u32 = 5;
|
||||
|
||||
pub struct State {
|
||||
|
||||
instance: wgpu::Instance,
|
||||
|
||||
device: wgpu::Device,
|
||||
@ -191,7 +191,6 @@ impl State {
|
||||
max_storage_textures_per_shader_stage: 4,
|
||||
..wgpu::Limits::default()
|
||||
}
|
||||
|
||||
} else {
|
||||
Limits {
|
||||
..wgpu::Limits::default()
|
||||
@ -391,9 +390,9 @@ impl State {
|
||||
surface_config.height,
|
||||
cgmath::Deg(45.0),
|
||||
0.1,
|
||||
10000.0,
|
||||
100000.0,
|
||||
);
|
||||
let camera_controller = camera::CameraController::new(4000.0, 0.4);
|
||||
let camera_controller = camera::CameraController::new(3000.0, 0.2);
|
||||
|
||||
Self {
|
||||
instance,
|
||||
@ -425,7 +424,7 @@ impl State {
|
||||
camera_controller,
|
||||
mouse_pressed: false,
|
||||
tile2_stroke_range,
|
||||
suspended: false // Initially the app is not suspended
|
||||
suspended: false, // Initially the app is not suspended
|
||||
}
|
||||
}
|
||||
|
||||
@ -474,12 +473,12 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn device_input(&mut self, event: &DeviceEvent) -> bool {
|
||||
pub fn device_input(&mut self, event: &DeviceEvent, window: &Window) -> bool {
|
||||
match event {
|
||||
DeviceEvent::MouseMotion { delta } => {
|
||||
if self.mouse_pressed {
|
||||
warn!("mouse {}", delta.0);
|
||||
self.camera_controller.process_mouse(delta.0, delta.1);
|
||||
self.camera_controller.process_mouse(delta.0 / window.scale_factor(), delta.1 / window.scale_factor());
|
||||
}
|
||||
true
|
||||
}
|
||||
@ -487,7 +486,7 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn window_input(&mut self, event: &WindowEvent) -> bool {
|
||||
pub fn window_input(&mut self, event: &WindowEvent, window: &Window) -> bool {
|
||||
match event {
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
@ -509,7 +508,6 @@ impl State {
|
||||
_ => self.camera_controller.process_keyboard(*key, *state),
|
||||
},
|
||||
WindowEvent::Touch(touch) => {
|
||||
|
||||
match touch.phase {
|
||||
TouchPhase::Started => {
|
||||
self.scene.last_touch = Some((touch.location.x, touch.location.y))
|
||||
@ -518,8 +516,8 @@ impl State {
|
||||
if let Some(start) = self.scene.last_touch {
|
||||
let delta_x = start.0 - touch.location.x;
|
||||
let delta_y = start.1 - touch.location.y;
|
||||
warn!("touch {} {}", delta_x, delta_y);
|
||||
self.camera_controller.process_touch(delta_x, delta_y);
|
||||
warn!("touch {} {} {}", delta_x, delta_y, window.scale_factor());
|
||||
self.camera_controller.process_touch(delta_x / window.scale_factor(), delta_y / window.scale_factor());
|
||||
}
|
||||
|
||||
self.scene.last_touch = Some((touch.location.x, touch.location.y))
|
||||
|
||||
@ -19,14 +19,14 @@ pub async fn setup(window: winit::window::Window, event_loop: EventLoop<()>) {
|
||||
.. // We're not using device_id currently
|
||||
} => {
|
||||
trace!("{:?}", event);
|
||||
state.device_input(event);
|
||||
state.device_input(event, &window);
|
||||
}
|
||||
|
||||
Event::WindowEvent {
|
||||
ref event,
|
||||
window_id,
|
||||
} if window_id == window.id() => {
|
||||
if !state.window_input(event) {
|
||||
if !state.window_input(event, &window) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested
|
||||
| WindowEvent::KeyboardInput {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user