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
76
77
78
79
80
81
82
83
84
85
mod world;
use crate::{Drawable, EventCtx, GeomBatch, GfxCtx, RewriteColor};
pub use world::{DummyID, ObjectID, World, WorldOutcome};
pub struct ToggleZoomed {
pub unzoomed: Drawable,
pub zoomed: Drawable,
just_unzoomed: bool,
}
impl ToggleZoomed {
pub fn new(ctx: &EventCtx, unzoomed: GeomBatch, zoomed: GeomBatch) -> ToggleZoomed {
ToggleZoomed {
unzoomed: ctx.upload(unzoomed),
zoomed: ctx.upload(zoomed),
just_unzoomed: false,
}
}
pub fn empty(ctx: &EventCtx) -> ToggleZoomed {
ToggleZoomed {
unzoomed: Drawable::empty(ctx),
zoomed: Drawable::empty(ctx),
just_unzoomed: false,
}
}
pub fn builder() -> ToggleZoomedBuilder {
ToggleZoomedBuilder {
unzoomed: GeomBatch::new(),
zoomed: GeomBatch::new(),
just_unzoomed: false,
}
}
pub fn draw(&self, g: &mut GfxCtx) {
if self.just_unzoomed || g.canvas.cam_zoom < g.canvas.settings.min_zoom_for_detail {
g.redraw(&self.unzoomed);
} else {
g.redraw(&self.zoomed);
}
}
}
#[derive(Clone)]
pub struct ToggleZoomedBuilder {
pub unzoomed: GeomBatch,
pub zoomed: GeomBatch,
just_unzoomed: bool,
}
impl ToggleZoomedBuilder {
pub fn color(mut self, transformation: RewriteColor) -> Self {
self.unzoomed = self.unzoomed.color(transformation);
self.zoomed = self.zoomed.color(transformation);
self
}
pub fn build(self, ctx: &EventCtx) -> ToggleZoomed {
if self.just_unzoomed {
assert!(self.zoomed.is_empty());
}
ToggleZoomed {
unzoomed: ctx.upload(self.unzoomed),
zoomed: ctx.upload(self.zoomed),
just_unzoomed: self.just_unzoomed,
}
}
}
impl std::convert::From<GeomBatch> for ToggleZoomedBuilder {
fn from(unzoomed: GeomBatch) -> Self {
Self {
unzoomed,
zoomed: GeomBatch::new(),
just_unzoomed: true,
}
}
}