Custom NSWindow drawing - objective-c

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.

Related

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.

Cocoa - NSWindow animation when displayed?

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.

Looking for a vertical NSToolBar lookalike

I'm looking for an NSToolBar type of object to use in my application. I need it to be vertical and to look nice. The buttons on the object do not need to be repositioned or customizable like the NSToolBar it, but I would like the same look and feel the NSToolBar has, just vertical.
I've tried the google route, but I'm not really sure what to search for when it comes to looking for obj-c objects or examples.
I know seeing as what I want is basically a static set of buttons along the side of my window I could just use a bunch of buttons, but it doesn't have the nice seamless look that the NSToolBar does.
Is there something out there similar to what I'm looking for? Is there a repository of obj-c objects or a nice collection of them on a site that I'm just not finding?
It wouldn't have much in the way of functionality, but if you check the 'Textured' box (under 'Appearance') in Interface Builder of an NSWindow, it will make the whole window look like a toolbar. Dropping a well-placed NSBox (set to 'Custom', and with a fill color of the background of a window-or-so) on top of the window leaving only a strip for what would look like a toolbar, you would have a visual approximation, although without any functionality of an NSToolbar whatsoever. Buttons would all have to be done manually, etc, etc.
However, I must caution you that this sounds like a major violation of the HIG. If you are trying to make something twitterish, I won't dissuade you, but it is a sort of crosroads there's no need to cross until Apple decides which path it is going to take.
The toolbar itself wouldn't be too tricky, but if you wanted to allow customization, that would be tricky. Since you didn't mention customization (or showing/hiding) all you really want is a vertical bar of buttons and a background color that matches the window color.
Make your window a textured window, using NSTexturedWindowMask, then create a subclass of NSView with the dimensions you want, drawing its background to match the window background color.
-(void)drawRect:(NSRect)dirtyRect {
[[[self window] backgroundColor] set];
NSRectFill(dirtyRect);
}
The buttons will just be subviews of this view.
Like I say, customization and showing/hiding make this is much harder task to achieve.

Howto draw a rect on screen. NSOpenGLContext vs transparent NSWindow + custom NSView

I'm reading pixels from an area of the main screen via NSOpenGLContext. Now I would like to draw a rect around that area to indicate where it actually is.
How would I do this?
My first thought was the "Cocoa way": create a transparent fullscreen NSWindow and a custom NSView to draw the rectangle path. But that feels a bit too complicated. Isn't it possible to draw directly on the NSOpenGLContext?
If you want to draw over elements not inside your application the floating window is the only correct way. There’s really no complication except mapping positions properly, which is easy to do with the coordinate-space conversions available on NSView and NSWindow.

Dimming NSWindow and layer NSView on top

Is there any way I could dim my NSWindow (basically putting a black transparent layer over top of it that you cannot click through) and then layer a custom NSView on top?
You could create an additional NSView which contains your custom NSView. This new NSView would simply draw the black transparent layer in its drawRect and capture all events to avoid them being passed through to the window.
A more compartmentalized way would be to make a borderless window containing the black view and the custom NSView, and make that a child window of the window you want to “dim”. Then use NSViewAnimation to fade the window in and out.
You will, of course, need to handle keeping their sizes matched if the “dimmed” window is resizable.
You could just set the background color of your NSWindow the black and change the opacity to your liking.