Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

continue line #42

Open
dcooley opened this issue Aug 29, 2020 · 0 comments
Open

continue line #42

dcooley opened this issue Aug 29, 2020 · 0 comments

Comments

@dcooley
Copy link
Contributor

dcooley commented Aug 29, 2020

I've updated the touchesBegan function in my forked repo to experiment adding a 'continue path' functionality, where the line you draw will automatically continue from the last one you did (if it exists)

continuousLine

Is something like this worth adding into the library?


The updated touchesBegan() looks like

    /// Determines whether the path should continue from the last touch point.
    public var shouldContinuePath = false


    override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard isEnabled, let touch = touches.first else { return }
        if #available(iOS 9.1, *) {
            guard allowedTouchTypes.flatMap({ $0.uiTouchTypes }).contains(touch.type) else { return }
        }
        guard delegate?.swiftyDraw(shouldBeginDrawingIn: self, using: touch) ?? true else { return }
        delegate?.swiftyDraw(didBeginDrawingIn: self, using: touch)
        
        firstPoint = shouldContinuePath && previousPoint != .zero ? previousPoint : touch.location(in: self)
        setTouchPoints(touch, view: self)
          
        let newLine = DrawItem(path: CGMutablePath(),
                           brush: Brush(color: brush.color.uiColor, width: brush.width, opacity: brush.opacity, blendMode: brush.blendMode), isFillPath: false)
        if shouldContinuePath && currentPoint != .zero {
            // draw a straight line between the end of the last touch point
            // and this new touch point
            newLine.path.addPath(createNewStraightPath())
        }
        addLine(newLine)
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant