mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 12:12:00 +03:00
cleanup after PR, and start to wittle down EventLoopMode to handle
multiple types of update events
This commit is contained in:
parent
c34fe4f2c7
commit
967c8929e3
@ -11,7 +11,7 @@ const DRAG_THRESHOLD: f64 = 5.0;
|
||||
|
||||
const PAN_SPEED: f64 = 15.0;
|
||||
|
||||
const PANNING_THRESHOLD : f64 = 25.0;
|
||||
const PANNING_THRESHOLD: f64 = 25.0;
|
||||
|
||||
pub struct Canvas {
|
||||
// All of these f64's are in screen-space, so do NOT use Pt2D.
|
||||
@ -145,18 +145,20 @@ impl Canvas {
|
||||
}
|
||||
} else if self.drag_just_ended {
|
||||
self.drag_just_ended = false;
|
||||
//} else if self.get_cursor_in_screen_space().is_none(){
|
||||
} else {
|
||||
let cursor_screen_pt = self.get_cursor().to_pt();
|
||||
let cursor_map_pt = self.screen_to_map(self.get_cursor());
|
||||
let inner_bounds = self.get_inner_bounds();
|
||||
let map_bounds = self.get_map_bounds();
|
||||
if !inner_bounds.contains(cursor_screen_pt) && self.edge_auto_panning
|
||||
&& map_bounds.contains(cursor_map_pt){
|
||||
if !inner_bounds.contains(cursor_screen_pt)
|
||||
&& self.edge_auto_panning
|
||||
&& map_bounds.contains(cursor_map_pt)
|
||||
{
|
||||
let center_pt = self.center_to_screen_pt().to_pt();
|
||||
let displacement_x = cursor_screen_pt.x() - center_pt.x();
|
||||
let displacement_y = cursor_screen_pt.y() - center_pt.y();
|
||||
let displacement_magnitude = f64::sqrt(displacement_x.powf(2.0) + displacement_y.powf(2.0));
|
||||
let displacement_magnitude =
|
||||
f64::sqrt(displacement_x.powf(2.0) + displacement_y.powf(2.0));
|
||||
let displacement_unit_x = displacement_x / displacement_magnitude;
|
||||
let displacement_unit_y = displacement_y / displacement_magnitude;
|
||||
//Add displacement along each axis
|
||||
@ -235,14 +237,20 @@ impl Canvas {
|
||||
fn get_inner_bounds(&self) -> Bounds {
|
||||
let mut b = Bounds::new();
|
||||
b.update(ScreenPt::new(PANNING_THRESHOLD, PANNING_THRESHOLD).to_pt());
|
||||
b.update(ScreenPt::new(self.window_width - PANNING_THRESHOLD, self.window_height - PANNING_THRESHOLD).to_pt());
|
||||
b.update(
|
||||
ScreenPt::new(
|
||||
self.window_width - PANNING_THRESHOLD,
|
||||
self.window_height - PANNING_THRESHOLD,
|
||||
)
|
||||
.to_pt(),
|
||||
);
|
||||
b
|
||||
}
|
||||
|
||||
fn get_map_bounds(&self) -> Bounds {
|
||||
let mut b = Bounds::new();
|
||||
b.update(Pt2D::new(0.0,0.0));
|
||||
b.update(Pt2D::new(self.map_dims.0,self.map_dims.1));
|
||||
b.update(Pt2D::new(0.0, 0.0));
|
||||
b.update(Pt2D::new(self.map_dims.0, self.map_dims.1));
|
||||
b
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::assets::Assets;
|
||||
use crate::tools::screenshot::{screenshot_current, screenshot_everything};
|
||||
use crate::tools::screenshot::screenshot_everything;
|
||||
use crate::{text, Canvas, Event, EventCtx, GfxCtx, Key, Prerender, Style, UserInput};
|
||||
use geom::Duration;
|
||||
use image::{GenericImageView, Pixel};
|
||||
@ -29,7 +29,6 @@ pub enum EventLoopMode {
|
||||
max_x: f64,
|
||||
max_y: f64,
|
||||
},
|
||||
ScreenCaptureCurrentShot,
|
||||
}
|
||||
|
||||
pub(crate) struct State<G: GUI> {
|
||||
@ -343,9 +342,6 @@ pub fn run<G: 'static + GUI, F: FnOnce(&mut EventCtx) -> G>(settings: Settings,
|
||||
} => {
|
||||
screenshot_everything(&mut state, &dir, &prerender, zoom, max_x, max_y);
|
||||
}
|
||||
EventLoopMode::ScreenCaptureCurrentShot => {
|
||||
screenshot_current(&mut state, &prerender);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -52,12 +52,6 @@ pub(crate) fn screenshot_everything<G: GUI>(
|
||||
finish(dir_path, filenames, num_tiles_x, num_tiles_y);
|
||||
}
|
||||
|
||||
pub(crate) fn screenshot_current<G: GUI>(state: &mut State<G>, prerender: &Prerender) {
|
||||
state.draw(prerender, true);
|
||||
thread::sleep(time::Duration::from_millis(100));
|
||||
screencap("../screenshot.gif");
|
||||
}
|
||||
|
||||
fn screencap(filename: &str) -> bool {
|
||||
if !process::Command::new("scrot")
|
||||
.args(&[
|
||||
|
@ -16,10 +16,7 @@ use crate::game::Transition;
|
||||
use crate::helpers::{list_names, ID};
|
||||
use crate::info::InfoPanel;
|
||||
pub use crate::info::{ContextualActions, Tab};
|
||||
use ezgui::{
|
||||
hotkey, lctrl, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, ScreenDims, ScreenPt,
|
||||
ScreenRectangle, Text,
|
||||
};
|
||||
use ezgui::{hotkey, lctrl, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, ScreenPt, Text};
|
||||
use geom::Polygon;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user