00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #import "TransparentWindow.h"
00011
00012 @implementation TransparentWindow
00013
00014
00015 - (id)initWithContentRect:(NSRect)contentRect
00016 styleMask:(unsigned int)aStyle
00017 backing:(NSBackingStoreType)bufferingType
00018 defer:(BOOL)flag {
00019
00020 if (self = [super initWithContentRect:contentRect
00021 styleMask:NSBorderlessWindowMask
00022 backing:NSBackingStoreBuffered
00023 defer:NO]) {
00024 [self setLevel: NSStatusWindowLevel];
00025 [self setBackgroundColor: [NSColor clearColor]];
00026 [self setAlphaValue:0.5];
00027 [self setOpaque:NO];
00028 [self setHasShadow:NO];
00029
00030 return self;
00031 }
00032
00033 return nil;
00034 }
00035
00036
00037 - (BOOL) canBecomeKeyWindow
00038 {
00039 return YES;
00040 }
00041
00042
00043 - (void)mouseDragged:(NSEvent *)theEvent
00044 {
00045 NSPoint currentLocation;
00046 NSPoint newOrigin;
00047 NSRect screenFrame = [[NSScreen mainScreen] frame];
00048 NSRect windowFrame = [self frame];
00049
00050 currentLocation = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
00051 newOrigin.x = currentLocation.x - initialLocation.x;
00052 newOrigin.y = currentLocation.y - initialLocation.y;
00053
00054
00055
00056
00057
00058
00059
00060
00061 if (newOrigin.y > NSMaxY(screenFrame) - windowFrame.size.height) {
00062
00063 newOrigin.y = NSMaxY(screenFrame) - windowFrame.size.height;
00064 }
00065
00066 if (newOrigin.y < NSMinY(screenFrame)) {
00067
00068 newOrigin.y = NSMinY(screenFrame);
00069 }
00070 if (newOrigin.x < NSMinX(screenFrame)) {
00071
00072 newOrigin.x = NSMinX(screenFrame);
00073 }
00074 if (newOrigin.x > NSMaxX(screenFrame) - windowFrame.size.width) {
00075
00076 newOrigin.x = NSMaxX(screenFrame) - windowFrame.size.width;
00077 }
00078
00079 [self setFrameOrigin:newOrigin];
00080 }
00081
00082
00083 - (void)mouseDown:(NSEvent *)theEvent
00084 {
00085 NSRect windowFrame = [self frame];
00086
00087
00088 initialLocation = [self convertBaseToScreen:[theEvent locationInWindow]];
00089 initialLocation.x -= windowFrame.origin.x;
00090 initialLocation.y -= windowFrame.origin.y;
00091 }
00092
00093
00094 @end