]>
Commit | Line | Data |
---|---|---|
be897af3 | 1 | // Copyright (C) 2024 Rubén Beltrán del Río |
98f09799 | 2 | |
be897af3 RBR |
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. | |
98f09799 | 7 | |
be897af3 RBR |
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. | |
98f09799 | 12 | |
be897af3 RBR |
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. | |
fdb4633d | 15 | import Patterns |
e2c37ac1 | 16 | import SwiftUI |
fdb4633d RBR |
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) { | |
e2c37ac1 | 27 | PatternView( |
be897af3 RBR |
28 | design: .constant(.stitch), pixelSize: 1.0, foregroundColor: .Map.stageForeground, |
29 | backgroundColor: .Map.stageBackground | |
e2c37ac1 RBR |
30 | ) |
31 | .frame(width: w(stages[0]), height: mapSize.height) | |
32 | PatternView( | |
be897af3 RBR |
33 | design: .constant(.shingles), pixelSize: 1.0, foregroundColor: .Map.stageForeground, |
34 | backgroundColor: .Map.stageBackground | |
e2c37ac1 RBR |
35 | ) |
36 | .offset(CGSize(width: w(stages[0]), height: 0)) | |
37 | .frame(width: w(stages[1]) - w(stages[0]), height: mapSize.height) | |
38 | PatternView( | |
be897af3 RBR |
39 | design: .constant(.shadowGrid), pixelSize: 1.0, foregroundColor: .Map.stageForeground, |
40 | backgroundColor: .Map.stageBackground | |
e2c37ac1 RBR |
41 | ) |
42 | .offset(CGSize(width: w(stages[1]), height: 0)) | |
43 | .frame(width: w(stages[2]) - w(stages[1]), height: mapSize.height) | |
44 | PatternView( | |
be897af3 RBR |
45 | design: .constant(.wicker), pixelSize: 1.0, foregroundColor: .Map.stageForeground, |
46 | backgroundColor: .Map.stageBackground | |
e2c37ac1 RBR |
47 | ) |
48 | .offset(CGSize(width: w(stages[2]), height: 0)) | |
49 | .frame(width: mapSize.width - w(stages[2]), height: mapSize.height) | |
fdb4633d RBR |
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() | |
e2c37ac1 | 63 | }.strokedPath(StrokeStyle(lineWidth: lineWidth / 4, dash: [10.0, 18.0])).stroke( |
be897af3 | 64 | Color.Map.axisColor) |
fdb4633d RBR |
65 | } |
66 | } | |
67 | ||
68 | func w(_ dimension: CGFloat) -> CGFloat { | |
69 | max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) | |
70 | } | |
71 | } | |
72 | ||
e2c37ac1 RBR |
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]) | |
fdb4633d | 77 | } |