/Volumes/Plantain/MyDocuments/Projects/MacTrek/MacTrek/Luky/Gui/TransparentWindow.m

00001 //
00002 //  TransparentWindow.m
00003 //  RoundedFloatingPanel
00004 //
00005 //  Created by Matt Gemmell on Thu Jan 08 2004.
00006 //  <http://iratescotsman.com/>
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     /* Today we can, this is a full screen app
00055     if( (newOrigin.y + windowFrame.size.height) > (NSMaxY(screenFrame) - [NSMenuView menuBarHeight]) ){
00056         // Prevent dragging into the menu bar area
00057         newOrigin.y = NSMaxY(screenFrame) - windowFrame.size.height - [NSMenuView menuBarHeight];
00058     }
00059     */
00060     
00061     if (newOrigin.y > NSMaxY(screenFrame) - windowFrame.size.height) {
00062         // Prevent dragging off top of screen
00063         newOrigin.y = NSMaxY(screenFrame) - windowFrame.size.height;
00064     }
00065     
00066     if (newOrigin.y < NSMinY(screenFrame)) {
00067         // Prevent dragging off bottom of screen
00068         newOrigin.y = NSMinY(screenFrame);
00069     }
00070     if (newOrigin.x < NSMinX(screenFrame)) {
00071         // Prevent dragging off left of screen
00072         newOrigin.x = NSMinX(screenFrame);
00073     }
00074     if (newOrigin.x > NSMaxX(screenFrame) - windowFrame.size.width) {
00075         // Prevent dragging off right of screen
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     // Get mouse location in global coordinates
00088     initialLocation = [self convertBaseToScreen:[theEvent locationInWindow]];
00089     initialLocation.x -= windowFrame.origin.x;
00090     initialLocation.y -= windowFrame.origin.y;
00091 }
00092 
00093 
00094 @end

Generated on Fri Jul 28 19:15:23 2006 for MacTrek by  doxygen 1.4.7