Fix moving the map and resizing

This commit is contained in:
Maximilian Ammann 2022-10-30 18:38:49 +01:00
parent 7278829910
commit 6fab04c70f
5 changed files with 26 additions and 5 deletions

View File

@ -138,10 +138,10 @@ impl<ET: 'static> EventLoop<ET> for WinitEventLoop<ET> {
..
} => *control_flow = ControlFlow::Exit,
WindowEvent::Resized(physical_size) => {
// FIXME map.resize(physical_size.width, physical_size.height);
map.context_mut().resize(physical_size.width, physical_size.height);
}
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
// FIXME map.resize(new_inner_size.width, new_inner_size.height);
map.context_mut().resize(new_inner_size.width, new_inner_size.height);
}
_ => {}
}
@ -152,7 +152,7 @@ impl<ET: 'static> EventLoop<ET> for WinitEventLoop<ET> {
let dt = now - last_render_time;
last_render_time = now;
// FIXME input_controller.update_state(map.view_state_mut(), dt);
input_controller.update_state(map.context_mut().world.view_state_mut(), dt);
match map.run_schedule() {
Ok(_) => {}

View File

@ -17,7 +17,7 @@ use maplibre::{
use winit::window::WindowBuilder;
use super::{RawWinitEventLoop, RawWinitWindow, WinitMapWindow, WinitMapWindowConfig};
use crate::winit::{WinitEnvironment, WinitEventLoop};
use crate::{WinitEnvironment, WinitEventLoop};
impl<T> MapWindow for WinitMapWindow<T> {
fn size(&self) -> WindowSize {

View File

@ -1,4 +1,8 @@
use crate::{render::Renderer, style::Style, world::World};
use crate::{
render::Renderer,
style::Style,
world::{ViewState, World},
};
/// Stores the context of the map.
pub struct MapContext {

View File

@ -57,4 +57,12 @@ impl<E: Environment> Map<E> {
self.schedule.run(&mut self.map_context);
Ok(())
}
pub fn context(&self) -> &MapContext {
&self.map_context
}
pub fn context_mut(&mut self) -> &mut MapContext {
&mut self.map_context
}
}

View File

@ -3,6 +3,7 @@ use std::ops::{Deref, DerefMut};
use cgmath::{Angle, Point3};
use crate::{
context::MapContext,
coords::{LatLon, ViewRegion, WorldCoords, Zoom, ZoomLevel, TILE_SIZE},
io::tile_repository::TileRepository,
render::camera::{Camera, Perspective, ViewProjection},
@ -52,6 +53,14 @@ impl World {
tile_repository,
}
}
pub fn view_state(&self) -> &ViewState {
&self.view_state
}
pub fn view_state_mut(&mut self) -> &mut ViewState {
&mut self.view_state
}
}
/// Stores the camera configuration.