NSOpenGLView: NSWindow resizeIndicator is missing - cocoa

I am currently creating a simple Cocoa Window programmatically with and NSOpenGLView attached to it. Anyways if I create the windows style mask with with NSResizableWindowMask and [m_window setShowsResizeIndicator: YES ]; I'd expect to see the resize indicator in the bottom right. The resizing works, but the indicator does not show at all. I also checked simple NSOpenGLView examples and they also have the same problem so I am pretty certain that it's not a bug in my code but rather a problem with a view that has 100% width and height. Is there any way to position the indicator ontop of the NSOpenGLView?

Short answer: NSOpenGLView will cover the resize indicator, no matter what you do. You can fake it positioning a custom texture at the bottom right corner of your View.
See this thread for detailed discussion and some example codes:
http://www.idevgames.com/forums/thread-6160.html

Related

How to make CGWindowListCreateImage render correct background color?

Capturing an image of an off-screen window with CGWindowListCreateImage is a common way to create QuickLook style zoom-in animations, but this seems create an image with the wrong background colour, slightly lighter than the real window.
This causes a flash at the end of the animation which kind of ruins the effect.
Does anyone have any idea why this happens and what can be done about it?
EDIT: I created a demonstration app for this problem. It is a bit large and complex for a Stack Overflow question, but the relevant code is probably in the ZoomingWindow.m methods takeSnapshot and makeAndPrepareSnapshotWindow.
Setting the window appearance to textured in Interface Builder fixed this. Of course that also changes the color of the window, but that is acceptable in this particular case.

Blurry NSImageView

I have an NSImageView in a view that utilizes Core Animation. Prior to using Core Animation the image looks fine but now its blurry and low quality. If I let NSImageView have a bezel border the issue goes away but I need it to have no border. Had this happened to anyone else?
Imgae in the background with no border, same image in the front with a border.
Thanks
EDIT: I forgot to mention that the image is an icon file (ICNS) so it has various sizes. The bordered view loads the correct size and the transparent one loads the smallest and stretches it.
Although not the way I wanted to, I managed to create a fix for the issue. The issue seemed to be the way that NSImageView was drawing the image so I created a custom NSView subclass with support for the same bindings I used in my original image view. Im not sure why the blurry-ness happend in the beginning, but drawing the image by hand in an NSView seems to do the trick.
Your image may be drawing in a non-pixel-aligned way. Have you tried shifting it by a half pixel?
Apple has a good demonstration of this in the BlurryView app in their "Cocoa Tips and Tricks" sample code.
Cocoa Tips and Tricks

Transparent rounded window but with opaque controls

I am trying to make a HUD with a transparent rounded window with opaque controls as is commonly seen in apps such as Xcode popups, the native volume control, etc.
I'm using the technique detailed here: How to implement HUD-style window like Address Book's "Show in Large Type"
but this renders controls in the view transparent. I've tried setAlphaValue:1.0 on the controls but that has no effect. Searches for other solutions point to Matt Gemmell's RoundedFloatingPanel component. I can't open the project in Xcode 4, but looking at the code as far as I can tell the only difference seems to be in Matt's code he sets the alpha of the window to 1.0 and uses a transparent fill for the NSRect in the view. I tried this but still end up with transparent controls.
So unsurprisingly, Matt Gemmell's code works just fine and I had made a mistake. I forgot that I was also messing with the alpha of the window elsewhere in my code in order to make it fade out on close.
To to sum it up for others running into this issue, if you set the alpha on the NSWindow the controls in that window will also be transparent. Instead set the alpha on the NSBezierPath fill color in the NSView. Just like Matt Gemmell's code does. :)

Padding at top of NSView in an NSScrollView

I have an NSView as the document of an NSScrollView. I would like to have a few pixels of padding at the top and bottom of the visible part of the view, regardless of where the scroller is positioned (not just at the top and bottom of the document as described here). For an example of an app that does this, look at Terminal.app. Regardless of the background color of the text, the top two visible rows of pixels are always the default background color.
I know I could simply draw everything two pixels lower and draw a rectangle at the top and bottom of the document-visible rect, but that will require changing a lot of complex code that I didn't write. Simpler ideas are welcomed!
The answer to the question you linked is actually a good solution for this problem too. In fact if your view is anything but an NSTextView, I'd say it's easier to implement.
Specifically: make your actual document view a subview of some other view, leaving room around the edges and make that view the scroll view's document view. If your content view (the one you wish to pad) changes sizes, have your "padding view" observe it for frame changes and resize to maintain the padding.
2015 Update
Content inset has been added to NSScrollView as of 10.10, making my older answer obsolete.

Cocoa: Custom control not limited to window frame - how to start?

I want to build a custom control that would work like this:
You have a kind of NSButton with an image.
You click the button and than appears a big square with a grid of photos.
You click one of the photos and it is set up as new image for the button. (square dissapears)
Now, how to draw this big square with photos if I want it not to be limited to window frame?
I mean, if the button was close to window border the square is going to be partially outside window. I would also like to add some shadow to the square and an animation for opening/closing.
One important thing: I want to be able to draw not only a square but any other simple shape (circle)!
This isn't really a drawing question so much as a general custom views question. It's important to make that distinction.
I'll describe this in terms of rectangles to give you the general idea*. You should make sure you understand the view hierarchy and view geometry in Cocoa. Without this important requisite knowledge, you'll remain dead in the water.
It's easy to set an NSButton's image, so I'll leave that to you. Your button's action, however, would tell some controller to show the "image picker" for the given button. Your image picker would be some type of borderless window with an image list inside. The image picker could be an IKImageBrowserView (you'll have to enable Image Kit in Interface Builder for this control to appear), which gives you an iPhoto-like grid of images (with/without titles, different border types, etc.).
An explanation of the operation of this controller and how it creates the window, manages the selection, and sets the button's image is very broad so if you get hung up on any of those steps, you'll need to create a separate question for each problem, otherwise this answer would have to be an instruction manual for writing your app for you.
* Your problem is a little more difficult because of your desire to have differently-shaped "popup windows" ... you'd have to make sure your available photos fit neatly within the shape so none of them are cut off. Armed with the basic knowledge of view geometry, I'll leave this to you as an exercise. A hint: you can use a borderless, transparent window to host a view that draws itself in any shape you please.

Resources