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

Is JNWAnimatableWindow interruptible? #10

Open
eonist opened this issue Mar 16, 2017 · 11 comments
Open

Is JNWAnimatableWindow interruptible? #10

eonist opened this issue Mar 16, 2017 · 11 comments

Comments

@eonist
Copy link

eonist commented Mar 16, 2017

I just found NSAnimatablePropertyContainer. Then I found your lib on github.

@jwilling
Copy link
Owner

What do you mean by interruptible? Do you mean where it interpolates between the current animation state and a new state?

@eonist
Copy link
Author

eonist commented Mar 16, 2017

Like how UIPropoertyAnimator is interruptible. Like you can make animation that is interactive. I'm working on this: https://vimeo.com/208548367

@jwilling
Copy link
Owner

Sorry for the delay. The implementation is not very complex, so if you're curious I'd just take a look. The frame resizing animation uses an explicit animation without taking the presentation layer's bounds into account, so it will not interpolate as you're suggesting. That being said, the purpose of this library is to provide access to a layer, which can be animated as you please. It's easily accomplished with the provided by the -layer property.

@eonist
Copy link
Author

eonist commented Mar 21, 2017

Thx for your reply. Your project came up while I researched NSAnimatablePropertyContainer. I guess its not like the new UIViewPropertyAnimator available since iOS 10. Which is all about being interruptible.

@jwilling
Copy link
Owner

jwilling commented Mar 21, 2017 via email

@eonist
Copy link
Author

eonist commented May 7, 2017

Im using Display link. Just found one of your blog posts that helped make it more performant: http://jwilling.com/blog/osx-animations/ Thanks! When are you transitioning to swift? ^^

@eonist
Copy link
Author

eonist commented May 9, 2017

👆 BTW your theory in this blog post is on point. Animating .frame.origin is laggy. Animating with .layer.position is smooth. Very noticeable when the amount of NSViews are numerous.

@eonist
Copy link
Author

eonist commented May 9, 2017

I'm still having huge problems getting hitTest to work with .layer.position animation. I think I will have to write a recursive method that traverse up the hierarchy to find the localGlobal and globalLocal position to hit test with.

@eonist
Copy link
Author

eonist commented May 9, 2017

Worked! Sharing is caring: This code takes care of converting between local and global coordinates when animating with layer instead of frame:

   /**
     * New
     * NOTE: convert(p,nil) usualy converts flipped geometry, but when using layer.position it wont work
     */
    func flipY(_ p:CGPoint)->CGPoint{
        return CGPoint(p.x, WinParser.height(window!) - p.y)/*flips the window y coordinates*/
    }
    /**
     * New
     * Converts global p to local p
     */
    func globToLoc(_ p:CGPoint)->CGPoint{
        let flippedPoint = flipY(p)
        let offset = globalPos()
        let localPoint = flippedPoint - offset
        return localPoint
    }
    /**
     * New
     * Returns the globalPoint of the self.frame.origin (where is this view in the POV of 0,0 of the upper most view)
     */
    func globalPos()->CGPoint{
        var offset:CGPoint = CGPoint()
        var parent:NSView? = self.superview
        while parent?.superview != nil {
            offset += parent!.layer!.position
            parent = parent?.superview
        }
        return offset
    }

@eonist
Copy link
Author

eonist commented May 9, 2017

The WinParser:

/**
     * NOTE: returns the window height (including the titleBar height)
     * NOTE: to return window height not including the titleBar height, the use window!.frame.height
     * NOTE: this method can also be used if you diff this method and the frame.height to get the titlebar height
     * NOTE: to get the width of a window yu can use: window!.frame.width
     */
    static func height(_ window:NSWindow)->CGFloat{
        return NSWindow.contentRect(forFrameRect: window.frame, styleMask: window.styleMask).height
    }

@jwilling
Copy link
Owner

Nice, thanks for sharing that!

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

2 participants