-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNNSlidingStackView.m
More file actions
123 lines (97 loc) · 2.71 KB
/
Copy pathNNSlidingStackView.m
File metadata and controls
123 lines (97 loc) · 2.71 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// NNSlidingStackView.m
// lunchd
//
// Created by MacRae Linton on 3/26/10.
// Copyright 2010 Apple Inc.. All rights reserved.
//
#import "NNSlidingStackView.h"
@implementation NNSlidingStackView
@synthesize stackBottom;
@synthesize stripeHeight;
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
stackBottom = 0.0;
stripeHeight = 60.0;
arrangedSubViews = [[NSMutableArray alloc] initWithCapacity:5];
}
return self;
}
- (BOOL)isFlipped
{
return YES;
}
- (void)addArrangedSubview:(NSView *)subView
{
float subViewHeight = [subView frame].size.height;
[subView setFrameOrigin:(NSPoint){ 0, stackBottom }];
[self setStackBottom: stackBottom + subViewHeight];
[self addSubview:subView];
[arrangedSubViews addObject:subView];
if (stackBottom > [self frame].size.height) {
[self setFrameSize:(NSSize){ [self frame].size.width, stackBottom }];
}
}
- (void)insertArrangedSubview:(NSView *)subView atIndex:(int)index
{
[self addArrangedSubview:subView];
[self slideViewAtIndex:[arrangedSubViews count]-1 toIndex:index];
}
- (void)drawRect:(NSRect)rect
{
//NSLog(@"Drawing RecT!: %@",[NSValue valueWithRect:rect]);
//Need to draw strips in the background.
NSColor *stripeColor = [NSColor colorWithDeviceRed:.93 green:.95 blue:.99 alpha:1.0];
[stripeColor set];
int numSections = stackBottom / stripeHeight, i;
// int startSection = rect.origin.y / stripeHeight;
float stripeWidth = rect.size.width;
NSRect stripeRect;
stripeRect.origin = (NSPoint){ 0, stripeHeight };
stripeRect.size = (NSSize){ stripeWidth, stripeHeight };
for (i = 0; i< numSections; i++){
if (i % 2){
stripeRect.origin.y = i * stripeHeight;
[NSBezierPath fillRect:stripeRect];
}
}
}
- (void)slideViewAtIndex:(int)startIndex toIndex:(int)endIndex
{
if (startIndex == endIndex){
return;
}
//grey out layer
//move all other layers while moving greyed out layer.
NSView *mommaView = [arrangedSubViews objectAtIndex:startIndex];
NSRect aRect = [mommaView frame];
//Right now we are giving no special treatment to the moved, could probably throw it in.
[arrangedSubViews removeObjectAtIndex:startIndex];
[arrangedSubViews insertObject:mommaView atIndex:endIndex];
int i, bottomIndex;
if (startIndex > endIndex){
i = endIndex;
bottomIndex = startIndex;
}else {
i = startIndex;
bottomIndex = endIndex;
}
for (i; i <=bottomIndex; i++){
NSView *babyView = [arrangedSubViews objectAtIndex:i];
aRect.origin.y = i * stripeHeight;
[[babyView animator] setFrame:aRect];
}
}
//NON GENERAL FUCNTIONS
- (void)updateTrackingAreas
{
NSLog(@"I DIDNT UDATE A TRACKING AREA");
}
- (void)updateAll
{
for (NSView *view in arrangedSubViews){
[view updateState];
}
}
@end