Transparent NSWindow but with standard border and shadow [duplicate] - objective-c

This question already has an answer here:
Holes in NSView or NSWindow
(1 answer)
Closed 6 years ago.
I want to have a more or less standard NSWindow with a toolbar and all that, but I want the content view to be transparent so that I can see through it. At the same time I want to keep the light gray outline of the window and also it's shadow. BUT I want to avoid the "inner" shadow I get from the toolbar inside the content view area.
What I have tried so far is just to set the window background color to a semi transparent color and also set opaque to NO. The problem is that the window border fades away with the alpha of the background itself, and the more transparency I have on the background, the more the shadow of the toolbar shows up within the content view.
Generally, the window shadow and border changes depending on the transparency of the content view, which I totally understand. But I want a behavior where it keeps the border and shadow just as if it was a completely opaque window, and then I want the content view area to be transparent.
I am not sure what I need to do conceptually to make it work. Maybe I have to draw the window border myself, maybe not. Maybe I need to draw the shadow myself, or maybe not.
Is there anyone that know how to build this? I don't need exact code details, but rather what parts I need to do custom..
I appreciate any input!

I dont't know if this is of any value for you after all this time but try:
[aWindow setOpaque:NO];
[aWindow setBackgroundColor:[NSColor clearColor]];

Subclass the NSView class, override the drawRect:(NSRect)dirtyRect method and set the color of the view as clearcolor, now set the class of your content view as the Subclass of NSView.

Related

NSTextField outer cell background inside custom draw view

I'm struggling with an NSTextField background issue. The textfield is within a custom view that has a semi-transparent black background. I've tried subclassing the field, the field's cell and a few other things to no avail. I'm getting this clearColor background outside of the text field cell. I'm looking for basically just a black NSSearchFeld, not having much luck though.
here is what i'm getting
I basically just want a textfield with a rounded stroke which blends into the black background.
thanks all, i'm fairly new to Xdev
figured it out, I needed to have the custom NSView subclass I'm using to draw the window use
[self bounds] when drawing vs the dirtyRect passed to the drawrect method.

How to prevent UIView background from rotating? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I rotate a UIView without the black bars?
I want the labels on my UIView to rotate (and they do) but I've set the background to a color other than black. When I rotate you can see the view's rectangle rotate against a black background. How can I keep the UIView's background still yet allow the rest of the subviews to rotate normally? And what is that black background behind everything? Do I have access to it?
I'm not sure I fully understand the question. What I think your question is (if I'm misunderstanding please clarify where I'm getting the question wrong):
You have a UIView that is the same size as the device's screen.
You want to rotate that view.
When you rotate that view the background of the view's parent view can be seen.
I think the only ways to resolve this are either:
A) Make the view you're rotating larger than the screen so that when you rotate the parent view isn't visible. If you do this make sure the parent view isn't set to clip it's subviews otherwise you won't see any difference after resizing.
OR
B) Make the parent view's background color match the color of the view you're rotating. If you don't want to permanently alter the background color of the parent view you can always change the color when you start the animation and revert to the original color when done.
P.S. - I think the "black background behind everything" is the background color of your app's UIWindow. If you want to change that you can do the following (assuming your app delegate has a window property defined but if you used one of the standard Xcode templates to create your app it should):
UIWindow* window = [[UIApplication sharedApplication].delegate window];
[window setBackgroundColor:<Some UIColor>];

Borderless NSWindow with rounded corners

I am creating a custom NSWindow with no title bar and am using NSBorderlessWindowMask to make it completely borderless. The problem I have with this however is that the window has sharp edges. As well as this there is no resize control.
How would I give a borderless window rounded corners?
This is not a duplicate of this
question as that question was more
about removing the title bar and it
currently holds no answers.
You can make the window totally transparent and handle drawing everything yourself. The sample I have is for an OpenGL view, but it should work for a Quartz view or Cocoa view as well.
Add the following to the initializer of your NSWindow subclass where you create the new window using the NSBorderlessWindowMask constant.
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
You will probably have to draw the resize control yourself. The sample I took this from is a full screen window so resizing isn't necessary.
Good Luck.
The easiest way to get a window with rounded corners is to place a NSBox into the window as these boxes have customizable rounded corners and customizable borders. If you then set the window to non-opaque and the background color to transparent ("clear color"), you have a NSWindow with rounded corners that draws a normal window shadow (even on older systems where such a window would otherwise not have a shadow). Most of it can be done in Interface Builder. See here for details.
Only titled windows get the rounded corners. So the only thing you have to do is this:
window.styleMask = [.titled]
window.titleVisibility = .hidden
window.titlebarAppearsTransparent = true
This should be the minimal configuration for a rounded window without a title bar.

setBackgroundColor covers element

I have an NSWindow, and I'm using this code to add a bottom-metal-bar at the bottom.
[MyWindow setContentBorderThickness:40.0 forEdge:NSMinYEdge];
That works fine. But, once I use this:
[MyWindow setBackgroundColor: [NSColor redColor]];
The red covers the bar at the bottom. The bar shows correctly without the background color.
Yes, it would appear that changing the background-color of an NSWindow negates its bottom border. In order to achieve both effects, you can do one of two things:
In Interface Builder, move all your interface elements to a subclass of NSView that draws its background and add the view to your window.
Create an NSView that emulates the bottom border of your window and set the window's background color.
Personally, I would go for the first option, because it requires less work (trying to emulate a bottom border will be difficult, even with NSGradient) , but both are a possibility.

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.