Repository Public License
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Camera9// File : App/Sources/Features/Camera/CameraControls.swift10// Description : The physical-feeling controls: shutter, mode selector,11// lens selector and the ruler dial used by every manual12// parameter.13// Module : Features14// Repository : https://git.spboucher.ai/orix-camera15// Project Website : https://www.orixlab.dev16// Created : 2026-11-2117// Last Modified : 2026-11-2118//19// =============================================================================20// AUTHOR & PROFESSIONAL AFFILIATION21// =============================================================================22//23// Author : Simon-Pierre Boucher24// Position : Professor of Finance25// Institution : Université du Québec en Outaouais (UQO)26// Department : Département des sciences administratives27// Organization : SP Boucher28//29// Website : https://spboucher.ai30// Git : https://git.spboucher.ai31//32// =============================================================================33// OFFICIAL CONTACT DIRECTORY34// =============================================================================35//36// General : info@spboucher.ai37// Professional : contact@spboucher.ai38// Direct : simon@spboucher.ai39// Research : research@spboucher.ai40// Development : dev@spboucher.ai41// Support : support@spboucher.ai42// Security/Admin : admin@spboucher.ai43// Notifications : notifications@spboucher.ai44//45// Preferred Contact: support@spboucher.ai46//47// =============================================================================48// COPYRIGHT & INTELLECTUAL PROPERTY49// =============================================================================50//51// Copyright (c) 202652// Simon-Pierre Boucher53//54// All rights reserved where applicable.55//56// This file is governed by the applicable project license,57// copyright notices, institutional agreements and relevant law.58//59// Unless expressly authorized by the applicable license or60// rights holder, copying, redistribution, sublicensing,61// publication and commercial exploitation are not permitted.62//63// Existing third-party rights and notices remain unaffected.64//65// =============================================================================66// CONFIDENTIALITY & SECURITY67// =============================================================================68//69// Classification : Public70// Distribution : Public repository; use is governed by the project license71// Security Contact : admin@spboucher.ai72//73// Access to this source does not independently grant permission74// to redistribute or disclose confidential materials.75//76// Do not embed credentials, private keys, access tokens,77// certificates or confidential personal information.78//79// =============================================================================80// LICENSE & MAINTENANCE81// =============================================================================82//83// License : Proprietary, all rights reserved (see license file)84// License File : LICENSE85// Maintainer : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import ORIXDesign93import ORIXImaging94import SwiftUI9596/// A horizontal ruler. Dragging moves an index over `count` stops; each stop gives one haptic tick.97struct RulerDial: View {98 let count: Int99 @Binding var index: Int100 var majorEvery = 3101 var tint: Color = Instrument.manual102 let label: (Int) -> String103 var accessibilityName: LocalizedStringKey104 var haptics = true105106 @State private var dragStart: Int?107 private let spacing: CGFloat = 13108109 var body: some View {110 GeometryReader { proxy in111 let centre = proxy.size.width / 2112 Canvas { context, size in113 for i in 0..<count {114 let x = centre + CGFloat(i - index) * spacing115 guard x > -4, x < size.width + 4 else { continue }116 let major = i % majorEvery == 0117 let h: CGFloat = major ? 16 : 9118 let fade = max(0.15, 1 - abs(x - centre) / centre)119 var path = Path()120 path.move(to: CGPoint(x: x, y: size.height - h))121 path.addLine(to: CGPoint(x: x, y: size.height))122 context.stroke(path, with: .color(.white.opacity(Double(fade) * (major ? 0.9 : 0.45))), lineWidth: major ? 1.5 : 1)123 if major {124 let text = Text(label(i)).font(.system(size: 10, weight: .semibold, design: .rounded)).foregroundStyle(.white.opacity(Double(fade) * 0.8))125 context.draw(text, at: CGPoint(x: x, y: size.height - 26))126 }127 }128 var needle = Path()129 needle.move(to: CGPoint(x: centre, y: size.height - 24))130 needle.addLine(to: CGPoint(x: centre, y: size.height))131 context.stroke(needle, with: .color(tint), lineWidth: 2)132 }133 .contentShape(Rectangle())134 .gesture(135 DragGesture(minimumDistance: 2)136 .onChanged { value in137 if dragStart == nil { dragStart = index }138 let target = min(max((dragStart ?? index) - Int((value.translation.width / spacing).rounded()), 0), count - 1)139 if target != index {140 index = target141 if haptics { ORIXHaptics.tick() }142 }143 }144 .onEnded { _ in dragStart = nil }145 )146 }147 .frame(height: 48)148 .accessibilityElement()149 .accessibilityIdentifier("dial")150 .accessibilityLabel(Text(accessibilityName))151 .accessibilityValue(Text(label(index)))152 .accessibilityAdjustableAction { direction in153 switch direction {154 case .increment: index = min(index + 1, count - 1)155 case .decrement: index = max(index - 1, 0)156 @unknown default: break157 }158 }159 }160}161162struct ShutterButton: View {163 enum Look { case photo, videoIdle, videoRecording, stop, busy }164 let look: Look165 var progress: Double?166 let action: () -> Void167 var onHoldStart: (() -> Void)?168 var onHoldEnd: (() -> Void)?169170 @State private var pressed = false171 @State private var holding = false172173 var body: some View {174 ZStack {175 Circle().stroke(.white, lineWidth: 4).frame(width: 76, height: 76)176 if let progress {177 Circle().trim(from: 0, to: min(max(progress, 0), 1))178 .stroke(Instrument.manual, style: StrokeStyle(lineWidth: 4, lineCap: .round))179 .rotationEffect(.degrees(-90)).frame(width: 76, height: 76)180 }181 switch look {182 case .photo: Circle().fill(.white).frame(width: 62, height: 62)183 case .videoIdle: Circle().fill(Instrument.record).frame(width: 62, height: 62)184 case .videoRecording, .stop: RoundedRectangle(cornerRadius: 7, style: .continuous).fill(look == .stop ? Instrument.manual : Instrument.record).frame(width: 30, height: 30)185 case .busy: ProgressView().tint(.white)186 }187 }188 .scaleEffect(pressed ? 0.93 : 1)189 .animation(.spring(response: 0.2, dampingFraction: 0.6), value: pressed)190 .animation(.snappy(duration: 0.2), value: look)191 .frame(width: 84, height: 84)192 .contentShape(Circle())193 .gesture(194 DragGesture(minimumDistance: 0)195 .onChanged { _ in196 guard !pressed else { return }197 pressed = true198 if let onHoldStart {199 Task {200 try? await Task.sleep(for: .milliseconds(450))201 if pressed { holding = true; onHoldStart() }202 }203 }204 }205 .onEnded { _ in206 pressed = false207 if holding { holding = false; onHoldEnd?() } else { action() }208 }209 )210 .accessibilityElement()211 .accessibilityIdentifier("shutter")212 .accessibilityLabel(Text(look == .videoIdle ? "Record" : (look == .videoRecording || look == .stop ? "Stop" : "Shutter")))213 .accessibilityAddTraits(.isButton)214 .accessibilityAction { action() }215 }216}217218struct ModeSelector: View {219 let selected: CameraMode220 let enabled: Bool221 let select: (CameraMode) -> Void222223 var body: some View {224 ScrollViewReader { proxy in225 ScrollView(.horizontal, showsIndicators: false) {226 HStack(spacing: 4) {227 ForEach(CameraMode.allCases) { mode in228 Button { select(mode) } label: {229 Text(mode.shortTitle)230 .font(.system(.caption, design: .rounded, weight: .bold))231 .kerning(0.6)232 .foregroundStyle(mode == selected ? Instrument.manual : Instrument.textDim)233 .padding(.horizontal, 12)234 .frame(minHeight: 44)235 .contentShape(Rectangle())236 }237 .buttonStyle(.plain)238 .id(mode)239 .accessibilityIdentifier("mode.\(mode.rawValue)")240 .accessibilityLabel(Text(mode.title))241 .accessibilityAddTraits(mode == selected ? .isSelected : [])242 }243 }244 .padding(.horizontal, 16)245 }246 .onChange(of: selected) { _, new in withAnimation(.snappy) { proxy.scrollTo(new, anchor: .center) } }247 .onAppear { proxy.scrollTo(selected, anchor: .center) }248 }249 .opacity(enabled ? 1 : 0.4)250 .disabled(!enabled)251 }252}253254struct LensSelector: View {255 let lenses: [LensDescriptor]256 let selectedID: String?257 let select: (LensDescriptor) -> Void258259 var body: some View {260 HStack(spacing: 6) {261 ForEach(lenses) { lens in262 Button { select(lens) } label: {263 Text(lens.label)264 .font(.system(size: lens.id == selectedID ? 13 : 12, weight: .bold, design: .rounded))265 .foregroundStyle(lens.id == selectedID ? Instrument.manual : .white)266 .frame(width: lens.id == selectedID ? 40 : 34, height: lens.id == selectedID ? 40 : 34)267 .background(.black.opacity(0.55), in: Circle())268 .frame(minWidth: 44, minHeight: 44)269 .contentShape(Rectangle())270 }271 .buttonStyle(.plain)272 .accessibilityIdentifier("lens.\(lens.kind)")273 .accessibilityLabel(Text("\(lens.label) lens, \(Int(lens.focalLength35mm.rounded())) millimetre equivalent"))274 .accessibilityAddTraits(lens.id == selectedID ? .isSelected : [])275 }276 }277 .padding(.horizontal, 4)278 .background(.black.opacity(0.25), in: Capsule())279 .animation(.snappy(duration: 0.2), value: selectedID)280 }281}282