mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 02:33:54 +03:00
fix a few DPI issues yuwen found, most caused by creating screen-space
geometry based on percentge of window width
This commit is contained in:
parent
8c77cdd889
commit
d3ade25c9f
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ScreenDims, ScreenPt,
|
||||
Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, JustDraw, Line, ScreenDims, ScreenPt,
|
||||
ScreenRectangle, Text, TextExt, Widget, WidgetImpl, WidgetOutput,
|
||||
};
|
||||
use abstutil::prettyprint_usize;
|
||||
@ -217,7 +217,8 @@ impl<T: Yvalue<T>> LinePlot<T> {
|
||||
for (color, poly) in Text::from(Line(t.to_string())).render_ctx(ctx).consume() {
|
||||
batch.fancy_push(color, poly.rotate(Angle::new_degs(-15.0)));
|
||||
}
|
||||
row.push(Widget::draw_batch(ctx, batch.autocrop()));
|
||||
// The text is already scaled; don't use Widget::draw_batch and scale it again.
|
||||
row.push(JustDraw::wrap(ctx, batch.autocrop()));
|
||||
}
|
||||
let x_axis = Widget::row(row).padding(10);
|
||||
|
||||
|
@ -15,7 +15,10 @@ 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, ScreenPt, Text};
|
||||
use ezgui::{
|
||||
hotkey, lctrl, Color, EventCtx, GeomBatch, GfxCtx, Key, Line, ScreenDims, ScreenPt,
|
||||
ScreenRectangle, Text,
|
||||
};
|
||||
use geom::Polygon;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
@ -256,6 +259,10 @@ impl CommonState {
|
||||
let draw = g.upload(batch);
|
||||
let top_left = ScreenPt::new(0.0, g.canvas.window_height - 1.5 * g.default_line_height());
|
||||
g.redraw_at(top_left, &draw);
|
||||
g.canvas.mark_covered_area(ScreenRectangle::top_left(
|
||||
top_left,
|
||||
ScreenDims::new(g.canvas.window_width, 1.5 * g.default_line_height()),
|
||||
));
|
||||
}
|
||||
|
||||
// Meant to be used for launching from other states
|
||||
|
@ -183,7 +183,10 @@ impl State for TrafficSignalEditor {
|
||||
"Export" => {
|
||||
let ts = orig_signal.export(&app.primary.map);
|
||||
abstutil::write_json(
|
||||
format!("traffic_signal_data/{}.json", ts.intersection_osm_node_id),
|
||||
format!(
|
||||
"../traffic_signal_data/{}.json",
|
||||
ts.intersection_osm_node_id
|
||||
),
|
||||
&ts,
|
||||
);
|
||||
}
|
||||
@ -288,7 +291,9 @@ impl State for TrafficSignalEditor {
|
||||
|
||||
pub fn make_top_panel(ctx: &mut EventCtx, app: &App, can_undo: bool, can_redo: bool) -> Composite {
|
||||
let row = vec![
|
||||
Btn::text_fg("Finish").build_def(ctx, hotkey(Key::Escape)),
|
||||
Btn::text_fg("Finish")
|
||||
.build_def(ctx, hotkey(Key::Escape))
|
||||
.margin_right(5),
|
||||
Btn::text_fg("Preview").build_def(ctx, lctrl(Key::P)),
|
||||
(if can_undo {
|
||||
Btn::svg_def("../data/system/assets/tools/undo.svg").build(ctx, "undo", lctrl(Key::Z))
|
||||
@ -316,12 +321,21 @@ pub fn make_top_panel(ctx: &mut EventCtx, app: &App, can_undo: bool, can_redo: b
|
||||
})
|
||||
.margin(15),
|
||||
if app.opts.dev {
|
||||
Btn::text_fg("Export").build_def(ctx, None)
|
||||
Btn::text_fg("Export")
|
||||
.tooltip(Text::from_multiline(vec![
|
||||
Line("This will create a JSON file in traffic_signal_data/.").small(),
|
||||
Line(
|
||||
"Contribute this to map how this traffic signal is currently timed in \
|
||||
real life.",
|
||||
)
|
||||
.small(),
|
||||
]))
|
||||
.build_def(ctx, None)
|
||||
} else {
|
||||
Widget::nothing()
|
||||
},
|
||||
];
|
||||
Composite::new(Widget::row(row).bg(app.cs.panel_bg))
|
||||
Composite::new(Widget::row(row).bg(app.cs.panel_bg).padding(5))
|
||||
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
|
||||
.build(ctx)
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ pub fn current_demand(
|
||||
let zoom = 300.0 / bounds.width();
|
||||
batch.push(app.cs.normal_intersection, polygon);
|
||||
|
||||
let mut txt_batch = GeomBatch::new();
|
||||
for (pl, demand) in demand_per_group {
|
||||
let percent = (demand as f64) / (total_demand as f64);
|
||||
batch.push(
|
||||
@ -138,14 +139,15 @@ pub fn current_demand(
|
||||
pl.make_arrow(percent * Distance::meters(3.0), ArrowCap::Triangle)
|
||||
.unwrap(),
|
||||
);
|
||||
batch.add_transformed(
|
||||
txt_batch.add_transformed(
|
||||
Text::from(Line(prettyprint_usize(demand))).render_ctx(ctx),
|
||||
pl.middle(),
|
||||
0.15,
|
||||
0.15 / ctx.get_scale_factor(),
|
||||
Angle::ZERO,
|
||||
RewriteColor::NoOp,
|
||||
);
|
||||
}
|
||||
batch.append(txt_batch);
|
||||
let mut transformed_batch = GeomBatch::new();
|
||||
for (color, poly) in batch.consume() {
|
||||
transformed_batch.fancy_push(
|
||||
|
@ -367,7 +367,7 @@ fn make_timeline(
|
||||
|
||||
let total_duration_so_far = end_time.unwrap_or_else(|| sim.time()) - phases[0].start_time;
|
||||
|
||||
let total_width = 0.22 * ctx.canvas.window_width;
|
||||
let total_width = 0.22 * ctx.canvas.window_width / ctx.get_scale_factor();
|
||||
let mut timeline = Vec::new();
|
||||
let num_phases = phases.len();
|
||||
let mut elevation = Vec::new();
|
||||
|
@ -328,7 +328,7 @@ pub fn make_signal_diagram(
|
||||
ctx,
|
||||
GeomBatch::from(vec![(
|
||||
Color::WHITE,
|
||||
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
|
||||
Polygon::rectangle(0.2 * ctx.canvas.window_width / ctx.get_scale_factor(), 2.0),
|
||||
)]),
|
||||
)
|
||||
.margin(15)
|
||||
@ -411,7 +411,7 @@ pub fn make_signal_diagram(
|
||||
}
|
||||
}
|
||||
|
||||
Composite::new(Widget::col(col).bg(app.cs.panel_bg))
|
||||
Composite::new(Widget::col(col).bg(app.cs.panel_bg).padding(10))
|
||||
.aligned(HorizontalAlignment::Left, VerticalAlignment::Top)
|
||||
.max_size_percent(30, 85)
|
||||
.build(ctx)
|
||||
|
@ -310,7 +310,7 @@ impl AgentMeter {
|
||||
ctx,
|
||||
GeomBatch::from(vec![(
|
||||
Color::WHITE,
|
||||
Polygon::rectangle(0.2 * ctx.canvas.window_width, 2.0),
|
||||
Polygon::rectangle(0.2 * ctx.canvas.window_width / ctx.get_scale_factor(), 2.0),
|
||||
)]),
|
||||
)
|
||||
.margin(15)
|
||||
|
Loading…
Reference in New Issue
Block a user