|
| 1 | +// |
| 2 | +// UserPuckStyleKit.swift |
| 3 | +// MapboxNavigation |
| 4 | +// |
| 5 | +// Created on 2017-10-11. |
| 6 | +// Copyright © 2017 Mapbox. All rights reserved. |
| 7 | +// |
| 8 | +// Generated by PaintCode |
| 9 | +// http://www.paintcodeapp.com |
| 10 | +// |
| 11 | + |
| 12 | +import UIKit |
| 13 | + |
| 14 | +class UserPuckStyleKit : NSObject { |
| 15 | + //// Drawing Methods |
| 16 | + |
| 17 | + @objc dynamic class func drawNavigationPuck(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 75, height: 75), resizing: ResizingBehavior = .aspectFit, fillColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000), puckColor: UIColor = UIColor(red: 0.149, green: 0.239, blue: 0.341, alpha: 1.000), shadowColor: UIColor = UIColor(red: 0.149, green: 0.239, blue: 0.341, alpha: 0.160), circleColor: UIColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)) { |
| 18 | + //// General Declarations |
| 19 | + let context = UIGraphicsGetCurrentContext()! |
| 20 | + |
| 21 | + //// Resize to Target Frame |
| 22 | + context.saveGState() |
| 23 | + let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 75, height: 75), target: targetFrame) |
| 24 | + context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY) |
| 25 | + context.scaleBy(x: resizedFrame.width / 75, y: resizedFrame.height / 75) |
| 26 | + |
| 27 | + //// Canvas 2 |
| 28 | + //// navigation_pluck |
| 29 | + //// Oval 7 |
| 30 | + //// path0_fill Drawing |
| 31 | + let path0_fillPath = UIBezierPath(ovalIn: CGRect(x: 9, y: 9, width: 57, height: 57)) |
| 32 | + fillColor.setFill() |
| 33 | + path0_fillPath.fill() |
| 34 | + |
| 35 | + //// Group 4 |
| 36 | + //// path1_stroke_2x Drawing |
| 37 | + let path1_stroke_2xPath = UIBezierPath() |
| 38 | + path1_stroke_2xPath.move(to: CGPoint(x: 37.5, y: 75)) |
| 39 | + path1_stroke_2xPath.addCurve(to: CGPoint(x: 75, y: 37.5), controlPoint1: CGPoint(x: 58.21, y: 75), controlPoint2: CGPoint(x: 75, y: 58.21)) |
| 40 | + path1_stroke_2xPath.addLine(to: CGPoint(x: 57, y: 37.5)) |
| 41 | + path1_stroke_2xPath.addCurve(to: CGPoint(x: 37.5, y: 57), controlPoint1: CGPoint(x: 57, y: 48.27), controlPoint2: CGPoint(x: 48.27, y: 57)) |
| 42 | + path1_stroke_2xPath.addLine(to: CGPoint(x: 37.5, y: 75)) |
| 43 | + path1_stroke_2xPath.close() |
| 44 | + path1_stroke_2xPath.move(to: CGPoint(x: 75, y: 37.5)) |
| 45 | + path1_stroke_2xPath.addCurve(to: CGPoint(x: 37.5, y: 0), controlPoint1: CGPoint(x: 75, y: 16.79), controlPoint2: CGPoint(x: 58.21, y: 0)) |
| 46 | + path1_stroke_2xPath.addLine(to: CGPoint(x: 37.5, y: 18)) |
| 47 | + path1_stroke_2xPath.addCurve(to: CGPoint(x: 57, y: 37.5), controlPoint1: CGPoint(x: 48.27, y: 18), controlPoint2: CGPoint(x: 57, y: 26.73)) |
| 48 | + path1_stroke_2xPath.addLine(to: CGPoint(x: 75, y: 37.5)) |
| 49 | + path1_stroke_2xPath.close() |
| 50 | + path1_stroke_2xPath.move(to: CGPoint(x: 37.5, y: 0)) |
| 51 | + path1_stroke_2xPath.addCurve(to: CGPoint(x: 0, y: 37.5), controlPoint1: CGPoint(x: 16.79, y: 0), controlPoint2: CGPoint(x: 0, y: 16.79)) |
| 52 | + path1_stroke_2xPath.addLine(to: CGPoint(x: 18, y: 37.5)) |
| 53 | + path1_stroke_2xPath.addCurve(to: CGPoint(x: 37.5, y: 18), controlPoint1: CGPoint(x: 18, y: 26.73), controlPoint2: CGPoint(x: 26.73, y: 18)) |
| 54 | + path1_stroke_2xPath.addLine(to: CGPoint(x: 37.5, y: 0)) |
| 55 | + path1_stroke_2xPath.close() |
| 56 | + path1_stroke_2xPath.move(to: CGPoint(x: 0, y: 37.5)) |
| 57 | + path1_stroke_2xPath.addCurve(to: CGPoint(x: 37.5, y: 75), controlPoint1: CGPoint(x: 0, y: 58.21), controlPoint2: CGPoint(x: 16.79, y: 75)) |
| 58 | + path1_stroke_2xPath.addLine(to: CGPoint(x: 37.5, y: 57)) |
| 59 | + path1_stroke_2xPath.addCurve(to: CGPoint(x: 18, y: 37.5), controlPoint1: CGPoint(x: 26.73, y: 57), controlPoint2: CGPoint(x: 18, y: 48.27)) |
| 60 | + path1_stroke_2xPath.addLine(to: CGPoint(x: 0, y: 37.5)) |
| 61 | + path1_stroke_2xPath.close() |
| 62 | + shadowColor.setFill() |
| 63 | + path1_stroke_2xPath.fill() |
| 64 | + |
| 65 | + //// path0_fill 2 Drawing |
| 66 | + let path0_fill2Path = UIBezierPath(ovalIn: CGRect(x: 9, y: 9, width: 57, height: 57)) |
| 67 | + circleColor.setFill() |
| 68 | + path0_fill2Path.fill() |
| 69 | + |
| 70 | + //// Page 1 |
| 71 | + //// Fill 1 |
| 72 | + //// path3_fill Drawing |
| 73 | + let path3_fillPath = UIBezierPath() |
| 74 | + path3_fillPath.move(to: CGPoint(x: 39.2, y: 28.46)) |
| 75 | + path3_fillPath.addCurve(to: CGPoint(x: 38.02, y: 27.69), controlPoint1: CGPoint(x: 39, y: 27.99), controlPoint2: CGPoint(x: 38.54, y: 27.68)) |
| 76 | + path3_fillPath.addCurve(to: CGPoint(x: 36.8, y: 28.49), controlPoint1: CGPoint(x: 37.5, y: 27.7), controlPoint2: CGPoint(x: 37.02, y: 28.01)) |
| 77 | + path3_fillPath.addLine(to: CGPoint(x: 27.05, y: 45.83)) |
| 78 | + path3_fillPath.addCurve(to: CGPoint(x: 27.28, y: 47.26), controlPoint1: CGPoint(x: 26.83, y: 46.32), controlPoint2: CGPoint(x: 26.92, y: 46.89)) |
| 79 | + path3_fillPath.addCurve(to: CGPoint(x: 28.71, y: 47.54), controlPoint1: CGPoint(x: 27.65, y: 47.64), controlPoint2: CGPoint(x: 28.21, y: 47.75)) |
| 80 | + path3_fillPath.addLine(to: CGPoint(x: 37.07, y: 44.03)) |
| 81 | + path3_fillPath.addCurve(to: CGPoint(x: 38.06, y: 44.02), controlPoint1: CGPoint(x: 37.39, y: 43.89), controlPoint2: CGPoint(x: 37.75, y: 43.89)) |
| 82 | + path3_fillPath.addLine(to: CGPoint(x: 46.26, y: 47.34)) |
| 83 | + path3_fillPath.addCurve(to: CGPoint(x: 47.71, y: 47.03), controlPoint1: CGPoint(x: 46.75, y: 47.54), controlPoint2: CGPoint(x: 47.32, y: 47.42)) |
| 84 | + path3_fillPath.addCurve(to: CGPoint(x: 48, y: 45.59), controlPoint1: CGPoint(x: 48.09, y: 46.64), controlPoint2: CGPoint(x: 48.2, y: 46.07)) |
| 85 | + path3_fillPath.addLine(to: CGPoint(x: 39.2, y: 28.46)) |
| 86 | + path3_fillPath.close() |
| 87 | + path3_fillPath.usesEvenOddFillRule = true |
| 88 | + puckColor.setFill() |
| 89 | + path3_fillPath.fill() |
| 90 | + |
| 91 | + context.restoreGState() |
| 92 | + } |
| 93 | + |
| 94 | + @objc(UserPuckStyleKitResizingBehavior) |
| 95 | + enum ResizingBehavior: Int { |
| 96 | + case aspectFit /// The content is proportionally resized to fit into the target rectangle. |
| 97 | + case aspectFill /// The content is proportionally resized to completely fill the target rectangle. |
| 98 | + case stretch /// The content is stretched to match the entire target rectangle. |
| 99 | + case center /// The content is centered in the target rectangle, but it is NOT resized. |
| 100 | + |
| 101 | + public func apply(rect: CGRect, target: CGRect) -> CGRect { |
| 102 | + if rect == target || target == CGRect.zero { |
| 103 | + return rect |
| 104 | + } |
| 105 | + |
| 106 | + var scales = CGSize.zero |
| 107 | + scales.width = abs(target.width / rect.width) |
| 108 | + scales.height = abs(target.height / rect.height) |
| 109 | + |
| 110 | + switch self { |
| 111 | + case .aspectFit: |
| 112 | + scales.width = min(scales.width, scales.height) |
| 113 | + scales.height = scales.width |
| 114 | + case .aspectFill: |
| 115 | + scales.width = max(scales.width, scales.height) |
| 116 | + scales.height = scales.width |
| 117 | + case .stretch: |
| 118 | + break |
| 119 | + case .center: |
| 120 | + scales.width = 1 |
| 121 | + scales.height = 1 |
| 122 | + } |
| 123 | + |
| 124 | + var result = rect.standardized |
| 125 | + result.size.width *= scales.width |
| 126 | + result.size.height *= scales.height |
| 127 | + result.origin.x = target.minX + (target.width - result.width) / 2 |
| 128 | + result.origin.y = target.minY + (target.height - result.height) / 2 |
| 129 | + return result |
| 130 | + } |
| 131 | + } |
| 132 | +} |
0 commit comments