Skip to content

Commit

Permalink
Fix arrow position when using border
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Vorontsov committed Nov 1, 2017
1 parent d2155f1 commit eb27ed6
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions Source/PopTip+Draw.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,39 @@ public extension PopTip {
case .down:
baloonFrame = CGRect(x: 0, y: arrowSize.height, width: rect.width - borderWidth * 2, height: rect.height - arrowSize.height - borderWidth * 2)

path.move(to: CGPoint(x: arrowPosition.x + borderWidth, y: arrowPosition.y))
path.addLine(to: CGPoint(x: borderWidth + arrowPosition.x + arrowSize.width / 2, y: arrowPosition.y + arrowSize.height))
path.addLine(to: CGPoint(x: baloonFrame.width - radius, y: arrowSize.height))
path.addArc(withCenter: CGPoint(x: baloonFrame.width - radius, y: arrowSize.height + radius) , radius: radius, startAngle: degreesToRadians(degrees: 270), endAngle: degreesToRadians(degrees: 0), clockwise: true)
path.move(to: CGPoint(x: arrowPosition.x, y: arrowPosition.y + borderWidth))
path.addLine(to: CGPoint(x: arrowPosition.x + arrowSize.width / 2, y: arrowPosition.y + arrowSize.height + borderWidth))
path.addLine(to: CGPoint(x: baloonFrame.width - radius, y: arrowSize.height + borderWidth))
path.addArc(withCenter: CGPoint(x: baloonFrame.width - radius, y: arrowSize.height + radius + borderWidth) , radius: radius, startAngle: degreesToRadians(degrees: 270), endAngle: degreesToRadians(degrees: 0), clockwise: true)
path.addLine(to: CGPoint(x: baloonFrame.width, y: arrowSize.height + baloonFrame.height - radius))
path.addArc(withCenter: CGPoint(x: baloonFrame.width - radius, y: arrowSize.height + baloonFrame.height - radius), radius: radius, startAngle: degreesToRadians(degrees: 0), endAngle: degreesToRadians(degrees: 90), clockwise: true)
path.addLine(to: CGPoint(x: borderWidth + radius, y: arrowSize.height + baloonFrame.height))
path.addArc(withCenter: CGPoint(x: borderWidth + radius, y: arrowSize.height + baloonFrame.height - radius), radius: radius, startAngle: degreesToRadians(degrees: 90), endAngle: degreesToRadians(degrees: 180), clockwise: true)
path.addLine(to: CGPoint(x: borderWidth, y: arrowSize.height + radius))
path.addArc(withCenter: CGPoint(x: borderWidth + radius, y: arrowSize.height + radius), radius: radius, startAngle: degreesToRadians(degrees: 180), endAngle: degreesToRadians(degrees: 270), clockwise: true)
path.addLine(to: CGPoint(x: borderWidth + arrowPosition.x - arrowSize.width / 2, y: arrowPosition.y + arrowSize.height))
path.addLine(to: CGPoint(x: borderWidth, y: arrowSize.height + radius + borderWidth))
path.addArc(withCenter: CGPoint(x: borderWidth + radius, y: arrowSize.height + radius + borderWidth), radius: radius, startAngle: degreesToRadians(degrees: 180), endAngle: degreesToRadians(degrees: 270), clockwise: true)
path.addLine(to: CGPoint(x: arrowPosition.x - arrowSize.width / 2, y: arrowPosition.y + arrowSize.height + borderWidth))
path.close()
case .up:
baloonFrame = CGRect(x: 0, y: 0, width: rect.size.width - borderWidth * 2, height: rect.size.height - arrowSize.height - borderWidth * 2)

path.move(to: CGPoint(x: arrowPosition.x + borderWidth, y: arrowPosition.y - borderWidth))
path.addLine(to: CGPoint(x: borderWidth + arrowPosition.x + arrowSize.width / 2, y: arrowPosition.y - arrowSize.height - borderWidth))
path.addLine(to: CGPoint(x: baloonFrame.width - radius, y: baloonFrame.origin.y + baloonFrame.height + borderWidth))
path.addArc(withCenter: CGPoint(x: baloonFrame.width - radius, y: baloonFrame.origin.y + baloonFrame.height - radius + borderWidth), radius:radius, startAngle:degreesToRadians(degrees: 90), endAngle:degreesToRadians(degrees: 0), clockwise:false)
path.move(to: CGPoint(x: arrowPosition.x, y: arrowPosition.y - borderWidth))
path.addLine(to: CGPoint(x: arrowPosition.x + arrowSize.width / 2, y: arrowPosition.y - arrowSize.height - borderWidth))
path.addLine(to: CGPoint(x: baloonFrame.width - radius, y: baloonFrame.origin.y + baloonFrame.height - borderWidth))
path.addArc(withCenter: CGPoint(x: baloonFrame.width - radius, y: baloonFrame.origin.y + baloonFrame.height - radius - borderWidth), radius:radius, startAngle:degreesToRadians(degrees: 90), endAngle:degreesToRadians(degrees: 0), clockwise:false)
path.addLine(to: CGPoint(x: baloonFrame.width, y: baloonFrame.origin.y + radius + borderWidth))
path.addArc(withCenter: CGPoint(x: baloonFrame.width - radius, y: baloonFrame.origin.y + radius + borderWidth), radius:radius, startAngle:degreesToRadians(degrees: 0), endAngle:degreesToRadians(degrees: 270), clockwise: false)
path.addLine(to: CGPoint(x: borderWidth + radius, y: baloonFrame.origin.y + borderWidth))
path.addArc(withCenter: CGPoint(x: borderWidth + radius, y: baloonFrame.origin.y + radius + borderWidth), radius:radius, startAngle:degreesToRadians(degrees: 270), endAngle:degreesToRadians(degrees: 180), clockwise: false)
path.addLine(to: CGPoint(x: borderWidth, y: baloonFrame.origin.y + baloonFrame.height - radius + borderWidth))
path.addArc(withCenter: CGPoint(x: borderWidth + radius, y: baloonFrame.origin.y + baloonFrame.height - radius + borderWidth), radius:radius, startAngle:degreesToRadians(degrees: 180), endAngle:degreesToRadians(degrees: 90), clockwise: false)
path.addLine(to: CGPoint(x: borderWidth + arrowPosition.x - arrowSize.width / 2, y: arrowPosition.y - arrowSize.height - borderWidth))
path.addLine(to: CGPoint(x: borderWidth, y: baloonFrame.origin.y + baloonFrame.height - radius - borderWidth))
path.addArc(withCenter: CGPoint(x: borderWidth + radius, y: baloonFrame.origin.y + baloonFrame.height - radius - borderWidth), radius:radius, startAngle:degreesToRadians(degrees: 180), endAngle:degreesToRadians(degrees: 90), clockwise: false)
path.addLine(to: CGPoint(x: arrowPosition.x - arrowSize.width / 2, y: arrowPosition.y - arrowSize.height - borderWidth))
path.close()
case .left:
baloonFrame = CGRect(x: 0, y: 0, width: rect.size.width - arrowSize.height - borderWidth * 2, height: rect.size.height - borderWidth * 2)

path.move(to: CGPoint(x: arrowPosition.x - borderWidth, y: arrowPosition.y))
path.addLine(to: CGPoint(x: arrowPosition.x - arrowSize.height - borderWidth, y: arrowPosition.y - arrowSize.width / 2))
path.addLine(to: CGPoint(x: baloonFrame.width - borderWidth, y: baloonFrame.origin.y + radius))
path.addLine(to: CGPoint(x: baloonFrame.width - borderWidth, y: baloonFrame.origin.y + radius + borderWidth))
path.addArc(withCenter: CGPoint(x: baloonFrame.width - radius - borderWidth, y: baloonFrame.origin.y + radius + borderWidth), radius:radius, startAngle:degreesToRadians(degrees: 0), endAngle:degreesToRadians(degrees: 270), clockwise: false)
path.addLine(to: CGPoint(x: radius + borderWidth, y: baloonFrame.origin.y + borderWidth))
path.addArc(withCenter: CGPoint(x: radius + borderWidth, y: baloonFrame.origin.y + radius + borderWidth), radius:radius, startAngle:degreesToRadians(degrees: 270), endAngle:degreesToRadians(degrees: 180), clockwise: false)
Expand Down

0 comments on commit eb27ed6

Please sign in to comment.