From 23d30da4949d7c757a9b00bd40bb530ae8be337f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Zie=CC=A8tek?= Date: Thu, 10 Jan 2019 12:33:55 +0100 Subject: [PATCH 1/3] Add more customization options - Attitude reference index: customizable line thickness - Horizon: customizable zero pitch line thickness - Horizon: fix display artifacts - Pitch ladder: customizable line thickness - Tape indicators: ability to hide each indicator --- Sources/AttitudeReferenceIndex.swift | 22 +++++++++++++--------- Sources/Horizon.swift | 3 ++- Sources/PitchLadder.swift | 12 ++++++------ Sources/Settings.swift | 10 ++++++++++ Sources/TapeIndicator.swift | 1 + 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Sources/AttitudeReferenceIndex.swift b/Sources/AttitudeReferenceIndex.swift index d4e4c1e..83b887d 100644 --- a/Sources/AttitudeReferenceIndex.swift +++ b/Sources/AttitudeReferenceIndex.swift @@ -30,12 +30,12 @@ class AttitudeReferenceIndex: SKNode { let height = CGFloat(style.sideBarHeight) let path = CGMutablePath() - path.move(to: CGPoint(x: -width, y: 2)) - path.addLine(to: CGPoint(x: 0, y: 2)) + path.move(to: CGPoint(x: -width, y: halfLineThickness)) + path.addLine(to: CGPoint(x: 0, y: halfLineThickness)) path.addLine(to: CGPoint(x: 0, y: -height)) - path.addLine(to: CGPoint(x: -4, y: -height)) - path.addLine(to: CGPoint(x: -4, y: -2)) - path.addLine(to: CGPoint(x: -width, y: -2)) + path.addLine(to: CGPoint(x: -style.lineThickness, y: -height)) + path.addLine(to: CGPoint(x: -style.lineThickness, y: -halfLineThickness)) + path.addLine(to: CGPoint(x: -width, y: -halfLineThickness)) path.closeSubpath() var trans = transform @@ -52,10 +52,10 @@ class AttitudeReferenceIndex: SKNode { private func buildCenterBar() -> SKShapeNode { let halfWidth = CGFloat(style.centerBarWidth) / 2 let path = CGMutablePath() - path.move(to: CGPoint(x: -halfWidth, y: 2)) - path.addLine(to: CGPoint(x: halfWidth, y: 2)) - path.addLine(to: CGPoint(x: halfWidth, y: -2)) - path.addLine(to: CGPoint(x: -halfWidth, y: -2)) + path.move(to: CGPoint(x: -halfWidth, y: halfLineThickness)) + path.addLine(to: CGPoint(x: halfWidth, y: halfLineThickness)) + path.addLine(to: CGPoint(x: halfWidth, y: -halfLineThickness)) + path.addLine(to: CGPoint(x: -halfWidth, y: -halfLineThickness)) path.closeSubpath() let shape = SKShapeNode(path: path) @@ -63,4 +63,8 @@ class AttitudeReferenceIndex: SKNode { shape.strokeColor = style.strokeColor return shape } + + private var halfLineThickness: CGFloat { + return style.lineThickness * 0.5 + } } diff --git a/Sources/Horizon.swift b/Sources/Horizon.swift index 9337bcf..3eb72de 100644 --- a/Sources/Horizon.swift +++ b/Sources/Horizon.swift @@ -21,7 +21,7 @@ class Horizon: SKNode { self.sceneSize = sceneSize skyNode = SKSpriteNode(color: style.skyColor, size: CGSize(width: 100, height: 100)) groundNode = SKSpriteNode(color: style.groundColor, size: CGSize(width: 100, height: 100)) - zeroPitchLine = SKShapeNode(rectOf: CGSize(width: 2 * sceneSize.width, height: 1)) + zeroPitchLine = SKShapeNode(rectOf: CGSize(width: 2 * sceneSize.width, height: style.zeroPitchLineThickness)) super.init() skyNode.size = CGSize(width: sceneSize.width * 2, height: sceneSize.height * 2) @@ -29,6 +29,7 @@ class Horizon: SKNode { skyNode.position = CGPoint(x: 0, y: sceneSize.height) groundNode.position = CGPoint(x: 0, y: -sceneSize.height) zeroPitchLine.strokeColor = style.zeroPitchLineColor + zeroPitchLine.fillColor = style.zeroPitchLineColor zeroPitchLine.position = CGPoint.zero gimbalNode.addChild(skyNode) diff --git a/Sources/PitchLadder.swift b/Sources/PitchLadder.swift index c886ea0..e691419 100644 --- a/Sources/PitchLadder.swift +++ b/Sources/PitchLadder.swift @@ -30,7 +30,7 @@ class PitchLadder: SKNode { } let pitchLines = skyPitchLines + skyPitchLines.map { ($0.0 * -1, $0.1) } for (degree, type) in pitchLines { - cropNode.addChild(builder.pitchLine(sceneSize: sceneSize, degree: degree, type: type)) + cropNode.addChild(builder.pitchLine(sceneSize: sceneSize, degree: degree, type: type, lineThickness: style.lineThickness)) } for (degree, type) in pitchLines.filter({ $1 == .major }) { cropNode.addChild(builder.leftPitchLineLabel(sceneSize: sceneSize, degree: degree, type: type)) @@ -64,14 +64,14 @@ private struct PitchLineBuilder { let style: PitchLadderStyleType - func pitchLine(sceneSize: CGSize, degree: Int, type: PitchLineType) -> SKShapeNode { + func pitchLine(sceneSize: CGSize, degree: Int, type: PitchLineType, lineThickness: CGFloat) -> SKShapeNode { let halfWidth = halfWidthForPitchLineType(type: type) let path = CGMutablePath() - path.move(to: CGPoint(x: -halfWidth, y: 2)) - path.addLine(to: CGPoint(x: halfWidth, y: 2)) - path.addLine(to: CGPoint(x: halfWidth, y: -2)) - path.addLine(to: CGPoint(x: -halfWidth, y: -2)) + path.move(to: CGPoint(x: -halfWidth, y: lineThickness * 0.5)) + path.addLine(to: CGPoint(x: halfWidth, y: lineThickness * 0.5)) + path.addLine(to: CGPoint(x: halfWidth, y: -lineThickness * 0.5)) + path.addLine(to: CGPoint(x: -halfWidth, y: -lineThickness * 0.5)) path.closeSubpath() var transform = CGAffineTransform(translationX: 0, y: CGFloat(degree) * sceneSize.pointsPerDegree) diff --git a/Sources/Settings.swift b/Sources/Settings.swift index 519cb60..6a5d7c6 100644 --- a/Sources/Settings.swift +++ b/Sources/Settings.swift @@ -63,12 +63,14 @@ public protocol HorizonStyleType { var skyColor: SKColor { get set } var groundColor: SKColor { get set } var zeroPitchLineColor: SKColor { get set } + var zeroPitchLineThickness: CGFloat { get set } } public struct DefaultHorizonStyle: HorizonStyleType { public var skyColor = SKColor(red: 0.078, green: 0.490, blue: 0.816, alpha: 1.00) public var groundColor = SKColor(red: 0.667, green: 0.855, blue: 0.196, alpha: 1.00) public var zeroPitchLineColor = SKColor(red: 0.8, green: 0.8, blue: 0.8, alpha: 1) + public var zeroPitchLineThickness = CGFloat(1) public init() {} } @@ -82,6 +84,7 @@ public protocol AttitudeReferenceIndexStyleType { var sideBarHeight: Int { get set } var sideBarWidth: Int { get set } var sideBarOffset: Int { get set } + var lineThickness: CGFloat { get set } } public struct DefaultAttitudeReferenceIndexStyle: AttitudeReferenceIndexStyleType { @@ -91,6 +94,7 @@ public struct DefaultAttitudeReferenceIndexStyle: AttitudeReferenceIndexStyleTyp public var sideBarWidth = 120 public var sideBarHeight = 20 public var sideBarOffset = 70 + public var lineThickness = CGFloat(4) public init() {} } @@ -106,6 +110,7 @@ public protocol PitchLadderStyleType { var majorLineWidth: Int { get set } var markerTextOffset: Int { get set } var magnitudeDisplayDegree: Int { get set } // Keep between 0 and 180 + var lineThickness: CGFloat { get set } } public struct DefaultPitchLadderStyle: PitchLadderStyleType { @@ -117,6 +122,7 @@ public struct DefaultPitchLadderStyle: PitchLadderStyleType { public var majorLineWidth = 50 public var markerTextOffset = 10 public var magnitudeDisplayDegree = 40 + public var lineThickness = CGFloat(4) public init() {} } @@ -174,6 +180,7 @@ public enum TapeMarkerJustification { public typealias Legend = (key: String, value: String) public protocol TapeIndicatorStyleType { + var visible: Bool { get set } var size: CGSize { get set } var type: TapeType { get set } var backgroundColor: SKColor { get set } @@ -193,6 +200,7 @@ public protocol TapeIndicatorStyleType { } public struct DefaultAltimeterStyle: TapeIndicatorStyleType { + public var visible = true public var size = CGSize(width: 60, height: 300) public var type = TapeType.continuous public var backgroundColor = SKColor(red: 0, green: 0, blue: 0, alpha: 0.5) @@ -214,6 +222,7 @@ public struct DefaultAltimeterStyle: TapeIndicatorStyleType { } public struct DefaultAirspeedIndicatorStyle: TapeIndicatorStyleType { + public var visible = true public var size = CGSize(width: 60, height: 300) public var type = TapeType.continuous public var backgroundColor = SKColor(red: 0, green: 0, blue: 0, alpha: 0.5) @@ -235,6 +244,7 @@ public struct DefaultAirspeedIndicatorStyle: TapeIndicatorStyleType { } public struct DefaultHeadingIndicatorStyle: TapeIndicatorStyleType { + public var visible = true public var size = CGSize(width: 400, height: 60) public var type = TapeType.compass public var backgroundColor = SKColor(red: 0, green: 0, blue: 0, alpha: 0.5) diff --git a/Sources/TapeIndicator.swift b/Sources/TapeIndicator.swift index 3159518..35c434d 100644 --- a/Sources/TapeIndicator.swift +++ b/Sources/TapeIndicator.swift @@ -45,6 +45,7 @@ class TapeIndicator: SKNode { pointer = TapePointer(initialValue: style.seedModel.lowerValue, style: style) super.init() + isHidden = !style.visible let backgroundShape = SKShapeNode(rectOf: style.size, cornerRadius: 2) backgroundShape.fillColor = style.backgroundColor backgroundShape.strokeColor = SKColor.clear From fa0f413d435a6e5e4dcfc1ec76f257f27560ce43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Zie=CC=A8tek?= Date: Thu, 10 Jan 2019 12:35:04 +0100 Subject: [PATCH 2/3] Swift 4.2 upgrade --- PrimaryFlightDisplay.podspec | 2 +- PrimaryFlightDisplay.xcodeproj/project.pbxproj | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/PrimaryFlightDisplay.podspec b/PrimaryFlightDisplay.podspec index a6508be..46c22af 100644 --- a/PrimaryFlightDisplay.podspec +++ b/PrimaryFlightDisplay.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |spec| spec.ios.deployment_target = '9.0' spec.osx.deployment_target = '10.10' spec.requires_arc = true - spec.swift_version = '4.1' + spec.swift_version = '4.2' spec.source = { git: "https://github.com/kouky/PrimaryFlightDisplay.git", tag: "#{spec.version}" } spec.source_files = "Sources/**/*.{h,swift}" diff --git a/PrimaryFlightDisplay.xcodeproj/project.pbxproj b/PrimaryFlightDisplay.xcodeproj/project.pbxproj index 35187ba..a61af54 100644 --- a/PrimaryFlightDisplay.xcodeproj/project.pbxproj +++ b/PrimaryFlightDisplay.xcodeproj/project.pbxproj @@ -226,6 +226,7 @@ TargetAttributes = { 27B17FC31C84309F006EEC9D = { CreatedOnToolsVersion = 7.2.1; + LastSwiftMigration = 1010; }; 27B17FD81C843D73006EEC9D = { CreatedOnToolsVersion = 7.2.1; @@ -434,6 +435,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -454,6 +456,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.kouky.PrimaryFlightDisplay-iOS"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 4.2; }; name = Release; }; From 30df2f8ae917ed0a11b96f7e9c917d80b4b8a746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Zie=CC=A8tek?= Date: Tue, 8 Dec 2020 16:33:22 +0100 Subject: [PATCH 3/3] Swirft 5 support --- PrimaryFlightDisplay.podspec | 2 +- PrimaryFlightDisplay.xcodeproj/project.pbxproj | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/PrimaryFlightDisplay.podspec b/PrimaryFlightDisplay.podspec index 46c22af..2145859 100644 --- a/PrimaryFlightDisplay.podspec +++ b/PrimaryFlightDisplay.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |spec| spec.ios.deployment_target = '9.0' spec.osx.deployment_target = '10.10' spec.requires_arc = true - spec.swift_version = '4.2' + spec.swift_version = '5.0' spec.source = { git: "https://github.com/kouky/PrimaryFlightDisplay.git", tag: "#{spec.version}" } spec.source_files = "Sources/**/*.{h,swift}" diff --git a/PrimaryFlightDisplay.xcodeproj/project.pbxproj b/PrimaryFlightDisplay.xcodeproj/project.pbxproj index a61af54..135dc90 100644 --- a/PrimaryFlightDisplay.xcodeproj/project.pbxproj +++ b/PrimaryFlightDisplay.xcodeproj/project.pbxproj @@ -238,6 +238,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 27B17FBA1C84309F006EEC9D; @@ -366,7 +367,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -409,7 +410,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -435,7 +436,6 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -456,7 +456,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.kouky.PrimaryFlightDisplay-iOS"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; }; name = Release; };