/* # Created by Matteo Rattotti on 13/03/06. # Copyright (c) 2006 - 2007 Shiny Frog. All rights reserved. # Contact matteo.rattotti@shinyfrog.net for any problem # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #import "TransparentWindow.h" @implementation TransparentWindow - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { if (self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]) { //[self setLevel: NSStatusWindowLevel]; [self setLevel: NSNormalWindowLevel]; //[self setLevel: kCGDesktopWindowLevel];// + 1]; [self setBackgroundColor: [NSColor clearColor]]; [self setAlphaValue:1.0]; [self setOpaque:NO]; [self setHasShadow:NO]; [self setMovableByWindowBackground:YES]; //[self setIgnoresMouseEvents:YES]; return self; } return nil; } - (BOOL) canBecomeKeyWindow { return YES; } - (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) > (NSMaxY(screenFrame) - [NSMenuView menuBarHeight]) ){ // Prevent dragging into the menu bar area newOrigin.y = NSMaxY(screenFrame) - windowFrame.size.height - [NSMenuView menuBarHeight]; } /* if (newOrigin.y < NSMinY(screenFrame)) { // Prevent dragging off bottom of screen newOrigin.y = NSMinY(screenFrame); } if (newOrigin.x < NSMinX(screenFrame)) { // Prevent dragging off left of screen newOrigin.x = NSMinX(screenFrame); } if (newOrigin.x > NSMaxX(screenFrame) - windowFrame.size.width) { // Prevent dragging off right of screen newOrigin.x = NSMaxX(screenFrame) - windowFrame.size.width; } */ [self setFrameOrigin:newOrigin]; } - (void)mouseDown:(NSEvent *)theEvent { //NSLog(@"click!"); NSRect windowFrame = [self frame]; // Get mouse location in global coordinates initialLocation = [self convertBaseToScreen:[theEvent locationInWindow]]; initialLocation.x -= windowFrame.origin.x; initialLocation.y -= windowFrame.origin.y; } @end