forked from nongio-zz/rik.theme
-
Notifications
You must be signed in to change notification settings - Fork 7
/
NSWindow+Rik.m
163 lines (142 loc) · 4.56 KB
/
NSWindow+Rik.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "Rik+Button.h"
#include "RikWindowButton.h"
#include <AppKit/NSAnimation.h>
#import <AppKit/NSWindow.h>
#import <AppKit/NSImage.h>
#import "GNUstepGUI/GSTheme.h"
@interface DefaultButtonAnimation: NSAnimation
{
NSButtonCell * defaultbuttoncell;
BOOL reverse;
}
@property (nonatomic, assign) BOOL reverse;
@property (retain) NSButtonCell * defaultbuttoncell;
@end
@implementation DefaultButtonAnimation
@synthesize reverse;
@synthesize defaultbuttoncell;
- (void)setCurrentProgress:(NSAnimationProgress)progress
{
[super setCurrentProgress: progress];
if(defaultbuttoncell)
{
if(reverse)
{
defaultbuttoncell.pulseProgress = [NSNumber numberWithFloat: 1.0 - progress];
}else{
defaultbuttoncell.pulseProgress = [NSNumber numberWithFloat: progress];
}
[[defaultbuttoncell controlView] setNeedsDisplay: YES];
}
if (defaultbuttoncell && progress >= 1.0)
{
reverse = !reverse;
[self startAnimation];
}
}
@end
@interface DefaultButtonAnimationController : NSObject <NSWindowDelegate>
{
DefaultButtonAnimation * animation;
NSButtonCell * buttoncell;
}
@property (retain) NSButtonCell * buttoncell;
@property (retain) NSAnimation * animation;
@end
@implementation DefaultButtonAnimationController
@synthesize buttoncell;
@synthesize animation;
- (id) initWithButtonCell: (NSButtonCell*) cell
{
if (self = [super init]) {
buttoncell = cell;
}
return self;
}
- (void) startPulse
{
[self startPulse: NO];
}
- (void) startPulse: (BOOL) reverse
{
animation = [[DefaultButtonAnimation alloc] initWithDuration:0.7
animationCurve:NSAnimationEaseInOut];
animation.reverse = reverse;
[animation addProgressMark: 1.0];
[animation setDelegate: self];
[animation setFrameRate:30.0];
[animation setAnimationBlockingMode:NSAnimationNonblocking];
animation.defaultbuttoncell = buttoncell;
[animation startAnimation];
}
- (void)animation:(NSAnimation *)a
didReachProgressMark:(NSAnimationProgress)progress
{
//[animation stopAnimation];
//[self startPulse: !animation.reverse];
}
- (void)windowDidResignKey:(NSNotification *)notification
{
[animation stopAnimation];
}
@end
@implementation NSWindow(RikTheme)
+ (NSButton *) standardWindowButton: (NSWindowButton)button
forStyleMask: (NSUInteger) mask
{
RikWindowButton *newButton;
switch (button)
{
case NSWindowCloseButton:
newButton = [[RikWindowButton alloc] init];
[newButton setBaseColor: [NSColor colorWithCalibratedRed: 0.698 green: 0.427 blue: 1.00 alpha: 1]];
[newButton setImage: [NSImage imageNamed: @"common_Close"]];
[newButton setAlternateImage: [NSImage imageNamed: @"common_CloseH"]];
[newButton setAction: @selector(performClose:)];
break;
case NSWindowMiniaturizeButton:
newButton = [[RikWindowButton alloc] init];
[newButton setBaseColor: [NSColor colorWithCalibratedRed: 0.9 green: 0.7 blue: 0.3 alpha: 1]];
[newButton setImage: [NSImage imageNamed: @"common_Miniaturize"]];
[newButton setAlternateImage: [NSImage imageNamed: @"common_MiniaturizeH"]];
[newButton setAction: @selector(miniaturize:)];
break;
case NSWindowZoomButton:
// FIXME
newButton = [[RikWindowButton alloc] init];
[newButton setBaseColor: [NSColor colorWithCalibratedRed: 0.322 green: 0.778 blue: 0.244 alpha: 1]];
[newButton setAction: @selector(zoom:)];
break;
case NSWindowToolbarButton:
// FIXME
newButton = [[RikWindowButton alloc] init];
[newButton setAction: @selector(toggleToolbarShown:)];
break;
case NSWindowDocumentIconButton:
default:
newButton = [[RikWindowButton alloc] init];
// FIXME
break;
}
[newButton setRefusesFirstResponder: YES];
[newButton setButtonType: NSMomentaryChangeButton];
[newButton setImagePosition: NSImageOnly];
[newButton setBordered: YES];
[newButton setTag: button];
return AUTORELEASE(newButton);
}
- (void) setDefaultButtonCell: (NSButtonCell *)aCell
{
ASSIGN(_defaultButtonCell, aCell);
_f.default_button_cell_key_disabled = NO;
[aCell setKeyEquivalent: @"\r"];
[aCell setKeyEquivalentModifierMask: 0];
[aCell setIsDefaultButton: [NSNumber numberWithBool: YES]];
DefaultButtonAnimationController * animationcontroller = [[DefaultButtonAnimationController alloc] initWithButtonCell: aCell];
[self setDelegate:animationcontroller];
[animationcontroller startPulse];
}
- (void) animateDefaultButton: (id)sender
{
}
@end