#import “TPWindow.h”
#import <AppKit/AppKit.h>
@implementation TPWindow
// This line initializes any window connected to the CustomWindow class as titleless…overriding the default AppKit init method.
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {
// Call the NSWindow method to instantiate the window, but add the borderless mask to make it titleless
// Sets ‘result’ as a variable reference to the new window object
NSWindow* result = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
// Set the background color to clear so that (along with the setOpaque call below) we can see through the parts of the window that we’re not drawing into
// If you want to have a window with a non-rectangular shape, un-comment the next line.
[result setBackgroundColor: [NSColor clearColor]];
// Note: You’ll need to provide an image in an image view in the window that will server as your ‘window’, otherwise the window will just be invisible.
// The next line makes the window float on top of all other windows. Uncomment it if you wish the window to remain on top of ALL other windows.
[result setLevel: NSStatusWindowLevel];
// Note: this is useful for startup screens or other utility windows that only you should control
// Control the transparency of the entire window. 0 is totally transparent… 1 is totally opaque.
[result setAlphaValue:1.0];
// Control Opaqueness. Leave “YES” to make it a “normal” window.
// Set to “NO”, and use in conjunction with the ‘clearColor’ background color above to make a window with a custom graphic shape.
[result setOpaque:NO];
// Does the window has a shadow?
[result setHasShadow: NO];
// Automatically center the window? Position will be handled as any normal xcode window would be if this is not used.
//[result center];
return result;
}
// Custom windows that use the NSBorderlessWindowMask can’t become key by default. Therefore, controls in such windows
// won’t ever be enabled by default. Thus, we override this method to change that.
- (BOOL) canBecomeKeyWindow
{
return NO;
}
// IMPORTANT //
// Everything below here (except the “@end” at the end
can be omitted if you are not allowing dragging of the window.
// Make sure the “CustomWindow.h” file has the single line mentioned above if you ARE going to implement dragging.
// This code implements dragging of the window manually, because borderless windows can not be dragged by default.
/*
- (void)mouseDragged:(NSEvent *)theEvent
{
NSPoint currentLocation;
NSPoint newOrigin;
NSRect screenFrame = [[NSScreen mainScreen] frame];
NSRect windowFrame = [self frame];
currentLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
newOrigin.x = currentLocation.x - initialLocation.x;
newOrigin.y = currentLocation.y - initialLocation.y;
if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height) ){
newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height);
}
[self setFrameOrigin:newOrigin];
}
// Get the intital mouse location
- (void)mouseDown:(NSEvent *)theEvent
{
NSRect windowFrame = [self frame];
initialLocation = [self convertBaseToScreen:[theEvent locationInWindow]];
initialLocation.x -= windowFrame.origin.x;
initialLocation.y -= windowFrame.origin.y;
}
*/
// Don’t delete this last line by accident!!! //
@end