mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
borrow text to draw, stop cloning everywhere
This commit is contained in:
parent
c2ddb7587b
commit
4eece7bae7
@ -9,6 +9,7 @@ cargo clippy -- \
|
||||
-A clippy::collapsible_if \
|
||||
-A clippy::cyclomatic_complexity \
|
||||
-A clippy::expect_fun_call \
|
||||
-A clippy::float_cmp \
|
||||
-A clippy::if_same_then_else \
|
||||
-A clippy::large_enum_variant \
|
||||
-A clippy::many_single_char_names \
|
||||
|
@ -84,7 +84,7 @@ impl GUI for UI {
|
||||
self.world.draw_selected(g, id);
|
||||
}
|
||||
|
||||
g.draw_blocking_text(self.osd.clone(), ezgui::BOTTOM_LEFT);
|
||||
g.draw_blocking_text(&self.osd, ezgui::BOTTOM_LEFT);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -237,3 +237,22 @@ other modes...
|
||||
|
||||
|
||||
maybe top menu changes by the mode! some stuff could be common (debug plugins?)
|
||||
|
||||
Forget top menu, modal menu, OSD, right-click menus, all the current GUI things. Start over from each mode -- how should it work ideally?
|
||||
- how do we indicate what major mode we're in and explain how to get out? top menu?
|
||||
|
||||
- tutorial mode
|
||||
- challenge creation mode
|
||||
- manage neighborhoods and scenarios
|
||||
- how should the main functions be chosen? load/save neighborhood/scenario
|
||||
- interactive sandbox mode
|
||||
- spawn traffic
|
||||
- maybe choose the spawn tool, then can select a building or intersection or road?
|
||||
- dont even allow selection of things that dont make sense
|
||||
- persistent (but maybe hideable?) controls for sim, OSD showing time and agent count and stuff
|
||||
- map edit mode
|
||||
- this makes sense as a separate thing, to visualize the edits and make sure to save them
|
||||
- and to make it clear that there's no mixing with a running sim
|
||||
- but how fluidly should this be enterable from the sandbox mode?
|
||||
- debug mode
|
||||
- stuff like tooltips, warp, search only belong here... until i make more generally usable navigation tools
|
||||
|
@ -163,7 +163,10 @@ impl GUI for GameState {
|
||||
txt.add_line("Great! Press ENTER to continue.".to_string());
|
||||
}
|
||||
// TODO Get rid of top menu and OSD and then put this somewhere more sensible. :)
|
||||
g.draw_blocking_text(txt, (HorizontalAlignment::Right, VerticalAlignment::Center));
|
||||
g.draw_blocking_text(
|
||||
&txt,
|
||||
(HorizontalAlignment::Right, VerticalAlignment::Center),
|
||||
);
|
||||
None
|
||||
}
|
||||
Mode::TutorialPart2(orig_cam_zoom) => {
|
||||
@ -174,7 +177,10 @@ impl GUI for GameState {
|
||||
txt.add_line("".to_string());
|
||||
txt.add_line("Great! Press ENTER to continue.".to_string());
|
||||
}
|
||||
g.draw_blocking_text(txt, (HorizontalAlignment::Right, VerticalAlignment::Center));
|
||||
g.draw_blocking_text(
|
||||
&txt,
|
||||
(HorizontalAlignment::Right, VerticalAlignment::Center),
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl AmbientPlugin for DebugObjectsState {
|
||||
if self.tooltip_key_held {
|
||||
if let Some(id) = self.selected {
|
||||
let txt = id.tooltip_lines(g, ctx);
|
||||
g.draw_mouse_tooltip(txt);
|
||||
g.draw_mouse_tooltip(&txt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ impl AmbientPlugin for DebugObjectsState {
|
||||
let mut txt = Text::new();
|
||||
txt.add_line(format!("{}", pt));
|
||||
txt.add_line(format!("{}", gps));
|
||||
g.draw_mouse_tooltip(txt);
|
||||
g.draw_mouse_tooltip(&txt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,21 +140,21 @@ impl BlockingPlugin for DebugPolygon {
|
||||
fn draw(&self, g: &mut GfxCtx, ctx: &DrawCtx) {
|
||||
match self.items[self.current] {
|
||||
Item::Point(pt) => {
|
||||
g.draw_text_at(Text::from_line(format!("{}", self.current)), pt);
|
||||
g.draw_text_at(&Text::from_line(format!("{}", self.current)), pt);
|
||||
}
|
||||
Item::Triangle(ref tri) => {
|
||||
for pt in &[tri.pt1, tri.pt2, tri.pt3] {
|
||||
g.draw_text_at(Text::from_line(format!("{}", self.current)), *pt);
|
||||
g.draw_text_at(&Text::from_line(format!("{}", self.current)), *pt);
|
||||
}
|
||||
g.draw_polygon(ctx.cs.get("selected"), &Polygon::from_triangle(tri));
|
||||
}
|
||||
Item::Polygon(ref poly) => {
|
||||
g.draw_polygon(ctx.cs.get("selected"), poly);
|
||||
g.draw_text_at(Text::from_line(format!("{}", self.current)), poly.center());
|
||||
g.draw_text_at(&Text::from_line(format!("{}", self.current)), poly.center());
|
||||
}
|
||||
}
|
||||
if let Some(pt) = self.center {
|
||||
g.draw_text_at(Text::from_line("c".to_string()), pt);
|
||||
g.draw_text_at(&Text::from_line("c".to_string()), pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ impl NonblockingPlugin for ShowScoreState {
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, _ctx: &DrawCtx) {
|
||||
g.draw_blocking_text(
|
||||
self.txt.clone(),
|
||||
&self.txt,
|
||||
(HorizontalAlignment::Right, VerticalAlignment::BelowTopMenu),
|
||||
);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ impl NonblockingPlugin for Legend {
|
||||
ctx.cs.get("turns protected by traffic signal right now"),
|
||||
);
|
||||
g.draw_text_at_screenspace_topleft(
|
||||
Text::from_line("Protected turn".to_string()),
|
||||
&Text::from_line("Protected turn".to_string()),
|
||||
ScreenPt::new(self.top_left.x + 20.0, self.top_left.y + 10.0),
|
||||
);
|
||||
|
||||
@ -83,7 +83,7 @@ impl NonblockingPlugin for Legend {
|
||||
.get("turns allowed with yielding by traffic signal right now"),
|
||||
);
|
||||
g.draw_text_at_screenspace_topleft(
|
||||
Text::from_line("Yield turn".to_string()),
|
||||
&Text::from_line("Yield turn".to_string()),
|
||||
ScreenPt::new(self.top_left.x + 20.0, self.top_left.y + 110.0),
|
||||
);
|
||||
|
||||
|
@ -78,8 +78,7 @@ impl AmbientPlugin for NeighborhoodSummary {
|
||||
|
||||
g.redraw(&self.draw_all_regions);
|
||||
for r in &self.regions {
|
||||
// TODO ezgui should take borrows
|
||||
g.draw_text_at(r.summary.clone(), r.center);
|
||||
g.draw_text_at(&r.summary, r.center);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ pub fn draw_signal_diagram(
|
||||
draw_signal_cycle(&cycle, g, ctx);
|
||||
|
||||
g.draw_text_at_screenspace_topleft(
|
||||
txt,
|
||||
&txt,
|
||||
ScreenPt::new(x1_screen + 10.0 + (intersection_width * zoom), y1),
|
||||
);
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ impl GUI for UI {
|
||||
abstutil::prettyprint_usize(g.get_num_uploads()),
|
||||
abstutil::prettyprint_usize(g.num_draw_calls),
|
||||
));
|
||||
g.draw_blocking_text(osd, BOTTOM_LEFT);
|
||||
g.draw_blocking_text(&osd, BOTTOM_LEFT);
|
||||
}
|
||||
|
||||
sample_intersection
|
||||
|
@ -141,7 +141,7 @@ impl<'a> GfxCtx<'a> {
|
||||
// The text box covers up what's beneath and eats the cursor (for get_cursor_in_map_space).
|
||||
pub fn draw_blocking_text(
|
||||
&mut self,
|
||||
txt: Text,
|
||||
txt: &Text,
|
||||
(horiz, vert): (HorizontalAlignment, VerticalAlignment),
|
||||
) {
|
||||
if txt.is_empty() {
|
||||
@ -175,7 +175,7 @@ impl<'a> GfxCtx<'a> {
|
||||
}
|
||||
|
||||
// TODO Rename these draw_nonblocking_text_*
|
||||
pub fn draw_text_at(&mut self, txt: Text, map_pt: Pt2D) {
|
||||
pub fn draw_text_at(&mut self, txt: &Text, map_pt: Pt2D) {
|
||||
let (width, height) = self.text_dims(&txt);
|
||||
let pt = self.canvas.map_to_screen(map_pt);
|
||||
text::draw_text_bubble(
|
||||
@ -190,12 +190,12 @@ impl<'a> GfxCtx<'a> {
|
||||
self.canvas.text_dims(txt)
|
||||
}
|
||||
|
||||
pub fn draw_text_at_screenspace_topleft(&mut self, txt: Text, pt: ScreenPt) {
|
||||
pub fn draw_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) {
|
||||
let dims = self.text_dims(&txt);
|
||||
text::draw_text_bubble(self, pt, txt, dims);
|
||||
}
|
||||
|
||||
pub fn draw_mouse_tooltip(&mut self, txt: Text) {
|
||||
pub fn draw_mouse_tooltip(&mut self, txt: &Text) {
|
||||
let (width, height) = self.text_dims(&txt);
|
||||
let x1 = self.canvas.cursor_x - (width / 2.0);
|
||||
let y1 = self.canvas.cursor_y - (height / 2.0);
|
||||
|
@ -230,7 +230,7 @@ pub fn run<G: GUI, F: FnOnce(&mut Canvas, &Prerender) -> G>(
|
||||
let mut target = display.draw();
|
||||
let mut g = GfxCtx::new(&canvas, &prerender, &mut target, &program);
|
||||
g.draw_blocking_text(
|
||||
Text::from_line("Loading... Check terminal for details".to_string()),
|
||||
&Text::from_line("Loading... Check terminal for details".to_string()),
|
||||
(HorizontalAlignment::Center, VerticalAlignment::Center),
|
||||
);
|
||||
canvas
|
||||
|
@ -146,7 +146,7 @@ impl Text {
|
||||
pub fn draw_text_bubble(
|
||||
g: &mut GfxCtx,
|
||||
top_left: ScreenPt,
|
||||
txt: Text,
|
||||
txt: &Text,
|
||||
// Callers almost always calculate this anyway
|
||||
(total_width, total_height): (f64, f64),
|
||||
) -> ScreenRectangle {
|
||||
|
@ -34,6 +34,6 @@ impl LogScroller {
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx) {
|
||||
g.draw_blocking_text(self.text.clone(), CENTERED);
|
||||
g.draw_blocking_text(&self.text, CENTERED);
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ impl<T: Clone> Menu<T> {
|
||||
x2: self.first_choice_row.x2,
|
||||
y2: self.top_left.y + (self.row_height * (txt.num_lines() as f64)),
|
||||
});
|
||||
g.draw_text_at_screenspace_topleft(txt, self.top_left);
|
||||
g.draw_text_at_screenspace_topleft(&txt, self.top_left);
|
||||
}
|
||||
|
||||
pub fn current_choice(&self) -> Option<&T> {
|
||||
|
@ -62,7 +62,7 @@ impl<T: Clone> ScrollingMenu<T> {
|
||||
let n = (g.canvas.window_height / g.canvas.line_height).floor() as isize - 1 - 6;
|
||||
if n <= 0 {
|
||||
// Weird small window, just display the prompt and bail out.
|
||||
g.draw_blocking_text(txt, CENTERED);
|
||||
g.draw_blocking_text(&txt, CENTERED);
|
||||
return;
|
||||
}
|
||||
n as usize
|
||||
@ -90,7 +90,7 @@ impl<T: Clone> ScrollingMenu<T> {
|
||||
}
|
||||
}
|
||||
|
||||
g.draw_blocking_text(txt, CENTERED);
|
||||
g.draw_blocking_text(&txt, CENTERED);
|
||||
}
|
||||
|
||||
pub fn current_choice(&self) -> &T {
|
||||
|
@ -36,7 +36,7 @@ impl TextBox {
|
||||
txt.append("|".to_string(), Some(text::SELECTED_COLOR));
|
||||
}
|
||||
|
||||
g.draw_blocking_text(txt, CENTERED);
|
||||
g.draw_blocking_text(&txt, CENTERED);
|
||||
}
|
||||
|
||||
pub fn event(&mut self, input: &mut UserInput) -> InputResult<()> {
|
||||
|
@ -147,7 +147,7 @@ impl TopMenu {
|
||||
None
|
||||
});
|
||||
txt.add_line(f.name.to_string());
|
||||
g.draw_text_at_screenspace_topleft(txt, ScreenPt::new(f.rectangle.x1, f.rectangle.y1));
|
||||
g.draw_text_at_screenspace_topleft(&txt, ScreenPt::new(f.rectangle.x1, f.rectangle.y1));
|
||||
}
|
||||
|
||||
if let Some((_, ref menu)) = self.submenu {
|
||||
|
@ -120,7 +120,7 @@ impl GUI for UI {
|
||||
|
||||
if self.show_labels {
|
||||
for (pt, label) in labels.into_iter() {
|
||||
g.draw_text_at(Text::from_line(label), pt);
|
||||
g.draw_text_at(&Text::from_line(label), pt);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -123,13 +123,13 @@ impl Road {
|
||||
|
||||
if let Some(ref label) = self.fwd_label {
|
||||
g.draw_text_at(
|
||||
Text::from_line(label.to_string()),
|
||||
&Text::from_line(label.to_string()),
|
||||
self.polygon(FORWARDS, model).center(),
|
||||
);
|
||||
}
|
||||
if let Some(ref label) = self.back_label {
|
||||
g.draw_text_at(
|
||||
Text::from_line(label.to_string()),
|
||||
&Text::from_line(label.to_string()),
|
||||
self.polygon(BACKWARDS, model).center(),
|
||||
);
|
||||
}
|
||||
@ -226,7 +226,7 @@ impl Model {
|
||||
g.draw_circle(color, &i.circle());
|
||||
|
||||
if let Some(ref label) = i.label {
|
||||
g.draw_text_at(Text::from_line(label.to_string()), i.center);
|
||||
g.draw_text_at(&Text::from_line(label.to_string()), i.center);
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ impl Model {
|
||||
g.draw_polygon(color, &b.polygon());
|
||||
|
||||
if let Some(ref label) = b.label {
|
||||
g.draw_text_at(Text::from_line(label.to_string()), b.center);
|
||||
g.draw_text_at(&Text::from_line(label.to_string()), b.center);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ impl GUI for UI {
|
||||
_ => {}
|
||||
};
|
||||
|
||||
g.draw_blocking_text(self.osd.clone(), ezgui::BOTTOM_LEFT);
|
||||
g.draw_blocking_text(&self.osd, ezgui::BOTTOM_LEFT);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ impl<ID: ObjectID> World<ID> {
|
||||
pub fn draw_selected(&self, g: &mut GfxCtx, id: ID) {
|
||||
let obj = &self.objects[&id];
|
||||
g.draw_polygon(Color::BLUE, &obj.polygon);
|
||||
g.draw_mouse_tooltip(obj.info.clone());
|
||||
g.draw_mouse_tooltip(&obj.info);
|
||||
}
|
||||
|
||||
pub fn mouseover_something(&self, ctx: &EventCtx, hide: &HashSet<ID>) -> Option<ID> {
|
||||
|
Loading…
Reference in New Issue
Block a user