Cocoa - NSWindow animation when displayed? - objective-c

How would I add some sort of CoreAnimation effect when showing a simple nswindow?
Thanks

I've done an animation like you describe before. However, it wasn't an easy task. Since your animation extends outside the bounds of the window itself, you'll need to render the animation in an oversized, transparent window. When the animation completes, you can order in the real window and remove the transparent one.
You'll need an image of the window to use as the content of your animation, so what I would do is order the window in (and probably make it the key window, too, so that it looks focused), but put it well off-screen so the user doesn't see it. Then use CGWindowListCreateImage to grab a screenshot of the window. Now you'll have what you need to create an animation.
After the animation completes, just order the real window over top of the transparent one, then remove the transparent window. Getting the math right so that the image of the window in the animation and the real window is a bit tricky, but it's definitely doable.

Related

Force NSPopover resizing with animation

I have an NSPopover that I want to resize with animation. In my case, setContentSize works, but without animation (apple says that animation is not guaranteed).
I'm investigating the use of NSViewAnimation. With this approach, the popover does resize with animation, but this requires setting the popover (window) frame origin, not just its size.
Here lies the problem, I need to know the edge to which the popover is "attached" to its positionRect because this edge should not move during resizing.
To this end, have set a rather inelegant method that involves comparing the position of the popover to that of the view to which it is attached in screen space, but I'd like to know if there is a more elegant solution to reach my goal (suggestions in obj-c are preferred, I'm already old.)

Make a wxWidgets panel always repaint when it is resized

I have a subclass of wxPanel inside a toplevel window with a couple of levels of wxSplitter above it. When the window is shown the some resizing and layout takes place. When it finishes the background of my panel has random junk (either black or other parts of the window) over some of its background. This seems to be a bug as it's using the bliting that is typically used to speed up scrolling, except that it's bliting from a location that doesn't belong to that panel.
Anyway, I figure I can fix it by making the window always repaint on resize and always draw the full contents of the wxPanel without any blitting. So: Is there any way to make it so the background of the wxPanel is always redrawn in full?
You can try wxFULL_REPAINT_ON_RESIZE style for your panel, see wxWindow docs.
Another way is to catch wxEVT_SIZE and call Refresh() for the relevant panel (and maybe even Update() after it although be careful as this will become a rather expensive op).

Drawing outside of NSWindow

I understand how to draw inside an NSWindow frame. But I don't understand how to achieve something like this for example:
If I knew, how this is called, I could investigate the matter further, but as I didn't know what to look for, this is impossible.
I appreciate any kind of hint.
Thanks a lot.
The app in the screenshot looks like it's using a customized NSDrawer. Drawers slide out from a side of a window and can display any content.
Take a look at the documentation to see if it's what you want:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Drawers/Drawers.html#//apple_ref/doc/uid/10000001-BABFIBIA
Drawers are easy to set up. However, while you have full control over the content inside a drawer, you don't have much control over how the border looks without using private APIs (e.g., the ragged edges in the screenshot). If you want more control, you can use a borderless child window.
Here's a tutorial that makes a borderless, entirely custom window: http://cocoawithlove.com/2008/12/drawing-custom-window-on-mac-os-x.html
Then, you can "attach" your custom window to the parent window with -[NSWindow addChildWindow:ordered:]. That will allow the child window to follow the parent window as it moves. You will still need to respond to changes to the parent window size, and perhaps some other properties, on your own.

IKImageView and scroll bars

I have an NSScrollView with an IKImageView inside to display images. This seems to work.
However, if I make the window smaller than the image, the scrollbars appear as they should, but the BOTTOM of the image is locked to the bottom of the window, instead of the top of the image being locked to the top of the window. In other words, I want the image to not move on the screen when I re-size the window from the bottom right.
I understand why this is, because in All of these classes, the origin is in the lower left, not the upper left. However, It's still behaving wrong. If you look at any other product (including Preview, which I assume is written with some of these libraries) the image/content/whatever, is locked to the top not the bottom.
How do I do this?
I've looked for methods in the NSScrollView and IKImageView. I've considered capturing the scroller events and manually moving the image down or up as appropriate, but I haven't seen a way to do this (Set the selector to a method I write in the controller?) and anyway, that seems very messy...
Is there an easy way to do this?
thanks.
Solution for future reference:
Make a subclass of IKImageView with only one over-ridden method:
-isFlipped()
{
return YES;
}
This subclass will also prove useful if I find that I need to re-implement the rotate:(id) method and the setImage:(NSImage) method which exist in the class (and in the case of rotate are USED IN THE DEMO supplied by Apple) but not documented, and therefore not officially supported...

Custom NSWindow drawing

I want to draw an NSWindow that looks similar to this:
http://vibealicious.com/site/apps/notify/screenshots/mainUIFull.png
In that it has a typical NSWindow appearance with the bottom bar and such, but instead of a title bar at the top, I want to draw a little arrow.
Is there a simple way to do this? Do I have to draw the entire window by hand (bottom bar and all) ? Or can I slightly modify the existing NSWindow layout to just draw that arrow at the top? Thanks
You could possibly fake the title bar by using a second child window that overlays the top section of the window and draws just the arrow. Otherwise, you'd need to draw the whole thing yourself.
Not sure what you mean by a simple way to do it, but it's not very hard to make your own window subclass and draw the window controls yourself. A child window would be a bit of overkill for this situation.
Have a look at the Round Transparent Window sample project.