import SwiftUI let amber = Color(red: 0xE0 / 255, green: 0xA3 / 255, blue: 0x40 / 255) /// Tutte le misure sono in pixel del reel (1080×1920), moltiplicate per `s` (punti per pixel del reel). /// Vengono da `_instagram/video/classifica_giochi_da_2/` (LEGGIMI, sovrimpressioni.py, grafica.py). private struct Box: ViewModifier { let x, y, w, h, s: CGFloat func body(content: Content) -> some View { content.frame(width: w * s, height: h * s).offset(x: x * s, y: y * s) } } private extension View { func box(_ x: CGFloat, _ y: CGFloat, _ w: CGFloat, _ h: CGFloat, _ s: CGFloat) -> some View { modifier(Box(x: x, y: y, w: w, h: h, s: s)) } } /// Le zone che Instagram copre o taglia (misurate il 28/10 sugli screenshot dell'iPhone di Paolo). struct SafeZones: View { let s: CGFloat var body: some View { ZStack(alignment: .topLeading) { // a tutto schermo il video perde 56 px per lato Hatch().box(0, 0, 56, 1920, s) Hatch().box(1024, 0, 56, 1920, s) // in alto: avatar e nome nel feed, "Reels / Amici" a tutto schermo zone("INTESTAZIONE DI INSTAGRAM", 56, 0, 968, 230) // a destra i tasti (cuore, commenti, condividi, salva) zone("TASTI", 900, 1390, 124, 310, vertical: true) // in basso avatar, nome e didascalia zone("NOME E DIDASCALIA", 56, 1700, 968, 220, top: true) // dove vanno i sottotitoli (fondo del blocco a y 1680, centro a x 500) RoundedRectangle(cornerRadius: 10 * s) .strokeBorder(Color.white.opacity(0.55), style: StrokeStyle(lineWidth: 1, dash: [5, 4])) .overlay(Text("SOTTOTITOLI").font(.system(size: 26 * s, weight: .semibold)).foregroundStyle(.white.opacity(0.6))) .box(80, 1540, 840, 140, s) } .allowsHitTesting(false) } private func zone(_ t: String, _ x: CGFloat, _ y: CGFloat, _ w: CGFloat, _ h: CGFloat, vertical: Bool = false, top: Bool = false) -> some View { Rectangle() .fill(Color.red.opacity(0.16)) .overlay(Rectangle().strokeBorder(Color.red.opacity(0.45), lineWidth: 1)) .overlay(alignment: top ? .top : .center) { Text(t) .font(.system(size: 24 * s, weight: .bold)) .kerning(1) .foregroundStyle(.white.opacity(0.55)) .fixedSize() .rotationEffect(.degrees(vertical ? -90 : 0)) .padding(.top, top ? 14 * s : 0) } .box(x, y, w, h, s) } } /// Righe diagonali: la parte che a tutto schermo non si vede. struct Hatch: View { var body: some View { Canvas { ctx, size in ctx.fill(Path(CGRect(origin: .zero, size: size)), with: .color(.black.opacity(0.45))) var p = Path() var x: CGFloat = -size.height while x < size.width { p.move(to: CGPoint(x: x, y: size.height)) p.addLine(to: CGPoint(x: x + size.height, y: 0)) x += 9 } ctx.stroke(p, with: .color(.red.opacity(0.35)), lineWidth: 1) } } } /// Le due top 5 come nel reel: Vale a sinistra (x 80–410), Paolo a destra (x 670–1000), /// testate a y 236, righe da 330×58 a passo 64 da y 304 (l'ultima finisce a 618). struct Classifiche: View { let s: CGFloat var nomiVale: [String] var nomiPaolo: [String] var body: some View { ZStack(alignment: .topLeading) { colonna(x: 80, testa: "TOP 5 DI VALE", iniziale: "V", nomi: nomiVale) colonna(x: 670, testa: "TOP 5 DI PAOLO", iniziale: "P", nomi: nomiPaolo) } .allowsHitTesting(false) } @ViewBuilder private func colonna(x: CGFloat, testa: String, iniziale: String, nomi: [String]) -> some View { testata(testa, iniziale).box(x, 236, 330, 60, s) ForEach(0..<5, id: \.self) { i in riga(i + 1, i < nomi.count && !nomi[i].isEmpty ? nomi[i] : "Gioco \(i + 1)") .box(x, 304 + CGFloat(i) * 64, 330, 58, s) } } private func testata(_ t: String, _ iniziale: String) -> some View { ZStack(alignment: .leading) { RoundedRectangle(cornerRadius: 14 * s) .fill(Color(white: 0.05).opacity(0.82)) .padding(.leading, 30 * s) .padding(.vertical, 2 * s) Circle().fill(Color(white: 0.3)) .overlay(Text(iniziale).font(.custom("BebasNeue-Regular", size: 40 * s)).foregroundStyle(.white)) .frame(width: 60 * s, height: 60 * s) Text(t) .font(.custom("BebasNeue-Regular", size: 40 * s)) .foregroundStyle(amber) .frame(maxWidth: .infinity) .padding(.leading, 60 * s) } } private func riga(_ n: Int, _ nome: String) -> some View { HStack(spacing: 0) { Text("\(n)") .font(.custom("BebasNeue-Regular", size: 50 * s)) .foregroundStyle(Color(white: 0.06)) .frame(width: 58 * s, height: 58 * s) .background(amber) Text(nome) .font(.system(size: 30 * s, weight: .bold)) .foregroundStyle(.white) .lineLimit(1) .minimumScaleFactor(0.7) .padding(.leading, 14 * s) .padding(.trailing, 12 * s) Spacer(minLength: 0) } .background(Color(white: 0.05).opacity(0.75)) .clipShape(RoundedRectangle(cornerRadius: 14 * s)) } } struct GridLines: View { var body: some View { GeometryReader { g in Path { p in for i in 1...2 { let x = g.size.width * CGFloat(i) / 3, y = g.size.height * CGFloat(i) / 3 p.move(to: CGPoint(x: x, y: 0)); p.addLine(to: CGPoint(x: x, y: g.size.height)) p.move(to: CGPoint(x: 0, y: y)); p.addLine(to: CGPoint(x: g.size.width, y: y)) } } .stroke(Color.white.opacity(0.28), lineWidth: 0.6) } .allowsHitTesting(false) } } struct FocusSquare: View { var locked: Bool @State private var scale: CGFloat = 1.4 var body: some View { Rectangle() .stroke(amber, lineWidth: 1.2) .frame(width: 70, height: 70) .scaleEffect(scale) .onAppear { withAnimation(.easeOut(duration: 0.25)) { scale = 1 } } .id(locked) } } struct ExposureSlider: View { var value: Float // -2 … +2 var onChange: (Float) -> Void @State private var start: Float = 0 @State private var dragging = false var body: some View { GeometryReader { g in let h = g.size.height let y = h / 2 - CGFloat(value) / 2 * (h / 2) ZStack { Rectangle().fill(amber.opacity(0.7)).frame(width: 1.2) Image(systemName: "sun.max.fill") .font(.system(size: 22)) .foregroundStyle(amber) .position(x: g.size.width / 2, y: y) } .frame(width: g.size.width, height: h) .contentShape(Rectangle()) .gesture(DragGesture(minimumDistance: 0) .onChanged { d in if !dragging { start = value; dragging = true } let delta = Float(-d.translation.height / (h / 2)) * 2 onChange(max(-2, min(2, start + delta))) } .onEnded { _ in dragging = false }) } } } /// Livello del microfono, verticale: verde fino a −12 dB, giallo fino a −3, rosso sopra. struct MicMeter: View { var level: Float // -60 … 0 var peak: Float var body: some View { GeometryReader { g in let h = g.size.height let f = CGFloat((level + 60) / 60) let pk = CGFloat((peak + 60) / 60) ZStack(alignment: .bottom) { Capsule().fill(Color.black.opacity(0.45)) Capsule() .fill(LinearGradient(stops: [ .init(color: .green, location: 0), .init(color: .green, location: 0.78), .init(color: .yellow, location: 0.86), .init(color: .red, location: 0.97), ], startPoint: .bottom, endPoint: .top)) .frame(height: h) .mask(alignment: .bottom) { Rectangle().frame(height: max(0, f) * h) } Rectangle().fill(.white).frame(height: 2) .offset(y: -max(0, pk) * h + 1) } .animation(.linear(duration: 0.1), value: level) } .allowsHitTesting(false) } } /// Formato "Paolo vs Vale" (Paolo, 24/11). Scelta di Paolo e Vale fra le quattro prove: la C, "striscia col nome". /// Due metà da 905 (Vale in alto, Paolo in basso) e in mezzo una striscia nera da 110 col nome del gioco; la scatola /// (360) sta a sinistra a cavallo della striscia, sopra tutti e due; le palette col voto a destra per Vale e a sinistra /// per Paolo (a destra in basso ci sono i tasti di Instagram). Facce fuori dalle zone: Vale sotto y 230, Paolo sopra y 1700. enum Fasce { static let h: CGFloat = 905 static let vale = CGRect(x: 0, y: 0, width: 1080, height: 905) static let striscia = CGRect(x: 0, y: 905, width: 1080, height: 110) static let paolo = CGRect(x: 0, y: 1015, width: 1080, height: 905) /// la scatola: lato 360, a 84 dal bordo sinistro, centrata sul taglio (y 960) static let scatola = CGRect(x: 84, y: 960 - 180, width: 360, height: 360) static func fascia(_ chi: String) -> CGRect { chi == "vale" ? vale : paolo } } /// Sotto l'inquadratura: la fascia dell'altro (segnaposto) e la striscia col nome. struct VsSfondo: View { let s: CGFloat let chi: String var body: some View { let altro = chi == "vale" ? Fasce.paolo : Fasce.vale ZStack(alignment: .topLeading) { Color.black ZStack { Color(white: 0.1) VStack(spacing: 10 * s) { Image(systemName: "person.fill") .font(.system(size: 190 * s)) Text(chi == "vale" ? "QUI PAOLO" : "QUI VALE") .font(.custom("BebasNeue-Regular", size: 64 * s)) } .foregroundStyle(Color(white: 0.28)) } .frame(width: altro.width * s, height: altro.height * s) .offset(y: altro.minY * s) } .allowsHitTesting(false) } } /// Sopra l'inquadratura: la striscia col nome, la scatola a cavallo e dove vanno le palette. struct VsSopra: View { let s: CGFloat var body: some View { ZStack(alignment: .topLeading) { // striscia nera col nome del gioco, filo ambra sopra e sotto ZStack(alignment: .leading) { Color(red: 0.05, green: 0.047, blue: 0.043) Text("NOME DEL GIOCO") .font(.custom("BebasNeue-Regular", size: 78 * s)) .foregroundStyle(amber) .padding(.leading, (Fasce.scatola.maxX + 40) * s) } .frame(width: 1080 * s, height: Fasce.striscia.height * s) .offset(y: Fasce.striscia.minY * s) Rectangle().fill(amber).frame(width: 1080 * s, height: 4 * s).offset(y: Fasce.striscia.minY * s) Rectangle().fill(amber).frame(width: 1080 * s, height: 4 * s).offset(y: (Fasce.striscia.maxY - 4) * s) // la scatola RoundedRectangle(cornerRadius: 4 * s) .fill(Color(white: 0.22)) .overlay(RoundedRectangle(cornerRadius: 4 * s).stroke(Color(white: 0.95), lineWidth: 3 * s)) .overlay(Text("SCATOLA").font(.custom("BebasNeue-Regular", size: 60 * s)).foregroundStyle(amber)) .shadow(color: .black.opacity(0.6), radius: 20 * s, y: 8 * s) .frame(width: Fasce.scatola.width * s, height: Fasce.scatola.height * s) .offset(x: Fasce.scatola.minX * s, y: Fasce.scatola.minY * s) // dove alzare le palette: Vale a destra, Paolo a sinistra paletta.offset(x: (812 - 100) * s, y: (452 - 100) * s) paletta.offset(x: (232 - 100) * s, y: (1400 - 100) * s) } .allowsHitTesting(false) } private var paletta: some View { Circle() .strokeBorder(amber.opacity(0.8), style: StrokeStyle(lineWidth: 2, dash: [6, 5])) .overlay(Text("VOTO").font(.custom("BebasNeue-Regular", size: 50 * s)).foregroundStyle(amber.opacity(0.8))) .frame(width: 200 * s, height: 200 * s) } }