]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Base Components/MapRender/MapStages.swift
0fc8f486a7ec16e5ef49d469a0e992387576b786
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapStages.swift
1 import SwiftUI
2 import Patterns
3
4 struct MapStages: View {
5
6 let mapSize: CGSize
7 let lineWidth: CGFloat
8 let stages: [CGFloat]
9 let opacity = 0.1
10
11 var body: some View {
12 ZStack(alignment: .topLeading) {
13 PatternView(design: .constant(.stitch), pixelSize: 1.0, foregroundColor: .map.stageForeground, backgroundColor: .map.stageBackground)
14 .frame(width: w(stages[0]), height: mapSize.height)
15 PatternView(design: .constant(.shingles), pixelSize: 1.0, foregroundColor: .map.stageForeground, backgroundColor: .map.stageBackground)
16 .offset(CGSize(width: w(stages[0]), height: 0))
17 .frame(width: w(stages[1]) - w(stages[0]), height: mapSize.height)
18 PatternView(design: .constant(.shadowGrid), pixelSize: 1.0, foregroundColor: .map.stageForeground, backgroundColor: .map.stageBackground)
19 .offset(CGSize(width: w(stages[1]), height: 0))
20 .frame(width: w(stages[2]) - w(stages[1]), height: mapSize.height)
21 PatternView(design: .constant(.wicker), pixelSize: 1.0, foregroundColor: .map.stageForeground, backgroundColor: .map.stageBackground)
22 .offset(CGSize(width: w(stages[2]), height: 0))
23 .frame(width: mapSize.width - w(stages[2]), height: mapSize.height)
24
25 Path { path in
26 path.move(to: CGPoint(x: w(stages[0]), y: 0))
27 path.addLine(to: CGPoint(x: w(stages[0]), y: mapSize.height))
28 path.closeSubpath()
29 path.move(to: CGPoint(x: w(stages[1]), y: 0))
30 path.addLine(to: CGPoint(x: w(stages[1]), y: mapSize.height))
31 path.closeSubpath()
32 path.move(to: CGPoint(x: w(stages[2]), y: 0))
33 path.addLine(to: CGPoint(x: w(stages[2]), y: mapSize.height))
34 path.closeSubpath()
35 path.move(to: CGPoint(x: w(stages[0]), y: 0))
36 path.closeSubpath()
37 }.strokedPath(StrokeStyle(lineWidth: lineWidth / 4, dash: [10.0, 18.0])).stroke(Color.map.axisColor)
38 }
39 }
40
41 func w(_ dimension: CGFloat) -> CGFloat {
42 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
43 }
44 }
45
46 struct MapStages_Previews: PreviewProvider {
47 static var previews: some View {
48 MapStages(
49 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(0.5),
50 stages: [25.0, 50.0, 75.0])
51 }
52 }