SPB Git

Repository Public BSD-3-Clause

LayersScreen.swift 9.1 KB 190 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Maps9// File             : Apps/ORIXMaps/Sources/Layers/LayersScreen.swift10// Module           : Layers11// Repository       : https://git.spboucher.ai/orix-maps12// Created          : 2026-11-2513// Last Modified    : 2026-11-2514//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import ORIXDesignSystem89import ORIXMapStyle90import SwiftUI9192extension Color {93    nonisolated init(_ c: HexColor) { self.init(red: Double(c.red) / 255, green: Double(c.green) / 255, blue: Double(c.blue) / 255, opacity: Double(c.alpha) / 255) }94}9596extension MapTheme {97    /// Built-in themes are named by the application so that they follow the interface language.98    var displayName: String {99        switch id {100        case "orix.day": String(localized: "ORIX Day")101        case "orix.midnight": String(localized: "Midnight")102        case "orix.terrain": String(localized: "Terrain")103        case "orix.minimal": String(localized: "Minimal")104        case "orix.transit": String(localized: "Transit")105        case "orix.topographic": String(localized: "Topographic")106        case "orix.explorer": String(localized: "Explorer")107        case "orix.highcontrast": String(localized: "High Contrast")108        default: name109        }110    }111}112113/// A miniature drawn from a theme's palette: land, water, a park, roads and a label bar.114struct ThemeSwatch: View {115    let theme: MapTheme116117    var body: some View {118        Canvas { ctx, size in119            let w = size.width, h = size.height120            ctx.fill(Path(CGRect(origin: .zero, size: size)), with: .color(Color(theme[.land])))121            var water = Path()122            water.move(to: CGPoint(x: w * 0.62, y: 0)); water.addCurve(to: CGPoint(x: w, y: h * 0.7), control1: CGPoint(x: w * 0.7, y: h * 0.35), control2: CGPoint(x: w * 0.85, y: h * 0.4))123            water.addLine(to: CGPoint(x: w, y: 0)); water.closeSubpath()124            ctx.fill(water, with: .color(Color(theme[.water])))125            ctx.fill(Path(roundedRect: CGRect(x: w * 0.08, y: h * 0.52, width: w * 0.3, height: h * 0.34), cornerRadius: 4), with: .color(Color(theme[.park])))126            if theme.showBuildings {127                for (x, y) in [(0.12, 0.14), (0.26, 0.14), (0.12, 0.3), (0.44, 0.62)] {128                    ctx.fill(Path(CGRect(x: w * x, y: h * y, width: w * 0.1, height: h * 0.1)), with: .color(Color(theme[.building])))129                }130            }131            func road(_ a: CGPoint, _ b: CGPoint, _ role: ColorRole, _ casing: ColorRole, _ width: CGFloat) {132                var p = Path(); p.move(to: a); p.addLine(to: b)133                let k = CGFloat(theme.roadWidthScale)134                if theme.roadCasings { ctx.stroke(p, with: .color(Color(theme[casing])), style: StrokeStyle(lineWidth: (width + 1.6) * k, lineCap: .round)) }135                ctx.stroke(p, with: .color(Color(theme[role])), style: StrokeStyle(lineWidth: width * k, lineCap: .round))136            }137            road(CGPoint(x: 0, y: h * 0.46), CGPoint(x: w * 0.74, y: h * 0.46), .minorRoad, .minorRoadCasing, 2.2)138            road(CGPoint(x: w * 0.42, y: 0), CGPoint(x: w * 0.42, y: h), .majorRoad, .majorRoadCasing, 3)139            road(CGPoint(x: 0, y: h * 0.92), CGPoint(x: w * 0.9, y: h * 0.2), .highway, .highwayCasing, 4)140            ctx.fill(Path(roundedRect: CGRect(x: w * 0.5, y: h * 0.74, width: w * 0.3, height: 5), cornerRadius: 2.5), with: .color(Color(theme[.placeLabel])))141        }142        .clipShape(.rect(cornerRadius: 12))143        .accessibilityHidden(true)144    }145}146147/// Theme picker and map display options.148struct LayersScreen: View {149    @Environment(AppModel.self) private var app150151    var body: some View {152        @Bindable var settings = app.settings153        ScrollView {154            VStack(alignment: .leading, spacing: ORIX.Spacing.l) {155                Text("Theme").font(.headline).accessibilityAddTraits(.isHeader)156                LazyVGrid(columns: [GridItem(.adaptive(minimum: 104), spacing: ORIX.Spacing.m)], spacing: ORIX.Spacing.m) {157                    ForEach(app.themes.all) { theme in158                        let selected = theme.id == app.settings.themeID159                        Button { app.selectTheme(theme.id) } label: {160                            VStack(spacing: 6) {161                                ThemeSwatch(theme: theme)162                                    .frame(height: 72)163                                    .overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(selected ? ORIX.Palette.accent : Color.primary.opacity(0.12), lineWidth: selected ? 3 : 1))164                                Text(theme.displayName).font(.caption.weight(selected ? .semibold : .regular)).lineLimit(1).minimumScaleFactor(0.8)165                            }166                        }167                        .buttonStyle(.plain)168                        .accessibilityLabel(Text(theme.displayName))169                        .accessibilityAddTraits(selected ? [.isSelected, .isButton] : .isButton)170                        .accessibilityIdentifier("theme.\(theme.id)")171                    }172                }173                Toggle("Use Midnight when the interface is dark", isOn: $settings.nightThemeAutomatic)174                    .onChange(of: app.settings.nightThemeAutomatic) { _, _ in app.refreshStyle() }175                if app.effectiveTheme.showTerrain {176                    NoticeView("Relief shading and contour lines appear only in regions that include terrain data. No installed region includes it yet.")177                }178                if app.effectiveTheme.emphasizeTransit {179                    NoticeView("Transit shows the railways and stations present in the map data. It has no schedules and no live service information.")180                }181                Button { app.modal = .studio } label: { Label("Edit themes in Map Studio", systemImage: "paintpalette") }182                    .buttonStyle(SecondaryButtonStyle())183            }184            .padding(ORIX.Spacing.l)185        }186        .navigationTitle("Map")187        .navigationBarTitleDisplayMode(.inline)188    }189}190
Files main
Menu

Theme