-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoundWindow.m
executable file
·79 lines (66 loc) · 1.85 KB
/
RoundWindow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// RoundWindow.m
// RoundWindow
//
// Created by Matt Gallagher on 12/12/08.
// Copyright 2008 Mocra. All rights reserved.
//
#import "RoundWindow.h"
@implementation RoundWindow
-(void)loadWindow{
[self setLevel:NSFloatingWindowLevel];
[self makeKeyAndOrderFront:self];
[self setAcceptsMouseMovedEvents:YES];
NSPoint currentLocation;
NSPoint newOrigin;
NSRect screenFrame = [[NSScreen mainScreen] frame];
NSRect windowFrame = [self frame];
//grab the current global mouse location; we could just as easily get the mouse location
//in the same way as we do in -mouseDown:
currentLocation = [NSEvent mouseLocation];
int windowWidth = [self frame].size.width / 2;
int windowHeight = [self frame].size.height - 25;
newOrigin.x = currentLocation.x - windowWidth + MOUSE_POSITION_X;
newOrigin.y = currentLocation.y - windowHeight - MOUSE_POSITION_Y;
// Don't let window get dragged up under the menu bar
if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height)-20 ){
newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height)-30;
}
//go ahead and move the window to the new location
[self setFrameOrigin:newOrigin];
[self makeKeyWindow];
}
//
// initWithContentRect:styleMask:backing:defer:screen:
//
// Init method for the object.
//
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)deferCreation
{
self = [super
initWithContentRect:contentRect
styleMask:NSNonactivatingPanelMask
backing:bufferingType
defer:deferCreation];
if (self)
{
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
}
return self;
}
//
// dealloc
//
// Releases instance memory.
//
- (void)dealloc
{
[[NSNotificationCenter defaultCenter]
removeObserver:self];
[super dealloc];
}
@end