1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// src/editor/hook/view_menu_drive.rs
//
// EditorHook: the Display menu's open state, click routing, and draw. The
// menu's geometry lives in `editor/view_menu.rs`; the selections it edits
// (view mode, show flags, the billboard toggle) are published to the renderer
// each tick as the `ViewOverrides` resource.
use super::*;
impl EditorHook {
// The top bar's Display chip.
pub(super) fn toggle_display_menu(&mut self) {
self.display_menu_open = !self.display_menu_open;
if self.display_menu_open {
self.create_menu = None;
}
}
// An open Display menu takes the press: a row acts (the menu stays up so
// several toggles land in one visit), anywhere else dismisses. A press on
// the top bar is left to the bar's own hit test, whose Display chip
// toggles the menu.
pub(super) fn route_display_menu_click(&mut self, input: &FrameInput, vp: [f32; 2]) -> bool {
if !self.display_menu_open {
return false;
}
let (mx, my) = (input.mouse_x, input.mouse_y);
if my <= hud::BAR_H {
return false;
}
if let Some(i) = view_menu::hit_row(mx, my, vp[0]) {
match view_menu::rows()[i] {
view_menu::MenuRow::Mode(m) => self.view_mode = m,
view_menu::MenuRow::Heading(_) => {}
view_menu::MenuRow::Flag(f, _) => {
self.show_flags = self.show_flags.toggled(f);
}
view_menu::MenuRow::Billboards => self.show_billboards = !self.show_billboards,
view_menu::MenuRow::Extent(c, _) => {
self.extent_show = self.extent_show.toggled(c);
}
}
return true;
}
if view_menu::over(mx, my, vp[0]) {
return true;
}
self.display_menu_open = false;
true
}
pub(super) fn drive_display_menu_draw(
&self,
world: &mut World,
vp: [f32; 2],
shown: bool,
mouse: [f32; 2],
) {
if !shown || !self.display_menu_open || self.sim.playing() {
view_menu::hide(world);
return;
}
view_menu::apply(
world,
vp[0],
view_menu::MenuState {
mode: self.view_mode,
show: self.show_flags,
billboards: self.show_billboards,
extents: self.extent_show,
},
mouse,
);
}
}