forked from HBehrens/CamHolderApp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBorderlessWindow.m
107 lines (84 loc) · 2.81 KB
/
BorderlessWindow.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// BorderlessWindow.m
// CameraControl
//
// Created by Heiko Behrens on 19.10.11.
// Copyright 2011 BeamApp. All rights reserved.
//
#import "BorderlessWindow.h"
@implementation BorderlessWindow
// NOTE: taken from http://www.cocoadev.com/index.pl?BorderlessWindow
- (void)mouseDragged:(NSEvent *)theEvent
{
if([self isZoomed])
return;
if (!isDragging)
{
initialLocation = [theEvent locationInWindow];
initialLocationOnScreen = [self convertBaseToScreen:[theEvent locationInWindow]];
initialFrame = [self frame];
isDragging = YES;
if (initialLocation.x > initialFrame.size.width - 20 && initialLocation.y < 20) {
shouldDrag = NO;
}
else {
//mouseDownType = PALMOUSEDRAGSHOULDMOVE;
shouldDrag = YES;
}
screenFrame = [[NSScreen mainScreen] frame];
windowFrame = [self frame];
minY = windowFrame.origin.y+(windowFrame.size.height-288);
}
// 1. Is the Event a resize drag (test for bottom right-hand corner)?
if (shouldDrag == FALSE)
{
// i. Remember the current downpoint
NSPoint currentLocationOnScreen = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
currentLocation = [theEvent locationInWindow];
// ii. Adjust the frame size accordingly
float heightDelta = (currentLocationOnScreen.y - initialLocationOnScreen.y);
if ((initialFrame.size.height - heightDelta) < 289)
{
windowFrame.size.height = 288;
//windowFrame.origin.y = initialLocation.y-(initialLocation.y - windowFrame.origin.y)+heightDelta;
windowFrame.origin.y = minY;
} else
{
windowFrame.size.height = (initialFrame.size.height - heightDelta);
windowFrame.origin.y = (initialFrame.origin.y + heightDelta);
}
windowFrame.size.width = initialFrame.size.width + (currentLocation.x - initialLocation.x);
if (windowFrame.size.width < 323)
{
windowFrame.size.width = 323;
}
// iii. Set
[self setFrame:windowFrame display:YES animate:NO];
}
else
{
//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 = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];
newOrigin.x = currentLocation.x - initialLocation.x;
newOrigin.y = currentLocation.y - initialLocation.y;
// Don't let window get dragged up under the menu bar
if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height) )
{
newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height);
}
//go ahead and move the window to the new location
[self setFrameOrigin:newOrigin];
}
}
- (void)mouseUp:(NSEvent *)theEvent
{
isDragging = NO;
}
+(NSRect)fullscreenRect:(NSScreen*)screen {
return screen.frame;
}
-(BOOL)isZoomed {
return NSEqualRects(self.frame, [self.class fullscreenRect:self.screen]);
}
@end