mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
make canvas know initial screen size, so centering on map pt initially does work
This commit is contained in:
parent
78f3107d8a
commit
b7f31cc8f4
@ -20,7 +20,7 @@
|
||||
"y": 394.67230224609377
|
||||
},
|
||||
"intersection_type": "TrafficSignal",
|
||||
"label": "bottleneck"
|
||||
"label": null
|
||||
}
|
||||
],
|
||||
[
|
||||
|
@ -33,16 +33,14 @@ fn main() {
|
||||
.unwrap()
|
||||
.start("./profile")
|
||||
.unwrap();*/
|
||||
let canvas = ezgui::Canvas::new();
|
||||
let mut canvas = ezgui::Canvas::new(1024, 768);
|
||||
if flags.sim_flags.load == "../data/raw_maps/ban_left_turn.abst" {
|
||||
ezgui::run(
|
||||
ui::UI::new(
|
||||
tutorial::TutorialState::new(flags.sim_flags, &canvas),
|
||||
tutorial::TutorialState::new(flags.sim_flags, &mut canvas),
|
||||
canvas,
|
||||
),
|
||||
"A/B Street",
|
||||
1024,
|
||||
768,
|
||||
);
|
||||
} else {
|
||||
ezgui::run(
|
||||
@ -51,8 +49,6 @@ fn main() {
|
||||
canvas,
|
||||
),
|
||||
"A/B Street",
|
||||
1024,
|
||||
768,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ enum State {
|
||||
const SPAWN_CARS_PER_BORDER: usize = 100 * 10;
|
||||
|
||||
impl TutorialState {
|
||||
pub fn new(flags: SimFlags, canvas: &Canvas) -> TutorialState {
|
||||
TutorialState {
|
||||
pub fn new(flags: SimFlags, canvas: &mut Canvas) -> TutorialState {
|
||||
let s = TutorialState {
|
||||
main: DefaultUIState::new(flags, None, canvas),
|
||||
state: State::GiveInstructions(LogScroller::new_from_lines(vec![
|
||||
"Welcome to the A/B Street tutorial!".to_string(),
|
||||
@ -35,7 +35,8 @@ impl TutorialState {
|
||||
"".to_string(),
|
||||
"Press ENTER to start the game!".to_string(),
|
||||
])),
|
||||
}
|
||||
};
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,9 +57,6 @@ impl UIState for TutorialState {
|
||||
) {
|
||||
match self.state {
|
||||
State::GiveInstructions(ref mut scroller) => {
|
||||
// TODO We really want to do this once in the constructor, but window size isn't
|
||||
// known yet.
|
||||
canvas.center_on_map_pt(self.main.primary.map.intersection("bottleneck").point);
|
||||
if scroller.event(input) {
|
||||
setup_scenario(&mut self.main.primary);
|
||||
// TODO Levels of indirection now feel bad. I almost want dependency injection
|
||||
|
@ -281,7 +281,6 @@ impl<S: UIState> UI<S> {
|
||||
}
|
||||
_ => {
|
||||
warn!("Couldn't load editor_state or it's for a different map, so just focusing on an arbitrary building");
|
||||
// TODO window_size isn't set yet, so this actually kinda breaks
|
||||
let focus_pt = ID::Building(BuildingID(0))
|
||||
.canonical_point(
|
||||
&ui.state.primary().map,
|
||||
|
@ -27,7 +27,7 @@ pub struct Canvas {
|
||||
}
|
||||
|
||||
impl Canvas {
|
||||
pub fn new() -> Canvas {
|
||||
pub fn new(initial_width: u32, initial_height: u32) -> Canvas {
|
||||
let texture_settings = TextureSettings::new().filter(Filter::Nearest);
|
||||
// TODO We could also preload everything and not need the RefCell.
|
||||
let glyphs = RefCell::new(
|
||||
@ -50,8 +50,8 @@ impl Canvas {
|
||||
|
||||
left_mouse_drag_from: None,
|
||||
window_size: Size {
|
||||
width: 0,
|
||||
height: 0,
|
||||
width: initial_width,
|
||||
height: initial_height,
|
||||
},
|
||||
|
||||
glyphs,
|
||||
|
@ -29,9 +29,10 @@ pub enum EventLoopMode {
|
||||
InputOnly,
|
||||
}
|
||||
|
||||
pub fn run<T, G: GUI<T>>(mut gui: G, window_title: &str, initial_width: u32, initial_height: u32) {
|
||||
pub fn run<T, G: GUI<T>>(mut gui: G, window_title: &str) {
|
||||
let opengl = OpenGL::V3_2;
|
||||
let settings = WindowSettings::new(window_title, [initial_width, initial_height])
|
||||
let initial_size = gui.get_mut_canvas().window_size;
|
||||
let settings = WindowSettings::new(window_title, [initial_size.width, initial_size.height])
|
||||
.opengl(opengl)
|
||||
.exit_on_esc(false)
|
||||
// TODO it'd be cool to dynamically tweak antialiasing settings as we zoom in
|
||||
|
@ -34,7 +34,7 @@ impl UI {
|
||||
)
|
||||
.unwrap();
|
||||
UI {
|
||||
canvas: Canvas::new(),
|
||||
canvas: Canvas::new(1024, 768),
|
||||
draw_map: DrawMap::new(map),
|
||||
cycler: Cycler::new(ANIMATION_PERIOD_S),
|
||||
}
|
||||
@ -62,5 +62,5 @@ impl GUI<()> for UI {
|
||||
|
||||
fn main() {
|
||||
let flags = Flags::from_args();
|
||||
ezgui::run(UI::new(flags), "Halloween tech demo", 1024, 768);
|
||||
ezgui::run(UI::new(flags), "Halloween tech demo");
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ pub struct UI {
|
||||
|
||||
impl UI {
|
||||
pub fn new() -> UI {
|
||||
let mut canvas = Canvas::new();
|
||||
let mut canvas = Canvas::new(1024, 768);
|
||||
// Start with mode 1's settings
|
||||
canvas.window_size.width = 1024;
|
||||
canvas.window_size.height = 768;
|
||||
@ -121,5 +121,5 @@ impl GUI<()> for UI {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
ezgui::run(UI::new(), "GUI Playground", 1024, 768);
|
||||
ezgui::run(UI::new(), "GUI Playground");
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ impl UI {
|
||||
Model::new()
|
||||
};
|
||||
UI {
|
||||
canvas: Canvas::new(),
|
||||
canvas: Canvas::new(1024, 768),
|
||||
model,
|
||||
state: State::Viewing,
|
||||
}
|
||||
@ -210,5 +210,5 @@ impl GUI<Text> for UI {
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
ezgui::run(UI::new(args.get(1)), "Synthetic map editor", 1024, 768);
|
||||
ezgui::run(UI::new(args.get(1)), "Synthetic map editor");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user