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 PAN_SPEED: f64 = 15.0;
|
||||||
|
|
||||||
const PANNING_THRESHOLD : f64 = 25.0;
|
const PANNING_THRESHOLD: f64 = 25.0;
|
||||||
|
|
||||||
pub struct Canvas {
|
pub struct Canvas {
|
||||||
// All of these f64's are in screen-space, so do NOT use Pt2D.
|
// 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 {
|
} else if self.drag_just_ended {
|
||||||
self.drag_just_ended = false;
|
self.drag_just_ended = false;
|
||||||
//} else if self.get_cursor_in_screen_space().is_none(){
|
|
||||||
} else {
|
} else {
|
||||||
let cursor_screen_pt = self.get_cursor().to_pt();
|
let cursor_screen_pt = self.get_cursor().to_pt();
|
||||||
let cursor_map_pt = self.screen_to_map(self.get_cursor());
|
let cursor_map_pt = self.screen_to_map(self.get_cursor());
|
||||||
let inner_bounds = self.get_inner_bounds();
|
let inner_bounds = self.get_inner_bounds();
|
||||||
let map_bounds = self.get_map_bounds();
|
let map_bounds = self.get_map_bounds();
|
||||||
if !inner_bounds.contains(cursor_screen_pt) && self.edge_auto_panning
|
if !inner_bounds.contains(cursor_screen_pt)
|
||||||
&& map_bounds.contains(cursor_map_pt){
|
&& self.edge_auto_panning
|
||||||
|
&& map_bounds.contains(cursor_map_pt)
|
||||||
|
{
|
||||||
let center_pt = self.center_to_screen_pt().to_pt();
|
let center_pt = self.center_to_screen_pt().to_pt();
|
||||||
let displacement_x = cursor_screen_pt.x() - center_pt.x();
|
let displacement_x = cursor_screen_pt.x() - center_pt.x();
|
||||||
let displacement_y = cursor_screen_pt.y() - center_pt.y();
|
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_x = displacement_x / displacement_magnitude;
|
||||||
let displacement_unit_y = displacement_y / displacement_magnitude;
|
let displacement_unit_y = displacement_y / displacement_magnitude;
|
||||||
//Add displacement along each axis
|
//Add displacement along each axis
|
||||||
@ -235,14 +237,20 @@ impl Canvas {
|
|||||||
fn get_inner_bounds(&self) -> Bounds {
|
fn get_inner_bounds(&self) -> Bounds {
|
||||||
let mut b = Bounds::new();
|
let mut b = Bounds::new();
|
||||||
b.update(ScreenPt::new(PANNING_THRESHOLD, PANNING_THRESHOLD).to_pt());
|
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
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_map_bounds(&self) -> Bounds {
|
fn get_map_bounds(&self) -> Bounds {
|
||||||
let mut b = Bounds::new();
|
let mut b = Bounds::new();
|
||||||
b.update(Pt2D::new(0.0,0.0));
|
b.update(Pt2D::new(0.0, 0.0));
|
||||||
b.update(Pt2D::new(self.map_dims.0,self.map_dims.1));
|
b.update(Pt2D::new(self.map_dims.0, self.map_dims.1));
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::assets::Assets;
|
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 crate::{text, Canvas, Event, EventCtx, GfxCtx, Key, Prerender, Style, UserInput};
|
||||||
use geom::Duration;
|
use geom::Duration;
|
||||||
use image::{GenericImageView, Pixel};
|
use image::{GenericImageView, Pixel};
|
||||||
@ -29,7 +29,6 @@ pub enum EventLoopMode {
|
|||||||
max_x: f64,
|
max_x: f64,
|
||||||
max_y: f64,
|
max_y: f64,
|
||||||
},
|
},
|
||||||
ScreenCaptureCurrentShot,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct State<G: GUI> {
|
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);
|
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);
|
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 {
|
fn screencap(filename: &str) -> bool {
|
||||||
if !process::Command::new("scrot")
|
if !process::Command::new("scrot")
|
||||||
.args(&[
|
.args(&[
|
||||||
|
@ -16,10 +16,7 @@ use crate::game::Transition;
|
|||||||
use crate::helpers::{list_names, ID};
|
use crate::helpers::{list_names, ID};
|
||||||
use crate::info::InfoPanel;
|
use crate::info::InfoPanel;
|
||||||
pub use crate::info::{ContextualActions, Tab};
|
pub use crate::info::{ContextualActions, Tab};
|
||||||
use ezgui::{
|
use ezgui::{hotkey, lctrl, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, ScreenPt, Text};
|
||||||
hotkey, lctrl, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, ScreenDims, ScreenPt,
|
|
||||||
ScreenRectangle, Text,
|
|
||||||
};
|
|
||||||
use geom::Polygon;
|
use geom::Polygon;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user