]>
Commit | Line | Data |
---|---|---|
1 | // Copyright (C) 2024 Rubén Beltrán del Río | |
2 | ||
3 | // This program is free software: you can redistribute it and/or modify | |
4 | // it under the terms of the GNU General Public License as published by | |
5 | // the Free Software Foundation, either version 3 of the License, or | |
6 | // (at your option) any later version. | |
7 | ||
8 | // This program is distributed in the hope that it will be useful, | |
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | // GNU General Public License for more details. | |
12 | ||
13 | // You should have received a copy of the GNU General Public License | |
14 | // along with this program. If not, see https://map.tranquil.systems. | |
15 | import Patterns | |
16 | import SwiftUI | |
17 | ||
18 | struct MapStages: View { | |
19 | ||
20 | let mapSize: CGSize | |
21 | let lineWidth: CGFloat | |
22 | let stages: [CGFloat] | |
23 | let opacity = 0.1 | |
24 | ||
25 | var body: some View { | |
26 | ZStack(alignment: .topLeading) { | |
27 | PatternView( | |
28 | design: .constant(.stitch), pixelSize: 1.0, foregroundColor: .Map.stageForeground, | |
29 | backgroundColor: .Map.stageBackground | |
30 | ) | |
31 | .frame(width: w(stages[0]), height: mapSize.height) | |
32 | PatternView( | |
33 | design: .constant(.shingles), pixelSize: 1.0, foregroundColor: .Map.stageForeground, | |
34 | backgroundColor: .Map.stageBackground | |
35 | ) | |
36 | .offset(CGSize(width: w(stages[0]), height: 0)) | |
37 | .frame(width: w(stages[1]) - w(stages[0]), height: mapSize.height) | |
38 | PatternView( | |
39 | design: .constant(.shadowGrid), pixelSize: 1.0, foregroundColor: .Map.stageForeground, | |
40 | backgroundColor: .Map.stageBackground | |
41 | ) | |
42 | .offset(CGSize(width: w(stages[1]), height: 0)) | |
43 | .frame(width: w(stages[2]) - w(stages[1]), height: mapSize.height) | |
44 | PatternView( | |
45 | design: .constant(.wicker), pixelSize: 1.0, foregroundColor: .Map.stageForeground, | |
46 | backgroundColor: .Map.stageBackground | |
47 | ) | |
48 | .offset(CGSize(width: w(stages[2]), height: 0)) | |
49 | .frame(width: mapSize.width - w(stages[2]), height: mapSize.height) | |
50 | ||
51 | Path { path in | |
52 | path.move(to: CGPoint(x: w(stages[0]), y: 0)) | |
53 | path.addLine(to: CGPoint(x: w(stages[0]), y: mapSize.height)) | |
54 | path.closeSubpath() | |
55 | path.move(to: CGPoint(x: w(stages[1]), y: 0)) | |
56 | path.addLine(to: CGPoint(x: w(stages[1]), y: mapSize.height)) | |
57 | path.closeSubpath() | |
58 | path.move(to: CGPoint(x: w(stages[2]), y: 0)) | |
59 | path.addLine(to: CGPoint(x: w(stages[2]), y: mapSize.height)) | |
60 | path.closeSubpath() | |
61 | path.move(to: CGPoint(x: w(stages[0]), y: 0)) | |
62 | path.closeSubpath() | |
63 | }.strokedPath(StrokeStyle(lineWidth: lineWidth / 4, dash: [10.0, 18.0])).stroke( | |
64 | Color.Map.axisColor) | |
65 | } | |
66 | } | |
67 | ||
68 | func w(_ dimension: CGFloat) -> CGFloat { | |
69 | max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) | |
70 | } | |
71 | } | |
72 | ||
73 | #Preview { | |
74 | MapStages( | |
75 | mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(0.5), | |
76 | stages: [25.0, 50.0, 75.0]) | |
77 | } |