1 // Copyright (C) 2024 Rubén Beltrán del Río
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.
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.
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.
18 struct MapStages: View {
21 let lineWidth: CGFloat
26 ZStack(alignment: .topLeading) {
28 design: .constant(.stitch), pixelSize: 1.0, foregroundColor: .Map.stageForeground,
29 backgroundColor: .Map.stageBackground
31 .frame(width: w(stages[0]), height: mapSize.height)
33 design: .constant(.shingles), pixelSize: 1.0, foregroundColor: .Map.stageForeground,
34 backgroundColor: .Map.stageBackground
36 .offset(CGSize(width: w(stages[0]), height: 0))
37 .frame(width: w(stages[1]) - w(stages[0]), height: mapSize.height)
39 design: .constant(.shadowGrid), pixelSize: 1.0, foregroundColor: .Map.stageForeground,
40 backgroundColor: .Map.stageBackground
42 .offset(CGSize(width: w(stages[1]), height: 0))
43 .frame(width: w(stages[2]) - w(stages[1]), height: mapSize.height)
45 design: .constant(.wicker), pixelSize: 1.0, foregroundColor: .Map.stageForeground,
46 backgroundColor: .Map.stageBackground
48 .offset(CGSize(width: w(stages[2]), height: 0))
49 .frame(width: mapSize.width - w(stages[2]), height: mapSize.height)
52 path.move(to: CGPoint(x: w(stages[0]), y: 0))
53 path.addLine(to: CGPoint(x: w(stages[0]), y: mapSize.height))
55 path.move(to: CGPoint(x: w(stages[1]), y: 0))
56 path.addLine(to: CGPoint(x: w(stages[1]), y: mapSize.height))
58 path.move(to: CGPoint(x: w(stages[2]), y: 0))
59 path.addLine(to: CGPoint(x: w(stages[2]), y: mapSize.height))
61 path.move(to: CGPoint(x: w(stages[0]), y: 0))
63 }.strokedPath(StrokeStyle(lineWidth: lineWidth / 4, dash: [10.0, 18.0])).stroke(
68 func w(_ dimension: CGFloat) -> CGFloat {
69 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
75 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(0.5),
76 stages: [25.0, 50.0, 75.0])