]> git.r.bdr.sh - rbdr/map/blob - Map/MapRenderComponents/MapStages.swift
052a3157af8a2ef2386a28ca4375704be38f63cd
[rbdr/map] / Map / MapRenderComponents / MapStages.swift
1 import SwiftUI
2
3 struct MapStages: View {
4
5 @Environment(\.colorScheme) var colorScheme
6
7 let mapSize: CGSize
8 let lineWidth: CGFloat
9 let stages: [CGFloat]
10 let opacity = 0.1
11
12 var color: MapColor {
13 MapColor.colorForScheme(colorScheme)
14 }
15
16 var body: some View {
17
18 ZStack(alignment: .topLeading) {
19 Path { path in
20 path.addRect(CGRect(x: 0, y: 0, width: w(stages[0]), height: mapSize.height))
21 }.fill(color.stages.i)
22 Path { path in
23 path.addRect(
24 CGRect(x: w(stages[0]), y: 0, width: w(stages[1]) - w(stages[0]), height: mapSize.height))
25 }.fill(color.stages.ii)
26 Path { path in
27 path.addRect(
28 CGRect(x: w(stages[1]), y: 0, width: w(stages[2]) - w(stages[1]), height: mapSize.height))
29 }.fill(color.stages.iii)
30 Path { path in
31 path.addRect(
32 CGRect(x: w(stages[2]), y: 0, width: mapSize.width - w(stages[2]), height: mapSize.height)
33 )
34 }.fill(color.stages.iv)
35
36 Path { path in
37 path.move(to: CGPoint(x: w(stages[0]), y: 0))
38 path.addLine(to: CGPoint(x: w(stages[0]), y: mapSize.height))
39 path.move(to: CGPoint(x: w(stages[1]), y: 0))
40 path.addLine(to: CGPoint(x: w(stages[1]), y: mapSize.height))
41 path.move(to: CGPoint(x: w(stages[2]), y: 0))
42 path.addLine(to: CGPoint(x: w(stages[2]), y: mapSize.height))
43 path.move(to: CGPoint(x: w(stages[0]), y: 0))
44 path.closeSubpath()
45 }.strokedPath(StrokeStyle(lineWidth: lineWidth, dash: [10.0])).stroke(color.foreground)
46 }
47 }
48
49 func w(_ dimension: CGFloat) -> CGFloat {
50 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
51 }
52 }
53
54 struct MapStages_Previews: PreviewProvider {
55 static var previews: some View {
56 MapStages(
57 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0),
58 stages: [25.0, 50.0, 75.0])
59 }
60 }